X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FWorkspace.cxx;h=022f9faa0babc181feed2ff42cce0468cb5cbcd2;hb=3ac87d29be6f3484efcfb3bcc204b7f99faa1eed;hp=dfe66d9bf51ba197638a23eba5815f2ec7c20c93;hpb=c06908465eb6da50572779f423d1e2c9e03b68dd;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Workspace.cxx b/lib/cpPlugins/Interface/Workspace.cxx index dfe66d9..022f9fa 100644 --- a/lib/cpPlugins/Interface/Workspace.cxx +++ b/lib/cpPlugins/Interface/Workspace.cxx @@ -3,7 +3,7 @@ // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: Workspace( ) - : m_Interface( NULL ) + : m_Plugins( NULL ) { this->m_Graph = TGraph::New( ); } @@ -16,26 +16,26 @@ cpPlugins::Interface::Workspace:: // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: -TInterface* cpPlugins::Interface::Workspace:: -GetInterface( ) +TPlugins* cpPlugins::Interface::Workspace:: +GetPlugins( ) { - return( this->m_Interface ); + return( this->m_Plugins ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::Workspace:: -SetInterface( TInterface* i ) +const cpPlugins::Interface::Workspace:: +TPlugins* cpPlugins::Interface::Workspace:: +GetPlugins( ) const { - if( this->m_Interface != i ) - this->m_Interface = i; + return( this->m_Plugins ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Workspace:: -Clear( ) +SetPlugins( TPlugins* i ) { - if( this->m_Graph.IsNotNull( ) ) - this->m_Graph->Clear( ); + if( this->m_Plugins != i ) + this->m_Plugins = i; } // ------------------------------------------------------------------------- @@ -54,17 +54,65 @@ GetGraph( ) const return( this->m_Graph ); } +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Workspace:: +Clear( ) +{ + if( this->m_Graph.IsNotNull( ) ) + this->m_Graph->Clear( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Workspace:: +ClearConnections( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Workspace:: +TFilter* cpPlugins::Interface::Workspace:: +GetFilter( const std::string& name ) +{ + TFilter* f = + dynamic_cast< TFilter* >( + this->m_Graph->GetVertex( name ).GetPointer( ) + ); + return( f ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface::Workspace:: +TFilter* cpPlugins::Interface::Workspace:: +GetFilter( const std::string& name ) const +{ + 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_Interface == NULL ) + 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 ); @@ -79,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( @@ -94,7 +162,7 @@ Connect( // 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 ) ); @@ -105,8 +173,8 @@ Connect( bool cpPlugins::Interface::Workspace:: Connect( TData* input_object, const std::string& input_name ) { - auto port = this->m_InputPorts.find( input_name ); - if( port != this->m_InputPorts.end( ) ) + auto port = this->m_ExposedInputPorts.find( input_name ); + if( port != this->m_ExposedInputPorts.end( ) ) { TFilter* filter = this->GetFilter( port->second.first ); if( filter != NULL ) @@ -122,99 +190,116 @@ Connect( TData* input_object, const std::string& input_name ) } // ------------------------------------------------------------------------- -cpPlugins::Interface::Workspace:: -TParameters* cpPlugins::Interface::Workspace:: -GetParameters( const std::string& name ) +bool cpPlugins::Interface::Workspace:: +Reduce( const std::string& name ) { - TFilter* f = this->GetFilter( name ); - if( f != NULL ) - return( f->GetParameters( ) ); - else - return( NULL ); + return( false ); } // ------------------------------------------------------------------------- -const cpPlugins::Interface::Workspace:: -TParameters* cpPlugins::Interface::Workspace:: -GetParameters( const std::string& name ) const +void cpPlugins::Interface::Workspace:: +ExposeInputPort( + const std::string& name, + const std::string& filter, const std::string& filter_input + ) { - const TFilter* f = this->GetFilter( name ); - if( f != NULL ) - return( f->GetParameters( ) ); - else - return( NULL ); + this->m_ExposedInputPorts[ name ] = TExposedPort( filter, filter_input ); } // ------------------------------------------------------------------------- -cpPlugins::Interface::Workspace:: -TFilter* cpPlugins::Interface::Workspace:: -GetFilter( const std::string& name ) +void cpPlugins::Interface::Workspace:: +ExposeOutputPort( + const std::string& name, + const std::string& filter, const std::string& filter_output + ) { - TFilter* f = - dynamic_cast< TFilter* >( - this->m_Graph->GetVertex( name ).GetPointer( ) - ); - return( f ); + this->m_ExposedOutputPorts[ name ] = TExposedPort( filter, filter_output ); } // ------------------------------------------------------------------------- -const cpPlugins::Interface::Workspace:: -TFilter* cpPlugins::Interface::Workspace:: -GetFilter( const std::string& name ) const +void cpPlugins::Interface::Workspace:: +HideInputPort( const std::string& name ) { - const TFilter* f = - dynamic_cast< const TFilter* >( - this->m_Graph->GetVertex( name ).GetPointer( ) - ); - return( f ); + 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 ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::Workspace:: -AddInputPort( - const std::string& name, - const std::string& filter, const std::string& filter_input - ) +const cpPlugins::Interface::Workspace:: +TExposedPorts& cpPlugins::Interface::Workspace:: +GetExposedInputPorts( ) const { - std::cout << name << " " << filter << " " << filter_input << std::endl; - - this->m_InputPorts[ name ] = TGlobalPort( filter, filter_input ); + return( this->m_ExposedInputPorts ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::Workspace:: -AddOutputPort( - const std::string& name, - const std::string& filter, const std::string& filter_output - ) +const cpPlugins::Interface::Workspace:: +TExposedPorts& cpPlugins::Interface::Workspace:: +GetExposedOutputPorts( ) const { - this->m_OutputPorts[ name ] = TGlobalPort( filter, filter_output ); + return( this->m_ExposedOutputPorts ); } // ------------------------------------------------------------------------- +/* TODO 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( ) ) + auto port = this->m_ExposedOutputPorts.find( name ); + if( port != this->m_ExposedOutputPorts.end( ) ) { TFilter* f = this->GetFilter( port->second.first ); if( f != NULL ) @@ -231,8 +316,8 @@ 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( ) ) + auto port = this->m_ExposedOutputPorts.find( name ); + if( port != this->m_ExposedOutputPorts.end( ) ) { const TFilter* f = this->GetFilter( port->second.first ); if( f != NULL ) @@ -248,19 +333,20 @@ GetOutput( const std::string& name ) const void cpPlugins::Interface::Workspace:: ClearInputPorts( ) { - this->m_InputPorts.clear( ); + this->m_ExposedInputPorts.clear( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Workspace:: ClearOutputPorts( ) { - this->m_OutputPorts.clear( ); + this->m_ExposedOutputPorts.clear( ); } +*/ // ------------------------------------------------------------------------- std::string cpPlugins::Interface::Workspace:: -Execute( ) +Execute( QWidget* p ) { // Find sinks std::set< std::string > sinks = this->m_Graph->GetSinks( ); @@ -269,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" );