#include <limits>
-#include <cpPlugins/Interface/ParametersListWidget.h>
-
-#include <vtkCommand.h>
-#include <vtkRenderWindowInteractor.h>
+#include <cpPlugins/Interface/ProcessObject.h>
#include <QCheckBox>
#include <QComboBox>
#include <QPushButton>
#include <QWidget>
-// -------------------------------------------------------------------------
-#include <cpPlugins/Interface/ProcessObject.h>
-#include <cpPlugins/Interface/Plugins.h>
-#include <cpPlugins/Interface/BaseApplication.h>
-
-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->updateParameters( );
- 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_Parameters( NULL ),
+ m_WidgetsUpdated( false )
{
this->m_Title = new QLabel( this );
this->m_Title->setText( "Parameters dialog title" );
return( this->m_Parameters );
}
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::ParametersQtDialog::
+setParameters( Parameters* parameters )
+{
+ if( this->m_Parameters != NULL || parameters == NULL )
+ return( false );
+ this->m_Parameters = parameters;
+ this->m_WidgetsUpdated = false;
+ return( true );
+}
+
+// -------------------------------------------------------------------------
+int cpPlugins::Interface::ParametersQtDialog::
+exec( )
+{
+ this->_updateWidgets( );
+ this->updateView( );
+
+ int ret = this->QDialog::exec( );
+ if( ret == 1 )
+ this->updateParameters( );
+ else
+ this->updateView( );
+ return( ret );
+}
+
// -------------------------------------------------------------------------
void cpPlugins::Interface::ParametersQtDialog::
-addInteractor( vtkRenderWindowInteractor* interactor )
+updateParameters( )
{
- this->m_Interactors.insert( interactor );
+ if( this->m_Parameters == NULL )
+ return;
+
+ // Put values
+ auto& raw_params = this->m_Parameters->GetRawParameters( );
+ for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
+ {
+ QString pName = pIt->first.c_str( );
+ switch( pIt->second.first )
+ {
+ case Parameters::String:
+ case Parameters::OpenFileName:
+ case Parameters::SaveFileName:
+ case Parameters::PathName:
+ case Parameters::IntList:
+ case Parameters::UintList:
+ case Parameters::RealList:
+ case Parameters::OpenFileNameList:
+ {
+ QLineEdit* v_string = this->findChild< QLineEdit* >( pName );
+ if( v_string != NULL )
+ pIt->second.second = v_string->text( ).toStdString( );
+ }
+ break;
+ case Parameters::Bool:
+ {
+ QCheckBox* v_bool = this->findChild< QCheckBox* >( pName );
+ if( v_bool != NULL )
+ pIt->second.second = ( v_bool->isChecked( ) )? "1": "0";
+ }
+ break;
+ case Parameters::Int:
+ case Parameters::Uint:
+ {
+ QSpinBox* v_uint = this->findChild< QSpinBox* >( pName );
+ if( v_uint )
+ {
+ std::stringstream str;
+ str << v_uint->value( );
+ pIt->second.second = str.str( );
+
+ } // fi
+ }
+ break;
+ case Parameters::Real:
+ {
+ QDoubleSpinBox* v_double = this->findChild< QDoubleSpinBox* >( pName );
+ if( v_double )
+ {
+ std::stringstream str;
+ str << v_double->value( );
+ pIt->second.second = str.str( );
+
+ } // fi
+ }
+ break;
+ case Parameters::StringList:
+ break;
+ case Parameters::BoolList:
+ break;
+ case Parameters::SaveFileNameList:
+ break;
+ case Parameters::PathNameList:
+ break;
+ case Parameters::Choices:
+ {
+ QComboBox* v_choices = this->findChild< QComboBox* >( pName );
+ if( v_choices != NULL )
+ {
+ std::istringstream str_choices( pIt->second.second );
+ std::string real_choices;
+ std::getline( str_choices, real_choices, '@' );
+ pIt->second.second =
+ real_choices + "@" +
+ v_choices->currentText( ).toStdString( );
+
+ } // fi
+ }
+ break;
+ default:
+ break;
+ } // hctiws
+
+ } // rof
+ this->m_Parameters->Modified( );
}
// -------------------------------------------------------------------------
-cpPlugins::Interface::ParametersQtDialog::
-TInteractors& cpPlugins::Interface::ParametersQtDialog::
-getInteractors( )
+void cpPlugins::Interface::ParametersQtDialog::
+updateView( )
{
- return( this->m_Interactors );
+ if( this->m_Parameters == NULL )
+ return;
+
+ // Put values
+ auto& raw_params = this->m_Parameters->GetRawParameters( );
+ for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
+ {
+ QString pName = pIt->first.c_str( );
+ switch( pIt->second.first )
+ {
+ case Parameters::String:
+ case Parameters::OpenFileName:
+ case Parameters::SaveFileName:
+ case Parameters::PathName:
+ case Parameters::IntList:
+ case Parameters::UintList:
+ case Parameters::RealList:
+ case Parameters::OpenFileNameList:
+ {
+ QLineEdit* v_string = this->findChild< QLineEdit* >( pName );
+ if( v_string != NULL )
+ v_string->setText( pIt->second.second.c_str( ) );
+ }
+ break;
+ case Parameters::Bool:
+ {
+ QCheckBox* v_bool = this->findChild< QCheckBox* >( pName );
+ if( v_bool != NULL )
+ v_bool->setChecked( pIt->second.second == "1" );
+ }
+ break;
+ case Parameters::Int:
+ case Parameters::Uint:
+ {
+ QSpinBox* v_uint = this->findChild< QSpinBox* >( pName );
+ if( v_uint )
+ {
+ std::istringstream tok_str( pIt->second.second );
+ int v;
+ tok_str >> v;
+ v_uint->setValue( v );
+
+ } // fi
+ }
+ break;
+ case Parameters::Real:
+ {
+ QDoubleSpinBox* v_double = this->findChild< QDoubleSpinBox* >( pName );
+ if( v_double )
+ {
+ std::istringstream tok_str( pIt->second.second );
+ double v;
+ tok_str >> v;
+ v_double->setValue( v );
+
+ } // fi
+ }
+ break;
+ case Parameters::StringList:
+ break;
+ case Parameters::BoolList:
+ break;
+ case Parameters::SaveFileNameList:
+ break;
+ case Parameters::PathNameList:
+ break;
+ case Parameters::Choices:
+ {
+ QComboBox* v_choices = this->findChild< QComboBox* >( pName );
+ if( v_choices != NULL )
+ {
+ std::istringstream str_choices( pIt->second.second );
+ std::string choices, real_choice;
+ std::getline( str_choices, choices, '@' );
+ std::getline( str_choices, real_choice, '@' );
+ std::istringstream str( choices );
+ std::string token;
+ int id = -1, cont = 0;
+ while( std::getline( str, token, '#' ) )
+ {
+ if( token == real_choice )
+ id = cont;
+ cont++;
+
+ } // elihw
+
+ if( id > -1 )
+ v_choices->setCurrentIndex( id );
+
+ } // fi
+ }
+ break;
+ default:
+ break;
+ } // hctiws
+
+ } // rof
}
// -------------------------------------------------------------------------
-const cpPlugins::Interface::ParametersQtDialog::
-TInteractors& cpPlugins::Interface::ParametersQtDialog::
-getInteractors( ) const
+void cpPlugins::Interface::ParametersQtDialog::
+_addButtons( )
{
- return( this->m_Interactors );
+ // Add buttons
+ this->m_Buttons = new QDialogButtonBox(
+ QDialogButtonBox::Ok | QDialogButtonBox::Cancel
+ );
+ this->connect(
+ this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
+ );
+ this->connect(
+ this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
+ );
+ this->m_ToolsLayout->addWidget( this->m_Buttons );
+
+ this->updateView( );
+ this->m_WidgetsUpdated = true;
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::ParametersQtDialog::
-setParameters( Parameters* parameters )
+void cpPlugins::Interface::ParametersQtDialog::
+_updateWidgets( )
{
- if( this->m_Parameters != NULL || parameters == NULL )
- return( false );
- this->m_Parameters = parameters;
+ if( this->m_WidgetsUpdated || this->m_Parameters == NULL )
+ return;
// Set dialog title
auto filter = this->m_Parameters->GetProcessObject( );
std::stringstream title;
- title << "Parameters for \"" << filter->GetName( ) << "\"";
+ title
+ << "Parameters for an object of class \""
+ << filter->GetClassName( )
+ << "\"";
this->m_Title->setText( title.str( ).c_str( ) );
// Put values
w_input = v_double;
}
break;
- case Parameters::Index:
- break;
- case Parameters::Point:
- break;
- case Parameters::Vector:
- break;
case Parameters::OpenFileName:
{
QFrame* frame = new QFrame( this );
w_input = frame;
}
break;
- case Parameters::IndexList:
- break;
- case Parameters::PointList:
- break;
- case Parameters::VectorList:
- break;
case Parameters::OpenFileNameList:
{
QFrame* frame = new QFrame( this );
QHBoxLayout* layout = new QHBoxLayout( frame );
QLineEdit* v_string = new QLineEdit( frame );
v_string->setObjectName( pIt->first.c_str( ) );
+ v_string->setMaxLength( std::numeric_limits< int >::max( ) );
v_string->setText( pIt->second.second.c_str( ) );
QPushButton* v_button = new QPushButton( frame );
v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) );
} // rof
- // Add buttons
- this->m_Buttons = new QDialogButtonBox(
- QDialogButtonBox::Ok | QDialogButtonBox::Cancel
- );
- this->connect(
- this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
- );
- this->connect(
- this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
- );
- this->m_ToolsLayout->addWidget( this->m_Buttons );
-
// Update values
- this->updateView( );
-
- return( true );
-}
-
-// -------------------------------------------------------------------------
-int cpPlugins::Interface::ParametersQtDialog::
-exec( )
-{
- int ret = this->QDialog::exec( );
- if( ret == 1 )
- this->updateParameters( );
- else
- this->updateView( );
- return( ret );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::ParametersQtDialog::
-show( )
-{
- this->QDialog::show( );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::ParametersQtDialog::
-updateParameters( )
-{
- if( this->m_Parameters == NULL )
- return;
-
- // Put values
- auto& raw_params = this->m_Parameters->GetRawParameters( );
- for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
- {
- QString pName = pIt->first.c_str( );
- switch( pIt->second.first )
- {
- case Parameters::String:
- case Parameters::OpenFileName:
- case Parameters::SaveFileName:
- case Parameters::PathName:
- case Parameters::IntList:
- case Parameters::UintList:
- case Parameters::RealList:
- case Parameters::OpenFileNameList:
- {
- QLineEdit* v_string = this->findChild< QLineEdit* >( pName );
- if( v_string != NULL )
- pIt->second.second = v_string->text( ).toStdString( );
- }
- break;
- case Parameters::Bool:
- {
- QCheckBox* v_bool = this->findChild< QCheckBox* >( pName );
- if( v_bool != NULL )
- pIt->second.second = ( v_bool->isChecked( ) )? "1": "0";
- }
- break;
- case Parameters::Int:
- case Parameters::Uint:
- {
- QSpinBox* v_uint = this->findChild< QSpinBox* >( pName );
- if( v_uint )
- {
- std::stringstream str;
- str << v_uint->value( );
- pIt->second.second = str.str( );
-
- } // fi
- }
- break;
- case Parameters::Real:
- {
- QDoubleSpinBox* v_double = this->findChild< QDoubleSpinBox* >( pName );
- if( v_double )
- {
- std::stringstream str;
- str << v_double->value( );
- pIt->second.second = str.str( );
-
- } // fi
- }
- break;
- case Parameters::Index:
- break;
- case Parameters::Point:
- break;
- case Parameters::Vector:
- break;
- case Parameters::StringList:
- break;
- case Parameters::BoolList:
- break;
- case Parameters::IndexList:
- break;
- case Parameters::PointList:
- break;
- case Parameters::VectorList:
- break;
- case Parameters::SaveFileNameList:
- break;
- case Parameters::PathNameList:
- break;
- case Parameters::Choices:
- {
- QComboBox* v_choices = this->findChild< QComboBox* >( pName );
- if( v_choices != NULL )
- {
- std::istringstream str_choices( pIt->second.second );
- std::string real_choices;
- std::getline( str_choices, real_choices, '@' );
- pIt->second.second =
- real_choices + "@" +
- v_choices->currentText( ).toStdString( );
-
- } // fi
- }
- break;
- default:
- break;
- } // hctiws
-
- } // rof
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::ParametersQtDialog::
-updateView( )
-{
- if( this->m_Parameters == NULL )
- return;
-
- // Put values
- auto& raw_params = this->m_Parameters->GetRawParameters( );
- for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt )
- {
- QString pName = pIt->first.c_str( );
- switch( pIt->second.first )
- {
- case Parameters::String:
- case Parameters::OpenFileName:
- case Parameters::SaveFileName:
- case Parameters::PathName:
- case Parameters::IntList:
- case Parameters::UintList:
- case Parameters::RealList:
- case Parameters::OpenFileNameList:
- {
- QLineEdit* v_string = this->findChild< QLineEdit* >( pName );
- if( v_string != NULL )
- v_string->setText( pIt->second.second.c_str( ) );
- }
- break;
- case Parameters::Bool:
- {
- QCheckBox* v_bool = this->findChild< QCheckBox* >( pName );
- if( v_bool != NULL )
- v_bool->setChecked( pIt->second.second == "1" );
- }
- break;
- case Parameters::Int:
- case Parameters::Uint:
- {
- QSpinBox* v_uint = this->findChild< QSpinBox* >( pName );
- if( v_uint )
- {
- std::istringstream tok_str( pIt->second.second );
- int v;
- tok_str >> v;
- v_uint->setValue( v );
-
- } // fi
- }
- break;
- case Parameters::Real:
- {
- QDoubleSpinBox* v_double = this->findChild< QDoubleSpinBox* >( pName );
- if( v_double )
- {
- std::istringstream tok_str( pIt->second.second );
- double v;
- tok_str >> v;
- v_double->setValue( v );
-
- } // fi
- }
- break;
- case Parameters::Index:
- break;
- case Parameters::Point:
- break;
- case Parameters::Vector:
- break;
- case Parameters::StringList:
- break;
- case Parameters::BoolList:
- break;
- case Parameters::IndexList:
- break;
- case Parameters::PointList:
- break;
- case Parameters::VectorList:
- break;
- case Parameters::SaveFileNameList:
- break;
- case Parameters::PathNameList:
- break;
- case Parameters::Choices:
- {
- QComboBox* v_choices = this->findChild< QComboBox* >( pName );
- if( v_choices != NULL )
- {
- std::istringstream str_choices( pIt->second.second );
- std::string choices, real_choice;
- std::getline( str_choices, choices, '@' );
- std::getline( str_choices, real_choice, '@' );
- std::istringstream str( choices );
- std::string token;
- int id = -1, cont = 0;
- while( std::getline( str, token, '#' ) )
- {
- if( token == real_choice )
- id = cont;
- cont++;
-
- } // elihw
-
- if( id > -1 )
- v_choices->setCurrentIndex( id );
-
- } // fi
- }
- break;
- default:
- break;
- } // hctiws
-
- } // rof
+ this->_addButtons( );
}
// -------------------------------------------------------------------------
this->m_Parameters->GetOpenFileName( param_name );
if( param_value == "" )
param_value = ".";
- QStringList filters;
- filters << "Any file (*)";
+ QStringList dialog_filters;
+ std::string extensions =
+ this->m_Parameters->GetAcceptedFileExtensions( param_name );
+ if( extensions != "" )
+ dialog_filters << extensions.c_str( );
+ dialog_filters << "Any file (*)";
// Show dialog and check if it was accepted
QFileDialog dialog( this );
dialog.setFileMode( QFileDialog::ExistingFile );
dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
- dialog.setNameFilters( filters );
+ dialog.setNameFilters( dialog_filters );
dialog.setAcceptMode( QFileDialog::AcceptOpen );
if( dialog.exec( ) )
line->setText( *( dialog.selectedFiles( ).begin( ) ) );
this->m_Parameters->GetSaveFileName( param_name );
if( param_value == "" )
param_value = ".";
- QStringList filters;
- filters << "Any file (*)";
+ QStringList dialog_filters;
+ std::string extensions =
+ this->m_Parameters->GetAcceptedFileExtensions( param_name );
+ if( extensions != "" )
+ dialog_filters << extensions.c_str( );
+ dialog_filters << "Any file (*)";
// Show dialog and check if it was accepted
QFileDialog dialog( this );
dialog.setFileMode( QFileDialog::AnyFile );
dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) );
- dialog.setNameFilters( filters );
+ dialog.setNameFilters( dialog_filters );
dialog.setAcceptMode( QFileDialog::AcceptSave );
if( dialog.exec( ) )
line->setText( *( dialog.selectedFiles( ).begin( ) ) );
std::string param_name = line->objectName( ).toStdString( );
if( param_name != "" )
{
- QStringList filters;
- filters << "Any file (*)";
+ QStringList dialog_filters;
+ std::string extensions =
+ this->m_Parameters->GetAcceptedFileExtensions( param_name );
+ if( extensions != "" )
+ dialog_filters << extensions.c_str( );
+ dialog_filters << "Any file (*)";
// Show dialog and check if it was accepted
QFileDialog dialog( this );
dialog.setFileMode( QFileDialog::ExistingFiles );
- dialog.setNameFilters( filters );
+ dialog.setNameFilters( dialog_filters );
dialog.setAcceptMode( QFileDialog::AcceptOpen );
if( dialog.exec( ) )
{
std::string( "\"" )
).c_str( ),
"Value:",
- 0, -2147483647, 2147483647, 1,
- &ok
+ 0,
+ -std::numeric_limits< int >::max( ),
+ std::numeric_limits< int >::max( ),
+ 1, &ok
);
if( ok )
{
std::string( "\"" )
).c_str( ),
"Value:",
- 0, 0, 2147483647, 1,
+ 0, 0, std::numeric_limits< int >::max( ), 1,
&ok
);
if( ok )
std::string( "\"" )
).c_str( ),
"Value:",
- 0, -2147483647, 2147483647, 1,
- &ok
+ 0,
+ -std::numeric_limits< double >::max( ),
+ std::numeric_limits< double >::max( ),
+ 1, &ok
);
if( ok )
{