From 58210251cae0ef5d2f00f75756fdef72b7104817 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 4 Jun 2017 06:28:08 +0200 Subject: [PATCH] Refactoring solve+recompute and reinstating initial solve+recompute behaviour --- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 29 +++---- src/Mod/Sketcher/Gui/CommandConstraints.h | 6 +- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 75 +++++++------------ .../Sketcher/Gui/CommandSketcherBSpline.cpp | 12 +-- src/Mod/Sketcher/Gui/CommandSketcherTools.cpp | 16 ++-- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 8 +- 6 files changed, 59 insertions(+), 87 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index a0065f5228..d05e457413 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -175,8 +175,7 @@ void openEditDatumDialog(Sketcher::SketchObject* sketch, int ConstrNbr) QMessageBox::critical(qApp->activeWindow(), QObject::tr("Dimensional constraint"), QString::fromUtf8(e.what())); Gui::Command::abortCommand(); - sketch->solve(); // we have to update the solver after this aborted addition. - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(sketch); } } } @@ -184,8 +183,7 @@ void openEditDatumDialog(Sketcher::SketchObject* sketch, int ConstrNbr) // command canceled Gui::Command::abortCommand(); - sketch->solve(); // we have to update the solver after this aborted addition. - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(sketch); // we have to update the solver after this aborted addition. } } } @@ -627,15 +625,24 @@ std::string SketcherGui::getStrippedPythonExceptionString(const Base::Exception return msg; } -void SketcherGui::tryAutoRecompute() +bool SketcherGui::tryAutoRecompute() { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool autoRecompute = hGrp->GetBool("AutoRecompute",false); if (autoRecompute) Gui::Command::updateActive(); + + return autoRecompute; } +void SketcherGui::tryAutoRecomputeIfNotSolve(Sketcher::SketchObject* obj) +{ + if(!tryAutoRecompute()) + obj->solve(); +} + + namespace SketcherGui { struct SelIdPair{ @@ -4767,8 +4774,7 @@ void CmdSketcherConstrainRadius::activated(int iMsg) QMessageBox::critical(qApp->activeWindow(), QObject::tr("Dimensional constraint"), QString::fromUtf8(e.what())); abortCommand(); - Obj->solve(); // we have to update the solver after this aborted addition. - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(Obj); // we have to update the solver after this aborted addition. } } else { @@ -4791,8 +4797,7 @@ void CmdSketcherConstrainRadius::activated(int iMsg) commitCommand(); if(updateNeeded) { - Obj->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(Obj); // we have to update the solver after this aborted addition. } } @@ -4902,8 +4907,7 @@ void CmdSketcherConstrainRadius::applyConstraint(std::vector &selSeq, QMessageBox::critical(qApp->activeWindow(), QObject::tr("Dimensional constraint"), QString::fromUtf8(e.what())); abortCommand(); - Obj->solve(); // we have to update the solver after this aborted addition. - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(Obj); // we have to update the solver after this aborted addition. } } else { @@ -4925,8 +4929,7 @@ void CmdSketcherConstrainRadius::applyConstraint(std::vector &selSeq, commitCommand(); if(updateNeeded) { - Obj->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(Obj); // we have to update the solver after this aborted addition. } } } diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.h b/src/Mod/Sketcher/Gui/CommandConstraints.h index 3e00a368ab..13aebca913 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.h +++ b/src/Mod/Sketcher/Gui/CommandConstraints.h @@ -103,8 +103,12 @@ std::string getStrippedPythonExceptionString(const Base::Exception); /// This function tries to auto-recompute the active document if the option /// is set in the user parameter. If the option is not set nothing will be done -void tryAutoRecompute(); +/// @return true if a recompute was undertaken, false if not. +bool tryAutoRecompute(); +/// This function tries to auto-recompute as tryAutoRecompute. If tryAutoRecompute +/// is not enabled, then it solves the SketchObject. +void tryAutoRecomputeIfNotSolve(Sketcher::SketchObject* obj); } #endif // SKETCHERGUI_DrawSketchHandler_H diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 745fa91e5a..f5adf119bb 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -361,8 +361,7 @@ public: sugConstr2.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); EditCurve.clear(); sketchgui->drawEdit(EditCurve); @@ -598,8 +597,7 @@ public: sugConstr2.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); @@ -1118,8 +1116,7 @@ public: } Gui::Command::commitCommand(); - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); } ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); @@ -1205,8 +1202,7 @@ public: sugConstr2.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); // remember the vertex for the next rounds constraint.. previousCurve = getHighestCurveIndex(); @@ -1578,8 +1574,7 @@ public: } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); @@ -1889,8 +1884,7 @@ public: sugConstr3.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); @@ -2194,8 +2188,7 @@ public: sugConstr2.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); @@ -2989,8 +2982,7 @@ private: Base::Console().Error("%s\n", e.what()); Gui::Command::abortCommand(); - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); return; } @@ -3028,8 +3020,7 @@ private: } } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); // This code enables the continuous creation mode. if (constrMethod == 0) { @@ -3407,8 +3398,7 @@ public: Base::Console().Error("%s\n", e.what()); Gui::Command::abortCommand(); - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); return false; } @@ -3439,8 +3429,7 @@ public: sugConstr4.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); @@ -3790,8 +3779,7 @@ public: Base::Console().Error("%s\n", e.what()); Gui::Command::abortCommand(); - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); return false; } @@ -3822,8 +3810,7 @@ public: sugConstr4.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); @@ -4137,8 +4124,7 @@ public: Base::Console().Error("%s\n", e.what()); Gui::Command::abortCommand(); - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); return false; } @@ -4169,8 +4155,7 @@ public: sugConstr4.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); @@ -4669,16 +4654,14 @@ public: Base::Console().Error("%s\n", e.what()); Gui::Command::abortCommand(); - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); return false; } Gui::Command::commitCommand(); - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); @@ -4731,8 +4714,7 @@ public: Gui::Command::abortCommand(); - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); if(!continuousMode){ DrawSketchHandler::quit(); @@ -5149,8 +5131,7 @@ public: sugConstr3.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); @@ -5402,8 +5383,7 @@ public: sugConstr.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); @@ -5688,8 +5668,7 @@ public: Gui::Command::abortCommand(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); } return true; } @@ -6494,8 +6473,7 @@ public: // redraw a changed Sketch if the solver geometry amount is the same as the SkethObject // geometry amount (as this avoids other issues). // This solver is a very low cost one anyway (there is actually nothing to solve). - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); Gui::Selection().clearSelection(); /* this is ok not to call to purgeHandler @@ -6708,8 +6686,7 @@ static const char *cursor_carboncopy[]={ Gui::Command::commitCommand(); - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); Gui::Selection().clearSelection(); /* this is ok not to call to purgeHandler @@ -6970,8 +6947,7 @@ public: sugConstr2.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); } catch (const Base::Exception& e) { Base::Console().Error("Failed to add slot: %s\n", e.what()); @@ -7200,8 +7176,7 @@ public: sugConstr2.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); } catch (const Base::Exception& e) { Base::Console().Error("Failed to add hexagon: %s\n", e.what()); diff --git a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp index 042583699c..e8030fe759 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp @@ -410,8 +410,7 @@ void CmdSketcherConvertToNURB::activated(int iMsg) commitCommand(); } - Obj->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(Obj); } bool CmdSketcherConvertToNURB::isActive(void) @@ -474,8 +473,7 @@ void CmdSketcherIncreaseDegree::activated(int iMsg) commitCommand(); - Obj->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(Obj); getSelection().clearSelection(); } @@ -634,8 +632,7 @@ void CmdSketcherIncreaseKnotMultiplicity::activated(int iMsg) commitCommand(); } - Obj->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(Obj); getSelection().clearSelection(); @@ -782,8 +779,7 @@ void CmdSketcherDecreaseKnotMultiplicity::activated(int iMsg) commitCommand(); } - Obj->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(Obj); getSelection().clearSelection(); } diff --git a/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp b/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp index 119ea3ef5c..0fe1c42c63 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp @@ -783,16 +783,14 @@ void CmdSketcherRestoreInternalAlignmentGeometry::activated(int iMsg) Base::Console().Error("%s\n", e.what()); Gui::Command::abortCommand(); - static_cast(Obj)->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(Obj)); return; } Gui::Command::commitCommand(); - static_cast(Obj)->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(Obj)); } } } @@ -982,8 +980,7 @@ void CmdSketcherSymmetry::activated(int iMsg) Gui::Command::abortCommand(); } - Obj->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(Obj); } bool CmdSketcherSymmetry::isActive(void) @@ -1123,8 +1120,7 @@ static const char *cursor_createcopy[]={ sugConstr1.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); EditCurve.clear(); sketchgui->drawEdit(EditCurve); @@ -1566,8 +1562,8 @@ static const char *cursor_createrectangulararray[]={ sugConstr1.clear(); } - static_cast(sketchgui->getObject())->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(static_cast(sketchgui->getObject())); + EditCurve.clear(); sketchgui->drawEdit(EditCurve); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 72db88d747..c2215bc693 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -769,9 +769,8 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe ,GeoId, PosId, x-xInit, y-yInit, relative ? 1 : 0 ); Gui::Command::commitCommand(); - - getSketchObject()->solve(); - tryAutoRecompute(); + + tryAutoRecomputeIfNotSolve(getSketchObject()); } catch (const Base::Exception& e) { Gui::Command::abortCommand(); @@ -804,8 +803,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe ); Gui::Command::commitCommand(); - getSketchObject()->solve(); - tryAutoRecompute(); + tryAutoRecomputeIfNotSolve(getSketchObject()); } catch (const Base::Exception& e) { Gui::Command::abortCommand();