Salome HOME
This commit was generated by cvs2git to create branch 'IMPORT'.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_NbSegmentsDlg.cxx
1 using namespace std;
2 //  File      : SMESHGUI_NbSegmentsDlg.cxx
3 //  Created   : Mon May 27 11:38:27 2002
4 //  Author    : Nicolas REJNERI
5
6 //  Project   : SALOME
7 //  Module    : SMESH
8 //  Copyright : Open CASCADE 2002
9 //  $Header$
10
11 #include "SMESHGUI_NbSegmentsDlg.h"
12 #include "SMESHGUI.h"
13
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16 #include "utilities.h"
17
18 // QT Includes
19 #include <qbuttongroup.h>
20 #include <qgroupbox.h>
21 #include <qlabel.h>
22 #include <qlineedit.h>
23 #include <qpushbutton.h>
24 #include <qradiobutton.h>
25 #include <qlayout.h>
26 #include <qvariant.h>
27 #include <qtooltip.h>
28 #include <qwhatsthis.h>
29 #include <qimage.h>
30 #include <qpixmap.h>
31 #include <qspinbox.h>
32
33 //=================================================================================
34 // class    : SMESHGUI_NbSegmentsDlg()
35 // purpose  : Constructs a SMESHGUI_NbSegmentsDlg 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_NbSegmentsDlg::SMESHGUI_NbSegmentsDlg( 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( "SMESHGUI",tr("ICON_DLG_NB_SEGMENTS")));
44     
45     if ( !name )
46       setName( "SMESHGUI_NbSegmentsDlg" );
47     resize( 303, 175 ); 
48     setCaption( tr( "SMESH_NB_SEGMENTS_TITLE"  ) );
49     setSizeGripEnabled( TRUE );
50     SMESHGUI_NbSegmentsDlgLayout = new QGridLayout( this ); 
51     SMESHGUI_NbSegmentsDlgLayout->setSpacing( 6 );
52     SMESHGUI_NbSegmentsDlgLayout->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_NbSegmentsDlgLayout->addWidget( GroupButtons, 2, 0 );
81
82     /***************************************************************/
83     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
84     GroupConstructors->setTitle( tr( "SMESH_NB_SEGMENTS_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_NbSegmentsDlgLayout->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_NbSeg = new QLabel(GroupC1 , "TextLabel_NbSeg" );
117     TextLabel_NbSeg->setText( tr( "SMESH_SEGMENTS"  ) );
118     GroupC1Layout->addWidget( TextLabel_NbSeg, 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     SpinBox_NbSeg = new QSpinBox( GroupC1, "SpinBox_NbSeg" );
124     GroupC1Layout->addWidget( SpinBox_NbSeg, 1, 1 );
125
126     LineEdit_NameHypothesis = new QLineEdit( GroupC1, "LineEdit_NameHypothesis" );
127     GroupC1Layout->addWidget( LineEdit_NameHypothesis, 0, 1 );
128     QSpacerItem* spacer1 = new QSpacerItem( 20, 24, QSizePolicy::Minimum, QSizePolicy::Fixed );
129     GroupC1Layout->addItem( spacer1, 1, 3 );
130     SMESHGUI_NbSegmentsDlgLayout->addWidget(GroupC1 , 1, 0 );
131
132     /***************************************************************/
133
134     Init() ;
135 }
136
137
138 //=================================================================================
139 // function : ~SMESHGUI_NbSegmentsDlg()
140 // purpose  : Destroys the object and frees any allocated resources
141 //=================================================================================
142 SMESHGUI_NbSegmentsDlg::~SMESHGUI_NbSegmentsDlg()
143 {
144     // no need to delete child widgets, Qt does it all for us
145 }
146
147
148 //=================================================================================
149 // function : Init()
150 // purpose  :
151 //=================================================================================
152 void SMESHGUI_NbSegmentsDlg::Init()
153 {
154
155   GroupC1->show();
156   myConstructorId = 0 ;
157   Constructor1->setChecked( TRUE );
158   myEditCurrentArgument = LineEdit_NameHypothesis ;
159
160   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
161   LineEdit_NameHypothesis->setText("") ;
162
163   SpinBox_NbSeg->setMinValue( 1 );
164   SpinBox_NbSeg->setMaxValue( 9999 );
165   SpinBox_NbSeg->setValue(3) ; /* myNbSeg */
166
167   myNbSeg = 3.0 ;
168   myNameHypothesis = "" ;
169
170   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
171
172   /* signals and slots connections */
173   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
174   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
175   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
176   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );  
177
178   connect( LineEdit_NameHypothesis, SIGNAL (textChanged(const QString&)  ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
179
180   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;  
181   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
182
183   /* Move widget on the botton right corner of main widget */
184   int x, y ;
185   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
186   this->move( x, y ) ; 
187   this->show() ; /* displays Dialog */
188
189   return ;
190 }
191
192
193
194 //=================================================================================
195 // function : ConstructorsClicked()
196 // purpose  : Radio button management
197 //=================================================================================
198 void SMESHGUI_NbSegmentsDlg::ConstructorsClicked(int constructorId)
199 {
200   return;
201 }
202
203 //=================================================================================
204 // function : ClickOnOk()
205 // purpose  :
206 //=================================================================================
207 void SMESHGUI_NbSegmentsDlg::ClickOnOk()
208 {
209   this->ClickOnApply() ;
210   this->ClickOnCancel() ;
211
212   return ;
213 }
214
215 //=================================================================================
216 // function : ClickOnApply()
217 // purpose  :
218 //=================================================================================
219 void SMESHGUI_NbSegmentsDlg::ClickOnApply()
220 {
221   switch(myConstructorId)
222     { 
223     case 0 :
224       { 
225         myNbSeg = SpinBox_NbSeg->value() ;
226         mySMESHGUI->CreateNbSegments( "NumberOfSegments", myNameHypothesis, myNbSeg );
227         break ;
228       }
229     }
230   return ;
231 }
232
233
234 //=================================================================================
235 // function : ClickOnCancel()
236 // purpose  :
237 //=================================================================================
238 void SMESHGUI_NbSegmentsDlg::ClickOnCancel()
239 {
240   mySMESHGUI->ResetState() ;
241   reject() ;
242 }
243
244
245 //=================================================================================
246 // function : DeactivateActiveDialog()
247 // purpose  :
248 //=================================================================================
249 void SMESHGUI_NbSegmentsDlg::DeactivateActiveDialog()
250 {
251   if ( GroupConstructors->isEnabled() ) {
252     GroupConstructors->setEnabled(false) ;
253     GroupC1->setEnabled(false) ;
254     GroupButtons->setEnabled(false) ;
255   } 
256 }
257
258
259 //=================================================================================
260 // function : TextChangedInLineEdit()
261 // purpose  :
262 //=================================================================================
263 void SMESHGUI_NbSegmentsDlg::TextChangedInLineEdit(const QString& newText)
264 {  
265   QLineEdit* send = (QLineEdit*)sender();
266   QString newT = strdup(newText) ;
267   
268   if (send == LineEdit_NameHypothesis) {
269     myNameHypothesis = newText ;
270   }
271   return ;
272 }
273
274
275 //=================================================================================
276 // function : ActivateThisDialog()
277 // purpose  :
278 //=================================================================================
279 void SMESHGUI_NbSegmentsDlg::ActivateThisDialog()
280 {
281   mySMESHGUI->EmitSignalDeactivateDialog() ;   
282   GroupConstructors->setEnabled(true) ;
283   GroupC1->setEnabled(true) ;
284   GroupButtons->setEnabled(true) ;
285   return ;
286 }
287
288
289 //=================================================================================
290 // function : enterEvent()
291 // purpose  :
292 //=================================================================================
293 void SMESHGUI_NbSegmentsDlg::enterEvent(QEvent* e)
294 {
295   if ( GroupConstructors->isEnabled() )
296     return ;  
297   ActivateThisDialog() ;
298   return ;
299 }
300
301
302 //=================================================================================
303 // function : closeEvent()
304 // purpose  :
305 //=================================================================================
306 void SMESHGUI_NbSegmentsDlg::closeEvent( QCloseEvent* e )
307 {
308   this->ClickOnCancel() ;
309   return ;
310 }