Salome HOME
23080: [CEA 1497] Do not merge a middle node in quadratic with the extreme nodes...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MergeDlg.cxx
index 7446b54b2d58ba9ac8c33bb122f14c71c1d8856b..5c62beb671f9dc2310c08fe19de1fefb0f579e11 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  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
 #include <vtkIntArray.h>
 #include <vtkProperty2D.h>
 #include <vtkPointData.h>
-#include <vtkConfigure.h>
-#if !defined(VTK_XVERSION)
-#define VTK_XVERSION (VTK_MAJOR_VERSION<<16)+(VTK_MINOR_VERSION<<8)+(VTK_BUILD_VERSION)
-#endif
 
 // Qt includes
 #include <QApplication>
 #define SPACING 6
 #define MARGIN  11
 
+namespace
+{
+  enum ActionType { MERGE_NODES, MERGE_ELEMENTS };
+}
 namespace SMESH
 {
   class TIdPreview
@@ -124,7 +124,7 @@ namespace SMESH
 
       // Create and display actor
       vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
-      aMapper->SetInput( myIdGrid );
+      aMapper->SetInputData( myIdGrid );
 
       myIdActor = SALOME_Actor::New();
       myIdActor->SetInfinitive(true);
@@ -140,19 +140,16 @@ namespace SMESH
       myPointsNumDataSet = vtkUnstructuredGrid::New();
 
       myPtsMaskPoints = vtkMaskPoints::New();
-      myPtsMaskPoints->SetInput(myPointsNumDataSet);
+      myPtsMaskPoints->SetInputData(myPointsNumDataSet);
       myPtsMaskPoints->SetOnRatio(1);
 
       myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
-      myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
+      myPtsSelectVisiblePoints->SetInputConnection(myPtsMaskPoints->GetOutputPort());
       myPtsSelectVisiblePoints->SelectInvisibleOff();
       myPtsSelectVisiblePoints->SetTolerance(0.1);
     
       myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
-      myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
-#if (VTK_XVERSION < 0x050200)
-      myPtsLabeledDataMapper->SetLabelFormat("%g");
-#endif
+      myPtsLabeledDataMapper->SetInputConnection(myPtsSelectVisiblePoints->GetOutputPort());
       myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
     
       vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
@@ -250,7 +247,7 @@ namespace SMESH
           anArray->SetValue( i, myIDs[i] );
         aDataSet->GetPointData()->SetScalars( anArray );
         anArray->Delete();
-        myPtsMaskPoints->SetInput( aDataSet );
+        myPtsMaskPoints->SetInputData( aDataSet );
         myPointLabels->SetVisibility( theIsActorVisible );
       }
       else {
@@ -314,7 +311,7 @@ SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
 {
   setModal(false);
   setAttribute(Qt::WA_DeleteOnClose, true);
-  setWindowTitle(myAction == 1 ? tr("SMESH_MERGE_ELEMENTS") : tr("SMESH_MERGE_NODES"));
+  setWindowTitle(myAction == MERGE_ELEMENTS ? tr("SMESH_MERGE_ELEMENTS") : tr("SMESH_MERGE_NODES"));
 
   myIdPreview = new SMESH::TIdPreview(SMESH::GetViewWindow( mySMESHGUI ));
 
@@ -332,7 +329,7 @@ SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
   DlgLayout->setMargin(MARGIN);
 
   /***************************************************************/
-  GroupConstructors = new QGroupBox(myAction == 1 ? 
+  GroupConstructors = new QGroupBox(myAction == MERGE_ELEMENTS ? 
                                     tr("SMESH_MERGE_ELEMENTS") : 
                                     tr("SMESH_MERGE_NODES"), 
                                     this);
@@ -343,7 +340,7 @@ SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
   GroupConstructorsLayout->setMargin(MARGIN);
 
   RadioButton = new QRadioButton(GroupConstructors);
-  RadioButton->setIcon(myAction == 1 ? IconMergeElems : IconMergeNodes);
+  RadioButton->setIcon(myAction == MERGE_ELEMENTS ? IconMergeElems : IconMergeNodes);
   RadioButton->setChecked(true);
   GroupConstructorsLayout->addWidget(RadioButton);
   ButtonGroup->addButton(RadioButton, 0);
@@ -385,7 +382,7 @@ SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
 
   /***************************************************************/
   // Controls for coincident elements detecting
-  GroupCoincident = new QGroupBox(myAction == 1 ? 
+  GroupCoincident = new QGroupBox(myAction == MERGE_ELEMENTS ? 
                                   tr("COINCIDENT_ELEMENTS") : 
                                   tr("COINCIDENT_NODES"), 
                                   this);
@@ -394,12 +391,16 @@ SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
   aCoincidentLayout->setSpacing(SPACING);
   aCoincidentLayout->setMargin(MARGIN);
 
-  if (myAction == 0) { // case merge nodes
+  if (myAction == MERGE_NODES) // case merge nodes
+  {
     QWidget* foo = new QWidget(GroupCoincident);
     TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), foo);
     SpinBoxTolerance = new SMESHGUI_SpinBox(foo);
     SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
 
+    SeparateCornersAndMedium = new QCheckBox(tr("SEPARATE_CORNERS_AND_MEDIUM"), foo);
+    SeparateCornersAndMedium->setEnabled( false );
+
     GroupExclude = new QGroupBox(tr("EXCLUDE_GROUPS"), foo);
     GroupExclude->setCheckable( true );
     GroupExclude->setChecked( false );
@@ -412,9 +413,10 @@ SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
     QGridLayout* fooLayout = new QGridLayout( foo );
     fooLayout->setSpacing(SPACING);
     fooLayout->setMargin(0);
-    fooLayout->addWidget(TextLabelTolerance, 0, 0 );
-    fooLayout->addWidget(SpinBoxTolerance,   0, 1 );
-    fooLayout->addWidget(GroupExclude,       1, 0, 1, 2 );
+    fooLayout->addWidget(TextLabelTolerance,       0, 0 );
+    fooLayout->addWidget(SpinBoxTolerance,         0, 1 );
+    fooLayout->addWidget(SeparateCornersAndMedium, 1, 0 );
+    fooLayout->addWidget(GroupExclude,             2, 0, 1, 2 );
     aCoincidentLayout->addWidget(foo);
   }
   else {
@@ -437,12 +439,14 @@ SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
   RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincidentWidget);
 
   SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincidentWidget);
+  ShowIDs = new QCheckBox(myAction == MERGE_ELEMENTS ? tr("SHOW_ELEMS_IDS") : tr("SHOW_NODES_IDS"), GroupCoincidentWidget);
 
   GroupCoincidentLayout->addWidget(ListCoincident,    0,   0, 4, 2);
   GroupCoincidentLayout->addWidget(DetectButton,      0,   2);
   GroupCoincidentLayout->addWidget(AddGroupButton,    2, 2);
   GroupCoincidentLayout->addWidget(RemoveGroupButton, 3, 2);
-  GroupCoincidentLayout->addWidget(SelectAllCB,       4, 0, 1, 3);
+  GroupCoincidentLayout->addWidget(SelectAllCB,       4, 0);
+  GroupCoincidentLayout->addWidget(ShowIDs,           4, 1);
   GroupCoincidentLayout->setRowMinimumHeight(1, 10);
   GroupCoincidentLayout->setRowStretch(1, 5);
 
@@ -506,13 +510,15 @@ SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
   DlgLayout->addWidget(GroupEdit);
   DlgLayout->addWidget(GroupButtons);
 
-  GroupCoincidentWidget->setVisible( myAction != 0 );
-  GroupCoincident->setVisible( myAction == 0 );
-  //if GroupExclude->setVisible( myAction == 0 );
+  GroupCoincidentWidget->setVisible( myAction != MERGE_NODES );
+  GroupCoincident      ->setVisible( myAction == MERGE_NODES );
+  //if GroupExclude->setVisible( myAction == MERGE_NODES );
   GroupEdit->hide();
 
   this->resize(10,10);
 
+  ShowIDs->setChecked( true );
+
   Init(); // Initialisations
 }
 
@@ -531,7 +537,7 @@ SMESHGUI_MergeDlg::~SMESHGUI_MergeDlg()
 //=================================================================================
 void SMESHGUI_MergeDlg::Init()
 {
-  if (myAction == 0) {
+  if ( myAction == MERGE_NODES ) {
     SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision");
     SpinBoxTolerance->SetValue(1e-05);
   }
@@ -552,7 +558,7 @@ void SMESHGUI_MergeDlg::Init()
   
   /* signals and slots connections */
   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
-  connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
+  connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
 
@@ -562,6 +568,7 @@ void SMESHGUI_MergeDlg::Init()
   connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
   connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
   connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
+  connect(ShowIDs, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup()));
   connect(ListEdit, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectElementFromGroup()));
   connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
   connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
@@ -571,15 +578,16 @@ void SMESHGUI_MergeDlg::Init()
   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
   /* to close dialog if study change */
-  connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
-
+  connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
+  connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this,  SLOT(onOpenView()));
+  connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
   // Init Mesh field from selection
   SelectionIntoArgument();
 
   // Update Buttons
   updateControls();
   
