Salome HOME
PAL16631 (SALOME crash after a mesh computation failed due to lack of memory)
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupDlg.cxx
index d6928d67326b5ed997ec1fa5091cd7afbdd08782..8968d907c014f6b78973747d980b7e6f0b09b180 100644 (file)
@@ -1,23 +1,23 @@
 //  SMESH SMESHGUI : GUI for SMESH component
 //
 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  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. 
-// 
-//  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. 
-// 
-//  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.org 
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  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.
+//
+//  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.
+//
+//  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
 //
 //
 //
 //  Module : SMESH
 //  $Header$
 
-using namespace std;
 #include "SMESHGUI_GroupDlg.h"
 #include "SMESHGUI_FilterDlg.h"
+#include "SMESHGUI_ShapeByMeshDlg.h"
 
 #include "SMESHGUI.h"
-#include "SALOMEGUI_QtCatchCorbaException.hxx"
+#include "SMESHGUI_Utils.h"
+#include "SMESHGUI_VTKUtils.h"
+#include "SMESHGUI_MeshUtils.h"
+#include "SMESHGUI_GroupUtils.h"
+#include "SMESHGUI_FilterUtils.h"
+#include "SMESHGUI_GEOMGenUtils.h"
+
+#include "SMESH_TypeFilter.hxx"
+#include "SMESH_Actor.h"
+
+#include "GEOMBase.h"
+#include "GEOM_SelectionFilter.h"
+
+#include "SUIT_Desktop.h"
+#include "SUIT_ResourceMgr.h"
+#include "SUIT_Session.h"
+#include "SUIT_MessageBox.h"
+
+#include "SalomeApp_Tools.h"
+#include "SalomeApp_Application.h"
+#include "SalomeApp_Study.h"
+#include "LightApp_Application.h"
+#include "SALOMEDSClient_Study.hxx"
+#include "SALOME_ListIO.hxx"
 #include "SALOME_ListIteratorOfListIO.hxx"
-#include "VTKViewer_InteractorStyleSALOME.h"
-#include "VTKViewer_ViewFrame.h"
-#include "QAD_Application.h"
-#include "QAD_Desktop.h"
-#include "QAD_MessageBox.h"
-#include "QAD_RightFrame.h"
+
+#include "SVTK_ViewWindow.h"
+#include "SVTK_Selector.h"
+
 #include "utilities.h"
 
-#include "SMESH_Actor.h"
+// OCCT Includes
+#include <TColStd_MapOfInteger.hxx>
 
 // QT Includes
 #include <qbuttongroup.h>
+#include <qcursor.h>
 #include <qgroupbox.h>
 #include <qhbox.h>
 #include <qlabel.h>
 #include <qlineedit.h>
 #include <qpushbutton.h>
+#include <qtoolbutton.h>
 #include <qradiobutton.h>
 #include <qcheckbox.h>
 #include <qlayout.h>
@@ -57,57 +81,110 @@ using namespace std;
 #include <qimage.h>
 #include <qpixmap.h>
 #include <qmemarray.h>
+#include <qwidgetstack.h>
+
+#include <QtxIntSpinBox.h>
 
 // STL includes
 #include <vector>
 #include <algorithm>
 
+using namespace std;
+
 //=================================================================================
-// class    : SMESHGUI_GroupDlg()
-// purpose  : 
+// function : SMESHGUI_GroupDlg()
+// purpose  :
 //=================================================================================
-SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( QWidget* parent, const char* name, SALOME_Selection* theSel,
-                                     SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl )
-  : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
+SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
+                                     SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl)
+     : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
+                WStyle_Title | WStyle_SysMenu | WDestructiveClose),
+     mySMESHGUI( theModule ),
+     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
+     mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
+     myIsBusy( false ),
+     myActor( 0 )
 {
-  if ( !name ) setName( "SMESHGUI_GroupDlg" );
-  initDialog(theSel, true);
-  init(theMesh);
-
-  /* Move widget on the botton right corner of main widget */
-  int x, y ;
-  mySMESHGUI->DefineDlgPosition(this, x, y);
-  this->move(x, y);
+  if (!name) setName("SMESHGUI_GroupDlg");
+  initDialog(true);
+  if (!theMesh->_is_nil())
+    init(theMesh);
+  else {
+    mySelectSubMesh->setEnabled(false);
+    mySelectGroup->setEnabled(false);
+    myGeomGroupBtn->setEnabled(false);
+    myGeomGroupLine->setEnabled(false);
+  }
 }
 
-SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( QWidget* parent, const char* name, SALOME_Selection* theSel,
-                                     SMESH::SMESH_Group_ptr theGroup, bool modal, WFlags fl )
-  : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
+//=================================================================================
+// function : SMESHGUI_GroupDlg()
+// purpose  :
+//=================================================================================
+SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
+                                     SMESH::SMESH_GroupBase_ptr theGroup, bool modal, WFlags fl)
+     : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
+                WStyle_Title | WStyle_SysMenu | WDestructiveClose),
+     mySMESHGUI( theModule ),
+     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
+     mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
+     myIsBusy( false )
 {
-  if ( !name ) setName( "SMESHGUI_GroupDlg" );
-  initDialog(theSel, false);
-  init(theGroup);
+  if (!name) setName("SMESHGUI_GroupDlg");
 
-  /* Move widget on the botton right corner of main widget */
-  int x, y ;
-  mySMESHGUI->DefineDlgPosition(this, x, y);
-  this->move(x, y);
+  initDialog(false);
+  if (!theGroup->_is_nil())
+    init(theGroup);
+  else {
+    mySelectSubMesh->setEnabled(false);
+    mySelectGroup->setEnabled(false);
+
+    myCurrentLineEdit = myMeshGroupLine;
+    setSelectionMode(5);
+  }
 }
 
-void SMESHGUI_GroupDlg::initDialog(SALOME_Selection* theSel, bool create)
+//=================================================================================
+// function : SMESHGUI_GroupDlg()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupDlg::initDialog(bool create)
 {
   myFilterDlg = 0;
-  
-  QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
+  myCreate = create;
+  myCurrentLineEdit = 0;
+
+  myShapeByMeshOp = 0;
+  myGeomPopup = 0;
+  myGeomObjects = new GEOM::ListOfGO();
+  myGeomObjects->length(0);
+
+  QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
+
+  if (create) {
+    setCaption(tr("SMESH_CREATE_GROUP_TITLE"));
+    myHelpFileName = "/files/creating_groups.htm";
+  }
+  else {
+    setCaption(tr("SMESH_EDIT_GROUP_TITLE"));
+    myHelpFileName = "/files/editing_groups.htm";
+  }
 
+  setSizeGripEnabled(TRUE);
+
+  QGridLayout* aMainLayout = new QGridLayout(this, 7, 3, 11, 6);
+
+  /***************************************************************/
+  QLabel* meshGroupLab = new QLabel(this, "mesh/group label");
   if (create)
-    setCaption( tr( "SMESH_CREATE_GROUP_TITLE"  ) );
-  else 
-    setCaption( tr( "SMESH_EDIT_GROUP_TITLE"  ) );
-  setSizeGripEnabled( TRUE );
+    meshGroupLab->setText(tr("SMESH_MESH"));
+  else
+    meshGroupLab->setText(tr("SMESH_GROUP"));
+  myMeshGroupBtn = new QPushButton(this, "mesh/group button");
+  myMeshGroupBtn->setPixmap(image0);
+  myMeshGroupLine = new QLineEdit(this, "mesh/group line");
+  myMeshGroupLine->setReadOnly(true);
 
-  QVBoxLayout* aMainLayout = new QVBoxLayout(this, 11, 6);
-  
   /***************************************************************/
   myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
   myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
@@ -124,16 +201,29 @@ void SMESHGUI_GroupDlg::initDialog(SALOME_Selection* theSel, bool create)
   }
   myTypeGroup->setEnabled(create);
   myTypeId = -1;
-    
+
   /***************************************************************/
