Clear( )
{
this->m_Filters.clear( );
- this->m_ExposedInputs.clear( );
- this->m_ExposedOutputs.clear( );
}
// -------------------------------------------------------------------------
GetFiltersNames( ) const
{
std::vector< std::string > n;
- for( auto i = this->m_Filters.begin( ); i != this->m_Filters.end( ); ++i )
- n.push_back( i->first );
+ for( auto i : this->m_Filters )
+ n.push_back( i.first );
return( n );
}
// -------------------------------------------------------------------------
cpPlugins::Interface::Workspace::
-TProcess* cpPlugins::Interface::Workspace::
+TFilter* cpPlugins::Interface::Workspace::
GetFilter( const std::string& name )
{
auto i = this->m_Filters.find( name );
// -------------------------------------------------------------------------
const cpPlugins::Interface::Workspace::
-TProcess* cpPlugins::Interface::Workspace::
+TFilter* cpPlugins::Interface::Workspace::
GetFilter( const std::string& name ) const
{
auto i = this->m_Filters.find( name );
TWidget* cpPlugins::Interface::Workspace::
GetWidget( const std::string& name )
{
- TProcess* process = this->GetFilter( name );
+ TFilter* process = this->GetFilter( name );
return( dynamic_cast< TWidget* >( process ) );
}
TWidget* cpPlugins::Interface::Workspace::
GetWidget( const std::string& name ) const
{
- const TProcess* process = this->GetFilter( name );
+ const TFilter* process = this->GetFilter( name );
return( dynamic_cast< const TWidget* >( process ) );
}
// -------------------------------------------------------------------------
cpPlugins::Interface::Workspace::
-TProcess* cpPlugins::Interface::Workspace::
-CreateFilter(
- const std::string& category,
- const std::string& filter,
- const std::string& name
- )
+TFilter* cpPlugins::Interface::Workspace::
+CreateFilter( const std::string& category, const std::string& filter )
{
typedef cpPlugins::BaseObjects::Widget _TWidget;
- TInterface::Pointer interface = TInterface::New( );
- TProcess::Pointer o = this->GetFilter( name );
- if( o.IsNull( ) )
+ TFilter::Pointer o = this->m_Plugins->CreateFilter( category, filter );
+ if( o.IsNotNull( ) )
{
- o = interface->CreateProcessObject( category, filter );
- if( o.IsNotNull( ) )
- {
- o->SetPrintExecution( this->m_PrintExecution );
- o->SetName( name );
-
- // Interactors
- for(
- auto i = this->m_Interactors.begin( );
- i != this->m_Interactors.end( );
- ++i
- )
- o->AddInteractor( *i );
-
- // Finish association
- this->m_Filters[ name ] = o;
-
- } // fi
+ // Choose a name
+ std::string name = filter;
+ while( this->GetFilter( name ) != NULL )
+ name += std::string( "_" );
+ o->SetPrintExecution( this->m_PrintExecution );
+ o->SetName( name );
+
+ // Interactors
+ for(
+ auto i = this->m_Interactors.begin( );
+ i != this->m_Interactors.end( );
+ ++i
+ )
+ o->AddInteractor( *i );
+
+ // Finish association
+ this->m_Filters[ name ] = o;
} // fi
return( o.GetPointer( ) );
this->m_Filters.erase( o );
// Rename exposed ports
- auto e = this->m_ExposedInputs.begin( );
- for( ; e != this->m_ExposedInputs.end( ); ++e )
- if( e->second.first == old_name )
- e->second.first = new_name;
- e = this->m_ExposedOutputs.begin( );
- for( ; e != this->m_ExposedOutputs.end( ); ++e )
- if( e->second.first == old_name )
- e->second.first = new_name;
+ /* TODO
+ auto e = this->m_ExposedInputs.begin( );
+ for( ; e != this->m_ExposedInputs.end( ); ++e )
+ if( e->second.first == old_name )
+ e->second.first = new_name;
+ e = this->m_ExposedOutputs.begin( );
+ for( ; e != this->m_ExposedOutputs.end( ); ++e )
+ if( e->second.first == old_name )
+ e->second.first = new_name;
+ */
return( true );
}
AddInteractor( vtkRenderWindowInteractor* iren )
{
if( iren != NULL )
+ {
this->m_Interactors.insert( iren );
+ for( auto f : this->m_Filters )
+ f.second->AddInteractor( iren );
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Workspace::
+Connect(
+ const std::string& origin_filter,
+ const std::string& origin_output,
+ const std::string& destination_filter,
+ const std::string& destination_input
+ )
+{
+ // Get filters and check pertinence
+ TFilter* origin = this->GetFilter( origin_filter );
+ TFilter* destination = this->GetFilter( destination_filter );
+ if( origin == NULL || destination == NULL )
+ return( false );
+ if( !( destination->HasInput( destination_input ) ) )
+ return( false );
+ if( !( origin->HasOutput( origin_output ) ) )
+ return( false );
+
+ // Check if there is room for a new connection
+ bool ok = true;
+ if( destination->IsInputMultiple( destination_input ) )
+ {
+ for(
+ unsigned int i = 0;
+ i < destination->GetInputSize( destination_input );
+ ++i
+ )
+ if(
+ destination->GetInput( destination_input, i )->GetSource( ) == origin
+ )
+ ok = false;
+ }
+ else
+ ok = ( destination->GetInput( destination_input ) == NULL );
+ if( ok )
+ destination->AddInput(
+ destination_input,
+ origin->GetOutput( origin_output )
+ );
+ return( ok );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Workspace::
+Connect(
+ TDataObject* input,
+ const std::string& destination_filter,
+ const std::string& destination_input
+ )
+{
+ // Get filters and check pertinence
+ if( input == NULL )
+ return( false );
+ TFilter* destination = this->GetFilter( destination_filter );
+ if( destination == NULL )
+ return( false );
+ if( !( destination->HasInput( destination_input ) ) )
+ return( false );
+
+ // Check if there is room for a new connection
+ bool ok = true;
+ if( destination->IsInputMultiple( destination_input ) )
+ {
+ for(
+ unsigned int i = 0;
+ i < destination->GetInputSize( destination_input );
+ ++i
+ )
+ if(
+ destination->GetInput( destination_input, i )->GetSource( ) ==
+ input->GetSource( )
+ )
+ ok = false;
+ }
+ else
+ ok = ( destination->GetInput( destination_input ) == NULL );
+ if( ok )
+ destination->AddInput(
+ destination_input,
+ input
+ );
+ return( ok );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Workspace::
+Disconnect(
+ const std::string& origin_filter,
+ const std::string& origin_output,
+ const std::string& destination_filter,
+ const std::string& destination_input
+ )
+{
+ // Get filters and check pertinence
+ TFilter* origin = this->GetFilter( origin_filter );
+ TFilter* destination = this->GetFilter( destination_filter );
+ if( origin == NULL || destination == NULL )
+ return( false );
+ if( !( destination->HasInput( destination_input ) ) )
+ return( false );
+ if( !( origin->HasOutput( origin_output ) ) )
+ return( false );
+
+ // Check if there is room for a new connection
+ bool ok = false;
+ unsigned int del_id = 0;
+ for(
+ unsigned int i = 0;
+ i < destination->GetInputSize( destination_input );
+ ++i
+ )
+ if(
+ destination->GetInput( destination_input, i )->GetSource( ) == origin
+ )
+ {
+ ok = true;
+ del_id = i;
+
+ } // fi
+ if( ok )
+ destination->DisconnectInput( destination_input, del_id );
+ return( ok );
}
// -------------------------------------------------------------------------
+/*
const cpPlugins::Interface::Workspace::
TExposedPorts& cpPlugins::Interface::Workspace::
GetExposedInputs( ) const
{
throw std::logic_error( "Disconnect 2" );
}
+*/
// -------------------------------------------------------------------------
void cpPlugins::Interface::Workspace::
-Execute( )
+Update( )
{
for( auto f = this->m_Filters.begin( ); f != this->m_Filters.end( ); ++f )
f->second->Update( );
// -------------------------------------------------------------------------
void cpPlugins::Interface::Workspace::
-Execute( const std::string& name )
+Update( const std::string& name )
{
auto filter = this->GetFilter( name );
if( filter != NULL )
: Superclass( ),
m_PrintExecution( false )
{
+ this->m_Plugins = TPlugins::New( );
}
// -------------------------------------------------------------------------
cpPlugins::Interface::Workspace::
~Workspace( )
{
- this->m_ExposedOutputs.clear( );
- this->m_ExposedInputs.clear( );
+ /* TODO
+ this->m_ExposedOutputs.clear( );
+ this->m_ExposedInputs.clear( );
+ */
this->m_Filters.clear( );
}