Salome HOME
IPAL21120 SIGSEGV on Meshing attached Compound with Automatic Hexadralization
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AddQuadraticElementDlg.cxx
index e101e8878f040cb1b14e47b6137162f29a5e65e9..cf714ae7853dd3017488efb17d9b3d5f197a2f7d 100644 (file)
@@ -1,21 +1,23 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-// 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.
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
+//  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.
 //
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 #include "SMESHGUI_AddQuadraticElementDlg.h"
 
@@ -86,7 +88,7 @@ using namespace std;
 
 namespace SMESH {
 
-  void ReverseConnectivity( vector<int> & ids, int type )
+  void ReverseConnectivity( vector<vtkIdType> & ids, int type )
   {
     // for reverse connectivity of other types keeping the first id, see
     // void SMESH_VisualObjDef::buildElemPrs() in SMESH_Object.cxx:900
@@ -134,7 +136,7 @@ namespace SMESH {
       reverse( ids.begin(), ids.end() );
     }
     else {
-      vector<int> aRevIds( ids.size() );
+      vector<vtkIdType> aRevIds( ids.size() );
       for ( int i = 0; i < ids.size(); i++)
         aRevIds[ i ] = ids[ conn[ i ]];
       ids = aRevIds;
@@ -220,8 +222,8 @@ namespace SMESH {
         aType = VTK_CONVEX_POINT_SET;
         break;
       case QUAD_PENTAHEDRON:
-        //aType = VTK_QUADRATIC_WEDGE; // NOT SUPPORTED IN VTK4.2
-        aType = VTK_CONVEX_POINT_SET;
+        aType = VTK_QUADRATIC_WEDGE;
+        //aType = VTK_CONVEX_POINT_SET;
         break; 
       case QUAD_HEXAHEDRON:
         aType = VTK_QUADRATIC_HEXAHEDRON;
@@ -236,9 +238,13 @@ namespace SMESH {
       }
       else {
         // VTK cell connectivity opposites the MED one for volumic elements
-        if ( theIds.size() > 8 ? !theReverse : theReverse ) {
-          ReverseConnectivity( theIds, theType );
+        if( aType != VTK_QUADRATIC_WEDGE) {
+          if ( theIds.size() > 8 ? !theReverse : theReverse ) {
+            ReverseConnectivity( theIds, theType );
+          }
         }
+        else if(theReverse)
+          ReverseConnectivity( theIds, theType );          
       }
             
       myGrid->Reset();
@@ -316,6 +322,54 @@ 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:
+  //! Constructor. Sets passed boolean flag to \c true.
+  BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
+  //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
+  ~BusyLocker() { myBusy = false; }
+private:
+  bool& myBusy; //! External 'busy state' boolean flag
+};
+
+/*!
+  \class IdEditItem
+  \brief Simple editable table item.
+  \internal
+*/
+
+class IdEditItem: public QTableItem
+{
+public:
+  IdEditItem(QTable*, EditType, const QString& );
+  ~IdEditItem();
+
+  QWidget* createEditor() const;
+};
+
+
+IdEditItem::IdEditItem(QTable* table, EditType et, const QString& text )
+  : QTableItem( table, et, text )
+{
+}
+
+IdEditItem::~IdEditItem()
+{
+}
+
+QWidget* IdEditItem::createEditor() const
+{
+  QLineEdit *aLineEdit = new QLineEdit(text(), table()->viewport());
+  aLineEdit->setValidator( new SMESHGUI_IdValidator(table()->viewport(), "validator", 1) );
+  return aLineEdit;
+}
 
 //=================================================================================
 // function : SMESHGUI_AddQuadraticElementDlg()
@@ -325,11 +379,12 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM
                                                                  const int theType,
                                                                  const char* name,
                                                                   bool modal, WFlags fl)
-     : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
-                WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
-     mySMESHGUI( theModule ),
-     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
-     myType( theType )
+  : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
+            WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
+    mySMESHGUI( theModule ),
+    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
+    myType( theType ),
+    myBusy( false )
 {
   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
     (SUIT_Session::session()->activeApplication());
@@ -448,17 +503,17 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM
   buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
   buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
   buttonCancel->setAutoDefault(TRUE);
-  aGroupButtonsLayout->addWidget(buttonCancel, 0, 1);
+  aGroupButtonsLayout->addWidget(buttonCancel, 0, 3);
   buttonApply = new QPushButton(GroupButtons, "buttonApply");
   buttonApply->setText(tr("SMESH_BUT_APPLY" ));
   buttonApply->setAutoDefault(TRUE);
-  aGroupButtonsLayout->addWidget(buttonApply, 0, 0);
-  aGroupButtonsLayout->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 3);
+  aGroupButtonsLayout->addWidget(buttonApply, 0, 1);
+  aGroupButtonsLayout->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
   buttonOk = new QPushButton(GroupButtons, "buttonOk");
   buttonOk->setText(tr("SMESH_BUT_APPLY_AND_CLOSE" ));
   buttonOk->setAutoDefault(TRUE);
   buttonOk->setDefault(TRUE);
-  aGroupButtonsLayout->addWidget(buttonOk, 0, 2);
+  aGroupButtonsLayout->addWidget(buttonOk, 0, 0);
   buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
   buttonHelp->setText(tr("SMESH_BUT_HELP" ));
   buttonHelp->setAutoDefault(TRUE);
@@ -487,7 +542,6 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
 {
   GroupArguments->show();
   myRadioButton1->setChecked(TRUE);
-  myIsEditCorners = true;
   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
   
   myActor = 0;
@@ -553,11 +607,11 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
   myTable->setEnabled( false );
   
   for ( int row = 0; row < myTable->numRows(); row++ )
-    {
-      SMESHGUI_IdEditItem* anEditItem = new SMESHGUI_IdEditItem( myTable, QTableItem::OnTyping, "" );
-      anEditItem->setReplaceable(false);
-      myTable->setItem(row, 1, anEditItem);
-    }
+  {
+    IdEditItem* anEditItem = new IdEditItem( myTable, QTableItem::OnTyping, "" );
+    anEditItem->setReplaceable(true);
+    myTable->setItem(row, 1, anEditItem);
+  }
   
   /* signals and slots connections */
   connect(mySelectButton, SIGNAL(clicked()), SLOT(SetEditCorners()));
@@ -583,8 +637,6 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     aViewWindow->SetSelectionMode( NodeSelection );
 
-  myBusy = false;
-
   SetEditCorners();
 }
 
@@ -594,68 +646,66 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
 //=================================================================================
 void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
 {
-  if (IsValid() && !mySMESHGUI->isActiveStudyLocked()) {
-    myBusy = true;
-    
-    vector<int> anIds;
-
-    switch (myType) {
-    case QUAD_EDGE:
-      anIds.push_back(myTable->text(0, 0).toInt());
-      anIds.push_back(myTable->text(0, 2).toInt());
-      anIds.push_back(myTable->text(0, 1).toInt());
-      break;
-    case QUAD_TRIANGLE:
-    case QUAD_QUADRANGLE:
-    case QUAD_TETRAHEDRON:
-    case QUAD_PYRAMID:
-    case QUAD_PENTAHEDRON:
-    case QUAD_HEXAHEDRON:
-      for ( int row = 0; row < myNbCorners; row++ )
-       anIds.push_back(myTable->text(row, 0).toInt());
-      for ( int row = 0; row < myTable->numRows(); row++ )
-       anIds.push_back(myTable->text(row, 1).toInt());
-      break;
-    }
-    if ( myReverseCB->isChecked())
-      SMESH::ReverseConnectivity( anIds, myType );
-    
-    int aNumberOfIds =  anIds.size();
-    SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
-    anArrayOfIdeces->length( aNumberOfIds );
-    
-    for (int i = 0; i < aNumberOfIds; i++)
-      anArrayOfIdeces[i] = anIds[ i ];
-
-    SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
-    switch (myType) {
-    case QUAD_EDGE:
-      aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
-    case QUAD_TRIANGLE:
-    case QUAD_QUADRANGLE:
-      aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
-    case QUAD_TETRAHEDRON:
-    case QUAD_PYRAMID:
-    case QUAD_PENTAHEDRON: 
-    case QUAD_HEXAHEDRON:
-      aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
-    }
-    
-    SALOME_ListIO aList; aList.Append( myActor->getIO() );
-    mySelector->ClearIndex();
-    mySelectionMgr->setSelectedObjects( aList, false );
+  if ( mySMESHGUI->isActiveStudyLocked() || myBusy || !IsValid() )
+    return;
 
-    SMESH::UpdateView();
-    mySimulation->SetVisibility(false);
+  BusyLocker lock( myBusy );
     
-    buttonOk->setEnabled(false);
-    buttonApply->setEnabled(false);
+  vector<vtkIdType> anIds;
 
-    UpdateTable();
-    SetEditCorners();
-
-    myBusy = false;
+  switch (myType) {
+  case QUAD_EDGE:
+    anIds.push_back(myTable->text(0, 0).toInt());
+    anIds.push_back(myTable->text(0, 2).toInt());
+    anIds.push_back(myTable->text(0, 1).toInt());
+    break;
+  case QUAD_TRIANGLE:
+  case QUAD_QUADRANGLE:
+  case QUAD_TETRAHEDRON:
+  case QUAD_PYRAMID:
+  case QUAD_PENTAHEDRON:
+  case QUAD_HEXAHEDRON:
+    for ( int row = 0; row < myNbCorners; row++ )
+      anIds.push_back(myTable->text(row, 0).toInt());
+    for ( int row = 0; row < myTable->numRows(); row++ )
+      anIds.push_back(myTable->text(row, 1).toInt());
+    break;
   }
+  if ( myReverseCB->isChecked())
+    SMESH::ReverseConnectivity( anIds, myType );
+  
+  int aNumberOfIds =  anIds.size();
+  SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
+  anArrayOfIdeces->length( aNumberOfIds );
+  
+  for (int i = 0; i < aNumberOfIds; i++)
+    anArrayOfIdeces[i] = anIds[ i ];
+  
+  SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
+  switch (myType) {
+  case QUAD_EDGE:
+    aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
+  case QUAD_TRIANGLE:
+  case QUAD_QUADRANGLE:
+    aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
+  case QUAD_TETRAHEDRON:
+  case QUAD_PYRAMID:
+  case QUAD_PENTAHEDRON: 
+  case QUAD_HEXAHEDRON:
+    aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
+  }
+  
+  SALOME_ListIO aList; aList.Append( myActor->getIO() );
+  mySelector->ClearIndex();
+  mySelectionMgr->setSelectedObjects( aList, false );
+  
+  mySimulation->SetVisibility(false);
+  SMESH::UpdateView();
+  
+  UpdateTable();
+  SetEditCorners();
+
+  updateButtons();
 }
 
 //=================================================================================
@@ -666,7 +716,6 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
 {
   ClickOnApply();
   ClickOnCancel();
-  return;
 }
 
 //=================================================================================
@@ -683,7 +732,6 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnCancel()
   disconnect(mySelectionMgr, 0, this, 0);
   mySMESHGUI->ResetState();
   reject();
-  return;
 }
 
 //=================================================================================
@@ -696,13 +744,13 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
   if (app) 
     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
   else {
-               QString platform;
+    QString platform;
 #ifdef WIN32
-               platform = "winapplication";
+    platform = "winapplication";
 #else
-               platform = "application";
+    platform = "application";
 #endif
-    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
+    SUIT_MessageBox::warn1(this, QObject::tr("WRN_WARNING"),
                           QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
                           arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
                           QObject::tr("BUT_OK"));
@@ -716,11 +764,8 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
 void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
 {
   if (myBusy) return;
-  myBusy = true;
+  BusyLocker lock( myBusy );
   
-  buttonOk->setEnabled(false);
-  buttonApply->setEnabled(false);
-
   mySimulation->SetVisibility(false);
 
   // hilight entered nodes
@@ -734,13 +779,15 @@ void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
     QStringList aListId = QStringList::split(" ", theNewText, false);
     bool allOk = true;
     for (int i = 0; i < aListId.count(); i++) {
-      if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
+      if ( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
+      {
        newIndices.Add( n->GetID() );
+      }
       else
-       {
-         allOk = false;
-         break;
-       }
+      {
+       allOk = false;
+       break;
+      }
     }
     
     mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
@@ -750,16 +797,9 @@ void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
     if ( sender() == myCornerNodes )
       UpdateTable( allOk );
   }
-  
-  if( IsValid() ) {
-    buttonOk->setEnabled(true);
-    buttonApply->setEnabled(true);
-  }
 
-  if ( sender() == myTable )
-    displaySimulation();
-  
-  myBusy = false;
+  updateButtons();
+  displaySimulation();
 }
 
 //=================================================================================
@@ -769,73 +809,65 @@ void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
 void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
 {
   if (myBusy) return;
+  BusyLocker lock( myBusy );
   
   if ( myIsEditCorners )
+  {
+    // clear
+    myActor = 0;
+    
+    myCornerNodes->setText("");
+    
+    if (!GroupButtons->isEnabled()) // inactive
+      return;
+    
+    mySimulation->SetVisibility(false);
+    
+    // get selected mesh
+    SALOME_ListIO aList;
+    mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
+    
+    if (aList.Extent() != 1)
     {
-      // clear
-      myActor = 0;
-      
-      myBusy = true;
-      myCornerNodes->setText("");
-      myBusy = false;
-      
-      if (!GroupButtons->isEnabled()) // inactive
-       return;
-      
-      buttonOk->setEnabled(false);
-      buttonApply->setEnabled(false);
-      
-      mySimulation->SetVisibility(false);
-      
-      // get selected mesh
-      SALOME_ListIO aList;
-      mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
-      
-      if (aList.Extent() != 1)
-       {
-         UpdateTable();
-         return;
-       }
-      
-      Handle(SALOME_InteractiveObject) anIO = aList.First();
-      myMesh = SMESH::GetMeshByIO(anIO);
-      if (myMesh->_is_nil())
-       return;
-      
-      myActor = SMESH::FindActorByEntry(anIO->getEntry());
-  
+      UpdateTable();
+      updateButtons();
+      return;
     }
+    
+    Handle(SALOME_InteractiveObject) anIO = aList.First();
+    myMesh = SMESH::GetMeshByIO(anIO);
+    if (myMesh->_is_nil()) {
+      updateButtons();
+      return;
+    }
+    
+    myActor = SMESH::FindActorByEntry(anIO->getEntry());
+    
+  }
   
-  if (!myActor)
+  if (!myActor) {
+    updateButtons();
     return;
+  }
   
   // get selected nodes
   QString aString = "";
   int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
   
   if ( myIsEditCorners )
-    {
-      myBusy = true;
-      myCornerNodes->setText(aString);
-      myBusy = false;
-      
-      UpdateTable();
-    }
+  {
+    myCornerNodes->setText(aString);
+    
+    UpdateTable();
+  }
   else if ( myTable->isEnabled() && nbNodes == 1 )
-    {
-      myBusy = true;
-      int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
-      if ( theCol == 1 )
-       myTable->setText(theRow, 1, aString);
-      myBusy = false;
-    }
+  {
+    int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
+    if ( theCol == 1 )
+      myTable->setText(theRow, 1, aString);
+  }
   
-  if ( IsValid() )
-    {
-      buttonOk->setEnabled( true );
-      buttonApply->setEnabled( true );
-    }
-
+  updateButtons();
   displaySimulation();
 }
 
@@ -845,42 +877,47 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
 //=================================================================================
 void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
 {
-  if (!myIsEditCorners) {
+  if ( IsValid() )
+  {
     SMESH::TElementSimulation::TVTKIds anIds;
     
     // Collect ids from the dialog
     int anID;
     bool ok;
     int aDisplayMode = VTK_SURFACE;
-
+    
     if ( myType == QUAD_EDGE )
-      {
-       anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 0).toInt() ) );
-       anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 2).toInt() ) );
-       anID = (myTable->text(0, 1)).toInt(&ok);
-       if (!ok) anID = (myTable->text(0, 0)).toInt();
-       anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
-       aDisplayMode = VTK_WIREFRAME;
-      }
+    {
+      anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 0).toInt() ) );
+      anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(0, 2).toInt() ) );
+      anID = (myTable->text(0, 1)).toInt(&ok);
+      if (!ok) anID = (myTable->text(0, 0)).toInt();
+      anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
+      aDisplayMode = VTK_WIREFRAME;
+    }
     else
