]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Workspace.cxx
Code cleaning
[cpPlugins.git] / lib / cpPlugins / Workspace.cxx
index 7ba11d1688feab1b435e6745d1fdf0bb7fede5bd..dd4ade8e7237fb4e3ad6482808a46ba27d66c29e 100644 (file)
@@ -7,6 +7,7 @@
 cpPlugins::Workspace::
 Workspace( )
   : m_Interface( NULL ),
+    m_PrintExecution( false ),
     m_MPRViewer( NULL )
 {
   this->m_Graph = TGraph::New( );
@@ -93,6 +94,28 @@ GetFilter( const std::string& name ) const
   return( f );
 }
 
+// -------------------------------------------------------------------------
+cpPlugins::DataObject* cpPlugins::Workspace::
+GetOutput( const std::string& filter, const std::string& output )
+{
+  auto f = this->GetFilter( filter );
+  if( f != NULL )
+    return( f->GetOutput( output ) );
+  else
+    return( NULL );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::DataObject* cpPlugins::Workspace::
+GetOutput( const std::string& filter, const std::string& output ) const
+{
+  auto f = this->GetFilter( filter );
+  if( f != NULL )
+    return( f->GetOutput( output ) );
+  else
+    return( NULL );
+}
+
 // -------------------------------------------------------------------------
 bool cpPlugins::Workspace::
 HasFilter( const std::string& name ) const
@@ -118,7 +141,7 @@ CreateFilter(
   if( !( this->m_Graph->HasVertexIndex( name ) ) )
   {
     ProcessObject::Pointer f =
-      this->m_Interface->Create( category, filter );
+      this->m_Interface->CreateProcessObject( category, filter );
     if( f.IsNotNull( ) )
     {
       if( f->IsInteractive( ) )
@@ -129,8 +152,10 @@ CreateFilter(
         f->SetInteractionObjects( interactive_objects );
 
       } // fi
+      f->SetPrintExecution( this->m_PrintExecution );
       Object::Pointer o = f.GetPointer( );
       this->m_Graph->SetVertex( name, o );
+      f->SetName( name );
 
     } // fi
     return( f.GetPointer( ) );
@@ -167,6 +192,35 @@ SetParameter( const std::string& name, const std::string& value )
   } // fi
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::Workspace::
+SetPrintExecution( bool b )
+{
+  this->m_PrintExecution = b;
+  auto vIt = this->m_Graph->BeginVertices( );
+  for( ; vIt != this->m_Graph->EndVertices( ); ++vIt )
+  {
+    auto f = dynamic_cast< ProcessObject* >( vIt->second.GetPointer( ) );
+    if( f != NULL )
+      f->SetPrintExecution( b );
+
+  } // rof
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Workspace::
+PrintExecutionOn( )
+{
+  this->SetPrintExecution( true );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Workspace::
+PrintExecutionOff( )
+{
+  this->SetPrintExecution( false );
+}
+
 // -------------------------------------------------------------------------
 vtkRenderWindowInteractor* cpPlugins::Workspace::
 GetSingleInteractor( )
@@ -223,7 +277,7 @@ Connect(
     return( false );
 
   // Real connection
-  if( dest->SetInput( input_name, orig->GetOutput( output_name ) ) )
+  if( dest->SetInputPort( input_name, orig->GetOutputPort( output_name ) ) )
   {
     this->m_Graph->AddEdge(
       orig_filter, dest_filter,
@@ -244,7 +298,7 @@ Connect( const OutputPort& port, const std::string& exposed_port )
   {
     ProcessObject* filter = this->GetFilter( i->second.first );
     if( filter != NULL )
-      return( filter->SetInput( i->second.second, port ) );
+      return( filter->SetInputPort( i->second.second, port ) );
     else
       return( false );
   }
@@ -369,7 +423,7 @@ GetExposedOutput( const std::string& name )
   {
     ProcessObject* filter = this->GetFilter( i->second.first );
     if( filter != NULL )
-      return( filter->GetOutput( i->second.second ) );
+      return( filter->GetOutputPort( i->second.second ) );
 
   } // fi
   return( null_port );
@@ -387,45 +441,40 @@ GetExposedOutput( const std::string& name ) const
   {
     const ProcessObject* filter = this->GetFilter( i->second.first );
     if( filter != NULL )
-      return( filter->GetOutput( i->second.second ) );
+      return( filter->GetOutputPort( i->second.second ) );
 
   } // fi
   return( null_port );
 }
 
 // -------------------------------------------------------------------------
-std::string cpPlugins::Workspace::
+void cpPlugins::Workspace::
 Execute( )
 {
   // Find sinks
   std::set< std::string > sinks = this->m_Graph->GetSinks( );
 
   // Update sinks
-  std::string err = "";
   for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt )
-  {
-    std::string lerr = this->Execute( *sIt );
-    if( lerr != "" )
-      err += lerr + std::string( "\n" );
-
-  } // rof
-  return( err );
+    this->Execute( *sIt );
 }
 
 // -------------------------------------------------------------------------
-std::string cpPlugins::Workspace::
+void cpPlugins::Workspace::
 Execute( const std::string& name )
 {
   // Get filter
   ProcessObject* f = this->GetFilter( name );
   if( f == NULL )
-    return(
-      std::string( "cpPlugins::Workspace: Vertex \"" ) +
-      name + std::string( "\" is not a filter." )
+  {
+    itkGenericExceptionMacro( 
+      "cpPlugins::Workspace: Vertex \"" << name << "\" is not a filter."
       );
 
-  // Execute and return
-  return( f->Update( ) );
+  } // fi
+
+  // Execute
+  f->Update( );
 }
 
 // eof - $RCSfile$