]> SALOME platform Git repositories - modules/geom.git/blob - src/GroupGUI/GroupGUI_GroupDlg.cxx
Salome HOME
Merge branch V7_3_1_BR
[modules/geom.git] / src / GroupGUI / GroupGUI_GroupDlg.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  GEOM GEOMGUI : GUI for Geometry component
24 //  File   : GroupGUI_GroupDlg.cxx
25 //  Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26
27 #include "GroupGUI_GroupDlg.h"
28
29 #include <DlgRef.h>
30 #include <GEOMBase.h>
31 #include <GeometryGUI.h>
32 #include <GEOM_Displayer.h>
33
34 #include <SalomeApp_Application.h>
35 #include <SalomeApp_Study.h>
36 #include <SalomeApp_Tools.h>
37
38 #include <LightApp_SelectionMgr.h>
39
40 #include <OCCViewer_ViewModel.h>
41 #include <OCCViewer_ViewManager.h>
42 #include <SVTK_ViewModel.h>
43 #include <SALOME_Prs.h>
44 #include <SALOME_ListIteratorOfListIO.hxx>
45
46 #include <SUIT_Desktop.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_OverrideCursor.h>
49 #include <SUIT_ResourceMgr.h>
50 #include <SUIT_Session.h>
51 #include <SUIT_ViewWindow.h>
52 #include <SUIT_ViewManager.h>
53
54 #include <QLabel>
55 #include <QListWidget>
56 #include <QLineEdit>
57 #include <QMap>
58
59 #include <AIS_ListOfInteractive.hxx>
60 #include <AIS_ListIteratorOfListOfInteractive.hxx>
61
62 #include <TopExp.hxx>
63 #include <TopExp_Explorer.hxx>
64 #include <TopTools_IndexedMapOfShape.hxx>
65 #include <TColStd_IndexedMapOfInteger.hxx>
66 #include <TColStd_MapOfInteger.hxx>
67 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
68
69 #include <GEOMImpl_Types.hxx>
70
71 #define GROUP_IDLST_COLOR Qt::blue // Specific color for the IDs of subShapes in the dialog box
72 #define GROUP_NEWIDLST_COLOR Qt::red // Specific color for the new IDs of subShapes in the dialog box
73
74 enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2, SUBSHAPES_OF_INVISIBLE_SHAPE2 };
75
76 GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
77   : GEOMBase_Skeleton(theGeometryGUI, parent, false),
78     myMode(mode),
79     myBusy(false),
80     myIsShapeType(false),
81     myIsHiddenMain(false)
82 {
83   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
84
85   QPixmap image0     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
86   QPixmap image1     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
87   QPixmap image2     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
88   QPixmap image3     (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
89   QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
90
91   setWindowTitle(myMode == CreateGroup ? tr("CREATE_GROUP_TITLE") : tr("EDIT_GROUP_TITLE"));
92
93   // Shape type button group
94   mainFrame()->GroupConstructors->setEnabled(myMode == CreateGroup);
95   mainFrame()->GroupConstructors->setTitle(tr("SHAPE_TYPE"));
96   mainFrame()->RadioButton1->setIcon(image0);
97   mainFrame()->RadioButton2->setIcon(image1);
98   mainFrame()->RadioButton3->setIcon(image2);
99   mainFrame()->RadioButton4->setIcon(image3);
100   mainFrame()->RadioButton4->show();
101
102   // Group name
103   mainFrame()->GroupBoxName->setTitle(tr("GROUP_NAME"));
104
105   // Main shape and sub-shapes
106   QGroupBox* GroupMedium = new QGroupBox(tr("MAIN_SUB_SHAPES"), centralWidget());
107   QGridLayout* aMedLayout = new QGridLayout(GroupMedium);
108   aMedLayout->setMargin(9);
109   aMedLayout->setSpacing(6);
110
111   QLabel* aMainLabel = new QLabel(tr("MAIN_SHAPE"), GroupMedium);
112
113   mySelBtn = new QPushButton(GroupMedium);
114   mySelBtn->setIcon(iconSelect);
115   mySelBtn->setEnabled(myMode == CreateGroup);
116
117   myMainName = new QLineEdit(GroupMedium);
118   myMainName->setReadOnly(true);
119   myMainName->setEnabled(myMode == CreateGroup);
120
121   myRestrictGroupBox = new QGroupBox(tr("SHAPE_SEL_RESTR"), GroupMedium);
122   myRestrictGroup = new QButtonGroup(myRestrictGroupBox);
123   QRadioButton* allSubs     = new QRadioButton(tr("NO_RESTR")            , myRestrictGroupBox);
124   QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"), myRestrictGroupBox);
125   QRadioButton* shape2Subs  = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") , myRestrictGroupBox);
126   QGridLayout* aRestrictLayout = new QGridLayout(myRestrictGroupBox);
127
128   QLabel* aSecondLabel = new QLabel(tr("SECOND_SHAPE"), myRestrictGroupBox);
129   mySelBtn2 = new QPushButton(myRestrictGroupBox);
130   mySelBtn2->setIcon(iconSelect);
131   mySelBtn2->setEnabled(false);
132   myShape2Name = new QLineEdit(myRestrictGroupBox);
133   myShape2Name->setReadOnly(true);
134   myShape2Name->setEnabled(false);
135
136   aRestrictLayout->setMargin(9);
137   aRestrictLayout->setSpacing(6);
138   aRestrictLayout->addWidget(allSubs,      0, 0, 1, 3);
139   aRestrictLayout->addWidget(inPlaceSubs,  1, 0, 1, 3);
140   aRestrictLayout->addWidget(shape2Subs,   2, 0, 1, 3);
141   aRestrictLayout->addWidget(aSecondLabel, 3, 0);
142   aRestrictLayout->addWidget(mySelBtn2,    3, 1);
143   aRestrictLayout->addWidget(myShape2Name, 3, 2);
144   myRestrictGroup->addButton(allSubs,      ALL_SUBSHAPES);
145   myRestrictGroup->addButton(inPlaceSubs,  GET_IN_PLACE);
146   myRestrictGroup->addButton(shape2Subs,   SUBSHAPES_OF_SHAPE2);
147   myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
148   allSubs->setChecked(true);
149
150   myShowOnlyBtn = new QPushButton(tr("SHOW_ONLY_SELECTED"), GroupMedium);
151   myHideSelBtn  = new QPushButton(tr("HIDE_SELECTED"), GroupMedium);
152   myShowAllBtn  = new QPushButton(tr("SHOW_ALL_SUB_SHAPES"), GroupMedium);
153
154   mySelAllBtn   = new QPushButton(tr("SELECT_ALL"), GroupMedium);
155   myAddBtn      = new QPushButton(tr("ADD"), GroupMedium);
156   myRemBtn      = new QPushButton(tr("REMOVE"), GroupMedium);
157
158   myIdList    = new QListWidget(GroupMedium);
159
160   myIdList->setSelectionMode(QAbstractItemView::ExtendedSelection);
161   myIdList->setFlow(QListView::TopToBottom);
162   myIdList->setWrapping(true);
163
164   aMedLayout->addWidget(aMainLabel,         0, 0);
165   aMedLayout->addWidget(mySelBtn,           0, 1);
166   aMedLayout->addWidget(myMainName,         0, 2, 1, 2);
167   aMedLayout->addWidget(myRestrictGroupBox, 1, 0, 4, 3);
168
169   aMedLayout->addWidget(myShowOnlyBtn,      1, 3);
170   aMedLayout->addWidget(myHideSelBtn,       2, 3);
171   aMedLayout->addWidget(myShowAllBtn,       3, 3);
172
173   aMedLayout->addWidget(myIdList,           5, 0, 4, 3);
174   aMedLayout->addWidget(mySelAllBtn,        5, 3);
175   aMedLayout->addWidget(myAddBtn,           6, 3);
176   aMedLayout->addWidget(myRemBtn,           7, 3);
177
178   aMedLayout->setColumnStretch(2, 5);
179   aMedLayout->setRowStretch(5, 5);
180   aMedLayout->setRowStretch(8, 5);
181
182   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
183   layout->setMargin(0); layout->setSpacing(6);
184   layout->addWidget(GroupMedium);
185
186   setHelpFileName("work_with_groups_page.html");
187
188   Init();
189   updateState();
190 }
191
192 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
193 {
194   GEOM_Displayer* aDisplayer = getDisplayer();
195   if (myIsHiddenMain) {
196     aDisplayer->Display(myMainObj);
197     myIsHiddenMain = false;
198   }
199   aDisplayer->Display(myGroup);
200   myDmMode = -1;
201 }
202
203 //=================================================================================
204 // function : Init()
205 // purpose  :
206 //=================================================================================
207 void GroupGUI_GroupDlg::Init()
208 {
209   myDmMode = -1;
210   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
211
212   //unset shape type to avoid preparation of selection before exact user shape type selection
213   unsetConstructorId();
214   myIsShapeType = false;
215
216   if (myMode == CreateGroup) {
217     initName(tr("GROUP_PREFIX"));
218
219     // Get ready for main shape selection
220     myEditCurrentArgument = myMainName;
221
222     connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
223     connect(mySelBtn,         SIGNAL(clicked()),    this, SLOT(SetEditCurrentArgument()));
224     connect(mySelBtn2,        SIGNAL(clicked()),    this, SLOT(SetEditCurrentArgument()));
225   }
226   else if (myMode == EditGroup) {
227     SALOME_ListIO aSelList;
228     aSelMgr->selectedObjects(aSelList);
229
230     if (aSelList.Extent()) {
231       GEOM::GEOM_Object_var anObj =
232         GEOMBase::ConvertIOinGEOMObject(aSelList.First());
233
234       if (!CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
235         myGroup = anObj;
236
237         mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
238
239         GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
240         myMainObj = anOper->GetMainShape(myGroup);
241         if (!CORBA::is_nil(myMainObj))
242           myMainName->setText(GEOMBase::GetName(myMainObj));
243
244         setShapeType((TopAbs_ShapeEnum)anOper->GetType(myGroup));
245
246         GEOM::ListOfLong_var aCurrList = anOper->GetObjects(myGroup);
247         for (int i = 0, n = aCurrList->length(); i < n; i++) {
248           QListWidgetItem* itm = new QListWidgetItem( QString( "%1" ).arg( aCurrList[ i ] ) );
249           myGroupIdList.append( aCurrList[ i ] );
250           itm->setTextColor( QColor( GROUP_IDLST_COLOR ) );
251           myIdList->addItem( itm );
252         }
253         myEditCurrentArgument = 0;
254       }
255       connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
256     }
257   }
258
259   connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
260
261   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
262   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
263
264   connect(myRestrictGroup, SIGNAL(buttonClicked(int)),     this, SLOT(SetEditCurrentArgument()));
265   connect(mySelAllBtn,     SIGNAL(clicked()),              this, SLOT(selectAllSubShapes()));
266   connect(myAddBtn,        SIGNAL(clicked()),              this, SLOT(add()));
267   connect(myRemBtn,        SIGNAL(clicked()),              this, SLOT(remove()));
268   connect(myShowOnlyBtn,   SIGNAL(clicked()),              this, SLOT(showOnlySelected()));
269   connect(myHideSelBtn,    SIGNAL(clicked()),              this, SLOT(showOnlySelected()));
270   connect(myShowAllBtn,    SIGNAL(clicked()),              this, SLOT(showOnlySelected()));
271   connect(myIdList,        SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
272
273   setInPlaceObj(GEOM::GEOM_Object::_nil());
274
275   myBusy = true; // just activate but do not select in the list
276   activateSelection();
277   myBusy = false;
278 }
279
280 //=================================================================================
281 // function : enterEvent()
282 // purpose  :
283 //=================================================================================
284 void GroupGUI_GroupDlg::enterEvent(QEvent* e)
285 {
286   if (!buttonCancel()->isEnabled())
287     ActivateThisDialog();
288 }
289
290 //=================================================================================
291 //function : closeEvent
292 //purpose  : remove temporary geom object
293 //=================================================================================
294 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
295 {
296   setInPlaceObj(GEOM::GEOM_Object::_nil());
297   erasePreview(true);
298
299   GEOMBase_Skeleton::closeEvent(e);
300 }
301
302 //=================================================================================
303 // function : ClickOnOk()
304 // purpose  :
305 //=================================================================================
306 void GroupGUI_GroupDlg::ClickOnOk()
307 {
308   setIsApplyAndClose(true);
309   if (ClickOnApply())
310     ClickOnCancel();
311   setIsApplyAndClose(false);
312 }
313
314 //=================================================================================
315 // function : ClickOnApply()
316 // purpose  :
317 //=================================================================================
318 bool GroupGUI_GroupDlg::ClickOnApply()
319 {
320   if(!isApplyAndClose()) {
321     setIsDisableBrowsing( true );
322     setIsDisplayResult( false );
323   }
324     
325   if (!onAccept(myMode == CreateGroup, true, isApplyAndClose()))
326     return false;
327
328   if(!isApplyAndClose()) {
329     setIsDisableBrowsing( false );
330     setIsDisplayResult( true );
331   }
332
333   if (myMode == CreateGroup)
334   {
335     initName();
336     myIdList->clear();
337     ConstructorsClicked(getConstructorId());
338   }
339   else
340   {
341     int n = myIdList->count();
342     myGroupIdList.clear();
343     if (n > 0)
344     {
345       for (int i = 0; i < n; i++) {
346         QListWidgetItem* anItem  = myIdList->item( i );
347         myGroupIdList.append( anItem->text().toInt() );
348         anItem->setTextColor( GROUP_IDLST_COLOR );
349       }
350     }
351     activateSelection();
352   }
353   return true;
354 }
355
356 //=================================================================================
357 // function : ActivateThisDialog()
358 // purpose  :
359 //=================================================================================
360 void GroupGUI_GroupDlg::ActivateThisDialog()
361 {
362   GEOMBase_Skeleton::ActivateThisDialog();
363
364   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
365           this, SLOT(SelectionIntoArgument()));
366
367   activateSelection();
368 }
369
370 //=================================================================================
371 // function : SetEditCurrentArgument()
372 // purpose  :
373 //=================================================================================
374 void GroupGUI_GroupDlg::SetEditCurrentArgument()
375 {
376   QPushButton* send = (QPushButton*)sender();
377
378   if (send == mySelBtn) {
379     myEditCurrentArgument = myMainName;
380     myShape2Name->setText("");
381   }
382   else if (send == mySelBtn2 || sender() == myRestrictGroup) {
383     setInPlaceObj(GEOM::GEOM_Object::_nil());
384     myShape2Name->setText("");
385     if (subSelectionWay() != ALL_SUBSHAPES) {
386       myEditCurrentArgument = myShape2Name;
387     }
388     else {
389       myEditCurrentArgument = 0;
390     }
391   }
392
393   activateSelection();
394
395   updateState();
396 }
397
398 //=================================================================================
399 // function : onGetInPlace()
400 // purpose  :
401 //=================================================================================
402 void GroupGUI_GroupDlg::onGetInPlace()
403 {
404   setInPlaceObj(GEOM::GEOM_Object::_nil());
405   myEditCurrentArgument->setText("");
406
407   bool isBlocked = myIdList->signalsBlocked();
408   myIdList->blockSignals(true);
409   myIdList->clearSelection();
410   myIdList->blockSignals(isBlocked);
411
412   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
413   SALOME_ListIO aSelList;
414   aSelMgr->selectedObjects(aSelList);
415
416   if (aSelList.Extent() != 1)
417     return;
418
419   GEOM::GEOM_Object_var anObj =
420     GEOMBase::ConvertIOinGEOMObject(aSelList.First());
421   if (GEOMBase::IsShape(anObj)) {
422     if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
423       SUIT_OverrideCursor wc;
424       myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
425       GEOM::GEOM_IShapesOperations_var aShapesOp =
426         getGeomEngine()->GetIShapesOperations(getStudyId());
427       if (subSelectionWay() == GET_IN_PLACE) {
428         GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
429         setInPlaceObj(aGetInPlaceObj);
430       }
431       else {
432         bool isVisible = true;
433         if (SALOME_View* view = GEOM_Displayer::GetActiveView())
434           isVisible = view->isVisible(aSelList.First());
435         setInPlaceObj(anObj, isVisible);
436       }
437       myEditCurrentArgument = 0;
438       //myBusy = true; // just activate but do not select in the list
439       activateSelection();
440       //myBusy = false;
441     }
442   }
443 }
444
445 //=================================================================================
446 //function : setInPlaceObj
447 //purpose  : temporarily add an object to study and remove old InPlaceObj
448 //=================================================================================
449 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
450 {
451   if (!myInPlaceObj->_is_equivalent(theObj))
452   {
453     myInPlaceObj = theObj;
454   }
455
456   // build map of indices
457   myMain2InPlaceIndices.Clear();
458   if (!myInPlaceObj->_is_nil()) {
459     GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
460     GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
461
462     GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
463     for ( int i = 0; i < aSubObjects->length(); i++ )
464     {
465       GEOM::ListOfLong_var aCurrList = aShapesOp->GetSameIDs( myMainObj, aSubObjects[i] );
466       if( aCurrList->length() > 1 ) {
467         //rnv : To Fix the 21561: EDF 2184 GEOM: Group with second shape restriction.
468         //      In case if GetSameIDs(...) method return more then one ID use 
469         //      GetSharedShapes(...) method to get sub-shapes of the second shape.
470         GEOM::ListOfGO_var aSubObjects2 = aShapesOp->GetSharedShapes( myMainObj, aSubObjects[i], getShapeType() );
471         for( int j = 0; j < aSubObjects2->length(); j++ ) {
472           CORBA::Long aMainIndex =  aLocOp->GetSubShapeIndex( myMainObj, aSubObjects2[j] );
473           CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i]);
474           if ( aMainIndex >= 0 && aPlaceIndex > 0 ) {
475             myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
476           }
477         }
478       } else if(aCurrList->length() > 0 ) {
479         CORBA::Long aMainIndex = aCurrList[0];
480         CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i] );
481         if ( aMainIndex >= 0 && aPlaceIndex > 0) {
482           myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
483         }
484       }
485     }
486   }
487   myInPlaceObjSelectState = subSelectionWay();
488   if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
489     myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
490 }
491
492 //=================================================================================
493 // function : SelectionIntoArgument()
494 // purpose  : Called when selection has changed
495 //=================================================================================
496 void GroupGUI_GroupDlg::SelectionIntoArgument()
497 {
498   if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
499     onGetInPlace();
500     return;
501   }
502
503   if (myEditCurrentArgument == myMainName) {  // Selection of a main shape is active
504     myEditCurrentArgument->setText("");
505     myIdList->clear();
506
507     LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
508     SALOME_ListIO aSelList;
509     aSelMgr->selectedObjects(aSelList);
510     int nbSel = aSelList.Extent();
511
512     if (nbSel == 1) {
513       GEOM::GEOM_Object_var anObj =
514         GEOMBase::ConvertIOinGEOMObject(aSelList.First());
515
516       if (GEOMBase::IsShape(anObj)) {
517         if (myIsHiddenMain) {
518           GEOM_Displayer* aDisplayer = getDisplayer();
519           aDisplayer->Display(myMainObj);
520           myIsHiddenMain = false;
521         }
522         myMainObj = anObj;
523         myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
524         // activate sub-shapes selection by default
525         myEditCurrentArgument = 0;
526         activateSelection();
527         updateState();
528       }
529     }
530     else {
531       if (myIsHiddenMain) {
532         GEOM_Displayer* aDisplayer = getDisplayer();
533         aDisplayer->Display(myMainObj);
534         myIsHiddenMain = false;
535       }
536       myMainObj = GEOM::GEOM_Object::_nil();
537     }
538   }
539   else { // an attempt to synchronize list box selection with 3d viewer
540     if (myBusy || myMainObj->_is_nil()) {
541       return;
542     }
543
544     bool isBlocked = myIdList->signalsBlocked();
545     myIdList->blockSignals(true);
546     myIdList->clearSelection();
547
548     TColStd_IndexedMapOfInteger aMapIndex;
549     int nbSel = getSelectedSubshapes(aMapIndex);
550
551     if (nbSel) {
552       QMap<int, int> aMap;
553       for (int i = 0, n = myIdList->count(); i < n; i++)
554         aMap.insert(myIdList->item(i)->text().toInt(), i);
555
556       bool highlight = false;
557       for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
558         if (aMap.contains(aMapIndex(ii))) {
559           myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
560           highlight = true;
561         }
562       }
563       if (highlight)
564         highlightSubShapes();
565     }
566     myIdList->blockSignals(isBlocked);
567
568     updateState(nbSel);
569   }
570 }
571
572 //=================================================================================
573 // function : ConstructorsClicked()
574 // purpose  : Radio button management
575 //=================================================================================
576 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
577 {
578   if (getConstructorId() != constructorId)
579     setConstructorId(constructorId);
580
581   myIsShapeType = true;
582   myIdList->clear();
583   myEditCurrentArgument = 0;
584
585   setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
586   activateSelection();
587   updateState();
588 }
589
590 //=================================================================================
591 // function : selectAllSubShapes
592 // purpose  :
593 //=================================================================================
594 void GroupGUI_GroupDlg::selectAllSubShapes()
595 {
596   if (CORBA::is_nil(myMainObj) || !myIsShapeType)
597     return;
598
599   GEOM::ListOfLong_var aSubShapes;
600   GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
601   aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
602   if (aSubShapes->length() > 0) {
603     if (subSelectionWay() == ALL_SUBSHAPES)
604     {
605 //      myIdList->clear(); // for sorted final list?
606
607       if (!aShOp->IsDone())
608         return;
609     }
610     else
611     {
612       aSubShapes = new GEOM::ListOfLong();
613       aSubShapes->length(myMain2InPlaceIndices.Extent());
614       TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
615       for (int i = 0; m2ip.More(); i++, m2ip.Next())
616         aSubShapes[i] = m2ip.Key();
617     }
618
619     bool isBlocked = myIdList->signalsBlocked();
620     myIdList->blockSignals(true);
621
622     for (int i = 0, n = aSubShapes->length(); i < n; i++) {
623       CORBA::Long anIndex = aSubShapes[i];
624       if (anIndex < 0)
625         continue;
626
627       QListWidgetItem* anItem = 0;
628       QString text = QString("%1").arg(anIndex);
629 //      if (!myInPlaceObj->_is_nil()) {
630         QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
631         if (found.count()) anItem = found[0];
632 //      }
633       if (!anItem) {
634         anItem = new QListWidgetItem(text);
635         anItem->setTextColor( myGroupIdList.contains(anIndex) ? QColor( GROUP_IDLST_COLOR ) : QColor( GROUP_NEWIDLST_COLOR ) );
636         myIdList->addItem(anItem);
637       }
638       anItem->setSelected(true);
639     }
640
641     myIdList->blockSignals(isBlocked);
642     highlightSubShapes();
643   }
644 }
645
646 //=================================================================================
647 // function : showOnlySelected
648 // purpose  :
649 //=================================================================================
650 void GroupGUI_GroupDlg::showOnlySelected()
651 {
652   if (CORBA::is_nil(myMainObj) || !myIsShapeType)
653     return;
654
655   QPushButton* send = (QPushButton*)sender();
656   if (send == myShowAllBtn) {
657     activateSelection();
658     return;
659   }
660
661   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
662   SALOME_ListIO aSelList;
663   aSelMgr->selectedObjects(aSelList);
664
665   GEOM_Displayer* aDisplayer = getDisplayer();
666
667   if (send == myHideSelBtn) {
668     aDisplayer->Erase(aSelList, /*forced=*/false, /*updateViewer=*/true);
669   }
670   else {
671     // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
672     SALOME_View* view = GEOM_Displayer::GetActiveView();
673     if (view) {
674       CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
675       Handle(SALOME_InteractiveObject) io =
676         new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
677       if (view->isVisible(io)) myIsHiddenMain = true;
678       
679       //keep the selected entry and IO in the map for checking
680       std::map<QString, Handle(SALOME_InteractiveObject)> aSelEntriesMap;
681       SALOME_ListIteratorOfListIO aSelIt(aSelList);
682       for ( ; aSelIt.More(); aSelIt.Next() ) {
683         Handle(SALOME_InteractiveObject) anSelIO = aSelIt.Value();
684         aSelEntriesMap[anSelIO->getEntry()] = anSelIO;
685       }
686       //get the displayed sub-shapes
687       SALOME_ListIO displayed;
688       view->GetVisible(displayed);
689       // Erase all, except the selected sub-shapes
690       std::map<QString, Handle(SALOME_InteractiveObject)>::iterator 
691         aSelDispIter = aSelEntriesMap.end();
692       SALOME_ListIteratorOfListIO aDispIt( displayed );
693       for ( ; aDispIt.More(); aDispIt.Next() ) {
694         Handle(SALOME_InteractiveObject) anIO = aDispIt.Value();
695         aSelDispIter = aSelEntriesMap.find( anIO->getEntry() );
696         if ( aSelDispIter != aSelEntriesMap.end() ) {
697           //sub-shape is selected, so erase it's record from map to keep in it not displayed, but selected sub-shapes only
698           aSelEntriesMap.erase(aSelDispIter);
699         } else {
700           //sub-shape is not in the map of selected, then erase it from view
701           aDisplayer->Erase( anIO, /*forced = */false, /*updateViewer = */false );
702         }
703       }
704
705       if ( !aSelEntriesMap.empty() ) {
706         // Build a presentation of the selected, but not displayed sub-shapes
707         TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
708         TopTools_IndexedMapOfShape aSubShapesMap;
709         TopExp::MapShapes(aMainShape, aSubShapesMap);
710         QString anEntryBase = aMainEntry.in();
711
712         TopExp_Explorer anExp (aMainShape, getShapeType());
713         for (; anExp.More(); anExp.Next()) {
714           TopoDS_Shape aSubShape = anExp.Current();
715           int index = aSubShapesMap.FindIndex(aSubShape);
716           QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
717           if ( aSelEntriesMap.find( anEntry ) == aSelEntriesMap.end() ) {
718             //skip not selected sub-shapes
719             continue;
720           }
721           SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, view);
722           if (aPrs) {
723             displayPreview(aPrs, true, false); // append, do not update
724           }
725         }
726       }
727       aDisplayer->UpdateViewer();
728     }
729
730     // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
731     if (getShapeType() == TopAbs_VERTEX && myIsHiddenMain) {
732       aDisplayer->Display(myMainObj);
733     }
734
735     // for the case when selected ids were not displayed in the viewer: Mantis issue 0021367
736     highlightSubShapes();
737   }
738 }
739
740 //=================================================================================
741 // function : getSelectedSubshapes
742 // purpose  :
743 //=================================================================================
744 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
745 {
746   theMapIndex.Clear();
747
748   SalomeApp_Application* app = myGeomGUI->getApp();
749   if (!app || myMainObj->_is_nil())
750     return 0;
751
752   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
753   SALOME_ListIO aSelList;
754   aSelMgr->selectedObjects(aSelList);
755
756   // try to find out and process the global selection
757   // (of not published objects and of published sub-shapes)
758   {
759     SALOME_ListIteratorOfListIO anIter (aSelList);
760     for (int i = 0; anIter.More(); anIter.Next(), i++)
761     {
762       Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
763       QString anEntry = anIObj->getEntry();
764       QString str = "_";
765       int index = anEntry.lastIndexOf(str);
766       if (index > 0) // selection among special preview
767       {
768         anEntry.remove(0, index+1);
769         int anIndex = anEntry.toInt();
770         if (anIndex)
771           theMapIndex.Add(anIndex);
772       }
773       else // selection among published shapes
774       {
775         SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
776         if (!appStudy) return 0;
777         _PTR(Study) aStudy = appStudy->studyDS();
778
779         _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
780         GEOM::GEOM_Object_var aGeomObj =
781           GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
782         TopoDS_Shape aShape;
783         if (GEOMBase::GetShape(aGeomObj, aShape)) {
784           if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
785             TopTools_IndexedMapOfShape aMainMap;
786             TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
787             TopExp::MapShapes(aMainShape, aMainMap);
788
789             TopExp_Explorer anExp (aShape, getShapeType());
790             bool isShowWarning = true;
791             for (; anExp.More(); anExp.Next()) {
792               TopoDS_Shape aSubShape = anExp.Current();
793               int anIndex = aMainMap.FindIndex(aSubShape);
794               if (anIndex == 0) {
795                 if (isShowWarning) {
796                   SUIT_MessageBox::warning(app->desktop(), QObject::tr("WRN_WARNING"),
797                                          tr("WRN_NOT_SUBSHAPE"));
798                   isShowWarning = false;
799                 }
800               }
801               else {
802                 if (subSelectionWay() != ALL_SUBSHAPES &&
803                     !myMain2InPlaceIndices.IsBound(anIndex))
804                   continue;
805                 theMapIndex.Add(anIndex);
806               }
807             }
808           }
809         }
810       }
811     } // for aSelList
812   }
813
814   return theMapIndex.Extent();
815 }
816
817 //=================================================================================
818 // function : add
819 // purpose  :
820 //=================================================================================
821 void GroupGUI_GroupDlg::add()
822 {
823   TColStd_IndexedMapOfInteger aMapIndex;
824   int nbSel = getSelectedSubshapes(aMapIndex);
825
826   TColStd_MapOfInteger aMap;
827   for (int i = 0, n = myIdList->count(); i < n; i++)
828     aMap.Add(myIdList->item(i)->text().toInt());
829
830   if (nbSel > 0) {
831     bool isBlocked = myIdList->signalsBlocked();
832     myIdList->blockSignals(true);
833
834     for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
835       if (aMap.Contains(aMapIndex(i)))
836         continue;
837
838       QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
839       anItem->setTextColor( myGroupIdList.contains( aMapIndex( i ) ) ? QColor( GROUP_IDLST_COLOR ) : QColor( GROUP_NEWIDLST_COLOR ) );
840       myIdList->addItem(anItem);
841       anItem->setSelected(true);
842     }
843
844     myIdList->blockSignals(isBlocked);
845   }
846
847   updateState();
848 }
849
850 //=================================================================================
851 // function : remove
852 // purpose  :
853 //=================================================================================
854 void GroupGUI_GroupDlg::remove()
855 {
856   bool isBlocked = myIdList->signalsBlocked();
857   myIdList->blockSignals(true);
858
859   QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
860   while (it.hasNext())
861     delete it.next();
862
863   myIdList->blockSignals(isBlocked);
864
865   highlightSubShapes();
866 }
867
868 //=================================================================================
869 //function : subSelectionWay
870 //purpose  :
871 //=================================================================================
872 int GroupGUI_GroupDlg::subSelectionWay() const
873 {
874   return myRestrictGroup->checkedId();
875 }
876
877 //=================================================================================
878 // function : getShapeType()
879 // purpose  :
880 //=================================================================================
881 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
882 {
883   switch (getConstructorId()) {
884   case 0:  return TopAbs_VERTEX;
885   case 1:  return TopAbs_EDGE;
886   case 2:  return TopAbs_FACE;
887   case 3:  return TopAbs_SOLID;
888   default: return TopAbs_SHAPE;
889   }
890 }
891
892 //=================================================================================
893 // function : setShapeType()
894 // purpose  :
895 //=================================================================================
896 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
897 {
898   int anId = 0;
899   switch (theType) {
900   case TopAbs_VERTEX: anId = 0; break;
901   case TopAbs_EDGE:   anId = 1; break;
902   case TopAbs_FACE:   anId = 2; break;
903   case TopAbs_SOLID:  anId = 3; break;
904   }
905   setConstructorId(anId);
906   if (!myIsShapeType)
907   {
908     myIsShapeType = true;
909     // workaround to avoid set checked button 0
910     setConstructorId(anId);
911   }
912 }
913
914 //=================================================================================
915 // function : activateSelection
916 // purpose  : Activate selection in accordance with myEditCurrentArgument
917 //=================================================================================
918 void GroupGUI_GroupDlg::activateSelection()
919 {
920   bool isApply = ((QPushButton*)sender() == buttonApply());
921   if(!isApplyAndClose())
922     erasePreview(false);
923
924   // local selection
925   if (!myMainObj->_is_nil() &&
926       !myEditCurrentArgument &&
927       myIsShapeType) // check if shape type is already choosen by user
928   {
929     GEOM_Displayer* aDisplayer = getDisplayer();
930
931     //display mode for main shape
932     if ( myDmMode == -1 ) {
933     SALOME_View* view = GEOM_Displayer::GetActiveView();
934       if (view) {
935         CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
936         Handle(SALOME_InteractiveObject) io =
937           new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
938         if ( view->isVisible( io ) ) {
939           Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIOinGEOMAISShape( io, true );
940           if(!aSh.IsNull()) {
941             myDmMode = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
942           }
943         }
944         else
945           myDmMode = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "display_mode" );
946       }
947     }
948     aDisplayer->SetDisplayMode(myDmMode);
949
950     // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
951     if(getShapeType() != TopAbs_VERTEX) {
952       aDisplayer->Erase(myMainObj, false, false);
953       myIsHiddenMain = true;
954     }
955     else
956       aDisplayer->Display(myMainObj);
957
958     aDisplayer->Erase(myGroup, false, false);
959
960     QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", "editgroup_color" );
961     Quantity_NameOfColor aCol = SalomeApp_Tools::color( aColor ).Name();
962
963     if(!isApplyAndClose()) {
964       SUIT_ViewWindow* aViewWindow = 0;
965       SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
966       if (activeStudy)
967         aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
968       if (aViewWindow == 0) return;
969
970       SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
971       if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
972           aViewManager->getType() != SVTK_Viewer::Type())
973         return;
974
975       SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
976       SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
977       if (aView == 0) return;
978
979       TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
980       TopoDS_Shape aRestrictionShape;
981
982       if (subSelectionWay() == ALL_SUBSHAPES) {
983         aRestrictionShape = aMainShape;
984
985         TopTools_IndexedMapOfShape aSubShapesMap;
986         TopExp::MapShapes(aMainShape, aSubShapesMap);
987         CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
988         QString anEntryBase = aMainEntry.in();
989
990         TopExp_Explorer anExp (aRestrictionShape, getShapeType());
991         for (; anExp.More(); anExp.Next()) {
992           TopoDS_Shape aSubShape = anExp.Current();
993           int index = aSubShapesMap.FindIndex(aSubShape);
994           QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
995           Handle(SALOME_InteractiveObject) io =
996             new SALOME_InteractiveObject(anEntry.toAscii(), "GEOM", "TEMP_IO");
997           if ( myGroupIdList.contains( index ) ) {
998             aDisplayer->SetColor( aCol );
999           }
1000           else {
1001             aDisplayer->UnsetColor();
1002           }
1003           SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
1004           if (aPrs) {
1005             displayPreview(aPrs, true, false); // append, do not update
1006             // TODO: map or delete Prs
1007           }
1008         }
1009       }
1010       else if (!myInPlaceObj->_is_nil()) {
1011         TopTools_IndexedMapOfShape aSubShapesMap;
1012         TopExp::MapShapes(aMainShape, aSubShapesMap);
1013         CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1014         QString anEntryBase = aMainEntry.in();
1015
1016         TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
1017         for (; aM2IPit.More(); aM2IPit.Next()) {
1018           int index = aM2IPit.Key();
1019           TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
1020           QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
1021
1022           if ( myGroupIdList.contains( index ) ) {
1023             aDisplayer->SetColor( aCol );
1024           }
1025           else {
1026             aDisplayer->UnsetColor();
1027           }
1028
1029           SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
1030           if (aPrs) {
1031             displayPreview(aPrs, true, false); // append, do not update
1032           }
1033         }
1034       }
1035       else ;
1036       aDisplayer->UnsetDisplayMode();
1037       aDisplayer->UnsetColor();
1038       aDisplayer->UpdateViewer();
1039     }
1040   }
1041
1042   globalSelection(GEOM_ALLSHAPES);
1043
1044   SelectionIntoArgument();
1045 }
1046
1047 //=================================================================================
1048 // function : updateState
1049 // purpose  :
1050 //=================================================================================
1051 void GroupGUI_GroupDlg::updateState (bool isAdd)
1052 {
1053   myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
1054   //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
1055
1056   bool hasSel = myIdList->selectedItems().count() > 0;
1057
1058   myRemBtn->setEnabled(hasSel);
1059   myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
1060   mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
1061
1062   mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
1063   myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
1064   if (subSelectionWay() == ALL_SUBSHAPES)
1065     setInPlaceObj(GEOM::GEOM_Object::_nil());
1066 }
1067
1068 //=================================================================================
1069 // function : selectionChanged
1070 // purpose  :
1071 //=================================================================================
1072 void GroupGUI_GroupDlg::selectionChanged()
1073 {
1074   highlightSubShapes();
1075 }
1076
1077 //=================================================================================
1078 // function : highlightSubShapes
1079 // purpose  :
1080 //=================================================================================
1081 void GroupGUI_GroupDlg::highlightSubShapes()
1082 {
1083   if (CORBA::is_nil(myMainObj))
1084     return;
1085
1086   TColStd_MapOfInteger anIds;
1087
1088   myBusy = true;
1089
1090   int ii = 0, nn = myIdList->count();
1091   for (; ii < nn; ii++)
1092   {
1093     if (myIdList->item(ii)->isSelected()) {
1094       int id = myIdList->item(ii)->text().toInt();
1095       if (subSelectionWay() != ALL_SUBSHAPES &&
1096           !myMain2InPlaceIndices.IsBound(id)) {
1097         //myIdList->item(ii)->setSelected(false);
1098       }
1099       else {
1100         anIds.Add(id);
1101       }
1102     }
1103   }
1104   SalomeApp_Application* app = myGeomGUI->getApp();
1105   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1106   aSelMgr->clearSelected();
1107
1108   SUIT_ViewWindow* aViewWindow = 0;
1109   SUIT_Study* activeStudy = app->activeStudy();
1110   if (activeStudy)
1111     aViewWindow = app->desktop()->activeWindow();
1112   if (aViewWindow == 0) return;
1113
1114   SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1115   if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1116       aViewManager->getType() != SVTK_Viewer::Type())
1117     return;
1118
1119   SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1120   SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1121   if (aView == 0) return;
1122
1123   // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
1124
1125   OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
1126   Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1127   AIS_ListOfInteractive List;
1128   //ic->DisplayedObjects(List);
1129   ic->ObjectsInside(List); // Mantis issue 0021367
1130
1131   SALOME_ListIO aSelList;
1132
1133   // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape
1134   GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
1135   QMap<int, QString> childsMap;
1136   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1137   if (appStudy) {
1138     _PTR(Study) aStudy = appStudy->studyDS();
1139     CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1140     QString anEntry = aMainEntry.in();
1141     _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
1142     _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
1143     for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
1144       GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
1145       if (!CORBA::is_nil(aChild)) {
1146         int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
1147         CORBA::String_var aChildEntry = aChild->GetStudyEntry();
1148         QString anEntry = aChildEntry.in();
1149         childsMap.insert(index, anEntry);
1150       }
1151     }
1152   }
1153
1154   AIS_ListIteratorOfListOfInteractive ite (List);
1155   for (; ite.More(); ite.Next()) {
1156     if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1157       Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1158       if (aSh->hasIO()) {
1159         Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
1160         QString anEntry = anIO->getEntry();
1161         int index = anEntry.lastIndexOf("_");
1162         anEntry.remove(0, index+1);
1163         int anIndex = anEntry.toInt();
1164         if (anIds.Contains(anIndex)) {
1165           aSelList.Append(anIO);
1166           if (childsMap.contains (anIndex)) {
1167             Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
1168             aSelList.Append(tmpIO);
1169           }
1170         }
1171       }
1172     }
1173   }
1174   aSelMgr->setSelectedObjects(aSelList);
1175
1176   myBusy = false;
1177
1178   if (nn < 3000)
1179     updateState(aSelList.Extent() > 0);
1180   else {
1181     myAddBtn->setEnabled(true);
1182     myAddBtn->setEnabled(true);
1183     myRemBtn->setEnabled(true);
1184   }
1185 }
1186
1187 //=================================================================================
1188 // function : createOperation
1189 // purpose  :
1190 //=================================================================================
1191 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1192 {
1193   return getGeomEngine()->GetIGroupOperations(getStudyId());
1194 }
1195
1196 #define RETURN_WITH_MSG(a, b) \
1197   if (!(a)) { \
1198     theMessage += (b); \
1199     return false; \
1200   }
1201
1202 //=================================================================================
1203 // function : isValid()
1204 // purpose  : Verify validity of input data
1205 //=================================================================================
1206 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
1207 {
1208   SalomeApp_Study* study = getStudy();
1209   ASSERT(study);
1210   RETURN_WITH_MSG  (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1211
1212   if (myMode == CreateGroup) {
1213     RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1214   }
1215   else {
1216     RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1217   }
1218
1219   QString aName (getNewObjectName());
1220   RETURN_WITH_MSG  (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1221
1222   RETURN_WITH_MSG  (myIdList->count(), tr("EMPTY_LIST"))
1223   return true;
1224 }
1225
1226 //=================================================================================
1227 // function : execute
1228 // purpose  :
1229 //=================================================================================
1230 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1231 {
1232   GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1233
1234   GEOM::GEOM_Object_var aGroup;
1235   if (myMode == CreateGroup)
1236     aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1237   else if (myMode == EditGroup)
1238     aGroup = myGroup;
1239
1240   if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1241     return false;
1242
1243   GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1244   if (!anOper->IsDone())
1245     return false;
1246
1247   if (aCurrList->length() > 0)
1248   {
1249     anOper->DifferenceIDs(aGroup, aCurrList);
1250     if (!anOper->IsDone())
1251       return false;
1252   }
1253
1254   int ii, nn = myIdList->count();
1255   if (nn > 0)
1256   {
1257     GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1258     aNewList->length(nn);
1259     for (ii = 0; ii < nn; ii++) {
1260       aNewList[ii] = myIdList->item(ii)->text().toInt();
1261     }
1262     anOper->UnionIDs(aGroup, aNewList);
1263     if (!anOper->IsDone())
1264       return false;
1265   }
1266
1267   SalomeApp_Study* study = getStudy();
1268   if (study) {
1269     QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1270     if (objIOR != "") {
1271       _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1272       if (SO) {
1273         _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1274         aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1275       }
1276     }
1277   }
1278
1279   objects.push_back(aGroup._retn());
1280
1281   return true;
1282 }
1283
1284 //================================================================
1285 // Function : getFather
1286 // Purpose  : Get father object for object to be added in study
1287 //            (called with addInStudy method)
1288 //================================================================
1289 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1290 {
1291   GEOM::GEOM_Object_var aFatherObj;
1292   if (theObj->GetType() == GEOM_GROUP) {
1293     GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1294     aFatherObj = anOper->GetMainShape(theObj);
1295   }
1296   return aFatherObj._retn();
1297 }