+    {
+      for ( int row = 0; row < myNbCorners; row++ )
+       anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(row, 0).toInt() ) );
+      
+      for ( int row = 0; row < myTable->numRows(); row++ )
       {
-       for ( int row = 0; row < myNbCorners; row++ )
-         anIds.push_back( myActor->GetObject()->GetNodeVTKId( myTable->text(row, 0).toInt() ) );
-       
-       for ( int row = 0; row < myTable->numRows(); row++ )
-         {
-           anID = (myTable->text(row, 1)).toInt(&ok);
-           if (!ok) {
-             anID = (myTable->text(row, 0)).toInt();
-             aDisplayMode = VTK_WIREFRAME;
-           }
-           anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
-         }
+       anID = (myTable->text(row, 1)).toInt(&ok);
+       if (!ok) {
+         anID = (myTable->text(row, 0)).toInt();
+         aDisplayMode = VTK_WIREFRAME;
+       }
+       anIds.push_back( myActor->GetObject()->GetNodeVTKId(anID) );
       }
+    }
     
     mySimulation->SetPosition(myActor,myType,anIds,aDisplayMode,myReverseCB->isChecked());
-    SMESH::UpdateView();
   }
+  else
+  {
+    mySimulation->SetVisibility(false);
+  }
+  SMESH::UpdateView();
 }
 
 //=================================================================================
