From 6885cd42cb7981803efb5c27c0a1a761084dc31c Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Tue, 12 Jan 2016 15:44:12 -0500 Subject: [PATCH] ... --- lib/cpExtensions/DataStructures/Graph.hxx | 58 ++++++- lib/cpPlugins/Interface/Workspace.cxx | 200 ++++++---------------- lib/cpPlugins/Interface/Workspace.h | 7 +- 3 files changed, 113 insertions(+), 152 deletions(-) diff --git a/lib/cpExtensions/DataStructures/Graph.hxx b/lib/cpExtensions/DataStructures/Graph.hxx index ef334d3..ac9e029 100644 --- a/lib/cpExtensions/DataStructures/Graph.hxx +++ b/lib/cpExtensions/DataStructures/Graph.hxx @@ -164,7 +164,39 @@ template< class V, class C, class I > void cpExtensions::DataStructures::Graph< V, C, I >:: RemoveVertex( const I& index ) { -#error REMOVE + auto i = this->m_Vertices.find( index ); + if( i != this->m_Vertices.end( ) ) + { + // Delete vertex + this->m_Vertices.erase( i ); + + // Delete edges starting from given vertex + auto mIt = this->m_Matrix.find( index ); + if( mIt != this->m_Matrix.end( ) ) + this->m_Matrix.erase( mIt ); + + // Delete edges arriving to given vertex + mIt = this->m_Matrix.begin( ); + for( ; mIt != this->m_Matrix.end( ); ++mIt ) + { + auto rIt = mIt->second.begin( ); + while( rIt != mIt->second.end( ) ) + { + if( rIt->first == index ) + { + mIt->second.erase( rIt ); + rIt = mIt->second.begin( ); + } + else + ++rIt; + + } // elihw + + } // rof + return( true ); + } + else + return( false ); } // ------------------------------------------------------------------------- @@ -196,7 +228,29 @@ template< class V, class C, class I > void cpExtensions::DataStructures::Graph< V, C, I >:: RemoveConnection( const I& orig, const I& dest, const C& cost ) { -#error remove connection + auto m = this->m_Matrix.find( orig ); + if( m != this->m_Matrix.end( ) ) + { + auto r = m->second.find( dest ); + if( r != m->second.end( ) ) + { + auto e = std::find( r->second.begin( ), r->second.end( ), cost ); + if( e != r->second.end( ) ) + { + r->second.erase( e ); + if( r->second.size( ) == 0 ) + { + m->second.erase( r ); + if( m->second.size( ) == 0 ) + this->m_Matrix.erase( m ); + + } // fi + + } // fi + + } // fi + + } // fi } // ------------------------------------------------------------------------- diff --git a/lib/cpPlugins/Interface/Workspace.cxx b/lib/cpPlugins/Interface/Workspace.cxx index a722908..3c42481 100644 --- a/lib/cpPlugins/Interface/Workspace.cxx +++ b/lib/cpPlugins/Interface/Workspace.cxx @@ -30,98 +30,6 @@ SetInterface( TInterface* i ) this->m_Interface = i; } -/* TODO - 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 ) - { - // 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 ); - } - - // ------------------------------------------------------------------------- - const cpPlugins::Interface::Workspace:: - TStringContainer& cpPlugins::Interface::Workspace:: - GetLoadedPlugins( ) const - { - return( this->m_LoadedPlugins ); - } - - // ------------------------------------------------------------------------- - void cpPlugins::Interface::Workspace:: - GetLoadedPluginCategories( TStringContainer& categories ) const - { - categories.clear( ); - auto fIt = this->m_LoadedFilters.begin( ); - for( ; fIt != this->m_LoadedFilters.end( ); ++fIt ) - categories.insert( fIt->first ); - } - - // ------------------------------------------------------------------------- - void cpPlugins::Interface::Workspace:: - GetLoadedPluginFilters( TStringContainer& filters ) const - { - 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 ); - } - - // ------------------------------------------------------------------------- - const cpPlugins::Interface::Workspace:: - TStringContainer& cpPlugins::Interface::Workspace:: - GetLoadedPluginFilters( const std::string& category ) const - { - static const TStringContainer EMPTY; - auto pIt = this->m_LoadedFilters.find( category ); - if( pIt != this->m_LoadedFilters.end( ) ) - return( pIt->second ); - else - return( EMPTY ); - } -*/ - // ------------------------------------------------------------------------- void cpPlugins::Interface::Workspace:: Clear( ) @@ -179,14 +87,8 @@ 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 ); @@ -201,19 +103,20 @@ Connect( // ------------------------------------------------------------------------- bool cpPlugins::Interface::Workspace:: -Connect( const std::string& i, const std::string& o ) +Connect( TData* input_object, const std::string& input_name ) { - auto ii = this->m_InputPorts.find( i ); - auto oi = this->m_OutputPorts.find( o ); - if( ii != this->m_InputPorts.end( ) && oi != this->m_OutputPorts.end( ) ) - return( - this->Connect( - oi->second.first, - ii->second.first, - oi->second.second, - ii->second.second - ) - ); + auto port = this->m_InputPorts.find( input_name ); + if( port != this->m_InputPorts.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( false ); } @@ -223,10 +126,7 @@ cpPlugins::Interface::Workspace:: TParameters* cpPlugins::Interface::Workspace:: GetParameters( const std::string& name ) { - TFilter* f = - dynamic_cast< TFilter* >( - this->m_Graph->GetVertex( name ).GetPointer( ) - ); + TFilter* f = this->GetFilter( name ); if( f != NULL ) return( f->GetParameters( ) ); else @@ -238,10 +138,7 @@ const cpPlugins::Interface::Workspace:: TParameters* cpPlugins::Interface::Workspace:: GetParameters( const std::string& name ) const { - const TFilter* f = - dynamic_cast< const TFilter* >( - this->m_Graph->GetVertex( name ).GetPointer( ) - ); + const TFilter* f = this->GetFilter( name ); if( f != NULL ) return( f->GetParameters( ) ); else @@ -309,6 +206,42 @@ AddOutputPort( this->m_OutputPorts[ name ] = TGlobalPort( filter, filter_output ); } +// ------------------------------------------------------------------------- +cpPlugins::Interface::Workspace:: +TData* cpPlugins::Interface::Workspace:: +GetOutput( const std::string& name ) +{ + auto port = this->m_OutputPorts.find( name ); + if( port != this->m_OutputPorts.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_OutputPorts.find( name ); + if( port != this->m_OutputPorts.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( ) @@ -347,10 +280,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 \"" ) + @@ -370,26 +300,4 @@ Execute( const std::string& name, QWidget* p ) return( f->Update( ) ); } -// ------------------------------------------------------------------------- -void cpPlugins::Interface::Workspace:: -_UpdateLoadedPluginsInformation( ) -{ - /* TODO - if( this->m_Interface != NULL ) - { - 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 - - } // fi - */ -} - // eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/Workspace.h b/lib/cpPlugins/Interface/Workspace.h index c11d155..919233f 100644 --- a/lib/cpPlugins/Interface/Workspace.h +++ b/lib/cpPlugins/Interface/Workspace.h @@ -60,7 +60,7 @@ namespace cpPlugins const std::string& output_name, const std::string& input_name ); - bool Connect( const std::string& i, const std::string& o ); + bool Connect( TData* input_object, const std::string& input_name ); TParameters* GetParameters( const std::string& name ); const TParameters* GetParameters( const std::string& name ) const; TFilter* GetFilter( const std::string& name ); @@ -77,6 +77,8 @@ namespace cpPlugins const std::string& name, const std::string& filter, const std::string& filter_output ); + TData* GetOutput( const std::string& name ); + const TData* GetOutput( const std::string& name ) const; void ClearInputPorts( ); void ClearOutputPorts( ); @@ -84,9 +86,6 @@ namespace cpPlugins std::string Execute( ); std::string Execute( const std::string& name, QWidget* p = NULL ); - protected: - void _UpdateLoadedPluginsInformation( ); - protected: // Plugins interface TInterface* m_Interface; -- 2.47.1