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