-  QHBox* aNameBox = new QHBox(this, "name box");
-  QLabel* aName = new QLabel(aNameBox, "name label");
+  QLabel* aName = new QLabel(this, "name label");
   aName->setText(tr("SMESH_NAME"));
   aName->setMinimumSize(50,0);
-  myName = new QLineEdit(aNameBox, "name");
-    
+  myName = new QLineEdit(this, "name");
+
   /***************************************************************/
-  QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, this, "content box");
+  myGrpTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Type of group");
+  myGrpTypeGroup->setTitle(tr("SMESH_GROUP_TYPE"));
+  myGrpTypeGroup->setExclusive(true);
+  QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), myGrpTypeGroup);
+  QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"),   myGrpTypeGroup);
+  myGrpTypeGroup->setEnabled(create);
+  myGrpTypeId = -1;
+
+  /***************************************************************/
+  myWGStack = new QWidgetStack( this, "widget stack");
+  QWidget* wg1 = new QFrame( myWGStack, "first widget" );
+  QWidget* wg2 = new QFrame( myWGStack, "second widget" );
+
+  /***************************************************************/
+  QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, wg1, "content box");
   aContentBox->setTitle(tr("SMESH_CONTENT"));
   QFrame* aContent = new QFrame(aContentBox, "content");
   QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
@@ -144,7 +234,6 @@ void SMESHGUI_GroupDlg::initDialog(SALOME_Selection* theSel, bool create)
   aLabel->setText(tr("SMESH_ID_ELEMENTS"));
   myElements = new QListBox(aContent, "elements list");
   myElements->setSelectionMode(QListBox::Extended);
-  //  myElements->setMinimumHeight(150);
 
   myFilter = new QPushButton(aContent, "filter");
   myFilter->setText(tr("SMESH_BUT_FILTER"));
@@ -168,11 +257,8 @@ void SMESHGUI_GroupDlg::initDialog(SALOME_Selection* theSel, bool create)
   aLayout->setRowStretch(2, 1);
   aLayout->setRowStretch(5, 1);
 
-  aContentBox->setMinimumHeight(aContent->sizeHint().height() + 
-                               aContentBox->sizeHint().height());
-
   /***************************************************************/
-  QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, this, "select box");
+  QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, wg1, "select box");
   aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
 
   mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
@@ -194,12 +280,59 @@ void SMESHGUI_GroupDlg::initDialog(SALOME_Selection* theSel, bool create)
   myGroupLine = new QLineEdit(aSelectBox, "group line");
   myGroupLine->setReadOnly(true);
   onSelectGroup(false);
+  
+  /***************************************************************/
+  QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 );
+  wg1Layout->addWidget(aContentBox, 0, 0);
+  wg1Layout->addWidget(aSelectBox, 1, 0);
+  wg1Layout->setRowStretch(2, 5);
+
+  /***************************************************************/
+  QLabel* geomObject = new QLabel(wg2, "geometry object label");
+  geomObject->setText(tr("SMESH_OBJECT_GEOM"));
+  myGeomGroupBtn = new QToolButton(wg2, "geometry group button");
+  myGeomGroupBtn->setIconSet( QIconSet(image0) );
+  myGeomGroupBtn->setToggleButton(true);
+  myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
+  myGeomGroupLine->setReadOnly(true); //VSR ???
+  onSelectGeomGroup(false);
+  
+  if (!create)
+    {
+      myGeomGroupBtn->setEnabled(false);
+      myGeomGroupLine->setEnabled(false);
+    }
+   
+  /***************************************************************/
+  QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 );
+  wg2Layout->addWidget(geomObject,     0, 0);
+  wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
+  wg2Layout->addWidget(myGeomGroupLine,0, 2);
+  wg2Layout->setRowStretch(1, 5);
 
-  aSelectBox->setMinimumHeight(mySubMeshBtn->sizeHint().height() + 
-                              myGroupBtn->sizeHint().height() +
-                              aSelectBox->sizeHint().height());
+  /***************************************************************/
+  QVBoxLayout* dumb = new QVBoxLayout(myWGStack);
+  dumb->addWidget(wg1);
+  dumb->addWidget(wg2);
+  myWGStack->addWidget( wg1, myGrpTypeGroup->id(rb1) );
+  myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) );
+
+  /***************************************************************/
+  QGroupBox* aColorBox = new QGroupBox(2, Qt::Horizontal, this, "color box");
+  aColorBox->setTitle(tr("SMESH_SET_COLOR"));
 
+  mySelectColorGroup = new QCheckBox(aColorBox, "color checkbox");
+  mySelectColorGroup->setText(tr("SMESH_CHECK_COLOR"));
+  
+  myColorSpinBox = new QtxIntSpinBox( aColorBox );
+  myColorSpinBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
+  myColorSpinBox->setMinValue( 0 );
+  myColorSpinBox->setMaxValue( 9999 );
+  
+  onSelectColorGroup(false);
+  
   /***************************************************************/
+  
   QFrame* aButtons = new QFrame(this, "button box");
   aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
   QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
@@ -215,20 +348,34 @@ void SMESHGUI_GroupDlg::initDialog(SALOME_Selection* theSel, bool create)
   QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
   aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
   aCloseBtn->setAutoDefault(true);
+  QPushButton* aHelpBtn = new QPushButton(aButtons, "help");
+  aHelpBtn->setText(tr("SMESH_BUT_HELP"));
+  aHelpBtn->setAutoDefault(true);
 
   aBtnLayout->addWidget(aOKBtn);
   aBtnLayout->addWidget(aApplyBtn);
   aBtnLayout->addStretch();
   aBtnLayout->addWidget(aCloseBtn);
+  aBtnLayout->addWidget(aHelpBtn);
 
   /***************************************************************/
-  aMainLayout->addWidget(myTypeGroup);
-  aMainLayout->addWidget(aNameBox);
-  aMainLayout->addWidget(aContentBox);
-  aMainLayout->addWidget(aSelectBox);
-  aMainLayout->addWidget(aButtons);
+  aMainLayout->addWidget(meshGroupLab,    0, 0);
+  aMainLayout->addWidget(myMeshGroupBtn,  0, 1);
+  aMainLayout->addWidget(myMeshGroupLine, 0, 2);
+  aMainLayout->addMultiCellWidget(myTypeGroup,    1, 1, 0, 2);
+  aMainLayout->addWidget(aName,      2, 0);
+  aMainLayout->addWidget(myName,     2, 2);
+  aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2);
+  aMainLayout->addMultiCellWidget(myWGStack,      4, 4, 0, 2);
+  aMainLayout->setRowStretch( 5, 5 );
+  aMainLayout->addMultiCellWidget(aColorBox,   6, 6, 0, 2);
+  aMainLayout->addMultiCellWidget(aButtons,       7, 7, 0, 2);
 
   /* signals and slots connections */
+  connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
+
+  connect(myGrpTypeGroup, SIGNAL(clicked(int)), this, SLOT(onGrpTypeChanged(int)));
+
   connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
 
   connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
@@ -243,24 +390,35 @@ void SMESHGUI_GroupDlg::initDialog(SALOME_Selection* theSel, bool create)
   connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
   connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
   connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
-
+  connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
+  connect(mySelectColorGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectColorGroup(bool)));
+  connect(myColorSpinBox, SIGNAL(valueChanged(const QString&)), this, SLOT(onNbColorsChanged(const QString&)));
+  
   connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
   connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
+  connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
 
   /* Init selection */
-  mySelection = theSel;  
-  mySMESHGUI = SMESHGUI::GetSMESHGUI();
   mySMESHGUI->SetActiveDialogBox(this);
   mySMESHGUI->SetState(800);
 
   mySelectionMode = -1;
+  myMeshFilter = new SMESH_TypeFilter(MESH);
   mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
   myGroupFilter = new SMESH_TypeFilter(GROUP);