-  if (myAction == 0)
+  if ( myAction == MERGE_NODES )
     myHelpFileName = "merging_nodes_page.html";
   else
     myHelpFileName = "merging_elements_page.html";
@@ -640,7 +648,7 @@ bool SMESHGUI_MergeDlg::ClickOnApply()
     SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
 
     if ( ListCoincident->count() == 0) {
-      if (myAction == 0)
+      if ( myAction == MERGE_NODES )
         SUIT_MessageBox::warning(this,
                                  tr("SMESH_WARNING"),
                                  tr("SMESH_NO_NODES_DETECTED"));
@@ -664,13 +672,13 @@ bool SMESHGUI_MergeDlg::ClickOnApply()
       aGroupsOfElements[anArrayNum++] = anIds.inout();
     }
 
-    if( myAction == 0 )
+    if( myAction == MERGE_NODES )
       aMeshEditor->MergeNodes (aGroupsOfElements.inout());
     else
       aMeshEditor->MergeElements (aGroupsOfElements.inout());
 
     if ( myTypeId == 0 ) {
-      if (myAction ==0)
+      if (myAction == MERGE_NODES )
         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
                                      tr("SMESH_MERGED_NODES").arg(QString::number(ListCoincident->count()).toLatin1().data()));
       else
@@ -684,6 +692,8 @@ bool SMESHGUI_MergeDlg::ClickOnApply()
   
   ListCoincident->clear();
   
