]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/ProcessObject.cxx
...
[cpPlugins.git] / lib / cpPlugins / Interface / ProcessObject.cxx
index 79fc2ab7f84880c3cdb59bdd002d38e8abc94f34..db873e9d4f854724c7606a79af4e4f00a705c5b6 100644 (file)
@@ -1,39 +1,41 @@
 #include <cpPlugins/Interface/ProcessObject.h>
-#include <cpPlugins/Interface/DataObject.h>
 
-// -------------------------------------------------------------------------
-cpPlugins::Interface::ProcessObject::
-ProcessObject( )
-  : Superclass( )
-{
-}
+#ifdef cpPlugins_Interface_QT4
+#include <QApplication>
+#include <cpPlugins/Interface/ParametersQtDialog.h>
+#endif // cpPlugins_Interface_QT4
 
-// -------------------------------------------------------------------------
-cpPlugins::Interface::ProcessObject::
-~ProcessObject( )
-{
-}
+#include <vtkRenderWindowInteractor.h>
 
 // -------------------------------------------------------------------------
-std::string cpPlugins::Interface::ProcessObject::
-GetClassName( ) const
+void cpPlugins::Interface::ProcessObject::
+Modified( ) const
 {
-  return( "cpPlugins::Interface::ProcessObject" );
+  if( this->m_ITKObject.IsNotNull( ) )
+    this->m_ITKObject->Modified( );
+  if( this->m_VTKObject.GetPointer( ) != NULL )
+    this->m_VTKObject->Modified( );
+  this->Superclass::Modified( );
 }
 
 // -------------------------------------------------------------------------
-const cpPlugins::Interface::ProcessObject::
-TParameters& cpPlugins::Interface::ProcessObject::
-GetDefaultParameters( ) const
+void cpPlugins::Interface::ProcessObject::
+GetInputsNames( std::set< std::string >& names ) const
 {
-  return( this->m_DefaultParameters );
+  names.clear( );
+  auto dIt = this->m_Inputs.begin( );
+  for( ; dIt != this->m_Inputs.end( ); ++dIt )
+    names.insert( dIt->first );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::ProcessObject::
-SetParameters( const TParameters& params )
+GetOutputsNames( std::set< std::string >& names ) const
 {
-  this->m_Parameters = params;
+  names.clear( );
+  auto dIt = this->m_Outputs.begin( );
+  for( ; dIt != this->m_Outputs.end( ); ++dIt )
+    names.insert( dIt->first );
 }
 
 // -------------------------------------------------------------------------
@@ -51,76 +53,161 @@ GetNumberOfOutputs( ) const
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::Interface::ProcessObject::
-SetNumberOfInputs( unsigned int n )
+bool cpPlugins::Interface::ProcessObject::
+SetOutputObjectName(
+  const std::string& new_object_name, const std::string& output_name
+  )
 {
-  this->m_Inputs.clear( );
-  this->m_Inputs.resize( n, NULL );
+  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::
-SetNumberOfOutputs( unsigned int n )
+SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj )
 {
-  this->m_Outputs.clear( );
-  this->m_Outputs.resize( n );
+  _TDataContainer::iterator i = this->m_Inputs.find( id );
+  if( i != this->m_Inputs.end( ) )
+  {
+    i->second = dobj;
+    this->Modified( );
 
-  // Sync outputs with this source
-  for( unsigned int odx = 0; odx < this->m_Outputs.size( ); ++odx )
-    this->m_Outputs[ odx ].SetSource( this );
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Interface::ProcessObject::
+Update( )
+{
+  std::string r = "";
+
+  // Force upstream updates
+  _TDataContainer::iterator i = this->m_Inputs.begin( );
+  for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
+  {
+    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 );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::ProcessObject::
-SetInput(
-  unsigned int idx, const cpPlugins::Interface::DataObject* dobj
-  )
+DisconnectOutputs( )
 {
-  if( idx < this->m_Inputs.size( ) )
-    this->m_Inputs[ idx ] = dobj;
+  _TDataContainer::iterator i = this->m_Outputs.begin( );
+  for( ; i != this->m_Outputs.end( ); ++i )
+    if( i->second.IsNotNull( ) )
+      i->second->DisconnectPipeline( );
 }
 
 // -------------------------------------------------------------------------
-cpPlugins::Interface::DataObject* cpPlugins::Interface::ProcessObject::
-GetOutput( unsigned int idx )
+void cpPlugins::Interface::ProcessObject::
+AddInteractor( vtkRenderWindowInteractor* interactor )
 {
-  if( idx < this->m_Outputs.size( ) )
-    return( &( this->m_Outputs[ idx ] ) );
-  else
-    return( NULL );
+#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 );
 }
 
 // -------------------------------------------------------------------------
-std::string cpPlugins::Interface::ProcessObject::
-Update( )
+cpPlugins::Interface::ProcessObject::
+DialogResult cpPlugins::Interface::ProcessObject::
+ExecConfigurationDialog( QWidget* parent )
 {
-  // Force upstream updates
-  for( unsigned int idx = 0; idx < this->m_Inputs.size( ); ++idx )
-    this->m_Inputs[ idx ]->GetSource( )->Update( );
+  DialogResult r = Self::DialogResult_Cancel;
+
+#ifdef cpPlugins_Interface_QT4
+
+  if( QApplication::instance( ) != NULL )
+  {
+    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 );
+
+    if( this->m_ParametersDialog->exec( ) == 1 )
+      r = Self::DialogResult_NoModal;
+    else
+      r = Self::DialogResult_Cancel;
+  }
+  else
+    r = Self::DialogResult_Cancel;
 
-  // Current update
-  std::string ret = this->_GenerateData( );
+#endif // cpPlugins_Interface_QT4
 
-  // Return error description, if any
-  return( ret );
+  return( r );
 }
 
 // -------------------------------------------------------------------------
-itk::DataObject* cpPlugins::Interface::ProcessObject::
-_GetInput( unsigned int idx )
+cpPlugins::Interface::ProcessObject::
+ProcessObject( )
+  : Superclass( ),
+    m_ITKObject( NULL ),
+    m_VTKObject( NULL ),
+    m_ParametersDialog( NULL ),
+    m_Plugins( NULL )
 {
-  if( idx < this->m_Inputs.size( ) )
-    return( this->m_Inputs[ idx ]->GetDataObject( ) );
-  else
-    return( NULL );
+  this->m_Parameters = TParameters::New( );
+  this->m_Parameters->SetProcessObject( this );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::ProcessObject::
+~ProcessObject( )
+{
+  if( this->m_ParametersDialog != NULL )
+    delete this->m_ParametersDialog;
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::ProcessObject::
-_SetOutput( unsigned int idx, itk::DataObject* dobj )
+_AddInput( const std::string& name )
 {
-  if( idx < this->m_Outputs.size( ) )
-    this->m_Outputs[ idx ].SetDataObject( dobj );
+  this->m_Inputs[ name ] = NULL;
+  this->Modified( );
 }
 
+// -------------------------------------------------------------------------
+CPPLUGINS_PROVIDER_SOURCE( cpPlugins::Interface::ProcessObject, 1, 1 );
+
 // eof - $RCSfile$