#include #include #include #include #include #include // ------------------------------------------------------------------------- cpBaseQtApplication::MainWindow:: 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 } // ------------------------------------------------------------------------- cpBaseQtApplication::MainWindow:: ~MainWindow( ) { } // ------------------------------------------------------------------------- cpBaseQtApplication::MainWindow:: TWorkspace* cpBaseQtApplication::MainWindow:: workspace( const std::string& wname ) { auto wIt = this->m_Workspaces.find( wname ); if( wIt != this->m_Workspaces.end( ) ) return( wIt->second.GetPointer( ) ); else return( NULL ); } // ------------------------------------------------------------------------- const cpBaseQtApplication::MainWindow:: TWorkspace* cpBaseQtApplication::MainWindow:: workspace( const std::string& wname ) const { auto wIt = this->m_Workspaces.find( wname ); if( wIt != this->m_Workspaces.end( ) ) return( wIt->second.GetPointer( ) ); else return( NULL ); } // ------------------------------------------------------------------------- cpBaseQtApplication::Pipeline::Canvas* cpBaseQtApplication::MainWindow:: canvas( ) { return( this->m_Canvas ); } // ------------------------------------------------------------------------- const cpBaseQtApplication::Pipeline::Canvas* cpBaseQtApplication::MainWindow:: canvas( ) const { return( this->m_Canvas ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: setCanvas( cpBaseQtApplication::Pipeline::Canvas* c ) { this->m_Canvas = c; } // ------------------------------------------------------------------------- cpBaseQtApplication::Plugins::Navigator* cpBaseQtApplication::MainWindow:: navigator( ) { return( this->m_Navigator ); } // ------------------------------------------------------------------------- const cpBaseQtApplication::Plugins::Navigator* cpBaseQtApplication::MainWindow:: navigator( ) const { return( this->m_Navigator ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: setNavigator( cpBaseQtApplication::Plugins::Navigator* n ) { this->m_Navigator = n; } // ------------------------------------------------------------------------- cpExtensions::QT::ActorsWidgetInterface* cpBaseQtApplication::MainWindow:: viewer( ) { return( this->m_Viewer ); } // ------------------------------------------------------------------------- const cpExtensions::QT::ActorsWidgetInterface* cpBaseQtApplication::MainWindow:: viewer( ) const { return( this->m_Viewer ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: setViewer( cpExtensions::QT::ActorsWidgetInterface* v ) { this->m_Viewer = v; } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _loadPlugins( const std::string& filename ) { try { this->m_Plugins->LoadPluginsFile( filename ); if( this->m_Navigator != NULL ) this->m_Navigator->Update( ); } 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->LoadPluginsDirectory( path ); this->m_Plugins->SaveEnvironment( this->m_RunPath ); if( this->m_Navigator != NULL ) this->m_Navigator->Update( ); } 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:: _clearWorkspaces( ) { this->m_Workspaces.clear( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _addWorkspace( const std::string& name ) { auto wIt = this->m_Workspaces.find( name ); if( wIt == this->m_Workspaces.end( ) ) { if( this->m_SingleWorkspace ) this->m_Workspaces.clear( ); this->m_Workspaces[ name ] = TWorkspace::New( ); this->setWindowTitle( ( this->m_BaseWindowTitle + name ).c_str( ) ); } // 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( ) ) { 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( ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _saveWorkspace( const std::string& wname, bool force ) { 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( ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _saveWorkspace( ) { for( auto wIt = this->m_Workspaces.begin( ); wIt != this->m_Workspaces.end( ); ++wIt ) { 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( ) ); } // rof } // ------------------------------------------------------------------------- void cpBaseQtApplication::MainWindow:: _loadWorkspace( const std::string& fname ) { try { this->_addWorkspace( fname ); this->m_Workspaces[ fname ]->Load( fname ); if( this->m_Canvas != NULL ) this->m_Canvas->setWorkspace( this->m_Workspaces[ fname ] ); } catch( std::exception& err ) { QMessageBox::critical( this, QMessageBox::tr( "Error loading workspace" ), QMessageBox::tr( err.what( ) ) ); } // yrt } // ------------------------------------------------------------------------- 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( ) ); } // eof - $RCSfile$