#include #include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- bool cpPipelineEditor::BaseQtMainWindow::_TBlocker:: eventFilter( QObject* obj, QEvent* event ) { return( true ); // -> Block all events /* NOTE: correct implementation: switch( event->type( ) ) { //list event you want to prevent here ... case QEvent::KeyPress: case QEvent::KeyRelease: case QEvent::MouseButtonRelease: case QEvent::MouseButtonPress: case QEvent::MouseButtonDblClick: //... return( true ); } // hctiws return( this->QObject::eventFilter( obj, event ) ); */ } // ------------------------------------------------------------------------- cpPipelineEditor::BaseQtMainWindow:: BaseQtMainWindow( int argc, char* argv[], QApplication* app, QWidget* parent ) : Superclass( parent ), m_Application( app ), m_PluginsPath( "." ), m_TreeWidget( NULL ), m_Editor( NULL ) { this->m_Interface.GuessAccesiblePlugins( ); // Try to load plugins from executable dir QFileInfo info( argv[ 0 ] ); if( info.exists( ) ) this->_LoadPluginsFromPath( info.canonicalPath( ).toStdString( ) ); // Prepare workspace this->m_Workspace.SetInterface( &( this->m_Interface ) ); } // ------------------------------------------------------------------------- cpPipelineEditor::BaseQtMainWindow:: ~BaseQtMainWindow( ) { this->m_Interface.UnloadAll( ); } // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _Configure( QTreeWidget* tree, cpExtensions::QT::SimpleMPRWidget* mpr, cpPipelineEditor::Editor* editor ) { this->m_TreeWidget = tree; if( this->m_TreeWidget != NULL ) this->_UpdateLoadedPlugins( ); this->m_Editor = editor; if( this->m_Editor != NULL ) this->m_Editor->setWorkspace( &( this->m_Workspace ) ); if( mpr != NULL ) this->m_Workspace.SetMPRViewer( mpr ); } // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _LoadPlugins( const std::string& filename ) { try { this->m_Interface.LoadPluginFile( filename ); this->_UpdateLoadedPlugins( ); } catch( std::exception& err ) { QMessageBox::critical( this, "Error loading plugins path", err.what( ) ); } // yrt } // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _LoadPluginsFromPath( const std::string& path ) { try { this->m_Interface.LoadPluginDir( path ); this->_UpdateLoadedPlugins( ); } catch( std::exception& err ) { QMessageBox::critical( this, "Error loading plugins path", err.what( ) ); } // yrt } // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _UpdateLoadedPlugins( ) { this->_Block( ); auto filters = this->m_Interface.GetFilters( ); if( filters.size( ) == 0 ) { this->_UnBlock( ); QMessageBox::critical( this, "Error loading default plugins", "No plugins loaded: remember to load some!!!" ); return; } // fi if( this->m_TreeWidget != NULL ) { for( auto cIt = filters.begin( ); cIt != filters.end( ); ++cIt ) { // Create or get category QList< QTreeWidgetItem* > cat_items = this->m_TreeWidget->findItems( cIt->first.c_str( ), Qt::MatchExactly | Qt::MatchRecursive ); QTreeWidgetItem* cat = NULL; if( cat_items.size( ) == 0 ) { cat = new QTreeWidgetItem( ( QTreeWidgetItem* )( NULL ), QStringList( cIt->first.c_str( ) ) ); this->m_TreeWidget->addTopLevelItem( cat ); } else cat = cat_items[ 0 ]; // Create filters auto fIt = cIt->second.begin( ); for( ; fIt != cIt->second.end( ); ++fIt ) { QList< QTreeWidgetItem* > filter_items = this->m_TreeWidget->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 } // fi this->_UnBlock( ); } // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _Block( ) { this->m_Application->setOverrideCursor( Qt::WaitCursor ); this->m_Application->installEventFilter( &( this->m_Blocker ) ); } // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _UnBlock( ) { while( this->m_Application->overrideCursor( ) ) this->m_Application->restoreOverrideCursor( ); this->m_Application->removeEventFilter( &( this->m_Blocker ) ); } // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _LoadWorkspace( const std::string& filename ) { std::string err = this->m_Workspace.LoadWorkspace( filename ); if( err != "" ) { QMessageBox::critical( this, QMessageBox::tr( "Error loading workspace" ), QMessageBox::tr( err.c_str( ) ) ); } else { if( this->m_Editor != NULL ) this->m_Editor->setWorkspace( &( this->m_Workspace ) ); } // fi } // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _SaveWorkspace( const std::string& filename ) { std::string err = this->m_Workspace.SaveWorkspace( filename ); if( err != "" ) QMessageBox::critical( this, QMessageBox::tr( "Error saving workspace" ), QMessageBox::tr( err.c_str( ) ) ); } // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _InteractiveLoadPlugins( ) { QFileDialog dlg( this ); dlg.setFileMode( QFileDialog::ExistingFiles ); dlg.setDirectory( this->m_PluginsPath.c_str( ) ); std::stringstream name_filter; std::string suffix = std::string( cpPlugins_LIB_EXT ); name_filter << "Plugins file (*." << cpPlugins_LIB_EXT << ");;All files (*)"; dlg.setNameFilter( name_filter.str( ).c_str( ) ); dlg.setDefaultSuffix( suffix.c_str( ) ); if( !( dlg.exec( ) ) ) return; QStringList names = dlg.selectedFiles( ); for( auto qIt = names.begin( ); qIt != names.end( ); ++qIt ) this->_LoadPlugins( qIt->toStdString( ) ); } // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _InteractiveLoadPluginsFromPath( ) { QFileDialog dlg( this ); dlg.setFileMode( QFileDialog::DirectoryOnly ); dlg.setDirectory( this->m_PluginsPath.c_str( ) ); if( !( dlg.exec( ) ) ) return; this->_LoadPluginsFromPath( dlg.selectedFiles( ).begin( )->toStdString( ) ); } // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _InteractiveLoadWorkspace( ) { QFileDialog dlg( this ); dlg.setFileMode( QFileDialog::ExistingFile ); dlg.setDirectory( "." ); dlg.setNameFilter( QFileDialog::tr( "Workspace file (*.wxml);;All files (*)" ) ); dlg.setDefaultSuffix( QFileDialog::tr( "wxml" ) ); if( !( dlg.exec( ) ) ) return; this->_LoadWorkspace( dlg.selectedFiles( ).begin( )->toStdString( ) ); } // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _InteractiveSaveWorkspace( ) { QFileDialog dlg( this ); dlg.setFileMode( QFileDialog::AnyFile ); dlg.setDirectory( "." ); dlg.setAcceptMode( QFileDialog::AcceptSave ); dlg.setNameFilter( QFileDialog::tr( "Workspace file (*.wxml);;All files (*)" ) ); dlg.setDefaultSuffix( QFileDialog::tr( "wxml" ) ); if( !( dlg.exec( ) ) ) return; this->_SaveWorkspace( dlg.selectedFiles( ).begin( )->toStdString( ) ); } // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _ExecFilter( const std::string& filter_name ) { this->_Block( ); try { this->m_Workspace.Execute( filter_name ); this->_UnBlock( ); } catch( itk::ExceptionObject& err1 ) { this->_UnBlock( ); QMessageBox::critical( this, QMessageBox::tr( "Error executing filter" ), QMessageBox::tr( err1.GetDescription( ) ) ); } catch( std::exception& err2 ) { this->_UnBlock( ); QMessageBox::critical( this, QMessageBox::tr( "Error executing filter" ), QMessageBox::tr( err2.what( ) ) ); } catch( ... ) { this->_UnBlock( ); QMessageBox::critical( this, QMessageBox::tr( "Error executing filter" ), QMessageBox::tr( "Unknown error" ) ); } // yrt } // eof - $RCSfile$