Salome HOME
NRI : First integration.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AddVolumeDlg.cxx
1 using namespace std;
2 //  File      : SMESHGUI_AddVolumeDlg.cxx
3 //  Created   : Wed Jun 26 21:00:14 2002
4 //  Author    : Nicolas REJNERI
5
6 //  Project   : SALOME
7 //  Module    : SMESH
8 //  Copyright : Open CASCADE 2002
9 //  $Header$
10
11
12 #include "SMESHGUI_AddVolumeDlg.h"
13
14 #include "SMESHGUI.h"
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "QAD_MessageBox.h"
18 #include "utilities.h"
19
20 // QT Includes
21 #include <qbuttongroup.h>
22 #include <qgroupbox.h>
23 #include <qlabel.h>
24 #include <qlineedit.h>
25 #include <qpushbutton.h>
26 #include <qradiobutton.h>
27 #include <qlayout.h>
28 #include <qvariant.h>
29 #include <qtooltip.h>
30 #include <qwhatsthis.h>
31 #include <qimage.h>
32 #include <qpixmap.h>
33 #include <qcheckbox.h>
34
35
36 //=================================================================================
37 // class    : SMESHGUI_AddVolumeDlg()
38 // purpose  : 
39 //=================================================================================
40 SMESHGUI_AddVolumeDlg::SMESHGUI_AddVolumeDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
41                                           int nbNodes, bool modal, WFlags fl )
42     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
43 {
44   myNodes = nbNodes;
45   QPixmap image0;
46   if ( myNodes == 4 )
47     image0 = QPixmap(QAD_Desktop::getResourceManager()->loadPixmap( "SMESHGUI",tr("ICON_DLG_TETRAS")));
48   else if ( myNodes == 8 )
49     image0 = QPixmap(QAD_Desktop::getResourceManager()->loadPixmap( "SMESHGUI",tr("ICON_DLG_HEXAS")));
50
51   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESHGUI",tr("ICON_SELECT")));
52
53   if ( !name )
54     setName( "SMESHGUI_AddVolumeDlg" );
55   resize( 303, 185 ); 
56   if ( myNodes == 4 )
57     setCaption( tr( "SMESH_ADD_TETRAS_TITLE"  ) );
58   else if ( myNodes == 8 )
59     setCaption( tr( "SMESH_ADD_HEXAS_TITLE"  ) );
60
61   setSizeGripEnabled( TRUE );
62   SMESHGUI_AddVolumeDlgLayout = new QGridLayout( this ); 
63   SMESHGUI_AddVolumeDlgLayout->setSpacing( 6 );
64   SMESHGUI_AddVolumeDlgLayout->setMargin( 11 );
65
66     /***************************************************************/
67   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
68   if ( myNodes == 4 )
69     GroupConstructors->setTitle( tr( "SMESH_TETRAS"  ) );
70   else if ( myNodes == 8 )
71     GroupConstructors->setTitle( tr( "SMESH_HEXAS"  ) );
72   
73   GroupConstructors->setExclusive( TRUE );
74   GroupConstructors->setColumnLayout(0, Qt::Vertical );
75   GroupConstructors->layout()->setSpacing( 0 );
76   GroupConstructors->layout()->setMargin( 0 );
77   GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
78   GroupConstructorsLayout->setAlignment( Qt::AlignTop );
79   GroupConstructorsLayout->setSpacing( 6 );
80   GroupConstructorsLayout->setMargin( 11 );
81   Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
82   Constructor1->setText( tr( ""  ) );
83   Constructor1->setPixmap( image0 );
84   Constructor1->setChecked( TRUE );
85   Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
86   Constructor1->setMinimumSize( QSize( 50, 0 ) );
87   GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
88   QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
89   GroupConstructorsLayout->addItem( spacer, 0, 1 );
90   SMESHGUI_AddVolumeDlgLayout->addWidget( GroupConstructors, 0, 0 );
91     
92     /***************************************************************/
93   GroupButtons = new QGroupBox( this, "GroupButtons" );
94   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
95   GroupButtons->setTitle( tr( ""  ) );
96   GroupButtons->setColumnLayout(0, Qt::Vertical );
97   GroupButtons->layout()->setSpacing( 0 );
98   GroupButtons->layout()->setMargin( 0 );
99   GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
100   GroupButtonsLayout->setAlignment( Qt::AlignTop );
101   GroupButtonsLayout->setSpacing( 6 );
102   GroupButtonsLayout->setMargin( 11 );
103   buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
104   buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
105   buttonCancel->setAutoDefault( TRUE );
106   GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
107   buttonApply = new QPushButton( GroupButtons, "buttonApply" );
108   buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
109   buttonApply->setAutoDefault( TRUE );
110   GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
111   QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
112   GroupButtonsLayout->addItem( spacer_9, 0, 2 );
113   buttonOk = new QPushButton( GroupButtons, "buttonOk" );
114   buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
115   buttonOk->setAutoDefault( TRUE );
116   buttonOk->setDefault( TRUE );
117   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
118   SMESHGUI_AddVolumeDlgLayout->addWidget( GroupButtons, 2, 0 );
119
120     /***************************************************************/
121   GroupC1 = new QGroupBox( this, "GroupC1" );
122   if ( myNodes == 4 )
123     GroupC1->setTitle( tr( "SMESH_ADD_TETRAS"  ) );
124   else if ( myNodes == 8 )
125     GroupC1->setTitle( tr( "SMESH_ADD_HEXAS"  ) );
126
127   GroupC1->setMinimumSize( QSize( 0, 0 ) );
128   GroupC1->setFrameShape( QGroupBox::Box );
129   GroupC1->setFrameShadow( QGroupBox::Sunken );
130   GroupC1->setColumnLayout(0, Qt::Vertical );
131   GroupC1->layout()->setSpacing( 0 );
132   GroupC1->layout()->setMargin( 0 );
133   GroupC1Layout = new QGridLayout( GroupC1->layout() );
134   GroupC1Layout->setAlignment( Qt::AlignTop );
135   GroupC1Layout->setSpacing( 6 );
136   GroupC1Layout->setMargin( 11 );
137   TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
138   TextLabelC1A1->setText( tr( "SMESH_ID_NODES"  ) );
139   TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
140   TextLabelC1A1->setFrameShape( QLabel::NoFrame );
141   TextLabelC1A1->setFrameShadow( QLabel::Plain );
142   GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
143   SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
144   SelectButtonC1A1->setText( tr( ""  ) );
145   SelectButtonC1A1->setPixmap( image1 );
146   SelectButtonC1A1->setToggleButton( FALSE );
147   GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
148   LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
149   GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
150
151   SMESHGUI_AddVolumeDlgLayout->addWidget( GroupC1, 1, 0 );
152
153   Init(Sel) ; /* Initialisations */
154 }
155
156 //=================================================================================
157 // function : ~SMESHGUI_AddVolumeDlg()
158 // purpose  : Destroys the object and frees any allocated resources
159 //=================================================================================
160 SMESHGUI_AddVolumeDlg::~SMESHGUI_AddVolumeDlg()
161 {
162     // no need to delete child widgets, Qt does it all for us
163 }
164
165
166 //=================================================================================
167 // function : Init()
168 // purpose  :
169 //=================================================================================
170 void SMESHGUI_AddVolumeDlg::Init( SALOME_Selection* Sel )
171 {
172
173   GroupC1->show();
174   myConstructorId = 0 ;
175   Constructor1->setChecked( TRUE );
176   myEditCurrentArgument = LineEditC1A1 ;        
177   mySelection = Sel;  
178   this->myOkNodes = false ;
179   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
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( SelectButtonC1A1, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
189   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
190   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
191   /* to close dialog if study change */
192   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
193
194   /* Move widget on the botton right corner of main widget */
195   int x, y ;
196   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
197   this->move( x, y ) ;
198   this->show() ; /* displays Dialog */
199
200   SelectionIntoArgument();
201
202   return ;
203 }
204
205
206 //=================================================================================
207 // function : ConstructorsClicked()
208 // purpose  : Radio button management
209 //=================================================================================
210 void SMESHGUI_AddVolumeDlg::ConstructorsClicked(int constructorId)
211 {
212   return ;
213 }
214
215
216 //=================================================================================
217 // function : ClickOnApply()
218 // purpose  :
219 //=================================================================================
220 void SMESHGUI_AddVolumeDlg::ClickOnApply()
221 {
222   switch(myConstructorId)
223     { 
224     case 0 :
225       { 
226         if(myOkNodes) {   
227           mySMESHGUI->EraseSimulationActors();
228           mySMESHGUI->AddVolume( myMesh, myMapIndex ) ;
229           mySMESHGUI->ViewNodes();
230           mySelection->ClearIObjects();
231         }
232         break ;
233       }
234     }
235   return ;
236 }
237
238 //=================================================================================
239 // function : ClickOnOk()
240 // purpose  :
241 //=================================================================================
242 void SMESHGUI_AddVolumeDlg::ClickOnOk()
243 {
244   this->ClickOnApply() ;
245   this->ClickOnCancel() ;
246   return ;
247 }
248
249 //=================================================================================
250 // function : ClickOnCancel()
251 // purpose  :
252 //=================================================================================
253 void SMESHGUI_AddVolumeDlg::ClickOnCancel()
254 {
255   QAD_Application::getDesktop()->SetSelectionMode( 4 );
256   disconnect( mySelection, 0, this, 0 );
257   mySMESHGUI->ResetState() ;
258   mySMESHGUI->EraseSimulationActors();
259   reject() ;
260   return ;
261 }
262
263
264 //=================================================================================
265 // function : SelectionIntoArgument()
266 // purpose  : Called when selection as changed or other case
267 //=================================================================================
268 void SMESHGUI_AddVolumeDlg::SelectionIntoArgument()
269 {
270   myEditCurrentArgument->setText("") ;
271   myOkNodes = false;
272   QString aString = "";
273
274   int nbSel = mySelection->IObjectCount();
275   if(nbSel != 1)
276     return;
277
278   int nbNodes = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aString) ;
279   if(nbNodes < 1)
280     return ;
281   
282   if ( mySelection->SelectionMode() != 1 ) {
283     QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
284                             tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_YES") );
285     return;
286   }
287
288   myEditCurrentArgument->setText(aString) ;
289   Standard_Boolean res;
290   myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
291   if (!res)
292     return ;
293
294   mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
295
296   if ( myNodes == 4 && nbNodes == 4 ) {
297     mySMESHGUI->DisplaySimulationTetra(myMesh, myMapIndex);
298     myOkNodes = true ;
299   } else if ( myNodes == 8 && nbNodes == 8 ) {
300     mySMESHGUI->DisplaySimulationHexa(myMesh, myMapIndex);
301     myOkNodes = true ;
302   } else {
303     //    mySMESHGUI->EraseSimulationActors();
304     myOkNodes = false ;
305   }
306   return ;
307 }
308
309
310 //=================================================================================
311 // function : SetEditCurrentArgument()
312 // purpose  :
313 //=================================================================================
314 void SMESHGUI_AddVolumeDlg::SetEditCurrentArgument()
315 {
316   QPushButton* send = (QPushButton*)sender();
317   switch (myConstructorId)
318     {
319     case 0: /* default constructor */
320       { 
321         if(send == SelectButtonC1A1) {
322           LineEditC1A1->setFocus() ;
323           myEditCurrentArgument = LineEditC1A1;
324         }
325         SelectionIntoArgument() ;
326         break;
327       }
328     }
329   return ;
330 }
331
332 //=================================================================================
333 // function : DeactivateActiveDialog()
334 // purpose  :
335 //=================================================================================
336 void SMESHGUI_AddVolumeDlg::DeactivateActiveDialog()
337 {
338   if ( GroupConstructors->isEnabled() ) {  
339     GroupConstructors->setEnabled(false) ;
340     GroupC1->setEnabled(false) ;
341     GroupButtons->setEnabled(false) ;
342     mySMESHGUI->EraseSimulationActors() ;
343     mySMESHGUI->ResetState() ;    
344     mySMESHGUI->SetActiveDialogBox(0) ;
345   }
346   return ;
347 }
348
349
350 //=================================================================================
351 // function : ActivateThisDialog()
352 // purpose  :
353 //=================================================================================
354 void SMESHGUI_AddVolumeDlg::ActivateThisDialog()
355 {
356   /* Emit a signal to deactivate the active dialog */
357   mySMESHGUI->EmitSignalDeactivateDialog() ;   
358   GroupConstructors->setEnabled(true) ;
359   GroupC1->setEnabled(true) ;
360   GroupButtons->setEnabled(true) ;
361   return ;
362 }
363
364
365 //=================================================================================
366 // function : enterEvent()
367 // purpose  :
368 //=================================================================================
369 void SMESHGUI_AddVolumeDlg::enterEvent(QEvent* e)
370 {
371   if ( GroupConstructors->isEnabled() )
372     return ;  
373   ActivateThisDialog() ;
374   return ;
375 }
376
377
378 //=================================================================================
379 // function : closeEvent()
380 // purpose  :
381 //=================================================================================
382 void SMESHGUI_AddVolumeDlg::closeEvent( QCloseEvent* e )
383 {
384   /* same than click on cancel button */
385   this->ClickOnCancel() ;
386   return ;
387 }
388