1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
44 #define IGESEXPORT_EXPORT __declspec( dllexport )
46 #define IGESEXPORT_EXPORT __declspec( dllimport )
49 #define IGESEXPORT_EXPORT
52 //=============================================================================
55 * \return 0 if theShape contains only simple entities (wires, edges and vertices),
56 * 1 if theShape contains only complex entities (shells, solids and compsolids)
57 * 2 if theShape contains only indifferent entities (faces)
58 * -1 if theShape contains both simple and complex entities (and in this case it
59 * cannot be saved without any loss neither in BRepMode == 0 nor in BRepMode == 1)
61 //=============================================================================
62 int KindOfBRep (const TopoDS_Shape& theShape)
66 switch (theShape.ShapeType())
70 bool isSimple = false;
71 bool isComplex = false;
72 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
73 for (; anIt.More(); anIt.Next()) {
74 TopoDS_Shape aS = anIt.Value();
75 int aKindSub = KindOfBRep(aS);
78 else if (aKindSub == 1)
80 else if (aKindSub == -1) {
81 return -1; // heterogeneous
84 if (isSimple && isComplex)
85 aKind = -1; // heterogeneous
92 case TopAbs_COMPSOLID:
109 //=============================================================================
113 //=============================================================================
118 int Export( const TopoDS_Shape& theShape,
119 const TCollection_AsciiString& theFileName,
120 const TCollection_AsciiString& theFormatName )
124 // define, whether to write only faces (5.1 IGES format)
125 // or shells and solids also (5.3 IGES format)
127 if (theFormatName.IsEqual("IGES_5_3"))
130 MESSAGE("Export IGES into file " << theFileName.ToCString());
132 // Mantis issue 0021350: check being exported shape, as some standalone
133 // entities (edges, wires and vertices) cannot be saved in BRepMode
134 if (aBrepMode == 1) {
135 int aKind = KindOfBRep(theShape);
137 Standard_Failure::Raise("EXPORT_IGES_HETEROGENEOUS_COMPOUND");
144 // commented for 0021350: Please don't catch exceptions silently and send an
145 // inappropriate error message instead, it is disturbing for the user and for us
148 // Set "C" numeric locale to save numbers correctly
149 Kernel_Utils::Localizer loc;
152 IGESControl_Controller::Init();
153 //IGESControl_Writer ICW (Interface_Static::CVal("write.iges.unit"),
154 // Interface_Static::IVal("write.iges.brep.mode"));
155 IGESControl_Writer ICW ("M", aBrepMode); // "write.iges.unit" ->> VSR 15.09.09: export explicitly in meters
156 Interface_Static::SetCVal("xstep.cascade.unit","M");
158 // 09.03.2010 skl for bug 0020726
159 // change default value "Average" to "Max"
160 Interface_Static::SetCVal("write.precision.mode","Max");
162 // perform shape writing
163 if (ICW.AddShape( theShape )) {
165 ok = ICW.Write( theFileName.ToCString() );
168 //catch(Standard_Failure)