]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Implementation of [bos #35140] [EDF] (2023-T1) Memory communication between SHAPER...
authorjfa <jfa@opencascade.com>
Thu, 1 Jun 2023 15:50:36 +0000 (16:50 +0100)
committerjfa <jfa@opencascade.com>
Tue, 8 Aug 2023 15:56:20 +0000 (16:56 +0100)
doc/salome/examples/import_export.py
doc/salome/gui/GEOM/input/import_export.doc
doc/salome/gui/GEOM/input/tui_importexport_geom_objs.doc [deleted file]
idl/XAOPlugin.idl
src/GEOM_SWIG/XAOPluginBuilder.py
src/XAO/XAO_XaoExporter.cxx
src/XAOPlugin/XAOPlugin_IOperations.cxx
src/XAOPlugin/XAOPlugin_IOperations.hxx
src/XAOPlugin/XAOPlugin_IOperations_i.cc
src/XAOPlugin/XAOPlugin_IOperations_i.hh

index e01203890ca9be7aed8a0a5f1b480248223d52b2..85e31d1dbac8b75c5fafe0db84f4bc4bc1add857 100644 (file)
@@ -45,6 +45,9 @@ geompy.ExportVTK(sphere, f_vtk2, 0.1)
 f_xao = os.path.join(tmpdir, "sphere.xao")
 geompy.ExportXAO(sphere, [], [], "author", f_xao)
 
+# export sphere to XAO format memory buffer (bytes array)
+buff_xao = geompy.ExportXAOMem(sphere, [], [], "author")
+
 # import BREP file
 sphere_brep = geompy.ImportBREP(f_brep)
 
@@ -64,6 +67,9 @@ sphere_stl2 = geompy.ImportSTL(f_stl2)
 # import XAO file
 ok, sphere_xao, sub_shapes, groups, fields = geompy.ImportXAO(f_xao)
 
+# import XAO data from memory buffer (bytes array)
+ok_mem, sphere_xao_mem, sub_shapes_mem, groups_mem, fields_mem = geompy.ImportXAOMem(buff_xao)
+
 # clean up
 for f in f_brep, f_iges, f_step, f_stl1, f_stl2, f_vtk1, f_vtk2, f_xao:
   os.remove(f)
index 7e79e38d69ee89770d48730a2517cf40237cee3a..57c96e57dbe86cc64aa4ddc28010c84058c30380 100644 (file)
@@ -88,6 +88,16 @@ In the \b File menu select <b>Import/XAO</b>.
 
 \par
 
+It is possible to import a shape from XAO file using the TUI Command:
+
+<em>ok, Shape, Sub_Shapes, Groups, Fields = geompy.ImportXAO(FileName)</em>
+
+It is also possible to import a shape from XAO format memory buffer (bytes array) using the TUI Command:
+
+<em>ok, Shape, Sub_Shapes, Groups, Fields = geompy.ImportXAOMem(aBuffer)</em>
+
+\par
+
 <em>To export a shape in the \b XAO format:</em>
 
 \par
@@ -104,6 +114,12 @@ In this dialog:
 - Select the \b Fields of the chosen shape to be exported.
 - Press "Apply" or "Apply & Close" button to get the result.
 
-It is also possible to export a shape using the TUI Command: <em>geompy.ExportXAO(Shape, Groups, Fields, Author, FileName, ShapeFileName)</em>
+It is possible to export a shape in XAO file using the TUI Command:
+
+<em>geompy.ExportXAO(Shape, Groups, Fields, Author, FileName, ShapeFileName)</em>
+
+It is also possible to export a shape in XAO format memory buffer (bytes array) using the TUI Command:
+
+<em>aBuffer = geompy.ExportXAOMem(Shape, Groups, Fields, Author)</em>
 
 */
diff --git a/doc/salome/gui/GEOM/input/tui_importexport_geom_objs.doc b/doc/salome/gui/GEOM/input/tui_importexport_geom_objs.doc
deleted file mode 100644 (file)
index 12c30a1..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-\anchor tui_creation_exportxao
-<br><h2>Creation of ExportXAO</h2>
-
-\code
-import salome
-import GEOM
-from salome.geom import geomBuilder
-geompy = geomBuilder.New()
-
-gg = salome.ImportComponentGUI("GEOM")
-
-# create ExportXAO object
-exportxao = geompy.ExportXAO([value], [value], [value], [value])
-
-# add object in the study
-id_exportxao = geompy.addToStudy(exportxao,"ExportXAO")
-
-# display exportxao
-gg.createAndDisplayGO(id_exportxao) 
-\endcode
-
index 08e81fc54af7b4cf6c141ce7c191526b7e7862a6..75a44f94aadc6e2efc0e60c509ce6bce242f70f3 100644 (file)
@@ -46,6 +46,19 @@ module GEOM
                        in string fileName,
                        in string shapeFileName );
     
