Salome HOME
DCQ:prepare 2.0.0
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_MaxElementAreaDlg.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_MaxElementAreaDlg.cxx
25 //           Moved here from SMESHGUI_MaxElementAreaDlg.cxx
26 //  Author : Nicolas REJNERI
27 //  Module : SMESH
28 //  $Header$
29
30 using namespace std;
31 #include "StdMeshersGUI_MaxElementAreaDlg.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_MaxElementAreaDlg()
56 // purpose  : Constructs a StdMeshersGUI_MaxElementAreaDlg 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_MaxElementAreaDlg::StdMeshersGUI_MaxElementAreaDlg (const QString& hypType,
62                                                                   QWidget* parent,
63                                                                   const char* name,
64                                                                   bool modal,
65                                                                   WFlags fl)
66      : QDialog (parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
67        myHypType(hypType)
68 {
69     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_MAX_ELEMENT_AREA")));
70     
71     if ( !name )
72       setName( "StdMeshersGUI_MaxElementAreaDlg" );
73     setCaption( tr( "SMESH_MAX_ELEMENT_AREA_TITLE"  ) );
74     setSizeGripEnabled( TRUE );
75     QGridLayout* StdMeshersGUI_MaxElementAreaDlgLayout = new QGridLayout( this ); 
76     StdMeshersGUI_MaxElementAreaDlgLayout->setSpacing( 6 );
77     StdMeshersGUI_MaxElementAreaDlgLayout->setMargin( 11 );
78
79     /***************************************************************/
80     iconLabel = new QLabel( this );
81     iconLabel->setPixmap( image0 );
82     iconLabel->setScaledContents( false );
83     iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
84     typeLabel = new QLabel( this );
85     typeLabel->setText( tr( "SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"  ) );
86     StdMeshersGUI_MaxElementAreaDlgLayout->addWidget( iconLabel, 0, 0 );
87     StdMeshersGUI_MaxElementAreaDlgLayout->addWidget( typeLabel, 0, 1 );
88     
89     /***************************************************************/
90     GroupC1 = new QGroupBox( this, "GroupC1" );
91     GroupC1->setTitle( tr( "SMESH_ARGUMENTS"  ) );
92     GroupC1->setColumnLayout(0, Qt::Vertical );
93     GroupC1->layout()->setSpacing( 0 );
94     GroupC1->layout()->setMargin( 0 );
95     QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
96     GroupC1Layout->setAlignment( Qt::AlignTop );
97     GroupC1Layout->setSpacing( 6 );
98     GroupC1Layout->setMargin( 11 );
99
100     TextLabel_NameHypothesis = new QLabel( GroupC1, "TextLabel_NameHypothesis" );
101     TextLabel_NameHypothesis->setText( tr( "SMESH_NAME"  ) );
102     GroupC1Layout->addWidget( TextLabel_NameHypothesis, 0, 0 );
103  
104     LineEdit_NameHypothesis = new QLineEdit( GroupC1, "LineEdit_NameHypothesis" );
105     GroupC1Layout->addWidget( LineEdit_NameHypothesis, 0, 1 );
106
107     TextLabel_MaxElementArea = new QLabel(GroupC1 , "TextLabel_MaxElementArea" );
108     TextLabel_MaxElementArea->setText( tr( "SMESH_MAX_ELEMENT_AREA"  ) );
109     GroupC1Layout->addWidget( TextLabel_MaxElementArea, 1, 0 );
110
111     SpinBox_MaxElementArea = new SMESHGUI_SpinBox( GroupC1, "SpinBox_MaxElementArea" ) ;
112     GroupC1Layout->addWidget( SpinBox_MaxElementArea, 1, 1 );
113
114     StdMeshersGUI_MaxElementAreaDlgLayout->addMultiCellWidget(GroupC1 , 1, 1, 0, 1);
115
116     /***************************************************************/
117     GroupButtons = new QGroupBox( this, "GroupButtons" );
118     GroupButtons->setColumnLayout(0, Qt::Vertical );
119     GroupButtons->layout()->setSpacing( 0 );
120     GroupButtons->layout()->setMargin( 0 );
121     QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
122     GroupButtonsLayout->setAlignment( Qt::AlignTop );
123     GroupButtonsLayout->setSpacing( 6 );
124     GroupButtonsLayout->setMargin( 11 );
125     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
126     buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
127     buttonOk->setAutoDefault( TRUE );
128     buttonOk->setDefault( TRUE );
129     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
130     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
131     buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
132     buttonApply->setAutoDefault( TRUE );
133     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
134     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
135     GroupButtonsLayout->addItem( spacer, 0, 2 );
136     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
137     buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
138     buttonCancel->setAutoDefault( TRUE );
139     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
140     StdMeshersGUI_MaxElementAreaDlgLayout->addMultiCellWidget( GroupButtons, 2, 2, 0, 1 );
141
142     /***************************************************************/
143     Init() ;
144 }
145
146
147 //=================================================================================
148 // function : ~StdMeshersGUI_MaxElementAreaDlg()
149 // purpose  : Destroys the object and frees any allocated resources
150 //=================================================================================
151 StdMeshersGUI_MaxElementAreaDlg::~StdMeshersGUI_MaxElementAreaDlg()
152 {
153     // no need to delete child widgets, Qt does it all for us
154 }
155
156
157 //=================================================================================
158 // function : Init()
159 // purpose  :
160 //=================================================================================
161 void StdMeshersGUI_MaxElementAreaDlg::Init()
162 {
163   /* min, max, step and decimals for spin boxes */
164   SpinBox_MaxElementArea->setPrecision( 10 );
165   SpinBox_MaxElementArea->RangeStepAndValidator( 0.001, 999999.999, 1.0, 3 ) ;
166   SpinBox_MaxElementArea->SetValue( 1.0 ) ;  /* is myMaxElementArea */
167   
168   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
169
170   char* sHypType = (char*)myHypType.latin1();
171   HypothesisData* aHypData = mySMESHGUI->GetHypothesisData(sHypType);
172   //CS_PhB ambiguous overload  LineEdit_NameHypothesis->setText( aHypData ? aHypData->Label : "" );
173   if (aHypData!=0)
174     {
175       LineEdit_NameHypothesis->setText(aHypData->Label);
176     }
177   else
178     {
179       LineEdit_NameHypothesis->setText("");
180     }
181
182   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
183
184   /* signals and slots connections */
185   connect( buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()) );
186   connect( buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()) ) ;
187   connect( buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()) );
188
189   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;  
190   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
191
192   /* Move widget on the botton right corner of main widget */
193   int x, y ;
194   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
195   this->move( x, y ) ; 
196   this->show() ; /* displays Dialog */
197 }
198
199
200 //=================================================================================
201 // function : ClickOnOk()
202 // purpose  :
203 //=================================================================================
204 void StdMeshersGUI_MaxElementAreaDlg::ClickOnOk()
205 {
206   if ( this->ClickOnApply() )
207     this->ClickOnCancel() ;
208 }
209
210 //=================================================================================
211 // function : ClickOnApply()
212 // purpose  :
213 //=================================================================================
214 bool StdMeshersGUI_MaxElementAreaDlg::ClickOnApply()
215 {
216   QString myHypName = LineEdit_NameHypothesis->text().stripWhiteSpace();
217   if ( myHypName.isEmpty() ) {
218     QAD_MessageBox::warn1( this, tr( "SMESH_WRN_WARNING" ), tr( "SMESH_WRN_EMPTY_NAME" ), tr( "SMESH_BUT_OK" ) );
219     return false;
220   }
221   
222   double myMaxElementArea = SpinBox_MaxElementArea->GetValue();
223
224   QAD_WaitCursor wc;
225   try {
226     SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow
227       (mySMESHGUI->CreateHypothesis(myHypType,
228                                     myHypName,
229                                     false)); // isAlgorithm
230     StdMeshers::StdMeshers_MaxElementArea_var MaxElArea =
231       StdMeshers::StdMeshers_MaxElementArea::_narrow(Hyp);
232     if (!MaxElArea->_is_nil())
233       MaxElArea->SetMaxElementArea(myMaxElementArea);
234   }
235   catch (const SALOME::SALOME_Exception& S_ex) {
236     wc.stop();
237     QtCatchCorbaException(S_ex);
238     return false;
239   }
240   return true;
241 }
242
243
244 //=================================================================================
245 // function : ClickOnCancel()
246 // purpose  :
247 //=================================================================================
248 void StdMeshersGUI_MaxElementAreaDlg::ClickOnCancel()
249 {
250   close();
251 }
252
253
254 //=================================================================================
255 // function : DeactivateActiveDialog()
256 // purpose  :
257 //=================================================================================
258 void StdMeshersGUI_MaxElementAreaDlg::DeactivateActiveDialog()
259 {
260   iconLabel->setEnabled(false) ;
261   typeLabel->setEnabled(false) ;
262   GroupC1->setEnabled(false) ;
263   GroupButtons->setEnabled(false) ;
264 }
265
266
267 //=================================================================================
268 // function : ActivateThisDialog()
269 // purpose  :
270 //=================================================================================
271 void StdMeshersGUI_MaxElementAreaDlg::ActivateThisDialog()
272 {
273   mySMESHGUI->EmitSignalDeactivateDialog() ;   
274   iconLabel->setEnabled(true) ;
275   typeLabel->setEnabled(true) ;
276   GroupC1->setEnabled(true) ;
277   GroupButtons->setEnabled(true) ;
278 }
279
280
281 //=================================================================================
282 // function : enterEvent()
283 // purpose  :
284 //=================================================================================
285 void StdMeshersGUI_MaxElementAreaDlg::enterEvent(QEvent* e)
286 {
287   ActivateThisDialog() ;
288 }
289
290
291 //=================================================================================
292 // function : closeEvent()
293 // purpose  :
294 //=================================================================================
295 void StdMeshersGUI_MaxElementAreaDlg::closeEvent( QCloseEvent* e )
296 {
297   mySMESHGUI->ResetState();
298   QDialog::closeEvent( e );
299 }