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