From: Leonardo Florez-Valencia Date: Sun, 25 Oct 2015 02:08:03 +0000 (-0500) Subject: Generic MPR+Plugins application base updated. X-Git-Tag: v0.1~320 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=0bb74f9a32de4ce1559973ebf72fda495aa2c587;p=cpPlugins.git Generic MPR+Plugins application base updated. --- diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index 4b1a4c9..1330603 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -1,6 +1,8 @@ #include "ImageMPR.h" #include "ui_ImageMPR.h" +#include + // ------------------------------------------------------------------------- #define ImageMPR_ConnectAction( ACTION ) \ QObject::connect( \ @@ -13,10 +15,11 @@ ImageMPR:: ImageMPR( QWidget* parent ) : QMainWindow( parent ), m_UI( new Ui::ImageMPR ), - m_ImageLoaded( "" ), - m_Flooding( false ) + m_Plugins( new TPlugins ), + m_MainImage( NULL ) { this->m_UI->setupUi( this ); + this->m_Plugins->SetWidget( this ); // Connect actions ImageMPR_ConnectAction( OpenImage ); @@ -32,8 +35,8 @@ ImageMPR( QWidget* parent ) ImageMPR_ConnectAction( ShowPlugins ); // Try to load default plugins - this->m_UI->MPR->LoadPlugins( ); - this->m_UI->MPR->AssociatePluginsToMenu( + this->m_Plugins->LoadPluginsConfigurationFile( "Plugins.cfg" ); + this->m_Plugins->AssociatePluginsToMenu( this->m_UI->MenuFilters, this, SLOT( _execPlugin( ) ) ); } @@ -43,32 +46,63 @@ ImageMPR:: ~ImageMPR( ) { delete this->m_UI; + delete this->m_Plugins; } // ------------------------------------------------------------------------- void ImageMPR:: _aOpenImage( ) { - if( this->m_ImageLoaded != "" ) + if( this->m_MainImage.IsNotNull( ) ) this->m_UI->MPR->ClearAll( ); - this->m_ImageLoaded = this->m_UI->MPR->LoadImage( ); + if( this->m_Plugins->ReadImage( this->m_MainImage, true ) ) + { + vtkImageData* vimage = this->m_MainImage->GetVTK< vtkImageData >( ); + if( vimage == NULL ) + QMessageBox::critical( + this, + QMessageBox::tr( "Error showing image." ), + QMessageBox::tr( + "Image was read, but no valid VTK conversion was found." + ) + ); + else + this->m_UI->MPR->ShowImage( vimage ); + + } // fi } // ------------------------------------------------------------------------- void ImageMPR:: _aOpenDICOMSeries( ) { - if( this->m_ImageLoaded != "" ) + if( this->m_MainImage.IsNotNull( ) ) this->m_UI->MPR->ClearAll( ); - this->m_ImageLoaded = this->m_UI->MPR->LoadDicomSeries( ); + if( this->m_Plugins->ReadDicomSeries( this->m_MainImage ) ) + { + vtkImageData* vimage = this->m_MainImage->GetVTK< vtkImageData >( ); + if( vimage == NULL ) + QMessageBox::critical( + this, + QMessageBox::tr( "Error showing image." ), + QMessageBox::tr( + "Image was read, but no valid VTK conversion was found." + ) + ); + else + this->m_UI->MPR->ShowImage( vimage ); + + } // fi } // ------------------------------------------------------------------------- void ImageMPR:: _aOpenSegmentation( ) { - if( this->m_ImageLoaded != "" ) + /* + if( this->m_ImageLoaded != "" ) this->m_ImageLoaded = this->m_UI->MPR->LoadImage( ); + */ } // ------------------------------------------------------------------------- @@ -81,6 +115,8 @@ _aOpenPolyData( ) void ImageMPR:: _aSaveImage( ) { + if( this->m_MainImage.IsNotNull( ) ) + this->m_Plugins->WriteImage( this->m_MainImage, true ); } // ------------------------------------------------------------------------- @@ -111,8 +147,8 @@ _aRedo( ) void ImageMPR:: _aLoadPlugins( ) { - this->m_UI->MPR->DialogLoadPlugins( ); - this->m_UI->MPR->AssociatePluginsToMenu( + this->m_Plugins->DialogLoadPlugins( ); + this->m_Plugins->AssociatePluginsToMenu( this->m_UI->MenuFilters, this, SLOT( _execPlugin( ) ) ); } @@ -131,21 +167,54 @@ _execPlugin( ) QAction* action = dynamic_cast< QAction* >( this->sender( ) ); if( action == NULL ) return; + QMenu* menu = dynamic_cast< QMenu* >( action->parentWidget( ) ); + if( menu == NULL ) + return; + std::string cate = menu->title( ).toStdString( ); std::string name = action->text( ).toStdString( ); + std::string err = ""; - if( name == "cpPlugins::BasicFilters::FloodFillImageFilter" ) + TPlugins::TProcessObject::Pointer filter; + if( this->m_Plugins->CreateFilter( filter, name ) ) { - this->m_Flooding = true; + if( cate == "ImageToMeshFilter" ) + { + if( filter->ExecConfigurationDialog( this ) ) + { + filter->SetInput( "Input", this->m_MainImage ); + this->_Block( ); + err = filter->Update( ); + this->_Unblock( ); + TPlugins::TMesh::Pointer mesh = + filter->GetOutput< TPlugins::TMesh >( "Input" ); + mesh->Print( std::cout ); + + } // fi + + } // fi } else - { - this->m_Flooding = false; - this->m_UI->MPR->ExecuteFilter( - name, this->m_ImageLoaded, "SegmentedImage" + QMessageBox::critical( + this, + tr( "Error creating filter" ), + tr( "No valid filter defined." ) ); - } // fi - + /* + if( name == "cpPlugins::BasicFilters::FloodFillImageFilter" ) + { + this->m_Flooding = true; + } + else + { + this->m_Flooding = false; + this->m_UI->MPR->ExecuteFilter( + name, this->m_ImageLoaded, "SegmentedImage" + ); + + } // fi + */ + // Configure filter /* TPluginFilter::Pointer filter = diff --git a/appli/ImageMPR/ImageMPR.h b/appli/ImageMPR/ImageMPR.h index b1d43ff..56b4623 100644 --- a/appli/ImageMPR/ImageMPR.h +++ b/appli/ImageMPR/ImageMPR.h @@ -4,6 +4,7 @@ #include // Qt stuff +#include #include // vtk stuff @@ -11,14 +12,7 @@ #include // Plugins interface -#include -#include -#include -#include -#include -#include -#include - +#include // ------------------------------------------------------------------------- namespace Ui @@ -123,6 +117,7 @@ public: typedef QMainWindow Superclass; typedef cpExtensions::Visualization::MPRObjects TMPRObjects; + typedef cpPlugins::Interface::Plugins TPlugins; // Plugins types /* @@ -141,6 +136,18 @@ public: explicit ImageMPR( QWidget* parent = 0 ); virtual ~ImageMPR( ); +protected: + inline void _Block( ) + { + QApplication::setOverrideCursor( Qt::WaitCursor ); + this->setEnabled( false ); + } + inline void _Unblock( ) + { + QApplication::restoreOverrideCursor( ); + this->setEnabled( true ); + } + /* protected: bool _LoadPlugins( const std::string& filename ); @@ -165,10 +172,11 @@ private slots: private: Ui::ImageMPR* m_UI; + TPlugins* m_Plugins; - // Some state flags - std::string m_ImageLoaded; - bool m_Flooding; + // Objects + TPlugins::TImage::Pointer m_MainImage; + std::vector< TPlugins::TMesh::Pointer > m_Meshes; // Plugins objects /* diff --git a/lib/cpPlugins/Interface/BaseMPRWindow.cxx b/lib/cpPlugins/Interface/BaseMPRWindow.cxx index 4cf552c..90100a1 100644 --- a/lib/cpPlugins/Interface/BaseMPRWindow.cxx +++ b/lib/cpPlugins/Interface/BaseMPRWindow.cxx @@ -2,27 +2,10 @@ #ifdef cpPlugins_Interface_QT4 -#ifdef _WIN32 -# define PLUGIN_PREFIX "" -# define PLUGIN_EXT "dll" -# define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)" -#else // Linux -# define PLUGIN_PREFIX "lib" -# define PLUGIN_EXT "so" -# define PLUGIN_REGEX "Plugins file (*.so);;All files (*)" -#endif // _WIN32 - -#include -#include - -#include -#include - // ------------------------------------------------------------------------- cpPlugins::Interface::BaseMPRWindow:: BaseMPRWindow( QWidget* parent ) - : cpExtensions::QT::QuadSplitter( parent ), - m_LastLoadedPlugin( "." ) + : cpExtensions::QT::QuadSplitter( parent ) { // Configure splitter this->m_XVTK = new QVTKWidget( this ); @@ -45,352 +28,72 @@ BaseMPRWindow( QWidget* parent ) cpPlugins::Interface::BaseMPRWindow:: ~BaseMPRWindow( ) { - if( this->m_WVTK != NULL ) - delete this->m_WVTK; - if( this->m_ZVTK != NULL ) - delete this->m_ZVTK; - if( this->m_YVTK != NULL ) - delete this->m_YVTK; - if( this->m_XVTK != NULL ) - delete this->m_XVTK; -} - -// ------------------------------------------------------------------------- -void cpPlugins::Interface::BaseMPRWindow:: -DialogLoadPlugins( ) -{ - // Show dialog and check if it was accepted - QFileDialog dialog( this ); - dialog.setFileMode( QFileDialog::ExistingFile ); - dialog.setDirectory( this->m_LastLoadedPlugin.c_str( ) ); - dialog.setNameFilter( tr( PLUGIN_REGEX ) ); - dialog.setDefaultSuffix( tr( PLUGIN_EXT ) ); - if( !( dialog.exec( ) ) ) - return; - - std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( ); - if( !( this->LoadPlugins( fname ) ) ) - QMessageBox::critical( - this, tr( "Ignoring plugin" ), tr( fname.c_str( ) ) - ); -} - -// ------------------------------------------------------------------------- -void cpPlugins::Interface::BaseMPRWindow:: -AssociatePluginsToMenu( QMenu* menu, QObject* obj, const char* slot ) -{ - std::map< std::string, std::set< std::string > >::const_iterator i; - std::set< std::string >::const_iterator j; - - menu->clear( ); - for( i = this->m_Filters.begin( ); i != this->m_Filters.end( ); i++ ) - { - QMenu* newMenu = menu->addMenu( i->first.c_str( ) ); - for( j = i->second.begin( ); j != i->second.end( ); ++j ) - { - QAction* a = newMenu->addAction( j->c_str( ) ); - QObject::connect( a, SIGNAL( triggered( ) ), obj, slot ); - - } // rof - - } // rof + if( this->m_WVTK != NULL ) delete this->m_WVTK; + if( this->m_ZVTK != NULL ) delete this->m_ZVTK; + if( this->m_YVTK != NULL ) delete this->m_YVTK; + if( this->m_XVTK != NULL ) delete this->m_XVTK; } // ------------------------------------------------------------------------- bool cpPlugins::Interface::BaseMPRWindow:: -LoadPlugins( const std::string& fname ) +ShowImage( vtkImageData* image ) { - this->Block( ); - - // Is it already loaded? - if( this->m_LoadedPlugins.find( fname ) != this->m_LoadedPlugins.end( ) ) - { - this->Unblock( ); - return( true ); - - } // fi - - // Was it succesfully loaded? - if( !( this->m_Interface.Load( fname ) ) ) - { - this->Unblock( ); - return( false ); - - } // fi - - // Update a simple track - this->m_LoadedPlugins.insert( fname ); - this->m_LastLoadedPlugin = fname; - this->_UpdatePlugins( ); - - this->Unblock( ); - return( true ); + bool r = ( image != NULL ); + if( r ) + this->m_MPRObjects->AddImage( image ); + return( r ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::BaseMPRWindow:: -LoadPlugins( ) +bool cpPlugins::Interface::BaseMPRWindow:: +ShowImage( vtkImageData* image, double r, double g, double b ) { - // Load file into a char buffer - std::ifstream in( - "Plugins.cfg", std::ios::in | std::ios::binary | std::ios::ate - ); - if( !in.is_open( ) ) - return; - std::streampos size = in.tellg( ); - char* buffer = new char[ size ]; - in.seekg( 0, std::ios::beg ); - in.read( buffer, size ); - in.close( ); - - // Read stream - std::stringstream in_stream( buffer ); - while( in_stream ) - { - char line[ 2048 ]; - in_stream.getline( line, 2048 ); - this->LoadPlugins( line ); - - } // elihw - - // Finish - delete buffer; + return( false ); } // ------------------------------------------------------------------------- -std::string cpPlugins::Interface::BaseMPRWindow:: -LoadImage( ) +bool cpPlugins::Interface::BaseMPRWindow:: +ShowMesh( vtkPolyData* mesh ) { - std::string msg = ""; - std::string ret = ""; - if( this->m_ImageReader.IsNull( ) ) - msg = "No valid image reader. Please load a valid plugin file."; - - if( this->m_ImageReader->ExecConfigurationDialog( this ) ) - { - this->Block( ); - msg = this->m_ImageReader->Update( ); - if( msg == "" ) - { - TImage::Pointer image = - this->m_ImageReader->GetOutput< TImage >( "Output" ); - if( this->m_Images.size( ) == 0 ) - ret = image->GetName( ); - else - ret = "Segmentation"; - this->m_Images[ ret ] = image; - this->m_ImageReader->DisconnectOutputs( ); - this->m_ImageReader->GetParameters( )->ClearStringList( "FileNames" ); - vtkImageData* vtk_id = image->GetVTK< vtkImageData >( ); - if( vtk_id != NULL ) - { - this->m_MPRObjects->AddImage( vtk_id ); - /* - MementoState(m_state, this->m_Image); - this->m_state++; - */ - } - else - msg = "Read image does not have a valid VTK converter."; - } - else - ret = ""; - - } // fi - - // Show errors and return - this->Unblock( ); - if( msg != "" ) - QMessageBox::critical( - this, tr( "Error reading image." ), tr( msg.c_str( ) ) - ); - return( ret ); + return( false ); } // ------------------------------------------------------------------------- -std::string cpPlugins::Interface::BaseMPRWindow:: -LoadDicomSeries( ) -{ - std::string msg = ""; - std::string ret = ""; - if( this->m_DicomSeriesReader.IsNull( ) ) - msg = "No valid DICOM series reader. Please load a valid plugin file."; - - if( this->m_DicomSeriesReader->ExecConfigurationDialog( this ) ) +/* + void cpPlugins::Interface::BaseMPRWindow:: + AddImage( const std::string& name, TImage* image ) { - this->Block( ); - msg = this->m_DicomSeriesReader->Update( ); - if( msg == "" ) - { - TImage::Pointer image = - this->m_DicomSeriesReader->GetOutput< TImage >( "Output" ); - if( this->m_Images.size( ) == 0 ) - ret = image->GetName( ); - else - ret = "Segmentation"; - this->m_Images[ ret ] = image; - this->m_DicomSeriesReader->DisconnectOutputs( ); - this->m_DicomSeriesReader->GetParameters( )-> - ClearStringList( "FileNames" ); - vtkImageData* vtk_id = image->GetVTK< vtkImageData >( ); - if( vtk_id != NULL ) - { - this->m_MPRObjects->AddImage( vtk_id ); - /* - MementoState(m_state, this->m_Image); - this->m_state++; - */ - } - else - msg = "Read dicom series does not have a valid VTK converter."; - } - else - ret = ""; - - } // fi - - // Show errors and return - this->Unblock( ); - if( msg != "" ) - QMessageBox::critical( - this, tr( "Error reading dicom series." ), tr( msg.c_str( ) ) - ); - return( ret ); -} + this->m_Images[ name ] = image; + vtkImageData* vtk_id = + this->m_Images[ name ]->GetVTK< vtkImageData >( ); + if( vtk_id != NULL ) + this->m_MPRObjects->AddImage( vtk_id ); + } +*/ // ------------------------------------------------------------------------- -std::string cpPlugins::Interface::BaseMPRWindow:: -LoadMesh( ) +double cpPlugins::Interface::BaseMPRWindow:: +GetWindow( ) const { - return( "" ); + return( this->m_MPRObjects->GetWindow( ) ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::BaseMPRWindow:: -ExecuteFilter( - const std::string& name, - const std::string& input_id, - const std::string& output_id - ) +double cpPlugins::Interface::BaseMPRWindow:: +GetLevel( ) const { - TProcessObject::Pointer filter = - this->m_Interface.CreateProcessObject( name ); - std::string category = filter->GetClassCategory( ); - if( category == "ImageToBinaryImageFilter" ) - { - TImages::iterator iIt = this->m_Images.find( input_id ); - if( iIt != this->m_Images.end( ) ) - { - filter->SetInput( "Input", this->m_Images[ input_id ] ); - bool dlg_ok = filter->ExecConfigurationDialog( NULL ); - if( !dlg_ok ) - return; - - std::string err = filter->Update( ); - if( err == "" ) - { - this->m_Images[ "Segmentation" ] = - filter->GetOutput< TImage >( "Output" ); - filter->DisconnectOutputs( ); - - vtkImageData* vtk_id = - this->m_Images[ "Segmentation" ]->GetVTK< vtkImageData >( ); - if( vtk_id != NULL ) - this->m_MPRObjects->AddImage( vtk_id ); - } - else - QMessageBox::critical( - this, tr( "Error with plugin" ), tr( err.c_str( ) ) - ); - - } // fi - - } // fi -} - -// ------------------------------------------------------------------------- -void cpPlugins::Interface::BaseMPRWindow:: -AddImage( const std::string& name, TImage* image ) -{ - this->m_Images[ name ] = image; - vtkImageData* vtk_id = - this->m_Images[ name ]->GetVTK< vtkImageData >( ); - if( vtk_id != NULL ) - this->m_MPRObjects->AddImage( vtk_id ); + return( this->m_MPRObjects->GetLevel( ) ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::BaseMPRWindow:: ClearAll( ) { - this->m_MPRObjects->ClearAll( ); - this->m_Images.clear( ); - this->m_Meshes.clear( ); -} - -// ------------------------------------------------------------------------- -void cpPlugins::Interface::BaseMPRWindow:: -_UpdatePlugins( ) -{ - typedef TInterface::TClasses _C; - - this->m_Filters.clear( ); - _C& classes = this->m_Interface.GetClasses( ); - for( _C::const_iterator i = classes.begin( ); i != classes.end( ); ++i ) - { - TProcessObject::Pointer o = - this->m_Interface.CreateProcessObject( i->first ); - std::string name = o->GetClassName( ); - std::string category = o->GetClassCategory( ); - if( category == "ImageReader" ) - this->m_ImageReader = o; - else if( category == "ImageWriter" ) - this->m_ImageWriter = o; - else if( category == "MeshReader" ) - this->m_MeshReader = o; - else if( category == "MeshWriter" ) - this->m_MeshWriter = o; - else if( category == "DicomSeriesReader" ) - this->m_DicomSeriesReader = o; - else - this->m_Filters[ category ].insert( name ); - - /* - if( category == "ImageReader" ) - this->m_ImageReaderClass = name; - else if( category == "ImageWriter" ) - this->m_ImageWriterClass = name; - else if( category == "MeshReader" ) - this->m_MeshReaderClass = name; - else if( category == "MeshWriter" ) - this->m_MeshWriterClass = name; - else if( category == "MeshToMeshFilter" ) - { - if( name.find_last_of( "Cutter" ) != std::string::npos ) - this->m_MeshCutterClass = name; - } - else if( category == "ImageToImageFilter" ) - { - QAction* action = - this->m_UI->MenuImageToImage->addAction( QString( name.c_str( ) ) ); - QObject::connect( - action, SIGNAL( triggered( ) ), - this, SLOT( _triggered_actionImageToImage( ) ) - ); - } - else if( category == "ImageToMeshFilter" ) - { - QAction* action = - this->m_UI->MenuImageToMesh->addAction( QString( name.c_str( ) ) ); - QObject::connect( - action, SIGNAL( triggered( ) ), - this, SLOT( _triggered_actionImageToMesh( ) ) - ); - - } // fi - */ - - } // rof + /* + this->m_MPRObjects->ClearAll( ); + this->m_Images.clear( ); + this->m_Meshes.clear( ); + */ } #endif // cpPlugins_Interface_QT4 diff --git a/lib/cpPlugins/Interface/BaseMPRWindow.h b/lib/cpPlugins/Interface/BaseMPRWindow.h index 94c5341..877e4c7 100644 --- a/lib/cpPlugins/Interface/BaseMPRWindow.h +++ b/lib/cpPlugins/Interface/BaseMPRWindow.h @@ -4,26 +4,15 @@ #include #include -#error ACA VOY - #ifdef cpPlugins_Interface_QT4 -#include -#include -#include - #include #include #include #include - #include #include -#include -#include -#include -#include namespace cpPlugins { @@ -37,12 +26,6 @@ namespace cpPlugins Q_OBJECT; public: - typedef cpPlugins::Interface::Interface TInterface; - typedef cpPlugins::Interface::ProcessObject TProcessObject; - typedef cpPlugins::Interface::DataObject TDataObject; - typedef cpPlugins::Interface::Image TImage; - typedef cpPlugins::Interface::Mesh TMesh; - typedef cpExtensions::Visualization::MPRObjects TMPRObjects; typedef TMPRObjects::TBaseStyle TBaseStyle; @@ -54,75 +37,17 @@ namespace cpPlugins typedef TMPRObjects::TKeyCommand TKeyCommand; typedef TMPRObjects::TVoidCommand TVoidCommand; - typedef std::set< std::string > TOrderedStringContainer; - typedef std::map< std::string, std::set< std::string > > TFilters; - public: explicit BaseMPRWindow( QWidget* parent = 0 ); virtual ~BaseMPRWindow( ); - void DialogLoadPlugins( ); - void AssociatePluginsToMenu( - QMenu* menu, QObject* obj, const char* slot - ); - - inline void Block( ) - { - QApplication::setOverrideCursor( Qt::WaitCursor ); - this->setEnabled( false ); - } - inline void Unblock( ) - { - QApplication::restoreOverrideCursor( ); - this->setEnabled( true ); - } - - bool LoadPlugins( const std::string& fname ); - void LoadPlugins( ); - - // Data IO - std::string ReadImage( TImage::Pointer& image ); - std::string ReadDicomSeries( TImage::Pointer& image ); - std::string ReadMesh( TMesh::Pointer& mesh ); - - std::string WriteImage( TImage* image ); - std::string WriteMesh( TMesh* mesh ); - - /* TODO - void ExecuteFilter( - const std::string& name, - const std::string& input_id, - const std::string& output_id - ); - */ - - // Filter acces - bool CreateFilter( - TProcessObject::Pointer& filter, const std::string& name - ) - { - return( this->m_Interface.CreateProcessObject( name ) ); - } - - // Somme visualization accessors - bool ShowImage( TImage* image, bool is_primal = true ); - bool ShowMesh( TMesh* mesh ); - double GetWindow( ) const - { - return( this->m_MPRObjects->GetWindow( ) ); - } - double GetLevel( ) const - { - return( this->m_MPRObjects->GetLevel( ) ); - } - - /* TODO - void ClearAll( ); - */ - - protected: - void _UpdatePlugins( ); + bool ShowImage( vtkImageData* image ); + bool ShowImage( vtkImageData* image, double r, double g, double b ); + bool ShowMesh( vtkPolyData* mesh ); + double GetWindow( ) const; + double GetLevel( ) const; + void ClearAll( ); protected: vtkSmartPointer< TMPRObjects > m_MPRObjects; @@ -131,17 +56,6 @@ namespace cpPlugins QVTKWidget* m_YVTK; QVTKWidget* m_ZVTK; QVTKWidget* m_WVTK; - - TInterface m_Interface; - TOrderedStringContainer m_LoadedPlugins; - std::string m_LastLoadedPlugin; - - TProcessObject::Pointer m_ImageReader; - TProcessObject::Pointer m_ImageWriter; - TProcessObject::Pointer m_MeshReader; - TProcessObject::Pointer m_MeshWriter; - TProcessObject::Pointer m_DicomSeriesReader; - TFilters m_Filters; }; } // ecapseman diff --git a/lib/cpPlugins/Interface/ParametersQtDialog.cxx b/lib/cpPlugins/Interface/ParametersQtDialog.cxx index 5a66983..e28a086 100644 --- a/lib/cpPlugins/Interface/ParametersQtDialog.cxx +++ b/lib/cpPlugins/Interface/ParametersQtDialog.cxx @@ -202,7 +202,9 @@ exec( ) QObject::connect( bb, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) ); this->m_ToolsLayout->addWidget( bb ); - return( this->QDialog::exec( ) ); + int ret = this->QDialog::exec( ); + this->syncParameters( ); + return( ret ); } // ------------------------------------------------------------------------- diff --git a/lib/cpPlugins/Interface/Plugins.cxx b/lib/cpPlugins/Interface/Plugins.cxx new file mode 100644 index 0000000..30378c2 --- /dev/null +++ b/lib/cpPlugins/Interface/Plugins.cxx @@ -0,0 +1,525 @@ +#include +#include + +#include +#include + +#ifdef cpPlugins_Interface_QT4 + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +# define PLUGIN_PREFIX "" +# define PLUGIN_EXT "dll" +# define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)" +#else // Linux +# define PLUGIN_PREFIX "lib" +# define PLUGIN_EXT "so" +# define PLUGIN_REGEX "Plugins file (*.so);;All files (*)" +#endif // _WIN32 + +#endif // cpPlugins_Interface_QT4 + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Plugins:: +Plugins( QWidget* widget ) + : m_Widget( widget ), + m_LastLoadedPlugin( "." ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Plugins:: +~Plugins( ) +{ + this->m_Interface.UnloadAll( ); +} + +// ------------------------------------------------------------------------- +QWidget* cpPlugins::Interface::Plugins:: +GetWidget( ) +{ + return( this->m_Widget ); +} + +// ------------------------------------------------------------------------- +const QWidget* cpPlugins::Interface::Plugins:: +GetWidget( ) const +{ + return( this->m_Widget ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Plugins:: +SetWidget( QWidget* widget ) +{ + this->m_Widget = widget; +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Plugins:: +BlockWidget( ) +{ +#ifdef cpPlugins_Interface_QT4 + if( this->m_Widget != NULL ) + { + QApplication::setOverrideCursor( Qt::WaitCursor ); + this->m_Widget->setEnabled( false ); + + } // fi +#endif // cpPlugins_Interface_QT4 +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Plugins:: +UnblockWidget( ) +{ +#ifdef cpPlugins_Interface_QT4 + if( this->m_Widget != NULL ) + { + QApplication::restoreOverrideCursor( ); + this->m_Widget->setEnabled( true ); + + } // fi +#endif // cpPlugins_Interface_QT4 +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Plugins:: +DialogLoadPlugins( ) +{ +#ifdef cpPlugins_Interface_QT4 + if( this->m_Widget != NULL ) + { + QFileDialog dialog( this->m_Widget ); + dialog.setFileMode( QFileDialog::ExistingFile ); + dialog.setDirectory( this->m_LastLoadedPlugin.c_str( ) ); + dialog.setNameFilter( QFileDialog::tr( PLUGIN_REGEX ) ); + dialog.setDefaultSuffix( QFileDialog::tr( PLUGIN_EXT ) ); + if( !( dialog.exec( ) ) ) + return; + + std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( ); + if( !( this->LoadPlugins( fname ) ) ) + QMessageBox::critical( + this->m_Widget, + QMessageBox::tr( "Ignoring plugin" ), + QMessageBox::tr( fname.c_str( ) ) + ); + + } // fi +#endif // cpPlugins_Interface_QT4 +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Plugins:: +AssociatePluginsToMenu( QMenu* menu, QObject* obj, const char* slot ) +{ +#ifdef cpPlugins_Interface_QT4 + std::map< std::string, std::set< std::string > >::const_iterator i; + std::set< std::string >::const_iterator j; + + menu->clear( ); + for( i = this->m_Filters.begin( ); i != this->m_Filters.end( ); i++ ) + { + QMenu* newMenu = menu->addMenu( i->first.c_str( ) ); + for( j = i->second.begin( ); j != i->second.end( ); ++j ) + { + QAction* a = newMenu->addAction( j->c_str( ) ); + QObject::connect( a, SIGNAL( triggered( ) ), obj, slot ); + + } // rof + + } // rof +#endif // cpPlugins_Interface_QT4 +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Plugins:: +LoadPlugins( const std::string& fname ) +{ + this->BlockWidget( ); + + // Is it already loaded? + bool ret = true; + if( this->m_LoadedPlugins.find( fname ) == this->m_LoadedPlugins.end( ) ) + { + // Was it succesfully loaded? + ret = this->m_Interface.Load( fname ); + + // Update a simple track + if( ret ) + { + this->m_LoadedPlugins.insert( fname ); + this->m_LastLoadedPlugin = fname; + this->_Update( ); + + } // fi + + } // fi + + this->UnblockWidget( ); + return( ret ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Plugins:: +LoadPluginsConfigurationFile( const std::string& fname ) +{ + // Load file into a char buffer + std::ifstream in( + fname.c_str( ), std::ios::in | std::ios::binary | std::ios::ate + ); + if( !in.is_open( ) ) + return( false ); + + std::streampos size = in.tellg( ); + char* buffer = new char[ size ]; + in.seekg( 0, std::ios::beg ); + in.read( buffer, size ); + in.close( ); + + // Read stream + std::stringstream in_stream( buffer ); + char line[ 4096 ]; + while( in_stream ) + { + in_stream.getline( line, 4096 ); + this->LoadPlugins( line ); + + } // elihw + delete buffer; + + return( true ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Plugins:: +TParameters* cpPlugins::Interface::Plugins:: +GetImageReaderParameters( ) +{ + return( this->m_ImageReader->GetParameters( ) ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Plugins:: +TParameters* cpPlugins::Interface::Plugins:: +GetMeshReaderParameters( ) +{ + return( this->m_MeshReader->GetParameters( ) ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Plugins:: +TParameters* cpPlugins::Interface::Plugins:: +GetImageWriterParameters( ) +{ + return( this->m_ImageWriter->GetParameters( ) ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Plugins:: +TParameters* cpPlugins::Interface::Plugins:: +GetMeshWriterParameters( ) +{ + return( this->m_MeshWriter->GetParameters( ) ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface::Plugins:: +TParameters* cpPlugins::Interface::Plugins:: +GetImageReaderParameters( ) const +{ + return( this->m_ImageReader->GetParameters( ) ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface::Plugins:: +TParameters* cpPlugins::Interface::Plugins:: +GetMeshReaderParameters( ) const +{ + return( this->m_MeshReader->GetParameters( ) ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface::Plugins:: +TParameters* cpPlugins::Interface::Plugins:: +GetImageWriterParameters( ) const +{ + return( this->m_ImageWriter->GetParameters( ) ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface::Plugins:: +TParameters* cpPlugins::Interface::Plugins:: +GetMeshWriterParameters( ) const +{ + return( this->m_MeshWriter->GetParameters( ) ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Plugins:: +ReadImage( TImage::Pointer& image, bool exec_qt ) +{ + std::string ret = ""; + if( this->m_ImageReader.IsNull( ) ) + ret = "Plugins: No valid image reader. Please load a valid plugin."; + + if( ret == "" ) + { + bool execute = true; + if( exec_qt ) + execute = this->m_ImageReader->ExecConfigurationDialog( this->m_Widget ); + if( execute ) + { + this->BlockWidget( ); + ret = this->m_ImageReader->Update( ); + this->UnblockWidget( ); + if( ret == "" ) + { + image = this->m_ImageReader->GetOutput< TImage >( "Output" ); + this->m_ImageReader->DisconnectOutputs( ); + this->m_ImageReader->GetParameters( )->ClearStringList( "FileNames" ); + } + else + image = NULL; + + } // fi + + } // fi + + // Show an error message and return + if( ret != "" ) + { +#ifdef cpPlugins_Interface_QT4 + if( this->m_Widget != NULL ) + QMessageBox::critical( + this->m_Widget, + QMessageBox::tr( "Error reading image." ), + QMessageBox::tr( ret.c_str( ) ) + ); +#endif // cpPlugins_Interface_QT4 + return( false ); + } + else + return( true ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Plugins:: +ReadDicomSeries( TImage::Pointer& image ) +{ + std::string ret = ""; + if( this->m_DicomSeriesReader.IsNull( ) ) + ret = "Plugins: No valid dicom series reader. Please load a valid plugin."; + + if( ret == "" ) + { + if( this->m_DicomSeriesReader->ExecConfigurationDialog( this->m_Widget ) ) + { + this->BlockWidget( ); + ret = this->m_DicomSeriesReader->Update( ); + this->UnblockWidget( ); + if( ret == "" ) + { + image = this->m_DicomSeriesReader->GetOutput< TImage >( "Output" ); + this->m_DicomSeriesReader->DisconnectOutputs( ); + this->m_DicomSeriesReader->GetParameters( )-> + ClearStringList( "FileNames" ); + } + else + image = NULL; + + } // fi + + } // fi + + // Show an error message and return + if( ret != "" ) + { +#ifdef cpPlugins_Interface_QT4 + if( this->m_Widget != NULL ) + QMessageBox::critical( + this->m_Widget, + QMessageBox::tr( "Error reading dicom series." ), + QMessageBox::tr( ret.c_str( ) ) + ); +#endif // cpPlugins_Interface_QT4 + return( false ); + } + else + return( true ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Plugins:: +ReadMesh( TMesh::Pointer& mesh, bool exec_qt ) +{ + std::string ret = ""; + if( this->m_MeshReader.IsNull( ) ) + ret = "Plugins: No valid mesh reader. Please load a valid plugin."; + + if( ret == "" ) + { + bool execute = true; + if( exec_qt ) + execute = this->m_MeshReader->ExecConfigurationDialog( this->m_Widget ); + if( execute ) + { + this->BlockWidget( ); + ret = this->m_MeshReader->Update( ); + this->UnblockWidget( ); + if( ret == "" ) + { + mesh = this->m_MeshReader->GetOutput< TMesh >( "Output" ); + this->m_MeshReader->DisconnectOutputs( ); + } + else + mesh = NULL; + + } // fi + + } // fi + + // Show an error message and return + if( ret != "" ) + { +#ifdef cpPlugins_Interface_QT4 + if( this->m_Widget != NULL ) + QMessageBox::critical( + this->m_Widget, + QMessageBox::tr( "Error reading image." ), + QMessageBox::tr( ret.c_str( ) ) + ); +#endif // cpPlugins_Interface_QT4 + return( false ); + } + else + return( true ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Plugins:: +WriteImage( TImage* image, bool exec_qt ) +{ + std::string ret = ""; + if( this->m_ImageWriter.IsNull( ) ) + ret = "Plugins: No valid image writer. Please load a valid plugin."; + + if( ret == "" ) + { + bool execute = true; + if( exec_qt ) + execute = this->m_ImageWriter->ExecConfigurationDialog( this->m_Widget ); + if( execute ) + { + this->m_ImageWriter->SetInput( "Input", image ); + this->BlockWidget( ); + ret = this->m_ImageWriter->Update( ); + this->UnblockWidget( ); + + } // fi + + } // fi + + // Show an error message and return + if( ret != "" ) + { +#ifdef cpPlugins_Interface_QT4 + if( this->m_Widget != NULL ) + QMessageBox::critical( + this->m_Widget, + QMessageBox::tr( "Error reading image." ), + QMessageBox::tr( ret.c_str( ) ) + ); +#endif // cpPlugins_Interface_QT4 + return( false ); + } + else + return( true ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Plugins:: +WriteMesh( TMesh* mesh, bool exec_qt ) +{ + std::string ret = ""; + if( this->m_MeshWriter.IsNull( ) ) + ret = "Plugins: No valid mesh writer. Please load a valid plugin."; + + if( ret == "" ) + { + bool execute = true; + if( exec_qt ) + execute = this->m_MeshReader->ExecConfigurationDialog( this->m_Widget ); + if( execute ) + { + this->m_MeshWriter->SetInput( 0, mesh ); + this->BlockWidget( ); + ret = this->m_MeshWriter->Update( ); + this->UnblockWidget( ); + + } // fi + + } // fi + + // Show an error message and return + if( ret != "" ) + { +#ifdef cpPlugins_Interface_QT4 + if( this->m_Widget != NULL ) + QMessageBox::critical( + this->m_Widget, + QMessageBox::tr( "Error reading image." ), + QMessageBox::tr( ret.c_str( ) ) + ); +#endif // cpPlugins_Interface_QT4 + return( false ); + } + else + return( true ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Plugins:: +CreateFilter( TProcessObject::Pointer& filter, const std::string& name ) +{ + filter = this->m_Interface.CreateProcessObject( name ); + return( filter.IsNotNull( ) ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Plugins:: +_Update( ) +{ + typedef TInterface::TClasses _C; + + this->m_Filters.clear( ); + _C& classes = this->m_Interface.GetClasses( ); + for( _C::const_iterator i = classes.begin( ); i != classes.end( ); ++i ) + { + TProcessObject::Pointer o = + this->m_Interface.CreateProcessObject( i->first ); + std::string name = o->GetClassName( ); + std::string category = o->GetClassCategory( ); + if( category == "ImageReader" ) + this->m_ImageReader = o; + else if( category == "ImageWriter" ) + this->m_ImageWriter = o; + else if( category == "MeshReader" ) + this->m_MeshReader = o; + else if( category == "MeshWriter" ) + this->m_MeshWriter = o; + else if( category == "DicomSeriesReader" ) + this->m_DicomSeriesReader = o; + else + this->m_Filters[ category ].insert( name ); + + } // rof +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/Plugins.h b/lib/cpPlugins/Interface/Plugins.h new file mode 100644 index 0000000..847b7e8 --- /dev/null +++ b/lib/cpPlugins/Interface/Plugins.h @@ -0,0 +1,102 @@ +#ifndef __CPPLUGINS__INTERFACE__PLUGINS__H__ +#define __CPPLUGINS__INTERFACE__PLUGINS__H__ + +#include + +#include +#include +#include + +#include +#include +#include +#include + +class QObject; +class QMenu; +class QWidget; + +namespace cpPlugins +{ + namespace Interface + { + /** + */ + class cpPlugins_Interface_EXPORT Plugins + { + public: + typedef cpPlugins::Interface::Interface TInterface; + typedef cpPlugins::Interface::ProcessObject TProcessObject; + typedef cpPlugins::Interface::DataObject TDataObject; + typedef cpPlugins::Interface::Image TImage; + typedef cpPlugins::Interface::Mesh TMesh; + typedef TProcessObject::TParameters TParameters; + + typedef std::set< std::string > TOrderedStringContainer; + typedef std::map< std::string, std::set< std::string > > TFilters; + + public: + Plugins( QWidget* widget = NULL ); + virtual ~Plugins( ); + + QWidget* GetWidget( ); + const QWidget* GetWidget( ) const; + void SetWidget( QWidget* widget ); + void BlockWidget( ); + void UnblockWidget( ); + void DialogLoadPlugins( ); + void AssociatePluginsToMenu( + QMenu* menu, QObject* obj, const char* slot + ); + + bool LoadPlugins( const std::string& fname ); + bool LoadPluginsConfigurationFile( const std::string& fname ); + + TParameters* GetImageReaderParameters( ); + TParameters* GetMeshReaderParameters( ); + TParameters* GetImageWriterParameters( ); + TParameters* GetMeshWriterParameters( ); + + const TParameters* GetImageReaderParameters( ) const; + const TParameters* GetMeshReaderParameters( ) const; + const TParameters* GetImageWriterParameters( ) const; + const TParameters* GetMeshWriterParameters( ) const; + + // Data IO + bool ReadImage( TImage::Pointer& image, bool exec_qt = false ); + bool ReadDicomSeries( TImage::Pointer& image ); + bool ReadMesh( TMesh::Pointer& mesh, bool exec_qt = false ); + + bool WriteImage( TImage* image, bool exec_qt = false ); + bool WriteMesh( TMesh* mesh, bool exec_qt = false ); + + // Filter acces + bool CreateFilter( + TProcessObject::Pointer& filter, const std::string& name + ); + + protected: + void _Update( ); + + protected: + QWidget* m_Widget; + + TInterface m_Interface; + TOrderedStringContainer m_LoadedPlugins; + std::string m_LastLoadedPlugin; + + TProcessObject::Pointer m_ImageReader; + TProcessObject::Pointer m_ImageWriter; + TProcessObject::Pointer m_MeshReader; + TProcessObject::Pointer m_MeshWriter; + TProcessObject::Pointer m_DicomSeriesReader; + TFilters m_Filters; + }; + + } // ecapseman + +} // ecapseman + +#endif // __CPPLUGINS__INTERFACE__PLUGINS__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index a4a1237..9fb4ea7 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -110,7 +110,6 @@ ExecConfigurationDialog( QWidget* parent ) } // fi - std::cout << "ok" << std::endl; if( !( this->m_ParametersDialog->IsModal( ) ) ) { this->m_ParametersDialog->show( ); @@ -118,6 +117,7 @@ ExecConfigurationDialog( QWidget* parent ) } else r = ( this->m_ParametersDialog->exec( ) == 1 ); + /* r = cpPlugins::Interface::ParametersQtDialog( this->m_Parameters, diff --git a/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx b/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx index 625838c..22ed81e 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx @@ -54,7 +54,10 @@ _GenerateData( ) mc->ComputeNormalsOff( ); mc->SetInputData( vtk_image ); for( unsigned int i = 0; i < values.size( ); ++i ) + { + std::cout << i << " " << values[ i ] << std::endl; mc->SetValue( i, values[ i ] ); + } mc->Update( ); pd = mc->GetOutput( ); } diff --git a/lib/cpPlugins/Plugins/IO/DicomSeriesReader.cxx b/lib/cpPlugins/Plugins/IO/DicomSeriesReader.cxx index 913190f..e915fcf 100644 --- a/lib/cpPlugins/Plugins/IO/DicomSeriesReader.cxx +++ b/lib/cpPlugins/Plugins/IO/DicomSeriesReader.cxx @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -39,6 +40,10 @@ ExecConfigurationDialog( QWidget* parent ) return( false ); // Prepare dialog + QApplication::setOverrideCursor( Qt::WaitCursor ); + if( parent != NULL ) + parent->setEnabled( false ); + QDialog* tree_dialog = new QDialog( parent ); QTreeWidget* tree_widget = new QTreeWidget( tree_dialog ); QList< QTreeWidgetItem* > tree_items; @@ -139,6 +144,10 @@ ExecConfigurationDialog( QWidget* parent ) ); toolsLayout->addWidget( bb ); + QApplication::restoreOverrideCursor( ); + if( parent != NULL ) + parent->setEnabled( true ); + if( tree_dialog->exec( ) == 0 ) return( false ); @@ -148,6 +157,10 @@ ExecConfigurationDialog( QWidget* parent ) QTreeWidgetItem* item_parent = item->parent( ); if( item_parent != NULL ) { + QApplication::setOverrideCursor( Qt::WaitCursor ); + if( parent != NULL ) + parent->setEnabled( false ); + std::string serie_dir = item_parent->text( 0 ).toStdString( ); std::string serie_id = item->text( 0 ).toStdString( ); serie_id = serie_id.substr( serie_id.find_first_of( " " ) + 1 ); @@ -158,6 +171,10 @@ ExecConfigurationDialog( QWidget* parent ) r = true; + QApplication::restoreOverrideCursor( ); + if( parent != NULL ) + parent->setEnabled( true ); + } // fi } // fi diff --git a/lib/cpPlugins/Plugins/IO/ImageReader.cxx b/lib/cpPlugins/Plugins/IO/ImageReader.cxx index d28b129..fc747eb 100644 --- a/lib/cpPlugins/Plugins/IO/ImageReader.cxx +++ b/lib/cpPlugins/Plugins/IO/ImageReader.cxx @@ -30,6 +30,7 @@ ExecConfigurationDialog( QWidget* parent ) dialog.setFileMode( QFileDialog::ExistingFiles ); dialog.setDirectory( QFileDialog::tr( name.c_str( ) ) ); dialog.setNameFilters( filters ); + dialog.setAcceptMode( QFileDialog::AcceptOpen ); if( dialog.exec( ) ) { QStringList names = dialog.selectedFiles( ); diff --git a/lib/cpPlugins/Plugins/IO/ImageWriter.cxx b/lib/cpPlugins/Plugins/IO/ImageWriter.cxx index a654979..63080e2 100644 --- a/lib/cpPlugins/Plugins/IO/ImageWriter.cxx +++ b/lib/cpPlugins/Plugins/IO/ImageWriter.cxx @@ -3,6 +3,43 @@ #include +#ifdef cpPlugins_Interface_QT4 +#include +#endif // cpPlugins_Interface_QT4 + +// ------------------------------------------------------------------------- +bool cpPlugins::IO::ImageWriter:: +ExecConfigurationDialog( QWidget* parent ) +{ + bool r = false; + +#ifdef cpPlugins_Interface_QT4 + + std::string name = this->m_Parameters->GetString( "FileName" ); + if( name == "" ) + name = "save.mhd"; + + // Show dialog and check if it was accepted + QString qname = + QFileDialog::getSaveFileName( + parent, + QFileDialog::tr( "Save File" ), + QFileDialog::tr( name.c_str( ) ), + QFileDialog::tr( "Image files (*.bmp *.png *.jpg *.jpeg *.dcm *.mhd *.nhdr *.nrrd *.tiff);;Any file (*)") + ); + name = qname.toStdString( ); + if( name != "" ) + { + this->m_Parameters->SetString( "FileName", name ); + r = true; + + } // fi + +#endif // cpPlugins_Interface_QT4 + + return( r ); +} + // ------------------------------------------------------------------------- cpPlugins::IO::ImageWriter:: ImageWriter( ) diff --git a/lib/cpPlugins/Plugins/IO/ImageWriter.h b/lib/cpPlugins/Plugins/IO/ImageWriter.h index 2c97de9..849fc47 100644 --- a/lib/cpPlugins/Plugins/IO/ImageWriter.h +++ b/lib/cpPlugins/Plugins/IO/ImageWriter.h @@ -26,6 +26,9 @@ namespace cpPlugins cpPlugins::IO::ImageWriter, "ImageWriter" ); + public: + virtual bool ExecConfigurationDialog( QWidget* parent ); + protected: ImageWriter( ); virtual ~ImageWriter( ); diff --git a/lib/cpPlugins/Plugins/IO/MeshWriter.cxx b/lib/cpPlugins/Plugins/IO/MeshWriter.cxx index 94af3cc..4aae3a3 100644 --- a/lib/cpPlugins/Plugins/IO/MeshWriter.cxx +++ b/lib/cpPlugins/Plugins/IO/MeshWriter.cxx @@ -5,6 +5,43 @@ #include #include +#ifdef cpPlugins_Interface_QT4 +#include +#endif // cpPlugins_Interface_QT4 + +// ------------------------------------------------------------------------- +bool cpPlugins::IO::MeshWriter:: +ExecConfigurationDialog( QWidget* parent ) +{ + bool r = false; + +#ifdef cpPlugins_Interface_QT4 + + std::string name = this->m_Parameters->GetString( "FileName" ); + if( name == "" ) + name = "save.vtk"; + + // Show dialog and check if it was accepted + QString qname = + QFileDialog::getSaveFileName( + parent, + QFileDialog::tr( "Save File" ), + QFileDialog::tr( name.c_str( ) ), + QFileDialog::tr( "Mesh files (*.vtk *.stl *.obj);;Any file (*)") + ); + name = qname.toStdString( ); + if( name != "" ) + { + this->m_Parameters->SetString( "FileName", name ); + r = true; + + } // fi + +#endif // cpPlugins_Interface_QT4 + + return( r ); +} + // ------------------------------------------------------------------------- cpPlugins::IO::MeshWriter:: MeshWriter( ) diff --git a/lib/cpPlugins/Plugins/IO/MeshWriter.h b/lib/cpPlugins/Plugins/IO/MeshWriter.h index 9def135..c97509d 100644 --- a/lib/cpPlugins/Plugins/IO/MeshWriter.h +++ b/lib/cpPlugins/Plugins/IO/MeshWriter.h @@ -28,6 +28,9 @@ namespace cpPlugins cpPlugins::IO::MeshWriter, "MeshWriter" ); + public: + virtual bool ExecConfigurationDialog( QWidget* parent ); + protected: MeshWriter( ); virtual ~MeshWriter( );