]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/ModelAPI/ModelAPI_Tools.cpp
Salome HOME
Add tools
[modules/shaper.git] / src / ModelAPI / ModelAPI_Tools.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 2f4fba7..56c2a0f
@@ -160,11 +160,13 @@ void findRandomColor(std::vector<int>& theValues)
 
 ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub)
 {
-  for (int a = theMain->size(ModelAPI_ResultPart::group()) - 1; a >= 0; a--) {
-    ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(
-        theMain->object(ModelAPI_ResultPart::group(), a));
-    if (aPart && aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value() == theSub) {
-      return aPart;
+  if (theMain != theSub) { // to optimize and avoid of crash on partset document close (don't touch the sub-document structure)
+    for (int a = theMain->size(ModelAPI_ResultPart::group()) - 1; a >= 0; a--) {
+      ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(
+          theMain->object(ModelAPI_ResultPart::group(), a));
+      if (aPart && aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value() == theSub) {
+        return aPart;
+      }
     }
   }
   return ResultPtr();
@@ -203,5 +205,11 @@ ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub)
   return ResultCompSolidPtr(); // not found
 }
 
+bool hasSubResults(const ResultPtr& theResult)
+{
+  ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theResult);
+  return aCompSolid.get() && aCompSolid->numberOfSubs() > 0;
+}
+
 } // namespace ModelAPI_Tools