From 78c4fca7f3bd6133ac9a8c41aa5f3f617546b686 Mon Sep 17 00:00:00 2001 From: Yoann Audouin Date: Thu, 15 Sep 2022 15:12:22 +0200 Subject: [PATCH] Adding support for BRep for shape --- src/SMESH/CMakeLists.txt | 4 +- ...H_DriverStep.cxx => SMESH_DriverShape.cxx} | 129 ++++++++++++------ ...H_DriverStep.hxx => SMESH_DriverShape.hxx} | 8 +- src/SMESH/SMESH_Mesh.cxx | 4 +- 4 files changed, 96 insertions(+), 49 deletions(-) rename src/SMESH/{SMESH_DriverStep.cxx => SMESH_DriverShape.cxx} (54%) rename src/SMESH/{SMESH_DriverStep.hxx => SMESH_DriverShape.hxx} (88%) diff --git a/src/SMESH/CMakeLists.txt b/src/SMESH/CMakeLists.txt index 75c964b99..afe512509 100644 --- a/src/SMESH/CMakeLists.txt +++ b/src/SMESH/CMakeLists.txt @@ -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_DriverStep.cxx b/src/SMESH/SMESH_DriverShape.cxx similarity index 54% rename from src/SMESH/SMESH_DriverStep.cxx rename to src/SMESH/SMESH_DriverShape.cxx index b19be4891..572da3e1e 100644 --- a/src/SMESH/SMESH_DriverStep.cxx +++ b/src/SMESH/SMESH_DriverShape.cxx @@ -20,54 +20,28 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File : SMESH_DriverStep.cxx +// File : SMESH_DriverShape.cxx // Author : Yoann AUDOUIN, EDF // Module : SMESH // -#include "SMESH_DriverStep.hxx" +#include "SMESH_DriverShape.hxx" +// step include #include #include #include +// Brep 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 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(); -} +#include +#include +namespace fs = boost::filesystem; /** * @brief Import the content of a shape file (STEP) into a TopDS_Shape object @@ -77,9 +51,9 @@ bool diffStepFile(std::string file1, std::string file2){ * * @return error code */ -int importShape(const std::string shape_file, TopoDS_Shape& aShape){ +int importSTEPShape(const std::string shape_file, TopoDS_Shape& aShape){ - std::cout << "Importing shape from " << shape_file << std::endl; + std::cout << "Importing STEP shape from " << shape_file << std::endl; STEPControl_Reader reader; // Forcing Unit in meter Interface_Static::SetCVal("xstep.cascade.unit","M"); @@ -105,9 +79,9 @@ int importShape(const std::string shape_file, TopoDS_Shape& aShape){ * * @return error code */ -int exportShape(const std::string shape_file, const TopoDS_Shape& aShape){ +int exportSTEPShape(const std::string shape_file, const TopoDS_Shape& aShape){ - std::cout << "Exporting shape to " << shape_file << std::endl; + std::cout << "Exporting STEP shape to " << shape_file << std::endl; STEPControl_Writer aWriter; // Forcing Unit in meter @@ -126,3 +100,78 @@ int exportShape(const std::string shape_file, const TopoDS_Shape& aShape){ 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_DriverStep.hxx b/src/SMESH/SMESH_DriverShape.hxx similarity index 88% rename from src/SMESH/SMESH_DriverStep.hxx rename to src/SMESH/SMESH_DriverShape.hxx index 18158ae49..b9e3a360e 100644 --- a/src/SMESH/SMESH_DriverStep.hxx +++ b/src/SMESH/SMESH_DriverShape.hxx @@ -20,13 +20,13 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File : SMESH_DriverStep.hxx +// File : SMESH_DriverShape.hxx // Author : Yoann AUDOUIN, EDF // Module : SMESH // -#ifndef _SMESH_DRIVERSTEP_HXX_ -#define _SMESH_DRIVERSTEP_HXX_ +#ifndef _SMESH_DRIVERSHAPE_HXX_ +#define _SMESH_DRIVERSHAPE_HXX_ #include #include @@ -35,7 +35,5 @@ 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 diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index a7bd39126..a3602c1ad 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -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); } } -- 2.39.2