Salome HOME
Fix mixed Python dump of a new and a closed study
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupDlg.cxx
index 10995de1942a6c74074942ad7e8ebf7c27e5fddd..36534f31ad8da3093cd5d62c3065f7f3c60e9dfe 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include <SMESH_TypeFilter.hxx>
 #include <SMESH_Actor.h>
-#include <SMESH_ActorUtils.h>
+//#include <SMESH_ActorUtils.h>
 #include <SMESH_LogicalFilter.hxx>
 
 // SALOME GEOM includes
 #include <GEOMBase.h>
 #include <GEOM_SelectionFilter.h>
+#include <GEOM_wrap.hxx>
 
 // SALOME GUI includes
 #include <QtxColorButton.h>
@@ -52,6 +53,7 @@
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_Session.h>
 #include <SUIT_MessageBox.h>
+#include <SUIT_OverrideCursor.h>
 
 #include <SalomeApp_Tools.h>
 #include <SalomeApp_Application.h>
@@ -59,7 +61,6 @@
 #include <LightApp_SelectionMgr.h>
 
 #include <SALOME_ListIO.hxx>
-#include <SALOME_ListIteratorOfListIO.hxx>
 
 #include <SVTK_ViewWindow.h>
 
 enum grpSelectionMode {
   grpNoSelection       = -1,
   grpNodeSelection     = 0,
-  grpBallSelection     = 1,
-  grpEdgeSelection     = 2,
-  grpFaceSelection     = 3,
-  grpVolumeSelection   = 4,
-  grpSubMeshSelection  = 5,
-  grpGroupSelection    = 6,
-  grpMeshSelection     = 7,
-  grpGeomSelection     = 8,
-  grpAllSelection      = 9,
+  grp0DSelection       = 1,
+  grpBallSelection     = 2,
+  grpEdgeSelection     = 3,
+  grpFaceSelection     = 4,
+  grpVolumeSelection   = 5,
+  grpSubMeshSelection  = 6,
+  grpGroupSelection    = 7,
+  grpMeshSelection     = 8,
+  grpGeomSelection     = 9,
+  grpAllSelection      = 10,
 };
 
 //=================================================================================
@@ -122,12 +124,12 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
                                       SMESH::SMESH_Mesh_ptr theMesh )
   : QDialog( SMESH::GetDesktop( theModule ) ),
     mySMESHGUI( theModule ),
-    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
+    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
     mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
     myIsBusy( false ),
     myNameChanged( false ),
-    myIsApplyAndClose( false ),
-    myNbChangesOfContents(0)
+    myNbChangesOfContents(0),
+    myIsApplyAndClose( false )
 {
   initDialog( true );
   if ( !theMesh->_is_nil() )
@@ -150,7 +152,7 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
                                       const bool theIsConvert )
   : QDialog( SMESH::GetDesktop( theModule ) ),
     mySMESHGUI( theModule ),
-    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
+    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
     mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
     myIsBusy( false ),
     myNameChanged( false ),
@@ -190,7 +192,7 @@ void SMESHGUI_GroupDlg::initDialog( bool create)
   QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
 
   setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
-  myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
+  myHelpFileName = create ? "creating_groups.html" : "editing_groups.html";
 
   setSizeGripEnabled( true);
 
@@ -214,6 +216,7 @@ void SMESHGUI_GroupDlg::initDialog( bool create)
 
   QStringList types;
   types.append( tr( "MESH_NODE" ) );
+  types.append( tr( "SMESH_ELEM0D" ) );
   types.append( tr( "SMESH_BALL_ELEM" ) );
   types.append( tr( "SMESH_EDGE" ) );
   types.append( tr( "SMESH_FACE" ) );
@@ -436,29 +439,30 @@ void SMESHGUI_GroupDlg::initDialog( bool create)
 
   connect(myOKBtn,         SIGNAL(clicked()), this, SLOT(onOK()));
   connect(myApplyBtn,      SIGNAL(clicked()), this, SLOT(onApply()));
-  connect(myCloseBtn,      SIGNAL(clicked()), this, SLOT(onClose()));
+  connect(myCloseBtn,      SIGNAL(clicked()), this, SLOT(reject()));
   connect(myHelpBtn,       SIGNAL(clicked()), this, SLOT(onHelp()));
 
   /* Init selection */
   mySMESHGUI->SetActiveDialogBox(this);
-  mySMESHGUI->SetState(800);
 
+  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
   mySelectionMode = grpNoSelection;
-  myMeshFilter = new SMESH_TypeFilter(MESH);
+
+  myMeshFilter    = new SMESH_TypeFilter(SMESH::MESH);
   mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
                                             SMESH_LogicalFilter::LO_OR,
                                             /*takeOwnership=*/true);
-  myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
-                                          SMESH_LogicalFilter::LO_OR,
-                                          /*takeOwnership=*/true);
-  SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
-  myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
+  myGroupFilter   = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
+                                            SMESH_LogicalFilter::LO_OR,
+                                            /*takeOwnership=*/true);
+  myGeomFilter    = new GEOM_SelectionFilter( aStudy, true );
 
   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