+  myEditCurrentArgument = (QWidget*)LineEditMesh;
+
   SMESH::UpdateView();
   SMESHGUI::Modified();
   
@@ -697,14 +707,14 @@ bool SMESHGUI_MergeDlg::ClickOnApply()
 void SMESHGUI_MergeDlg::ClickOnOk()
 {
   if (ClickOnApply())
-    ClickOnCancel();
+    reject();
 }
 
 //=================================================================================
-// function : ClickOnCancel()
+// function : reject()
 // purpose  :
 //=================================================================================
-void SMESHGUI_MergeDlg::ClickOnCancel()
+void SMESHGUI_MergeDlg::reject()
 {
   myIdPreview->SetPointsLabeled(false);
   SMESH::SetPointRepresentation(false);
@@ -718,7 +728,32 @@ void SMESHGUI_MergeDlg::ClickOnCancel()
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     aViewWindow->SetSelectionMode(ActorSelection);
 
-  reject();
+  QDialog::reject();
+}
+
+//=================================================================================
+// function : onOpenView()
+// purpose  :
+//=================================================================================
+void SMESHGUI_MergeDlg::onOpenView()
+{
+  if ( mySelector ) {
+    SMESH::SetPointRepresentation(false);
+  }
+  else {
+    mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
+    ActivateThisDialog();
+  }
+}
+
+//=================================================================================
+// function : onCloseView()
+// purpose  :
+//=================================================================================
+void SMESHGUI_MergeDlg::onCloseView()
+{
+  DeactivateActiveDialog();
+  mySelector = 0;
 }
 
 //=================================================================================
@@ -778,6 +813,17 @@ void SMESHGUI_MergeDlg::updateControls()
   bool enable = !(myMesh->_is_nil()) && (ListCoincident->count() || (myTypeId == 0));
   buttonOk->setEnabled(enable);
   buttonApply->setEnabled(enable);
+  DetectButton->setEnabled( !myMesh->_is_nil() );
+
+  if ( myAction == MERGE_NODES )
+  {
+    bool has2ndOrder = (( !myMesh->_is_nil() ) &&
+                        ( myMesh->NbEdgesOfOrder( SMESH::ORDER_QUADRATIC ) > 0 ||
+                          myMesh->NbFacesOfOrder( SMESH::ORDER_QUADRATIC ) > 0 ||
+                          myMesh->NbVolumesOfOrder( SMESH::ORDER_QUADRATIC ) > 0 ));
+
+    SeparateCornersAndMedium->setEnabled( has2ndOrder );
+  }
 }
 
 //=================================================================================
