]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1763 Coincidence constraint lost after removing one of split lines
authornds <nds@opencascade.com>
Tue, 29 Nov 2016 05:30:13 +0000 (08:30 +0300)
committernds <nds@opencascade.com>
Tue, 29 Nov 2016 05:30:37 +0000 (08:30 +0300)
src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp
src/SketchPlugin/SketchPlugin_ConstraintSplit.h

index 9ff84a54232f270380c0109a62c09e52b7ae6111..0023cc47bac3d66610dcd808de9a9bf539c00a12 100755 (executable)
@@ -278,7 +278,7 @@ void SketchPlugin_ConstraintSplit::execute()
 
   // coincidence to feature
   updateCoincidenceConstraintsToFeature(aCoincidenceToFeature, aFurtherCoincidences,
-                                        aFeatureResults);
+                                        aFeatureResults, aSplitFeature);
   // tangency
   updateTangentConstraintsToFeature(aTangentFeatures, aFurtherCoincidences);
 
@@ -392,16 +392,11 @@ std::shared_ptr<GeomDataAPI_Point2D> SketchPlugin_ConstraintSplit::getPointOfRef
   return aPointAttribute;
 }
 
-void SketchPlugin_ConstraintSplit::getFeaturePoints(AttributePoint2DPtr& theStartPointAttr,
+void SketchPlugin_ConstraintSplit::getFeaturePoints(const FeaturePtr& theFeature,
+                                                    AttributePoint2DPtr& theStartPointAttr,
                                                     AttributePoint2DPtr& theEndPointAttr)
 {
-  AttributePoint2DPtr aPointAttribute;
-
-  AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
-                                           data()->attribute(SketchPlugin_Constraint::VALUE()));
-  FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
-
-  std::string aFeatureKind = aBaseFeature->getKind();
+  std::string aFeatureKind = theFeature->getKind();
   std::string aStartAttributeName, anEndAttributeName;
   if (aFeatureKind == SketchPlugin_Line::ID()) {
     aStartAttributeName = SketchPlugin_Line::START_ID();
@@ -413,9 +408,9 @@ void SketchPlugin_ConstraintSplit::getFeaturePoints(AttributePoint2DPtr& theStar
   }
   if (!aStartAttributeName.empty() && !anEndAttributeName.empty()) {
     theStartPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                                         aBaseFeature->attribute(aStartAttributeName));
+                                         theFeature->attribute(aStartAttributeName));
     theEndPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                                         aBaseFeature->attribute(anEndAttributeName));
+                                         theFeature->attribute(anEndAttributeName));
   }
 }
 
