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 const TCollection_AsciiString& /*theFormatName*/,
33 TCollection_AsciiString& theError)
35 MESSAGE("Import STEP model from file " << theFileName.ToCString());
36 TopoDS_Shape aResShape;
37 //VRV: OCC 4.0 migration
38 STEPControl_Reader aReader;
39 //VRV: OCC 4.0 migration
40 TopoDS_Compound compound;
42 B.MakeCompound( compound );
44 IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
46 if (status == IFSelect_RetDone) {
47 Standard_Boolean failsonly = Standard_False ;
48 aReader.PrintCheckLoad (failsonly, IFSelect_ItemsByEntity);
50 Standard_Integer nbr = aReader.NbRootsForTransfer();
51 aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
53 for ( Standard_Integer n=1; n <= nbr; n++) {
54 Standard_Boolean ok = aReader.TransferRoot(n);
55 /* Collecting resulting entities */
56 Standard_Integer nbs = aReader.NbShapes();
59 // THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM);
60 continue; // skip empty root
62 /* For a single entity */
63 else if (nbr == 1 && nbs == 1) {
64 aResShape = aReader.Shape(1);
68 for ( Standard_Integer i=1; i<=nbs; i++ ) {
69 TopoDS_Shape aShape = aReader.Shape(i);
70 if ( aShape.IsNull() ) {
71 // THROW_SALOME_CORBA_EXCEPTION("Null shape in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ;
76 B.Add( compound, aShape ) ;
80 if ( aResShape.IsNull() )
85 // case IFSelect_RetVoid:
86 // theError = "Nothing created or No data to process";
88 // case IFSelect_RetError:
89 // theError = "Error in command or input data";
91 // case IFSelect_RetFail:
92 // theError = "Execution was run, but has failed";
94 // case IFSelect_RetStop:
95 // theError = "Execution has been stopped. Quite possible, an exception was raised";
100 theError = "Wrong format of the imported file. Can't import file.";
104 catch (Standard_Failure) {
105 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
106 theError = aFail->GetMessageString();