]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/Workspace.cxx
Editor finished
[cpPlugins.git] / lib / cpPlugins / Interface / Workspace.cxx
index fb8f91e5f55361a8a33e23e1804eaf3d7bed2dff..022f9faa0babc181feed2ff42cce0468cb5cbcd2 100644 (file)
@@ -3,7 +3,7 @@
 // -------------------------------------------------------------------------
 cpPlugins::Interface::Workspace::
 Workspace( )
-  : m_LastLoadedPlugin( "" )
+  : m_Plugins( NULL )
 {
   this->m_Graph = TGraph::New( );
 }
@@ -15,94 +15,43 @@ cpPlugins::Interface::Workspace::
 }
 
 // -------------------------------------------------------------------------
-bool cpPlugins::Interface::Workspace::
-LoadPluginsPath( const std::string& path, bool r )
-{
-  // Load all plugins from given folder
-  std::list< std::string > files =
-    this->m_Interface.LoadFromFolder( path, r );
-
-  // Update a simple track
-  bool ret = false;
-  if( files.size( ) > 0 )
-  {
-    for( auto fIt = files.begin( ); fIt != files.end( ); ++fIt )
-    {
-      this->m_LoadedPlugins.insert( *fIt );
-      this->m_LastLoadedPlugin = *fIt;
-
-    } // rof
-    this->_UpdateLoadedPluginsInformation( );
-    ret = true;
-
-  } // fi
-  return( ret );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Workspace::
-LoadPlugins( const std::string& fname )
+cpPlugins::Interface::Workspace::
+TPlugins* cpPlugins::Interface::Workspace::
+GetPlugins( )
 {
-  // Is it already loaded?
-  bool ret = true;
-  if( this->m_LoadedPlugins.find( fname ) == this->m_LoadedPlugins.end( ) )
-  {
-    // Was it succesfully loaded?
-    ret = this->m_Interface.Load( fname );
-
-    // Update a simple track
-    if( ret )
-    {
-      this->m_LoadedPlugins.insert( fname );
-      this->m_LastLoadedPlugin = fname;
-      this->_UpdateLoadedPluginsInformation( );
-
-    } // fi
-
-  } // fi
-  return( ret );
+  return( this->m_Plugins );
 }
 
 // -------------------------------------------------------------------------
 const cpPlugins::Interface::Workspace::
-TStringContainer& cpPlugins::Interface::Workspace::
-GetLoadedPlugins( ) const
+TPlugins* cpPlugins::Interface::Workspace::
+GetPlugins( ) const
 {
-  return( this->m_LoadedPlugins );
+  return( this->m_Plugins );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::Workspace::
-GetLoadedPluginCategories( TStringContainer& categories ) const
+SetPlugins( TPlugins* i )
 {
-  categories.clear( );
-  auto fIt = this->m_LoadedFilters.begin( );
-  for( ; fIt != this->m_LoadedFilters.end( ); ++fIt )
-    categories.insert( fIt->first );
+  if( this->m_Plugins != i )
+    this->m_Plugins = i;
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::Interface::Workspace::
-GetLoadedPluginFilters( TStringContainer& filters ) const
+cpPlugins::Interface::Workspace::
+TGraph* cpPlugins::Interface::Workspace::
+GetGraph( )
 {
-  filters.clear( );
-  auto pIt = this->m_LoadedFilters.begin( );
-  for( ; pIt != this->m_LoadedFilters.end( ); ++pIt )
-    for( auto fIt = pIt->second.begin( ); fIt != pIt->second.end( ); ++fIt )
-      filters.insert( *fIt );
+  return( this->m_Graph );
 }
 
 // -------------------------------------------------------------------------
 const cpPlugins::Interface::Workspace::
-TStringContainer& cpPlugins::Interface::Workspace::
-GetLoadedPluginFilters( const std::string& category ) const
+TGraph* cpPlugins::Interface::Workspace::
+GetGraph( ) const
 {
-  static const TStringContainer EMPTY;
-  auto pIt = this->m_LoadedFilters.find( category );
-  if( pIt != this->m_LoadedFilters.end( ) )
-    return( pIt->second );
-  else
-    return( EMPTY );
+  return( this->m_Graph );
 }
 
 // -------------------------------------------------------------------------
@@ -113,35 +62,62 @@ Clear( )
     this->m_Graph->Clear( );
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Workspace::
+ClearConnections( )
+{
+}
+
 // -------------------------------------------------------------------------
 cpPlugins::Interface::Workspace::
-TGraph* cpPlugins::Interface::Workspace::
-GetGraph( )
+TFilter* cpPlugins::Interface::Workspace::
+GetFilter( const std::string& name )
 {
-  return( this->m_Graph );
+  TFilter* f =
+    dynamic_cast< TFilter* >(
+      this->m_Graph->GetVertex( name ).GetPointer( )
+      );
+  return( f );
 }
 
 // -------------------------------------------------------------------------
 const cpPlugins::Interface::Workspace::
-TGraph* cpPlugins::Interface::Workspace::
-GetGraph( ) const
+TFilter* cpPlugins::Interface::Workspace::
+GetFilter( const std::string& name ) const
 {
-  return( this->m_Graph );
+  const TFilter* f =
+    dynamic_cast< const TFilter* >(
+      this->m_Graph->GetVertex( name ).GetPointer( )
+      );
+  return( f );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Workspace::
+HasFilter( const std::string& name ) const
+{
+  if( this->m_Graph->HasVertexIndex( name ) )
+    return( this->GetFilter( name ) != NULL );
+  else
+    return( false );
 }
 
 // -------------------------------------------------------------------------
 bool cpPlugins::Interface::Workspace::
 CreateFilter( const std::string& filter, const std::string& name )
 {
+  if( this->m_Plugins == NULL )
+    return( false );
+
   // Get or create new filter from name
   if( !( this->m_Graph->HasVertexIndex( name ) ) )
   {
-    TFilter::Pointer f = this->m_Interface.CreateObject( filter );
+    TFilter::Pointer f = this->m_Plugins->CreateObject( filter );
     if( f.IsNotNull( ) )
     {
       f->SetName( name );
       TObject::Pointer o = f.GetPointer( );
-      this->m_Graph->InsertVertex( name, o );
+      this->m_Graph->SetVertex( name, o );
       return( true );
     }
     else
@@ -151,6 +127,26 @@ CreateFilter( const std::string& filter, const std::string& name )
     return( true );
 }
 
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Workspace::
+RenameFilter( const std::string& old_name, const std::string& new_name )
+{
+  if( this->m_Graph->RenameVertex( old_name, new_name ) )
+  {
+    TFilter* f = this->GetFilter( new_name );
+    f->SetName( new_name );
+    return( true );
+  }
+  else
+    return( false );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Workspace::
+RemoveFilter( const std::string& name )
+{
+}
+
 // -------------------------------------------------------------------------
 bool cpPlugins::Interface::Workspace::
 Connect(
@@ -159,20 +155,14 @@ Connect(
   )
 {
   // Get filters
-  TFilter* orig =
-    dynamic_cast< TFilter* >(
-      this->m_Graph->GetVertex( orig_filter ).GetPointer( )
-      );
-  TFilter* dest =
-    dynamic_cast< TFilter* >(
-      this->m_Graph->GetVertex( dest_filter ).GetPointer( )
-      );
+  TFilter* orig = this->GetFilter( orig_filter );
+  TFilter* dest = this->GetFilter( dest_filter );
   if( orig == NULL || dest == NULL )
     return( false );
 
   // Real connection
   dest->SetInput( input_name, orig->GetOutput< TData >( output_name ) );
-  this->m_Graph->AddConnection(
+  this->m_Graph->AddEdge(
     orig_filter, dest_filter,
     TConnection( output_name, input_name )
     );
@@ -180,79 +170,183 @@ Connect(
 }
 
 // -------------------------------------------------------------------------
-cpPlugins::Interface::Workspace::
-TParameters* cpPlugins::Interface::Workspace::
-GetParameters( const std::string& name )
+bool cpPlugins::Interface::Workspace::
+Connect( TData* input_object, const std::string& input_name )
 {
-  TFilter* f =
-    dynamic_cast< TFilter* >(
-      this->m_Graph->GetVertex( name ).GetPointer( )
-      );
-  if( f != NULL )
-    return( f->GetParameters( ) );
+  auto port = this->m_ExposedInputPorts.find( input_name );
+  if( port != this->m_ExposedInputPorts.end( ) )
+  {
+    TFilter* filter = this->GetFilter( port->second.first );
+    if( filter != NULL )
+    {
+      filter->SetInput( port->second.second, input_object );
+      return( true );
+    }
+    else
+      return( false );
+  }
   else
-    return( NULL );
+    return( false );
 }
 
 // -------------------------------------------------------------------------
-const cpPlugins::Interface::Workspace::
-TParameters* cpPlugins::Interface::Workspace::
-GetParameters( const std::string& name ) const
+bool cpPlugins::Interface::Workspace::
+Reduce( const std::string& name )
 {
-  const TFilter* f =
-    dynamic_cast< const TFilter* >(
-      this->m_Graph->GetVertex( name ).GetPointer( )
-      );
-  if( f != NULL )
-    return( f->GetParameters( ) );
-  else
-    return( NULL );
+  return( false );
 }
 
 // -------------------------------------------------------------------------
-cpPlugins::Interface::Workspace::
-TFilter* cpPlugins::Interface::Workspace::
-GetFilter( const std::string& name )
+void cpPlugins::Interface::Workspace::
+ExposeInputPort(
+  const std::string& name,
+  const std::string& filter, const std::string& filter_input
+  )
 {
-  TFilter* f =
-    dynamic_cast< TFilter* >(
-      this->m_Graph->GetVertex( name ).GetPointer( )
-      );
-  return( f );
+  this->m_ExposedInputPorts[ name ] = TExposedPort( filter, filter_input );
 }
 
 // -------------------------------------------------------------------------
-const cpPlugins::Interface::Workspace::
-TFilter* cpPlugins::Interface::Workspace::
-GetFilter( const std::string& name ) const
+void cpPlugins::Interface::Workspace::
+ExposeOutputPort(
+  const std::string& name,
+  const std::string& filter, const std::string& filter_output
+  )
 {
-  const TFilter* f =
-    dynamic_cast< const TFilter* >(
-      this->m_Graph->GetVertex( name ).GetPointer( )
-      );
-  return( f );
+  this->m_ExposedOutputPorts[ name ] = TExposedPort( filter, filter_output );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Workspace::
+HideInputPort( const std::string& name )
+{
+  auto i = this->m_ExposedInputPorts.find( name );
+  if( i != this->m_ExposedInputPorts.end( ) )
+    this->m_ExposedInputPorts.erase( i );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Workspace::
+HideOutputPort( const std::string& name )
+{
+  auto i = this->m_ExposedOutputPorts.find( name );
+  if( i != this->m_ExposedOutputPorts.end( ) )
+    this->m_ExposedOutputPorts.erase( i );
 }
 
 // -------------------------------------------------------------------------
 bool cpPlugins::Interface::Workspace::
-HasFilter( const std::string& name ) const
+RenameExposedInputPort(
+  const std::string& old_name,
+  const std::string& new_name
+  )
 {
-  if( this->m_Graph->HasVertexIndex( name ) )
-    return( this->GetFilter( name ) != NULL );
+  auto o = this->m_ExposedInputPorts.find( old_name );
+  auto n = this->m_ExposedInputPorts.find( new_name );
+  if(
+    o != this->m_ExposedInputPorts.end( ) &&
+    n == this->m_ExposedInputPorts.end( )
+    )
+  {
+    this->m_ExposedInputPorts[ new_name ] = o->second;
+    this->m_ExposedInputPorts.erase( o );
+  }
   else
     return( false );
 }
 
 // -------------------------------------------------------------------------
 bool cpPlugins::Interface::Workspace::
-Reduce( const std::string& name )
+RenameExposedOutputPort(
+  const std::string& old_name,
+  const std::string& new_name
+  )
 {
-  return( false );
+  auto o = this->m_ExposedOutputPorts.find( old_name );
+  auto n = this->m_ExposedOutputPorts.find( new_name );
+  if(
+    o != this->m_ExposedOutputPorts.end( ) &&
+    n == this->m_ExposedOutputPorts.end( )
+    )
+  {
+    this->m_ExposedOutputPorts[ new_name ] = o->second;
+    this->m_ExposedOutputPorts.erase( o );
+  }
+  else
+    return( false );
 }
 
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Workspace::
+TExposedPorts& cpPlugins::Interface::Workspace::
+GetExposedInputPorts( ) const
+{
+  return( this->m_ExposedInputPorts );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Workspace::
+TExposedPorts& cpPlugins::Interface::Workspace::
+GetExposedOutputPorts( ) const
+{
+  return( this->m_ExposedOutputPorts );
+}
+
+// -------------------------------------------------------------------------
+/* TODO
+cpPlugins::Interface::Workspace::
+TData* cpPlugins::Interface::Workspace::
+GetOutput( const std::string& name )
+{
+  auto port = this->m_ExposedOutputPorts.find( name );
+  if( port != this->m_ExposedOutputPorts.end( ) )
+  {
+    TFilter* f = this->GetFilter( port->second.first );
+    if( f != NULL )
+      return( f->GetOutput< TData >( port->second.second ) );
+    else
+      return( NULL );
+  }
+  else
+    return( NULL );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Workspace::
+TData* cpPlugins::Interface::Workspace::
+GetOutput( const std::string& name ) const
+{
+  auto port = this->m_ExposedOutputPorts.find( name );
+  if( port != this->m_ExposedOutputPorts.end( ) )
+  {
+    const TFilter* f = this->GetFilter( port->second.first );
+    if( f != NULL )
+      return( f->GetOutput< TData >( port->second.second ) );
+    else
+      return( NULL );
+  }
+  else
+    return( NULL );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Workspace::
+ClearInputPorts( )
+{
+  this->m_ExposedInputPorts.clear( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Workspace::
+ClearOutputPorts( )
+{
+  this->m_ExposedOutputPorts.clear( );
+}
+*/
+
 // -------------------------------------------------------------------------
 std::string cpPlugins::Interface::Workspace::
-Execute( )
+Execute( QWidget* p )
 {
   // Find sinks
   std::set< std::string > sinks = this->m_Graph->GetSinks( );
@@ -261,7 +355,7 @@ Execute( )
   std::string err = "";
   for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt )
   {
-    std::string lerr = this->Execute( *sIt, NULL );
+    std::string lerr = this->Execute( *sIt, p );
     if( lerr != "" )
       err += lerr + std::string( "\n" );
 
@@ -274,10 +368,7 @@ std::string cpPlugins::Interface::Workspace::
 Execute( const std::string& name, QWidget* p )
 {
   // Get filter
-  TFilter* f =
-    dynamic_cast< TFilter* >(
-      this->m_Graph->GetVertex( name ).GetPointer( )
-      );
+  TFilter* f = this->GetFilter( name );
   if( f == NULL )
     return(
       std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +
@@ -297,20 +388,4 @@ Execute( const std::string& name, QWidget* p )
     return( f->Update( ) );
 }
 
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Workspace::
-_UpdateLoadedPluginsInformation( )
-{
-  this->m_LoadedFilters.clear( );
-  const TInterface::TClasses& cls = this->m_Interface.GetClasses( );
-  for( auto i = cls.begin( ); i != cls.end( ); ++i )
-  {
-    TFilter::Pointer o = this->m_Interface.CreateObject( i->first );
-    std::string name = o->GetClassName( );
-    std::string category = o->GetClassCategory( );
-    this->m_LoadedFilters[ category ].insert( name );
-
-  } // rof
-}
-
 // eof - $RCSfile$