2 #include "ui_MainWnd.h"
6 #include <QDoubleSpinBox>
9 // -------------------------------------------------------------------------
11 _ParametersDialog( const TParameters& parameters )
13 if( this->m_ActiveParameters != NULL )
14 this->m_ActiveParameters->close( );
15 this->m_ActiveParameters = new QWidget( NULL );
16 this->m_ActiveParameters->setWindowFlags( Qt::FramelessWindowHint );
17 this->m_ActiveParameters->setWindowFlags( Qt::WindowTitleHint );
19 QGridLayout* gridLayout = new QGridLayout( this->m_ActiveParameters );
20 QVBoxLayout* verticalLayout = new QVBoxLayout( );
23 QLabel* title = new QLabel( this->m_ActiveParameters );
24 title->setText( this->m_ActivePlugin->GetClassName( ).c_str( ) );
25 verticalLayout->addWidget( title );
27 TParameters::const_iterator pIt = parameters.begin( );
28 for( ; pIt != parameters.end( ); ++pIt )
30 std::string par_name = pIt->first;
31 std::string par_type = pIt->second.first;
32 std::string par_value = pIt->second.second;
34 if( par_type == "double" )
36 QHBoxLayout* horizontalLayout = new QHBoxLayout( );
37 QLabel* label = new QLabel( this->m_ActiveParameters );
38 label->setText( QString( par_name.c_str( ) ) );
39 horizontalLayout->addWidget( label );
41 QDoubleSpinBox* v_double =
42 new QDoubleSpinBox( this->m_ActiveParameters );
43 v_double->setDecimals( 3 );
44 v_double->setMinimum( -( std::numeric_limits< double >::max( ) ) );
45 v_double->setMaximum( std::numeric_limits< double >::max( ) );
46 v_double->setValue( std::atof( par_value.c_str( ) ) );
47 v_double->setObjectName( QString( par_name.c_str( ) ) );
48 horizontalLayout->addWidget( v_double );
49 verticalLayout->addLayout( horizontalLayout );
54 gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
55 QMetaObject::connectSlotsByName( this->m_ActiveParameters );
56 this->m_ActiveParameters->show( );
59 typedef std::map< std::string, QWidget* > _TWidgets;
61 TParameters::const_iterator pIt = parameters.begin( );
62 for( ; pIt != parameters.end( ); ++pIt )
64 unsigned long pos = pIt->first.find_last_of( ":" );
65 std::string v_name = pIt->first.substr( 0, pos );
66 std::string v_type = pIt->first.substr( pos + 1 );
67 QHBoxLayout* horizontalLayout = new QHBoxLayout( );
68 QLabel* label = new QLabel( this->m_ActiveParameters );
69 label->setText( QString( v_name.c_str( ) ) );
70 horizontalLayout->addWidget( label );
71 if( v_type == "real" )
73 QDoubleSpinBox* v_double = new QDoubleSpinBox( this->m_ActiveParameters );
74 v_double->setDecimals( 3 );
75 v_double->setMinimum( -( std::numeric_limits< double >::max( ) ) );
76 v_double->setMaximum( std::numeric_limits< double >::max( ) );
77 v_double->setValue( std::atof( pIt->second.c_str( ) ) );
78 horizontalLayout->addWidget( v_double );
79 widgets[ pIt->first ] = v_double;
81 else if( v_type == "atomic_real" )
83 if( v_name == "MeshType" )
85 QLabel* info = new QLabel( this->m_ActiveParameters );
86 if( typeid( TScalar ) == typeid( float ) )
87 info->setText( QString( "float" ) );
88 else if( typeid( TScalar ) == typeid( double ) )
89 info->setText( QString( "double" ) );
90 horizontalLayout->addWidget( info );
91 widgets[ pIt->first ] = info;
94 verticalLayout.addLayout( horizontalLayout );
96 gridLayout.addLayout( &verticalLayout, 0, 0, 1, 1 );
98 QDialogButtonBox buttonBox( this->m_ActiveParameters );
99 buttonBox.setOrientation( Qt::Horizontal );
100 buttonBox.setStandardButtons(
101 QDialogButtonBox::Cancel | QDialogButtonBox::Ok
103 gridLayout.addWidget( &buttonBox, 1, 0, 1, 1 );
105 &buttonBox, SIGNAL( accepted( ) ),
106 this->m_ActiveParameters, SLOT( accept( ) )
109 &buttonBox, SIGNAL( rejected( ) ),
110 this->m_ActiveParameters, SLOT( reject( ) )
112 QMetaObject::connectSlotsByName( this->m_ActiveParameters );
115 if( dlg.exec( ) == QDialog::Accepted )
117 _TWidgets::const_iterator wIt = widgets.begin( );
118 for( ; wIt != widgets.end( ); ++wIt )
120 unsigned long pos = wIt->first.find_last_of( ":" );
121 std::string v_name = wIt->first.substr( 0, pos );
122 std::string v_type = wIt->first.substr( pos + 1 );
123 std::stringstream sstr;
124 if( v_type == "real" )
126 QDoubleSpinBox* v_double =
127 dynamic_cast< QDoubleSpinBox* >( wIt->second );
128 if( v_double != NULL )
129 sstr << v_double->value( );
131 else if( v_type == "atomic_real" )
133 if( v_name == "MeshType" )
135 QLabel* info = dynamic_cast< QLabel* >( wIt->second );
137 sstr << info->text( ).toStdString( );
142 parameters[ wIt->first ] = sstr.str( );
151 // -------------------------------------------------------------------------
153 _triggered_actionSegmentImage( )
157 // -------------------------------------------------------------------------
159 _triggered_actionFilterSegmentation( )
162 if( this->m_SegmentedImage == NULL )
164 QAction* action = dynamic_cast< QAction* >( this->sender( ) );
167 std::string filter_name = action->text( ).toStdString( );
170 if( this->m_ActivePlugin != NULL ) delete this->m_ActivePlugin;
171 this->m_ActivePlugin =
172 dynamic_cast< TPlugin* >(
173 this->m_Plugins.CreateObject(
174 this->m_SegmentationFilterClasses[ filter_name ]
178 // Show parameters dialog
179 this->_ParametersDialog( this->m_ActivePlugin->GetDefaultParameters( ) );
182 // -------------------------------------------------------------------------
184 _triggered_actionProcessMesh( )