X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpBaseQtApplication%2FMainWindow.cxx;h=668eb3bff5951d0e3dae76672b5935957d4bce00;hb=61b3659afe961ed248f30e26f9ca8f28fcfafddc;hp=bfe8b5b9d4b5b9943b3e36080dbd4b7c543529a9;hpb=8d542556415c0f37a325b1641bb51b2bc284a115;p=cpPlugins.git diff --git a/lib/cpBaseQtApplication/MainWindow.cxx b/lib/cpBaseQtApplication/MainWindow.cxx index bfe8b5b..668eb3b 100644 --- a/lib/cpBaseQtApplication/MainWindow.cxx +++ b/lib/cpBaseQtApplication/MainWindow.cxx @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include @@ -8,30 +10,18 @@ // ------------------------------------------------------------------------- cpBaseQtApplication::MainWindow:: -MainWindow( - int argc, char* argv[], - QWidget* parent - ) +MainWindow( int argc, char* argv[], QWidget* parent ) : Superclass( parent ), m_LastSaveFileName( "" ), - m_SingleWorkspace( false ), m_BaseWindowTitle( "cpBaseQtApplication" ), m_Canvas( NULL ), m_Navigator( NULL ), m_Viewer( NULL ) { this->m_RunPath = QDir( "." ).canonicalPath( ).toStdString( ); - this->m_Plugins = TPlugins::New( ); - try - { - this->m_Plugins->GuessEnvironment( this->m_RunPath ); - this->m_Plugins->GuessPlugins( ); - } - catch( std::exception& err ) - { - QMessageBox::critical( this, "Error guessing plugins.", err.what( ) ); - - } // yrt + this->m_Loader.GuessEnvironment( this->m_RunPath ); + this->m_Loader.SaveEnvironment( this->m_RunPath ); + this->_clearWorkspace( ); } // ------------------------------------------------------------------------- @@ -43,25 +33,17 @@ cpBaseQtApplication::MainWindow:: // ------------------------------------------------------------------------- cpBaseQtApplication::MainWindow:: TWorkspace* cpBaseQtApplication::MainWindow:: -workspace( const std::string& wname ) +workspace( ) { - auto wIt = this->m_Workspaces.find( wname ); - if( wIt != this->m_Workspaces.end( ) ) - return( wIt->second.GetPointer( ) ); - else - return( NULL ); + return( this->m_Workspace ); } // ------------------------------------------------------------------------- const cpBaseQtApplication::MainWindow:: TWorkspace* cpBaseQtApplication::MainWindow:: -workspace( const std::string& wname ) const +workspace( ) const { - auto wIt = this->m_Workspaces.find( wname ); - if( wIt != this->m_Workspaces.end( ) ) - return( wIt->second.GetPointer( ) ); - else - return( NULL ); + return( this->m_Workspace ); } // ------------------------------------------------------------------------- @@ -85,6 +67,9 @@ void cpBaseQtApplication::MainWindow:: setCanvas( cpBaseQtApplication::Pipeline::Canvas* c ) { this->m_Canvas = c; + if( this->m_Canvas != NULL ) + this->m_Canvas->setWorkspace( this->m_Workspace ); + } // ------------------------------------------------------------------------- @@ -131,6 +116,13 @@ void cpBaseQtApplication::MainWindow:: setViewer( cpExtensions::QT::ActorsWidgetInterface* v ) { this->m_Viewer = v; + if( this->m_Viewer != NULL ) + { + auto interactors = this->m_Viewer->GetInteractors( ); + for( auto i : interactors ) + this->m_Workspace->AddInteractor( i ); + + } // fi } // ------------------------------------------------------------------------- @@ -139,7 +131,7 @@ _loadPlugins( const std::string& filename ) { try { - this->m_Plugins->LoadPluginsFile( filename ); + this->m_Loader.Register( filename ); if( this->m_Navigator != NULL ) this->m_Navigator->Update( ); } @@ -179,8 +171,8 @@ _loadPluginsFromPath( const std::string& path ) { try { - this->m_Plugins->LoadPluginsDirectory( path ); - this->m_Plugins->SaveEnvironment( this->m_RunPath ); + this->m_Loader.RegisterFromDirectory( path ); + this->m_Loader.SaveEnvironment( this->m_RunPath ); if( this->m_Navigator != NULL ) this->m_Navigator->Update( ); } @@ -208,126 +200,39 @@ _loadPluginsFromPath( ) // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: -_clearWorkspaces( ) -{ - this->m_Workspaces.clear( ); -} - -// ------------------------------------------------------------------------- -void cpBaseQtApplication::MainWindow:: -_addWorkspace( const std::string& name ) +_clearWorkspace( ) { - auto wIt = this->m_Workspaces.find( name ); - if( wIt == this->m_Workspaces.end( ) ) + this->setWindowTitle( this->m_BaseWindowTitle.c_str( ) ); + this->m_Workspace = TWorkspace::New( ); + if( this->m_Canvas != NULL ) { - if( this->m_SingleWorkspace ) - this->m_Workspaces.clear( ); - this->m_Workspaces[ name ] = TWorkspace::New( ); - this->setWindowTitle( ( this->m_BaseWindowTitle + name ).c_str( ) ); + this->m_Canvas->clear( ); + this->m_Canvas->setWorkspace( this->m_Workspace ); } // fi -} - -// ------------------------------------------------------------------------- -void cpBaseQtApplication::MainWindow:: -_addWorkspace( ) -{ - bool ok; - QString text = - QInputDialog::getText( - this, "Creating a new workspace...", - "New workspace name: ", - QLineEdit::Normal, - "new_workspace", - &ok - ); - if( ok && !text.isEmpty( ) ) - this->_addWorkspace( text.toStdString( ) ); -} - -// ------------------------------------------------------------------------- -void cpBaseQtApplication::MainWindow:: -_saveWorkspace( const std::string& wname, const std::string& fname ) -{ - auto wIt = this->m_Workspaces.find( wname ); - if( wIt != this->m_Workspaces.end( ) ) + if( this->m_Viewer != NULL ) { - try - { - wIt->second->Save( fname ); - this->m_LastSaveFileName = fname; - } - catch( std::exception& err ) - { - QMessageBox::critical( - this, - QMessageBox::tr( "Error saving workspace" ), - QMessageBox::tr( err.what( ) ) - ); - - } // yrt - } - else - QMessageBox::critical( - this, - "Error saving workspace", - ( - std::string( "Workspace \"" ) + wname + - std::string( "\" does not exist." ) - ).c_str( ) - ); + // TODO: this->m_Viewer->clear( ); + auto interactors = this->m_Viewer->GetInteractors( ); + for( auto i : interactors ) + this->m_Workspace->AddInteractor( i ); + + } // fi } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: -_saveWorkspace( const std::string& wname, bool force ) +_saveWorkspace( const std::string& fname ) { - auto wIt = this->m_Workspaces.find( wname ); - if( wIt != this->m_Workspaces.end( ) ) - { - if( this->m_LastSaveFileName == "" || force ) - { - 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" ) ); - dlg.setWindowTitle( - ( - std::string( "Saving \"" ) + wIt->first + std::string( "\"..." ) - ).c_str( ) - ); - if( dlg.exec( ) ) - this->_saveWorkspace( - wIt->first, dlg.selectedFiles( ).begin( )->toStdString( ) - ); - } - else - this->_saveWorkspace( wIt->first, this->m_LastSaveFileName ); - } - else - QMessageBox::critical( - this, - "Error saving workspace", - ( - std::string( "Workspace \"" ) + wname + - std::string( "\" does not exist." ) - ).c_str( ) - ); + this->m_LastSaveFileName = fname; + this->m_Workspace->Save( this->m_LastSaveFileName ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _saveWorkspace( ) { - for( - auto wIt = this->m_Workspaces.begin( ); - wIt != this->m_Workspaces.end( ); - ++wIt - ) + if( this->m_LastSaveFileName == "" ) { QFileDialog dlg( this ); dlg.setFileMode( QFileDialog::AnyFile ); @@ -337,17 +242,12 @@ _saveWorkspace( ) QFileDialog::tr( "Workspace file (*.wxml);;All files (*)" ) ); dlg.setDefaultSuffix( QFileDialog::tr( "wxml" ) ); - dlg.setWindowTitle( - ( - std::string( "Saving \"" ) + wIt->first + std::string( "\"..." ) - ).c_str( ) - ); + dlg.setWindowTitle( "Saving workspace" ); if( dlg.exec( ) ) - this->_saveWorkspace( - wIt->first, dlg.selectedFiles( ).begin( )->toStdString( ) - ); - - } // rof + this->_saveWorkspace( dlg.selectedFiles( ).begin( )->toStdString( ) ); + } + else + this->_saveWorkspace( this->m_LastSaveFileName ); } // ------------------------------------------------------------------------- @@ -356,10 +256,11 @@ _loadWorkspace( const std::string& fname ) { try { - this->_addWorkspace( fname ); - this->m_Workspaces[ fname ]->Load( fname ); + this->_clearWorkspace( ); + this->m_Workspace->Load( fname ); + this->m_LastSaveFileName = ""; if( this->m_Canvas != NULL ) - this->m_Canvas->setWorkspace( this->m_Workspaces[ fname ] ); + this->m_Canvas->setWorkspace( this->m_Workspace ); } catch( std::exception& err ) { @@ -388,4 +289,21 @@ _loadWorkspace( ) this->_loadWorkspace( dlg.selectedFiles( ).begin( )->toStdString( ) ); } +// ------------------------------------------------------------------------- +void cpBaseQtApplication::MainWindow:: +_actorsProperties( ) +{ + auto data = + dynamic_cast< cpExtensions::QT::ActorsWidgetInterface* >( + this->m_Viewer + ); + if( data != NULL ) + { + auto dlg = new cpExtensions::QT::ConfigurationChooser( this ); + dlg->setData( data ); + dlg->exec( ); + + } // fi +} + // eof - $RCSfile$