Salome HOME
[Code coverage]: Move checking the algorithm's result into separate function
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Tools.cpp
index 5a893f50b218d813a3530f39685d26f19ce924ed..e642cc59f65fe7385ee73c179bcea2dad2e032bb 100644 (file)
@@ -19,6 +19,7 @@
 //
 
 #include "GeomAlgoAPI_Tools.h"
+#include "GeomAlgoAPI_MakeShape.h"
 
 #include <clocale>
 
@@ -58,3 +59,32 @@ std::string File_Tools::name(const std::string& theFileName)
   OSD_Path aPath(aFileName);
   return aPath.Name().ToCString();
 }
+
+bool AlgoError::isAlgorithmFailed(const GeomMakeShapePtr& theAlgorithm,
+                                  const std::string& theFeature,
+                                  std::string& theError)
+{
+  theError.clear();
+  if (!theAlgorithm->isDone()) {
+    theError = "Error: " + (theFeature.empty() ? "The" : theFeature) + " algorithm failed.";
+    std::string anAlgoError = theAlgorithm->getError();
+    if (!anAlgoError.empty())
+      theError += " " + anAlgoError;
+    return true;
+  }
+  if (!theAlgorithm->shape() || theAlgorithm->shape()->isNull()) {
+    theError = "Error: Resulting shape";
+    if (!theFeature.empty())
+      theError += "of " + theFeature;
+    theError += " is Null.";
+    return true;
+  }
+  if (!theAlgorithm->isValid()) {
+    theError = "Error: Resulting shape";
+    if (!theFeature.empty())
+      theError += "of " + theFeature;
+    theError += " is not valid.";
+    return true;
+  }
+  return false;
+}