]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/BaseObjects/ProcessObject.cxx
debug finished
[cpPlugins.git] / lib / cpPlugins / BaseObjects / ProcessObject.cxx
index 7f8533ae25cf7bfaaf9d4d8a7162e0b5472cc007..35b95ff643525bf900a30ed4fe8313eea3fa646a 100644 (file)
@@ -1,8 +1,44 @@
 #include <cpPlugins/BaseObjects/ProcessObject.h>
-#include <cpPlugins/QT/ParametersDialog.h>
-#include <cpExtensions/Utility.h>
 #include <itkProcessObject.h>
 #include <itkExceptionObject.h>
+#include <cpPlugins/Utility.h>
+#include <cpPlugins/BaseObjects/Events.h>
+#include <cpPlugins/QT/ParametersDialog.h>
+
+// -------------------------------------------------------------------------
+void cpPlugins::BaseObjects::ProcessObject::
+PrintExecutionOn( )
+{
+  this->SetPrintExecution( true );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::BaseObjects::ProcessObject::
+PrintExecutionOff( )
+{
+  this->SetPrintExecution( false );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::BaseObjects::ProcessObject::
+GetPrintExecution( ) const
+{
+  return( this->m_PrintExecution );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::BaseObjects::ProcessObject::
+SetPrintExecution( bool v )
+{
+  this->m_PrintExecution = v;
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::BaseObjects::ProcessObject::
+SetPrintExecutionStream( std::ofstream* s )
+{
+  this->m_PrintExecutionStream = s;
+}
 
 // -------------------------------------------------------------------------
 cpPlugins::BaseObjects::Parameters*
@@ -54,6 +90,22 @@ GetOutputsNames( ) const
   return( names );
 }
 
+// -------------------------------------------------------------------------
+bool cpPlugins::BaseObjects::ProcessObject::
+HasInput( const std::string& n ) const
+{
+  auto i = this->m_Inputs.find( n );
+  return( i != this->m_Inputs.end( ) );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::BaseObjects::ProcessObject::
+HasOutput( const std::string& n ) const
+{
+  auto i = this->m_Outputs.find( n );
+  return( i != this->m_Outputs.end( ) );
+}
+
 // -------------------------------------------------------------------------
 unsigned int cpPlugins::BaseObjects::ProcessObject::
 GetNumberOfInputs( ) const
@@ -106,6 +158,23 @@ SetInput( const std::string& n, cpPlugins::BaseObjects::DataObject* o )
   this->AddInput( n, o );
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::BaseObjects::ProcessObject::
+DisconnectInput( const std::string& n, unsigned int id )
+{
+  auto inIt = this->m_Inputs.find( n );
+  if( inIt != this->m_Inputs.end( ) )
+  {
+    auto multi = dynamic_cast< MultipleInputsPort* >( inIt->second );
+    auto single = dynamic_cast< InputPort* >( inIt->second );
+    if( multi != NULL )
+      multi->Delete( id );
+    else if( single != NULL )
+      single->Add( NULL );
+
+  } // fi
+}
+
 // -------------------------------------------------------------------------
 void cpPlugins::BaseObjects::ProcessObject::
 DisconnectInputs( )
@@ -138,16 +207,11 @@ void cpPlugins::BaseObjects::ProcessObject::
 Modified( ) const
 {
   this->Superclass::Modified( );
-  this->m_LastExecutionSpan = -1;
-}
 
-// -------------------------------------------------------------------------
-itk::ModifiedTimeType cpPlugins::BaseObjects::ProcessObject::
-GetMTime( ) const
-{
-  auto params_time = this->m_Parameters.GetMTime( );
-  auto filter_time = this->Superclass::GetMTime( );
-  return( ( params_time > filter_time )? params_time: filter_time );
+  cpPlugins::BaseObjects::Events::Modified evt;
+  evt.Time = this->m_LastExecutionTime;
+  evt.Span = this->m_LastExecutionSpan;
+  this->InvokeEvent( evt );
 }
 
 // -------------------------------------------------------------------------
@@ -155,38 +219,41 @@ void cpPlugins::BaseObjects::ProcessObject::
 Update( )
 {
   // Force upstream updates
-  bool need_to_update = this->m_ExplicitExecution;
-  for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
+  bool update = ( this->m_LastExecutionTime < this->GetMTime( ) );
+  for( auto input : this->m_Inputs )
   {
-    bool iv = i->second->IsValid( );
-    bool ir = i->second->IsRequired( );
-    if( !iv && ir )
-      this->_Error(
-        std::string( "Required input \"" ) + i->first +
-        std::string( "\" is not valid." )
-        );
-    if( iv )
+    for( unsigned int i = 0; i < input.second->Size( ); ++i )
     {
-      unsigned int n = i->second->Size( );
-      for( unsigned int j = 0; j < n; ++j )
+      auto obj = input.second->Get( i );
+      if( obj != NULL )
       {
-        Self* src = i->second->Get( j )->GetSource( );
+        auto src = obj->GetSource( );
         if( src != NULL )
         {
-          need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
           src->Update( );
+          update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
 
         } // fi
+      }
+      else
+      {
+        if( input.second->IsRequired( ) )
+          this->_Error(
+            std::string( "Required input \"" ) + input.first +
+            std::string( "\" in filter \"" ) +
+            this->m_Name +
+            std::string( "\" is not valid." )
+            );
 
-      } // rof
+      } // fi
 
-    } // fi
+    } // rof
 
   } // rof
 
-  // Current update
-  if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
+  if( update || this->m_ExplicitExecution )
   {
+    // Show a message, if needed...
     if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
     {
       *( this->m_PrintExecutionStream )
@@ -198,12 +265,15 @@ Update( )
 
     } // fi
 
-    auto t_start = cpExtensions_CHRONO;
+    // Execute filter's algorithm and keep information about time
+    auto t_start = cpPlugins_CHRONO;
     this->_GenerateData( );
-    auto t_end = cpExtensions_CHRONO;
+    auto t_end = cpPlugins_CHRONO;
+    this->Modified( );
     this->m_LastExecutionSpan = long( t_end - t_start );
     this->m_LastExecutionTime = this->GetMTime( );
 
+    // End the message, if needed...
     if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
     {
       *( this->m_PrintExecutionStream )
@@ -238,8 +308,6 @@ CreateQDialog( )
 void cpPlugins::BaseObjects::ProcessObject::
 AddInteractor( vtkRenderWindowInteractor* i )
 {
-  if( this->m_Interactors.insert( i ).second )
-    this->Modified( );
 }
 
 // -------------------------------------------------------------------------
@@ -261,6 +329,7 @@ ProcessObject( )
     m_PrintExecution( false ),
     m_PrintExecutionStream( &( std::cout ) )
 {
+  this->m_Parameters.SetProcessObject( this );
 }
 
 // -------------------------------------------------------------------------