1 // Copyright (C) 2007-2012 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: IGESExport.cxx
24 // Created: Wed May 19 14:49:45 2004
25 // Author: Pavel TELKOV
27 #include "utilities.h"
29 #include <Basics_Utils.hxx>
31 #include <IGESControl_Controller.hxx>
32 #include <IGESControl_Writer.hxx>
33 #include <Interface_Static.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Iterator.hxx>
38 #include <TCollection_AsciiString.hxx>
40 #include <Standard_Failure.hxx>
43 #if defined IGESEXPORT_EXPORTS || defined IGESExport_EXPORTS
45 #define IGESEXPORT_EXPORT __declspec( dllexport )
47 #define IGESEXPORT_EXPORT
51 #define IGESEXPORT_EXPORT __declspec( dllimport )
53 #define IGESEXPORT_EXPORT
57 #define IGESEXPORT_EXPORT
60 //=============================================================================
63 * \return 0 if theShape contains only simple entities (wires, edges and vertices),
64 * 1 if theShape contains only complex entities (shells, solids and compsolids)
65 * 2 if theShape contains only indifferent entities (faces)
66 * -1 if theShape contains both simple and complex entities (and in this case it
67 * cannot be saved without any loss neither in BRepMode == 0 nor in BRepMode == 1)
69 //=============================================================================
70 int KindOfBRep (const TopoDS_Shape& theShape)
74 switch (theShape.ShapeType())
78 bool isSimple = false;
79 bool isComplex = false;
80 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
81 for (; anIt.More(); anIt.Next()) {
82 TopoDS_Shape aS = anIt.Value();
83 int aKindSub = KindOfBRep(aS);
86 else if (aKindSub == 1)
88 else if (aKindSub == -1) {
89 return -1; // heterogeneous
92 if (isSimple && isComplex)
93 aKind = -1; // heterogeneous
100 case TopAbs_COMPSOLID:
117 //=============================================================================
121 //=============================================================================
126 int Export( const TopoDS_Shape& theShape,
127 const TCollection_AsciiString& theFileName,
128 const TCollection_AsciiString& theFormatName )
132 // define, whether to write only faces (5.1 IGES format)
133 // or shells and solids also (5.3 IGES format)
135 if (theFormatName.IsEqual("IGES_5_3"))
138 MESSAGE("Export IGES into file " << theFileName.ToCString());
140 // Mantis issue 0021350: check being exported shape, as some standalone
141 // entities (edges, wires and vertices) cannot be saved in BRepMode
142 if (aBrepMode == 1) {
143 int aKind = KindOfBRep(theShape);
145 Standard_Failure::Raise("EXPORT_IGES_HETEROGENEOUS_COMPOUND");
152 // commented for 0021350: Please don't catch exceptions silently and send an
153 // inappropriate error message instead, it is disturbing for the user and for us
156 // Set "C" numeric locale to save numbers correctly
157 Kernel_Utils::Localizer loc;
160 IGESControl_Controller::Init();
161 //IGESControl_Writer ICW (Interface_Static::CVal("write.iges.unit"),
162 // Interface_Static::IVal("write.iges.brep.mode"));
163 IGESControl_Writer ICW ("M", aBrepMode); // "write.iges.unit" ->> VSR 15.09.09: export explicitly in meters
164 Interface_Static::SetCVal("xstep.cascade.unit","M");
166 // 09.03.2010 skl for bug 0020726
167 // change default value "Average" to "Max"
168 Interface_Static::SetCVal("write.precision.mode","Max");
170 // perform shape writing
171 if (ICW.AddShape( theShape )) {
173 ok = ICW.Write( theFileName.ToCString() );
176 //catch(Standard_Failure)