+++ /dev/null
-#include <cpBaseQtApplication/MainWindow.h>
-#include <cpBaseQtApplication/Plugins/Navigator.h>
-#include <cpBaseQtApplication/Pipeline/Canvas.h>
-#include <cpExtensions/QT/ConfigurationChooser.h>
-#include <cpExtensions/QT/ActorsWidgetInterface.h>
-
-#include <QDir>
-#include <QFileDialog>
-#include <QInputDialog>
-
-// -------------------------------------------------------------------------
-cpBaseQtApplication::MainWindow::
-MainWindow( int argc, char* argv[], QWidget* parent )
- : Superclass( parent ),
- m_LastSaveFileName( "" ),
- m_BaseWindowTitle( "cpBaseQtApplication" ),
- m_Canvas( NULL ),
- m_Navigator( NULL ),
- m_Viewer( NULL )
-{
- this->m_RunPath = QDir( "." ).canonicalPath( ).toStdString( );
- this->m_Loader.GuessEnvironment( this->m_RunPath );
- this->m_Loader.SaveEnvironment( this->m_RunPath );
- this->_clearWorkspace( );
-}
-
-// -------------------------------------------------------------------------
-cpBaseQtApplication::MainWindow::
-~MainWindow( )
-{
-}
-
-// -------------------------------------------------------------------------
-cpBaseQtApplication::MainWindow::
-TWorkspace* cpBaseQtApplication::MainWindow::
-workspace( )
-{
- return( this->m_Workspace );
-}
-
-// -------------------------------------------------------------------------
-const cpBaseQtApplication::MainWindow::
-TWorkspace* cpBaseQtApplication::MainWindow::
-workspace( ) const
-{
- return( this->m_Workspace );
-}
-
-// -------------------------------------------------------------------------
-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;
- if( this->m_Canvas != NULL )
- this->m_Canvas->setWorkspace( this->m_Workspace );
-
-}
-
-// -------------------------------------------------------------------------
-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;
- if( this->m_Viewer != NULL )
- {
- auto interactors = this->m_Viewer->GetInteractors( );
- for( auto i : interactors )
- this->m_Workspace->AddInteractor( i );
-
- } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpBaseQtApplication::MainWindow::
-_loadPlugins( const std::string& filename )
-{
- try
- {
- this->m_Loader.Register( 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_Loader.RegisterFromDirectory( path );
- this->m_Loader.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::
-_clearWorkspace( )
-{
- this->setWindowTitle( this->m_BaseWindowTitle.c_str( ) );
- this->m_Workspace = TWorkspace::New( );
- if( this->m_Canvas != NULL )
- {
- this->m_Canvas->clear( );
- this->m_Canvas->setWorkspace( this->m_Workspace );
-
- } // fi
- if( this->m_Viewer != NULL )
- {
- // 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& fname )
-{
- this->m_LastSaveFileName = fname;
- this->m_Workspace->Save( this->m_LastSaveFileName );
-}
-
-// -------------------------------------------------------------------------
-void cpBaseQtApplication::MainWindow::
-_saveWorkspace( )
-{
- if( this->m_LastSaveFileName == "" )
- {
- 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( "Saving workspace" );
- if( dlg.exec( ) )
- this->_saveWorkspace( dlg.selectedFiles( ).begin( )->toStdString( ) );
- }
- else
- this->_saveWorkspace( this->m_LastSaveFileName );
-}
-
-// -------------------------------------------------------------------------
-void cpBaseQtApplication::MainWindow::
-_loadWorkspace( const std::string& fname )
-{
- try
- {
- this->_clearWorkspace( );
- this->m_Workspace->Load( fname );
- this->m_LastSaveFileName = "";
- if( this->m_Canvas != NULL )
- this->m_Canvas->setWorkspace( this->m_Workspace );
- }
- 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( ) );
-}
-
-// -------------------------------------------------------------------------
-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$