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