1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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
20 #include <GeomAlgoAPI_IGESExport.h>
22 #include "GeomAlgoAPI_Tools.h"
25 #include <IGESControl_Controller.hxx>
26 #include <IGESControl_Writer.hxx>
27 #include <Interface_Static.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Iterator.hxx>
32 //=============================================================================
36 //=============================================================================
39 * \return 0 if theShape contains only simple entities (wires, edges and vertices),
40 * 1 if theShape contains only complex entities (shells, solids and compsolids)
41 * 2 if theShape contains only indifferent entities (faces)
42 * -1 if theShape contains both simple and complex entities (and in this case it
43 * cannot be saved without any loss neither in BRepMode == 0 nor in BRepMode == 1)
45 //=============================================================================
46 int KindOfBRep (const TopoDS_Shape& theShape)
50 switch (theShape.ShapeType())
54 bool isSimple = false;
55 bool isComplex = false;
56 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
57 for (; anIt.More(); anIt.Next()) {
58 TopoDS_Shape aS = anIt.Value();
59 int aKindSub = KindOfBRep(aS);
62 else if (aKindSub == 1)
64 else if (aKindSub == -1) {
65 return -1; // heterogeneous
68 if (isSimple && isComplex)
69 aKind = -1; // heterogeneous
76 case TopAbs_COMPSOLID:
93 //=============================================================================
94 bool IGESExport(const std::string& theFileName,
95 const std::string& theFormatName,
96 const std::shared_ptr<GeomAPI_Shape>& theShape,
97 std::string& theError)
100 std::cout << "Export IGES into file " << theFileName << std::endl;
103 if (!theShape.get()) {
104 theError = "IGES Export failed: An invalid argument";
108 // theFormatName expected "IGES-5.1", "IGES-5.3"...
109 TCollection_AsciiString aFormatName(theFormatName.c_str());
110 TCollection_AsciiString aVersion = aFormatName.Token("-", 2);
112 if (!aVersion.IsEqual("5.1") || !aVersion.IsEqual("5.3"))
113 std::cout << "Warning: unrecognized version " << aVersion.ToCString()
114 << ". Default version: 5.1." << std::endl;
116 // define, whether to write only faces (5.1 IGES format)
117 // or shells and solids also (5.3 IGES format)
119 if( aVersion.IsEqual( "5.3" ) )
122 // Mantis issue 0021350: check being exported shape, as some stand-alone
123 // entities (edges, wires and vertices) cannot be saved in BRepMode
124 if( aBrepMode == 1 ) {
125 int aKind = KindOfBRep( theShape->impl<TopoDS_Shape>() );
127 theError = "EXPORT_IGES_HETEROGENEOUS_COMPOUND";
129 } else if( aKind == 2 )
135 // Set "C" numeric locale to save numbers correctly
136 GeomAlgoAPI_Tools::Localizer loc;
139 IGESControl_Controller::Init();
140 IGESControl_Writer ICW( "M", aBrepMode ); // export explicitly in meters
141 Interface_Static::SetCVal( "xstep.cascade.unit", "M" );
143 // 09.03.2010 skl for bug 0020726
144 // change default value "Average" to "Max"
145 Interface_Static::SetCVal( "write.precision.mode", "Max" );
147 // perform shape writing
148 if( ICW.AddShape( theShape->impl<TopoDS_Shape>() ) ) {
150 return ICW.Write(theFileName.c_str()) == Standard_True;