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