]> Creatis software - cpPlugins.git/blob - plugins/VTKIO/MeshWriter.cxx
fa44b2d56a3161fb70c813604aa76436d1a54ca3
[cpPlugins.git] / plugins / VTKIO / MeshWriter.cxx
1 #include <VTKIO/MeshWriter.h>
2 #include <cpInstances/DataObjects/Mesh.h>
3 #include <cpPlugins/QT/SaveFileDialog.h>
4
5 #include <vtkPolyData.h>
6 #include <vtkPolyDataWriter.h>
7
8 #ifdef cpPlugins_QT4
9 #  include <QApplication>
10 #endif // cpPlugins_QT4
11
12 // -------------------------------------------------------------------------
13 QDialog* cpPluginsVTKIO::MeshWriter::
14 CreateQDialog( )
15 {
16 #ifdef cpPlugins_QT4
17   cpPlugins::QT::SaveFileDialog* dlg = NULL;
18   if( QApplication::instance( ) != NULL )
19   {
20     dlg = new cpPlugins::QT::SaveFileDialog( );
21     dlg->SetParameters( &( this->m_Parameters ), "FileName" );
22
23   } // fi
24   return( dlg );
25 #else // cpPlugins_QT4
26   return( NULL );
27 #endif // cpPlugins_QT4
28 }
29
30 // -------------------------------------------------------------------------
31 cpPluginsVTKIO::MeshWriter::
32 MeshWriter( )
33   : Superclass( )
34 {
35   this->_ConfigureInput< cpInstances::DataObjects::Mesh >( "Input", true, false );
36   this->m_Parameters.Clear( );
37   this->m_Parameters.ConfigureAsSaveFileName( "FileName", "" );
38   this->m_Parameters.SetAcceptedFileExtensions(
39     "FileName",
40     "Mesh files (*.vtk)"
41     );
42 }
43
44 // -------------------------------------------------------------------------
45 cpPluginsVTKIO::MeshWriter::
46 ~MeshWriter( )
47 {
48 }
49
50 // -------------------------------------------------------------------------
51 void cpPluginsVTKIO::MeshWriter::
52 _GenerateData( )
53 {
54   auto mesh = this->GetInputData< vtkPolyData >( "Input" );
55   if( mesh == NULL )
56     this->_Error( "Invalid input mesh." );
57
58   auto f = this->_CreateVTK< vtkPolyDataWriter >( );
59   f->SetFileName( this->m_Parameters.GetSaveFileName( "FileName" ).c_str( ) );
60   f->SetInputData( mesh );
61   f->SetFileTypeToBinary( );
62   f->Update( );
63 }
64
65 // eof - $RCSfile$