Salome HOME
Some forgotten return statments
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_NbSegmentsDlg.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_NbSegmentsDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESHGUI_NbSegmentsDlg.h"
31 #include "SMESHGUI.h"
32
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
36
37 // QT Includes
38 #include <qbuttongroup.h>
39 #include <qgroupbox.h>
40 #include <qlabel.h>
41 #include <qlineedit.h>
42 #include <qpushbutton.h>
43 #include <qradiobutton.h>
44 #include <qlayout.h>
45 #include <qvariant.h>
46 #include <qtooltip.h>
47 #include <qwhatsthis.h>
48 #include <qimage.h>
49 #include <qpixmap.h>
50 #include <qspinbox.h>
51
52 //=================================================================================
53 // class    : SMESHGUI_NbSegmentsDlg()
54 // purpose  : Constructs a SMESHGUI_NbSegmentsDlg 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_NbSegmentsDlg::SMESHGUI_NbSegmentsDlg( 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_NB_SEGMENTS")));
63     
64     if ( !name )
65       setName( "SMESHGUI_NbSegmentsDlg" );
66     resize( 303, 175 ); 
67     setCaption( tr( "SMESH_NB_SEGMENTS_TITLE"  ) );
68     setSizeGripEnabled( TRUE );
69     SMESHGUI_NbSegmentsDlgLayout = new QGridLayout( this ); 
70     SMESHGUI_NbSegmentsDlgLayout->setSpacing( 6 );
71     SMESHGUI_NbSegmentsDlgLayout->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_NbSegmentsDlgLayout->addWidget( GroupButtons, 2, 0 );
100
101     /***************************************************************/
102     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
103     GroupConstructors->setTitle( tr( "SMESH_NB_SEGMENTS_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_NbSegmentsDlgLayout->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_NbSeg = new QLabel(GroupC1 , "TextLabel_NbSeg" );
136     TextLabel_NbSeg->setText( tr( "SMESH_SEGMENTS"  ) );
137     GroupC1Layout->addWidget( TextLabel_NbSeg, 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     SpinBox_NbSeg = new QSpinBox( GroupC1, "SpinBox_NbSeg" );
143     GroupC1Layout->addWidget( SpinBox_NbSeg, 1, 1 );
144
145     LineEdit_NameHypothesis = new QLineEdit( GroupC1, "LineEdit_NameHypothesis" );
146     GroupC1Layout->addWidget( LineEdit_NameHypothesis, 0, 1 );
147     QSpacerItem* spacer1 = new QSpacerItem( 20, 24, QSizePolicy::Minimum, QSizePolicy::Fixed );
148     GroupC1Layout->addItem( spacer1, 1, 3 );
149     SMESHGUI_NbSegmentsDlgLayout->addWidget(GroupC1 , 1, 0 );
150
151     /***************************************************************/
152
153     Init() ;
154 }
155
156
157 //=================================================================================
158 // function : ~SMESHGUI_NbSegmentsDlg()
159 // purpose  : Destroys the object and frees any allocated resources
160 //=================================================================================
161 SMESHGUI_NbSegmentsDlg::~SMESHGUI_NbSegmentsDlg()
162 {
163     // no need to delete child widgets, Qt does it all for us
164 }
165
166
167 //=================================================================================
168 // function : Init()
169 // purpose  :
170 //=================================================================================
171 void SMESHGUI_NbSegmentsDlg::Init()
172 {
173
174   GroupC1->show();
175   myConstructorId = 0 ;
176   Constructor1->setChecked( TRUE );
177   myEditCurrentArgument = LineEdit_NameHypothesis ;
178
179   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
180   LineEdit_NameHypothesis->setText("") ;
181
182   SpinBox_NbSeg->setMinValue( 1 );
183   SpinBox_NbSeg->setMaxValue( 9999 );
184   SpinBox_NbSeg->setValue(3) ; /* myNbSeg */
185
186   myNbSeg = 3.0 ;
187   myNameHypothesis = "" ;
188
189   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
190
191   /* signals and slots connections */
192   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
193   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
194   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
195   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );  
196
197   connect( LineEdit_NameHypothesis, SIGNAL (textChanged(const QString&)  ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
198
199   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;  
200   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
201
202   /* Move widget on the botton right corner of main widget */
203   int x, y ;
204   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
205   this->move( x, y ) ; 
206   this->show() ; /* displays Dialog */
207
208   return ;
209 }
210
211
212
213 //=================================================================================
214 // function : ConstructorsClicked()
215 // purpose  : Radio button management
216 //=================================================================================
217 void SMESHGUI_NbSegmentsDlg::ConstructorsClicked(int constructorId)
218 {
219   return;
220 }
221
222 //=================================================================================
223 // function : ClickOnOk()
224 // purpose  :
225 //=================================================================================
226 void SMESHGUI_NbSegmentsDlg::ClickOnOk()
227 {
228   this->ClickOnApply() ;
229   this->ClickOnCancel() ;
230
231   return ;
232 }
233
234 //=================================================================================
235 // function : ClickOnApply()
236 // purpose  :
237 //=================================================================================
238 void SMESHGUI_NbSegmentsDlg::ClickOnApply()
239 {
240   switch(myConstructorId)
241     { 
242     case 0 :
243       { 
244         myNbSeg = SpinBox_NbSeg->value() ;
245         mySMESHGUI->CreateNbSegments( "NumberOfSegments", myNameHypothesis, myNbSeg );
246         break ;
247       }
248     }
249   return ;
250 }
251
252
253 //=================================================================================
254 // function : ClickOnCancel()
255 // purpose  :
256 //=================================================================================
257 void SMESHGUI_NbSegmentsDlg::ClickOnCancel()
258 {
259   mySMESHGUI->ResetState() ;
260   reject() ;
261 }
262
263
264 //=================================================================================
265 // function : DeactivateActiveDialog()
266 // purpose  :
267 //=================================================================================
268 void SMESHGUI_NbSegmentsDlg::DeactivateActiveDialog()
269 {
270   if ( GroupConstructors->isEnabled() ) {
271     GroupConstructors->setEnabled(false) ;
272     GroupC1->setEnabled(false) ;
273     GroupButtons->setEnabled(false) ;
274   } 
275 }
276
277
278 //=================================================================================
279 // function : TextChangedInLineEdit()
280 // purpose  :
281 //=================================================================================
282 void SMESHGUI_NbSegmentsDlg::TextChangedInLineEdit(const QString& newText)
283 {  
284   QLineEdit* send = (QLineEdit*)sender();
285   QString newT = strdup(newText) ;
286   
287   if (send == LineEdit_NameHypothesis) {
288     myNameHypothesis = newText ;
289   }
290   return ;
291 }
292
293
294 //=================================================================================
295 // function : ActivateThisDialog()
296 // purpose  :
297 //=================================================================================
298 void SMESHGUI_NbSegmentsDlg::ActivateThisDialog()
299 {
300   mySMESHGUI->EmitSignalDeactivateDialog() ;   
301   GroupConstructors->setEnabled(true) ;
302   GroupC1->setEnabled(true) ;
303   GroupButtons->setEnabled(true) ;
304   return ;
305 }
306
307
308 //=================================================================================
309 // function : enterEvent()
310 // purpose  :
311 //=================================================================================
312 void SMESHGUI_NbSegmentsDlg::enterEvent(QEvent* e)
313 {
314   if ( GroupConstructors->isEnabled() )
315     return ;  
316   ActivateThisDialog() ;
317   return ;
318 }
319
320
321 //=================================================================================
322 // function : closeEvent()
323 // purpose  :
324 //=================================================================================
325 void SMESHGUI_NbSegmentsDlg::closeEvent( QCloseEvent* e )
326 {
327   this->ClickOnCancel() ;
328   return ;
329 }