1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
20 // File: STEPImport.cxx
21 // Created: Wed May 19 14:41:10 2004
22 // Author: Pavel TELKOV
23 // <ptv@mutex.nnov.opencascade.com>
25 #include "utilities.h"
27 #include <BRep_Builder.hxx>
29 #include <IFSelect_ReturnStatus.hxx>
31 #include <STEPControl_Reader.hxx>
33 #include <TCollection_AsciiString.hxx>
34 #include <TopoDS_Compound.hxx>
35 #include <TopoDS_Shape.hxx>
37 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
40 #include <SALOME_WNT.hxx>
42 #define SALOME_WNT_EXPORT
45 //=============================================================================
49 //=============================================================================
54 TopoDS_Shape Import (const TCollection_AsciiString& theFileName,
55 TCollection_AsciiString& theError)
57 MESSAGE("Import STEP model from file " << theFileName.ToCString());
58 TopoDS_Shape aResShape;
59 //VRV: OCC 4.0 migration
60 STEPControl_Reader aReader;
61 //VRV: OCC 4.0 migration
62 TopoDS_Compound compound;
64 B.MakeCompound( compound );
66 IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
68 if (status == IFSelect_RetDone) {
69 Standard_Boolean failsonly = Standard_False ;
70 aReader.PrintCheckLoad (failsonly, IFSelect_ItemsByEntity);
72 Standard_Integer nbr = aReader.NbRootsForTransfer();
73 aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
75 for ( Standard_Integer n=1; n <= nbr; n++) {
76 Standard_Boolean ok = aReader.TransferRoot(n);
77 /* Collecting resulting entities */
78 Standard_Integer nbs = aReader.NbShapes();
81 // THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM);
82 continue; // skip empty root
84 /* For a single entity */
85 else if (nbr == 1 && nbs == 1) {
86 aResShape = aReader.Shape(1);
90 for ( Standard_Integer i=1; i<=nbs; i++ ) {
91 TopoDS_Shape aShape = aReader.Shape(i);
92 if ( aShape.IsNull() ) {
93 // THROW_SALOME_CORBA_EXCEPTION("Null shape in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ;
98 B.Add( compound, aShape ) ;
102 if ( aResShape.IsNull() )
103 aResShape = compound;
107 // case IFSelect_RetVoid:
108 // theError = "Nothing created or No data to process";
110 // case IFSelect_RetError:
111 // theError = "Error in command or input data";
113 // case IFSelect_RetFail:
114 // theError = "Execution was run, but has failed";
116 // case IFSelect_RetStop:
117 // theError = "Execution has been stopped. Quite possible, an exception was raised";
122 theError = "Wrong format of the imported file. Can't import file.";
126 catch (Standard_Failure) {
127 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
128 theError = aFail->GetMessageString();