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