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