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