From 4db7da73140e96b4bbd5228bbd58bb07cb874f16 Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Tue, 28 Jun 2022 23:58:08 +0530 Subject: [PATCH] [Sketcher] Only move one piece of B-spline when dragging --- src/Mod/Sketcher/App/Sketch.cpp | 60 +++++++++++++++++++++ src/Mod/Sketcher/App/Sketch.h | 9 ++++ src/Mod/Sketcher/App/SketchObject.h | 13 +++++ src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 9 +++- 4 files changed, 89 insertions(+), 2 deletions(-) diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index 7e548ec499..4bbeb41f7d 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -4021,6 +4021,66 @@ void Sketch::resetInitMove() isInitMove = false; } +int Sketch::initBSplinePieceMove(int geoId, PointPos pos, const Base::Vector3d& firstPoint, bool fine) +{ + isFine = fine; + + geoId = checkGeoId(geoId); + + clearTemporaryConstraints(); + + // don't try to move sketches that contain conflicting constraints + if (hasConflicts()) { + isInitMove = false; + return -1; + } + + // this is only meant for B-Splines + if (Geoms[geoId].type != BSpline || pos == PointPos::start || pos == PointPos::end) { + return -1; + } + + // Find the closest knot + auto partBsp = static_cast(Geoms[geoId].geo); + double uNear; + partBsp->closestParameter(firstPoint, uNear); + GCS::BSpline &bsp = BSplines[Geoms[geoId].index]; + auto& knots = bsp.knots; + auto upperknot = std::upper_bound( + knots.begin(), knots.end(), uNear, + [](double u, double* element) { + return u < *element; + }); + + size_t idx = 0; + // skipping the first knot for adjustment + // TODO: ensure this works for periodic as well + for (size_t i=1; iinitTemporaryMove(drag.DragCurve, Sketcher::PointPos::none, false); - + if (geo->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { + getSketchObject()->initTemporaryBSplinePieceMove( + drag.DragCurve, Sketcher::PointPos::none, + Base::Vector3d(drag.xInit, drag.yInit, 0.0), false); + } else { + getSketchObject()->initTemporaryMove(drag.DragCurve, Sketcher::PointPos::none, false); + } } else { Mode = STATUS_NONE; }