Salome HOME
Remove obsolete conditionals
[modules/geom.git] / src / STLPlugin / STLPlugin_ExportDriver.cxx
1 // Copyright (C) 2014  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 "STLPlugin_ExportDriver.hxx"
22 #include "STLPlugin_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 <BRepBuilderAPI_Copy.hxx>
33 #include <StlAPI_Writer.hxx>
34 #include <TopoDS_Shape.hxx>
35
36 //=======================================================================
37 //function : GetID
38 //purpose  :
39 //=======================================================================
40 const Standard_GUID& STLPlugin_ExportDriver::GetID()
41 {
42   static Standard_GUID aGUID("88678a6a-885c-477c-b90b-51934572c61d");
43   return aGUID;
44 }
45
46 //=======================================================================
47 //function : STLPlugin_ExportDriver
48 //purpose  :
49 //=======================================================================
50 STLPlugin_ExportDriver::STLPlugin_ExportDriver()
51 {
52 }
53
54 //=======================================================================
55 //function : Execute
56 //purpose  :
57 //=======================================================================
58 Standard_Integer STLPlugin_ExportDriver::Execute( TFunction_Logbook& log ) const
59 {
60   if (Label().IsNull()) return 0;
61   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
62
63   STLPlugin_IExport aData (aFunction);
64
65   // retrieve the being exported shape
66   TopoDS_Shape aShape;
67   Handle(GEOM_Function) aRefFunction = aData.GetOriginal();
68   if( aRefFunction.IsNull() ) return 0;
69   aShape = aRefFunction->GetValue();
70   if( aShape.IsNull() ) return 0;
71   // set the result of function to be used by next operations
72   aFunction->SetValue( aShape );
73
74   TCollection_AsciiString aFileName = aData.GetFileName();
75   double aDeflection = aData.GetDeflection();
76   bool anIsASCII = aData.GetIsASCII();
77   bool anIsRelative = aData.GetIsRelative();
78
79   MESSAGE( "Export STL into file " << aFileName );
80
81   // Set "C" numeric locale to save numbers correctly
82   Kernel_Utils::Localizer loc;
83
84   try
85   {
86     StlAPI_Writer aWriter;
87     // set relative mode on false for using custom deflection coefficient
88     aWriter.RelativeMode( ) = anIsRelative;
89     aWriter.ASCIIMode() = anIsASCII;
90     if( anIsRelative )
91       aWriter.SetCoefficient( aDeflection );
92     else
93       aWriter.SetDeflection( aDeflection );
94     BRepBuilderAPI_Copy aCopy( aShape, Standard_False );
95     aWriter.Write( aCopy.Shape(), aFileName.ToCString() );
96     log.SetTouched( Label() );
97     return 1;
98   }
99   catch( Standard_Failure )
100   {
101     //THROW_SALOME_CORBA_EXCEPTION("Exception catched in ExportSTL", SALOME::BAD_PARAM);
102   }
103   return 0;
104 }
105
106 //=======================================================================
107 //function : MustExecute
108 //purpose  :
109 //=======================================================================
110 Standard_Boolean STLPlugin_ExportDriver::MustExecute( const TFunction_Logbook& ) const
111 {
112   return Standard_True;
113 }
114
115 //================================================================================
116 /*!
117  * \brief Returns a name of creation operation and names and values of creation parameters
118  */
119 //================================================================================
120 bool STLPlugin_ExportDriver::
121 GetCreationInformation( std::string&             theOperationName,
122                         std::vector<GEOM_Param>& theParams )
123 {
124   return false;
125 }
126
127 IMPLEMENT_STANDARD_HANDLE( STLPlugin_ExportDriver,GEOM_BaseDriver );
128 IMPLEMENT_STANDARD_RTTIEXT( STLPlugin_ExportDriver,GEOM_BaseDriver );