-
-  connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onClose()));
+  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
+  myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
+  
+  connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
-  connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
+  connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
+
+  myGrpTypeGroup->setButton(myGrpTypeGroup->id(rb1)); // VSR !!!
+  onGrpTypeChanged(myGrpTypeGroup->id(rb1)); // VSR!!!
+
+  if (myMesh->_is_nil() )
+    myTypeGroup->setButton(0);
 
   updateButtons();
 }
@@ -271,23 +429,40 @@ void SMESHGUI_GroupDlg::initDialog(SALOME_Selection* theSel, bool create)
 //=================================================================================
 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
 {
-    // no need to delete child widgets, Qt does it all for us
+  // no need to delete child widgets, Qt does it all for us
+  if ( myFilterDlg != 0 )
+  {
+    myFilterDlg->reparent( 0, QPoint() );
+    delete myFilterDlg;
+  }
 }
 
-
 //=================================================================================
 // function : Init()
 // purpose  :
 //=================================================================================
-void SMESHGUI_GroupDlg::init(SMESH::SMESH_Mesh_ptr theMesh)
+void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
 {
+  mySelectionMgr->installFilter(myMeshFilter);
+
   /* init data from current selection */
   myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
   myGroup = SMESH::SMESH_Group::_nil();
+  myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
+
+  myActor = SMESH::FindActorByObject(myMesh);
+  SMESH::SetPickable(myActor);
+
+  SALOME_ListIO aList;
+  mySelectionMgr->selectedObjects( aList );
+  if( !aList.IsEmpty() )
+  {
+    QString aName = aList.First()->getName();
+    myMeshGroupLine->setText(aName) ;
+    myMeshGroupLine->home( false );
+  }
 
-  Standard_Boolean aResult;
-  myActor = mySMESHGUI->FindActor(myMesh, aResult, true);
-  mySMESHGUI->SetPickable(myActor);
+  myCurrentLineEdit = 0;
 
   myTypeGroup->setButton(0);
   onTypeChanged(0);
@@ -297,17 +472,16 @@ void SMESHGUI_GroupDlg::init(SMESH::SMESH_Mesh_ptr theMesh)
 // function : Init()
 // purpose  :
 //=================================================================================
-void SMESHGUI_GroupDlg::init(SMESH::SMESH_Group_ptr theGroup)
+void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
 {
-
   myMesh = theGroup->GetMesh();
-  myGroup = SMESH::SMESH_Group::_duplicate(theGroup);
+  
+  myName->setText(theGroup->GetName());
+  myName->home(false);
 
-  Standard_Boolean aResult;
-  myActor = mySMESHGUI->FindActor(myMesh, aResult, true);
-  if ( !myActor )
-    myActor = mySMESHGUI->FindActor(myGroup, aResult, true);
-  mySMESHGUI->SetPickable(myActor);
+  myColorSpinBox->setValue( theGroup->GetColorNumber() );
+  
+  myMeshGroupLine->setText(theGroup->GetName());
 
   int aType = 0;
   switch(theGroup->GetType()) {
@@ -315,32 +489,82 @@ void SMESHGUI_GroupDlg::init(SMESH::SMESH_Group_ptr theGroup)
   case SMESH::EDGE: aType = 1; break;
   case SMESH::FACE: aType = 2; break;
   case SMESH::VOLUME: aType = 3; break;
-  } 
+  }
   myTypeGroup->setButton(aType);
-  onTypeChanged(aType);
-
-  myName->setText(myGroup->GetName());
-  myName->home(false);
-
-  if (!theGroup->IsEmpty()) {
-    SMESH::long_array_var anElements = myGroup->GetListOfID();
-    int k = anElements->length();
-    for (int i = 0; i < k; i++) {
-      myIdList.append(anElements[i]);
-      myElements->insertItem(QString::number(anElements[i]));
+  
+  myGroup = SMESH::SMESH_Group::_narrow( theGroup );
+
+  if ( !myGroup->_is_nil() )
+    {
+      myActor = SMESH::FindActorByObject(myMesh);
+      if ( !myActor )
+       myActor = SMESH::FindActorByObject(myGroup);
+      SMESH::SetPickable(myActor);
+
+      myGrpTypeGroup->setButton(0);
+      onGrpTypeChanged(0);
+      
+      myCurrentLineEdit = 0;
+      myElements->clear();
+      setSelectionMode(aType);
+      myTypeId = aType;
+      
+      myIdList.clear();
+      if (!myGroup->IsEmpty()) {
+       SMESH::long_array_var anElements = myGroup->GetListOfID();
+       int k = anElements->length();
+       for (int i = 0; i < k; i++) {
+         myIdList.append(anElements[i]);
+         myElements->insertItem(QString::number(anElements[i]));
+       }
+       myElements->selectAll(true);
+      }
+    }
+  else
+    {
+      myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
+      
+      if ( !myGroupOnGeom->_is_nil() )
+       {
+         myActor = SMESH::FindActorByObject(myMesh);
+         if ( !myActor )
+           myActor = SMESH::FindActorByObject(myGroup);
+         SMESH::SetPickable(myActor);
+
+         myGrpTypeGroup->setButton(1);
+         onGrpTypeChanged(1);
+         
+         QString aShapeName("");
+         _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+         GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
+         if (!aGroupShape->_is_nil())
+           {
+             _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
+             aShapeName = aGroupShapeSO->GetName().c_str();
+           }
+         myGeomGroupLine->setText( aShapeName );
+       }
     }
-    myElements->selectAll(true);
-  }
 }
 
-
 //=================================================================================
 // function : updateButtons()
-// purpose  : 
+// purpose  :
 //=================================================================================
 void SMESHGUI_GroupDlg::updateButtons()
 {
-  bool enable = !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0;
+  bool enable = !myName->text().stripWhiteSpace().isEmpty();
+
+  if (myGrpTypeId == 0) {
+    enable = enable && myElements->count() > 0;
+    enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
+  }
+  else if (myGrpTypeId == 1) {
+    if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
+      enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
+    }
+  }
+
   QPushButton* aBtn;
   aBtn = (QPushButton*) child("ok", "QPushButton");
   if (aBtn) aBtn->setEnabled(enable);
@@ -350,64 +574,103 @@ void SMESHGUI_GroupDlg::updateButtons()
 
 //=================================================================================
 // function : onNameChanged()
-// purpose  : 
+// purpose  :
 //=================================================================================
-void SMESHGUI_GroupDlg::onNameChanged(const QString& text)
+void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
+{
+  updateButtons();
+}
+
+//=================================================================================
+// function : onNbColorsChanged()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupDlg::onNbColorsChanged (const QString& text)
 {
   updateButtons();
 }
 
 //=================================================================================
 // function : onTypeChanged()
-// purpose  : Radio button management
+// purpose  : Group elements type radio button management
 //=================================================================================
-void SMESHGUI_GroupDlg::onTypeChanged(int id)
+void SMESHGUI_GroupDlg::onTypeChanged (int id)
 {
   if (myTypeId != id) {
     myElements->clear();
     if (myCurrentLineEdit == 0)
       setSelectionMode(id);
-    myFilter->setEnabled(id == 1 || id == 2);
   }
   myTypeId = id;
 }
 
+//=================================================================================
+// function : onGrpTypeChanged()
+// purpose  : Group type radio button management
+//=================================================================================
+void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
+{
+  if (myGrpTypeId != id) {
+    myWGStack->raiseWidget( id );
+    onSelectGeomGroup(id == 1);
+  }
+  myGrpTypeId = id;
+}
+
 //=================================================================================
 // function : setSelectionMode()
 // purpose  : Radio button management
 //=================================================================================
-void SMESHGUI_GroupDlg::setSelectionMode(int theMode)
+void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
 {
+  // PAL7314
+  if (myMesh->_is_nil())
+    return;
   if (mySelectionMode != theMode) {
-    mySelection->ClearIObjects();
-    mySelection->ClearFilters();
-    if (mySelectionMode == 0)
-      mySMESHGUI->EraseSimulationActors();
+    // [PAL10408] mySelectionMgr->clearSelected();
+    mySelectionMgr->clearFilters();
+    if (myActor)
+      myActor->SetPointRepresentation(false);
+    else
+      SMESH::SetPointRepresentation(false);
     if (theMode < 4) {
-      if (theMode == 0) {
-       mySMESHGUI->ViewNodes();
-       QAD_Application::getDesktop()->SetSelectionMode(NodeSelection, true);
-      }
-      else if (theMode == 1) {
-       QAD_Application::getDesktop()->SetSelectionMode(EdgeSelection, true);
-      }
-      else if (theMode == 2) {
-       QAD_Application::getDesktop()->SetSelectionMode(FaceSelection, true);
-      }
-      else {
-       QAD_Application::getDesktop()->SetSelectionMode(VolumeSelection, true);
+      switch (theMode) {
+      case 0:
+        if (myActor)
+         myActor->SetPointRepresentation(true);
+       else
+         SMESH::SetPointRepresentation(true);
+       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+         aViewWindow->SetSelectionMode(NodeSelection);
+       break;
+      case 1:
+       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+         aViewWindow->SetSelectionMode(EdgeSelection);
+       break;
+      case 2:
+       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+         aViewWindow->SetSelectionMode(FaceSelection);
+       break;
+      default:
+       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+         aViewWindow->SetSelectionMode(VolumeSelection);
       }
-    }
-    else {
-      QAD_Application::getDesktop()->SetSelectionMode(ActorSelection, true);
+    } else {
       if (theMode == 4)
-       mySelection->AddFilter(mySubMeshFilter);
+       mySelectionMgr->installFilter(mySubMeshFilter);
       else if (theMode == 5)
-       mySelection->AddFilter(myGroupFilter);
+       mySelectionMgr->installFilter(myGroupFilter);
+      else if (theMode == 6)
+       mySelectionMgr->installFilter(myMeshFilter);
+      else if (theMode == 7)
+       mySelectionMgr->installFilter(myGeomFilter);
+      
+      if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+       aViewWindow->SetSelectionMode(ActorSelection);
     }
     mySelectionMode = theMode;
-  }
-} 
+  } 
+}
 
 //=================================================================================
 // function : onApply()