-  connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(onClose()));
+  connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(reject()));
   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),  this, SLOT(onObjectSelectionChanged()));
   connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()),      this, SLOT(onVisibilityChanged()));
-
+  connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()),   this, SLOT(onOpenView()));
+  connect(mySMESHGUI, SIGNAL(SignalCloseView()),              this, SLOT(onCloseView()));
   rb1->setChecked(true); // VSR !!!
   onGrpTypeChanged(0); // VSR!!!
 
@@ -494,10 +498,7 @@ QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
   QString aName = "";
 
   // collect all object names of SMESH component
-  SalomeApp_Study* appStudy =
-    dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
-  if ( !appStudy ) return aName;
-  _PTR(Study) aStudy = appStudy->studyDS();
+  _PTR(Study) aStudy = SMESH::getStudy();
 
   std::set<std::string> aSet;
   _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
@@ -515,12 +516,27 @@ QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
   bool isUnique = false;
   while (!isUnique) {
     aName = theOperation + "_" + QString::number(++aNumber);
-    isUnique = (aSet.count(aName.toLatin1().data()) == 0);
+    isUnique = (aSet.count(std::string(aName.toUtf8().constData())) == 0);
   }
 
   return aName;
 }
 
+void  SMESHGUI_GroupDlg::setDefaultName() const
+{
+  QString aResName;
+  int i=1;
+  QString aPrefix ="Group_";
+  _PTR(SObject) anObj;
+  do
+  {
+    aResName = aPrefix + QString::number( i++ );
+    anObj = SMESH::getStudy()->FindObject( aResName.toUtf8().constData() );
+  }
+  while ( anObj );
+  myName->setText(aResName); 
+}
+
 //=================================================================================
 // function : Init()
 // purpose  :
@@ -543,13 +559,15 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
   SetAppropriateActor();
 
   setDefaultGroupColor();
+  setDefaultName();
+
 
   SALOME_ListIO aList;
   mySelectionMgr->selectedObjects( aList );
   if( !aList.IsEmpty() )
   {
     QString aName = aList.First()->getName();
-    myMeshGroupLine->setText(aName);
+    myMeshGroupLine->setText(aName);//??????
     myMeshGroupLine->home( false );
   }
 
@@ -572,7 +590,7 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
 
   myNameChanged = true;
   myName->blockSignals(true);
-  myName->setText(theGroup->GetName());
+  myName->setText(SMESH::fromUtf8(theGroup->GetName()));
   myName->blockSignals(false);
   myName->home(false);
 
@@ -583,11 +601,14 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
 
   int aType = 0;
   switch(theGroup->GetType()) {
-  case SMESH::NODE:   aType = 0; break;
-  case SMESH::BALL:   aType = 1; break;
-  case SMESH::EDGE:   aType = 2; break;
-  case SMESH::FACE:   aType = 3; break;
-  case SMESH::VOLUME: aType = 4; break;
+  case SMESH::NODE:   aType = grpNodeSelection;   break;
+  case SMESH::ELEM0D: aType = grp0DSelection;     break;
+  case SMESH::BALL:   aType = grpBallSelection;   break;
+  case SMESH::EDGE:   aType = grpEdgeSelection;   break;
+  case SMESH::FACE:   aType = grpFaceSelection;   break;
+  case SMESH::VOLUME: aType = grpVolumeSelection; break;
+  case SMESH::ALL:
+  case SMESH::NB_ELEMENT_TYPES: break;
   }
   myTypeGroup->button(aType)->setChecked(true);
 
@@ -639,7 +660,7 @@ void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
   else if ( grpType == 1 ) // group on geom
   {
     QString aShapeName( "" );
-    _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+    _PTR(Study) aStudy = SMESH::getStudy();
     GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
     if (!aGroupShape->_is_nil())
     {
@@ -707,6 +728,17 @@ void SMESHGUI_GroupDlg::updateButtons()
     }
   }
 
+  bool meshHasGeom = ( myMesh->_is_nil() || myMesh->HasShapeToMesh() );
+  if ( myGrpTypeId != 1 )
+  {
+    myGrpTypeGroup->button(1)->setEnabled( meshHasGeom );
+  }
+  else
+  {
+    myGeomGroupBtn->setEnabled( meshHasGeom );
+    myGeomGroupLine->setEnabled( meshHasGeom );
+  }
+
   myOKBtn->setEnabled(enable);
   myApplyBtn->setEnabled(enable);
 }
@@ -805,7 +837,10 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
       break;
     case grpBallSelection:
-      //if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
+      if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
+      break;
+    case grp0DSelection:
+      if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : Elem0DSelection);
       break;
     case grpFaceSelection:
       if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
