From cfbf42387151400387b1783bcf6589ae87118217 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 6 Sep 2016 12:01:09 +0300 Subject: [PATCH] Fix incorrect coincidence with center of external arc (issue #1685) --- src/SketchSolver/SketchSolver_Storage.cpp | 42 ++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index 88f56124e..c85b10a4a 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -25,6 +25,10 @@ static bool isEqual(const std::list& theCVec1, const std::list& theCVec2); +/// \brief Convert result to feature or attribute +static void resultToFeatureOrAttribute(const ObjectPtr& theResult, + FeaturePtr& theFeature, AttributePtr& theAttribute); + void SketchSolver_Storage::addConstraint(ConstraintPtr theConstraint, ConstraintWrapperPtr theSolverConstraint) @@ -88,6 +92,8 @@ void SketchSolver_Storage::addConstraint( static std::list pointAttributes(FeaturePtr theFeature) { std::list aPoints; + if (!theFeature->data() || !theFeature->data()->isValid()) + return aPoints; if (theFeature->getKind() == SketchPlugin_Arc::ID()) { aPoints.push_back(theFeature->attribute(SketchPlugin_Arc::CENTER_ID())); aPoints.push_back(theFeature->attribute(SketchPlugin_Arc::START_ID())); @@ -231,8 +237,10 @@ bool SketchSolver_Storage::update(AttributePtr theAttribute, const GroupID& theG AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(anAttribute); if (aRefAttr) { if (aRefAttr->isObject()) { - FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object()); - return update(aFeature, theGroup, theForce); + FeaturePtr aFeature; + resultToFeatureOrAttribute(aRefAttr->object(), aFeature, anAttribute); + if (aFeature) + return update(aFeature, theGroup, theForce); } else { anAttribute = aRefAttr->attr(); if (!anAttribute->isInitialized()) @@ -311,8 +319,13 @@ const EntityWrapperPtr& SketchSolver_Storage::entity(const AttributePtr& theAttr std::dynamic_pointer_cast(theAttribute); if (aRefAttr) { if (aRefAttr->isObject()) { - FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object()); - return entity(aFeature); + FeaturePtr aFeature; + AttributePtr anAttribute; + resultToFeatureOrAttribute(aRefAttr->object(), aFeature, anAttribute); + if (aFeature) + return entity(aFeature); + else + return entity(anAttribute); } else return entity(aRefAttr->attr()); } @@ -961,3 +974,24 @@ bool isEqual(const std::list& theCVec1, } return true; } + +void resultToFeatureOrAttribute(const ObjectPtr& theResult, + FeaturePtr& theFeature, AttributePtr& theAttribute) +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(theResult); + // if the feature has several results, we choose which one is referred + const std::list& aResults = aFeature->results(); + if (aResults.size() > 1 && theResult != aFeature->lastResult()) { + // actually, the attribute refers to center of arc or circle, but not the edge, get correct attributes + std::string anAttrName; + if (aFeature->getKind() == SketchPlugin_Arc::ID()) + anAttrName = SketchPlugin_Arc::CENTER_ID(); + else if (aFeature->getKind() == SketchPlugin_Circle::ID()) + anAttrName = SketchPlugin_Circle::CENTER_ID(); + if (!anAttrName.empty()) { + theAttribute = aFeature->attribute(anAttrName); + aFeature = FeaturePtr(); + } + } + theFeature = aFeature; +} -- 2.39.2