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.
This commit is contained in:
Abdullah Tahiri
2015-06-08 17:21:53 +02:00
committed by wmayer
parent da5270131c
commit d1acd124cc
4 changed files with 44 additions and 2 deletions

View File

@@ -51,6 +51,8 @@
#include <Base/Tools.h> #include <Base/Tools.h>
#include <Base/Console.h> #include <Base/Console.h>
#include <App/Document.h>
#include <Mod/Part/App/Geometry.h> #include <Mod/Part/App/Geometry.h>
#include "SketchObject.h" #include "SketchObject.h"

View File

@@ -70,6 +70,10 @@
# include <QTextStream> # include <QTextStream>
#endif #endif
#ifndef _PreComp_
# include <boost/bind.hpp>
#endif
#include <Inventor/SbTime.h> #include <Inventor/SbTime.h>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
@@ -293,6 +297,22 @@ ViewProviderSketch::~ViewProviderSketch()
delete rubberband; 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 *************************************************************** // handler management ***************************************************************
void ViewProviderSketch::activateHandler(DrawSketchHandler *newHandler) void ViewProviderSketch::activateHandler(DrawSketchHandler *newHandler)
{ {
@@ -4206,6 +4226,11 @@ bool ViewProviderSketch::setEdit(int ModNum)
getSketchObject()->solve(); // This call to the solver is needed to initialize the DoF and solve time controls 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. //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; return true;
} }
@@ -4495,6 +4520,9 @@ void ViewProviderSketch::unsetEdit(int ModNum)
std::string DocName = getSketchObject()->getDocument()->getName(); std::string DocName = getSketchObject()->getDocument()->getName();
Gui::Selection().addSelection(DocName.c_str(),ObjName.c_str()); Gui::Selection().addSelection(DocName.c_str(),ObjName.c_str());
connectUndoDocument.disconnect();
connectRedoDocument.disconnect();
// when pressing ESC make sure to close the dialog // when pressing ESC make sure to close the dialog
Gui::Control().closeDialog(); Gui::Control().closeDialog();
} }

View File

@@ -32,6 +32,9 @@
#include <Gui/GLPainter.h> #include <Gui/GLPainter.h>
#include <boost/signals.hpp> #include <boost/signals.hpp>
#include <QCoreApplication> #include <QCoreApplication>
#include <Gui/Document.h>
#include <boost/signals.hpp>
class TopoDS_Shape; class TopoDS_Shape;
class TopoDS_Face; class TopoDS_Face;
@@ -206,6 +209,7 @@ public:
virtual bool mouseButtonPressed(int Button, bool pressed, const SbVec2s& cursorPos, const Gui::View3DInventorViewer* viewer); virtual bool mouseButtonPressed(int Button, bool pressed, const SbVec2s& cursorPos, const Gui::View3DInventorViewer* viewer);
//@} //@}
friend class DrawSketchHandler; friend class DrawSketchHandler;
friend struct ::EditData; friend struct ::EditData;
@@ -241,6 +245,14 @@ protected:
/// build up the visual of the constraints /// build up the visual of the constraints
void rebuildConstraintsVisual(void); 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*/ /** @name Protected helpers for drawing constraint icons*/
//@{ //@{
QString iconTypeFromConstraint(Sketcher::Constraint *constraint); QString iconTypeFromConstraint(Sketcher::Constraint *constraint);