]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1716 split removes radius constraint
authornds <nds@opencascade.com>
Thu, 8 Sep 2016 03:58:52 +0000 (06:58 +0300)
committernds <nds@opencascade.com>
Thu, 8 Sep 2016 03:58:52 +0000 (06:58 +0300)
Split: splitCircle - Radius, Equal constraints should be moved to created base Arc.

src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp
src/SketchPlugin/SketchPlugin_ConstraintSplit.h

index 54edf285c6221d9270b2a60f7d398cee68d5b629..395ae31715335f41489bb6144aba5486e2af8416 100755 (executable)
@@ -94,7 +94,8 @@ void SketchPlugin_ConstraintSplit::execute()
   getConstraints(aFeaturesToDelete, aFeaturesToUpdate, aTangentFeatures, aCoincidenceToFeature);
 
   std::map<AttributePtr, std::list<AttributePtr> > aBaseRefAttributes;
-  getRefAttributes(aBaseFeature, aBaseRefAttributes);
+  std::list<AttributePtr> aRefsToFeature;
+  getRefAttributes(aBaseFeature, aBaseRefAttributes, aRefsToFeature);
 
   std::map<AttributePtr, AttributePtr> aBasePointModifiedAttributes;
 
@@ -165,6 +166,22 @@ void SketchPlugin_ConstraintSplit::execute()
     std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(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<AttributePtr>::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<FeaturePtr>& theFeatu
 }
 
 void SketchPlugin_ConstraintSplit::getRefAttributes(const FeaturePtr& theFeature,
-                                                    std::map<AttributePtr, std::list<AttributePtr> >& theRefs)
+                                                    std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
+                                                    std::list<AttributePtr>& theRefsToFeature)
 {
   theRefs.clear();
 
@@ -470,7 +491,10 @@ void SketchPlugin_ConstraintSplit::getRefAttributes(const FeaturePtr& theFeature
   for (; aPIt != aPLast; aPIt++)
     aPointAttributesSet.insert(*aPIt);
 
-  const std::set<AttributePtr>& aRefsAttributes = theFeature->data()->refsToMe();
+  std::set<AttributePtr> aRefsAttributes = getFeatureResult(theFeature)->data()->refsToMe();
+  std::set<AttributePtr> aFRefsList = theFeature->data()->refsToMe();
+  aRefsAttributes.insert(aFRefsList.begin(), aFRefsList.end());
+
   std::set<AttributePtr>::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<ModelAPI_AttributeRefAttr>(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<AttributePtr>& theRefsToFeature)
+{
+  std::list<AttributePtr>::const_iterator anIt = theRefsToFeature.begin(),
+                                          aLast = theRefsToFeature.end();
+  for (; anIt != aLast; anIt++) {
+    AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIt);
+    if (aRefAttr.get())
+      aRefAttr->setObject(theFeatureBaseResult);
+  }
+}
+
 void SketchPlugin_ConstraintSplit::updateRefAttConstraints(
                       const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
                       const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes)
index 1acbadd2b8751257412e7c78626df2663f4f4c69..eab2ae86f0336a1d75005f536fe1d9e0c08f1e1e 100755 (executable)
@@ -111,8 +111,15 @@ private:
               std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature/*,
               std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToPoint*/);
 
+  /// Obtains references to feature point attributes and to feature,
+  /// e.g. for feature line: 1st container is <1st line point, list<entity_a in distance, entity_b in parallel> >
+  ///                                         <2nd line point, list<> >
+  ///      for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
+  /// \param theFeature an investigated feature
+  /// \param theRefs a container of list of referenced attributes
   void getRefAttributes(const FeaturePtr& theFeature,
-                        std::map<AttributePtr, std::list<AttributePtr> >& theRefs);
+                        std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
+                        std::list<AttributePtr>& 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<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theTangentFeatures,
               const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& 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<ModelAPI_Result>& theFeatureBaseResult,
+                                   const std::list<AttributePtr>& 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