Salome HOME
872d8b3f5a7339521e3e044ff8332c30934a9d2d
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_IGESImport.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include <GeomAlgoAPI_IGESImport.h>
4
5 // OOCT includes
6 #include <IGESControl_Reader.hxx>
7 #include <IGESData_IGESModel.hxx>
8
9 //=============================================================================
10 /*!
11  *
12  */
13 //=============================================================================
14 TopoDS_Shape IGESImport(const std::string& theFileName,
15                         const std::string&,
16                         std::string& theError)
17 {
18   #ifdef _DEBUG
19   std::cout << "Import IGES from file " << theFileName << std::endl;
20   #endif
21   TopoDS_Shape aResShape;
22   IGESControl_Reader aReader;
23   try {
24     IFSelect_ReturnStatus status = aReader.ReadFile( theFileName.c_str() );
25
26     if (status == IFSelect_RetDone) {
27       #ifdef _DEBUG
28       std::cout << "ImportIGES : all Geometry Transfer" << std::endl;
29       #endif
30       aReader.ClearShapes();
31       aReader.TransferRoots();
32
33       #ifdef _DEBUG
34       std::cout << "ImportIGES : count of shapes produced = " << aReader.NbShapes() << std::endl;
35       #endif
36       aResShape = aReader.OneShape();
37     }
38     else {
39       switch (status) {
40         case IFSelect_RetVoid:
41           theError = "Nothing created or No data to process";
42           break;
43         case IFSelect_RetError:
44           theError = "Error in command or input data";
45           break;
46         case IFSelect_RetFail:
47           theError = "Execution was run, but has failed";
48           break;
49         case IFSelect_RetStop:
50           theError = "Execution has been stopped. Quite possible, an exception was raised";
51           break;
52         default:
53           theError = "Wrong format of the imported file. Can't import file.";
54           break;
55       }
56       aResShape.Nullify();
57     }
58   }
59   catch( Standard_Failure ) {
60     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
61     theError = aFail->GetMessageString();
62     aResShape.Nullify();
63   }
64
65   return aResShape;
66 }