]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
Salome HOME
1. Correction for perfomance problem by Apply button state update: do not listen...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetMultiSelector.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * ModuleBase_WidgetMultiSelector.cpp
5  *
6  *  Created on: Aug 28, 2014
7  *      Author: sbh
8  */
9
10 #include <ModuleBase_WidgetMultiSelector.h>
11 #include <ModuleBase_WidgetShapeSelector.h>
12 #include <ModuleBase_ISelection.h>
13 #include <ModuleBase_IWorkshop.h>
14 #include <ModuleBase_IViewer.h>
15 #include <ModuleBase_Tools.h>
16 #include <ModuleBase_Definitions.h>
17 #include <ModuleBase_IModule.h>
18 #include <ModuleBase_ViewerPrs.h>
19
20 #include <ModelAPI_Data.h>
21 #include <ModelAPI_Object.h>
22 #include <ModelAPI_AttributeSelectionList.h>
23 #include <ModelAPI_AttributeRefList.h>
24 #include <ModelAPI_AttributeRefAttrList.h>
25 #include <ModelAPI_Tools.h>
26
27 #include <Config_WidgetAPI.h>
28
29 #include <QGridLayout>
30 #include <QLabel>
31 #include <QListWidget>
32 #include <QObject>
33 #include <QString>
34 #include <QComboBox>
35 #include <QEvent>
36 #include <QAction>
37 #include <QApplication>
38 #include <QClipboard>
39 #include <QTimer>
40
41 #include <memory>
42 #include <string>
43
44 const int ATTRIBUTE_SELECTION_INDEX_ROLE = Qt::UserRole + 1;
45
46 /**
47 * Customization of a List Widget to make it to be placed on full width of container
48 */
49 class CustomListWidget : public QListWidget
50 {
51 public:
52   /// Constructor
53   /// \param theParent a parent widget
54   CustomListWidget( QWidget* theParent )
55     : QListWidget( theParent )
56   {
57   }
58
59   /// Redefinition of virtual method
60   virtual QSize sizeHint() const
61   {
62     int aHeight = 2*QFontMetrics( font() ).height();
63     QSize aSize = QListWidget::sizeHint();
64     return QSize( aSize.width(), aHeight );
65   }
66
67   /// Redefinition of virtual method
68   virtual QSize minimumSizeHint() const
69   {
70     int aHeight = 4/*2*/*QFontMetrics( font() ).height();
71     QSize aSize = QListWidget::minimumSizeHint();
72     return QSize( aSize.width(), aHeight );
73   }
74
75 #ifndef WIN32
76 // The code is necessary only for Linux because
77 //it can not update viewport on widget resize
78 protected:
79   void resizeEvent(QResizeEvent* theEvent)
80   {
81     QListWidget::resizeEvent(theEvent);
82     QTimer::singleShot(5, viewport(), SLOT(repaint()));
83   }
84 #endif
85 };
86
87 ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
88                                                                ModuleBase_IWorkshop* theWorkshop,
89                                                                const Config_WidgetAPI* theData)
90 : ModuleBase_WidgetSelector(theParent, theWorkshop, theData)
91 {
92   QGridLayout* aMainLay = new QGridLayout(this);
93   ModuleBase_Tools::adjustMargins(aMainLay);
94
95   QLabel* aTypeLabel = new QLabel(tr("Type"), this);
96   aMainLay->addWidget(aTypeLabel, 0, 0);
97
98   myTypeCombo = new QComboBox(this);
99   // There is no sense to parameterize list of types while we can not parameterize selection mode
100
101   std::string aPropertyTypes = theData->getProperty("type_choice");
102   QString aTypesStr = aPropertyTypes.c_str();
103   QStringList aShapeTypes = aTypesStr.split(' ', QString::SkipEmptyParts);
104
105   myIsUseChoice = theData->getBooleanAttribute("use_choice", false);
106
107   if (!aShapeTypes.empty())
108     myTypeCombo->addItems(aShapeTypes);
109   aMainLay->addWidget(myTypeCombo, 0, 1);
110   // if the xml definition contains one type, the controls to select a type should not be shown
111   if (aShapeTypes.size() <= 1 || !myIsUseChoice) {
112     aTypeLabel->setVisible(false);
113     myTypeCombo->setVisible(false);
114   }
115
116   std::string aLabelText = theData->getProperty("label");
117   QLabel* aListLabel = new QLabel(!aLabelText.empty() ? aLabelText.c_str()
118                                                       : tr("Selected objects:"), this);
119   aMainLay->addWidget(aListLabel, 1, 0);
120   // if the xml definition contains one type, an information label should be shown near to the latest
121   if (aShapeTypes.size() <= 1) {
122     QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
123     if (!aLabelIcon.isEmpty()) {
124       QLabel* aSelectedLabel = new QLabel("", this);
125       aSelectedLabel->setPixmap(QPixmap(aLabelIcon));
126       aMainLay->addWidget(aSelectedLabel, 1, 1);
127     }
128     aMainLay->setColumnStretch(2, 1);
129   }
130
131   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
132   myListControl = new CustomListWidget(this);
133   QString anObjName = QString::fromStdString(attributeID());
134   myListControl->setObjectName(anObjName);
135   myListControl->setToolTip(aToolTip);
136   myListControl->setSelectionMode(QAbstractItemView::ExtendedSelection);
137
138   aMainLay->addWidget(myListControl, 2, 0, 1, -1);
139   aMainLay->setRowStretch(2, 1);
140   //aMainLay->addWidget(new QLabel(this)); //FIXME(sbh)???
141   //aMainLay->setRowMinimumHeight(3, 20);
142   //this->setLayout(aMainLay);
143   connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectionTypeChanged()));
144
145   myCopyAction = new QAction(QIcon(":pictures/copy.png"), tr("Copy"), this);
146   myCopyAction->setShortcut(QKeySequence::Copy);
147   myCopyAction->setEnabled(false);
148   connect(myCopyAction, SIGNAL(triggered(bool)), SLOT(onCopyItem()));
149   myListControl->addAction(myCopyAction);
150
151   myDeleteAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this);
152   myDeleteAction->setEnabled(false);
153   connect(myDeleteAction, SIGNAL(triggered(bool)), SLOT(onDeleteItem()));
154   myListControl->addAction(myDeleteAction);
155
156   myListControl->setContextMenuPolicy(Qt::ActionsContextMenu);
157   connect(myListControl, SIGNAL(itemSelectionChanged()), SLOT(onListSelection()));
158 }
159
160 ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector()
161 {
162 }
163
164 //********************************************************************
165 void ModuleBase_WidgetMultiSelector::activateCustom()
166 {
167   ModuleBase_WidgetSelector::activateCustom();
168
169   myWorkshop->module()->activateCustomPrs(myFeature,
170                             ModuleBase_IModule::CustomizeHighlightedObjects, true);
171 }
172
173 //********************************************************************
174 void ModuleBase_WidgetMultiSelector::deactivate()
175 {
176   ModuleBase_WidgetSelector::deactivate();
177
178   myWorkshop->module()->deactivateCustomPrs(ModuleBase_IModule::CustomizeHighlightedObjects, true);
179 }
180
181 //********************************************************************
182 bool ModuleBase_WidgetMultiSelector::storeValueCustom()
183 {
184   // the value is stored on the selection changed signal processing 
185   // A rare case when plugin was not loaded. 
186   if (!myFeature)
187     return false;
188
189   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
190   std::string aType = anAttribute->attributeType();
191   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
192     AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
193     aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
194   }
195   return true;
196 }
197
198 //********************************************************************
199 bool ModuleBase_WidgetMultiSelector::restoreValueCustom()
200 {
201   // A rare case when plugin was not loaded. 
202   if (!myFeature)
203     return false;
204
205   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
206   std::string aType = anAttribute->attributeType();
207   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
208     AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
209     // Restore shape type
210     std::string aSelectionType = aSelectionListAttr->selectionType().c_str();
211     if (!aSelectionType.empty())
212       setCurrentShapeType(ModuleBase_Tools::shapeType(aSelectionType.c_str()));
213   }
214   updateSelectionList();
215   return true;
216 }
217
218 //********************************************************************
219 bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
220                                                   const bool theToValidate)
221 {
222   QList<ModuleBase_ViewerPrsPtr> aSkippedValues;
223
224   /// remove unused objects from the model attribute.
225   /// It should be performed before new attributes append.
226   removeUnusedAttributeObjects(theValues);
227
228   QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
229   bool isDone = false;
230   for (; anIt != aLast; anIt++) {
231     ModuleBase_ViewerPrsPtr aValue = *anIt;
232     bool aProcessed = false;
233     if (!theToValidate || isValidInFilters(aValue)) {
234       aProcessed = setSelectionCustom(aValue);
235     }
236     else
237       aSkippedValues.append(aValue);
238     // if there is at least one set, the result is true
239     isDone = isDone || aProcessed;
240   }
241   // updateObject - to update/redisplay feature
242   // it is commented in order to perfom it outside the method
243   //if (isDone) {
244     //updateObject(myFeature);
245     // this emit is necessary to call store/restore method an restore type of selection
246     //emit valuesChanged();
247   //}
248
249   theValues.clear();
250   if (!aSkippedValues.empty())
251     theValues.append(aSkippedValues);
252
253   return isDone;
254 }
255
256 //********************************************************************
257 void ModuleBase_WidgetMultiSelector::getHighlighted(QList<ModuleBase_ViewerPrsPtr>& theValues)
258 {
259   std::set<int> anAttributeIds;
260   getSelectedAttributeIndices(anAttributeIds);
261   if (!anAttributeIds.empty())
262     convertIndicesToViewerSelection(anAttributeIds, theValues);
263 }
264
265 //********************************************************************
266 bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
267 {
268   bool aValid = ModuleBase_WidgetSelector::isValidSelectionCustom(thePrs);
269   if (aValid) {
270     ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
271     aValid = aResult.get() != NULL;
272     if (aValid) {
273       if (myFeature) {
274         // We can not select a result of our feature
275         const std::list<ResultPtr>& aResList = myFeature->results();
276         std::list<ResultPtr>::const_iterator aIt;
277         bool isSkipSelf = false;
278         for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
279           if ((*aIt) == aResult) {
280             isSkipSelf = true;
281             break;
282           }
283         }
284         if (isSkipSelf)
285           aValid = false;
286       }
287     }
288   }
289   return aValid;
290 }
291
292 //********************************************************************
293 bool ModuleBase_WidgetMultiSelector::processDelete()
294 {
295   // find attribute indices to delete
296   std::set<int> anAttributeIds;
297   getSelectedAttributeIndices(anAttributeIds);
298
299   // refill attribute by the items which indices are not in the list of ids
300   bool aDone = false;
301   DataPtr aData = myFeature->data();
302   AttributePtr anAttribute = aData->attribute(attributeID());
303   std::string aType = anAttribute->attributeType();
304   aDone = !anAttributeIds.empty();
305   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
306     AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
307     aSelectionListAttr->remove(anAttributeIds);
308
309   }
310   else if (aType == ModelAPI_AttributeRefList::typeId()) {
311     AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
312     aRefListAttr->remove(anAttributeIds);
313   }
314   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
315     AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
316     aRefAttrListAttr->remove(anAttributeIds);
317   }
318
319   if (aDone) {
320     // update object is necessary to flush update signal. It leads to objects references map update
321     // and the operation presentation will not contain deleted items visualized as parameters of
322     // the feature.
323     updateObject(myFeature);
324
325     restoreValue();
326     myWorkshop->setSelected(getAttributeSelection());
327   }
328   return aDone;
329 }
330
331 //********************************************************************
332 QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
333 {
334   QList<QWidget*> result;
335   //result << myTypeCombo;
336   result << myListControl;
337   return result;
338 }
339
340 //********************************************************************
341 void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
342 {
343   activateSelectionAndFilters(true);
344   QList<ModuleBase_ViewerPrsPtr> anEmptyList;
345   // This method will call Selection changed event which will call onSelectionChanged
346   // To clear mySelection, myListControl and storeValue()
347   // So, we don't need to call it
348   myWorkshop->setSelected(anEmptyList);
349 }
350
351 void ModuleBase_WidgetMultiSelector::updateFocus()
352 {
353   // Set focus to List control in order to make possible 
354   // to use Tab key for transfer the focus to next widgets
355   myListControl->setCurrentRow(myListControl->model()->rowCount() - 1);
356   ModuleBase_Tools::setFocus(myListControl,
357                              "ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()");
358 }
359
360 //********************************************************************
361 void ModuleBase_WidgetMultiSelector::updateSelectionName()
362 {
363 }
364
365 //********************************************************************
366 QIntList ModuleBase_WidgetMultiSelector::getShapeTypes() const
367 {
368   QIntList aShapeTypes;
369
370   if (myTypeCombo->count() > 1 && myIsUseChoice) {
371     aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->currentText()));
372   }
373   else {
374     for (int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) {
375       TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->itemText(i));
376       aShapeTypes.append(aType);
377       if (aType == TopAbs_SOLID)
378         aShapeTypes.append(TopAbs_COMPSOLID);
379     }
380   }
381   return aShapeTypes;
382 }
383
384 //********************************************************************
385 void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType)
386 {
387   QString aShapeTypeName;
388   
389   for (int idx = 0; idx < myTypeCombo->count(); ++idx) {
390     aShapeTypeName = myTypeCombo->itemText(idx);
391     TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
392     if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
393       bool aWasActivated = activateSelectionAndFilters(false);
394       bool isBlocked = myTypeCombo->blockSignals(true);
395       myTypeCombo->setCurrentIndex(idx);
396       myTypeCombo->blockSignals(isBlocked);
397       if (aWasActivated)
398         activateSelectionAndFilters(true);
399       break;
400     }
401   }
402 }
403
404 QList<ModuleBase_ViewerPrsPtr> ModuleBase_WidgetMultiSelector::getAttributeSelection() const
405 {
406   QList<ModuleBase_ViewerPrsPtr> aSelected;
407   convertIndicesToViewerSelection(std::set<int>(), aSelected);
408   return aSelected;
409 }
410
411 //********************************************************************
412 void ModuleBase_WidgetMultiSelector::updateSelectionList()
413 {
414   myListControl->clear();
415
416   DataPtr aData = myFeature->data();
417   AttributePtr anAttribute = aData->attribute(attributeID());
418   std::string aType = anAttribute->attributeType();
419   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
420     AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
421     for (int i = 0; i < aSelectionListAttr->size(); i++) {
422       AttributeSelectionPtr aAttr = aSelectionListAttr->value(i);
423       QListWidgetItem* anItem = new QListWidgetItem(aAttr->namingName().c_str(), myListControl);
424       anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
425       myListControl->addItem(anItem);
426     }
427   }
428   else if (aType == ModelAPI_AttributeRefList::typeId()) {
429     AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
430     for (int i = 0; i < aRefListAttr->size(); i++) {
431       ObjectPtr anObject = aRefListAttr->object(i);
432       if (anObject.get()) {
433         QListWidgetItem* anItem = new QListWidgetItem(anObject->data()->name().c_str(),
434                                                       myListControl);
435         anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
436         myListControl->addItem(anItem);
437       }
438     }
439   }
440   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
441     AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
442     for (int i = 0; i < aRefAttrListAttr->size(); i++) {
443       AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
444       QString aName;
445       if (anAttribute.get()) {
446         std::string anAttrName = generateName(anAttribute, myWorkshop);
447         aName = QString::fromStdString(anAttrName);
448       }
449       else {
450         ObjectPtr anObject = aRefAttrListAttr->object(i);
451         if (anObject.get()) {
452           aName = anObject->data()->name().c_str();
453         }
454       }
455       QListWidgetItem* anItem = new QListWidgetItem(aName, myListControl);
456       anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
457       myListControl->addItem(anItem);
458     }
459   }
460
461   // We have to call repaint because sometimes the List control is not updated
462   myListControl->repaint();
463 }
464
465 //********************************************************************
466 std::string ModuleBase_WidgetMultiSelector::validatorType(const QString& theType) const
467 {
468   std::string aType;
469
470   if (theType == "Vertices")
471     aType = "vertex";
472   else if (theType == "Edges")
473     aType = "edge";
474   else if (theType == "Faces")
475     aType = "face";
476   else if (theType == "Solids")
477     aType = "solid";
478
479   return aType;
480 }
481
482 //********************************************************************
483 void ModuleBase_WidgetMultiSelector::onCopyItem()
484 {
485   QList<QListWidgetItem*> aItems = myListControl->selectedItems();
486   QString aRes;
487   foreach(QListWidgetItem* aItem, aItems) {
488     if (!aRes.isEmpty())
489       aRes += "\n";
490     aRes += aItem->text();
491   }
492   if (!aRes.isEmpty()) {
493     QClipboard *clipboard = QApplication::clipboard();
494     clipboard->setText(aRes);
495   }
496 }
497
498 //********************************************************************
499 void ModuleBase_WidgetMultiSelector::onDeleteItem()
500 {
501   processDelete();
502 }
503
504 //********************************************************************
505 void ModuleBase_WidgetMultiSelector::onListSelection()
506 {
507   QList<QListWidgetItem*> aItems = myListControl->selectedItems();
508   myCopyAction->setEnabled(!aItems.isEmpty());
509   myDeleteAction->setEnabled(!aItems.isEmpty());
510   
511   myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects,
512                                         true);
513 }
514
515 //********************************************************************
516 void ModuleBase_WidgetMultiSelector::getSelectedAttributeIndices(std::set<int>& theAttributeIds)
517 {
518   QList<QListWidgetItem*> aItems = myListControl->selectedItems();
519   foreach(QListWidgetItem* anItem, aItems) {
520     int anIndex = anItem->data(ATTRIBUTE_SELECTION_INDEX_ROLE).toInt();
521     if (theAttributeIds.find(anIndex) == theAttributeIds.end())
522       theAttributeIds.insert(anIndex);
523   }
524 }
525
526 void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<int> theAttributeIds,
527                                                       QList<ModuleBase_ViewerPrsPtr>& theValues) const
528 {
529   if(myFeature.get() == NULL)
530     return;
531
532   DataPtr aData = myFeature->data();
533   AttributePtr anAttribute = aData->attribute(attributeID());
534   std::string aType = anAttribute->attributeType();
535   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
536     AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
537     for (int i = 0; i < aSelectionListAttr->size(); i++) {
538       // filter by attribute indices only if the container is not empty otherwise return all items
539       if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
540         continue;
541       AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
542       ResultPtr anObject = anAttr->context();
543       if (anObject.get())
544         theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
545                new ModuleBase_ViewerPrs(anObject, anAttr->value(), NULL)));
546     }
547   }
548   else if (aType == ModelAPI_AttributeRefList::typeId()) {
549     AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
550     for (int i = 0; i < aRefListAttr->size(); i++) {
551       // filter by attribute indices only if the container is not empty otherwise return all items
552       if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
553         continue;
554       ObjectPtr anObject = aRefListAttr->object(i);
555       if (anObject.get()) {
556         theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
557                new ModuleBase_ViewerPrs(anObject, GeomShapePtr(), NULL)));
558       }
559     }
560   }
561   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
562     AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
563     for (int i = 0; i < aRefAttrListAttr->size(); i++) {
564       // filter by attribute indices only if the container is not empty otherwise return all items
565       if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
566         continue;
567       ObjectPtr anObject = aRefAttrListAttr->object(i);
568       if (!anObject.get())
569         continue;
570       TopoDS_Shape aShape;
571       AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
572       if (anAttribute.get()) {
573         GeomShapePtr aGeomShape = ModuleBase_Tools::getShape(anAttribute, myWorkshop);
574         theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
575                new ModuleBase_ViewerPrs(anObject, aGeomShape, NULL)));
576       }
577     }
578   }
579 }
580
581 void ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
582                                                  (QList<ModuleBase_ViewerPrsPtr>& theValues)
583 {
584   std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection = convertSelection(theValues);
585   DataPtr aData = myFeature->data();
586   AttributePtr anAttribute = aData->attribute(attributeID());
587   std::string aType = anAttribute->attributeType();
588   std::set<GeomShapePtr> aShapes;
589   std::set<int> anIndicesToBeRemoved;
590   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
591     // iteration through data model to find not selected elements to remove them
592     AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
593     for (int i = 0; i < aSelectionListAttr->size(); i++) {
594       AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
595       bool aFound = findInSelection(anAttr->context(), anAttr->value(), aGeomSelection);
596       if (!aFound)
597         anIndicesToBeRemoved.insert(i);
598     }
599     aSelectionListAttr->remove(anIndicesToBeRemoved);
600   }
601   else if (aType == ModelAPI_AttributeRefList::typeId()) {
602     AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
603     for (int i = 0; i < aRefListAttr->size(); i++) {
604       ObjectPtr anObject = aRefListAttr->object(i);
605       if (anObject.get()) {
606         bool aFound = findInSelection(anObject, GeomShapePtr(), aGeomSelection);
607         if (!aFound)
608           anIndicesToBeRemoved.insert(i);
609       }
610     }
611     aRefListAttr->remove(anIndicesToBeRemoved);
612   }
613   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
614     std::set<AttributePtr> anAttributes;
615     QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
616     ObjectPtr anObject;
617     GeomShapePtr aShape;
618     for (; anIt != aLast; anIt++) {
619       ModuleBase_ViewerPrsPtr aPrs = *anIt;
620       getGeomSelection(aPrs, anObject, aShape);
621       AttributePtr anAttr = myWorkshop->module()->findAttribute(anObject, aShape);
622       if (anAttr.get() && anAttributes.find(anAttr) == anAttributes.end())
623         anAttributes.insert(anAttr);
624     }
625
626     AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
627     for (int i = 0; i < aRefAttrListAttr->size(); i++) {
628       bool aFound = false;
629       if (aRefAttrListAttr->isAttribute(i)) {
630         AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
631         aFound = anAttributes.find(anAttribute) != anAttributes.end();
632       }
633       else {
634         aFound = findInSelection(aRefAttrListAttr->object(i), GeomShapePtr(), aGeomSelection);
635       }
636       if (!aFound)
637         anIndicesToBeRemoved.insert(i);
638     }
639     aRefAttrListAttr->remove(anIndicesToBeRemoved);
640   }
641 }
642
643 std::map<ObjectPtr, std::set<GeomShapePtr> > ModuleBase_WidgetMultiSelector::convertSelection
644                                                      (QList<ModuleBase_ViewerPrsPtr>& theValues)
645 {
646   // convert prs list to objects map
647   std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection;
648   std::set<GeomShapePtr> aShapes;
649   QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
650   ObjectPtr anObject;
651   GeomShapePtr aShape;
652   GeomShapePtr anEmptyShape(new GeomAPI_Shape());
653   for (; anIt != aLast; anIt++) {
654     ModuleBase_ViewerPrsPtr aPrs = *anIt;
655     getGeomSelection(aPrs, anObject, aShape);
656     aShapes.clear();
657     if (aGeomSelection.find(anObject) != aGeomSelection.end()) // found
658       aShapes = aGeomSelection[anObject];
659     // we need to know if there was an empty shape in selection for the object
660     if (!aShape.get())
661       aShape = anEmptyShape;
662     if (aShape.get() && aShapes.find(aShape) == aShapes.end()) // not found
663       aShapes.insert(aShape);
664     aGeomSelection[anObject] = aShapes;
665   }
666   return aGeomSelection;
667 }
668
669 bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject,
670                               const GeomShapePtr& theShape,
671                               const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection)
672 {
673   bool aFound = false;
674   GeomShapePtr anEmptyShape(new GeomAPI_Shape());
675   GeomShapePtr aShape = theShape.get() ? theShape : anEmptyShape;
676   if (theGeomSelection.find(theObject) != theGeomSelection.end()) {// found
677     const std::set<GeomShapePtr>& aShapes = theGeomSelection.at(theObject);
678     std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
679     for (; anIt != aLast && !aFound; anIt++) {
680       GeomShapePtr aCShape = *anIt;
681       if (aCShape.get())
682         aFound = aCShape->isEqual(aShape);
683     }
684   }
685   return aFound;
686 }