Salome HOME
introduce biquadratic quadratic pentahedron (18 nodes)
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AddQuadraticElementDlg.cxx
index 3a72de15241aab33b4caa01ea809753d0067e84d..4193be407c39abb92198d6e1f6867f1f2446423f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -55,6 +55,8 @@
 
 #include <SalomeApp_Application.h>
 
+#include <Qtx.h>
+
 // IDL includes
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
 
 namespace
 {
+
+  // Define the sequences of ids
+  static int FirstEdgeIds[] = {0};
+  static int LastEdgeIds[] =  {1};
+
+  static int FirstTriangleIds[] = {0,1,2};
+  static int LastTriangleIds[] =  {1,2,0};
+
+  static int FirstQuadrangleIds[] = {0,1,2,3};
+  static int LastQuadrangleIds[] =  {1,2,3,0};
+
+  static int FirstTetrahedronIds[] = {0,1,2,3,3,3};
+  static int LastTetrahedronIds[] =  {1,2,0,0,1,2};
+
+  static int FirstPyramidIds[] = {0,1,2,3,4,4,4,4};
+  static int LastPyramidIds[] =  {1,2,3,0,0,1,2,3};
+
+  static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2};
+  static int LastPentahedronIds[] =  {1,2,0,4,5,3,3,4,5};
+
+  static int FirstHexahedronIds[] = {0,1,2,3,4,5,6,7,0,1,2,3};
+  static int LastHexahedronIds[] =  {1,2,3,0,5,6,7,4,4,5,6,7};
+
+  static std::vector<int> FirstPolygonIds;
+  static std::vector<int> LastPolygonIds;
+
   void ReverseConnectivity( std::vector<vtkIdType> & ids, SMDSAbs_EntityType type,
                             bool toReverse, // inverse element
                             bool toVtkOrder ) // smds connectivity to vtk one
   {
     if ( toReverse ) // first reverse smds order
     {
-      const std::vector<int>& index = SMDS_MeshCell::reverseSmdsOrder(type);
+      const std::vector<int>& index = SMDS_MeshCell::reverseSmdsOrder(type, ids.size());
       SMDS_MeshCell::applyInterlace( index, ids );
     }
     if ( toVtkOrder ) // from smds to vtk connectivity
@@ -111,7 +139,8 @@ namespace
 }
 namespace SMESH
 {
-  class TElementSimulation {
+  class TElementSimulationQuad
+  {
     SalomeApp_Application* myApplication;
     SUIT_ViewWindow* myViewWindow;
     SVTK_ViewWindow* myVTKViewWindow;
@@ -121,14 +150,14 @@ namespace SMESH
     vtkUnstructuredGrid* myGrid;
     //vtkProperty* myBackProp, *myProp;
 
-    //vtkFloatingPointType myRGB[3], myBackRGB[3];
+    //double myRGB[3], myBackRGB[3];
 
     SALOME_Actor* myFaceOrientation;
     vtkPolyDataMapper* myFaceOrientationDataMapper;
     SMESH_FaceOrientationFilter* myFaceOrientationFilter;
 
   public:
-    TElementSimulation (SalomeApp_Application* theApplication)
+    TElementSimulationQuad (SalomeApp_Application* theApplication)
     {
       myApplication = theApplication;
       SUIT_ViewManager* mgr = theApplication->activeViewManager();
@@ -140,23 +169,25 @@ namespace SMESH
 
       // Create and display actor
       myMapper = vtkDataSetMapper::New();
-      myMapper->SetInput(myGrid);
+      myMapper->SetInputData(myGrid);
 
       myPreviewActor = SALOME_Actor::New();
       myPreviewActor->PickableOff();
       myPreviewActor->VisibilityOff();
       myPreviewActor->SetMapper(myMapper);
 
+      QColor ffc, bfc;
+      int delta;
       vtkProperty* myProp = vtkProperty::New();
-      vtkFloatingPointType aRGB[3], aBackRGB[3];
-      GetColor( "SMESH", "fill_color", aRGB[0], aRGB[1], aRGB[2], QColor( 0, 170, 255 ) );
-      myProp->SetColor( aRGB[0], aRGB[1], aRGB[2] );
+      SMESH::GetColor( "SMESH", "preview_color", ffc, delta, "0, 255, 0|-100" ) ;
+   
+      myProp->SetColor( ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255. );
       myPreviewActor->SetProperty( myProp );
       myProp->Delete();
 
       vtkProperty* myBackProp = vtkProperty::New();
-      GetColor( "SMESH", "backface_color", aBackRGB[0], aBackRGB[1], aBackRGB[2], QColor( 0, 0, 255 ) );
-      myBackProp->SetColor( aBackRGB[0], aBackRGB[1], aBackRGB[2] );
+      bfc = Qtx::mainColorToSecondary(ffc, delta);
+      myBackProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
       myPreviewActor->SetBackfaceProperty( myBackProp );
       myBackProp->Delete();
 
@@ -164,10 +195,10 @@ namespace SMESH
 
       // Orientation of faces
       myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
-      myFaceOrientationFilter->SetInput(myGrid);
+      myFaceOrientationFilter->SetInputData(myGrid);
 
       myFaceOrientationDataMapper = vtkPolyDataMapper::New();
-      myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput());
+      myFaceOrientationDataMapper->SetInputConnection(myFaceOrientationFilter->GetOutputPort());
 
       myFaceOrientation = SALOME_Actor::New();
       myFaceOrientation->PickableOff();
@@ -175,6 +206,7 @@ namespace SMESH
       myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
 
       vtkProperty* anOrientationProp = vtkProperty::New();
+      double aRGB[3];
       GetColor( "SMESH", "orientation_color", aRGB[0], aRGB[1], aRGB[2], QColor( 255, 255, 255 ) );
       anOrientationProp->SetColor( aRGB[0], aRGB[1], aRGB[2] );
       myFaceOrientation->SetProperty( anOrientationProp );
@@ -225,7 +257,7 @@ namespace SMESH
     }
 
 
-    ~TElementSimulation()
+    ~TElementSimulationQuad()
     {
       if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
         myVTKViewWindow->RemoveActor(myPreviewActor);
@@ -244,41 +276,17 @@ namespace SMESH
 
       myGrid->Delete();
 
-//       myProp->Delete();
-//       myBackProp->Delete();
+      //       myProp->Delete();
+      //       myBackProp->Delete();
     }
   };
 }
 
