X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FParametersQtDialog.cxx;h=90393ffc9150fe4e3daebfc167b8374d123a9fb4;hb=003b7bc4f88cbe4aa6cc27fcd16b8cda94eba9be;hp=5a669832393aa1cf8321e1d8fc576244383ebabb;hpb=7d66cc1aeec6d5bbcd4c963fe4115e4d64eaee67;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/ParametersQtDialog.cxx b/lib/cpPlugins/Interface/ParametersQtDialog.cxx index 5a66983..90393ff 100644 --- a/lib/cpPlugins/Interface/ParametersQtDialog.cxx +++ b/lib/cpPlugins/Interface/ParametersQtDialog.cxx @@ -6,11 +6,8 @@ #include -#include -#include -#include -#include -#include +#include +#include #include #include @@ -19,13 +16,81 @@ #include #include +// ------------------------------------------------------------------------- +#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 ), - m_Interactor( NULL ) + m_IsModal( false ) { this->m_Title = new QLabel( this ); this->m_Title->setText( "Parameters dialog title" ); @@ -41,11 +106,8 @@ cpPlugins::Interface::ParametersQtDialog:: ~ParametersQtDialog( ) { delete this->m_Title; - delete this->m_MainLayout; delete this->m_ToolsLayout; - - for( unsigned int i = 0; i < this->m_Widgets.size( ); ++i ) - this->m_Widgets[ i ]->Delete( ); + delete this->m_MainLayout; } // ------------------------------------------------------------------------- @@ -65,9 +127,25 @@ getParameters( ) const // ------------------------------------------------------------------------- void cpPlugins::Interface::ParametersQtDialog:: -setInteractor( vtkRenderWindowInteractor* interactor ) +addInteractor( vtkRenderWindowInteractor* interactor ) +{ + this->m_Interactors.insert( interactor ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::ParametersQtDialog:: +TInteractors& cpPlugins::Interface::ParametersQtDialog:: +getInteractors( ) { - this->m_Interactor = interactor; + return( this->m_Interactors ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface::ParametersQtDialog:: +TInteractors& cpPlugins::Interface::ParametersQtDialog:: +getInteractors( ) const +{ + return( this->m_Interactors ); } // ------------------------------------------------------------------------- @@ -139,26 +217,25 @@ setParameters( Parameters* parameters ) } else if( pt == Parameters::Point || pt == Parameters::Index ) { - if( this->m_Interactor != NULL ) + 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 ) { - // Create a point widget and its representation - vtkSmartPointer< vtkPointHandleRepresentation3D > handle = - vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); - handle->GetProperty( )->SetColor( 1, 0, 0 ); - vtkSmartPointer< vtkSeedRepresentation > rep = - vtkSmartPointer< vtkSeedRepresentation >::New( ); - rep->SetHandleRepresentation( handle ); - - cpExtensions::Interaction::SeedWidget* widget = - cpExtensions::Interaction::SeedWidget::New( ); - widget->SetInteractor( this->m_Interactor ); - widget->SetRepresentation( rep ); - widget->On( ); - - this->m_Widgets.push_back( widget ); - this->m_IsModal = false; + TStyle* style = + dynamic_cast< TStyle* >( ( *iIt )->GetInteractorStyle( ) ); + if( style != NULL ) + { + style->SeedWidgetOn( ); + style->SetSeedWidgetCommand( command ); - } // fi + } // fi + + } // rof + this->m_IsModal = false; } // fi @@ -202,7 +279,10 @@ exec( ) QObject::connect( bb, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) ); this->m_ToolsLayout->addWidget( bb ); - return( this->QDialog::exec( ) ); + int ret = this->QDialog::exec( ); + if( ret == 1 ) + this->syncParameters( ); + return( ret ); } // ------------------------------------------------------------------------- @@ -219,7 +299,97 @@ show( ) void cpPlugins::Interface::ParametersQtDialog:: syncParameters( ) { - std::cout << "TODO: SyncParameters" << std::endl; + 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 = this->m_Parameters->GetType( *nIt ); + + if( pt == Parameters::String ) + { + 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 = this->findChild< QCheckBox* >( nIt->c_str( ) ); + if( v != NULL ) + this->m_Parameters->SetBool( *nIt, v->isChecked( ) ); + } + else if( pt == Parameters::Uint ) + { + 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 = this->findChild< QSpinBox* >( nIt->c_str( ) ); + if( v != NULL ) + this->m_Parameters->SetInt( *nIt, v->value( ) ); + } + else if( pt == Parameters::Real ) + { + QDoubleSpinBox* v = this->findChild< QDoubleSpinBox* >( nIt->c_str( ) ); + if( v != NULL ) + this->m_Parameters->SetReal( *nIt, v->value( ) ); + } + 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 ) + { + this->m_Parameters->ClearStringList( *nIt ); + 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 ) + { + this->m_Parameters->ClearIntList( *nIt ); + 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 ) + { + this->m_Parameters->ClearUintList( *nIt ); + 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 ) + { + this->m_Parameters->ClearRealList( *nIt ); + std::vector< double > values = lst->GetDoubleValues( ); + for( int r = 0; r < values.size( ); ++r ) + this->m_Parameters->AddToRealList( *nIt, values[ r ] ); + + } // fi + + } // fi + } + else if( pt == Parameters::Point || pt == Parameters::Index ) + { + } // fi + + } // rof } @@ -246,148 +416,6 @@ syncParameters( ) }; */ /* - bool cpPlugins::Interface:: - ParametersQtDialog( - Parameters* parameters, const std::string& title, QWidget* parent - ) - { - // 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 ); - - // Put 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 = this->m_Parameters->GetType( *nIt ); - - QWidget* w_input = NULL; - if( pt == Parameters::String ) - { - QLineEdit* v_string = new QLineEdit( dlg ); - v_string->setText( "Enter some text!!!" ); - w_input = v_string; - } - else if( pt == Parameters::Bool ) - { - QCheckBox* v_bool = new QCheckBox( dlg ); - v_bool->setText( "[ON/OFF]" ); - v_bool->setChecked( this->m_Parameters->GetBool( *nIt ) ); - w_input = v_bool; - } - else if( pt == Parameters::Uint ) - { - QSpinBox* v_uint = new QSpinBox( dlg ); - v_uint->setMinimum( 0 ); - v_uint->setMaximum( std::numeric_limits< int >::max( ) ); - v_uint->setValue( this->m_Parameters->GetUint( *nIt ) ); - w_input = v_uint; - } - else if( pt == Parameters::Int ) - { - QSpinBox* v_int = new QSpinBox( dlg ); - v_int->setMinimum( -std::numeric_limits< int >::max( ) ); - v_int->setMaximum( std::numeric_limits< int >::max( ) ); - v_int->setValue( this->m_Parameters->GetInt( *nIt ) ); - w_input = v_int; - } - else if( pt == Parameters::Real ) - { - QDoubleSpinBox* v_double = new QDoubleSpinBox( dlg ); - v_double->setDecimals( 3 ); - v_double->setMinimum( -std::numeric_limits< double >::max( ) ); - v_double->setMaximum( std::numeric_limits< double >::max( ) ); - v_double->setValue( this->m_Parameters->GetReal( *nIt ) ); - w_input = v_double; - } - else if( - pt == Parameters::StringList || - pt == Parameters::IntList || - pt == Parameters::UintList || - pt == Parameters::RealList - ) - { - cpPlugins::Interface::ParametersListWidget* l_double = - new cpPlugins::Interface::ParametersListWidget( *nIt, dlg ); - w_input = l_double; - - } // fi - - // Ok, a representation was created - if( w_input != NULL ) - { - w_input->setObjectName( QString( nIt->c_str( ) ) ); - - QHBoxLayout* horizontalLayout = new QHBoxLayout( ); - QLabel* label = new QLabel( dlg ); - label->setText( QString( nIt->c_str( ) ) ); - horizontalLayout->addWidget( label ); - horizontalLayout->addWidget( w_input ); - verticalLayout->addLayout( horizontalLayout ); - - } // fi - - } // rof - - // 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 ); - - // Get values back - nIt = names.begin( ); - for( ; nIt != names.end( ); ++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 ) - this->m_Parameters->SetString( *nIt, v_string->text( ).toStdString( ) ); - } - else if( pt == Parameters::Bool ) - { - QCheckBox* v_bool = dlg->findChild< QCheckBox* >( nIt->c_str( ) ); - if( v_bool != NULL ) - this->m_Parameters->SetBool( *nIt, v_bool->isChecked( ) ); - } - else if( pt == Parameters::Uint ) - { - QSpinBox* v_uint = dlg->findChild< QSpinBox* >( nIt->c_str( ) ); - if( v_uint != NULL ) - this->m_Parameters->SetUint( *nIt, v_uint->value( ) ); - } - else if( pt == Parameters::Int ) - { - QSpinBox* v_int = dlg->findChild< QSpinBox* >( nIt->c_str( ) ); - if( v_int != NULL ) - this->m_Parameters->SetInt( *nIt, v_int->value( ) ); - } - else if( pt == Parameters::Real ) - { - QDoubleSpinBox* v_double = - dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) ); - if( v_double != NULL ) - this->m_Parameters->SetReal( *nIt, v_double->value( ) ); } else if( pt == Parameters::StringList || @@ -396,33 +424,33 @@ syncParameters( ) 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( ); + 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 = l_double->GetIntValues( ); + 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 = l_double->GetUintValues( ); + 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 = l_double->GetDoubleValues( ); + std::vector< double > values = lst->GetDoubleValues( ); for( int r = 0; r < values.size( ); ++r ) this->m_Parameters->AddToRealList( *nIt, values[ r ] );