@@ -817,15 +852,15 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
 
       SMESH_TypeFilter* f = 0;
       switch (myTypeId) {
-      case grpNodeSelection:   f = new SMESH_TypeFilter(SUBMESH); break;
-      case grpEdgeSelection:   f = new SMESH_TypeFilter(SUBMESH_EDGE); break;
-      case grpFaceSelection:   f = new SMESH_TypeFilter(SUBMESH_FACE); break;
-      case grpVolumeSelection: f = new SMESH_TypeFilter(SUBMESH_SOLID); break;
-      default:                 f = new SMESH_TypeFilter(SUBMESH);
+      case grpNodeSelection:   f = new SMESH_TypeFilter(SMESH::SUBMESH); break;
+      case grpEdgeSelection:   f = new SMESH_TypeFilter(SMESH::SUBMESH_EDGE); break;
+      case grpFaceSelection:   f = new SMESH_TypeFilter(SMESH::SUBMESH_FACE); break;
+      case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_SOLID); break;
+      default:                 f = new SMESH_TypeFilter(SMESH::SUBMESH);
       }
       QList<SUIT_SelectionFilter*> filtList;
       filtList.append( f );
-      filtList.append( new SMESH_TypeFilter(SUBMESH_COMPOUND));
+      filtList.append( new SMESH_TypeFilter(SMESH::SUBMESH_COMPOUND));
       mySubMeshFilter->setFilters( filtList );
 
       mySelectionMgr->installFilter( mySubMeshFilter );
@@ -837,12 +872,13 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
 
       SMESH_TypeFilter* f = 0;
       switch (myTypeId) {
-      case grpNodeSelection:   f = new SMESH_TypeFilter(GROUP_NODE); break;
-      case grpBallSelection:   f = new SMESH_TypeFilter(GROUP_BALL); break;
-      case grpEdgeSelection:   f = new SMESH_TypeFilter(GROUP_EDGE); break;
-      case grpFaceSelection:   f = new SMESH_TypeFilter(GROUP_FACE); break;
-      case grpVolumeSelection: f = new SMESH_TypeFilter(GROUP_VOLUME); break;
-      default:                 f = new SMESH_TypeFilter(GROUP);
+      case grpNodeSelection:   f = new SMESH_TypeFilter(SMESH::GROUP_NODE);   break;
+      case grp0DSelection:     f = new SMESH_TypeFilter(SMESH::GROUP_0D);     break;
+      case grpBallSelection:   f = new SMESH_TypeFilter(SMESH::GROUP_BALL);   break;
+      case grpEdgeSelection:   f = new SMESH_TypeFilter(SMESH::GROUP_EDGE);   break;
+      case grpFaceSelection:   f = new SMESH_TypeFilter(SMESH::GROUP_FACE);   break;
+      case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_VOLUME); break;
+      default:                 f = new SMESH_TypeFilter(SMESH::GROUP);
       }
       QList<SUIT_SelectionFilter*> filtList;
       filtList.append( f );
@@ -875,7 +911,7 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
 //=================================================================================
 bool SMESHGUI_GroupDlg::onApply()
 {
-  if (mySMESHGUI->isActiveStudyLocked())
+  if (SMESHGUI::isStudyLocked())
     return false;
 
   if (myName->text().trimmed().isEmpty())
@@ -883,10 +919,11 @@ bool SMESHGUI_GroupDlg::onApply()
 
   SMESH::ElementType aType = SMESH::ALL;
   switch (myTypeId) {
-  case grpNodeSelection:   aType = SMESH::NODE; break;
-  case grpBallSelection:   aType = SMESH::BALL; break;
-  case grpEdgeSelection:   aType = SMESH::EDGE; break;
-  case grpFaceSelection:   aType = SMESH::FACE; break;
+  case grpNodeSelection:   aType = SMESH::NODE;   break;
+  case grp0DSelection:     aType = SMESH::ELEM0D; break;
+  case grpBallSelection:   aType = SMESH::BALL;   break;
+  case grpEdgeSelection:   aType = SMESH::EDGE;   break;
+  case grpFaceSelection:   aType = SMESH::FACE;   break;
   case grpVolumeSelection: aType = SMESH::VOLUME; break;
   }
 
@@ -894,8 +931,10 @@ bool SMESHGUI_GroupDlg::onApply()
   QStringList anEntryList;
 
   SMESH::SMESH_GroupBase_var resultGroup;
-  bool isCreation;
+  bool isCreation = false, isConversion = false;
     
+  SUIT_OverrideCursor wc;
+
   if (myGrpTypeId == 0)  // standalone
   {
     if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
@@ -913,8 +952,9 @@ bool SMESHGUI_GroupDlg::onApply()
         else
           myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
 
-        myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
+        myGroupOnGeom   = SMESH::SMESH_GroupOnGeom::_nil();
         myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
+        isConversion    = true;
       }
     }
 
@@ -1006,13 +1046,11 @@ bool SMESHGUI_GroupDlg::onApply()
       if (myMesh->_is_nil() || !myGeomObjects->length())
         return false;
 
-      _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
-      GEOM::GEOM_IGroupOperations_var aGroupOp =
-        SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
+      _PTR(Study) aStudy = SMESH::getStudy();
 
       if (myGeomObjects->length() == 1) {
         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
-                                                    myName->text().toLatin1().data(),
+                                                    myName->text().toUtf8(),
                                                     myGeomObjects[0]);
       }
       else {
@@ -1022,20 +1060,18 @@ bool SMESHGUI_GroupDlg::onApply()
 
         // create a geometry group
         GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
-        _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
 
-        if (geomGen->_is_nil() || !aStudy)
+        if (geomGen->_is_nil())
           return false;
 
-        GEOM::GEOM_IGroupOperations_var op =
-          geomGen->GetIGroupOperations(aStudy->StudyId());
+        GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
         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++) {
+        for ( int i =0; i < (int)myGeomObjects->length(); i++) {
           TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
           if (i == 0)
             aGroupType = aSubShapeType;
@@ -1045,8 +1081,8 @@ bool SMESHGUI_GroupDlg::onApply()
           }
         }
 
