1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ModuleBase_WidgetMultiSelector.cpp
6 * Created on: Aug 28, 2014
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>
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>
25 #include <Config_WidgetAPI.h>
27 #include <QGridLayout>
29 #include <QListWidget>
35 #include <QApplication>
42 const int ATTRIBUTE_SELECTION_INDEX_ROLE = Qt::UserRole + 1;
45 * Customization of a List Widget to make it to be placed on full width of container
47 class CustomListWidget : public QListWidget
51 /// \param theParent a parent widget
52 CustomListWidget( QWidget* theParent )
53 : QListWidget( theParent )
57 /// Redefinition of virtual method
58 virtual QSize sizeHint() const
60 int aHeight = 2*QFontMetrics( font() ).height();
61 QSize aSize = QListWidget::sizeHint();
62 return QSize( aSize.width(), aHeight );
65 /// Redefinition of virtual method
66 virtual QSize minimumSizeHint() const
68 int aHeight = 4/*2*/*QFontMetrics( font() ).height();
69 QSize aSize = QListWidget::minimumSizeHint();
70 return QSize( aSize.width(), aHeight );
74 // The code is necessary only for Linux because
75 //it can not update viewport on widget resize
77 void resizeEvent(QResizeEvent* theEvent)
79 QListWidget::resizeEvent(theEvent);
80 QTimer::singleShot(5, viewport(), SLOT(repaint()));
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),
92 QGridLayout* aMainLay = new QGridLayout(this);
93 ModuleBase_Tools::adjustMargins(aMainLay);
95 QLabel* aTypeLabel = new QLabel(tr("Type"), this);
96 aMainLay->addWidget(aTypeLabel, 0, 0);
98 myTypeCombo = new QComboBox(this);
99 // There is no sense to parameterize list of types while we can not parameterize selection mode
101 std::string aPropertyTypes = theData->getProperty("type_choice");
102 QString aTypesStr = aPropertyTypes.c_str();
103 QStringList aShapeTypes = aTypesStr.split(' ', QString::SkipEmptyParts);
105 myIsUseChoice = theData->getBooleanAttribute("use_choice", true);
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);
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);
128 aMainLay->setColumnStretch(2, 1);
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);
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()));
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);
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);
156 myListControl->setContextMenuPolicy(Qt::ActionsContextMenu);
157 connect(myListControl, SIGNAL(itemSelectionChanged()), SLOT(onListSelection()));
160 ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector()
164 //********************************************************************
165 void ModuleBase_WidgetMultiSelector::activateCustom()
167 ModuleBase_WidgetSelector::activateCustom();
169 myWorkshop->module()->activateCustomPrs(myFeature,
170 ModuleBase_IModule::CustomizeHighlightedObjects, true);
173 //********************************************************************
174 void ModuleBase_WidgetMultiSelector::deactivate()
176 ModuleBase_WidgetSelector::deactivate();
178 myWorkshop->module()->deactivateCustomPrs(ModuleBase_IModule::CustomizeHighlightedObjects, true);
181 //********************************************************************
182 bool ModuleBase_WidgetMultiSelector::storeValueCustom() const
184 // the value is stored on the selection changed signal processing
185 // A rare case when plugin was not loaded.
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());
199 //********************************************************************
200 bool ModuleBase_WidgetMultiSelector::restoreValueCustom()
202 // A rare case when plugin was not loaded.
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()));
214 updateSelectionList();
218 //********************************************************************
219 void ModuleBase_WidgetMultiSelector::storeAttributeValue()
221 ModuleBase_WidgetValidated::storeAttributeValue();
223 AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
224 std::string aType = anAttribute->attributeType();
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();
232 else if (aType == ModelAPI_AttributeRefList::typeId()) {
233 AttributeRefListPtr aRefListAttr =
234 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
235 mySelectionCount = aRefListAttr->size();
237 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
238 AttributeRefAttrListPtr aRefAttrListAttr =
239 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
240 mySelectionCount = aRefAttrListAttr->size();
244 //********************************************************************
245 bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
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);
254 if (!thePrs.shape().IsNull()) {
255 GeomShapePtr aGeomShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
256 aGeomShape->setImpl(new TopoDS_Shape(thePrs.shape()));
258 AttributePtr anAttribute = myWorkshop->module()->findAttribute(thePrs.object(), aGeomShape);
259 if (anAttribute.get()) {
260 aRefAttrListAttr->append(anAttribute);
265 ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
268 ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
269 /*ObjectPtr anObject;
271 getGeomSelection(thePrs, anObject, aShape);
272 setObject(anObject, aShape);*/
277 //********************************************************************
278 void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid)
280 ModuleBase_WidgetValidated::restoreAttributeValue(theValid);
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);
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();
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();
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();
312 //********************************************************************
313 void ModuleBase_WidgetMultiSelector::clearAttribute()
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();
322 else if (aType == ModelAPI_AttributeRefList::typeId()) {
323 AttributeRefListPtr aRefListAttr =
324 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
325 aRefListAttr->clear();
327 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
328 AttributeRefAttrListPtr aRefAttrListAttr =
329 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
330 aRefAttrListAttr->clear();
334 //********************************************************************
335 void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
336 GeomShapePtr theShape)
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);
346 else if (aType == ModelAPI_AttributeRefList::typeId()) {
347 AttributeRefListPtr aRefListAttr =
348 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
349 aRefListAttr->append(theSelectedObject);
351 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
352 //AttributeRefAttrListPtr aRefAttrListAttr =
353 // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
354 //aRefAttrListAttr->clear();
358 //********************************************************************
359 bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
360 const bool theToValidate)
362 QList<ModuleBase_ViewerPrs> aSkippedValues;
364 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
366 for (; anIt != aLast; anIt++) {
367 ModuleBase_ViewerPrs aValue = *anIt;
368 bool aProcessed = false;
369 if (!theToValidate || isValidInFilters(aValue)) {
370 aProcessed = setSelectionCustom(aValue);
373 aSkippedValues.append(aValue);
374 // if there is at least one set, the result is true
375 isDone = isDone || aProcessed;
377 // updateObject - to update/redisplay feature
378 // it is commented in order to perfom it outside the method
380 //updateObject(myFeature);
381 // this emit is necessary to call store/restore method an restore type of selection
382 //emit valuesChanged();
385 if (!aSkippedValues.empty())
386 theValues.append(aSkippedValues);
391 //********************************************************************
392 void ModuleBase_WidgetMultiSelector::getHighlighted(QList<ModuleBase_ViewerPrs>& theValues)
394 std::set<int> anAttributeIds;
395 getSelectedAttributeIndices(anAttributeIds);
396 if (!anAttributeIds.empty())
397 convertIndicesToViewerSelection(anAttributeIds, theValues);
400 //********************************************************************
401 bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
403 bool aValid = ModuleBase_WidgetSelector::isValidSelectionCustom(thePrs);
405 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
406 aValid = aResult.get() != NULL;
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) {
427 //********************************************************************
428 bool ModuleBase_WidgetMultiSelector::processDelete()
430 // find attribute indices to delete
431 std::set<int> anAttributeIds;
432 getSelectedAttributeIndices(anAttributeIds);
434 // refill attribute by the items which indices are not in the list of ids
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);
445 else if (aType == ModelAPI_AttributeRefList::typeId()) {
446 AttributeRefListPtr aRefListAttr =
447 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttribute);
448 aRefListAttr->remove(anAttributeIds);
450 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
451 AttributeRefAttrListPtr aRefAttrListAttr =
452 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
453 aRefAttrListAttr->remove(anAttributeIds);
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
460 updateObject(myFeature);
463 myWorkshop->setSelected(getAttributeSelection());
468 //********************************************************************
469 QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
471 QList<QWidget*> result;
472 //result << myTypeCombo;
473 result << myListControl;
477 //********************************************************************
478 void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
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);
488 void ModuleBase_WidgetMultiSelector::updateFocus()
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()");
497 //********************************************************************
498 void ModuleBase_WidgetMultiSelector::updateSelectionName()
502 //********************************************************************
503 QIntList ModuleBase_WidgetMultiSelector::getShapeTypes() const
505 QIntList aShapeTypes;
507 if (myTypeCombo->count() > 1 && myIsUseChoice) {
508 aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->currentText()));
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);
521 //********************************************************************
522 void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType)
524 QString aShapeTypeName;
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);
535 activateSelectionAndFilters(true);
541 QList<ModuleBase_ViewerPrs> ModuleBase_WidgetMultiSelector::getAttributeSelection() const
543 QList<ModuleBase_ViewerPrs> aSelected;
544 convertIndicesToViewerSelection(std::set<int>(), aSelected);
548 //********************************************************************
549 void ModuleBase_WidgetMultiSelector::updateSelectionList()
551 myListControl->clear();
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);
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(),
573 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
574 myListControl->addItem(anItem);
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);
584 if (anAttribute.get()) {
585 std::string anAttrName = generateName(anAttribute);
586 aName = QString::fromStdString(anAttrName);
589 ObjectPtr anObject = aRefAttrListAttr->object(i);
590 if (anObject.get()) {
591 aName = anObject->data()->name().c_str();
594 QListWidgetItem* anItem = new QListWidgetItem(aName, myListControl);
595 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
596 myListControl->addItem(anItem);
600 // We have to call repaint because sometimes the List control is not updated
601 myListControl->repaint();
604 //********************************************************************
605 std::string ModuleBase_WidgetMultiSelector::validatorType(const QString& theType) const
609 if (theType == "Vertices")
611 else if (theType == "Edges")
613 else if (theType == "Faces")
615 else if (theType == "Solids")
621 //********************************************************************
622 void ModuleBase_WidgetMultiSelector::onCopyItem()
624 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
626 foreach(QListWidgetItem* aItem, aItems) {
629 aRes += aItem->text();
631 if (!aRes.isEmpty()) {
632 QClipboard *clipboard = QApplication::clipboard();
633 clipboard->setText(aRes);
637 //********************************************************************
638 void ModuleBase_WidgetMultiSelector::onDeleteItem()
643 //********************************************************************
644 void ModuleBase_WidgetMultiSelector::onListSelection()
646 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
647 myCopyAction->setEnabled(!aItems.isEmpty());
648 myDeleteAction->setEnabled(!aItems.isEmpty());
650 myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects,
654 //********************************************************************
655 void ModuleBase_WidgetMultiSelector::getSelectedAttributeIndices(std::set<int>& theAttributeIds)
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);
665 void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<int> theAttributeIds,
666 QList<ModuleBase_ViewerPrs>& theValues) const
668 if(myFeature.get() == NULL)
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())
680 AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
681 ResultPtr anObject = anAttr->context();
682 if (anObject.get()) {
684 std::shared_ptr<GeomAPI_Shape> aShapePtr = anAttr->value();
685 if (aShapePtr.get()) {
686 aShape = aShapePtr->impl<TopoDS_Shape>();
688 theValues.append(ModuleBase_ViewerPrs(anObject, aShape, NULL));
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())
699 ObjectPtr anObject = aRefListAttr->object(i);
700 if (anObject.get()) {
701 theValues.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL));
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())
712 ObjectPtr anObject = aRefAttrListAttr->object(i);
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>();
722 theValues.append(ModuleBase_ViewerPrs(anObject, aShape, NULL));