Salome HOME
INT PAL 0052775: Any dialogue with the selector raises an exception for second viewer
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AddQuadraticElementDlg.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_AddMeshElementDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI_AddQuadraticElementDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_GroupUtils.h"
35 #include "SMESHGUI_IdValidator.h"
36
37 #include <SMESH_Actor.h>
38 #include <SMESH_ActorUtils.h>
39 #include <SMESH_FaceOrientationFilter.h>
40 #include <SMDS_Mesh.hxx>
41
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_ViewManager.h>
48
49 #include <LightApp_SelectionMgr.h>
50
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53
54 #include <SALOME_ListIO.hxx>
55
56 #include <SalomeApp_Application.h>
57
58 #include <Qtx.h>
59
60 // IDL includes
61 #include <SALOMEconfig.h>
62 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
63
64 // OCCT includes
65 #include <TColStd_MapOfInteger.hxx>
66
67 // VTK includes
68 #include <vtkIdList.h>
69 #include <vtkUnstructuredGrid.h>
70 #include <vtkDataSetMapper.h>
71 #include <vtkPolyDataMapper.h>
72 #include <vtkProperty.h>
73 #include <vtkCellType.h>
74
75 // Qt includes
76 #include <QComboBox>
77 #include <QGroupBox>
78 #include <QLabel>
79 #include <QLineEdit>
80 #include <QPushButton>
81 #include <QRadioButton>
82 #include <QVBoxLayout>
83 #include <QHBoxLayout>
84 #include <QGridLayout>
85 #include <QCheckBox>
86 #include <QTableWidget>
87 #include <QKeyEvent>
88 #include <QButtonGroup>
89
90 // STL includes
91 #include <vector>
92
93 #define SPACING 6
94 #define MARGIN  11
95
96 namespace
97 {
98   void ReverseConnectivity( std::vector<vtkIdType> & ids, SMDSAbs_EntityType type,
99                             bool toReverse, // inverse element
100                             bool toVtkOrder ) // smds connectivity to vtk one
101   {
102     if ( toReverse ) // first reverse smds order
103     {
104       const std::vector<int>& index = SMDS_MeshCell::reverseSmdsOrder(type);
105       SMDS_MeshCell::applyInterlace( index, ids );
106     }
107     if ( toVtkOrder ) // from smds to vtk connectivity
108     {
109       const std::vector<int>& index = SMDS_MeshCell::toVtkOrder(type);
110       SMDS_MeshCell::applyInterlace( index, ids );
111     }
112   }
113 }
114 namespace SMESH
115 {
116   class TElementSimulationQuad {
117     SalomeApp_Application* myApplication;
118     SUIT_ViewWindow* myViewWindow;
119     SVTK_ViewWindow* myVTKViewWindow;
120
121     SALOME_Actor* myPreviewActor;
122     vtkDataSetMapper* myMapper;
123     vtkUnstructuredGrid* myGrid;
124     //vtkProperty* myBackProp, *myProp;
125
126     //double myRGB[3], myBackRGB[3];
127
128     SALOME_Actor* myFaceOrientation;
129     vtkPolyDataMapper* myFaceOrientationDataMapper;
130     SMESH_FaceOrientationFilter* myFaceOrientationFilter;
131
132   public:
133     TElementSimulationQuad (SalomeApp_Application* theApplication)
134     {
135       myApplication = theApplication;
136       SUIT_ViewManager* mgr = theApplication->activeViewManager();
137       if (!mgr) return;
138       myViewWindow = mgr->getActiveView();
139       myVTKViewWindow = GetVtkViewWindow(myViewWindow);
140
141       myGrid = vtkUnstructuredGrid::New();
142
143       // Create and display actor
144       myMapper = vtkDataSetMapper::New();
145       myMapper->SetInputData(myGrid);
146
147       myPreviewActor = SALOME_Actor::New();
148       myPreviewActor->PickableOff();
149       myPreviewActor->VisibilityOff();
150       myPreviewActor->SetMapper(myMapper);
151       
152       QColor ffc, bfc;
153       int delta;
154       vtkProperty* myProp = vtkProperty::New();
155       SMESH::GetColor( "SMESH", "preview_color", ffc, delta, "0, 255, 0|-100" ) ;
156    
157       myProp->SetColor( ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255. );
158       myPreviewActor->SetProperty( myProp );
159       myProp->Delete();
160
161       vtkProperty* myBackProp = vtkProperty::New();
162       bfc = Qtx::mainColorToSecondary(ffc, delta);
163       myBackProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
164       myPreviewActor->SetBackfaceProperty( myBackProp );
165       myBackProp->Delete();
166
167       myVTKViewWindow->AddActor(myPreviewActor);
168
169       // Orientation of faces
170       myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
171       myFaceOrientationFilter->SetInputData(myGrid);
172
173       myFaceOrientationDataMapper = vtkPolyDataMapper::New();
174       myFaceOrientationDataMapper->SetInputConnection(myFaceOrientationFilter->GetOutputPort());
175
176       myFaceOrientation = SALOME_Actor::New();
177       myFaceOrientation->PickableOff();
178       myFaceOrientation->VisibilityOff();
179       myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
180
181       vtkProperty* anOrientationProp = vtkProperty::New();
182       double aRGB[3];
183       GetColor( "SMESH", "orientation_color", aRGB[0], aRGB[1], aRGB[2], QColor( 255, 255, 255 ) );
184       anOrientationProp->SetColor( aRGB[0], aRGB[1], aRGB[2] );
185       myFaceOrientation->SetProperty( anOrientationProp );
186       anOrientationProp->Delete();
187
188       myVTKViewWindow->AddActor(myFaceOrientation);
189     }
190
191     typedef std::vector<vtkIdType> TVTKIds;
192     void SetPosition (SMESH_Actor*       theActor,
193                       SMDSAbs_EntityType theType,
194                       TVTKIds&           theIds,
195                       const int          theMode,
196                       const bool         theReverse)
197     {
198       vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
199       myGrid->SetPoints(aGrid->GetPoints());
200
201       //add points
202
203       ReverseConnectivity( theIds, theType, theReverse, /*toVtkOrder=*/true);
204
205       myGrid->Reset();
206       vtkIdList *anIds = vtkIdList::New();
207
208       for (int i = 0, iEnd = theIds.size(); i < iEnd; i++) {
209         anIds->InsertId(i,theIds[i]);
210         //std::cout << i<< ": " << theIds[i] << std::endl;
211       }
212
213       vtkIdType aType = SMDS_MeshCell::toVtkType(theType);
214       myGrid->InsertNextCell(aType,anIds);
215       anIds->Delete();
216
217       myGrid->Modified();
218
219       myPreviewActor->GetMapper()->Update();
220       myPreviewActor->SetRepresentation( theMode );
221       SetVisibility(true, theActor->GetFacesOriented());
222     }
223
224
225     void SetVisibility (bool theVisibility, bool theShowOrientation = false)
226     {
227       myPreviewActor->SetVisibility(theVisibility);
228       myFaceOrientation->SetVisibility(theShowOrientation);
229       RepaintCurrentView();
230     }
231
232
233     ~TElementSimulationQuad()
234     {
235       if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
236         myVTKViewWindow->RemoveActor(myPreviewActor);
237         myVTKViewWindow->RemoveActor(myFaceOrientation);
238       }
239       myPreviewActor->Delete();
240       myFaceOrientation->Delete();
241
242       myMapper->RemoveAllInputs();
243       myMapper->Delete();
244
245       myFaceOrientationFilter->Delete();
246
247       myFaceOrientationDataMapper->RemoveAllInputs();
248       myFaceOrientationDataMapper->Delete();
249
250       myGrid->Delete();
251
252 //       myProp->Delete();
253 //       myBackProp->Delete();
254     }
255   };
256 }
257
258
259 // Define the sequences of ids
260 static int FirstEdgeIds[] = {0};
261 static int LastEdgeIds[] =  {1};
262
263 static int FirstTriangleIds[] = {0,1,2};
264 static int LastTriangleIds[] =  {1,2,0};
265
266 static int FirstQuadrangleIds[] = {0,1,2,3};
267 static int LastQuadrangleIds[] =  {1,2,3,0};
268
269 static int FirstTetrahedronIds[] = {0,1,2,3,3,3};
270 static int LastTetrahedronIds[] =  {1,2,0,0,1,2};
271
272 static int FirstPyramidIds[] = {0,1,2,3,4,4,4,4};
273 static int LastPyramidIds[] =  {1,2,3,0,0,1,2,3};
274
275 static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2};
276 static int LastPentahedronIds[] =  {1,2,0,4,5,3,3,4,5};
277
278 static int FirstHexahedronIds[] = {0,1,2,3,4,5,6,7,0,1,2,3};
279 static int LastHexahedronIds[] =  {1,2,3,0,5,6,7,4,4,5,6,7};
280
281 /*!
282   \class BusyLocker
283   \brief Simple 'busy state' flag locker.
284   \internal
285 */
286 class BusyLocker
287 {
288 public:
289   //! Constructor. Sets passed boolean flag to \c true.
290   BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
291   //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
292   ~BusyLocker() { myBusy = false; }
293 private:
294   bool& myBusy; //! External 'busy state' boolean flag
295 };
296
297 /*!
298   \class IdEditItem
299   \brief Simple editable table item.
300   \internal
301 */
302 class IdEditItem: public QTableWidgetItem
303 {
304 public:
305   IdEditItem(const QString& text );
306   ~IdEditItem();
307
308   QWidget* createEditor() const;
309 };
310
311 IdEditItem::IdEditItem(const QString& text )
312   : QTableWidgetItem(text, QTableWidgetItem::UserType+100)
313 {
314 }
315
316 IdEditItem::~IdEditItem()
317 {
318 }
319
320 QWidget* IdEditItem::createEditor() const
321 {
322   QLineEdit *aLineEdit = new QLineEdit(text(), tableWidget());
323   aLineEdit->setValidator( new SMESHGUI_IdValidator(tableWidget(), 1) );
324   return aLineEdit;
325 }
326
327 //=================================================================================
328 // function : SMESHGUI_AddQuadraticElementDlg()
329 // purpose  : constructor
330 //=================================================================================
331
332 SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule,
333                                                                   const SMDSAbs_EntityType theType )
334   : QDialog( SMESH::GetDesktop( theModule ) ),
335     mySMESHGUI( theModule ),
336     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
337     myGeomType( theType ),
338     //myType( theType ),
339     myBusy( false )
340 {
341   setModal( false );
342   setAttribute( Qt::WA_DeleteOnClose, true );
343
344   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
345     (SUIT_Session::session()->activeApplication());
346
347   mySimulation = new SMESH::TElementSimulationQuad (anApp);
348   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
349
350   QString anElementName;
351
352   switch ( myGeomType ) {
353   case SMDSEntity_Quad_Edge:
354     anElementName = QString("QUADRATIC_EDGE");
355     break;
356   case SMDSEntity_Quad_Triangle:
357     anElementName = QString("QUADRATIC_TRIANGLE");
358     break;
359   case SMDSEntity_Quad_Quadrangle:
360     anElementName = QString("QUADRATIC_QUADRANGLE");
361     break;
362   case SMDSEntity_BiQuad_Quadrangle:
363     anElementName = QString("BIQUADRATIC_QUADRANGLE");
364     break;
365   case SMDSEntity_BiQuad_Triangle:
366     anElementName = QString("BIQUADRATIC_TRIANGLE");
367     break;
368   case SMDSEntity_Quad_Tetra:
369     anElementName = QString("QUADRATIC_TETRAHEDRON");
370     break;
371   case SMDSEntity_Quad_Pyramid:
372     anElementName = QString("QUADRATIC_PYRAMID");
373     break;
374   case SMDSEntity_Quad_Penta:
375     anElementName = QString("QUADRATIC_PENTAHEDRON");
376     break;
377   case SMDSEntity_Quad_Hexa:
378     anElementName = QString("QUADRATIC_HEXAHEDRON");
379     break;
380   case SMDSEntity_TriQuad_Hexa:
381     anElementName = QString("TRIQUADRATIC_HEXAHEDRON");
382     break;
383   default:
384     myGeomType = SMDSEntity_Quad_Edge;
385     anElementName = QString("QUADRATIC_EDGE");
386   }
387
388   QString iconName           = tr(QString("ICON_DLG_%1").arg(anElementName).toLatin1().data());
389   QString caption            = tr(QString("SMESH_ADD_%1_TITLE").arg(anElementName).toLatin1().data());
390   QString argumentsGrTitle   = tr(QString("SMESH_ADD_%1").arg(anElementName).toLatin1().data());
391   QString constructorGrTitle = tr(QString("SMESH_%1").arg(anElementName).toLatin1().data());
392
393   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
394   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
395
396   setWindowTitle(caption);
397
398   setSizeGripEnabled(true);
399
400   QVBoxLayout* aDialogLayout = new QVBoxLayout(this);
401   aDialogLayout->setSpacing(SPACING);
402   aDialogLayout->setMargin(MARGIN);
403
404   /***************************************************************/
405   GroupConstructors = new QGroupBox(constructorGrTitle, this);
406   QButtonGroup* ButtonGroup = new QButtonGroup(this);
407   QHBoxLayout* aGroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
408   aGroupConstructorsLayout->setSpacing(SPACING);
409   aGroupConstructorsLayout->setMargin(MARGIN);
410
411   myRadioButton1 = new QRadioButton(GroupConstructors);
412   myRadioButton1->setIcon(image0);
413   aGroupConstructorsLayout->addWidget(myRadioButton1);
414   ButtonGroup->addButton(myRadioButton1, 0);
415
416   /***************************************************************/
417   GroupArguments = new QGroupBox(argumentsGrTitle, this);
418   QGridLayout* aGroupArgumentsLayout = new QGridLayout(GroupArguments);
419   aGroupArgumentsLayout->setSpacing(SPACING);
420   aGroupArgumentsLayout->setMargin(MARGIN);
421
422   // Corner nodes
423   QLabel* aCornerNodesLabel = new QLabel(tr("SMESH_CORNER_NODES"), GroupArguments);
424   myCornerSelectButton = new QPushButton(GroupArguments);
425   myCornerSelectButton->setIcon(image1);
426   myCornerNodes = new QLineEdit(GroupArguments);
427
428   // Mid-edge nodes
429   myTable = new QTableWidget(GroupArguments);
430
431   // Mid-face nodes
432   myMidFaceLabel = new QLabel(tr("SMESH_MIDFACE_NODES"), GroupArguments);
433   myMidFaceSelectButton = new QPushButton(GroupArguments);
434   myMidFaceSelectButton->setIcon(image1);
435   myMidFaceNodes = new QLineEdit(GroupArguments);
436   myMidFaceNodes->setValidator(new SMESHGUI_IdValidator(this, 6));
437
438   // Central node
439   myCenterLabel = new QLabel(tr("SMESH_CENTER_NODE"), GroupArguments);
440   myCenterSelectButton = new QPushButton(GroupArguments);
441   myCenterSelectButton->setIcon(image1);
442   myCenterNode = new QLineEdit(GroupArguments);
443   myCenterNode->setValidator(new SMESHGUI_IdValidator(this, 1));
444
445   myReverseCB = new QCheckBox(tr("SMESH_REVERSE"), GroupArguments);
446
447   aGroupArgumentsLayout->addWidget(aCornerNodesLabel,     0, 0);
448   aGroupArgumentsLayout->addWidget(myCornerSelectButton,  0, 1);
449   aGroupArgumentsLayout->addWidget(myCornerNodes,         0, 2);
450   aGroupArgumentsLayout->addWidget(myTable,               1, 0, 1, 3);
451   aGroupArgumentsLayout->addWidget(myMidFaceLabel,        2, 0);
452   aGroupArgumentsLayout->addWidget(myMidFaceSelectButton, 2, 1);
453   aGroupArgumentsLayout->addWidget(myMidFaceNodes,        2, 2);
454   aGroupArgumentsLayout->addWidget(myCenterLabel,         3, 0);
455   aGroupArgumentsLayout->addWidget(myCenterSelectButton,  3, 1);
456   aGroupArgumentsLayout->addWidget(myCenterNode,          3, 2);
457   aGroupArgumentsLayout->addWidget(myReverseCB,           4, 0, 1, 3);
458
459     /***************************************************************/
460   GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
461   GroupGroups->setCheckable( true );
462   QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
463   GroupGroupsLayout->setSpacing(SPACING);
464   GroupGroupsLayout->setMargin(MARGIN);
465
466   TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
467   ComboBox_GroupName = new QComboBox( GroupGroups );
468   ComboBox_GroupName->setEditable( true );
469   ComboBox_GroupName->setInsertPolicy( QComboBox::NoInsert );
470
471   GroupGroupsLayout->addWidget( TextLabel_GroupName );
472   GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
473
474   /***************************************************************/
475   GroupButtons = new QGroupBox(this);
476   QHBoxLayout* aGroupButtonsLayout = new QHBoxLayout(GroupButtons);
477   aGroupButtonsLayout->setSpacing(SPACING);
478   aGroupButtonsLayout->setMargin(MARGIN);
479
480   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
481   buttonOk->setAutoDefault(true);
482   buttonOk->setDefault(true);
483   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
484   buttonApply->setAutoDefault(true);
485   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
486   buttonCancel->setAutoDefault(true);
487   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
488   buttonHelp->setAutoDefault(true);
489
490   aGroupButtonsLayout->addWidget(buttonOk);
491   aGroupButtonsLayout->addSpacing(10);
492   aGroupButtonsLayout->addWidget(buttonApply);
493   aGroupButtonsLayout->addSpacing(10);
494   aGroupButtonsLayout->addStretch();
495   aGroupButtonsLayout->addWidget(buttonCancel);
496   aGroupButtonsLayout->addWidget(buttonHelp);
497
498   /***************************************************************/
499   aDialogLayout->addWidget(GroupConstructors);
500   aDialogLayout->addWidget(GroupArguments);
501   aDialogLayout->addWidget(GroupGroups);
502   aDialogLayout->addWidget(GroupButtons);
503
504   Init(); /* Initialisations */
505 }
506
507 //=================================================================================
508 // function : ~SMESHGUI_AddQuadraticElementDlg()
509 // purpose  : Destroys the object and frees any allocated resources
510 //=================================================================================
511
512 SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
513 {
514   delete mySimulation;
515 }
516
517 //=================================================================================
518 // function : Init()
519 // purpose  :
520 //=================================================================================
521
522 void SMESHGUI_AddQuadraticElementDlg::Init()
523 {
524   myRadioButton1->setChecked(true);
525   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
526
527   /* reset "Add to group" control */
528   GroupGroups->setChecked( false );
529
530   myActor = 0;
531   myNbMidFaceNodes = 0;
532   myNbCenterNodes = 0;
533
534   int aNumRows;
535
536   switch (myGeomType) {
537   case SMDSEntity_Quad_Edge:
538     aNumRows = 1;
539     myNbCorners = 2;
540     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_edges
541     break;
542   case SMDSEntity_Quad_Triangle:
543     aNumRows = 3;
544     myNbCorners = 3;
545     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_triangles
546     break;
547   case SMDSEntity_BiQuad_Triangle:
548     aNumRows = 3;
549     myNbCorners = 3;
550     myNbCenterNodes = 1;
551     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_triangles
552     break;
553   case SMDSEntity_Quad_Quadrangle:
554     aNumRows = 4;
555     myNbCorners = 4;
556     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_quadrangles
557     break;
558   case SMDSEntity_BiQuad_Quadrangle:
559     aNumRows = 4;
560     myNbCorners = 4;
561     myNbCenterNodes = 1;
562     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_quadrangles
563     break;
564   case SMDSEntity_Quad_Tetra:
565     aNumRows = 6;
566     myNbCorners = 4;
567     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_tetrahedrons
568     break;
569   case SMDSEntity_Quad_Pyramid:
570     aNumRows = 8;
571     myNbCorners = 5;
572     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pyramids
573     break;
574   case SMDSEntity_Quad_Penta:
575     aNumRows = 9;
576     myNbCorners = 6;
577     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pentahedrons
578     break;
579   case SMDSEntity_Quad_Hexa:
580     aNumRows = 12;
581     myNbCorners = 8;
582     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_hexahedrons
583     break;
584   case SMDSEntity_TriQuad_Hexa:
585     aNumRows = 12;
586     myNbCorners = 8;
587     myNbMidFaceNodes = 6;
588     myNbCenterNodes = 1;
589     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_hexahedrons
590     break;
591   }
592
593   myMidFaceLabel       ->setVisible( myNbMidFaceNodes );
594   myMidFaceSelectButton->setVisible( myNbMidFaceNodes );
595   myMidFaceNodes       ->setVisible( myNbMidFaceNodes );
596   myCenterLabel        ->setVisible( myNbCenterNodes );
597   myCenterSelectButton ->setVisible( myNbCenterNodes );
598   myCenterNode         ->setVisible( myNbCenterNodes );
599
600   myCornerNodes->setValidator(new SMESHGUI_IdValidator(this, myNbCorners));
601
602   /* initialize table */
603   myTable->setColumnCount(3);
604   myTable->setRowCount(aNumRows);
605
606   QStringList aColLabels;
607   aColLabels.append(tr("SMESH_FIRST"));
608   aColLabels.append(tr("SMESH_MIDDLE"));
609   aColLabels.append(tr("SMESH_LAST"));
610   myTable->setHorizontalHeaderLabels(aColLabels);
611
612   for ( int col = 0; col < myTable->columnCount(); col++ )
613     myTable->setColumnWidth(col, 80);
614
615   //myTable->setColumnReadOnly(0, true); // VSR: TODO
616   //myTable->setColumnReadOnly(2, true); // VSR: TODO
617
618   myTable->setEnabled( false );
619
620   for ( int row = 0; row < myTable->rowCount(); row++ )
621   {
622     myTable->setItem( row, 0, new QTableWidgetItem( "" ) );
623     myTable->item( row, 0 )->setFlags(0);
624
625     IdEditItem* anEditItem = new IdEditItem( "" );
626     anEditItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
627     myTable->setItem(row, 1, anEditItem);
628
629     myTable->setItem( row, 2, new QTableWidgetItem( "" ) );
630     myTable->item( row, 2 )->setFlags(0);
631   }
632
633   /* signals and slots connections */
634   connect(myCornerSelectButton, SIGNAL(clicked()), SLOT(SetCurrentSelection()));
635   connect(myMidFaceSelectButton, SIGNAL(clicked()), SLOT(SetCurrentSelection()));
636   connect(myCenterSelectButton, SIGNAL(clicked()), SLOT(SetCurrentSelection()));
637   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
638   connect(myTable,        SIGNAL(cellDoubleClicked(int, int)), SLOT(onCellDoubleClicked(int, int)));
639   connect(myTable,        SIGNAL(cellChanged (int, int)), SLOT(onCellTextChange(int, int)));
640   connect(myCornerNodes,  SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
641   connect(myMidFaceNodes, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
642   connect(myCenterNode,  SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
643   connect(myReverseCB,    SIGNAL(stateChanged(int)), SLOT(onReverse(int)));
644
645   connect(buttonOk, SIGNAL(clicked()),     SLOT(ClickOnOk()));
646   connect(buttonCancel, SIGNAL(clicked()), SLOT(reject()));
647   connect(buttonApply, SIGNAL(clicked()),  SLOT(ClickOnApply()));
648   connect(buttonHelp, SIGNAL(clicked()),   SLOT(ClickOnHelp()));
649
650   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
651   connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(reject()));
652   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), SLOT(reject()));
653   connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), SLOT(onOpenView()));
654   connect(mySMESHGUI, SIGNAL (SignalCloseView()), SLOT(onCloseView()));
655
656   myCurrentLineEdit = myCornerNodes;
657
658   // set selection mode
659   SMESH::SetPointRepresentation(true);
660
661   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
662     aViewWindow->SetSelectionMode( NodeSelection );
663
664   SelectionIntoArgument();
665 }
666
667 //=================================================================================
668 // function : ClickOnApply()
669 // purpose  :
670 //=================================================================================
671
672 bool SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
673 {
674   if( !isValid() )
675     return false;
676
677   if ( mySMESHGUI->isActiveStudyLocked() || myBusy || !IsValid() )
678     return false;
679
680   BusyLocker lock( myBusy );
681
682   std::vector<vtkIdType> anIds;
683
684   switch (myGeomType) {
685   case SMDSEntity_Quad_Edge:
686     anIds.push_back(myTable->item(0, 0)->text().toInt());
687     anIds.push_back(myTable->item(0, 2)->text().toInt());
688     anIds.push_back(myTable->item(0, 1)->text().toInt());
689     break;
690   case SMDSEntity_Quad_Triangle:
691   case SMDSEntity_Quad_Quadrangle:
692   case SMDSEntity_BiQuad_Triangle:
693   case SMDSEntity_BiQuad_Quadrangle:
694   case SMDSEntity_Quad_Tetra:
695   case SMDSEntity_Quad_Pyramid:
696   case SMDSEntity_Quad_Penta:
697   case SMDSEntity_Quad_Hexa:
698   case SMDSEntity_TriQuad_Hexa:
699     for ( int row = 0; row < myNbCorners; row++ )
700       anIds.push_back(myTable->item(row, 0)->text().toInt());
701     for ( int row = 0; row < myTable->rowCount(); row++ )
702       anIds.push_back(myTable->item(row, 1)->text().toInt());
703     if ( myNbMidFaceNodes )
704     {
705       QStringList aListId = myMidFaceNodes->text().split(" ", QString::SkipEmptyParts);
706       for (int i = 0; i < aListId.count(); i++)
707         anIds.push_back( aListId[ i ].toInt() );
708     }
709     if ( myNbCenterNodes )
710     {
711       QStringList aListId = myCenterNode->text().split(" ", QString::SkipEmptyParts);
712       anIds.push_back( aListId[ 0 ].toInt() );
713     }
714     break;
715   }
716   if ( myReverseCB->isChecked())
717     ReverseConnectivity( anIds, myGeomType, /*toReverse=*/true, /*toVtkOrder=*/false );
718
719   int aNumberOfIds =  anIds.size();
720   SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
721   anArrayOfIdeces->length( aNumberOfIds );
722
723   for (int i = 0; i < aNumberOfIds; i++)
724     anArrayOfIdeces[i] = anIds[ i ];
725
726   bool addToGroup = GroupGroups->isChecked();
727   QString aGroupName;
728
729   SMESH::SMESH_GroupBase_var aGroup;
730   int idx = 0;
731   if( addToGroup ) {
732     aGroupName = ComboBox_GroupName->currentText();
733     for ( int i = 1; i <= ComboBox_GroupName->count(); i++ ) {
734       QString aName = ComboBox_GroupName->itemText( i );
735       if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
736         idx = i;
737     }
738     if ( idx > 0 && idx <= myGroups.count() ) {
739       SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
740       if ( !aGeomGroup->_is_nil() ) {
741         int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
742                                              tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
743                                              tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
744         if ( res == 1 ) return false;
745       }
746       aGroup = myGroups[idx-1];
747     }
748   }
749
750   SMESH::ElementType anElementType;
751   long anElemId = -1;
752   SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
753   switch (myGeomType) {
754   case SMDSEntity_Quad_Edge:
755     anElementType = SMESH::EDGE;
756     anElemId = aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
757   case SMDSEntity_Quad_Triangle:
758   case SMDSEntity_Quad_Quadrangle:
759   case SMDSEntity_BiQuad_Triangle:
760   case SMDSEntity_BiQuad_Quadrangle:
761     anElementType = SMESH::FACE;
762     anElemId = aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
763   case SMDSEntity_Quad_Tetra:
764   case SMDSEntity_Quad_Pyramid:
765   case SMDSEntity_Quad_Penta:
766   case SMDSEntity_Quad_Hexa:
767   case SMDSEntity_TriQuad_Hexa:
768     anElementType = SMESH::VOLUME;
769     anElemId = aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
770   default: break;
771   }
772
773   if ( anElemId != -1 && addToGroup && !aGroupName.isEmpty() ) {
774     SMESH::SMESH_Group_var aGroupUsed;
775     if ( aGroup->_is_nil() ) {
776       // create new group
777       aGroupUsed = SMESH::AddGroup( myMesh, anElementType, aGroupName );
778       if ( !aGroupUsed->_is_nil() ) {
779         myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
780         ComboBox_GroupName->addItem( aGroupName );
781       }
782     }
783     else {
784       SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
785       if ( !aGeomGroup->_is_nil() ) {
786         aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
787         if ( !aGroupUsed->_is_nil() && idx > 0 ) {
788           myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
789           SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
790         }
791       }
792       else
793         aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
794     }
795
796     if ( !aGroupUsed->_is_nil() ) {
797       SMESH::long_array_var anIdList = new SMESH::long_array;
798       anIdList->length( 1 );
799       anIdList[0] = anElemId;
800       aGroupUsed->Add( anIdList.inout() );
801     }
802   }
803
804   SALOME_ListIO aList; aList.Append( myActor->getIO() );
805   mySelector->ClearIndex();
806   mySelectionMgr->setSelectedObjects( aList, false );
807
808   mySimulation->SetVisibility(false);
809   SMESH::UpdateView();
810
811   UpdateTable();
812   SetCurrentSelection();
813
814   updateButtons();
815
816   SMESHGUI::Modified();
817
818   return true;
819 }
820
821 //=================================================================================
822 // function : ClickOnOk()
823 // purpose  :
824 //=================================================================================
825
826 void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
827 {
828   if ( ClickOnApply() )
829     reject();
830 }
831
832 //=================================================================================
833 // function : reject()
834 // purpose  :
835 //=================================================================================
836
837 void SMESHGUI_AddQuadraticElementDlg::reject()
838 {
839   mySelectionMgr->clearSelected();
840   mySimulation->SetVisibility(false);
841   SMESH::SetPointRepresentation(false);
842   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
843     aViewWindow->SetSelectionMode( ActorSelection );
844   disconnect(mySelectionMgr, 0, this, 0);
845   mySMESHGUI->ResetState();
846   QDialog::reject();
847 }
848
849 //=================================================================================
850 // function : onOpenView()
851 // purpose  :
852 //=================================================================================
853 void SMESHGUI_AddQuadraticElementDlg::onOpenView()
854 {
855   if ( mySelector && mySimulation ) {
856     mySimulation->SetVisibility(false);
857     SMESH::SetPointRepresentation(false);
858   }
859   else {
860     mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
861     mySimulation = new SMESH::TElementSimulationQuad(
862       dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
863     ActivateThisDialog();
864   }
865 }
866
867 //=================================================================================
868 // function : onCloseView()
869 // purpose  :
870 //=================================================================================
871 void SMESHGUI_AddQuadraticElementDlg::onCloseView()
872 {
873   DeactivateActiveDialog();
874   mySelector = 0;
875   delete mySimulation;
876   mySimulation = 0;
877 }
878 //=================================================================================
879 // function : ClickOnHelp()
880 // purpose  :
881 //=================================================================================
882
883 void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
884 {
885   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
886   if (app)
887     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
888   else {
889     QString platform;
890 #ifdef WIN32
891     platform = "winapplication";
892 #else
893     platform = "application";
894 #endif
895     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
896                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
897                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
898                                                                  platform)).
899                              arg(myHelpFileName));
900   }
901 }
902
903 //=================================================================================
904 // function : onTextChange()
905 // purpose  :
906 //=================================================================================
907
908 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
909 {
910   if (myBusy) return;
911   BusyLocker lock( myBusy );
912
913   mySimulation->SetVisibility(false);
914
915   // hilight entered nodes
916   SMDS_Mesh* aMesh = 0;
917   if (myActor)
918     aMesh = myActor->GetObject()->GetMesh();
919
920   QLineEdit* send = (QLineEdit*)sender();
921   if (send == myCornerNodes ||
922       send == myMidFaceNodes ||
923       send == myCenterNode)
924     myCurrentLineEdit = send;
925
926   if (aMesh) {
927     TColStd_MapOfInteger newIndices;
928
929     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
930     bool allOk = true;
931     for (int i = 0; i < aListId.count(); i++) {
932       if ( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
933       {
934         newIndices.Add( n->GetID() );
935       }
936       else
937       {
938         allOk = false;
939         break;
940       }
941     }
942
943     mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
944     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
945       aViewWindow->highlight( myActor->getIO(), true, true );
946
947     if ( myCurrentLineEdit == myCornerNodes )
948       UpdateTable( allOk );
949   }
950
951   updateButtons();
952   displaySimulation();
953 }
954
955 //=================================================================================
956 // function : SelectionIntoArgument()
957 // purpose  : Called when selection has changed
958 //=================================================================================
959
960 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
961 {
962   if (myBusy) return;
963   BusyLocker lock( myBusy );
964
965   QString aCurrentEntry = myEntry;
966
967   if ( myCurrentLineEdit )
968   {
969     // clear
970     myActor = 0;
971
972     myCurrentLineEdit->setText("");
973
974     if (!GroupButtons->isEnabled()) // inactive
975       return;
976
977     mySimulation->SetVisibility(false);
978
979     // get selected mesh
980     SALOME_ListIO aList;
981     mySelectionMgr->selectedObjects(aList);
982
983     if (aList.Extent() != 1)
984     {
985       UpdateTable();
986       updateButtons();
987       return;
988     }
989
990     Handle(SALOME_InteractiveObject) anIO = aList.First();
991     myEntry = anIO->getEntry();
992     myMesh = SMESH::GetMeshByIO(anIO);
993     if (myMesh->_is_nil()) {
994       updateButtons();
995       return;
996     }
997
998     myActor = SMESH::FindActorByEntry(anIO->getEntry());
999
1000   }
1001
1002   // process groups
1003   if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
1004     SMESH::ElementType anElementType;
1005     switch ( myGeomType ) {
1006     case SMDSEntity_Quad_Edge:
1007       anElementType = SMESH::EDGE; break;
1008     case SMDSEntity_Quad_Triangle:
1009     case SMDSEntity_Quad_Quadrangle:
1010     case SMDSEntity_BiQuad_Triangle:
1011     case SMDSEntity_BiQuad_Quadrangle:
1012       anElementType = SMESH::FACE; break;
1013     case SMDSEntity_Quad_Tetra:
1014     case SMDSEntity_Quad_Pyramid:
1015     case SMDSEntity_Quad_Penta:
1016     case SMDSEntity_Quad_Hexa:
1017     case SMDSEntity_TriQuad_Hexa:
1018       anElementType = SMESH::VOLUME; break;
1019     }
1020     myGroups.clear();
1021     ComboBox_GroupName->clear();
1022     ComboBox_GroupName->addItem( QString() );
1023     SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
1024     for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
1025       SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
1026       if ( !aGroup->_is_nil() && aGroup->GetType() == anElementType ) {
1027         QString aGroupName( aGroup->GetName() );
1028         if ( !aGroupName.isEmpty() ) {
1029           myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
1030           ComboBox_GroupName->addItem( aGroupName );
1031         }
1032       }
1033     }
1034   }
1035
1036   if (!myActor) {
1037     updateButtons();
1038     return;
1039   }
1040
1041   // get selected nodes
1042   QString aString = "";
1043   int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
1044
1045   if ( myCurrentLineEdit )
1046   {
1047     if ( myCurrentLineEdit != myCenterNode || nbNodes == 1 )
1048       myCurrentLineEdit->setText(aString);
1049
1050     if ( myCurrentLineEdit == myCornerNodes )
1051       UpdateTable();
1052   }
1053   else if ( myTable->isEnabled() && nbNodes == 1 )
1054   {
1055     int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
1056     if ( theCol == 1 )
1057       myTable->item(theRow, 1)->setText(aString);
1058   }
1059
1060   updateButtons();
1061   displaySimulation();
1062 }
1063
1064 //=================================================================================
1065 // function : displaySimulation()
1066 // purpose  :
1067 //=================================================================================
1068
1069 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
1070 {
1071   if ( IsValid() )
1072   {
1073     SMESH::TElementSimulationQuad::TVTKIds anIds;
1074
1075     // Collect ids from the dialog
1076     int anID;
1077     bool ok;
1078     int aDisplayMode = VTK_SURFACE;
1079
1080     if ( myGeomType == SMDSEntity_Quad_Edge )
1081     {
1082       anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 0)->text().toInt() ) );
1083       anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(0, 2)->text().toInt() ) );
1084       anID = myTable->item(0, 1)->text().toInt(&ok);
1085       if (!ok) anID = myTable->item(0, 0)->text().toInt();
1086       anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
1087       aDisplayMode = VTK_WIREFRAME;
1088     }
1089     else
1090     {
1091       for ( int row = 0; row < myNbCorners; row++ )
1092         anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->item(row, 0)->text().toInt() ) );
1093
1094       for ( int row = 0; row < myTable->rowCount(); row++ )
1095       {
1096         anID = myTable->item(row, 1)->text().toInt(&ok);
1097         if (!ok) {
1098           anID = myTable->item(row, 0)->text().toInt();
1099           aDisplayMode = VTK_WIREFRAME;
1100         }
1101         anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
1102       }
1103       if ( myNbMidFaceNodes )
1104       {
1105         QStringList aListId = myMidFaceNodes->text().split(" ", QString::SkipEmptyParts);
1106         for (int i = 0; i < aListId.count(); i++)
1107           anIds.push_back( myActor->GetObject()->GetNodeVTKId( aListId[ i ].toInt() ));
1108       }
1109       if ( myNbCenterNodes )
1110       {
1111         QStringList aListId = myCenterNode->text().split(" ", QString::SkipEmptyParts);
1112         anIds.push_back( myActor->GetObject()->GetNodeVTKId( aListId[ 0 ].toInt() ));
1113       }
1114     }
1115
1116     mySimulation->SetPosition(myActor,myGeomType,anIds,aDisplayMode,myReverseCB->isChecked());
1117   }
1118   else
1119   {
1120     mySimulation->SetVisibility(false);
1121   }
1122   SMESH::UpdateView();
1123 }
1124
1125 //=================================================================================
1126 // function : SetCurrentSelection()
1127 // purpose  :
1128 //=================================================================================
1129
1130 void SMESHGUI_AddQuadraticElementDlg::SetCurrentSelection()
1131 {
1132   QPushButton* send = (QPushButton*)sender();
1133   myCurrentLineEdit = 0;
1134
1135   if (send == myCornerSelectButton)
1136     myCurrentLineEdit = myCornerNodes;
1137   else if ( send == myMidFaceSelectButton )
1138     myCurrentLineEdit = myMidFaceNodes;
1139   else if ( send == myCenterSelectButton )
1140     myCurrentLineEdit = myCenterNode;
1141
1142   if ( myCurrentLineEdit )
1143   {
1144     myCurrentLineEdit->setFocus();
1145     SelectionIntoArgument();
1146   }
1147 }
1148
1149 //=================================================================================
1150 // function : DeactivateActiveDialog()
1151 // purpose  :
1152 //=================================================================================
1153
1154 void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
1155 {
1156   if (GroupConstructors->isEnabled()) {
1157     GroupConstructors->setEnabled(false);
1158     GroupArguments->setEnabled(false);
1159     GroupButtons->setEnabled(false);
1160     mySimulation->SetVisibility(false);
1161     mySMESHGUI->ResetState();
1162     mySMESHGUI->SetActiveDialogBox(0);
1163   }
1164 }
1165
1166 //=================================================================================
1167 // function : ActivateThisDialog()
1168 // purpose  :
1169 //=================================================================================
1170
1171 void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
1172 {
1173   /* Emit a signal to deactivate the active dialog */
1174   mySMESHGUI->EmitSignalDeactivateDialog();
1175
1176   GroupConstructors->setEnabled(true);
1177   GroupArguments->setEnabled(true);
1178   GroupButtons->setEnabled(true);
1179
1180   SMESH::SetPointRepresentation(true);
1181
1182   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1183     aViewWindow->SetSelectionMode( NodeSelection );
1184   SelectionIntoArgument();
1185 }
1186
1187 //=================================================================================
1188 // function : enterEvent()
1189 // purpose  :
1190 //=================================================================================
1191 void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
1192 {
1193   if ( !GroupConstructors->isEnabled() ) {
1194     SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
1195     if ( aViewWindow && !mySelector && !mySimulation) {
1196       mySelector = aViewWindow->GetSelector();
1197       mySimulation = new SMESH::TElementSimulationQuad(
1198         dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
1199     }
1200     ActivateThisDialog();
1201   }
1202 }
1203
1204 //=================================================================================
1205 // function : onReverse()
1206 // purpose  :
1207 //=================================================================================
1208
1209 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
1210 {
1211   mySimulation->SetVisibility(false);
1212   displaySimulation();
1213   updateButtons();
1214 }
1215
1216 //=================================================================================
1217 // function : IsValid()
1218 // purpose  :
1219 //=================================================================================
1220
1221 bool SMESHGUI_AddQuadraticElementDlg::IsValid()
1222 {
1223   SMDS_Mesh* aMesh = 0;
1224   if (myActor)
1225     aMesh = myActor->GetObject()->GetMesh();
1226   if (!aMesh)
1227     return false;
1228
1229   bool ok;
1230   std::set< int > okIDs;
1231   for ( int row = 0; row < myTable->rowCount(); row++ )
1232   {
1233     int anID =  myTable->item(row, 1)->text().toInt(&ok);
1234     if ( !ok )
1235       return false;
1236
1237     const SMDS_MeshNode * aNode = aMesh->FindNode(anID);
1238     if ( !aNode )
1239       return false;
1240     okIDs.insert( anID );
1241   }
1242
1243   QStringList aListId;
1244   if ( myNbMidFaceNodes )
1245     aListId += myMidFaceNodes->text().split(" ", QString::SkipEmptyParts);
1246   if ( myNbCenterNodes )
1247     aListId += myCenterNode->text().split(" ", QString::SkipEmptyParts);
1248
1249   for (int i = 0; i < aListId.count(); i++)
1250   {
1251     int anID = aListId[ i ].toInt(&ok);
1252     if ( !ok )
1253       return false;
1254
1255     if ( !aMesh->FindNode(anID) )
1256       return false;
1257     okIDs.insert( anID );
1258   }
1259
1260   return okIDs.size() == myTable->rowCount() + myNbMidFaceNodes + myNbCenterNodes;
1261 }
1262
1263 //=================================================================================
1264 // function : UpdateTable()
1265 // purpose  :
1266 //=================================================================================
1267
1268 void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
1269 {
1270   QStringList aListCorners = myCornerNodes->text().split(" ", QString::SkipEmptyParts);
1271
1272   if ( aListCorners.count() == myNbCorners && theConersValidity )
1273   {
1274     myTable->setEnabled( true );
1275
1276     // clear the Middle column
1277     for ( int row = 0; row < myTable->rowCount(); row++ )
1278       myTable->item( row, 1 )->setText("");
1279
1280     int* aFirstColIds;
1281     int* aLastColIds;
1282
1283     switch (myGeomType) {
1284     case SMDSEntity_Quad_Edge:
1285       aFirstColIds = FirstEdgeIds;
1286       aLastColIds  = LastEdgeIds;
1287       break;
1288     case SMDSEntity_Quad_Triangle:
1289     case SMDSEntity_BiQuad_Triangle:
1290       aFirstColIds = FirstTriangleIds;
1291       aLastColIds  = LastTriangleIds;
1292       break;
1293     case SMDSEntity_Quad_Quadrangle:
1294     case SMDSEntity_BiQuad_Quadrangle:
1295       aFirstColIds = FirstQuadrangleIds;
1296       aLastColIds  = LastQuadrangleIds;
1297       break;
1298     case SMDSEntity_Quad_Tetra:
1299       aFirstColIds = FirstTetrahedronIds;
1300       aLastColIds  = LastTetrahedronIds;
1301       break;
1302     case SMDSEntity_Quad_Pyramid:
1303       aFirstColIds = FirstPyramidIds;
1304       aLastColIds  = LastPyramidIds;
1305       break;
1306     case SMDSEntity_Quad_Penta:
1307       aFirstColIds = FirstPentahedronIds;
1308       aLastColIds  = LastPentahedronIds;
1309       break;
1310     case SMDSEntity_Quad_Hexa:
1311     case SMDSEntity_TriQuad_Hexa:
1312       aFirstColIds = FirstHexahedronIds;
1313       aLastColIds  = LastHexahedronIds;
1314       break;
1315     }
1316
1317     // fill the First and the Last columns
1318     for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
1319       myTable->item( i, 0 )->setText( aListCorners[ aFirstColIds[i] ] );
1320
1321     for (int i = 0, iEnd = myTable->rowCount(); i < iEnd; i++)
1322       myTable->item( i, 2 )->setText( aListCorners[ aLastColIds[i] ] );
1323   }
1324   else
1325   {
1326     // clear table
1327     for ( int row = 0; row < myTable->rowCount(); row++ )
1328       for ( int col = 0; col < myTable->columnCount(); col++ )
1329         if ( QTableWidgetItem* aTWI = myTable->item(row, col) ) aTWI->setText("");
1330
1331     myTable->setEnabled( false );
1332   }
1333 }
1334
1335 //=================================================================================
1336 // function : onTableActivate()
1337 // purpose  :
1338 //=================================================================================
1339
1340 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol )
1341 {
1342   myCurrentLineEdit = 0;
1343   displaySimulation();
1344   updateButtons();
1345 }
1346
1347 //=================================================================================
1348 // function : onCellTextChange()
1349 // purpose  :
1350 //=================================================================================
1351
1352 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
1353 {
1354   myCurrentLineEdit = 0;
1355   displaySimulation();
1356   updateButtons();
1357 }
1358
1359 //=================================================================================
1360 // function : keyPressEvent()
1361 // purpose  :
1362 //=================================================================================
1363
1364 void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
1365 {
1366   QDialog::keyPressEvent( e );
1367   if ( e->isAccepted() )
1368     return;
1369
1370   if ( e->key() == Qt::Key_F1 ) {
1371     e->accept();
1372     ClickOnHelp();
1373   }
1374 }
1375
1376 //=======================================================================
1377 //function : updateButtons
1378 //purpose  : 
1379 //=======================================================================
1380
1381 void SMESHGUI_AddQuadraticElementDlg::updateButtons()
1382 {
1383   bool valid = IsValid();
1384   buttonOk->setEnabled( valid );
1385   buttonApply->setEnabled( valid );
1386 }
1387
1388 //=================================================================================
1389 // function : isValid
1390 // purpose  :
1391 //=================================================================================
1392
1393 bool SMESHGUI_AddQuadraticElementDlg::isValid()
1394 {
1395   if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
1396     SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );
1397     return false;
1398   }
1399   return true;
1400 }