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