Salome HOME
Task 3.2. To keep compounds’ sub-shapes for all operations (issue #3139)
[modules/shaper.git] / src / GeomAPI / GeomAPI_ShapeHierarchy.cpp
index cac15eabe4d78435489629b17e9fae0374b55e51..53522d415840a2c24139d8a14ef338e8cd15e3e2 100644 (file)
@@ -60,6 +60,19 @@ GeomShapePtr GeomAPI_ShapeHierarchy::parent(const GeomShapePtr& theShape,
   return aParent;
 }
 
+GeomShapePtr GeomAPI_ShapeHierarchy::root(const GeomShapePtr& theShape,
+                                          bool theMarkProcessed)
+{
+  GeomShapePtr aParent = parent(theShape, theMarkProcessed);
+  GeomShapePtr aRoot = aParent;
+  while (aParent) {
+    aParent = parent(aRoot, theMarkProcessed);
+    if (aParent)
+      aRoot = aParent;
+  }
+  return aRoot;
+}
+
 void GeomAPI_ShapeHierarchy::markProcessed(const GeomShapePtr& theShape)
 {
   myProcessedObjects.insert(theShape);
@@ -84,6 +97,17 @@ void GeomAPI_ShapeHierarchy::markModified(const GeomShapePtr& theSource,
   myModifiedObjects[theSource] = theModified;
 }
 
+const ListOfShape& GeomAPI_ShapeHierarchy::objects(GeomShapePtr theParent) const
+{
+  MapShapeToIndex::const_iterator aFoundIndex = myParentIndices.find(theParent);
+  if (aFoundIndex == myParentIndices.end()) {
+    static const ListOfShape THE_DUMMY = ListOfShape();
+    return THE_DUMMY; // no such shape
+  }
+
+  return mySubshapes[aFoundIndex->second].second;
+}
+
 void GeomAPI_ShapeHierarchy::objectsByType(
     ListOfShape& theShapesByType,
     ListOfShape& theOtherShapes,
@@ -146,17 +170,16 @@ void GeomAPI_ShapeHierarchy::topLevelObjects(ListOfShape& theDestination) const
   iterator anIt = aThis->begin(), aEnd = aThis->end();
   for (; anIt != aEnd; ++anIt) {
     GeomShapePtr aShape = *anIt;
-    GeomShapePtr aParent = aThis->parent(aShape);
-    GeomShapePtr aRoot = aParent;
-    while (aParent) {
-      aParent = aThis->parent(aRoot);
-      if (aParent)
-        aRoot = aParent;
-    }
-
+    GeomShapePtr aRoot = aThis->root(aShape);
     if (aRoot) {
-      // compose a compund with the modified shapes
-      aShape = collectSubs(aRoot, SetOfShape(), myModifiedObjects);
+      // check the current shape was modified
+      MapShapeToShape::const_iterator aFound = myModifiedObjects.find(aRoot);
+      if (aFound != myModifiedObjects.end())
+        aShape = aFound->second;
+      else {
+        // compose a compund with the modified shapes
+        aShape = collectSubs(aRoot, SetOfShape(), myModifiedObjects);
+      }
     }
     else {
       // check the current shape was modified