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