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 //=============================================================================
83 namespace IGESExport {
85 bool Export(const TCollection_AsciiString& theFileName,
86 const TCollection_AsciiString& theFormatName,
87 const TopoDS_Shape& theShape,
88 TCollection_AsciiString& theError)
90 // theFormatName expected "IGES-5.1", "IGES-5.3"...
91 TCollection_AsciiString aVersion = theFormatName.Token("-", 2);
93 if (!aVersion.IsEqual("5.1") || !aVersion.IsEqual("5.3"))
94 std::cout << "Warning: unrecognized version " << aVersion.ToCString()
95 << ". Default version: 5.1." << std::endl;
97 // define, whether to write only faces (5.1 IGES format)
98 // or shells and solids also (5.3 IGES format)
100 if( aVersion.IsEqual( "5.3" ) )
104 std::cout << "Export IGES into file " << theFileName.ToCString() << std::endl;
107 // Mantis issue 0021350: check being exported shape, as some stand-alone
108 // entities (edges, wires and vertices) cannot be saved in BRepMode
109 if( aBrepMode == 1 ) {
110 int aKind = KindOfBRep( theShape );
112 theError = "EXPORT_IGES_HETEROGENEOUS_COMPOUND";
114 } else if( aKind == 2 )
120 // Set "C" numeric locale to save numbers correctly
121 GeomAlgoAPI_Tools::Localizer loc;
124 IGESControl_Controller::Init();
125 IGESControl_Writer ICW( "M", aBrepMode ); // export explicitly in meters
126 Interface_Static::SetCVal( "xstep.cascade.unit", "M" );
128 // 09.03.2010 skl for bug 0020726
129 // change default value "Average" to "Max"
130 Interface_Static::SetCVal( "write.precision.mode", "Max" );
132 // perform shape writing
133 if( ICW.AddShape( theShape ) ) {
135 return ICW.Write( theFileName.ToCString() );