1 // Copyright (C) 2014-2016 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>
35 #include <Bnd_Box.hxx>
36 #include <BRepBndLib.hxx>
37 #include <BRepTools.hxx>
38 #include <BRepMesh_IncrementalMesh.hxx>
40 #define MAX2(X, Y) ( Abs(X) > Abs(Y) ? Abs(X) : Abs(Y) )
41 #define MAX3(X, Y, Z) ( MAX2 ( MAX2(X, Y) , Z ) )
43 //=======================================================================
46 //=======================================================================
47 const Standard_GUID& STLPlugin_ExportDriver::GetID()
49 static Standard_GUID aGUID("88678a6a-885c-477c-b90b-51934572c61d");
53 //=======================================================================
54 //function : STLPlugin_ExportDriver
56 //=======================================================================
57 STLPlugin_ExportDriver::STLPlugin_ExportDriver()
61 //=======================================================================
64 //=======================================================================
65 Standard_Integer STLPlugin_ExportDriver::Execute(Handle(TFunction_Logbook)& log) const
67 if (Label().IsNull()) return 0;
68 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
70 STLPlugin_IExport aData (aFunction);
72 // retrieve the being exported shape
74 Handle(GEOM_Function) aRefFunction = aData.GetOriginal();
75 if( aRefFunction.IsNull() ) return 0;
76 aShape = aRefFunction->GetValue();
77 if( aShape.IsNull() ) return 0;
78 // set the result of function to be used by next operations
79 aFunction->SetValue( aShape );
81 TCollection_AsciiString aFileName = aData.GetFileName();
82 double aDeflection = aData.GetDeflection();
83 bool anIsASCII = aData.GetIsASCII();
84 bool anIsRelative = aData.GetIsRelative();
86 MESSAGE( "Export STL into file " << aFileName );
88 // Set "C" numeric locale to save numbers correctly
89 Kernel_Utils::Localizer loc;
93 StlAPI_Writer aWriter;
95 BRepBuilderAPI_Copy aCopy( aShape, Standard_False );
96 TopoDS_Shape aCopyShape = aCopy.Shape();
98 aWriter.ASCIIMode() = anIsASCII;
100 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
102 BRepBndLib::Add( aShape, bndBox );
103 bndBox.Get( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
104 aDeflection = MAX3( aXmax-aXmin, aYmax-aYmin, aZmax-aZmin ) * aDeflection;
106 //Compute triangulation
107 BRepTools::Clean( aCopyShape );
108 BRepMesh_IncrementalMesh aMesh( aCopyShape, aDeflection );
109 aWriter.Write( aCopyShape, aFileName.ToCString() );
110 log->SetTouched(Label());
113 catch( Standard_Failure )
115 //THROW_SALOME_CORBA_EXCEPTION("Exception caught in ExportSTL", SALOME::BAD_PARAM);
120 //================================================================================
122 * \brief Returns a name of creation operation and names and values of creation parameters
124 //================================================================================
125 bool STLPlugin_ExportDriver::
126 GetCreationInformation( std::string& theOperationName,
127 std::vector<GEOM_Param>& theParams )
132 IMPLEMENT_STANDARD_RTTIEXT( STLPlugin_ExportDriver,GEOM_BaseDriver );