From: Leonardo Florez-Valencia Date: Fri, 2 Oct 2015 15:59:23 +0000 (-0500) Subject: Widget integration (step 1/6) X-Git-Tag: v0.1~353 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=b4cc15873d07ef87910a4aa6492e74022cda1a25;p=cpPlugins.git Widget integration (step 1/6) --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 83c4b84..797b910 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,22 @@ IF(WIN32 OR APPLE) ) ENDIF(WIN32 OR APPLE) +## ======================= +## = Local bash commands = +## ======================= +SET( + bash_PROGRAMS + cpPlugins_createHost + ) + +FOREACH(prog ${bash_PROGRAMS}) + IF(MSVC) + SET(${prog}_APP ${PROJECT_BINARY_DIR}/$(ConfigurationName)/${prog}) + ELSE(MSVC) + SET(${prog}_APP ${PROJECT_BINARY_DIR}/${prog}) + ENDIF(MSVC) +ENDFOREACH(prog) + ## =========================== ## = Subdirs containing code = ## =========================== diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index 5951d1f..6cc4ed1 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -135,12 +135,8 @@ _LoadPlugins( const std::string& filename ) // ------------------------------------------------------------------------- std::string ImageMPR:: -_LoadImage( TPluginImage::Pointer& image, const QStringList& names ) +_LoadImage( TPluginImage::Pointer& image ) { - // Block application - QApplication::setOverrideCursor( Qt::WaitCursor ); - this->setEnabled( false ); - std::string ret = ""; image = NULL; @@ -149,31 +145,32 @@ _LoadImage( TPluginImage::Pointer& image, const QStringList& names ) this->m_Plugins.CreateProcessObject( this->m_ImageReaderClass ); if( reader.IsNotNull( ) ) { - // Configure reader - TParameters params = reader->GetDefaultParameters( ); - QStringList::const_iterator qIt = names.begin( ); - for( ; qIt != names.end( ); ++qIt ) - params.AddValueToStringList( "FileNames", qIt->toStdString( ) ); - params.SetValueAsBool( "VectorType", false ); - reader->SetParameters( params ); - - // Execute and get error message, if any - ret = reader->Update( ); - - // Assign fresh image, if any - if( ret == "" ) + if( reader->ExecConfigurationDialog( this ) ) { - image = reader->GetOutput< TPluginImage >( 0 ); - reader->DisconnectOutputs( ); + // Block application + QApplication::setOverrideCursor( Qt::WaitCursor ); + this->setEnabled( false ); + + // Execute and get error message, if any + ret = reader->Update( ); + + // Assign fresh image, if any + if( ret == "" ) + { + image = reader->GetOutput< TPluginImage >( 0 ); + reader->DisconnectOutputs( ); + + } // fi + + // Unblock application + QApplication::restoreOverrideCursor( ); + this->setEnabled( true ); } // fi } else ret = "No suitable reader object found in loaded plugins."; - // Finish reading - QApplication::restoreOverrideCursor( ); - this->setEnabled( true ); return( ret ); } @@ -203,20 +200,8 @@ _triggered_actionOpenPlugins( ) void ImageMPR:: _triggered_actionOpenInputImage( ) { - // Show dialog and check if it was accepted - QFileDialog dialog( this ); - dialog.setFileMode( QFileDialog::ExistingFiles ); - dialog.setDirectory( tr( "." ) ); - dialog.setNameFilter( - tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" ) - ); - dialog.setDefaultSuffix( tr( "mhd" ) ); - if( !( dialog.exec( ) ) ) - return; - // Read image - std::string err = - this->_LoadImage( this->m_InputImage, dialog.selectedFiles( ) ); + std::string err = this->_LoadImage( this->m_InputImage ); if( err == "" ) { vtkImageData* vtk_id = this->m_InputImage->GetVTKImageData( ); @@ -257,20 +242,8 @@ _triggered_actionOpenSegmentation( ) } // fi - // Show dialog and check if it was accepted - QFileDialog dialog( this ); - dialog.setFileMode( QFileDialog::ExistingFiles ); - dialog.setDirectory( tr( "." ) ); - dialog.setNameFilter( - tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" ) - ); - dialog.setDefaultSuffix( tr( "mhd" ) ); - if( !( dialog.exec( ) ) ) - return; - // Read image - std::string err = - this->_LoadImage( this->m_InputSegmentation, dialog.selectedFiles( ) ); + std::string err = this->_LoadImage( this->m_InputSegmentation ); if( err == "" ) { vtkImageData* vtk_id = this->m_InputSegmentation->GetVTKImageData( ); @@ -298,57 +271,51 @@ _triggered_actionOpenSegmentation( ) void ImageMPR:: _triggered_actionOpenInputPolyData( ) { - // Show dialog and check if it was accepted - QFileDialog dialog( this ); - dialog.setFileMode( QFileDialog::ExistingFile ); - dialog.setDirectory( tr( "." ) ); - dialog.setNameFilter( - tr( "Mesh files (*.vtk *.obj);;All files (*)" ) - ); - dialog.setDefaultSuffix( tr( "vtk" ) ); - if( !( dialog.exec( ) ) ) - return; - this->m_InputMesh = NULL; // Get a reader from plugins TPluginFilter::Pointer reader = this->m_Plugins.CreateProcessObject( this->m_MeshReaderClass ); - // Configure reader - TParameters reader_params = reader->GetDefaultParameters( ); - QStringList q_fnames = dialog.selectedFiles( ); - QStringList::const_iterator qIt = q_fnames.begin( ); - for( ; qIt != q_fnames.end( ); ++qIt ) - reader_params.SetValueAsString( "FileName", qIt->toStdString( ) ); - reader->SetParameters( reader_params ); - - // Execute and get error message, if any - QApplication::setOverrideCursor( Qt::WaitCursor ); - this->setEnabled( false ); - std::string err = reader->Update( ); - QApplication::restoreOverrideCursor( ); - this->setEnabled( true ); - - - // Assign fresh image, if any - if( err == "" ) + if( reader.IsNotNull( ) ) { - this->m_InputMesh = reader->GetOutput< TPluginMesh >( 0 ); - reader->DisconnectOutputs( ); - if( this->m_InputMesh.IsNotNull( ) ) + // Configure reader + if( reader->ExecConfigurationDialog( this ) ) { - vtkActor* vtk_actor = this->m_InputMesh->GetVTKActor( ); - if( vtk_actor != NULL ) + // Execute and get error message, if any + QApplication::setOverrideCursor( Qt::WaitCursor ); + this->setEnabled( false ); + std::string err = reader->Update( ); + QApplication::restoreOverrideCursor( ); + this->setEnabled( true ); + + // Assign fresh mesh, if any + if( err == "" ) { - this->m_MPRObjects->Get3DRenderer( )->AddActor( vtk_actor ); - this->m_MPRObjects->Render( 4 ); + this->m_InputMesh = reader->GetOutput< TPluginMesh >( 0 ); + reader->DisconnectOutputs( ); + if( this->m_InputMesh.IsNotNull( ) ) + { + vtkActor* vtk_actor = this->m_InputMesh->GetVTKActor( ); + if( vtk_actor != NULL ) + { + this->m_MPRObjects->Get3DRenderer( )->AddActor( vtk_actor ); + this->m_MPRObjects->Render( 4 ); + } + else + QMessageBox::critical( + this, + tr( "Error message" ), + tr( "Read mesh does not have a valid vtkActor." ) + ); + + } // fi } else QMessageBox::critical( this, - tr( "Error message" ), - tr( "Read mesh does not have a valid vtkActor." ) + tr( "Error reading mesh" ), + tr( err.c_str( ) ) ); } // fi @@ -356,8 +323,8 @@ _triggered_actionOpenInputPolyData( ) else QMessageBox::critical( this, - tr( "Error reading mesh" ), - tr( err.c_str( ) ) + tr( "Error reading single mesh" ), + tr( "No suitable mesh reader found in loaded plugins." ) ); } diff --git a/appli/ImageMPR/ImageMPR.h b/appli/ImageMPR/ImageMPR.h index cf3e5c1..d82f026 100644 --- a/appli/ImageMPR/ImageMPR.h +++ b/appli/ImageMPR/ImageMPR.h @@ -48,9 +48,7 @@ public: protected: bool _LoadPlugins( const std::string& filename ); - std::string _LoadImage( - TPluginImage::Pointer& image, const QStringList& names - ); + std::string _LoadImage( TPluginImage::Pointer& image ); private slots: void _triggered_actionOpenPlugins( ); diff --git a/cmake/cpPluginsConfig.cmake.in b/cmake/cpPluginsConfig.cmake.in index 6cd7904..d5e0f39 100644 --- a/cmake/cpPluginsConfig.cmake.in +++ b/cmake/cpPluginsConfig.cmake.in @@ -90,13 +90,24 @@ SET(cpPlugins_LIBRARY cpPlugins) # -- Executable names -- # ====================== -FIND_PROGRAM( - cpPlugins_createHost_APP - NAMES cpPlugins_createHost - HINTS /usr /usr/local - PATHS @CMAKE_INSTALL_PREFIX@/bin @PROJECT_BINARY_DIR@ - PATH_SUFFIXES bin sbin - DOC "Where is cpPlugins_createHost?" - ) +IF(MSVC) + FIND_PROGRAM( + cpPlugins_createHost_APP + NAMES cpPlugins_createHost + HINTS /usr /usr/local + PATHS @CMAKE_INSTALL_PREFIX@/bin @PROJECT_BINARY_DIR@/Debug @PROJECT_BINARY_DIR@/Release @PROJECT_BINARY_DIR@/MinSizeRel @PROJECT_BINARY_DIR@/RelWithDebInfo + PATH_SUFFIXES bin sbin + DOC "Where is cpPlugins_createHost?" + ) +ELSE(MSVC) + FIND_PROGRAM( + cpPlugins_createHost_APP + NAMES cpPlugins_createHost + HINTS /usr /usr/local + PATHS @CMAKE_INSTALL_PREFIX@/bin @PROJECT_BINARY_DIR@ + PATH_SUFFIXES bin sbin + DOC "Where is cpPlugins_createHost?" + ) +ENDIF(MSVC) ## eof - $RCSfile$ diff --git a/lib/cpPlugins/Plugins/BasicFilters/CMakeLists.txt b/lib/cpPlugins/Plugins/BasicFilters/CMakeLists.txt index ebc0779..361ba10 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/CMakeLists.txt +++ b/lib/cpPlugins/Plugins/BasicFilters/CMakeLists.txt @@ -17,8 +17,8 @@ FILE(GLOB LIB_SOURCES_CXX "*.cxx") ADD_CUSTOM_COMMAND( OUTPUT ${LIBRARY_NAME}_Host.cxx - DEPENDS ${PROJECT_BINARY_DIR}/$(ConfigurationName)/cpPlugins_createHost ${LIB_HEADERS_H} ${LIB_HEADERS_HPP} ${LIB_HEADERS_HXX} - COMMAND ${PROJECT_BINARY_DIR}/$(ConfigurationName)/cpPlugins_createHost ${LIBRARY_NAME}_Host.cxx cpPlugins::BasicFilters ${LIB_HEADERS_H} + DEPENDS ${cpPlugins_createHost_APP} ${LIB_HEADERS_H} + COMMAND ${cpPlugins_createHost_APP} ${LIBRARY_NAME}_Host.cxx cpPlugins::BasicFilters ${LIB_HEADERS_H} ) ADD_LIBRARY( diff --git a/lib/cpPlugins/Plugins/IO/CMakeLists.txt b/lib/cpPlugins/Plugins/IO/CMakeLists.txt index 243e4c0..98dca49 100644 --- a/lib/cpPlugins/Plugins/IO/CMakeLists.txt +++ b/lib/cpPlugins/Plugins/IO/CMakeLists.txt @@ -17,8 +17,8 @@ FILE(GLOB LIB_SOURCES_CXX "*.cxx") ADD_CUSTOM_COMMAND( OUTPUT ${LIBRARY_NAME}_Host.cxx - DEPENDS ${PROJECT_BINARY_DIR}/$(ConfigurationName)/cpPlugins_createHost ${LIB_HEADERS_H} ${LIB_HEADERS_HPP} ${LIB_HEADERS_HXX} - COMMAND ${PROJECT_BINARY_DIR}/$(ConfigurationName)/cpPlugins_createHost ${LIBRARY_NAME}_Host.cxx cpPlugins::IO ${LIB_HEADERS_H} + DEPENDS ${cpPlugins_createHost_APP} ${LIB_HEADERS_H} + COMMAND ${cpPlugins_createHost_APP} ${LIBRARY_NAME}_Host.cxx cpPlugins::IO ${LIB_HEADERS_H} ) ADD_LIBRARY( diff --git a/lib/cpPlugins/Plugins/IO/ImageReader.cxx b/lib/cpPlugins/Plugins/IO/ImageReader.cxx index 38739df..4b1d365 100644 --- a/lib/cpPlugins/Plugins/IO/ImageReader.cxx +++ b/lib/cpPlugins/Plugins/IO/ImageReader.cxx @@ -6,6 +6,42 @@ #include #include +#ifdef cpPlugins_Interface_QT4 +#include +#endif // cpPlugins_Interface_QT4 + +// ------------------------------------------------------------------------- +bool cpPlugins::IO::ImageReader:: +ExecConfigurationDialog( QWidget* parent ) +{ + bool r = false; + +#ifdef cpPlugins_Interface_QT4 + + // Show dialog and check if it was accepted + QFileDialog dialog( parent ); + dialog.setFileMode( QFileDialog::ExistingFiles ); + dialog.setDirectory( QFileDialog::tr( "." ) ); + dialog.setNameFilter( QFileDialog::tr( "All files (*)" ) ); + if( dialog.exec( ) ) + { + this->m_Parameters = this->m_DefaultParameters; + QStringList names = dialog.selectedFiles( ); + QStringList::const_iterator qIt = names.begin( ); + for( ; qIt != names.end( ); ++qIt ) + this->m_Parameters.AddValueToStringList( + "FileNames", qIt->toStdString( ) + ); + this->m_Parameters.SetValueAsBool( "VectorType", false ); + r = true; + + } // fi + +#endif // cpPlugins_Interface_QT4 + + return( r ); +} + // ------------------------------------------------------------------------- cpPlugins::IO::ImageReader:: ImageReader( ) diff --git a/lib/cpPlugins/Plugins/IO/ImageReader.h b/lib/cpPlugins/Plugins/IO/ImageReader.h index 803e5f8..aeee9fa 100644 --- a/lib/cpPlugins/Plugins/IO/ImageReader.h +++ b/lib/cpPlugins/Plugins/IO/ImageReader.h @@ -34,6 +34,9 @@ namespace cpPlugins itkNewMacro( Self ); itkTypeMacro( ImageReader, cpPluginsInterfaceImageSource ); + public: + virtual bool ExecConfigurationDialog( QWidget* parent ); + protected: ImageReader( ); virtual ~ImageReader( ); diff --git a/lib/cpPlugins/Plugins/IO/MeshReader.cxx b/lib/cpPlugins/Plugins/IO/MeshReader.cxx index 6706904..b8da8a3 100644 --- a/lib/cpPlugins/Plugins/IO/MeshReader.cxx +++ b/lib/cpPlugins/Plugins/IO/MeshReader.cxx @@ -4,6 +4,45 @@ #include #include +#ifdef cpPlugins_Interface_QT4 +#include +#endif // cpPlugins_Interface_QT4 + +// ------------------------------------------------------------------------- +bool cpPlugins::IO::MeshReader:: +ExecConfigurationDialog( QWidget* parent ) +{ + bool r = false; + +#ifdef cpPlugins_Interface_QT4 + + // 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( ) ) + { + this->m_Parameters = this->m_DefaultParameters; + QStringList names = dialog.selectedFiles( ); + this->m_Parameters.AddValueToStringList( + "FileNames", names[ 0 ].toStdString( ) + ); + + /* TODO + this->m_Parameters.SetValueAsString( "PixelType", "float" ); + this->m_Parameters.SetValueAsUint( "Dimension", 3 ); + */ + + r = true; + + } // fi + +#endif // cpPlugins_Interface_QT4 + + return( r ); +} + // ------------------------------------------------------------------------- cpPlugins::IO::MeshReader:: MeshReader( ) diff --git a/lib/cpPlugins/Plugins/IO/MeshReader.h b/lib/cpPlugins/Plugins/IO/MeshReader.h index 224cc03..f66e07c 100644 --- a/lib/cpPlugins/Plugins/IO/MeshReader.h +++ b/lib/cpPlugins/Plugins/IO/MeshReader.h @@ -25,6 +25,9 @@ namespace cpPlugins itkNewMacro( Self ); itkTypeMacro( MeshReader, cpPluginsInterfaceMeshSource ); + public: + virtual bool ExecConfigurationDialog( QWidget* parent ); + protected: MeshReader( ); virtual ~MeshReader( );