1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: STEPImport.cxx
24 // Created: Wed May 19 14:41:10 2004
25 // Author: Pavel TELKOV
26 // <ptv@mutex.nnov.opencascade.com>
28 #include "utilities.h"
30 #include <Basics_Utils.hxx>
32 #include <BRep_Builder.hxx>
34 #include <IFSelect_ReturnStatus.hxx>
36 #include <STEPControl_Reader.hxx>
38 #include <TCollection_AsciiString.hxx>
39 #include <TopoDS_Compound.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TDF_Label.hxx>
42 #include <Interface_Static.hxx>
44 #include <Standard_Failure.hxx>
45 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
48 #if defined STEPIMPORT_EXPORTS || defined STEPImport_EXPORTS
50 #define STEPIMPORT_EXPORT __declspec( dllexport )
52 #define STEPIMPORT_EXPORT
56 #define STEPIMPORT_EXPORT __declspec( dllimport )
58 #define STEPIMPORT_EXPORT
62 #define STEPIMPORT_EXPORT
65 //=============================================================================
69 //=============================================================================
74 TopoDS_Shape Import (const TCollection_AsciiString& theFileName,
75 const TCollection_AsciiString& /*theFormatName*/,
76 TCollection_AsciiString& theError,
79 MESSAGE("Import STEP model from file " << theFileName.ToCString());
80 // Set "C" numeric locale to save numbers correctly
81 Kernel_Utils::Localizer loc;
82 TopoDS_Shape aResShape;
83 //VRV: OCC 4.0 migration
84 STEPControl_Reader aReader;
85 //VSR: 16/09/09: Convert to METERS
86 Interface_Static::SetCVal("xstep.cascade.unit","M");
87 //VRV: OCC 4.0 migration
88 TopoDS_Compound compound;
90 B.MakeCompound( compound );
92 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
95 IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
97 if (status == IFSelect_RetDone) {
98 Standard_Boolean failsonly = Standard_False ;
99 aReader.PrintCheckLoad (failsonly, IFSelect_ItemsByEntity);
101 Standard_Integer nbr = aReader.NbRootsForTransfer();
102 aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
104 for ( Standard_Integer n=1; n <= nbr; n++) {
105 Standard_Boolean ok = aReader.TransferRoot(n);
106 /* Collecting resulting entities */
107 Standard_Integer nbs = aReader.NbShapes();
110 // THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM);
111 continue; // skip empty root
113 /* For a single entity */
114 else if (nbr == 1 && nbs == 1) {
115 aResShape = aReader.Shape(1);
119 for ( Standard_Integer i=1; i<=nbs; i++ ) {
120 TopoDS_Shape aShape = aReader.Shape(i);
121 if ( aShape.IsNull() ) {
122 // THROW_SALOME_CORBA_EXCEPTION("Null shape in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ;
127 B.Add( compound, aShape ) ;
131 if ( aResShape.IsNull() )
132 aResShape = compound;
136 // case IFSelect_RetVoid:
137 // theError = "Nothing created or No data to process";
139 // case IFSelect_RetError:
140 // theError = "Error in command or input data";
142 // case IFSelect_RetFail:
143 // theError = "Execution was run, but has failed";
145 // case IFSelect_RetStop:
146 // theError = "Execution has been stopped. Quite possible, an exception was raised";
151 theError = "Wrong format of the imported file. Can't import file.";
155 catch (Standard_Failure) {
156 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
157 theError = aFail->GetMessageString();
160 // Return previous locale