From 200d9db0c2459d2de208f5933f5419a67ac45f3b Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Fri, 9 Nov 2018 14:51:20 +0100 Subject: [PATCH] Sketcher: Ellipse trimming with internal aligment geometry ========================================================== Trimming was not considering a case where an ellipse is trimmed with respect to its own internal aligment geometry. This resulted in Coincident Constraints with PointPos = Sketcher::none, which is invalid. --- src/Mod/Sketcher/App/SketchObject.cpp | 41 +++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index e8b42d8de7..46701fa4d9 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -2139,6 +2139,27 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) delete geoNew; rebuildVertexIndex(); + + auto handleinternalalignment = [this] (Constraint * constr, int GeoId, PointPos & secondPos) { + if( constr->Type == Sketcher::InternalAlignment && + ( constr->AlignmentType == Sketcher::EllipseMajorDiameter || + constr->AlignmentType == Sketcher::EllipseMinorDiameter ) ) { + + Base::Vector3d sp = getPoint(constr->First,start); + Base::Vector3d ep = getPoint(constr->First,end); + + Base::Vector3d ee = getPoint(GeoId,start); + + if( (ee-sp).Length() < (ee-ep).Length() ) { + secondPos = Sketcher::start; + } + else { + secondPos = Sketcher::end; + } + } + }; + + PointPos secondPos1 = Sketcher::none, secondPos2 = Sketcher::none; ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject; for (std::vector::const_iterator it=constraints.begin(); @@ -2146,12 +2167,28 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) Constraint *constr = *(it); if (secondPos1 == Sketcher::none && (constr->First == GeoId1 && constr->Second == GeoId)) { constrType1= Sketcher::Coincident; - secondPos1 = constr->FirstPos; + if(constr->FirstPos == Sketcher::none){ + handleinternalalignment(constr, GeoId, secondPos1); + } + else { + secondPos1 = constr->FirstPos; + } + } else if(secondPos2 == Sketcher::none && (constr->First == GeoId2 && constr->Second == GeoId)) { constrType2 = Sketcher::Coincident; - secondPos2 = constr->FirstPos; + + if(constr->FirstPos == Sketcher::none){ + handleinternalalignment(constr, GeoId, secondPos2); + } + else { + secondPos2 = constr->FirstPos; + } } } + + if( (constrType1 == Sketcher::Coincident && secondPos1 == Sketcher::none) || + (constrType2 == Sketcher::Coincident && secondPos2 == Sketcher::none)) + THROWM(ValueError,"Invalid position Sketcher::none when creating a Coincident constraint") // constrain the trimming points on the corresponding geometries Sketcher::Constraint *newConstr = new Sketcher::Constraint();