]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/ProcessObject.cxx
...
[cpPlugins.git] / lib / cpPlugins / Interface / ProcessObject.cxx
index a4a123755f80e6afcee30170693bc1770c7e5bb0..db873e9d4f854724c7606a79af4e4f00a705c5b6 100644 (file)
@@ -1,9 +1,12 @@
 #include <cpPlugins/Interface/ProcessObject.h>
 
 #ifdef cpPlugins_Interface_QT4
+#include <QApplication>
 #include <cpPlugins/Interface/ParametersQtDialog.h>
 #endif // cpPlugins_Interface_QT4
 
+#include <vtkRenderWindowInteractor.h>
+
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::ProcessObject::
 Modified( ) const
@@ -16,19 +19,23 @@ Modified( ) const
 }
 
 // -------------------------------------------------------------------------
-cpPlugins::Interface::ProcessObject::
-TParameters* cpPlugins::Interface::ProcessObject::
-GetParameters( )
+void cpPlugins::Interface::ProcessObject::
+GetInputsNames( std::set< std::string >& names ) const
 {
-  return( this->m_Parameters.GetPointer( ) );
+  names.clear( );
+  auto dIt = this->m_Inputs.begin( );
+  for( ; dIt != this->m_Inputs.end( ); ++dIt )
+    names.insert( dIt->first );
 }
 
 // -------------------------------------------------------------------------
-const cpPlugins::Interface::ProcessObject::
-TParameters* cpPlugins::Interface::ProcessObject::
-GetParameters( ) const
+void cpPlugins::Interface::ProcessObject::
+GetOutputsNames( std::set< std::string >& names ) const
 {
-  return( this->m_Parameters.GetPointer( ) );
+  names.clear( );
+  auto dIt = this->m_Outputs.begin( );
+  for( ; dIt != this->m_Outputs.end( ); ++dIt )
+    names.insert( dIt->first );
 }
 
 // -------------------------------------------------------------------------
@@ -45,6 +52,23 @@ GetNumberOfOutputs( ) const
   return( this->m_Outputs.size( ) );
 }
 
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::ProcessObject::
+SetOutputObjectName(
+  const std::string& new_object_name, const std::string& output_name
+  )
+{
+  auto oIt = this->m_Outputs.find( output_name );
+  if( oIt != this->m_Outputs.end( ) )
+  {
+    this->m_OutputObjectsNames[ output_name ] = new_object_name;
+    this->Modified( );
+    return( true );
+  }
+  else
+    return( false );
+}
+
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::ProcessObject::
 SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj )
@@ -68,16 +92,31 @@ Update( )
   _TDataContainer::iterator i = this->m_Inputs.begin( );
   for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
   {
-    Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
-    if( src != NULL )
-      r = src->Update( );
-
+    if( i->second.IsNotNull( ) )
+    {
+      Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
+      if( src != NULL )
+        r = src->Update( );
+    }
+    else
+      r = "cpPlugins::Interface::ProcessObject: No input connected.";
+    
   } // rof
 
   // Current update
   if( r == "" )
     r = this->_GenerateData( );
 
+  // Configure output names
+  auto oIt = this->m_Outputs.begin( );
+  for( ; oIt != this->m_Outputs.end( ); ++oIt )
+  {
+    auto nIt = this->m_OutputObjectsNames.find( oIt->first );
+    if( nIt != this->m_OutputObjectsNames.end( ) )
+      oIt->second->SetName( nIt->second );
+
+  } // rof
+
   // Return error description, if any
   return( r );
 }
@@ -93,39 +132,46 @@ DisconnectOutputs( )
 }
 
 // -------------------------------------------------------------------------
-bool cpPlugins::Interface::ProcessObject::
+void cpPlugins::Interface::ProcessObject::
+AddInteractor( vtkRenderWindowInteractor* interactor )
+{
+#ifdef cpPlugins_Interface_QT4
+  if( this->m_ParametersDialog == NULL )
+    this->m_ParametersDialog = new ParametersQtDialog( );
+  this->m_ParametersDialog->addInteractor( interactor );
+#endif // cpPlugins_Interface_QT4
+  this->m_Interactors.insert( interactor );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::ProcessObject::
+DialogResult cpPlugins::Interface::ProcessObject::
 ExecConfigurationDialog( QWidget* parent )
 {
-  bool r = false;
+  DialogResult r = Self::DialogResult_Cancel;
 
 #ifdef cpPlugins_Interface_QT4
 
-  if( this->m_ParametersDialog == NULL )
+  if( QApplication::instance( ) != NULL )
   {
-    this->m_ParametersDialog = new ParametersQtDialog( parent );
-    this->m_ParametersDialog->setTitle(
-      this->GetClassName( ) + std::string( " basic configuration" )
-      );
+    if( this->m_ParametersDialog == NULL )
+      this->m_ParametersDialog = new ParametersQtDialog( );
+    /* TODO
+       this->m_ParametersDialog->setTitle(
+       this->GetClassName( ) + std::string( " basic configuration" )
+       );
+    */
+
+    this->m_ParametersDialog->setParent( NULL );
     this->m_ParametersDialog->setParameters( this->m_Parameters );
 
-  } // fi
-
-  std::cout << "ok" << std::endl;
-  if( !( this->m_ParametersDialog->IsModal( ) ) )
-  {
-    this->m_ParametersDialog->show( );
-    r = true;
+    if( this->m_ParametersDialog->exec( ) == 1 )
+      r = Self::DialogResult_NoModal;
+    else
+      r = Self::DialogResult_Cancel;
   }
   else
-    r = ( this->m_ParametersDialog->exec( ) == 1 );
-  /*
-    r = cpPlugins::Interface::ParametersQtDialog(
-    this->m_Parameters,
-    this->GetClassName( ) + std::string( " basic configuration" ),
-    parent
-    );
-    if( r )
-  */
+    r = Self::DialogResult_Cancel;
 
 #endif // cpPlugins_Interface_QT4
 
@@ -138,16 +184,18 @@ ProcessObject( )
   : Superclass( ),
     m_ITKObject( NULL ),
     m_VTKObject( NULL ),
-    m_ParametersDialog( NULL )
+    m_ParametersDialog( NULL ),
+    m_Plugins( NULL )
 {
   this->m_Parameters = TParameters::New( );
+  this->m_Parameters->SetProcessObject( this );
 }
 
 // -------------------------------------------------------------------------
 cpPlugins::Interface::ProcessObject::
 ~ProcessObject( )
 {
-  if( this->m_ParametersDialog == NULL )
+  if( this->m_ParametersDialog != NULL )
     delete this->m_ParametersDialog;
 }
 
@@ -159,4 +207,7 @@ _AddInput( const std::string& name )
   this->Modified( );
 }
 
+// -------------------------------------------------------------------------
+CPPLUGINS_PROVIDER_SOURCE( cpPlugins::Interface::ProcessObject, 1, 1 );
+
 // eof - $RCSfile$