-
-// Define the sequences of ids
-static int FirstEdgeIds[] = {0};
-static int LastEdgeIds[] =  {1};
-
-static int FirstTriangleIds[] = {0,1,2};
-static int LastTriangleIds[] =  {1,2,0};
-
-static int FirstQuadrangleIds[] = {0,1,2,3};
-static int LastQuadrangleIds[] =  {1,2,3,0};
-
-static int FirstTetrahedronIds[] = {0,1,2,3,3,3};
-static int LastTetrahedronIds[] =  {1,2,0,0,1,2};
-
-static int FirstPyramidIds[] = {0,1,2,3,4,4,4,4};
-static int LastPyramidIds[] =  {1,2,3,0,0,1,2,3};
-
-static int FirstPentahedronIds[] = {0,1,2,3,4,5,0,1,2};
-static int LastPentahedronIds[] =  {1,2,0,4,5,3,3,4,5};
-
-static int FirstHexahedronIds[] = {0,1,2,3,4,5,6,7,0,1,2,3};
-static int LastHexahedronIds[] =  {1,2,3,0,5,6,7,4,4,5,6,7};
-
 /*!
   \class BusyLocker
   \brief Simple 'busy state' flag locker.
   \internal
 */
-
 class BusyLocker
 {
 public:
@@ -295,7 +303,6 @@ private:
   \brief Simple editable table item.
   \internal
 */
-
 class IdEditItem: public QTableWidgetItem
 {
 public:
@@ -325,14 +332,14 @@ QWidget* IdEditItem::createEditor() const
 // function : SMESHGUI_AddQuadraticElementDlg()
 // purpose  : constructor
 //=================================================================================
+
 SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theModule,
                                                                   const SMDSAbs_EntityType theType )
   : QDialog( SMESH::GetDesktop( theModule ) ),
     mySMESHGUI( theModule ),
     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
-    myGeomType( theType ),
-    //myType( theType ),
-    myBusy( false )
+    myBusy( false ),
+    myGeomType( theType )
 {
   setModal( false );
   setAttribute( Qt::WA_DeleteOnClose, true );
@@ -340,7 +347,7 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM
   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
     (SUIT_Session::session()->activeApplication());
 
-  mySimulation = new SMESH::TElementSimulation (anApp);
+  mySimulation = new SMESH::TElementSimulationQuad (anApp);
   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
 
   QString anElementName;
@@ -355,9 +362,15 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM
   case SMDSEntity_Quad_Quadrangle:
     anElementName = QString("QUADRATIC_QUADRANGLE");
     break;
+  case SMDSEntity_Quad_Polygon:
+    anElementName = QString("QUADRATIC_POLYGON");
+    break;
   case SMDSEntity_BiQuad_Quadrangle:
     anElementName = QString("BIQUADRATIC_QUADRANGLE");
     break;
+  case SMDSEntity_BiQuad_Triangle:
+    anElementName = QString("BIQUADRATIC_TRIANGLE");
+    break;
   case SMDSEntity_Quad_Tetra:
     anElementName = QString("QUADRATIC_TETRAHEDRON");
     break;
@@ -367,6 +380,9 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM
   case SMDSEntity_Quad_Penta:
     anElementName = QString("QUADRATIC_PENTAHEDRON");
     break;
+  case SMDSEntity_BiQuad_Penta:
+    anElementName = QString("BIQUADRATIC_PENTAHEDRON");
+    break;
   case SMDSEntity_Quad_Hexa:
     anElementName = QString("QUADRATIC_HEXAHEDRON");
     break;
@@ -501,6 +517,7 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM
 // function : ~SMESHGUI_AddQuadraticElementDlg()
 // purpose  : Destroys the object and frees any allocated resources
 //=================================================================================
+
 SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
 {
   delete mySimulation;
@@ -510,6 +527,7 @@ SMESHGUI_AddQuadraticElementDlg::~SMESHGUI_AddQuadraticElementDlg()
 // function : Init()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::Init()
 {
   myRadioButton1->setChecked(true);
@@ -522,7 +540,7 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
   myNbMidFaceNodes = 0;
   myNbCenterNodes = 0;
 
-  int aNumRows;
+  int aNumRows = 0;
 
   switch (myGeomType) {
   case SMDSEntity_Quad_Edge:
@@ -535,6 +553,12 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
     myNbCorners = 3;
     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_triangles
     break;
+  case SMDSEntity_BiQuad_Triangle:
+    aNumRows = 3;
+    myNbCorners = 3;
+    myNbCenterNodes = 1;
+    myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_triangles
+    break;
   case SMDSEntity_Quad_Quadrangle:
     aNumRows = 4;
     myNbCorners = 4;
@@ -546,6 +570,11 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
     myNbCenterNodes = 1;
     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_quadrangles
     break;
+  case SMDSEntity_Quad_Polygon:
+    aNumRows = 5;
+    myNbCorners = 0; // no limit
+    myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_polygons
+    break;
   case SMDSEntity_Quad_Tetra:
     aNumRows = 6;
     myNbCorners = 4;
@@ -561,6 +590,12 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
     myNbCorners = 6;
     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pentahedrons
     break;
+  case SMDSEntity_BiQuad_Penta:
+    aNumRows = 9;
+    myNbCorners = 6;
+    myNbMidFaceNodes = 3;
+    myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_pentahedrons
+    break;
   case SMDSEntity_Quad_Hexa:
     aNumRows = 12;
     myNbCorners = 8;
@@ -573,6 +608,7 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
     myNbCenterNodes = 1;
     myHelpFileName = "adding_quadratic_elements_page.html#?"; //Adding_hexahedrons
     break;
+  default:;
   }
 
   myMidFaceLabel       ->setVisible( myNbMidFaceNodes );
@@ -635,6 +671,8 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
   connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(reject()));
   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), SLOT(reject()));
+  connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), SLOT(onOpenView()));
+  connect(mySMESHGUI, SIGNAL (SignalCloseView()), SLOT(onCloseView()));
 
   myCurrentLineEdit = myCornerNodes;
 
