]> Creatis software - cpPlugins.git/blobdiff - appli/PipelineEditor/PipelineEditor.cxx
Cast image filter added. ROI filter modified.
[cpPlugins.git] / appli / PipelineEditor / PipelineEditor.cxx
index d14d0cfafa44f4d59b2f11be32662f21a5ea07cb..32a4546eb595f42aef59ca177847a71b5eda2f1f 100644 (file)
@@ -1,12 +1,9 @@
 #include <PipelineEditor.h>
 #include <ui_PipelineEditor.h>
 
-/* TODO
-   #include <cpExtensions/QT/SimpleMPRWidget.h>
-   #include <cpExtensions/QT/ImageWidget.h>
-   #include <cpExtensions/QT/ConfigurationChooser.h>
-*/
 #include <cpPlugins/Utility.h>
+#include <cpExtensions/QT/SimpleMPRWidget.h>
+#include <cpExtensions/QT/ImageWidget.h>
 #include <cpExtensions/QT/ActorsWidgetInterface.h>
 #include <vtkImageData.h>
 #include <vtkPolyData.h>
@@ -18,7 +15,6 @@ PipelineEditor( int argc, char* argv[], QWidget* parent )
     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 );
@@ -31,41 +27,18 @@ PipelineEditor( int argc, char* argv[], QWidget* parent )
   cpBaseQtApplication_ConnectAction( actionOpenWorkspace, _loadWorkspace );
   cpBaseQtApplication_ConnectAction( actionSaveWorkspace, _saveWorkspace );
   cpBaseQtApplication_ConnectAction( actionSaveWorkspaceAs, _saveWorkspace );
+  cpBaseQtApplication_ConnectAction( actionActorsProperties, _actorsProperties );
+  this->m_UI->Canvas->connectOutputPortSlot(
+    this, SLOT( _slotView( const std::string&, bool ) )
+    );
+  this->connect(
+    this->m_UI->actionPrintExecutionInformation, SIGNAL( triggered( bool ) ),
+    this, SLOT( _slotPrintExecutionInformation( bool ) )
+    );
 
   // Load command-line given workspace (if any)
-  this->m_ActiveWS = "empty";
   if( argc > 1 )
-  {
     this->_loadWorkspace( argv[ 1 ] );
-    this->m_ActiveWS = argv[ 1 ];
-  }
-  else
-    this->_addWorkspace( this->m_ActiveWS );
-
-  /* TODO
-     this->connect(
-     this->m_UI->actionOpenWorkspace, SIGNAL( triggered( ) ),
-     this, SLOT( _slotOpenWorkspace( ) )
-     );
-     this->connect(
-     this->m_UI->actionSaveWorkspace, SIGNAL( triggered( ) ),
-     this, SLOT( _slotSaveWorkspace( ) )
-     );
-     this->connect(
-     this->m_UI->actionSaveWorkspaceAs, SIGNAL( triggered( ) ),
-     this, SLOT( _slotSaveWorkspaceAs( ) )
-     );
-     this->connect(
-     this->m_UI->actionActorsProperties, SIGNAL( triggered( ) ),
-     this, SLOT( _slotActorsProperties( ) )
-     );
-     this->m_UI->Canvas->connectOutputPortSlot(
-     this, SLOT( _slotView( const std::string&, bool ) )
-     );
-  */
-
-
-  // Associate qt-based objects
 }
 
 // -------------------------------------------------------------------------
@@ -75,33 +48,6 @@ PipelineEditor::
   delete this->m_UI;
 }
 
-// -------------------------------------------------------------------------
-template< class _TWidget >
-std::pair< _TWidget*, bool > PipelineEditor::
-_configureViewer( )
-{
-  /* TODO
-     auto new_viewer = dynamic_cast< _TWidget* >( this->m_UI->Viewer );
-     bool ok = false;
-     if( new_viewer == NULL )
-     {
-     new_viewer = new _TWidget( );
-     delete this->m_UI->Viewer;
-     this->m_UI->Viewer = new_viewer;
-     ok = true;
-
-     auto interactors = new_viewer->GetInteractors( );
-     for( auto w : this->m_Workspaces )
-     for( auto i : interactors )
-     w.second->AddInteractor( i );
-
-     } // fi
-     this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
-     return( std::pair< _TWidget*, bool >( new_viewer, ok ) );
-  */
-  return( std::pair< _TWidget*, bool >( NULL, false ) );
-}
-
 // -------------------------------------------------------------------------
 void PipelineEditor::
 _slotView( const std::string& name, bool show )
