Salome HOME
[bos #35140] [EDF] (2023-T1) Memory communication between SHAPER and GEOM
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_XAOImport.cpp
index 864e42b9b0e6f1e5236cf0f72def3b2a20b87733..5b241497642e6d8c6a15fcbedf5aa8bbd50893e4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2022  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -66,3 +66,46 @@ std::shared_ptr<GeomAPI_Shape> XAOImport(const std::string& theFileName,
   aGeomShape->setImpl(new TopoDS_Shape(aShape));
   return aGeomShape;
 }
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+std::shared_ptr<GeomAPI_Shape> XAOImportMem(const std::string& theMemoryBuff,
+                                            std::string& theError,
+                                            XAO::Xao* theXao)
+{
+#ifdef _DEBUG
+  std::cout << "Import XAO from file " << theFileName << std::endl;
+#endif
+  if (theMemoryBuff.empty() || !theXao) {
+    theError = "An invalid argument.";
+    return std::shared_ptr<GeomAPI_Shape>();
+  }
+
+  TopoDS_Shape aShape;
+  try {
+    if (XAO::XaoExporter::setXML(theMemoryBuff, theXao)) {
+      XAO::Geometry* aGeometry = theXao->getGeometry();
+      XAO::Format aFormat = aGeometry->getFormat();
+      if (aFormat == XAO::BREP) {
+        if (XAO::BrepGeometry* aBrepGeometry = dynamic_cast<XAO::BrepGeometry*>(aGeometry))
+          aShape = aBrepGeometry->getTopoDS_Shape();
+      } else {
+        theError = "Unsupported XAO geometry format:" + XAO::XaoUtils::shapeFormatToString(aFormat);
+        aShape.Nullify();
+      }
+    } else {
+      theError = "XAO object was not read successful";
+      aShape.Nullify();
+    }
+  } catch (XAO::XAO_Exception& e) {
+    theError = e.what();
+    aShape.Nullify();
+  }
+
+  std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+  aGeomShape->setImpl(new TopoDS_Shape(aShape));
+  return aGeomShape;
+}