@@ -891,8 +928,8 @@ void SMESHGUI_AddQuadraticElementDlg::SetEditCorners()
 {
   myCornerNodes->setFocus();
   myIsEditCorners = true;
-  
   SelectionIntoArgument();
+  updateButtons();
 }
 
 //=================================================================================
@@ -940,7 +977,6 @@ void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
   if (GroupConstructors->isEnabled())
     return;
   ActivateThisDialog();
-  return;
 }
 
 //=================================================================================
@@ -951,7 +987,6 @@ void SMESHGUI_AddQuadraticElementDlg::closeEvent (QCloseEvent*)
 {
   /* same than click on cancel button */
   ClickOnCancel();
-  return;
 }
 
 //=================================================================================
@@ -970,13 +1005,9 @@ void SMESHGUI_AddQuadraticElementDlg::hideEvent (QHideEvent*)
 //=================================================================================
 void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
 {
-  if (!IsValid())
-    return;
-
-  if (state >= 0) {
-    mySimulation->SetVisibility(false);
-    displaySimulation();
-  }
+  mySimulation->SetVisibility(false);
+  displaySimulation();
+  updateButtons();
 }
 
 
@@ -995,15 +1026,15 @@ bool SMESHGUI_AddQuadraticElementDlg::IsValid()
   bool ok;
   
   for ( int row = 0; row < myTable->numRows(); row++ )