-        GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
-        GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
+        GEOM::GEOM_Object_var  aMeshShape = myMesh->GetShapeToMesh();
+        GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
         op->UnionList(aGroupVar, myGeomObjects);
 
         if (op->IsDone()) {
@@ -1054,12 +1090,12 @@ bool SMESHGUI_GroupDlg::onApply()
           QString aNewGeomGroupName ( "Auto_group_for_" );
           aNewGeomGroupName += myName->text();
           SALOMEDS::SObject_var aNewGroupSO =
-            geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
-                                aNewGeomGroupName.toLatin1().data(), aMeshShape);
+            geomGen->AddInStudy(aGroupVar,
+                                aNewGeomGroupName.toUtf8(), aMeshShape);
         }
 
         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
-                                                    myName->text().toLatin1().data(),
+                                                    myName->text().toUtf8(),
                                                     aGroupVar);
       }
       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
@@ -1077,14 +1113,14 @@ bool SMESHGUI_GroupDlg::onApply()
   {
     if ( myFilter->_is_nil() ) return false;
 
-    if (CORBA::is_nil(myGroupOnFilter)) { // creation
+    if (CORBA::is_nil(myGroupOnFilter)) // creation
+    {
       if (myMesh->_is_nil())
         return false;
 
       myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
-                                                      myName->text().toLatin1().data(),
+                                                      myName->text().toUtf8(),
                                                       myFilter);
-
       resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
       isCreation = true;
     }
@@ -1098,7 +1134,7 @@ bool SMESHGUI_GroupDlg::onApply()
     anIsOk = true;
   }
 
-  if( anIsOk )
+  if ( anIsOk )
   {
     SALOMEDS::Color aColor = getGroupColor();
     resultGroup->SetColor(aColor);
@@ -1107,42 +1143,66 @@ bool SMESHGUI_GroupDlg::onApply()
     if( aMeshGroupSO )
       anEntryList.append( aMeshGroupSO->GetID().c_str() );
 
+    resultGroup->SetName(myName->text().trimmed().toUtf8());
+
     if ( isCreation )
     {
       SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
 
       /* init for the next operation */
-      myName->setText( "" );
+      setDefaultName();
       myElements->clear();
       myGroup         = SMESH::SMESH_Group::_nil();
       myGroupOnGeom   = SMESH::SMESH_GroupOnGeom::_nil();
       myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
       myFilter        = SMESH::Filter::_nil();
+
+      setDefaultGroupColor(); // reset color for case if 'auto-color' feature is enabled.
     }
     else
     {
-      resultGroup->SetName(myName->text().toLatin1().data());
-
       if ( aMeshGroupSO )
-        if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
-          anActor->setName(myName->text().toLatin1().data());
+      {
+        if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
+        {
+          Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
+          if ( isConversion ) { // need to reset TVisualObj and actor
+            SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true );
+            SMESH::Update( anIO,true);
+            myActorsList.clear();
+            anActor = SMESH::FindActorByEntry( anIO->getEntry() );
+            if ( !anActor ) return false;
+            myActorsList.append( anActor );
+          }
+          anActor->setName(myName->text().toUtf8());
+          QColor c;
+          int delta;
           switch ( myTypeId ) {
           case grpNodeSelection:   anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
+          case grp0DSelection:     anActor->Set0DColor  ( aColor.R, aColor.G, aColor.B ); break;
           case grpBallSelection:   anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
           case grpEdgeSelection:   anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
-          case grpFaceSelection:   
           case grpVolumeSelection: 
+            SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
+            anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;          
+            break;
+          case grpFaceSelection:   
           default:
-              QColor c;
-              int delta;
-              SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
-              anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;          
+            SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
+            anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;          
+            break;
+          }
+          // update a visible group according to a changed contents
+          if ( !isConversion && anActor->GetVisibility() )
+          {
+            SMESH::Update( anIO, true );
+            SMESH::RepaintCurrentView();
           }
         }
+      }
     }
     SMESHGUI::Modified();
     mySMESHGUI->updateObjBrowser(true);
-    SMESH::UpdateView(); // asv: fix of BUG PAL5515
     mySelectionMgr->clearSelected();
 
     if( LightApp_Application* anApp =
@@ -1160,8 +1220,10 @@ void SMESHGUI_GroupDlg::onOK()
 {
   setIsApplyAndClose( true );
   if ( onApply() )
-    onClose();
+    reject();
   setIsApplyAndClose( false );
+
+  if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
 }
 
 //=================================================================================
@@ -1264,6 +1326,10 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
         // any visible actor of group or submesh of myMesh
         SetAppropriateActor();
 
+        setDefaultGroupColor();
+        if (myName->text().isEmpty())
+          setDefaultName();
+
         aString = aList.First()->getName();
         myMeshGroupLine->setText(aString);
         myMeshGroupLine->home( false );
@@ -1341,18 +1407,22 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
           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)
