Salome HOME
220644989a40bea718f255c70dea4f730dd19602
[modules/geom.git] / src / VTKPlugin / VTKPlugin_ExportDriver.cxx
1 // Copyright (C) 2014-2023  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 "VTKPlugin_ExportDriver.hxx"
22 #include "VTKPlugin_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 #include "OCC2VTK_Tools.h"
31 #include "GEOM_VertexSource.h"
32 #include "GEOM_EdgeSource.h"
33 #include "GEOM_WireframeFace.h"
34 #include "GEOM_ShadingFace.h"
35
36 // OOCT includes
37 #include <TCollection_AsciiString.hxx>
38 #include <TopExp.hxx>
39 #include <TopExp_Explorer.hxx>
40 #include <TopoDS.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <Poly_Triangulation.hxx>
43 #include <BRep_Tool.hxx>
44 #include <BRepTools.hxx>
45
46 // VTK includes
47 #include <vtkAppendPolyData.h>
48 #include <vtkPolyDataWriter.h>
49
50 //=======================================================================
51 //function : GetID
52 //purpose  :
53 //=======================================================================
54 const Standard_GUID& VTKPlugin_ExportDriver::GetID()
55 {
56   static Standard_GUID aGUID("0966443c-6f3c-4ebe-ba46-c0833786d817");
57   return aGUID;
58 }
59
60 //=======================================================================
61 //function : VTKPlugin_ExportDriver
62 //purpose  :
63 //=======================================================================
64 VTKPlugin_ExportDriver::VTKPlugin_ExportDriver()
65 {
66 }
67
68 //=======================================================================
69 //function : Execute
70 //purpose  :
71 //=======================================================================
72 Standard_Integer VTKPlugin_ExportDriver::Execute(Handle(TFunction_Logbook)& /*log*/) const
73 {
74   if (Label().IsNull()) return 0;
75   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
76
77   VTKPlugin_IExport aData (aFunction);
78
79   // retrieve the being exported shape
80   TopoDS_Shape aShape;
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 );
87
88   TCollection_AsciiString aFileName = aData.GetFileName();
89   float aDeflection = float( aData.GetDeflection() );
90
91   MESSAGE( "Export VTK into file " << aFileName );
92   try
93   {
94     // Set "C" numeric locale to save numbers correctly
95     Kernel_Utils::Localizer loc;
96
97     vtkPolyData* pd = GEOM::GetVTKData( aShape, aDeflection );
98     vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();    
99     aWriter->SetInputData( pd );
100     aWriter->SetFileName( aFileName.ToCString() );
101     aWriter->Write();
102     aWriter->Delete();
103     pd->Delete(); //instantiated by the GEOM::GetData(...) method
104
105     return 1;
106   }
107   catch( Standard_Failure& )
108   {
109     //THROW_SALOME_CORBA_EXCEPTION("Exception caught in ExportVTK", SALOME::BAD_PARAM);
110   }
111   return 0;
112 }
113
114 //================================================================================
115 /*!
116  * \brief Returns a name of creation operation and names and values of creation parameters
117  */
118 //================================================================================
119 bool VTKPlugin_ExportDriver::
120 GetCreationInformation( std::string&             /*theOperationName*/,
121                         std::vector<GEOM_Param>& /*theParams*/ )
122 {
123   return false;
124 }
125
126 IMPLEMENT_STANDARD_RTTIEXT( VTKPlugin_ExportDriver,GEOM_BaseDriver )