From: Leonardo Florez-Valencia Date: Mon, 18 Jan 2016 03:26:43 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~267 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=de874ea850042e77a99a456188f423c8df2e374f;p=cpPlugins.git ... --- diff --git a/lib/cpPlugins/Interface/Parameters.cxx b/lib/cpPlugins/Interface/Parameters.cxx index 3423bea..7e2459c 100644 --- a/lib/cpPlugins/Interface/Parameters.cxx +++ b/lib/cpPlugins/Interface/Parameters.cxx @@ -2,14 +2,6 @@ #include #include -// ------------------------------------------------------------------------- -const cpPlugins::Interface::Parameters:: -TParameters& cpPlugins::Interface::Parameters:: -GetRawParameters( ) const -{ - return( this->m_Parameters ); -} - // ------------------------------------------------------------------------- cpPlugins::Interface:: ProcessObject* cpPlugins::Interface::Parameters:: @@ -89,7 +81,8 @@ GetTypeAsString( const TString& name ) const else cpPlugins_Parameters_TypeAsString( Index ); else cpPlugins_Parameters_TypeAsString( Point ); else cpPlugins_Parameters_TypeAsString( Vector ); - else cpPlugins_Parameters_TypeAsString( FileName ); + else cpPlugins_Parameters_TypeAsString( OpenFileName ); + else cpPlugins_Parameters_TypeAsString( SaveFileName ); else cpPlugins_Parameters_TypeAsString( PathName ); else cpPlugins_Parameters_TypeAsString( StringList ); else cpPlugins_Parameters_TypeAsString( BoolList ); @@ -99,7 +92,8 @@ GetTypeAsString( const TString& name ) const else cpPlugins_Parameters_TypeAsString( IndexList ); else cpPlugins_Parameters_TypeAsString( PointList ); else cpPlugins_Parameters_TypeAsString( VectorList ); - else cpPlugins_Parameters_TypeAsString( FileNameList ); + else cpPlugins_Parameters_TypeAsString( OpenFileNameList ); + else cpPlugins_Parameters_TypeAsString( SaveFileNameList ); else cpPlugins_Parameters_TypeAsString( PathNameList ); else cpPlugins_Parameters_TypeAsString( Choices ); else return( "NoType" ); @@ -122,7 +116,8 @@ GetTypeFromString( const std::string& t ) else cpPlugins_Parameters_TypeFromString( Index, t ); else cpPlugins_Parameters_TypeFromString( Point, t ); else cpPlugins_Parameters_TypeFromString( Vector, t ); - else cpPlugins_Parameters_TypeFromString( FileName, t ); + else cpPlugins_Parameters_TypeFromString( OpenFileName, t ); + else cpPlugins_Parameters_TypeFromString( SaveFileName, t ); else cpPlugins_Parameters_TypeFromString( PathName, t ); else cpPlugins_Parameters_TypeFromString( StringList, t ); else cpPlugins_Parameters_TypeFromString( BoolList, t ); @@ -132,7 +127,8 @@ GetTypeFromString( const std::string& t ) else cpPlugins_Parameters_TypeFromString( IndexList, t ); else cpPlugins_Parameters_TypeFromString( PointList, t ); else cpPlugins_Parameters_TypeFromString( VectorList, t ); - else cpPlugins_Parameters_TypeFromString( FileNameList, t ); + else cpPlugins_Parameters_TypeFromString( OpenFileNameList, t ); + else cpPlugins_Parameters_TypeFromString( SaveFileNameList, t ); else cpPlugins_Parameters_TypeFromString( PathNameList, t ); else cpPlugins_Parameters_TypeFromString( Choices, t ); else return( Self::NoType ); @@ -361,4 +357,20 @@ PrintSelf( std::ostream& os, itk::Indent indent ) const << std::endl; } +// ------------------------------------------------------------------------- +cpPlugins::Interface::Parameters:: +TParameters& cpPlugins::Interface::Parameters:: +GetRawParameters( ) +{ + return( this->m_Parameters ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface::Parameters:: +TParameters& cpPlugins::Interface::Parameters:: +GetRawParameters( ) const +{ + return( this->m_Parameters ); +} + // eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/Parameters.h b/lib/cpPlugins/Interface/Parameters.h index a2cb861..765f82f 100644 --- a/lib/cpPlugins/Interface/Parameters.h +++ b/lib/cpPlugins/Interface/Parameters.h @@ -139,12 +139,15 @@ namespace cpPlugins { // Some forward declarations class ProcessObject; + class ParametersQtDialog; /** */ class cpPlugins_Interface_EXPORT Parameters : public itk::Object { + friend class ParametersQtDialog; + public: typedef Parameters Self; typedef itk::Object Superclass; @@ -153,14 +156,14 @@ namespace cpPlugins enum Type { - String , Bool , Int , - Uint , Real , Index , - Point , Vector , FileName , - PathName , StringList , BoolList , - IntList , UintList , RealList , - IndexList , PointList , VectorList , - FileNameList , PathNameList , Choices , - NoType + String , Bool , Int , + Uint , Real , Index , + Point , Vector , OpenFileName , + SaveFileName , PathName , StringList , + BoolList , IntList , UintList , + RealList , IndexList , PointList , + VectorList , OpenFileNameList , SaveFileNameList , + PathNameList , Choices , NoType }; typedef bool TBool; @@ -168,7 +171,8 @@ namespace cpPlugins typedef unsigned long TUint; typedef double TReal; typedef std::string TString; - typedef std::string TFileName; + typedef std::string TOpenFileName; + typedef std::string TSaveFileName; typedef std::string TPathName; typedef std::pair< Self::Type, std::string > TParameter; @@ -186,7 +190,8 @@ namespace cpPlugins cpPlugins_Parameters_Configure( Index ); cpPlugins_Parameters_Configure( Point ); cpPlugins_Parameters_Configure( Vector ); - cpPlugins_Parameters_Configure( FileName ); + cpPlugins_Parameters_Configure( OpenFileName ); + cpPlugins_Parameters_Configure( SaveFileName ); cpPlugins_Parameters_Configure( PathName ); cpPlugins_Parameters_Configure( StringList ); cpPlugins_Parameters_Configure( BoolList ); @@ -196,7 +201,8 @@ namespace cpPlugins cpPlugins_Parameters_Configure( IndexList ); cpPlugins_Parameters_Configure( PointList ); cpPlugins_Parameters_Configure( VectorList ); - cpPlugins_Parameters_Configure( FileNameList ); + cpPlugins_Parameters_Configure( OpenFileNameList ); + cpPlugins_Parameters_Configure( SaveFileNameList ); cpPlugins_Parameters_Configure( PathNameList ); cpPlugins_Parameters_Configure( Choices ); @@ -204,7 +210,8 @@ namespace cpPlugins cpPlugins_Parameters_GetSet( Int ); cpPlugins_Parameters_GetSet( Uint ); cpPlugins_Parameters_GetSet( Real ); - cpPlugins_Parameters_GetSet( FileName ); + cpPlugins_Parameters_GetSet( OpenFileName ); + cpPlugins_Parameters_GetSet( SaveFileName ); cpPlugins_Parameters_GetSet( PathName ); cpPlugins_Parameters_GetSetList( String ); @@ -212,12 +219,12 @@ namespace cpPlugins cpPlugins_Parameters_GetSetList( Int ); cpPlugins_Parameters_GetSetList( Uint ); cpPlugins_Parameters_GetSetList( Real ); - cpPlugins_Parameters_GetSetList( FileName ); + cpPlugins_Parameters_GetSetList( OpenFileName ); + cpPlugins_Parameters_GetSetList( SaveFileName ); cpPlugins_Parameters_GetSetList( PathName ); public: // To impact pipeline - const TParameters& GetRawParameters( ) const; virtual ProcessObject* GetProcessObject( ); virtual const ProcessObject* GetProcessObject( ) const; virtual void SetProcessObject( ProcessObject* v ); @@ -315,6 +322,9 @@ namespace cpPlugins virtual ~Parameters( ); void PrintSelf( std::ostream& os, itk::Indent indent ) const; + TParameters& GetRawParameters( ); + const TParameters& GetRawParameters( ) const; + private: // Purposely not implemented Parameters( const Self& other ); diff --git a/lib/cpPlugins/Interface/ParametersQtDialog.cxx b/lib/cpPlugins/Interface/ParametersQtDialog.cxx index 431ddfe..3df62ee 100644 --- a/lib/cpPlugins/Interface/ParametersQtDialog.cxx +++ b/lib/cpPlugins/Interface/ParametersQtDialog.cxx @@ -10,9 +10,10 @@ #include #include -#include #include +#include #include +#include #include #include #include @@ -54,7 +55,7 @@ public: else if( this->Dialog->getParameters( )->HasPoint( this->Name ) ) { this->Dialog->getParameters( )->SetPoint( this->Name, 3, seed ); - this->Dialog->syncParameters( ); + this->Dialog->updateParameters( ); auto filter = this->Dialog->getParameters( )->GetProcessObject( ); if( filter != NULL ) { @@ -90,8 +91,7 @@ public: cpPlugins::Interface::ParametersQtDialog:: ParametersQtDialog( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f ), - m_Parameters( NULL ), - m_IsModal( false ) + m_Parameters( NULL ) { this->m_Title = new QLabel( this ); this->m_Title->setText( "Parameters dialog title" ); @@ -111,13 +111,6 @@ cpPlugins::Interface::ParametersQtDialog:: delete this->m_MainLayout; } -// ------------------------------------------------------------------------- -bool cpPlugins::Interface::ParametersQtDialog:: -IsModal( ) const -{ - return( this->m_IsModal ); -} - // ------------------------------------------------------------------------- cpPlugins::Interface:: Parameters* cpPlugins::Interface::ParametersQtDialog:: @@ -153,10 +146,9 @@ getInteractors( ) const bool cpPlugins::Interface::ParametersQtDialog:: setParameters( Parameters* parameters ) { - this->m_IsModal = true; - this->m_Parameters = parameters; - if( this->m_Parameters == NULL ) + if( this->m_Parameters != NULL || parameters == NULL ) return( false ); + this->m_Parameters = parameters; // Set dialog title auto filter = this->m_Parameters->GetProcessObject( ); @@ -174,6 +166,7 @@ setParameters( Parameters* parameters ) case Parameters::String: { QLineEdit* v_string = new QLineEdit( this ); + v_string->setObjectName( pIt->first.c_str( ) ); v_string->setText( pIt->second.second.c_str( ) ); w_input = v_string; } @@ -181,6 +174,7 @@ setParameters( Parameters* parameters ) case Parameters::Bool: { QCheckBox* v_bool = new QCheckBox( this ); + v_bool->setObjectName( pIt->first.c_str( ) ); v_bool->setText( "[ON/OFF]" ); v_bool->setChecked( pIt->second.second == "1" ); w_input = v_bool; @@ -193,6 +187,7 @@ setParameters( Parameters* parameters ) int v; tok_str >> v; QSpinBox* v_uint = new QSpinBox( this ); + v_uint->setObjectName( pIt->first.c_str( ) ); if( pIt->second.first == Parameters::Uint ) v_uint->setMinimum( 0 ); else @@ -208,6 +203,7 @@ setParameters( Parameters* parameters ) double v; tok_str >> v; QDoubleSpinBox* v_double = new QDoubleSpinBox( this ); + v_double->setObjectName( pIt->first.c_str( ) ); v_double->setDecimals( 3 ); v_double->setMinimum( -std::numeric_limits< double >::max( ) ); v_double->setMaximum( std::numeric_limits< double >::max( ) ); @@ -221,44 +217,149 @@ setParameters( Parameters* parameters ) break; case Parameters::Vector: break; - case Parameters::FileName: + case Parameters::OpenFileName: { 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->setText( pIt->second.second.c_str( ) ); QPushButton* v_button = new QPushButton( frame ); - v_button->setObjectName( pIt->first.c_str( ) ); + v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) ); v_button->setText( "..." ); v_button->connect( v_button, SIGNAL( clicked( ) ), - this, SLOT( _dlg_MultipleFiles( ) ) + this, SLOT( _dlg_OpenSingleFile( ) ) + ); + layout->addWidget( v_string ); + layout->addWidget( v_button ); + w_input = frame; + } + case Parameters::SaveFileName: + { + 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->setText( pIt->second.second.c_str( ) ); + QPushButton* v_button = new QPushButton( frame ); + v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) ); + v_button->setText( "..." ); + v_button->connect( + v_button, SIGNAL( clicked( ) ), + this, SLOT( _dlg_SaveSingleFile( ) ) ); - layout->addWidget( v_string ); layout->addWidget( v_button ); w_input = frame; } break; case Parameters::PathName: - break; + { + 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->setText( pIt->second.second.c_str( ) ); + QPushButton* v_button = new QPushButton( frame ); + v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) ); + v_button->setText( "..." ); + v_button->connect( + v_button, SIGNAL( clicked( ) ), + this, SLOT( _dlg_OpenSinglePath( ) ) + ); + layout->addWidget( v_string ); + layout->addWidget( v_button ); + w_input = frame; + } + break; case Parameters::StringList: break; case Parameters::BoolList: break; case Parameters::IntList: - break; + { + 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->setText( pIt->second.second.c_str( ) ); + QPushButton* v_button = new QPushButton( frame ); + v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) ); + v_button->setText( "+" ); + v_button->connect( + v_button, SIGNAL( clicked( ) ), + this, SLOT( _dlg_AddInt( ) ) + ); + layout->addWidget( v_string ); + layout->addWidget( v_button ); + w_input = frame; + } + break; case Parameters::UintList: - break; + { + 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->setText( pIt->second.second.c_str( ) ); + QPushButton* v_button = new QPushButton( frame ); + v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) ); + v_button->setText( "+" ); + v_button->connect( + v_button, SIGNAL( clicked( ) ), + this, SLOT( _dlg_AddUint( ) ) + ); + layout->addWidget( v_string ); + layout->addWidget( v_button ); + w_input = frame; + } + break; case Parameters::RealList: - break; + { + 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->setText( pIt->second.second.c_str( ) ); + QPushButton* v_button = new QPushButton( frame ); + v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) ); + v_button->setText( "+" ); + v_button->connect( + v_button, SIGNAL( clicked( ) ), + this, SLOT( _dlg_AddReal( ) ) + ); + layout->addWidget( v_string ); + layout->addWidget( v_button ); + w_input = frame; + } + break; case Parameters::IndexList: break; case Parameters::PointList: break; case Parameters::VectorList: break; - case Parameters::FileNameList: + 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->setText( pIt->second.second.c_str( ) ); + QPushButton* v_button = new QPushButton( frame ); + v_button->setObjectName( ( pIt->first + "_=?btn" ).c_str( ) ); + v_button->setText( "..." ); + v_button->connect( + v_button, SIGNAL( clicked( ) ), + this, SLOT( _dlg_OpenMultipleFiles( ) ) + ); + layout->addWidget( v_string ); + layout->addWidget( v_button ); + w_input = frame; + } + break; + case Parameters::SaveFileNameList: break; case Parameters::PathNameList: break; @@ -269,49 +370,9 @@ setParameters( Parameters* parameters ) break; } // hctiws - /* TODO - else if( pt == Parameters::Real ) - else if( - pt == Parameters::StringList || - pt == Parameters::IntList || - pt == Parameters::UintList || - pt == Parameters::RealList - ) - { - cpPlugins::Interface::ParametersListWidget* l_double = - new cpPlugins::Interface::ParametersListWidget( *nIt, this ); - w_input = l_double; - } - else if( pt == Parameters::Point || pt == Parameters::Index ) - { - 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 ) - { - TStyle* style = - dynamic_cast< TStyle* >( ( *iIt )->GetInteractorStyle( ) ); - if( style != NULL ) - { - style->SeedWidgetOn( ); - style->SetSeedWidgetCommand( command ); - - } // fi - - } // rof - this->m_IsModal = false; - - } // fi - */ - // Ok, a representation was created if( w_input != NULL ) { - w_input->setObjectName( QString( pIt->first.c_str( ) ) ); - QHBoxLayout* new_layout = new QHBoxLayout( ); QLabel* label = new QLabel( this ); label->setText( QString( pIt->first.c_str( ) ) ); @@ -322,27 +383,31 @@ setParameters( Parameters* parameters ) } // fi } // rof - return( this->m_IsModal ); + + // 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 ); + + return( true ); } // ------------------------------------------------------------------------- int cpPlugins::Interface::ParametersQtDialog:: exec( ) { - if( !this->m_IsModal ) - return( 0 ); - - // Add buttons - QDialogButtonBox* bb = new QDialogButtonBox( - QDialogButtonBox::Ok | QDialogButtonBox::Cancel - ); - QObject::connect( bb, SIGNAL( accepted( ) ), this, SLOT( accept( ) ) ); - QObject::connect( bb, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) ); - this->m_ToolsLayout->addWidget( bb ); - int ret = this->QDialog::exec( ); if( ret == 1 ) - this->syncParameters( ); + this->updateParameters( ); + else + this->updateView( ); return( ret ); } @@ -350,187 +415,485 @@ exec( ) void cpPlugins::Interface::ParametersQtDialog:: show( ) { - if( this->m_IsModal ) - return; - this->QDialog::show( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::ParametersQtDialog:: -syncParameters( ) +updateParameters( ) { 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 ) + // Put values + auto& raw_params = this->m_Parameters->GetRawParameters( ); + for( auto pIt = raw_params.begin( ); pIt != raw_params.end( ); ++pIt ) { - Parameters::Type pt = this->m_Parameters->GetType( *nIt ); - - if( pt == Parameters::String ) + QString pName = pIt->first.c_str( ); + switch( pIt->second.first ) { - QLineEdit* v = this->findChild< QLineEdit* >( nIt->c_str( ) ); - if( v != NULL ) - this->m_Parameters->SetString( *nIt, v->text( ).toStdString( ) ); + 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"; } - else if( pt == Parameters::Bool ) + break; + case Parameters::Int: + case Parameters::Uint: { - QCheckBox* v = this->findChild< QCheckBox* >( nIt->c_str( ) ); - if( v != NULL ) - this->m_Parameters->SetBool( *nIt, v->isChecked( ) ); + QSpinBox* v_uint = this->findChild< QSpinBox* >( pName ); + if( v_uint ) + { + std::stringstream str; + str << v_uint->value( ); + pIt->second.second = str.str( ); + + } // fi } - else if( pt == Parameters::Uint ) + break; + case Parameters::Real: { - QSpinBox* v = this->findChild< QSpinBox* >( nIt->c_str( ) ); - if( v != NULL ) - this->m_Parameters->SetUint( *nIt, v->value( ) ); + QDoubleSpinBox* v_double = this->findChild< QDoubleSpinBox* >( pName ); + if( v_double ) + { + std::stringstream str; + str << v_double->value( ); + pIt->second.second = str.str( ); + + } // fi } - else if( pt == Parameters::Int ) + 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: + 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 ) { - QSpinBox* v = this->findChild< QSpinBox* >( nIt->c_str( ) ); - if( v != NULL ) - this->m_Parameters->SetInt( *nIt, v->value( ) ); + 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( ) ); } - else if( pt == Parameters::Real ) + break; + case Parameters::Bool: { - QDoubleSpinBox* v = this->findChild< QDoubleSpinBox* >( nIt->c_str( ) ); - if( v != NULL ) - this->m_Parameters->SetReal( *nIt, v->value( ) ); + QCheckBox* v_bool = this->findChild< QCheckBox* >( pName ); + if( v_bool != NULL ) + v_bool->setChecked( pIt->second.second == "1" ); } - 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 ) + break; + case Parameters::Int: + case Parameters::Uint: + { + QSpinBox* v_uint = this->findChild< QSpinBox* >( pName ); + if( v_uint ) { - 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 + std::istringstream tok_str( pIt->second.second ); + int v; + tok_str >> v; + v_uint->setValue( v ); } // fi } - else if( pt == Parameters::Point || pt == Parameters::Index ) + break; + case Parameters::Real: { - } // fi + 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: + break; + default: + break; + } // hctiws } // rof } // ------------------------------------------------------------------------- void cpPlugins::Interface::ParametersQtDialog:: -_dlg_MultipleFiles( ) +_dlg_OpenSingleFile( ) { - QObject* sender = this->sender( ); - // std::cout << "OK " << sender << " " << sender->objectName( ).toStdString( ) << std::endl; -} + QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) ); + if( btn != NULL ) + { + std::string bName = btn->objectName( ).toStdString( ); + std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) ); + QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) ); + if( line != NULL ) + { + std::string param_name = line->objectName( ).toStdString( ); + if( param_name != "" ) + { + std::string param_value = + this->m_Parameters->GetOpenFileName( param_name ); + if( param_value == "" ) + param_value = "."; + QStringList filters; + 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.setAcceptMode( QFileDialog::AcceptOpen ); + if( dialog.exec( ) ) + line->setText( *( dialog.selectedFiles( ).begin( ) ) ); + } // fi + } // fi + } // fi +} +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +_dlg_SaveSingleFile( ) +{ + QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) ); + if( btn != NULL ) + { + std::string bName = btn->objectName( ).toStdString( ); + std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) ); + QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) ); + if( line != NULL ) + { + std::string param_name = line->objectName( ).toStdString( ); + if( param_name != "" ) + { + std::string param_value = + this->m_Parameters->GetSaveFileName( param_name ); + if( param_value == "" ) + param_value = "."; + QStringList filters; + 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.setAcceptMode( QFileDialog::AcceptSave ); + if( dialog.exec( ) ) + line->setText( *( dialog.selectedFiles( ).begin( ) ) ); + } // fi + } // fi -/* TODO - enum Type - { - Index, - Point, - StringList, - BoolList, - IntList, - UintList, - IndexList, - PointList, - Choices, - NoType - }; -*/ -/* - } - 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 ) - { - 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 ) + } // fi +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +_dlg_OpenSinglePath( ) +{ + QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) ); + if( btn != NULL ) + { + std::string bName = btn->objectName( ).toStdString( ); + std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) ); + QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) ); + if( line != NULL ) { - 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::string param_name = line->objectName( ).toStdString( ); + if( param_name != "" ) + { + std::string param_value = + this->m_Parameters->GetPathName( param_name ); + if( param_value == "" ) + param_value = "."; + + // Show dialog and check if it was accepted + QFileDialog dialog( this ); + dialog.setFileMode( QFileDialog::Directory ); + dialog.setDirectory( QFileDialog::tr( param_value.c_str( ) ) ); + dialog.setAcceptMode( QFileDialog::AcceptOpen ); + if( dialog.exec( ) ) + line->setText( *( dialog.selectedFiles( ).begin( ) ) ); + + } // fi + + } // fi + + } // fi +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +_dlg_OpenMultipleFiles( ) +{ + QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) ); + if( btn != NULL ) + { + std::string bName = btn->objectName( ).toStdString( ); + std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) ); + + QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) ); + if( line != NULL ) { - 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::string param_name = line->objectName( ).toStdString( ); + if( param_name != "" ) + { + QStringList filters; + filters << "Any file (*)"; + + // Show dialog and check if it was accepted + QFileDialog dialog( this ); + dialog.setFileMode( QFileDialog::ExistingFiles ); + dialog.setNameFilters( filters ); + dialog.setAcceptMode( QFileDialog::AcceptOpen ); + if( dialog.exec( ) ) + { + if( dialog.selectedFiles( ).size( ) > 0 ) + { + std::stringstream str; + auto files = dialog.selectedFiles( ); + auto fIt = files.begin( ); + str << fIt->toStdString( ); + ++fIt; + for( ; fIt != files.end( ); ++fIt ) + str << "#" << fIt->toStdString( ); + line->setText( str.str( ).c_str( ) ); + + } // fi + + } // fi + + } // fi + + } // fi + + } // fi +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +_dlg_AddInt( ) +{ + QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) ); + if( btn != NULL ) + { + std::string bName = btn->objectName( ).toStdString( ); + std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) ); + QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) ); + if( line != NULL ) { - std::vector< double > values = lst->GetDoubleValues( ); - for( int r = 0; r < values.size( ); ++r ) - this->m_Parameters->AddToRealList( *nIt, values[ r ] ); + std::string param_name = line->objectName( ).toStdString( ); + if( param_name != "" ) + { + bool ok; + int value = + QInputDialog::getInt( + this, + ( + std::string( "Add new value to \"" ) + + param_name + + std::string( "\"" ) + ).c_str( ), + "Value:", + 0, -2147483647, 2147483647, 1, + &ok + ); + if( ok ) + { + std::string values = line->text( ).toStdString( ); + if( values != "" ) + values += "#"; + std::stringstream str; + str << values << value; + line->setText( str.str( ).c_str( ) ); + + } // fi + + } // fi } // fi + } // fi +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +_dlg_AddUint( ) +{ + QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) ); + if( btn != NULL ) + { + std::string bName = btn->objectName( ).toStdString( ); + std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) ); + QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) ); + if( line != NULL ) + { + std::string param_name = line->objectName( ).toStdString( ); + if( param_name != "" ) + { + bool ok; + int value = + QInputDialog::getInt( + this, + ( + std::string( "Add new value to \"" ) + + param_name + + std::string( "\"" ) + ).c_str( ), + "Value:", + 0, 0, 2147483647, 1, + &ok + ); + if( ok ) + { + std::string values = line->text( ).toStdString( ); + if( values != "" ) + values += "#"; + std::stringstream str; + str << values << value; + line->setText( str.str( ).c_str( ) ); + + } // fi + + } // fi + } // fi + } // fi +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +_dlg_AddReal( ) +{ + QPushButton* btn = dynamic_cast< QPushButton* >( this->sender( ) ); + if( btn != NULL ) + { + std::string bName = btn->objectName( ).toStdString( ); + std::string line_name = bName.substr( 0, bName.find( "_=?btn" ) ); + QLineEdit* line = this->findChild< QLineEdit* >( line_name.c_str( ) ); + if( line != NULL ) + { + std::string param_name = line->objectName( ).toStdString( ); + if( param_name != "" ) + { + bool ok; + double value = + QInputDialog::getDouble( + this, + ( + std::string( "Add new value to \"" ) + + param_name + + std::string( "\"" ) + ).c_str( ), + "Value:", + 0, -2147483647, 2147483647, 1, + &ok + ); + if( ok ) + { + std::string values = line->text( ).toStdString( ); + if( values != "" ) + values += "#"; + std::stringstream str; + str << values << value; + line->setText( str.str( ).c_str( ) ); + + } // fi + + } // fi + } // fi - } // rof - return( true ); - } -*/ + } // fi +} #endif // cpPlugins_Interface_QT4 diff --git a/lib/cpPlugins/Interface/ParametersQtDialog.h b/lib/cpPlugins/Interface/ParametersQtDialog.h index ee5c238..4d4d37f 100644 --- a/lib/cpPlugins/Interface/ParametersQtDialog.h +++ b/lib/cpPlugins/Interface/ParametersQtDialog.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -38,7 +39,6 @@ namespace cpPlugins ParametersQtDialog( QWidget* parent = 0, Qt::WindowFlags f = 0 ); virtual ~ParametersQtDialog( ); - bool IsModal( ) const; Parameters* getParameters( ) const; void addInteractor( vtkRenderWindowInteractor* interactor ); TInteractors& getInteractors( ); @@ -47,17 +47,25 @@ namespace cpPlugins virtual int exec( ); virtual void show( ); - void syncParameters( ); + + void updateParameters( ); + void updateView( ); protected slots: - void _dlg_MultipleFiles( ); + void _dlg_OpenSingleFile( ); + void _dlg_SaveSingleFile( ); + void _dlg_OpenSinglePath( ); + void _dlg_OpenMultipleFiles( ); + void _dlg_AddInt( ); + void _dlg_AddUint( ); + void _dlg_AddReal( ); protected: Parameters* m_Parameters; QLabel* m_Title; QGridLayout* m_MainLayout; QVBoxLayout* m_ToolsLayout; - bool m_IsModal; + QDialogButtonBox* m_Buttons; TInteractors m_Interactors; }; diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index fc010b8..db873e9 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -165,19 +165,10 @@ ExecConfigurationDialog( QWidget* parent ) this->m_ParametersDialog->setParent( NULL ); this->m_ParametersDialog->setParameters( this->m_Parameters ); - if( !( this->m_ParametersDialog->IsModal( ) ) ) - { - this->m_ParametersDialog->show( ); - r = Self::DialogResult_Modal; - } + if( this->m_ParametersDialog->exec( ) == 1 ) + r = Self::DialogResult_NoModal; else - { - if( this->m_ParametersDialog->exec( ) == 1 ) - r = Self::DialogResult_NoModal; - else - r = Self::DialogResult_Cancel; - - } // fi + r = Self::DialogResult_Cancel; } else r = Self::DialogResult_Cancel; diff --git a/lib/cpPlugins/Plugins/IO/ImageReader.cxx b/lib/cpPlugins/Plugins/IO/ImageReader.cxx index e18c987..e1f3c66 100644 --- a/lib/cpPlugins/Plugins/IO/ImageReader.cxx +++ b/lib/cpPlugins/Plugins/IO/ImageReader.cxx @@ -58,7 +58,7 @@ ImageReader( ) { this->_MakeOutput< cpPlugins::Interface::Image >( "Output" ); - this->m_Parameters->ConfigureAsFileNameList( "FileNames" ); + this->m_Parameters->ConfigureAsOpenFileNameList( "FileNames" ); this->m_Parameters->ConfigureAsBool( "VectorType" ); this->m_Parameters->SetBool( "VectorType", false ); } @@ -74,7 +74,7 @@ std::string cpPlugins::IO::ImageReader:: _GenerateData( ) { // Get filenames - TStringList names = this->m_Parameters->GetFileNameList( "FileNames" ); + TStringList names = this->m_Parameters->GetOpenFileNameList( "FileNames" ); std::string r = ""; if( names.size( ) >= 1 ) diff --git a/lib/cpPlugins/Plugins/IO/ImageWriter.cxx b/lib/cpPlugins/Plugins/IO/ImageWriter.cxx index 76ffd84..5b2f89b 100644 --- a/lib/cpPlugins/Plugins/IO/ImageWriter.cxx +++ b/lib/cpPlugins/Plugins/IO/ImageWriter.cxx @@ -49,7 +49,7 @@ ImageWriter( ) : Superclass( ) { this->_AddInput( "Input" ); - this->m_Parameters->ConfigureAsFileName( "FileName" ); + this->m_Parameters->ConfigureAsSaveFileName( "FileName" ); } // ------------------------------------------------------------------------- @@ -114,7 +114,7 @@ std::string cpPlugins::IO::ImageWriter:: _RealGD( itk::DataObject* image ) { // Get filename - std::string fname = this->m_Parameters->GetFileName( "FileName" ); + std::string fname = this->m_Parameters->GetSaveFileName( "FileName" ); typedef itk::ImageFileWriter< I > _W; _W* writer = this->_CreateITK< _W >( ); diff --git a/lib/cpPlugins/Plugins/IO/MeshReader.cxx b/lib/cpPlugins/Plugins/IO/MeshReader.cxx index cfcd512..473686d 100644 --- a/lib/cpPlugins/Plugins/IO/MeshReader.cxx +++ b/lib/cpPlugins/Plugins/IO/MeshReader.cxx @@ -50,7 +50,7 @@ MeshReader( ) std::vector< TParameters::TString > valid_types; valid_types.push_back( "float" ); valid_types.push_back( "double" ); - this->m_Parameters->ConfigureAsFileName( "FileName" ); + this->m_Parameters->ConfigureAsOpenFileName( "FileName" ); this->m_Parameters->ConfigureAsChoices( "PixelType", valid_types ); this->m_Parameters->ConfigureAsUint( "Dimension" ); @@ -97,7 +97,7 @@ std::string cpPlugins::IO::MeshReader:: _GD1( ) { // Get filename - std::string fname = this->m_Parameters->GetFileName( "FileName" ); + std::string fname = this->m_Parameters->GetOpenFileName( "FileName" ); vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( ); pdr->SetFileName( fname.c_str( ) ); diff --git a/lib/cpPlugins/Plugins/IO/MeshWriter.cxx b/lib/cpPlugins/Plugins/IO/MeshWriter.cxx index e45367d..feb05ad 100644 --- a/lib/cpPlugins/Plugins/IO/MeshWriter.cxx +++ b/lib/cpPlugins/Plugins/IO/MeshWriter.cxx @@ -51,7 +51,7 @@ MeshWriter( ) : Superclass( ) { this->_AddInput( "Input" ); - this->m_Parameters->ConfigureAsFileName( "FileName" ); + this->m_Parameters->ConfigureAsSaveFileName( "FileName" ); } // ------------------------------------------------------------------------- @@ -71,7 +71,7 @@ _GenerateData( ) vtkPolyData* i = mesh->GetVTK< vtkPolyData >( ); if( i == NULL ) return( "MeshWriter: No suitable input." ); - std::string fname = this->m_Parameters->GetFileName( "FileName" ); + std::string fname = this->m_Parameters->GetSaveFileName( "FileName" ); vtkPolyDataWriter* pdw = this->_CreateVTK< vtkPolyDataWriter >( ); pdw->SetInputData( i );