#include #include #include #include #include #include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- bool cpBaseQtApplication::MainWindow::_TBlocker:: eventFilter( QObject* obj, QEvent* event ) { return( true ); // -> Block all events /* NOTE: this should be the 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 ) ); */ } // ------------------------------------------------------------------------- cpBaseQtApplication::MainWindow:: MainWindow( int argc, char* argv[], QApplication* app, QWidget* parent ) : Superclass( parent ), m_Application( app ), m_PluginsPath( "." ), m_TreeWidget( NULL ), m_Editor( NULL ), m_MPR( NULL ) { QFileInfo e_path( argv[ 0 ] ); QDir r_path( "." ); this->m_RunPath = r_path.canonicalPath( ).toStdString( ); std::stringstream paths; paths << e_path.canonicalPath( ).toStdString( ) << cpPlugins_SEPARATOR << this->m_RunPath; try { this->m_Interface.AddEnvironments( this->m_RunPath ); } catch( ... ) { } try { this->m_Interface.OpenEnvironments( this->m_RunPath ); } catch( ... ) { } try { this->m_Interface.SaveEnvironments( this->m_RunPath ); } catch( ... ) { } this->UpdateEnvironment( ); this->m_Workspace.SetInterface( &( this->m_Interface ) ); } // ------------------------------------------------------------------------- cpBaseQtApplication::MainWindow:: ~MainWindow( ) { } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: UpdateEnvironment( ) { try { this->m_Interface.LoadEnvironments( ); this->m_Interface.GuessPlugins( ); } catch( std::exception& err ) { QMessageBox::critical( this, "Error loading required libraries", err.what( ) ); return; } // yrt } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _Configure( QTreeWidget* tree, cpExtensions::QT::SimpleMPRWidget* mpr, cpBaseQtApplication::Editor* editor ) { this->m_TreeWidget = tree; this->_UpdateLoadedPlugins( ); this->m_Editor = editor; this->m_MPR = mpr; if( this->m_Editor != NULL ) { this->m_Editor->setWorkspace( &( this->m_Workspace ) ); // Slots <-> signals this->connect( this->m_Editor, SIGNAL( execFilter( const std::string& ) ), this, SLOT( _ExecFilter( const std::string& ) ) ); this->connect( this->m_Editor, SIGNAL( showFilterOutput( const std::string&, const std::string& ) ), this, SLOT( _ShowData( const std::string&, const std::string& ) ) ); this->connect( this->m_Editor, SIGNAL( hideFilterOutput( const std::string&, const std::string& ) ), this, SLOT( _HideData( const std::string&, const std::string& ) ) ); this->connect( this->m_Editor, SIGNAL( visualPropertiesFilterOutput( const std::string&, const std::string& ) ), this, SLOT( _DataProperties( const std::string&, const std::string& ) ) ); } // fi if( this->m_MPR != NULL ) this->m_Workspace.SetMPRViewer( this->m_MPR ); this->_ClearWorkspace( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _ClearWorkspace( ) { if( this->m_Editor != NULL ) this->m_Editor->clear( ); if( this->m_MPR != NULL ) this->m_MPR->Clear( ); this->m_Workspace.Clear( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _AddEnvironments( const std::string& environments ) { try { this->m_Interface.AddEnvironments( environments ); } catch( ... ) { } try { this->m_Interface.SaveEnvironments( this->m_RunPath ); } catch( ... ) { } this->UpdateEnvironment( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _LoadPlugins( const std::string& filename ) { try { this->m_Interface.LoadFile( filename ); this->_UpdateLoadedPlugins( ); } catch( std::exception& err ) { QMessageBox::critical( this, "Error loading plugins path", err.what( ) ); } // yrt } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _LoadPluginsFromPath( const std::string& path ) { try { this->m_Interface.LoadDirectory( path ); this->_UpdateLoadedPlugins( ); } catch( std::exception& err ) { QMessageBox::critical( this, "Error loading plugins path", err.what( ) ); } // yrt } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _UpdateLoadedPlugins( ) { if( this->m_TreeWidget == NULL ) return; this->_Block( ); auto categories = this->m_Interface.GetCategories( ); unsigned int filter_count = 0; for( auto cIt = categories.begin( ); cIt != categories.end( ); ++cIt ) { // Create or get category QList< QTreeWidgetItem* > cat_items = this->m_TreeWidget->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_TreeWidget->addTopLevelItem( cat ); } else cat = cat_items[ 0 ]; // Create filters auto filters = this->m_Interface.GetFilters( *cIt ); filter_count += filters.size( ); for( auto fIt = filters.begin( ); fIt != filters.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 this->m_TreeWidget->expandAll( ); this->_UnBlock( ); if( filter_count == 0 ) QMessageBox::critical( this, "Error loading default plugins", "No plugins loaded: remember to load some!!!" ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _Block( ) { this->m_Application->setOverrideCursor( Qt::WaitCursor ); this->m_Application->installEventFilter( &( this->m_Blocker ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _UnBlock( ) { while( this->m_Application->overrideCursor( ) ) this->m_Application->restoreOverrideCursor( ); this->m_Application->removeEventFilter( &( this->m_Blocker ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _LoadWorkspace( const std::string& filename ) { this->_ClearWorkspace( ); 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->redrawWorkspace( ); } // fi } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _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 cpBaseQtApplication::MainWindow:: _BackgroundProperties( unsigned int i ) { if( this->m_MPR == NULL ) return; QColor color = QColorDialog::getColor( QColor( 0, 0, 0 ), this, "Select Color", QColorDialog::DontUseNativeDialog ); if( color.isValid( ) ) { double r = double( color.red( ) ) / double( 255 ); double g = double( color.green( ) ) / double( 255 ); double b = double( color.blue( ) ) / double( 255 ); if( i >= 4 ) { unsigned int maxId = ( i == 4 )? 3: 4; for( unsigned int j = 0; j < maxId; ++j ) { auto ren = this->m_MPR->GetRenderer( j ); if( ren != NULL ) { ren->SetBackground( r, g, b ); ren->Render( ); } // fi } // rof } else { auto ren = this->m_MPR->GetRenderer( i ); if( ren != NULL ) { ren->SetBackground( r, g, b ); ren->Render( ); } // fi } // fi } // fi } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _DataProperties( const std::string& actor ) { if( this->m_MPR == NULL ) return; this->_Block( ); auto actors = this->m_MPR->GetActors( actor ); auto dlg = new cpBaseQtApplication::ActorPropertiesQDialog( NULL ); for( auto i = actors.begin( ); i != actors.end( ); ++i ) dlg->addActor( *i ); dlg->addRenderWindow( this->m_MPR->GetRenderWindow( 0 ) ); dlg->addRenderWindow( this->m_MPR->GetRenderWindow( 1 ) ); dlg->addRenderWindow( this->m_MPR->GetRenderWindow( 2 ) ); dlg->addRenderWindow( this->m_MPR->GetRenderWindow( 3 ) ); this->_UnBlock( ); dlg->exec( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _ShowData( const std::string& filter_name, const std::string& output_name ) { if( this->m_MPR == NULL ) return; auto output = this->m_Workspace.GetOutput( filter_name, output_name ); if( output != NULL ) { this->_Block( ); auto actor = output->GetVTKActor( ); if( actor != NULL ) { this->m_MPR->AddActor( actor, output_name + std::string( "@" ) + filter_name ); this->_UnBlock( ); } else { this->_UnBlock( ); QMessageBox::critical( this, QMessageBox::tr( "Error showing data" ), QMessageBox::tr( "Unknown VTK conversion." ) ); } // fi } else QMessageBox::critical( this, QMessageBox::tr( "Error showing data" ), QMessageBox::tr( "Unknown port name." ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _HideData( const std::string& filter, const std::string& output ) { std::cout << "MainWindow::HideData" << std::endl; /* TODO */ } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _DataProperties( const std::string& filter_name, const std::string& output_name ) { if( this->m_MPR == NULL ) return; auto output = this->m_Workspace.GetOutput( filter_name, output_name ); if( output != NULL ) this->_DataProperties( output_name + std::string( "@" ) + filter_name ); else QMessageBox::critical( this, QMessageBox::tr( "Error showing data" ), QMessageBox::tr( "Unknown port name." ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _InteractiveLoadPlugins( ) { QFileDialog dlg( this ); dlg.setFileMode( QFileDialog::ExistingFiles ); dlg.setDirectory( this->m_PluginsPath.c_str( ) ); std::stringstream filter; std::string suffix = std::string( cpPlugins_LIB_EXT ); filter << "Plugins file (*." << cpPlugins_LIB_EXT << ");;All files (*)"; dlg.setNameFilter( 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 cpBaseQtApplication::MainWindow:: _InteractiveLoadPluginsFromPath( ) { QFileDialog d( this ); d.setFileMode( QFileDialog::DirectoryOnly ); d.setDirectory( this->m_PluginsPath.c_str( ) ); if( !( d.exec( ) ) ) return; this->_LoadPluginsFromPath( d.selectedFiles( ).begin( )->toStdString( ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _ShowPlugins( ) { auto paths = this->m_Interface.GetPaths( ); auto plugins = this->m_Interface.GetPlugins( ); std::stringstream info; info << "----- PATHS -----" << std::endl; for( auto i = paths.begin( ); i != paths.end( ); ++i ) info << " " << *i << std::endl; info << std::endl << "----- PLUGINS -----" << std::endl; for( auto i = plugins.begin( ); i != plugins.end( ); ++i ) info << " " << *i << std::endl; QMessageBox::information( this, "Loaded libraries and plugins information", info.str( ).c_str( ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _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 cpBaseQtApplication::MainWindow:: _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 cpBaseQtApplication::MainWindow:: _InteractiveAddEnviromentPaths( ) { PathsDialog dlg( this ); dlg.addPaths( this->m_Interface.GetPaths( ) ); if( dlg.exec( ) ) { auto paths = dlg.getPaths( ); std::stringstream envs; for( auto p = paths.begin( ); p != paths.end( ); ++p ) envs << *p << cpPlugins_SEPARATOR; this->_AddEnvironments( envs.str( ) ); this->UpdateEnvironment( ); } // fi } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _ExecFilter( const std::string& filter_name ) { cpBaseQtApplication_Execute( this->m_Workspace.Execute( filter_name ) ); } // eof - $RCSfile$