+    /*!
+     *  Export a shape to XAO format in a byte array
+     *  \param shape The shape to export
+     *  \param groups The list of groups to export
+     *  \param fields The list of fields to export
+     *  \param author The author of the export
+     *  \return Byte array with exported data.
+     */
+    SALOMEDS::TMPFile ExportXAOMem( in GEOM::GEOM_Object shape,
+                                    in GEOM::ListOfGO groups, 
+                                    in GEOM::ListOfFields fields,
+                                    in string author );
+    
     /*!
      *  Import a shape from XAO format
      *  \param fileName The name of the file to import
@@ -60,6 +73,21 @@ module GEOM
                        out GEOM::ListOfGO subShapes, 
                        out GEOM::ListOfGO groups, 
                        out GEOM::ListOfFields fields );
+    
+    /*!
+     *  Import a shape from XAO format byte array
+     *  \param theBuff The byte array with data in XAO format
+     *  \param shape The imported shape
+     *  \param subShapes The list of imported subShapes
+     *  \param groups The list of imported groups
+     *  \param fields The list of imported fields
+     *  \return boolean indicating if import was successful.
+     */
+    boolean ImportXAOMem( in SALOMEDS::TMPFile theBuff,
+                          out GEOM::GEOM_Object shape,
+                          out GEOM::ListOfGO subShapes, 
+                          out GEOM::ListOfGO groups, 
+                          out GEOM::ListOfFields fields );
   };
 };
 
index 4d560113c47486854bbb49cb9b4b338d2d71b463..14b9b1e890b14f0556adff4f75ef2bbbd60e45dd 100644 (file)
@@ -18,6 +18,7 @@
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
+import GEOM
 from GEOM import IXAOOperations
 
 # Engine Library Name
@@ -57,6 +58,32 @@ def ExportXAO(self, shape, groups, fields, author, fileName, shapeFileName = "")
     RaiseIfFailed("ExportXAO", anOp)
     return res
 
+## Export a shape to XAO format in byte array
+#  @param shape The shape to export
+#  @param groups The list of groups to export
+#  @param fields The list of fields to export
+#  @param author The author of the file
+#  @return Byte array with exported data
+#
+#  @ingroup l2_import_export
+def ExportXAOMem(self, shape, groups, fields, author):
+    """
+    Export a shape to XAO format in byte array
+    
+    Parameters:
+        shape The shape to export
+        groups The list of groups to export
+        fields The list of fields to export
+
+    Returns:
+        Byte array with exported data
+    """
+    from salome.geom.geomBuilder import RaiseIfFailed
+    anOp = GetXAOPluginOperations(self)
+    res = anOp.ExportXAOMem(shape, groups, fields, author)
+    RaiseIfFailed("ExportXAOMem", anOp)
+    return res
+
 ## Import a shape from XAO format
 #  @param fileName The name of the file to import
 #  @param theName Object name; when specified, this parameter is used
