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 std::shared_ptr<GeomAPI_Shape>& theShape,
84 std::string& theError)
87 std::cout << "Export IGES into file " << theFileName << std::endl;
90 if (!theShape.get()) {
91 theError = "IGES Export failed: An invalid argument";
95 // theFormatName expected "IGES-5.1", "IGES-5.3"...
96 TCollection_AsciiString aFormatName(theFormatName.c_str());
97 TCollection_AsciiString aVersion = aFormatName.Token("-", 2);
99 if (!aVersion.IsEqual("5.1") || !aVersion.IsEqual("5.3"))
100 std::cout << "Warning: unrecognized version " << aVersion.ToCString()
101 << ". Default version: 5.1." << std::endl;
103 // define, whether to write only faces (5.1 IGES format)
104 // or shells and solids also (5.3 IGES format)
106 if( aVersion.IsEqual( "5.3" ) )
109 // Mantis issue 0021350: check being exported shape, as some stand-alone
110 // entities (edges, wires and vertices) cannot be saved in BRepMode
111 if( aBrepMode == 1 ) {
112 int aKind = KindOfBRep( theShape->impl<TopoDS_Shape>() );
114 theError = "EXPORT_IGES_HETEROGENEOUS_COMPOUND";
116 } else if( aKind == 2 )
122 // Set "C" numeric locale to save numbers correctly
123 GeomAlgoAPI_Tools::Localizer loc;
126 IGESControl_Controller::Init();
127 IGESControl_Writer ICW( "M", aBrepMode ); // export explicitly in meters
128 Interface_Static::SetCVal( "xstep.cascade.unit", "M" );
130 // 09.03.2010 skl for bug 0020726
131 // change default value "Average" to "Max"
132 Interface_Static::SetCVal( "write.precision.mode", "Max" );
134 // perform shape writing
135 if( ICW.AddShape( theShape->impl<TopoDS_Shape>() ) ) {
137 return ICW.Write(theFileName.c_str()) == Standard_True;