Salome HOME
Prevent exception at shape selection if no mesh was pre-selected
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AddMeshElementDlg.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_AddMeshElementDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 #include "SMESHGUI_AddMeshElementDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
36 #include "SMESH_ActorUtils.h"
37  
38 #include "VTKViewer_ViewFrame.h"
39 #include "SMDS_Mesh.hxx"
40 #include "SMESH_Actor.h"
41
42 #include "QAD_Application.h"
43 #include "QAD_Desktop.h"
44 #include "QAD_MessageBox.h"
45
46 #include "utilities.h"
47
48 #include <vtkCell.h>
49 #include <vtkIdList.h>
50 #include <vtkIntArray.h>
51 #include <vtkCellArray.h>
52 #include <vtkUnsignedCharArray.h>
53 #include <vtkUnstructuredGrid.h>
54 #include <vtkDataSetMapper.h>
55
56 // QT Includes
57 #include <qbuttongroup.h>
58 #include <qgroupbox.h>
59 #include <qlabel.h>
60 #include <qlineedit.h>
61 #include <qpushbutton.h>
62 #include <qradiobutton.h>
63 #include <qlayout.h>
64 #include <qvariant.h>
65 #include <qtooltip.h>
66 #include <qwhatsthis.h>
67 #include <qimage.h>
68 #include <qpixmap.h>
69 #include <qcheckbox.h>
70 #include <qregexp.h>
71
72 #include <list>
73 #include <TColStd_IndexedMapOfInteger.hxx>
74
75 using namespace std;
76
77 namespace SMESH{
78
79   class TElementSimulation{
80     QAD_Study* myStudy;
81     QAD_StudyFrame* myStudyFrame;
82     VTKViewer_ViewFrame* myViewFrame;
83
84     SALOME_Actor *myPreviewActor;
85     vtkDataSetMapper* myMapper;
86     vtkUnstructuredGrid* myGrid;
87
88   public:
89
90     TElementSimulation(QAD_Study* theStudy):
91       myStudy(theStudy),
92       myStudyFrame(theStudy->getActiveStudyFrame()),
93       myViewFrame(GetVtkViewFrame(theStudy->getActiveStudyFrame()))
94     {
95       myGrid = vtkUnstructuredGrid::New();
96   
97       // Create and display actor
98       myMapper = vtkDataSetMapper::New();
99       myMapper->SetInput( myGrid );
100
101       myPreviewActor = SALOME_Actor::New();
102       myPreviewActor->PickableOff();
103       myPreviewActor->VisibilityOff();
104       myPreviewActor->SetMapper( myMapper );
105
106       vtkProperty* aProp = vtkProperty::New();
107       float anRGB[3];
108       anRGB[0] = GetFloat("SMESH:SettingsFillColorRed", 0)/255.;
109       anRGB[1] = GetFloat("SMESH:SettingsFillColorGreen", 170)/255.;
110       anRGB[2] = GetFloat("SMESH:SettingsFillColorBlue", 255)/255.;
111       aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
112       myPreviewActor->SetProperty( aProp );
113       aProp->Delete();
114
115       vtkProperty* aBackProp = vtkProperty::New();
116       anRGB[0] = GetFloat("SMESH:SettingsBackFaceColorRed", 0)/255.;
117       anRGB[1] = GetFloat("SMESH:SettingsBackFaceColorGreen", 0)/255.;
118       anRGB[2] = GetFloat("SMESH:SettingsBackFaceColorBlue", 255)/255.;
119       aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
120       myPreviewActor->SetBackfaceProperty( aBackProp );
121       aBackProp->Delete();
122
123       myViewFrame->AddActor( myPreviewActor );
124
125     }
126
127
128     typedef list<vtkIdType> TVTKIds;
129     void SetPosition(SMESH_Actor* theActor, 
130                      vtkIdType theType, 
131                      const TVTKIds& theIds)
132     {
133       vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
134       myGrid->SetPoints(aGrid->GetPoints());
135
136       myGrid->Reset();
137       vtkIdList *anIds = vtkIdList::New();
138       TVTKIds::const_iterator anIt = theIds.begin();
139       for (int i = 0; anIt != theIds.end(); anIt++,i++)
140         anIds->InsertId(i, *anIt);
141       myGrid->InsertNextCell(theType,anIds);
142       anIds->Delete();
143
144       myGrid->Modified();
145
146       SetVisibility(true);
147     }
148
149
150     void SetVisibility(bool theVisibility){
151       myPreviewActor->SetVisibility(theVisibility);
152       RepaintCurrentView();
153     }
154
155
156     ~TElementSimulation(){
157       if(FindVtkViewFrame(myStudy,myStudyFrame)){
158         myViewFrame->RemoveActor(myPreviewActor);
159       }
160       myPreviewActor->Delete();
161
162       myMapper->RemoveAllInputs();
163       myMapper->Delete();
164
165       myGrid->Delete();
166     }
167
168   };
169
170 }
171
172 //=================================================================================
173 // class    : SMESHGUI_AddMeshElementDlg()
174 // purpose  : 
175 //=================================================================================
176 SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( QWidget* parent, const char* name,
177                                                        SALOME_Selection* Sel, 
178                                                        SMDSAbs_ElementType ElementType, int nbNodes,
179                                                        bool modal, WFlags fl )
180     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu |
181                Qt::WDestructiveClose)
182 {
183   mySimulation = new SMESH::TElementSimulation(SMESH::GetActiveStudy());
184
185   // verify nb nodes and type
186   myNbNodes = nbNodes;
187   myElementType = ElementType;
188   switch ( ElementType ) {
189   case SMDSAbs_Face:
190     if ( myNbNodes != 3 && myNbNodes != 4 )
191       myNbNodes = 3;
192     break;
193   case SMDSAbs_Volume:
194     if ( myNbNodes != 4 && myNbNodes != 8 ) //(nbNodes < 4 || nbNodes > 8 || nbNodes == 7)
195       myNbNodes = 4;
196     break;
197   default:
198     myElementType = SMDSAbs_Edge;
199     myNbNodes = 2;
200   }
201
202   QString elemName;
203   switch ( myNbNodes ) {
204   case 2: elemName = "EDGE"; break;
205   case 3: elemName = "TRIANGLE"; break;
206   case 4: elemName =
207     myElementType == SMDSAbs_Face ? elemName = "QUADRANGLE" : elemName = "TETRAS"; break;
208 //   case 5:
209 //   case 6:
210   default: // 8
211     elemName = "HEXAS";
212   }
213   QString iconName      = tr( QString("ICON_DLG_%1").arg(elemName) );
214   QString buttonGrTitle = tr( QString("SMESH_%1").arg(elemName) );
215   QString caption       = tr( QString("SMESH_ADD_%1_TITLE").arg(elemName) );
216   QString grBoxTitle    = tr( QString("SMESH_ADD_%1").arg(elemName) );
217     
218   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", iconName ));
219   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr("ICON_SELECT")));
220
221   if ( !name )
222     setName( "SMESHGUI_AddMeshElementDlg" );
223   resize( 303, 185 ); 
224   setCaption( caption );
225
226   setSizeGripEnabled( TRUE );
227   SMESHGUI_AddMeshElementDlgLayout = new QGridLayout( this ); 
228   SMESHGUI_AddMeshElementDlgLayout->setSpacing( 6 );
229   SMESHGUI_AddMeshElementDlgLayout->setMargin( 11 );
230
231   /***************************************************************/
232   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
233   GroupConstructors->setTitle( buttonGrTitle );
234   
235   GroupConstructors->setExclusive( TRUE );
236   GroupConstructors->setColumnLayout(0, Qt::Vertical );
237   GroupConstructors->layout()->setSpacing( 0 );
238   GroupConstructors->layout()->setMargin( 0 );
239   GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
240   GroupConstructorsLayout->setAlignment( Qt::AlignTop );
241   GroupConstructorsLayout->setSpacing( 6 );
242   GroupConstructorsLayout->setMargin( 11 );
243   Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
244   Constructor1->setText( tr( ""  ) );
245   Constructor1->setPixmap( image0 );
246   Constructor1->setChecked( TRUE );
247   Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
248   Constructor1->setMinimumSize( QSize( 50, 0 ) );
249   GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
250   QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
251   GroupConstructorsLayout->addItem( spacer, 0, 1 );
252   SMESHGUI_AddMeshElementDlgLayout->addWidget( GroupConstructors, 0, 0 );
253     
254   /***************************************************************/
255   GroupButtons = new QGroupBox( this, "GroupButtons" );
256   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
257   GroupButtons->setTitle( tr( ""  ) );
258   GroupButtons->setColumnLayout(0, Qt::Vertical );
259   GroupButtons->layout()->setSpacing( 0 );
260   GroupButtons->layout()->setMargin( 0 );
261   GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
262   GroupButtonsLayout->setAlignment( Qt::AlignTop );
263   GroupButtonsLayout->setSpacing( 6 );
264   GroupButtonsLayout->setMargin( 11 );
265   buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
266   buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
267   buttonCancel->setAutoDefault( TRUE );
268   GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
269   buttonApply = new QPushButton( GroupButtons, "buttonApply" );
270   buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
271   buttonApply->setAutoDefault( TRUE );
272   GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
273   QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
274   GroupButtonsLayout->addItem( spacer_9, 0, 2 );
275   buttonOk = new QPushButton( GroupButtons, "buttonOk" );
276   buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
277   buttonOk->setAutoDefault( TRUE );
278   buttonOk->setDefault( TRUE );
279   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
280   SMESHGUI_AddMeshElementDlgLayout->addWidget( GroupButtons, 2, 0 );
281
282   /***************************************************************/
283   GroupC1 = new QGroupBox( this, "GroupC1" );
284   GroupC1->setTitle( grBoxTitle );
285
286   GroupC1->setMinimumSize( QSize( 0, 0 ) );
287   GroupC1->setFrameShape( QGroupBox::Box );
288   GroupC1->setFrameShadow( QGroupBox::Sunken );
289   GroupC1->setColumnLayout(0, Qt::Vertical );
290   GroupC1->layout()->setSpacing( 0 );
291   GroupC1->layout()->setMargin( 0 );
292   GroupC1Layout = new QGridLayout( GroupC1->layout() );
293   GroupC1Layout->setAlignment( Qt::AlignTop );
294   GroupC1Layout->setSpacing( 6 );
295   GroupC1Layout->setMargin( 11 );
296   TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
297   TextLabelC1A1->setText( tr( "SMESH_ID_NODES"  ) );
298   TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
299   TextLabelC1A1->setFrameShape( QLabel::NoFrame );
300   TextLabelC1A1->setFrameShadow( QLabel::Plain );
301   GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
302   SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
303   SelectButtonC1A1->setText( tr( ""  ) );
304   SelectButtonC1A1->setPixmap( image1 );
305   SelectButtonC1A1->setToggleButton( FALSE );
306   GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
307   LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
308 //  LineEditC1A1->setReadOnly( TRUE );
309   LineEditC1A1->setValidator( new SMESHGUI_IdValidator( this, "validator", myNbNodes ));
310   GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
311
312   if ( myElementType == SMDSAbs_Face ) {
313     Reverse = new QCheckBox( GroupC1, "Reverse" );
314     Reverse->setText( tr( "SMESH_REVERSE"  ) );
315     GroupC1Layout->addWidget( Reverse, 1, 0 );
316   }
317   else
318     Reverse = 0;
319
320   SMESHGUI_AddMeshElementDlgLayout->addWidget( GroupC1, 1, 0 );
321
322   Init(Sel) ; /* Initialisations */
323 }
324
325 //=================================================================================
326 // function : ~SMESHGUI_AddMeshElementDlg()
327 // purpose  : Destroys the object and frees any allocated resources
328 //=================================================================================
329 SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg()
330 {
331     // no need to delete child widgets, Qt does it all for us
332   delete mySimulation;
333 }
334
335
336 //=================================================================================
337 // function : Init()
338 // purpose  :
339 //=================================================================================
340 void SMESHGUI_AddMeshElementDlg::Init( SALOME_Selection* Sel )
341 {
342
343   GroupC1->show();
344   Constructor1->setChecked( TRUE );
345   myEditCurrentArgument = LineEditC1A1 ;        
346   mySelection = Sel;  
347   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
348   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
349
350   myOkNodes = false ;
351   myActor = 0;
352
353   /* signals and slots connections */
354   connect(buttonOk, SIGNAL( clicked() ),     SLOT( ClickOnOk() ) );
355   connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) ) ;
356   connect(buttonApply, SIGNAL( clicked() ),  SLOT(ClickOnApply() ) );
357
358   connect(SelectButtonC1A1, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) ) ;
359   connect(LineEditC1A1, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
360   connect(mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), SLOT( DeactivateActiveDialog()));
361   connect(mySelection, SIGNAL( currentSelectionChanged() ), SLOT( SelectionIntoArgument() ) );
362   /* to close dialog if study frame change */
363   connect( mySMESHGUI, SIGNAL ( SignalStudyFrameChanged() ), SLOT( ClickOnCancel() ) ) ;
364
365   if ( Reverse )
366     connect( Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)) );
367
368   /* Move widget on the botton right corner of main widget */
369   int x, y ;
370   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
371   this->move( x, y ) ;
372   this->show() ; /* displays Dialog */
373
374   // set selection mode
375   SMESH::SetPointRepresentation(true);
376   QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
377
378   SelectionIntoArgument();
379
380   myBusy = false;
381 }
382
383 //=================================================================================
384 // function : ClickOnApply()
385 // purpose  :
386 //=================================================================================
387 void SMESHGUI_AddMeshElementDlg::ClickOnApply()
388 {
389   if ( myOkNodes && !mySMESHGUI->ActiveStudyLocked() ) {
390
391     myBusy = true;
392     SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
393     anArrayOfIdeces->length( myNbNodes );
394     bool reverse = ( Reverse && Reverse->isChecked() );
395     QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
396     for ( int i = 0; i < aListId.count(); i++ )
397       if ( reverse )
398         anArrayOfIdeces[i] = aListId[ myNbNodes - i - 1 ].toInt();
399       else
400         anArrayOfIdeces[i] = aListId[ i ].toInt();
401
402     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
403     switch ( myElementType ) {
404     case SMDSAbs_Edge:
405       aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
406     case SMDSAbs_Face:
407       aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
408     case SMDSAbs_Volume:
409       aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
410     default:;
411     }
412     
413     mySelection->ClearIObjects();
414     mySelection->AddIObject( myActor->getIO(), false );
415
416     SMESH::UpdateView();
417     mySimulation->SetVisibility(false);
418
419     buttonOk->setEnabled( false );
420     buttonApply->setEnabled( false );
421
422     myEditCurrentArgument->setText("");
423
424     myBusy = false;
425   }
426 }
427
428 //=================================================================================
429 // function : ClickOnOk()
430 // purpose  :
431 //=================================================================================
432 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
433 {
434   this->ClickOnApply() ;
435   this->ClickOnCancel() ;
436   return ;
437 }
438
439 //=================================================================================
440 // function : ClickOnCancel()
441 // purpose  :
442 //=================================================================================
443 void SMESHGUI_AddMeshElementDlg::ClickOnCancel()
444 {
445   mySelection->ClearIObjects();
446   mySimulation->SetVisibility(false);
447   SMESH::SetPointRepresentation(false);
448   QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
449   disconnect( mySelection, 0, this, 0 );
450   mySMESHGUI->ResetState() ;
451   reject() ;
452   return ;
453 }
454
455 //=======================================================================
456 //function : onTextChange
457 //purpose  : 
458 //=======================================================================
459
460 void SMESHGUI_AddMeshElementDlg::onTextChange(const QString& theNewText)
461 {
462   if ( myBusy ) return;
463   myBusy = true;
464
465   myOkNodes = false;
466
467   buttonOk->setEnabled( false );
468   buttonApply->setEnabled( false );
469
470   mySimulation->SetVisibility(false);
471
472   // hilight entered nodes
473   SMDS_Mesh* aMesh = 0;
474   if ( myActor )
475     aMesh = myActor->GetObject()->GetMesh();
476   if ( aMesh ) {
477
478     mySelection->ClearIObjects();
479     mySelection->AddIObject( myActor->getIO() );
480
481     QStringList aListId = QStringList::split( " ", theNewText, false);
482     bool allOk = true;
483     for ( int i = 0; i < aListId.count(); i++ ) {
484       const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
485       if ( n ) {
486         if ( mySelection->IsIndexSelected( myActor->getIO(), n->GetID() ))
487           allOk = false;
488         else
489           mySelection->AddOrRemoveIndex (myActor->getIO(), n->GetID(), true);
490       }
491       else
492         allOk = false;
493     }
494     myOkNodes = (allOk && myNbNodes == aListId.count() );
495
496     if ( myOkNodes ) {
497       buttonOk->setEnabled( true );
498       buttonApply->setEnabled( true );
499       displaySimulation();
500     }
501   }
502
503   myBusy = false;
504 }
505
506 //=================================================================================
507 // function : SelectionIntoArgument()
508 // purpose  : Called when selection has changed
509 //=================================================================================
510 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
511 {
512   if ( myBusy ) return;
513
514   // clear
515
516   myOkNodes = false;
517   myActor = 0;
518
519   myBusy = true;
520   myEditCurrentArgument->setText( "" );
521   myBusy = false;
522
523   if ( !GroupButtons->isEnabled() ) // inactive
524     return;
525
526   buttonOk->setEnabled( false );
527   buttonApply->setEnabled( false );
528
529   mySimulation->SetVisibility(false);
530 //  SMESH::SetPointRepresentation(true);
531
532   // get selected mesh
533
534   int nbSel = mySelection->IObjectCount();
535   if(nbSel != 1)
536     return;
537
538   myMesh = SMESH::GetMeshByIO( mySelection->firstIObject() );
539   if ( myMesh->_is_nil() )
540     return;
541
542   myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
543   if ( !myActor )
544     return;
545
546   // get selected nodes
547
548   QString aString = "";
549   int nbNodes = SMESH::GetNameOfSelectedNodes(mySelection, aString) ;
550   myBusy = true;
551   myEditCurrentArgument->setText( aString );
552   myBusy = false;
553   if ( myNbNodes != nbNodes )
554     return;
555
556   // OK
557
558   myOkNodes = true;
559
560   buttonOk->setEnabled( true );
561   buttonApply->setEnabled( true );
562
563   displaySimulation();
564 }
565
566 //=======================================================================
567 //function : displaySimulation
568 //purpose  : 
569 //=======================================================================
570
571 void SMESHGUI_AddMeshElementDlg::displaySimulation()
572 {
573   if ( myOkNodes && GroupButtons->isEnabled() )
574   {
575     SMESH::TElementSimulation::TVTKIds anIds;
576     QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
577     for ( int i = 0; i < aListId.count(); i++ )
578       anIds.push_back( myActor->GetObject()->GetNodeVTKId( aListId[ i ].toInt() ));
579
580     if ( Reverse && Reverse->isChecked() )
581       anIds.reverse();
582
583     vtkIdType aType = 0;
584     switch ( myNbNodes ) {
585     case 2: aType = VTK_LINE; break;
586     case 3: aType = VTK_TRIANGLE; break;
587     case 4: aType = myElementType == SMDSAbs_Face ? VTK_QUAD : VTK_TETRA; break;
588     case 8: aType = VTK_HEXAHEDRON; break;
589     default: return;
590     }
591       
592     mySimulation->SetPosition(myActor,aType,anIds);
593   }
594 }
595
596
597 //=================================================================================
598 // function : SetEditCurrentArgument()
599 // purpose  :
600 //=================================================================================
601 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
602 {
603   QPushButton* send = (QPushButton*)sender();
604   if(send == SelectButtonC1A1) {
605     LineEditC1A1->setFocus() ;
606     myEditCurrentArgument = LineEditC1A1;
607   }
608   SelectionIntoArgument() ;
609 }
610
611 //=================================================================================
612 // function : DeactivateActiveDialog()
613 // purpose  :
614 //=================================================================================
615 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
616 {
617   if ( GroupConstructors->isEnabled() ) {  
618     GroupConstructors->setEnabled(false) ;
619     GroupC1->setEnabled(false) ;
620     GroupButtons->setEnabled(false) ;
621     mySimulation->SetVisibility(false);
622     mySMESHGUI->ResetState() ;    
623     mySMESHGUI->SetActiveDialogBox(0) ;
624   }
625   return ;
626 }
627
628
629 //=================================================================================
630 // function : ActivateThisDialog()
631 // purpose  :
632 //=================================================================================
633 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
634 {
635   /* Emit a signal to deactivate the active dialog */
636   mySMESHGUI->EmitSignalDeactivateDialog() ;   
637
638   GroupConstructors->setEnabled(true) ;
639   GroupC1->setEnabled(true) ;
640   GroupButtons->setEnabled(true) ;
641
642   SMESH::SetPointRepresentation(true);
643   QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
644
645   SelectionIntoArgument();
646 }
647
648 //=================================================================================
649 // function : enterEvent()
650 // purpose  :
651 //=================================================================================
652 void SMESHGUI_AddMeshElementDlg::enterEvent(QEvent* e)
653 {
654   if ( GroupConstructors->isEnabled() )
655     return ;  
656   ActivateThisDialog() ;
657   return ;
658 }
659
660
661 //=================================================================================
662 // function : closeEvent()
663 // purpose  :
664 //=================================================================================
665 void SMESHGUI_AddMeshElementDlg::closeEvent( QCloseEvent* e )
666 {
667   /* same than click on cancel button */
668   this->ClickOnCancel() ;
669   return ;
670 }
671 //=======================================================================
672 //function : hideEvent
673 //purpose  : caused by ESC key
674 //=======================================================================
675
676 void SMESHGUI_AddMeshElementDlg::hideEvent ( QHideEvent * e )
677 {
678   if ( !isMinimized() )
679     ClickOnCancel() ;
680 }
681
682 //=======================================================================
683 //function : CheckBox
684 //purpose  : 
685 //=======================================================================
686
687 void SMESHGUI_AddMeshElementDlg::CheckBox( int state )
688 {
689   if ( !myOkNodes )
690     return;
691   
692   if ( state >= 0 ) {
693     mySimulation->SetVisibility(false);
694     displaySimulation();
695   }
696 }