Salome HOME
Remove "MAC" ends of lines
[modules/geom.git] / src / GroupGUI / GroupGUI_GroupDlg.cxx
index d49e014a760c88cb414efa93669e8be539c0eb90..356b9e1a1095b6f896d29f6cb4ff4f530dc770df 100644 (file)
@@ -1,24 +1,24 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  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
+// Copyright (C) 2003-2007  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 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.
+// 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
+// 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
+
 //  GEOM GEOMGUI : GUI for Geometry component
 //  File   : GroupGUI_GroupDlg.cxx
 //  Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
@@ -71,7 +71,8 @@ GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QW
   : GEOMBase_Skeleton(theGeometryGUI, parent, false),
     myMode(mode),
     myBusy(false),
-    myIsShapeType(false)
+    myIsShapeType(false),
+    myIsHiddenMain(false)
 {
   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
 
@@ -111,35 +112,38 @@ GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QW
   myMainName->setReadOnly(true);
   myMainName->setEnabled(myMode == CreateGroup);
 
-  QLabel* aSecondLabel = new QLabel(tr("SECOND_SHAPE"), GroupMedium);
+  myRestrictGroupBox = new QGroupBox(tr("SHAPE_SEL_RESTR"), GroupMedium);
+  myRestrictGroup = new QButtonGroup(myRestrictGroupBox);
+  QRadioButton* allSubs     = new QRadioButton(tr("NO_RESTR")            , myRestrictGroupBox);
+  QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"), myRestrictGroupBox);
+  QRadioButton* shape2Subs  = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") , myRestrictGroupBox);
+  QGridLayout* aRestrictLayout = new QGridLayout(myRestrictGroupBox);
 
-  mySelBtn2 = new QPushButton(GroupMedium);
+  QLabel* aSecondLabel = new QLabel(tr("SECOND_SHAPE"), myRestrictGroupBox);
+  mySelBtn2 = new QPushButton(myRestrictGroupBox);
   mySelBtn2->setIcon(iconSelect);
   mySelBtn2->setEnabled(false);
-
-  myShape2Name = new QLineEdit(GroupMedium);
+  myShape2Name = new QLineEdit(myRestrictGroupBox);
   myShape2Name->setReadOnly(true);
   myShape2Name->setEnabled(false);
 
-  myRestrictGroupBox = new QGroupBox(tr("SHAPE_SEL_RESTR"), GroupMedium);
-  myRestrictGroup = new QButtonGroup(myRestrictGroupBox);
-  QRadioButton* allSubs     = new QRadioButton(tr("NO_RESTR")            , myRestrictGroupBox);
-  QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"), myRestrictGroupBox);
-  QRadioButton* shape2Subs  = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") , myRestrictGroupBox);
-  QVBoxLayout* aRestrictLayout = new QVBoxLayout(myRestrictGroupBox);
   aRestrictLayout->setMargin(9);
   aRestrictLayout->setSpacing(6);
-  aRestrictLayout->addWidget(allSubs);
-  aRestrictLayout->addWidget(inPlaceSubs);
-  aRestrictLayout->addWidget(shape2Subs);
-  myRestrictGroup->addButton(allSubs,     ALL_SUBSHAPES);
-  myRestrictGroup->addButton(inPlaceSubs, GET_IN_PLACE);
-  myRestrictGroup->addButton(shape2Subs,  SUBSHAPES_OF_SHAPE2);
+  aRestrictLayout->addWidget(allSubs,      0, 0, 1, 3);
+  aRestrictLayout->addWidget(inPlaceSubs,  1, 0, 1, 3);
+  aRestrictLayout->addWidget(shape2Subs,   2, 0, 1, 3);
+  aRestrictLayout->addWidget(aSecondLabel, 3, 0);
+  aRestrictLayout->addWidget(mySelBtn2,    3, 1);
+  aRestrictLayout->addWidget(myShape2Name, 3, 2);
+  myRestrictGroup->addButton(allSubs,      ALL_SUBSHAPES);
+  myRestrictGroup->addButton(inPlaceSubs,  GET_IN_PLACE);
+  myRestrictGroup->addButton(shape2Subs,   SUBSHAPES_OF_SHAPE2);
+  myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
   allSubs->setChecked(true);
 
-  myShowOnlyBtn = new QPushButton(tr("Show only selected"), GroupMedium);
-  myHideSelBtn  = new QPushButton(tr("Hide selected"), GroupMedium);
-  myShowAllBtn  = new QPushButton(tr("Show all sub-shapes"), GroupMedium);
+  myShowOnlyBtn = new QPushButton(tr("SHOW_ONLY_SELECTED"), GroupMedium);
+  myHideSelBtn  = new QPushButton(tr("HIDE_SELECTED"), GroupMedium);
+  myShowAllBtn  = new QPushButton(tr("SHOW_ALL_SUB_SHAPES"), GroupMedium);
 
   mySelAllBtn   = new QPushButton(tr("SELECT_ALL"), GroupMedium);
   myAddBtn      = new QPushButton(tr("ADD"), GroupMedium);
@@ -154,21 +158,20 @@ GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QW
   aMedLayout->addWidget(aMainLabel,         0, 0);
   aMedLayout->addWidget(mySelBtn,           0, 1);
   aMedLayout->addWidget(myMainName,         0, 2, 1, 2);
-  aMedLayout->addWidget(aSecondLabel,       1, 0);
-  aMedLayout->addWidget(mySelBtn2,          1, 1);
-  aMedLayout->addWidget(myShape2Name,       1, 2, 1, 2);
-  aMedLayout->addWidget(myRestrictGroupBox, 2, 0, 3, 3);
+  aMedLayout->addWidget(myRestrictGroupBox, 1, 0, 4, 3);
 
-  aMedLayout->addWidget(myShowOnlyBtn,      2, 3);
-  aMedLayout->addWidget(myHideSelBtn,       3, 3);
-  aMedLayout->addWidget(myShowAllBtn,       4, 3);
+  aMedLayout->addWidget(myShowOnlyBtn,      1, 3);
+  aMedLayout->addWidget(myHideSelBtn,       2, 3);
+  aMedLayout->addWidget(myShowAllBtn,       3, 3);
 
+  aMedLayout->addWidget(myIdList,           5, 0, 4, 3);
   aMedLayout->addWidget(mySelAllBtn,        5, 3);
   aMedLayout->addWidget(myAddBtn,           6, 3);
   aMedLayout->addWidget(myRemBtn,           7, 3);
 
-  aMedLayout->addWidget(myIdList,           5, 0, 3, 3);
-  aMedLayout->setRowStretch(5, 1);
+  aMedLayout->setColumnStretch(2, 5);
+  aMedLayout->setRowStretch(5, 5);
+  aMedLayout->setRowStretch(8, 5);
 
   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
   layout->setMargin(0); layout->setSpacing(6);
@@ -177,10 +180,16 @@ GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QW
   setHelpFileName("work_with_groups_page.html");
 
   Init();
+  updateState();
 }
 
 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
 {
+  if (myIsHiddenMain) {
+    GEOM_Displayer* aDisplayer = getDisplayer();
+    aDisplayer->Display(myMainObj);
+    myIsHiddenMain = false;
+  }
 }
 
 //=================================================================================
