From e2fb8817731f6231d34941a208e46b36dad425b2 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Sun, 17 Apr 2016 20:22:53 -0500 Subject: [PATCH] ... --- appli/examples/plugins/CMakeLists.txt | 1 + .../examples/plugins/example_GuessPlugins.cxx | 24 ++++++++++++ .../plugins/example_ReadWriteImage.cxx | 28 ++++--------- .../example_ReadWriteImageWithWorkspace.cxx | 20 ++-------- lib/cpPipelineEditor/BaseQtMainWindow.cxx | 16 +++----- lib/cpPlugins/Interface.cxx | 39 +++++++++++-------- lib/cpPlugins/Interface.h | 2 + 7 files changed, 66 insertions(+), 64 deletions(-) create mode 100644 appli/examples/plugins/example_GuessPlugins.cxx diff --git a/appli/examples/plugins/CMakeLists.txt b/appli/examples/plugins/CMakeLists.txt index 752c62b..fa578a8 100644 --- a/appli/examples/plugins/CMakeLists.txt +++ b/appli/examples/plugins/CMakeLists.txt @@ -1,5 +1,6 @@ SET( examples_SOURCES + example_GuessPlugins example_LoadPluginsFile example_LoadPluginsDirectory example_ReadWriteImage diff --git a/appli/examples/plugins/example_GuessPlugins.cxx b/appli/examples/plugins/example_GuessPlugins.cxx new file mode 100644 index 0000000..6d2f7a1 --- /dev/null +++ b/appli/examples/plugins/example_GuessPlugins.cxx @@ -0,0 +1,24 @@ +#include +#include + +int main( int argc, char* argv[] ) +{ + // Load interface + cpPlugins::Interface interface; + interface.GuessAccesiblePlugins( ); + + // Show loaded filters + auto filters = interface.GetFilters( ); + for( auto cIt = filters.begin( ); cIt != filters.end( ); ++cIt ) + { + std::cout << "Category: " << cIt->first << std::endl; + for( auto nIt = cIt->second.begin( ); nIt != cIt->second.end( ); ++nIt ) + std::cout + << "\tFilter: " << *nIt + << std::endl; + + } // rof + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/appli/examples/plugins/example_ReadWriteImage.cxx b/appli/examples/plugins/example_ReadWriteImage.cxx index e327074..5532068 100644 --- a/appli/examples/plugins/example_ReadWriteImage.cxx +++ b/appli/examples/plugins/example_ReadWriteImage.cxx @@ -3,11 +3,11 @@ int main( int argc, char* argv[] ) { - if( argc < 4 ) + if( argc < 3 ) { std::cerr << "Usage: " << argv[ 0 ] - << " plugins_library input_image(s) output_image" << std::endl; + << " input_image(s) output_image" << std::endl; return( 1 ); } // fi @@ -15,19 +15,7 @@ int main( int argc, char* argv[] ) // Load interface int ret = 0; cpPlugins::Interface interface; - try - { - interface.LoadPluginFile( argv[ 1 ] ); - } - catch( std::exception& err ) - { - std::cerr - << "Interface load failed on \"" << argv[ 1 ] << "\": " - << err.what( ) - << std::endl; - ret = 1; - - } // fi + interface.GuessAccesiblePlugins( ); // Create filters cpPlugins::ProcessObject::Pointer reader; @@ -38,8 +26,7 @@ int main( int argc, char* argv[] ) if( reader.IsNull( ) ) { std::cerr - << "\"IO::ImageReader\" creation failed from \"" - << argv[ 1 ] << "\"" + << "\"IO::ImageReader\" creation failed." << std::endl; ret = 1; @@ -48,8 +35,7 @@ int main( int argc, char* argv[] ) if( writer.IsNull( ) ) { std::cerr - << "\"IO::ImageWriter\" creation failed from \"" - << argv[ 1 ] << "\"" + << "\"IO::ImageWriter\" creation failed." << std::endl; ret = 1; @@ -58,7 +44,7 @@ int main( int argc, char* argv[] ) catch( std::exception& err ) { std::cerr - << "Filter creation failed on \"" << argv[ 1 ] << "\": " + << "Filter creation failed: " << err.what( ) << std::endl; ret = 1; @@ -69,7 +55,7 @@ int main( int argc, char* argv[] ) { // Configure filters auto reader_params = reader->GetParameters( ); - for( int i = 2; i < argc - 1; ++i ) + for( int i = 1; i < argc - 1; ++i ) reader_params->AddToOpenFileNameList( "FileNames", argv[ i ] ); auto writer_params = writer->GetParameters( ); writer_params->SetSaveFileName( "FileName", argv[ argc - 1 ] ); diff --git a/appli/examples/plugins/example_ReadWriteImageWithWorkspace.cxx b/appli/examples/plugins/example_ReadWriteImageWithWorkspace.cxx index cba6793..1d2382d 100644 --- a/appli/examples/plugins/example_ReadWriteImageWithWorkspace.cxx +++ b/appli/examples/plugins/example_ReadWriteImageWithWorkspace.cxx @@ -4,11 +4,11 @@ int main( int argc, char* argv[] ) { - if( argc < 4 ) + if( argc < 3 ) { std::cerr << "Usage: " << argv[ 0 ] - << " plugins_library input_image(s) output_image" << std::endl; + << " input_image(s) output_image" << std::endl; return( 1 ); } // fi @@ -16,19 +16,7 @@ int main( int argc, char* argv[] ) // Load interface int ret = 0; cpPlugins::Interface interface; - try - { - interface.LoadPluginFile( argv[ 1 ] ); - } - catch( std::exception& err ) - { - std::cerr - << "Interface load failed on \"" << argv[ 1 ] << "\": " - << err.what( ) - << std::endl; - ret = 1; - - } // fi + interface.GuessAccesiblePlugins( ); // Create filters cpPlugins::Workspace workspace; @@ -39,7 +27,7 @@ int main( int argc, char* argv[] ) // Configure filters auto reader_params = reader->GetParameters( ); - for( int i = 2; i < argc - 1; ++i ) + for( int i = 1; i < argc - 1; ++i ) reader_params->AddToOpenFileNameList( "FileNames", argv[ i ] ); auto writer_params = writer->GetParameters( ); writer_params->SetSaveFileName( "FileName", argv[ argc - 1 ] ); diff --git a/lib/cpPipelineEditor/BaseQtMainWindow.cxx b/lib/cpPipelineEditor/BaseQtMainWindow.cxx index c19dd6f..b600c0e 100644 --- a/lib/cpPipelineEditor/BaseQtMainWindow.cxx +++ b/lib/cpPipelineEditor/BaseQtMainWindow.cxx @@ -43,22 +43,16 @@ BaseQtMainWindow( m_TreeWidget( NULL ), m_Editor( NULL ) { - // Prepare plugins interface + this->m_Interface.GuessAccesiblePlugins( ); + QFileInfo info( argv[ 0 ] ); if( info.exists( ) ) { - this->m_Interface.LoadConfiguration( cpPlugins_CONFIG_FILE ); - this->_LoadPluginsFromPath( this->m_PluginsPath ); - this->m_PluginsPath = info.canonicalPath( ).toStdString( ); - - } // fi - QDir exec_dir( "." ); - if( exec_dir.exists( ) ) - { - this->_LoadPluginsFromPath( exec_dir.canonicalPath( ).toStdString( ) ); - this->m_PluginsPath = exec_dir.canonicalPath( ).toStdString( ); + auto exec_dir = info.canonicalPath( ).toStdString( ); + this->_LoadPluginsFromPath( exec_dir ); } // fi + this->_UpdateLoadedPlugins( ); // Prepare workspace this->m_Workspace.SetInterface( &( this->m_Interface ) ); diff --git a/lib/cpPlugins/Interface.cxx b/lib/cpPlugins/Interface.cxx index 1d88373..9a2f709 100644 --- a/lib/cpPlugins/Interface.cxx +++ b/lib/cpPlugins/Interface.cxx @@ -28,6 +28,26 @@ GetFilters( ) return( this->m_Filters ); } +// ------------------------------------------------------------------------- +void cpPlugins::Interface:: +GuessAccesiblePlugins( ) +{ + // Load environment configuration + char* path = std::getenv( "cpPlugins_PATHS" ); + if( path != NULL ) + { + std::vector< std::string > tokens; + cpPlugins::TokenizeString( tokens, path, "#" ); + for( auto tIt = tokens.begin( ); tIt != tokens.end( ); ++tIt ) + try { this->LoadPluginDir( *tIt ); } catch( ... ) { } + + } // fi + + // Load local path + auto lpath = cpPlugins::CanonicalPath( "." ); + try { this->LoadPluginDir( lpath ); } catch( ... ) { } +} + // ------------------------------------------------------------------------- bool cpPlugins::Interface:: LoadConfiguration( const std::string& filename ) @@ -39,18 +59,7 @@ LoadConfiguration( const std::string& filename ) this->UnloadAll( ); std::string line; while( std::getline( in, line ) ) - { - try - { - this->LoadPluginFile( line ); - } - catch( ... ) - { - // Do nothing - - } // yrt - - } // elihw + try { this->LoadPluginFile( line ); } catch( ... ) { } return( true ); } @@ -163,10 +172,8 @@ LoadPluginDir( const std::string& dirname ) ); count++; } - catch( ... ) - { - // Ignore errors - } // yrt + catch( ... ) { } + } // elihw closedir( dir ); } diff --git a/lib/cpPlugins/Interface.h b/lib/cpPlugins/Interface.h index 451c0e0..22d4811 100644 --- a/lib/cpPlugins/Interface.h +++ b/lib/cpPlugins/Interface.h @@ -29,6 +29,8 @@ namespace cpPlugins const TFilters& GetFilters( ); + void GuessAccesiblePlugins( ); + bool LoadConfiguration( const std::string& filename ); bool SaveConfiguration( const std::string& filename ) const; void LoadPluginFile( const std::string& filename ); -- 2.47.1