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 );
122 GroupC1Layout->addWidget( myPreview, row, 1 );
124 paramIt = myParamList.begin();
125 std::list<QWidget*>::const_iterator anIt = mySpinList.begin();
126 for( ; paramIt!=myParamList.end(); paramIt++, anIt++ )
128 (*paramIt)->TakeValue( *anIt );
129 UpdateShown( *paramIt, *anIt );
130 FunctionPreview( *paramIt, *anIt );
133 /***************************************************************/
134 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
135 GroupButtons->setColumnLayout(0, Qt::Vertical);
136 GroupButtons->layout()->setSpacing(0);
137 GroupButtons->layout()->setMargin(0);
138 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
139 GroupButtonsLayout->setAlignment(Qt::AlignTop);
140 GroupButtonsLayout->setSpacing(6);
141 GroupButtonsLayout->setMargin(11);
143 myButtonOk = new QPushButton(GroupButtons, "buttonOk");
144 myButtonOk->setText(tr("SMESH_BUT_OK"));
145 myButtonOk->setAutoDefault(TRUE);
146 myButtonOk->setDefault(TRUE);
147 GroupButtonsLayout->addWidget(myButtonOk, 0, 0);
148 /* add spacer between buttons */
149 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
151 myButtonCancel = new QPushButton(GroupButtons, "buttonCancel");
152 myButtonCancel->setText(tr("SMESH_BUT_CANCEL"));
153 myButtonCancel->setAutoDefault(TRUE);
154 GroupButtonsLayout->addWidget(myButtonCancel, 0, 2);
156 /***************************************************************/
157 topLayout->addWidget(GroupC1, 1 );
158 topLayout->addWidget(GroupButtons, 0 );
160 /* signals and slots connections */
161 connect(myButtonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
162 connect(myButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
165 //======================================================================================
166 // function : ~SMESHGUI_aParameterDlg()
167 // purpose : Destructor
168 //======================================================================================
169 SMESHGUI_aParameterDlg::~SMESHGUI_aParameterDlg()
173 //=======================================================================
174 //function : ClickOnOk
176 //=======================================================================
177 void SMESHGUI_aParameterDlg::ClickOnOk()
179 if (!mySMESHGUI->isActiveStudyLocked()) {
180 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
181 list<QWidget*>::iterator widgetIt = mySpinList.begin();
183 paramIt != myParamList.end() && widgetIt != mySpinList.end();
184 paramIt++ , widgetIt++)
185 (*paramIt)->TakeValue(*widgetIt);
191 //=======================================================================
192 // function : Parameters()
193 // purpose : return a list of parameters from a dialog box
194 //=======================================================================
195 bool SMESHGUI_aParameterDlg::Parameters( SMESHGUI* theModule,
196 list<SMESHGUI_aParameterPtr> params,
199 if (!params.empty()) {
200 SMESHGUI_aParameterDlg *Dialog =
201 new SMESHGUI_aParameterDlg( theModule, params, aTitle, TRUE);
202 return (Dialog->exec() == QDialog::Accepted);
207 //=======================================================================
208 // function : FunctionPreview
210 //=======================================================================
211 void SMESHGUI_aParameterDlg::FunctionPreview( const SMESHGUI_aParameterPtr p, QWidget* w )
213 if( !w || !w->isShown() )
216 SMESHGUI_strParameter* str_param = dynamic_cast<SMESHGUI_strParameter*>( p.operator->() );
217 SMESHGUI_tableParameter* tab_param = dynamic_cast<SMESHGUI_tableParameter*>( p.operator->() );
218 SMESHGUI_boolParameter* bool_param = dynamic_cast<SMESHGUI_boolParameter*>( p.operator->() );
219 if( str_param && str_param->needPreview() )
221 QString val; str_param->GetNewText( val );
223 myPreview->setParams( val );
225 else if( tab_param && tab_param->needPreview() )
227 SMESH::double_array d;
228 tab_param->data( d );
229 myPreview->setParams( d );
231 else if( bool_param && bool_param->needPreview() )
234 bool_param->GetNewInt( exp );
235 myPreview->setIsExp( exp );
239 //=======================================================================
240 // function : onValueChanged
242 //=======================================================================
243 void SMESHGUI_aParameterDlg::onValueChanged()
245 if( sender()->inherits( "QWidget" ) )
247 QWidget* w = ( QWidget* )sender();
250 std::list<QWidget*>::const_iterator anIt = mySpinList.begin(),
251 aLast = mySpinList.end();
252 std::list<SMESHGUI_aParameterPtr>::const_iterator aPIt = myParamList.begin();
253 for( ; anIt!=aLast; anIt++, aPIt++ )
256 (*aPIt)->TakeValue( w );
257 UpdateShown( *aPIt, w );
258 FunctionPreview( *aPIt, w );
264 //=======================================================================
265 // function : onValueChanged
267 //=======================================================================
268 void SMESHGUI_aParameterDlg::UpdateShown( const SMESHGUI_aParameterPtr param, QWidget* w )
270 SMESHGUI_dependParameter* depPar = dynamic_cast<SMESHGUI_enumParameter*>( param.get() );
272 depPar = dynamic_cast<SMESHGUI_boolParameter*>( param.get() );
277 SMESHGUI_dependParameter::ShownMap& map = depPar->shownMap();
282 depPar->TakeValue( w );
283 depPar->GetNewInt( val );
284 bool hasValue = map.contains( val );
286 std::list<QWidget*>::const_iterator anIt = mySpinList.begin(),
287 aLast = mySpinList.end(),
288 aLIt = myLabelList.begin();
289 std::list<SMESHGUI_aParameterPtr>::iterator aPIt = myParamList.begin();
290 bool preview = false;
291 for( int i=0; anIt!=aLast; anIt++, aLIt++, i++, aPIt++ )
293 bool shown = hasValue && map[ val ].contains( i );
294 (*anIt)->setShown( shown );
295 (*aLIt)->setShown( shown );
298 SMESHGUI_strParameter* str_param = dynamic_cast<SMESHGUI_strParameter*>( (*aPIt).operator->() );
299 SMESHGUI_tableParameter* tab_param = dynamic_cast<SMESHGUI_tableParameter*>( (*aPIt).operator->() );
300 preview = preview || ( str_param && str_param->needPreview() ) || ( tab_param && tab_param->needPreview() );
303 myPreview->setShown( preview );