@@ -210,11 +219,10 @@ void GroupGUI_GroupDlg::Init()
     aSelMgr->selectedObjects(aSelList);
 
     if (aSelList.Extent()) {
-      Standard_Boolean aResult = Standard_False;
       GEOM::GEOM_Object_var anObj =
-        GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
+        GEOMBase::ConvertIOinGEOMObject(aSelList.First());
 
-      if (aResult && !CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
+      if (!CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
         myGroup = anObj;
 
         mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
@@ -285,6 +293,7 @@ void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
 //=================================================================================
 void GroupGUI_GroupDlg::ClickOnOk()
 {
+  setIsApplyAndClose(true);
   if (ClickOnApply())
     ClickOnCancel();
 }
@@ -373,10 +382,9 @@ void GroupGUI_GroupDlg::onGetInPlace()
   if (aSelList.Extent() != 1)
     return;
 
-  Standard_Boolean aResult = Standard_False;
   GEOM::GEOM_Object_var anObj =
-    GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
-  if (aResult && !anObj->_is_nil() && GEOMBase::IsShape(anObj)) {
+    GEOMBase::ConvertIOinGEOMObject(aSelList.First());
+  if (GEOMBase::IsShape(anObj)) {
     if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
       SUIT_OverrideCursor wc;
       myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
@@ -420,10 +428,13 @@ void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool i
     GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
     for (int i = 0; i < aSubObjects->length(); i++)
     {
-      CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex(myMainObj, aSubObjects[i]);
-      CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex(myInPlaceObj, aSubObjects[i]);
-      if (aMainIndex >= 0 && aPlaceIndex > 0)
-        myMain2InPlaceIndices.Bind(aMainIndex, aPlaceIndex);
+      GEOM::GEOM_Object_var aSS = aShapesOp->GetSame(myMainObj, aSubObjects[i]);
+      if (!CORBA::is_nil(aSS)) {
+        CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex(myMainObj, aSS);
+        CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex(myInPlaceObj, aSubObjects[i]);
+        if (aMainIndex >= 0 && aPlaceIndex > 0)
+          myMain2InPlaceIndices.Bind(aMainIndex, aPlaceIndex);
+      }
     }
   }
   myInPlaceObjSelectState = subSelectionWay();
@@ -452,11 +463,15 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
     int nbSel = aSelList.Extent();
 
     if (nbSel == 1) {
-      Standard_Boolean aResult = Standard_False;
       GEOM::GEOM_Object_var anObj =
-        GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
+        GEOMBase::ConvertIOinGEOMObject(aSelList.First());
 
-      if (aResult && !anObj->_is_nil() && GEOMBase::IsShape(anObj)) {
+      if (GEOMBase::IsShape(anObj)) {
+        if (myIsHiddenMain) {
+          GEOM_Displayer* aDisplayer = getDisplayer();
+          aDisplayer->Display(myMainObj);
+          myIsHiddenMain = false;
+        }
         myMainObj = anObj;
         myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
         // activate subshapes selection by default
@@ -466,11 +481,16 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
       }
     }
     else {
+      if (myIsHiddenMain) {
+        GEOM_Displayer* aDisplayer = getDisplayer();
+        aDisplayer->Display(myMainObj);
+        myIsHiddenMain = false;
+      }
       myMainObj = GEOM::GEOM_Object::_nil();
     }
   }
   else { // an attempt to synchronize list box selection with 3d viewer
-    if (myBusy) {
+    if (myBusy || myMainObj->_is_nil()) {
       return;
     }
 
@@ -486,10 +506,15 @@ void GroupGUI_GroupDlg::SelectionIntoArgument()
       for (int i = 0, n = myIdList->count(); i < n; i++)
         aMap.insert(myIdList->item(i)->text().toInt(), i);
 
+      bool highlight = false;
       for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
-        if (aMap.contains(aMapIndex(ii)))
+        if (aMap.contains(aMapIndex(ii))) {
           myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
+          highlight = true;
+        }
       }
+      if (highlight)
+        highlightSubShapes();
     }
     myIdList->blockSignals(isBlocked);
 
@@ -592,11 +617,28 @@ void GroupGUI_GroupDlg::showOnlySelected()
   GEOM_Displayer* aDisplayer = getDisplayer();
 
   if (send == myHideSelBtn) {
-    aDisplayer->Erase(aSelList, false, true);
+    aDisplayer->Erase(aSelList, /*forced=*/false, /*updateViewer=*/true);
   }
   else {
-    aDisplayer->EraseAll();
+    // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
+    SALOME_View* view = GEOM_Displayer::GetActiveView();
+    if (view) {
+      CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
+      Handle(SALOME_InteractiveObject) io =
+        new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
+      if (view->isVisible(io)) myIsHiddenMain = true;
+    }
+
+    aDisplayer->EraseAll(/*forced = false, updateViewer = true*/);
     aDisplayer->Display(aSelList, true);
+
+    // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
+    if (getShapeType() == TopAbs_VERTEX && myIsHiddenMain) {
+      aDisplayer->Display(myMainObj);
+    }
+
+    // for the case when selected ids were not displayed in the viewer: Mantis issue 0021367
+    highlightSubShapes();
   }
 }
 
@@ -609,7 +651,8 @@ int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMap
   theMapIndex.Clear();
 
   SalomeApp_Application* app = myGeomGUI->getApp();
-  if (!app) return 0;
+  if (!app || myMainObj->_is_nil())
+    return 0;
 
   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
   SALOME_ListIO aSelList;
@@ -645,7 +688,7 @@ int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMap
         if (GEOMBase::GetShape(aGeomObj, aShape)) {
           if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
             TopTools_IndexedMapOfShape aMainMap;
-            TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
+            TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
             TopExp::MapShapes(aMainShape, aMainMap);
 
             TopExp_Explorer anExp (aShape, getShapeType());
@@ -779,6 +822,26 @@ void GroupGUI_GroupDlg::activateSelection()
   {
     GEOM_Displayer* aDisplayer = getDisplayer();
 
+    // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
+    if (getShapeType() == TopAbs_VERTEX) {
+      if (myIsHiddenMain)
+        aDisplayer->Display(myMainObj);
+    }
+    else {
+      SALOME_View* view = GEOM_Displayer::GetActiveView();
+      if (view) {
+        CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
+        Handle(SALOME_InteractiveObject) io =
+          new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
+        if (view->isVisible(io)) {
+          aDisplayer->Erase(myMainObj, false, false);
+          myIsHiddenMain = true;
+        }
+      }
+    }
+
+    int prevDisplayMode = aDisplayer->SetDisplayMode(0);
+
     SUIT_ViewWindow* aViewWindow = 0;
     SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
     if (activeStudy)
@@ -794,32 +857,52 @@ void GroupGUI_GroupDlg::activateSelection()
     SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
     if (aView == 0) return;
 
-    TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
+    TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
     TopoDS_Shape aRestrictionShape;
-    if (subSelectionWay() == ALL_SUBSHAPES)
-      aRestrictionShape = aMainShape;
-    else if (!myInPlaceObj->_is_nil())
-      aRestrictionShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myInPlaceObj);
-    else ;
 
-    TopTools_IndexedMapOfShape aSubShapesMap;
-    TopExp::MapShapes(aMainShape, aSubShapesMap);
-    CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
-    QString anEntryBase = aMainEntry.in();
-
-    TopExp_Explorer anExp (aRestrictionShape, getShapeType());
-    for (; anExp.More(); anExp.Next())
-    {
-      TopoDS_Shape aSubShape = anExp.Current();
-      int index = aSubShapesMap.FindIndex(aSubShape);
-      QString anEntry = anEntryBase + QString("_%1").arg(index);
+    if (subSelectionWay() == ALL_SUBSHAPES) {
+      aRestrictionShape = aMainShape;
 
-      SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
-      if (aPrs) {
-        displayPreview(aPrs, true, false); // append, do not update
+      TopTools_IndexedMapOfShape aSubShapesMap;
+      TopExp::MapShapes(aMainShape, aSubShapesMap);
+      CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
+      QString anEntryBase = aMainEntry.in();
+
+      TopExp_Explorer anExp (aRestrictionShape, getShapeType());
+      for (; anExp.More(); anExp.Next()) {
+        TopoDS_Shape aSubShape = anExp.Current();
+        int index = aSubShapesMap.FindIndex(aSubShape);
+        QString anEntry = anEntryBase + QString("_%1").arg(index);
+
+        SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
+        if (aPrs) {
+          displayPreview(aPrs, true, false); // append, do not update
+          // TODO: map or delete Prs
+        }
+      }
+    }
+    else if (!myInPlaceObj->_is_nil()) {
+      TopTools_IndexedMapOfShape aSubShapesMap;
+      TopExp::MapShapes(aMainShape, aSubShapesMap);
+      CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
+      QString anEntryBase = aMainEntry.in();
+
+      TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
+      for (; aM2IPit.More(); aM2IPit.Next()) {
+        int index = aM2IPit.Key();
+        TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
+        QString anEntry = anEntryBase + QString("_%1").arg(index);
+
+        SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
+        if (aPrs) {
+          displayPreview(aPrs, true, false); // append, do not update
+        }
       }
     }
+    else ;
+
     aDisplayer->UpdateViewer();
+    aDisplayer->SetDisplayMode(prevDisplayMode);
   }
 
   globalSelection(GEOM_ALLSHAPES);
@@ -842,7 +925,7 @@ void GroupGUI_GroupDlg::updateState (bool isAdd)
   myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
   mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
 
-  mySelBtn2->setEnabled(   subSelectionWay() != ALL_SUBSHAPES);
+  mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
   myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
   if (subSelectionWay() == ALL_SUBSHAPES)
     setInPlaceObj(GEOM::GEOM_Object::_nil());
@@ -877,7 +960,7 @@ void GroupGUI_GroupDlg::highlightSubShapes()
       int id = myIdList->item(ii)->text().toInt();
       if (subSelectionWay() != ALL_SUBSHAPES &&
           !myMain2InPlaceIndices.IsBound(id)) {
-        myIdList->item(ii)->setSelected(false);
+        //myIdList->item(ii)->setSelected(false);
       }
       else {
         anIds.Add(id);
@@ -903,15 +986,37 @@ void GroupGUI_GroupDlg::highlightSubShapes()
   SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
   if (aView == 0) return;
 
-  // TODO: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
+  // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
 
   OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
   Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
   AIS_ListOfInteractive List;
-  ic->DisplayedObjects(List);
+  //ic->DisplayedObjects(List);
+  ic->ObjectsInside(List); // Mantis issue 0021367
 
   SALOME_ListIO aSelList;
 
+  // To highlight the selected subshape in Object Browser, if it's already published under the main shape
+  GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
+  QMap<int, QString> childsMap;
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
+  if (appStudy) {
+    _PTR(Study) aStudy = appStudy->studyDS();
+    CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
+    QString anEntry = aMainEntry.in();
+    _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
+    _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
+    for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
+      GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
+      if (!CORBA::is_nil(aChild)) {
+        int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
+        CORBA::String_var aChildEntry = aChild->GetStudyEntry();
+        QString anEntry = aChildEntry.in();
+        childsMap.insert(index, anEntry);
+      }
+    }
+  }
+
   AIS_ListIteratorOfListOfInteractive ite (List);
   for (; ite.More(); ite.Next()) {
     if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
@@ -922,8 +1027,13 @@ void GroupGUI_GroupDlg::highlightSubShapes()
         int index = anEntry.lastIndexOf("_");
         anEntry.remove(0, index+1);
         int anIndex = anEntry.toInt();
-        if (anIds.Contains(anIndex))
+        if (anIds.Contains(anIndex)) {
           aSelList.Append(anIO);
+          if (childsMap.contains (anIndex)) {
+            Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
+            aSelList.Append(tmpIO);
+          }
+        }
       }
     }
   }
@@ -1022,11 +1132,9 @@ bool GroupGUI_GroupDlg::execute(ObjectList& objects)
 
   SalomeApp_Study* study = getStudy();
   if (study) {
-    char* objIOR = GEOMBase::GetIORFromObject(aGroup);
-    std::string IOR(objIOR);
-    free(objIOR);
-    if (IOR != "") {
-      _PTR(SObject) SO (study->studyDS()->FindObjectIOR(IOR));
+    QString objIOR = GEOMBase::GetIORFromObject(aGroup);
+    if (objIOR != "") {
+      _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
       if (SO) {
         _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
         aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
@@ -1042,7 +1150,7 @@ bool GroupGUI_GroupDlg::execute(ObjectList& objects)
 //================================================================
 // Function : getFather
 // Purpose  : Get father object for object to be added in study
-//            ( called with addInStudy method )
+//            (called with addInStudy method)
 //================================================================
 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
 {