From 5089a57d658a105c6b90da6d256c95601542f2ed Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 21 Apr 2017 18:12:39 +0300 Subject: [PATCH] Fix the frequently appeared "conflicting constraints" message when the point is coincident with the feature and its extremity. --- .../SketchSolver_ConstraintCoincidence.cpp | 40 +++++++++++++++++++ .../SketchSolver_ConstraintCoincidence.h | 1 + 2 files changed, 41 insertions(+) diff --git a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp index a2c3357b6..88de9a68c 100644 --- a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp @@ -5,6 +5,33 @@ #include #include +#include +#include + +static void getCoincidentFeatureExtremities(const ConstraintPtr& theConstraint, + const StoragePtr& theStorage, + EntityWrapperPtr theExtremities[2]) +{ + for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) { + AttributeRefAttrPtr aRefAttr = theConstraint->refattr(SketchPlugin_Constraint::ATTRIBUTE(i)); + if (!aRefAttr || !aRefAttr->isObject()) + continue; + + FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object()); + if (!aFeature) + continue; + + if (aFeature->getKind() == SketchPlugin_Line::ID()) { + theExtremities[0] = theStorage->entity(aFeature->attribute(SketchPlugin_Line::START_ID())); + theExtremities[1] = theStorage->entity(aFeature->attribute(SketchPlugin_Line::END_ID())); + } else if (aFeature->getKind() == SketchPlugin_Arc::ID()) { + theExtremities[0] = theStorage->entity(aFeature->attribute(SketchPlugin_Arc::START_ID())); + theExtremities[1] = theStorage->entity(aFeature->attribute(SketchPlugin_Arc::END_ID())); + } + } +} + + void SketchSolver_ConstraintCoincidence::process() { cleanErrorMsg(); @@ -58,6 +85,9 @@ void SketchSolver_ConstraintCoincidence::getAttributes( myType = CONSTRAINT_PT_ON_CIRCLE; else myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE(); + + // obtain extremity points of the coincident feature for further checking of multi-coincidence + getCoincidentFeatureExtremities(myBaseConstraint, myStorage, myFeatureExtremities); } else myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE(); } @@ -68,6 +98,16 @@ void SketchSolver_ConstraintCoincidence::notify(const FeaturePtr& theFeatur PlaneGCSSolver_UpdateCoincidence* anUpdater = static_cast(theUpdater); bool isAccepted = anUpdater->checkCoincidence(myAttributes.front(), myAttributes.back()); + + // additionally check the point is coincident to extremity of coincident feature + if (myFeatureExtremities[0] && myFeatureExtremities[1]) { + EntityWrapperPtr aPoint = + myAttributes.front()->type() == ENTITY_POINT ? myAttributes.front() : myAttributes.back(); + + for (int i = 0; i < 2; ++i) + isAccepted = isAccepted && !anUpdater->isPointOnEntity(aPoint, myFeatureExtremities[i]); + } + if (isAccepted) { if (!myInSolver) { myInSolver = true; diff --git a/src/SketchSolver/SketchSolver_ConstraintCoincidence.h b/src/SketchSolver/SketchSolver_ConstraintCoincidence.h index 83ec15b40..0a3ea83e8 100644 --- a/src/SketchSolver/SketchSolver_ConstraintCoincidence.h +++ b/src/SketchSolver/SketchSolver_ConstraintCoincidence.h @@ -41,6 +41,7 @@ protected: protected: bool myInSolver; ///< shows the constraint is added to the solver + EntityWrapperPtr myFeatureExtremities[2]; ///< extremities of a feature, a point is coincident to }; #endif -- 2.39.2