-    {
-      int anID =  (myTable->text(row, 1)).toInt(&ok);
-      if ( !ok )
-       return false;
-      
-      const SMDS_MeshNode * aNode = aMesh->FindNode(anID);
-      if ( !aNode )
-       return false;
-    }
+  {
+    int anID =  (myTable->text(row, 1)).toInt(&ok);
+    if ( !ok )
+      return false;
+    
+    const SMDS_MeshNode * aNode = aMesh->FindNode(anID);
+    if ( !aNode )
+      return false;
+  }
   
   return true;
 }
@@ -1017,63 +1048,63 @@ void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
   QStringList aListCorners = QStringList::split(" ", myCornerNodes->text(), false);
   
   if ( aListCorners.count() == myNbCorners && theConersValidity )
-    {
-      myTable->setEnabled( true );
-      
-      // clear the Middle column 
-      for ( int row = 0; row < myTable->numRows(); row++ )
-       myTable->setText( row, 1, "");
-      
-      int* aFirstColIds;
-      int* aLastColIds;
-
-      switch (myType) {
-      case QUAD_EDGE:
-       aFirstColIds = FirstEdgeIds;
-       aLastColIds  = LastEdgeIds;
-       break;
-      case QUAD_TRIANGLE:
-       aFirstColIds = FirstTriangleIds;
-       aLastColIds  = LastTriangleIds;
-       break;
-      case QUAD_QUADRANGLE:
-       aFirstColIds = FirstQuadrangleIds;
-       aLastColIds  = LastQuadrangleIds;
-       break;
-      case QUAD_TETRAHEDRON:
-       aFirstColIds = FirstTetrahedronIds;
-       aLastColIds  = LastTetrahedronIds;
-       break;
-      case QUAD_PYRAMID:
-       aFirstColIds = FirstPyramidIds;
-       aLastColIds  = LastPyramidIds;
-       break;
-      case QUAD_PENTAHEDRON:
-       aFirstColIds = FirstPentahedronIds;
-       aLastColIds  = LastPentahedronIds;
-       break; 
-      case QUAD_HEXAHEDRON:
-       aFirstColIds = FirstHexahedronIds;
-       aLastColIds  = LastHexahedronIds;
-       break;
-      }
-      
-      // fill the First and the Last columns
-      for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++)
-       myTable->setText( i, 0, aListCorners[ aFirstColIds[i] ] );
-      
-      for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++)
-       myTable->setText( i, 2, aListCorners[ aLastColIds[i] ] );
+  {
+    myTable->setEnabled( true );
+    
+    // clear the Middle column 
+    for ( int row = 0; row < myTable->numRows(); row++ )
+      myTable->setText( row, 1, "");
+    
+    int* aFirstColIds;
+    int* aLastColIds;
+    
+    switch (myType) {
+    case QUAD_EDGE:
+      aFirstColIds = FirstEdgeIds;
+      aLastColIds  = LastEdgeIds;
+      break;
+    case QUAD_TRIANGLE:
+      aFirstColIds = FirstTriangleIds;
+      aLastColIds  = LastTriangleIds;
+      break;
+    case QUAD_QUADRANGLE:
+      aFirstColIds = FirstQuadrangleIds;
+      aLastColIds  = LastQuadrangleIds;
+      break;
+    case QUAD_TETRAHEDRON:
+      aFirstColIds = FirstTetrahedronIds;
+      aLastColIds  = LastTetrahedronIds;
+      break;
+    case QUAD_PYRAMID:
+      aFirstColIds = FirstPyramidIds;
+      aLastColIds  = LastPyramidIds;
+      break;
+    case QUAD_PENTAHEDRON:
+      aFirstColIds = FirstPentahedronIds;
+      aLastColIds  = LastPentahedronIds;
+      break; 
+    case QUAD_HEXAHEDRON:
+      aFirstColIds = FirstHexahedronIds;
+      aLastColIds  = LastHexahedronIds;
+      break;
     }
+    
+    // fill the First and the Last columns
+    for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++)
+      myTable->setText( i, 0, aListCorners[ aFirstColIds[i] ] );
+    
+    for (int i = 0, iEnd = myTable->numRows(); i < iEnd; i++)
+      myTable->setText( i, 2, aListCorners[ aLastColIds[i] ] );
+  }
   else
