Salome HOME
Issue #1664 In the Sketcher, add the function Split a segment - correction of constra...
authornds <nds@opencascade.com>
Wed, 31 Aug 2016 09:32:55 +0000 (12:32 +0300)
committernds <nds@opencascade.com>
Wed, 31 Aug 2016 09:33:17 +0000 (12:33 +0300)
src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp
src/SketchPlugin/SketchPlugin_ConstraintSplit.h
src/SketchPlugin/Test/TestSplit.py

index 8bbdb36e823b744379e2356c286837a72e78caed..2647f986b6bfc08789e697c636c7784776a704b2 100755 (executable)
@@ -35,7 +35,7 @@
 #include <ModelGeomAlgo_Point2D.h>
 #include <Events_Loop.h>
 
-//#define DEBUG_SPLIT
+#define DEBUG_SPLIT
 #ifdef DEBUG_SPLIT
 #include <iostream>
 #endif
@@ -87,6 +87,11 @@ void SketchPlugin_ConstraintSplit::execute()
   std::map<FeaturePtr, IdToPointPair> aCoincidenceToPoint;
   getConstraints(aFeaturesToDelete, aTangentFeatures, aCoincidenceToFeature, aCoincidenceToPoint);
 
+  std::map<AttributePtr, std::list<AttributePtr> > aBaseRefAttributes;
+  getRefAttributes(aBaseFeature, aBaseRefAttributes);
+
+  std::map<AttributePtr, AttributePtr> aBasePointModifiedAttributes;
+
 #ifdef DEBUG_SPLIT
   std::cout << std::endl;
   std::cout << "SketchPlugin_ConstraintSplit::execute()" << std::endl;
@@ -149,6 +154,27 @@ void SketchPlugin_ConstraintSplit::execute()
       std::cout <<     " -Point attribute:" << ModelGeomAlgo_Point2D::getPointAttributeInfo(aPointAttr) << std::endl;
     }
   }
+  std::map<AttributePtr, std::list<AttributePtr> >::const_iterator aRefIt = aBaseRefAttributes.begin(),
+                                                                   aRefLast = aBaseRefAttributes.end();
+  std::cout << "References to bound point of feature [" << aBaseRefAttributes.size() << "]" <<std::endl;
+  for (; aRefIt != aRefLast; aRefIt++) {
+    AttributePtr aBaseAttr = aRefIt->first;
+    std::list<AttributePtr> aRefAttributes = aRefIt->second;
+    std::string aRefsInfo;
+    std::list<AttributePtr>::const_iterator aRefAttrIt = aRefAttributes.begin(),
+                                            aRefAttrLast = aRefAttributes.end();
+    for (; aRefAttrIt != aRefAttrLast; aRefAttrIt++) {
+      AttributePtr aRAttr = *aRefAttrIt;
+      aRefsInfo.append(aRAttr->id());
+      FeaturePtr aRFeature = ModelAPI_Feature::feature(aRAttr->owner());
+      aRefsInfo.append("(" + aRFeature->name() + ") ");
+    }
+
+    std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aBaseAttr);
+    std::cout <<     " -Point attribute:" << aPointAttr->id().c_str()
+              << "[" << aRefAttributes.size() << "]" << aRefsInfo << std::endl;
+  }
+
   std::cout << std::endl;
   std::cout << "---- SPLIT ----" << std::endl;
   std::cout << std::endl;
@@ -392,6 +418,42 @@ void SketchPlugin_ConstraintSplit::getConstraints(std::set<FeaturePtr>& theFeatu
   }
 }
 