@@ -415,16 +678,30 @@ void SMESHGUI_GroupDlg::setSelectionMode(int theMode)
 //=================================================================================
 bool SMESHGUI_GroupDlg::onApply()
 {
-  if (!myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0) {
-    mySelection->ClearIObjects();
-    if (myGroup->_is_nil()) {
+  if (mySMESHGUI->isActiveStudyLocked())
+    return false;
+
+  if (myName->text().stripWhiteSpace().isEmpty())
+    return false;
+
+  if (myGrpTypeId == 0) { // on mesh elements
+    if (!myElements->count())
+      return false;
+
+    mySelectionMgr->clearSelected();
+
+    if (myGroup->_is_nil()) { // creation
+      if (myMesh->_is_nil())
+        return false;
+
       SMESH::ElementType aType = SMESH::ALL;
-      switch(myTypeId) {
+      switch (myTypeId) {
       case 0: aType = SMESH::NODE; break;
       case 1: aType = SMESH::EDGE; break;
       case 2: aType = SMESH::FACE; break;
       case 3: aType = SMESH::VOLUME; break;
       }
+
       SMESH::long_array_var anIdList = new SMESH::long_array;
       int i, k = myElements->count();
       anIdList->length(k);
@@ -433,20 +710,33 @@ bool SMESHGUI_GroupDlg::onApply()
        anIdList[i] = anItem->text().toInt();
       }
 
-      myGroup = mySMESHGUI->AddGroup(myMesh, aType, myName->text());
-      myGroup->Add(anIdList);
+      myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
+      myGroup->Add(anIdList.inout());
+
+      int aColorNumber = myColorSpinBox->value();
+      myGroup->SetColorNumber(aColorNumber);
+
+      _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
+
+      SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
+      SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
 
       /* init for next operation */
       myName->setText("");
+      myColorSpinBox->setValue(0);
       myElements->clear();
       myGroup = SMESH::SMESH_Group::_nil();
-    }
-    else {
+
+    } else { // edition
       myGroup->SetName(myName->text());
+        
+      int aColorNumber = myColorSpinBox->value();
+      myGroup->SetColorNumber(aColorNumber);
 
       QValueList<int> aAddList;
       QValueList<int>::iterator anIt;
       QListBoxItem* anItem;
+
       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
        int anId = anItem->text().toInt();
        if ((anIt = myIdList.find(anId)) == myIdList.end())
@@ -460,7 +750,7 @@ bool SMESHGUI_GroupDlg::onApply()
         int i;
        for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
          anIdList[i] = *anIt;
-       myGroup->Add(anIdList);
+       myGroup->Add(anIdList.inout());
       }
       if (!myIdList.empty()) {
        SMESH::long_array_var anIdList = new SMESH::long_array;
@@ -468,7 +758,7 @@ bool SMESHGUI_GroupDlg::onApply()
         int i;
        for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
          anIdList[i] = *anIt;
-       myGroup->Remove(anIdList);
+       myGroup->Remove(anIdList.inout());
       }
       /* init for next operation */
       myIdList.clear();
@@ -476,10 +766,102 @@ bool SMESHGUI_GroupDlg::onApply()
        myIdList.append(anItem->text().toInt());
     }
 
-    mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
-    mySelection->ClearIObjects();
+    mySMESHGUI->updateObjBrowser(true);
+    SMESH::UpdateView(); // asv: fix of BUG PAL5515
+    mySelectionMgr->clearSelected();
+    return true;
+  }
+  else if (myGrpTypeId == 1) { // on geom object
+    if (CORBA::is_nil(myGroupOnGeom)) { // creation
+      if (myMesh->_is_nil() || !myGeomObjects->length())
+        return false;
+
+      SMESH::ElementType aType = SMESH::ALL;
+      switch (myTypeId) {
+      case 0: aType = SMESH::NODE; break;
+      case 1: aType = SMESH::EDGE; break;
+      case 2: aType = SMESH::FACE; break;
+      case 3: aType = SMESH::VOLUME; break;
+      }
+
+      _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+      GEOM::GEOM_IGroupOperations_var aGroupOp =
+       SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
+
+      if (myGeomObjects->length() == 1) {
+       myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
+      }
+      else {
+        SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
+        if ( aSMESHGen->_is_nil() )
+          return false;
+
+        // create a geometry group
+        GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
+        _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+
+        if (geomGen->_is_nil() || !aStudy)
+          return false;
+
+        GEOM::GEOM_IGroupOperations_var op =
+          geomGen->GetIGroupOperations(aStudy->StudyId());
+        if (op->_is_nil())
+          return false;
+
+        // check and add all selected GEOM objects: they must be
+        // a sub-shapes of the main GEOM and must be of one type
+        TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
+        for ( int i =0; i < myGeomObjects->length(); i++) {
+          TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
+          if (i == 0)
+            aGroupType = aSubShapeType;
+          else if (aSubShapeType != aGroupType) {
+            aGroupType = TopAbs_SHAPE;
+            break;
+          }
+        }
+
+        GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
+        GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
+        op->UnionList(aGroupVar, myGeomObjects);
+
+        if (op->IsDone()) {
+          // publish the GEOM group in study
+          QString aNewGeomGroupName ("Auto_group_for_");
+          aNewGeomGroupName += myName->text();
+          SALOMEDS::SObject_var aNewGroupSO =
+            geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
+        }
+
+        myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
+      }
+
+      int aColorNumber = myColorSpinBox->value();
+      myGroupOnGeom->SetColorNumber(aColorNumber);
+
+      _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
+
+      SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
+
+      SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
+
+      /* init for next operation */
+      myName->setText("");
+      myColorSpinBox->setValue(0);
+      myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
+    }
+    else { // edition
+      myGroupOnGeom->SetName(myName->text());
+
+      int aColorNumber = myColorSpinBox->value();
+      myGroupOnGeom->SetColorNumber(aColorNumber);
+    }
+
+    mySMESHGUI->updateObjBrowser(true);
+    mySelectionMgr->clearSelected();
     return true;
   }
+
   return false;
 }
 
@@ -493,17 +875,6 @@ void SMESHGUI_GroupDlg::onOK()
     onClose();
 }
 
