Salome HOME
Merge branch 'jfa/40620_ExportXAO_separate_BREP'
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_XAOExport.cpp
index 9f0983fe25e56aa9f236d88d5aa421f96548ed34..73e17a19a341d8fd7b6d48fde4e9c5f5ded6c604 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -55,7 +55,8 @@ bool SetShapeToXAO(const std::shared_ptr<GeomAPI_Shape>& theShape,
 //=============================================================================
 bool XAOExport(const std::string& theFileName,
                XAO::Xao* theXao,
-               std::string& theError)
+               std::string& theError,
+               const std::string& theShapeFileName)
 {
   #ifdef _DEBUG
   std::cout << "Export XAO into file " << theFileName << std::endl;
@@ -72,7 +73,7 @@ bool XAOExport(const std::string& theFileName,
     bool aWasFree = aShape.Free(); // make top level topology free, same as imported
     if (!aWasFree)
       aShape.Free(Standard_True);
-    XAO::XaoExporter::saveToFile(theXao, theFileName, "");
+    XAO::XaoExporter::saveToFile(theXao, theFileName, theShapeFileName);
     if (!aWasFree)
       aShape.Free(Standard_False);
   } catch (XAO::XAO_Exception& e) {
@@ -81,3 +82,40 @@ bool XAOExport(const std::string& theFileName,
   }
   return true;
 }
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+const std::string XAOExportMem(XAO::Xao* theXao,
+                               std::string& theError)
+{
+  std::string aRetBuff ("");
+
+#ifdef _DEBUG
+  std::cout << "Export XAO into memory buffer " << std::endl;
+#endif
+
+  if (!theXao) {
+    theError = "An invalid argument.";
+    return aRetBuff;
+  }
+
+  try {
+    XAO::BrepGeometry* aGeometry = dynamic_cast<XAO::BrepGeometry*>(theXao->getGeometry());
+    TopoDS_Shape aShape = aGeometry->getTopoDS_Shape();
+    bool aWasFree = aShape.Free(); // make top level topology free, same as imported
+    if (!aWasFree)
+      aShape.Free(Standard_True);
+
+    aRetBuff = XAO::XaoExporter::saveToXml(theXao);
+
+    if (!aWasFree)
+      aShape.Free(Standard_False);
+  } catch (XAO::XAO_Exception& e) {
+    theError = e.what();
+    return aRetBuff;
+  }
+  return aRetBuff;
+}