@@ -117,124 +63,90 @@ _slotView( const std::string& name, bool show )
   auto output_name = tokens[ 0 ];
 
   // Process data
-  try
+  if( show )
   {
-    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 )
+    try
     {
-      int dim = image->GetDataDimension( );
-      if( dim == 2 )
-        viewer =
-          this->_configureViewer< cpExtensions::QT::ImageWidget >(
-            this->m_UI->Viewer
-            );
-      else if( dim == 3 )
+      auto ws = this->workspace( );
+      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
             );
+
+      } // fi
+      if(
+        dynamic_cast< QWidget* >( viewer ) !=
+        dynamic_cast< QWidget* >( this->m_UI->Viewer ) &&
+        viewer != NULL
+        )
+      {
+        delete this->m_UI->Viewer;
+        this->m_UI->Viewer = dynamic_cast< QWidget* >( viewer );
+        this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
+        this->setViewer( viewer );
+
+      } // fi
+      if( image != NULL )
+      {
+        this->m_Blocker.block( );
+        auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
+        auto imv = dynamic_cast< cpExtensions::QT::ImageWidget* >( viewer );
+        if( mpr != NULL )
+          mpr->SetImage( image, name );
+        else if( imv != NULL )
+          imv->SetImage( image, name );
+        this->m_Blocker.unblock( );
+      }
+      else if( mesh != NULL )
+      {
+        this->m_Blocker.block( );
+        auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
+        if( mpr != NULL )
+          mpr->Add( mesh, name );
+        this->m_Blocker.unblock( );
+
+      } // fi
     }
-    else if( mesh != NULL )
-      viewer =
-        this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
-          this->m_UI->Viewer
-          );
-    if( ( QWidget* )( viewer ) != ( QWidget* )( this->m_UI->Viewer ) )
+    catch( std::exception& err )
     {
-      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( ) )
-      );
-
-  } // yrt
-
-  /* TODO
-     try
-     {
-     if( filter != NULL )
-     {
-     if( image != NULL )
-     {
-     int dim = image->GetDataDimension( );
-     if( dim == 2 )
-     {
-     auto viewer =
-     this->_configureViewer< cpExtensions::QT::ImageWidget >( );
-     this->m_Blocker.block( );
-     viewer.first->SetImage( image, 2, name );
-     viewer.first->ResetCamera( );
-     viewer.first->Render( );
-     this->m_Blocker.unblock( );
-     }
-     else if( dim == 3 )
-     {
-     auto viewer =
-     this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >( );
-     this->m_Blocker.block( );
-     viewer.first->SetImage( image, name );
-     viewer.first->ResetCameras( );
-     viewer.first->Render( );
-     this->m_Blocker.unblock( );
-
-     } // fi
-     }
-     else if( mesh != NULL )
-     {
-     auto viewer =
-     dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >(
-     this->m_UI->Viewer
-     );
-     if( viewer != NULL )
-     {
-     this->m_Blocker.block( );
-     viewer->Add( mesh, name );
-     viewer->Render( );
-     this->m_Blocker.unblock( );
-
-     } // fi
-
-     } // fi
-
-     } // fi
-     }
-     catch( std::exception& err )
-     {
-     } // yrt
-  */
+      QMessageBox::critical(
+        NULL,
+        QMessageBox::tr( "Error showing data" ),
+        QMessageBox::tr( err.what( ) )
+        );
+
+    } // yrt
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
 void PipelineEditor::
-_slotActorsProperties( )
+_slotPrintExecutionInformation( bool show )
 {
-  /* TODO
-     auto data =
-     dynamic_cast< cpExtensions::QT::ActorsWidgetInterface* >(
-     this->m_UI->Viewer
-     );
-     if( data != NULL )
-     {
-     auto dlg = new cpExtensions::QT::ConfigurationChooser( this );
-     dlg->setData( data );
-     dlg->exec( );
-
-     } // fi
-  */
+  if( this->m_Workspace.IsNotNull( ) )
+    this->m_Workspace->SetPrintExecution( show );
 }
 
 // -------------------------------------------------------------------------