@@ -651,13 +689,14 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
 // function : ClickOnApply()
 // purpose  :
 //=================================================================================
-void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
+
+bool SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
 {
   if( !isValid() )
-    return;
+    return false;
 
   if ( mySMESHGUI->isActiveStudyLocked() || myBusy || !IsValid() )
-    return;
+    return false;
 
   BusyLocker lock( myBusy );
 
@@ -671,10 +710,13 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
     break;
   case SMDSEntity_Quad_Triangle:
   case SMDSEntity_Quad_Quadrangle:
+  case SMDSEntity_Quad_Polygon:
+  case SMDSEntity_BiQuad_Triangle:
   case SMDSEntity_BiQuad_Quadrangle:
   case SMDSEntity_Quad_Tetra:
   case SMDSEntity_Quad_Pyramid:
   case SMDSEntity_Quad_Penta:
+  case SMDSEntity_BiQuad_Penta:
   case SMDSEntity_Quad_Hexa:
   case SMDSEntity_TriQuad_Hexa:
     for ( int row = 0; row < myNbCorners; row++ )
@@ -693,11 +735,12 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
       anIds.push_back( aListId[ 0 ].toInt() );
     }
     break;
+  default:;
   }
   if ( myReverseCB->isChecked())
     ReverseConnectivity( anIds, myGeomType, /*toReverse=*/true, /*toVtkOrder=*/false );
 
