1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <GeomAlgoAPI_IGESExport.h>
23 #include "GeomAlgoAPI_Tools.h"
26 #include <IGESControl_Controller.hxx>
27 #include <IGESControl_Writer.hxx>
28 #include <Interface_Static.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Iterator.hxx>
33 //=============================================================================
37 //=============================================================================
40 * \return 0 if theShape contains only simple entities (wires, edges and vertices),
41 * 1 if theShape contains only complex entities (shells, solids and compsolids)
42 * 2 if theShape contains only indifferent entities (faces)
43 * -1 if theShape contains both simple and complex entities (and in this case it
44 * cannot be saved without any loss neither in BRepMode == 0 nor in BRepMode == 1)
46 //=============================================================================
47 int KindOfBRep (const TopoDS_Shape& theShape)
51 switch (theShape.ShapeType())
55 bool isSimple = false;
56 bool isComplex = false;
57 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
58 for (; anIt.More(); anIt.Next()) {
59 TopoDS_Shape aS = anIt.Value();
60 int aKindSub = KindOfBRep(aS);
63 else if (aKindSub == 1)
65 else if (aKindSub == -1) {
66 return -1; // heterogeneous
69 if (isSimple && isComplex)
70 aKind = -1; // heterogeneous
77 case TopAbs_COMPSOLID:
94 //=============================================================================
95 bool IGESExport(const std::string& theFileName,
96 const std::string& theFormatName,
97 const std::shared_ptr<GeomAPI_Shape>& theShape,
98 std::string& theError)
101 std::cout << "Export IGES into file " << theFileName << std::endl;
104 if (!theShape.get()) {
105 theError = "IGES Export failed: An invalid argument";
109 // theFormatName expected "IGES-5.1", "IGES-5.3"...
110 TCollection_AsciiString aFormatName(theFormatName.c_str());
111 TCollection_AsciiString aVersion = aFormatName.Token("-", 2);
113 if (!aVersion.IsEqual("5.1") || !aVersion.IsEqual("5.3"))
114 std::cout << "Warning: unrecognized version " << aVersion.ToCString()
115 << ". Default version: 5.1." << std::endl;
117 // define, whether to write only faces (5.1 IGES format)
118 // or shells and solids also (5.3 IGES format)
120 if( aVersion.IsEqual( "5.3" ) )
123 // Mantis issue 0021350: check being exported shape, as some stand-alone
124 // entities (edges, wires and vertices) cannot be saved in BRepMode
125 if( aBrepMode == 1 ) {
126 int aKind = KindOfBRep( theShape->impl<TopoDS_Shape>() );
128 theError = "EXPORT_IGES_HETEROGENEOUS_COMPOUND";
130 } else if( aKind == 2 )
136 // Set "C" numeric locale to save numbers correctly
137 GeomAlgoAPI_Tools::Localizer loc;
140 IGESControl_Controller::Init();
141 IGESControl_Writer ICW( "M", aBrepMode ); // export explicitly in meters
142 Interface_Static::SetCVal( "xstep.cascade.unit", "M" );
144 // 09.03.2010 skl for bug 0020726
145 // change default value "Average" to "Max"
146 Interface_Static::SetCVal( "write.precision.mode", "Max" );
148 // perform shape writing
149 if( ICW.AddShape( theShape->impl<TopoDS_Shape>() ) ) {
151 return ICW.Write(theFileName.c_str()) == Standard_True;