@@ -804,7 +850,7 @@ void SMESHGUI_MergeDlg::onDetect()
     else src = SMESH::SMESH_IDSource::_duplicate( mySubMeshOrGroup );
 
     switch (myAction) {
-    case 0 :
+    case MERGE_NODES :
       for ( int i = 0; GroupExclude->isChecked() && i < ListExclude->count(); i++ ) {
         if ( ListExclude->item( i )->checkState() == Qt::Checked ) {
           aExcludeGroups->length( aExcludeGroups->length()+1 );
@@ -814,9 +860,11 @@ void SMESHGUI_MergeDlg::onDetect()
       aMeshEditor->FindCoincidentNodesOnPartBut(src.in(),
                                                 SpinBoxTolerance->GetValue(), 
                                                 aGroupsArray.out(),
-                                                aExcludeGroups.in());
+                                                aExcludeGroups.in(),
+                                                SeparateCornersAndMedium->isEnabled() &&
+                                                SeparateCornersAndMedium->isChecked());
       break;
-    case 1 :
+    case MERGE_ELEMENTS :
       aMeshEditor->FindEqualElements(src.in(), aGroupsArray.out());
       break;
     }
@@ -835,6 +883,7 @@ void SMESHGUI_MergeDlg::onDetect()
 
   ListCoincident->selectAll();
   updateControls();
+  SMESH::UpdateView();
 }
 
 //=================================================================================
@@ -845,8 +894,13 @@ void SMESHGUI_MergeDlg::onSelectGroup()
 {
   if (myIsBusy || !myActor)
     return;
+
+  if( ListCoincident->count() != ListCoincident->selectedItems().count() )
+    SelectAllCB->setChecked( false );
+
   myEditCurrentArgument = (QWidget*)ListCoincident;
 
+  myIsBusy = true;
   ListEdit->clear();
   
   TColStd_MapOfInteger anIndices;
@@ -872,18 +926,22 @@ void SMESHGUI_MergeDlg::onSelectGroup()
   aList.Append(myActor->getIO());
   mySelectionMgr->setSelectedObjects(aList,false);
   
-  if (myAction == 0) {
-    myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
-    myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
-  }
-  else {
-    std::list< gp_XYZ > aGrCentersXYZ;
-    FindGravityCenter(anIndices, aGrCentersXYZ);
-    myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
-    myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
-  }
+  if (ShowIDs->isChecked()) 
+    if ( myAction == MERGE_NODES ) {
+      myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
+      myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
+    }
+    else {
+      std::list< gp_XYZ > aGrCentersXYZ;
+      FindGravityCenter(anIndices, aGrCentersXYZ);
+      myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
+      myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
+    }
+  else
+    myIdPreview->SetPointsLabeled(false);
 
   updateControls();
+  myIsBusy = false;
 }
 
 //=================================================================================
@@ -920,17 +978,20 @@ void SMESHGUI_MergeDlg::onSelectElementFromGroup()
   SALOME_ListIO aList;
   aList.Append(myActor->getIO());
   mySelectionMgr->setSelectedObjects(aList);
-
-  if (myAction == 0) {
-    myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
-    myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
-  }
-  else {
-    std::list< gp_XYZ > aGrCentersXYZ;
-    FindGravityCenter(anIndices, aGrCentersXYZ);
-    myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
-    myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
-  }
+  
+  if (ShowIDs->isChecked())
+    if (myAction == MERGE_NODES) {
+      myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
+      myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
+    }
+    else {
+      std::list< gp_XYZ > aGrCentersXYZ;
+      FindGravityCenter(anIndices, aGrCentersXYZ);
+      myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
+      myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
+    }
+  else 
+    myIdPreview->SetPointsLabeled(false);
 }
 
 //=================================================================================
@@ -982,9 +1043,15 @@ void SMESHGUI_MergeDlg::onRemoveGroup()
     delete anItem;
 
   ListEdit->clear();
+  myIdPreview->SetPointsLabeled(false);
   updateControls();
-
+  SMESH::UpdateView();
   myIsBusy = false;
+
+  if( ListCoincident->count() == 0 ) {
+    myEditCurrentArgument = (QWidget*)LineEditMesh;
+    SelectAllCB->setChecked( false );
+  }
 }
 
 //=================================================================================
@@ -1041,6 +1108,11 @@ void SMESHGUI_MergeDlg::onRemoveElement()
   
   myIsBusy = false;
   onEditGroup();
+
+  if( ListCoincident->count() == 0 ) {
+    myEditCurrentArgument = (QWidget*)LineEditMesh;
+    SelectAllCB->setChecked( false );
+  }
 }
 
 //=================================================================================
@@ -1100,12 +1172,13 @@ void SMESHGUI_MergeDlg::SelectionIntoArgument()
   if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
     QString aString = "";
     LineEditMesh->setText(aString);
