From 1341a9a41f9e3320b52b40519d12c7b515e37a31 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 21 Jan 2016 15:31:29 +0300 Subject: [PATCH] Constraint attributes may be changed (issue #1200) --- .../Test/TestConstraintDistance.py | 8 +++ src/SketchSolver/SketchSolver_Constraint.cpp | 50 +++++++++++++++++-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/SketchPlugin/Test/TestConstraintDistance.py b/src/SketchPlugin/Test/TestConstraintDistance.py index e9703fa63..3adefded1 100644 --- a/src/SketchPlugin/Test/TestConstraintDistance.py +++ b/src/SketchPlugin/Test/TestConstraintDistance.py @@ -165,5 +165,13 @@ aDistance.setValue(PT_LINE_DIST) aSession.finishOperation() assert (distancePointLine(aSketchPointCoords, aSketchLine) == PT_LINE_DIST) #========================================================================= +# Set distance between line boundaries +#========================================================================= +aSession.startOperation() +refattrA.setAttr(aLineAStartPoint) +refattrB.setAttr(aLineAEndPoint) +aSession.finishOperation() +assert (distancePointPoint(aLineAStartPoint, aLineAEndPoint) != PT_LINE_DIST) +#========================================================================= # End of test #========================================================================= diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 7dbde50c7..ef10bf57e 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -115,13 +115,57 @@ void SketchSolver_Constraint::process() void SketchSolver_Constraint::update() { cleanErrorMsg(); - std::list aWrapper = myStorage->constraint(myBaseConstraint); + std::list::iterator aWIt = aWrapper.begin(); + + // Check if attributes of constraint are changed, rebuild constraint + std::set anAttributes; + std::set::iterator aFoundAttr; + std::set aFeatures; + std::set::iterator aFoundFeat; + for (int anEntIndex = 0; anEntIndex < 4; ++anEntIndex) { + AttributePtr anAttr = + myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(anEntIndex)); + if (!anAttr) + continue; + + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(anAttr); + if (aRefAttr) { + if (aRefAttr->isObject()) { + FeaturePtr aFeat = ModelAPI_Feature::feature(aRefAttr->object()); + aFeatures.insert(aFeat); + } else + anAttributes.insert(aRefAttr->attr()); + } else + anAttributes.insert(anAttr); + } + bool hasNewAttr = !(anAttributes.empty() && aFeatures.empty()); + for (; hasNewAttr && aWIt != aWrapper.end(); ++ aWIt) { + const std::list& aSubs = (*aWIt)->entities(); + std::list::const_iterator aSIt = aSubs.begin(); + for (; hasNewAttr && aSIt != aSubs.end(); ++aSIt) { + if ((*aSIt)->baseAttribute()) { + aFoundAttr = anAttributes.find((*aSIt)->baseAttribute()); + if (aFoundAttr != anAttributes.end()) + anAttributes.erase(aFoundAttr); + } else { + aFoundFeat = aFeatures.find((*aSIt)->baseFeature()); + if (aFoundFeat != aFeatures.end()) + aFeatures.erase(aFoundFeat); + } + hasNewAttr = !(anAttributes.empty() && aFeatures.empty()); + } + } + if (hasNewAttr) { + remove(); + process(); + return; + } + AttributeDoublePtr aValueAttr = std::dynamic_pointer_cast( myBaseConstraint->attribute(SketchPlugin_Constraint::VALUE())); if (aValueAttr) { - std::list::iterator aWIt = aWrapper.begin(); - for (; aWIt != aWrapper.end(); ++aWIt) + for (aWIt = aWrapper.begin(); aWIt != aWrapper.end(); ++aWIt) if (fabs((*aWIt)->value() - aValueAttr->value()) > tolerance) { (*aWIt)->setValue(aValueAttr->value()); myStorage->setNeedToResolve(true); -- 2.39.2