]> Creatis software - cpPlugins.git/blobdiff - appli/PipelineEditor/PipelineEditor.cxx
...
[cpPlugins.git] / appli / PipelineEditor / PipelineEditor.cxx
index 0f2d3fde2d6d5cf1efc60b1010b0f7ce59f01a2e..a83a797febcdae4883e7d8ae6ce06eeeb4c031e0 100644 (file)
@@ -1,70 +1,75 @@
-#include "PipelineEditor.h"
-#include "ui_PipelineEditor.h"
+#include <PipelineEditor.h>
+#include <ui_PipelineEditor.h>
 
-#include <QMessageBox>
-
-#include <cpPipelineEditor/Editor.h>
-#include <cpExtensions/QT/PropertyWidget.h>
-
-#include <vtkImageData.h>
-#include <vtkPolyData.h>
-#include <vtkRenderWindowInteractor.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>
+*/
 
 // -------------------------------------------------------------------------
 PipelineEditor::
-PipelineEditor( int argc, char* argv[], QApplication* app, QWidget* parent )
-  : Superclass( argc, argv, app, parent ),
-    m_UI( new Ui::PipelineEditor )
+PipelineEditor( int argc, char* argv[], QWidget* parent )
+  : Superclass( argc, argv, parent ),
+    m_UI( new Ui::PipelineEditor ),
+    m_ActiveWS( "ws" )
 {
   // Basic configuration
   this->m_UI->setupUi( this );
-  this->_Configure(
-    this->m_UI->LoadedPlugins,
-    this->m_UI->Viewer,
-    this->m_UI->Canvas->editor( )
-    );
-
-  // 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& ) )
-    );
-  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->setCanvas( this->m_UI->Canvas );
+  this->setNavigator( this->m_UI->Navigator );
+  this->m_UI->Navigator->Update( );
+
+  // Connect slots <-> signals
+  cpBaseQtApplication_ConnectAction( actionLoadDirectory, _loadPluginsFromPath );
+  cpBaseQtApplication_ConnectAction( actionLoadLibrary, _loadPlugins );
+
+  // Load command-line given workspace (if any)
+  if( argc > 1 )
+  {
+    this->_loadWorkspace( argv[ 1 ] );
+    this->m_ActiveWS = argv[ 1 ];
+  }
+  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(
+     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
 }
 
 // -------------------------------------------------------------------------
@@ -74,104 +79,215 @@ 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::
-_ShowFilterOutput(
-  const std::string& filter_name, const std::string& output_name
-  )
+_addWorkspace( const std::string& name )
 {
-  // Update filter, if needed
-  this->_ExecFilter( filter_name );
+  /* TODO
+     typedef cpExtensions::QT::ActorsWidgetInterface _TInterface;
 
-  // Get output
-  auto filter = this->m_Workspace.GetFilter( filter_name );
-  if( filter != NULL )
-  {
-    auto id = filter->GetOutputData< vtkImageData >( output_name );
-    auto md = filter->GetOutputData< vtkPolyData >( output_name );
-    if( id != NULL )
-    {
-      this->_Block( );
-      this->m_UI->Viewer->Clear( );
-      this->m_UI->Viewer->SetMainImage( id );
-      this->_UnBlock( );
-    }
-    else if( md != NULL )
-    {
-      this->_Block( );
-      this->m_UI->Viewer->AddMesh( md );
-      this->_UnBlock( );
-    }
-    else
-      QMessageBox::critical(
-        this,
-        QMessageBox::tr( "Error showing data" ),
-        QMessageBox::tr( "No known VTK conversion!" )
-        );
-  }
-  else
-    QMessageBox::critical(
-      this,
-      QMessageBox::tr( "Error showing data" ),
-      QMessageBox::tr( "Unknown filter." )
-      );
+     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::
-_HideFilterOutput(
-  const std::string& filter_name, const std::string& output_name
-  )
+_slotOpenWorkspace( )
 {
-  /*
-  // Get output
-  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 );
+  /* 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
+     } // fi
+     this->m_UI->Canvas->setWorkspace( this->workspace( this->m_ActiveWS ) );
+     this->setWindowTitle(
+     (
+     std::string( "PipelineEditor - " ) +
+     this->m_ActiveWS
+     ).c_str( )
+     );
+  */
+}
 
-  } // fi
+// -------------------------------------------------------------------------
+void PipelineEditor::
+_slotSaveWorkspace( )
+{
+  /* TODO
+     this->_saveWorkspace( this->m_ActiveWS, false );
+     this->setWindowTitle(
+     (
+     std::string( "PipelineEditor - " ) +
+     this->m_LastSaveFileName
+     ).c_str( )
+     );
   */
 }
 
 // -------------------------------------------------------------------------
 void PipelineEditor::
-_PropertiesFilterOutput(
-  const std::string& filter_name, const std::string& output_name
-  )
+_slotSaveWorkspaceAs( )
 {
-  /*
-  // Get output
-  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;
-      auto prop = this->m_UI->Viewer->GetProp( data_name );
-
-      cpExtensions::QT::PropertyWidget* wdg =
-        new cpExtensions::QT::PropertyWidget( NULL );
-      wdg->SetProp( prop );
-      wdg->SetRenderWindow( this->m_UI->Viewer->GetInteractor( 3 )->GetRenderWindow( ) );
-      wdg->show( );
-    }
-    else
-      QMessageBox::critical(
-        this,
-        QMessageBox::tr( "Error showing data" ),
-        QMessageBox::tr( "No known VTK conversion!" )
-        );
-
-  } // fi
+  /* TODO
+     this->_saveWorkspace( this->m_ActiveWS, true );
+     this->setWindowTitle(
+     (
+     std::string( "PipelineEditor - " ) +
+     this->m_LastSaveFileName
+     ).c_str( )
+     );
   */
 }
 
+// -------------------------------------------------------------------------
+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( );
+     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 )
+     {
+     QMessageBox::critical(
+     NULL,
+     QMessageBox::tr( "Error showing data" ),
+     QMessageBox::tr( err.what( ) )
+     );
+
+     } // yrt
+  */
+}
+
+// -------------------------------------------------------------------------
+void PipelineEditor::
+_slotActorsProperties( )
+{
+  /* 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
+  */
+}
+
+// -------------------------------------------------------------------------
+#include <cpBaseQtApplication/MainHelper.h>
+cpBaseQtApplication_Main( PipelineEditor );
+cpBaseQtApplication_MainComplement;
+
 // eof - $RCSfile$