1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_aParameterDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_aParameterDlg.h"
30 #include "SMESHGUI_aParameter.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_FunctionPreview.h"
36 #include "SUIT_Tools.h"
37 #include "SUIT_Desktop.h"
40 #include <qgroupbox.h>
42 #include <qpushbutton.h>
45 #include <qvalidator.h>
46 #include <qlineedit.h>
50 //======================================================================================
51 // function : SMESHGUI_aParameterDlg()
53 // The dialog will by default be modal, unless you set 'modal' to
54 // false when constructing dialog
56 //======================================================================================
57 SMESHGUI_aParameterDlg::SMESHGUI_aParameterDlg
58 ( SMESHGUI* theModule,
59 std::list<SMESHGUI_aParameterPtr> params,
62 : QDialog( SMESH::GetDesktop( theModule ), "MyParameterDialog", modal, WStyle_Customize |
63 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
67 /* creating widgets */
72 /* Move widget on the botton right corner of main widget */
73 SUIT_Tools::centerWidget(this, SMESH::GetDesktop( theModule ) );
76 //======================================================================================
77 // function : SMESHGUI_aParameterDlg::init()
78 // purpose : creates dialog's layout
79 //======================================================================================
80 void SMESHGUI_aParameterDlg::init()
82 setSizeGripEnabled(TRUE);
84 QVBoxLayout* topLayout = new QVBoxLayout(this);
85 topLayout->setMargin(11); topLayout->setSpacing(6);
87 /***************************************************************/
88 QGroupBox* GroupC1 = new QGroupBox(this, "GroupC1");
89 GroupC1->setColumnLayout(0, Qt::Vertical);
90 GroupC1->layout()->setSpacing(0);
91 GroupC1->layout()->setMargin(0);
92 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout());
93 GroupC1Layout->setAlignment(Qt::AlignTop);
94 GroupC1Layout->setSpacing(6);
95 GroupC1Layout->setMargin(11);
96 /* Spin boxes with labels */
97 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
99 for( row = 0; paramIt != myParamList.end(); paramIt++ , row++)
101 SMESHGUI_aParameterPtr param = (*paramIt);
102 QLabel * label = new QLabel(GroupC1, "TextLabel");
103 GroupC1Layout->addWidget(label, row, 0);
104 label->setText(param->Label());
105 QWidget* aSpinWidget = param->CreateWidget( GroupC1 );
107 GroupC1Layout->addWidget(aSpinWidget, row, 1);
108 aSpinWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
109 aSpinWidget->setMinimumSize(150, 0);
111 QString sig = param->sigValueChanged();
112 if( !sig.isEmpty() /*&& param->GetType()!=SMESHGUI_aParameter::TABLE*/ )
113 connect( aSpinWidget, sig.latin1(), this, SLOT( onValueChanged() ) );
115 param->InitializeWidget(aSpinWidget);
116 mySpinList.push_back(aSpinWidget);
117 myLabelList.push_back(label);
121 myPreview = new SMESHGUI_FunctionPreview( GroupC1 );
123 GroupC1Layout->addWidget( myPreview, row, 1 );
125 paramIt = myParamList.begin();
126 std::list<QWidget*>::const_iterator anIt = mySpinList.begin();
127 for( ; paramIt!=myParamList.end(); paramIt++, anIt++ )
129 (*paramIt)->TakeValue( *anIt );
130 UpdateShown( *paramIt, *anIt );
131 FunctionPreview( *paramIt, *anIt );
134 /***************************************************************/
135 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
136 GroupButtons->setColumnLayout(0, Qt::Vertical);
137 GroupButtons->layout()->setSpacing(0);
138 GroupButtons->layout()->setMargin(0);
139 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
140 GroupButtonsLayout->setAlignment(Qt::AlignTop);
141 GroupButtonsLayout->setSpacing(6);
142 GroupButtonsLayout->setMargin(11);
144 myButtonOk = new QPushButton(GroupButtons, "buttonOk");
145 myButtonOk->setText(tr("SMESH_BUT_OK"));
146 myButtonOk->setAutoDefault(TRUE);
147 myButtonOk->setDefault(TRUE);
148 GroupButtonsLayout->addWidget(myButtonOk, 0, 0);
149 /* add spacer between buttons */
150 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
152 myButtonCancel = new QPushButton(GroupButtons, "buttonCancel");
153 myButtonCancel->setText(tr("SMESH_BUT_CANCEL"));
154 myButtonCancel->setAutoDefault(TRUE);
155 GroupButtonsLayout->addWidget(myButtonCancel, 0, 2);
157 /***************************************************************/
158 topLayout->addWidget(GroupC1, 1 );
159 topLayout->addWidget(GroupButtons, 0 );
161 /* signals and slots connections */
162 connect(myButtonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
163 connect(myButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
166 //======================================================================================
167 // function : ~SMESHGUI_aParameterDlg()
168 // purpose : Destructor
169 //======================================================================================
170 SMESHGUI_aParameterDlg::~SMESHGUI_aParameterDlg()
174 //=======================================================================
175 //function : ClickOnOk
177 //=======================================================================
178 void SMESHGUI_aParameterDlg::ClickOnOk()
180 if (!mySMESHGUI->isActiveStudyLocked()) {
181 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
182 list<QWidget*>::iterator widgetIt = mySpinList.begin();
184 paramIt != myParamList.end() && widgetIt != mySpinList.end();
185 paramIt++ , widgetIt++)
186 (*paramIt)->TakeValue(*widgetIt);
192 //=======================================================================
193 // function : Parameters()
194 // purpose : return a list of parameters from a dialog box
195 //=======================================================================
196 bool SMESHGUI_aParameterDlg::Parameters( SMESHGUI* theModule,
197 list<SMESHGUI_aParameterPtr> params,
200 if (!params.empty()) {
201 SMESHGUI_aParameterDlg *Dialog =
202 new SMESHGUI_aParameterDlg( theModule, params, aTitle, TRUE);
203 return (Dialog->exec() == QDialog::Accepted);
208 //=======================================================================
209 // function : FunctionPreview
211 //=======================================================================
212 void SMESHGUI_aParameterDlg::FunctionPreview( const SMESHGUI_aParameterPtr p, QWidget* w )
214 if( !w || !w->isShown() )
217 SMESHGUI_strParameter* str_param = dynamic_cast<SMESHGUI_strParameter*>( p.operator->() );
218 SMESHGUI_tableParameter* tab_param = dynamic_cast<SMESHGUI_tableParameter*>( p.operator->() );
219 SMESHGUI_boolParameter* bool_param = dynamic_cast<SMESHGUI_boolParameter*>( p.operator->() );
220 if( str_param && str_param->needPreview() )
222 QString val; str_param->GetNewText( val );
224 myPreview->setParams( val );
226 else if( tab_param && tab_param->needPreview() )
228 SMESH::double_array d;
229 tab_param->data( d );
230 myPreview->setParams( d );
232 else if( bool_param && bool_param->needPreview() )
235 bool_param->GetNewInt( exp );
236 myPreview->setIsExp( exp );
240 //=======================================================================
241 // function : onValueChanged
243 //=======================================================================
244 void SMESHGUI_aParameterDlg::onValueChanged()
246 if( sender()->inherits( "QWidget" ) )
248 QWidget* w = ( QWidget* )sender();
251 std::list<QWidget*>::const_iterator anIt = mySpinList.begin(),
252 aLast = mySpinList.end();
253 std::list<SMESHGUI_aParameterPtr>::const_iterator aPIt = myParamList.begin();
254 for( ; anIt!=aLast; anIt++, aPIt++ )
257 (*aPIt)->TakeValue( w );
258 UpdateShown( *aPIt, w );
259 FunctionPreview( *aPIt, w );
265 //=======================================================================
266 // function : onValueChanged
268 //=======================================================================
269 void SMESHGUI_aParameterDlg::UpdateShown( const SMESHGUI_aParameterPtr param, QWidget* w )
271 SMESHGUI_dependParameter* depPar = dynamic_cast<SMESHGUI_enumParameter*>( param.get() );
273 depPar = dynamic_cast<SMESHGUI_boolParameter*>( param.get() );
278 SMESHGUI_dependParameter::ShownMap& map = depPar->shownMap();
283 depPar->TakeValue( w );
284 depPar->GetNewInt( val );
285 bool hasValue = map.contains( val );
287 std::list<QWidget*>::const_iterator anIt = mySpinList.begin(),
288 aLast = mySpinList.end(),
289 aLIt = myLabelList.begin();
290 std::list<SMESHGUI_aParameterPtr>::iterator aPIt = myParamList.begin();
291 bool preview = false;
292 for( int i=0; anIt!=aLast; anIt++, aLIt++, i++, aPIt++ )
294 bool shown = hasValue && map[ val ].contains( i );
295 (*anIt)->setShown( shown );
296 (*aLIt)->setShown( shown );
299 SMESHGUI_strParameter* str_param = dynamic_cast<SMESHGUI_strParameter*>( (*aPIt).operator->() );
300 SMESHGUI_tableParameter* tab_param = dynamic_cast<SMESHGUI_tableParameter*>( (*aPIt).operator->() );
301 preview = preview || ( str_param && str_param->needPreview() ) || ( tab_param && tab_param->needPreview() );
304 myPreview->setShown( preview );