Salome HOME
Issue #529 : 4.07. Import IGES, export to BREP, STEP, IGES - Remove redundant code...
[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 //extern "C" {
15 namespace IGESImport {
16 TopoDS_Shape Import(const TCollection_AsciiString& theFileName,
17                     const TCollection_AsciiString&,
18                     TCollection_AsciiString& theError)
19 {
20   #ifdef _DEBUG
21   std::cout << "Import IGES from file " << theFileName << std::endl;
22   #endif
23   TopoDS_Shape aResShape;
24   IGESControl_Reader aReader;
25   try {
26     IFSelect_ReturnStatus status = aReader.ReadFile( theFileName.ToCString() );
27
28     if (status == IFSelect_RetDone) {
29       #ifdef _DEBUG
30       std::cout << "ImportIGES : all Geometry Transfer" << std::endl;
31       #endif
32       aReader.ClearShapes();
33       aReader.TransferRoots();
34
35       #ifdef _DEBUG
36       std::cout << "ImportIGES : count of shapes produced = " << aReader.NbShapes() << std::endl;
37       #endif
38       aResShape = aReader.OneShape();
39     }
40     else {
41       switch (status) {
42         case IFSelect_RetVoid:
43           theError = "Nothing created or No data to process";
44           break;
45         case IFSelect_RetError:
46           theError = "Error in command or input data";
47           break;
48         case IFSelect_RetFail:
49           theError = "Execution was run, but has failed";
50           break;
51         case IFSelect_RetStop:
52           theError = "Execution has been stopped. Quite possible, an exception was raised";
53           break;
54         default:
55           theError = "Wrong format of the imported file. Can't import file.";
56           break;
57       }
58       aResShape.Nullify();
59     }
60   }
61   catch( Standard_Failure ) {
62     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
63     theError = aFail->GetMessageString();
64     aResShape.Nullify();
65   }
66
67   return aResShape;
68 }
69
70 }
71 //}