X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FWorkspace.cxx;h=b37c2caa8b5c92d2418c6450515389847350f3a3;hb=1b600247da314fe62d007ca8a0ce24d0006931f4;hp=3c42481f7bcb6b797ab64e1ab63b1ef82e72eaf2;hpb=6885cd42cb7981803efb5c27c0a1a761084dc31c;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Workspace.cxx b/lib/cpPlugins/Interface/Workspace.cxx index 3c42481..b37c2ca 100644 --- a/lib/cpPlugins/Interface/Workspace.cxx +++ b/lib/cpPlugins/Interface/Workspace.cxx @@ -1,9 +1,12 @@ #include +#include +#include // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: Workspace( ) - : m_Interface( NULL ) + : m_Plugins( NULL ), + m_MPRViewer( NULL ) { this->m_Graph = TGraph::New( ); } @@ -16,26 +19,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,29 +57,144 @@ 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:: -CreateFilter( const std::string& filter, const std::string& name ) +HasFilter( const std::string& name ) const { - if( this->m_Interface == NULL ) + 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 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 ); + f->SetSingleInteractor( this->m_SingleInteractor ); + f->SetMPRViewer( this->m_MPRViewer ); + TObject::Pointer o = f.GetPointer( ); this->m_Graph->SetVertex( name, o ); - return( true ); - } - else - return( false ); + + } // 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; } // ------------------------------------------------------------------------- @@ -93,8 +211,8 @@ Connect( return( false ); // Real connection - dest->SetInput( input_name, orig->GetOutput< TData >( output_name ) ); - this->m_Graph->AddConnection( + dest->SetInput( input_name, orig->GetOutputPort( output_name ) ); + this->m_Graph->AddEdge( orig_filter, dest_filter, TConnection( output_name, input_name ) ); @@ -103,10 +221,10 @@ Connect( // ------------------------------------------------------------------------- bool cpPlugins::Interface::Workspace:: -Connect( TData* input_object, const std::string& input_name ) +Connect( TData::Pointer* 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 ) @@ -121,64 +239,6 @@ Connect( TData* input_object, const std::string& input_name ) return( false ); } -// ------------------------------------------------------------------------- -cpPlugins::Interface::Workspace:: -TParameters* cpPlugins::Interface::Workspace:: -GetParameters( const std::string& name ) -{ - TFilter* f = this->GetFilter( name ); - if( f != NULL ) - return( f->GetParameters( ) ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -const cpPlugins::Interface::Workspace:: -TParameters* cpPlugins::Interface::Workspace:: -GetParameters( const std::string& name ) const -{ - const TFilter* f = this->GetFilter( name ); - if( f != NULL ) - return( f->GetParameters( ) ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -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:: Reduce( const std::string& name ) @@ -188,72 +248,98 @@ Reduce( const std::string& name ) // ------------------------------------------------------------------------- void cpPlugins::Interface::Workspace:: -AddInputPort( +ExposeInputPort( const std::string& name, const std::string& filter, const std::string& filter_input ) { - this->m_InputPorts[ name ] = TGlobalPort( filter, filter_input ); + this->m_ExposedInputPorts[ name ] = TExposedPort( filter, filter_input ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Workspace:: -AddOutputPort( +ExposeOutputPort( const std::string& name, const std::string& filter, const std::string& filter_output ) { - this->m_OutputPorts[ name ] = TGlobalPort( filter, filter_output ); + this->m_ExposedOutputPorts[ name ] = TExposedPort( filter, filter_output ); } // ------------------------------------------------------------------------- -cpPlugins::Interface::Workspace:: -TData* cpPlugins::Interface::Workspace:: -GetOutput( const std::string& name ) +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 port = this->m_OutputPorts.find( name ); - if( port != this->m_OutputPorts.end( ) ) + 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( ) + ) { - TFilter* f = this->GetFilter( port->second.first ); - if( f != NULL ) - return( f->GetOutput< TData >( port->second.second ) ); - else - return( NULL ); + this->m_ExposedInputPorts[ new_name ] = o->second; + this->m_ExposedInputPorts.erase( o ); } else - return( NULL ); + return( false ); } // ------------------------------------------------------------------------- -const cpPlugins::Interface::Workspace:: -TData* cpPlugins::Interface::Workspace:: -GetOutput( const std::string& name ) const +bool cpPlugins::Interface::Workspace:: +RenameExposedOutputPort( + const std::string& old_name, + const std::string& new_name + ) { - auto port = this->m_OutputPorts.find( name ); - if( port != this->m_OutputPorts.end( ) ) + 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( ) + ) { - const TFilter* f = this->GetFilter( port->second.first ); - if( f != NULL ) - return( f->GetOutput< TData >( port->second.second ) ); - else - return( NULL ); + this->m_ExposedOutputPorts[ new_name ] = o->second; + this->m_ExposedOutputPorts.erase( o ); } else - return( NULL ); + return( false ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::Workspace:: -ClearInputPorts( ) +const cpPlugins::Interface::Workspace:: +TExposedPorts& cpPlugins::Interface::Workspace:: +GetExposedInputPorts( ) const { - this->m_InputPorts.clear( ); + return( this->m_ExposedInputPorts ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::Workspace:: -ClearOutputPorts( ) +const cpPlugins::Interface::Workspace:: +TExposedPorts& cpPlugins::Interface::Workspace:: +GetExposedOutputPorts( ) const { - this->m_OutputPorts.clear( ); + return( this->m_ExposedOutputPorts ); } // ------------------------------------------------------------------------- @@ -267,7 +353,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 ); if( lerr != "" ) err += lerr + std::string( "\n" ); @@ -277,7 +363,7 @@ Execute( ) // ------------------------------------------------------------------------- std::string cpPlugins::Interface::Workspace:: -Execute( const std::string& name, QWidget* p ) +Execute( const std::string& name ) { // Get filter TFilter* f = this->GetFilter( name ); @@ -288,16 +374,7 @@ Execute( const std::string& name, QWidget* p ) ); // Execute and return - if( p != NULL ) - { - auto diag_res = f->ExecConfigurationDialog( p ); - if( diag_res == TFilter::DialogResult_NoModal ) - return( f->Update( ) ); - else - return( "" ); - } - else - return( f->Update( ) ); + return( f->Update( ) ); } // eof - $RCSfile$