From 023e319b84e4ee9e15ae0a73adb577501c9b34e2 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 10 Dec 2017 19:44:08 +0100 Subject: [PATCH] Sketcher: Clean code and adapt previous solution only to non-relative cases =========================================================================== Cleaning up ViewProviderSketch, as relative mode is never used for points. Adapting the recalculation of the initial solution only to non-relative cases. For relative movement cases (movePoint with relative=true) no cases where such a solution will be advantageous have been identified and applying a similar solution involves changing the current behaviour too much, as to run the risk of introducing further bugs. Decision to be revised if such cases where an advantage can be found are discovered. --- src/Mod/Sketcher/App/Sketch.cpp | 16 +++++++++------- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index 83ba3478a2..727abc3367 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -3199,13 +3199,15 @@ int Sketch::movePoint(int geoId, PointPos pos, Base::Vector3d toPoint, bool rela 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) { + 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; + } } } } diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 02af490f2c..d5055114ff 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -767,7 +767,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe try { Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.movePoint(%i,%i,App.Vector(%f,%f,0),%i)" ,getObject()->getNameInDocument() - ,GeoId, PosId, x-xInit, y-yInit, relative ? 1 : 0 + ,GeoId, PosId, x-xInit, y-yInit, 0 ); Gui::Command::commitCommand(); @@ -1136,9 +1136,9 @@ bool ViewProviderSketch::mouseMove(const SbVec2s &cursorPos, Gui::View3DInventor int GeoId; Sketcher::PointPos PosId; getSketchObject()->getGeoVertexIndex(edit->DragPoint, GeoId, PosId); - Base::Vector3d vec(x-xInit,y-yInit,0); + Base::Vector3d vec(x,y,0); if (GeoId != Sketcher::Constraint::GeoUndef && PosId != Sketcher::none) { - if (getSketchObject()->getSolvedSketch().movePoint(GeoId, PosId, vec, relative) == 0) { + 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));