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