+void SketchPlugin_ConstraintSplit::getRefAttributes(const FeaturePtr& theFeature,
+                                                    std::map<AttributePtr, std::list<AttributePtr> >& theRefs)
+{
+  theRefs.clear();
+
+  std::list<AttributePtr> aPointAttributes = theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+  std::set<AttributePtr> aPointAttributesSet;
+
+  std::list<AttributePtr>::const_iterator aPIt = aPointAttributes.begin(), aPLast = aPointAttributes.end();
+  for (; aPIt != aPLast; aPIt++)
+    aPointAttributesSet.insert(*aPIt);
+
+  const std::set<AttributePtr>& aRefsAttributes = theFeature->data()->refsToMe();
+  std::set<AttributePtr>::const_iterator aIt;
+  for (aIt = aRefsAttributes.cbegin(); aIt != aRefsAttributes.cend(); ++aIt) {
+    AttributePtr anAttr = (*aIt);
+    FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttr->owner());
+    if (anAttrFeature.get() != this &&
+        anAttr.get() && anAttr->attributeType() == ModelAPI_AttributeRefAttr::typeId()) {
+      AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
+      if (!aRefAttr->isObject()) {
+        AttributePtr anAttrInRef = aRefAttr->attr();
+        if (anAttrInRef.get() && aPointAttributesSet.find(anAttrInRef) != aPointAttributesSet.end()) {
+          if (theRefs.find(anAttrInRef) != theRefs.end())
+            theRefs[anAttrInRef].push_back(aRefAttr);
+          else {
+            std::list<AttributePtr> anAttrList;
+            anAttrList.push_back(aRefAttr);
+            theRefs[anAttrInRef] = anAttrList;
+          }
+        }
+      }
+    }
+  }
+}
+
 void SketchPlugin_ConstraintSplit::updateCoincidenceConstraintsToFeature(
       const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
       const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
index 4c1e2bfeafbda53d684c41b3c9892177a7201ba6..bd602854c6100c6b7bdddcbddaba84f51ffb03ad 100755 (executable)
@@ -109,6 +109,9 @@ private:
               std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
               std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToPoint);
 
+  void getRefAttributes(const FeaturePtr& theFeature,
+                        std::map<AttributePtr, std::list<AttributePtr> >& theRefs);
+
   /// 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
index 08e10b53467bd4efd5044e1ba09eec5976199d1b..aa140610cb2db15244e8d10d5a92fe29fb555519 100644 (file)
@@ -75,6 +75,54 @@ assert(idList.count(SketchConstraintCoincidenceId) == 2)
 assert(idList.count(SketchConstraintTangentId) == 1)
 # Test end
 
+# Test split on arc with one point
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchArc_1 = Sketch_1.addArc(50, 50, 0, 50, 100, 50, True)
+Sketch_1.setFixed(SketchArc_1.startPoint())
+Sketch_1.setFixed(SketchArc_1.endPoint())
+Sketch_1.setRadius(SketchArc_1, 50)
+SketchPoint_1 = Sketch_1.addPoint(50, 100)
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchArc_1.result()[0])
+Sketch_1.addSplit(SketchArc_1, SketchPoint_1.coordinates(), SketchArc_1.endPoint())
+model.do()
+
+Sketch_1_feature = featureToCompositeFeature(Sketch_1.feature())
+idList = []
+for index in range(Sketch_1_feature.numberOfSubs()):
+  idList.append(Sketch_1_feature.subFeature(index).getKind())
+
+assert(idList.count(SketchArcId) == 2)
+assert(idList.count(SketchPointId) == 1)
+assert(idList.count(SketchConstraintCoincidenceId) == 2)
+assert(idList.count(SketchConstraintEqualId) == 1)
+assert(idList.count(SketchConstraintTangentId) == 1)
+# Test end
+
+# Test split on arc with two points
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchArc_1 = Sketch_1.addArc(50, 50, 0, 50, 100, 50, True)
+Sketch_1.setFixed(SketchArc_1.startPoint())
+Sketch_1.setFixed(SketchArc_1.endPoint())
+Sketch_1.setRadius(SketchArc_1, 50)
+SketchPoint_1 = Sketch_1.addPoint(25, 93.301270189222)
+SketchPoint_2 = Sketch_1.addPoint(75, 93.301270189222)
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchArc_1.result()[0])
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_2.coordinates(), SketchArc_1.result()[0])
+Sketch_1.addSplit(SketchArc_1, SketchPoint_1.coordinates(), SketchPoint_2.coordinates())
+model.do()
+
+Sketch_1_feature = featureToCompositeFeature(Sketch_1.feature())
+idList = []
+for index in range(Sketch_1_feature.numberOfSubs()):
+  idList.append(Sketch_1_feature.subFeature(index).getKind())
+
+assert(idList.count(SketchArcId) == 3)
+assert(idList.count(SketchPointId) == 2)
+assert(idList.count(SketchConstraintCoincidenceId) == 4)
+assert(idList.count(SketchConstraintEqualId) == 2)
+assert(idList.count(SketchConstraintTangentId) == 2)
+# Test end
+
 model.end()
 
 assert(model.checkPythonDump())