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