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