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