X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FWorkspace.cxx;h=b37c2caa8b5c92d2418c6450515389847350f3a3;hb=1b600247da314fe62d007ca8a0ce24d0006931f4;hp=9e8d4e1e7ab3d35ee94b332a7ff4fc0ee8a2816f;hpb=f654620df52b811be7bd263a1775c93d29c69a65;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Workspace.cxx b/lib/cpPlugins/Interface/Workspace.cxx index 9e8d4e1..b37c2ca 100644 --- a/lib/cpPlugins/Interface/Workspace.cxx +++ b/lib/cpPlugins/Interface/Workspace.cxx @@ -1,10 +1,14 @@ #include +#include +#include // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: Workspace( ) - : m_LastLoadedPlugin( "" ) + : m_Plugins( NULL ), + m_MPRViewer( NULL ) { + this->m_Graph = TGraph::New( ); } // ------------------------------------------------------------------------- @@ -14,116 +18,183 @@ cpPlugins::Interface::Workspace:: } // ------------------------------------------------------------------------- -bool cpPlugins::Interface::Workspace:: -LoadPluginsPath( const std::string& path, bool r ) +cpPlugins::Interface::Workspace:: +TPlugins* cpPlugins::Interface::Workspace:: +GetPlugins( ) { - // 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 ); + return( this->m_Plugins ); } // ------------------------------------------------------------------------- -bool cpPlugins::Interface::Workspace:: -LoadPlugins( const std::string& fname ) +const cpPlugins::Interface::Workspace:: +TPlugins* cpPlugins::Interface::Workspace:: +GetPlugins( ) const { - // 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( ); + return( this->m_Plugins ); +} - } // fi +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Workspace:: +SetPlugins( TPlugins* i ) +{ + if( this->m_Plugins != i ) + this->m_Plugins = i; +} - } // fi - return( ret ); +// ------------------------------------------------------------------------- +cpPlugins::Interface::Workspace:: +TGraph* cpPlugins::Interface::Workspace:: +GetGraph( ) +{ + return( this->m_Graph ); } // ------------------------------------------------------------------------- const cpPlugins::Interface::Workspace:: -TStringContainer& cpPlugins::Interface::Workspace:: -GetLoadedPlugins( ) const +TGraph* cpPlugins::Interface::Workspace:: +GetGraph( ) const { - return( this->m_LoadedPlugins ); + return( this->m_Graph ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Workspace:: -GetLoadedPluginCategories( TStringContainer& categories ) const +Clear( ) { - categories.clear( ); - auto fIt = this->m_LoadedFilters.begin( ); - for( ; fIt != this->m_LoadedFilters.end( ); ++fIt ) - categories.insert( fIt->first ); + if( this->m_Graph.IsNotNull( ) ) + this->m_Graph->Clear( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Workspace:: -GetLoadedPluginFilters( TStringContainer& filters ) const +ClearConnections( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Workspace:: +TFilter* cpPlugins::Interface::Workspace:: +GetFilter( const std::string& name ) { - 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 ); + TFilter* f = + dynamic_cast< TFilter* >( + this->m_Graph->GetVertex( name ).GetPointer( ) + ); + return( f ); } // ------------------------------------------------------------------------- const cpPlugins::Interface::Workspace:: -TStringContainer& cpPlugins::Interface::Workspace:: -GetLoadedPluginFilters( const std::string& category ) const +TFilter* cpPlugins::Interface::Workspace:: +GetFilter( const std::string& name ) const { - static const TStringContainer EMPTY; - auto pIt = this->m_LoadedFilters.find( category ); - if( pIt != this->m_LoadedFilters.end( ) ) - return( pIt->second ); - else - return( EMPTY ); + 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 ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Workspace:: +TFilter* cpPlugins::Interface::Workspace:: CreateFilter( const std::string& filter, const std::string& name ) { + if( this->m_Plugins == NULL ) + return( NULL ); + // 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_Plugins->CreateObject( filter ); + if( f.IsNotNull( ) ) { - o->SetName( name ); - this->m_Vertices[ name ] = o; - return( true ); - } - else - return( false ); + f->SetName( name ); + f->SetSingleInteractor( this->m_SingleInteractor ); + f->SetMPRViewer( this->m_MPRViewer ); + + TObject::Pointer o = f.GetPointer( ); + this->m_Graph->SetVertex( name, o ); + + } // fi + return( f.GetPointer( ) ); } else + return( this->GetFilter( name ) ); +} + +// ------------------------------------------------------------------------- +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 ) +{ +} + +// ------------------------------------------------------------------------- +vtkRenderWindowInteractor* cpPlugins::Interface::Workspace:: +GetSingleInteractor( ) +{ + return( this->m_SingleInteractor ); +} + +// ------------------------------------------------------------------------- +const vtkRenderWindowInteractor* cpPlugins::Interface::Workspace:: +GetSingleInteractor( ) const +{ + return( this->m_SingleInteractor ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Workspace:: +SetSingleInteractor( vtkRenderWindowInteractor* interactor ) +{ + this->m_SingleInteractor = interactor; +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface:: +SimpleMPRWidget* cpPlugins::Interface::Workspace:: +GetMPRViewer( ) +{ + return( this->m_MPRViewer ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface:: +SimpleMPRWidget* cpPlugins::Interface::Workspace:: +GetMPRViewer( ) const +{ + return( this->m_MPRViewer ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Workspace:: +SetMPRViewer( cpPlugins::Interface::SimpleMPRWidget* wdg ) +{ + this->m_MPRViewer = wdg; } // ------------------------------------------------------------------------- @@ -134,66 +205,141 @@ 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 = 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_AdjMatrix[ orig_filter ][ dest_filter ].push_back( + dest->SetInput( input_name, orig->GetOutputPort( output_name ) ); + this->m_Graph->AddEdge( + orig_filter, dest_filter, TConnection( output_name, input_name ) ); return( false ); } // ------------------------------------------------------------------------- -cpPlugins::Interface::Workspace:: -TParameters* cpPlugins::Interface::Workspace:: -GetParameters( const std::string& name ) +bool cpPlugins::Interface::Workspace:: +Connect( TData::Pointer* input_object, const std::string& input_name ) { - auto vIt = this->m_Vertices.find( name ); - if( vIt != this->m_Vertices.end( ) ) + auto port = this->m_ExposedInputPorts.find( input_name ); + if( port != this->m_ExposedInputPorts.end( ) ) { - TFilter* f = dynamic_cast< TFilter* >( vIt->second.GetPointer( ) ); - if( f != NULL ) - return( f->GetParameters( ) ); + TFilter* filter = this->GetFilter( port->second.first ); + if( filter != NULL ) + { + filter->SetInput( port->second.second, input_object ); + return( true ); + } else - return( NULL ); + 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 ) { - auto vIt = this->m_Vertices.find( name ); - if( vIt != this->m_Vertices.end( ) ) + return( false ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Workspace:: +ExposeInputPort( + const std::string& name, + const std::string& filter, const std::string& filter_input + ) +{ + this->m_ExposedInputPorts[ name ] = TExposedPort( filter, filter_input ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Workspace:: +ExposeOutputPort( + const std::string& name, + const std::string& filter, const std::string& filter_output + ) +{ + 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:: +RenameExposedInputPort( + const std::string& old_name, + const std::string& new_name + ) +{ + 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( ) + ) { - const TFilter* f = - dynamic_cast< const TFilter* >( vIt->second.GetPointer( ) ); - if( f != NULL ) - return( f->GetParameters( ) ); - else - return( NULL ); + this->m_ExposedInputPorts[ new_name ] = o->second; + this->m_ExposedInputPorts.erase( o ); } else - return( NULL ); + return( false ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::Workspace:: -Reduce( const std::string& name ) +RenameExposedOutputPort( + const std::string& old_name, + const std::string& new_name + ) +{ + 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 ); } // ------------------------------------------------------------------------- @@ -201,13 +347,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 +366,7 @@ 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* >( vIt->second.GetPointer( ) ); + TFilter* f = this->GetFilter( name ); if( f == NULL ) return( std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) + @@ -243,20 +377,4 @@ Execute( const std::string& name ) 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$