@@ -91,7 +118,78 @@ def ImportXAO(self, fileName, theName=None):
     """
     from salome.geom.geomBuilder import RaiseIfFailed
     anOp = GetXAOPluginOperations(self)
-    res = anOp.ImportXAO(fileName)
+    (res, shape, subShapes, groups, fields) = anOp.ImportXAO(fileName)
     RaiseIfFailed("ImportXAO", anOp)
-    self._autoPublish(res[1], theName, "imported")
-    return res
+    if res:
+        # publish imported shape
+        self._autoPublish(shape, theName, "imported")
+        # publish imported sub shapes, groups and fields
+        if theName or self.myMaxNbSubShapesAllowed:
+            for ss in (subShapes + groups + fields):
+                self.addToStudyInFather(shape, ss, ss.GetName())
+                if isinstance( ss, GEOM._objref_GEOM_Field ):
+                    listStepIDs = ss.GetSteps()
+                    for stepID in listStepIDs:
+                        step = ss.GetStep(stepID)
+                        self.addToStudyInFather(ss, step, step.GetName())
+                        pass
+                    pass
+                pass
+            pass
+        pass
+    return (res, shape, subShapes, groups, fields)
+
+## Import a shape from XAO format byte array
+#  @param byteArray byte array with XAO data
+#  @param theName Object name; when specified, this parameter is used
+#         for result publication in the study. Otherwise, if automatic
+#         publication is switched on, default value is used for result name.
+# 
+#  @return tuple (\a res, \a shape, \a subShapes, \a groups, \a fields)
+#       \a res Flag indicating if the import was successful
+#       \a shape The imported shape
+#       \a subShapes The list of imported subShapes
+#       \a groups The list of imported groups
+#       \a fields The list of imported fields
+#
+#  @ingroup l2_import_export
+def ImportXAOMem(self, byteArray, theName=None):
+    """
+    Import a shape from XAO format byte array
+    
+    Parameters:
+        byteArray byte array with XAO data
+        theName Object name; when specified, this parameter is used
+                for result publication in the study. Otherwise, if automatic
+                publication is switched on, default value is used for result name.
+
+    Returns:
+        A tuple (res, shape, subShapes, groups, fields):
+        - res: Flag indicating if the import was successful
+        - shape: The imported shape
+        - subShapes: The list of imported subShapes
+        - groups: The list of imported groups
+        - fields: The list of imported fields
+    """
+    from salome.geom.geomBuilder import RaiseIfFailed
+    anOp = GetXAOPluginOperations(self)
+    (res, shape, subShapes, groups, fields) = anOp.ImportXAOMem(byteArray)
+    RaiseIfFailed("ImportXAOMem", anOp)
+    if res:
+        # publish imported shape
+        self._autoPublish(shape, theName, "imported")
+        # publish imported sub shapes, groups and fields
+        if theName or self.myMaxNbSubShapesAllowed:
+            for ss in (subShapes + groups + fields):
+                self.addToStudyInFather(shape, ss, ss.GetName())
+                if isinstance( ss, GEOM._objref_GEOM_Field ):
+                    listStepIDs = ss.GetSteps()
+                    for stepID in listStepIDs:
+                        step = ss.GetStep(stepID)
+                        self.addToStudyInFather(ss, step, step.GetName())
+                        pass
+                    pass
+                pass
+            pass
+        pass
+    return (res, shape, subShapes, groups, fields)
index 9f39919671ec21ac77211485578f43954094ad3e..3e95671b4f49187848068d5538123cf92aeec66a 100644 (file)
@@ -655,7 +655,9 @@ const std::string XaoExporter::saveToXml(Xao* xaoObject)
 
     xmlChar *xmlbuff;
     int buffersize;
-    xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); // format = 1 for node indentation
+    //xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); // format = 1 for node indentation
+    // save with encoding to correspond to "saveToFile" and provide the same file size
+    xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "UTF-8", 1); // format = 1 for node indentation
     xmlFreeDoc(doc);
     xmlCleanupGlobals();
 
index de2b1b9d29ef8c1e07a2d0e6d5102da171bd3a39..53d2161511ec73c25760734d0f4329a7b3b069a3 100644 (file)
@@ -58,6 +58,8 @@
 
 #include <TopExp.hxx>
 
+#include <algorithm>
+
 XAO::Dimension shapeEnumToDimension(const TopAbs_ShapeEnum& shape)
 {
   XAO::Dimension dim;
@@ -323,12 +325,13 @@ void XAOPlugin_IOperations::exportSubshapes( const Handle(GEOM_Object)& shape, X
 
 //=============================================================================
 /*!
- *  Export a shape to XAO format
- *  \param shape The shape to export
- *  \param groups The list of groups to export
- *  \param fields The list of fields to export
- *  \param fileName The name of the file to exported
- *  \return boolean indicating if export was succeful.
+ *  Export a shape to XAO format file.
+ *  \param shape The shape to export.
+ *  \param groups The list of groups to export.
+ *  \param fields The list of fields to export.
+ *  \param fileName The name of the file to be exported.
+ *  \param shapeFileName The name of the file for shape, if it should be exported separately.
+ *  \return boolean indicating if export was successful.
  */
 //=============================================================================
 bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
@@ -337,22 +340,68 @@ bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
                                        const char* author,
                                        const char* fileName,
                                        const char* shapeFileName )
+{
+  if (!fileName || !strlen(fileName)) {
+    SetErrorCode("Empty file name");
+    return false;
+  }
+
+  exportXAO( shape, groupList, fieldList, author, fileName, shapeFileName );
+  return IsDone();
+}
+
+//=============================================================================
+/*!
+ *  Export a shape to XAO format string.
+ *  \param shape The shape to export.
+ *  \param groups The list of groups to export.
+ *  \param fields The list of fields to export.
+ *  \return The exported string.
+ */
+//=============================================================================
+std::string XAOPlugin_IOperations::ExportXAOMem( Handle(GEOM_Object) shape,
+                                                 std::list<Handle(GEOM_Object)> groupList,
+                                                 std::list<Handle(GEOM_Field)> fieldList,
+                                                 const char* author )
+{
+  std::string anXML = exportXAO( shape, groupList, fieldList, author, NULL, NULL );
+  return anXML;
+}
+
+//=============================================================================
+/*!
+ *  Export a shape to XAO format file or string.
+ *  \param shape The shape to export.
+ *  \param groups The list of groups to export.
+ *  \param fields The list of fields to export.
+ *  \param fileName The name of the file to be exported. If empty, export to string.
+ *  \param shapeFileName The name of the file for shape, if it should be exported separately.
+ *  \return The exported string, if fileName is empty, or empty string.
+ */
+//=============================================================================
+std::string XAOPlugin_IOperations::exportXAO( Handle(GEOM_Object) shape,
+                                              std::list<Handle(GEOM_Object)> groupList,
+                                              std::list<Handle(GEOM_Field)> fieldList,
+                                              const char* author,
+                                              const char* fileName,
+                                              const char* shapeFileName )
 {
   SetErrorCode(KO);
+  std::string anXML ("");
 
-  if (shape.IsNull()) return false;
+  if (shape.IsNull()) return anXML;
 
   // add a new shape function with parameters
   Handle(GEOM_Function) lastFunction = shape->GetLastFunction();
-  if (lastFunction.IsNull()) return false;
+  if (lastFunction.IsNull()) return anXML;
 
   // add a new result object
   Handle(GEOM_Object) result = GetEngine()->AddObject(GEOM_IMPORT);
 
   // add an Export function
   Handle(GEOM_Function) exportFunction = result->AddFunction(XAOPlugin_Driver::GetID(), EXPORT_SHAPE);
-  if (exportFunction.IsNull()) return false;
-  if (exportFunction->GetDriverGUID() != XAOPlugin_Driver::GetID()) return false;
+  if (exportFunction.IsNull()) return anXML;
+  if (exportFunction->GetDriverGUID() != XAOPlugin_Driver::GetID()) return anXML;
 
   // create the XAO object
   XAO::Xao* xaoObject = new XAO::Xao();
@@ -369,16 +418,36 @@ bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
   exportSubshapes(shape, geometry);
   xaoObject->setGeometry(geometry);
 
-  if (!exportGroups(groupList, xaoObject, geometry)) return false;
+  if (!exportGroups(groupList, xaoObject, geometry)) return anXML;
   exportFields(fieldList, xaoObject, geometry);
 
-  // export the XAO to the file
-  xaoObject->exportXAO(fileName, shapeFileName);
+  bool isFile = (fileName && strlen(fileName));
+  if (isFile) {
+    // export the XAO to the file
+    xaoObject->exportXAO(fileName, shapeFileName);
+  }
+  else {
+    // export the XAO to the string
+    anXML = xaoObject->getXML();
+  }
 
   // make a Python command
-  GEOM::TPythonDump pd(exportFunction);
-  std::string convFileName = Kernel_Utils::BackSlashToSlash(fileName);
-  pd << "exported = geompy.ExportXAO(" << shape;
+  GEOM::TPythonDump pd (exportFunction);
+  if (isFile) {
+    pd << "exported = geompy.ExportXAO(";
+  }
+  else {
+    if (!shape->GetName().IsEmpty()) {
+      std::string aGeometryNamePy (shape->GetName().ToCString());
+      std::replace(aGeometryNamePy.begin(), aGeometryNamePy.end(), ' ', '_');
+      pd << "aXAOBuff_" << aGeometryNamePy.c_str() << " = geompy.ExportXAOMem(";
+    }
+    else
+      pd << "aXAOBuff = geompy.ExportXAOMem(";
+  }
+
+  // shape
+  pd << shape;
 
   // list of groups
   pd << ", [";
@@ -404,12 +473,24 @@ bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
     }
   }
   pd << "], ";
-  pd << "\"" << author << "\", \"" << convFileName.c_str() << "\", \"" << shapeFileName << "\")";
+
+  // author
+  pd << "\"" << author << "\"";
+
+  // files
+  if (isFile) {
+    std::string convFileName = Kernel_Utils::BackSlashToSlash(fileName);
+    std::string convShapeFileName;
+    if (shapeFileName && strlen(shapeFileName))
+      convShapeFileName = Kernel_Utils::BackSlashToSlash(shapeFileName);
+    pd << ", \"" << convFileName.c_str() << "\", \"" << convShapeFileName.c_str() << "\"";
+  }
+  pd << ")";
 
   SetErrorCode(OK);
   delete xaoObject;
 
-  return true;
+  return anXML;
 }
 
 void XAOPlugin_IOperations::importSubShapes( XAO::Geometry* xaoGeometry,
@@ -440,7 +521,10 @@ void XAOPlugin_IOperations::importSubShapes( XAO::Geometry* xaoGeometry,
       return;
 
     subShape->SetName(name.c_str());
-    subShape->SetType(shapeType);
+
+    // commented out, as it prevents correct operation information filling
+    // type should be a GEOM_SUBSHAPE
+    //subShape->SetType(shapeType);
 
     GEOM_ISubShape aSSI(aFunction);
     aSSI.SetMainShape(function);
@@ -456,13 +540,13 @@ void XAOPlugin_IOperations::importSubShapes( XAO::Geometry* xaoGeometry,
 
 //=============================================================================
 /*!
- *  Import a shape from XAO format
- *  \param fileName The name of the file to import
- *  \param shape The imported shape
- *  \param subShapes The list of imported groups
- *  \param groups The list of imported groups
- *  \param fields The list of imported fields
- *  \return boolean indicating if import was succeful.
+ *  Import a shape from XAO format file.
+ *  \param fileName The name of the file to import.
+ *  \param shape The imported shape.
+ *  \param subShapes The list of imported sub-shapes.
+ *  \param groups The list of imported groups.
+ *  \param fields The list of imported fields.
+ *  \return boolean indicating if import was successful.
  */
 //=============================================================================
 bool XAOPlugin_IOperations::ImportXAO( const char* fileName,
@@ -470,17 +554,70 @@ bool XAOPlugin_IOperations::ImportXAO( const char* fileName,
                                        Handle(TColStd_HSequenceOfTransient)& subShapes,
                                        Handle(TColStd_HSequenceOfTransient)& groups,
                                        Handle(TColStd_HSequenceOfTransient)& fields )
+{
+  if (fileName == NULL || !strlen(fileName)) {
+    SetErrorCode("Empty file name");
+  }
+
+  importXAO( fileName, "", shape, subShapes, groups, fields );
+  return IsDone();
+}
+
+//=============================================================================
+/*!
+ *  Import a shape from XAO format string.
+ *  \param theXML The input buffer.
+ *  \param shape The imported shape.
+ *  \param subShapes The list of imported sub-shapes.
+ *  \param groups The list of imported groups.
+ *  \param fields The list of imported fields.
+ *  \return boolean indicating if import was successful.
+ */
+//=============================================================================
+bool XAOPlugin_IOperations::ImportXAOMem( const std::string& theXML,
+                                          Handle(GEOM_Object)& shape,
+                                          Handle(TColStd_HSequenceOfTransient)& subShapes,
+                                          Handle(TColStd_HSequenceOfTransient)& groups,
+                                          Handle(TColStd_HSequenceOfTransient)& fields )
+{
+  importXAO( NULL, theXML, shape, subShapes, groups, fields );
+  return IsDone();
+}
+
+//=============================================================================
+/*!
+ *  Import a shape from XAO format file.
+ *  \param fileName The name of the file to import.
+ *  \param shape The imported shape.
+ *  \param subShapes The list of imported sub-shapes.
+ *  \param groups The list of imported groups.
+ *  \param fields The list of imported fields.
+ *  \return boolean indicating if import was successful.
+ */
+//=============================================================================
+bool XAOPlugin_IOperations::importXAO( const char* fileName,
+                                       const std::string& theXML,
+                                       Handle(GEOM_Object)& shape,
+                                       Handle(TColStd_HSequenceOfTransient)& subShapes,
+                                       Handle(TColStd_HSequenceOfTransient)& groups,
+                                       Handle(TColStd_HSequenceOfTransient)& fields )
 {
   SetErrorCode(KO);
 
-  if (fileName == NULL || groups.IsNull() || fields.IsNull())
+  if (groups.IsNull() || fields.IsNull())
     return false;
 
+  bool isFile = (fileName && strlen(fileName));
+
   // Read the XAO
   XAO::Xao* xaoObject = new XAO::Xao();
   try
   {
-    xaoObject->importXAO(fileName);
+    if (isFile)
+      xaoObject->importXAO(fileName);
+    else {
+     xaoObject->setXML(theXML);
+    }
   }
   catch (XAO::XAO_Exception& exc)
   {
@@ -503,7 +640,14 @@ bool XAOPlugin_IOperations::ImportXAO( const char* fileName,
   if (function.IsNull()) return false;
   if (function->GetDriverGUID() != XAOPlugin_Driver::GetID()) return false;
 
-  function->SetString( XAOPlugin_Driver::GetFileNameTag(), fileName );
+  // Initialize python dimp here to prevent dumping of sub shapes, groups and fields
+  GEOM::TPythonDump pd(function);
+
+  if (isFile)
+    function->SetString( XAOPlugin_Driver::GetFileNameTag(), fileName );
+  else {
+    function->SetString( XAOPlugin_Driver::GetFileNameTag(), "NO, imported from byte array" );
+  }
 
   // set the geometry
   if (xaoGeometry->getFormat() == XAO::BREP)
@@ -658,7 +802,6 @@ bool XAOPlugin_IOperations::ImportXAO( const char* fileName,
   }
 
   // make a Python command
-  GEOM::TPythonDump pd(function);
   pd << "(imported, " << shape << ", ";
 
   // list of sub shapes
@@ -695,9 +838,21 @@ bool XAOPlugin_IOperations::ImportXAO( const char* fileName,
       pd << obj << ((i < nbFields) ? ", " : "");
     }
   }
-  std::string convFileName =  Kernel_Utils::BackSlashToSlash( fileName );
-  pd << "]";
-  pd << ") = geompy.ImportXAO(\"" << convFileName.c_str() << "\")";
+  pd << "]) = geompy.";
+
+  if (isFile) {
+    std::string convFileName =  Kernel_Utils::BackSlashToSlash( fileName );
+    pd << "ImportXAO(\"" << convFileName.c_str() << "\")";
+  }
+  else {
+    if (!shape->GetName().IsEmpty()) {
+      std::string aGeometryNamePy (shape->GetName().ToCString());
+      std::replace(aGeometryNamePy.begin(), aGeometryNamePy.end(), ' ', '_');
+      pd << "ImportXAOMem(aXAOBuff_" << aGeometryNamePy.c_str() << ")";
+    }
+    else
+      pd << "ImportXAOMem(aXAOBuff)";
+  }
 
   delete xaoObject;
   SetErrorCode(OK);
index 1e8bdcb45b0941d6bd079e47d64bede537b00518..20f63b9e640f0a913979304aac80aebc3c8a8d56 100644 (file)
@@ -49,14 +49,37 @@ public:
                   const char* author,
                   const char* fileName,
                   const char* shapeFileName );
-  
+
+  std::string ExportXAOMem( Handle(GEOM_Object) shape,
+                            std::list<Handle(GEOM_Object)> groupList,
+                            std::list<Handle(GEOM_Field)> fieldList,
+                            const char* author );
+
   bool ImportXAO( const char* fileName,
                   Handle(GEOM_Object)& shape,
                   Handle(TColStd_HSequenceOfTransient)& subShapes,
                   Handle(TColStd_HSequenceOfTransient)& groups,
                   Handle(TColStd_HSequenceOfTransient)& fields );
 
+  bool ImportXAOMem( const std::string& theXML,
+                     Handle(GEOM_Object)& shape,
+                     Handle(TColStd_HSequenceOfTransient)& subShapes,
+                     Handle(TColStd_HSequenceOfTransient)& groups,
+                     Handle(TColStd_HSequenceOfTransient)& fields );
+
 private:
+  std::string exportXAO( Handle(GEOM_Object) shape,
+                         std::list<Handle(GEOM_Object)> groupList,
+                         std::list<Handle(GEOM_Field)> fieldList,
+                         const char* author,
+                         const char* fileName,
+                         const char* shapeFileName );
+  bool importXAO( const char* fileName,
+                  const std::string& theXML,
+                  Handle(GEOM_Object)& shape,
+                  Handle(TColStd_HSequenceOfTransient)& subShapes,
+                  Handle(TColStd_HSequenceOfTransient)& groups,
+                  Handle(TColStd_HSequenceOfTransient)& fields );
   void importSubShapes( XAO::Geometry* xaoGeometry,
                         Handle(GEOM_Function) function,
                         int shapeType,
index a80107d600797fb2590c5ff7e64a31766c1c2c55..f9b489be67b9e414a493b9ddbbbf92f945077191 100644 (file)
@@ -49,14 +49,14 @@ XAOPlugin_IOperations_i::~XAOPlugin_IOperations_i()
 
 //=============================================================================
 /*!
- *  Export a shape to XAO format
+ *  Export a shape to XAO format file
  *  \param shape The shape to export
  *  \param groups The list of groups to export
  *  \param fields The list of fields to export
  *  \param author The author of the export
  *  \param fileName The name of the exported file
- *  \param shapeFileName If not empty, save to shape to this external file
- *  \return boolean indicating if export was succeful.
+ *  \param shapeFileName If not empty, save the BREP shape to this external file
+ *  \return boolean indicating if export was successful.
  */
 //=============================================================================
 CORBA::Boolean XAOPlugin_IOperations_i::ExportXAO( GEOM::GEOM_Object_ptr shape,
@@ -66,12 +66,63 @@ CORBA::Boolean XAOPlugin_IOperations_i::ExportXAO( GEOM::GEOM_Object_ptr shape,
                                                    const char* fileName,
                                                    const char* shapeFileName)
 {
-  bool isGood = false;
+  exportXAO( shape, groups, fields, author, true, fileName, shapeFileName );
+  return IsDone();
+}
+
+//=============================================================================
+/*!
+ *  Export a shape to XAO format buffer
+ *  \param shape The shape to export
+ *  \param groups The list of groups to export
+ *  \param fields The list of fields to export
+ *  \param author The author of the export
+ *  \return The output buffer
+ */
+//=============================================================================
+SALOMEDS::TMPFile* XAOPlugin_IOperations_i::ExportXAOMem( GEOM::GEOM_Object_ptr shape,
+                                                          const GEOM::ListOfGO& groups,
+                                                          const GEOM::ListOfFields& fields,
+                                                          const char* author )
+{
+  std::string anXMLBuf = exportXAO( shape, groups, fields, author, false, "", "" );
+
+  int size = anXMLBuf.size();
+  CORBA::Octet* OctetBuf = SALOMEDS::TMPFile::allocbuf(size);
+  memcpy(OctetBuf, anXMLBuf.c_str(), size);
+  SALOMEDS::TMPFile_var SeqFile = new SALOMEDS::TMPFile (size,size,OctetBuf,1);
+  return SeqFile._retn();
+}
+
+//=============================================================================
+/*!
+ *  Export a shape to XAO format
+ *  \param shape The shape to export
+ *  \param groups The list of groups to export
+ *  \param fields The list of fields to export
+ *  \param author The author of the export
+ *  \param toFile Export to file if true, otherwise export to memory buffer (the returned string)
+ *  \param fileName The name of the exported file
+ *  \param shapeFileName If not empty, save the BREP shape to this external file
+ *  \return string The exported buffer if toFile=false, otherwise an empty string
+ */
+//=============================================================================
+std::string XAOPlugin_IOperations_i::exportXAO( GEOM::GEOM_Object_ptr shape,
+                                                const GEOM::ListOfGO& groups,
+                                                const GEOM::ListOfFields& fields,
+                                                const char* author,
+                                                const bool  toFile,
+                                                const char* fileName,
+                                                const char* shapeFileName)
+{
+  std::string anXMLBuff;
   // Set a not done flag
   GetOperations()->SetNotDone();
 
   // Get the reference shape
   Handle(GEOM_Object) reference = GetObjectImpl( shape );
+  if( reference.IsNull() )
+    return anXMLBuff;
 
   // Get the reference groups
   CORBA::ULong ind = 0;
@@ -79,7 +130,7 @@ CORBA::Boolean XAOPlugin_IOperations_i::ExportXAO( GEOM::GEOM_Object_ptr shape,
   for (; ind < groups.length(); ind++)
   {
     Handle(GEOM_Object) gobj = GetObjectImpl( groups[ind] );
-    if (gobj.IsNull()) return false;
+    if (gobj.IsNull()) return anXMLBuff;
     groupsObj.push_back(gobj);
   }
 
@@ -89,17 +140,21 @@ CORBA::Boolean XAOPlugin_IOperations_i::ExportXAO( GEOM::GEOM_Object_ptr shape,
   for( ; ind < fields.length(); ind++ )
   {
     Handle(GEOM_Field) fobj = Handle(GEOM_Field)::DownCast( GetBaseObjectImpl( fields[ind] ) );
-    if( fobj.IsNull() ) return false;
+    if( fobj.IsNull() ) return anXMLBuff;
     fieldsObj.push_back(fobj);
   }
 
-  if( !reference.IsNull() )
+  if ( toFile )
   {
     // Export XAO
-    isGood = GetOperations()->ExportXAO( reference, groupsObj, fieldsObj, author, fileName, shapeFileName );
+    GetOperations()->ExportXAO( reference, groupsObj, fieldsObj, author, fileName, shapeFileName );
+  }
+  else
+  {
+    anXMLBuff = GetOperations()->ExportXAOMem( reference, groupsObj, fieldsObj, author );
   }
 
-  return isGood;
+  return anXMLBuff;
 }
 
 //=============================================================================
@@ -110,7 +165,7 @@ CORBA::Boolean XAOPlugin_IOperations_i::ExportXAO( GEOM::GEOM_Object_ptr shape,
  *  \param subShapes The list of imported subShapes
  *  \param groups The list of imported groups
  *  \param fields The list of imported fields
- *  \return boolean indicating if import was succeful.
+ *  \return boolean indicating if import was successful.
  */
 //=============================================================================
 CORBA::Boolean XAOPlugin_IOperations_i::ImportXAO( const char* fileName,
@@ -118,6 +173,53 @@ CORBA::Boolean XAOPlugin_IOperations_i::ImportXAO( const char* fileName,
                                                   GEOM::ListOfGO_out subShapes,
                                                   GEOM::ListOfGO_out groups,
                                                   GEOM::ListOfFields_out fields)
+{
+  SALOMEDS::TMPFile_var aBuff;
+  importXAO( true, fileName, aBuff, shape, subShapes, groups, fields);
+  return IsDone();
+}
+
+//=============================================================================
+/*!
+ *  Import a shape from XAO format memory buffer
+ *  \param fileName The name of the file to import
+ *  \param shape The imported shape
+ *  \param subShapes The list of imported subShapes
+ *  \param groups The list of imported groups
+ *  \param fields The list of imported fields
+ *  \return boolean indicating if import was successful.
+ */
+//=============================================================================
+CORBA::Boolean XAOPlugin_IOperations_i::ImportXAOMem( const SALOMEDS::TMPFile& theBuff,
+                                                      GEOM::GEOM_Object_out shape,
+                                                      GEOM::ListOfGO_out subShapes,
+                                                      GEOM::ListOfGO_out groups,
+                                                      GEOM::ListOfFields_out fields)
+{
+  importXAO( false, NULL, theBuff, shape, subShapes, groups, fields);
+  return IsDone();
+}
+
+//=============================================================================
+/*!
+ *  Import a shape from XAO format
+ *  \param isFile Boolean flag to switch between import from file or from buffer
+ *  \param fileName The name of the file to import from if isFile=true
+ *  \param theBuff The buffer to import from if isFile=false
+ *  \param shape The imported shape
+ *  \param subShapes The list of imported subShapes
+ *  \param groups The list of imported groups
+ *  \param fields The list of imported fields
+ *  \return boolean indicating if import was successful.
+ */
+//=============================================================================
+CORBA::Boolean XAOPlugin_IOperations_i::importXAO( const bool isFile,
+                                                   const char* fileName,
+                                                   const SALOMEDS::TMPFile& theBuff,
+                                                  GEOM::GEOM_Object_out shape,
+                                                  GEOM::ListOfGO_out subShapes,
+                                                  GEOM::ListOfGO_out groups,
+                                                  GEOM::ListOfFields_out fields)
 {
   GEOM::GEOM_Object_var vshape;
   shape = vshape._retn();
@@ -133,9 +235,21 @@ CORBA::Boolean XAOPlugin_IOperations_i::ImportXAO( const char* fileName,
   Handle(TColStd_HSequenceOfTransient) importedGroups = new TColStd_HSequenceOfTransient();
   Handle(TColStd_HSequenceOfTransient) importedFields = new TColStd_HSequenceOfTransient();
   Handle(GEOM_Object) hshape;
-  bool res = GetOperations()->ImportXAO( fileName, hshape, importedSubShapes, importedGroups, importedFields );
 
-  if( !GetOperations()->IsDone() || !res )
+  if (isFile) {
+    GetOperations()->ImportXAO( fileName, hshape, importedSubShapes, importedGroups, importedFields );
+  }
+  else {
+    if (theBuff.length() < 1)
+      return false;
+
+    char* buf = (char*)theBuff.NP_data();
+    //std::string anXMLBuff (buf); // works wrongly
+    std::string anXMLBuff (buf, theBuff.length());
+    GetOperations()->ImportXAOMem( anXMLBuff, hshape, importedSubShapes, importedGroups, importedFields );
+  }
+
+  if( !GetOperations()->IsDone() )
     return false;
 
   // parse fields
@@ -165,7 +279,7 @@ CORBA::Boolean XAOPlugin_IOperations_i::ImportXAO( const char* fileName,
 
   shape = GetObject( hshape );
 
-  return res;
+  return IsDone();
 }
 
 XAOPlugin_IOperations* XAOPlugin_IOperations_i::GetOperations()
index eb5bd721fa1190296440ab9861b0847f2b01f11b..a34b009130e094ba611a80b8660dd4d84b73cf8c 100644 (file)
@@ -50,13 +50,41 @@ public:
                             const char* fileName,
                             const char* shapeFileName );
 
+  SALOMEDS::TMPFile* ExportXAOMem( GEOM::GEOM_Object_ptr shape,
+                            const GEOM::ListOfGO& groups,
+                            const GEOM::ListOfFields& fields,
+                            const char* author );
+
   CORBA::Boolean ImportXAO( const char* fileName,
                             GEOM::GEOM_Object_out shape,
                             GEOM::ListOfGO_out subShapes,
                             GEOM::ListOfGO_out groups,
                             GEOM::ListOfFields_out fields );
 
+  CORBA::Boolean ImportXAOMem( const SALOMEDS::TMPFile& theBuff,
+                               GEOM::GEOM_Object_out shape,
+                               GEOM::ListOfGO_out subShapes,
+                               GEOM::ListOfGO_out groups,
+                               GEOM::ListOfFields_out fields );
+
   XAOPlugin_IOperations* GetOperations();
+
+private:
+  std::string exportXAO( GEOM::GEOM_Object_ptr shape,
+                         const GEOM::ListOfGO& groups,
+                         const GEOM::ListOfFields& fields,
+                         const char* author,
+                         const bool  toFile,
+                         const char* fileName,
+                         const char* shapeFileName );
+
+  CORBA::Boolean importXAO( const bool isFile,
+                            const char* fileName,
+                            const SALOMEDS::TMPFile& theBuff,
+                            GEOM::GEOM_Object_out shape,
+                            GEOM::ListOfGO_out subShapes,
+                            GEOM::ListOfGO_out groups,
+                            GEOM::ListOfFields_out fields );
 };
 
 #endif