Salome HOME
Provide pop-up menu for steps
[modules/shaper.git] / src / ModelAPI / ModelAPI_Tools.cpp
index 074b903d55cc28d42615493e3d6633772fb19201..c6b8a6f7257df6ba4933747cb038402399502a87 100644 (file)
@@ -23,6 +23,7 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_ResultPart.h>
@@ -106,6 +107,7 @@ std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult)
   return theResult->shape();
 }
 
+// LCOV_EXCL_START
 const char* toString(ModelAPI_ExecState theExecState)
 {
   switch (theExecState) {
@@ -118,7 +120,6 @@ const char* toString(ModelAPI_ExecState theExecState)
   }
 }
 
-// LCOV_EXCL_START
 std::string getFeatureError(const FeaturePtr& theFeature)
 {
   std::string anError;
@@ -301,14 +302,16 @@ bool hasSubResults(const ResultPtr& theResult)
   return aCompSolid.get() && aCompSolid->numberOfSubs() > 0;
 }
 
-void allSubs(const ResultBodyPtr& theResult, std::list<ResultPtr>& theResults) {
+void allSubs(const ResultBodyPtr& theResult, std::list<ResultPtr>& theResults,
+             const bool theLowerOnly) {
   // iterate sub-bodies of compsolid
   ResultBodyPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
   if (aComp.get()) {
     int aNumSub = aComp->numberOfSubs();
     for (int a = 0; a < aNumSub; a++) {
       ResultBodyPtr aSub = aComp->subResult(a);
-      theResults.push_back(aSub);
+      if (!theLowerOnly || aSub->numberOfSubs() == 0)
+        theResults.push_back(aSub);
       allSubs(aSub, theResults);
     }
   }
@@ -758,4 +761,27 @@ std::set<FeaturePtr> getParents(const FeaturePtr& theFeature)
   return aParents;
 }
 
+void removeResults(const std::list<ResultPtr>& theResults)
+{
+  // collect all documents where the results must be removed
+  std::map<DocumentPtr, std::list<ResultPtr> > aDocs;
+
+  std::list<ResultPtr>::const_iterator aResIter = theResults.cbegin();
+  for(; aResIter != theResults.cend(); aResIter++) {
+    DocumentPtr aDoc = (*aResIter)->document();
+    if (!aDocs.count(aDoc))
+      aDocs[aDoc] = std::list<ResultPtr>();
+    aDocs[aDoc].push_back(*aResIter);
+  }
+  // create a "remove" feature in each doc
+  std::map<DocumentPtr, std::list<ResultPtr> >::iterator aDoc = aDocs.begin();
+  for(; aDoc != aDocs.end(); aDoc++) {
+    FeaturePtr aRemove = aDoc->first->addFeature("RemoveResults");
+    if (aRemove) {
+      for(aResIter = aDoc->second.cbegin(); aResIter != aDoc->second.cend(); aResIter++)
+        aRemove->selectionList("results")->append(*aResIter, GeomShapePtr());
+    }
+  }
+}
+
 } // namespace ModelAPI_Tools