+        if (aGeomGroup->GetType() == 37) {
+          GEOM::GEOM_IGroupOperations_wrap anOp =
+            SMESH::GetGEOMGen()->GetIGroupOperations();
           aGroupMainShape = anOp->GetMainShape(aGeomGroup);
-        else
-          aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
+          // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
+        }
+        else {
+          aGroupMainShape = aGeomGroup;
+          aGroupMainShape->Register();
+        }
+        CORBA::String_var entry = aGroupMainShape->GetStudyEntry();
         _PTR(SObject) aGroupMainShapeSO =
-          aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
+          SMESH::getStudy()->FindObjectID( entry.in() );
 
         _PTR(SObject) anObj, aRef;
         bool isRefOrSubShape = false;
@@ -1376,10 +1446,10 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
 
       myGeomObjects->length(i);
       if ( i == 0 )
-        {
-          myIsBusy = false;
-          return;
-        }
+      {
+        myIsBusy = false;
+        return;
+      }
 
       aNbSel = i;
     }
@@ -1527,12 +1597,14 @@ void SMESHGUI_GroupDlg::onSelectAll()
 
   myElementsLab->setEnabled( !noElemsModif );
   myElements->setEnabled   ( !noElemsModif );
-  myFilterBtn->setEnabled  ( !mySelectAll->isChecked() );
+  myFilterBtn->setEnabled  ( !noElemsModif );
   myAddBtn->setEnabled     ( !noElemsModif );
   myRemoveBtn->setEnabled  ( !noElemsModif );
   mySortBtn->setEnabled    ( !noElemsModif );
   mySelectBox->setEnabled  ( !noElemsModif );
   myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
+  if ( noElemsModif ) mySMESHGUI->ResetState();
+  else                mySMESHGUI->SetState(800);
 
   int selMode     = mySelectionMode;
   mySelectionMode = grpNoSelection;
@@ -1593,7 +1665,7 @@ void SMESHGUI_GroupDlg::onSelectGroup(bool on)
 
 //=================================================================================
 // function : (onSelectGeomGroup)
-// purpose  : Called when group type changed. on == "on group" or "on filter"
+// purpose  : Called when group type changed. on == "on geometry" or "on filter"
 //=================================================================================
 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
 {
@@ -1604,7 +1676,7 @@ void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
     else if (mySelectGroup->isChecked()) {
       mySelectGroup->setChecked(false);
     }
-    if ( myGrpTypeId == 1 ) { // on group
+    if ( myGrpTypeId == 1 ) { // on geometry
       myCurrentLineEdit = myGeomGroupLine;
       updateGeomPopup();
     }
@@ -1669,10 +1741,11 @@ void SMESHGUI_GroupDlg::setFilters()
   SMESH::ElementType aType = SMESH::ALL;
   switch ( myTypeId )
   {
-    case grpNodeSelection:   aType = SMESH::NODE; break;
-    case grpBallSelection:   aType = SMESH::BALL; break;
-    case grpEdgeSelection:   aType = SMESH::EDGE; break;
-    case grpFaceSelection:   aType = SMESH::FACE; break;
+    case grpNodeSelection:   aType = SMESH::NODE;   break;
+    case grp0DSelection:     aType = SMESH::ELEM0D; break;
+    case grpBallSelection:   aType = SMESH::BALL;   break;
+    case grpEdgeSelection:   aType = SMESH::EDGE;   break;
+    case grpFaceSelection:   aType = SMESH::FACE;   break;
     case grpVolumeSelection: aType = SMESH::VOLUME; break;
     default:                 return;
   }
@@ -1691,8 +1764,12 @@ void SMESHGUI_GroupDlg::setFilters()
     myFilterDlg->Init( aType );
   }
 
-  myFilterDlg->SetSelection();
+  bool isStandalone = ( sender() == myFilterBtn );
+  myFilterDlg->SetEnabled( /*setInViewer=*/isStandalone,
+                           /*diffSources=*/isStandalone );
   myFilterDlg->SetMesh( myMesh );
+  myFilterDlg->SetGroup( myGroupOnFilter );
+  myFilterDlg->SetSelection();
   myFilterDlg->SetSourceWg( myElements, false );
 
   myFilterDlg->show();
@@ -1730,6 +1807,10 @@ void SMESHGUI_GroupDlg::onFilterAccepted()
         mesh = myGroupOnFilter->GetMesh();
     }
     myFilter->SetMesh( mesh );
+
+    // highlight ids if selection changed in the Viewer (IPAL52924)
+    myCurrentLineEdit = 0;
+    onObjectSelectionChanged();
   }
 
   updateButtons();
@@ -1748,6 +1829,8 @@ void SMESHGUI_GroupDlg::onAdd()
 
   if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
 
+  SUIT_OverrideCursor wc;
+
   myIsBusy = true;
   int sizeBefore = myElements->count();
 
