Salome HOME
Issue #2324: Update all indexes on show/hide
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_STEPExport.cpp
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <GeomAlgoAPI_STEPExport.h>
22
23 #include "GeomAlgoAPI_Tools.h"
24
25 #include <TopoDS_Shape.hxx>
26
27 // OOCT includes
28 #include <IFSelect_ReturnStatus.hxx>
29 #include <STEPControl_Writer.hxx>
30 #include <Interface_Static.hxx>
31
32 bool STEPExport(const std::string& theFileName,
33                 const std::string& theFormatName,
34                 const std::shared_ptr<GeomAPI_Shape>& theShape,
35                 std::string& theError)
36 {
37   #ifdef _DEBUG
38   std::cout << "Export STEP into file " << theFileName << std::endl;
39   #endif
40
41   if (!theShape.get()) {
42     theError = "STEP Export failed: An invalid argument";
43     return false;
44   }
45
46   try
47   {
48     // Set "C" numeric locale to save numbers correctly
49     GeomAlgoAPI_Tools::Localizer loc;
50
51     IFSelect_ReturnStatus status ;
52     //VRV: OCC 4.0 migration
53     STEPControl_Writer aWriter;
54     Interface_Static::SetCVal("xstep.cascade.unit","M");
55     Interface_Static::SetCVal("write.step.unit", "M");
56     Interface_Static::SetIVal("write.step.nonmanifold", 1);
57     status = aWriter.Transfer(theShape->impl<TopoDS_Shape>(), STEPControl_AsIs);
58     //VRV: OCC 4.0 migration
59     if( status == IFSelect_RetDone )
60       status = aWriter.Write(theFileName.c_str());
61
62     // Return previous locale
63     if( status == IFSelect_RetDone )
64       return true;
65   }
66   catch (Standard_Failure)
67   {
68     theError = "Exception catched in STEPExport";
69   }
70   return false;
71 }