]> Creatis software - cpPlugins.git/blobdiff - lib/cpBaseQtApplication/MainWindow.cxx
Cast image filter added. ROI filter modified.
[cpPlugins.git] / lib / cpBaseQtApplication / MainWindow.cxx
index 0b67e49f5df7d297b19f8fd05e640b3613f321fd..1bdca767b08be6428f5c5336d663c35d78a176d9 100644 (file)
@@ -1,5 +1,8 @@
 #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>
@@ -13,6 +16,7 @@ MainWindow(
   )
   : Superclass( parent ),
     m_LastSaveFileName( "" ),
+    m_BaseWindowTitle( "cpBaseQtApplication" ),
     m_Canvas( NULL ),
     m_Navigator( NULL ),
     m_Viewer( NULL )
@@ -29,6 +33,7 @@ MainWindow(
     QMessageBox::critical( this, "Error guessing plugins.", err.what( ) );
 
   } // yrt
+  this->_clearWorkspace( );
 }
 
 // -------------------------------------------------------------------------
@@ -40,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 );
 }
 
 // -------------------------------------------------------------------------
@@ -82,6 +79,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 );
+
 }
 
 // -------------------------------------------------------------------------
@@ -128,6 +128,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
 }
 
 // -------------------------------------------------------------------------
@@ -205,120 +212,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->m_Workspaces[ name ] = TWorkspace::New( );
-}
-
-// -------------------------------------------------------------------------
-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( ) );
-}
+  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 );
 
-// -------------------------------------------------------------------------
-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( ) )
+  } // fi
+  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 );
@@ -328,17 +254,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 );
 }
 
 // -------------------------------------------------------------------------
@@ -347,8 +268,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_Workspace );
   }
   catch( std::exception& err )
   {
@@ -377,4 +301,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$