Salome HOME
Provide pop-up menu for steps
[modules/shaper.git] / src / ModelAPI / ModelAPI_Tools.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 9dc5e4e..c6b8a6f
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "ModelAPI_Tools.h"
@@ -24,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>
@@ -107,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) {
@@ -119,7 +120,6 @@ const char* toString(ModelAPI_ExecState theExecState)
   }
 }
 
-// LCOV_EXCL_START
 std::string getFeatureError(const FeaturePtr& theFeature)
 {
   std::string anError;
@@ -302,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);
     }
   }
@@ -759,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