From a361af4aadb5edef2fa72a9e0cc24ecb0d6deadc Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 8 Jun 2015 17:21:53 +0200 Subject: [PATCH] Sketcher: Bug fix: Undo/Redo implementation ================================================ Fixes a bug in master that the dependent 3D geometry would not update on Undo (in Auto update mode enabled). Undo and redo signals are handled by ViewProvider in order to introduce an recompute or solve() of the sketchObject as determined by the Auto Update Mode in order to update DoF and dependent geometry if necessary. --- src/Mod/Sketcher/App/SketchObject.cpp | 2 ++ src/Mod/Sketcher/App/SketchObject.h | 2 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 30 ++++++++++++++++++++- src/Mod/Sketcher/Gui/ViewProviderSketch.h | 12 +++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index bfcbb61996..7260fa6743 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -51,6 +51,8 @@ #include #include +#include + #include #include "SketchObject.h" diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index f58f151052..921d606a3e 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -227,7 +227,7 @@ protected: /// get called by the container when a property has changed virtual void onChanged(const App::Property* /*prop*/); virtual void onDocumentRestored(); - + private: std::vector ExternalGeo; diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 22839d61e9..9cbaaf8553 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -70,6 +70,10 @@ # include #endif +#ifndef _PreComp_ +# include +#endif + #include #include @@ -292,6 +296,22 @@ ViewProviderSketch::~ViewProviderSketch() { delete rubberband; } + +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 +} + +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 +} // handler management *************************************************************** void ViewProviderSketch::activateHandler(DrawSketchHandler *newHandler) @@ -4205,6 +4225,11 @@ bool ViewProviderSketch::setEdit(int ModNum) getSketchObject()->solve(); // This call to the solver is needed to initialize the DoF and solve time controls //draw(); is not necessary, because a solve triggers an updateData. + + connectUndoDocument = Gui::Application::Instance->activeDocument() + ->signalUndoDocument.connect(boost::bind(&ViewProviderSketch::slotUndoDocument, this, _1)); + connectRedoDocument = Gui::Application::Instance->activeDocument() + ->signalRedoDocument.connect(boost::bind(&ViewProviderSketch::slotRedoDocument, this, _1)); return true; } @@ -4494,7 +4519,10 @@ void ViewProviderSketch::unsetEdit(int ModNum) std::string ObjName = getSketchObject()->getNameInDocument(); std::string DocName = getSketchObject()->getDocument()->getName(); Gui::Selection().addSelection(DocName.c_str(),ObjName.c_str()); - + + connectUndoDocument.disconnect(); + connectRedoDocument.disconnect(); + // when pressing ESC make sure to close the dialog Gui::Control().closeDialog(); } diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index f3cbfb25f3..c806e36b2f 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -32,6 +32,9 @@ #include #include #include +#include + +#include class TopoDS_Shape; class TopoDS_Face; @@ -206,6 +209,7 @@ public: virtual bool mouseButtonPressed(int Button, bool pressed, const SbVec2s& cursorPos, const Gui::View3DInventorViewer* viewer); //@} + friend class DrawSketchHandler; friend struct ::EditData; @@ -240,6 +244,14 @@ protected: EditData *edit; /// build up the visual of the constraints void rebuildConstraintsVisual(void); + + void slotUndoDocument(const Gui::Document&); + void slotRedoDocument(const Gui::Document&); + +protected: + boost::signals::connection connectUndoDocument; + boost::signals::connection connectRedoDocument; + /** @name Protected helpers for drawing constraint icons*/ //@{