Salome HOME
Update copyrights 2014.
[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             for (; anExp.More(); anExp.Next()) {
791               TopoDS_Shape aSubShape = anExp.Current();
792               int anIndex = aMainMap.FindIndex(aSubShape);
793               if (anIndex == 0) {
794                 SUIT_MessageBox::warning(app->desktop(), QObject::tr("WRN_WARNING"),
795                                          tr("WRN_NOT_SUBSHAPE"));
796               }
797               else {
798                 if (subSelectionWay() != ALL_SUBSHAPES &&
799                     !myMain2InPlaceIndices.IsBound(anIndex))
800                   continue;
801                 theMapIndex.Add(anIndex);
802               }
803             }
804           }
805         }
806       }
807     } // for aSelList
808   }
809
810   return theMapIndex.Extent();
811 }
812
813 //=================================================================================
814 // function : add
815 // purpose  :
816 //=================================================================================
817 void GroupGUI_GroupDlg::add()
818 {
819   TColStd_IndexedMapOfInteger aMapIndex;
820   int nbSel = getSelectedSubshapes(aMapIndex);
821
822   TColStd_MapOfInteger aMap;
823   for (int i = 0, n = myIdList->count(); i < n; i++)
824     aMap.Add(myIdList->item(i)->text().toInt());
825
826   if (nbSel > 0) {
827     bool isBlocked = myIdList->signalsBlocked();
828     myIdList->blockSignals(true);
829
830     for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
831       if (aMap.Contains(aMapIndex(i)))
832         continue;
833
834       QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
835       anItem->setTextColor( myGroupIdList.contains( aMapIndex( i ) ) ? QColor( GROUP_IDLST_COLOR ) : QColor( GROUP_NEWIDLST_COLOR ) );
836       myIdList->addItem(anItem);
837       anItem->setSelected(true);
838     }
839
840     myIdList->blockSignals(isBlocked);
841   }
842
843   updateState();
844 }
845
846 //=================================================================================
847 // function : remove
848 // purpose  :
849 //=================================================================================
850 void GroupGUI_GroupDlg::remove()
851 {
852   bool isBlocked = myIdList->signalsBlocked();
853   myIdList->blockSignals(true);
854
855   QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
856   while (it.hasNext())
857     delete it.next();
858
859   myIdList->blockSignals(isBlocked);
860
861   highlightSubShapes();
862 }
863
864 //=================================================================================
865 //function : subSelectionWay
866 //purpose  :
867 //=================================================================================
868 int GroupGUI_GroupDlg::subSelectionWay() const
869 {
870   return myRestrictGroup->checkedId();
871 }
872
873 //=================================================================================
874 // function : getShapeType()
875 // purpose  :
876 //=================================================================================
877 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
878 {
879   switch (getConstructorId()) {
880   case 0:  return TopAbs_VERTEX;
881   case 1:  return TopAbs_EDGE;
882   case 2:  return TopAbs_FACE;
883   case 3:  return TopAbs_SOLID;
884   default: return TopAbs_SHAPE;
885   }
886 }
887
888 //=================================================================================
889 // function : setShapeType()
890 // purpose  :
891 //=================================================================================
892 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
893 {
894   int anId = 0;
895   switch (theType) {
896   case TopAbs_VERTEX: anId = 0; break;
897   case TopAbs_EDGE:   anId = 1; break;
898   case TopAbs_FACE:   anId = 2; break;
899   case TopAbs_SOLID:  anId = 3; break;
900   }
901   setConstructorId(anId);
902   if (!myIsShapeType)
903   {
904     myIsShapeType = true;
905     // workaround to avoid set checked button 0
906     setConstructorId(anId);
907   }
908 }
909
910 //=================================================================================
911 // function : activateSelection
912 // purpose  : Activate selection in accordance with myEditCurrentArgument
913 //=================================================================================
914 void GroupGUI_GroupDlg::activateSelection()
915 {
916   bool isApply = ((QPushButton*)sender() == buttonApply());
917   if(!isApplyAndClose())
918     erasePreview(false);
919
920   // local selection
921   if (!myMainObj->_is_nil() &&
922       !myEditCurrentArgument &&
923       myIsShapeType) // check if shape type is already choosen by user
924   {
925     GEOM_Displayer* aDisplayer = getDisplayer();
926
927     //display mode for main shape
928     if ( myDmMode == -1 ) {
929     SALOME_View* view = GEOM_Displayer::GetActiveView();
930       if (view) {
931         CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
932         Handle(SALOME_InteractiveObject) io =
933           new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
934         if ( view->isVisible( io ) ) {
935           Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIOinGEOMAISShape( io, true );
936           if(!aSh.IsNull()) {
937             myDmMode = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
938           }
939         }
940         else
941           myDmMode = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "display_mode" );
942       }
943     }
944     aDisplayer->SetDisplayMode(myDmMode);
945
946     // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
947     if(getShapeType() != TopAbs_VERTEX) {
948       aDisplayer->Erase(myMainObj, false, false);
949       myIsHiddenMain = true;
950     }
951     else
952       aDisplayer->Display(myMainObj);
953
954     aDisplayer->Erase(myGroup, false, false);
955
956     QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", "editgroup_color" );
957     Quantity_NameOfColor aCol = SalomeApp_Tools::color( aColor ).Name();
958
959     if(!isApplyAndClose()) {
960       SUIT_ViewWindow* aViewWindow = 0;
961       SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
962       if (activeStudy)
963         aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
964       if (aViewWindow == 0) return;
965
966       SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
967       if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
968           aViewManager->getType() != SVTK_Viewer::Type())
969         return;
970
971       SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
972       SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
973       if (aView == 0) return;
974
975       TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
976       TopoDS_Shape aRestrictionShape;
977
978       if (subSelectionWay() == ALL_SUBSHAPES) {
979         aRestrictionShape = aMainShape;
980
981         TopTools_IndexedMapOfShape aSubShapesMap;
982         TopExp::MapShapes(aMainShape, aSubShapesMap);
983         CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
984         QString anEntryBase = aMainEntry.in();
985
986         TopExp_Explorer anExp (aRestrictionShape, getShapeType());
987         for (; anExp.More(); anExp.Next()) {
988           TopoDS_Shape aSubShape = anExp.Current();
989           int index = aSubShapesMap.FindIndex(aSubShape);
990           QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
991           Handle(SALOME_InteractiveObject) io =
992             new SALOME_InteractiveObject(anEntry.toAscii(), "GEOM", "TEMP_IO");
993           if ( myGroupIdList.contains( index ) ) {
994             aDisplayer->SetColor( aCol );
995           }
996           else {
997             aDisplayer->UnsetColor();
998           }
999           SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
1000           if (aPrs) {
1001             displayPreview(aPrs, true, false); // append, do not update
1002             // TODO: map or delete Prs
1003           }
1004         }
1005       }
1006       else if (!myInPlaceObj->_is_nil()) {
1007         TopTools_IndexedMapOfShape aSubShapesMap;
1008         TopExp::MapShapes(aMainShape, aSubShapesMap);
1009         CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1010         QString anEntryBase = aMainEntry.in();
1011
1012         TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
1013         for (; aM2IPit.More(); aM2IPit.Next()) {
1014           int index = aM2IPit.Key();
1015           TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
1016           QString anEntry = QString( "TEMP_" ) + anEntryBase + QString("_%1").arg(index);
1017
1018           if ( myGroupIdList.contains( index ) ) {
1019             aDisplayer->SetColor( aCol );
1020           }
1021           else {
1022             aDisplayer->UnsetColor();
1023           }
1024
1025           SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
1026           if (aPrs) {
1027             displayPreview(aPrs, true, false); // append, do not update
1028           }
1029         }
1030       }
1031       else ;
1032       aDisplayer->UnsetDisplayMode();
1033       aDisplayer->UnsetColor();
1034       aDisplayer->UpdateViewer();
1035     }
1036   }
1037
1038   globalSelection(GEOM_ALLSHAPES);
1039
1040   SelectionIntoArgument();
1041 }
1042
1043 //=================================================================================
1044 // function : updateState
1045 // purpose  :
1046 //=================================================================================
1047 void GroupGUI_GroupDlg::updateState (bool isAdd)
1048 {
1049   myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
1050   //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
1051
1052   bool hasSel = myIdList->selectedItems().count() > 0;
1053
1054   myRemBtn->setEnabled(hasSel);
1055   myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
1056   mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
1057
1058   mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
1059   myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
1060   if (subSelectionWay() == ALL_SUBSHAPES)
1061     setInPlaceObj(GEOM::GEOM_Object::_nil());
1062 }
1063
1064 //=================================================================================
1065 // function : selectionChanged
1066 // purpose  :
1067 //=================================================================================
1068 void GroupGUI_GroupDlg::selectionChanged()
1069 {
1070   highlightSubShapes();
1071 }
1072
1073 //=================================================================================
1074 // function : highlightSubShapes
1075 // purpose  :
1076 //=================================================================================
1077 void GroupGUI_GroupDlg::highlightSubShapes()
1078 {
1079   if (CORBA::is_nil(myMainObj))
1080     return;
1081
1082   TColStd_MapOfInteger anIds;
1083
1084   myBusy = true;
1085
1086   int ii = 0, nn = myIdList->count();
1087   for (; ii < nn; ii++)
1088   {
1089     if (myIdList->item(ii)->isSelected()) {
1090       int id = myIdList->item(ii)->text().toInt();
1091       if (subSelectionWay() != ALL_SUBSHAPES &&
1092           !myMain2InPlaceIndices.IsBound(id)) {
1093         //myIdList->item(ii)->setSelected(false);
1094       }
1095       else {
1096         anIds.Add(id);
1097       }
1098     }
1099   }
1100   SalomeApp_Application* app = myGeomGUI->getApp();
1101   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1102   aSelMgr->clearSelected();
1103
1104   SUIT_ViewWindow* aViewWindow = 0;
1105   SUIT_Study* activeStudy = app->activeStudy();
1106   if (activeStudy)
1107     aViewWindow = app->desktop()->activeWindow();
1108   if (aViewWindow == 0) return;
1109
1110   SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1111   if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1112       aViewManager->getType() != SVTK_Viewer::Type())
1113     return;
1114
1115   SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1116   SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1117   if (aView == 0) return;
1118
1119   // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
1120
1121   OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
1122   Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1123   AIS_ListOfInteractive List;
1124   //ic->DisplayedObjects(List);
1125   ic->ObjectsInside(List); // Mantis issue 0021367
1126
1127   SALOME_ListIO aSelList;
1128
1129   // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape
1130   GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
1131   QMap<int, QString> childsMap;
1132   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1133   if (appStudy) {
1134     _PTR(Study) aStudy = appStudy->studyDS();
1135     CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1136     QString anEntry = aMainEntry.in();
1137     _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
1138     _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
1139     for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
1140       GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
1141       if (!CORBA::is_nil(aChild)) {
1142         int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
1143         CORBA::String_var aChildEntry = aChild->GetStudyEntry();
1144         QString anEntry = aChildEntry.in();
1145         childsMap.insert(index, anEntry);
1146       }
1147     }
1148   }
1149
1150   AIS_ListIteratorOfListOfInteractive ite (List);
1151   for (; ite.More(); ite.Next()) {
1152     if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1153       Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1154       if (aSh->hasIO()) {
1155         Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
1156         QString anEntry = anIO->getEntry();
1157         int index = anEntry.lastIndexOf("_");
1158         anEntry.remove(0, index+1);
1159         int anIndex = anEntry.toInt();
1160         if (anIds.Contains(anIndex)) {
1161           aSelList.Append(anIO);
1162           if (childsMap.contains (anIndex)) {
1163             Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
1164             aSelList.Append(tmpIO);
1165           }
1166         }
1167       }
1168     }
1169   }
1170   aSelMgr->setSelectedObjects(aSelList);
1171
1172   myBusy = false;
1173
1174   if (nn < 3000)
1175     updateState(aSelList.Extent() > 0);
1176   else {
1177     myAddBtn->setEnabled(true);
1178     myAddBtn->setEnabled(true);
1179     myRemBtn->setEnabled(true);
1180   }
1181 }
1182
1183 //=================================================================================
1184 // function : createOperation
1185 // purpose  :
1186 //=================================================================================
1187 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1188 {
1189   return getGeomEngine()->GetIGroupOperations(getStudyId());
1190 }
1191
1192 #define RETURN_WITH_MSG(a, b) \
1193   if (!(a)) { \
1194     theMessage += (b); \
1195     return false; \
1196   }
1197
1198 //=================================================================================
1199 // function : isValid()
1200 // purpose  : Verify validity of input data
1201 //=================================================================================
1202 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
1203 {
1204   SalomeApp_Study* study = getStudy();
1205   ASSERT(study);
1206   RETURN_WITH_MSG  (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1207
1208   if (myMode == CreateGroup) {
1209     RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1210   }
1211   else {
1212     RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1213   }
1214
1215   QString aName (getNewObjectName());
1216   RETURN_WITH_MSG  (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1217
1218   RETURN_WITH_MSG  (myIdList->count(), tr("EMPTY_LIST"))
1219   return true;
1220 }
1221
1222 //=================================================================================
1223 // function : execute
1224 // purpose  :
1225 //=================================================================================
1226 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1227 {
1228   GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1229
1230   GEOM::GEOM_Object_var aGroup;
1231   if (myMode == CreateGroup)
1232     aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1233   else if (myMode == EditGroup)
1234     aGroup = myGroup;
1235
1236   if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1237     return false;
1238
1239   GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1240   if (!anOper->IsDone())
1241     return false;
1242
1243   if (aCurrList->length() > 0)
1244   {
1245     anOper->DifferenceIDs(aGroup, aCurrList);
1246     if (!anOper->IsDone())
1247       return false;
1248   }
1249
1250   int ii, nn = myIdList->count();
1251   if (nn > 0)
1252   {
1253     GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1254     aNewList->length(nn);
1255     for (ii = 0; ii < nn; ii++) {
1256       aNewList[ii] = myIdList->item(ii)->text().toInt();
1257     }
1258     anOper->UnionIDs(aGroup, aNewList);
1259     if (!anOper->IsDone())
1260       return false;
1261   }
1262
1263   SalomeApp_Study* study = getStudy();
1264   if (study) {
1265     QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1266     if (objIOR != "") {
1267       _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1268       if (SO) {
1269         _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1270         aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1271       }
1272     }
1273   }
1274
1275   objects.push_back(aGroup._retn());
1276
1277   return true;
1278 }
1279
1280 //================================================================
1281 // Function : getFather
1282 // Purpose  : Get father object for object to be added in study
1283 //            (called with addInStudy method)
1284 //================================================================
1285 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1286 {
1287   GEOM::GEOM_Object_var aFatherObj;
1288   if (theObj->GetType() == GEOM_GROUP) {
1289     GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1290     aFatherObj = anOper->GetMainShape(theObj);
1291   }
1292   return aFatherObj._retn();
1293 }