diff --git a/src/SMESH/CMakeLists.txt b/src/SMESH/CMakeLists.txt index fee16b4cd..1cd4f0c16 100644 --- a/src/SMESH/CMakeLists.txt +++ b/src/SMESH/CMakeLists.txt @@ -92,6 +92,7 @@ SET(SMESHimpl_HEADERS SMESH_Homard.hxx ctpl.h DriverMesh.hxx + DriverStep.hxx ) # --- sources --- @@ -113,6 +114,7 @@ SET(SMESHimpl_SOURCES MG_ADAPT.cxx SMESH_Homard.cxx DriverMesh.cxx + DriverStep.cxx ) # --- rules --- diff --git a/src/SMESH/DriverMesh.cxx b/src/SMESH/DriverMesh.cxx new file mode 100644 index 000000000..29d4a6fa5 --- /dev/null +++ b/src/SMESH/DriverMesh.cxx @@ -0,0 +1,95 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : DriverMesh.cxx +// Author : Yoann AUDOUIN, EDF +// Module : SMESH +// + +#include "DriverMesh.hxx" + +#include "SMESH_Mesh.hxx" +#include "SMESH_Gen.hxx" + +#include +#include + +using namespace MEDCoupling; + +/** + * @brief Compares the mesh from two mesh files (MED) + * + * @param mesh_file1 First file + * @param mesh_file2 Second file + * @param mesh_name Name of the mesh in the files + * + * @return true if the mesh within the files are identical + */ +bool diff_med_file(const std::string mesh_file1, const std::string mesh_file2, const std::string mesh_name){ + MEDFileUMesh* medmesh1 = MEDFileUMesh::New(mesh_file1, mesh_name); + MEDFileUMesh* medmesh2 = MEDFileUMesh::New(mesh_file2, mesh_name); + MEDCouplingUMesh *m0_1=medmesh1->getMeshAtLevel(0,false); + MEDCouplingUMesh *m0_2=medmesh2->getMeshAtLevel(0,false); + return m0_1->isEqual(m0_2, 1e-12); +} + +/** + * @brief Import a mesh from a mesh file (MED) into a SMESH_Mesh object + * + * @param mesh_file the file + * @param aMesh the object + * @param mesh_name the name of the mesh in the file + * + * @return error code + */ +int import_mesh(const std::string mesh_file, SMESH_Mesh& aMesh, const std::string mesh_name){ + // TODO: change that as it depends on the language + std::cout << "Importing mesh from " << mesh_file << std::endl; + int ret = aMesh.MEDToMesh(mesh_file.c_str(), mesh_name.c_str()); + return ret; +} + +/** + * @brief Export the content of a SMESH_Mesh into a mesh file (MED) + * + * @param mesh_file the file + * @param aMesh the object + * @param mesh_name name of the mesh in the file + * + * @return error code + */ +int export_mesh(const std::string mesh_file, SMESH_Mesh& aMesh, const std::string mesh_name){ + + // TODO: See how to get the name of the mesh. Is it usefull ? + std::cout << "Exporting mesh to " << mesh_file << std::endl; + aMesh.ExportMED(mesh_file.c_str(), // theFile + mesh_name.c_str(), // theMeshName + false, // theAutoGroups + -1, // theVersion + nullptr, // theMeshPart + true, // theAutoDimension + true, // theAddODOnVertices + 1e-8, // theZTolerance + true // theSaveNumbers + ); + return true; +} diff --git a/src/SMESH/DriverMesh.hxx b/src/SMESH/DriverMesh.hxx new file mode 100644 index 000000000..5a1485faf --- /dev/null +++ b/src/SMESH/DriverMesh.hxx @@ -0,0 +1,46 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : DriverMesh.hxx +// Author : Yoann AUDOUIN, EDF +// Module : SMESH +// + +#ifndef _DRIVERMESH_HXX_ +#define _DRIVERMESH_HXX_ + +#include +#include + +class SMESH_Mesh; + +bool diff_med_file(const std::string mesh_file1, + const std::string mesh_file2, + const std::string mesh_name); +int import_mesh(const std::string mesh_file, + SMESH_Mesh& aMesh, + const std::string meshName); +int export_mesh(const std::string mesh_file, + SMESH_Mesh& aMesh, + const std::string meshName); + +#endif diff --git a/src/SMESH/DriverStep.cxx b/src/SMESH/DriverStep.cxx new file mode 100644 index 000000000..54d4e8de5 --- /dev/null +++ b/src/SMESH/DriverStep.cxx @@ -0,0 +1,128 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : DriverStep.cxx +// Author : Yoann AUDOUIN, EDF +// Module : SMESH +// + +#include "DriverStep.hxx" + +#include +#include +#include + +//Occ include +#include + + +/** + * @brief Compares two shape file (STEP) + * + * @param file1 first file + * @param file2 second file + * + * @return true if the files are the same + */ +bool diff_step_file(std::string file1, std::string file2){ + std::ifstream sfile1(file1); + std::ifstream sfile2(file2); + std::string line1, line2; + int nb_lines = 0; + + while(!sfile1.eof() && !sfile2.eof()){ + std::getline(sfile1, line1); + std::getline(sfile2, line2); + nb_lines++; + // Skipping 4th line contain date of creation + if (nb_lines==4){ + std::cout << "Skipping line" << std::endl; + continue; + } + + // if lines are different end of read + if(line1 != line2){ + return false; + } + + } + // True if we reached the end of both files + return sfile1.eof() && sfile2.eof(); +} + +/** + * @brief Import the content of a shape file (STEP) into a TopDS_Shape object + * + * @param shape_file the shape file + * @param aShape the object + * + * @return error code + */ +int import_shape(const std::string shape_file, TopoDS_Shape& aShape){ + + std::cout << "Importing shape from " << shape_file << std::endl; + STEPControl_Reader reader; + // Forcing Unit in meter + Interface_Static::SetCVal("xstep.cascade.unit","M"); + Interface_Static::SetIVal("read.step.ideas", 1); + Interface_Static::SetIVal("read.step.nonmanifold", 1); + IFSelect_ReturnStatus aStat = reader.ReadFile(shape_file.c_str()); + if(aStat != IFSelect_RetDone) + std::cout << "Reading error for " << shape_file << std::endl; + + int NbTrans = reader.TransferRoots(); + // There should be only one shape within the file + assert(NbTrans==1); + aShape = reader.OneShape(); + + return true; +} + +/** + * @brief Export the content of a TopoDS_Shape into a shape file (STEP) + * + * @param shape_file the shape file + * @param aShape the object + * + * @return error code + */ +int export_shape(const std::string shape_file, const TopoDS_Shape& aShape){ + + std::cout << "Exporting shape to " << shape_file << std::endl; + + STEPControl_Writer aWriter; + // Forcing Unit in meter + Interface_Static::SetCVal("xstep.cascade.unit","M"); + Interface_Static::SetCVal("write.step.unit","M"); + Interface_Static::SetIVal("write.step.nonmanifold", 1); + + IFSelect_ReturnStatus aStat = aWriter.Transfer(aShape,STEPControl_AsIs); + if(aStat != IFSelect_RetDone) + std::cout << "Transfer error for " << shape_file << std::endl; + + aStat = aWriter.Write(shape_file.c_str()); + + if(aStat != IFSelect_RetDone) + std::cout << "Writing error for " << shape_file << std::endl; + + return aStat; +} diff --git a/src/SMESH/DriverStep.hxx b/src/SMESH/DriverStep.hxx new file mode 100644 index 000000000..ab13d1e52 --- /dev/null +++ b/src/SMESH/DriverStep.hxx @@ -0,0 +1,41 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : DriverStep.hxx +// Author : Yoann AUDOUIN, EDF +// Module : SMESH +// + +#ifndef _DRIVERSTEP_HXX_ +#define _DRIVERSTEP_HXX_ + +#include +#include + +class TopoDS_Shape; + +int import_shape(const std::string shape_file, TopoDS_Shape& aShape); +int export_shape(const std::string shape_file, const TopoDS_Shape& aShape); +bool diff_step_file(std::string file1, std::string file2); + + +#endif \ No newline at end of file