From b0b63ffc080562afecb4c26299e07c82b4eeff76 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 8 Sep 2016 06:58:52 +0300 Subject: [PATCH] Issue #1716 split removes radius constraint Split: splitCircle - Radius, Equal constraints should be moved to created base Arc. --- .../SketchPlugin_ConstraintSplit.cpp | 49 +++++++++++++++++-- .../SketchPlugin_ConstraintSplit.h | 16 +++++- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp index 54edf285c..395ae3171 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp @@ -94,7 +94,8 @@ void SketchPlugin_ConstraintSplit::execute() getConstraints(aFeaturesToDelete, aFeaturesToUpdate, aTangentFeatures, aCoincidenceToFeature); std::map > aBaseRefAttributes; - getRefAttributes(aBaseFeature, aBaseRefAttributes); + std::list aRefsToFeature; + getRefAttributes(aBaseFeature, aBaseRefAttributes, aRefsToFeature); std::map aBasePointModifiedAttributes; @@ -165,6 +166,22 @@ void SketchPlugin_ConstraintSplit::execute() std::shared_ptr aPointAttr = std::dynamic_pointer_cast(aBaseAttr); std::cout << aPointAttr->id().c_str() << ": " << "[" << aRefAttributes.size() << "] " << aRefsInfo << std::endl; } + std::cout << std::endl; + std::cout << std::endl << "References to base feature [" << aRefsToFeature.size() << "]" << std::endl; + std::list::const_iterator aRefAttrIt = aRefsToFeature.begin(), + aRefAttrLast = aRefsToFeature.end(); + std::string aRefsInfo; + for (; aRefAttrIt != aRefAttrLast; aRefAttrIt++) { + if (!aRefsInfo.empty()) + aRefsInfo.append(","); + AttributePtr aRAttr = *aRefAttrIt; + aRefsInfo.append(aRAttr->id()); + FeaturePtr aRFeature = ModelAPI_Feature::feature(aRAttr->owner()); + aRefsInfo.append("(" + aRFeature->name() + ") "); + } + std::cout << "[" << aRefsToFeature.size() << "] " << aRefsInfo << std::endl; + + std::cout << std::endl; std::cout << "---- SPLIT ----" << std::endl; std::cout << std::endl; @@ -185,8 +202,11 @@ void SketchPlugin_ConstraintSplit::execute() FeaturePtr aCircleFeature = aBaseFeature; splitCircle(aSplitFeature, aBaseFeature, anAfterFeature, aFurtherCoincidences, aCreatedFeatures, aModifiedAttributes); + + updateRefFeatureConstraints(getFeatureResult(aBaseFeature), aRefsToFeature); + aFeaturesToDelete.insert(aCircleFeature); - aBaseObjectAttr->setObject(ResultPtr()); // as circle is removed, temporary fill this attribute + aBaseObjectAttr->setObject(ResultPtr()); // as circle is removed, temporary fill this attribute*/ } #ifdef DEBUG_SPLIT @@ -459,7 +479,8 @@ void SketchPlugin_ConstraintSplit::getConstraints(std::set& theFeatu } void SketchPlugin_ConstraintSplit::getRefAttributes(const FeaturePtr& theFeature, - std::map >& theRefs) + std::map >& theRefs, + std::list& theRefsToFeature) { theRefs.clear(); @@ -470,7 +491,10 @@ void SketchPlugin_ConstraintSplit::getRefAttributes(const FeaturePtr& theFeature for (; aPIt != aPLast; aPIt++) aPointAttributesSet.insert(*aPIt); - const std::set& aRefsAttributes = theFeature->data()->refsToMe(); + std::set aRefsAttributes = getFeatureResult(theFeature)->data()->refsToMe(); + std::set aFRefsList = theFeature->data()->refsToMe(); + aRefsAttributes.insert(aFRefsList.begin(), aFRefsList.end()); + std::set::const_iterator aIt; for (aIt = aRefsAttributes.cbegin(); aIt != aRefsAttributes.cend(); ++aIt) { AttributePtr anAttr = (*aIt); @@ -478,7 +502,7 @@ void SketchPlugin_ConstraintSplit::getRefAttributes(const FeaturePtr& theFeature if (anAttrFeature.get() != this && anAttr.get() && anAttr->attributeType() == ModelAPI_AttributeRefAttr::typeId()) { AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(anAttr); - if (!aRefAttr->isObject()) { + if (!aRefAttr->isObject()) { /// find attributes referenced to feature point attributes AttributePtr anAttrInRef = aRefAttr->attr(); if (anAttrInRef.get() && aPointAttributesSet.find(anAttrInRef) != aPointAttributesSet.end()) { if (theRefs.find(anAttrInRef) != theRefs.end()) @@ -490,6 +514,9 @@ void SketchPlugin_ConstraintSplit::getRefAttributes(const FeaturePtr& theFeature } } } + else { /// find attributes referenced to feature itself + theRefsToFeature.push_back(anAttr); + } } } } @@ -585,6 +612,18 @@ void SketchPlugin_ConstraintSplit::updateTangentConstraintsToFeature( } } +void SketchPlugin_ConstraintSplit::updateRefFeatureConstraints(const ResultPtr& theFeatureBaseResult, + const std::list& theRefsToFeature) +{ + std::list::const_iterator anIt = theRefsToFeature.begin(), + aLast = theRefsToFeature.end(); + for (; anIt != aLast; anIt++) { + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(*anIt); + if (aRefAttr.get()) + aRefAttr->setObject(theFeatureBaseResult); + } +} + void SketchPlugin_ConstraintSplit::updateRefAttConstraints( const std::map >& theBaseRefAttributes, const std::set >& theModifiedAttributes) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.h b/src/SketchPlugin/SketchPlugin_ConstraintSplit.h index 1acbadd2b..eab2ae86f 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.h @@ -111,8 +111,15 @@ private: std::map, IdToPointPair>& theCoincidenceToFeature/*, std::map, IdToPointPair>& theCoincidenceToPoint*/); + /// Obtains references to feature point attributes and to feature, + /// e.g. for feature line: 1st container is <1st line point, list > + /// <2nd line point, list<> > + /// for feature circle 2nd container is + /// \param theFeature an investigated feature + /// \param theRefs a container of list of referenced attributes void getRefAttributes(const FeaturePtr& theFeature, - std::map >& theRefs); + std::map >& theRefs, + std::list& theRefsToFeature); /// Move coincidence constraint from feature to point if it is found /// \param theCoincidenceToFeature coincidence to feature to be connected to new feature @@ -130,6 +137,13 @@ private: const std::map, IdToPointPair>& theTangentFeatures, const std::set >& theFurtherCoincidences); + + /// Move constraints from base feature to given feature + /// \param theFeature a base feature + /// \param theRefsToFeature list of attributes referenced to base feature + void updateRefFeatureConstraints(const std::shared_ptr& theFeatureBaseResult, + const std::list& theRefsToFeature); + /// Move constraints from attribute of base feature to attribute after modification /// \param theBaseRefAttributes container of references to the attributes of base feature /// \param theModifiedAttributes container of attributes placed instead of base attributes -- 2.39.2