Salome HOME
Remove OCC_LIBS from LDFLAGS
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_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   : SMESHGUI_MaxElementVolumeDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESHGUI_MaxElementVolumeDlg.h"
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_SpinBox.h"
33
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "utilities.h"
37
38 // QT Includes
39 #include <qbuttongroup.h>
40 #include <qgroupbox.h>
41 #include <qlabel.h>
42 #include <qlineedit.h>
43 #include <qpushbutton.h>
44 #include <qradiobutton.h>
45 #include <qlayout.h>
46 #include <qvariant.h>
47 #include <qtooltip.h>
48 #include <qwhatsthis.h>
49 #include <qimage.h>
50 #include <qpixmap.h>
51
52 //=================================================================================
53 // class    : SMESHGUI_MaxElementVolumeDlg()
54 // purpose  : Constructs a SMESHGUI_MaxElementVolumeDlg which is a child of 'parent', with the 
55 //            name 'name' and widget flags set to 'f'.
56 //            The dialog will by default be modeless, unless you set 'modal' to
57 //            TRUE to construct a modal dialog.
58 //=================================================================================
59 SMESHGUI_MaxElementVolumeDlg::SMESHGUI_MaxElementVolumeDlg( QWidget* parent, const char* name, bool modal, WFlags fl )
60     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
61 {
62     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_MAX_ELEMENT_VOLUME")));
63     
64     if ( !name )
65       setName( "SMESHGUI_MaxElementVolumeDlg" );
66     resize( 303, 175 ); 
67     setCaption( tr( "SMESH_MAX_ELEMENT_VOLUME_TITLE"  ) );
68     setSizeGripEnabled( TRUE );
69     SMESHGUI_MaxElementVolumeDlgLayout = new QGridLayout( this ); 
70     SMESHGUI_MaxElementVolumeDlgLayout->setSpacing( 6 );
71     SMESHGUI_MaxElementVolumeDlgLayout->setMargin( 11 );
72
73     /***************************************************************/
74     GroupButtons = new QGroupBox( this, "GroupButtons" );
75     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
76     GroupButtons->setTitle( tr( ""  ) );
77     GroupButtons->setColumnLayout(0, Qt::Vertical );
78     GroupButtons->layout()->setSpacing( 0 );
79     GroupButtons->layout()->setMargin( 0 );
80     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
81     GroupButtonsLayout->setAlignment( Qt::AlignTop );
82     GroupButtonsLayout->setSpacing( 6 );
83     GroupButtonsLayout->setMargin( 11 );
84     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
85     buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
86     buttonCancel->setAutoDefault( TRUE );
87     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
88     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
89     buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
90     buttonApply->setAutoDefault( TRUE );
91     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
92     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
93     GroupButtonsLayout->addItem( spacer, 0, 2 );
94     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
95     buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
96     buttonOk->setAutoDefault( TRUE );
97     buttonOk->setDefault( TRUE );
98     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
99     SMESHGUI_MaxElementVolumeDlgLayout->addWidget( GroupButtons, 2, 0 );
100
101     /***************************************************************/
102     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
103     GroupConstructors->setTitle( tr( "SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"  ) );
104     GroupConstructors->setExclusive( TRUE );
105     GroupConstructors->setColumnLayout(0, Qt::Vertical );
106     GroupConstructors->layout()->setSpacing( 0 );
107     GroupConstructors->layout()->setMargin( 0 );
108     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
109     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
110     GroupConstructorsLayout->setSpacing( 6 );
111     GroupConstructorsLayout->setMargin( 11 );
112     QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
113     GroupConstructorsLayout->addItem( spacer_2, 0, 1 );
114     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
115     Constructor1->setText( tr( ""  ) );
116     Constructor1->setPixmap( image0 );
117     Constructor1->setChecked( TRUE );
118     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
119     Constructor1->setMinimumSize( QSize( 50, 0 ) );
120     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
121     QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
122     GroupConstructorsLayout->addItem( spacer_3, 0, 1 );
123     SMESHGUI_MaxElementVolumeDlgLayout->addWidget( GroupConstructors, 0, 0 );
124     
125     /***************************************************************/
126     GroupC1 = new QGroupBox( this, "GroupC1" );
127     GroupC1->setTitle( tr( "SMESH_ARGUMENTS"  ) );
128     GroupC1->setColumnLayout(0, Qt::Vertical );
129     GroupC1->layout()->setSpacing( 0 );
130     GroupC1->layout()->setMargin( 0 );
131     GroupC1Layout = new QGridLayout( GroupC1->layout() );
132     GroupC1Layout->setAlignment( Qt::AlignTop );
133     GroupC1Layout->setSpacing( 6 );
134     GroupC1Layout->setMargin( 11 );
135     TextLabel_MaxElementVolume = new QLabel(GroupC1 , "TextLabel_MaxElementVolume" );
136     TextLabel_MaxElementVolume->setText( tr( "SMESH_MAX_ELEMENT_VOLUME"  ) );
137     GroupC1Layout->addWidget( TextLabel_MaxElementVolume, 1, 0 );
138     TextLabel_NameHypothesis = new QLabel( GroupC1, "TextLabel_NameHypothesis" );
139     TextLabel_NameHypothesis->setText( tr( "SMESH_NAME"  ) );
140     GroupC1Layout->addWidget( TextLabel_NameHypothesis, 0, 0 );
141
142     // LineEdit_MaxElementVolume = new QLineEdit(GroupC1 , "LineEdit_MaxElementVolume" );
143     // GroupC1Layout->addWidget( LineEdit_MaxElementVolume, 1, 1 );
144     SpinBox_MaxElementVolume = new SMESHGUI_SpinBox( GroupC1, "SpinBox_MaxElementVolume" ) ;
145     GroupC1Layout->addWidget( SpinBox_MaxElementVolume, 1, 1 );
146
147     LineEdit_NameHypothesis = new QLineEdit( GroupC1, "LineEdit_NameHypothesis" );
148     GroupC1Layout->addWidget( LineEdit_NameHypothesis, 0, 1 );
149     QSpacerItem* spacer1 = new QSpacerItem( 20, 24, QSizePolicy::Minimum, QSizePolicy::Fixed );
150     GroupC1Layout->addItem( spacer1, 1, 3 );
151     SMESHGUI_MaxElementVolumeDlgLayout->addWidget(GroupC1 , 1, 0 );
152
153     /***************************************************************/
154
155     Init() ;
156 }
157
158
159 //=================================================================================
160 // function : ~SMESHGUI_MaxElementVolumeDlg()
161 // purpose  : Destroys the object and frees any allocated resources
162 //=================================================================================
163 SMESHGUI_MaxElementVolumeDlg::~SMESHGUI_MaxElementVolumeDlg()
164 {
165     // no need to delete child widgets, Qt does it all for us
166 }
167
168
169 //=================================================================================
170 // function : Init()
171 // purpose  :
172 //=================================================================================
173 void SMESHGUI_MaxElementVolumeDlg::Init()
174 {
175   
176   GroupC1->show();
177   myConstructorId = 0 ;
178   Constructor1->setChecked( TRUE );
179   myEditCurrentArgument = LineEdit_NameHypothesis ;
180
181
182   /* Get setting of step value from file configuration */
183   double step ;
184   // QString St = QAD_CONFIG->getSetting( "xxxxxxxxxxxxx" ) ;  TODO
185   // step = St.toDouble() ;                                    TODO
186   step = 1.0 ;
187
188   /* min, max, step and decimals for spin boxes */
189   SpinBox_MaxElementVolume->setPrecision( 10 );
190   SpinBox_MaxElementVolume->RangeStepAndValidator( 0.001, 999999.999, step, 3 ) ;
191   SpinBox_MaxElementVolume->SetValue( 1.0 ) ;  /* is myMaxElementVolume */
192
193   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
194   LineEdit_NameHypothesis->setText("") ;
195
196   myNameHypothesis = "" ;
197   myMaxElementVolume = 1.0 ;
198
199   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
200
201   /* signals and slots connections */
202   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
203   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
204   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
205   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );  
206
207   connect( LineEdit_NameHypothesis, SIGNAL (textChanged(const QString&)  ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
208
209   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;  
210   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
211
212   /* Move widget on the botton right corner of main widget */
213   int x, y ;
214   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
215   this->move( x, y ) ; 
216   this->show() ; /* displays Dialog */
217
218   return ;
219 }
220
221
222
223 //=================================================================================
224 // function : ConstructorsClicked()
225 // purpose  : Radio button management
226 //=================================================================================
227 void SMESHGUI_MaxElementVolumeDlg::ConstructorsClicked(int constructorId)
228 {
229   return;
230 }
231
232 //=================================================================================
233 // function : ClickOnOk()
234 // purpose  :
235 //=================================================================================
236 void SMESHGUI_MaxElementVolumeDlg::ClickOnOk()
237 {
238   this->ClickOnApply() ;
239   this->ClickOnCancel() ;
240
241   return ;
242 }
243
244 //=================================================================================
245 // function : ClickOnApply()
246 // purpose  :
247 //=================================================================================
248 void SMESHGUI_MaxElementVolumeDlg::ClickOnApply()
249 {
250   switch(myConstructorId)
251     { 
252     case 0 :
253       { 
254         myMaxElementVolume = SpinBox_MaxElementVolume->GetValue() ;
255         mySMESHGUI->CreateMaxElementVolume( "MaxElementVolume", myNameHypothesis, myMaxElementVolume );
256         break ;
257       }
258     }
259   return ;
260 }
261
262
263 //=================================================================================
264 // function : ClickOnCancel()
265 // purpose  :
266 //=================================================================================
267 void SMESHGUI_MaxElementVolumeDlg::ClickOnCancel()
268 {
269   mySMESHGUI->ResetState() ;
270   reject() ;
271 }
272
273 //=================================================================================
274 // function : TextChangedInLineEdit()
275 // purpose  :
276 //=================================================================================
277 void SMESHGUI_MaxElementVolumeDlg::TextChangedInLineEdit(const QString& newText)
278 {  
279   QLineEdit* send = (QLineEdit*)sender();
280   QString newT = strdup(newText) ;
281   
282   if (send == LineEdit_NameHypothesis) {
283     myNameHypothesis = newText ;
284   }
285   return ;
286 }
287
288
289 //=================================================================================
290 // function : DeactivateActiveDialog()
291 // purpose  :
292 //=================================================================================
293 void SMESHGUI_MaxElementVolumeDlg::DeactivateActiveDialog()
294 {
295   if ( GroupConstructors->isEnabled() ) {
296     GroupConstructors->setEnabled(false) ;
297     GroupC1->setEnabled(false) ;
298     GroupButtons->setEnabled(false) ;
299   } 
300 }
301
302
303 //=================================================================================
304 // function : ActivateThisDialog()
305 // purpose  :
306 //=================================================================================
307 void SMESHGUI_MaxElementVolumeDlg::ActivateThisDialog()
308 {
309   mySMESHGUI->EmitSignalDeactivateDialog() ;   
310   GroupConstructors->setEnabled(true) ;
311   GroupC1->setEnabled(true) ;
312   GroupButtons->setEnabled(true) ;
313   return ;
314 }
315
316
317 //=================================================================================
318 // function : enterEvent()
319 // purpose  :
320 //=================================================================================
321 void SMESHGUI_MaxElementVolumeDlg::enterEvent(QEvent* e)
322 {
323   if ( GroupConstructors->isEnabled() )
324     return ;  
325   ActivateThisDialog() ;
326   return ;
327 }
328
329
330 //=================================================================================
331 // function : closeEvent()
332 // purpose  :
333 //=================================================================================
334 void SMESHGUI_MaxElementVolumeDlg::closeEvent( QCloseEvent* e )
335 {
336   this->ClickOnCancel() ;
337   return ;
338 }