From f533290f40279617e54e19086dde7c0ba9b07f5b Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Mon, 14 Mar 2016 17:53:06 -0500 Subject: [PATCH] ... --- appli/PipelineEditor/PipelineEditor.cxx | 63 ++++++++++++------- lib/cpPlugins/BaseWidget.cxx | 25 ++++++++ lib/cpPlugins/BaseWidget.h | 5 ++ lib/cpPlugins/Interface.cxx | 54 ++++++++++++++-- lib/cpPlugins/Interface.h | 2 + lib/cpPlugins/ProcessObject.cxx | 14 +++++ lib/cpPlugins/ProcessObject.h | 7 +-- lib/cpPlugins/Workspace.cxx | 9 +-- .../Base_explicit_description.txt | 2 + 9 files changed, 143 insertions(+), 38 deletions(-) diff --git a/appli/PipelineEditor/PipelineEditor.cxx b/appli/PipelineEditor/PipelineEditor.cxx index 5fe9bdf..9868abc 100644 --- a/appli/PipelineEditor/PipelineEditor.cxx +++ b/appli/PipelineEditor/PipelineEditor.cxx @@ -61,8 +61,13 @@ PipelineEditor( int argc, char* argv[], QApplication* app, QWidget* parent ) QFileInfo info( argv[ 0 ] ); if( info.exists( ) ) { - this->m_PluginsPath = info.canonicalPath( ).toStdString( ); - this->_LoadPluginsFromPath( this->m_PluginsPath ); + if( !( this->m_Interface.LoadConfiguration( cpPlugins_CONFIG_FILE ) ) ) + { + this->m_PluginsPath = info.canonicalPath( ).toStdString( ); + this->_LoadPluginsFromPath( this->m_PluginsPath ); + } + else + this->_UpdateLoadedPlugins( ); } // fi @@ -200,6 +205,7 @@ _UpdateLoadedPlugins( ) } // rof this->_UnBlock( ); + this->m_Interface.SaveConfiguration( cpPlugins_CONFIG_FILE ); } // ------------------------------------------------------------------------- @@ -223,15 +229,14 @@ _UnBlock( ) void PipelineEditor:: _ButtonLoadPluginsFile( ) { - /* QFileDialog dlg( this ); dlg.setFileMode( QFileDialog::ExistingFiles ); dlg.setDirectory( "." ); std::stringstream name_filter; - std::string suffix = std::string( cpPlugins_PLUGIN_EXT ).substr( 1 ); - - name_filter << "Plugins file (*" << cpPlugins_PLUGIN_EXT << ");;All files (*)"; + std::string suffix = std::string( cpPlugins_PLUGIN_EXT ); + name_filter + << "Plugins file (*." << cpPlugins_PLUGIN_EXT << ");;All files (*)"; dlg.setNameFilter( name_filter.str( ).c_str( ) ); dlg.setDefaultSuffix( suffix.c_str( ) ); @@ -242,7 +247,18 @@ _ButtonLoadPluginsFile( ) QStringList names = dlg.selectedFiles( ); std::stringstream err_str; for( auto qIt = names.begin( ); qIt != names.end( ); ++qIt ) - err_str << this->m_Interface->Load( qIt->toStdString( ) ); + { + try + { + this->m_Interface.LoadPluginFile( qIt->toStdString( ) ); + } + catch( std::exception& err ) + { + err_str << err.what( ) << std::endl; + + } // yrt + + } // rof // Show an error message std::string err = err_str.str( ); @@ -254,9 +270,8 @@ _ButtonLoadPluginsFile( ) ); // Update view - this->m_Interface->SaveDefaultConfiguration( this->m_PluginsPath ); + // TODO: this->m_Interface.SaveDefaultConfiguration( this->m_PluginsPath ); this->_UpdateLoadedPlugins( ); - */ } // ------------------------------------------------------------------------- @@ -264,25 +279,25 @@ void PipelineEditor:: _ButtonLoadPluginsPath( ) { /* - QFileDialog dlg( this ); - dlg.setFileMode( QFileDialog::DirectoryOnly ); - dlg.setDirectory( "." ); - if( !( dlg.exec( ) ) ) + QFileDialog dlg( this ); + dlg.setFileMode( QFileDialog::DirectoryOnly ); + dlg.setDirectory( "." ); + if( !( dlg.exec( ) ) ) return; - // Read - std::string dir = dlg.selectedFiles( ).begin( )->toStdString( ); - std::string err = this->m_Interface->LoadFromFolder( dir, false ); - if( err != "" ) + // Read + std::string dir = dlg.selectedFiles( ).begin( )->toStdString( ); + std::string err = this->m_Interface->LoadFromFolder( dir, false ); + if( err != "" ) QMessageBox::critical( - this, - "Error loading plugins directory", - err.c_str( ) - ); + this, + "Error loading plugins directory", + err.c_str( ) + ); - // Update view - this->m_Interface->SaveDefaultConfiguration( this->m_PluginsPath ); - this->_UpdateLoadedPlugins( ); + // Update view + this->m_Interface->SaveDefaultConfiguration( this->m_PluginsPath ); + this->_UpdateLoadedPlugins( ); */ } diff --git a/lib/cpPlugins/BaseWidget.cxx b/lib/cpPlugins/BaseWidget.cxx index 35915d2..faebdce 100644 --- a/lib/cpPlugins/BaseWidget.cxx +++ b/lib/cpPlugins/BaseWidget.cxx @@ -38,6 +38,31 @@ SetSingleInteractor( vtkRenderWindowInteractor* i ) } // fi } +// ------------------------------------------------------------------------- +bool cpPlugins::BaseWidget:: +IsInteractive( ) +{ + return( true ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::BaseWidget:: +SetInteractionObjects( const std::vector< void* >& objs ) +{ + if( objs.size( ) > 0 ) + { + vtkRenderWindowInteractor* rwi = + reinterpret_cast< vtkRenderWindowInteractor* >( objs[ 0 ] ); + this->SetSingleInteractor( rwi ); + } + if( objs.size( ) > 1 ) + { + TMPRWidget* wdg = reinterpret_cast< TMPRWidget* >( objs[ 1 ] ); + this->SetMPRViewer( wdg ); + + } // fi +} + // ------------------------------------------------------------------------- cpPlugins::BaseWidget:: BaseWidget( ) diff --git a/lib/cpPlugins/BaseWidget.h b/lib/cpPlugins/BaseWidget.h index 04de85a..3dddc59 100644 --- a/lib/cpPlugins/BaseWidget.h +++ b/lib/cpPlugins/BaseWidget.h @@ -39,6 +39,11 @@ namespace cpPlugins void SetMPRViewer( TMPRWidget* v ); void SetSingleInteractor( vtkRenderWindowInteractor* i ); + virtual bool IsInteractive( ) override; + virtual void SetInteractionObjects( + const std::vector< void* >& objs + ) override; + protected: BaseWidget( ); virtual ~BaseWidget( ); diff --git a/lib/cpPlugins/Interface.cxx b/lib/cpPlugins/Interface.cxx index 0ee1faf..2592882 100644 --- a/lib/cpPlugins/Interface.cxx +++ b/lib/cpPlugins/Interface.cxx @@ -1,6 +1,7 @@ #include #ifdef cpPlugins_SYS_WINDOWS +# include #else // cpPlugins_SYS_WINDOWS # include #endif // cpPlugins_SYS_WINDOWS @@ -26,6 +27,45 @@ GetFilters( ) return( this->m_Filters ); } +// ------------------------------------------------------------------------- +bool cpPlugins::Interface:: +LoadConfiguration( const std::string& filename ) +{ + std::ifstream in( filename.c_str( ) ); + if( !in ) + return( false ); + + this->UnloadAll( ); + std::string line; + while( std::getline( in, line ) ) + { + try + { + this->LoadPluginFile( line ); + } + catch( ... ) + { + // Do nothing + + } // yrt + + } // elihw + return( true ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface:: +SaveConfiguration( const std::string& filename ) const +{ + std::ofstream out( filename.c_str( ) ); + if( !out ) + return( false ); + auto dIt = this->m_DynLibraries.begin( ); + for( ; dIt != this->m_DynLibraries.end( ); ++dIt ) + out << dIt->first << std::endl; + out.close( ); +} + // ------------------------------------------------------------------------- void cpPlugins::Interface:: LoadPluginFile( const std::string& filename ) @@ -124,7 +164,7 @@ _DLOpen( const std::string& fname ) { void* hnd = NULL; #ifdef cpPlugins_SYS_WINDOWS - // TODO: + hnd = ::LoadLibraryA( fname.c_str( ) ); #else // cpPlugins_SYS_WINDOWS hnd = dlopen( fname.c_str( ), RTLD_NOW | RTLD_GLOBAL ); dlerror( ); @@ -137,11 +177,15 @@ cpPlugins::Interface:: TFilters cpPlugins::Interface:: _DLGetFilters( void* hnd ) { + typedef const TFilters ( *f_t )( ); + TFilters filters; #ifdef cpPlugins_SYS_WINDOWS - // TODO: + auto f = ( f_t )( + ::GetProcAddress( ( HMODULE )hnd, "cpPlugins_LoadedFilters" ) + ); + std::cout << f << std::endl; #else // cpPlugins_SYS_WINDOWS - typedef const TFilters ( *f_t )( ); auto f = ( f_t ) dlsym( hnd, "cpPlugins_LoadedFilters" ); const char* err = dlerror( ); if( err != NULL ) @@ -154,8 +198,8 @@ _DLGetFilters( void* hnd ) ); } // fi - filters = f( ); #endif // cpPlugins_SYS_WINDOWS + filters = f( ); return( filters ); } @@ -187,7 +231,7 @@ void cpPlugins::Interface:: _DLClose( void* hnd ) { #ifdef cpPlugins_SYS_WINDOWS - // TODO: + ::FreeLibrary( ( HMODULE )hnd ); #else // cpPlugins_SYS_WINDOWS dlclose( hnd ); #endif // cpPlugins_SYS_WINDOWS diff --git a/lib/cpPlugins/Interface.h b/lib/cpPlugins/Interface.h index 61ddf3b..5dcd843 100644 --- a/lib/cpPlugins/Interface.h +++ b/lib/cpPlugins/Interface.h @@ -29,6 +29,8 @@ namespace cpPlugins const TFilters& GetFilters( ); + bool LoadConfiguration( const std::string& filename ); + bool SaveConfiguration( const std::string& filename ) const; void LoadPluginFile( const std::string& filename ); void UnloadAll( ); diff --git a/lib/cpPlugins/ProcessObject.cxx b/lib/cpPlugins/ProcessObject.cxx index 52b4ac4..b915bec 100644 --- a/lib/cpPlugins/ProcessObject.cxx +++ b/lib/cpPlugins/ProcessObject.cxx @@ -264,6 +264,20 @@ CreateQtDialog( ) #endif // cpPlugins_QT4 } +// ------------------------------------------------------------------------- +bool cpPlugins::ProcessObject:: +IsInteractive( ) +{ + return( false ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::ProcessObject:: +SetInteractionObjects( const std::vector< void* >& objs ) +{ + // Do nothing +} + // ------------------------------------------------------------------------- cpPlugins::ProcessObject:: ProcessObject( ) diff --git a/lib/cpPlugins/ProcessObject.h b/lib/cpPlugins/ProcessObject.h index 3979ac5..932d465 100644 --- a/lib/cpPlugins/ProcessObject.h +++ b/lib/cpPlugins/ProcessObject.h @@ -9,11 +9,6 @@ namespace cpPlugins { - // Forward declaration - /* TODO - class ParametersQtDialog; - */ - /** */ class cpPlugins_EXPORT ProcessObject @@ -62,6 +57,8 @@ namespace cpPlugins // Qt dialog creation virtual ParametersQtDialog* CreateQtDialog( ); + virtual bool IsInteractive( ); + virtual void SetInteractionObjects( const std::vector< void* >& objs ); protected: ProcessObject( ); diff --git a/lib/cpPlugins/Workspace.cxx b/lib/cpPlugins/Workspace.cxx index f6491ca..9476679 100644 --- a/lib/cpPlugins/Workspace.cxx +++ b/lib/cpPlugins/Workspace.cxx @@ -121,11 +121,12 @@ CreateFilter( this->m_Interface->Create( category, filter ); if( f.IsNotNull( ) ) { - BaseWidget* bw = dynamic_cast< BaseWidget* >( f.GetPointer( ) ); - if( bw != NULL ) + if( f->IsInteractive( ) ) { - bw->SetSingleInteractor( this->m_SingleInteractor ); - bw->SetMPRViewer( this->m_MPRViewer ); + std::vector< void* > interactive_objects; + interactive_objects.push_back( this->m_SingleInteractor ); + interactive_objects.push_back( this->m_MPRViewer ); + f->SetInteractionObjects( interactive_objects ); } // fi Object::Pointer o = f.GetPointer( ); diff --git a/lib/cpPlugins_ITKInstances/Base_explicit_description.txt b/lib/cpPlugins_ITKInstances/Base_explicit_description.txt index 0b4d7de..00dd960 100644 --- a/lib/cpPlugins_ITKInstances/Base_explicit_description.txt +++ b/lib/cpPlugins_ITKInstances/Base_explicit_description.txt @@ -1,4 +1,5 @@ i complex +i map i string i vector i itkArray.h @@ -33,6 +34,7 @@ c itk::ImportImageContainer< unsigned long , #1 > c itk::ImportImageContainer< unsigned long , std::complex< #5 > > c itk::ImportImageContainer< unsigned long , itk::RGBPixel< #1 > > c itk::ImportImageContainer< unsigned long , itk::RGBAPixel< #1 > > +c itk::SimpleDataObjectDecorator< std::map< itk::Index< #6 >, std::pair< itk::Index< #6 >, short >, itk::Functor::IndexLexicographicCompare< #6 > > > a #1 = #integers;#floats a #2 = #all_dims a #3 = bool;std::string -- 2.45.1