Salome HOME
A new event Visual Attributes Changed is defined for performance sake.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetMultiSelector.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <ModuleBase_WidgetMultiSelector.h>
21
22 #include <GeomAPI_AISObject.h>
23
24 #include <ModuleBase_ActionIntParameter.h>
25 #include <ModuleBase_Definitions.h>
26 #include <ModuleBase_Events.h>
27 #include <ModuleBase_IconFactory.h>
28 #include <ModuleBase_IModule.h>
29 #include <ModuleBase_ISelection.h>
30 #include <ModuleBase_ISelectionActivate.h>
31 #include <ModuleBase_IPropertyPanel.h>
32 #include <ModuleBase_IViewer.h>
33 #include <ModuleBase_IWorkshop.h>
34 #include <ModuleBase_ListView.h>
35 #include <ModuleBase_ResultPrs.h>
36 #include <ModuleBase_Tools.h>
37 #include <ModuleBase_ViewerPrs.h>
38 #include <ModuleBase_WidgetShapeSelector.h>
39 #include <ModuleBase_ChoiceCtrl.h>
40 #include <ModuleBase_WidgetSelectionFilter.h>
41
42 #include <ModelAPI_Data.h>
43 #include <ModelAPI_Object.h>
44 #include <ModelAPI_AttributeSelectionList.h>
45 #include <ModelAPI_AttributeRefList.h>
46 #include <ModelAPI_AttributeRefAttrList.h>
47 #include <ModelAPI_Tools.h>
48 #include <ModelAPI_Events.h>
49
50 #include <Config_WidgetAPI.h>
51
52 #include <AIS_InteractiveObject.hxx>
53
54 #include <QGridLayout>
55 #include <QLabel>
56 #include <QListWidget>
57 #include <QObject>
58 #include <QString>
59 #include <QComboBox>
60 #include <QEvent>
61 #include <QApplication>
62 #include <QClipboard>
63 #include <QTimer>
64 #include <QMainWindow>
65 #include <QCheckBox>
66 #include <QPushButton>
67
68 #include <memory>
69 #include <string>
70
71 //#define DEBUG_UNDO_REDO
72
73 #ifdef DEBUG_UNDO_REDO
74 void printHistoryInfo(const QString& theMethodName, int theCurrentHistoryIndex,
75   QList<QList<std::shared_ptr<ModuleBase_ViewerPrs> > > theSelectedHistoryValues)
76 {
77   QStringList aSizes;
78   for (int i = 0; i < theSelectedHistoryValues.size(); i++)
79     aSizes.append(QString::number(theSelectedHistoryValues[i].size()));
80
81   std::cout << theMethodName.toStdString()
82             << "  current = " << theCurrentHistoryIndex
83             << " size(history) =  " << theSelectedHistoryValues.size()
84             << " (" << aSizes.join(", ").toStdString() << ")"
85             << std::endl;
86 }
87 #endif
88
89
90 QStringList getIconsList(const QStringList& theNames)
91 {
92   QStringList aIcons;
93   foreach (QString aName, theNames) {
94     QString aUName = aName.toUpper();
95     if ((aUName == "VERTICES") || (aUName == "VERTEX"))
96       aIcons << ":pictures/vertex32.png";
97     else if ((aUName == "EDGES") || (aUName == "EDGE"))
98       aIcons << ":pictures/edge32.png";
99     else if ((aUName == "FACES") || (aUName == "FACE"))
100       aIcons << ":pictures/face32.png";
101     else if ((aUName == "SOLIDS") || (aUName == "SOLID"))
102       aIcons << ":pictures/solid32.png";
103   }
104   return aIcons;
105 }
106
107 /// Stores default values of selected option (selection mode)
108 /// It is used only in case if myTypeCtrl is used
109 static QMap<std::string, std::string> defaultValues;
110
111
112 ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
113                                                                ModuleBase_IWorkshop* theWorkshop,
114                                                                const Config_WidgetAPI* theData)
115 : ModuleBase_WidgetSelector(theParent, theWorkshop, theData),
116   myIsSetSelectionBlocked(false), myCurrentHistoryIndex(-1),
117   myIsFirst(true), myFiltersWgt(0)
118 {
119   std::string aPropertyTypes = theData->getProperty("shape_types");
120   QString aTypesStr = aPropertyTypes.c_str();
121   myShapeTypes = aTypesStr.split(' ', QString::SkipEmptyParts);
122   myIsUseChoice = theData->getBooleanAttribute("use_choice", false);
123
124   QString aAllowedList(theData->getProperty("allow_objects").c_str());
125   if (!aAllowedList.isEmpty())
126     myAllowedObjects = aAllowedList.split(' ', QString::SkipEmptyParts);
127
128   QVBoxLayout* aMainLay = new QVBoxLayout(this);
129   ModuleBase_Tools::adjustMargins(aMainLay);
130
131   QStringList aIconsList = getIconsList(myShapeTypes);
132   myTypeCtrl = new ModuleBase_ChoiceCtrl(this, myShapeTypes, aIconsList);
133   myTypeCtrl->setLabel(tr("Type"));
134   if (!myShapeTypes.empty()) {
135     myTypeCtrl->setValue(0);
136     myDefMode = myShapeTypes.first().toStdString();
137   }
138   aMainLay->addWidget(myTypeCtrl);
139
140   // There is no sense to parameterize list of types while we can not parameterize selection mode
141   // if the xml definition contains one type, the controls to select a type should not be shown
142   if (myShapeTypes.size() <= 1 || !myIsUseChoice) {
143     myTypeCtrl->setVisible(false);
144   }
145
146   QString aLabelText = translate(theData->getProperty("label"));
147   if (aLabelText.size() > 0) {
148     QWidget* aLabelWgt = new QWidget(this);
149     QHBoxLayout* aLabelLayout = new QHBoxLayout(aLabelWgt);
150     aLabelLayout->setContentsMargins(0, 0, 0, 0);
151     aMainLay->addWidget(aLabelWgt);
152
153     QLabel* aListLabel = new QLabel(aLabelText, this);
154     aLabelLayout->addWidget(aListLabel);
155     // if the xml definition contains one type, an information label
156     // should be shown near to the latest
157     if (myShapeTypes.size() <= 1) {
158       QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
159       if (!aLabelIcon.isEmpty()) {
160         QLabel* aSelectedLabel = new QLabel("", this);
161         aSelectedLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
162         aLabelLayout->addWidget(aSelectedLabel);
163         aLabelLayout->addStretch(1);
164       }
165     }
166   }
167
168   QString aToolTip = translate(theData->widgetTooltip());
169   QString anObjName = QString::fromStdString(attributeID());
170   myListView = new ModuleBase_ListView(this, anObjName, aToolTip);
171   connect(myListView->getControl(), SIGNAL(itemSelectionChanged()), SLOT(onListSelection()));
172   connect(myListView, SIGNAL(deleteActionClicked()), SLOT(onDeleteItem()));
173   connect(myListView, SIGNAL(listActivated()), SLOT(onListActivated()));
174
175   aMainLay->addWidget(myListView->getControl());
176   connect(myTypeCtrl, SIGNAL(valueChanged(int)), this, SLOT(onSelectionTypeChanged()));
177
178   std::string aUseFilters = theData->getProperty("use_filters");
179   if (aUseFilters.length() > 0) {
180     QWidget* aFltrWgt = new QWidget(this);
181     QHBoxLayout* aFltrLayout = new QHBoxLayout(aFltrWgt);
182
183     myFiltersWgt = new ModuleBase_FilterStarter(aUseFilters.c_str(), aFltrWgt, theWorkshop);
184     aFltrLayout->addWidget(myFiltersWgt);
185
186     aFltrLayout->addStretch();
187
188     QPushButton* aShowBtn = new QPushButton(tr("Show only"), aFltrWgt);
189     aShowBtn->setCheckable(true);
190     aShowBtn->setChecked(false);
191     connect(aShowBtn, SIGNAL(toggled(bool)), SLOT(onShowOnly(bool)));
192     aFltrLayout->addWidget(aShowBtn);
193
194     aMainLay->addWidget(aFltrWgt);
195   }
196
197   bool aSameTop = theData->getBooleanAttribute("same_topology", false);
198   if (aSameTop) {
199     myGeomCheck = new QCheckBox(tr("Add elements that share the same topology"), this);
200     aMainLay->addWidget(myGeomCheck);
201     connect(myGeomCheck, SIGNAL(toggled(bool)), SLOT(onSameTopology(bool)));
202   }
203   else
204     myGeomCheck = 0;
205
206   myIsNeutralPointClear = theData->getBooleanAttribute("clear_in_neutral_point", true);
207   if (myShapeTypes.size() > 1 || myIsUseChoice) {
208     if (defaultValues.contains(myFeatureId + attributeID())) {
209       myDefMode = defaultValues[myFeatureId + attributeID()];
210       myTypeCtrl->setValue(myDefMode.c_str());
211     }
212   }
213 }
214
215 ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector()
216 {
217 }
218
219 //********************************************************************
220 void ModuleBase_WidgetMultiSelector::activateCustom()
221 {
222   ModuleBase_WidgetSelector::activateCustom();
223
224   ModuleBase_IModule* aModule = myWorkshop->module();
225   aModule->activateCustomPrs(myFeature,
226                             ModuleBase_IModule::CustomizeHighlightedObjects, true);
227   clearSelectedHistory();
228   if (myAllowedObjects.length() > 0) {
229     Handle(SelectMgr_Filter) aFilter = aModule->selectionFilter(SF_GlobalFilter);
230     if (!aFilter.IsNull()) {
231       Handle(ModuleBase_ShapeDocumentFilter) aDocFilter =
232         Handle(ModuleBase_ShapeDocumentFilter)::DownCast(aFilter);
233       if (!aDocFilter.IsNull()) {
234         QStringList aSelFilters = aDocFilter->nonSelectableTypes();
235         foreach(QString aType, aSelFilters) {
236           if (aSelFilters.contains(aType)) {
237             aDocFilter->removeNonSelectableType(aType);
238             myTmpAllowed.append(aType);
239           }
240         }
241       }
242     }
243   }
244 }
245
246 //********************************************************************
247 void ModuleBase_WidgetMultiSelector::deactivate()
248 {
249   myWorkshop->module()->enableCustomModes();
250
251   ModuleBase_WidgetSelector::deactivate();
252   if (myVisibleObjects.size())
253     onShowOnly(false);
254
255   myWorkshop->module()->deactivateCustomPrs(ModuleBase_IModule::CustomizeHighlightedObjects, true);
256   clearSelectedHistory();
257   if (myTmpAllowed.length() > 0) {
258     ModuleBase_IModule* aModule = myWorkshop->module();
259     Handle(SelectMgr_Filter) aFilter = aModule->selectionFilter(SF_GlobalFilter);
260     if (!aFilter.IsNull()) {
261       Handle(ModuleBase_ShapeDocumentFilter) aDocFilter =
262         Handle(ModuleBase_ShapeDocumentFilter)::DownCast(aFilter);
263       if (!aDocFilter.IsNull()) {
264         foreach(QString aType, myTmpAllowed) {
265           aDocFilter->addNonSelectableType(aType);
266         }
267       }
268     }
269     myTmpAllowed.clear();
270   }
271 }
272
273 //********************************************************************
274 void ModuleBase_WidgetMultiSelector::updateAfterDeactivation()
275 {
276   // restore previous Undo/Redo workshop state
277   myWorkshop->updateCommandStatus();
278 }
279
280 //********************************************************************
281 void ModuleBase_WidgetMultiSelector::updateAfterActivation()
282 {
283   // fill Undo/Redo actions with current information
284   myWorkshop->updateCommandStatus();
285 }
286
287 //********************************************************************
288 bool ModuleBase_WidgetMultiSelector::storeValueCustom()
289 {
290   // the value is stored on the selection changed signal processing
291   // A rare case when plugin was not loaded.
292   if (!myFeature)
293     return false;
294
295   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
296   std::string aType = anAttribute->attributeType();
297   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
298     AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
299     if (myTypeCtrl->isVisible()) {
300       std::string aMode = myTypeCtrl->textValue().toStdString();
301       if (myIsFirst && (!myDefMode.empty()))
302         aMode = myDefMode;
303
304       aSelectionListAttr->setSelectionType(aMode);
305       myIsFirst = false;
306     } else { // no type, set the type as a first element of the list shape type when it is appeared
307       if (aSelectionListAttr->size()) {
308         AttributeSelectionPtr aSel = aSelectionListAttr->value(0);
309         GeomShapePtr aFirstVal = aSel->value();
310         if (!aFirstVal.get() && aSel->context().get())
311           aFirstVal = aSel->context()->shape();
312         if (aFirstVal.get() && !aFirstVal->isNull())
313           aSelectionListAttr->setSelectionType(aFirstVal->shapeTypeStr());
314       }
315     }
316   }
317   return true;
318 }
319
320 //********************************************************************
321 bool ModuleBase_WidgetMultiSelector::restoreValueCustom()
322 {
323   // A rare case when plugin was not loaded.
324   if (!myFeature)
325     return false;
326
327   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
328   AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
329   std::string aType = anAttribute->attributeType();
330   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
331     // Restore shape type
332     std::string aSelectionType = aSelectionListAttr->selectionType().c_str();
333     if (!aSelectionType.empty()) {
334       setCurrentShapeType(ModuleBase_Tools::shapeType(aSelectionType.c_str()));
335       myDefMode = aSelectionType;
336       myIsFirst = false;
337     }
338   }
339   if (myGeomCheck)
340     myGeomCheck->setChecked(aSelectionListAttr->isGeometricalSelection());
341   updateSelectionList();
342   return true;
343 }
344
345 //********************************************************************
346 bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
347                                                   const bool theToValidate)
348 {
349   if (myIsSetSelectionBlocked)
350     return false;
351
352   AttributeSelectionListPtr aSelectionListAttr;
353   if (attribute()->attributeType() == ModelAPI_AttributeSelectionList::typeId())
354     aSelectionListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(attribute());
355   if (aSelectionListAttr.get())
356     aSelectionListAttr->cashValues(true);
357
358   /// remove unused objects from the model attribute.
359   /// It should be performed before new attributes append.
360   bool isDone = removeUnusedAttributeObjects(theValues);
361
362   QList<ModuleBase_ViewerPrsPtr> anInvalidValues;
363   QList<ModuleBase_ViewerPrsPtr> anAttributeValues;
364   QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
365   for (; anIt != aLast; anIt++) {
366     ModuleBase_ViewerPrsPtr aValue = *anIt;
367     // do not validate and append to attribute selection presentation if it exists in the attribute
368     ObjectPtr anObject;
369     GeomShapePtr aShape;
370     getGeomSelection(aValue, anObject, aShape);
371     if (ModuleBase_Tools::hasObject(attribute(), anObject, aShape, myWorkshop, myIsInValidate)) {
372       anAttributeValues.append(aValue);
373       continue;
374     }
375     if (theToValidate && !isValidInFilters(aValue))
376       anInvalidValues.append(aValue);
377   }
378   bool aHasInvalidValues = anInvalidValues.size() > 0;
379
380   for (anIt = theValues.begin(); anIt != aLast; anIt++) {
381     ModuleBase_ViewerPrsPtr aValue = *anIt;
382     bool aProcessed = false;
383     if ((aHasInvalidValues && anInvalidValues.contains(aValue)) ||
384         anAttributeValues.contains(aValue))
385       continue;
386     aProcessed = setSelectionCustom(aValue); /// it is not optimal as hasObject() is already checked
387     // if there is at least one set, the result is true
388     isDone = isDone || aProcessed;
389   }
390   // Check the selection with validators
391   QString aError = getError();
392   if (aError.length() > 0) {
393     aSelectionListAttr->clear();
394     isDone = false;
395   }
396   // updateObject - to update/redisplay feature
397   // it is commented in order to perfom it outside the method
398   //if (isDone) {
399     //updateObject(myFeature);
400     // this emit is necessary to call store/restore method an restore type of selection
401     //emit valuesChanged();
402   //}
403
404   if (aSelectionListAttr.get())
405     aSelectionListAttr->cashValues(false);
406
407   theValues.clear();
408   if (!anInvalidValues.empty())
409     theValues.append(anInvalidValues);
410
411   if (isDone) // may be the feature's result is not displayed, but attributes should be
412     myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeArguments,
413                              true);/// hope that something is redisplayed by object updated
414
415   return isDone;
416 }
417
418 //********************************************************************
419 void ModuleBase_WidgetMultiSelector::getHighlighted(QList<ModuleBase_ViewerPrsPtr>& theValues)
420 {
421   std::set<int> anAttributeIds;
422   getSelectedAttributeIndices(anAttributeIds);
423   if (!anAttributeIds.empty())
424     convertIndicesToViewerSelection(anAttributeIds, theValues);
425 }
426
427 //********************************************************************
428 bool ModuleBase_WidgetMultiSelector::canProcessAction(ModuleBase_ActionType theActionType,
429                                                       bool& isActionEnabled)
430 {
431   isActionEnabled = false;
432   bool aCanProcess = false;
433   switch (theActionType) {
434     case ActionUndo:
435     case ActionRedo: {
436       aCanProcess = true;
437       isActionEnabled = theActionType == ActionUndo ? myCurrentHistoryIndex > 0
438           : (mySelectedHistoryValues.size() > 0 &&
439              myCurrentHistoryIndex < mySelectedHistoryValues.size() - 1);
440     }
441     break;
442     default:
443       aCanProcess = ModuleBase_WidgetSelector::canProcessAction(theActionType, isActionEnabled);
444     break;
445   }
446   return aCanProcess;
447 }
448
449 //********************************************************************
450 bool ModuleBase_WidgetMultiSelector::processAction(ModuleBase_ActionType theActionType,
451                                                    const ActionParamPtr& theParam)
452 {
453   switch (theActionType) {
454     case ActionUndo:
455     case ActionRedo: {
456       ActionIntParamPtr aParam =
457         std::dynamic_pointer_cast<ModuleBase_ActionIntParameter>(theParam);
458       int aNb = aParam->value();
459       if (theActionType == ActionUndo)
460         myCurrentHistoryIndex -= aNb;
461       else
462         myCurrentHistoryIndex += aNb;
463       QList<ModuleBase_ViewerPrsPtr> aSelected = mySelectedHistoryValues[myCurrentHistoryIndex];
464       // equal vertices should not be used here
465       ModuleBase_ISelection::filterSelectionOnEqualPoints(aSelected);
466       bool isDone = setSelection(aSelected,
467                                  false /*need not validate because values already was in list*/);
468       updateOnSelectionChanged(isDone);
469
470       myWorkshop->updateCommandStatus();
471 #ifdef DEBUG_UNDO_REDO
472       printHistoryInfo(QString("processAction %1").arg(theActionType == ActionUndo ? "Undo"
473         : "Redo"), myCurrentHistoryIndex, mySelectedHistoryValues);
474 #endif
475       return true;
476     }
477     default:
478       return ModuleBase_ModelWidget::processAction(theActionType, theParam);
479   }
480 }
481
482 //********************************************************************
483 bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
484 {
485   bool aValid = ModuleBase_WidgetSelector::isValidSelectionCustom(thePrs);
486   if (aValid) {
487     ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
488     if (!aResult.get()) { // In case if a feature was selected
489       FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(thePrs->object());
490       if (aFeature.get())
491         aResult = aFeature->firstResult();
492     }
493     aValid = aResult.get() != NULL;
494     if (aValid) {
495       if (myFeature) {
496         // We can not select a result of our feature
497         std::list<ResultPtr> aResults;
498         ModelAPI_Tools::allResults(myFeature, aResults);
499         std::list<ResultPtr>::const_iterator aIt;
500         bool isSkipSelf = false;
501         for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
502           if ((*aIt) == aResult) {
503             isSkipSelf = true;
504             break;
505           }
506         }
507         if (isSkipSelf)
508           aValid = false;
509       }
510     }
511   }
512   return aValid;
513 }
514
515 //********************************************************************
516 bool ModuleBase_WidgetMultiSelector::processDelete()
517 {
518   appendFirstSelectionInHistory();
519
520   // find attribute indices to delete
521   std::set<int> anAttributeIds;
522   getSelectedAttributeIndices(anAttributeIds);
523
524   QModelIndexList anIndices = myListView->getControl()->selectionModel()->selectedIndexes();
525
526   // refill attribute by the items which indices are not in the list of ids
527   bool aDone = false;
528   DataPtr aData = myFeature->data();
529   AttributePtr anAttribute = aData->attribute(attributeID());
530   std::string aType = anAttribute->attributeType();
531   aDone = !anAttributeIds.empty();
532   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
533     AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
534     aSelectionListAttr->remove(anAttributeIds);
535
536   }
537   else if (aType == ModelAPI_AttributeRefList::typeId()) {
538     AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
539     aRefListAttr->remove(anAttributeIds);
540   }
541   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
542     AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
543     aRefAttrListAttr->remove(anAttributeIds);
544   }
545
546   if (aDone) {
547     // update object is necessary to flush update signal. It leads to objects references map update
548     // and the operation presentation will not contain deleted items visualized as parameters of
549     // the feature.
550     updateObject(myFeature);
551
552     restoreValue();
553     myWorkshop->setSelected(getAttributeSelection());
554
555     // may be the feature's result is not displayed, but attributes should be
556     myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeArguments,
557                               true); /// hope that something is redisplayed by object updated
558   }
559
560   // Restore selection
561   myListView->restoreSelection(anIndices);
562
563   appendSelectionInHistory();
564   return true/*aDone*/; // following #2438 Delete should be processed even if nothing is delete
565 }
566
567 //********************************************************************
568 QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
569 {
570   QList<QWidget*> result;
571   result << myListView->getControl();
572   return result;
573 }
574
575 //********************************************************************
576 void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
577 {
578   // Clear current selection in order to avoid updating of object browser with obsolete indexes
579   // which can appear because of results deletetion after changing a type of selection
580   QString aSelectionType = myTypeCtrl->textValue();
581   QList<ModuleBase_ViewerPrsPtr> aEmptyList;
582   myWorkshop->setSelected(aEmptyList);
583
584   updateSelectionModesAndFilters(true);
585   myWorkshop->selectionActivate()->updateSelectionModes();
586
587   if (!myFeature)
588     return;
589   /// store the selected type
590   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
591   std::string aType = anAttribute->attributeType();
592   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
593     AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
594     aSelectionListAttr->setSelectionType(aSelectionType.toStdString());
595   }
596
597   // clear attribute values
598   DataPtr aData = myFeature->data();
599   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
600     AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
601     aSelectionListAttr->clear();
602   }
603   else if (aType == ModelAPI_AttributeRefList::typeId()) {
604     AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
605     aRefListAttr->clear();
606   }
607   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
608     AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
609     aRefAttrListAttr->clear();
610   }
611
612   // update object is necessary to flush update signal. It leads to objects references map update
613   // and the operation presentation will not contain deleted items visualized as parameters of
614   // the feature.
615   updateObject(myFeature);
616   restoreValue();
617   myWorkshop->setSelected(getAttributeSelection());
618   // may be the feature's result is not displayed, but attributes should be
619   myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeArguments,
620                             true); /// hope that something is redisplayed by object updated
621   // clear history should follow after set selected to do not increase history by setSelected
622   clearSelectedHistory();
623
624   if (myWorkshop->propertyPanel()->activeWidget() != this)
625     myWorkshop->propertyPanel()->activateWidget(this);
626 }
627
628 //********************************************************************
629 bool ModuleBase_WidgetMultiSelector::processSelection()
630 {
631   if (!myIsNeutralPointClear) {
632     QList<ModuleBase_ViewerPrsPtr> aSelected = getFilteredSelected();
633     // do not clear selected object
634     if (aSelected.size() == 0) {
635       if (!getAttributeSelection().empty()) {
636         // Restore selection in the viewer by the attribute selection list
637         // it should be postponed to exit from the selectionChanged processing
638         static Events_ID anEvent = Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION);
639         ModelAPI_EventCreator::get()->sendUpdated(myFeature, anEvent);
640         Events_Loop::loop()->flush(anEvent);
641         return true;
642       }
643     }
644   }
645   appendFirstSelectionInHistory();
646   bool aDone = ModuleBase_WidgetSelector::processSelection();
647   appendSelectionInHistory();
648   return aDone;
649 }
650
651 void ModuleBase_WidgetMultiSelector::appendFirstSelectionInHistory()
652 {
653   if (mySelectedHistoryValues.empty()) {
654     myCurrentHistoryIndex++;
655     mySelectedHistoryValues.append(getAttributeSelection());
656
657 #ifdef DEBUG_UNDO_REDO
658     printHistoryInfo("appendSelectionInHistory", myCurrentHistoryIndex, mySelectedHistoryValues);
659 #endif
660   }
661 }
662
663 void ModuleBase_WidgetMultiSelector::appendSelectionInHistory()
664 {
665   while (myCurrentHistoryIndex != mySelectedHistoryValues.count() - 1)
666     mySelectedHistoryValues.removeLast();
667
668   QList<ModuleBase_ViewerPrsPtr> aSelected = getFilteredSelected();
669   myCurrentHistoryIndex++;
670   mySelectedHistoryValues.append(aSelected);
671   myWorkshop->updateCommandStatus();
672
673 #ifdef DEBUG_UNDO_REDO
674   printHistoryInfo("appendSelectionInHistory", myCurrentHistoryIndex, mySelectedHistoryValues);
675 #endif
676 }
677
678 void ModuleBase_WidgetMultiSelector::clearSelectedHistory()
679 {
680   mySelectedHistoryValues.clear();
681   myCurrentHistoryIndex = -1;
682   myWorkshop->updateCommandStatus();
683
684 #ifdef DEBUG_UNDO_REDO
685   printHistoryInfo("clearSelectedHistory", myCurrentHistoryIndex, mySelectedHistoryValues);
686 #endif
687 }
688
689 void ModuleBase_WidgetMultiSelector::updateFocus()
690 {
691   // Set focus to List control in order to make possible
692   // to use Tab key for transfer the focus to next widgets
693   ModuleBase_Tools::setFocus(myListView->getControl(),
694                              "ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()");
695 }
696
697 //********************************************************************
698 void ModuleBase_WidgetMultiSelector::updateSelectionName()
699 {
700 }
701
702 //********************************************************************
703 void ModuleBase_WidgetMultiSelector::updateOnSelectionChanged(const bool theDone)
704 {
705   if (myIsSetSelectionBlocked)
706     return;
707   ModuleBase_WidgetSelector::updateOnSelectionChanged(theDone);
708
709   // according to #2154 we need to update OB selection when selection in the viewer happens
710   // it is important to flush sinchronize selection signal after flush of Update/Create/Delete.
711   // because we need that Object Browser has been already updated when synchronize happens.
712
713   // Restore selection in the viewer by the attribute selection list
714   // it is possible that diring selection attribute filling, selection in Object Browser
715   // is changed(some items were removed/added) and as result, selection in the viewer
716   // differs from the selection come to this method. By next rows, we restore selection
717   // in the viewer according to content of selection attribute. Case is Edge selection in Group
718   myIsSetSelectionBlocked = true;
719   static Events_ID anEvent = Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION);
720   ModelAPI_EventCreator::get()->sendUpdated(myFeature, anEvent);
721   Events_Loop::loop()->flush(anEvent);
722   myIsSetSelectionBlocked = false;
723 }
724
725 //********************************************************************
726 QIntList ModuleBase_WidgetMultiSelector::shapeTypes() const
727 {
728   QIntList aShapeTypes;
729
730   if (myShapeTypes.length() > 1 && myIsUseChoice) {
731     aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCtrl->textValue()));
732   }
733   else {
734     foreach (QString aType, myShapeTypes) {
735       aShapeTypes.append(ModuleBase_Tools::shapeType(aType));
736     }
737   }
738   return aShapeTypes;
739 }
740
741 //********************************************************************
742 void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const int theShapeType)
743 {
744   QString aShapeTypeName;
745
746   int idx = 0;
747   foreach (QString aShapeTypeName, myShapeTypes) {
748     int aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
749     if(aRefType == theShapeType && idx != myTypeCtrl->value()) {
750       updateSelectionModesAndFilters(false);
751       bool isBlocked = myTypeCtrl->blockSignals(true);
752       myTypeCtrl->setValue(idx);
753       myTypeCtrl->blockSignals(isBlocked);
754       updateSelectionModesAndFilters(true);
755       break;
756     }
757     idx++;
758   }
759 }
760
761 QList<ModuleBase_ViewerPrsPtr> ModuleBase_WidgetMultiSelector::getAttributeSelection() const
762 {
763   QList<ModuleBase_ViewerPrsPtr> aSelected;
764   convertIndicesToViewerSelection(std::set<int>(), aSelected);
765   return aSelected;
766 }
767
768 //********************************************************************
769 void ModuleBase_WidgetMultiSelector::updateSelectionList()
770 {
771   myListView->getControl()->clear();
772
773   DataPtr aData = myFeature->data();
774   AttributePtr anAttribute = aData->attribute(attributeID());
775   std::string aType = anAttribute->attributeType();
776   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
777     AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
778     for (int i = 0; i < aSelectionListAttr->size(); i++) {
779       AttributeSelectionPtr aAttr = aSelectionListAttr->value(i);
780       myListView->addItem(aAttr->namingName().c_str(), i);
781     }
782   }
783   else if (aType == ModelAPI_AttributeRefList::typeId()) {
784     AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
785     for (int i = 0; i < aRefListAttr->size(); i++) {
786       ObjectPtr anObject = aRefListAttr->object(i);
787       if (anObject.get()) {
788         myListView->addItem(anObject->data()->name().c_str(), i);
789       }
790     }
791   }
792   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
793     AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
794     for (int i = 0; i < aRefAttrListAttr->size(); i++) {
795       AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
796       QString aName;
797       if (anAttribute.get()) {
798         std::string anAttrName = ModuleBase_Tools::generateName(anAttribute, myWorkshop);
799         aName = QString::fromStdString(anAttrName);
800       }
801       else {
802         ObjectPtr anObject = aRefAttrListAttr->object(i);
803         if (anObject.get()) {
804           aName = anObject->data()->name().c_str();
805         }
806       }
807       myListView->addItem(aName, i);
808     }
809   }
810
811   // We have to call repaint because sometimes the List control is not updated
812   myListView->getControl()->update();
813 }
814
815 //********************************************************************
816 std::string ModuleBase_WidgetMultiSelector::validatorType(const QString& theType) const
817 {
818   std::string aType;
819
820   if (theType == "Vertices")
821     aType = "vertex";
822   else if (theType == "Edges")
823     aType = "edge";
824   else if (theType == "Faces")
825     aType = "face";
826   else if (theType == "Solids")
827     aType = "solid";
828
829   return aType;
830 }
831
832 //********************************************************************
833 void ModuleBase_WidgetMultiSelector::clearSelection()
834 {
835   bool isClearInNeutralPoint = myIsNeutralPointClear;
836   myIsNeutralPointClear = true;
837
838   QList<ModuleBase_ViewerPrsPtr> anEmptyList;
839   // This method will call Selection changed event which will call onSelectionChanged
840   // To clear mySelection, myListView and storeValue()
841   // So, we don't need to call it
842   myWorkshop->setSelected(anEmptyList);
843
844   myIsNeutralPointClear = isClearInNeutralPoint;
845 }
846
847 //********************************************************************
848 void ModuleBase_WidgetMultiSelector::onDeleteItem()
849 {
850   processDelete();
851 }
852
853 //********************************************************************
854 void ModuleBase_WidgetMultiSelector::onListSelection()
855 {
856   myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects,
857                                          true);
858 }
859
860 //********************************************************************
861 void ModuleBase_WidgetMultiSelector::getSelectedAttributeIndices(std::set<int>& theAttributeIds)
862 {
863   myListView->getSelectedIndices(theAttributeIds);
864 }
865
866 void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<int> theAttributeIds,
867                                                    QList<ModuleBase_ViewerPrsPtr>& theValues) const
868 {
869   if(myFeature.get() == NULL)
870     return;
871
872   DataPtr aData = myFeature->data();
873   AttributePtr anAttribute = aData->attribute(attributeID());
874   std::string aType = anAttribute->attributeType();
875   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
876     AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
877     for (int i = 0; i < aSelectionListAttr->size(); i++) {
878       // filter by attribute indices only if the container is not empty otherwise return all items
879       if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
880         continue;
881       AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
882       ObjectPtr anObject = anAttr->contextObject();
883       if (anObject.get())
884         theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
885                new ModuleBase_ViewerPrs(anObject, anAttr->value(), NULL)));
886     }
887   }
888   else if (aType == ModelAPI_AttributeRefList::typeId()) {
889     AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
890     for (int i = 0; i < aRefListAttr->size(); i++) {
891       // filter by attribute indices only if the container is not empty otherwise return all items
892       if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
893         continue;
894       ObjectPtr anObject = aRefListAttr->object(i);
895       if (anObject.get()) {
896         theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
897                new ModuleBase_ViewerPrs(anObject, GeomShapePtr(), NULL)));
898       }
899     }
900   }
901   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
902     AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
903     for (int i = 0; i < aRefAttrListAttr->size(); i++) {
904       // filter by attribute indices only if the container is not empty otherwise return all items
905       if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
906         continue;
907       ObjectPtr anObject = aRefAttrListAttr->object(i);
908       if (!anObject.get())
909         continue;
910       TopoDS_Shape aShape;
911       AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
912       if (anAttribute.get()) {
913         GeomShapePtr aGeomShape = ModuleBase_Tools::getShape(anAttribute, myWorkshop);
914         theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
915                new ModuleBase_ViewerPrs(anObject, aGeomShape, NULL)));
916       }
917     }
918   }
919 }
920
921 bool ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
922                                                  (QList<ModuleBase_ViewerPrsPtr>& theValues)
923 {
924   bool isDone = false;
925
926   std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection = convertSelection(theValues);
927   DataPtr aData = myFeature->data();
928   AttributePtr anAttribute = aData->attribute(attributeID());
929   std::string aType = anAttribute->attributeType();
930   std::set<GeomShapePtr> aShapes;
931   std::set<int> anIndicesToBeRemoved;
932   FeaturePtr aFeature;
933   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
934     // iteration through data model to find not selected elements to remove them
935     AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
936     for (int i = 0; i < aSelectionListAttr->size(); i++) {
937       AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
938       //aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->contextObject());
939       //if (!aFeature.get()) { // Feature can not be found as geometry selection
940         bool aFound = findInSelection(
941           anAttr->contextObject(), anAttr->value(), aGeomSelection, myWorkshop);
942         if (!aFound)
943           anIndicesToBeRemoved.insert(i);
944 //      }
945     }
946     isDone = anIndicesToBeRemoved.size() > 0;
947     if (isDone)
948       aSelectionListAttr->remove(anIndicesToBeRemoved);
949   }
950   else if (aType == ModelAPI_AttributeRefList::typeId()) {
951     AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
952     for (int i = 0; i < aRefListAttr->size(); i++) {
953       ObjectPtr anObject = aRefListAttr->object(i);
954       if (anObject.get()) {
955         bool aFound = findInSelection(anObject, GeomShapePtr(), aGeomSelection,
956                                       myWorkshop);
957         if (!aFound)
958           anIndicesToBeRemoved.insert(i);
959       }
960     }
961     isDone = anIndicesToBeRemoved.size() > 0;
962     aRefListAttr->remove(anIndicesToBeRemoved);
963   }
964   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
965     std::set<AttributePtr> anAttributes;
966     QList<ModuleBase_ViewerPrsPtr>::const_iterator
967       anIt = theValues.begin(), aLast = theValues.end();
968     ObjectPtr anObject;
969     GeomShapePtr aShape;
970     for (; anIt != aLast; anIt++) {
971       ModuleBase_ViewerPrsPtr aPrs = *anIt;
972       getGeomSelection(aPrs, anObject, aShape);
973       AttributePtr anAttr = myWorkshop->module()->findAttribute(anObject, aShape);
974       if (anAttr.get() && anAttributes.find(anAttr) == anAttributes.end())
975         anAttributes.insert(anAttr);
976     }
977
978     AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
979     for (int i = 0; i < aRefAttrListAttr->size(); i++) {
980       bool aFound = false;
981       if (aRefAttrListAttr->isAttribute(i)) {
982         AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
983         aFound = anAttributes.find(anAttribute) != anAttributes.end();
984       }
985       else {
986         aFound = findInSelection(aRefAttrListAttr->object(i), GeomShapePtr(), aGeomSelection,
987                                  myWorkshop);
988       }
989       if (!aFound)
990         anIndicesToBeRemoved.insert(i);
991     }
992     isDone = anIndicesToBeRemoved.size() > 0;
993     aRefAttrListAttr->remove(anIndicesToBeRemoved);
994   }
995
996   return isDone;
997 }
998
999 std::map<ObjectPtr, std::set<GeomShapePtr> > ModuleBase_WidgetMultiSelector::convertSelection
1000                                                      (QList<ModuleBase_ViewerPrsPtr>& theValues)
1001 {
1002   // convert prs list to objects map
1003   std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection;
1004   std::set<GeomShapePtr> aShapes;
1005   QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
1006   ObjectPtr anObject;
1007   GeomShapePtr aShape;
1008   GeomShapePtr anEmptyShape(new GeomAPI_Shape());
1009   for (; anIt != aLast; anIt++) {
1010     ModuleBase_ViewerPrsPtr aPrs = *anIt;
1011     getGeomSelection(aPrs, anObject, aShape);
1012     aShapes.clear();
1013     if (aGeomSelection.find(anObject) != aGeomSelection.end()) // found
1014       aShapes = aGeomSelection[anObject];
1015     // we need to know if there was an empty shape in selection for the object
1016     if (!aShape.get())
1017       aShape = anEmptyShape;
1018     if (aShape.get() && aShapes.find(aShape) == aShapes.end()) // not found
1019       aShapes.insert(aShape);
1020     aGeomSelection[anObject] = aShapes;
1021   }
1022   return aGeomSelection;
1023 }
1024
1025 bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject,
1026                               GeomShapePtr theShape,
1027                               const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection,
1028                               ModuleBase_IWorkshop* theWorkshop)
1029 {
1030   if (!theObject.get())
1031     return false;
1032   // issue #2154: we should not remove from list objects hidden in the viewer if selection
1033   // was done with SHIFT button
1034   if (theWorkshop->hasSHIFTPressed() && !theObject->isDisplayed())
1035     return true;
1036
1037   bool aFound = false;
1038   GeomShapePtr aShape = theShape;
1039   if (!aShape.get()) {
1040     // #2429 (the preselection of a sketch is not taken into account)
1041     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1042     if (aResult.get())
1043       aShape = aResult->shape();
1044   }
1045   if (theGeomSelection.find(theObject) != theGeomSelection.end()) {// found
1046     const std::set<GeomShapePtr>& aShapes = theGeomSelection.at(theObject);
1047     std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
1048     for (; anIt != aLast && !aFound; anIt++) {
1049       GeomShapePtr aCShape = *anIt;
1050       if (aCShape.get())
1051       {
1052         // treat shape equal to context as null: 2219, keep order of shapes in list
1053         if (aCShape->isNull()) { // in selection, shape of result is equal to selected shape
1054           // if so, here we need to check shape of result
1055           ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1056           if (aResult.get())
1057             aCShape = aResult->shape();
1058         }
1059         aFound = aCShape->isSame(aShape);
1060       }
1061     }
1062   }
1063
1064   // issue #2903: (Possibility to hide faces) - check whether given shape is a hidden sub-shape
1065   if (!aFound && theShape.get() && theWorkshop->hasSHIFTPressed() && theObject->isDisplayed()) {
1066     AISObjectPtr anAIS = theWorkshop->findPresentation(theObject);
1067     if (anAIS.get() != NULL) {
1068       Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1069
1070       Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast(anAISIO);
1071       if (!aResultPrs.IsNull() && aResultPrs->isSubShapeHidden(theShape->impl<TopoDS_Shape>()))
1072         return true;
1073     }
1074   }
1075
1076   return aFound;
1077 }
1078
1079 QList<ActionInfo>
1080   ModuleBase_WidgetMultiSelector::actionsList(ModuleBase_ActionType theActionType) const
1081 {
1082   QList<ActionInfo> aList;
1083   if (myCurrentHistoryIndex > -1) {
1084     int i = 0;
1085     QString aTitle("Selection %1 items");
1086     QString aTit("Selection %1 item");
1087     QIcon aIcon(":pictures/selection.png");
1088     int aNb;
1089     switch (theActionType) {
1090     case ActionUndo:
1091       i = 1;
1092       while (i <= myCurrentHistoryIndex) {
1093         aNb = mySelectedHistoryValues.at(i).count();
1094         if (aNb == 1) {
1095           ActionInfo aInfo(aIcon, aTit.arg(aNb));
1096           aList.insert(0, aInfo);
1097         } else {
1098           ActionInfo aInfo(aIcon, aTitle.arg(aNb));
1099           aList.insert(0, aInfo);
1100         }
1101         i++;
1102       }
1103       break;
1104     case ActionRedo:
1105       i = mySelectedHistoryValues.length() - 1;
1106       while (i > myCurrentHistoryIndex) {
1107         aNb = mySelectedHistoryValues.at(i).count();
1108         if (aNb == 1) {
1109           ActionInfo aInfo(aIcon, aTit.arg(mySelectedHistoryValues.at(i).count()));
1110           aList.insert(0, aInfo);
1111         } else {
1112           ActionInfo aInfo(aIcon, aTitle.arg(mySelectedHistoryValues.at(i).count()));
1113           aList.insert(0, aInfo);
1114         }
1115         i--;
1116       }
1117       break;
1118     }
1119   }
1120   return aList;
1121 }
1122
1123
1124 void ModuleBase_WidgetMultiSelector::onFeatureAccepted()
1125 {
1126   defaultValues[myFeatureId + attributeID()] = myDefMode;
1127 }
1128
1129 void ModuleBase_WidgetMultiSelector::onListActivated()
1130 {
1131   //focusTo();
1132   emitFocusInWidget();
1133 }
1134
1135 void ModuleBase_WidgetMultiSelector::onSameTopology(bool theOn)
1136 {
1137   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
1138   std::string aType = anAttribute->attributeType();
1139   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
1140     AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
1141     aSelectionListAttr->setGeometricalSelection(theOn);
1142     updateObject(myFeature);
1143   }
1144 }
1145
1146 void ModuleBase_WidgetMultiSelector::onShowOnly(bool theChecked)
1147 {
1148   std::list<ResultPtr> aResults = myFeature->results();
1149    std::list<ResultPtr>::const_iterator aIt;
1150   if (theChecked) {
1151     myVisibleObjects = myWorkshop->displayedObjects();
1152     for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
1153       myVisibleObjects.removeAll(*aIt);
1154     }
1155     myWorkshop->module()->disableCustomMode(ModuleBase_IModule::CustomizeArguments);
1156   }
1157   else
1158     myWorkshop->module()->enableCustomModes();
1159
1160   foreach(ObjectPtr aObj, myVisibleObjects) {
1161     aObj->setDisplayed(!theChecked);
1162   }
1163
1164   if (!theChecked) {
1165     // Hide and show the group result in order to make it above all objects
1166     bool aOldState = myWorkshop->enableUpdateViewer(false);
1167     for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
1168       (*aIt)->setDisplayed(false);
1169     }
1170     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1171     for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
1172       (*aIt)->setDisplayed(true);
1173     }
1174     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1175     myWorkshop->enableUpdateViewer(aOldState);
1176
1177     myVisibleObjects.clear();
1178   } else
1179     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1180 }