From ee2d32474429582645370b33d6d37e8470f686fa Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Wed, 5 Jun 2024 02:58:39 +0530 Subject: [PATCH] [Sketcher] Fix some issues with trimming splines 1. Transfer point-on-object to the correct resulting curve: Currently the constraint remains on the "start" curve created after the trim. 2. Expose internal geometries of both resulting B-splines. --- src/Mod/Sketcher/App/SketchObject.cpp | 46 ++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 34f7bdaea9..e4f4cc526a 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -2992,6 +2992,46 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) delConstraints(delete_list, false); }; + // Pick the appropriate portion which should inherit the point-on-object constraint + // Assume that GeoId1 is the pre-existing curve + auto chooseCurveForPointOnObject = [this](int GeoId1, + double curve1Start, + double curve1End, + int GeoId2, + double curve2Start, + double curve2End) { + const Part::GeomCurve* curve = static_cast(this->getGeometry(GeoId1)); + const std::vector& constraints = this->Constraints.getValues(); + std::vector newConstraints(constraints); + int constrId = 0; + std::vector delete_list; + bool changed = false; + for (const auto* constr : constraints) { + // There is a preexisting PointOnObject constraint, see where it belongs + if (constr->Type == Sketcher::PointOnObject && constr->Second == GeoId1) { + Base::Vector3d pp = getPoint(constr->First, constr->FirstPos); + double u; + curve->closestParameter(pp, u); + if ((curve2Start <= u) && (u <= curve2End)) { + std::unique_ptr constrNew(newConstraints[constrId]->clone()); + constrNew->Second = GeoId2; + Constraint* constrPtr = constrNew.release(); + newConstraints[constrId] = constrPtr; + changed = true; + } + else if (!((curve1Start <= u) && (u <= curve1End))) { + // TODO: Not on any of the curves. Delete? + } + + } + ++constrId; + } + + if (changed) { + this->Constraints.setValues(std::move(newConstraints)); + } + }; + // makes an equality constraint between GeoId1 and GeoId2 auto constrainAsEqual = [this](int GeoId1, int GeoId2) { auto newConstr = std::make_unique(); @@ -3274,6 +3314,8 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) newVals.push_back(newVals[GeoId]->clone()); int newGeoId = newVals.size() - 1; + chooseCurveForPointOnObject(GeoId, firstParam, point1Param, newGeoId, point2Param, lastParam); + if (isDerivedFromTrimmedCurve) { static_cast(newVals[GeoId]) ->setRange(firstParam, point1Param); @@ -3328,8 +3370,10 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) Sketcher::PointPos::mid); } - if (isNonPeriodicBSpline) + if (isNonPeriodicBSpline) { exposeInternalGeometry(GeoId); + exposeInternalGeometry(newGeoId); + } // if we do not have a recompute, the sketch must be solved to update the DoF of the // solver