1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include <GeomAlgoAPI_IGESExport.h>
5 #include "GeomAlgoAPI_Tools.h"
8 #include <IGESControl_Controller.hxx>
9 #include <IGESControl_Writer.hxx>
10 #include <Interface_Static.hxx>
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Iterator.hxx>
15 //=============================================================================
19 //=============================================================================
22 * \return 0 if theShape contains only simple entities (wires, edges and vertices),
23 * 1 if theShape contains only complex entities (shells, solids and compsolids)
24 * 2 if theShape contains only indifferent entities (faces)
25 * -1 if theShape contains both simple and complex entities (and in this case it
26 * cannot be saved without any loss neither in BRepMode == 0 nor in BRepMode == 1)
28 //=============================================================================
29 int KindOfBRep (const TopoDS_Shape& theShape)
33 switch (theShape.ShapeType())
37 bool isSimple = false;
38 bool isComplex = false;
39 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
40 for (; anIt.More(); anIt.Next()) {
41 TopoDS_Shape aS = anIt.Value();
42 int aKindSub = KindOfBRep(aS);
45 else if (aKindSub == 1)
47 else if (aKindSub == -1) {
48 return -1; // heterogeneous
51 if (isSimple && isComplex)
52 aKind = -1; // heterogeneous
59 case TopAbs_COMPSOLID:
76 //=============================================================================
79 namespace IGESExport {
81 bool Export(const TCollection_AsciiString& theFileName,
82 const TCollection_AsciiString& theFormatName,
83 const TopoDS_Shape& theShape,
84 TCollection_AsciiString& theError)
86 // theFormatName expected "IGES-5.1", "IGES-5.3"...
87 TCollection_AsciiString aVersion = theFormatName.Token("-", 2);
89 if (!aVersion.IsEqual("5.1") || !aVersion.IsEqual("5.3"))
90 std::cout << "Warning: unrecognized version " << aVersion.ToCString()
91 << ". Default version: 5.1." << std::endl;
93 // define, whether to write only faces (5.1 IGES format)
94 // or shells and solids also (5.3 IGES format)
96 if( aVersion.IsEqual( "5.3" ) )
100 std::cout << "Export IGES into file " << theFileName.ToCString() << std::endl;
103 // Mantis issue 0021350: check being exported shape, as some stand-alone
104 // entities (edges, wires and vertices) cannot be saved in BRepMode
105 if( aBrepMode == 1 ) {
106 int aKind = KindOfBRep( theShape );
108 theError = "EXPORT_IGES_HETEROGENEOUS_COMPOUND";
110 } else if( aKind == 2 )
116 // Set "C" numeric locale to save numbers correctly
117 GeomAlgoAPI_Tools::Localizer loc;
120 IGESControl_Controller::Init();
121 IGESControl_Writer ICW( "M", aBrepMode ); // export explicitly in meters
122 Interface_Static::SetCVal( "xstep.cascade.unit", "M" );
124 // 09.03.2010 skl for bug 0020726
125 // change default value "Average" to "Max"
126 Interface_Static::SetCVal( "write.precision.mode", "Max" );
128 // perform shape writing
129 if( ICW.AddShape( theShape ) ) {
131 return ICW.Write( theFileName.ToCString() );