Salome HOME
Porting SMESH module to Qt 4
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : SMESHGUI_AddMeshElementDlg.cxx
23 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
24 //
25
26 //  SMESH includes
27 #include "SMESHGUI_AddMeshElementDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
34
35 #include <SMESH_Actor.h>
36 #include <SMESH_ActorUtils.h>
37 #include <SMDS_Mesh.hxx>
38
39 // SALOME GUI inclues
40 #include <SUIT_Desktop.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_MessageBox.h>
44 #include <SUIT_ViewManager.h>
45 #include <LightApp_SelectionMgr.h>
46 #include <SALOME_ListIO.hxx>
47 #include <SalomeApp_Application.h>
48 #include <SVTK_ViewModel.h>
49 #include <SVTK_ViewWindow.h>
50
51 // IDL incldues
52 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
53
54 // OCCT includes
55 #include <TColStd_MapOfInteger.hxx>
56
57 // VTK includes
58 #include <vtkCell.h>
59 #include <vtkIdList.h>
60 #include <vtkUnstructuredGrid.h>
61 #include <vtkDataSetMapper.h>
62 #include <vtkProperty.h>
63
64 // Qt includes
65 #include <QGroupBox>
66 #include <QLabel>
67 #include <QLineEdit>
68 #include <QPushButton>
69 #include <QRadioButton>
70 #include <QHBoxLayout>
71 #include <QVBoxLayout>
72 #include <QGridLayout>
73 #include <qvariant.h>
74 #include <QCheckBox>
75 #include <QKeyEvent>
76
77 #define SPACING 6
78 #define MARGIN  11
79
80 namespace SMESH
81 {
82   class TElementSimulation
83   {
84     SalomeApp_Application* myApplication;
85     SUIT_ViewWindow* myViewWindow;
86     SVTK_ViewWindow* myVTKViewWindow;
87
88     SALOME_Actor* myPreviewActor;
89     vtkDataSetMapper* myMapper;
90     vtkUnstructuredGrid* myGrid;
91
92   public:
93     TElementSimulation (SalomeApp_Application* theApplication)
94     {
95       myApplication = theApplication;
96       SUIT_ViewManager* mgr = theApplication->activeViewManager();
97       if (!mgr) return;
98       myViewWindow = mgr->getActiveView();
99       myVTKViewWindow = GetVtkViewWindow(myViewWindow);
100
101       myGrid = vtkUnstructuredGrid::New();
102
103       // Create and display actor
104       myMapper = vtkDataSetMapper::New();
105       myMapper->SetInput(myGrid);
106
107       myPreviewActor = SALOME_Actor::New();
108       myPreviewActor->PickableOff();
109       myPreviewActor->VisibilityOff();
110       myPreviewActor->SetMapper(myMapper);
111
112       vtkFloatingPointType anRGB[3];
113       vtkProperty* aProp = vtkProperty::New();
114       GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
115       aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
116       myPreviewActor->SetProperty( aProp );
117       aProp->Delete();
118
119       vtkProperty* aBackProp = vtkProperty::New();
120       GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
121       aBackProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
122       myPreviewActor->SetBackfaceProperty( aBackProp );
123       aBackProp->Delete();
124
125       myVTKViewWindow->AddActor(myPreviewActor);
126     }
127
128     typedef std::vector<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       const int* aConn = NULL;
137       switch (theType) {
138       case VTK_TETRA:
139         {
140           static int anIds[] = {0,2,1,3};
141           aConn = anIds;
142           break;
143         }
144       case VTK_PYRAMID:
145         {
146           static int anIds[] = {0,3,2,1,4};
147           aConn = anIds;
148           break;
149         }
150       case VTK_HEXAHEDRON:
151         {
152           static int anIds[] = {0,3,2,1,4,7,6,5};
153           aConn = anIds;
154           break;
155         }
156       }
157
158       myGrid->Reset();
159       vtkIdList *anIds = vtkIdList::New();
160
161       if(aConn)
162         for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
163           anIds->InsertId(i,theIds[aConn[i]]);
164       else
165         for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
166           anIds->InsertId(i,theIds[i]);
167
168       myGrid->InsertNextCell(theType,anIds);
169       anIds->Delete();
170
171       myGrid->Modified();
172
173       SetVisibility(true);
174     }
175
176
177     void SetVisibility (bool theVisibility)
178     {
179       myPreviewActor->SetVisibility(theVisibility);
180       RepaintCurrentView();
181     }
182
183
184     ~TElementSimulation()
185     {
186       if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
187         myVTKViewWindow->RemoveActor(myPreviewActor);
188       }
189       myPreviewActor->Delete();
190
191       myMapper->RemoveAllInputs();
192       myMapper->Delete();
193
194       myGrid->Delete();
195     }
196   };
197 }
198
199 //=================================================================================
200 // function : SMESHGUI_AddMeshElementDlg()
201 // purpose  : constructor
202 //=================================================================================
203 SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule,
204                                                         SMDSAbs_ElementType ElementType, 
205                                                         int nbNodes )
206   : QDialog( SMESH::GetDesktop( theModule ) ),
207     mySMESHGUI( theModule ),
208     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
209 {
210   setModal( false );
211   setAttribute( Qt::WA_DeleteOnClose, true );
212
213   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
214     (SUIT_Session::session()->activeApplication());
215   myIsPoly = false;
216   mySimulation = new SMESH::TElementSimulation (anApp);
217   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
218
219   // verify nb nodes and type
220   myNbNodes = nbNodes;
221   myElementType = ElementType;
222   switch (ElementType) {
223   case SMDSAbs_Face:
224     //     if (myNbNodes != 3 && myNbNodes != 4)
225     //       myNbNodes = 3;
226     //     break;
227   case SMDSAbs_Volume:
228     //     if (myNbNodes != 4 && myNbNodes != 8) //(nbNodes < 4 || nbNodes > 8 || nbNodes == 7)
229     //       myNbNodes = 4;
230     break;
231   default:
232     myElementType = SMDSAbs_Edge;
233     myNbNodes = 2;
234   }
235
236   QString elemName;
237   if (myNbNodes == 2) {
238     elemName = "EDGE";
239     myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor";
240   }
241   else if (myNbNodes == 3) {
242     elemName = "TRIANGLE";
243     myHelpFileName = "adding_nodes_and_elements_page.html#adding_triangles_anchor";
244   }
245   else if (myNbNodes == 4)
246     if (myElementType == SMDSAbs_Face) {
247       elemName = "QUADRANGLE";
248       myHelpFileName = "adding_nodes_and_elements_page.html#adding_quadrangles_anchor";
249     }
250     else {
251       elemName = "TETRAS";
252       myHelpFileName = "adding_nodes_and_elements_page.html#adding_tetrahedrons_anchor";
253     }
254   else if (myNbNodes == 8) {
255     elemName = "HEXAS";
256     myHelpFileName = "adding_nodes_and_elements_page.html#adding_hexahedrons_anchor";
257   }
258   else if (myElementType == SMDSAbs_Face) {
259     elemName = "POLYGON";
260     myIsPoly = true;
261     myHelpFileName = "adding_nodes_and_elements_page.html#adding_polygons_anchor";
262   }
263   else if (myElementType == SMDSAbs_Volume) {
264     myHelpFileName = "adding_nodes_and_elements_page.html#adding_polyhedrons_anchor";
265   }
266   
267   QString iconName      = tr(QString("ICON_DLG_%1").arg(elemName).toLatin1().data());
268   QString buttonGrTitle = tr(QString("SMESH_%1").arg(elemName).toLatin1().data());
269   QString caption       = tr(QString("SMESH_ADD_%1_TITLE").arg(elemName).toLatin1().data());
270   QString grBoxTitle    = tr(QString("SMESH_ADD_%1").arg(elemName).toLatin1().data());
271
272   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
273   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
274
275   setWindowTitle(caption);
276   setSizeGripEnabled(true);
277
278   QVBoxLayout* aTopLayout = new QVBoxLayout(this);
279   aTopLayout->setSpacing(SPACING);
280   aTopLayout->setMargin(MARGIN);
281
282   /***************************************************************/
283   GroupConstructors = new QGroupBox(buttonGrTitle, this);
284   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
285   GroupConstructorsLayout->setSpacing(SPACING);
286   GroupConstructorsLayout->setMargin(MARGIN);
287
288   Constructor1 = new QRadioButton(GroupConstructors);
289   Constructor1->setIcon(image0);
290   Constructor1->setChecked(true);
291
292   GroupConstructorsLayout->addWidget(Constructor1);
293   GroupConstructorsLayout->addStretch();
294
295   /***************************************************************/
296   GroupC1 = new QGroupBox(grBoxTitle, this);
297   QGridLayout* GroupC1Layout = new QGridLayout(GroupC1);
298   GroupC1Layout->setSpacing(SPACING);
299   GroupC1Layout->setMargin(MARGIN);
300
301   TextLabelC1A1 = new QLabel(tr("SMESH_ID_NODES"), GroupC1);
302   SelectButtonC1A1 = new QPushButton(GroupC1);
303   SelectButtonC1A1->setIcon(image1);
304   LineEditC1A1 = new QLineEdit(GroupC1);
305   //  LineEditC1A1->setReadOnly(true);
306   if (!myIsPoly)
307     LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this, myNbNodes));
308
309   Reverse = myElementType == SMDSAbs_Face ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
310
311   GroupC1Layout->addWidget(TextLabelC1A1,    0, 0);
312   GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
313   GroupC1Layout->addWidget(LineEditC1A1,     0, 2);
314   if ( Reverse ) GroupC1Layout->addWidget(Reverse, 1, 0, 1, 3);
315
316   /***************************************************************/
317   GroupButtons = new QGroupBox(this);
318   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
319   GroupButtonsLayout->setSpacing(SPACING);
320   GroupButtonsLayout->setMargin(MARGIN);
321
322   buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
323   buttonOk->setAutoDefault(true);
324   buttonOk->setDefault(true);
325   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
326   buttonApply->setAutoDefault(true);
327   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
328   buttonCancel->setAutoDefault(true);
329   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
330   buttonHelp->setAutoDefault(true);
331
332   GroupButtonsLayout->addWidget(buttonOk);
333   GroupButtonsLayout->addSpacing(10);
334   GroupButtonsLayout->addWidget(buttonApply);
335   GroupButtonsLayout->addSpacing(10);
336   GroupButtonsLayout->addStretch();
337   GroupButtonsLayout->addWidget(buttonCancel);
338   GroupButtonsLayout->addWidget(buttonHelp);
339
340   /***************************************************************/
341   aTopLayout->addWidget(GroupConstructors);
342   aTopLayout->addWidget(GroupC1);
343   aTopLayout->addWidget(GroupButtons);
344
345   Init(); /* Initialisations */
346 }
347
348 //=================================================================================
349 // function : ~SMESHGUI_AddMeshElementDlg()
350 // purpose  : Destroys the object and frees any allocated resources
351 //=================================================================================
352 SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg()
353 {
354   delete mySimulation;
355 }
356
357 //=================================================================================
358 // function : Init()
359 // purpose  :
360 //=================================================================================
361 void SMESHGUI_AddMeshElementDlg::Init()
362 {
363   GroupC1->show();
364   Constructor1->setChecked(true);
365   myEditCurrentArgument = LineEditC1A1;
366   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
367
368   myNbOkNodes = 0;
369   myActor = 0;
370
371   /* signals and slots connections */
372   connect(buttonOk, SIGNAL(clicked()),     SLOT(ClickOnOk()));
373   connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
374   connect(buttonApply, SIGNAL(clicked()),  SLOT(ClickOnApply()));
375   connect(buttonHelp, SIGNAL(clicked()),   SLOT(ClickOnHelp()));
376
377   connect(SelectButtonC1A1, SIGNAL(clicked()), SLOT(SetEditCurrentArgument()));
378   connect(LineEditC1A1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
379   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
380   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
381   /* to close dialog if study frame change */
382   connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
383
384   if (Reverse)
385     connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)));
386
387   // set selection mode
388   SMESH::SetPointRepresentation(true);
389
390   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
391     aViewWindow->SetSelectionMode( NodeSelection );
392
393   myBusy = false;
394
395   SelectionIntoArgument();
396 }
397
398 //=================================================================================
399 // function : ClickOnApply()
400 // purpose  :
401 //=================================================================================
402 void SMESHGUI_AddMeshElementDlg::ClickOnApply()
403 {
404   if (myNbOkNodes && !mySMESHGUI->isActiveStudyLocked()) {
405     myBusy = true;
406     SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
407     anArrayOfIdeces->length(myNbNodes);
408     bool reverse = (Reverse && Reverse->isChecked());
409     QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
410     for (int i = 0; i < aListId.count(); i++)
411       if (reverse)
412         anArrayOfIdeces[i] = aListId[ myNbNodes - i - 1 ].toInt();
413       else
414         anArrayOfIdeces[i] = aListId[ i ].toInt();
415
416     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
417     switch (myElementType) {
418     case SMDSAbs_Edge:
419       aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
420     case SMDSAbs_Face:{
421       if(myIsPoly)
422         aMeshEditor->AddPolygonalFace(anArrayOfIdeces.inout());
423       else
424         aMeshEditor->AddFace(anArrayOfIdeces.inout());
425       break;
426
427     }
428     case SMDSAbs_Volume:
429       aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
430     default:;
431     }
432
433     SALOME_ListIO aList; aList.Append( myActor->getIO() );
434     mySelector->ClearIndex();
435     mySelectionMgr->setSelectedObjects( aList, false );
436
437     SMESH::UpdateView();
438     mySimulation->SetVisibility(false);
439
440     buttonOk->setEnabled(false);
441     buttonApply->setEnabled(false);
442
443     myEditCurrentArgument->setText("");
444
445     myBusy = false;
446   }
447 }
448
449 //=================================================================================
450 // function : ClickOnOk()
451 // purpose  :
452 //=================================================================================
453 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
454 {
455   ClickOnApply();
456   ClickOnCancel();
457 }
458
459 //=================================================================================
460 // function : ClickOnCancel()
461 // purpose  :
462 //=================================================================================
463 void SMESHGUI_AddMeshElementDlg::ClickOnCancel()
464 {
465   //mySelectionMgr->clearSelected();
466   mySimulation->SetVisibility(false);
467   SMESH::SetPointRepresentation(false);
468   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
469     aViewWindow->SetSelectionMode( ActorSelection );
470   disconnect(mySelectionMgr, 0, this, 0);
471   mySMESHGUI->ResetState();
472   reject();
473 }
474
475 //=================================================================================
476 // function : ClickOnHelp()
477 // purpose  :
478 //=================================================================================
479 void SMESHGUI_AddMeshElementDlg::ClickOnHelp()
480 {
481   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
482   if (app) 
483     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
484   else {
485     QString platform;
486 #ifdef WIN32
487     platform = "winapplication";
488 #else
489     platform = "application";
490 #endif
491     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
492                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
493                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
494                                                                  platform)).
495                              arg(myHelpFileName));
496   }
497 }
498
499 //=================================================================================
500 // function : onTextChange()
501 // purpose  :
502 //=================================================================================
503 void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
504 {
505   if (myBusy) return;
506   myBusy = true;
507
508   myNbOkNodes = 0;
509
510   buttonOk->setEnabled(false);
511   buttonApply->setEnabled(false);
512
513   mySimulation->SetVisibility(false);
514
515   // hilight entered nodes
516   SMDS_Mesh* aMesh = 0;
517   if (myActor)
518     aMesh = myActor->GetObject()->GetMesh();
519
520   if (aMesh) {
521     TColStd_MapOfInteger newIndices;
522     
523     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
524     bool allOk = true;
525     for (int i = 0; i < aListId.count(); i++) {
526       if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
527         {
528           newIndices.Add( n->GetID() );
529           myNbOkNodes++;
530         }
531       else
532         allOk = false;  
533     }
534     
535     mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
536     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
537       aViewWindow->highlight( myActor->getIO(), true, true );
538     
539     myNbOkNodes = ( allOk && myNbNodes == aListId.count() );
540     
541     if (myIsPoly)
542       {
543         if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
544           myNbOkNodes = 0;
545         else
546           myNbOkNodes = aListId.count();
547       }
548   }
549   
550   if(myNbOkNodes) {
551     buttonOk->setEnabled(true);
552     buttonApply->setEnabled(true);
553     displaySimulation();
554   }
555   
556   myBusy = false;
557 }
558
559 //=================================================================================
560 // function : SelectionIntoArgument()
561 // purpose  : Called when selection has changed
562 //=================================================================================
563 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
564 {
565   if (myBusy) return;
566
567   // clear
568   myNbOkNodes = 0;
569   myActor = 0;
570
571   myBusy = true;
572   myEditCurrentArgument->setText("");
573   myBusy = false;
574
575   if (!GroupButtons->isEnabled()) // inactive
576     return;
577
578   buttonOk->setEnabled(false);
579   buttonApply->setEnabled(false);
580
581   mySimulation->SetVisibility(false);
582   //  SMESH::SetPointRepresentation(true);
583
584   // get selected mesh
585   SALOME_ListIO aList;
586   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
587
588   if (aList.Extent() != 1)
589     return;
590
591   Handle(SALOME_InteractiveObject) anIO = aList.First();
592   myMesh = SMESH::GetMeshByIO(anIO);
593   if (myMesh->_is_nil())
594     return;
595
596   myActor = SMESH::FindActorByEntry(anIO->getEntry());
597   if (!myActor)
598     return;
599
600   // get selected nodes
601   QString aString = "";
602   int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
603   myBusy = true;
604   myEditCurrentArgument->setText(aString);
605   myBusy = false;
606   if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
607     myNbNodes = nbNodes;
608   } else if (myNbNodes != nbNodes) {
609     return;
610   }
611
612   // OK
613   myNbOkNodes = nbNodes;
614
615   buttonOk->setEnabled(true);
616   buttonApply->setEnabled(true);
617
618   displaySimulation();
619 }
620
621 //=================================================================================
622 // function : displaySimulation()
623 // purpose  :
624 //=================================================================================
625 void SMESHGUI_AddMeshElementDlg::displaySimulation()
626 {
627   if (myNbOkNodes && GroupButtons->isEnabled()) {
628     SMESH::TElementSimulation::TVTKIds anIds;
629     QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
630     for (int i = 0; i < aListId.count(); i++)
631       anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt()));
632
633     if (Reverse && Reverse->isChecked())
634       reverse(anIds.begin(),anIds.end());
635
636     vtkIdType aType = 0;
637     if (myIsPoly)
638       switch ( myElementType ) {
639       case SMDSAbs_Face  : aType = VTK_POLYGON; break;
640       default: return;
641       }
642     else {
643       switch (myNbNodes) {
644       case 2: aType = VTK_LINE; break;
645       case 3: aType = VTK_TRIANGLE; break;
646       case 4: aType = myElementType == SMDSAbs_Face ? VTK_QUAD : VTK_TETRA; break;
647       case 8: aType = VTK_HEXAHEDRON; break;
648       default: return;
649       }
650     }
651
652     mySimulation->SetPosition(myActor,aType,anIds);
653     SMESH::UpdateView();
654   }
655 }
656
657 //=================================================================================
658 // function : SetEditCurrentArgument()
659 // purpose  :
660 //=================================================================================
661 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
662 {
663   QPushButton* send = (QPushButton*)sender();
664   if (send == SelectButtonC1A1) {
665     LineEditC1A1->setFocus();
666     myEditCurrentArgument = LineEditC1A1;
667   }
668   SelectionIntoArgument();
669 }
670
671 //=================================================================================
672 // function : DeactivateActiveDialog()
673 // purpose  :
674 //=================================================================================
675 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
676 {
677   if (GroupConstructors->isEnabled()) {
678     GroupConstructors->setEnabled(false);
679     GroupC1->setEnabled(false);
680     GroupButtons->setEnabled(false);
681     mySimulation->SetVisibility(false);
682     mySMESHGUI->ResetState();
683     mySMESHGUI->SetActiveDialogBox(0);
684   }
685 }
686
687 //=================================================================================
688 // function : ActivateThisDialog()
689 // purpose  :
690 //=================================================================================
691 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
692 {
693   /* Emit a signal to deactivate the active dialog */
694   mySMESHGUI->EmitSignalDeactivateDialog();
695
696   GroupConstructors->setEnabled(true);
697   GroupC1->setEnabled(true);
698   GroupButtons->setEnabled(true);
699
700   SMESH::SetPointRepresentation(true);
701
702   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
703     aViewWindow->SetSelectionMode( NodeSelection );
704   SelectionIntoArgument();
705 }
706
707 //=================================================================================
708 // function : enterEvent()
709 // purpose  :
710 //=================================================================================
711 void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
712 {
713   if (GroupConstructors->isEnabled())
714     return;
715   ActivateThisDialog();
716 }
717
718 //=================================================================================
719 // function : closeEvent()
720 // purpose  :
721 //=================================================================================
722 void SMESHGUI_AddMeshElementDlg::closeEvent (QCloseEvent*)
723 {
724   /* same than click on cancel button */
725   ClickOnCancel();
726 }
727
728 //=================================================================================
729 // function : hideEvent()
730 // purpose  : caused by ESC key
731 //=================================================================================
732 void SMESHGUI_AddMeshElementDlg::hideEvent (QHideEvent*)
733 {
734   if (!isMinimized())
735     ClickOnCancel();
736 }
737
738 //=================================================================================
739 // function : CheckBox()
740 // purpose  :
741 //=================================================================================
742 void SMESHGUI_AddMeshElementDlg::CheckBox (int state)
743 {
744   if (!myNbOkNodes)
745     return;
746
747   if (state >= 0) {
748     mySimulation->SetVisibility(false);
749     displaySimulation();
750   }
751 }
752
753 //=================================================================================
754 // function : keyPressEvent()
755 // purpose  :
756 //=================================================================================
757 void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
758 {
759   QDialog::keyPressEvent( e );
760   if ( e->isAccepted() )
761     return;
762   
763   if ( e->key() == Qt::Key_F1 ) {
764     e->accept();
765     ClickOnHelp();
766   }
767 }