]> Creatis software - cpPlugins.git/blobdiff - appli/PipelineEditor/PipelineEditor.cxx
Cast image filter added. ROI filter modified.
[cpPlugins.git] / appli / PipelineEditor / PipelineEditor.cxx
index a4cd75e79a82be20ef74ed1d545da061eda89417..32a4546eb595f42aef59ca177847a71b5eda2f1f 100644 (file)
@@ -1,70 +1,44 @@
-#include "PipelineEditor.h"
-#include "ui_PipelineEditor.h"
-
-#include <QMessageBox>
-
-#include <cpPipelineEditor/Editor.h>
-#include <cpExtensions/QT/PropertyWidget.h>
+#include <PipelineEditor.h>
+#include <ui_PipelineEditor.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>
-#include <vtkRenderWindowInteractor.h>
 
 // -------------------------------------------------------------------------
 PipelineEditor::
-PipelineEditor( int argc, char* argv[], QApplication* app, QWidget* parent )
-  : Superclass( argc, argv, app, parent ),
+PipelineEditor( int argc, char* argv[], QWidget* parent )
+  : Superclass( argc, argv, parent ),
     m_UI( new Ui::PipelineEditor )
 {
   // Basic configuration
+  this->m_BaseWindowTitle = "PipelineEditor - ";
   this->m_UI->setupUi( this );
-  this->_Configure(
-    this->m_UI->LoadedPlugins,
-    this->m_UI->Viewer,
-    this->m_UI->Canvas->editor( )
-    );
+  this->setCanvas( this->m_UI->Canvas );
+  this->setNavigator( this->m_UI->Navigator );
+  this->m_UI->Navigator->Update( );
 
-  // Connect actions to slots
-  this->connect(
-    this->m_UI->ButtonLoadPluginsFile, SIGNAL( clicked( ) ),
-    this, SLOT( _InteractiveLoadPlugins( ) )
-    );
-  this->connect(
-    this->m_UI->ButtonLoadPluginsPath, SIGNAL( clicked( ) ),
-    this, SLOT( _InteractiveLoadPluginsFromPath( ) )
-    );
-  this->connect(
-    this->m_UI->ActionOpenWorkspace, SIGNAL( triggered( ) ),
-    this, SLOT( _InteractiveLoadWorkspace( ) )
-    );
-  this->connect(
-    this->m_UI->ActionSaveWorkspace, SIGNAL( triggered( ) ),
-    this, SLOT( _InteractiveSaveWorkspace( ) )
-    );
-  this->connect(
-    this->m_UI->Canvas->editor( ),
-    SIGNAL( execFilter( const std::string& ) ),
-    this,
-    SLOT( _ExecFilter( const std::string& ) )
+  // Connect slots <-> signals
+  cpBaseQtApplication_ConnectAction( actionLoadDirectory, _loadPluginsFromPath );
+  cpBaseQtApplication_ConnectAction( actionLoadLibrary, _loadPlugins );
+  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->Canvas->editor( ),
-    SIGNAL( showFilterOutput( const std::string&, const std::string& ) ),
-    this,
-    SLOT( _ShowFilterOutput( const std::string&, const std::string& ) )
-    );
-  this->connect(
-    this->m_UI->Canvas->editor( ),
-    SIGNAL( hideFilterOutput( const std::string&, const std::string& ) ),
-    this,
-    SLOT( _HideFilterOutput( const std::string&, const std::string& ) )
-    );
-  this->connect(
-    this->m_UI->Canvas->editor( ),
-    SIGNAL( visualPropertiesFilterOutput( const std::string&, const std::string& ) ),
-    this,
-    SLOT( _PropertiesFilterOutput( const std::string&, const std::string& ) )
+    this->m_UI->actionPrintExecutionInformation, SIGNAL( triggered( bool ) ),
+    this, SLOT( _slotPrintExecutionInformation( bool ) )
     );
+
+  // Load command-line given workspace (if any)
+  if( argc > 1 )
+    this->_loadWorkspace( argv[ 1 ] );
 }
 
 // -------------------------------------------------------------------------
@@ -76,122 +50,108 @@ PipelineEditor::
 
 // -------------------------------------------------------------------------
 void PipelineEditor::