@@ -1759,7 +1842,11 @@ void SMESHGUI_GroupDlg::onAdd()
     break;
   case grpBallSelection:
     aType = SMESH::BALL;
-    //mySelector->SetSelectionMode(BallSelection);
+    mySelector->SetSelectionMode(BallSelection);
+    break;
+  case grp0DSelection:
+    aType = SMESH::ELEM0D;
+    mySelector->SetSelectionMode(Elem0DSelection);
     break;
   case grpEdgeSelection:
     aType = SMESH::EDGE;
@@ -1914,9 +2001,8 @@ void SMESHGUI_GroupDlg::onAdd()
     onListSelectionChanged();
 
   } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
-    _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
-    GEOM::GEOM_IGroupOperations_var aGroupOp =
-      SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
+    GEOM::GEOM_IGroupOperations_wrap aGroupOp =
+      SMESH::GetGEOMGen()->GetIGroupOperations();
 
     SMESH::ElementType aGroupType = SMESH::ALL;
     switch(aGroupOp->GetType(myGeomObjects[0])) {
@@ -1929,8 +2015,8 @@ void SMESHGUI_GroupDlg::onAdd()
 
     if (aGroupType == aType) {
       _PTR(SObject) aGroupSO =
-        //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
-        aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
+        //SMESH::getStudy()->FindObjectIOR(SMESH::getStudy()->ConvertObjectToIOR(myGeomGroup));
+        SMESH::getStudy()->FindObjectID(myGeomObjects[0]->GetStudyEntry());
       // Construct filter
       SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
       SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
@@ -2000,10 +2086,11 @@ void SMESHGUI_GroupDlg::onRemove()
 
     SMESH::ElementType aType = SMESH::ALL;
     switch(myTypeId) {
-    case grpNodeSelection:   aType = SMESH::NODE; break;
-    case grpBallSelection:   aType = SMESH::BALL; break;
-    case grpEdgeSelection:   aType = SMESH::EDGE; break;
-    case grpFaceSelection:   aType = SMESH::FACE; break;
+    case grpNodeSelection:   aType = SMESH::NODE;   break;
+    case grp0DSelection:     aType = SMESH::ELEM0D; break;
+    case grpBallSelection:   aType = SMESH::BALL;   break;
+    case grpEdgeSelection:   aType = SMESH::EDGE;   break;
+    case grpFaceSelection:   aType = SMESH::FACE;   break;
     case grpVolumeSelection: aType = SMESH::VOLUME; break;
     }
 
@@ -2053,15 +2140,13 @@ void SMESHGUI_GroupDlg::onRemove()
       }
     }
     else if (myCurrentLineEdit == myGroupLine) {
-      Standard_Boolean aRes;
-      //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 = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
-        if (aRes && !aGroup->_is_nil()) {
+        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();
@@ -2126,15 +2211,6 @@ void SMESHGUI_GroupDlg::onSort()
   }
 }
 
-//=================================================================================
-// function : closeEvent()
-// purpose  :
-//=================================================================================
-void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
-{
-  onClose();
-}
-
 //=================================================================================
 // function : onVisibilityChanged()
 // purpose  :
@@ -2145,10 +2221,10 @@ void SMESHGUI_GroupDlg::onVisibilityChanged()
 }
 
 //=================================================================================
-// function : SMESHGUI_GroupDlg::onClose
+// function : SMESHGUI_GroupDlg::reject
 // purpose  : SLOT called when "Close" button pressed. Close dialog
 //=================================================================================
-void SMESHGUI_GroupDlg::onClose()
+void SMESHGUI_GroupDlg::reject()
 {
   if (SMESH::GetCurrentVtkView()) {
     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
@@ -2169,7 +2245,35 @@ void SMESHGUI_GroupDlg::onClose()
   mySelectionMgr->clearFilters();
   mySMESHGUI->ResetState();
 
-  reject();
+  QDialog::reject();
+
+  if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
+}
+
+//=================================================================================
+// function : onOpenView()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupDlg::onOpenView()
+{
+  if ( mySelector ) {
+    SMESH::SetPointRepresentation(false);
+  }
+  else {
+    mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
+    mySMESHGUI->EmitSignalDeactivateDialog();
+    setEnabled(true);
+  }
+}
+
+//=================================================================================
+// function : onCloseView()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupDlg::onCloseView()
+{
+  onDeactivate();
+  mySelector = 0;
 }
 
 //=================================================================================
@@ -2180,25 +2284,27 @@ 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;
+  {
+    app->onHelpContextModule
+      ( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) : QString(""), myHelpFileName );
+  }
+  else
+  {
 #ifdef WIN32
-    platform = "winapplication";
+    QString platform = "winapplication";
 #else
-    platform = "application";
+    QString platform = "application";
 #endif
     SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
                              tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
-                             arg(app->resourceMgr()->stringValue( "ExternalBrowser",
-                                                                 platform)).
+                             arg(app->resourceMgr()->stringValue( "ExternalBrowser", platform)).
                              arg(myHelpFileName));
   }
 }
 
 //=================================================================================
 // function : SMESHGUI_GroupDlg::onDeactivate
