Salome HOME
Adding error handling.
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_XAOExport.cpp
index 6bd8127920b90a48a834500a15a630c1eaabe1a0..8bf37d5383197eb73faeb52e1a9f286b49a81418 100644 (file)
 #include <XAO_XaoExporter.hxx>
 #include <XAO_BrepGeometry.hxx>
 
+//=============================================================================
+bool SetShapeToXAO(const std::shared_ptr<GeomAPI_Shape>& theShape,
+                   XAO::Xao* theXao,
+                   std::string& theError)
+{
+  if (!theShape.get() || !theXao) {
+    theError = "An invalid argument.";
+    return false;
+  }
+
+  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+  try {
+    XAO::BrepGeometry* aGeometry = new XAO::BrepGeometry;
+    theXao->setGeometry(aGeometry);
+    aGeometry->setTopoDS_Shape(aShape);
+  } catch (XAO::XAO_Exception& e) {
+    theError = e.what();
+    return false;
+  }
+  return true;
+}
+
 //=============================================================================
 /*!
  *
  */
 //=============================================================================
 bool XAOExport(const std::string& theFileName,
-               const std::shared_ptr<GeomAPI_Shape>& theShape,
                XAO::Xao* theXao,
                std::string& theError)
 {
@@ -27,16 +48,12 @@ bool XAOExport(const std::string& theFileName,
   std::cout << "Export XAO into file " << theFileName << std::endl;
   #endif
 
-  if (theFileName.empty() || !theShape.get() || !theXao) {
+  if (theFileName.empty() || !theXao) {
     theError = "An invalid argument.";
     return false;
   }
 
-  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
   try {
-    XAO::BrepGeometry* aGeometry = new XAO::BrepGeometry;
-    theXao->setGeometry(aGeometry);
-    aGeometry->setTopoDS_Shape(aShape);
     XAO::XaoExporter::saveToFile(theXao, theFileName);
   } catch (XAO::XAO_Exception& e) {
     theError = e.what();