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