1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include <GeomAlgoAPI_IGESExport.h>
6 //#include <utilities.h>
7 //#include <Basics_Utils.hxx>
10 #include <IGESControl_Controller.hxx>
11 #include <IGESControl_Writer.hxx>
12 #include <Interface_Static.hxx>
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Iterator.hxx>
17 //=============================================================================
21 //=============================================================================
24 * \return 0 if theShape contains only simple entities (wires, edges and vertices),
25 * 1 if theShape contains only complex entities (shells, solids and compsolids)
26 * 2 if theShape contains only indifferent entities (faces)
27 * -1 if theShape contains both simple and complex entities (and in this case it
28 * cannot be saved without any loss neither in BRepMode == 0 nor in BRepMode == 1)
30 //=============================================================================
31 int KindOfBRep (const TopoDS_Shape& theShape)
35 switch (theShape.ShapeType())
39 bool isSimple = false;
40 bool isComplex = false;
41 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
42 for (; anIt.More(); anIt.Next()) {
43 TopoDS_Shape aS = anIt.Value();
44 int aKindSub = KindOfBRep(aS);
47 else if (aKindSub == 1)
49 else if (aKindSub == -1) {
50 return -1; // heterogeneous
53 if (isSimple && isComplex)
54 aKind = -1; // heterogeneous
61 case TopAbs_COMPSOLID:
78 //=============================================================================
81 namespace IGESExport {
83 bool Export(const TCollection_AsciiString& theFileName,
84 const TCollection_AsciiString& theFormatName,
85 const TopoDS_Shape& theShape,
86 TCollection_AsciiString& theError, const TDF_Label&)
88 // theFormatName expected "IGES-5.1", "IGES-5.3"...
89 TCollection_AsciiString aVersion = theFormatName.Token("-", 2);
91 if (!aVersion.IsEqual("5.1") || !aVersion.IsEqual("5.3"))
92 std::cout << "Warning: unrecognized version " << aVersion.ToCString()
93 << ". Default version: 5.1." << std::endl;
95 // define, whether to write only faces (5.1 IGES format)
96 // or shells and solids also (5.3 IGES format)
98 if( aVersion.IsEqual( "5.3" ) )
102 std::cout << "Export IGES into file " << theFileName.ToCString() << std::endl;
105 // Mantis issue 0021350: check being exported shape, as some stand-alone
106 // entities (edges, wires and vertices) cannot be saved in BRepMode
107 if( aBrepMode == 1 ) {
108 int aKind = KindOfBRep( theShape );
110 theError = "EXPORT_IGES_HETEROGENEOUS_COMPOUND";
112 } else if( aKind == 2 )
118 // // Set "C" numeric locale to save numbers correctly
119 // Kernel_Utils::Localizer loc;
122 IGESControl_Controller::Init();
123 IGESControl_Writer ICW( "M", aBrepMode ); // export explicitly in meters
124 Interface_Static::SetCVal( "xstep.cascade.unit", "M" );
126 // 09.03.2010 skl for bug 0020726
127 // change default value "Average" to "Max"
128 Interface_Static::SetCVal( "write.precision.mode", "Max" );
130 // perform shape writing
131 if( ICW.AddShape( theShape ) ) {
133 return ICW.Write( theFileName.ToCString() );