From 2d16a964beb97df4af8f734a28accf44bbf6abd4 Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 29 Mar 2017 11:01:30 +0300 Subject: [PATCH] Checking that collinearity constraint is already in the solver --- .../SketchSolver_ConstraintCollinear.cpp | 13 +++++++++++-- src/SketchSolver/SketchSolver_ConstraintCollinear.h | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/SketchSolver/SketchSolver_ConstraintCollinear.cpp b/src/SketchSolver/SketchSolver_ConstraintCollinear.cpp index 32ec0721d..555b77e5b 100644 --- a/src/SketchSolver/SketchSolver_ConstraintCollinear.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintCollinear.cpp @@ -115,7 +115,16 @@ void SketchSolver_ConstraintCollinear::notify(const FeaturePtr& theFeature, isNew = true; if (isNew) { mySolverConstraint = createPointsOnLine(aPoints[0], aPoints[1], aLine); - myStorage->removeConstraint(myBaseConstraint); - myStorage->addConstraint(myBaseConstraint, mySolverConstraint); + if (myInSolver) { + myStorage->removeConstraint(myBaseConstraint); + myInSolver = false; + } + if (mySolverConstraint) { + myStorage->addConstraint(myBaseConstraint, mySolverConstraint); + myInSolver = true; + } + + for (int i = 0; i < 4; ++i) + myIsConstraintApplied[i] = aConstraintToApply[i]; } } diff --git a/src/SketchSolver/SketchSolver_ConstraintCollinear.h b/src/SketchSolver/SketchSolver_ConstraintCollinear.h index a70cc80ac..abceb5431 100644 --- a/src/SketchSolver/SketchSolver_ConstraintCollinear.h +++ b/src/SketchSolver/SketchSolver_ConstraintCollinear.h @@ -18,7 +18,8 @@ class SketchSolver_ConstraintCollinear : public SketchSolver_Constraint public: /// Constructor based on SketchPlugin constraint SketchSolver_ConstraintCollinear(ConstraintPtr theConstraint) - : SketchSolver_Constraint(theConstraint) + : SketchSolver_Constraint(theConstraint), + myInSolver(false) { for (int i = 0; i < 4; ++i) myIsConstraintApplied[i] = false; @@ -35,6 +36,7 @@ protected: private: EntityWrapperPtr myPoints[4]; ///< extremities on collinear lines bool myIsConstraintApplied[4]; ///< set \c true if point on opposite line + bool myInSolver; ///< the constraint is added to the solver }; #endif -- 2.39.2