Salome HOME
Merge from OCC_development_generic_2006
[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   // Move widget on the botton right corner of main widget
415   int x, y;
416   mySMESHGUI->DefineDlgPosition(this, x, y);
417   this->move(x, y);
418   this->show(); // displays Dialog
419
420   // set selection mode
421   SMESH::SetPointRepresentation(true);
422
423   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
424     aViewWindow->SetSelectionMode( NodeSelection );
425
426   myBusy = false;
427
428   SelectionIntoArgument();
429 }
430
431 //=================================================================================
432 // function : ClickOnApply()
433 // purpose  :
434 //=================================================================================
435 void SMESHGUI_AddMeshElementDlg::ClickOnApply()
436 {
437   if (myNbOkNodes && !mySMESHGUI->isActiveStudyLocked()) {
438     myBusy = true;
439     SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
440     anArrayOfIdeces->length(myNbNodes);
441     bool reverse = (Reverse && Reverse->isChecked());
442     QStringList aListId = QStringList::split(" ", myEditCurrentArgument->text(), false);
443     for (int i = 0; i < aListId.count(); i++)
444       if (reverse)
445         anArrayOfIdeces[i] = aListId[ myNbNodes - i - 1 ].toInt();
446       else
447         anArrayOfIdeces[i] = aListId[ i ].toInt();
448
449     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
450     switch (myElementType) {
451     case SMDSAbs_Edge:
452       aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
453     case SMDSAbs_Face:
454       aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
455     case SMDSAbs_Volume:
456       aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
457     default:;
458     }
459
460     SALOME_ListIO aList; aList.Append( myActor->getIO() );
461     mySelector->ClearIndex();
462     mySelectionMgr->setSelectedObjects( aList, false );
463
464     SMESH::UpdateView();
465     mySimulation->SetVisibility(false);
466
467     buttonOk->setEnabled(false);
468     buttonApply->setEnabled(false);
469
470     myEditCurrentArgument->setText("");
471
472     myBusy = false;
473   }
474 }
475
476 //=================================================================================
477 // function : ClickOnOk()
478 // purpose  :
479 //=================================================================================
480 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
481 {
482   this->ClickOnApply();
483   this->ClickOnCancel();
484   return;
485 }
486
487 //=================================================================================
488 // function : ClickOnCancel()
489 // purpose  :
490 //=================================================================================
491 void SMESHGUI_AddMeshElementDlg::ClickOnCancel()
492 {
493   //mySelectionMgr->clearSelected();
494   mySimulation->SetVisibility(false);
495   SMESH::SetPointRepresentation(false);
496   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
497     aViewWindow->SetSelectionMode( ActorSelection );
498   disconnect(mySelectionMgr, 0, this, 0);
499   mySMESHGUI->ResetState();
500   reject();
501   return;
502 }
503
504 //=================================================================================
505 // function : onTextChange()
506 // purpose  :
507 //=================================================================================
508 void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
509 {
510   if (myBusy) return;
511   myBusy = true;
512
513   myNbOkNodes = 0;
514
515   buttonOk->setEnabled(false);
516   buttonApply->setEnabled(false);
517
518   mySimulation->SetVisibility(false);
519
520   // hilight entered nodes
521   SMDS_Mesh* aMesh = 0;
522   if (myActor)
523     aMesh = myActor->GetObject()->GetMesh();
524
525   if (aMesh) {
526     TColStd_MapOfInteger newIndices;
527     
528     QStringList aListId = QStringList::split(" ", theNewText, false);
529     bool allOk = true;
530     for (int i = 0; i < aListId.count(); i++) {
531       if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
532       {
533         newIndices.Add( n->GetID() );
534         myNbOkNodes++;
535       }
536       else
537         allOk = false;  
538     }
539     
540     mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
541     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
542       aViewWindow->highlight( myActor->getIO(), true, true );
543     
544     myNbOkNodes = ( allOk && myNbNodes == aListId.count() );
545     
546     if (myIsPoly)
547       {
548         if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
549           myNbOkNodes = 0;
550         else
551           myNbOkNodes = aListId.count();
552       }
553   }
554   
555   if(myNbOkNodes) {
556     buttonOk->setEnabled(true);
557     buttonApply->setEnabled(true);
558     displaySimulation();
559   }
560   
561   myBusy = false;
562 }
563
564 //=================================================================================
565 // function : SelectionIntoArgument()
566 // purpose  : Called when selection has changed
567 //=================================================================================
568 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
569 {
570   if (myBusy) return;
571
572   // clear
573   myNbOkNodes = 0;
574   myActor = 0;
575
576   myBusy = true;
577   myEditCurrentArgument->setText("");
578   myBusy = false;
579
580   if (!GroupButtons->isEnabled()) // inactive
581     return;
582
583   buttonOk->setEnabled(false);
584   buttonApply->setEnabled(false);
585
586   mySimulation->SetVisibility(false);
587 //  SMESH::SetPointRepresentation(true);
588
589   // get selected mesh
590   SALOME_ListIO aList;
591   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
592
593   if (aList.Extent() != 1)
594     return;
595
596   Handle(SALOME_InteractiveObject) anIO = aList.First();
597   myMesh = SMESH::GetMeshByIO(anIO);
598   if (myMesh->_is_nil())
599     return;
600
601   myActor = SMESH::FindActorByEntry(anIO->getEntry());
602   if (!myActor)
603     return;
604
605   // get selected nodes
606   QString aString = "";
607   int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
608   myBusy = true;
609   myEditCurrentArgument->setText(aString);
610   myBusy = false;
611   if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
612     myNbNodes = nbNodes;
613   } else if (myNbNodes != nbNodes) {
614     return;
615   }
616
617   // OK
618   myNbOkNodes = nbNodes;
619
620   buttonOk->setEnabled(true);
621   buttonApply->setEnabled(true);
622
623   displaySimulation();
624 }
625
626 //=================================================================================
627 // function : displaySimulation()
628 // purpose  :
629 //=================================================================================
630 void SMESHGUI_AddMeshElementDlg::displaySimulation()
631 {
632   if (myNbOkNodes && GroupButtons->isEnabled()) {
633     SMESH::TElementSimulation::TVTKIds anIds;
634     QStringList aListId = QStringList::split(" ", myEditCurrentArgument->text(), false);
635     for (int i = 0; i < aListId.count(); i++)
636       anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt()));
637
638     if (Reverse && Reverse->isChecked())
639       reverse(anIds.begin(),anIds.end());
640
641     vtkIdType aType = 0;
642     if (myIsPoly)
643       switch ( myElementType ) {
644       case SMDSAbs_Face  : aType = VTK_POLYGON; break;
645       default: return;
646       }
647     else {
648       switch (myNbNodes) {
649       case 2: aType = VTK_LINE; break;
650       case 3: aType = VTK_TRIANGLE; break;
651       case 4: aType = myElementType == SMDSAbs_Face ? VTK_QUAD : VTK_TETRA; break;
652       case 8: aType = VTK_HEXAHEDRON; break;
653       default: return;
654       }
655     }
656
657     mySimulation->SetPosition(myActor,aType,anIds);
658     SMESH::UpdateView();
659   }
660 }
661
662 //=================================================================================
663 // function : SetEditCurrentArgument()
664 // purpose  :
665 //=================================================================================
666 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
667 {
668   QPushButton* send = (QPushButton*)sender();
669   if (send == SelectButtonC1A1) {
670     LineEditC1A1->setFocus();
671     myEditCurrentArgument = LineEditC1A1;
672   }
673   SelectionIntoArgument();
674 }
675
676 //=================================================================================
677 // function : DeactivateActiveDialog()
678 // purpose  :
679 //=================================================================================
680 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
681 {
682   if (GroupConstructors->isEnabled()) {
683     GroupConstructors->setEnabled(false);
684     GroupC1->setEnabled(false);
685     GroupButtons->setEnabled(false);
686     mySimulation->SetVisibility(false);
687     mySMESHGUI->ResetState();
688     mySMESHGUI->SetActiveDialogBox(0);
689   }
690 }
691
692 //=================================================================================
693 // function : ActivateThisDialog()
694 // purpose  :
695 //=================================================================================
696 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
697 {
698   /* Emit a signal to deactivate the active dialog */
699   mySMESHGUI->EmitSignalDeactivateDialog();
700
701   GroupConstructors->setEnabled(true);
702   GroupC1->setEnabled(true);
703   GroupButtons->setEnabled(true);
704
705   SMESH::SetPointRepresentation(true);
706
707   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
708     aViewWindow->SetSelectionMode( NodeSelection );
709   SelectionIntoArgument();
710 }
711
712 //=================================================================================
713 // function : enterEvent()
714 // purpose  :
715 //=================================================================================
716 void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
717 {
718   if (GroupConstructors->isEnabled())
719     return;
720   ActivateThisDialog();
721   return;
722 }
723
724 //=================================================================================
725 // function : closeEvent()
726 // purpose  :
727 //=================================================================================
728 void SMESHGUI_AddMeshElementDlg::closeEvent (QCloseEvent*)
729 {
730   /* same than click on cancel button */
731   this->ClickOnCancel();
732   return;
733 }
734
735 //=================================================================================
736 // function : hideEvent()
737 // purpose  : caused by ESC key
738 //=================================================================================
739 void SMESHGUI_AddMeshElementDlg::hideEvent (QHideEvent*)
740 {
741   if (!isMinimized())
742     ClickOnCancel();
743 }
744
745 //=================================================================================
746 // function : CheckBox()
747 // purpose  :
748 //=================================================================================
749 void SMESHGUI_AddMeshElementDlg::CheckBox (int state)
750 {
751   if (!myNbOkNodes)
752     return;
753
754   if (state >= 0) {
755     mySimulation->SetVisibility(false);
756     displaySimulation();
757   }
758 }