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