X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FProcessObject.cxx;h=364816a4d094ae5c2df701dec48228ecc929ae05;hb=6226e722a440b16cd35bb126353f6a14ff86bccf;hp=7d2a19257fe1340b2dfa9d30934bf6a04d178837;hpb=ad814fa27df55cd06a071e474e56efc27f9f8fa5;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index 7d2a192..364816a 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -1,165 +1,170 @@ #include +#include #ifdef cpPlugins_Interface_QT4 #include #include +#include #endif // cpPlugins_Interface_QT4 -#include +// ------------------------------------------------------------------------- +std::set< std::string > cpPlugins::Interface::ProcessObject:: +GetInputsNames( ) const +{ + std::set< std::string > names; + for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i ) + names.insert( i->first ); + return( names ); +} // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -Modified( ) const +std::set< std::string > cpPlugins::Interface::ProcessObject:: +GetOutputsNames( ) const { - if( this->m_ITKObject.IsNotNull( ) ) - this->m_ITKObject->Modified( ); - if( this->m_VTKObject.GetPointer( ) != NULL ) - this->m_VTKObject->Modified( ); - this->Superclass::Modified( ); + std::set< std::string > names; + for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i ) + names.insert( i->first ); + return( names ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -GetInputsNames( std::set< std::string >& names ) const +unsigned int cpPlugins::Interface::ProcessObject:: +GetNumberOfInputs( ) const { - names.clear( ); - auto dIt = this->m_Inputs.begin( ); - for( ; dIt != this->m_Inputs.end( ); ++dIt ) - names.insert( dIt->first ); + return( this->m_Inputs.size( ) ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -GetOutputsNames( std::set< std::string >& names ) const +unsigned int cpPlugins::Interface::ProcessObject:: +GetNumberOfOutputs( ) const { - names.clear( ); - auto dIt = this->m_Outputs.begin( ); - for( ; dIt != this->m_Outputs.end( ); ++dIt ) - names.insert( dIt->first ); + return( this->m_Outputs.size( ) ); } // ------------------------------------------------------------------------- -bool cpPlugins::Interface::ProcessObject:: -SetOutputObjectName( - const std::string& new_object_name, const std::string& output_name - ) +cpPlugins::Interface:: +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) { - auto oIt = this->m_Outputs.find( output_name ); - if( oIt != this->m_Outputs.end( ) ) + static OutputProcessObjectPort null_port; + auto i = this->m_Outputs.find( id ); + if( i == this->m_Outputs.end( ) ) { - this->m_OutputObjectsNames[ output_name ] = new_object_name; - this->Modified( ); - return( true ); + null_port = NULL; + return( null_port ); } else - return( false ); + return( i->second ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj ) +const cpPlugins::Interface:: +OutputProcessObjectPort& cpPlugins::Interface::ProcessObject:: +GetOutput( const std::string& id ) const { - _TDataContainer::iterator i = this->m_Inputs.find( id ); - if( i != this->m_Inputs.end( ) ) - { - i->second = dobj; - this->Modified( ); - - } // fi + 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 ); } // ------------------------------------------------------------------------- -std::string cpPlugins::Interface::ProcessObject:: -Update( ) +bool cpPlugins::Interface::ProcessObject:: +SetInput( const std::string& id, const OutputProcessObjectPort& port ) { - std::string r = ""; - - // Force upstream updates - _TDataContainer::iterator i = this->m_Inputs.begin( ); - for( ; i != this->m_Inputs.end( ) && r == ""; ++i ) - { - Self* src = dynamic_cast< Self* >( i->second->GetSource( ) ); - if( src != NULL ) - r = src->Update( ); - - } // rof - - // Current update - if( r == "" ) - r = this->_GenerateData( ); - - // Configure output names - auto oIt = this->m_Outputs.begin( ); - for( ; oIt != this->m_Outputs.end( ); ++oIt ) + auto i = this->m_Inputs.find( id ); + if( i != this->m_Inputs.end( ) ) { - auto nIt = this->m_OutputObjectsNames.find( oIt->first ); - if( nIt != this->m_OutputObjectsNames.end( ) ) - oIt->second->SetName( nIt->second ); + if( i->second.GetPointer( ) != port.GetPointer( ) ) + { + i->second = port; + this->Modified( ); - } // rof + } // 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( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -AddInteractor( vtkRenderWindowInteractor* interactor ) +Disconnect( ) { -#ifdef cpPlugins_Interface_QT4 - this->m_ParametersDialog->addInteractor( interactor ); -#endif // cpPlugins_Interface_QT4 + this->DisconnectInputs( ); + this->DisconnectOutputs( ); } // ------------------------------------------------------------------------- -cpPlugins::Interface::ProcessObject:: -DialogResult cpPlugins::Interface::ProcessObject:: -ExecConfigurationDialog( QWidget* parent ) +itk::ModifiedTimeType cpPlugins::Interface::ProcessObject:: +GetMTime( ) const { - DialogResult r = Self::DialogResult_Cancel; + auto params_time = this->m_Parameters->GetMTime( ); + auto filter_time = this->Superclass::GetMTime( ); + return( ( params_time < filter_time )? params_time: filter_time ); +} -#ifdef cpPlugins_Interface_QT4 +// ------------------------------------------------------------------------- +std::string cpPlugins::Interface::ProcessObject:: +Update( ) +{ + std::string r = ""; - if( QApplication::instance( ) != NULL ) + // Force upstream updates + auto i = this->m_Inputs.begin( ); + bool need_to_update = false; + for( ; i != this->m_Inputs.end( ) && r == ""; ++i ) { - if( this->m_ParametersDialog == NULL ) - this->m_ParametersDialog = new ParametersQtDialog( ); - this->m_ParametersDialog->setTitle( - this->GetClassName( ) + std::string( " basic configuration" ) - ); + 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( ); - this->m_ParametersDialog->setParent( NULL ); - this->m_ParametersDialog->setParameters( this->m_Parameters ); + } // fi - if( !( this->m_ParametersDialog->IsModal( ) ) ) - { - this->m_ParametersDialog->show( ); - r = Self::DialogResult_Modal; - } - else + } // fi + + } // rof + + // Current update + if( r == "" ) + { + if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update ) { - if( this->m_ParametersDialog->exec( ) == 1 ) - r = Self::DialogResult_NoModal; - else - r = Self::DialogResult_Cancel; + r = this->_GenerateData( ); + this->m_LastExecutionTime = this->GetMTime( ); } // fi - } - else - r = Self::DialogResult_Cancel; -#endif // cpPlugins_Interface_QT4 + } // fi + // Return error description, if any return( r ); } @@ -167,32 +172,45 @@ ExecConfigurationDialog( QWidget* parent ) cpPlugins::Interface::ProcessObject:: ProcessObject( ) : Superclass( ), - m_ITKObject( NULL ), - m_VTKObject( NULL ), + m_LastExecutionTime( 0 ), m_ParametersDialog( NULL ), - m_Plugins( 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( ) { + 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( ); -// ------------------------------------------------------------------------- -CPPLUGINS_PROVIDER_SOURCE( cpPlugins::Interface::ProcessObject, 1, 1 ); + } // fi +} // eof - $RCSfile$