From eff8529ec6ca4a530740b2a03322679804ff070d Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sat, 9 Dec 2017 16:43:52 +0100 Subject: [PATCH] Sketcher: jumping while dragging - force recalculate initial solution ===================================================================== fixes #1734 Upon dragging, the initial solution is first calculated and them DogLeg is left with the work of solving for a solution next to the initial solution. When the change is too big and the gradients are no longer accurate to continue dragging, the dragging flips and jumps. The solution offered here is, not to update always the solution, as this also creates artifacts, but update it if the dragging goes beyond 20 times the initial dragging distance. https://forum.freecadweb.org/viewtopic.php?f=3&t=7589#p203580 https://forum.freecadweb.org/viewtopic.php?f=3&t=7589#p203712 --- src/Mod/Sketcher/App/Sketch.cpp | 18 ++++++++++++++++-- src/Mod/Sketcher/App/Sketch.h | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index 58a48106ba..83ba3478a2 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -68,7 +68,7 @@ TYPESYSTEM_SOURCE(Sketcher::Sketch, Base::Persistence) Sketch::Sketch() : SolveTime(0), GCSsys(), ConstraintsCounter(0), isInitMove(false), isFine(true), - defaultSolver(GCS::DogLeg),defaultSolverRedundant(GCS::DogLeg),debugMode(GCS::Minimal) +defaultSolver(GCS::DogLeg),defaultSolverRedundant(GCS::DogLeg),debugMode(GCS::Minimal) { } @@ -3193,8 +3193,22 @@ int Sketch::movePoint(int geoId, PointPos pos, Base::Vector3d toPoint, bool rela if (hasConflicts()) return -1; - if (!isInitMove) + if (!isInitMove) { initMove(geoId, pos); + initToPoint = toPoint; + moveStep = 0; + } + else { + if (moveStep == 0) { + moveStep = (toPoint-initToPoint).Length(); + } + else { + if( (toPoint-initToPoint).Length() > 20*moveStep) { // I am getting too far away from the original solution so reinit the solution + initMove(geoId, pos); + initToPoint = toPoint; + } + } + } if (relative) { for (int i=0; i < int(MoveParameters.size()-1); i+=2) { diff --git a/src/Mod/Sketcher/App/Sketch.h b/src/Mod/Sketcher/App/Sketch.h index 9f29c29d93..d1c834f581 100644 --- a/src/Mod/Sketcher/App/Sketch.h +++ b/src/Mod/Sketcher/App/Sketch.h @@ -397,6 +397,8 @@ protected: bool isInitMove; bool isFine; + Base::Vector3d initToPoint; + double moveStep; public: GCS::Algorithm defaultSolver;