Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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 = "adding_nodes_and_elements_page.html#adding_edges_anchor";
253   }
254   else if (myNbNodes == 3) {
255     elemName = "TRIANGLE";
256     myHelpFileName = "adding_nodes_and_elements_page.html#adding_triangles_anchor";
257   }
258   else if (myNbNodes == 4)
259     if (myElementType == SMDSAbs_Face) {
260       elemName = "QUADRANGLE";
261       myHelpFileName = "adding_nodes_and_elements_page.html#adding_quadrangles_anchor";
262     }
263     else {
264       elemName = "TETRAS";
265       myHelpFileName = "adding_nodes_and_elements_page.html#adding_tetrahedrons_anchor";
266     }
267   else if (myNbNodes == 8) {
268     elemName = "HEXAS";
269     myHelpFileName = "adding_nodes_and_elements_page.html#adding_hexahedrons_anchor";
270   }
271   else if (myElementType == SMDSAbs_Face) {
272     elemName = "POLYGON";
273     myIsPoly = true;
274     myHelpFileName = "adding_nodes_and_elements_page.html#adding_polygons_anchor";
275   }
276   else if (myElementType == SMDSAbs_Volume) {
277     myHelpFileName = "adding_nodes_and_elements_page.html#adding_polyhedrons_anchor";
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                 QString platform;
541 #ifdef WIN32
542                 platform = "winapplication";
543 #else
544                 platform = "application";
545 #endif
546     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
547                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
548                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
549                            QObject::tr("BUT_OK"));
550   }
551 }
552
553 //=================================================================================
554 // function : onTextChange()
555 // purpose  :
556 //=================================================================================
557 void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
558 {
559   if (myBusy) return;
560   myBusy = true;
561
562   myNbOkNodes = 0;
563
564   buttonOk->setEnabled(false);
565   buttonApply->setEnabled(false);
566
567   mySimulation->SetVisibility(false);
568
569   // hilight entered nodes
570   SMDS_Mesh* aMesh = 0;
571   if (myActor)
572     aMesh = myActor->GetObject()->GetMesh();
573
574   if (aMesh) {
575     TColStd_MapOfInteger newIndices;
576     
577     QStringList aListId = QStringList::split(" ", theNewText, false);
578     bool allOk = true;
579     for (int i = 0; i < aListId.count(); i++) {
580       if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
581       {
582         newIndices.Add( n->GetID() );
583         myNbOkNodes++;
584       }
585       else
586         allOk = false;  
587     }
588     
589     mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
590     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
591       aViewWindow->highlight( myActor->getIO(), true, true );
592     
593     myNbOkNodes = ( allOk && myNbNodes == aListId.count() );
594     
595     if (myIsPoly)
596       {
597         if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
598           myNbOkNodes = 0;
599         else
600           myNbOkNodes = aListId.count();
601       }
602   }
603   
604   if(myNbOkNodes) {
605     buttonOk->setEnabled(true);
606     buttonApply->setEnabled(true);
607     displaySimulation();
608   }
609   
610   myBusy = false;
611 }
612
613 //=================================================================================
614 // function : SelectionIntoArgument()
615 // purpose  : Called when selection has changed
616 //=================================================================================
617 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
618 {
619   if (myBusy) return;
620
621   // clear
622   myNbOkNodes = 0;
623   myActor = 0;
624
625   myBusy = true;
626   myEditCurrentArgument->setText("");
627   myBusy = false;
628
629   if (!GroupButtons->isEnabled()) // inactive
630     return;
631
632   buttonOk->setEnabled(false);
633   buttonApply->setEnabled(false);
634
635   mySimulation->SetVisibility(false);
636 //  SMESH::SetPointRepresentation(true);
637
638   // get selected mesh
639   SALOME_ListIO aList;
640   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
641
642   if (aList.Extent() != 1)
643     return;
644
645   Handle(SALOME_InteractiveObject) anIO = aList.First();
646   myMesh = SMESH::GetMeshByIO(anIO);
647   if (myMesh->_is_nil())
648     return;
649
650   myActor = SMESH::FindActorByEntry(anIO->getEntry());
651   if (!myActor)
652     return;
653
654   // get selected nodes
655   QString aString = "";
656   int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
657   myBusy = true;
658   myEditCurrentArgument->setText(aString);
659   myBusy = false;
660   if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
661     myNbNodes = nbNodes;
662   } else if (myNbNodes != nbNodes) {
663     return;
664   }
665
666   // OK
667   myNbOkNodes = nbNodes;
668
669   buttonOk->setEnabled(true);
670   buttonApply->setEnabled(true);
671
672   displaySimulation();
673 }
674
675 //=================================================================================
676 // function : displaySimulation()
677 // purpose  :
678 //=================================================================================
679 void SMESHGUI_AddMeshElementDlg::displaySimulation()
680 {
681   if (myNbOkNodes && GroupButtons->isEnabled()) {
682     SMESH::TElementSimulation::TVTKIds anIds;
683     QStringList aListId = QStringList::split(" ", myEditCurrentArgument->text(), false);
684     for (int i = 0; i < aListId.count(); i++)
685       anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt()));
686
687     if (Reverse && Reverse->isChecked())
688       reverse(anIds.begin(),anIds.end());
689
690     vtkIdType aType = 0;
691     if (myIsPoly)
692       switch ( myElementType ) {
693       case SMDSAbs_Face  : aType = VTK_POLYGON; break;
694       default: return;
695       }
696     else {
697       switch (myNbNodes) {
698       case 2: aType = VTK_LINE; break;
699       case 3: aType = VTK_TRIANGLE; break;
700       case 4: aType = myElementType == SMDSAbs_Face ? VTK_QUAD : VTK_TETRA; break;
701       case 8: aType = VTK_HEXAHEDRON; break;
702       default: return;
703       }
704     }
705
706     mySimulation->SetPosition(myActor,aType,anIds);
707     SMESH::UpdateView();
708   }
709 }
710
711 //=================================================================================
712 // function : SetEditCurrentArgument()
713 // purpose  :
714 //=================================================================================
715 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
716 {
717   QPushButton* send = (QPushButton*)sender();
718   if (send == SelectButtonC1A1) {
719     LineEditC1A1->setFocus();
720     myEditCurrentArgument = LineEditC1A1;
721   }
722   SelectionIntoArgument();
723 }
724
725 //=================================================================================
726 // function : DeactivateActiveDialog()
727 // purpose  :
728 //=================================================================================
729 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
730 {
731   if (GroupConstructors->isEnabled()) {
732     GroupConstructors->setEnabled(false);
733     GroupC1->setEnabled(false);
734     GroupButtons->setEnabled(false);
735     mySimulation->SetVisibility(false);
736     mySMESHGUI->ResetState();
737     mySMESHGUI->SetActiveDialogBox(0);
738   }
739 }
740
741 //=================================================================================
742 // function : ActivateThisDialog()
743 // purpose  :
744 //=================================================================================
745 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
746 {
747   /* Emit a signal to deactivate the active dialog */
748   mySMESHGUI->EmitSignalDeactivateDialog();
749
750   GroupConstructors->setEnabled(true);
751   GroupC1->setEnabled(true);
752   GroupButtons->setEnabled(true);
753
754   SMESH::SetPointRepresentation(true);
755
756   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
757     aViewWindow->SetSelectionMode( NodeSelection );
758   SelectionIntoArgument();
759 }
760
761 //=================================================================================
762 // function : enterEvent()
763 // purpose  :
764 //=================================================================================
765 void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
766 {
767   if (GroupConstructors->isEnabled())
768     return;
769   ActivateThisDialog();
770   return;
771 }
772
773 //=================================================================================
774 // function : closeEvent()
775 // purpose  :
776 //=================================================================================
777 void SMESHGUI_AddMeshElementDlg::closeEvent (QCloseEvent*)
778 {
779   /* same than click on cancel button */
780   this->ClickOnCancel();
781   return;
782 }
783
784 //=================================================================================
785 // function : hideEvent()
786 // purpose  : caused by ESC key
787 //=================================================================================
788 void SMESHGUI_AddMeshElementDlg::hideEvent (QHideEvent*)
789 {
790   if (!isMinimized())
791     ClickOnCancel();
792 }
793
794 //=================================================================================
795 // function : CheckBox()
796 // purpose  :
797 //=================================================================================
798 void SMESHGUI_AddMeshElementDlg::CheckBox (int state)
799 {
800   if (!myNbOkNodes)
801     return;
802
803   if (state >= 0) {
804     mySimulation->SetVisibility(false);
805     displaySimulation();
806   }
807 }
808
809 //=================================================================================
810 // function : keyPressEvent()
811 // purpose  :
812 //=================================================================================
813 void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
814 {
815   QDialog::keyPressEvent( e );
816   if ( e->isAccepted() )
817     return;
818   
819   if ( e->key() == Key_F1 )
820     {
821       e->accept();
822       ClickOnHelp();
823     }
824 }