Salome HOME
updated copyright message
[modules/shaper.git] / src / GeomAPI / GeomAPI_ShapeHierarchy.cpp
index cac15eabe4d78435489629b17e9fae0374b55e51..7eeb3e4d6d8edbc7f17073949cc7c5e400db4f2a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -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