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