]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/Workspace.cxx
Pipeline editor added.
[cpPlugins.git] / lib / cpPlugins / Interface / Workspace.cxx
index 9e8d4e1e7ab3d35ee94b332a7ff4fc0ee8a2816f..4e5f51a515fa1227eff9660a2987573e3148bd69 100644 (file)
@@ -5,6 +5,7 @@ cpPlugins::Interface::Workspace::
 Workspace( )
   : m_LastLoadedPlugin( "" )
 {
+  this->m_Graph = TGraph::New( );
 }
 
 // -------------------------------------------------------------------------
@@ -104,19 +105,35 @@ GetLoadedPluginFilters( const std::string& category ) const
     return( EMPTY );
 }
 
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Workspace::
+TGraph* cpPlugins::Interface::Workspace::
+GetGraph( )
+{
+  return( this->m_Graph );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Workspace::
+TGraph* cpPlugins::Interface::Workspace::
+GetGraph( ) const
+{
+  return( this->m_Graph );
+}
+
 // -------------------------------------------------------------------------
 bool cpPlugins::Interface::Workspace::
 CreateFilter( const std::string& filter, const std::string& name )
 {
   // Get or create new filter from name
-  auto vIt = this->m_Vertices.find( name );
-  if( vIt == this->m_Vertices.end( ) )
+  if( !( this->m_Graph->HasVertexIndex( name ) ) )
   {
-    TFilter::Pointer o = this->m_Interface.CreateObject( filter );
-    if( o.IsNotNull( ) )
+    TFilter::Pointer f = this->m_Interface.CreateObject( filter );
+    if( f.IsNotNull( ) )
     {
-      o->SetName( name );
-      this->m_Vertices[ name ] = o;
+      f->SetName( name );
+      TObject::Pointer o = f.GetPointer( );
+      this->m_Graph->InsertVertex( name, o );
       return( true );
     }
     else
@@ -134,20 +151,21 @@ Connect(
   )
 {
   // Get filters
-  auto oIt = this->m_Vertices.find( orig_filter );
-  if( oIt == this->m_Vertices.end( ) )
-    return( false );
-  auto dIt = this->m_Vertices.find( dest_filter );
-  if( dIt == this->m_Vertices.end( ) )
-    return( false );
-  TFilter* orig = dynamic_cast< TFilter* >( oIt->second.GetPointer( ) );
-  TFilter* dest = dynamic_cast< TFilter* >( dIt->second.GetPointer( ) );
+  TFilter* orig =
+    dynamic_cast< TFilter* >(
+      this->m_Graph->GetVertex( orig_filter ).GetPointer( )
+      );
+  TFilter* dest =
+    dynamic_cast< TFilter* >(
+      this->m_Graph->GetVertex( dest_filter ).GetPointer( )
+      );
   if( orig == NULL || dest == NULL )
     return( false );
 
   // Real connection
   dest->SetInput( input_name, orig->GetOutput< TData >( output_name ) );
-  this->m_AdjMatrix[ orig_filter ][ dest_filter ].push_back(
+  this->m_Graph->AddConnection(
+    orig_filter, dest_filter,
     TConnection( output_name, input_name )
     );
   return( false );
@@ -158,15 +176,12 @@ cpPlugins::Interface::Workspace::
 TParameters* cpPlugins::Interface::Workspace::
 GetParameters( const std::string& name )
 {
-  auto vIt = this->m_Vertices.find( name );
-  if( vIt != this->m_Vertices.end( ) )
-  {
-    TFilter* f = dynamic_cast< TFilter* >( vIt->second.GetPointer( ) );
-    if( f != NULL )
-      return( f->GetParameters( ) );
-    else
-      return( NULL );
-  }
+  TFilter* f =
+    dynamic_cast< TFilter* >(
+      this->m_Graph->GetVertex( name ).GetPointer( )
+      );
+  if( f != NULL )
+    return( f->GetParameters( ) );
   else
     return( NULL );
 }
@@ -176,16 +191,12 @@ const cpPlugins::Interface::Workspace::
 TParameters* cpPlugins::Interface::Workspace::
 GetParameters( const std::string& name ) const
 {
-  auto vIt = this->m_Vertices.find( name );
-  if( vIt != this->m_Vertices.end( ) )
-  {
-    const TFilter* f =
-      dynamic_cast< const TFilter* >( vIt->second.GetPointer( ) );
-    if( f != NULL )
-      return( f->GetParameters( ) );
-    else
-      return( NULL );
-  }
+  const TFilter* f =
+    dynamic_cast< const TFilter* >(
+      this->m_Graph->GetVertex( name ).GetPointer( )
+      );
+  if( f != NULL )
+    return( f->GetParameters( ) );
   else
     return( NULL );
 }
@@ -194,6 +205,7 @@ GetParameters( const std::string& name ) const
 bool cpPlugins::Interface::Workspace::
 Reduce( const std::string& name )
 {
+  return( false );
 }
 
 // -------------------------------------------------------------------------
@@ -201,13 +213,7 @@ std::string cpPlugins::Interface::Workspace::
 Execute( )
 {
   // Find sinks
-  std::set< std::string > sinks;
-  auto vIt = this->m_Vertices.begin( );
-  for( ; vIt != this->m_Vertices.end( ); ++vIt )
-    sinks.insert( vIt->first );
-  auto mIt = this->m_AdjMatrix.begin( );
-  for( ; mIt != this->m_AdjMatrix.end( ); ++mIt )
-    sinks.erase( mIt->first );
+  std::set< std::string > sinks = this->m_Graph->GetSinks( );
 
   // Update sinks
   std::string err = "";
@@ -226,13 +232,10 @@ std::string cpPlugins::Interface::Workspace::
 Execute( const std::string& name )
 {
   // Get filter
-  auto vIt = this->m_Vertices.find( name );
-  if( vIt == this->m_Vertices.end( ) )
-    return(
-      std::string( "cpPlugins::Interface::Workspace: No filter \"" ) +
-      name + std::string( "\"" )
+  TFilter* f =
+    dynamic_cast< TFilter* >(
+      this->m_Graph->GetVertex( name ).GetPointer( )
       );
-  TFilter* f = dynamic_cast< TFilter* >( vIt->second.GetPointer( ) );
   if( f == NULL )
     return(
       std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +