]> Creatis software - cpPlugins.git/blobdiff - appli/cpPipelineEditor/App_cpPipelineEditor.cxx
...
[cpPlugins.git] / appli / cpPipelineEditor / App_cpPipelineEditor.cxx
index 8c0a1559a9319eb9a23f8562f49d290c34414b9b..864d96fb99f7ebaabd075c3baf164caae633f6d3 100644 (file)
@@ -5,18 +5,23 @@
 
 #include <QFileDialog>
 #include <QMessageBox>
+
+#include <vtkImageData.h>
+#include <vtkPolyData.h>
+
 #include <cpPlugins/Interface/Workspace.h>
+#include <cpPlugins/Interface/DataObject.h>
 
 // -------------------------------------------------------------------------
 #define App_cpPipelineEditor_ConnectAction( ACTION )    \
-  QObject::connect(                                     \
+  this->connect(                                        \
     this->m_UI->Action##ACTION, SIGNAL( triggered( ) ), \
     this, SLOT( _Action##ACTION( ) )                    \
     )
 
 // -------------------------------------------------------------------------
 #define App_cpPipelineEditor_ConnectButton( BUTTON )    \
-  QObject::connect(                                     \
+  this->connect(                                        \
     this->m_UI->Button##BUTTON, SIGNAL( clicked( ) ),   \
     this, SLOT( _Button##BUTTON( ) )                    \
     )
@@ -52,12 +57,28 @@ App_cpPipelineEditor( int argc, char* argv[], QWidget* parent )
   this->m_Workspace = new cpPlugins::Interface::Workspace( );
   this->m_Workspace->SetPlugins( this->m_Plugins );
   this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace );
+  this->m_Workspace->AddInteractor( this->m_UI->Viewer->GetInteractor( 0 ) );
+  this->m_Workspace->AddInteractor( this->m_UI->Viewer->GetInteractor( 1 ) );
+  this->m_Workspace->AddInteractor( this->m_UI->Viewer->GetInteractor( 2 ) );
+  this->m_Workspace->AddInteractor( this->m_UI->Viewer->GetInteractor( 3 ) );
 
   // Connect actions to slots
   App_cpPipelineEditor_ConnectButton( LoadPluginsFile );
   App_cpPipelineEditor_ConnectButton( LoadPluginsPath );
   App_cpPipelineEditor_ConnectAction( OpenWorkspace );
   App_cpPipelineEditor_ConnectAction( SaveWorkspace );
+  this->connect(
+    this->m_UI->Canvas->editor( ),
+    SIGNAL( execFilter( const std::string& ) ),
+    this,
+    SLOT( _ExecFilter( const std::string& ) )
+    );
+  this->connect(
+    this->m_UI->Canvas->editor( ),
+    SIGNAL( showFilterOutput( const std::string&, const std::string& ) ),
+    this,
+    SLOT( _ShowFilterOutput( const std::string&, const std::string& ) )
+    );
 }
 
 // -------------------------------------------------------------------------
@@ -252,4 +273,62 @@ _ActionSaveWorkspace( )
       );
 }
 
+
+// -------------------------------------------------------------------------
+void App_cpPipelineEditor::
+_ExecFilter( const std::string& filter_name )
+{
+  if( this->m_Workspace != NULL )
+  {
+    // Update filter, if needed
+    std::string err = this->m_Workspace->Execute( filter_name );
+    if( err != "" )
+      QMessageBox::critical(
+        this,
+        QMessageBox::tr( "Error executing filter" ),
+        QMessageBox::tr( err.c_str( ) )
+        );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void App_cpPipelineEditor::
+_ShowFilterOutput(
+  const std::string& filter_name, const std::string& output_name
+  )
+{
+  typedef cpPlugins::Interface::DataObject _TDataObject;
+
+  // Update filter, if needed
+  this->_ExecFilter( filter_name );
+
+  // Get output
+  auto filter = this->m_Workspace->GetFilter( filter_name );
+  if( filter != NULL )
+  {
+    auto output = filter->GetOutput< _TDataObject >( output_name );
+    if( output != NULL )
+    {
+      std::string data_name = output_name + "@" + filter_name;
+      if( this->m_UI->Viewer->AddData( output, data_name, "" ) )
+      {
+        if( this->m_UI->Viewer->GetNumberOfData( ) > 1 )
+          this->m_UI->Viewer->SetDataColor( data_name, 1, 0, 0 );
+        else
+          this->m_UI->Viewer->SetMainImage( data_name );
+        this->m_UI->Viewer->ShowData( data_name );
+      }
+      else
+        QMessageBox::critical(
+          this,
+          QMessageBox::tr( "Error showing data" ),
+          QMessageBox::tr( "No known VTK conversion!" )
+          );
+
+    } // fi
+
+  } // fi
+}
+
 // eof - $RCSfile$