Salome HOME
3. Mixed topology: solids, faces, edges and vertices
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_STEPExport.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    GEOMALGOAPI_STEPExport.cpp
4 // Created: May 14, 2015
5 // Author:  Sergey POKHODENKO
6
7 #include <GeomAlgoAPI_STEPExport.h>
8
9 #include "GeomAlgoAPI_Tools.h"
10
11 #include <TopoDS_Shape.hxx>
12
13 // OOCT includes
14 #include <IFSelect_ReturnStatus.hxx>
15 #include <STEPControl_Writer.hxx>
16 #include <Interface_Static.hxx>
17
18 bool STEPExport(const std::string& theFileName,
19                 const std::string& theFormatName,
20                 const std::shared_ptr<GeomAPI_Shape>& theShape,
21                 std::string& theError)
22 {
23   #ifdef _DEBUG
24   std::cout << "Export STEP into file " << theFileName << std::endl;
25   #endif
26
27   if (!theShape.get()) {
28     theError = "STEP Export failed: An invalid argument";
29     return false;
30   }
31
32   try
33   {
34     // Set "C" numeric locale to save numbers correctly
35     GeomAlgoAPI_Tools::Localizer loc;
36
37     IFSelect_ReturnStatus status ;
38     //VRV: OCC 4.0 migration
39     STEPControl_Writer aWriter;
40     Interface_Static::SetCVal("xstep.cascade.unit","M");
41     Interface_Static::SetCVal("write.step.unit", "M");
42     Interface_Static::SetIVal("write.step.nonmanifold", 1);
43     status = aWriter.Transfer(theShape->impl<TopoDS_Shape>(), STEPControl_AsIs);
44     //VRV: OCC 4.0 migration
45     if( status == IFSelect_RetDone )
46       status = aWriter.Write(theFileName.c_str());
47
48     // Return previous locale
49     if( status == IFSelect_RetDone )
50       return true;
51   }
52   catch (Standard_Failure)
53   {
54     theError = "Exception catched in STEPExport";
55   }
56   return false;
57 }