1 // Copyright (C) 2014-2023 CEA/DEN, EDF R&D, 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_ExportDriver.hxx"
22 #include "IGESPlugin_IExport.hxx"
25 #include <utilities.h>
26 #include <Basics_Utils.hxx>
27 #include <Basics_OCCTVersion.hxx>
30 #include "GEOM_Function.hxx"
33 #include <IGESControl_Controller.hxx>
34 #include <IGESControl_Writer.hxx>
35 #include <IGESData_IGESModel.hxx>
36 #include <Interface_Static.hxx>
39 #include <XSAlgo_AlgoContainer.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <TopoDS_Iterator.hxx>
44 #include <UnitsMethods.hxx>
46 //=============================================================================
49 * \return 0 if theShape contains only simple entities (wires, edges and vertices),
50 * 1 if theShape contains only complex entities (shells, solids and compsolids)
51 * 2 if theShape contains only indifferent entities (faces)
52 * -1 if theShape contains both simple and complex entities (and in this case it
53 * cannot be saved without any loss neither in BRepMode == 0 nor in BRepMode == 1)
55 //=============================================================================
56 int KindOfBRep (const TopoDS_Shape& theShape)
60 switch (theShape.ShapeType())
64 bool isSimple = false;
65 bool isComplex = false;
66 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
67 for (; anIt.More(); anIt.Next()) {
68 TopoDS_Shape aS = anIt.Value();
69 int aKindSub = KindOfBRep(aS);
72 else if (aKindSub == 1)
74 else if (aKindSub == -1) {
75 return -1; // heterogeneous
78 if (isSimple && isComplex)
79 aKind = -1; // heterogeneous
86 case TopAbs_COMPSOLID:
103 //=======================================================================
106 //=======================================================================
107 const Standard_GUID& IGESPlugin_ExportDriver::GetID()
109 static Standard_GUID aGUID("8fa4111a-24cb-4819-8f03-b0e2890d2a2a");
113 //=======================================================================
114 //function : IGESPlugin_ExportDriver
116 //=======================================================================
117 IGESPlugin_ExportDriver::IGESPlugin_ExportDriver()
121 //=======================================================================
124 //=======================================================================
125 Standard_Integer IGESPlugin_ExportDriver::Execute(Handle(TFunction_Logbook)& /*log*/) const
127 if (Label().IsNull()) return 0;
128 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
130 IGESPlugin_IExport aData (aFunction);
132 // retrieve the being exported shape
134 Handle(GEOM_Function) aRefFunction = aData.GetOriginal();
135 if( aRefFunction.IsNull() ) return 0;
136 aShape = aRefFunction->GetValue();
137 if( aShape.IsNull() ) return 0;
138 // set the result of function to be used by next operations
139 aFunction->SetValue( aShape );
141 TCollection_AsciiString aFileName = aData.GetFileName();
142 TCollection_AsciiString aVersion = aData.GetVersion();
143 // define, whether to write only faces (5.1 IGES format)
144 // or shells and solids also (5.3 IGES format)
146 if( aVersion.IsEqual( "5.3" ) )
149 MESSAGE("Export IGES into file " << aFileName.ToCString());
151 // Mantis issue 0021350: check being exported shape, as some standalone
152 // entities (edges, wires and vertices) cannot be saved in BRepMode
153 if( aBrepMode == 1 ) {
154 int aKind = KindOfBRep( aShape );
156 Standard_Failure::Raise( "EXPORT_IGES_HETEROGENEOUS_COMPOUND" );
157 else if( aKind == 2 )
163 // Set "C" numeric locale to save numbers correctly
164 Kernel_Utils::Localizer loc;
167 IGESControl_Controller::Init();
168 IGESControl_Writer ICW( "M", aBrepMode ); // export explicitly in meters
169 Interface_Static::SetCVal( "xstep.cascade.unit", "M" );
171 #if OCC_VERSION_LARGE >= 0x07070000
172 Interface_Static::SetCVal("write.iges.unit", "M");
173 XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
174 Standard_Real aScaleFactorMM = UnitsMethods::GetCasCadeLengthUnit();
175 ICW.Model()->ChangeGlobalSection().SetCascadeUnit(aScaleFactorMM);
178 // 09.03.2010 skl for bug 0020726
179 // change default value "Average" to "Max"
180 Interface_Static::SetCVal( "write.precision.mode", "Max" );
182 // perform shape writing
183 if( ICW.AddShape( aShape ) ) {
185 return ICW.Write( aFileName.ToCString() );
190 //================================================================================
192 * \brief Returns a name of creation operation and names and values of creation parameters
194 //================================================================================
195 bool IGESPlugin_ExportDriver::
196 GetCreationInformation( std::string& /*theOperationName*/,
197 std::vector<GEOM_Param>& /*theParams*/ )
202 IMPLEMENT_STANDARD_RTTIEXT( IGESPlugin_ExportDriver,GEOM_BaseDriver )