)
: Superclass( parent ),
m_LastSaveFileName( "" ),
- m_SingleWorkspace( false ),
m_BaseWindowTitle( "cpBaseQtApplication" ),
m_Canvas( NULL ),
m_Navigator( NULL ),
QMessageBox::critical( this, "Error guessing plugins.", err.what( ) );
} // yrt
+ this->_clearWorkspace( );
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
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 );
}
// -------------------------------------------------------------------------
if( this->m_Viewer != NULL )
{
auto interactors = this->m_Viewer->GetInteractors( );
- for( auto wIt : this->m_Workspaces )
- for( auto i : interactors )
- wIt.second->AddInteractor( i );
+ for( auto i : interactors )
+ this->m_Workspace->AddInteractor( i );
} // fi
}
// -------------------------------------------------------------------------
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( );
- if( this->m_Canvas != NULL )
- this->m_Canvas->setWorkspace( this->m_Workspaces[ name ] );
- if( this->m_Viewer != NULL )
- {
- auto interactors = this->m_Viewer->GetInteractors( );
- auto wIt = this->m_Workspaces.find( name );
- for( auto i : interactors )
- wIt->second->AddInteractor( i );
-
- } // fi
- 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 );
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 );
}
// -------------------------------------------------------------------------
{
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 )
{