]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Workspace.cxx
...
[cpPlugins.git] / lib / cpPlugins / Workspace.cxx
index dd4ade8e7237fb4e3ad6482808a46ba27d66c29e..b3f6af70a41e280e55d49211b6499563748e120d 100644 (file)
@@ -172,9 +172,42 @@ RenameFilter( const std::string& old_name, const std::string& new_name )
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::Workspace::
+bool cpPlugins::Workspace::
 RemoveFilter( const std::string& name )
 {
+  auto filter = this->GetFilter( name );
+  if( filter != NULL )
+  {
+    auto vIt = this->m_Graph->BeginVertices( );
+    for( ; vIt != this->m_Graph->EndVertices( ); ++vIt )
+    {
+      if( vIt->first != name )
+      {
+        if( this->m_Graph->HasEdge( name, vIt->first ) )
+        {
+          auto edges = this->m_Graph->GetEdges( name, vIt->first );
+          auto other = this->GetFilter( vIt->first );
+          for( auto eIt = edges.begin( ); eIt != edges.end( ); ++eIt )
+            other->SetInput( eIt->first, ( DataObject* )( NULL ) );
+
+        } // fi
+
+        if( this->m_Graph->HasEdge( vIt->first, name ) )
+        {
+          auto edges = this->m_Graph->GetEdges( vIt->first, name );
+          for( auto eIt = edges.begin( ); eIt != edges.end( ); ++eIt )
+            filter->SetInput( eIt->first, ( DataObject* )( NULL ) );
+
+        } // fi
+
+      } // fi
+
+    } // rof
+    this->m_Graph->RemoveVertex( name );
+    return( true );
+  }
+  else
+    return( false );
 }
 
 // -------------------------------------------------------------------------
@@ -306,6 +339,32 @@ Connect( const OutputPort& port, const std::string& exposed_port )
     return( false );
 }
 
+// -------------------------------------------------------------------------
+bool cpPlugins::Workspace::
+Disconnect(
+  const std::string& orig_filter, const std::string& dest_filter,
+  const std::string& output_name, const std::string& input_name
+  )
+{
+  // Get filters
+  ProcessObject* orig = this->GetFilter( orig_filter );
+  ProcessObject* dest = this->GetFilter( dest_filter );
+  if( orig == NULL || dest == NULL )
+    return( false );
+
+  // Real disconnection
+  if( dest->SetInput( input_name, ( DataObject* )( NULL ) ) )
+  {
+    this->m_Graph->RemoveEdge(
+      orig_filter, dest_filter,
+      TConnection( output_name, input_name )
+      );
+    return( true );
+  }
+  else
+    return( false );
+}
+
 // -------------------------------------------------------------------------
 bool cpPlugins::Workspace::
 Reduce( const std::string& name )
@@ -467,7 +526,7 @@ Execute( const std::string& name )
   ProcessObject* f = this->GetFilter( name );
   if( f == NULL )
   {
-    itkGenericExceptionMacro( 
+    itkGenericExceptionMacro(
       "cpPlugins::Workspace: Vertex \"" << name << "\" is not a filter."
       );