-_ShowFilterOutput(
-  const std::string& filter_name, const std::string& output_name
-  )
+_slotView( const std::string& name, bool show )
 {
-  // Update filter, if needed
-  this->_ExecFilter( filter_name );
+  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 ];
 
-  // Get output
-  auto filter = this->m_Workspace.GetFilter( filter_name );
-  if( filter != NULL )
+  // Process data
+  if( show )
   {
-    auto out = filter->GetOutput( output_name );
-    if( out != NULL )
+    try
     {
-      auto id = out->GetVTK< vtkImageData >( );
-      auto md = out->GetVTK< vtkPolyData >( );
-      if( id != NULL )
+      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 )
       {
-        this->_Block( );
-        this->m_UI->Viewer->Clear( );
-        this->m_UI->Viewer->SetMainImage( id );
-        auto actors = this->m_UI->Viewer->GetMainImageActors( );
-        out->ClearVTKActors( );
-        for( auto aIt = actors.begin( ); aIt != actors.end( ); ++aIt )
-          out->AddVTKActor( aIt->first, aIt->second );
-        this->_UnBlock( );
+        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( md != NULL )
+      else if( mesh != NULL )
       {
-        this->_Block( );
-        this->m_UI->Viewer->AddMesh( md );
-        out->AddVTKActor(
-          this->m_UI->Viewer->GetActor( md ),
-          this->m_UI->Viewer->GetRenderer( 3 )
-          );
-        this->_UnBlock( );
+        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
-        QMessageBox::critical(
-          this,
-          QMessageBox::tr( "Error showing data" ),
-          QMessageBox::tr( "No known VTK conversion!" )
-          );
+      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
+    catch( std::exception& err )
+    {
       QMessageBox::critical(
-        this,
+        NULL,
         QMessageBox::tr( "Error showing data" ),
-        QMessageBox::tr( "Unknown port name." )
+        QMessageBox::tr( err.what( ) )
         );
-  }
-  else
-    QMessageBox::critical(
-      this,
-      QMessageBox::tr( "Error showing data" ),
-      QMessageBox::tr( "Unknown filter." )
-      );
+
+    } // yrt
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
 void PipelineEditor::
-_HideFilterOutput(
-  const std::string& filter_name, const std::string& output_name
-  )
+_slotPrintExecutionInformation( bool show )
 {
-  // Get output
-  /* TODO
-     auto filter = this->m_Workspace.GetFilter( filter_name );
-     if( filter != NULL )
-     {
-     auto output = filter->GetOutputData( output_name );
-     if( output != NULL )
-     {
-     std::string data_name = output_name + "@" + filter_name;
-     this->m_UI->Viewer->HideData( data_name );
-
-     } // fi
-
-     } // fi
-  */
+  if( this->m_Workspace.IsNotNull( ) )
+    this->m_Workspace->SetPrintExecution( show );
 }
 
 // -------------------------------------------------------------------------
-void PipelineEditor::
-_PropertiesFilterOutput(
-  const std::string& filter_name, const std::string& output_name
-  )
-{
-  // Get output
-  auto filter = this->m_Workspace.GetFilter( filter_name );
-  if( filter != NULL )
-  {
-    auto output = filter->GetOutputData< vtkPolyData >( output_name );
-    if( output != NULL )
-    {
-      auto actor = this->m_UI->Viewer->GetActor( output );
-      if( actor != NULL )
-      {
-        cpExtensions::QT::PropertyWidget* wdg =
-          new cpExtensions::QT::PropertyWidget( NULL );
-        wdg->SetProp( actor );
-        wdg->SetRenderWindow(
-          this->m_UI->Viewer->GetInteractor( 3 )->GetRenderWindow( )
-          );
-        wdg->show( );
-
-      } // fi
-    }
-    else
-      QMessageBox::critical(
-        this,
-        QMessageBox::tr( "Error showing data" ),
-        QMessageBox::tr( "No known VTK conversion!" )
-        );
-
-  } // fi
-}
+#include <cpBaseQtApplication/MainHelper.h>
+cpBaseQtApplication_Main( PipelineEditor );
+cpBaseQtApplication_MainComplement;
 
 // eof - $RCSfile$