Salome HOME
PAL17233: Projection 2D doesn't work (bis)
[modules/geom.git] / src / GroupGUI / GroupGUI_GroupDlg.cxx
index 0559aaff7d226ffc9a86bc0e90d2f878a98036a6..e5a61aa2ce3c3f0e799b704a1bc93594255c4fd1 100644 (file)
@@ -17,7 +17,7 @@
 //  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 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
 
 #include "GroupGUI_GroupDlg.h"
 
+#include "SUIT_Desktop.h"
+#include "SUIT_Session.h"
+#include "SalomeApp_Application.h"
+#include "SalomeApp_Study.h"
+#include "LightApp_SelectionMgr.h"
+
 #include "GEOMBase.h"
 
 #include "GEOMImpl_Types.hxx"
 
-#include "QAD_Desktop.h"
-
 #include <qlabel.h>
 #include <qlistbox.h>
 #include <qlineedit.h>
 #include <TColStd_IndexedMapOfInteger.hxx>
 #include <TColStd_MapOfInteger.hxx>
 
-GroupGUI_GroupDlg::GroupGUI_GroupDlg(Mode mode, 
-                                    QWidget* parent, 
-                                    const char* name,
-                                    SALOME_Selection* Sel, 
-                                    bool modal, 
-                                    WFlags fl)
-  :GEOMBase_Skeleton( parent, "GroupGUI_GroupDlg", Sel, false,
-                    WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
-   myMode( mode ), 
+
+GroupGUI_GroupDlg::GroupGUI_GroupDlg(Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
+  :GEOMBase_Skeleton( theGeometryGUI, parent, "GroupGUI_GroupDlg", false,
+                      WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
+   myMode( mode ),
    myBusy( false )
 {
-  QPixmap image0( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_VERTEX" ) ) );
-  QPixmap image1( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_EDGE" ) ) );
-  QPixmap image2( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_FACE" ) ) );
-  QPixmap image3( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_OBJBROWSER_SOLID" ) ) );
-  
-  QPixmap iconSelect( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
+  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+
+  QPixmap image0     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
+  QPixmap image1     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
+  QPixmap image2     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
+  QPixmap image3     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
+  QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
 
   setCaption( myMode == CreateGroup ? tr( "CREATE_GROUP_TITLE" ) : tr( "EDIT_GROUP_TITLE" ) );
 
@@ -91,13 +92,13 @@ GroupGUI_GroupDlg::GroupGUI_GroupDlg(Mode mode,
   myMainName = new QLineEdit( aFrame );
   myMainName->setReadOnly( true );
   myMainName->setEnabled( myMode == CreateGroup );
-  
-  mySelSubBtn = new QPushButton( tr( "SELECT_SUB_SHAPES" ), aFrame );  
-  mySelAllBtn = new QPushButton( tr( "SELECT_ALL" ), aFrame );  
-  myAddBtn    = new QPushButton( tr( "ADD" ), aFrame );  
-  myRemBtn    = new QPushButton( tr( "REMOVE" ), aFrame );  
+
+  mySelSubBtn = new QPushButton( tr( "SELECT_SUB_SHAPES" ), aFrame );
+  mySelAllBtn = new QPushButton( tr( "SELECT_ALL" ), aFrame );
+  myAddBtn    = new QPushButton( tr( "ADD" ), aFrame );
+  myRemBtn    = new QPushButton( tr( "REMOVE" ), aFrame );
   myIdList    = new QListBox( aFrame );
-  
+
   myIdList->setSelectionMode( QListBox::Extended );
   myIdList->setRowMode( QListBox::FitToWidth );
 
@@ -110,7 +111,9 @@ GroupGUI_GroupDlg::GroupGUI_GroupDlg(Mode mode,
   aMedLayout->addWidget( myAddBtn, 2, 3 );
   aMedLayout->addWidget( myRemBtn, 3, 3 );
 
-  Init( Sel );
+  setHelpFileName("working_with_groups.htm");
+
+  Init();
 }
 
 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
@@ -122,10 +125,8 @@ GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
 // function : Init()
 // purpose  :
 //=================================================================================
-void GroupGUI_GroupDlg::Init( SALOME_Selection* Sel )
+void GroupGUI_GroupDlg::Init()
 {
-  mySelection = Sel;
-
   // san -- TODO: clear selected sub-shapes...
 
   if ( myMode == CreateGroup ) {
@@ -134,14 +135,14 @@ void GroupGUI_GroupDlg::Init( SALOME_Selection* Sel )
     // Get ready for main shape selection
     myEditCurrentArgument = myMainName;
 
-    connect( GroupConstructors, SIGNAL( clicked( int ) ),            this, SLOT( ConstructorsClicked( int ) ) );
-    connect( mySelBtn,          SIGNAL( clicked() ),                 this, SLOT(SetEditCurrentArgument()));
+    connect( GroupConstructors, SIGNAL( clicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
+    connect( mySelBtn,          SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
   }
-  else if ( myMode == EditGroup && Sel->IObjectCount() ) {
+  else if ( myMode == EditGroup && IObjectCount() ) {
     Standard_Boolean aResult = Standard_False;
     GEOM::GEOM_Object_var anObj =
-      GEOMBase::ConvertIOinGEOMObject( Sel->firstIObject(), aResult );
-    
+      GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
+
     if ( aResult && !CORBA::is_nil( anObj ) && anObj->GetType() == GEOM_GROUP ) {
       myGroup = anObj;
 
@@ -150,28 +151,31 @@ void GroupGUI_GroupDlg::Init( SALOME_Selection* Sel )
       GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
       myMainObj = anOp->GetMainShape( myGroup );
       if ( !CORBA::is_nil( myMainObj ) )
-       myMainName->setText( GEOMBase::GetName( myMainObj ) );
+        myMainName->setText( GEOMBase::GetName( myMainObj ) );
 
       setShapeType( (TopAbs_ShapeEnum)anOp->GetType( myGroup ) );
 
       GEOM::ListOfLong_var aCurrList = anOp->GetObjects( myGroup );
       QListBoxItem* anItem;
       for ( int i = 0, n = aCurrList->length(); i < n; i++ ) {
-       anItem = new QListBoxText( QString( "%1" ).arg(aCurrList[i] ) );
-       myIdList->insertItem( anItem );
+        anItem = new QListBoxText( QString( "%1" ).arg(aCurrList[i] ) );
+        myIdList->insertItem( anItem );
       }
 
       myEditCurrentArgument = 0;
     }
   }
 
+  LightApp_SelectionMgr* aSelMgr =
+    ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
+
+  connect( aSelMgr,     SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
+
   connect( buttonOk   , SIGNAL( clicked() ), this, SLOT( ClickOnOk()    ) );
   connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
 
   connect( mySelSubBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
   connect( mySelAllBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
-  connect( mySelection,SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
-  connect( mySelAllBtn, SIGNAL( clicked() ), this, SLOT( selectAllSubShapes() ) );
   connect( myAddBtn,    SIGNAL( clicked() ), this, SLOT( add() ) );
   connect( myRemBtn,    SIGNAL( clicked() ), this, SLOT( remove() ) );
   connect( myIdList,    SIGNAL( selectionChanged() ), this, SLOT( selectionChanged() ) );
@@ -199,7 +203,6 @@ void GroupGUI_GroupDlg::ClickOnOk()
     ClickOnCancel();
 }
 
-
 //=================================================================================
 // function : ClickOnApply()
 // purpose  :
@@ -210,7 +213,12 @@ bool GroupGUI_GroupDlg::ClickOnApply()
     return false;
 
   if ( myMode == CreateGroup )
-    initName();
+    {
+      initName();
+      myIdList->clear();
+    }
+  else
+    activateSelection();
   return true;
 }
 
@@ -223,7 +231,8 @@ void GroupGUI_GroupDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
 
-  connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
+  connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
+           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
 
   activateSelection();
 }
@@ -235,7 +244,7 @@ void GroupGUI_GroupDlg::ActivateThisDialog()
 void GroupGUI_GroupDlg::LineEditReturnPressed()
 {
   QLineEdit* send = ( QLineEdit* )sender();
-  
+
   if ( send == myMainName && !myEditCurrentArgument ) {
     myEditCurrentArgument = myMainName;
     activateSelection();
@@ -261,7 +270,11 @@ void GroupGUI_GroupDlg::SetEditCurrentArgument()
     myEditCurrentArgument = 0;
 
   activateSelection();
-  updateState();
+
+  if ( send == mySelAllBtn )
+    selectAllSubShapes();
+  else
+    updateState();
 }
 
 
@@ -273,23 +286,24 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
 {
   if ( myEditCurrentArgument ) {  // Selection of a main shape is active
     myEditCurrentArgument->setText( "" );
-    
-    if ( mySelection->IObjectCount() == 1 ) {
+    myIdList->clear();
+
+    if ( IObjectCount() == 1 ) {
       Standard_Boolean aResult = Standard_False;
       GEOM::GEOM_Object_var anObj =
-        GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aResult );
+        GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
 
       if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
         myMainObj = anObj;
         myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
         updateState();
-       return;
+        return;
       }
     }
 
     myMainObj = GEOM::GEOM_Object::_nil();
   }
-  else {  // an attempt to synchronize list box selection with 3d viewer
+  else { // an attempt to synchronize list box selection with 3d viewer
     if ( myBusy )
       return;
 
@@ -297,25 +311,69 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
     myIdList->blockSignals( true );
     myIdList->clearSelection();
 
-    if ( mySelection->IObjectCount() == 1 ) {
+    TColStd_IndexedMapOfInteger aMapIndex;
+
+    if ( IObjectCount() == 1 ) {
       Standard_Boolean aResult = Standard_False;
       GEOM::GEOM_Object_var anObj =
-       GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aResult );
+        GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
+
+      if ( aResult && !anObj->_is_nil() )
+        ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->
+          selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
+    }
+
+    // try to find out and process the object browser selection
+    if ( !aMapIndex.Extent() ) {
+      globalSelection( GEOM_ALLSHAPES );
       
-      if ( aResult && !anObj->_is_nil() ) {
-       QMap<int, int> aMap;
-       for ( int i = 0, n = myIdList->count(); i < n; i++ )
-         aMap.insert( myIdList->item( i )->text().toInt(), i );
-       
-       TColStd_IndexedMapOfInteger aMapIndex;
-       mySelection->GetIndex( mySelection->firstIObject(), aMapIndex );
-       for ( int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++ ) {
-         if ( aMap.contains( aMapIndex( ii ) ) )
-           myIdList->setSelected( aMap[aMapIndex( ii )], true );
+      GEOM::ListOfGO anObjects;
+      GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
+
+      GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
+      GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
+
+      for (int i = 0; i < anObjects.length(); i++) 
+       {
+         GEOM::GEOM_Object_var aGeomObj = anObjects[i];
+         GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
+         TopoDS_Shape aShape;
+         if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) ) 
+           {
+             aSubObjects->length(1);
+             aSubObjects[0] = aGeomObj;
+           }
+         else if (aGeomObj->GetType() == GEOM_GROUP)
+           aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
+         else
+           continue;
+
+         for (int i = 0; i < aSubObjects->length(); i++) 
+           {
+             TopoDS_Shape aShape;
+             if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) ) 
+               {
+                 CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
+                 if ( anIndex >= 0 )
+                   aMapIndex.Add( anIndex );
+               }
+           }
        }
-      }
+      
+      if ( !myMainObj->_is_nil() )
+       localSelection( myMainObj, getShapeType() );
     }
 
+    if (aMapIndex.Extent() >= 1) {
+      QMap<int, int> aMap;
+      for ( int i = 0, n = myIdList->count(); i < n; i++ )
+        aMap.insert( myIdList->item( i )->text().toInt(), i );
+
+      for ( int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++ ) {
+        if ( aMap.contains( aMapIndex( ii ) ) )
+          myIdList->setSelected( aMap[aMapIndex( ii )], true );
+      }
+    }
     myIdList->blockSignals( isBlocked );
   }
 
@@ -352,7 +410,7 @@ void GroupGUI_GroupDlg::selectAllSubShapes()
   bool isBlocked = myIdList->signalsBlocked();
   myIdList->blockSignals( true );
   myIdList->clear();
-  
+
   QListBoxItem* anItem;
   for ( int i = 0, n = aSubShapes->length(); i < n; i++ ) {
     CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubShapes[i] );
@@ -379,30 +437,71 @@ void GroupGUI_GroupDlg::add()
   for ( int i = 0, n = myIdList->count(); i < n; i++ )
     aMap.Add( myIdList->item( i )->text().toInt() );
 
-  if ( mySelection->IObjectCount() == 1 ) {
+  TColStd_IndexedMapOfInteger aMapIndex;
+
+  if ( IObjectCount() == 1 ) {
     Standard_Boolean aResult = Standard_False;
     GEOM::GEOM_Object_var anObj =
-      GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aResult );
+      GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
 
-    if ( aResult && !anObj->_is_nil() ) {
-      TColStd_IndexedMapOfInteger aMapIndex;
-      mySelection->GetIndex( mySelection->firstIObject(), aMapIndex );
-      QListBoxItem* anItem;
-      bool isBlocked = myIdList->signalsBlocked();
-      myIdList->blockSignals( true );
-
-      for ( int i = 1, n = aMapIndex.Extent(); i <= n; i++ ) {
-       if ( aMap.Contains( aMapIndex( i ) ) )
-         continue;
+    if ( aResult && !anObj->_is_nil() )
+      ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->
+        selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
+  }
 
-       anItem = new QListBoxText( QString( "%1" ).arg( aMapIndex( i ) ) );
-       myIdList->insertItem( anItem );
-       myIdList->setSelected( anItem, true );
+  // try to find out and process the object browser selection
+  if ( !aMapIndex.Extent() ) {
+    GEOM::ListOfGO anObjects;
+    GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
+    
+    GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
+    GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
+    
+    for (int i = 0; i < anObjects.length(); i++) 
+      {
+       GEOM::GEOM_Object_var aGeomObj = anObjects[i];
+       GEOM::ListOfGO_var aSubObjects  = new GEOM::ListOfGO();
+       TopoDS_Shape aShape;
+       if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) ) 
+         {
+           aSubObjects->length(1);
+           aSubObjects[0] = aGeomObj;
+         }
+       else if (aGeomObj->GetType() == GEOM_GROUP)
+         aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
+       else
+         break;
+       
+       for (int i = 0; i < aSubObjects->length(); i++) 
+         {
+         TopoDS_Shape aShape;
+         if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) ) 
+           {
+             CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
+             if ( anIndex >= 0 )
+               aMapIndex.Add( anIndex );
+           }
+       }
       }
+  }
+
+  if ( aMapIndex.Extent() >= 1 ) {
+    QListBoxItem* anItem;
+    bool isBlocked = myIdList->signalsBlocked();
+    myIdList->blockSignals( true );
+
+    for ( int i = 1, n = aMapIndex.Extent(); i <= n; i++ ) {
+      if ( aMap.Contains( aMapIndex( i ) ) )
+        continue;
 
-      myIdList->blockSignals( isBlocked );
+      anItem = new QListBoxText( QString( "%1" ).arg( aMapIndex( i ) ) );
+      myIdList->insertItem( anItem );
+      myIdList->setSelected( anItem, true );
     }
+
+    myIdList->blockSignals( isBlocked );
   }
+
   updateState();
 }
 
@@ -413,7 +512,7 @@ void GroupGUI_GroupDlg::add()
 void GroupGUI_GroupDlg::remove()
 {
   for ( int i = myIdList->count() - 1; i >= 0; i-- ) {
-    if ( myIdList->isSelected( i ) ) 
+    if ( myIdList->isSelected( i ) )
       myIdList->removeItem( i );
   }
   updateState();
@@ -456,7 +555,7 @@ void GroupGUI_GroupDlg::setShapeType( const TopAbs_ShapeEnum theType )
   case TopAbs_EDGE:   anId = 1; break;
   case TopAbs_FACE:   anId = 2; break;
   case TopAbs_SOLID:  anId = 3; break;
-  }  
+  }
   GroupConstructors->setButton( anId );
 }
 
@@ -483,17 +582,77 @@ void GroupGUI_GroupDlg::activateSelection()
 void GroupGUI_GroupDlg::updateState()
 {
   bool isAdd = false;
-  if ( mySelection->IObjectCount() == 1 ) {
+
+  TColStd_IndexedMapOfInteger aMapIndex;
+
+  if ( IObjectCount() == 1 ) {
     Standard_Boolean aResult = Standard_False;
     GEOM::GEOM_Object_var anObj =
-      GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aResult );
+      GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
 
-    if ( aResult && !anObj->_is_nil() ) {
-      TColStd_IndexedMapOfInteger aMapIndex;
-      mySelection->GetIndex( mySelection->firstIObject(), aMapIndex );
-      isAdd = aMapIndex.Extent() > 0;
-    }
+    if ( aResult && !anObj->_is_nil() )
+      ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->
+        selectionMgr()->GetIndexes( firstIObject(), aMapIndex );
+  }
+
+  // try to find out and process the object browser selection
+  if ( !aMapIndex.Extent() && !CORBA::is_nil( myMainObj ) ) {
+    GEOM::ListOfGO anObjects;
+    GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
+    
+    GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
+    GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
+
+     isAdd = true;
+     
+     for (int i = 0; i < anObjects.length(); i++) 
+       {
+        GEOM::GEOM_Object_var aGeomObj = anObjects[i];
+        GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
+        TopoDS_Shape aShape;
+        if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) ) 
+          {
+            aSubObjects->length(1);
+            aSubObjects[0] = aGeomObj;
+          }
+        else if (aGeomObj->GetType() == GEOM_GROUP)
+          aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
+        else
+          {
+            aMapIndex.Clear();
+            break;
+          }
+        
+        for (int i = 0; i < aSubObjects->length(); i++) 
+          {
+            TopoDS_Shape aShape;
+            aSubObjects[i];
+            if ( GEOMBase::GetShape(aSubObjects[i], aShape, getShapeType()) ) 
+              {
+                CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubObjects[i] );
+                if ( anIndex >= 0 )
+                  aMapIndex.Add( anIndex );
+                else
+                  isAdd = false;
+              }
+            else
+              isAdd = false;
+            
+            if ( !isAdd ) {
+              aMapIndex.Clear();
+              break;
+            }
+          }
+        
+        if ( !isAdd ) {
+          aMapIndex.Clear();
+          break;
+        }
+       }
   }
+  
+  isAdd = aMapIndex.Extent() > 0;
+
   myAddBtn->setEnabled( !myEditCurrentArgument && !CORBA::is_nil( myMainObj ) && isAdd );
   bool hasSel = false;
   for ( int ii = 0, nn = myIdList->count(); !hasSel && ii < nn; ii++ )
@@ -522,8 +681,10 @@ void GroupGUI_GroupDlg::highlightSubShapes()
     return;
 
   Standard_Boolean isOk;
-  Handle(GEOM_AISShape) aSh = 
-    GEOMBase::ConvertIORinGEOMAISShape( GEOMBase::GetIORFromObject( myMainObj ), isOk, true );
+  char* objIOR = GEOMBase::GetIORFromObject( myMainObj );
+  Handle(GEOM_AISShape) aSh =
+    GEOMBase::ConvertIORinGEOMAISShape( objIOR, isOk, true );
+  free( objIOR );
   if ( !isOk || aSh.IsNull() )
     return;
 
@@ -533,10 +694,12 @@ void GroupGUI_GroupDlg::highlightSubShapes()
 
   for ( int ii = 0, nn = myIdList->count(); ii < nn; ii++ )
     if ( myIdList->isSelected( ii ) )
-      anIds.Add( myIdList->item( ii )->text().toInt() );    
+      anIds.Add( myIdList->item( ii )->text().toInt() );
 
-  mySelection->ClearIObjects();
-  mySelection->AddOrRemoveIndex( aSh->getIO(), anIds, false, true );
+  LightApp_SelectionMgr* aSelMgr =
+    ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
+  aSelMgr->clearSelected();
+  aSelMgr->AddOrRemoveIndex( aSh->getIO(), anIds, false );
 
   myBusy = false;
 
@@ -564,9 +727,9 @@ GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
 //=================================================================================
 bool GroupGUI_GroupDlg::isValid( QString& theMessage )
 {
-  QAD_Study* study = getStudy();
+  SalomeApp_Study* study = getStudy();
   ASSERT(study);
-  RETURN_WITH_MSG  ( !study->getStudyDocument()->GetProperties()->IsLocked(), tr( "GEOM_STUDY_LOCKED" ) )
+  RETURN_WITH_MSG  ( !study->studyDS()->GetProperties()->IsLocked(), tr( "GEOM_STUDY_LOCKED" ) )
 
   if ( myMode == CreateGroup ) {
     RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_MAIN_OBJ" ) )
@@ -575,8 +738,8 @@ bool GroupGUI_GroupDlg::isValid( QString& theMessage )
     RETURN_WITH_MSG( !CORBA::is_nil( myMainObj ), tr( "NO_GROUP" ) )
   }
 
-  const char* aName = getNewObjectName();
-  RETURN_WITH_MSG  ( aName && strlen( aName ), tr( "EMPTY_NAME" ) )
+  QString aName (getNewObjectName());
+  RETURN_WITH_MSG  ( !aName.stripWhiteSpace().isEmpty(), tr( "EMPTY_NAME" ) )
 
   RETURN_WITH_MSG  ( myIdList->count(), tr( "EMPTY_LIST" ) )
   return true;
@@ -589,9 +752,9 @@ bool GroupGUI_GroupDlg::isValid( QString& theMessage )
 bool GroupGUI_GroupDlg::execute( ObjectList& objects )
 {
   GEOM::GEOM_IGroupOperations_var anOp = GEOM::GEOM_IGroupOperations::_narrow( getOperation() );
-  
+
   GEOM::GEOM_Object_var aGroup;
-  if ( myMode == CreateGroup ) 
+  if ( myMode == CreateGroup )
     aGroup = anOp->CreateGroup( myMainObj, getShapeType() );
   else if ( myMode == EditGroup )
     aGroup = myGroup;
@@ -610,19 +773,21 @@ bool GroupGUI_GroupDlg::execute( ObjectList& objects )
   }
 
   for ( int ii = 0, nn = myIdList->count(); ii < nn; ii++ ) {
-    anOp->AddObject( aGroup, myIdList->item( ii )->text().toInt() );    
+    anOp->AddObject( aGroup, myIdList->item( ii )->text().toInt() );
     if ( !anOp->IsDone()  )
       return false;
   }
 
-  QAD_Study* study = getStudy();
+  SalomeApp_Study* study = getStudy();
   if ( study ) {
-    string IOR = GEOMBase::GetIORFromObject( aGroup );
+    char* objIOR = GEOMBase::GetIORFromObject( aGroup );
+    string IOR( objIOR );
+    free( objIOR );
     if ( IOR != "" ) {
-      SALOMEDS::SObject_var SO = study->getStudyDocument()->FindObjectIOR( IOR.c_str() );
-      if ( !SO->_is_nil() ) { 
-       SALOMEDS::StudyBuilder_var aBuilder = study->getStudyDocument()->NewBuilder();
-       aBuilder->SetName( SO, getNewObjectName() );
+      _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
+      if ( SO ) {
+        _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
+        aBuilder->SetName( SO, getNewObjectName() );
       }
     }
   }
@@ -646,3 +811,4 @@ GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather( GEOM::GEOM_Object_ptr theObj
   }
   return aFatherObj._retn();
 }
+