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