-//=================================================================================
-// function : onClose()
-// purpose  :
-//=================================================================================
-void SMESHGUI_GroupDlg::onClose()
-{
-  close();
-}
-
-
-static bool busy = false;
 //=================================================================================
 // function : onListSelectionChanged()
 // purpose  : Called when selection in element list is changed
@@ -511,33 +882,25 @@ static bool busy = false;
 void SMESHGUI_GroupDlg::onListSelectionChanged()
 {
   //  MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
-  if (busy || !myActor) return;
-  busy = true;
+  if( myIsBusy || !myActor) return;
+    myIsBusy = true;
 
   if (myCurrentLineEdit == 0) {
-    mySelection->ClearIObjects();
+    mySelectionMgr->clearSelected();
     TColStd_MapOfInteger aIndexes;
     QListBoxItem* anItem;
     for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
       if (anItem->isSelected()) {
-       std::vector<int> aVtkList;
-       if (myTypeId == 0)
-         aVtkList = myActor->GetNodeVtkId(anItem->text().toInt());
-       else
-         aVtkList = myActor->GetElemVtkId(anItem->text().toInt());
-
-       if (aVtkList.size() > 0) {
-         std::vector<int>::iterator it;
-         for (it = aVtkList.begin(); it != aVtkList.end(); ++it) {
-           aIndexes.Add(*it);
-         }
-       }
+       int anId = anItem->text().toInt();
+       aIndexes.Add(anId);
       }
     }
-    mySelection->AddOrRemoveIndex(myActor->getIO(), aIndexes, false, false);
-    mySelection->AddIObject(myActor->getIO());
+    mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
+    SALOME_ListIO aList;
+    aList.Append(myActor->getIO());
+    mySelectionMgr->setSelectedObjects(aList,false);
   }
-  busy = false;
+  myIsBusy = false;
 }
 
 //=================================================================================
@@ -546,39 +909,217 @@ void SMESHGUI_GroupDlg::onListSelectionChanged()
 //=================================================================================
 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
 {
-  if (busy) return;
-  busy = true;
+  if ( myIsBusy || !isEnabled()) return;
+  if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
+
+  myIsBusy = true;
 
-  int aNbSel = mySelection->IObjectCount();
+  SALOME_ListIO aList;
+  mySelectionMgr->selectedObjects( aList );
+  
+  int aNbSel = aList.Extent();
   myElements->clearSelection();
 
   if (myCurrentLineEdit) {
-    myCurrentLineEdit->setText("") ;
+    myCurrentLineEdit->setText("");
     QString aString = "";
-    if (aNbSel >= 1) {
-      if (aNbSel > 1) {
-       if (myCurrentLineEdit = mySubMeshLine)
+
+    if (myCurrentLineEdit == myMeshGroupLine) {
+      mySelectSubMesh->setEnabled(false);
+      mySelectGroup->setEnabled(false);
+      myGroupLine->setText("");
+      mySubMeshLine->setText("");
+
+      myGeomGroupBtn->setEnabled(false);
+      myGeomGroupLine->setEnabled(false);
+      myGeomGroupLine->setText("");
+      myGeomObjects = new GEOM::ListOfGO();
+      myGeomObjects->length(0);
+
+      if (myGeomGroupBtn->isOn())
+       myGeomGroupBtn->setOn(false);
+      if (!myCreate)
+        myName->setText("");
+
+      myElements->clear();
+
+      if (aNbSel != 1 ) {
+        myGroup = SMESH::SMESH_Group::_nil();
+       myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); 
+        myMesh = SMESH::SMESH_Mesh::_nil();
+       updateGeomPopup();
+        updateButtons();
+        myIsBusy = false;
+        return;
+      }
+      Handle(SALOME_InteractiveObject) IO = aList.First();
+
+      if (myCreate) {
+        myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
+       updateGeomPopup();
+        if (myMesh->_is_nil())
+       {
+          updateButtons();
+         myIsBusy = false;
+         return;
+       }
+        myGroup = SMESH::SMESH_Group::_nil();
+
+        myActor = SMESH::FindActorByObject(myMesh);
+        SMESH::SetPickable(myActor);
+
+        aString = aList.First()->getName();
+        myMeshGroupLine->setText(aString) ;
+        myMeshGroupLine->home( false );
+
+        mySelectSubMesh->setEnabled(true);
+        mySelectGroup->setEnabled(true);
+        myGeomGroupBtn->setEnabled(true);
+        myGeomGroupLine->setEnabled(true);
+        updateButtons();
+      } else {
+        SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
+        if (aGroup->_is_nil())
+       {
+         myIsBusy = false;
+          return;
+       }
+        myIsBusy = false;
+        myCurrentLineEdit = 0;
+
+       myGroup = SMESH::SMESH_Group::_nil();
+       myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
+       
+        init(aGroup);
+        myIsBusy = true;
+        mySelectSubMesh->setEnabled(true);
+        mySelectGroup->setEnabled(true);
+      }
+      myCurrentLineEdit = 0;
+      myIsBusy = false;
+      if (!myCreate)
+        return;
+
+      if (myGrpTypeId == 0)
+       {
+         if (myTypeId == -1)
+           onTypeChanged(0);
+         else
+           {
+             myElements->clear();
+             setSelectionMode(myTypeId);
+           }
+       }
+
+      myIsBusy = false;
+      return;
+
+    } else if (myCurrentLineEdit == myGeomGroupLine) {
+
+      myGeomObjects = new GEOM::ListOfGO();
+
+      // The mesh SObject
+      _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
+
+      if (aNbSel == 0 || !aMeshSO)
+       {
+         myGeomObjects->length(0);
+          updateButtons();
+         myIsBusy = false;
+         return;
+       }
+
+      myGeomObjects->length(aNbSel);
+
+      GEOM::GEOM_Object_var aGeomGroup;
+      Standard_Boolean testResult;
+      int i = 0;
+      
+      SALOME_ListIteratorOfListIO anIt (aList);
+      for (; anIt.More(); anIt.Next()) {
+       
+       testResult = Standard_False;
+       aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
+
+       // Check if the object is a geometry group
+       if (!testResult || CORBA::is_nil(aGeomGroup))
+         continue;
+       
+
+       // Check if group constructed on the same shape as a mesh or on its child
+       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+       GEOM::GEOM_IGroupOperations_var anOp =
+         SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
+
+       // The main shape of the group
+       GEOM::GEOM_Object_var aGroupMainShape;
+       if (aGeomGroup->GetType() == 37)
+         aGroupMainShape = anOp->GetMainShape(aGeomGroup);
+       else
+         aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
+       _PTR(SObject) aGroupMainShapeSO =
+         //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
+         aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
+       
+       _PTR(SObject) anObj, aRef;
+       bool isRefOrSubShape = false;
+       if (aMeshSO->FindSubObject(1, anObj) &&  anObj->ReferencedObject(aRef)) {
+         //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
+         if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
+           isRefOrSubShape = true;
+         } else {
+           _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
+           _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
+           //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
+           while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
+             //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
+             if (aRef->GetID() == aFather->GetID())
+               isRefOrSubShape = true;
+             else
+               aFather = aFather->GetFather();
+           }
+         }
+       }
+       if (isRefOrSubShape)
+         myGeomObjects[i++] = aGeomGroup;
+      }
+      
+      myGeomObjects->length(i);
+      if ( i == 0 )
+       {
+         myIsBusy = false;
+         return;
+       }
+      
+      aNbSel = i;
+    }
+
+    if(aNbSel >= 1) {
+      if(aNbSel > 1) {
+       if(myCurrentLineEdit == mySubMeshLine)
          aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
-       else if (myCurrentLineEdit = myGroupLine)
+       else if(myCurrentLineEdit == myGroupLine)
          aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
-      }
-      else {
-       aString = mySelection->firstIObject()->getName();
+       else if(myCurrentLineEdit == myGeomGroupLine)
+         aString = tr("%1 Objects").arg(aNbSel);
+      } else {
+       aString = aList.First()->getName();
       }
     }
 
-    myCurrentLineEdit->setText(aString) ;
-    myCurrentLineEdit->home( false );
-  }
-  else {
-    if (aNbSel == 1) {
+    myCurrentLineEdit->setText(aString);
+    myCurrentLineEdit->home(false);
+
+    updateButtons();
+
+  } else {
+    if (aNbSel == 1 && myActor ) {
       QString aListStr = "";
       int aNbItems = 0;
       if (myTypeId == 0) {
-       aNbItems = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aListStr);
-      }
-      else {
-       aNbItems = mySMESHGUI->GetNameOfSelectedElements(mySelection, aListStr);
+       aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
+      } else {
+       aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
       }
       if (aNbItems > 0) {
        QStringList anElements = QStringList::split(" ", aListStr);
@@ -590,9 +1131,18 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
       }
     }
   }
