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/ or email : webmaster.salome@opencascade.com
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 const TCollection_AsciiString& /*theFormatName*/,
56 TCollection_AsciiString& theError)
58 MESSAGE("Import STEP model from file " << theFileName.ToCString());
59 TopoDS_Shape aResShape;
60 //VRV: OCC 4.0 migration
61 STEPControl_Reader aReader;
62 //VRV: OCC 4.0 migration
63 TopoDS_Compound compound;
65 B.MakeCompound( compound );
67 IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
69 if (status == IFSelect_RetDone) {
70 Standard_Boolean failsonly = Standard_False ;
71 aReader.PrintCheckLoad (failsonly, IFSelect_ItemsByEntity);
73 Standard_Integer nbr = aReader.NbRootsForTransfer();
74 aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
76 for ( Standard_Integer n=1; n <= nbr; n++) {
77 Standard_Boolean ok = aReader.TransferRoot(n);
78 /* Collecting resulting entities */
79 Standard_Integer nbs = aReader.NbShapes();
82 // THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM);
83 continue; // skip empty root
85 /* For a single entity */
86 else if (nbr == 1 && nbs == 1) {
87 aResShape = aReader.Shape(1);
91 for ( Standard_Integer i=1; i<=nbs; i++ ) {
92 TopoDS_Shape aShape = aReader.Shape(i);
93 if ( aShape.IsNull() ) {
94 // THROW_SALOME_CORBA_EXCEPTION("Null shape in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ;
99 B.Add( compound, aShape ) ;
103 if ( aResShape.IsNull() )
104 aResShape = compound;
108 // case IFSelect_RetVoid:
109 // theError = "Nothing created or No data to process";
111 // case IFSelect_RetError:
112 // theError = "Error in command or input data";
114 // case IFSelect_RetFail:
115 // theError = "Execution was run, but has failed";
117 // case IFSelect_RetStop:
118 // theError = "Execution has been stopped. Quite possible, an exception was raised";
123 theError = "Wrong format of the imported file. Can't import file.";
127 catch (Standard_Failure) {
128 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
129 theError = aFail->GetMessageString();