]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/IO/MeshWriter.cxx
More tree visualization
[cpPlugins.git] / lib / cpPlugins / Plugins / IO / MeshWriter.cxx
1 #include "MeshWriter.h"
2 #include <cpPlugins/Interface/Mesh.h>
3
4 #include <vtkSmartPointer.h>
5 #include <vtkPolyData.h>
6 #include <vtkPolyDataWriter.h>
7
8 #ifdef cpPlugins_Interface_QT4
9 #include <QFileDialog>
10 #endif // cpPlugins_Interface_QT4
11
12 // -------------------------------------------------------------------------
13 bool cpPlugins::IO::MeshWriter::
14 ExecConfigurationDialog( QWidget* parent )
15 {
16   bool r = false;
17
18 #ifdef cpPlugins_Interface_QT4
19
20   std::string name = this->m_Parameters->GetString( "FileName" );
21   if( name == "" )
22     name = "save.vtk";
23
24   // Show dialog and check if it was accepted
25   QString qname =
26     QFileDialog::getSaveFileName(
27       parent,
28       QFileDialog::tr( "Save File" ),
29       QFileDialog::tr( name.c_str( ) ),
30       QFileDialog::tr( "Mesh files (*.vtk *.stl *.obj);;Any file (*)")
31       );
32   name = qname.toStdString( );
33   if( name != "" )
34   {
35     this->m_Parameters->SetString( "FileName", name );
36     r = true;
37
38   } // fi
39
40 #endif // cpPlugins_Interface_QT4
41
42   return( r );
43 }
44
45 // -------------------------------------------------------------------------
46 cpPlugins::IO::MeshWriter::
47 MeshWriter( )
48   : Superclass( )
49 {
50   this->_AddInput( "Input" );
51
52   this->m_Parameters->ConfigureAsString( "FileName", "" );
53 }
54
55 // -------------------------------------------------------------------------
56 cpPlugins::IO::MeshWriter::
57 ~MeshWriter( )
58 {
59 }
60
61 // -------------------------------------------------------------------------
62 std::string cpPlugins::IO::MeshWriter::
63 _GenerateData( )
64 {
65   cpPlugins::Interface::Mesh* mesh =
66     this->GetInput< cpPlugins::Interface::Mesh >( "Input" );
67   if( mesh == NULL )
68     return( "MeshWriter: No input mesh." );
69   vtkPolyData* i = mesh->GetVTK< vtkPolyData >( );
70   if( i == NULL )
71     return( "MeshWriter: No suitable input." );
72   std::string fname = this->m_Parameters->GetString( "FileName" );
73
74   vtkPolyDataWriter* pdw = this->_CreateVTK< vtkPolyDataWriter >( );
75   pdw->SetInputData( i );
76   pdw->SetFileName( fname.c_str( ) );
77   pdw->Update( );
78   if( pdw->GetErrorCode( ) != 0 )
79     return( "MeshWriter: someting wrong happened." );
80   return( "" );
81 }
82
83 // eof - $RCSfile$