Salome HOME
7455d5ca8a0f30b8e3f766c20c31be1690cfd19b
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_STEPExport.cpp
1 // Copyright (C) 2014-2021  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <GeomAlgoAPI_STEPExport.h>
21
22 #include "GeomAlgoAPI_Tools.h"
23
24 #include <TopoDS_Shape.hxx>
25
26 // OOCT includes
27 #include <IFSelect_ReturnStatus.hxx>
28 #include <STEPControl_Writer.hxx>
29 #include <Interface_Static.hxx>
30
31 bool STEPExport(const std::string& theFileName,
32                 const std::string& /*theFormatName*/,
33                 const std::shared_ptr<GeomAPI_Shape>& theShape,
34                 std::string& theError)
35 {
36   #ifdef _DEBUG
37   std::cout << "Export STEP into file " << theFileName << std::endl;
38   #endif
39
40   if (!theShape.get()) {
41     theError = "STEP Export failed: An invalid argument";
42     return false;
43   }
44
45   try
46   {
47     // Set "C" numeric locale to save numbers correctly
48     GeomAlgoAPI_Tools::Localizer loc;
49
50     IFSelect_ReturnStatus status ;
51     //VRV: OCC 4.0 migration
52     STEPControl_Writer aWriter;
53     Interface_Static::SetCVal("xstep.cascade.unit","M");
54     Interface_Static::SetCVal("write.step.unit", "M");
55     Interface_Static::SetIVal("write.step.nonmanifold", 1);
56     status = aWriter.Transfer(theShape->impl<TopoDS_Shape>(), STEPControl_AsIs);
57     //VRV: OCC 4.0 migration
58     if( status == IFSelect_RetDone )
59       status = aWriter.Write(theFileName.c_str());
60
61     // Return previous locale
62     if( status == IFSelect_RetDone )
63       return true;
64   }
65   catch (Standard_Failure)
66   {
67     theError = "Exception catched in STEPExport";
68   }
69   return false;
70 }