X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FProcessObject.cxx;h=364816a4d094ae5c2df701dec48228ecc929ae05;hb=6226e722a440b16cd35bb126353f6a14ff86bccf;hp=f0d8d52886531aa72bcf80096c28d622a04cb925;hpb=ec99f46f898bfcd579161f1b2c28f8d9b2c8f333;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index f0d8d52..364816a 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -1,34 +1,30 @@ #include +#include #ifdef cpPlugins_Interface_QT4 +#include #include +#include #endif // cpPlugins_Interface_QT4 // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -Modified( ) const -{ - if( this->m_ITKObject.IsNotNull( ) ) - this->m_ITKObject->Modified( ); - if( this->m_VTKObject.GetPointer( ) != NULL ) - this->m_VTKObject->Modified( ); - this->Superclass::Modified( ); -} - -// ------------------------------------------------------------------------- -cpPlugins::Interface::ProcessObject:: -TParameters* cpPlugins::Interface::ProcessObject:: -GetParameters( ) +std::set< std::string > cpPlugins::Interface::ProcessObject:: +GetInputsNames( ) const { - return( this->m_Parameters.GetPointer( ) ); + std::set< std::string > names; + for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i ) + names.insert( i->first ); + return( names ); } // ------------------------------------------------------------------------- -const cpPlugins::Interface::ProcessObject:: -TParameters* cpPlugins::Interface::ProcessObject:: -GetParameters( ) const +std::set< std::string > cpPlugins::Interface::ProcessObject:: +GetOutputsNames( ) const { - return( this->m_Parameters.GetPointer( ) ); + std::set< std::string > names; + for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i ) + names.insert( i->first ); + return( names ); } // ------------------------------------------------------------------------- @@ -46,89 +42,129 @@ GetNumberOfOutputs( ) const } // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj ) +cpPlugins::Interface:: +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) { - _TDataContainer::iterator i = this->m_Inputs.find( id ); - if( i != this->m_Inputs.end( ) ) + static OutputProcessObjectPort null_port; + auto i = this->m_Outputs.find( id ); + if( i == this->m_Outputs.end( ) ) { - i->second = dobj; - this->Modified( ); - - } // fi + null_port = NULL; + return( null_port ); + } + else + return( i->second ); } // ------------------------------------------------------------------------- -std::string cpPlugins::Interface::ProcessObject:: -Update( ) +const cpPlugins::Interface:: +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) const { - std::string r = ""; + static const OutputProcessObjectPort null_port; + auto i = this->m_Outputs.find( id ); + if( i == this->m_Outputs.end( ) ) + return( null_port ); + else + return( i->second ); +} - // Force upstream updates - _TDataContainer::iterator i = this->m_Inputs.begin( ); - for( ; i != this->m_Inputs.end( ) && r == ""; ++i ) +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::ProcessObject:: +SetInput( const std::string& id, const OutputProcessObjectPort& port ) +{ + auto i = this->m_Inputs.find( id ); + if( i != this->m_Inputs.end( ) ) { - Self* src = dynamic_cast< Self* >( i->second->GetSource( ) ); - if( src != NULL ) - r = src->Update( ); - - } // rof + if( i->second.GetPointer( ) != port.GetPointer( ) ) + { + i->second = port; + this->Modified( ); - // Current update - if( r == "" ) - r = this->_GenerateData( ); + } // fi + return( true ); + } + else + return( false ); +} - // Return error description, if any - return( r ); +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ProcessObject:: +DisconnectInputs( ) +{ + auto i = this->m_Inputs.begin( ); + for( ; i != this->m_Inputs.end( ); ++i ) + i->second = NULL; + this->Modified( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: DisconnectOutputs( ) { - _TDataContainer::iterator i = this->m_Outputs.begin( ); + auto i = this->m_Outputs.begin( ); for( ; i != this->m_Outputs.end( ); ++i ) - if( i->second.IsNotNull( ) ) - i->second->DisconnectPipeline( ); + if( i->second.IsValid( ) ) + i->second->DisconnectFromPipeline( ); + this->Modified( ); } // ------------------------------------------------------------------------- -bool cpPlugins::Interface::ProcessObject:: -ExecConfigurationDialog( QWidget* parent ) +void cpPlugins::Interface::ProcessObject:: +Disconnect( ) { - bool r = false; + this->DisconnectInputs( ); + this->DisconnectOutputs( ); +} -#ifdef cpPlugins_Interface_QT4 +// ------------------------------------------------------------------------- +itk::ModifiedTimeType cpPlugins::Interface::ProcessObject:: +GetMTime( ) const +{ + auto params_time = this->m_Parameters->GetMTime( ); + auto filter_time = this->Superclass::GetMTime( ); + return( ( params_time < filter_time )? params_time: filter_time ); +} + +// ------------------------------------------------------------------------- +std::string cpPlugins::Interface::ProcessObject:: +Update( ) +{ + std::string r = ""; - if( this->m_ParametersDialog == NULL ) + // Force upstream updates + auto i = this->m_Inputs.begin( ); + bool need_to_update = false; + for( ; i != this->m_Inputs.end( ) && r == ""; ++i ) { - this->m_ParametersDialog = new ParametersQtDialog( parent ); - this->m_ParametersDialog->setTitle( - this->GetClassName( ) + std::string( " basic configuration" ) - ); - this->m_ParametersDialog->setParameters( this->m_Parameters ); + if( i->second.IsValid( ) ) + { + Self* src = dynamic_cast< Self* >( i->second->GetSource( ) ); + if( src != NULL ) + { + need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) ); + r = src->Update( ); - } // fi + } // fi + + } // fi - if( !( this->m_ParametersDialog->IsModal( ) ) ) + } // rof + + // Current update + if( r == "" ) { - this->m_ParametersDialog->show( ); - r = true; - } - else - r = ( this->m_ParametersDialog->exec( ) == 1 ); - /* - r = cpPlugins::Interface::ParametersQtDialog( - this->m_Parameters, - this->GetClassName( ) + std::string( " basic configuration" ), - parent - ); - if( r ) - // TODO: !!! this->m_Parameters = parameters; - */ + if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update ) + { + r = this->_GenerateData( ); + this->m_LastExecutionTime = this->GetMTime( ); -#endif // cpPlugins_Interface_QT4 + } // fi + + } // fi + // Return error description, if any return( r ); } @@ -136,27 +172,45 @@ ExecConfigurationDialog( QWidget* parent ) cpPlugins::Interface::ProcessObject:: ProcessObject( ) : Superclass( ), - m_ITKObject( NULL ), - m_VTKObject( NULL ), - m_ParametersDialog( NULL ) + m_LastExecutionTime( 0 ), + m_ParametersDialog( NULL ), + m_MPRViewer( NULL ) { this->m_Parameters = TParameters::New( ); + this->m_Parameters->SetProcessObject( this ); + +#ifdef cpPlugins_Interface_QT4 + if( QApplication::instance( ) != NULL ) + { + this->m_ParametersDialog = new ParametersQtDialog( ); + this->m_ParametersDialog->setParameters( this->m_Parameters ); + + } // fi +#endif // cpPlugins_Interface_QT4 } // ------------------------------------------------------------------------- cpPlugins::Interface::ProcessObject:: ~ProcessObject( ) { - if( this->m_ParametersDialog == NULL ) + this->Disconnect( ); + if( this->m_ParametersDialog != NULL ) delete this->m_ParametersDialog; } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -_AddInput( const std::string& name ) +_AddInput( const std::string& name, bool required ) { - this->m_Inputs[ name ] = NULL; - this->Modified( ); +// typedef typename _TInputs::value_type _TValue; + auto i = this->m_Inputs.find( name ); + if( i == this->m_Inputs.end( ) ) + { + InputProcessObjectPort new_port( required ); + this->m_Inputs[ name ] = new_port; + this->Modified( ); + + } // fi } // eof - $RCSfile$