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 "VTKPlugin_ExportDriver.hxx"
22 #include "VTKPlugin_IExport.hxx"
25 #include <utilities.h>
26 #include <Basics_Utils.hxx>
29 #include "GEOM_Function.hxx"
30 #include "OCC2VTK_Tools.h"
31 #include "GEOM_VertexSource.h"
32 #include "GEOM_EdgeSource.h"
33 #include "GEOM_WireframeFace.h"
34 #include "GEOM_ShadingFace.h"
37 #include <TCollection_AsciiString.hxx>
39 #include <TopExp_Explorer.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <Poly_Triangulation.hxx>
43 #include <BRep_Tool.hxx>
44 #include <BRepTools.hxx>
47 #include <vtkAppendPolyData.h>
48 #include <vtkPolyDataWriter.h>
50 //=======================================================================
53 //=======================================================================
54 const Standard_GUID& VTKPlugin_ExportDriver::GetID()
56 static Standard_GUID aGUID("0966443c-6f3c-4ebe-ba46-c0833786d817");
60 //=======================================================================
61 //function : VTKPlugin_ExportDriver
63 //=======================================================================
64 VTKPlugin_ExportDriver::VTKPlugin_ExportDriver()
68 //=======================================================================
71 //=======================================================================
72 Standard_Integer VTKPlugin_ExportDriver::Execute(Handle(TFunction_Logbook)& log) const
74 if (Label().IsNull()) return 0;
75 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
77 VTKPlugin_IExport aData (aFunction);
79 // retrieve the being exported shape
81 Handle(GEOM_Function) aRefFunction = aData.GetOriginal();
82 if( aRefFunction.IsNull() ) return 0;
83 aShape = aRefFunction->GetValue();
84 if( aShape.IsNull() ) return 0;
85 // set the result of function to be used by next operations
86 aFunction->SetValue( aShape );
88 TCollection_AsciiString aFileName = aData.GetFileName();
89 float aDeflection = float( aData.GetDeflection() );
91 MESSAGE( "Export VTK into file " << aFileName );
94 // Set "C" numeric locale to save numbers correctly
95 Kernel_Utils::Localizer loc;
97 vtkPolyData* pd = GEOM::GetVTKData( aShape, aDeflection );
98 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
99 aWriter->SetInputData( pd );
100 aWriter->SetFileName( aFileName.ToCString() );
103 pd->Delete(); //instanciated by the GEOM::GetData(...) method
107 catch( Standard_Failure )
109 //THROW_SALOME_CORBA_EXCEPTION("Exception catched in ExportVTK", SALOME::BAD_PARAM);
114 //================================================================================
116 * \brief Returns a name of creation operation and names and values of creation parameters
118 //================================================================================
119 bool VTKPlugin_ExportDriver::
120 GetCreationInformation( std::string& theOperationName,
121 std::vector<GEOM_Param>& theParams )
126 IMPLEMENT_STANDARD_RTTIEXT( VTKPlugin_ExportDriver,GEOM_BaseDriver );