1 // File: STEPImport.cxx
2 // Created: Wed May 19 14:41:10 2004
3 // Author: Pavel TELKOV
4 // <ptv@mutex.nnov.opencascade.com>
8 #include <BRep_Builder.hxx>
10 #include <IFSelect_ReturnStatus.hxx>
12 #include <STEPControl_Reader.hxx>
14 #include <TCollection_AsciiString.hxx>
15 #include <TopoDS_Compound.hxx>
16 #include <TopoDS_Shape.hxx>
18 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
21 #include <SALOME_WNT.hxx>
23 #define SALOME_WNT_EXPORT
26 //=============================================================================
30 //=============================================================================
35 TopoDS_Shape Import (const TCollection_AsciiString& theFileName,
36 TCollection_AsciiString& theError)
38 MESSAGE("Import STEP model from file " << theFileName.ToCString());
39 TopoDS_Shape aResShape;
40 //VRV: OCC 4.0 migration
41 STEPControl_Reader aReader;
42 //VRV: OCC 4.0 migration
43 TopoDS_Compound compound;
45 B.MakeCompound( compound );
47 IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
49 if (status == IFSelect_RetDone) {
50 Standard_Boolean failsonly = Standard_False ;
51 aReader.PrintCheckLoad (failsonly, IFSelect_ItemsByEntity);
53 Standard_Integer nbr = aReader.NbRootsForTransfer();
54 aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
56 for ( Standard_Integer n=1; n <= nbr; n++) {
57 Standard_Boolean ok = aReader.TransferRoot(n);
58 /* Collecting resulting entities */
59 Standard_Integer nbs = aReader.NbShapes();
62 // THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM);
63 continue; // skip empty root
65 /* For a single entity */
66 else if (nbr == 1 && nbs == 1) {
67 aResShape = aReader.Shape(1);
71 for ( Standard_Integer i=1; i<=nbs; i++ ) {
72 TopoDS_Shape aShape = aReader.Shape(i);
73 if ( aShape.IsNull() ) {
74 // THROW_SALOME_CORBA_EXCEPTION("Null shape in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ;
79 B.Add( compound, aShape ) ;
83 if ( aResShape.IsNull() )
88 // case IFSelect_RetVoid:
89 // theError = "Nothing created or No data to process";
91 // case IFSelect_RetError:
92 // theError = "Error in command or input data";
94 // case IFSelect_RetFail:
95 // theError = "Execution was run, but has failed";
97 // case IFSelect_RetStop:
98 // theError = "Execution has been stopped. Quite possible, an exception was raised";
103 theError = "Wrong format of the imported file. Can't import file.";
107 catch (Standard_Failure) {
108 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
109 theError = aFail->GetMessageString();