Salome HOME
Task 3.2. To keep compounds’ sub-shapes for all operations (issue #3139)
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Tools.cpp
index 55a1738426044d18276c31f08beaa65c2c16d58c..9880565debf733075a6fb03a71a05a339ce6258a 100644 (file)
@@ -22,6 +22,8 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Tools.h>
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_ShapeTools.h>
@@ -241,3 +243,30 @@ bool FeaturesPlugin_Tools::getShape(const AttributeSelectionListPtr theSelection
   }
   return true;
 }
+
+//==================================================================================================
+bool FeaturesPlugin_Tools::shapesFromSelectionList(
+    const std::shared_ptr<ModelAPI_AttributeSelectionList> theSelectionList,
+    const bool theStoreFullHierarchy,
+    GeomAPI_ShapeHierarchy& theHierarchy,
+    std::list<ResultPtr>& theParts)
+{
+  int aSize = theSelectionList->size();
+  for (int anObjectsIndex = 0; anObjectsIndex < aSize; anObjectsIndex++) {
+    AttributeSelectionPtr anObjectAttr = theSelectionList->value(anObjectsIndex);
+    std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
+    if (!anObject.get()) { // may be for not-activated parts
+      return false;
+    }
+    ResultPtr aContext = anObjectAttr->context();
+    if (aContext->groupName() == ModelAPI_ResultPart::group())
+      theParts.push_back(aContext);
+    else {
+      // store full shape hierarchy for the corresponding version only
+      theHierarchy.addObject(anObject);
+      if (theStoreFullHierarchy)
+        ModelAPI_Tools::fillShapeHierarchy(anObject, aContext, theHierarchy);
+    }
+  }
+  return true;
+}