-// purpose  : SLOT called when dialog must be deativated
+// purpose  : SLOT called when dialog must be deactivated
 //=================================================================================
 void SMESHGUI_GroupDlg::onDeactivate()
 {
@@ -2213,26 +2319,20 @@ void SMESHGUI_GroupDlg::onDeactivate()
 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
 {
   if (!isEnabled()) {
+    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
+    if ( aViewWindow && !mySelector) {
+      mySelector = aViewWindow->GetSelector();
+    }
     mySMESHGUI->EmitSignalDeactivateDialog();
     setEnabled(true);
     mySelectionMode = grpNoSelection;
     setSelectionMode(myTypeId);
-    //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
     mySMESHGUI->SetActiveDialogBox(this);
-    mySMESHGUI->SetState(800);
+    if ( mySelectBox->isEnabled() ) mySMESHGUI->SetState(800);
+    else                            mySMESHGUI->ResetState();
   }
 }
 
-//=================================================================================
-// function : hideEvent
-// purpose  : caused by ESC key
-//=================================================================================
-void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
-{
-  if (!isMinimized() && !myIsBusy)
-    onClose();
-}
-
 //=================================================================================
 // function : keyPressEvent()
 // purpose  :
@@ -2244,16 +2344,16 @@ void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
     return;
 
   if ( e->key() == Qt::Key_F1 )
-    {
-      e->accept();
-      onHelp();
-    }
+  {
+    e->accept();
+    onHelp();
+  }
 }
 
 //================================================================================
 /*!
  * \brief Enable showing of the popup when Geometry selection btn is clicked
 * \param enable - true to enable
+ * \param enable - true to enable
  */
 //================================================================================
 
@@ -2289,17 +2389,17 @@ void SMESHGUI_GroupDlg::updateGeomPopup()
 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
 {
   if ( myGeomPopup && isBtnOn )
-    {
-      myCurrentLineEdit = myGeomGroupLine;
-      QAction* a = myGeomPopup->exec( QCursor::pos() );
-      if (!a || myActions[a] == DIRECT_GEOM_INDEX)
-        setSelectionMode(grpGeomSelection);
-    }
+  {
+    myCurrentLineEdit = myGeomGroupLine;
+    QAction* a = myGeomPopup->exec( QCursor::pos() );
+    if (!a || myActions[a] == DIRECT_GEOM_INDEX)
+      setSelectionMode(grpGeomSelection);
+  }
   else if (!isBtnOn)
-    {
-      myCurrentLineEdit = 0;
-      setSelectionMode(grpAllSelection);
-    }
+  {
+    myCurrentLineEdit = 0;
+    setSelectionMode(grpAllSelection);
+  }
 }
 
 //=================================================================================
@@ -2310,26 +2410,26 @@ void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
 {
   int index = myActions[a];
   if ( index == GEOM_BY_MESH_INDEX )
-    {
-      mySelectionMode = grpNoSelection;
-      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();
-      }
+  {
+    mySelectionMode = grpNoSelection;
+    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();
+    }
+  }
 }
 
 //================================================================================
