X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=appli%2FcpPipelineEditor%2FcpPipelineEditor.cxx;h=872b4f4a33907f9f2cbf2539f16a4c07439b5fdb;hb=f4aeff15ebb41183d4b89f41b29ec26043848722;hp=87fd6c86e65984f7c81926d1aeac700462407da9;hpb=dd763c7c99bb59edcc7035738ff1ad10255e2525;p=cpPlugins.git diff --git a/appli/cpPipelineEditor/cpPipelineEditor.cxx b/appli/cpPipelineEditor/cpPipelineEditor.cxx index 87fd6c8..872b4f4 100644 --- a/appli/cpPipelineEditor/cpPipelineEditor.cxx +++ b/appli/cpPipelineEditor/cpPipelineEditor.cxx @@ -1,6 +1,8 @@ #include "cpPipelineEditor.h" #include "ui_cpPipelineEditor.h" +#include "QNodesEditor.h" + #include #include #include @@ -12,6 +14,13 @@ this, SLOT( _Action##ACTION( ) ) \ ) +// ------------------------------------------------------------------------- +#define cpPipelineEditor_ConnectButton( BUTTON ) \ + QObject::connect( \ + this->m_UI->Button##BUTTON, SIGNAL( clicked( ) ), \ + this, SLOT( _Button##BUTTON( ) ) \ + ) + // ------------------------------------------------------------------------- cpPipelineEditor:: cpPipelineEditor( QWidget* parent ) @@ -22,7 +31,10 @@ cpPipelineEditor( QWidget* parent ) this->m_UI->setupUi( this ); // Connect actions to slots + cpPipelineEditor_ConnectButton( LoadPluginsFile ); + cpPipelineEditor_ConnectButton( LoadPluginsPath ); cpPipelineEditor_ConnectAction( OpenWorkspace ); + cpPipelineEditor_ConnectAction( SaveWorkspace ); } // ------------------------------------------------------------------------- @@ -34,6 +46,131 @@ cpPipelineEditor:: delete this->m_Workspace; } +// ------------------------------------------------------------------------- +void cpPipelineEditor:: +_UpdateLoadedPlugins( ) +{ + typedef cpPlugins::Interface::Workspace::TStringContainer _TStrings; + + if( this->m_Workspace == NULL ) + return; + + _TStrings categories; + this->m_Workspace->GetLoadedPluginCategories( categories ); + for( auto cIt = categories.begin( ); cIt != categories.end( ); ++cIt ) + { + // Create or get category + QList< QTreeWidgetItem* > cat_items = + this->m_UI->LoadedPlugins->findItems( + cIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive + ); + QTreeWidgetItem* cat = NULL; + if( cat_items.size( ) == 0 ) + { + cat = new QTreeWidgetItem( + ( QTreeWidgetItem* )( NULL ), QStringList( cIt->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 ) + { + // Find filter + QList< QTreeWidgetItem* > filter_items = + this->m_UI->LoadedPlugins->findItems( + fIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive + ); + auto fiIt = filter_items.begin( ); + auto found_fiIt = filter_items.end( ); + for( ; fiIt != filter_items.end( ); ++fiIt ) + if( ( *fiIt )->parent( ) == cat ) + found_fiIt = fiIt; + + // Add filter + if( found_fiIt == filter_items.end( ) ) + QTreeWidgetItem* filter = new QTreeWidgetItem( + cat, QStringList( fIt->c_str( ) ) + ); + + } // rof + + } // rof +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor:: +_ButtonLoadPluginsFile( ) +{ + QFileDialog dlg( this ); + dlg.setFileMode( QFileDialog::ExistingFiles ); + dlg.setDirectory( "." ); +#ifdef _WIN32 + dlg.setNameFilter( "Plugins file (*.dll);;All files (*)" ); + dlg.setDefaultSuffix( "dll" ); +#else // _WIN32 + dlg.setNameFilter( "Plugins file (*.so);;All files (*)" ); + dlg.setDefaultSuffix( "so" ); +#endif // _WIN32 + 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( ) ) ) ) + err_str << qIt->toStdString( ) << std::endl; + + // Show an error message + std::string err = err_str.str( ); + if( err.size( ) > 0 ) + QMessageBox::critical( + this, + "Error loading plugins", + err.c_str( ) + ); + + // Update view + this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); + this->_UpdateLoadedPlugins( ); +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor:: +_ButtonLoadPluginsPath( ) +{ + QFileDialog dlg( this ); + dlg.setFileMode( QFileDialog::DirectoryOnly ); + dlg.setDirectory( "." ); + 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 ) ) ) + QMessageBox::critical( + this, + "Error loading plugins directory", + dir.c_str( ) + ); + + // Update view + this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); + this->_UpdateLoadedPlugins( ); +} + // ------------------------------------------------------------------------- void cpPipelineEditor:: _ActionOpenWorkspace( ) @@ -55,7 +192,7 @@ _ActionOpenWorkspace( ) std::string err = this->m_Workspace->LoadWorkspace( fname ); if( err == "" ) { - this->m_UI->Canvas->setWorkspace( this->m_Workspace ); + this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); } else { @@ -70,4 +207,32 @@ _ActionOpenWorkspace( ) } // fi } +// ------------------------------------------------------------------------- +void cpPipelineEditor:: +_ActionSaveWorkspace( ) +{ + if( this->m_Workspace == NULL ) + return; + + QFileDialog dlg( this ); + dlg.setFileMode( QFileDialog::AnyFile ); + dlg.setDirectory( "." ); + dlg.setAcceptMode( QFileDialog::AcceptSave ); + dlg.setNameFilter( + QFileDialog::tr( "Workspace file (*.xml);;All files (*)" ) + ); + dlg.setDefaultSuffix( QFileDialog::tr( "xml" ) ); + if( !( dlg.exec( ) ) ) + return; + std::string fname = dlg.selectedFiles( ).at( 0 ).toStdString( ); + + std::string err = this->m_Workspace->SaveWorkspace( fname ); + if( err != "" ) + QMessageBox::critical( + this, + QMessageBox::tr( "Error saving workspace" ), + QMessageBox::tr( err.c_str( ) ) + ); +} + // eof - $RCSfile$