Salome HOME
Adding support for BRep for shape
authorYoann Audouin <yoann.audouin@edf.fr>
Thu, 15 Sep 2022 13:12:22 +0000 (15:12 +0200)
committerYoann Audouin <yoann.audouin@edf.fr>
Tue, 18 Oct 2022 13:02:19 +0000 (15:02 +0200)
src/SMESH/CMakeLists.txt
src/SMESH/SMESH_DriverShape.cxx [new file with mode: 0644]
src/SMESH/SMESH_DriverShape.hxx [new file with mode: 0644]
src/SMESH/SMESH_DriverStep.cxx [deleted file]
src/SMESH/SMESH_DriverStep.hxx [deleted file]
src/SMESH/SMESH_Mesh.cxx

index 75c964b9970c54574aece7784c22a3bca0b7e497..afe51250917f5f0e5bada4349c4c072903f962b4 100644 (file)
@@ -91,7 +91,7 @@ SET(SMESHimpl_HEADERS
   MG_ADAPT.hxx
   SMESH_Homard.hxx
   SMESH_DriverMesh.hxx
-  SMESH_DriverStep.hxx
+  SMESH_DriverShape.hxx
 )
 
 # --- sources ---
@@ -113,7 +113,7 @@ SET(SMESHimpl_SOURCES
   MG_ADAPT.cxx
   SMESH_Homard.cxx
   SMESH_DriverMesh.cxx
-  SMESH_DriverStep.cxx
+  SMESH_DriverShape.cxx
 )
 
 # --- rules ---
