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 <QDoubleSpinBox>
14 #include <QFileDialog>
15 #include <QHBoxLayout>
16 #include <QInputDialog>
18 #include <QPushButton>
21 // -------------------------------------------------------------------------
22 #include <cpPlugins/Interface/ProcessObject.h>
23 #include <cpPlugins/Interface/Plugins.h>
24 #include <cpPlugins/Interface/BaseApplication.h>
26 class SingleSeedCommand
30 static SingleSeedCommand* New( )
31 { return( new SingleSeedCommand ); }
32 virtual void Execute( vtkObject* caller, unsigned long eid, void* data )
34 // Get seed, avoiding segfaults!!!
35 if( eid != vtkCommand::PlacePointEvent || this->Dialog == NULL )
37 vtkSeedWidget* widget = dynamic_cast< vtkSeedWidget* >( caller );
40 vtkSeedRepresentation* rep = widget->GetSeedRepresentation( );
43 if( rep->GetNumberOfSeeds( ) == 0 )
46 rep->GetSeedWorldPosition( 0, seed );
48 // Delete all seeds (remember that this command is just for one seed)
49 while( rep->GetNumberOfSeeds( ) > 0 )
50 widget->DeleteSeed( 0 );
52 if( this->Dialog->getParameters( )->HasIndex( this->Name ) )
55 else if( this->Dialog->getParameters( )->HasPoint( this->Name ) )
57 this->Dialog->getParameters( )->SetPoint( this->Name, 3, seed );
58 this->Dialog->updateParameters( );
59 auto filter = this->Dialog->getParameters( )->GetProcessObject( );
62 auto plugins = filter->GetPlugins( );
65 auto app = plugins->GetApplication( );
67 app->UpdateActualFilter( );
81 virtual ~SingleSeedCommand( )
86 cpPlugins::Interface::ParametersQtDialog* Dialog;
90 // -------------------------------------------------------------------------
91 cpPlugins::Interface::ParametersQtDialog::
92 ParametersQtDialog( QWidget* parent, Qt::WindowFlags f )
93 : QDialog( parent, f ),
96 this->m_Title = new QLabel( this );
97 this->m_Title->setText( "Parameters dialog title" );
99 this->m_MainLayout = new QGridLayout( this );
100 this->m_ToolsLayout = new QVBoxLayout( );
101 this->m_ToolsLayout->addWidget( this->m_Title );
102 this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 );
105 // -------------------------------------------------------------------------
106 cpPlugins::Interface::ParametersQtDialog::
107 ~ParametersQtDialog( )
109 delete this->m_Title;
110 delete this->m_ToolsLayout;
111 delete this->m_MainLayout;
114 // -------------------------------------------------------------------------
115 cpPlugins::Interface::
116 Parameters* cpPlugins::Interface::ParametersQtDialog::
117 getParameters( ) const
119 return( this->m_Parameters );
122 // -------------------------------------------------------------------------
123 void cpPlugins::Interface::ParametersQtDialog::
124 addInteractor( vtkRenderWindowInteractor* interactor )
126 this->m_Interactors.insert( interactor );
129 // -------------------------------------------------------------------------
130 cpPlugins::Interface::ParametersQtDialog::
131 TInteractors& cpPlugins::Interface::ParametersQtDialog::
134 return( this->m_Interactors );
137 // -------------------------------------------------------------------------
138 const cpPlugins::Interface::ParametersQtDialog::
139 TInteractors& cpPlugins::Interface::ParametersQtDialog::
140 getInteractors( ) const
142 return( this->m_Interactors );
145 // -------------------------------------------------------------------------
146 bool cpPlugins::Interface::ParametersQtDialog::
147 setParameters( Parameters* parameters )
149 if( this->m_Parameters != NULL || parameters == NULL )
151 this->m_Parameters = parameters;
154 auto filter = this->m_Parameters->GetProcessObject( );
155 std::stringstream title;
156 title << "Parameters for \"" << filter->GetName( ) << "\"";
157 this->m_Title->setText( title.str( ).c_str( ) );
160 auto& raw_params = this->m_Parameters->GetRawParameters( );
161 for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
163 QWidget* w_input = NULL;
164 switch( pIt->second.first )
166 case Parameters::String:
168 QLineEdit* v_string = new QLineEdit( this );
169 v_string->setObjectName( pIt->first.c_str( ) );
170 v_string->setText( pIt->second.second.c_str( ) );
174 case Parameters::Bool:
176 QCheckBox* v_bool = new QCheckBox( this );
177 v_bool->setObjectName( pIt->first.c_str( ) );
178 v_bool->setText( "[ON/OFF]" );
179 v_bool->setChecked( pIt->second.second == "1" );
183 case Parameters::Int:
184 case Parameters::Uint:
186 std::istringstream tok_str( pIt->second.second );
189 QSpinBox* v_uint = new QSpinBox( this );
190 v_uint->setObjectName( pIt->first.c_str( ) );
191 if( pIt->second.first == Parameters::Uint )
192 v_uint->setMinimum( 0 );
194 v_uint->setMinimum( -std::numeric_limits< int >::max( ) );
195 v_uint->setMaximum( std::numeric_limits< int >::max( ) );
196 v_uint->setValue( v );
200 case Parameters::Real:
202 std::istringstream tok_str( pIt->second.second );
205 QDoubleSpinBox* v_double = new QDoubleSpinBox( this );
206 v_double->setObjectName( pIt->first.c_str( ) );
207 v_double->setDecimals( 3 );
208 v_double->setMinimum( -std::numeric_limits< double >::max( ) );
209 v_double->setMaximum( std::numeric_limits< double >::max( ) );
210 v_double->setValue( v );
214 case Parameters::Index:
216 case Parameters::Point:
218 case Parameters::Vector:
220 case Parameters::OpenFileName:
222 QFrame* frame = new QFrame( this );
223 QHBoxLayout* layout = new QHBoxLayout( frame );
224 QLineEdit* v_string = new QLineEdit( frame );
225 v_string->setObjectName( pIt->first.c_str( ) );
226 v_string->setText( pIt->second.second.c_str( ) );
227 QPushButton* v_button = new QPushButton( frame );
228 v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
229 v_button->setText( "..." );
231 v_button, SIGNAL( clicked( ) ),
232 this, SLOT( _dlg_OpenSingleFile( ) )
234 layout->addWidget( v_string );
235 layout->addWidget( v_button );
238 case Parameters::SaveFileName:
240 QFrame* frame = new QFrame( this );
241 QHBoxLayout* layout = new QHBoxLayout( frame );
242 QLineEdit* v_string = new QLineEdit( frame );
243 v_string->setObjectName( pIt->first.c_str( ) );
244 v_string->setText( pIt->second.second.c_str( ) );
245 QPushButton* v_button = new QPushButton( frame );
246 v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
247 v_button->setText( "..." );
249 v_button, SIGNAL( clicked( ) ),
250 this, SLOT( _dlg_SaveSingleFile( ) )
252 layout->addWidget( v_string );
253 layout->addWidget( v_button );
257 case Parameters::PathName:
259 QFrame* frame = new QFrame( this );
260 QHBoxLayout* layout = new QHBoxLayout( frame );
261 QLineEdit* v_string = new QLineEdit( frame );
262 v_string->setObjectName( pIt->first.c_str( ) );
263 v_string->setText( pIt->second.second.c_str( ) );
264 QPushButton* v_button = new QPushButton( frame );
265 v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
266 v_button->setText( "..." );
268 v_button, SIGNAL( clicked( ) ),
269 this, SLOT( _dlg_OpenSinglePath( ) )
271 layout->addWidget( v_string );
272 layout->addWidget( v_button );
276 case Parameters::StringList:
278 case Parameters::BoolList:
280 case Parameters::IntList:
282 QFrame* frame = new QFrame( this );
283 QHBoxLayout* layout = new QHBoxLayout( frame );
284 QLineEdit* v_string = new QLineEdit( frame );
285 v_string->setObjectName( pIt->first.c_str( ) );
286 v_string->setText( pIt->second.second.c_str( ) );
287 QPushButton* v_button = new QPushButton( frame );
288 v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
289 v_button->setText( "+" );
291 v_button, SIGNAL( clicked( ) ),
292 this, SLOT( _dlg_AddInt( ) )
294 layout->addWidget( v_string );
295 layout->addWidget( v_button );
299 case Parameters::UintList:
301 QFrame* frame = new QFrame( this );
302 QHBoxLayout* layout = new QHBoxLayout( frame );
303 QLineEdit* v_string = new QLineEdit( frame );
304 v_string->setObjectName( pIt->first.c_str( ) );
305 v_string->setText( pIt->second.second.c_str( ) );
306 QPushButton* v_button = new QPushButton( frame );
307 v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
308 v_button->setText( "+" );
310 v_button, SIGNAL( clicked( ) ),
311 this, SLOT( _dlg_AddUint( ) )
313 layout->addWidget( v_string );
314 layout->addWidget( v_button );
318 case Parameters::RealList:
320 QFrame* frame = new QFrame( this );
321 QHBoxLayout* layout = new QHBoxLayout( frame );
322 QLineEdit* v_string = new QLineEdit( frame );
323 v_string->setObjectName( pIt->first.c_str( ) );
324 v_string->setText( pIt->second.second.c_str( ) );
325 QPushButton* v_button = new QPushButton( frame );
326 v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
327 v_button->setText( "+" );
329 v_button, SIGNAL( clicked( ) ),
330 this, SLOT( _dlg_AddReal( ) )
332 layout->addWidget( v_string );
333 layout->addWidget( v_button );
337 case Parameters::IndexList:
339 case Parameters::PointList:
341 case Parameters::VectorList:
343 case Parameters::OpenFileNameList:
345 QFrame* frame = new QFrame( this );
346 QHBoxLayout* layout = new QHBoxLayout( frame );
347 QLineEdit* v_string = new QLineEdit( frame );
348 v_string->setObjectName( pIt->first.c_str( ) );
349 v_string->setText( pIt->second.second.c_str( ) );
350 QPushButton* v_button = new QPushButton( frame );
351 v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
352 v_button->setText( "..." );
354 v_button, SIGNAL( clicked( ) ),
355 this, SLOT( _dlg_OpenMultipleFiles( ) )
357 layout->addWidget( v_string );
358 layout->addWidget( v_button );
362 case Parameters::SaveFileNameList:
364 case Parameters::PathNameList:
366 case Parameters::Choices:
373 // Ok, a representation was created
374 if( w_input != NULL )
376 QHBoxLayout* new_layout = new QHBoxLayout( );
377 QLabel* label = new QLabel( this );
378 label->setText( QString( pIt->first.c_str( ) ) );
379 new_layout->addWidget( label );
380 new_layout->addWidget( w_input );
381 this->m_ToolsLayout->addLayout( new_layout );
388 this->m_Buttons = new QDialogButtonBox(
389 QDialogButtonBox::Ok | QDialogButtonBox::Cancel
392 this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
395 this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
397 this->m_ToolsLayout->addWidget( this->m_Buttons );
402 // -------------------------------------------------------------------------
403 int cpPlugins::Interface::ParametersQtDialog::
406 int ret = this->QDialog::exec( );
408 this->updateParameters( );
414 // -------------------------------------------------------------------------
415 void cpPlugins::Interface::ParametersQtDialog::
418 this->QDialog::show( );
421 // -------------------------------------------------------------------------
422 void cpPlugins::Interface::ParametersQtDialog::
425 if( this->m_Parameters == NULL )
429 auto& raw_params = this->m_Parameters->GetRawParameters( );
430 for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
432 QString pName = pIt->first.c_str( );
433 switch( pIt->second.first )
435 case Parameters::String:
436 case Parameters::OpenFileName:
437 case Parameters::SaveFileName:
438 case Parameters::PathName:
439 case Parameters::IntList:
440 case Parameters::UintList:
441 case Parameters::RealList:
442 case Parameters::OpenFileNameList:
444 QLineEdit* v_string = this->findChild< QLineEdit* >( pName );
445 if( v_string != NULL )
446 pIt->second.second = v_string->text( ).toStdString( );
449 case Parameters::Bool:
451 QCheckBox* v_bool = this->findChild< QCheckBox* >( pName );
453 pIt->second.second = ( v_bool->isChecked( ) )? "1": "0";
456 case Parameters::Int:
457 case Parameters::Uint:
459 QSpinBox* v_uint = this->findChild< QSpinBox* >( pName );
462 std::stringstream str;
463 str << v_uint->value( );
464 pIt->second.second = str.str( );
469 case Parameters::Real:
471 QDoubleSpinBox* v_double = this->findChild< QDoubleSpinBox* >( pName );
474 std::stringstream str;
475 str << v_double->value( );
476 pIt->second.second = str.str( );
481 case Parameters::Index:
483 case Parameters::Point:
485 case Parameters::Vector:
487 case Parameters::StringList:
489 case Parameters::BoolList:
491 case Parameters::IndexList:
493 case Parameters::PointList:
495 case Parameters::VectorList:
497 case Parameters::SaveFileNameList:
499 case Parameters::PathNameList:
501 case Parameters::Choices:
510 // -------------------------------------------------------------------------
511 void cpPlugins::Interface::ParametersQtDialog::
514 if( this->m_Parameters == NULL )
518 auto& raw_params = this->m_Parameters->GetRawParameters( );
519 for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
521 QString pName = pIt->first.c_str( );
522 switch( pIt->second.first )
524 case Parameters::String:
525 case Parameters::OpenFileName:
526 case Parameters::SaveFileName:
527 case Parameters::PathName:
528 case Parameters::IntList:
529 case Parameters::UintList:
530 case Parameters::RealList:
531 case Parameters::OpenFileNameList:
533 QLineEdit* v_string = this->findChild< QLineEdit* >( pName );
534 if( v_string != NULL )
535 v_string->setText( pIt->second.second.c_str( ) );
538 case Parameters::Bool:
540 QCheckBox* v_bool = this->findChild< QCheckBox* >( pName );
542 v_bool->setChecked( pIt->second.second == "1" );
545 case Parameters::Int:
546 case Parameters::Uint:
548 QSpinBox* v_uint = this->findChild< QSpinBox* >( pName );
551 std::istringstream tok_str( pIt->second.second );
554 v_uint->setValue( v );
559 case Parameters::Real:
561 QDoubleSpinBox* v_double = this->findChild< QDoubleSpinBox* >( pName );
564 std::istringstream tok_str( pIt->second.second );
567 v_double->setValue( v );
572 case Parameters::Index:
574 case Parameters::Point:
576 case Parameters::Vector:
578 case Parameters::StringList:
580 case Parameters::BoolList:
582 case Parameters::IndexList:
584 case Parameters::PointList:
586 case Parameters::VectorList:
588 case Parameters::SaveFileNameList:
590 case Parameters::PathNameList:
592 case Parameters::Choices:
601 // -------------------------------------------------------------------------
602 void cpPlugins::Interface::ParametersQtDialog::
603 _dlg_OpenSingleFile( )
605 QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
608 std::string bName = btn->objectName( ).toStdString( );
609 std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
610 QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
613 std::string param_name = line->objectName( ).toStdString( );
614 if( param_name != "" )
616 std::string param_value =
617 this->m_Parameters->GetOpenFileName( param_name );
618 if( param_value == "" )
621 filters << "Any file (*)";
623 // Show dialog and check if it was accepted
624 QFileDialog dialog( this );
625 dialog.setFileMode( QFileDialog::ExistingFile );
626 dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
627 dialog.setNameFilters( filters );
628 dialog.setAcceptMode( QFileDialog::AcceptOpen );
630 line->setText( *( dialog.selectedFiles( ).begin( ) ) );
639 // -------------------------------------------------------------------------
640 void cpPlugins::Interface::ParametersQtDialog::
641 _dlg_SaveSingleFile( )
643 QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
646 std::string bName = btn->objectName( ).toStdString( );
647 std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
648 QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
651 std::string param_name = line->objectName( ).toStdString( );
652 if( param_name != "" )
654 std::string param_value =
655 this->m_Parameters->GetSaveFileName( param_name );
656 if( param_value == "" )
659 filters << "Any file (*)";
661 // Show dialog and check if it was accepted
662 QFileDialog dialog( this );
663 dialog.setFileMode( QFileDialog::AnyFile );
664 dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
665 dialog.setNameFilters( filters );
666 dialog.setAcceptMode( QFileDialog::AcceptSave );
668 line->setText( *( dialog.selectedFiles( ).begin( ) ) );
677 // -------------------------------------------------------------------------
678 void cpPlugins::Interface::ParametersQtDialog::
679 _dlg_OpenSinglePath( )
681 QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
684 std::string bName = btn->objectName( ).toStdString( );
685 std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
686 QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
689 std::string param_name = line->objectName( ).toStdString( );
690 if( param_name != "" )
692 std::string param_value =
693 this->m_Parameters->GetPathName( param_name );
694 if( param_value == "" )
697 // Show dialog and check if it was accepted
698 QFileDialog dialog( this );
699 dialog.setFileMode( QFileDialog::Directory );
700 dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
701 dialog.setAcceptMode( QFileDialog::AcceptOpen );
703 line->setText( *( dialog.selectedFiles( ).begin( ) ) );
712 // -------------------------------------------------------------------------
713 void cpPlugins::Interface::ParametersQtDialog::
714 _dlg_OpenMultipleFiles( )
716 QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
719 std::string bName = btn->objectName( ).toStdString( );
720 std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
722 QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
725 std::string param_name = line->objectName( ).toStdString( );
726 if( param_name != "" )
729 filters << "Any file (*)";
731 // Show dialog and check if it was accepted
732 QFileDialog dialog( this );
733 dialog.setFileMode( QFileDialog::ExistingFiles );
734 dialog.setNameFilters( filters );
735 dialog.setAcceptMode( QFileDialog::AcceptOpen );
738 if( dialog.selectedFiles( ).size( ) > 0 )
740 std::stringstream str;
741 auto files = dialog.selectedFiles( );
742 auto fIt = files.begin( );
743 str << fIt->toStdString( );
745 for( ; fIt != files.end( ); ++fIt )
746 str << "#" << fIt->toStdString( );
747 line->setText( str.str( ).c_str( ) );
760 // -------------------------------------------------------------------------
761 void cpPlugins::Interface::ParametersQtDialog::
764 QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
767 std::string bName = btn->objectName( ).toStdString( );
768 std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
769 QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
772 std::string param_name = line->objectName( ).toStdString( );
773 if( param_name != "" )
777 QInputDialog::getInt(
780 std::string( "Add new value to \"" ) +
785 0, -2147483647, 2147483647, 1,
790 std::string values = line->text( ).toStdString( );
793 std::stringstream str;
794 str << values << value;
795 line->setText( str.str( ).c_str( ) );
806 // -------------------------------------------------------------------------
807 void cpPlugins::Interface::ParametersQtDialog::
810 QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
813 std::string bName = btn->objectName( ).toStdString( );
814 std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
815 QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
818 std::string param_name = line->objectName( ).toStdString( );
819 if( param_name != "" )
823 QInputDialog::getInt(
826 std::string( "Add new value to \"" ) +
836 std::string values = line->text( ).toStdString( );
839 std::stringstream str;
840 str << values << value;
841 line->setText( str.str( ).c_str( ) );
852 // -------------------------------------------------------------------------
853 void cpPlugins::Interface::ParametersQtDialog::
856 QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) );
859 std::string bName = btn->objectName( ).toStdString( );
860 std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) );
861 QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) );
864 std::string param_name = line->objectName( ).toStdString( );
865 if( param_name != "" )
869 QInputDialog::getDouble(
872 std::string( "Add new value to \"" ) +
877 0, -2147483647, 2147483647, 1,
882 std::string values = line->text( ).toStdString( );
885 std::stringstream str;
886 str << values << value;
887 line->setText( str.str( ).c_str( ) );
898 #endif // cpPlugins_Interface_QT4