]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Plugins/IO/MeshReader.cxx
Getting ready for interactive initialization.
[cpPlugins.git] / lib / cpPlugins / Plugins / IO / MeshReader.cxx
index 67069046163d768395fc55d2e23c5b8a871f6497..f8c3b84483a96a6b79be61bf9a11eb056fddcd48 100644 (file)
@@ -4,33 +4,59 @@
 #include <vtkPolyData.h>
 #include <vtkPolyDataReader.h>
 
+#ifdef cpPlugins_Interface_QT4
+#include <QFileDialog>
+#endif // cpPlugins_Interface_QT4
+
 // -------------------------------------------------------------------------
 cpPlugins::IO::MeshReader::
-MeshReader( )
-  : Superclass( ),
-    m_Reader( NULL )
+DialogResult cpPlugins::IO::MeshReader::
+ExecConfigurationDialog( QWidget* parent )
 {
-  this->m_ClassName = "cpPlugins::IO::MeshReader";
-  this->m_ClassCategory = "MeshReader";
+  DialogResult r = Self::DialogResult_Cancel;
 
-  this->SetNumberOfOutputs( 1 );
-  this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
+#ifdef cpPlugins_Interface_QT4
 
-  using namespace cpPlugins::Interface;
-  this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
-  this->m_DefaultParameters.Configure( Parameters::String, "PixelType" );
-  this->m_DefaultParameters.Configure( Parameters::Uint, "Dimension" );
-  this->m_DefaultParameters.SetValueAsString( "PixelType", "float" );
-  this->m_DefaultParameters.SetValueAsUint( "Dimension", 3 );
-  this->m_Parameters = this->m_DefaultParameters;
+  // Show dialog and check if it was accepted
+  QFileDialog dialog( parent );
+  dialog.setFileMode( QFileDialog::ExistingFile );
+  dialog.setDirectory( QFileDialog::tr( "." ) );
+  dialog.setNameFilter( QFileDialog::tr( "All files (*)" ) );
+  if( dialog.exec( ) )
+  {
+    QStringList names = dialog.selectedFiles( );
+    this->m_Parameters->SetString( "FileName", names[ 0 ].toStdString( ) );
+    this->m_Parameters->SetSelectedChoice( "PixelType", "float" );
+    this->m_Parameters->SetUint( "Dimension", 3 );
+
+    r = Self::DialogResult_NoModal;
+
+  } // fi
+
+#endif // cpPlugins_Interface_QT4
+
+  return( r );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::IO::MeshReader::
+MeshReader( )
+  : Superclass( )
+{
+  this->_MakeOutput< cpPlugins::Interface::Mesh >( "Output" );
+
+  std::vector< TParameters::TString > valid_types;
+  valid_types.push_back( "float" );
+  valid_types.push_back( "double" );
+  this->m_Parameters->ConfigureAsString( "FileName", "" );
+  this->m_Parameters->ConfigureAsChoices( "PixelType", valid_types );
+  this->m_Parameters->ConfigureAsUint( "Dimension", 3 );
 }
 
 // -------------------------------------------------------------------------
 cpPlugins::IO::MeshReader::
 ~MeshReader( )
 {
-  if( this->m_Reader != NULL )
-    this->m_Reader = NULL;
 }
 
 // -------------------------------------------------------------------------
@@ -38,7 +64,7 @@ std::string cpPlugins::IO::MeshReader::
 _GenerateData( )
 {
   using namespace cpPlugins::Interface;
-  Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" );
+  Parameters::TUint dim = this->m_Parameters->GetUint( "Dimension" );
   std::string r = "MeshReader: Mesh dimension not supported.";
   if( dim == 2 )
     r = this->_GD0< 2 >( );
@@ -53,7 +79,8 @@ std::string cpPlugins::IO::MeshReader::
 _GD0( )
 {
   using namespace cpPlugins::Interface;
-  Parameters::TString pt = this->m_Parameters.GetValueAsString( "PixelType" );
+  Parameters::TString pt =
+    this->m_Parameters->GetSelectedChoice( "PixelType" );
   std::string r = "MeshReader: Mesh pixel type not supported";
   if( pt == "float" )       r = this->_GD1< float, D >( );
   else if( pt == "double" ) r = this->_GD1< double, D >( );
@@ -66,22 +93,16 @@ std::string cpPlugins::IO::MeshReader::
 _GD1( )
 {
   // Get filename
-  using namespace cpPlugins::Interface;
-  Parameters::TString fname =
-    this->m_Parameters.GetValueAsString( "FileName" );
-
-  if( this->m_Reader != NULL )
-    this->m_Reader->Delete( );
+  std::string fname = this->m_Parameters->GetString( "FileName" );
 
-  vtkPolyDataReader* pdr = vtkPolyDataReader::New( );
-  this->m_Reader = pdr;
+  vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
   pdr->SetFileName( fname.c_str( ) );
   pdr->Update( );
 
   cpPlugins::Interface::Mesh* out =
-    this->GetOutput< cpPlugins::Interface::Mesh >( 0 );
+    this->GetOutput< cpPlugins::Interface::Mesh >( "Output" );
   if( out != NULL )
-    out->SetVTKMesh( pdr->GetOutput( ) );
+    out->SetVTK( pdr->GetOutput( ) );
   else
     return( "MeshReader: output not correctly created." );
   return( "" );