]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Tue, 22 Nov 2016 00:16:48 +0000 (19:16 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Tue, 22 Nov 2016 00:16:48 +0000 (19:16 -0500)
appli/PipelineEditor/PipelineEditor.cxx
appli/PipelineEditor/PipelineEditor.h
lib/cpBaseQtApplication/MainWindow.cxx
lib/cpBaseQtApplication/MainWindow.h

index a83a797febcdae4883e7d8ae6ce06eeeb4c031e0..d14d0cfafa44f4d59b2f11be32662f21a5ea07cb 100644 (file)
@@ -2,23 +2,24 @@
 #include <ui_PipelineEditor.h>
 
 /* TODO
-   #include <cpPlugins/Utility.h>
    #include <cpExtensions/QT/SimpleMPRWidget.h>
    #include <cpExtensions/QT/ImageWidget.h>
    #include <cpExtensions/QT/ConfigurationChooser.h>
-   #include <cpExtensions/QT/ActorsWidgetInterface.h>
-   #include <vtkImageData.h>
-   #include <vtkPolyData.h>
 */
+#include <cpPlugins/Utility.h>
+#include <cpExtensions/QT/ActorsWidgetInterface.h>
+#include <vtkImageData.h>
+#include <vtkPolyData.h>
 
 // -------------------------------------------------------------------------
 PipelineEditor::
 PipelineEditor( int argc, char* argv[], QWidget* parent )
   : Superclass( argc, argv, parent ),
-    m_UI( new Ui::PipelineEditor ),
-    m_ActiveWS( "ws" )
+    m_UI( new Ui::PipelineEditor )
 {
   // Basic configuration
+  this->m_SingleWorkspace = true;
+  this->m_BaseWindowTitle = "PipelineEditor - ";
   this->m_UI->setupUi( this );
   this->setCanvas( this->m_UI->Canvas );
   this->setNavigator( this->m_UI->Navigator );
@@ -27,8 +28,12 @@ PipelineEditor( int argc, char* argv[], QWidget* parent )
   // Connect slots <-> signals
   cpBaseQtApplication_ConnectAction( actionLoadDirectory, _loadPluginsFromPath );
   cpBaseQtApplication_ConnectAction( actionLoadLibrary, _loadPlugins );
+  cpBaseQtApplication_ConnectAction( actionOpenWorkspace, _loadWorkspace );
+  cpBaseQtApplication_ConnectAction( actionSaveWorkspace, _saveWorkspace );
+  cpBaseQtApplication_ConnectAction( actionSaveWorkspaceAs, _saveWorkspace );
 
   // Load command-line given workspace (if any)
+  this->m_ActiveWS = "empty";
   if( argc > 1 )
   {
     this->_loadWorkspace( argv[ 1 ] );
@@ -36,15 +41,6 @@ PipelineEditor( int argc, char* argv[], QWidget* parent )
   }
   else
     this->_addWorkspace( this->m_ActiveWS );
-  /* TODO
-     this->m_UI->Canvas->setWorkspace( this->workspace( this->m_ActiveWS ) );
-     this->setWindowTitle(
-     (
-     std::string( "PipelineEditor - " ) +
-     this->m_ActiveWS
-     ).c_str( )
-     );
-  */
 
   /* TODO
      this->connect(
@@ -108,108 +104,70 @@ _configureViewer( )
 
 // -------------------------------------------------------------------------
 void PipelineEditor::
-_addWorkspace( const std::string& name )
-{
-  /* TODO
-     typedef cpExtensions::QT::ActorsWidgetInterface _TInterface;
-
-     this->Superclass::_addWorkspace( name );
-     auto ws = this->m_Workspaces.find( name );
-     if( ws != this->m_Workspaces.end( ) )
-     {
-     ws->second->PrintExecutionOn( );
-     auto wdg = dynamic_cast< _TInterface* >( this->m_UI->Viewer );
-     if( wdg == NULL )
-     return;
-     auto interactors = wdg->GetInteractors( );
-     for( auto i : interactors )
-     ws->second->AddInteractor( i );
-
-     } // fi
-  */
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::
-_slotOpenWorkspace( )
-{
-  /* TODO
-     this->m_LastSaveFileName = "";
-     this->_loadWorkspace( );
-     if( this->m_Workspaces.size( ) == 2 )
-     {
-     auto wIt = this->m_Workspaces.find( this->m_ActiveWS );
-     this->m_Workspaces.erase( wIt );
-     this->m_ActiveWS = this->m_Workspaces.begin( )->first;
-     }
-     else if( this->m_Workspaces.size( ) == 1 )
-     {
-     this->m_ActiveWS = this->m_Workspaces.begin( )->first;
-     }
-     else
-     {
-     this->m_ActiveWS = "ws";
-     this->_addWorkspace( this->m_ActiveWS );
-
-     } // fi
-     this->m_UI->Canvas->setWorkspace( this->workspace( this->m_ActiveWS ) );
-     this->setWindowTitle(
-     (
-     std::string( "PipelineEditor - " ) +
-     this->m_ActiveWS
-     ).c_str( )
-     );
-  */
-}
-
-// -------------------------------------------------------------------------
-void PipelineEditor::
-_slotSaveWorkspace( )
+_slotView( const std::string& name, bool show )
 {
-  /* TODO
-     this->_saveWorkspace( this->m_ActiveWS, false );
-     this->setWindowTitle(
-     (
-     std::string( "PipelineEditor - " ) +
-     this->m_LastSaveFileName
-     ).c_str( )
-     );
-  */
-}
+  typedef cpExtensions::QT::ActorsWidgetInterface _TViewer;
+
+  // Get filter parameters
+  std::vector< std::string > tokens;
+  cpPlugins::Tokenize( tokens, name, "@" );
+  if( tokens.size( ) != 2 )
+    return;
+  auto filter_name = tokens[ 1 ];
+  auto output_name = tokens[ 0 ];
+
+  // Process data
+  try
+  {
+    auto ws = this->workspace( this->m_ActiveWS );
+    auto filter = ws->GetFilter( filter_name );
+    cpBaseQtApplication_Execute( filter->Update( ) );
+    auto image = filter->GetOutputData< vtkImageData >( output_name );
+    auto mesh = filter->GetOutputData< vtkPolyData >( output_name );
+    _TViewer* viewer = NULL;
+    if( image != NULL )
+    {
+      int dim = image->GetDataDimension( );
+      if( dim == 2 )
+        viewer =
+          this->_configureViewer< cpExtensions::QT::ImageWidget >(
+            this->m_UI->Viewer
+            );
+      else if( dim == 3 )
+        viewer =
+          this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
+            this->m_UI->Viewer
+            );
+    }
+    else if( mesh != NULL )
+      viewer =
+        this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
+          this->m_UI->Viewer
+          );
+    if( ( QWidget* )( viewer ) != ( QWidget* )( this->m_UI->Viewer ) )
+    {
+      delete this->m_UI->Viewer;
+      this->m_UI->Viewer = viewer;
+      this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
+      this->setViewer( viewer );
+
+    } // fi
+  }
+  catch( std::exception& err )
+  {
+    QMessageBox::critical(
+      NULL,
+      QMessageBox::tr( "Error showing data" ),
+      QMessageBox::tr( err.what( ) )
+      );
 
-// -------------------------------------------------------------------------
-void PipelineEditor::
-_slotSaveWorkspaceAs( )
-{
-  /* TODO
-     this->_saveWorkspace( this->m_ActiveWS, true );
-     this->setWindowTitle(
-     (
-     std::string( "PipelineEditor - " ) +
-     this->m_LastSaveFileName
-     ).c_str( )
-     );
-  */
-}
+  } // yrt
 