diff --git a/src/SMESH/SMESH_DriverShape.cxx b/src/SMESH/SMESH_DriverShape.cxx
new file mode 100644 (file)
index 0000000..572da3e
--- /dev/null
@@ -0,0 +1,177 @@
+// 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   : SMESH_DriverShape.cxx
+//  Author : Yoann AUDOUIN, EDF
+//  Module : SMESH
+//
+
+#include "SMESH_DriverShape.hxx"
+
+// step include
+#include <STEPControl_Reader.hxx>
+#include <STEPControl_Writer.hxx>
+#include <Interface_Static.hxx>
+
+// Brep include
+#include <BRepTools.hxx>
+#include <BRep_Builder.hxx>
+
+//Occ include
+#include <TopoDS.hxx>
+
+#include <boost/filesystem.hpp>
+#include <boost/algorithm/string.hpp>
+namespace fs = boost::filesystem;
+
+/**
+ * @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 importSTEPShape(const std::string shape_file, TopoDS_Shape& aShape){
+
+  std::cout << "Importing STEP 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 exportSTEPShape(const std::string shape_file, const TopoDS_Shape& aShape){
+
+  std::cout << "Exporting STEP 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;
+}
+
+/**
+ * @brief Import the content of a shape file (BREP) into a TopDS_Shape object
+ *
+ * @param shape_file the shape file
+ * @param aShape the object
+ *
+ * @return error code
+ */
+int importBREPShape(const std::string shape_file, TopoDS_Shape& aShape){
+
+  std::cout << "Importing BREP shape from " << shape_file << std::endl;
+  BRep_Builder builder;
+  BRepTools::Read(aShape, shape_file.c_str(), builder);
+
+  return true;
+}
+
+/**
+ * @brief Export the content of a TopoDS_Shape into a shape file (BREP)
+ *
+ * @param shape_file the shape file
+ * @param aShape the object
+ *
+ * @return error code
+ */
+int exportBREPShape(const std::string shape_file, const TopoDS_Shape& aShape){
+
+  std::cout << "Exporting BREP shape to " << shape_file << std::endl;
+  BRepTools::Write(aShape, shape_file.c_str());
+
+  return true;
+}
+
+/**
+ * @brief Import the content of a shape file into a TopDS_Shape object
+ *
+ * @param shape_file the shape file
+ * @param aShape the object
+ *
+ * @return error code
+ */
+int importShape(const std::string shape_file, TopoDS_Shape& aShape){
+  std::string type = fs::path(shape_file).extension().string();
+  boost::algorithm::to_lower(type);
+  if (type == ".brep"){
+    return importBREPShape(shape_file, aShape);
+  } else if (type == ".step"){
+    return importSTEPShape(shape_file, aShape);
+  } else {
+    std::cout << "Unknow format: " << type << std::endl;
+    return false;
+  }
+}
+
+/**
+ * @brief Import the content of a shape file into a TopDS_Shape object
+ *
+ * @param shape_file the shape file
+ * @param aShape the object
+ *
+ * @return error code
+ */
+int exportShape(const std::string shape_file, const TopoDS_Shape& aShape){
+  std::string type = fs::path(shape_file).extension().string();
+  boost::algorithm::to_lower(type);
+  if (type == ".brep"){
+    return exportBREPShape(shape_file, aShape);
+  } else if (type == ".step"){
+    return exportSTEPShape(shape_file, aShape);
+  } else {
+    std::cout << "Unknow format: " << type << std::endl;
+    return false;
+  }
+}
diff --git a/src/SMESH/SMESH_DriverShape.hxx b/src/SMESH/SMESH_DriverShape.hxx
new file mode 100644 (file)
index 0000000..b9e3a36
--- /dev/null
@@ -0,0 +1,39 @@
+// 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   : SMESH_DriverShape.hxx
+//  Author : Yoann AUDOUIN, EDF
+//  Module : SMESH
+//
+
+#ifndef _SMESH_DRIVERSHAPE_HXX_
+#define _SMESH_DRIVERSHAPE_HXX_
+
+#include <string>
+#include <cassert>
+
+class TopoDS_Shape;
+
+int importShape(const std::string shape_file, TopoDS_Shape& aShape);
+int exportShape(const std::string shape_file, const TopoDS_Shape& aShape);
+
+#endif
\ No newline at end of file
diff --git a/src/SMESH/SMESH_DriverStep.cxx b/src/SMESH/SMESH_DriverStep.cxx
deleted file mode 100644 (file)
index b19be48..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-// 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   : SMESH_DriverStep.cxx
-//  Author : Yoann AUDOUIN, EDF
-//  Module : SMESH
-//
-
-#include "SMESH_DriverStep.hxx"
-
-#include <STEPControl_Reader.hxx>
-#include <STEPControl_Writer.hxx>
-#include <Interface_Static.hxx>
-
-//Occ include
-#include <TopoDS.hxx>
-
-
-/**
- * @brief Compares two shape file (STEP)
- *
- * @param file1 first file
- * @param file2 second file
- *
- * @return true if the files are the same
- */
-bool diffStepFile(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 importShape(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 exportShape(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/SMESH_DriverStep.hxx b/src/SMESH/SMESH_DriverStep.hxx
deleted file mode 100644 (file)
index 18158ae..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-// 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   : SMESH_DriverStep.hxx
-//  Author : Yoann AUDOUIN, EDF
-//  Module : SMESH
-//
-
-#ifndef _SMESH_DRIVERSTEP_HXX_
-#define _SMESH_DRIVERSTEP_HXX_
-
-#include <string>
-#include <cassert>
-
-class TopoDS_Shape;
-
-int importShape(const std::string shape_file, TopoDS_Shape& aShape);
-int exportShape(const std::string shape_file, const TopoDS_Shape& aShape);
-bool diffStepFile(std::string file1, std::string file2);
-
-
-#endif
\ No newline at end of file
index a7bd39126142b3b6b0750e004123f6fe3af2e91a..a3602c1ad134b432810fa828bd624fd702a89159 100644 (file)
@@ -87,7 +87,7 @@ namespace fs=boost::filesystem;
 #define MAX_MED_GROUP_NAME_LENGTH 80
 
 #ifdef _DEBUG_
-static int MYDEBUG = 0;
+static int MYDEBUG = 1;
 #else
 static int MYDEBUG = 0;
 #endif
@@ -241,7 +241,7 @@ SMESH_Mesh::~SMESH_Mesh()
     int result=pthread_create(&thread, NULL, deleteMeshDS, (void*)_meshDS);
 #endif
 
-  fs::remove_all(tmp_folder);
+  //fs::remove_all(tmp_folder);
 
   }
 }