X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FParametersQtDialog.cxx;h=90393ffc9150fe4e3daebfc167b8374d123a9fb4;hb=00b54bc0344d74f31df8b93f7c28a07cfc8d6873;hp=9f6aadcdbc910fd960cbcb233ff19cc9b0b64c64;hpb=2eaf38cfdcbd2cfb0cc323dad6ded6bbeb436edf;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/ParametersQtDialog.cxx b/lib/cpPlugins/Interface/ParametersQtDialog.cxx index 9f6aadc..90393ff 100644 --- a/lib/cpPlugins/Interface/ParametersQtDialog.cxx +++ b/lib/cpPlugins/Interface/ParametersQtDialog.cxx @@ -3,96 +3,205 @@ #ifdef cpPlugins_Interface_QT4 #include -#include #include + +#include +#include + #include -#include #include #include #include -#include #include #include // ------------------------------------------------------------------------- -bool cpPlugins::Interface:: -ParametersQtDialog( - Parameters* parameters, const std::string& title, QWidget* parent - ) +#include +#include +#include + +class SingleSeedCommand + : public vtkCommand +{ +public: + static SingleSeedCommand* New( ) + { return( new SingleSeedCommand ); } + virtual void Execute( vtkObject* caller, unsigned long eid, void* data ) + { + // Get seed, avoiding segfaults!!! + if( eid != vtkCommand::PlacePointEvent || this->Dialog == NULL ) + return; + vtkSeedWidget* widget = dynamic_cast< vtkSeedWidget* >( caller ); + if( widget == NULL ) + return; + vtkSeedRepresentation* rep = widget->GetSeedRepresentation( ); + if( rep == NULL ) + return; + if( rep->GetNumberOfSeeds( ) == 0 ) + return; + double seed[ 3 ]; + rep->GetSeedWorldPosition( 0, seed ); + + // Delete all seeds (remember that this command is just for one seed) + while( rep->GetNumberOfSeeds( ) > 0 ) + widget->DeleteSeed( 0 ); + + if( this->Dialog->getParameters( )->HasIndex( this->Name ) ) + { + } + else if( this->Dialog->getParameters( )->HasPoint( this->Name ) ) + { + this->Dialog->getParameters( )->SetPoint( this->Name, 3, seed ); + this->Dialog->syncParameters( ); + auto filter = this->Dialog->getParameters( )->GetProcessObject( ); + if( filter != NULL ) + { + auto plugins = filter->GetPlugins( ); + if( plugins != NULL ) + { + auto app = plugins->GetApplication( ); + if( app != NULL ) + app->UpdateActualFilter( ); + + } // fi + + } // fi + + } // fi + } +protected: + SingleSeedCommand( ) + : vtkCommand( ), + Dialog( NULL ) + { + } + virtual ~SingleSeedCommand( ) + { + } + +public: + cpPlugins::Interface::ParametersQtDialog* Dialog; + std::string Name; +}; + +// ------------------------------------------------------------------------- +cpPlugins::Interface::ParametersQtDialog:: +ParametersQtDialog( QWidget* parent, Qt::WindowFlags f ) + : QDialog( parent, f ), + m_Parameters( NULL ), + m_IsModal( false ) { - // Create dialog with a simple layout - QDialog* dlg = new QDialog( parent ); - dlg->setWindowFlags( Qt::FramelessWindowHint ); - dlg->setWindowFlags( Qt::WindowTitleHint ); - QGridLayout* gridLayout = new QGridLayout( dlg ); - QVBoxLayout* verticalLayout = new QVBoxLayout( ); - - // Put a title - QLabel* dlg_title = new QLabel( dlg ); - dlg_title->setText( title.c_str( ) ); - verticalLayout->addWidget( dlg_title ); + this->m_Title = new QLabel( this ); + this->m_Title->setText( "Parameters dialog title" ); + + this->m_MainLayout = new QGridLayout( this ); + this->m_ToolsLayout = new QVBoxLayout( ); + this->m_ToolsLayout->addWidget( this->m_Title ); + this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::ParametersQtDialog:: +~ParametersQtDialog( ) +{ + delete this->m_Title; + delete this->m_ToolsLayout; + delete this->m_MainLayout; +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::ParametersQtDialog:: +IsModal( ) const +{ + return( this->m_IsModal ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface:: +Parameters* cpPlugins::Interface::ParametersQtDialog:: +getParameters( ) const +{ + return( this->m_Parameters ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +addInteractor( vtkRenderWindowInteractor* interactor ) +{ + this->m_Interactors.insert( interactor ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::ParametersQtDialog:: +TInteractors& cpPlugins::Interface::ParametersQtDialog:: +getInteractors( ) +{ + return( this->m_Interactors ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface::ParametersQtDialog:: +TInteractors& cpPlugins::Interface::ParametersQtDialog:: +getInteractors( ) const +{ + return( this->m_Interactors ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::ParametersQtDialog:: +setParameters( Parameters* parameters ) +{ + this->m_IsModal = true; + this->m_Parameters = parameters; + if( this->m_Parameters == NULL ) + return( false ); // Put values std::vector< std::string > names; - parameters->GetNames( names ); + this->m_Parameters->GetNames( names ); std::vector< std::string >::const_iterator nIt = names.begin( ); for( ; nIt != names.end( ); ++nIt ) { - Parameters::Type pt = parameters->GetType( *nIt ); - - /* TODO - enum Type - { - Bool, - Index, - Point, - StringList, - BoolList, - IntList, - UintList, - IndexList, - PointList, - NoType - }; - */ + Parameters::Type pt = this->m_Parameters->GetType( *nIt ); + QWidget* w_input = NULL; if( pt == Parameters::String ) { - QLineEdit* v_string = new QLineEdit( dlg ); + QLineEdit* v_string = new QLineEdit( this ); v_string->setText( "Enter some text!!!" ); w_input = v_string; } else if( pt == Parameters::Bool ) { - QCheckBox* v_bool = new QCheckBox( dlg ); + QCheckBox* v_bool = new QCheckBox( this ); v_bool->setText( "[ON/OFF]" ); - v_bool->setChecked( parameters->GetBool( *nIt ) ); + v_bool->setChecked( this->m_Parameters->GetBool( *nIt ) ); w_input = v_bool; } else if( pt == Parameters::Uint ) { - QSpinBox* v_uint = new QSpinBox( dlg ); + QSpinBox* v_uint = new QSpinBox( this ); v_uint->setMinimum( 0 ); v_uint->setMaximum( std::numeric_limits< int >::max( ) ); - v_uint->setValue( parameters->GetUint( *nIt ) ); + v_uint->setValue( this->m_Parameters->GetUint( *nIt ) ); w_input = v_uint; } else if( pt == Parameters::Int ) { - QSpinBox* v_int = new QSpinBox( dlg ); + QSpinBox* v_int = new QSpinBox( this ); v_int->setMinimum( -std::numeric_limits< int >::max( ) ); v_int->setMaximum( std::numeric_limits< int >::max( ) ); - v_int->setValue( parameters->GetInt( *nIt ) ); + v_int->setValue( this->m_Parameters->GetInt( *nIt ) ); w_input = v_int; } else if( pt == Parameters::Real ) { - QDoubleSpinBox* v_double = new QDoubleSpinBox( dlg ); + QDoubleSpinBox* v_double = new QDoubleSpinBox( this ); v_double->setDecimals( 3 ); v_double->setMinimum( -std::numeric_limits< double >::max( ) ); v_double->setMaximum( std::numeric_limits< double >::max( ) ); - v_double->setValue( parameters->GetReal( *nIt ) ); + v_double->setValue( this->m_Parameters->GetReal( *nIt ) ); w_input = v_double; } else if( @@ -103,8 +212,30 @@ ParametersQtDialog( ) { cpPlugins::Interface::ParametersListWidget* l_double = - new cpPlugins::Interface::ParametersListWidget( *nIt, dlg ); + new cpPlugins::Interface::ParametersListWidget( *nIt, this ); w_input = l_double; + } + else if( pt == Parameters::Point || pt == Parameters::Index ) + { + vtkSmartPointer< SingleSeedCommand > command = + vtkSmartPointer< SingleSeedCommand >::New( ); + command->Dialog = this; + command->Name = *nIt; + + auto iIt = this->m_Interactors.begin( ); + for( ; iIt != this->m_Interactors.end( ); ++iIt ) + { + TStyle* style = + dynamic_cast< TStyle* >( ( *iIt )->GetInteractorStyle( ) ); + if( style != NULL ) + { + style->SeedWidgetOn( ); + style->SetSeedWidgetCommand( command ); + + } // fi + + } // rof + this->m_IsModal = false; } // fi @@ -113,66 +244,101 @@ ParametersQtDialog( { w_input->setObjectName( QString( nIt->c_str( ) ) ); - QHBoxLayout* horizontalLayout = new QHBoxLayout( ); - QLabel* label = new QLabel( dlg ); + QHBoxLayout* new_layout = new QHBoxLayout( ); + QLabel* label = new QLabel( this ); label->setText( QString( nIt->c_str( ) ) ); - horizontalLayout->addWidget( label ); - horizontalLayout->addWidget( w_input ); - verticalLayout->addLayout( horizontalLayout ); + new_layout->addWidget( label ); + new_layout->addWidget( w_input ); + this->m_ToolsLayout->addLayout( new_layout ); } // fi } // rof + return( this->m_IsModal ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +setTitle( const std::string& title ) +{ + this->m_Title->setText( title.c_str( ) ); +} + +// ------------------------------------------------------------------------- +int cpPlugins::Interface::ParametersQtDialog:: +exec( ) +{ + if( !this->m_IsModal ) + return( 0 ); // Add buttons QDialogButtonBox* bb = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel ); - QObject::connect( bb, SIGNAL( accepted( ) ), dlg, SLOT( accept( ) ) ); - QObject::connect( bb, SIGNAL( rejected( ) ), dlg, SLOT( reject( ) ) ); - verticalLayout->addWidget( bb ); - gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 ); - - // Execute - QMetaObject::connectSlotsByName( dlg ); - if( !( dlg->exec( ) ) ) - return( false ); + QObject::connect( bb, SIGNAL( accepted( ) ), this, SLOT( accept( ) ) ); + QObject::connect( bb, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) ); + this->m_ToolsLayout->addWidget( bb ); - // Get values back - nIt = names.begin( ); + int ret = this->QDialog::exec( ); + if( ret == 1 ) + this->syncParameters( ); + return( ret ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +show( ) +{ + if( this->m_IsModal ) + return; + + this->QDialog::show( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +syncParameters( ) +{ + if( this->m_Parameters == NULL ) + return; + + // Get values + std::vector< std::string > names; + this->m_Parameters->GetNames( names ); + std::vector< std::string >::const_iterator nIt = names.begin( ); for( ; nIt != names.end( ); ++nIt ) { - Parameters::Type pt = parameters->GetType( *nIt ); + Parameters::Type pt = this->m_Parameters->GetType( *nIt ); + if( pt == Parameters::String ) { - QLineEdit* v_string = dlg->findChild< QLineEdit* >( nIt->c_str( ) ); - if( v_string != NULL ) - parameters->SetString( *nIt, v_string->text( ).toStdString( ) ); + QLineEdit* v = this->findChild< QLineEdit* >( nIt->c_str( ) ); + if( v != NULL ) + this->m_Parameters->SetString( *nIt, v->text( ).toStdString( ) ); } else if( pt == Parameters::Bool ) { - QCheckBox* v_bool = dlg->findChild< QCheckBox* >( nIt->c_str( ) ); - if( v_bool != NULL ) - parameters->SetBool( *nIt, v_bool->isChecked( ) ); + QCheckBox* v = this->findChild< QCheckBox* >( nIt->c_str( ) ); + if( v != NULL ) + this->m_Parameters->SetBool( *nIt, v->isChecked( ) ); } else if( pt == Parameters::Uint ) { - QSpinBox* v_uint = dlg->findChild< QSpinBox* >( nIt->c_str( ) ); - if( v_uint != NULL ) - parameters->SetUint( *nIt, v_uint->value( ) ); + QSpinBox* v = this->findChild< QSpinBox* >( nIt->c_str( ) ); + if( v != NULL ) + this->m_Parameters->SetUint( *nIt, v->value( ) ); } else if( pt == Parameters::Int ) { - QSpinBox* v_int = dlg->findChild< QSpinBox* >( nIt->c_str( ) ); - if( v_int != NULL ) - parameters->SetInt( *nIt, v_int->value( ) ); + QSpinBox* v = this->findChild< QSpinBox* >( nIt->c_str( ) ); + if( v != NULL ) + this->m_Parameters->SetInt( *nIt, v->value( ) ); } else if( pt == Parameters::Real ) { - QDoubleSpinBox* v_double = - dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) ); - if( v_double != NULL ) - parameters->SetReal( *nIt, v_double->value( ) ); + QDoubleSpinBox* v = this->findChild< QDoubleSpinBox* >( nIt->c_str( ) ); + if( v != NULL ) + this->m_Parameters->SetReal( *nIt, v->value( ) ); } else if( pt == Parameters::StringList || @@ -181,46 +347,124 @@ ParametersQtDialog( pt == Parameters::RealList ) { - cpPlugins::Interface::ParametersListWidget* l_double = - dlg->findChild< cpPlugins::Interface::ParametersListWidget* >( + cpPlugins::Interface::ParametersListWidget* lst = + this->findChild< cpPlugins::Interface::ParametersListWidget* >( nIt->c_str( ) ); - if( l_double != NULL ) + if( lst != NULL ) { if( pt == Parameters::StringList ) { - std::vector< std::string > values = l_double->GetStringValues( ); + this->m_Parameters->ClearStringList( *nIt ); + std::vector< std::string > values = lst->GetStringValues( ); for( int r = 0; r < values.size( ); ++r ) - parameters->AddToStringList( *nIt, values[ r ] ); + this->m_Parameters->AddToStringList( *nIt, values[ r ] ); } else if( pt == Parameters::IntList ) { - std::vector< int > values = l_double->GetIntValues( ); + this->m_Parameters->ClearIntList( *nIt ); + std::vector< int > values = lst->GetIntValues( ); for( int r = 0; r < values.size( ); ++r ) - parameters->AddToIntList( *nIt, values[ r ] ); + this->m_Parameters->AddToIntList( *nIt, values[ r ] ); } else if( pt == Parameters::UintList ) { - std::vector< unsigned int > values = l_double->GetUintValues( ); + this->m_Parameters->ClearUintList( *nIt ); + std::vector< unsigned int > values = lst->GetUintValues( ); for( int r = 0; r < values.size( ); ++r ) - parameters->AddToUintList( *nIt, values[ r ] ); + this->m_Parameters->AddToUintList( *nIt, values[ r ] ); } else if( pt == Parameters::RealList ) { - std::vector< double > values = l_double->GetDoubleValues( ); + this->m_Parameters->ClearRealList( *nIt ); + std::vector< double > values = lst->GetDoubleValues( ); for( int r = 0; r < values.size( ); ++r ) - parameters->AddToRealList( *nIt, values[ r ] ); + this->m_Parameters->AddToRealList( *nIt, values[ r ] ); } // fi } // fi - + } + else if( pt == Parameters::Point || pt == Parameters::Index ) + { } // fi } // rof - return( true ); } + + + + + + + + +/* TODO + enum Type + { + Index, + Point, + StringList, + BoolList, + IntList, + UintList, + IndexList, + PointList, + Choices, + NoType + }; +*/ +/* + } + else if( + pt == Parameters::StringList || + pt == Parameters::IntList || + pt == Parameters::UintList || + pt == Parameters::RealList + ) + { + cpPlugins::Interface::ParametersListWidget* lst = + this->findChild< cpPlugins::Interface::ParametersListWidget* >( + nIt->c_str( ) + ); + if( lst != NULL ) + { + if( pt == Parameters::StringList ) + { + std::vector< std::string > values = lst->GetStringValues( ); + for( int r = 0; r < values.size( ); ++r ) + this->m_Parameters->AddToStringList( *nIt, values[ r ] ); + } + else if( pt == Parameters::IntList ) + { + std::vector< int > values = lst->GetIntValues( ); + for( int r = 0; r < values.size( ); ++r ) + this->m_Parameters->AddToIntList( *nIt, values[ r ] ); + } + else if( pt == Parameters::UintList ) + { + std::vector< unsigned int > values = lst->GetUintValues( ); + for( int r = 0; r < values.size( ); ++r ) + this->m_Parameters->AddToUintList( *nIt, values[ r ] ); + } + else if( pt == Parameters::RealList ) + { + std::vector< double > values = lst->GetDoubleValues( ); + for( int r = 0; r < values.size( ); ++r ) + this->m_Parameters->AddToRealList( *nIt, values[ r ] ); + + } // fi + + } // fi + + } // fi + + } // rof + return( true ); + } +*/ + #endif // cpPlugins_Interface_QT4 // eof - $RCSfile$