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
20 //=============================================================================
24 //=============================================================================
29 __declspec(__dllexport)
31 TopoDS_Shape Import (const TCollection_AsciiString& theFileName,
32 TCollection_AsciiString& theError)
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;
41 B.MakeCompound( compound );
43 IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
45 if (status == IFSelect_RetDone) {
46 Standard_Boolean failsonly = Standard_False ;
47 aReader.PrintCheckLoad (failsonly, IFSelect_ItemsByEntity);
49 Standard_Integer nbr = aReader.NbRootsForTransfer();
50 aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
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();
58 // THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM);
59 continue; // skip empty root
61 /* For a single entity */
62 else if (nbr == 1 && nbs == 1) {
63 aResShape = aReader.Shape(1);
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) ;
75 B.Add( compound, aShape ) ;
79 if ( aResShape.IsNull() )
84 // case IFSelect_RetVoid:
85 // theError = "Nothing created or No data to process";
87 // case IFSelect_RetError:
88 // theError = "Error in command or input data";
90 // case IFSelect_RetFail:
91 // theError = "Execution was run, but has failed";
93 // case IFSelect_RetStop:
94 // theError = "Execution has been stopped. Quite possible, an exception was raised";
99 theError = "Wrong format of the imported file. Can't import file.";
103 catch (Standard_Failure) {
104 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
105 theError = aFail->GetMessageString();