]> SALOME platform Git repositories - modules/geom.git/blob - src/STEPImport/STEPImport.cxx
Salome HOME
02a0dd823b2e6a8b04fbb8627370e204ce1900e1
[modules/geom.git] / src / STEPImport / STEPImport.cxx
1 // File:        STEPImport.cxx
2 // Created:     Wed May 19 14:41:10 2004
3 // Author:      Pavel TELKOV
4 //              <ptv@mutex.nnov.opencascade.com>
5
6 #include "utilities.h"
7
8 #include <BRep_Builder.hxx>
9
10 #include <IFSelect_ReturnStatus.hxx>
11
12 #include <STEPControl_Reader.hxx>
13
14 #include <TCollection_AsciiString.hxx>
15 #include <TopoDS_Compound.hxx>
16 #include <TopoDS_Shape.hxx>
17
18 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
19
20 //=============================================================================
21 /*!
22  *  Import()
23  */
24 //=============================================================================
25
26 extern "C"
27 {
28 #ifdef WNT
29   __declspec(__dllexport)
30 #endif
31   TopoDS_Shape Import (const TCollection_AsciiString& theFileName,
32                        TCollection_AsciiString&       theError)
33   {
34     MESSAGE("Import STEP model from file " << theFileName.ToCString());
35     TopoDS_Shape aResShape;
36     //VRV: OCC 4.0 migration
37     STEPControl_Reader aReader;
38     //VRV: OCC 4.0 migration
39     TopoDS_Compound compound;
40     BRep_Builder B;
41     B.MakeCompound( compound );
42     try {
43       IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
44
45       if (status == IFSelect_RetDone) {
46         Standard_Boolean failsonly = Standard_False ;
47         aReader.PrintCheckLoad (failsonly, IFSelect_ItemsByEntity);
48         /* Root transfers */
49         Standard_Integer nbr = aReader.NbRootsForTransfer();
50         aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
51
52         for ( Standard_Integer n=1; n <= nbr; n++) {
53           Standard_Boolean ok = aReader.TransferRoot(n);
54           /* Collecting resulting entities */
55           Standard_Integer nbs = aReader.NbShapes();
56           if (!ok || nbs == 0)
57           {
58             // THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM);
59             continue; // skip empty root
60           }
61           /* For a single entity */
62           else if (nbr == 1 && nbs == 1) {
63             aResShape = aReader.Shape(1);
64             break;
65           }
66
67           for ( Standard_Integer i=1; i<=nbs; i++ ) {
68             TopoDS_Shape aShape = aReader.Shape(i);
69             if ( aShape.IsNull() ) {
70               // THROW_SALOME_CORBA_EXCEPTION("Null shape in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ;
71               //return aResShape;
72               continue;
73             }
74             else {
75               B.Add( compound, aShape ) ;
76             }
77           }
78         }
79         if ( aResShape.IsNull() )
80           aResShape = compound;
81
82       } else {
83 //        switch (status) {
84 //        case IFSelect_RetVoid:
85 //          theError = "Nothing created or No data to process";
86 //          break;
87 //        case IFSelect_RetError:
88 //          theError = "Error in command or input data";
89 //          break;
90 //        case IFSelect_RetFail:
91 //          theError = "Execution was run, but has failed";
92 //          break;
93 //        case IFSelect_RetStop:
94 //          theError = "Execution has been stopped. Quite possible, an exception was raised";
95 //          break;
96 //        default:
97 //          break;
98 //        }
99         theError = "Wrong format of the imported file. Can't import file.";
100         aResShape.Nullify();
101       }
102     }
103     catch (Standard_Failure) {
104       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
105       theError = aFail->GetMessageString();
106       aResShape.Nullify();
107     }
108     return aResShape;
109   }
110 }