#include "ImageMPR.h"
#include "ui_ImageMPR.h"
+#include <cpPlugins/Interface/ParametersQtDialog.h>
+
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
-#include <QDialogButtonBox>
-#include <QDoubleSpinBox>
#include <QFileDialog>
-#include <QLabel>
#include <QMessageBox>
#ifdef _WIN32
m_UI( new Ui::ImageMPR ),
m_ImageReaderClass( "" ),
m_ImageWriterClass( "" ),
- m_InputImage( NULL ),
- m_ParametersDlg( NULL )
+ m_InputImage( NULL )
{
this->m_UI->setupUi( this );
// Delete objects
delete this->m_UI;
delete this->m_MPR;
- if( this->m_ParametersDlg != NULL )
- {
- this->m_ParametersDlg->close( );
- delete this->m_ParametersDlg;
-
- } // fi
}
// -------------------------------------------------------------------------
return( true );
}
-// -------------------------------------------------------------------------
-bool ImageMPR::
-_ParametersDialog( TPluginFilter* filter )
-{
- if( this->m_ParametersDlg != NULL )
- {
- this->m_ParametersDlg->close( );
- delete this->m_ParametersDlg;
-
- } // fi
- this->m_ParametersDlg = new QDialog( NULL );
- this->m_ParametersDlg->setWindowFlags( Qt::FramelessWindowHint );
- this->m_ParametersDlg->setWindowFlags( Qt::WindowTitleHint );
-
- QGridLayout* gridLayout = new QGridLayout( this->m_ParametersDlg );
- QVBoxLayout* verticalLayout = new QVBoxLayout( );
-
- // Put a title
- QLabel* title = new QLabel( this->m_ParametersDlg );
- title->setText( filter->GetClassName( ).c_str( ) );
- verticalLayout->addWidget( title );
-
- // Put values
- TParameters parameters = filter->GetDefaultParameters( );
- std::vector< std::string > names = parameters.GetParameters( );
- std::vector< std::string >::const_iterator nIt = names.begin( );
- for( ; nIt != names.end( ); ++nIt )
- {
- std::string par_name = *nIt;
- TParameters::Type par_type = parameters.GetParameterType( par_name );
-
- /* TODO
- enum Type
- {
- String = 0,
- Bool,
- Int,
- Uint,
- Real,
- Index,
- Point,
- StringList,
- BoolList,
- IntList,
- UintList,
- RealList,
- IndexList,
- PointList,
- NoType
- };
- */
- QHBoxLayout* horizontalLayout = new QHBoxLayout( );
- QLabel* label = new QLabel( this->m_ParametersDlg );
- label->setText( QString( par_name.c_str( ) ) );
- horizontalLayout->addWidget( label );
-
- QWidget* w_input = NULL;
- if( par_type == TParameters::Uint )
- {
- QSpinBox* v_uint =
- new QSpinBox( this->m_ParametersDlg );
- v_uint->setMinimum( -100 );
- v_uint->setMaximum( std::numeric_limits< int >::max( ) );
- v_uint->setValue( parameters.GetValueAsUint( par_name ) );
- v_uint->setObjectName( QString( par_name.c_str( ) ) );
- w_input = v_uint;
- }
- else if( par_type == TParameters::Int )
- {
- QSpinBox* v_int =
- new QSpinBox( this->m_ParametersDlg );
- v_int->setMinimum( -std::numeric_limits< int >::max( ) );
- v_int->setMaximum( std::numeric_limits< int >::max( ) );
- v_int->setValue( parameters.GetValueAsInt( par_name ) );
- v_int->setObjectName( QString( par_name.c_str( ) ) );
- w_input = v_int;
- }
- else if( par_type == TParameters::Real )
- {
- QDoubleSpinBox* v_double =
- new QDoubleSpinBox( this->m_ParametersDlg );
- v_double->setDecimals( 3 );
- v_double->setMinimum( -( std::numeric_limits< double >::max( ) ) );
- v_double->setMaximum( std::numeric_limits< double >::max( ) );
- v_double->setValue( parameters.GetValueAsReal( par_name ) );
- v_double->setObjectName( QString( par_name.c_str( ) ) );
- w_input = v_double;
-
- } // fi
-
- if( w_input != NULL )
- {
- horizontalLayout->addWidget( w_input );
- verticalLayout->addLayout( horizontalLayout );
-
- } // fi
-
- } // rof
-
- // Add buttons
- QDialogButtonBox* bb = new QDialogButtonBox(
- QDialogButtonBox::Ok | QDialogButtonBox::Cancel
- );
- QObject::connect(
- bb, SIGNAL( accepted( ) ), this->m_ParametersDlg, SLOT( accept( ) )
- );
- QObject::connect(
- bb, SIGNAL( rejected( ) ), this->m_ParametersDlg, SLOT( reject( ) )
- );
- verticalLayout->addWidget( bb );
- gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
-
- // Execute
- QMetaObject::connectSlotsByName( this->m_ParametersDlg );
- if( !( this->m_ParametersDlg->exec( ) ) )
- return( false );
-
- // Get values back
- nIt = names.begin( );
- for( ; nIt != names.end( ); ++nIt )
- {
- std::string par_name = *nIt;
- TParameters::Type par_type = parameters.GetParameterType( par_name );
- if( par_type == TParameters::Uint )
- {
- QSpinBox* v_uint =
- this->m_ParametersDlg->findChild< QSpinBox* >( par_name.c_str( ) );
- if( v_uint != NULL )
- parameters.SetValueAsUint( par_name, v_uint->value( ) );
- }
- else if( par_type == TParameters::Int )
- {
- QSpinBox* v_int =
- this->m_ParametersDlg->findChild< QSpinBox* >( par_name.c_str( ) );
- if( v_int != NULL )
- parameters.SetValueAsInt( par_name, v_int->value( ) );
- }
- else if( par_type == TParameters::Real )
- {
- QDoubleSpinBox* v_double =
- this->m_ParametersDlg->findChild< QDoubleSpinBox* >(
- par_name.c_str( )
- );
- if( v_double != NULL )
- parameters.SetValueAsReal( par_name, v_double->value( ) );
-
- } // fi
-
- } // rof
- filter->SetParameters( parameters );
- return( true );
-}
-
// -------------------------------------------------------------------------
void ImageMPR::
_triggered_actionOpenPlugins( )
// Configure filter
TPluginFilter::Pointer filter =
this->m_Plugins.CreateProcessObject( name );
- if( !( this->_ParametersDialog( filter ) ) )
+ TParameters parameters = filter->GetDefaultParameters( );
+ bool dlg_ok =
+ cpPlugins::Interface::ParametersQtDialog(
+ parameters, filter->GetClassName( )
+ );
+ if( !dlg_ok )
return;
// Execute filter
+ filter->SetParameters( parameters );
filter->SetInput( 0, this->m_InputImage );
- filter->Update( );
+ std::string err = filter->Update( );
// Update image
- TPluginImage* result =
- dynamic_cast< TPluginImage* >( filter->GetOutput( 0 ) );
- result->DisconnectPipeline( );
- this->m_InputImage = result;
- if( this->m_InputImage.IsNotNull( ) )
- this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) );
+ if( err == "" )
+ {
+ TPluginImage* result =
+ dynamic_cast< TPluginImage* >( filter->GetOutput( 0 ) );
+ result->DisconnectPipeline( );
+ this->m_InputImage = result;
+ if( this->m_InputImage.IsNotNull( ) )
+ this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) );
+ }
+ else
+ QMessageBox::critical(
+ this,
+ tr( "Error executing filter" ),
+ tr( err.c_str( ) )
+ );
}
// -------------------------------------------------------------------------
if( action == NULL )
return;
std::string name = action->text( ).toStdString( );
+
+ // Configure filter
+ TPluginFilter::Pointer filter =
+ this->m_Plugins.CreateProcessObject( name );
+ TParameters parameters = filter->GetDefaultParameters( );
+ bool dlg_ok =
+ cpPlugins::Interface::ParametersQtDialog(
+ parameters, filter->GetClassName( )
+ );
+ if( !dlg_ok )
+ return;
+
+ // Execute filter
+ filter->SetParameters( parameters );
+ filter->SetInput( 0, this->m_InputImage );
+ std::string err = filter->Update( );
+
+ // Update image
+ if( err == "" )
+ {
+ /* TODO
+ TPluginImage* result =
+ dynamic_cast< TPluginImage* >( filter->GetOutput( 0 ) );
+ result->DisconnectPipeline( );
+ this->m_InputImage = result;
+ if( this->m_InputImage.IsNotNull( ) )
+ this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) );
+ */
+ }
+ else
+ QMessageBox::critical(
+ this,
+ tr( "Error executing filter" ),
+ tr( err.c_str( ) )
+ );
}
// eof - $RCSfile$