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