1 // Copyright (C) 2014 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "STLPlugin_ExportDriver.hxx"
22 #include "STLPlugin_IExport.hxx"
25 #include <utilities.h>
26 #include <Basics_Utils.hxx>
29 #include "GEOM_Function.hxx"
32 #include <BRepBuilderAPI_Copy.hxx>
33 #include <StlAPI_Writer.hxx>
34 #include <TopoDS_Shape.hxx>
36 //=======================================================================
39 //=======================================================================
40 const Standard_GUID& STLPlugin_ExportDriver::GetID()
42 static Standard_GUID aGUID("88678a6a-885c-477c-b90b-51934572c61d");
46 //=======================================================================
47 //function : STLPlugin_ExportDriver
49 //=======================================================================
50 STLPlugin_ExportDriver::STLPlugin_ExportDriver()
54 //=======================================================================
57 //=======================================================================
58 Standard_Integer STLPlugin_ExportDriver::Execute( TFunction_Logbook& log ) const
60 if (Label().IsNull()) return 0;
61 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
63 STLPlugin_IExport aData (aFunction);
65 // retrieve the being exported shape
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 );
74 TCollection_AsciiString aFileName = aData.GetFileName();
75 double aDeflection = aData.GetDeflection();
76 bool anIsASCII = aData.GetIsASCII();
77 bool anIsRelative = aData.GetIsRelative();
79 MESSAGE( "Export STL into file " << aFileName );
81 // Set "C" numeric locale to save numbers correctly
82 Kernel_Utils::Localizer loc;
86 StlAPI_Writer aWriter;
87 // set relative mode on false for using custom deflection coefficient
88 aWriter.RelativeMode( ) = anIsRelative;
89 aWriter.ASCIIMode() = anIsASCII;
91 aWriter.SetCoefficient( aDeflection );
93 aWriter.SetDeflection( aDeflection );
94 BRepBuilderAPI_Copy aCopy( aShape, Standard_False );
95 aWriter.Write( aCopy.Shape(), aFileName.ToCString() );
96 log.SetTouched( Label() );
99 catch( Standard_Failure )
101 //THROW_SALOME_CORBA_EXCEPTION("Exception catched in ExportSTL", SALOME::BAD_PARAM);
106 //=======================================================================
107 //function : MustExecute
109 //=======================================================================
110 Standard_Boolean STLPlugin_ExportDriver::MustExecute( const TFunction_Logbook& ) const
112 return Standard_True;
115 //================================================================================
117 * \brief Returns a name of creation operation and names and values of creation parameters
119 //================================================================================
120 bool STLPlugin_ExportDriver::
121 GetCreationInformation( std::string& theOperationName,
122 std::vector<GEOM_Param>& theParams )
127 IMPLEMENT_STANDARD_HANDLE( STLPlugin_ExportDriver,GEOM_BaseDriver );
128 IMPLEMENT_STANDARD_RTTIEXT( STLPlugin_ExportDriver,GEOM_BaseDriver );