Sketcher: ViewProviderSketch delay updateData on undo/redo transactions

=======================================================================

On App:Document::undo, applchn is called on every transactional object (e.g. properties) affected, which
calls Paste on the property.

Each of the properties of SketchObject cause a call to SketchObject::OnChanged, and App::DocumentObject::OnChanged, the latter
calling onChangeProperty, which signals the viewprovider from Gui::Document::slotChangedObject via ViewProviderSketch::updateData.

This causes that the ViewProvider is updated when Constraints and Geometry indexes are not matching.

The solution proposed has three parts:
1. First, at ViewProvider::updateData update is prevented while undo/redo transaction is performed by checking isPerformingTransaction()
2. Second, the onUndoRedoFinished() mechanism of SketchObject causes the call of updateData when it solves the sketch (and sets the solved geometry)
3. Third, Gui::Document::signalUndoDocument and Gui::Document::signalRedoDocument (via the slots in ViewProviderSketch) are
used to perform the recompute of the ViewProvider when the undo/redo transaction is finished if needed.
This commit is contained in:
Abdullah Tahiri
2020-06-11 20:14:19 +02:00
committed by wwmayer
parent b08aa0d0e9
commit ee9eb741b4
2 changed files with 26 additions and 11 deletions

View File

@@ -369,18 +369,31 @@ ViewProviderSketch::~ViewProviderSketch()
void ViewProviderSketch::slotUndoDocument(const Gui::Document& /*doc*/)
{
if(getSketchObject()->noRecomputes)
getSketchObject()->solve(); // the sketch must be solved to update the DoF of the solver
else
getSketchObject()->getDocument()->recompute(); // or fully recomputed if applicable
// Note 1: this slot is only operative during edit mode (see signal connection/disconnection)
// Note 2: ViewProviderSketch::UpdateData does not generate updates during undo/redo
// transactions as mid-transaction data may not be in a valid state (e.g. constraints
// may reference invalid geometry). However undo/redo notify SketchObject after the undo/redo
// and before this slot is called.
// Note 3: Note that recomputes are no longer inhibited during the call to this slot.
forceUpdateData();
}
void ViewProviderSketch::slotRedoDocument(const Gui::Document& /*doc*/)
{
if(getSketchObject()->noRecomputes)
getSketchObject()->solve(); // the sketch must be solved to update the DoF of the solver
else
getSketchObject()->getDocument()->recompute(); // or fully recomputed if applicable
// Note 1: this slot is only operative during edit mode (see signal connection/disconnection)
// Note 2: ViewProviderSketch::UpdateData does not generate updates during undo/redo
// transactions as mid-transaction data may not be in a valid state (e.g. constraints
// may reference invalid geometry). However undo/redo notify SketchObject after the undo/redo
// and before this slot is called.
// Note 3: Note that recomputes are no longer inhibited during the call to this slot.
forceUpdateData();
}
void ViewProviderSketch::forceUpdateData()
{
if(!getSketchObject()->noRecomputes) { // the sketch was already solved in SketchObject in onUndoRedoFinished
Gui::Command::updateActive();
}
}
// handler management ***************************************************************
@@ -5548,8 +5561,8 @@ void ViewProviderSketch::updateData(const App::Property *prop)
{
ViewProvider2DObject::updateData(prop);
if (edit && (prop == &(getSketchObject()->Geometry) ||
prop == &(getSketchObject()->Constraints))) {
if ( edit && !getSketchObject()->getDocument()->isPerformingTransaction() &&
(prop == &(getSketchObject()->Geometry) || prop == &(getSketchObject()->Constraints))) {
edit->FullyConstrained = false;
// At this point, we do not need to solve the Sketch
// If we are adding geometry an update can be triggered before the sketch is actually solved.

View File

@@ -279,6 +279,8 @@ protected:
boost::signals2::connection connectUndoDocument;
boost::signals2::connection connectRedoDocument;
void forceUpdateData();
/// Return display string for constraint including hiding units if
//requested.
QString getPresentationString(const Sketcher::Constraint *constraint);
@@ -427,7 +429,7 @@ protected:
std::string editDocName;
std::string editObjName;
std::string editSubName;
// Virtual space variables
bool isShownVirtualSpace; // indicates whether the present virtual space view is the Real Space or the Virtual Space (virtual space 1 or 2)