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