Salome HOME
Adding support for BRep for shape
[modules/smesh.git] / src / SMESH / SMESH_DriverMesh.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  File   : SMESH_DriverMesh.cxx
24 //  Author : Yoann AUDOUIN, EDF
25 //  Module : SMESH
26 //
27
28 #include "SMESH_DriverMesh.hxx"
29
30 #include "SMESH_Mesh.hxx"
31 #include "SMESH_Gen.hxx"
32
33 #include <MEDFileMesh.hxx>
34 #include <MEDCouplingUMesh.hxx>
35
36 using namespace MEDCoupling;
37
38 /**
39  * @brief Compares the mesh from two mesh files (MED)
40  *
41  * @param mesh_file1 First file
42  * @param mesh_file2 Second file
43  * @param mesh_name Name of the mesh in the files
44  *
45  * @return true if the mesh within the files are identical
46  */
47 bool diffMEDFile(const std::string mesh_file1, const std::string mesh_file2, const std::string mesh_name){
48   MEDFileUMesh* medmesh1 = MEDFileUMesh::New(mesh_file1, mesh_name);
49   MEDFileUMesh* medmesh2 = MEDFileUMesh::New(mesh_file2, mesh_name);
50   MEDCouplingUMesh *m0_1=medmesh1->getMeshAtLevel(0,false);
51   MEDCouplingUMesh *m0_2=medmesh2->getMeshAtLevel(0,false);
52   return m0_1->isEqual(m0_2, 1e-12);
53 }
54
55 /**
56  * @brief Import a mesh from a mesh file (MED) into a SMESH_Mesh object
57  *
58  * @param mesh_file the file
59  * @param aMesh the object
60  * @param mesh_name the name of the mesh in the file
61  *
62  * @return error code
63  */
64 int importMesh(const std::string mesh_file, SMESH_Mesh& aMesh, const std::string mesh_name){
65   // TODO: change that as it depends on the language
66   std::cout << "Importing mesh from " << mesh_file << std::endl;
67   int ret = aMesh.MEDToMesh(mesh_file.c_str(), mesh_name.c_str());
68   return ret;
69 }
70
71 /**
72  * @brief Export the content of a SMESH_Mesh into a mesh file (MED)
73  *
74  * @param mesh_file the file
75  * @param aMesh the object
76  * @param mesh_name name of the mesh in the file
77  *
78  * @return error code
79  */
80 int exportMesh(const std::string mesh_file, SMESH_Mesh& aMesh, const std::string mesh_name){
81
82   // TODO: See how to get the name of the mesh. Is it usefull ?
83   std::cout << "Exporting mesh to " << mesh_file << std::endl;
84   aMesh.ExportMED(mesh_file.c_str(), // theFile
85                   mesh_name.c_str(), // theMeshName
86                   false, // theAutoGroups
87                   -1, // theVersion
88                   nullptr, // theMeshPart
89                   true, // theAutoDimension
90                   true, // theAddODOnVertices
91                   1e-8, // theZTolerance
92                   true // theSaveNumbers
93                   );
94   return true;
95 }