Salome HOME
28d40d2829a9c617de91772783b11aec72d49d77
[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
25 #include <Config_WidgetAPI.h>
26
27 #include <QGridLayout>
28 #include <QLabel>
29 #include <QListWidget>
30 #include <QObject>
31 #include <QString>
32 #include <QComboBox>
33 #include <QEvent>
34 #include <QAction>
35 #include <QApplication>
36 #include <QClipboard>
37 #include <QTimer>
38
39 #include <memory>
40 #include <string>
41
42 const int ATTRIBUTE_SELECTION_INDEX_ROLE = Qt::UserRole + 1;
43
44 /**
45 * Customization of a List Widget to make it to be placed on full width of container
46 */
47 class CustomListWidget : public QListWidget
48 {
49 public:
50   /// Constructor
51   /// \param theParent a parent widget
52   CustomListWidget( QWidget* theParent )
53     : QListWidget( theParent )
54   {
55   }
56
57   /// Redefinition of virtual method
58   virtual QSize sizeHint() const
59   {
60     int aHeight = 2*QFontMetrics( font() ).height();
61     QSize aSize = QListWidget::sizeHint();
62     return QSize( aSize.width(), aHeight );
63   }
64
65   /// Redefinition of virtual method
66   virtual QSize minimumSizeHint() const
67   {
68     int aHeight = 4/*2*/*QFontMetrics( font() ).height();
69     QSize aSize = QListWidget::minimumSizeHint();
70     return QSize( aSize.width(), aHeight );
71   }
72
73 #ifndef WIN32
74 // The code is necessary only for Linux because
75 //it can not update viewport on widget resize
76 protected:
77   void resizeEvent(QResizeEvent* theEvent)
78   {
79     QListWidget::resizeEvent(theEvent);
80     QTimer::singleShot(5, viewport(), SLOT(repaint()));
81   }
82 #endif
83 };
84
85 ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
86                                                                ModuleBase_IWorkshop* theWorkshop,
87                                                                const Config_WidgetAPI* theData,
88                                                                const std::string& theParentId)
89  : ModuleBase_WidgetSelector(theParent, theWorkshop, theData, theParentId),
90    mySelectionCount(0)
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", true);
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() const
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 =
193                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
194     aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
195   }
196   return true;
197 }
198
199 //********************************************************************
200 bool ModuleBase_WidgetMultiSelector::restoreValueCustom()
201 {
202   // A rare case when plugin was not loaded. 
203   if (!myFeature)
204     return false;
205
206   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
207   std::string aType = anAttribute->attributeType();
208   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
209     AttributeSelectionListPtr aSelectionListAttr =
210                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
211     // Restore shape type
212     setCurrentShapeType(ModuleBase_Tools::shapeType(aSelectionListAttr->selectionType().c_str()));
213   }
214   updateSelectionList();
215   return true;
216 }
217
218 //********************************************************************
219 void ModuleBase_WidgetMultiSelector::storeAttributeValue()
220 {
221   ModuleBase_WidgetValidated::storeAttributeValue();
222
223   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
224   std::string aType = anAttribute->attributeType();
225
226   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
227     AttributeSelectionListPtr aSelectionListAttr =
228                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
229     mySelectionType = aSelectionListAttr->selectionType();
230     mySelectionCount = aSelectionListAttr->size();
231   }
232   else if (aType == ModelAPI_AttributeRefList::typeId()) {
233     AttributeRefListPtr aRefListAttr =
234                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
235     mySelectionCount = aRefListAttr->size();
236   }
237   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
238     AttributeRefAttrListPtr aRefAttrListAttr =
239                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
240     mySelectionCount = aRefAttrListAttr->size();
241   }
242 }
243
244 //********************************************************************
245 bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
246 {
247   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
248   std::string aType = anAttribute->attributeType();
249   if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
250     AttributeRefAttrListPtr aRefAttrListAttr =
251                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
252
253     bool isDone = false;
254     if (!thePrs.shape().IsNull()) {
255       GeomShapePtr aGeomShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
256       aGeomShape->setImpl(new TopoDS_Shape(thePrs.shape()));
257
258       AttributePtr anAttribute = myWorkshop->module()->findAttribute(thePrs.object(), aGeomShape);
259       if (anAttribute.get()) {
260         aRefAttrListAttr->append(anAttribute);
261         isDone = true;
262       }
263     }
264     if (!isDone)
265       ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
266   }
267   else {
268     ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
269     /*ObjectPtr anObject;
270     GeomShapePtr aShape;
271     getGeomSelection(thePrs, anObject, aShape);
272     setObject(anObject, aShape);*/
273   }
274   return true;
275 }
276
277 //********************************************************************
278 void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid)
279 {
280   ModuleBase_WidgetValidated::restoreAttributeValue(theValid);
281
282   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
283   std::string aType = anAttribute->attributeType();
284   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
285     AttributeSelectionListPtr aSelectionListAttr =
286                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
287     aSelectionListAttr->setSelectionType(mySelectionType);
288
289     // restore selection in the attribute. Indeed there is only one stored object
290     int aCountAppened = aSelectionListAttr->size() - mySelectionCount;
291     for (int i = 0; i < aCountAppened; i++)
292       aSelectionListAttr->removeLast();
293   }
294   else if (aType == ModelAPI_AttributeRefList::typeId()) {
295     AttributeRefListPtr aRefListAttr =
296                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
297     // restore objects in the attribute. Indeed there is only one stored object
298     int aCountAppened = aRefListAttr->size() - mySelectionCount;
299     for (int i = 0; i < aCountAppened; i++)
300       aRefListAttr->removeLast();
301   }
302   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
303     AttributeRefAttrListPtr aRefAttrListAttr =
304                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
305     // restore objects in the attribute. Indeed there is only one stored object
306     int aCountAppened = aRefAttrListAttr->size() - mySelectionCount;
307     for (int i = 0; i < aCountAppened; i++)
308       aRefAttrListAttr->removeLast();
309   }
310 }
311
312 //********************************************************************
313 void ModuleBase_WidgetMultiSelector::clearAttribute()
314 {
315   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
316   std::string aType = anAttribute->attributeType();
317   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
318     AttributeSelectionListPtr aSelectionListAttr =
319                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
320     aSelectionListAttr->clear();
321   }
322   else if (aType == ModelAPI_AttributeRefList::typeId()) {
323     AttributeRefListPtr aRefListAttr =
324                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
325     aRefListAttr->clear();
326   }
327   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
328     AttributeRefAttrListPtr aRefAttrListAttr =
329                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
330     aRefAttrListAttr->clear();
331   }
332 }
333
334 //********************************************************************
335 void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
336                                                GeomShapePtr theShape)
337 {
338   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
339   std::string aType = anAttribute->attributeType();
340   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
341     AttributeSelectionListPtr aSelectionListAttr =
342                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
343     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
344     aSelectionListAttr->append(aResult, theShape, myIsInValidate);
345   }
346   else if (aType == ModelAPI_AttributeRefList::typeId()) {
347     AttributeRefListPtr aRefListAttr =
348                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
349     aRefListAttr->append(theSelectedObject);
350   }
351   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
352     //AttributeRefAttrListPtr aRefAttrListAttr =
353     //             std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
354     //aRefAttrListAttr->clear();
355   }
356 }
357
358 //********************************************************************
359 bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
360                                                   const bool theToValidate)
361 {
362   QList<ModuleBase_ViewerPrs> aSkippedValues;
363
364   QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
365   bool isDone = false;
366   for (; anIt != aLast; anIt++) {
367     ModuleBase_ViewerPrs aValue = *anIt;
368     bool aProcessed = false;
369     if (!theToValidate || isValidInFilters(aValue)) {
370       aProcessed = setSelectionCustom(aValue);
371     }
372     else
373       aSkippedValues.append(aValue);
374     // if there is at least one set, the result is true
375     isDone = isDone || aProcessed;
376   }
377   // updateObject - to update/redisplay feature
378   // it is commented in order to perfom it outside the method
379   //if (isDone) {
380     //updateObject(myFeature);
381     // this emit is necessary to call store/restore method an restore type of selection
382     //emit valuesChanged();
383   //}
384   theValues.clear();
385   if (!aSkippedValues.empty())
386     theValues.append(aSkippedValues);
387
388   return isDone;
389 }
390
391 //********************************************************************
392 void ModuleBase_WidgetMultiSelector::getHighlighted(QList<ModuleBase_ViewerPrs>& theValues)
393 {
394   std::set<int> anAttributeIds;
395   getSelectedAttributeIndices(anAttributeIds);
396   if (!anAttributeIds.empty())
397     convertIndicesToViewerSelection(anAttributeIds, theValues);
398 }
399
400 //********************************************************************
401 bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
402 {
403   bool aValid = ModuleBase_WidgetSelector::isValidSelectionCustom(thePrs);
404   if (aValid) {
405     ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
406     aValid = aResult.get() != NULL;
407     if (aValid) {
408       if (myFeature) {
409         // We can not select a result of our feature
410         const std::list<ResultPtr>& aResList = myFeature->results();
411         std::list<ResultPtr>::const_iterator aIt;
412         bool isSkipSelf = false;
413         for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
414           if ((*aIt) == aResult) {
415             isSkipSelf = true;
416             break;
417           }
418         }
419         if (isSkipSelf)
420           aValid = false;
421       }
422     }
423   }
424   return aValid;
425 }
426
427 //********************************************************************
428 bool ModuleBase_WidgetMultiSelector::processDelete()
429 {
430   // find attribute indices to delete
431   std::set<int> anAttributeIds;
432   getSelectedAttributeIndices(anAttributeIds);
433
434   // refill attribute by the items which indices are not in the list of ids
435   bool aDone = false;
436   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
437   std::string aType = anAttribute->attributeType();
438   aDone = !anAttributeIds.empty();
439   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
440     AttributeSelectionListPtr aSelectionListAttr =
441                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
442     aSelectionListAttr->remove(anAttributeIds);
443
444   }
445   else if (aType == ModelAPI_AttributeRefList::typeId()) {
446     AttributeRefListPtr aRefListAttr =
447                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
448       aRefListAttr->remove(anAttributeIds);
449   }
450   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
451     AttributeRefAttrListPtr aRefAttrListAttr =
452                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
453     aRefAttrListAttr->remove(anAttributeIds);
454   }
455
456   if (aDone) {
457     // update object is necessary to flush update signal. It leads to objects references map update
458     // and the operation presentation will not contain deleted items visualized as parameters of
459     // the feature.
460     updateObject(myFeature);
461
462     restoreValue();
463     myWorkshop->setSelected(getAttributeSelection());
464   }
465   return aDone;
466 }
467
468 //********************************************************************
469 QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
470 {
471   QList<QWidget*> result;
472   //result << myTypeCombo;
473   result << myListControl;
474   return result;
475 }
476
477 //********************************************************************
478 void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
479 {
480   activateSelectionAndFilters(true);
481   QList<ModuleBase_ViewerPrs> anEmptyList;
482   // This method will call Selection changed event which will call onSelectionChanged
483   // To clear mySelection, myListControl and storeValue()
484   // So, we don't need to call it
485   myWorkshop->setSelected(anEmptyList);
486 }
487
488 void ModuleBase_WidgetMultiSelector::updateFocus()
489 {
490   // Set focus to List control in order to make possible 
491   // to use Tab key for transfer the focus to next widgets
492   myListControl->setCurrentRow(myListControl->model()->rowCount() - 1);
493   ModuleBase_Tools::setFocus(myListControl,
494                              "ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()");
495 }
496
497 //********************************************************************
498 void ModuleBase_WidgetMultiSelector::updateSelectionName()
499 {
500 }
501
502 //********************************************************************
503 QIntList ModuleBase_WidgetMultiSelector::getShapeTypes() const
504 {
505   QIntList aShapeTypes;
506
507   if (myTypeCombo->count() > 1 && myIsUseChoice) {
508     aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->currentText()));
509   }
510   else {
511     for (int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) {
512       TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->itemText(i));
513       aShapeTypes.append(aType);
514       if (aType == TopAbs_SOLID)
515         aShapeTypes.append(TopAbs_COMPSOLID);
516     }
517   }
518   return aShapeTypes;
519 }
520
521 //********************************************************************
522 void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType)
523 {
524   QString aShapeTypeName;
525   
526   for (int idx = 0; idx < myTypeCombo->count(); ++idx) {
527     aShapeTypeName = myTypeCombo->itemText(idx);
528     TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
529     if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
530       activateSelectionAndFilters(false);
531       bool isBlocked = myTypeCombo->blockSignals(true);
532       myTypeCombo->setCurrentIndex(idx);
533       myTypeCombo->blockSignals(isBlocked);
534
535       activateSelectionAndFilters(true);
536       break;
537     }
538   }
539 }
540
541 QList<ModuleBase_ViewerPrs> ModuleBase_WidgetMultiSelector::getAttributeSelection() const
542 {
543   QList<ModuleBase_ViewerPrs> aSelected;
544   convertIndicesToViewerSelection(std::set<int>(), aSelected);
545   return aSelected;
546 }
547
548 //********************************************************************
549 void ModuleBase_WidgetMultiSelector::updateSelectionList()
550 {
551   myListControl->clear();
552
553   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
554   std::string aType = anAttribute->attributeType();
555   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
556     AttributeSelectionListPtr aSelectionListAttr =
557                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
558     for (int i = 0; i < aSelectionListAttr->size(); i++) {
559       AttributeSelectionPtr aAttr = aSelectionListAttr->value(i);
560       QListWidgetItem* anItem = new QListWidgetItem(aAttr->namingName().c_str(), myListControl);
561       anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
562       myListControl->addItem(anItem);
563     }
564   }
565   else if (aType == ModelAPI_AttributeRefList::typeId()) {
566     AttributeRefListPtr aRefListAttr =
567                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
568     for (int i = 0; i < aRefListAttr->size(); i++) {
569       ObjectPtr anObject = aRefListAttr->object(i);
570       if (anObject.get()) {
571         QListWidgetItem* anItem = new QListWidgetItem(anObject->data()->name().c_str(),
572                                                       myListControl);
573         anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
574         myListControl->addItem(anItem);
575       }
576     }
577   }
578   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
579     AttributeRefAttrListPtr aRefAttrListAttr =
580                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
581     for (int i = 0; i < aRefAttrListAttr->size(); i++) {
582       AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
583       QString aName;
584       if (anAttribute.get()) {
585         std::string anAttrName = generateName(anAttribute);
586         aName = QString::fromStdString(anAttrName);
587       }
588       else {
589         ObjectPtr anObject = aRefAttrListAttr->object(i);
590         if (anObject.get()) {
591           aName = anObject->data()->name().c_str();
592         }
593       }
594       QListWidgetItem* anItem = new QListWidgetItem(aName, myListControl);
595       anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
596       myListControl->addItem(anItem);
597     }
598   }
599
600   // We have to call repaint because sometimes the List control is not updated
601   myListControl->repaint();
602 }
603
604 //********************************************************************
605 std::string ModuleBase_WidgetMultiSelector::validatorType(const QString& theType) const
606 {
607   std::string aType;
608
609   if (theType == "Vertices")
610     aType = "vertex";
611   else if (theType == "Edges")
612     aType = "edge";
613   else if (theType == "Faces")
614     aType = "face";
615   else if (theType == "Solids")
616     aType = "solid";
617
618   return aType;
619 }
620
621 //********************************************************************
622 void ModuleBase_WidgetMultiSelector::onCopyItem()
623 {
624   QList<QListWidgetItem*> aItems = myListControl->selectedItems();
625   QString aRes;
626   foreach(QListWidgetItem* aItem, aItems) {
627     if (!aRes.isEmpty())
628       aRes += "\n";
629     aRes += aItem->text();
630   }
631   if (!aRes.isEmpty()) {
632     QClipboard *clipboard = QApplication::clipboard();
633     clipboard->setText(aRes);
634   }
635 }
636
637 //********************************************************************
638 void ModuleBase_WidgetMultiSelector::onDeleteItem()
639 {
640   processDelete();
641 }
642
643 //********************************************************************
644 void ModuleBase_WidgetMultiSelector::onListSelection()
645 {
646   QList<QListWidgetItem*> aItems = myListControl->selectedItems();
647   myCopyAction->setEnabled(!aItems.isEmpty());
648   myDeleteAction->setEnabled(!aItems.isEmpty());
649   
650   myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects,
651                                         true);
652 }
653
654 //********************************************************************
655 void ModuleBase_WidgetMultiSelector::getSelectedAttributeIndices(std::set<int>& theAttributeIds)
656 {
657   QList<QListWidgetItem*> aItems = myListControl->selectedItems();
658   foreach(QListWidgetItem* anItem, aItems) {
659     int anIndex = anItem->data(ATTRIBUTE_SELECTION_INDEX_ROLE).toInt();
660     if (theAttributeIds.find(anIndex) == theAttributeIds.end())
661       theAttributeIds.insert(anIndex);
662   }
663 }
664
665 void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<int> theAttributeIds,
666                                                       QList<ModuleBase_ViewerPrs>& theValues) const
667 {
668   if(myFeature.get() == NULL)
669     return;
670
671   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
672   std::string aType = anAttribute->attributeType();
673   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
674     AttributeSelectionListPtr aSelectionListAttr =
675                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
676     for (int i = 0; i < aSelectionListAttr->size(); i++) {
677       // filter by attribute indices only if the container is not empty otherwise return all items
678       if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
679         continue;
680       AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
681       ResultPtr anObject = anAttr->context();
682       if (anObject.get()) {
683         TopoDS_Shape aShape;
684         std::shared_ptr<GeomAPI_Shape> aShapePtr = anAttr->value();
685         if (aShapePtr.get()) {
686           aShape = aShapePtr->impl<TopoDS_Shape>();
687         }
688         theValues.append(ModuleBase_ViewerPrs(anObject, aShape, NULL));
689       }
690     }
691   }
692   else if (aType == ModelAPI_AttributeRefList::typeId()) {
693     AttributeRefListPtr aRefListAttr =
694                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
695     for (int i = 0; i < aRefListAttr->size(); i++) {
696       // filter by attribute indices only if the container is not empty otherwise return all items
697       if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
698         continue;
699       ObjectPtr anObject = aRefListAttr->object(i);
700       if (anObject.get()) {
701         theValues.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL));
702       }
703     }
704   }
705   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
706     AttributeRefAttrListPtr aRefAttrListAttr =
707                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
708     for (int i = 0; i < aRefAttrListAttr->size(); i++) {
709       // filter by attribute indices only if the container is not empty otherwise return all items
710       if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
711         continue;
712       ObjectPtr anObject = aRefAttrListAttr->object(i);
713       if (!anObject.get())
714         continue;
715       TopoDS_Shape aShape;
716       AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
717       if (anAttribute.get()) {
718         GeomShapePtr aGeomShape = myWorkshop->module()->findShape(anAttribute);
719         if (aGeomShape.get()) {
720           aShape = aGeomShape->impl<TopoDS_Shape>();
721         }
722         theValues.append(ModuleBase_ViewerPrs(anObject, aShape, NULL));
723       }
724     }
725   }
726 }