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