Salome HOME
Extract ShapeHierarchy as a separate object
[modules/shaper.git] / src / ModelAPI / ModelAPI_Tools.cpp
index 413f52c4ce616edd2c2e4cb49f84f0621dde2737..f77e99951ae430e70d004b73e5b4a641d5ce5ddb 100644 (file)
@@ -38,6 +38,8 @@
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
 
+#include <GeomAPI_ShapeHierarchy.h>
+
 #define RECURSE_TOP_LEVEL 50
 
 //#define DEBUG_REMOVE_FEATURES
@@ -762,6 +764,21 @@ std::set<FeaturePtr> getParents(const FeaturePtr& theFeature)
   return aParents;
 }
 
+void fillShapeHierarchy(const GeomShapePtr& theShape,
+                        const ResultPtr& theContext,
+                        GeomAPI_ShapeHierarchy& theHierarchy)
+{
+  ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(theContext);
+  if (aResCompSolidPtr.get()) {
+    std::shared_ptr<GeomAPI_Shape> aContextShape = aResCompSolidPtr->shape();
+    if (aContextShape->shapeType() <= GeomAPI_Shape::COMPSOLID) {
+      theHierarchy.addParent(theShape, aContextShape);
+      fillShapeHierarchy(aContextShape, aResCompSolidPtr, theHierarchy);
+    }
+  }
+}
+
+
 void removeResults(const std::list<ResultPtr>& theResults)
 {
   // collect all documents where the results must be removed