1 // Copyright (C) 2014-2024 CEA, EDF, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "IGESPlugin_ImportDriver.hxx"
22 #include "IGESPlugin_IImport.hxx"
25 #include <utilities.h>
26 #include <Basics_Utils.hxx>
29 #include "GEOM_Function.hxx"
30 #include "GEOMImpl_Types.hxx"
33 #include <IFSelect_ReturnStatus.hxx>
34 #include <IGESControl_Reader.hxx>
35 #include <IGESData_IGESModel.hxx>
36 #include <IGESData_IGESEntity.hxx>
38 #include <Interface_Static.hxx>
39 #include <Interface_InterfaceModel.hxx>
40 #include <XSControl_TransferReader.hxx>
41 #include <XSControl_WorkSession.hxx>
42 #include <Transfer_TransientProcess.hxx>
43 #include <Transfer_Binder.hxx>
44 #include <TransferBRep.hxx>
46 #include <TNaming_Builder.hxx>
47 #include <TDF_TagSource.hxx>
48 #include <TDataStd_Name.hxx>
49 #include <TDF_Label.hxx>
51 #include <TCollection_HAsciiString.hxx>
52 #include <TopoDS_Shape.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <BRep_Builder.hxx>
57 #include <StdFail_NotDone.hxx>
58 #include <Standard_Failure.hxx>
59 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
61 //=======================================================================
64 //=======================================================================
65 const Standard_GUID& IGESPlugin_ImportDriver::GetID()
67 static Standard_GUID aGUID("3dbb09b8-659f-4a0f-88b9-d9968c43a448");
71 //=======================================================================
72 //function : IGESPlugin_ImportDriver
74 //=======================================================================
75 IGESPlugin_ImportDriver::IGESPlugin_ImportDriver()
79 //=======================================================================
82 //=======================================================================
83 Standard_Integer IGESPlugin_ImportDriver::Execute(Handle(TFunction_Logbook)& log) const
85 if( Label().IsNull() ) return 0;
86 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
88 IGESPlugin_IImport aData( aFunction );
90 TCollection_AsciiString aFileName = aData.GetFileName().ToCString();
91 bool anIsIgnoreUnits = aData.GetIsIgnoreUnits();
92 TDF_Label aShapeLabel = aFunction->GetNamingEntry();
94 TopoDS_Shape aResShape;
95 TCollection_AsciiString anError;
97 // Set "C" numeric locale to save numbers correctly
98 Kernel_Utils::Localizer loc;
100 IGESControl_Reader aReader;
102 Interface_Static::SetCVal( "xstep.cascade.unit", "M" );
107 IFSelect_ReturnStatus status = aReader.ReadFile( aFileName.ToCString() );
109 if (status == IFSelect_RetDone) {
110 if( anIsIgnoreUnits ) {
111 // need re-scale a model, set UnitFlag to 'meter'
112 Handle(IGESData_IGESModel) aModel =
113 Handle(IGESData_IGESModel)::DownCast( aReader.Model() );
114 if( !aModel.IsNull() ) {
115 IGESData_GlobalSection aGS = aModel->GlobalSection();
117 aModel->SetGlobalSection(aGS);
121 MESSAGE("ImportIGES : all Geometry Transfer");
124 // aReader.TransferRoots(false);
125 aReader.ClearShapes();
126 aReader.TransferRoots();
128 MESSAGE("ImportIGES : count of shapes produced = " << aReader.NbShapes());
129 aResShape = aReader.OneShape();
131 // BEGIN: Store names of sub-shapes from file
132 Handle(Interface_InterfaceModel) Model = aReader.WS()->Model();
133 Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader();
135 Handle(Transfer_TransientProcess) TP = /*TransientProcess();*/TR->TransientProcess();
136 Standard_Integer nb = Model->NbEntities();
137 for (Standard_Integer i = 1; i <= nb; i++) {
138 Handle(IGESData_IGESEntity) ent = Handle(IGESData_IGESEntity)::DownCast(Model->Value(i));
139 if (ent.IsNull() || ! ent->HasName()) continue;
142 Handle(Transfer_Binder) binder = TP->Find( ent );
143 if( binder.IsNull() ) continue;
144 TopoDS_Shape S = TransferBRep::ShapeResult( binder );
145 if( S.IsNull() ) continue;
147 // create label and set shape
150 L = aTag.NewChild( aShapeLabel );
151 TNaming_Builder tnBuild (L);
152 tnBuild.Generated(S);
155 TCollection_AsciiString string = ent->NameValue()->String();
157 string.RightAdjust();
158 TCollection_ExtendedString str (string);
159 TDataStd_Name::Set(L, str);
166 case IFSelect_RetVoid:
167 anError = "Nothing created or No data to process";
169 case IFSelect_RetError:
170 anError = "Error in command or input data";
172 case IFSelect_RetFail:
173 anError = "Execution was run, but has failed";
175 case IFSelect_RetStop:
176 anError = "Execution has been stopped. Quite possible, an exception was raised";
181 anError = "Wrong format of the imported file. Can't import file.";
185 catch( Standard_Failure& aFail ) {
186 anError = aFail.GetMessageString();
190 if( aResShape.IsNull() ) {
191 StdFail_NotDone::Raise( anError.ToCString() );
195 aFunction->SetValue( aResShape );
197 log->SetTouched(Label());
202 //================================================================================
204 * \brief Returns a name of creation operation and names and values of creation parameters
206 //================================================================================
208 bool IGESPlugin_ImportDriver::
209 GetCreationInformation( std::string& theOperationName,
210 std::vector<GEOM_Param>& theParams )
212 if( Label().IsNull() ) return 0;
213 Handle(GEOM_Function) function = GEOM_Function::GetFunction( Label() );
215 IGESPlugin_IImport aCI( function );
216 Standard_Integer aType = function->GetType();
218 theOperationName = "ImportIGES";
222 AddParam( theParams, "File name", aCI.GetFileName() );
223 if( aCI.GetIsIgnoreUnits() )
224 AddParam( theParams, "Format", "IGES_SCALE" );
232 TCollection_AsciiString
233 IGESPlugin_ImportDriver::GetValue( const TCollection_AsciiString& theFileName,
234 const TCollection_AsciiString& theParameterName,
235 TCollection_AsciiString& theError )
237 Handle(TCollection_HAsciiString) aValue;
239 if (theParameterName != "LEN_UNITS") {
240 theError = theParameterName + " parameter reading is not supported by IGES plugin";
241 return TCollection_AsciiString();
244 // Set "C" numeric locale to save numbers correctly
245 Kernel_Utils::Localizer loc;
247 IGESControl_Reader aReader;
249 Interface_Static::SetCVal("xstep.cascade.unit","M");
254 IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
255 if (status == IFSelect_RetDone) {
256 Handle(IGESData_IGESModel) aModel =
257 Handle(IGESData_IGESModel)::DownCast(aReader.Model());
258 if (!aModel.IsNull()) {
259 aValue = aModel->GlobalSection().UnitName();
260 //if (!aValue.IsNull()) {
261 // Handle(TCollection_HAsciiString) aPrefix = new TCollection_HAsciiString ("UNIT_");
262 // aValue->Prepend(aPrefix);
267 theError = theFileName + " reading failed";
270 catch (Standard_Failure& aFail) {
271 theError = aFail.GetMessageString();
273 if (!aValue.IsNull())
274 return aValue->String();
276 return TCollection_AsciiString();
279 IMPLEMENT_STANDARD_RTTIEXT( IGESPlugin_ImportDriver, GEOM_BaseDriver )