1 // Copyright (C) 2014-2015 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>
29 #include "GEOM_Function.hxx"
32 #include <IGESControl_Controller.hxx>
33 #include <IGESControl_Writer.hxx>
34 #include <Interface_Static.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Iterator.hxx>
39 //=============================================================================
42 * \return 0 if theShape contains only simple entities (wires, edges and vertices),
43 * 1 if theShape contains only complex entities (shells, solids and compsolids)
44 * 2 if theShape contains only indifferent entities (faces)
45 * -1 if theShape contains both simple and complex entities (and in this case it
46 * cannot be saved without any loss neither in BRepMode == 0 nor in BRepMode == 1)
48 //=============================================================================
49 int KindOfBRep (const TopoDS_Shape& theShape)
53 switch (theShape.ShapeType())
57 bool isSimple = false;
58 bool isComplex = false;
59 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
60 for (; anIt.More(); anIt.Next()) {
61 TopoDS_Shape aS = anIt.Value();
62 int aKindSub = KindOfBRep(aS);
65 else if (aKindSub == 1)
67 else if (aKindSub == -1) {
68 return -1; // heterogeneous
71 if (isSimple && isComplex)
72 aKind = -1; // heterogeneous
79 case TopAbs_COMPSOLID:
96 //=======================================================================
99 //=======================================================================
100 const Standard_GUID& IGESPlugin_ExportDriver::GetID()
102 static Standard_GUID aGUID("8fa4111a-24cb-4819-8f03-b0e2890d2a2a");
106 //=======================================================================
107 //function : IGESPlugin_ExportDriver
109 //=======================================================================
110 IGESPlugin_ExportDriver::IGESPlugin_ExportDriver()
114 //=======================================================================
117 //=======================================================================
118 Standard_Integer IGESPlugin_ExportDriver::Execute( TFunction_Logbook& log ) const
120 if (Label().IsNull()) return 0;
121 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
123 IGESPlugin_IExport aData (aFunction);
125 // retrieve the being exported shape
127 Handle(GEOM_Function) aRefFunction = aData.GetOriginal();
128 if( aRefFunction.IsNull() ) return 0;
129 aShape = aRefFunction->GetValue();
130 if( aShape.IsNull() ) return 0;
131 // set the result of function to be used by next operations
132 aFunction->SetValue( aShape );
134 TCollection_AsciiString aFileName = aData.GetFileName();
135 TCollection_AsciiString aVersion = aData.GetVersion();
136 // define, whether to write only faces (5.1 IGES format)
137 // or shells and solids also (5.3 IGES format)
139 if( aVersion.IsEqual( "5.3" ) )
142 MESSAGE("Export IGES into file " << aFileName.ToCString());
144 // Mantis issue 0021350: check being exported shape, as some standalone
145 // entities (edges, wires and vertices) cannot be saved in BRepMode
146 if( aBrepMode == 1 ) {
147 int aKind = KindOfBRep( aShape );
149 Standard_Failure::Raise( "EXPORT_IGES_HETEROGENEOUS_COMPOUND" );
150 else if( aKind == 2 )
156 // Set "C" numeric locale to save numbers correctly
157 Kernel_Utils::Localizer loc;
160 IGESControl_Controller::Init();
161 IGESControl_Writer ICW( "M", aBrepMode ); // export explicitly in meters
162 Interface_Static::SetCVal( "xstep.cascade.unit", "M" );
164 // 09.03.2010 skl for bug 0020726
165 // change default value "Average" to "Max"
166 Interface_Static::SetCVal( "write.precision.mode", "Max" );
168 // perform shape writing
169 if( ICW.AddShape( aShape ) ) {
171 return ICW.Write( aFileName.ToCString() );
176 //=======================================================================
177 //function : MustExecute
179 //=======================================================================
180 Standard_Boolean IGESPlugin_ExportDriver::MustExecute( const TFunction_Logbook& ) const
182 return Standard_True;
185 //================================================================================
187 * \brief Returns a name of creation operation and names and values of creation parameters
189 //================================================================================
190 bool IGESPlugin_ExportDriver::
191 GetCreationInformation( std::string& theOperationName,
192 std::vector<GEOM_Param>& theParams )
197 IMPLEMENT_STANDARD_HANDLE( IGESPlugin_ExportDriver,GEOM_BaseDriver );
198 IMPLEMENT_STANDARD_RTTIEXT( IGESPlugin_ExportDriver,GEOM_BaseDriver );