Salome HOME
This commit was generated by cvs2git to create branch 'PAL_OCC'.
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_MaxElementVolumeDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : StdMeshersGUI_MaxElementVolumeDlg.cxx
25 //           Moved here from SMESHGUI_MaxElementVolumeDlg.cxx
26 //  Author : Nicolas REJNERI
27 //  Module : SMESH
28 //  $Header$
29
30 using namespace std;
31 #include "StdMeshersGUI_MaxElementVolumeDlg.h"
32 #include "SMESHGUI.h"
33 #include "SMESHGUI_SpinBox.h"
34
35 #include <SALOMEconfig.h>
36 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
37
38 #include "QAD_Application.h"
39 #include "QAD_Desktop.h"
40 #include "utilities.h"
41
42 #include "SALOMEGUI_QtCatchCorbaException.hxx"
43 #include "QAD_MessageBox.h"
44 #include "QAD_WaitCursor.h"
45
46 // QT Includes
47 #include <qgroupbox.h>
48 #include <qlabel.h>
49 #include <qlineedit.h>
50 #include <qpushbutton.h>
51 #include <qlayout.h>
52 #include <qpixmap.h>
53
54 //=================================================================================
55 // class    : StdMeshersGUI_MaxElementVolumeDlg()
56 // purpose  : Constructs a StdMeshersGUI_MaxElementVolumeDlg which is a child of 'parent', with the 
57 //            name 'name' and widget flags set to 'f'.
58 //            The dialog will by default be modeless, unless you set 'modal' to
59 //            TRUE to construct a modal dialog.
60 //=================================================================================
61 StdMeshersGUI_MaxElementVolumeDlg::StdMeshersGUI_MaxElementVolumeDlg (const QString& hypType,
62                                                                       QWidget* parent,
63                                                                       const char* name,
64                                                                       bool modal, WFlags fl)
65      : QDialog (parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
66        myHypType(hypType)
67 {
68     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_MAX_ELEMENT_VOLUME")));
69     
70     if ( !name )
71       setName( "StdMeshersGUI_MaxElementVolumeDlg" );
72     setCaption( tr( "SMESH_MAX_ELEMENT_VOLUME_TITLE"  ) );
73     setSizeGripEnabled( TRUE );
74     QGridLayout* StdMeshersGUI_MaxElementVolumeDlgLayout = new QGridLayout( this ); 
75     StdMeshersGUI_MaxElementVolumeDlgLayout->setSpacing( 6 );
76     StdMeshersGUI_MaxElementVolumeDlgLayout->setMargin( 11 );
77
78     /***************************************************************/
79     iconLabel = new QLabel( this );
80     iconLabel->setPixmap( image0 );
81     iconLabel->setScaledContents( false );
82     iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
83     typeLabel = new QLabel( this );
84     typeLabel->setText( tr( "SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"  ) );
85     StdMeshersGUI_MaxElementVolumeDlgLayout->addWidget( iconLabel, 0, 0 );
86     StdMeshersGUI_MaxElementVolumeDlgLayout->addWidget( typeLabel, 0, 1 );
87     
88     /***************************************************************/
89     GroupButtons = new QGroupBox( this, "GroupButtons" );
90     GroupButtons->setColumnLayout(0, Qt::Vertical );
91     GroupButtons->layout()->setSpacing( 0 );
92     GroupButtons->layout()->setMargin( 0 );
93     QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
94     GroupButtonsLayout->setAlignment( Qt::AlignTop );
95     GroupButtonsLayout->setSpacing( 6 );
96     GroupButtonsLayout->setMargin( 11 );
97     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
98     buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
99     buttonOk->setAutoDefault( TRUE );
100     buttonOk->setDefault( TRUE );
101     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
102     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
103     buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
104     buttonApply->setAutoDefault( TRUE );
105     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
106     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
107     GroupButtonsLayout->addItem( spacer, 0, 2 );
108     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
109     buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
110     buttonCancel->setAutoDefault( TRUE );
111     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
112     StdMeshersGUI_MaxElementVolumeDlgLayout->addMultiCellWidget( GroupButtons, 2, 2, 0, 1 );
113
114     /***************************************************************/
115     GroupC1 = new QGroupBox( this, "GroupC1" );
116     GroupC1->setTitle( tr( "SMESH_ARGUMENTS"  ) );
117     GroupC1->setColumnLayout(0, Qt::Vertical );
118     GroupC1->layout()->setSpacing( 0 );
119     GroupC1->layout()->setMargin( 0 );
120     QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
121     GroupC1Layout->setAlignment( Qt::AlignTop );
122     GroupC1Layout->setSpacing( 6 );
123     GroupC1Layout->setMargin( 11 );
124
125     TextLabel_NameHypothesis = new QLabel( GroupC1, "TextLabel_NameHypothesis" );
126     TextLabel_NameHypothesis->setText( tr( "SMESH_NAME"  ) );
127     GroupC1Layout->addWidget( TextLabel_NameHypothesis, 0, 0 );
128
129     LineEdit_NameHypothesis = new QLineEdit( GroupC1, "LineEdit_NameHypothesis" );
130     GroupC1Layout->addWidget( LineEdit_NameHypothesis, 0, 1 );
131
132     TextLabel_MaxElementVolume = new QLabel(GroupC1 , "TextLabel_MaxElementVolume" );
133     TextLabel_MaxElementVolume->setText( tr( "SMESH_MAX_ELEMENT_VOLUME"  ) );
134     GroupC1Layout->addWidget( TextLabel_MaxElementVolume, 1, 0 );
135
136     SpinBox_MaxElementVolume = new SMESHGUI_SpinBox( GroupC1, "SpinBox_MaxElementVolume" ) ;
137     GroupC1Layout->addWidget( SpinBox_MaxElementVolume, 1, 1 );
138
139     StdMeshersGUI_MaxElementVolumeDlgLayout->addMultiCellWidget(GroupC1 , 1, 1, 0, 1 );
140
141     /***************************************************************/
142     Init() ;
143 }
144
145
146 //=================================================================================
147 // function : ~StdMeshersGUI_MaxElementVolumeDlg()
148 // purpose  : Destroys the object and frees any allocated resources
149 //=================================================================================
150 StdMeshersGUI_MaxElementVolumeDlg::~StdMeshersGUI_MaxElementVolumeDlg()
151 {
152     // no need to delete child widgets, Qt does it all for us
153 }
154
155
156 //=================================================================================
157 // function : Init()
158 // purpose  :
159 //=================================================================================
160 void StdMeshersGUI_MaxElementVolumeDlg::Init()
161 {
162   /* min, max, step and decimals for spin boxes */
163   SpinBox_MaxElementVolume->setPrecision( 10 );
164   SpinBox_MaxElementVolume->RangeStepAndValidator( 0.001, 999999.999, 1.0, 3 ) ;
165   SpinBox_MaxElementVolume->SetValue( 1.0 ) ;  /* is myMaxElementVolume */
166
167   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
168
169   char* sHypType = (char*)myHypType.latin1();
170   HypothesisData* aHypData = mySMESHGUI->GetHypothesisData(sHypType);
171   //_CS_PhB ambiguous overload  LineEdit_NameHypothesis->setText( aHypData ? aHypData->Label : "" );
172   if (aHypData!=0)
173     {
174       LineEdit_NameHypothesis->setText(aHypData->Label);
175     }
176   else
177     {
178       LineEdit_NameHypothesis->setText("");
179     }
180
181   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
182
183   /* signals and slots connections */
184   connect( buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()) );
185   connect( buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()) ) ;
186   connect( buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()) );
187
188   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;  
189   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
190
191   /* Move widget on the botton right corner of main widget */
192   int x, y ;
193   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
194   this->move( x, y ) ; 
195   this->show() ; /* displays Dialog */
196 }
197
198
199 //=================================================================================
200 // function : ClickOnOk()
201 // purpose  :
202 //=================================================================================
203 void StdMeshersGUI_MaxElementVolumeDlg::ClickOnOk()
204 {
205   if ( this->ClickOnApply() )
206     this->ClickOnCancel() ;
207 }
208
209 //=================================================================================
210 // function : ClickOnApply()
211 // purpose  :
212 //=================================================================================
213 bool StdMeshersGUI_MaxElementVolumeDlg::ClickOnApply()
214 {
215   QString myHypName = LineEdit_NameHypothesis->text().stripWhiteSpace();
216   if ( myHypName.isEmpty() ) {
217     QAD_MessageBox::warn1( this, tr( "SMESH_WRN_WARNING" ), tr( "SMESH_WRN_EMPTY_NAME" ), tr( "SMESH_BUT_OK" ) );
218     return false;
219   }
220   
221   double myMaxElementVolume = SpinBox_MaxElementVolume->GetValue();
222   
223   QAD_WaitCursor wc;
224   try {
225     SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow
226       (mySMESHGUI->CreateHypothesis(myHypType,
227                                     myHypName,
228                                     false)); // isAlgorithm
229     StdMeshers::StdMeshers_MaxElementVolume_var MaxElVolume =
230       StdMeshers::StdMeshers_MaxElementVolume::_narrow(Hyp);
231     if (!MaxElVolume->_is_nil())
232       MaxElVolume->SetMaxElementVolume(myMaxElementVolume);
233   }
234   catch (const SALOME::SALOME_Exception& S_ex) {
235     wc.stop();
236     QtCatchCorbaException(S_ex);
237     return false;
238   }
239   return true;
240 }
241
242
243 //=================================================================================
244 // function : ClickOnCancel()
245 // purpose  :
246 //=================================================================================
247 void StdMeshersGUI_MaxElementVolumeDlg::ClickOnCancel()
248 {
249   close();
250 }
251
252
253 //=================================================================================
254 // function : DeactivateActiveDialog()
255 // purpose  :
256 //=================================================================================
257 void StdMeshersGUI_MaxElementVolumeDlg::DeactivateActiveDialog()
258 {
259   iconLabel->setEnabled(false) ;
260   typeLabel->setEnabled(false) ;
261   GroupC1->setEnabled(false) ;
262   GroupButtons->setEnabled(false) ;
263 }
264
265
266 //=================================================================================
267 // function : ActivateThisDialog()
268 // purpose  :
269 //=================================================================================
270 void StdMeshersGUI_MaxElementVolumeDlg::ActivateThisDialog()
271 {
272   mySMESHGUI->EmitSignalDeactivateDialog() ;   
273   iconLabel->setEnabled(true) ;
274   typeLabel->setEnabled(true) ;
275   GroupC1->setEnabled(true) ;
276   GroupButtons->setEnabled(true) ;
277 }
278
279
280 //=================================================================================
281 // function : enterEvent()
282 // purpose  :
283 //=================================================================================
284 void StdMeshersGUI_MaxElementVolumeDlg::enterEvent(QEvent* e)
285 {
286   ActivateThisDialog() ;
287 }
288
289
290 //=================================================================================
291 // function : closeEvent()
292 // purpose  :
293 //=================================================================================
294 void StdMeshersGUI_MaxElementVolumeDlg::closeEvent( QCloseEvent* e )
295 {
296   mySMESHGUI->ResetState();
297   QDialog::closeEvent( e );
298 }