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 = myFeature->data()->selectionList(attributeID());
193 aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
198 //********************************************************************
199 bool ModuleBase_WidgetMultiSelector::restoreValueCustom()
201 // A rare case when plugin was not loaded.
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 std::string aSelectionType = aSelectionListAttr->selectionType().c_str();
211 if (!aSelectionType.empty())
212 setCurrentShapeType(ModuleBase_Tools::shapeType(aSelectionType.c_str()));
214 updateSelectionList();
218 //********************************************************************
219 void ModuleBase_WidgetMultiSelector::storeAttributeValue()
221 ModuleBase_WidgetValidated::storeAttributeValue();
223 DataPtr aData = myFeature->data();
224 AttributePtr anAttribute = aData->attribute(attributeID());
225 std::string aType = anAttribute->attributeType();
226 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
227 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
228 mySelectionType = aSelectionListAttr->selectionType();
229 mySelectionCount = aSelectionListAttr->size();
231 else if (aType == ModelAPI_AttributeRefList::typeId()) {
232 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
233 mySelectionCount = aRefListAttr->size();
235 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
236 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
237 mySelectionCount = aRefAttrListAttr->size();
241 //********************************************************************
242 void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid)
244 ModuleBase_WidgetValidated::restoreAttributeValue(theValid);
246 DataPtr aData = myFeature->data();
247 AttributePtr anAttribute = aData->attribute(attributeID());
248 std::string aType = anAttribute->attributeType();
249 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
250 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
251 aSelectionListAttr->setSelectionType(mySelectionType);
253 // restore selection in the attribute. Indeed there is only one stored object
254 int aCountAppened = aSelectionListAttr->size() - mySelectionCount;
255 for (int i = 0; i < aCountAppened; i++)
256 aSelectionListAttr->removeLast();
258 else if (aType == ModelAPI_AttributeRefList::typeId()) {
259 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
260 // restore objects in the attribute. Indeed there is only one stored object
261 int aCountAppened = aRefListAttr->size() - mySelectionCount;
262 for (int i = 0; i < aCountAppened; i++)
263 aRefListAttr->removeLast();
265 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
266 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
267 // restore objects in the attribute. Indeed there is only one stored object
268 int aCountAppened = aRefAttrListAttr->size() - mySelectionCount;
269 for (int i = 0; i < aCountAppened; i++)
270 aRefAttrListAttr->removeLast();
274 //********************************************************************
275 void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
276 GeomShapePtr theShape)
278 DataPtr aData = myFeature->data();
279 AttributePtr anAttribute = aData->attribute(attributeID());
280 std::string aType = anAttribute->attributeType();
281 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
282 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
283 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
284 if (!aSelectionListAttr->isInList(aResult, theShape, myIsInValidate))
285 aSelectionListAttr->append(aResult, theShape, myIsInValidate);
287 else if (aType == ModelAPI_AttributeRefList::typeId()) {
288 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
289 if (!aRefListAttr->isInList(theSelectedObject))
290 aRefListAttr->append(theSelectedObject);
292 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
293 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
294 AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape);
296 if (anAttribute.get()) {
297 if (!aRefAttrListAttr->isInList(anAttribute))
298 aRefAttrListAttr->append(anAttribute);
301 if (!aRefAttrListAttr->isInList(theSelectedObject))
302 aRefAttrListAttr->append(theSelectedObject);
307 //********************************************************************
308 bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
309 const bool theToValidate)
311 QList<ModuleBase_ViewerPrs> aSkippedValues;
313 /// remove unused objects from the model attribute.
314 /// It should be performed before new attributes append.
315 removeUnusedAttributeObjects(theValues);
317 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
319 for (; anIt != aLast; anIt++) {
320 ModuleBase_ViewerPrs aValue = *anIt;
321 bool aProcessed = false;
322 if (!theToValidate || isValidInFilters(aValue)) {
323 aProcessed = setSelectionCustom(aValue);
326 aSkippedValues.append(aValue);
327 // if there is at least one set, the result is true
328 isDone = isDone || aProcessed;
330 // updateObject - to update/redisplay feature
331 // it is commented in order to perfom it outside the method
333 //updateObject(myFeature);
334 // this emit is necessary to call store/restore method an restore type of selection
335 //emit valuesChanged();
338 /// remove unused objects from the model attribute
339 //removeUnusedAttributeObjects(theValues);
342 if (!aSkippedValues.empty())
343 theValues.append(aSkippedValues);
348 //********************************************************************
349 void ModuleBase_WidgetMultiSelector::getHighlighted(QList<ModuleBase_ViewerPrs>& theValues)
351 std::set<int> anAttributeIds;
352 getSelectedAttributeIndices(anAttributeIds);
353 if (!anAttributeIds.empty())
354 convertIndicesToViewerSelection(anAttributeIds, theValues);
357 //********************************************************************
358 bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
360 bool aValid = ModuleBase_WidgetSelector::isValidSelectionCustom(thePrs);
362 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
363 aValid = aResult.get() != NULL;
366 // We can not select a result of our feature
367 const std::list<ResultPtr>& aResList = myFeature->results();
368 std::list<ResultPtr>::const_iterator aIt;
369 bool isSkipSelf = false;
370 for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
371 if ((*aIt) == aResult) {
384 //********************************************************************
385 bool ModuleBase_WidgetMultiSelector::processDelete()
387 // find attribute indices to delete
388 std::set<int> anAttributeIds;
389 getSelectedAttributeIndices(anAttributeIds);
391 // refill attribute by the items which indices are not in the list of ids
393 DataPtr aData = myFeature->data();
394 AttributePtr anAttribute = aData->attribute(attributeID());
395 std::string aType = anAttribute->attributeType();
396 aDone = !anAttributeIds.empty();
397 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
398 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
399 aSelectionListAttr->remove(anAttributeIds);
402 else if (aType == ModelAPI_AttributeRefList::typeId()) {
403 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
404 aRefListAttr->remove(anAttributeIds);
406 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
407 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
408 aRefAttrListAttr->remove(anAttributeIds);
412 // update object is necessary to flush update signal. It leads to objects references map update
413 // and the operation presentation will not contain deleted items visualized as parameters of
415 updateObject(myFeature);
418 myWorkshop->setSelected(getAttributeSelection());
423 //********************************************************************
424 QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
426 QList<QWidget*> result;
427 //result << myTypeCombo;
428 result << myListControl;
432 //********************************************************************
433 void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
435 activateSelectionAndFilters(true);
436 QList<ModuleBase_ViewerPrs> anEmptyList;
437 // This method will call Selection changed event which will call onSelectionChanged
438 // To clear mySelection, myListControl and storeValue()
439 // So, we don't need to call it
440 myWorkshop->setSelected(anEmptyList);
443 void ModuleBase_WidgetMultiSelector::updateFocus()
445 // Set focus to List control in order to make possible
446 // to use Tab key for transfer the focus to next widgets
447 myListControl->setCurrentRow(myListControl->model()->rowCount() - 1);
448 ModuleBase_Tools::setFocus(myListControl,
449 "ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()");
452 //********************************************************************
453 void ModuleBase_WidgetMultiSelector::updateSelectionName()
457 //********************************************************************
458 QIntList ModuleBase_WidgetMultiSelector::getShapeTypes() const
460 QIntList aShapeTypes;
462 if (myTypeCombo->count() > 1 && myIsUseChoice) {
463 aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->currentText()));
466 for (int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) {
467 TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->itemText(i));
468 aShapeTypes.append(aType);
469 if (aType == TopAbs_SOLID)
470 aShapeTypes.append(TopAbs_COMPSOLID);
476 //********************************************************************
477 void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType)
479 QString aShapeTypeName;
481 for (int idx = 0; idx < myTypeCombo->count(); ++idx) {
482 aShapeTypeName = myTypeCombo->itemText(idx);
483 TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
484 if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
485 activateSelectionAndFilters(false);
486 bool isBlocked = myTypeCombo->blockSignals(true);
487 myTypeCombo->setCurrentIndex(idx);
488 myTypeCombo->blockSignals(isBlocked);
490 activateSelectionAndFilters(true);
496 QList<ModuleBase_ViewerPrs> ModuleBase_WidgetMultiSelector::getAttributeSelection() const
498 QList<ModuleBase_ViewerPrs> aSelected;
499 convertIndicesToViewerSelection(std::set<int>(), aSelected);
503 //********************************************************************
504 void ModuleBase_WidgetMultiSelector::updateSelectionList()
506 myListControl->clear();
508 DataPtr aData = myFeature->data();
509 AttributePtr anAttribute = aData->attribute(attributeID());
510 std::string aType = anAttribute->attributeType();
511 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
512 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
513 for (int i = 0; i < aSelectionListAttr->size(); i++) {
514 AttributeSelectionPtr aAttr = aSelectionListAttr->value(i);
515 QListWidgetItem* anItem = new QListWidgetItem(aAttr->namingName().c_str(), myListControl);
516 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
517 myListControl->addItem(anItem);
520 else if (aType == ModelAPI_AttributeRefList::typeId()) {
521 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
522 for (int i = 0; i < aRefListAttr->size(); i++) {
523 ObjectPtr anObject = aRefListAttr->object(i);
524 if (anObject.get()) {
525 QListWidgetItem* anItem = new QListWidgetItem(anObject->data()->name().c_str(),
527 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
528 myListControl->addItem(anItem);
532 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
533 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
534 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
535 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
537 if (anAttribute.get()) {
538 std::string anAttrName = generateName(anAttribute, myWorkshop);
539 aName = QString::fromStdString(anAttrName);
542 ObjectPtr anObject = aRefAttrListAttr->object(i);
543 if (anObject.get()) {
544 aName = anObject->data()->name().c_str();
547 QListWidgetItem* anItem = new QListWidgetItem(aName, myListControl);
548 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
549 myListControl->addItem(anItem);
553 // We have to call repaint because sometimes the List control is not updated
554 myListControl->repaint();
557 //********************************************************************
558 std::string ModuleBase_WidgetMultiSelector::validatorType(const QString& theType) const
562 if (theType == "Vertices")
564 else if (theType == "Edges")
566 else if (theType == "Faces")
568 else if (theType == "Solids")
574 //********************************************************************
575 void ModuleBase_WidgetMultiSelector::onCopyItem()
577 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
579 foreach(QListWidgetItem* aItem, aItems) {
582 aRes += aItem->text();
584 if (!aRes.isEmpty()) {
585 QClipboard *clipboard = QApplication::clipboard();
586 clipboard->setText(aRes);
590 //********************************************************************
591 void ModuleBase_WidgetMultiSelector::onDeleteItem()
596 //********************************************************************
597 void ModuleBase_WidgetMultiSelector::onListSelection()
599 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
600 myCopyAction->setEnabled(!aItems.isEmpty());
601 myDeleteAction->setEnabled(!aItems.isEmpty());
603 myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects,
607 //********************************************************************
608 void ModuleBase_WidgetMultiSelector::getSelectedAttributeIndices(std::set<int>& theAttributeIds)
610 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
611 foreach(QListWidgetItem* anItem, aItems) {
612 int anIndex = anItem->data(ATTRIBUTE_SELECTION_INDEX_ROLE).toInt();
613 if (theAttributeIds.find(anIndex) == theAttributeIds.end())
614 theAttributeIds.insert(anIndex);
618 void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<int> theAttributeIds,
619 QList<ModuleBase_ViewerPrs>& theValues) const
621 if(myFeature.get() == NULL)
624 DataPtr aData = myFeature->data();
625 AttributePtr anAttribute = aData->attribute(attributeID());
626 std::string aType = anAttribute->attributeType();
627 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
628 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
629 for (int i = 0; i < aSelectionListAttr->size(); i++) {
630 // filter by attribute indices only if the container is not empty otherwise return all items
631 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
633 AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
634 ResultPtr anObject = anAttr->context();
635 if (anObject.get()) {
637 std::shared_ptr<GeomAPI_Shape> aShapePtr = anAttr->value();
638 if (aShapePtr.get()) {
639 aShape = aShapePtr->impl<TopoDS_Shape>();
641 theValues.append(ModuleBase_ViewerPrs(anObject, aShape, NULL));
645 else if (aType == ModelAPI_AttributeRefList::typeId()) {
646 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
647 for (int i = 0; i < aRefListAttr->size(); i++) {
648 // filter by attribute indices only if the container is not empty otherwise return all items
649 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
651 ObjectPtr anObject = aRefListAttr->object(i);
652 if (anObject.get()) {
653 theValues.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL));
657 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
658 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
659 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
660 // filter by attribute indices only if the container is not empty otherwise return all items
661 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
663 ObjectPtr anObject = aRefAttrListAttr->object(i);
667 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
668 if (anAttribute.get()) {
669 GeomShapePtr aGeomShape = myWorkshop->module()->findShape(anAttribute);
670 if (aGeomShape.get()) {
671 aShape = aGeomShape->impl<TopoDS_Shape>();
673 theValues.append(ModuleBase_ViewerPrs(anObject, aShape, NULL));
679 void ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
680 (QList<ModuleBase_ViewerPrs>& theValues)
682 std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection = convertSelection(theValues);
683 DataPtr aData = myFeature->data();
684 AttributePtr anAttribute = aData->attribute(attributeID());
685 std::string aType = anAttribute->attributeType();
686 std::set<GeomShapePtr> aShapes;
687 std::set<int> anIndicesToBeRemoved;
688 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
689 // iteration through data model to find not selected elements to remove them
690 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
691 for (int i = 0; i < aSelectionListAttr->size(); i++) {
692 AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
693 bool aFound = findInSelection(anAttr->context(), anAttr->value(), aGeomSelection);
695 anIndicesToBeRemoved.insert(i);
697 aSelectionListAttr->remove(anIndicesToBeRemoved);
699 else if (aType == ModelAPI_AttributeRefList::typeId()) {
700 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
701 for (int i = 0; i < aRefListAttr->size(); i++) {
702 ObjectPtr anObject = aRefListAttr->object(i);
703 if (anObject.get()) {
704 bool aFound = findInSelection(anObject, GeomShapePtr(), aGeomSelection);
706 anIndicesToBeRemoved.insert(i);
709 aRefListAttr->remove(anIndicesToBeRemoved);
711 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
712 std::set<AttributePtr> anAttributes;
713 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
716 for (; anIt != aLast; anIt++) {
717 ModuleBase_ViewerPrs aPrs = *anIt;
718 getGeomSelection(aPrs, anObject, aShape);
719 AttributePtr anAttr = myWorkshop->module()->findAttribute(anObject, aShape);
720 if (anAttr.get() && anAttributes.find(anAttr) == anAttributes.end())
721 anAttributes.insert(anAttr);
724 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
725 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
727 if (aRefAttrListAttr->isAttribute(i)) {
728 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
729 aFound = anAttributes.find(anAttribute) != anAttributes.end();
732 aFound = findInSelection(aRefAttrListAttr->object(i), GeomShapePtr(), aGeomSelection);
735 anIndicesToBeRemoved.insert(i);
737 aRefAttrListAttr->remove(anIndicesToBeRemoved);
741 std::map<ObjectPtr, std::set<GeomShapePtr> > ModuleBase_WidgetMultiSelector::convertSelection
742 (QList<ModuleBase_ViewerPrs>& theValues)
744 // convert prs list to objects map
745 std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection;
746 std::set<GeomShapePtr> aShapes;
747 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
750 GeomShapePtr anEmptyShape(new GeomAPI_Shape());
751 for (; anIt != aLast; anIt++) {
752 ModuleBase_ViewerPrs aPrs = *anIt;
753 getGeomSelection(aPrs, anObject, aShape);
755 if (aGeomSelection.find(anObject) != aGeomSelection.end()) // found
756 aShapes = aGeomSelection[anObject];
757 // we need to know if there was an empty shape in selection for the object
759 aShape = anEmptyShape;
760 if (aShape.get() && aShapes.find(aShape) == aShapes.end()) // not found
761 aShapes.insert(aShape);
762 aGeomSelection[anObject] = aShapes;
764 return aGeomSelection;
767 bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject,
768 const GeomShapePtr& theShape,
769 const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection)
772 GeomShapePtr anEmptyShape(new GeomAPI_Shape());
773 GeomShapePtr aShape = theShape.get() ? theShape : anEmptyShape;
774 if (theGeomSelection.find(theObject) != theGeomSelection.end()) {// found
775 const std::set<GeomShapePtr>& aShapes = theGeomSelection.at(theObject);
776 std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
777 for (; anIt != aLast && !aFound; anIt++) {
778 GeomShapePtr aCShape = *anIt;
780 aFound = aCShape->isEqual(aShape);