-    {
-      // clear table
-      for ( int row = 0; row < myTable->numRows(); row++ )
-        for ( int col = 0; col < myTable->numCols(); col++ )
-         myTable->setText(row, col, "");
-      
-      myTable->setEnabled( false );
-    }
+  {
+    // clear table
+    for ( int row = 0; row < myTable->numRows(); row++ )
+      for ( int col = 0; col < myTable->numCols(); col++ )
+       myTable->setText(row, col, "");
+    
+    myTable->setEnabled( false );
+  }
 }
 
 
@@ -1083,11 +1114,9 @@ void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
 //=================================================================================
 void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol, int theButton, const QPoint& theMousePos )
 {
-  if ( theButton == 1 && theCol == 1 )
-    myIsEditCorners = false;
-  
+  myIsEditCorners = false;
   displaySimulation();
-  return;
+  updateButtons();
 }
 
 
@@ -1097,17 +1126,12 @@ void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCo
 //=================================================================================
 void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
 {
-  onTextChange( myTable->text(theRow, theCol) );
+  myIsEditCorners = false;
+  displaySimulation();
+  updateButtons();
 }
 
 
-QWidget* SMESHGUI_IdEditItem::createEditor() const
-{
-  QLineEdit *aLineEdit = new QLineEdit(text(), table()->viewport());
-  aLineEdit->setValidator( new SMESHGUI_IdValidator(table()->viewport(), "validator", 1) );
-  return aLineEdit;
-}
-
 //=================================================================================
 // function : keyPressEvent()
 // purpose  :
@@ -1119,8 +1143,15 @@ void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
     return;
 
   if ( e->key() == Key_F1 )
-    {
-      e->accept();
-      ClickOnHelp();
-    }
+  {
+    e->accept();
+    ClickOnHelp();
+  }
+}
+
+void SMESHGUI_AddQuadraticElementDlg::updateButtons()
+{
+  bool valid = IsValid();
+  buttonOk->setEnabled( valid );
+  buttonApply->setEnabled( valid );
 }