X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FcpPipelineEditor%2FcpPipelineEditor.cxx;h=6bda2a75087139d916155dfd18612aca04a1ffc7;hb=c06908465eb6da50572779f423d1e2c9e03b68dd;hp=872b4f4a33907f9f2cbf2539f16a4c07439b5fdb;hpb=f4aeff15ebb41183d4b89f41b29ec26043848722;p=cpPlugins.git diff --git a/appli/cpPipelineEditor/cpPipelineEditor.cxx b/appli/cpPipelineEditor/cpPipelineEditor.cxx index 872b4f4..6bda2a7 100644 --- a/appli/cpPipelineEditor/cpPipelineEditor.cxx +++ b/appli/cpPipelineEditor/cpPipelineEditor.cxx @@ -23,13 +23,36 @@ // ------------------------------------------------------------------------- cpPipelineEditor:: -cpPipelineEditor( QWidget* parent ) +cpPipelineEditor( int argc, char* argv[], QWidget* parent ) : QMainWindow( parent ), m_UI( new Ui::cpPipelineEditor ), m_Workspace( NULL ) { this->m_UI->setupUi( this ); + // Prepare plugins interface + this->m_Plugins = new cpPlugins::Interface::Interface( ); + QFileInfo info( argv[ 0 ] ); + if( info.exists( ) ) + { + std::string path = info.canonicalPath( ).toStdString( ); + if( !( this->m_Plugins->LoadDefaultConfiguration( path ) ) ) + if( this->m_Plugins->LoadFromFolder( path, false ) ) + if( !( this->m_Plugins->SaveDefaultConfiguration( path ) ) ) + QMessageBox::critical( + this, + "Error creating default plugins configuration", + "Could not save default plugins configuration" + ); + this->_UpdateLoadedPlugins( ); + + } // fi + + // Create an empty workspace + this->m_Workspace = new cpPlugins::Interface::Workspace( ); + this->m_Workspace->SetInterface( this->m_Plugins ); + this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); + // Connect actions to slots cpPipelineEditor_ConnectButton( LoadPluginsFile ); cpPipelineEditor_ConnectButton( LoadPluginsPath ); @@ -44,45 +67,52 @@ cpPipelineEditor:: delete this->m_UI; if( this->m_Workspace != NULL ) delete this->m_Workspace; + delete this->m_Plugins; } // ------------------------------------------------------------------------- void cpPipelineEditor:: _UpdateLoadedPlugins( ) { - typedef cpPlugins::Interface::Workspace::TStringContainer _TStrings; + auto& classes = this->m_Plugins->GetClasses( ); - if( this->m_Workspace == NULL ) + if( classes.size( ) == 0 ) + { + QMessageBox::critical( + this, + "Error loading default plugins", + "No plugins loaded: remember to load some!!!" + ); return; - _TStrings categories; - this->m_Workspace->GetLoadedPluginCategories( categories ); - for( auto cIt = categories.begin( ); cIt != categories.end( ); ++cIt ) + } // fi + + auto catIt = classes.begin( ); + for( ; catIt != classes.end( ); ++catIt ) { // Create or get category QList< QTreeWidgetItem* > cat_items = this->m_UI->LoadedPlugins->findItems( - cIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive + catIt->first.c_str( ), Qt::MatchExactly | Qt::MatchRecursive ); QTreeWidgetItem* cat = NULL; if( cat_items.size( ) == 0 ) { cat = new QTreeWidgetItem( - ( QTreeWidgetItem* )( NULL ), QStringList( cIt->c_str( ) ) + ( QTreeWidgetItem* )( NULL ), QStringList( catIt->first.c_str( ) ) ); this->m_UI->LoadedPlugins->addTopLevelItem( cat ); } else cat = cat_items[ 0 ]; - // Add filters - _TStrings filters = this->m_Workspace->GetLoadedPluginFilters( *cIt ); - for( auto fIt = filters.begin( ); fIt != filters.end( ); ++fIt ) + // Create filters + auto fIt = catIt->second.begin( ); + for( ; fIt != catIt->second.end( ); ++fIt ) { - // Find filter QList< QTreeWidgetItem* > filter_items = this->m_UI->LoadedPlugins->findItems( - fIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive + fIt->first.c_str( ), Qt::MatchExactly | Qt::MatchRecursive ); auto fiIt = filter_items.begin( ); auto found_fiIt = filter_items.end( ); @@ -93,9 +123,8 @@ _UpdateLoadedPlugins( ) // Add filter if( found_fiIt == filter_items.end( ) ) QTreeWidgetItem* filter = new QTreeWidgetItem( - cat, QStringList( fIt->c_str( ) ) + cat, QStringList( fIt->first.c_str( ) ) ); - } // rof } // rof @@ -118,15 +147,11 @@ _ButtonLoadPluginsFile( ) if( !( dlg.exec( ) ) ) return; - // Create a new workspace, if not ready - if( this->m_Workspace == NULL ) - this->m_Workspace = new cpPlugins::Interface::Workspace( ); - // Read QStringList names = dlg.selectedFiles( ); std::stringstream err_str; for( auto qIt = names.begin( ); qIt != names.end( ); ++qIt ) - if( !( this->m_Workspace->LoadPlugins( qIt->toStdString( ) ) ) ) + if( !( this->m_Plugins->Load( qIt->toStdString( ) ) ) ) err_str << qIt->toStdString( ) << std::endl; // Show an error message @@ -139,7 +164,6 @@ _ButtonLoadPluginsFile( ) ); // Update view - this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); this->_UpdateLoadedPlugins( ); } @@ -153,13 +177,9 @@ _ButtonLoadPluginsPath( ) if( !( dlg.exec( ) ) ) return; - // Create a new workspace, if not ready - if( this->m_Workspace == NULL ) - this->m_Workspace = new cpPlugins::Interface::Workspace( ); - // Read std::string dir = dlg.selectedFiles( ).begin( )->toStdString( ); - if( !( this->m_Workspace->LoadPluginsPath( dir, false ) ) ) + if( !( this->m_Plugins->LoadFromFolder( dir, false ) ) ) QMessageBox::critical( this, "Error loading plugins directory", @@ -167,7 +187,6 @@ _ButtonLoadPluginsPath( ) ); // Update view - this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); this->_UpdateLoadedPlugins( ); } @@ -189,12 +208,9 @@ _ActionOpenWorkspace( ) if( this->m_Workspace != NULL ) delete this->m_Workspace; this->m_Workspace = new cpPlugins::Interface::Workspace( ); + this->m_Workspace->SetInterface( this->m_Plugins ); std::string err = this->m_Workspace->LoadWorkspace( fname ); - if( err == "" ) - { - this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); - } - else + if( err != "" ) { delete this->m_Workspace; this->m_Workspace = NULL; @@ -203,8 +219,9 @@ _ActionOpenWorkspace( ) QMessageBox::tr( "Error loading workspace" ), QMessageBox::tr( err.c_str( ) ) ); - - } // fi + } + else + this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); } // -------------------------------------------------------------------------