1 #include <cpPlugins/Interface/ParametersQtDialog.h>
3 #ifdef cpPlugins_Interface_QT4
7 #include <cpPlugins/Interface/ParametersListWidget.h>
9 #include <vtkCommand.h>
10 #include <vtkRenderWindowInteractor.h>
13 #include <QDialogButtonBox>
14 #include <QDoubleSpinBox>
15 #include <QHBoxLayout>
19 // -------------------------------------------------------------------------
20 #include <cpPlugins/Interface/ProcessObject.h>
21 #include <cpPlugins/Interface/Plugins.h>
22 #include <cpPlugins/Interface/BaseApplication.h>
24 class SingleSeedCommand
28 static SingleSeedCommand* New( )
29 { return( new SingleSeedCommand ); }
30 virtual void Execute( vtkObject* caller, unsigned long eid, void* data )
32 // Get seed, avoiding segfaults!!!
33 if( eid != vtkCommand::PlacePointEvent || this->Dialog == NULL )
35 vtkSeedWidget* widget = dynamic_cast< vtkSeedWidget* >( caller );
38 vtkSeedRepresentation* rep = widget->GetSeedRepresentation( );
41 if( rep->GetNumberOfSeeds( ) == 0 )
44 rep->GetSeedWorldPosition( 0, seed );
46 // Delete all seeds (remember that this command is just for one seed)
47 while( rep->GetNumberOfSeeds( ) > 0 )
48 widget->DeleteSeed( 0 );
50 if( this->Dialog->getParameters( )->HasIndex( this->Name ) )
53 else if( this->Dialog->getParameters( )->HasPoint( this->Name ) )
55 this->Dialog->getParameters( )->SetPoint( this->Name, 3, seed );
56 this->Dialog->syncParameters( );
57 auto filter = this->Dialog->getParameters( )->GetProcessObject( );
60 auto plugins = filter->GetPlugins( );
63 auto app = plugins->GetApplication( );
65 app->UpdateActualFilter( );
79 virtual ~SingleSeedCommand( )
84 cpPlugins::Interface::ParametersQtDialog* Dialog;
88 // -------------------------------------------------------------------------
89 cpPlugins::Interface::ParametersQtDialog::
90 ParametersQtDialog( QWidget* parent, Qt::WindowFlags f )
91 : QDialog( parent, f ),
95 this->m_Title = new QLabel( this );
96 this->m_Title->setText( "Parameters dialog title" );
98 this->m_MainLayout = new QGridLayout( this );
99 this->m_ToolsLayout = new QVBoxLayout( );
100 this->m_ToolsLayout->addWidget( this->m_Title );
101 this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 );
104 // -------------------------------------------------------------------------
105 cpPlugins::Interface::ParametersQtDialog::
106 ~ParametersQtDialog( )
108 delete this->m_Title;
109 delete this->m_ToolsLayout;
110 delete this->m_MainLayout;
113 // -------------------------------------------------------------------------
114 bool cpPlugins::Interface::ParametersQtDialog::
117 return( this->m_IsModal );
120 // -------------------------------------------------------------------------
121 cpPlugins::Interface::
122 Parameters* cpPlugins::Interface::ParametersQtDialog::
123 getParameters( ) const
125 return( this->m_Parameters );
128 // -------------------------------------------------------------------------
129 void cpPlugins::Interface::ParametersQtDialog::
130 addInteractor( vtkRenderWindowInteractor* interactor )
132 this->m_Interactors.insert( interactor );
135 // -------------------------------------------------------------------------
136 cpPlugins::Interface::ParametersQtDialog::
137 TInteractors& cpPlugins::Interface::ParametersQtDialog::
140 return( this->m_Interactors );
143 // -------------------------------------------------------------------------
144 const cpPlugins::Interface::ParametersQtDialog::
145 TInteractors& cpPlugins::Interface::ParametersQtDialog::
146 getInteractors( ) const
148 return( this->m_Interactors );
151 // -------------------------------------------------------------------------
152 bool cpPlugins::Interface::ParametersQtDialog::
153 setParameters( Parameters* parameters )
155 this->m_IsModal = true;
156 this->m_Parameters = parameters;
157 if( this->m_Parameters == NULL )
161 std::vector< std::string > names;
162 this->m_Parameters->GetNames( names );
163 std::vector< std::string >::const_iterator nIt = names.begin( );
164 for( ; nIt != names.end( ); ++nIt )
166 Parameters::Type pt = this->m_Parameters->GetType( *nIt );
168 QWidget* w_input = NULL;
169 if( pt == Parameters::String )
171 QLineEdit* v_string = new QLineEdit( this );
172 v_string->setText( "Enter some text!!!" );
175 else if( pt == Parameters::Bool )
177 QCheckBox* v_bool = new QCheckBox( this );
178 v_bool->setText( "[ON/OFF]" );
179 v_bool->setChecked( this->m_Parameters->GetBool( *nIt ) );
182 else if( pt == Parameters::Uint )
184 QSpinBox* v_uint = new QSpinBox( this );
185 v_uint->setMinimum( 0 );
186 v_uint->setMaximum( std::numeric_limits< int >::max( ) );
187 v_uint->setValue( this->m_Parameters->GetUint( *nIt ) );
190 else if( pt == Parameters::Int )
192 QSpinBox* v_int = new QSpinBox( this );
193 v_int->setMinimum( -std::numeric_limits< int >::max( ) );
194 v_int->setMaximum( std::numeric_limits< int >::max( ) );
195 v_int->setValue( this->m_Parameters->GetInt( *nIt ) );
198 else if( pt == Parameters::Real )
200 QDoubleSpinBox* v_double = new QDoubleSpinBox( this );
201 v_double->setDecimals( 3 );
202 v_double->setMinimum( -std::numeric_limits< double >::max( ) );
203 v_double->setMaximum( std::numeric_limits< double >::max( ) );
204 v_double->setValue( this->m_Parameters->GetReal( *nIt ) );
208 pt == Parameters::StringList ||
209 pt == Parameters::IntList ||
210 pt == Parameters::UintList ||
211 pt == Parameters::RealList
214 cpPlugins::Interface::ParametersListWidget* l_double =
215 new cpPlugins::Interface::ParametersListWidget( *nIt, this );
218 else if( pt == Parameters::Point || pt == Parameters::Index )
220 vtkSmartPointer< SingleSeedCommand > command =
221 vtkSmartPointer< SingleSeedCommand >::New( );
222 command->Dialog = this;
223 command->Name = *nIt;
225 auto iIt = this->m_Interactors.begin( );
226 for( ; iIt != this->m_Interactors.end( ); ++iIt )
229 dynamic_cast< TStyle* >( ( *iIt )->GetInteractorStyle( ) );
232 style->SeedWidgetOn( );
233 style->SetSeedWidgetCommand( command );
238 this->m_IsModal = false;
242 // Ok, a representation was created
243 if( w_input != NULL )
245 w_input->setObjectName( QString( nIt->c_str( ) ) );
247 QHBoxLayout* new_layout = new QHBoxLayout( );
248 QLabel* label = new QLabel( this );
249 label->setText( QString( nIt->c_str( ) ) );
250 new_layout->addWidget( label );
251 new_layout->addWidget( w_input );
252 this->m_ToolsLayout->addLayout( new_layout );
257 return( this->m_IsModal );
260 // -------------------------------------------------------------------------
261 void cpPlugins::Interface::ParametersQtDialog::
262 setTitle( const std::string& title )
264 this->m_Title->setText( title.c_str( ) );
267 // -------------------------------------------------------------------------
268 int cpPlugins::Interface::ParametersQtDialog::
271 if( !this->m_IsModal )
275 QDialogButtonBox* bb = new QDialogButtonBox(
276 QDialogButtonBox::Ok | QDialogButtonBox::Cancel
278 QObject::connect( bb, SIGNAL( accepted( ) ), this, SLOT( accept( ) ) );
279 QObject::connect( bb, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) );
280 this->m_ToolsLayout->addWidget( bb );
282 int ret = this->QDialog::exec( );
284 this->syncParameters( );
288 // -------------------------------------------------------------------------
289 void cpPlugins::Interface::ParametersQtDialog::
292 if( this->m_IsModal )
295 this->QDialog::show( );
298 // -------------------------------------------------------------------------
299 void cpPlugins::Interface::ParametersQtDialog::
302 if( this->m_Parameters == NULL )
306 std::vector< std::string > names;
307 this->m_Parameters->GetNames( names );
308 std::vector< std::string >::const_iterator nIt = names.begin( );
309 for( ; nIt != names.end( ); ++nIt )
311 Parameters::Type pt = this->m_Parameters->GetType( *nIt );
313 if( pt == Parameters::String )
315 QLineEdit* v = this->findChild< QLineEdit* >( nIt->c_str( ) );
317 this->m_Parameters->SetString( *nIt, v->text( ).toStdString( ) );
319 else if( pt == Parameters::Bool )
321 QCheckBox* v = this->findChild< QCheckBox* >( nIt->c_str( ) );
323 this->m_Parameters->SetBool( *nIt, v->isChecked( ) );
325 else if( pt == Parameters::Uint )
327 QSpinBox* v = this->findChild< QSpinBox* >( nIt->c_str( ) );
329 this->m_Parameters->SetUint( *nIt, v->value( ) );
331 else if( pt == Parameters::Int )
333 QSpinBox* v = this->findChild< QSpinBox* >( nIt->c_str( ) );
335 this->m_Parameters->SetInt( *nIt, v->value( ) );
337 else if( pt == Parameters::Real )
339 QDoubleSpinBox* v = this->findChild< QDoubleSpinBox* >( nIt->c_str( ) );
341 this->m_Parameters->SetReal( *nIt, v->value( ) );
344 pt == Parameters::StringList ||
345 pt == Parameters::IntList ||
346 pt == Parameters::UintList ||
347 pt == Parameters::RealList
350 cpPlugins::Interface::ParametersListWidget* lst =
351 this->findChild< cpPlugins::Interface::ParametersListWidget* >(
356 if( pt == Parameters::StringList )
358 this->m_Parameters->ClearStringList( *nIt );
359 std::vector< std::string > values = lst->GetStringValues( );
360 for( int r = 0; r < values.size( ); ++r )
361 this->m_Parameters->AddToStringList( *nIt, values[ r ] );
363 else if( pt == Parameters::IntList )
365 this->m_Parameters->ClearIntList( *nIt );
366 std::vector< int > values = lst->GetIntValues( );
367 for( int r = 0; r < values.size( ); ++r )
368 this->m_Parameters->AddToIntList( *nIt, values[ r ] );
370 else if( pt == Parameters::UintList )
372 this->m_Parameters->ClearUintList( *nIt );
373 std::vector< unsigned int > values = lst->GetUintValues( );
374 for( int r = 0; r < values.size( ); ++r )
375 this->m_Parameters->AddToUintList( *nIt, values[ r ] );
377 else if( pt == Parameters::RealList )
379 this->m_Parameters->ClearRealList( *nIt );
380 std::vector< double > values = lst->GetDoubleValues( );
381 for( int r = 0; r < values.size( ); ++r )
382 this->m_Parameters->AddToRealList( *nIt, values[ r ] );
388 else if( pt == Parameters::Point || pt == Parameters::Index )
421 pt == Parameters::StringList ||
422 pt == Parameters::IntList ||
423 pt == Parameters::UintList ||
424 pt == Parameters::RealList
427 cpPlugins::Interface::ParametersListWidget* lst =
428 this->findChild< cpPlugins::Interface::ParametersListWidget* >(
433 if( pt == Parameters::StringList )
435 std::vector< std::string > values = lst->GetStringValues( );
436 for( int r = 0; r < values.size( ); ++r )
437 this->m_Parameters->AddToStringList( *nIt, values[ r ] );
439 else if( pt == Parameters::IntList )
441 std::vector< int > values = lst->GetIntValues( );
442 for( int r = 0; r < values.size( ); ++r )
443 this->m_Parameters->AddToIntList( *nIt, values[ r ] );
445 else if( pt == Parameters::UintList )
447 std::vector< unsigned int > values = lst->GetUintValues( );
448 for( int r = 0; r < values.size( ); ++r )
449 this->m_Parameters->AddToUintList( *nIt, values[ r ] );
451 else if( pt == Parameters::RealList )
453 std::vector< double > values = lst->GetDoubleValues( );
454 for( int r = 0; r < values.size( ); ++r )
455 this->m_Parameters->AddToRealList( *nIt, values[ r ] );
468 #endif // cpPlugins_Interface_QT4