@@ -588,11 +583,21 @@ void SketchPlugin_ConstraintSplit::getRefAttributes(const FeaturePtr& theFeature
 void SketchPlugin_ConstraintSplit::updateCoincidenceConstraintsToFeature(
       const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
       const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
-      const std::set<ResultPtr>& theFeatureResults)
+      const std::set<ResultPtr>& theFeatureResults,
+      const FeaturePtr& theSplitFeature)
 {
   if (theCoincidenceToFeature.empty())
     return;
 
+  // we should build coincidence constraints to end of the split feature
+  std::set<std::shared_ptr<GeomDataAPI_Point2D> > aNewCoincidencesToSplitFeature;
+  AttributePoint2DPtr aStartPointAttr, anEndPointAttr;
+  getFeaturePoints(theSplitFeature, aStartPointAttr, anEndPointAttr);
+  if (theFurtherCoincidences.find(aStartPointAttr) == theFurtherCoincidences.end())
+    aNewCoincidencesToSplitFeature.insert(aStartPointAttr);
+  if (theFurtherCoincidences.find(anEndPointAttr) == theFurtherCoincidences.end())
+    aNewCoincidencesToSplitFeature.insert(anEndPointAttr);
+
   std::map<FeaturePtr, IdToPointPair>::const_iterator aCIt = theCoincidenceToFeature.begin(),
                                                             aCLast = theCoincidenceToFeature.end();
 #ifdef DEBUG_SPLIT
@@ -615,6 +620,19 @@ void SketchPlugin_ConstraintSplit::updateCoincidenceConstraintsToFeature(
     if (aFeaturePointAttribute.get()) {
       aCoincFeature->refattr(anAttributeId)->setObject(ResultPtr());
       aCoincFeature->refattr(anAttributeId)->setAttr(aFeaturePointAttribute);
+      // create new coincidences to split feature points
+      std::set<AttributePoint2DPtr>::const_iterator aSFIt = aNewCoincidencesToSplitFeature.begin(),
+                                                    aSFLast = aNewCoincidencesToSplitFeature.end();
+      for (; aSFIt != aSFLast; aSFIt++) {
+        AttributePoint2DPtr aSFAttribute = *aSFIt;
+        if (aCoincPnt->isEqual(aSFAttribute->pnt())) {
+          std::string aSecondAttribute = SketchPlugin_Constraint::ENTITY_A();
+          if (anAttributeId == SketchPlugin_Constraint::ENTITY_A())
+            aSecondAttribute = SketchPlugin_Constraint::ENTITY_B();
+          createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+                           aSFAttribute, aCoincFeature->refattr(aSecondAttribute)->attr());
+        }
+      }
     }
     else {
       /// find feature by shape intersected the point
@@ -751,7 +769,8 @@ void SketchPlugin_ConstraintSplit::splitLine(FeaturePtr& theSplitFeature,
   AttributePoint2DPtr aSecondPointAttrOfSplit =
     getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
   AttributePoint2DPtr aStartPointAttrOfBase, anEndPointAttrOfBase;
-  getFeaturePoints(aStartPointAttrOfBase, anEndPointAttrOfBase);
+
+  getFeaturePoints(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
   if (!aStartPointAttrOfBase.get() && !anEndPointAttrOfBase.get()) {
     setError("Error: Feature has no start and end points.");
     return;
@@ -884,7 +903,7 @@ void SketchPlugin_ConstraintSplit::splitArc(FeaturePtr& theSplitFeature,
   AttributePoint2DPtr aSecondPointAttrOfSplit =
     getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
   AttributePoint2DPtr aStartPointAttrOfBase, anEndPointAttrOfBase;
-  getFeaturePoints(aStartPointAttrOfBase, anEndPointAttrOfBase);
+  getFeaturePoints(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
   if (!aStartPointAttrOfBase.get() && !anEndPointAttrOfBase.get()) {
     setError("Error: Feature has no start and end points.");
     return;
index 95cb9a9327353fe571958a0627da18e77e48b69a..b6c13e3e1b03fab300d7f6a93cef84df0c85d039 100755 (executable)
@@ -91,9 +91,11 @@ class SketchPlugin_ConstraintSplit : public SketchPlugin_ConstraintBase
 private:
   /// Returns geom point attribute of the feature bounds. It processes line or arc.
   /// For circle feature, the result attributes are null
+  /// \param theFeature a source feature
   /// \param theStartPointAttr an out attribute to start point
   /// \param theStartPointAttr an out attribute to end point
-  void getFeaturePoints(std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
+  void getFeaturePoints(const FeaturePtr& theFeature,
+                        std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
                         std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
 
   /// Returns cast of attribute to geometrical point if the attribute is a ref attr attribute
@@ -128,11 +130,14 @@ private:
   /// Move coincidence constraint from feature to point if it is found
   /// \param theCoincidenceToFeature coincidence to feature to be connected to new feature
   /// \param theFurtherCoincidences a list of points where coincidences will be build
-  /// \paramv theFeatureResults created results after split where constaint might be connected
+  /// \param theFeatureResults created results after split where constaint might be connected
+  /// \param theSplitFeature feature created by split, new coincidences to points should be created
+  /// if theCoincidenceToFeature contains equal points
   void updateCoincidenceConstraintsToFeature(
       const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
       const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
-      const std::set<ResultPtr>& theFeatureResults);
+      const std::set<ResultPtr>& theFeatureResults,
+      const FeaturePtr& theSplitFeature);
 
   /// Move tangency constraint to the nearest split feature that has a coincidence to the tangent
   /// \param theTangentFeatures tangencies to feature to be connected to nearest feature