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 bool cpPlugins::Interface::ParametersQtDialog::
137 setParameters( Parameters* parameters )
139 this->m_IsModal = true;
140 this->m_Parameters = parameters;
141 if( this->m_Parameters == NULL )
145 std::vector< std::string > names;
146 this->m_Parameters->GetNames( names );
147 std::vector< std::string >::const_iterator nIt = names.begin( );
148 for( ; nIt != names.end( ); ++nIt )
150 Parameters::Type pt = this->m_Parameters->GetType( *nIt );
152 QWidget* w_input = NULL;
153 if( pt == Parameters::String )
155 QLineEdit* v_string = new QLineEdit( this );
156 v_string->setText( "Enter some text!!!" );
159 else if( pt == Parameters::Bool )
161 QCheckBox* v_bool = new QCheckBox( this );
162 v_bool->setText( "[ON/OFF]" );
163 v_bool->setChecked( this->m_Parameters->GetBool( *nIt ) );
166 else if( pt == Parameters::Uint )
168 QSpinBox* v_uint = new QSpinBox( this );
169 v_uint->setMinimum( 0 );
170 v_uint->setMaximum( std::numeric_limits< int >::max( ) );
171 v_uint->setValue( this->m_Parameters->GetUint( *nIt ) );
174 else if( pt == Parameters::Int )
176 QSpinBox* v_int = new QSpinBox( this );
177 v_int->setMinimum( -std::numeric_limits< int >::max( ) );
178 v_int->setMaximum( std::numeric_limits< int >::max( ) );
179 v_int->setValue( this->m_Parameters->GetInt( *nIt ) );
182 else if( pt == Parameters::Real )
184 QDoubleSpinBox* v_double = new QDoubleSpinBox( this );
185 v_double->setDecimals( 3 );
186 v_double->setMinimum( -std::numeric_limits< double >::max( ) );
187 v_double->setMaximum( std::numeric_limits< double >::max( ) );
188 v_double->setValue( this->m_Parameters->GetReal( *nIt ) );
192 pt == Parameters::StringList ||
193 pt == Parameters::IntList ||
194 pt == Parameters::UintList ||
195 pt == Parameters::RealList
198 cpPlugins::Interface::ParametersListWidget* l_double =
199 new cpPlugins::Interface::ParametersListWidget( *nIt, this );
202 else if( pt == Parameters::Point || pt == Parameters::Index )
204 vtkSmartPointer< SingleSeedCommand > command =
205 vtkSmartPointer< SingleSeedCommand >::New( );
206 command->Dialog = this;
207 command->Name = *nIt;
209 auto iIt = this->m_Interactors.begin( );
210 for( ; iIt != this->m_Interactors.end( ); ++iIt )
213 dynamic_cast< TStyle* >( ( *iIt )->GetInteractorStyle( ) );
216 style->SeedWidgetOn( );
217 style->SetSeedWidgetCommand( command );
222 this->m_IsModal = false;
226 // Ok, a representation was created
227 if( w_input != NULL )
229 w_input->setObjectName( QString( nIt->c_str( ) ) );
231 QHBoxLayout* new_layout = new QHBoxLayout( );
232 QLabel* label = new QLabel( this );
233 label->setText( QString( nIt->c_str( ) ) );
234 new_layout->addWidget( label );
235 new_layout->addWidget( w_input );
236 this->m_ToolsLayout->addLayout( new_layout );
241 return( this->m_IsModal );
244 // -------------------------------------------------------------------------
245 void cpPlugins::Interface::ParametersQtDialog::
246 setTitle( const std::string& title )
248 this->m_Title->setText( title.c_str( ) );
251 // -------------------------------------------------------------------------
252 int cpPlugins::Interface::ParametersQtDialog::
255 if( !this->m_IsModal )
259 QDialogButtonBox* bb = new QDialogButtonBox(
260 QDialogButtonBox::Ok | QDialogButtonBox::Cancel
262 QObject::connect( bb, SIGNAL( accepted( ) ), this, SLOT( accept( ) ) );
263 QObject::connect( bb, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) );
264 this->m_ToolsLayout->addWidget( bb );
266 int ret = this->QDialog::exec( );
268 this->syncParameters( );
272 // -------------------------------------------------------------------------
273 void cpPlugins::Interface::ParametersQtDialog::
276 if( this->m_IsModal )
279 this->QDialog::show( );
282 // -------------------------------------------------------------------------
283 void cpPlugins::Interface::ParametersQtDialog::
286 if( this->m_Parameters == NULL )
290 std::vector< std::string > names;
291 this->m_Parameters->GetNames( names );
292 std::vector< std::string >::const_iterator nIt = names.begin( );
293 for( ; nIt != names.end( ); ++nIt )
295 Parameters::Type pt = this->m_Parameters->GetType( *nIt );
297 if( pt == Parameters::String )
299 QLineEdit* v = this->findChild< QLineEdit* >( nIt->c_str( ) );
301 this->m_Parameters->SetString( *nIt, v->text( ).toStdString( ) );
303 else if( pt == Parameters::Bool )
305 QCheckBox* v = this->findChild< QCheckBox* >( nIt->c_str( ) );
307 this->m_Parameters->SetBool( *nIt, v->isChecked( ) );
309 else if( pt == Parameters::Uint )
311 QSpinBox* v = this->findChild< QSpinBox* >( nIt->c_str( ) );
313 this->m_Parameters->SetUint( *nIt, v->value( ) );
315 else if( pt == Parameters::Int )
317 QSpinBox* v = this->findChild< QSpinBox* >( nIt->c_str( ) );
319 this->m_Parameters->SetInt( *nIt, v->value( ) );
321 else if( pt == Parameters::Real )
323 QDoubleSpinBox* v = this->findChild< QDoubleSpinBox* >( nIt->c_str( ) );
325 this->m_Parameters->SetReal( *nIt, v->value( ) );
328 pt == Parameters::StringList ||
329 pt == Parameters::IntList ||
330 pt == Parameters::UintList ||
331 pt == Parameters::RealList
334 cpPlugins::Interface::ParametersListWidget* lst =
335 this->findChild< cpPlugins::Interface::ParametersListWidget* >(
340 if( pt == Parameters::StringList )
342 this->m_Parameters->ClearStringList( *nIt );
343 std::vector< std::string > values = lst->GetStringValues( );
344 for( int r = 0; r < values.size( ); ++r )
345 this->m_Parameters->AddToStringList( *nIt, values[ r ] );
347 else if( pt == Parameters::IntList )
349 this->m_Parameters->ClearIntList( *nIt );
350 std::vector< int > values = lst->GetIntValues( );
351 for( int r = 0; r < values.size( ); ++r )
352 this->m_Parameters->AddToIntList( *nIt, values[ r ] );
354 else if( pt == Parameters::UintList )
356 this->m_Parameters->ClearUintList( *nIt );
357 std::vector< unsigned int > values = lst->GetUintValues( );
358 for( int r = 0; r < values.size( ); ++r )
359 this->m_Parameters->AddToUintList( *nIt, values[ r ] );
361 else if( pt == Parameters::RealList )
363 this->m_Parameters->ClearRealList( *nIt );
364 std::vector< double > values = lst->GetDoubleValues( );
365 for( int r = 0; r < values.size( ); ++r )
366 this->m_Parameters->AddToRealList( *nIt, values[ r ] );
372 else if( pt == Parameters::Point || pt == Parameters::Index )
405 pt == Parameters::StringList ||
406 pt == Parameters::IntList ||
407 pt == Parameters::UintList ||
408 pt == Parameters::RealList
411 cpPlugins::Interface::ParametersListWidget* lst =
412 this->findChild< cpPlugins::Interface::ParametersListWidget* >(
417 if( pt == Parameters::StringList )
419 std::vector< std::string > values = lst->GetStringValues( );
420 for( int r = 0; r < values.size( ); ++r )
421 this->m_Parameters->AddToStringList( *nIt, values[ r ] );
423 else if( pt == Parameters::IntList )
425 std::vector< int > values = lst->GetIntValues( );
426 for( int r = 0; r < values.size( ); ++r )
427 this->m_Parameters->AddToIntList( *nIt, values[ r ] );
429 else if( pt == Parameters::UintList )
431 std::vector< unsigned int > values = lst->GetUintValues( );
432 for( int r = 0; r < values.size( ); ++r )
433 this->m_Parameters->AddToUintList( *nIt, values[ r ] );
435 else if( pt == Parameters::RealList )
437 std::vector< double > values = lst->GetDoubleValues( );
438 for( int r = 0; r < values.size( ); ++r )
439 this->m_Parameters->AddToRealList( *nIt, values[ r ] );
452 #endif // cpPlugins_Interface_QT4