-  int aNumberOfIds =  anIds.size();
+  int aNumberOfIds = anIds.size();
   SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
   anArrayOfIdeces->length( aNumberOfIds );
 
@@ -720,32 +763,48 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
       SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
       if ( !aGeomGroup->_is_nil() ) {
         int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
-                                             tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
+                                             tr( "MESH_GEOM_GRP_CHOSEN" ).arg( aGroupName ),
                                              tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
-        if ( res == 1 ) return;
+        if ( res == 1 ) return false;
+      }
+      SMESH::SMESH_GroupOnFilter_var aFilterGroup = SMESH::SMESH_GroupOnFilter::_narrow( myGroups[idx-1] );
+      if ( !aFilterGroup->_is_nil() ) {
+        int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
+                                             tr( "MESH_FILTER_GRP_CHOSEN" ).arg( aGroupName ),
+                                             tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
+        if ( res == 1 ) return false;
       }
       aGroup = myGroups[idx-1];
     }
   }
 
-  SMESH::ElementType anElementType;
-  long anElemId = -1;
+  SMESH::ElementType anElementType = SMESH::ALL;
+  long anElemId = -1, nbElemsBefore = 0;
   SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
   switch (myGeomType) {
   case SMDSEntity_Quad_Edge:
     anElementType = SMESH::EDGE;
+    nbElemsBefore = myMesh->NbEdges();
     anElemId = aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
   case SMDSEntity_Quad_Triangle:
   case SMDSEntity_Quad_Quadrangle:
+  case SMDSEntity_BiQuad_Triangle:
   case SMDSEntity_BiQuad_Quadrangle:
     anElementType = SMESH::FACE;
+    nbElemsBefore = myMesh->NbFaces();
     anElemId = aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
+  case SMDSEntity_Quad_Polygon:
+    anElementType = SMESH::FACE;
+    nbElemsBefore = myMesh->NbFaces();
+    anElemId = aMeshEditor->AddQuadPolygonalFace(anArrayOfIdeces.inout()); break;
   case SMDSEntity_Quad_Tetra:
   case SMDSEntity_Quad_Pyramid:
   case SMDSEntity_Quad_Penta:
+  case SMDSEntity_BiQuad_Penta:
   case SMDSEntity_Quad_Hexa:
   case SMDSEntity_TriQuad_Hexa:
     anElementType = SMESH::VOLUME;
+    nbElemsBefore = myMesh->NbVolumes();
     anElemId = aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
   default: break;
   }