-    
+
     ListCoincident->clear();
     ListEdit->clear();
     myActor = 0;
+    myMesh = SMESH::SMESH_Mesh::_nil();
     QString aCurrentEntry = myEntry;
-    
+
     int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
     if (nbSel != 1) {
       myIdPreview->SetPointsLabeled(false);
@@ -1118,30 +1191,30 @@ void SMESHGUI_MergeDlg::SelectionIntoArgument()
 
     SALOME_ListIO aList;
     mySelectionMgr->selectedObjects(aList);
-    
+
     Handle(SALOME_InteractiveObject) IO = aList.First();
     myEntry = IO->getEntry();
     myMesh = SMESH::GetMeshByIO(IO);
-    
+
     if (myMesh->_is_nil())
       return;
 
     LineEditMesh->setText(aString);
-    
+
     myActor = SMESH::FindActorByEntry(IO->getEntry());
     if (!myActor)
       myActor = SMESH::FindActorByObject(myMesh);
-    
-    if ( myActor && myTypeId ==1 ) {
+
+    if ( myActor && myTypeId == 1 && mySelector->IsSelectionEnabled() ) {
       mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
-      
+
       if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
            !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
           !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
         mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
-      
-      if (myAction == 0) {
+
+      if (myAction == MERGE_NODES) {
         SMESH::SetPointRepresentation(true);
         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
           aViewWindow->SetSelectionMode(NodeSelection);
@@ -1152,7 +1225,7 @@ void SMESHGUI_MergeDlg::SelectionIntoArgument()
     }
 
     // process groups
-    if ( myAction == 0 && !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
+    if ( myAction == MERGE_NODES && !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
       myGroups.clear();
       ListExclude->clear();
       SMESH::ListOfGroups_var aListOfGroups = myMesh->GetGroups();
@@ -1220,30 +1293,15 @@ void SMESHGUI_MergeDlg::ActivateThisDialog()
 // function : enterEvent()
 // purpose  :
 //=================================================================================
-void SMESHGUI_MergeDlg::enterEvent(QEvent*)
+void SMESHGUI_MergeDlg::enterEvent (QEvent*)
 {
-  if (!GroupConstructors->isEnabled())
+  if ( !GroupConstructors->isEnabled() ) {
+    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
+    if ( aViewWindow && !mySelector) {
+      mySelector = aViewWindow->GetSelector();
+    }
     ActivateThisDialog();
-}
-
-//=================================================================================
-// function : closeEvent()
-// purpose  :
-//=================================================================================
-void SMESHGUI_MergeDlg::closeEvent(QCloseEvent*)
-{
-  /* same than click on cancel button */
-  ClickOnCancel();
-}
-
-//=======================================================================
-//function : hideEvent
-//purpose  : caused by ESC key
-//=======================================================================
-void SMESHGUI_MergeDlg::hideEvent (QHideEvent *)
-{
-  if (!isMinimized())
-    ClickOnCancel();
+  }
 }
 
 //=================================================================================
@@ -1280,7 +1338,7 @@ void SMESHGUI_MergeDlg::onTypeChanged (int id)
     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
       aViewWindow->SetSelectionMode(ActorSelection);
     mySelectionMgr->clearFilters();
-    if (myAction == 0)
+    if (myAction == MERGE_NODES)
       GroupCoincidentWidget->hide();
     else
       GroupCoincident->hide();
@@ -1291,8 +1349,8 @@ void SMESHGUI_MergeDlg::onTypeChanged (int id)
     SMESH::UpdateView();
 
     // Costruction of the logical filter
-    SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
-    SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
+    SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
+    SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (SMESH::GROUP);
     
     QList<SUIT_SelectionFilter*> aListOfFilters;
     if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
@@ -1301,16 +1359,18 @@ void SMESHGUI_MergeDlg::onTypeChanged (int id)
     myMeshOrSubMeshOrGroupFilter =
       new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
 
-    if (myAction == 0) {
+    if (myAction == MERGE_NODES) {
       GroupCoincidentWidget->show();
       SMESH::SetPointRepresentation(true);
       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
-        aViewWindow->SetSelectionMode(NodeSelection);
+        if( mySelector->IsSelectionEnabled() )
+          aViewWindow->SetSelectionMode(NodeSelection);
     }
     else {
       GroupCoincident->show();
       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
-        aViewWindow->SetSelectionMode(CellSelection);
+        if( mySelector->IsSelectionEnabled() )
+          aViewWindow->SetSelectionMode(CellSelection);
     }
     GroupEdit->show();
     break;