1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESH_DriverStep.cxx
24 // Author : Yoann AUDOUIN, EDF
28 #include "SMESH_DriverStep.hxx"
30 #include <STEPControl_Reader.hxx>
31 #include <STEPControl_Writer.hxx>
32 #include <Interface_Static.hxx>
39 * @brief Compares two shape file (STEP)
41 * @param file1 first file
42 * @param file2 second file
44 * @return true if the files are the same
46 bool diffStepFile(std::string file1, std::string file2){
47 std::ifstream sfile1(file1);
48 std::ifstream sfile2(file2);
49 std::string line1, line2;
52 while(!sfile1.eof() && !sfile2.eof()){
53 std::getline(sfile1, line1);
54 std::getline(sfile2, line2);
56 // Skipping 4th line contain date of creation
58 std::cout << "Skipping line" << std::endl;
62 // if lines are different end of read
68 // True if we reached the end of both files
69 return sfile1.eof() && sfile2.eof();
73 * @brief Import the content of a shape file (STEP) into a TopDS_Shape object
75 * @param shape_file the shape file
76 * @param aShape the object
80 int importShape(const std::string shape_file, TopoDS_Shape& aShape){
82 std::cout << "Importing shape from " << shape_file << std::endl;
83 STEPControl_Reader reader;
84 // Forcing Unit in meter
85 Interface_Static::SetCVal("xstep.cascade.unit","M");
86 Interface_Static::SetIVal("read.step.ideas", 1);
87 Interface_Static::SetIVal("read.step.nonmanifold", 1);
88 IFSelect_ReturnStatus aStat = reader.ReadFile(shape_file.c_str());
89 if(aStat != IFSelect_RetDone)
90 std::cout << "Reading error for " << shape_file << std::endl;
92 int NbTrans = reader.TransferRoots();
93 // There should be only one shape within the file
95 aShape = reader.OneShape();
101 * @brief Export the content of a TopoDS_Shape into a shape file (STEP)
103 * @param shape_file the shape file
104 * @param aShape the object
108 int exportShape(const std::string shape_file, const TopoDS_Shape& aShape){
110 std::cout << "Exporting shape to " << shape_file << std::endl;
112 STEPControl_Writer aWriter;
113 // Forcing Unit in meter
114 Interface_Static::SetCVal("xstep.cascade.unit","M");
115 Interface_Static::SetCVal("write.step.unit","M");
116 Interface_Static::SetIVal("write.step.nonmanifold", 1);
118 IFSelect_ReturnStatus aStat = aWriter.Transfer(aShape,STEPControl_AsIs);
119 if(aStat != IFSelect_RetDone)
120 std::cout << "Transfer error for " << shape_file << std::endl;
122 aStat = aWriter.Write(shape_file.c_str());
124 if(aStat != IFSelect_RetDone)
125 std::cout << "Writing error for " << shape_file << std::endl;