]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
Salome HOME
ModuleBase_WidgetShapeSelector correction to process AttrRefAtt like MultiSelector...
[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 void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid)
246 {
247   ModuleBase_WidgetValidated::restoreAttributeValue(theValid);
248
249   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
250   std::string aType = anAttribute->attributeType();
251   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
252     AttributeSelectionListPtr aSelectionListAttr =
253                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
254     aSelectionListAttr->setSelectionType(mySelectionType);
255
256     // restore selection in the attribute. Indeed there is only one stored object
257     int aCountAppened = aSelectionListAttr->size() - mySelectionCount;
258     for (int i = 0; i < aCountAppened; i++)
259       aSelectionListAttr->removeLast();
260   }
261   else if (aType == ModelAPI_AttributeRefList::typeId()) {
262     AttributeRefListPtr aRefListAttr =
263                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
264     // restore objects in the attribute. Indeed there is only one stored object
265     int aCountAppened = aRefListAttr->size() - mySelectionCount;
266     for (int i = 0; i < aCountAppened; i++)
267       aRefListAttr->removeLast();
268   }
269   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
270     AttributeRefAttrListPtr aRefAttrListAttr =
271                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
272     // restore objects in the attribute. Indeed there is only one stored object
273     int aCountAppened = aRefAttrListAttr->size() - mySelectionCount;
274     for (int i = 0; i < aCountAppened; i++)
275       aRefAttrListAttr->removeLast();
276   }
277 }
278
279 //********************************************************************
280 void ModuleBase_WidgetMultiSelector::clearAttribute()
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->clear();
288   }
289   else if (aType == ModelAPI_AttributeRefList::typeId()) {
290     AttributeRefListPtr aRefListAttr =
291                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
292     aRefListAttr->clear();
293   }
294   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
295     AttributeRefAttrListPtr aRefAttrListAttr =
296                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
297     aRefAttrListAttr->clear();
298   }
299 }
300
301 //********************************************************************
302 void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
303                                                GeomShapePtr theShape)
304 {
305   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
306   std::string aType = anAttribute->attributeType();
307   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
308     AttributeSelectionListPtr aSelectionListAttr =
309                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
310     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
311     aSelectionListAttr->append(aResult, theShape, myIsInValidate);
312   }
313   else if (aType == ModelAPI_AttributeRefList::typeId()) {
314     AttributeRefListPtr aRefListAttr =
315                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
316     aRefListAttr->append(theSelectedObject);
317   }
318   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
319     AttributeRefAttrListPtr aRefAttrListAttr =
320                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
321
322     AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape);
323     if (anAttribute.get())
324       aRefAttrListAttr->append(anAttribute);
325     else
326       aRefAttrListAttr->append(theSelectedObject);
327   }
328 }
329
330 //********************************************************************
331 bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
332                                                   const bool theToValidate)
333 {
334   QList<ModuleBase_ViewerPrs> aSkippedValues;
335
336   QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
337   bool isDone = false;
338   for (; anIt != aLast; anIt++) {
339     ModuleBase_ViewerPrs aValue = *anIt;
340     bool aProcessed = false;
341     if (!theToValidate || isValidInFilters(aValue)) {
342       aProcessed = setSelectionCustom(aValue);
343     }
344     else
345       aSkippedValues.append(aValue);
346     // if there is at least one set, the result is true
347     isDone = isDone || aProcessed;
348   }
349   // updateObject - to update/redisplay feature
350   // it is commented in order to perfom it outside the method
351   //if (isDone) {
352     //updateObject(myFeature);
353     // this emit is necessary to call store/restore method an restore type of selection
354     //emit valuesChanged();
355   //}
356   theValues.clear();
357   if (!aSkippedValues.empty())
358     theValues.append(aSkippedValues);
359
360   return isDone;
361 }
362
363 //********************************************************************
364 void ModuleBase_WidgetMultiSelector::getHighlighted(QList<ModuleBase_ViewerPrs>& theValues)
365 {
366   std::set<int> anAttributeIds;
367   getSelectedAttributeIndices(anAttributeIds);
368   if (!anAttributeIds.empty())
369     convertIndicesToViewerSelection(anAttributeIds, theValues);
370 }
371
372 //********************************************************************
373 bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
374 {
375   bool aValid = ModuleBase_WidgetSelector::isValidSelectionCustom(thePrs);
376   if (aValid) {
377     ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
378     aValid = aResult.get() != NULL;
379     if (aValid) {
380       if (myFeature) {
381         // We can not select a result of our feature
382         const std::list<ResultPtr>& aResList = myFeature->results();
383         std::list<ResultPtr>::const_iterator aIt;
384         bool isSkipSelf = false;
385         for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
386           if ((*aIt) == aResult) {
387             isSkipSelf = true;
388             break;
389           }
390         }
391         if (isSkipSelf)
392           aValid = false;
393       }
394     }
395   }
396   return aValid;
397 }
398
399 //********************************************************************
400 bool ModuleBase_WidgetMultiSelector::processDelete()
401 {
402   // find attribute indices to delete
403   std::set<int> anAttributeIds;
404   getSelectedAttributeIndices(anAttributeIds);
405
406   // refill attribute by the items which indices are not in the list of ids
407   bool aDone = false;
408   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
409   std::string aType = anAttribute->attributeType();
410   aDone = !anAttributeIds.empty();
411   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
412     AttributeSelectionListPtr aSelectionListAttr =
413                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
414     aSelectionListAttr->remove(anAttributeIds);
415
416   }
417   else if (aType == ModelAPI_AttributeRefList::typeId()) {
418     AttributeRefListPtr aRefListAttr =
419                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
420       aRefListAttr->remove(anAttributeIds);
421   }
422   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
423     AttributeRefAttrListPtr aRefAttrListAttr =
424                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
425     aRefAttrListAttr->remove(anAttributeIds);
426   }
427
428   if (aDone) {
429     // update object is necessary to flush update signal. It leads to objects references map update
430     // and the operation presentation will not contain deleted items visualized as parameters of
431     // the feature.
432     updateObject(myFeature);
433
434     restoreValue();
435     myWorkshop->setSelected(getAttributeSelection());
436   }
437   return aDone;
438 }
439
440 //********************************************************************
441 QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
442 {
443   QList<QWidget*> result;
444   //result << myTypeCombo;
445   result << myListControl;
446   return result;
447 }
448
449 //********************************************************************
450 void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
451 {
452   activateSelectionAndFilters(true);
453   QList<ModuleBase_ViewerPrs> anEmptyList;
454   // This method will call Selection changed event which will call onSelectionChanged
455   // To clear mySelection, myListControl and storeValue()
456   // So, we don't need to call it
457   myWorkshop->setSelected(anEmptyList);
458 }
459
460 void ModuleBase_WidgetMultiSelector::updateFocus()
461 {
462   // Set focus to List control in order to make possible 
463   // to use Tab key for transfer the focus to next widgets
464   myListControl->setCurrentRow(myListControl->model()->rowCount() - 1);
465   ModuleBase_Tools::setFocus(myListControl,
466                              "ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()");
467 }
468
469 //********************************************************************
470 void ModuleBase_WidgetMultiSelector::updateSelectionName()
471 {
472 }
473
474 //********************************************************************
475 QIntList ModuleBase_WidgetMultiSelector::getShapeTypes() const
476 {
477   QIntList aShapeTypes;
478
479   if (myTypeCombo->count() > 1 && myIsUseChoice) {
480     aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->currentText()));
481   }
482   else {
483     for (int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) {
484       TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->itemText(i));
485       aShapeTypes.append(aType);
486       if (aType == TopAbs_SOLID)
487         aShapeTypes.append(TopAbs_COMPSOLID);
488     }
489   }
490   return aShapeTypes;
491 }
492
493 //********************************************************************
494 void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType)
495 {
496   QString aShapeTypeName;
497   
498   for (int idx = 0; idx < myTypeCombo->count(); ++idx) {
499     aShapeTypeName = myTypeCombo->itemText(idx);
500     TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
501     if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
502       activateSelectionAndFilters(false);
503       bool isBlocked = myTypeCombo->blockSignals(true);
504       myTypeCombo->setCurrentIndex(idx);
505       myTypeCombo->blockSignals(isBlocked);
506
507       activateSelectionAndFilters(true);
508       break;
509     }
510   }
511 }
512
513 QList<ModuleBase_ViewerPrs> ModuleBase_WidgetMultiSelector::getAttributeSelection() const
514 {
515   QList<ModuleBase_ViewerPrs> aSelected;
516   convertIndicesToViewerSelection(std::set<int>(), aSelected);
517   return aSelected;
518 }
519
520 //********************************************************************
521 void ModuleBase_WidgetMultiSelector::updateSelectionList()
522 {
523   myListControl->clear();
524
525   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
526   std::string aType = anAttribute->attributeType();
527   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
528     AttributeSelectionListPtr aSelectionListAttr =
529                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
530     for (int i = 0; i < aSelectionListAttr->size(); i++) {
531       AttributeSelectionPtr aAttr = aSelectionListAttr->value(i);
532       QListWidgetItem* anItem = new QListWidgetItem(aAttr->namingName().c_str(), myListControl);
533       anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
534       myListControl->addItem(anItem);
535     }
536   }
537   else if (aType == ModelAPI_AttributeRefList::typeId()) {
538     AttributeRefListPtr aRefListAttr =
539                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
540     for (int i = 0; i < aRefListAttr->size(); i++) {
541       ObjectPtr anObject = aRefListAttr->object(i);
542       if (anObject.get()) {
543         QListWidgetItem* anItem = new QListWidgetItem(anObject->data()->name().c_str(),
544                                                       myListControl);
545         anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
546         myListControl->addItem(anItem);
547       }
548     }
549   }
550   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
551     AttributeRefAttrListPtr aRefAttrListAttr =
552                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
553     for (int i = 0; i < aRefAttrListAttr->size(); i++) {
554       AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
555       QString aName;
556       if (anAttribute.get()) {
557         std::string anAttrName = generateName(anAttribute);
558         aName = QString::fromStdString(anAttrName);
559       }
560       else {
561         ObjectPtr anObject = aRefAttrListAttr->object(i);
562         if (anObject.get()) {
563           aName = anObject->data()->name().c_str();
564         }
565       }
566       QListWidgetItem* anItem = new QListWidgetItem(aName, myListControl);
567       anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
568       myListControl->addItem(anItem);
569     }
570   }
571
572   // We have to call repaint because sometimes the List control is not updated
573   myListControl->repaint();
574 }
575
576 //********************************************************************
577 std::string ModuleBase_WidgetMultiSelector::validatorType(const QString& theType) const
578 {
579   std::string aType;
580
581   if (theType == "Vertices")
582     aType = "vertex";
583   else if (theType == "Edges")
584     aType = "edge";
585   else if (theType == "Faces")
586     aType = "face";
587   else if (theType == "Solids")
588     aType = "solid";
589
590   return aType;
591 }
592
593 //********************************************************************
594 void ModuleBase_WidgetMultiSelector::onCopyItem()
595 {
596   QList<QListWidgetItem*> aItems = myListControl->selectedItems();
597   QString aRes;
598   foreach(QListWidgetItem* aItem, aItems) {
599     if (!aRes.isEmpty())
600       aRes += "\n";
601     aRes += aItem->text();
602   }
603   if (!aRes.isEmpty()) {
604     QClipboard *clipboard = QApplication::clipboard();
605     clipboard->setText(aRes);
606   }
607 }
608
609 //********************************************************************
610 void ModuleBase_WidgetMultiSelector::onDeleteItem()
611 {
612   processDelete();
613 }
614
615 //********************************************************************
616 void ModuleBase_WidgetMultiSelector::onListSelection()
617 {
618   QList<QListWidgetItem*> aItems = myListControl->selectedItems();
619   myCopyAction->setEnabled(!aItems.isEmpty());
620   myDeleteAction->setEnabled(!aItems.isEmpty());
621   
622   myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects,
623                                         true);
624 }
625
626 //********************************************************************
627 void ModuleBase_WidgetMultiSelector::getSelectedAttributeIndices(std::set<int>& theAttributeIds)
628 {
629   QList<QListWidgetItem*> aItems = myListControl->selectedItems();
630   foreach(QListWidgetItem* anItem, aItems) {
631     int anIndex = anItem->data(ATTRIBUTE_SELECTION_INDEX_ROLE).toInt();
632     if (theAttributeIds.find(anIndex) == theAttributeIds.end())
633       theAttributeIds.insert(anIndex);
634   }
635 }
636
637 void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<int> theAttributeIds,
638                                                       QList<ModuleBase_ViewerPrs>& theValues) const
639 {
640   if(myFeature.get() == NULL)
641     return;
642
643   AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
644   std::string aType = anAttribute->attributeType();
645   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
646     AttributeSelectionListPtr aSelectionListAttr =
647                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
648     for (int i = 0; i < aSelectionListAttr->size(); i++) {
649       // filter by attribute indices only if the container is not empty otherwise return all items
650       if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
651         continue;
652       AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
653       ResultPtr anObject = anAttr->context();
654       if (anObject.get()) {
655         TopoDS_Shape aShape;
656         std::shared_ptr<GeomAPI_Shape> aShapePtr = anAttr->value();
657         if (aShapePtr.get()) {
658           aShape = aShapePtr->impl<TopoDS_Shape>();
659         }
660         theValues.append(ModuleBase_ViewerPrs(anObject, aShape, NULL));
661       }
662     }
663   }
664   else if (aType == ModelAPI_AttributeRefList::typeId()) {
665     AttributeRefListPtr aRefListAttr =
666                  std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
667     for (int i = 0; i < aRefListAttr->size(); i++) {
668       // filter by attribute indices only if the container is not empty otherwise return all items
669       if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
670         continue;
671       ObjectPtr anObject = aRefListAttr->object(i);
672       if (anObject.get()) {
673         theValues.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL));
674       }
675     }
676   }
677   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
678     AttributeRefAttrListPtr aRefAttrListAttr =
679                  std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
680     for (int i = 0; i < aRefAttrListAttr->size(); i++) {
681       // filter by attribute indices only if the container is not empty otherwise return all items
682       if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
683         continue;
684       ObjectPtr anObject = aRefAttrListAttr->object(i);
685       if (!anObject.get())
686         continue;
687       TopoDS_Shape aShape;
688       AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
689       if (anAttribute.get()) {
690         GeomShapePtr aGeomShape = myWorkshop->module()->findShape(anAttribute);
691         if (aGeomShape.get()) {
692           aShape = aGeomShape->impl<TopoDS_Shape>();
693         }
694         theValues.append(ModuleBase_ViewerPrs(anObject, aShape, NULL));
695       }
696     }
697   }
698 }