]> Creatis software - cpMesh.git/blob - appli/InteractiveDeformableMeshSegmentation/MainWnd_ExecutePlugins.cxx
8429a818d38ceb7c41dfa1f792359d1e30801dc4
[cpMesh.git] / appli / InteractiveDeformableMeshSegmentation / MainWnd_ExecutePlugins.cxx
1 #include "MainWnd.h"
2 #include "ui_MainWnd.h"
3
4 #include <cstdlib>
5
6 #include <QDoubleSpinBox>
7 #include <QLabel>
8
9 // -------------------------------------------------------------------------
10 bool MainWnd::
11 _ParametersDialog( const TParameters& parameters )
12 {
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 );
18
19   QGridLayout* gridLayout = new QGridLayout( this->m_ActiveParameters );
20   QVBoxLayout* verticalLayout = new QVBoxLayout( );
21
22   // Put values
23   QLabel* title = new QLabel( this->m_ActiveParameters );
24   title->setText( this->m_ActivePlugin->GetClassName( ).c_str( ) );
25   verticalLayout->addWidget( title );
26
27   TParameters::const_iterator pIt = parameters.begin( );
28   for( ; pIt != parameters.end( ); ++pIt )
29   {
30     std::string par_name = pIt->first;
31     std::string par_type = pIt->second.first;
32     std::string par_value = pIt->second.second;
33
34     if( par_type == "double" )
35     {
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 );
40
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 );
50
51     } // fi
52
53   } // rof
54   gridLayout->addLayout( verticalLayout, 0, 0, 1, 1 );
55   QMetaObject::connectSlotsByName( this->m_ActiveParameters );
56   this->m_ActiveParameters->show( );
57
58   /*
59     typedef std::map< std::string, QWidget* > _TWidgets;
60     _TWidgets widgets;
61     TParameters::const_iterator pIt = parameters.begin( );
62     for( ; pIt != parameters.end( ); ++pIt )
63     {
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" )
72     {
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;
80     }
81     else if( v_type == "atomic_real" )
82     {
83     if( v_name == "MeshType" )
84     {
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;
92     } // fi
93     } // fi
94     verticalLayout.addLayout( horizontalLayout );
95     } // rof
96     gridLayout.addLayout( &verticalLayout, 0, 0, 1, 1 );
97     // Buttons box
98     QDialogButtonBox buttonBox( this->m_ActiveParameters );
99     buttonBox.setOrientation( Qt::Horizontal );
100     buttonBox.setStandardButtons(
101     QDialogButtonBox::Cancel | QDialogButtonBox::Ok
102     );
103     gridLayout.addWidget( &buttonBox, 1, 0, 1, 1 );
104     QObject::connect(
105     &buttonBox, SIGNAL( accepted( ) ),
106     this->m_ActiveParameters, SLOT( accept( ) )
107     );
108     QObject::connect(
109     &buttonBox, SIGNAL( rejected( ) ),
110     this->m_ActiveParameters, SLOT( reject( ) )
111     );
112     QMetaObject::connectSlotsByName( this->m_ActiveParameters );
113
114     // Execute dialog
115     if( dlg.exec( ) == QDialog::Accepted )
116     {
117     _TWidgets::const_iterator wIt = widgets.begin( );
118     for( ; wIt != widgets.end( ); ++wIt )
119     {
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" )
125     {
126     QDoubleSpinBox* v_double =
127     dynamic_cast< QDoubleSpinBox* >( wIt->second );
128     if( v_double != NULL )
129     sstr << v_double->value( );
130     }
131     else if( v_type == "atomic_real" )
132     {
133     if( v_name == "MeshType" )
134     {
135     QLabel* info = dynamic_cast< QLabel* >( wIt->second );
136     if( info != NULL )
137     sstr << info->text( ).toStdString( );
138
139     } // fi
140
141     } // fi
142     parameters[ wIt->first ] = sstr.str( );
143
144     } // rof
145     return( true );
146     }
147   */
148   return( false );
149 }
150
151 // -------------------------------------------------------------------------
152 void MainWnd::
153 _triggered_actionSegmentImage( )
154 {
155 }
156
157 // -------------------------------------------------------------------------
158 void MainWnd::
159 _triggered_actionFilterSegmentation( )
160 {
161   // Get filter name
162   if( this->m_SegmentedImage == NULL )
163     return;
164   QAction* action = dynamic_cast< QAction* >( this->sender( ) );
165   if( action == NULL )
166     return;
167   std::string filter_name = action->text( ).toStdString( );
168
169   // Create plugin
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 ]
175         )
176       );
177
178   // Show parameters dialog
179   this->_ParametersDialog( this->m_ActivePlugin->GetDefaultParameters( ) );
180 }
181
182 // -------------------------------------------------------------------------
183 void MainWnd::
184 _triggered_actionProcessMesh( )
185 {
186 }
187
188 // eof - $RCSfile$