Salome HOME
Migration to OCCT 7.0
[modules/geom.git] / src / STEPPlugin / STEPPlugin_ExportDriver.cxx
1 // Copyright (C) 2014-2016  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 #include "STEPPlugin_IOperations.hxx"
24
25 // KERNEL includes
26 #include <utilities.h>
27 #include <Basics_Utils.hxx>
28
29 // GEOM includes
30 #include "GEOM_Function.hxx"
31
32 // OOCT includes
33 #include <IFSelect_ReturnStatus.hxx>
34 #include <STEPControl_Writer.hxx>
35 #include <Interface_Static.hxx>
36 #include <TCollection_AsciiString.hxx>
37 #include <TopoDS_Shape.hxx>
38
39 //=======================================================================
40 //function : GetID
41 //purpose  :
42 //=======================================================================
43 const Standard_GUID& STEPPlugin_ExportDriver::GetID()
44 {
45   static Standard_GUID aGUID("c47b9a61-c6a4-4335-8b13-6badb16b036f");
46   return aGUID;
47 }
48
49 //=======================================================================
50 //function : STEPPlugin_ExportDriver
51 //purpose  :
52 //=======================================================================
53 STEPPlugin_ExportDriver::STEPPlugin_ExportDriver()
54 {
55 }
56
57 //=======================================================================
58 //function : Execute
59 //purpose  :
60 //=======================================================================
61 Standard_Integer STEPPlugin_ExportDriver::Execute(LOGBOOK& log) const
62 {
63   if (Label().IsNull()) return 0;
64   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
65
66   STEPPlugin_IExport aData (aFunction);
67
68   // retrieve the being exported shape
69   TopoDS_Shape aShape;
70   Handle(GEOM_Function) aRefFunction = aData.GetOriginal();
71   if( aRefFunction.IsNull() ) return 0;
72   aShape = aRefFunction->GetValue();
73   if( aShape.IsNull() ) return 0;
74   // set the result of function to be used by next operations
75   aFunction->SetValue( aShape );
76
77   TCollection_AsciiString aFileName = aData.GetFileName();
78   Standard_Integer        anUnit    = aData.GetUnit();
79   TCollection_AsciiString aWriteUnit;
80
81   switch (anUnit) {
82   case STEPPlugin_IOperations::LengthUnit_Inch:
83     aWriteUnit = "INCH";
84     break;
85   case STEPPlugin_IOperations::LengthUnit_Millimeter:
86     aWriteUnit = "MM";
87     break;
88   case STEPPlugin_IOperations::LengthUnit_Foot:
89     aWriteUnit = "FT";
90     break;
91   case STEPPlugin_IOperations::LengthUnit_Mile:
92     aWriteUnit = "MI";
93     break;
94   case STEPPlugin_IOperations::LengthUnit_Meter:
95     aWriteUnit = "M";
96     break;
97   case STEPPlugin_IOperations::LengthUnit_Kilometer:
98     aWriteUnit = "KM";
99     break;
100   case STEPPlugin_IOperations::LengthUnit_Milliinch:
101     aWriteUnit = "MIL";
102     break;
103   case STEPPlugin_IOperations::LengthUnit_Micrometer:
104     aWriteUnit = "UM";
105     break;
106   case STEPPlugin_IOperations::LengthUnit_Centimeter:
107     aWriteUnit = "CM";
108     break;
109   case STEPPlugin_IOperations::LengthUnit_Microinch:
110     aWriteUnit = "UIN";
111     break;
112   default:
113     return 0;
114   }
115
116   MESSAGE("Export STEP into file " << aFileName.ToCString());
117
118   try
119   {
120     // Set "C" numeric locale to save numbers correctly
121     Kernel_Utils::Localizer loc;
122
123     IFSelect_ReturnStatus status ;
124     //VRV: OCC 4.0 migration
125     STEPControl_Writer aWriter;
126     Interface_Static::SetCVal("xstep.cascade.unit","M");
127     Interface_Static::SetCVal("write.step.unit", aWriteUnit.ToCString());
128     Interface_Static::SetIVal("write.step.nonmanifold", 1);
129     status = aWriter.Transfer( aShape, STEPControl_AsIs );
130     //VRV: OCC 4.0 migration
131     if( status == IFSelect_RetDone )
132       status = aWriter.Write( aFileName.ToCString() );
133
134     // Return previous locale
135     if( status == IFSelect_RetDone )
136       return 1;
137   }
138   catch (Standard_Failure)
139   {
140       //THROW_SALOME_CORBA_EXCEPTION("Exception catched in STEPExport", SALOME::BAD_PARAM);
141   }
142   return 0;
143 }
144
145 //================================================================================
146 /*!
147  * \brief Returns a name of creation operation and names and values of creation parameters
148  */
149 //================================================================================
150 bool STEPPlugin_ExportDriver::
151 GetCreationInformation( std::string&             theOperationName,
152                         std::vector<GEOM_Param>& theParams )
153 {
154   return false;
155 }
156
157 OCCT_IMPLEMENT_STANDARD_RTTIEXT( STEPPlugin_ExportDriver,GEOM_BaseDriver );