Salome HOME
593bf5a94ed79e3b8b69a8a467a7507dd05ab59f
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_IGESImport.cpp
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <GeomAlgoAPI_IGESImport.h>
21
22 #include <TopoDS_Shape.hxx>
23
24 // OOCT includes
25 #include <IGESControl_Reader.hxx>
26 #include <IGESData_IGESModel.hxx>
27
28 //=============================================================================
29 /*!
30  *
31  */
32 //=============================================================================
33 std::shared_ptr<GeomAPI_Shape> IGESImport(const std::string& theFileName,
34                                           const std::string&,
35                                           std::string& theError)
36 {
37   #ifdef _DEBUG
38   std::cout << "Import IGES from file " << theFileName << std::endl;
39   #endif
40   TopoDS_Shape aShape;
41   IGESControl_Reader aReader;
42   try {
43     IFSelect_ReturnStatus status = aReader.ReadFile( theFileName.c_str() );
44
45     if (status == IFSelect_RetDone) {
46       #ifdef _DEBUG
47       std::cout << "ImportIGES : all Geometry Transfer" << std::endl;
48       #endif
49       aReader.ClearShapes();
50       aReader.TransferRoots();
51
52       #ifdef _DEBUG
53       std::cout << "ImportIGES : count of shapes produced = " << aReader.NbShapes() << std::endl;
54       #endif
55       aShape = aReader.OneShape();
56     }
57     else {
58       switch (status) {
59         case IFSelect_RetVoid:
60           theError = "Nothing created or No data to process";
61           break;
62         case IFSelect_RetError:
63           theError = "Error in command or input data";
64           break;
65         case IFSelect_RetFail:
66           theError = "Execution was run, but has failed";
67           break;
68         case IFSelect_RetStop:
69           theError = "Execution has been stopped. Quite possible, an exception was raised";
70           break;
71         default:
72           theError = "Wrong format of the imported file. Can't import file.";
73           break;
74       }
75       aShape.Nullify();
76     }
77   }
78   catch( Standard_Failure const& anException) {
79     theError = anException.GetMessageString();
80     aShape.Nullify();
81   }
82
83   std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
84   aGeomShape->setImpl(new TopoDS_Shape(aShape));
85   return aGeomShape;
86 }