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