]> Creatis software - cpPlugins.git/blobdiff - lib/cpBaseQtApplication/MainWindow.cxx
..
[cpPlugins.git] / lib / cpBaseQtApplication / MainWindow.cxx
index 9b16236acb94760f09af7f12bf3fb1f8d7e8c6ad..ac8858ed934da7028651f2cb0b9d7e29261a13fa 100644 (file)
@@ -16,7 +16,6 @@ MainWindow(
   )
   : Superclass( parent ),
     m_LastSaveFileName( "" ),
-    m_SingleWorkspace( false ),
     m_BaseWindowTitle( "cpBaseQtApplication" ),
     m_Canvas( NULL ),
     m_Navigator( NULL ),
@@ -34,6 +33,7 @@ MainWindow(
     QMessageBox::critical( this, "Error guessing plugins.", err.what( ) );
 
   } // yrt
+  this->_clearWorkspace( );
 }
 
 // -------------------------------------------------------------------------
@@ -45,25 +45,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 );
 }
 
 // -------------------------------------------------------------------------
@@ -136,9 +128,8 @@ setViewer( cpExtensions::QT::ActorsWidgetInterface* v )
   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
 }
@@ -218,136 +209,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( );
-    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 );
@@ -357,17 +251,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 );
 }
 
 // -------------------------------------------------------------------------
@@ -376,10 +265,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 )
   {