1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GEOMALGOAPI_IGESExport.cpp
4 // Created: Dec 24, 2014
5 // Author: Sergey BELASH
7 #include <GeomAlgoAPI_IGESExport.h>
9 #include "GeomAlgoAPI_Tools.h"
12 #include <IGESControl_Controller.hxx>
13 #include <IGESControl_Writer.hxx>
14 #include <Interface_Static.hxx>
16 #include <TopoDS_Shape.hxx>
17 #include <TopoDS_Iterator.hxx>
19 //=============================================================================
23 //=============================================================================
26 * \return 0 if theShape contains only simple entities (wires, edges and vertices),
27 * 1 if theShape contains only complex entities (shells, solids and compsolids)
28 * 2 if theShape contains only indifferent entities (faces)
29 * -1 if theShape contains both simple and complex entities (and in this case it
30 * cannot be saved without any loss neither in BRepMode == 0 nor in BRepMode == 1)
32 //=============================================================================
33 int KindOfBRep (const TopoDS_Shape& theShape)
37 switch (theShape.ShapeType())
41 bool isSimple = false;
42 bool isComplex = false;
43 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
44 for (; anIt.More(); anIt.Next()) {
45 TopoDS_Shape aS = anIt.Value();
46 int aKindSub = KindOfBRep(aS);
49 else if (aKindSub == 1)
51 else if (aKindSub == -1) {
52 return -1; // heterogeneous
55 if (isSimple && isComplex)
56 aKind = -1; // heterogeneous
63 case TopAbs_COMPSOLID:
80 //=============================================================================
81 bool IGESExport(const std::string& theFileName,
82 const std::string& theFormatName,
83 const TopoDS_Shape& theShape,
84 std::string& theError)
86 // theFormatName expected "IGES-5.1", "IGES-5.3"...
87 TCollection_AsciiString aFormatName(theFormatName.c_str());
88 TCollection_AsciiString aVersion = aFormatName.Token("-", 2);
90 if (!aVersion.IsEqual("5.1") || !aVersion.IsEqual("5.3"))
91 std::cout << "Warning: unrecognized version " << aVersion.ToCString()
92 << ". Default version: 5.1." << std::endl;
94 // define, whether to write only faces (5.1 IGES format)
95 // or shells and solids also (5.3 IGES format)
97 if( aVersion.IsEqual( "5.3" ) )
101 std::cout << "Export IGES into file " << theFileName << std::endl;
104 // Mantis issue 0021350: check being exported shape, as some stand-alone
105 // entities (edges, wires and vertices) cannot be saved in BRepMode
106 if( aBrepMode == 1 ) {
107 int aKind = KindOfBRep( theShape );
109 theError = "EXPORT_IGES_HETEROGENEOUS_COMPOUND";
111 } else if( aKind == 2 )
117 // Set "C" numeric locale to save numbers correctly
118 GeomAlgoAPI_Tools::Localizer loc;
121 IGESControl_Controller::Init();
122 IGESControl_Writer ICW( "M", aBrepMode ); // export explicitly in meters
123 Interface_Static::SetCVal( "xstep.cascade.unit", "M" );
125 // 09.03.2010 skl for bug 0020726
126 // change default value "Average" to "Max"
127 Interface_Static::SetCVal( "write.precision.mode", "Max" );
129 // perform shape writing
130 if( ICW.AddShape( theShape ) ) {
132 return ICW.Write(theFileName.c_str());