Salome HOME
8f5f0db18ca296283bd5fe79cb4015af3fcb97df
[modules/geom.git] / src / STEPPlugin / STEPPlugin_ExportDriver.cxx
1 // Copyright (C) 2014-2015  CEA/DEN, EDF R&D, OPEN CASCADE
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 // internal includes
21 #include "STEPPlugin_ExportDriver.hxx"
22 #include "STEPPlugin_IExport.hxx"
23
24 // KERNEL includes
25 #include <utilities.h>
26 #include <Basics_Utils.hxx>
27
28 // GEOM includes
29 #include "GEOM_Function.hxx"
30
31 // OOCT includes
32 #include <IFSelect_ReturnStatus.hxx>
33 #include <STEPControl_Writer.hxx>
34 #include <Interface_Static.hxx>
35 #include <TCollection_AsciiString.hxx>
36 #include <TopoDS_Shape.hxx>
37
38 //=======================================================================
39 //function : GetID
40 //purpose  :
41 //=======================================================================
42 const Standard_GUID& STEPPlugin_ExportDriver::GetID()
43 {
44   static Standard_GUID aGUID("c47b9a61-c6a4-4335-8b13-6badb16b036f");
45   return aGUID;
46 }
47
48 //=======================================================================
49 //function : STEPPlugin_ExportDriver
50 //purpose  :
51 //=======================================================================
52 STEPPlugin_ExportDriver::STEPPlugin_ExportDriver()
53 {
54 }
55
56 //=======================================================================
57 //function : Execute
58 //purpose  :
59 //=======================================================================
60 Standard_Integer STEPPlugin_ExportDriver::Execute( TFunction_Logbook& log ) const
61 {
62   if (Label().IsNull()) return 0;
63   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
64
65   STEPPlugin_IExport aData (aFunction);
66
67   // retrieve the being exported shape
68   TopoDS_Shape aShape;
69   Handle(GEOM_Function) aRefFunction = aData.GetOriginal();
70   if( aRefFunction.IsNull() ) return 0;
71   aShape = aRefFunction->GetValue();
72   if( aShape.IsNull() ) return 0;
73   // set the result of function to be used by next operations
74   aFunction->SetValue( aShape );
75
76   TCollection_AsciiString aFileName = aData.GetFileName();
77
78   MESSAGE("Export STEP into file " << aFileName.ToCString());
79
80   try
81   {
82     // Set "C" numeric locale to save numbers correctly
83     Kernel_Utils::Localizer loc;
84
85     IFSelect_ReturnStatus status ;
86     //VRV: OCC 4.0 migration
87     STEPControl_Writer aWriter;
88     Interface_Static::SetCVal("xstep.cascade.unit","M");
89     Interface_Static::SetCVal("write.step.unit", "M");
90     Interface_Static::SetIVal("write.step.nonmanifold", 1);
91     status = aWriter.Transfer( aShape, STEPControl_AsIs );
92     //VRV: OCC 4.0 migration
93     if( status == IFSelect_RetDone )
94       status = aWriter.Write( aFileName.ToCString() );
95
96     // Return previous locale
97     if( status == IFSelect_RetDone )
98       return 1;
99   }
100   catch (Standard_Failure)
101   {
102       //THROW_SALOME_CORBA_EXCEPTION("Exception catched in STEPExport", SALOME::BAD_PARAM);
103   }
104   return 0;
105 }
106
107 //=======================================================================
108 //function : MustExecute
109 //purpose  :
110 //=======================================================================
111 Standard_Boolean STEPPlugin_ExportDriver::MustExecute( const TFunction_Logbook& ) const
112 {
113   return Standard_True;
114 }
115
116 //================================================================================
117 /*!
118  * \brief Returns a name of creation operation and names and values of creation parameters
119  */
120 //================================================================================
121 bool STEPPlugin_ExportDriver::
122 GetCreationInformation( std::string&             theOperationName,
123                         std::vector<GEOM_Param>& theParams )
124 {
125   return false;
126 }
127
128 IMPLEMENT_STANDARD_HANDLE( STEPPlugin_ExportDriver,GEOM_BaseDriver );
129 IMPLEMENT_STANDARD_RTTIEXT( STEPPlugin_ExportDriver,GEOM_BaseDriver );