-// -------------------------------------------------------------------------
-void PipelineEditor::
-_slotView( const std::string& name, bool show )
-{
   /* TODO
-     std::vector< std::string > tokens;
-     cpPlugins::Tokenize( tokens, name, "@" );
-     if( tokens.size( ) != 2 )
-     return;
      try
      {
-     auto ws = this->workspace( this->m_ActiveWS );
-     auto filter = ws->GetFilter( tokens[ 1 ] );
      if( filter != NULL )
      {
-     cpBaseQtApplication_Execute( filter->Update( ) );
-     auto image = filter->GetOutputData< vtkImageData >( tokens[ 0 ] );
-     auto mesh = filter->GetOutputData< vtkPolyData >( tokens[ 0 ] );
      if( image != NULL )
      {
      int dim = image->GetDataDimension( );
@@ -256,12 +214,6 @@ _slotView( const std::string& name, bool show )
      }
      catch( std::exception& err )
      {
-     QMessageBox::critical(
-     NULL,
-     QMessageBox::tr( "Error showing data" ),
-     QMessageBox::tr( err.what( ) )
-     );
-
      } // yrt
   */
 }
index 1ab1c61c012cfc725e7aff9e8f3320f80fbdcc8d..eb2c3337529a7a4ebf60ab31df3672d26bd2450e 100644 (file)
@@ -28,10 +28,6 @@ protected:
   inline std::pair< _TWidget*, bool > _configureViewer( );
 
 protected slots:
-  virtual void _addWorkspace( const std::string& name ) cpPlugins_OVERRIDE;
-  void _slotOpenWorkspace( );
-  void _slotSaveWorkspace( );
-  void _slotSaveWorkspaceAs( );
   void _slotView( const std::string& name, bool show );
   void _slotActorsProperties( );
 
index 0b67e49f5df7d297b19f8fd05e640b3613f321fd..bfe8b5b9d4b5b9943b3e36080dbd4b7c543529a9 100644 (file)
@@ -1,5 +1,6 @@
 #include <cpBaseQtApplication/MainWindow.h>
 #include <cpBaseQtApplication/Plugins/Navigator.h>
+#include <cpBaseQtApplication/Pipeline/Canvas.h>
 
 #include <QDir>
 #include <QFileDialog>
@@ -13,6 +14,8 @@ MainWindow(
   )
   : Superclass( parent ),
     m_LastSaveFileName( "" ),
+    m_SingleWorkspace( false ),
+    m_BaseWindowTitle( "cpBaseQtApplication" ),
     m_Canvas( NULL ),
     m_Navigator( NULL ),
     m_Viewer( NULL )
@@ -216,7 +219,13 @@ _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
 }
 
 // -------------------------------------------------------------------------
@@ -349,6 +358,8 @@ _loadWorkspace( const std::string& fname )
   {
     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 )
   {
index a8bf7bc205f15670559c79159336e4fca86180f7..b62d30f62fe388343bb95ef6018257cdc57f0073 100644 (file)
@@ -166,6 +166,9 @@ namespace cpBaseQtApplication
     std::string       m_LastSaveFileName;
     std::map< std::string, TWorkspace::Pointer > m_Workspaces;
 
+    bool        m_SingleWorkspace;
+    std::string m_BaseWindowTitle;
+
     Pipeline::Canvas*                        m_Canvas;
     Plugins::Navigator*                      m_Navigator;
     cpExtensions::QT::ActorsWidgetInterface* m_Viewer;