Salome HOME
Implementation of ExportMEDCoupling.
[modules/smesh.git] / src / SMESH / SMESH_Mesh.cxx
index 315bf6544e97f85fdb4fc7f7b70fa1cfc1331340..d21330b4e83e5ca0544c0935cbbf91a5301a964c 100644 (file)
@@ -1392,48 +1392,17 @@ bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
   return false;
 }
 
-//================================================================================
-/*!
- * \brief Export the mesh to a med file
- *  \param [in] file - name of the MED file
- *  \param [in] theMeshName - name of this mesh
- *  \param [in] theAutoGroups - boolean parameter for creating/not creating
- *              the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
- *              the typical use is auto_groups=false.
- *  \param [in] theVersion - define the minor (xy, where version is x.y.z) of MED file format.
- *              If theVersion is equal to -1, the minor version is not changed (default).
- *  \param [in] meshPart - mesh data to export
- *  \param [in] theAutoDimension - if \c true, a space dimension of a MED mesh can be either
- *              - 1D if all mesh nodes lie on OX coordinate axis, or
- *              - 2D if all mesh nodes lie on XOY coordinate plane, or
- *              - 3D in the rest cases.
- *              If \a theAutoDimension is \c false, the space dimension is always 3.
- *  \param [in] theAddODOnVertices - to create 0D elements on all vertices
- *  \param [in] theAllElemsToGroup - to make every element to belong to any group (PAL23413)
- *  \param [in] ZTolerance - tolerance in Z direction. If Z coordinate of a node is close to zero
- *              within a given tolerance, the coordinate is set to zero.
- *              If \a ZTolerance is negative, the node coordinates are kept as is.
- *  \return int - mesh index in the file
- */
-//================================================================================
-
-void SMESH_Mesh::ExportMED(const char *        file,
+void SMESH_Mesh::ExportMEDCommmon(DriverMED_W_SMESHDS_Mesh& myWriter,
                            const char*         theMeshName,
                            bool                theAutoGroups,
-                           int                 theVersion,
                            const SMESHDS_Mesh* meshPart,
                            bool                theAutoDimension,
                            bool                theAddODOnVertices,
                            double              theZTolerance,
                            bool                theAllElemsToGroup)
 {
-  MESSAGE("MED_VERSION:"<< theVersion);
-
-  Driver_Mesh::Status status;
+  Driver_Mesh::Status status = Driver_Mesh::DRS_OK;
   SMESH_TRY;
-
-  DriverMED_W_SMESHDS_Mesh myWriter;
-  myWriter.SetFile         ( file , theVersion);
   myWriter.SetMesh         ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS   );
   myWriter.SetAutoDimension( theAutoDimension );
   myWriter.AddODOnVertices ( theAddODOnVertices );
@@ -1492,6 +1461,64 @@ void SMESH_Mesh::ExportMED(const char *        file,
     throw TooLargeForExport("MED");
 }
 
+/*!
+ * Same as SMESH_Mesh::ExportMED except for \a file and \a theVersion
+ */
+MEDCoupling::MCAuto<MEDCoupling::DataArrayByte> SMESH_Mesh::ExportMEDCoupling(
+                           const char*         theMeshName,
+                           bool                theAutoGroups,
+                           const SMESHDS_Mesh* meshPart,
+                           bool                theAutoDimension,
+                           bool                theAddODOnVertices,
+                           double              theZTolerance,
+                           bool                theAllElemsToGroup)
+{
+  DriverMED_W_SMESHDS_Mesh_Mem myWriter;
+  this->ExportMEDCommmon(myWriter,theMeshName,theAutoGroups,meshPart,theAutoDimension,theAddODOnVertices,theZTolerance,theAllElemsToGroup);
+  return myWriter.getData();
+}
+
+//================================================================================
+/*!
+ * \brief Export the mesh to a med file
+ *  \param [in] file - name of the MED file
+ *  \param [in] theMeshName - name of this mesh
+ *  \param [in] theAutoGroups - boolean parameter for creating/not creating
+ *              the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
+ *              the typical use is auto_groups=false.
+ *  \param [in] theVersion - define the minor (xy, where version is x.y.z) of MED file format.
+ *              If theVersion is equal to -1, the minor version is not changed (default).
+ *  \param [in] meshPart - mesh data to export
+ *  \param [in] theAutoDimension - if \c true, a space dimension of a MED mesh can be either
+ *              - 1D if all mesh nodes lie on OX coordinate axis, or
+ *              - 2D if all mesh nodes lie on XOY coordinate plane, or
+ *              - 3D in the rest cases.
+ *              If \a theAutoDimension is \c false, the space dimension is always 3.
+ *  \param [in] theAddODOnVertices - to create 0D elements on all vertices
+ *  \param [in] theAllElemsToGroup - to make every element to belong to any group (PAL23413)
+ *  \param [in] ZTolerance - tolerance in Z direction. If Z coordinate of a node is close to zero
+ *              within a given tolerance, the coordinate is set to zero.
+ *              If \a ZTolerance is negative, the node coordinates are kept as is.
+ *  \return int - mesh index in the file
+ */
+//================================================================================
+
+void SMESH_Mesh::ExportMED(const char *        file,
+                           const char*         theMeshName,
+                           bool                theAutoGroups,
+                           int                 theVersion,
+                           const SMESHDS_Mesh* meshPart,
+                           bool                theAutoDimension,
+                           bool                theAddODOnVertices,
+                           double              theZTolerance,
+                           bool                theAllElemsToGroup)
+{
+  MESSAGE("MED_VERSION:"<< theVersion);
+  DriverMED_W_SMESHDS_Mesh myWriter;
+  myWriter.SetFile( file , theVersion );
+  this->ExportMEDCommmon(myWriter,theMeshName,theAutoGroups,meshPart,theAutoDimension,theAddODOnVertices,theZTolerance,theAllElemsToGroup);
+}
+
 //================================================================================
 /*!
  * \brief Export the mesh to a SAUV file