@@ -761,7 +820,8 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
       }
     }
     else {
-      SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
+      SMESH::SMESH_GroupOnGeom_var     aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
+      SMESH::SMESH_GroupOnFilter_var aFilterGroup = SMESH::SMESH_GroupOnFilter::_narrow( aGroup );
       if ( !aGeomGroup->_is_nil() ) {
         aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
         if ( !aGroupUsed->_is_nil() && idx > 0 ) {
@@ -769,6 +829,13 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
           SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
         }
       }
+      else if ( !aFilterGroup->_is_nil() ) {
+        aGroupUsed = myMesh->ConvertToStandalone( aFilterGroup );
+        if ( !aGroupUsed->_is_nil() && idx > 0 ) {
+          myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
+          SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
+        }
+      }
       else
         aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
     }
@@ -781,6 +848,24 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
     }
   }
 
+  if ( nbElemsBefore == 0  )
+  {
+    // 1st element of the type has been added, update actor to show this entity
+    unsigned int aMode = myActor->GetEntityMode();
+    switch ( anElementType ) {
+    case SMESH::EDGE:
+      myActor->SetRepresentation(SMESH_Actor::eEdge);
+      myActor->SetEntityMode( aMode |= SMESH_Actor::eEdges ); break;
+    case SMESH::FACE:
+      myActor->SetRepresentation(SMESH_Actor::eSurface);
+      myActor->SetEntityMode( aMode |= SMESH_Actor::eFaces ); break;
+    case SMESH::VOLUME:
+      myActor->SetRepresentation(SMESH_Actor::eSurface);
+      myActor->SetEntityMode( aMode |= SMESH_Actor::eVolumes ); break;
+    default:;
+    }
+  }
+
   SALOME_ListIO aList; aList.Append( myActor->getIO() );
   mySelector->ClearIndex();
   mySelectionMgr->setSelectedObjects( aList, false );
@@ -794,22 +879,26 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
   updateButtons();
 
   SMESHGUI::Modified();
+
+  return true;
 }
 
 //=================================================================================
 // function : ClickOnOk()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
 {
-  ClickOnApply();
-  reject();
+  if ( ClickOnApply() )
+    reject();
 }
 
 //=================================================================================
 // function : reject()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::reject()
 {
   mySelectionMgr->clearSelected();
@@ -822,10 +911,40 @@ void SMESHGUI_AddQuadraticElementDlg::reject()
   QDialog::reject();
 }
 
