#include #include #include #include #include #include #include #include #include #include #include #include #include /* TODO #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_Navigator( NULL ), m_Editor( NULL ), m_MPR( NULL ) { // Use some evident paths QFileInfo e_path( argv[ 0 ] ); QDir r_path( "." ); std::set< std::string > paths; paths.insert( e_path.canonicalPath( ).toStdString( ) ); paths.insert( r_path.canonicalPath( ).toStdString( ) ); std::stringstream env; for( auto p = paths.begin( ); p != paths.end( ); ++p ) env << *p << cpPlugins_ENV_SEPARATOR; // Some variables this->m_RunPath = r_path.canonicalPath( ).toStdString( ); // Get the plugins interface this->m_Plugins = TPlugins::New( ); try { this->m_Plugins->OpenEnvironments( env.str( ) ); } catch( ... ) { } try { this->m_Plugins->SaveEnvironments( this->m_RunPath ); } catch( ... ) { } this->updateEnvironment( ); // Create local workspace this->m_Workspace = TWorkspace::New( ); } // ------------------------------------------------------------------------- cpBaseQtApplication::MainWindow:: ~MainWindow( ) { } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: updateEnvironment( ) { try { this->m_Plugins->LoadEnvironments( ); this->m_Plugins->GuessPlugins( ); } catch( std::exception& err ) { QMessageBox::critical( this, "Error loading required libraries", err.what( ) ); return; } // yrt } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: updateFilter( const std::string& name ) { auto filter = this->m_Workspace->GetFilter( name ); if( filter != NULL ) cpBaseQtApplication_Execute( filter->Update( ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: showData( const std::string& name, const std::string& port ) { this->updateFilter( name ); auto filter = this->m_Workspace->GetFilter( name ); if( filter != NULL ) this->showData( filter->GetOutput( port ), port + std::string( "@" ) + name ); else QMessageBox::critical( this, QMessageBox::tr( "Error showing data" ), QMessageBox::tr( "Unknown filter." ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: showData( cpPlugins::BaseObjects::DataObject* data, const std::string& name ) { if( this->m_MPR == NULL || data == NULL ) return; // Associate visual data this->_block( ); bool success = this->m_MPR->Add( data->GetVTK< vtkDataSet >( ), name ); this->_unBlock( ); // Show data or show an error if( success ) this->m_MPR->Render( ); else QMessageBox::critical( this, QMessageBox::tr( "Error showing data" ), QMessageBox::tr( "Unknown conversion to a \"vtkProp\" object." ) ); } // ------------------------------------------------------------------------- /* TODO void cpBaseQtApplication::MainWindow:: hideData( const std::string& name, const std::string& port ) { this->hideData( port + std::string( "@" ) + name ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: hideData( const std::string& name ) { } */ // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: dataProperties( const std::string& name, const std::string& port ) { this->dataProperties( port + std::string( "@" ) + name ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: dataProperties( const std::string& name ) { if( this->m_MPR == NULL ) return; auto props = this->m_MPR->GetViewProps( name ); if( props.size( ) > 0 ) { this->_block( ); auto dlg = new cpBaseQtApplication::ActorPropertiesQDialog( NULL ); dlg->setProps( props ); dlg->addRenderWindow( this->m_MPR->GetXRenderWindow( ) ); dlg->addRenderWindow( this->m_MPR->GetYRenderWindow( ) ); dlg->addRenderWindow( this->m_MPR->GetZRenderWindow( ) ); dlg->addRenderWindow( this->m_MPR->GetWRenderWindow( ) ); this->_unBlock( ); dlg->exec( ); } // fi } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _block( ) { if( this->m_Application != NULL ) { this->m_Application->setOverrideCursor( Qt::WaitCursor ); this->m_Application->installEventFilter( &( this->m_Blocker ) ); } // fi } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _unBlock( ) { if( this->m_Application != NULL ) { while( this->m_Application->overrideCursor( ) ) this->m_Application->restoreOverrideCursor( ); this->m_Application->removeEventFilter( &( this->m_Blocker ) ); } // fi } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _configure( PluginsNavigator* nav, TMPR* mpr, Editor* edt ) { this->m_Navigator = nav; this->m_MPR = mpr; this->m_Editor = edt; this->_updatePlugins( ); if( this->m_Editor != NULL ) this->m_Editor->setWorkspace( this->m_Workspace ); // Associate interactors if( this->m_MPR != NULL ) { this->m_Workspace->AddInteractor( this->m_MPR->GetXInteractor( ) ); this->m_Workspace->AddInteractor( this->m_MPR->GetYInteractor( ) ); this->m_Workspace->AddInteractor( this->m_MPR->GetZInteractor( ) ); this->m_Workspace->AddInteractor( this->m_MPR->GetWInteractor( ) ); } // fi } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _updatePlugins( ) { if( this->m_Navigator == NULL ) return; this->_block( ); this->m_Navigator->Update( ); this->_unBlock( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _loadWorkspace( const std::string& filename ) { try { this->m_Workspace->Load( filename ); } catch( std::exception& err ) { QMessageBox::critical( this, QMessageBox::tr( "Error loading workspace" ), QMessageBox::tr( err.what( ) ) ); } // yrt if( this->m_Editor != NULL ) this->m_Editor->redrawWorkspace( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _loadWorkspace( ) { 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:: _saveWorkspace( const std::string& filename ) { try { this->m_Workspace->Save( filename ); } catch( std::exception& err ) { QMessageBox::critical( this, QMessageBox::tr( "Error saving workspace" ), QMessageBox::tr( err.what( ) ) ); } // yrt } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _saveWorkspace( ) { 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:: _showPlugins( ) { std::stringstream info; this->m_Plugins->Print( info ); QMessageBox::information( this, "Loaded libraries and plugins information", info.str( ).c_str( ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _addEnvironmentPaths( const std::string& envs ) { try { this->m_Plugins->AddEnvironments( envs ); } catch( ... ) { } try { this->m_Plugins->SaveEnvironments( this->m_RunPath ); } catch( ... ) { } this->updateEnvironment( ); this->_updatePlugins( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _addEnvironmentPaths( ) { PathsDialog dlg( this ); dlg.addPaths( this->m_Plugins->GetPaths( ) ); if( dlg.exec( ) ) { auto paths = dlg.getPaths( ); std::stringstream envs; for( auto p = paths.begin( ); p != paths.end( ); ++p ) envs << *p << cpPlugins_ENV_SEPARATOR; this->_addEnvironmentPaths( envs.str( ) ); } // fi } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _loadPlugins( const std::string& filename ) { try { this->m_Plugins->LoadFile( filename ); this->_updatePlugins( ); } catch( std::exception& err ) { QMessageBox::critical( this, "Error loading plugins path", err.what( ) ); } // yrt } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _loadPlugins( ) { QFileDialog dlg( this ); dlg.setFileMode( QFileDialog::ExistingFiles ); 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:: _loadPluginsFromPath( const std::string& path ) { try { this->m_Plugins->LoadDirectory( path ); this->_updatePlugins( ); } catch( std::exception& err ) { QMessageBox::critical( this, "Error loading plugins path", err.what( ) ); } // yrt } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _loadPluginsFromPath( ) { QFileDialog d( this ); d.setFileMode( QFileDialog::DirectoryOnly ); if( !( d.exec( ) ) ) return; this->_loadPluginsFromPath( d.selectedFiles( ).begin( )->toStdString( ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _actorsProperties( ) { if( this->m_MPR != NULL ) { auto dlg = new cpExtensions::QT::ConfigurationChooser( this ); dlg->setData( this->m_MPR ); dlg->exec( ); } // fi } // ------------------------------------------------------------------------- /* TODO void cpBaseQtApplication::MainWindow:: _ClearWorkspace( ) { if( this->m_Editor != NULL ) this->m_Editor->clear( ); this->m_Workspace->Clear( ); } */ // eof - $RCSfile$