-  busy = false;
-}
 
+  if (!myActor) {
+    if (!myGroup->_is_nil())
+      myActor = SMESH::FindActorByObject(myGroup);
+    else if(!myGroupOnGeom->_is_nil())
+      myActor = SMESH::FindActorByObject(myGroupOnGeom);
+    else
+      myActor = SMESH::FindActorByObject(myMesh);
+  }
+
+  myIsBusy = false;
+}
 
 //=================================================================================
 // function : onSelectSubMesh()
@@ -604,6 +1154,9 @@ void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
     if (mySelectGroup->isChecked()) {
       mySelectGroup->setChecked(false);
     }
+    //VSR: else if (mySelectGeomGroup->isChecked()) {
+    //VSR:   mySelectGeomGroup->setChecked(false);
+    //VSR: }
     myCurrentLineEdit = mySubMeshLine;
     setSelectionMode(4);
   }
@@ -617,6 +1170,7 @@ void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
   mySubMeshLine->setEnabled(on);
 }
 
+
 //=================================================================================
 // function : (onSelectGroup)
 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
@@ -640,6 +1194,46 @@ void SMESHGUI_GroupDlg::onSelectGroup(bool on)
   myGroupLine->setEnabled(on);
 }
 
+
+//=================================================================================
+// function : (onSelectGeomGroup)
+// purpose  : Called when selection in 3D view or ObjectBrowser is changed
+//=================================================================================
+void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
+{
+  if (on) {
+    if (mySelectSubMesh->isChecked()) {
+      mySelectSubMesh->setChecked(false);
+    }
+    else if (mySelectGroup->isChecked()) {
+      mySelectGroup->setChecked(false);
+    }
+    myCurrentLineEdit = myGeomGroupLine;
+    updateGeomPopup();
+    setSelectionMode(8);
+  }
+  else {
+    myGeomGroupBtn->setOn(false);
+    myGeomObjects->length(0);
+    myGeomGroupLine->setText("");
+    myCurrentLineEdit = 0;
+    if (myTypeId != -1)
+      setSelectionMode(myTypeId);
+  }
+}
+
+//=================================================================================
+// function : (onSelectColorGroup)
+// purpose  : Called when setting a color on group
+//=================================================================================
+void SMESHGUI_GroupDlg::onSelectColorGroup(bool on)
+{
+  if (!on)
+    myColorSpinBox->setValue(0);
+  
+  myColorSpinBox->setEnabled(on);
+}
+
 //=================================================================================
 // function : setCurrentSelection()
 // purpose  :
