X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FProcessObject.cxx;h=6f3bd34e3d8e537e47282613974ae73f87548272;hb=24dc7fa44ff75dc9336d703b8243ce1e52ff3429;hp=f2499c212f1e28cc05e067a3f451c3309e96f8c8;hpb=61e052afc5b659224bbc85b7d15b93402ea7d5a7;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index f2499c2..6f3bd34 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -1,40 +1,79 @@ #include +#ifdef cpPlugins_Interface_QT4 +#include +#endif // cpPlugins_Interface_QT4 + +#include + // ------------------------------------------------------------------------- -cpPlugins::Interface::ProcessObject:: -ProcessObject( ) - : Superclass( ), - m_OutputsDisconnected( false ) +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:: -~ProcessObject( ) +bool cpPlugins::Interface::ProcessObject:: +IsInteractive( ) const { - this->_DeleteOutputs( ); + std::vector< std::string > names; + this->m_Parameters->GetNames( names ); + bool res = false; + auto i = names.begin( ); + for( ; i != names.end( ); ++i ) + { + TParameters::Type t = this->m_Parameters->GetType( *i ); + res |= ( t == TParameters::Point ); + res |= ( t == TParameters::Index ); + res |= ( t == TParameters::PointList ); + res |= ( t == TParameters::IndexList ); + + } // rof + return( res ); } // ------------------------------------------------------------------------- -std::string cpPlugins::Interface::ProcessObject:: -GetClassName( ) const +cpPlugins::Interface::ProcessObject:: +TParameters* cpPlugins::Interface::ProcessObject:: +GetParameters( ) { - return( "cpPlugins::Interface::ProcessObject" ); + return( this->m_Parameters.GetPointer( ) ); } // ------------------------------------------------------------------------- const cpPlugins::Interface::ProcessObject:: -TParameters& cpPlugins::Interface::ProcessObject:: -GetDefaultParameters( ) const +TParameters* cpPlugins::Interface::ProcessObject:: +GetParameters( ) const +{ + return( this->m_Parameters.GetPointer( ) ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface:: +Plugins* cpPlugins::Interface::ProcessObject:: +GetPlugins( ) { - return( this->m_DefaultParameters ); + return( this->m_Plugins ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface:: +Plugins* cpPlugins::Interface::ProcessObject:: +GetPlugins( ) const +{ + return( this->m_Plugins ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -SetParameters( const TParameters& params ) +SetPlugins( Plugins* p ) { - this->m_Parameters = params; + this->m_Plugins = p; } // ------------------------------------------------------------------------- @@ -52,59 +91,59 @@ GetNumberOfOutputs( ) const } // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -SetNumberOfInputs( unsigned int n ) +std::vector< std::string > cpPlugins::Interface::ProcessObject:: +GetInputsNames( ) const { - this->m_Inputs.clear( ); - this->m_Inputs.resize( n, NULL ); + std::vector< std::string > r; + auto dIt = this->m_Inputs.begin( ); + for( ; dIt != this->m_Inputs.end( ); ++dIt ) + r.push_back( dIt->first ); + return( r ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -SetNumberOfOutputs( unsigned int n ) +std::vector< std::string > cpPlugins::Interface::ProcessObject:: +GetOutputsNames( ) const { - this->_DeleteOutputs( ); - this->m_Outputs.clear( ); - this->m_Outputs.resize( n, NULL ); - this->m_OutputsDisconnected = false; + std::vector< std::string > r; + auto dIt = this->m_Outputs.begin( ); + for( ; dIt != this->m_Outputs.end( ); ++dIt ) + r.push_back( dIt->first ); + return( r ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -SetInput( - unsigned int idx, const cpPlugins::Interface::DataObject* dobj - ) +SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj ) { - if( idx < this->m_Inputs.size( ) ) - this->m_Inputs[ idx ] = dobj; -} + _TDataContainer::iterator i = this->m_Inputs.find( id ); + if( i != this->m_Inputs.end( ) ) + { + i->second = dobj; + this->Modified( ); -// ------------------------------------------------------------------------- -cpPlugins::Interface::DataObject* cpPlugins::Interface::ProcessObject:: -GetOutput( unsigned int idx ) -{ - if( idx < this->m_Outputs.size( ) ) - return( this->m_Outputs[ idx ] ); - else - return( NULL ); + } // fi } // ------------------------------------------------------------------------- std::string cpPlugins::Interface::ProcessObject:: Update( ) { - // Force upstream updates std::string r = ""; - for( unsigned int i = 0; i < this->m_Inputs.size( ) && r == ""; ++i ) - r = this->m_Inputs[ i ]->GetSource( )->Update( ); + + // 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( ); - this->m_OutputsDisconnected = false; - - } // fi // Return error description, if any return( r ); @@ -114,39 +153,82 @@ Update( ) void cpPlugins::Interface::ProcessObject:: DisconnectOutputs( ) { - this->m_OutputsDisconnected = true; - for( unsigned int idx = 0; idx < this->m_Outputs.size( ); ++idx ) - if( this->m_Outputs[ idx ] != NULL ) - this->m_Outputs[ idx ]->GetDataObject( )->DisconnectPipeline( ); + _TDataContainer::iterator i = this->m_Outputs.begin( ); + for( ; i != this->m_Outputs.end( ); ++i ) + if( i->second.IsNotNull( ) ) + i->second->DisconnectPipeline( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ProcessObject:: +AddInteractor( vtkRenderWindowInteractor* interactor ) +{ +#ifdef cpPlugins_Interface_QT4 + this->m_ParametersDialog->addInteractor( interactor ); +#endif // cpPlugins_Interface_QT4 } // ------------------------------------------------------------------------- -itk::DataObject* cpPlugins::Interface::ProcessObject:: -_GetInput( unsigned int idx ) +cpPlugins::Interface::ProcessObject:: +DialogResult cpPlugins::Interface::ProcessObject:: +ExecConfigurationDialog( QWidget* parent ) { - if( idx < this->m_Inputs.size( ) ) - return( this->m_Inputs[ idx ]->GetDataObject( ) ); + DialogResult r = Self::DialogResult_Cancel; + +#ifdef cpPlugins_Interface_QT4 + + this->m_ParametersDialog->setParent( NULL ); + this->m_ParametersDialog->setParameters( this->m_Parameters ); + + if( !( this->m_ParametersDialog->IsModal( ) ) ) + { + this->m_ParametersDialog->show( ); + r = Self::DialogResult_Modal; + } else - return( NULL ); + { + if( this->m_ParametersDialog->exec( ) == 1 ) + r = Self::DialogResult_NoModal; + else + r = Self::DialogResult_Cancel; + + } // fi + +#endif // cpPlugins_Interface_QT4 + + return( r ); } // ------------------------------------------------------------------------- -void cpPlugins::Interface::ProcessObject:: -_SetOutput( unsigned int idx, itk::DataObject* dobj ) +cpPlugins::Interface::ProcessObject:: +ProcessObject( ) + : Superclass( ), + m_ITKObject( NULL ), + m_VTKObject( NULL ), + m_Plugins( NULL ) +{ + this->m_Parameters = TParameters::New( ); + this->m_Parameters->SetProcessObject( this ); + + this->m_ParametersDialog = new ParametersQtDialog( ); + this->m_ParametersDialog->setTitle( + this->GetClassName( ) + std::string( " basic configuration" ) + ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::ProcessObject:: +~ProcessObject( ) { - if( idx < this->m_Outputs.size( ) ) - if( this->m_Outputs[ idx ] != NULL ) - this->m_Outputs[ idx ]->SetDataObject( dobj ); + delete this->m_ParametersDialog; } // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: -_DeleteOutputs( ) +_AddInput( const std::string& name ) { - if( !( this->m_OutputsDisconnected ) ) - for( unsigned int idx = 0; idx < this->m_Outputs.size( ); ++idx ) - if( this->m_Outputs[ idx ] != NULL ) - delete this->m_Outputs[ idx ]; + this->m_Inputs[ name ] = NULL; + this->Modified( ); } // eof - $RCSfile$