Salome HOME
cc46fda83e713cb9a4f3315176415938bd7e36fd
[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, const TDF_Label&)
19 {
20   #ifdef _DEBUG
21   std::cout << "Import IGES from file " << theFileName << std::endl;
22   #endif
23   TopoDS_Shape aResShape;
24
25 //  bool anIsIgnoreUnits = false;
26
27   IGESControl_Reader aReader;
28   try {
29     IFSelect_ReturnStatus status = aReader.ReadFile( theFileName.ToCString() );
30
31     if (status == IFSelect_RetDone) {
32 //      if( anIsIgnoreUnits ) {
33 //        // need re-scale a model, set UnitFlag to 'meter'
34 //        Handle(IGESData_IGESModel) aModel =
35 //          Handle(IGESData_IGESModel)::DownCast( aReader.Model() );
36 //        if( !aModel.IsNull() ) {
37 //          IGESData_GlobalSection aGS = aModel->GlobalSection();
38 //          aGS.SetUnitFlag(6);
39 //          aModel->SetGlobalSection(aGS);
40 //        }
41 //      }
42
43       #ifdef _DEBUG
44       std::cout << "ImportIGES : all Geometry Transfer" << std::endl;
45       #endif
46       aReader.ClearShapes();
47       aReader.TransferRoots();
48
49       #ifdef _DEBUG
50       std::cout << "ImportIGES : count of shapes produced = " << aReader.NbShapes() << std::endl;
51       #endif
52       aResShape = aReader.OneShape();
53     }
54     else {
55       switch (status) {
56         case IFSelect_RetVoid:
57           theError = "Nothing created or No data to process";
58           break;
59         case IFSelect_RetError:
60           theError = "Error in command or input data";
61           break;
62         case IFSelect_RetFail:
63           theError = "Execution was run, but has failed";
64           break;
65         case IFSelect_RetStop:
66           theError = "Execution has been stopped. Quite possible, an exception was raised";
67           break;
68         default:
69           theError = "Wrong format of the imported file. Can't import file.";
70           break;
71         }
72       aResShape.Nullify();
73     }
74   }
75   catch( Standard_Failure ) {
76     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
77     theError = aFail->GetMessageString();
78     aResShape.Nullify();
79   }
80
81   return aResShape;
82 }
83
84 }
85 //}