From b6729a41d7999f78ded08365a90c4e792d672e07 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Fri, 25 Dec 2020 06:43:24 +0100 Subject: [PATCH] Sketcher: encapsulate Sketch::SolveTime and RecalculateInitialSolutionWhileMovingPoint members --- src/Mod/Sketcher/App/Sketch.h | 13 +++++++++++++ src/Mod/Sketcher/App/SketchObject.cpp | 2 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 10 +++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Mod/Sketcher/App/Sketch.h b/src/Mod/Sketcher/App/Sketch.h index 3babff3a9a..be04c5521e 100644 --- a/src/Mod/Sketcher/App/Sketch.h +++ b/src/Mod/Sketcher/App/Sketch.h @@ -104,6 +104,8 @@ public: inline bool hasRedundancies(void) const { return !Redundant.empty(); } inline const std::vector &getRedundant(void) const { return Redundant; } + inline float getSolveTime() const { return SolveTime; } + inline bool hasMalformedConstraints(void) const { return malformedConstraints; } public: std::set < std::pair< int, Sketcher::PointPos>> getDependencyGroup(int geoId, PointPos pos) const; @@ -132,6 +134,16 @@ public: */ int movePoint(int geoId, PointPos pos, Base::Vector3d toPoint, bool relative=false); + /** + * Sets whether the initial solution should be recalculated while dragging after a certain distance from the previous drag point + * for smoother dragging operation. + */ + bool getRecalculateInitialSolutionWhileMovingPoint() const + {return RecalculateInitialSolutionWhileMovingPoint;} + + void setRecalculateInitialSolutionWhileMovingPoint(bool recalculateInitialSolutionWhileMovingPoint) + {RecalculateInitialSolutionWhileMovingPoint = recalculateInitialSolutionWhileMovingPoint;} + /// add dedicated geometry //@{ /// add a point @@ -378,6 +390,7 @@ public: BSpline = 9 }; +protected: float SolveTime; bool RecalculateInitialSolutionWhileMovingPoint; diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 4bf10a90b2..e2984bd3b4 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -294,7 +294,7 @@ int SketchObject::solve(bool updateGeoAfterSolving/*=true*/) Base::Console().Error("Sketch %s has malformed constraints!\n",this->getNameInDocument()); } - lastSolveTime=solvedSketch.SolveTime; + lastSolveTime=solvedSketch.getSolveTime(); if (err == 0 && updateGeoAfterSolving) { // set the newly solved geometry diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 8b28077b54..1abe2c1608 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -1276,9 +1276,9 @@ bool ViewProviderSketch::mouseMove(const SbVec2s &cursorPos, Gui::View3DInventor if (getSketchObject()->getSolvedSketch().movePoint(GeoId, PosId, vec, false) == 0) { setPositionText(Base::Vector2d(x,y)); draw(true,false); - signalSolved(QString::fromLatin1("Solved in %1 sec").arg(getSketchObject()->getSolvedSketch().SolveTime)); + signalSolved(QString::fromLatin1("Solved in %1 sec").arg(getSketchObject()->getSolvedSketch().getSolveTime())); } else { - signalSolved(QString::fromLatin1("Unsolved (%1 sec)").arg(getSketchObject()->getSolvedSketch().SolveTime)); + signalSolved(QString::fromLatin1("Unsolved (%1 sec)").arg(getSketchObject()->getSolvedSketch().getSolveTime())); //Base::Console().Log("Error solving:%d\n",ret); } } @@ -1317,9 +1317,9 @@ bool ViewProviderSketch::mouseMove(const SbVec2s &cursorPos, Gui::View3DInventor if (getSketchObject()->getSolvedSketch().movePoint(edit->DragCurve, Sketcher::none, vec, relative) == 0) { setPositionText(Base::Vector2d(x,y)); draw(true,false); - signalSolved(QString::fromLatin1("Solved in %1 sec").arg(getSketchObject()->getSolvedSketch().SolveTime)); + signalSolved(QString::fromLatin1("Solved in %1 sec").arg(getSketchObject()->getSolvedSketch().getSolveTime())); } else { - signalSolved(QString::fromLatin1("Unsolved (%1 sec)").arg(getSketchObject()->getSolvedSketch().SolveTime)); + signalSolved(QString::fromLatin1("Unsolved (%1 sec)").arg(getSketchObject()->getSolvedSketch().getSolveTime())); } } return true; @@ -6255,7 +6255,7 @@ bool ViewProviderSketch::setEdit(int ModNum) // Enable solver initial solution update while dragging. ParameterGrp::handle hGrp2 = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); - getSketchObject()->getSolvedSketch().RecalculateInitialSolutionWhileMovingPoint = hGrp2->GetBool("RecalculateInitialSolutionWhileDragging",true); + getSketchObject()->getSolvedSketch().setRecalculateInitialSolutionWhileMovingPoint(hGrp2->GetBool("RecalculateInitialSolutionWhileDragging",true)); // intercept del key press from main app