@@ -648,7 +1242,15 @@ void SMESHGUI_GroupDlg::setCurrentSelection()
 {
   QPushButton* send = (QPushButton*)sender();
   myCurrentLineEdit = 0;
-  if (send == mySubMeshBtn) {
+  if (send == myMeshGroupBtn) {
+    myCurrentLineEdit = myMeshGroupLine;
+    if (myCreate)
+      setSelectionMode(6);
+    else
+      setSelectionMode(5);
+    onObjectSelectionChanged();
+  }
+  else if (send == mySubMeshBtn) {
     myCurrentLineEdit = mySubMeshLine;
     onObjectSelectionChanged();
   }
@@ -661,7 +1263,7 @@ void SMESHGUI_GroupDlg::setCurrentSelection()
 
 //=================================================================================
 // function : setFilters()
-// purpose  : SLOT. Called when "Filter" button pressed. 
+// purpose  : SLOT. Called when "Filter" button pressed.
 //=================================================================================
 void SMESHGUI_GroupDlg::setFilters()
 {
@@ -674,19 +1276,29 @@ void SMESHGUI_GroupDlg::setFilters()
     case 3 : aType = SMESH::VOLUME; break;
     default: return;
   }
+
   if ( myFilterDlg == 0 )
-    myFilterDlg = new SMESHGUI_FilterDlg( this, aType, true );
+  {
+    myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
+    connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
+  }
   else
     myFilterDlg->Init( aType );
 
-  myFilterDlg->SetSelection( mySelection );
+  myFilterDlg->SetSelection();
   myFilterDlg->SetMesh( myMesh );
   myFilterDlg->SetSourceWg( myElements );
 
-  if ( myFilterDlg->exec() != QDialog::Accepted )
-    return;
+  myFilterDlg->show();
+}
 
+//=================================================================================
+// function : onFilterAccepted()
+// purpose  : SLOT. Called when Filter dlg closed with OK button.
+//            Uncheck "Select submesh" and "Select group" checkboxes
+//=================================================================================
+void SMESHGUI_GroupDlg::onFilterAccepted()
+{
   if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
   {
     mySelectionMode = myTypeId;
@@ -701,28 +1313,47 @@ void SMESHGUI_GroupDlg::setFilters()
 //=================================================================================
 void SMESHGUI_GroupDlg::onAdd()
 {
-  int aNbSel = mySelection->IObjectCount();
-  if (aNbSel == 0) return;
+  SALOME_ListIO aList;
+  mySelectionMgr->selectedObjects( aList );
+
+  int aNbSel = aList.Extent();
+
+  if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
 
-  busy = true;
+  myIsBusy = true;
 
   SMESH::ElementType aType = SMESH::ALL;
   switch(myTypeId) {
-  case 0: aType = SMESH::NODE; break;
-  case 1: aType = SMESH::EDGE; break;
-  case 2: aType = SMESH::FACE; break;
-  case 3: aType = SMESH::VOLUME; break;
+  case 0: 
+    aType = SMESH::NODE; 
+    mySelector->SetSelectionMode(NodeSelection);
+    break;
+  case 1: 
+    aType = SMESH::EDGE; 
+    mySelector->SetSelectionMode(EdgeSelection);
+    break;
+  case 2: 
+    aType = SMESH::FACE; 
+    mySelector->SetSelectionMode(FaceSelection);
+    break;
+  case 3: 
+    aType = SMESH::VOLUME; 
+    mySelector->SetSelectionMode(VolumeSelection);
+    break;
+  default:
+    mySelector->SetSelectionMode(ActorSelection);
   }
 
+
   if (myCurrentLineEdit == 0) {
-    if (aNbSel != 1) { busy = false; return; }
+    //if (aNbSel != 1) { myIsBusy = false; return; }
     QString aListStr = "";
     int aNbItems = 0;
     if (myTypeId == 0) {
-      aNbItems = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aListStr);
+      aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
     }
     else {
-      aNbItems = mySMESHGUI->GetNameOfSelectedElements(mySelection, aListStr);
+      aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
     }
     if (aNbItems > 0) {
       QStringList anElements = QStringList::split(" ", aListStr);
@@ -736,66 +1367,53 @@ void SMESHGUI_GroupDlg::onAdd()
        myElements->setSelected(anItem, true);
       }
     }
-  }
-  else if (myCurrentLineEdit == mySubMeshLine) {
-    Standard_Boolean aRes;
-    SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
+  } else if (myCurrentLineEdit == mySubMeshLine) {
+    //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
+    
+    SALOME_ListIO aList;
+    mySelectionMgr->selectedObjects( aList );
+
+    SALOME_ListIteratorOfListIO anIt (aList);
     for (; anIt.More(); anIt.Next()) {
-      SMESH::SMESH_subMesh_var aSubMesh = mySMESHGUI->ConvertIOinSubMesh(anIt.Value(), aRes);
-      if (aRes && !aSubMesh->_is_nil()) {
+      SMESH::SMESH_subMesh_var aSubMesh =
+        SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
+      if (!aSubMesh->_is_nil()) {
        // check if mesh is the same
        if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
-         if (aType == SMESH::NODE) {
-           try {
-             SMESH::long_array_var anElements = aSubMesh->GetNodesId();
-             int k = anElements->length();
-             QListBoxItem* anItem = 0;
-             for (int i = 0; i < k; i++) {
-               QString aText = QString::number(anElements[i]);
-               anItem = myElements->findItem(aText, Qt::ExactMatch);
-               if (!anItem) {
-                 anItem = new QListBoxText(aText);
-                 myElements->insertItem(anItem);
-               }
-               myElements->setSelected(anItem, true);
-             }
-           }
-           catch (const SALOME::SALOME_Exception& ex) {
-             QtCatchCorbaException(ex);
-           }
-         }
-         else {
-           try {
-             SMESH::long_array_var anElements = aSubMesh->GetElementsId();
-             int k = anElements->length();
-             QListBoxItem* anItem = 0;
-             for (int i = 0; i < k; i++) {
-               QString aText = QString::number(anElements[i]);
-               anItem = myElements->findItem(aText, Qt::ExactMatch);
-               if (!anItem) {
-                 anItem = new QListBoxText(aText);
-                 myElements->insertItem(anItem);
-               }
-               myElements->setSelected(anItem, true);
-             }
-           }
-           catch (const SALOME::SALOME_Exception& ex) {
-             QtCatchCorbaException(ex);
-           }
-         }
-       }
+          try {
+            SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
+            int k = anElements->length();
+            QListBoxItem* anItem = 0;
+            for (int i = 0; i < k; i++) {
+              QString aText = QString::number(anElements[i]);
+              anItem = myElements->findItem(aText, Qt::ExactMatch);
+              if (!anItem) {
+                anItem = new QListBoxText(aText);
+                myElements->insertItem(anItem);
+              }
+              myElements->setSelected(anItem, true);
+            }
+          }
+          catch (const SALOME::SALOME_Exception& ex) {
+            SalomeApp_Tools::QtCatchCorbaException(ex);
+          }
+        }
       }
     }
     mySelectSubMesh->setChecked(false);
-    busy = false;
+    myIsBusy = false;
     onListSelectionChanged();
-  }
-  else if (myCurrentLineEdit == myGroupLine) {
-    Standard_Boolean aRes;
-    SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
+
+  } else if (myCurrentLineEdit == myGroupLine) {
+    //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
+    SALOME_ListIO aList;
+    mySelectionMgr->selectedObjects( aList );
+    
+    SALOME_ListIteratorOfListIO anIt (aList);
     for (; anIt.More(); anIt.Next()) {
-      SMESH::SMESH_Group_var aGroup = mySMESHGUI->ConvertIOinSMESHGroup(anIt.Value(), aRes);
-      if (aRes && !aGroup->_is_nil()) {
+      SMESH::SMESH_Group_var aGroup =
+        SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
+      if (!aGroup->_is_nil()) {
        // check if mesh is the same
        if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
          SMESH::long_array_var anElements = aGroup->GetListOfID();
@@ -814,11 +1432,57 @@ void SMESHGUI_GroupDlg::onAdd()
       }
     }
     mySelectGroup->setChecked(false);
-    busy = false;
+    myIsBusy = false;
+    onListSelectionChanged();
+
+  } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
+    _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+    GEOM::GEOM_IGroupOperations_var aGroupOp =
+      SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
+
+    SMESH::ElementType aGroupType = SMESH::ALL;
+    switch(aGroupOp->GetType(myGeomObjects[0])) {
+    case 7: aGroupType = SMESH::NODE; break;
+    case 6: aGroupType = SMESH::EDGE; break;
+    case 4: aGroupType = SMESH::FACE; break;
+    case 2: aGroupType = SMESH::VOLUME; break;
+    default: myIsBusy = false; return;
+    }
+
+    if (aGroupType == aType) {
+      _PTR(SObject) aGroupSO =
+        //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
+        aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
+      // Construct filter
+      SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
+      SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
+      SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
+      aBelongToGeom->SetGeom(myGeomObjects[0]);
+      aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
+      aBelongToGeom->SetElementType(aType);
+      aFilter->SetPredicate(aBelongToGeom);
+
+      SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
+
+      int k = anElements->length();
+      QListBoxItem* anItem = 0;
+      for (int i = 0; i < k; i++) {
+       QString aText = QString::number(anElements[i]);
+       anItem = myElements->findItem(aText, Qt::ExactMatch);
+       if (!anItem) {
+         anItem = new QListBoxText(aText);
+         myElements->insertItem(anItem);
+       }
+       myElements->setSelected(anItem, true);
+      }
+    }
+
+    //VSR: mySelectGeomGroup->setChecked(false);
+    myIsBusy = false;
     onListSelectionChanged();
   }
-  busy = false;
-  //  mySelection->ClearIObjects();
+  myIsBusy = false;
+  //  mySelectionMgr->clearSelected();
   updateButtons();
 }
 
@@ -828,18 +1492,21 @@ void SMESHGUI_GroupDlg::onAdd()
 //=================================================================================
 void SMESHGUI_GroupDlg::onRemove()
 {
-  busy = true;
+  myIsBusy = true;
   if (myCurrentLineEdit == 0) {
     for (int i = myElements->count(); i > 0; i--) {
       if (myElements->isSelected(i-1)) {
        myElements->removeItem(i-1);
       }
     }
-  }
-  else {
-    int aNbSel = mySelection->IObjectCount();
-    if (aNbSel == 0) { busy = false; return; }
-    
+  } else {
+    SALOME_ListIO aList;
+    mySelectionMgr->selectedObjects( aList );
+
+    int aNbSel = aList.Extent();
+
+    if (aNbSel == 0) { myIsBusy = false; return; }
+
     SMESH::ElementType aType = SMESH::ALL;
     switch(myTypeId) {
     case 0: aType = SMESH::NODE; break;
@@ -849,11 +1516,14 @@ void SMESHGUI_GroupDlg::onRemove()
     }
 
     if (myCurrentLineEdit == mySubMeshLine) {
-      Standard_Boolean aRes;
-      SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
+      //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
+      SALOME_ListIO aList;
+      mySelectionMgr->selectedObjects( aList );
+
+      SALOME_ListIteratorOfListIO anIt (aList);
       for (; anIt.More(); anIt.Next()) {
-       SMESH::SMESH_subMesh_var aSubMesh = mySMESHGUI->ConvertIOinSubMesh(anIt.Value(), aRes);
-       if (aRes && !aSubMesh->_is_nil()) {
+       SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
+       if (!aSubMesh->_is_nil()) {
          // check if mesh is the same
          if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
            if (aType == SMESH::NODE) {
@@ -867,7 +1537,7 @@ void SMESHGUI_GroupDlg::onRemove()
                }
              }
              catch (const SALOME::SALOME_Exception& ex) {
-               QtCatchCorbaException(ex);
+               SalomeApp_Tools::QtCatchCorbaException(ex);
              }
            }
            else {
@@ -881,7 +1551,7 @@ void SMESHGUI_GroupDlg::onRemove()
                }
              }
              catch (const SALOME::SALOME_Exception& ex) {
-               QtCatchCorbaException(ex);
+               SalomeApp_Tools::QtCatchCorbaException(ex);
              }
            }
          }
@@ -890,9 +1560,13 @@ void SMESHGUI_GroupDlg::onRemove()
     }
     else if (myCurrentLineEdit == myGroupLine) {
       Standard_Boolean aRes;
-      SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
+      //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
+      SALOME_ListIO aList;
+      mySelectionMgr->selectedObjects( aList );
+
+      SALOME_ListIteratorOfListIO anIt (aList);
       for (; anIt.More(); anIt.Next()) {
-       SMESH::SMESH_Group_var aGroup = mySMESHGUI->ConvertIOinSMESHGroup(anIt.Value(), aRes);
+       SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
        if (aRes && !aGroup->_is_nil()) {
          // check if mesh is the same
          if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
@@ -908,7 +1582,7 @@ void SMESHGUI_GroupDlg::onRemove()
       }
     }
   }
