]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp
Salome HOME
Issue #529 : 4.07. Import IGES, export to BREP, STEP, IGES - Export IGES
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_IGESExport.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include <GeomAlgoAPI_IGESExport.h>
4
5 //// KERNEL includes
6 //#include <utilities.h>
7 //#include <Basics_Utils.hxx>
8
9 // OOCT includes
10 #include <IGESControl_Controller.hxx>
11 #include <IGESControl_Writer.hxx>
12 #include <Interface_Static.hxx>
13
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Iterator.hxx>
16
17 //=============================================================================
18 /*!
19  *
20  */
21 //=============================================================================
22 /*!
23  *  KindOfBRep
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)
29  */
30 //=============================================================================
31 int KindOfBRep (const TopoDS_Shape& theShape)
32 {
33   int aKind = 2;
34
35   switch (theShape.ShapeType())
36   {
37   case TopAbs_COMPOUND:
38     {
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);
45         if (aKindSub == 0)
46           isSimple = true;
47         else if (aKindSub == 1)
48           isComplex = true;
49         else if (aKindSub == -1) {
50           return -1; // heterogeneous
51         }
52       }
53       if (isSimple && isComplex)
54         aKind = -1; // heterogeneous
55       else if (isSimple)
56         aKind = 0;
57       else if (isComplex)
58         aKind = 1;
59     }
60     break;
61   case TopAbs_COMPSOLID:
62   case TopAbs_SOLID:
63   case TopAbs_SHELL:
64     aKind = 1;
65     break;
66   case TopAbs_WIRE:
67   case TopAbs_EDGE:
68   case TopAbs_VERTEX:
69     aKind = 0;
70     break;
71   default:
72     aKind = 2;
73   }
74
75   return aKind;
76 }
77
78 //=============================================================================
79 //extern "C" {
80 namespace IGESExport {
81
82 bool Export(const TCollection_AsciiString& theFileName,
83             const TCollection_AsciiString&,
84             const TopoDS_Shape& theShape,
85             TCollection_AsciiString& theError, const TDF_Label&)
86 {
87   //TODO(spo): pass version as argument of the function
88   TCollection_AsciiString aVersion = "5.3";
89   // define, whether to write only faces (5.1 IGES format)
90   // or shells and solids also (5.3 IGES format)
91   int aBrepMode = 0;
92   if( aVersion.IsEqual( "5.3" ) )
93     aBrepMode = 1;
94
95   #ifdef _DEBUG
96   std::cout << "Export IGES into file " << theFileName.ToCString() << std::endl;
97   #endif
98
99   // Mantis issue 0021350: check being exported shape, as some stand-alone
100   // entities (edges, wires and vertices) cannot be saved in BRepMode
101   if( aBrepMode == 1 ) {
102     int aKind = KindOfBRep( theShape );
103     if( aKind == -1 ) {
104       theError = "EXPORT_IGES_HETEROGENEOUS_COMPOUND";
105       return false;
106     } else if( aKind == 2 )
107       aBrepMode = 1;
108     else
109       aBrepMode = aKind;
110   }
111
112 //  // Set "C" numeric locale to save numbers correctly
113 //  Kernel_Utils::Localizer loc;
114
115   // initialize writer
116   IGESControl_Controller::Init();
117   IGESControl_Writer ICW( "M", aBrepMode ); // export explicitly in meters
118   Interface_Static::SetCVal( "xstep.cascade.unit", "M" );
119
120   // 09.03.2010 skl for bug 0020726
121   // change default value "Average" to "Max"
122   Interface_Static::SetCVal( "write.precision.mode", "Max" );
123
124   // perform shape writing
125   if( ICW.AddShape( theShape ) ) {
126     ICW.ComputeModel();
127     return (bool)ICW.Write( theFileName.ToCString() );
128   }
129   return false;
130 }
131
132 }
133
134 //}