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/Console.h>
#include <App/Document.h>
#include <Mod/Part/App/Geometry.h>
#include "SketchObject.h"

View File

@ -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<Part::Geometry *> ExternalGeo;

View File

@ -70,6 +70,10 @@
# include <QTextStream>
#endif
#ifndef _PreComp_
# include <boost/bind.hpp>
#endif
#include <Inventor/SbTime.h>
#include <boost/scoped_ptr.hpp>
@ -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();
}

View File

@ -32,6 +32,9 @@
#include <Gui/GLPainter.h>
#include <boost/signals.hpp>
#include <QCoreApplication>
#include <Gui/Document.h>
#include <boost/signals.hpp>
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*/
//@{