+//=================================================================================
+// function : onOpenView()
+// purpose  :
+//=================================================================================
+void SMESHGUI_AddQuadraticElementDlg::onOpenView()
+{
+  if ( mySelector && mySimulation ) {
+    mySimulation->SetVisibility(false);
+    SMESH::SetPointRepresentation(false);
+  }
+  else {
+    mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
+    mySimulation = new SMESH::TElementSimulationQuad(
+      dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
+    ActivateThisDialog();
+  }
+}
+
+//=================================================================================
+// function : onCloseView()
+// purpose  :
+//=================================================================================
+void SMESHGUI_AddQuadraticElementDlg::onCloseView()
+{
+  DeactivateActiveDialog();
+  mySelector = 0;
+  delete mySimulation;
+  mySimulation = 0;
+}
 //=================================================================================
 // function : ClickOnHelp()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
 {
   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
@@ -850,6 +969,7 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
 // function : onTextChange()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
 {
   if (myBusy) return;
@@ -901,6 +1021,7 @@ void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
 // function : SelectionIntoArgument()
 // purpose  : Called when selection has changed
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
 {
   if (myBusy) return;
@@ -922,7 +1043,7 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
 
     // get selected mesh
     SALOME_ListIO aList;
-    mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
+    mySelectionMgr->selectedObjects(aList);
 
     if (aList.Extent() != 1)
     {
@@ -945,20 +1066,24 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
 
   // process groups
   if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
-    SMESH::ElementType anElementType;
+    SMESH::ElementType anElementType = SMESH::ALL;
     switch ( myGeomType ) {
     case SMDSEntity_Quad_Edge:
       anElementType = SMESH::EDGE; break;
     case SMDSEntity_Quad_Triangle:
     case SMDSEntity_Quad_Quadrangle:
+    case SMDSEntity_Quad_Polygon:
+    case SMDSEntity_BiQuad_Triangle:
     case SMDSEntity_BiQuad_Quadrangle:
       anElementType = SMESH::FACE; break;
     case SMDSEntity_Quad_Tetra:
     case SMDSEntity_Quad_Pyramid:
     case SMDSEntity_Quad_Penta:
+    case SMDSEntity_BiQuad_Penta:
     case SMDSEntity_Quad_Hexa:
     case SMDSEntity_TriQuad_Hexa:
       anElementType = SMESH::VOLUME; break;
+    default:;
     }
     myGroups.clear();
     ComboBox_GroupName->clear();
@@ -1008,11 +1133,12 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
 // function : displaySimulation()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
 {
   if ( IsValid() )
   {
-    SMESH::TElementSimulation::TVTKIds anIds;
+    SMESH::TElementSimulationQuad::TVTKIds anIds;
 
     // Collect ids from the dialog
     int anID;
@@ -1068,6 +1194,7 @@ void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
 // function : SetCurrentSelection()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::SetCurrentSelection()
 {
   QPushButton* send = (QPushButton*)sender();
@@ -1091,6 +1218,7 @@ void SMESHGUI_AddQuadraticElementDlg::SetCurrentSelection()
 // function : DeactivateActiveDialog()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
 {
   if (GroupConstructors->isEnabled()) {
@@ -1107,6 +1235,7 @@ void SMESHGUI_AddQuadraticElementDlg::DeactivateActiveDialog()
 // function : ActivateThisDialog()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
 {
   /* Emit a signal to deactivate the active dialog */
@@ -1129,15 +1258,22 @@ void SMESHGUI_AddQuadraticElementDlg::ActivateThisDialog()
 //=================================================================================
 void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
 {
-  if (GroupConstructors->isEnabled())
-    return;
-  ActivateThisDialog();
+  if ( !GroupConstructors->isEnabled() ) {
+    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
+    if ( aViewWindow && !mySelector && !mySimulation) {
+      mySelector = aViewWindow->GetSelector();
+      mySimulation = new SMESH::TElementSimulationQuad(
+        dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
+    }
+    ActivateThisDialog();
+  }
 }
 
 //=================================================================================
 // function : onReverse()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
 {
   mySimulation->SetVisibility(false);
@@ -1145,11 +1281,11 @@ void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
   updateButtons();
 }
 
-
 //=================================================================================
 // function : IsValid()
 // purpose  :
 //=================================================================================
+
 bool SMESHGUI_AddQuadraticElementDlg::IsValid()
 {
   SMDS_Mesh* aMesh = 0;
@@ -1189,17 +1325,56 @@ bool SMESHGUI_AddQuadraticElementDlg::IsValid()
     okIDs.insert( anID );
   }
 
-  return okIDs.size() == myTable->rowCount() + myNbMidFaceNodes + myNbCenterNodes;
+  return (int) okIDs.size() == myTable->rowCount() + myNbMidFaceNodes + myNbCenterNodes;
 }
 
 //=================================================================================
 // function : UpdateTable()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
 {
   QStringList aListCorners = myCornerNodes->text().split(" ", QString::SkipEmptyParts);
 
+  if ( myGeomType == SMDSEntity_Quad_Polygon )        // POLYGON
+  {
+    if ( aListCorners.count() < 3 )
+      theConersValidity = false;
+
+    if ( aListCorners.count() != myTable->rowCount() && theConersValidity )
+    {
+      // adjust nb of rows for the polygon
+      int oldNbRows = myTable->rowCount();
+      myTable->setRowCount( aListCorners.count() );
+      for ( int row = oldNbRows; row < myTable->rowCount(); row++ )
+      {
+        myTable->setItem( row, 0, new QTableWidgetItem( "" ) );
+        myTable->item( row, 0 )->setFlags(0);
+
+        IdEditItem* anEditItem = new IdEditItem( "" );
+        anEditItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
+        myTable->setItem(row, 1, anEditItem);
+
+        myTable->setItem( row, 2, new QTableWidgetItem( "" ) );
+        myTable->item( row, 2 )->setFlags(0);
+      }
+      myNbCorners = aListCorners.count();
+
+      // fill FirstPolygonIds and LastPolygonIds
+      FirstPolygonIds.resize( aListCorners.count() );
+      LastPolygonIds .resize( aListCorners.count() );
+      for ( int i = 0; i < aListCorners.count(); ++i )
+      {
+        FirstPolygonIds[i] = i;
+        LastPolygonIds [i] = i+1;
+      }
+      LastPolygonIds.back() = 0;
+
+      myNbCorners = aListCorners.count();
+    }
+  }
+
   if ( aListCorners.count() == myNbCorners && theConersValidity )
   {
     myTable->setEnabled( true );
@@ -1208,8 +1383,8 @@ void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
     for ( int row = 0; row < myTable->rowCount(); row++ )
       myTable->item( row, 1 )->setText("");
 
-    int* aFirstColIds;
-    int* aLastColIds;
+    int* aFirstColIds = 0;
+    int* aLastColIds  = 0;
 
     switch (myGeomType) {
     case SMDSEntity_Quad_Edge:
@@ -1217,6 +1392,7 @@ void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
       aLastColIds  = LastEdgeIds;
       break;
     case SMDSEntity_Quad_Triangle:
+    case SMDSEntity_BiQuad_Triangle:
       aFirstColIds = FirstTriangleIds;
       aLastColIds  = LastTriangleIds;
       break;
@@ -1225,6 +1401,10 @@ void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
       aFirstColIds = FirstQuadrangleIds;
       aLastColIds  = LastQuadrangleIds;
       break;
+    case SMDSEntity_Quad_Polygon:
+      aFirstColIds = & FirstPolygonIds[0];
+      aLastColIds  = & LastPolygonIds[0];
+      break;
     case SMDSEntity_Quad_Tetra:
       aFirstColIds = FirstTetrahedronIds;
       aLastColIds  = LastTetrahedronIds;
@@ -1234,6 +1414,7 @@ void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
       aLastColIds  = LastPyramidIds;
       break;
     case SMDSEntity_Quad_Penta:
+    case SMDSEntity_BiQuad_Penta:
       aFirstColIds = FirstPentahedronIds;
       aLastColIds  = LastPentahedronIds;
       break;
@@ -1242,6 +1423,7 @@ void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
       aFirstColIds = FirstHexahedronIds;
       aLastColIds  = LastHexahedronIds;
       break;
+    default:;
     }
 
     // fill the First and the Last columns
@@ -1262,11 +1444,11 @@ void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
   }
 }
 
-
 //=================================================================================
 // function : onTableActivate()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol )
 {
   myCurrentLineEdit = 0;
@@ -1274,11 +1456,11 @@ void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCo
   updateButtons();
 }
 
-
 //=================================================================================
 // function : onCellTextChange()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
 {
   myCurrentLineEdit = 0;
@@ -1290,6 +1472,7 @@ void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
 // function : keyPressEvent()
 // purpose  :
 //=================================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
 {
   QDialog::keyPressEvent( e );
@@ -1302,6 +1485,11 @@ void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
   }
 }
 
+//=======================================================================
+//function : updateButtons
+//purpose  : 
+//=======================================================================
+
 void SMESHGUI_AddQuadraticElementDlg::updateButtons()
 {
   bool valid = IsValid();
@@ -1313,6 +1501,7 @@ void SMESHGUI_AddQuadraticElementDlg::updateButtons()
 // function : isValid
 // purpose  :
 //=================================================================================
+
 bool SMESHGUI_AddQuadraticElementDlg::isValid()
 {
   if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {