Skip to content

Commit

Permalink
Sketcher: Bug fix: Undo/Redo implementation
Browse files Browse the repository at this point in the history
================================================

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.
  • Loading branch information
abdullahtahiriyo authored and wwmayer committed Jun 15, 2015
1 parent da52701 commit d1acd12
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Sketcher/App/SketchObject.h
Expand Up @@ -227,7 +227,7 @@ class SketcherExport SketchObject : public Part::Part2DObject
/// 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;

Expand Down
30 changes: 29 additions & 1 deletion src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
Expand Up @@ -70,6 +70,10 @@
# include <QTextStream>
#endif

#ifndef _PreComp_
# include <boost/bind.hpp>
#endif

#include <Inventor/SbTime.h>
#include <boost/scoped_ptr.hpp>

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand Down
12 changes: 12 additions & 0 deletions src/Mod/Sketcher/Gui/ViewProviderSketch.h
Expand Up @@ -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;
Expand Down Expand Up @@ -206,6 +209,7 @@ class SketcherGuiExport ViewProviderSketch : public PartGui::ViewProvider2DObjec
virtual bool mouseButtonPressed(int Button, bool pressed, const SbVec2s& cursorPos, const Gui::View3DInventorViewer* viewer);
//@}


friend class DrawSketchHandler;
friend struct ::EditData;

Expand Down Expand Up @@ -240,6 +244,14 @@ class SketcherGuiExport ViewProviderSketch : public PartGui::ViewProvider2DObjec
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*/
//@{
Expand Down

0 comments on commit d1acd12

Please sign in to comment.