]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/ProcessObject.cxx
...
[cpPlugins.git] / lib / cpPlugins / ProcessObject.cxx
index aa910648c24ca0def0bfbb00174ad68df66543b3..02beb8849b774a75e8370dad59a2fe22f4c3da57 100644 (file)
@@ -1,7 +1,8 @@
 #include <cpPlugins/ProcessObject.h>
 #include <cpPlugins/ParametersQtDialog.h>
 #include <itkProcessObject.h>
-
+#include <itkExceptionObject.h>
+#include <iostream>
 // -------------------------------------------------------------------------
 cpPlugins::Parameters* cpPlugins::ProcessObject::
 GetParameters( )
@@ -189,6 +190,14 @@ Disconnect( )
   this->DisconnectOutputs( );
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::ProcessObject::
+Modified( ) const
+{
+  this->Superclass::Modified( );
+  this->m_LastExecutionSpan = -1;
+}
+
 // -------------------------------------------------------------------------
 itk::ModifiedTimeType cpPlugins::ProcessObject::
 GetMTime( ) const
@@ -199,30 +208,28 @@ GetMTime( ) const
 }
 
 // -------------------------------------------------------------------------
-std::string cpPlugins::ProcessObject::
+void cpPlugins::ProcessObject::
 Update( )
 {
-  std::string r = "";
-
   // Force upstream updates
   auto i = this->m_Inputs.begin( );
   bool need_to_update = false;
-  for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
+  for( ; i != this->m_Inputs.end( ); ++i )
   {
     bool iv = i->second.IsValid( );
     bool ir = i->second.IsRequired( );
     if( !iv && ir )
-      r =
-        "ProcessObject: Required input \"" +
-        i->first + "@" + this->GetClassName( ) +
-        "\" is not valid (=NULL).";
-    if( iv && r == "" )
+      this->_Error(
+        std::string( "Required input \"" ) + i->first +
+        std::string( "\" is not valid." )
+        );
+    if( iv )
     {
       Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
       if( src != NULL )
       {
         need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
-        r = src->Update( );
+        src->Update( );
 
       } // fi
 
@@ -231,27 +238,33 @@ Update( )
   } // rof
 
   // Current update
-  if( r == "" )
+  if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
   {
-    if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
+    if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
     {
-      std::cout
+      *( this->m_PrintExecutionStream )
         << "cpPlugins: Updating \""
-        << this->GetClassName( ) << ":" << this->GetClassCategory( )
+        << this->GetClassCategory( ) << ":" << this->GetClassName( )
         << "\"... ";
-      std::cout.flush( );
-      this->m_LastExecutionSpan = cpPlugins_CHRONO;
-      r = this->_GenerateData( );
-      this->m_LastExecutionSpan = cpPlugins_CHRONO - this->m_LastExecutionSpan;
-      this->m_LastExecutionTime = this->GetMTime( );
-      std::cout << "done in " << ( double( this->m_LastExecutionSpan ) / double( 1000 ) ) << "s!" << std::endl;
+      this->m_PrintExecutionStream->flush( );
 
     } // fi
 
-  } // fi
+    this->m_LastExecutionSpan = cpPlugins_CHRONO;
+    this->_GenerateData( );
+    this->m_LastExecutionSpan = cpPlugins_CHRONO - this->m_LastExecutionSpan;
+    this->m_LastExecutionTime = this->GetMTime( );
+
+    if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL )
+    {
+      *( this->m_PrintExecutionStream )
+        << "done in "
+        << this->m_LastExecutionSpan
+        << " ms." << std::endl;
 
-  // Return error description, if any
-  return( r );
+    } // fi
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
@@ -290,7 +303,10 @@ SetInteractionObjects( const std::vector< void* >& objs )
 cpPlugins::ProcessObject::
 ProcessObject( )
   : Superclass( ),
-    m_LastExecutionTime( 0 )
+    m_LastExecutionTime( 0 ),
+    m_LastExecutionSpan( -1 ),
+    m_PrintExecution( false ),
+    m_PrintExecutionStream( &( std::cout ) )
 {
 }
 
@@ -313,4 +329,18 @@ _AddInput( const std::string& name, bool required )
   } // fi
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::ProcessObject::
+_Error( const std::string& error )
+{
+  if( error != "" )
+  {
+    itkExceptionMacro(
+      "Error: \"" << this->GetClassCategory( ) << "::" <<
+      this->GetClassName( ) << "\": " << error
+      );
+
+  } // fi
+}
+
 // eof - $RCSfile$