-  busy = false;
+  myIsBusy = false;
   updateButtons();
 }
 
@@ -923,7 +1597,7 @@ void SMESHGUI_GroupDlg::onSort()
   // myElements->update();
   int i, k = myElements->count();
   if (k > 0) {
-    busy = true;
+    myIsBusy = true;
     QStringList aSelected;
     std::vector<int> anArray(k);
     //    QMemArray<int> anArray(k);
@@ -931,7 +1605,7 @@ void SMESHGUI_GroupDlg::onSort()
     // fill the array
     for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
       anArray[i] = anItem->text().toInt();
-      if (anItem->isSelected()) 
+      if (anItem->isSelected())
        aSelected.append(anItem->text());
     }
     // sort & update list
@@ -945,7 +1619,7 @@ void SMESHGUI_GroupDlg::onSort()
       anItem = myElements->findItem(*it, Qt::ExactMatch);
       if (anItem) myElements->setSelected(anItem, true);
     }
-    busy = false;
+    myIsBusy = false;
   }
 }
 
@@ -953,25 +1627,230 @@ void SMESHGUI_GroupDlg::onSort()
 // function : closeEvent()
 // purpose  :
 //=================================================================================
-void SMESHGUI_GroupDlg::closeEvent( QCloseEvent* e )
+void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
+{
+  onClose();
+}
+
+//=================================================================================
+// function : SMESHGUI_GroupDlg::onClose
+// purpose  : SLOT called when "Close" button pressed. Close dialog
+//=================================================================================
+void SMESHGUI_GroupDlg::onClose()
 {
-  QAD_StudyFrame* aStudyFrame = mySMESHGUI->GetActiveStudy()->getActiveStudyFrame();
-  if (aStudyFrame->getTypeView() == VIEW_VTK) {
-    mySMESHGUI->SetPickable();
-    if (mySelectionMode == 0)
-      mySMESHGUI->EraseSimulationActors();
+  if (SMESH::GetCurrentVtkView()) {
+    SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
+    SMESH::SetPointRepresentation(false);
+    SMESH::SetPickable();
+  }
 
-    // remove filters from viewer
-    VTKViewer_InteractorStyleSALOME* aStyle = ((VTKViewer_ViewFrame*)aStudyFrame->getRightFrame()->getViewFrame())->getRWInteractor()->GetInteractorStyleSALOME();
-    aStyle->RemoveEdgeFilter();
-    aStyle->RemoveFaceFilter();
+  mySelectionMgr->clearSelected();
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    aViewWindow->SetSelectionMode(ActorSelection);
+  mySelectionMgr->clearFilters();
+  mySMESHGUI->ResetState();
+
+  reject();
+}
 
+//=================================================================================
+// function : onHelp()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupDlg::onHelp()
+{
+  LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
+  if (app) 
+    app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
+  else {
+               QString platform;
+#ifdef WIN32
+               platform = "winapplication";
+#else
+               platform = "application";
+#endif
+    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
+                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                          arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
+                          QObject::tr("BUT_OK"));
   }
-  
-  mySelection->ClearIObjects();
-  QAD_Application::getDesktop()->SetSelectionMode(ActorSelection);
-  mySelection->ClearFilters();
+}
+
+//=================================================================================
+// function : SMESHGUI_GroupDlg::onDeactivate
+// purpose  : SLOT called when dialog must be deativated
+//=================================================================================
+void SMESHGUI_GroupDlg::onDeactivate()
+{
   mySMESHGUI->ResetState();
+  setEnabled(false);
+}
+
+//=================================================================================
+// function : SMESHGUI_GroupDlg::enterEvent
+// purpose  : Event filter
+//=================================================================================
+void SMESHGUI_GroupDlg::enterEvent (QEvent*)
+{
+  if (!isEnabled()) {
+    mySMESHGUI->EmitSignalDeactivateDialog();
+    setEnabled(true);
+    mySelectionMode = -1;
+    setSelectionMode(myTypeId);
+    //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
+    mySMESHGUI->SetActiveDialogBox(this);
+    mySMESHGUI->SetState(800);
+  }
+}
+
+//=================================================================================
+// function : hideEvent
+// purpose  : caused by ESC key
+//=================================================================================
+void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
+{
+  if (!isMinimized() && !myIsBusy)
+    onClose();
+}
 
-  QDialog::closeEvent( e );
+//=================================================================================
+// function : keyPressEvent()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
+{
+  QDialog::keyPressEvent( e );
+  if ( e->isAccepted() )
+    return;
+
+  if ( e->key() == Key_F1 )
+    {
+      e->accept();
+      onHelp();
+    }
+}
+
+//================================================================================
+/*!
+ * \brief Enable showing of the popup when Geometry selection btn is clicked
+  * \param enable - true to enable
+ */
+//================================================================================
+
+enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
+
+void SMESHGUI_GroupDlg::updateGeomPopup()
+{
+  bool enable = false;
+
+  if ( !myMesh->_is_nil() )
+    enable = myMesh->NbEdges() > 0;
+
+  if ( myGeomGroupBtn )
+  {
+    disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
+    if ( enable ) {
+      if ( !myGeomPopup ) {
+        myGeomPopup = new QPopupMenu();
+        myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
+        myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
+        connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
+      }
+      connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
+    }
+  }
+}
+
+
+//=================================================================================
+// function : onGeomSelectionButton()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
+{
+  if ( myGeomPopup && isBtnOn )
+    {
+      myCurrentLineEdit = myGeomGroupLine;
+      int id = myGeomPopup->exec( QCursor::pos() );
+      if (id == DIRECT_GEOM_INDEX || id == -1)
+       setSelectionMode(7);
+    }
+  else if (!isBtnOn)
+    {
+      myCurrentLineEdit = 0;
+      setSelectionMode(8);
+    }
+}
+
+//=================================================================================
+// function : onGeomPopup()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupDlg::onGeomPopup( int index )
+{
+  if ( index == GEOM_BY_MESH_INDEX )
+    {
+      mySelectionMode = -1;
+      if ( !myShapeByMeshOp ) {
+       myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
+       connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
+               SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
+       connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
+               SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
+      }
+      // set mesh object to SMESHGUI_ShapeByMeshOp and start it
+      if ( !myMesh->_is_nil() ) {
+       myIsBusy = true;
+        hide(); // stop processing selection
+       myIsBusy = false;
+        myShapeByMeshOp->setModule( mySMESHGUI );
+        myShapeByMeshOp->setStudy( 0 ); // it's really necessary
+        myShapeByMeshOp->SetMesh( myMesh );
+        myShapeByMeshOp->start();
+      }
+    }
+}
+
+//================================================================================
+/*!
+ * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
+ */
+//================================================================================
+
+void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
+{
+  if ( myShapeByMeshOp == op ) {
+    mySMESHGUI->getApp()->updateObjectBrowser();
+    show();
+    // Select a found geometry object
+    GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
+    if ( !aGeomVar->_is_nil() )
+    {
+      QString ID = aGeomVar->GetStudyEntry();
+      _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+      if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.latin1() )) {
+       SALOME_ListIO anIOList;
+       Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
+         ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
+       anIOList.Append( anIO );
+       mySelectionMgr->setSelectedObjects( anIOList, false );
+       onObjectSelectionChanged();
+      }
+    }
+  }
+}
+
+//================================================================================
+/*!
+ * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
+ */
+//================================================================================
+
+void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
+{
+  if ( myShapeByMeshOp == op )
+    {
+      show();
+      setSelectionMode(7);
+    }
 }