@@ -2348,8 +2448,7 @@ void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
     if ( !aGeomVar->_is_nil() )
     {
       QString ID = aGeomVar->GetStudyEntry();
-      _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
-      if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
+      if ( _PTR(SObject) aGeomSO = SMESH::getStudy()->FindObjectID( ID.toLatin1().data() )) {
         SALOME_ListIO anIOList;
         Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
           ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
@@ -2370,10 +2469,10 @@ void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
 {
   if ( myShapeByMeshOp == op )
-    {
-      show();
-      setSelectionMode(grpGeomSelection);
-    }
+  {
+    show();
+    setSelectionMode(grpGeomSelection);
+  }
 }
 
 //=================================================================================
@@ -2434,15 +2533,20 @@ void SMESHGUI_GroupDlg::setDefaultGroupColor()
 
   bool isAutoColor = myMesh->GetAutoColor();
 
-  QColor aQColor;
+  QColor aQColor = myColorBtn->color();
   if( !isAutoColor )
   {
-    int r = 0, g = 0, b = 0;
-    SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
-    aQColor.setRgb( r, g, b );
+    if ( !aQColor.isValid() ) {
+      int r = 0, g = 0, b = 0;
+      SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
+      aQColor.setRgb( r, g, b );
+    }
   }
   else
   {
+#ifdef SIMPLE_AUTOCOLOR   // simplified algorithm for auto-colors
+    SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
+#else                     // old algorithm  for auto-colors
     SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
 
     QList<SALOMEDS::Color> aReservedColors;
@@ -2454,6 +2558,8 @@ void SMESHGUI_GroupDlg::setDefaultGroupColor()
     }
 
     SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
+#endif                    // SIMPLE_AUTOCOLOR
+
     aQColor.setRgb( (int)( aColor.R * 255.0 ),
                     (int)( aColor.G * 255.0 ),
                     (int)( aColor.B * 255.0 ) );
@@ -2467,7 +2573,7 @@ void SMESHGUI_GroupDlg::setDefaultGroupColor()
 // function : SetAppropriateActor()
 // purpose  : Find more appropriate of visible actors, set it to myActor, allow picking
 //            NPAL19389: create a group with a selection in another group.
-//            if mesh actor is not visible - find any first visible group or submesh
+//            if mesh actor is not visible - find any first visible group or sub-mesh
 //=================================================================================
 bool SMESHGUI_GroupDlg::SetAppropriateActor()
 {
@@ -2478,21 +2584,23 @@ bool SMESHGUI_GroupDlg::SetAppropriateActor()
 
   SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
 
-  if (myGeomGroupBtn->isChecked()) {   // try current group on geometry actor
-    if (!isActor) {
-      if (!myGroupOnGeom->_is_nil()) {
-        SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
-        if (anActor && anActor->hasIO())
-          {
-            isActor = true;
-            if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
-              isActor = false;
-            else
-              myActorsList.append(anActor);
-          }
-      }
+  if (myGrpTypeGroup->checkedId() > 0) {   // try current group on geometry actor
+    SMESH_Actor* anActor = 0;
+    if (!myGroupOnGeom->_is_nil())
+      anActor = SMESH::FindActorByObject(myGroupOnGeom);
+    if (!myGroupOnFilter->_is_nil())
+      anActor = SMESH::FindActorByObject(myGroupOnFilter);
+    if (anActor && anActor->hasIO())
+    {
+      isActor = true;
+      if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
+        isActor = false;
+      else
+        myActorsList.append(anActor);
     }
-  } else {
+    return anActor;
+  }
+  else {
     // try mesh actor
     SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
     if (anActor && anActor->hasIO()) {
@@ -2502,42 +2610,50 @@ bool SMESHGUI_GroupDlg::SetAppropriateActor()
       else
         myActorsList.append(anActor);
     }
-    
+
     // try group actor
+    SMESH_Actor* aGroupActor = 0;
     if (!isActor && !myGroup->_is_nil()) {
-      SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
-      if (anActor && anActor->hasIO())
-        myActorsList.append(anActor);
+      aGroupActor = SMESH::FindActorByObject(myGroup);
+      if (aGroupActor && aGroupActor->hasIO())
+        myActorsList.append(aGroupActor);
     }
-    
-    // try any visible actor of group or submesh of current mesh
+
+    // try any visible actor of group or sub-mesh of current mesh
     if (aViewWindow) {
       // mesh entry
       _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
       if (aSObject) {
         CORBA::String_var meshEntry = aSObject->GetID().c_str();
         int len = strlen(meshEntry);
-        
+
         // iterate on all actors in current view window, search for
         // any visible actor, that belongs to group or submesh of current mesh
         VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
         vtkActorCollection *aCollection = aCopy.GetActors();
         int nbItems = aCollection->GetNumberOfItems();
         for (int i=0; i<nbItems && !isActor; i++)
-          {
-            SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
-            if (anActor && anActor->hasIO()) {
-              Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
-              if (aViewWindow->isVisible(anIO)) {
-                if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
-                  myActorsList.append(anActor);
-              }
+        {
+          SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
+          if (anActor && anActor->hasIO()) {
+            Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
+            if (aViewWindow->isVisible(anIO)) {
+              if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
+                myActorsList.append(anActor);
             }
           }
+        }
       }
     }
+
+    // Show a standalone group if nothing else is visible (IPAL52227)
+    if ( myActorsList.count() == 1 &&
+         myActorsList[0] == aGroupActor &&
+         aViewWindow && !aViewWindow->isVisible(aGroupActor->getIO()))
+      SMESH::UpdateView( aViewWindow, SMESH::eDisplay, aGroupActor->getIO()->getEntry() );
   }
-  
+
+
   if (myActorsList.count() > 0) {
     QListIterator<SMESH_Actor*> it( myActorsList );
     while ( it.hasNext() ) {
@@ -2546,10 +2662,10 @@ bool SMESHGUI_GroupDlg::SetAppropriateActor()
         anActor->SetPickable(true);
     }
   }
-  
+
   return ( isActor || (myActorsList.count() > 0) );
 }
-  
+
 //=======================================================================
 //function : setShowEntityMode
 //purpose  : make shown only entity corresponding to my type
@@ -2561,11 +2677,12 @@ void SMESHGUI_GroupDlg::setShowEntityMode()
       if (!myStoredShownEntity)
         myStoredShownEntity = actor->GetEntityMode();
       switch ( myTypeId ) {
-      case grpNodeSelection:   restoreShowEntityMode(); break;
-      case grpBallSelection:   actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
-      case grpEdgeSelection:   actor->SetEntityMode( SMESH_Actor::eEdges ); break;
-      case grpFaceSelection:   actor->SetEntityMode( SMESH_Actor::eFaces ); break;
-      case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
+      case grpNodeSelection:   restoreShowEntityMode();                          break;
+      case grp0DSelection:     actor->SetEntityMode( SMESH_Actor::e0DElements ); break;
+      case grpBallSelection:   actor->SetEntityMode( SMESH_Actor::eBallElem );   break;
+      case grpEdgeSelection:   actor->SetEntityMode( SMESH_Actor::eEdges );      break;
+      case grpFaceSelection:   actor->SetEntityMode( SMESH_Actor::eFaces );      break;
+      case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes );    break;
       }
     }
   }