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>
18 #include <ModuleBase_ViewerPrs.h>
19 #include <ModuleBase_IconFactory.h>
21 #include <ModelAPI_Data.h>
22 #include <ModelAPI_Object.h>
23 #include <ModelAPI_AttributeSelectionList.h>
24 #include <ModelAPI_AttributeRefList.h>
25 #include <ModelAPI_AttributeRefAttrList.h>
26 #include <ModelAPI_Tools.h>
28 #include <Config_WidgetAPI.h>
30 #include <QGridLayout>
32 #include <QListWidget>
38 #include <QApplication>
45 const int ATTRIBUTE_SELECTION_INDEX_ROLE = Qt::UserRole + 1;
48 * Customization of a List Widget to make it to be placed on full width of container
50 class CustomListWidget : public QListWidget
54 /// \param theParent a parent widget
55 CustomListWidget( QWidget* theParent )
56 : QListWidget( theParent )
60 /// Redefinition of virtual method
61 virtual QSize sizeHint() const
63 int aHeight = 2*QFontMetrics( font() ).height();
64 QSize aSize = QListWidget::sizeHint();
65 return QSize( aSize.width(), aHeight );
68 /// Redefinition of virtual method
69 virtual QSize minimumSizeHint() const
71 int aHeight = 4/*2*/*QFontMetrics( font() ).height();
72 QSize aSize = QListWidget::minimumSizeHint();
73 return QSize( aSize.width(), aHeight );
77 // The code is necessary only for Linux because
78 //it can not update viewport on widget resize
80 void resizeEvent(QResizeEvent* theEvent)
82 QListWidget::resizeEvent(theEvent);
83 QTimer::singleShot(5, viewport(), SLOT(repaint()));
88 ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
89 ModuleBase_IWorkshop* theWorkshop,
90 const Config_WidgetAPI* theData)
91 : ModuleBase_WidgetSelector(theParent, theWorkshop, theData)
93 QGridLayout* aMainLay = new QGridLayout(this);
94 ModuleBase_Tools::adjustMargins(aMainLay);
96 QLabel* aTypeLabel = new QLabel(tr("Type"), this);
97 aMainLay->addWidget(aTypeLabel, 0, 0);
99 myTypeCombo = new QComboBox(this);
100 // There is no sense to parameterize list of types while we can not parameterize selection mode
102 std::string aPropertyTypes = theData->getProperty("type_choice");
103 QString aTypesStr = aPropertyTypes.c_str();
104 QStringList aShapeTypes = aTypesStr.split(' ', QString::SkipEmptyParts);
106 myIsUseChoice = theData->getBooleanAttribute("use_choice", false);
108 if (!aShapeTypes.empty())
109 myTypeCombo->addItems(aShapeTypes);
110 aMainLay->addWidget(myTypeCombo, 0, 1);
111 // if the xml definition contains one type, the controls to select a type should not be shown
112 if (aShapeTypes.size() <= 1 || !myIsUseChoice) {
113 aTypeLabel->setVisible(false);
114 myTypeCombo->setVisible(false);
117 std::string aLabelText = theData->getProperty("label");
118 QLabel* aListLabel = new QLabel(!aLabelText.empty() ? aLabelText.c_str()
119 : tr("Selected objects:"), this);
120 aMainLay->addWidget(aListLabel, 1, 0);
121 // if the xml definition contains one type, an information label should be shown near to the latest
122 if (aShapeTypes.size() <= 1) {
123 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
124 if (!aLabelIcon.isEmpty()) {
125 QLabel* aSelectedLabel = new QLabel("", this);
126 aSelectedLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
127 aMainLay->addWidget(aSelectedLabel, 1, 1);
129 aMainLay->setColumnStretch(2, 1);
132 QString aToolTip = QString::fromStdString(theData->widgetTooltip());
133 myListControl = new CustomListWidget(this);
134 QString anObjName = QString::fromStdString(attributeID());
135 myListControl->setObjectName(anObjName);
136 myListControl->setToolTip(aToolTip);
137 myListControl->setSelectionMode(QAbstractItemView::ExtendedSelection);
139 aMainLay->addWidget(myListControl, 2, 0, 1, -1);
140 aMainLay->setRowStretch(2, 1);
141 //aMainLay->addWidget(new QLabel(this)); //FIXME(sbh)???
142 //aMainLay->setRowMinimumHeight(3, 20);
143 //this->setLayout(aMainLay);
144 connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectionTypeChanged()));
146 myCopyAction = new QAction(QIcon(":pictures/copy.png"), tr("Copy"), this);
147 myCopyAction->setShortcut(QKeySequence::Copy);
148 myCopyAction->setEnabled(false);
149 connect(myCopyAction, SIGNAL(triggered(bool)), SLOT(onCopyItem()));
150 myListControl->addAction(myCopyAction);
152 myDeleteAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this);
153 myDeleteAction->setEnabled(false);
154 connect(myDeleteAction, SIGNAL(triggered(bool)), SLOT(onDeleteItem()));
155 myListControl->addAction(myDeleteAction);
157 myListControl->setContextMenuPolicy(Qt::ActionsContextMenu);
158 connect(myListControl, SIGNAL(itemSelectionChanged()), SLOT(onListSelection()));
160 myIsNeutralPointClear = theData->getBooleanAttribute("clear_in_neutral_point", true);
163 ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector()
167 //********************************************************************
168 void ModuleBase_WidgetMultiSelector::activateCustom()
170 ModuleBase_WidgetSelector::activateCustom();
172 myWorkshop->module()->activateCustomPrs(myFeature,
173 ModuleBase_IModule::CustomizeHighlightedObjects, true);
176 //********************************************************************
177 void ModuleBase_WidgetMultiSelector::deactivate()
179 ModuleBase_WidgetSelector::deactivate();
181 myWorkshop->module()->deactivateCustomPrs(ModuleBase_IModule::CustomizeHighlightedObjects, true);
184 //********************************************************************
185 bool ModuleBase_WidgetMultiSelector::storeValueCustom()
187 // the value is stored on the selection changed signal processing
188 // A rare case when plugin was not loaded.
192 AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
193 std::string aType = anAttribute->attributeType();
194 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
195 AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
196 aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
201 //********************************************************************
202 bool ModuleBase_WidgetMultiSelector::restoreValueCustom()
204 // A rare case when plugin was not loaded.
208 AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
209 std::string aType = anAttribute->attributeType();
210 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
211 AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
212 // Restore shape type
213 std::string aSelectionType = aSelectionListAttr->selectionType().c_str();
214 if (!aSelectionType.empty())
215 setCurrentShapeType(ModuleBase_Tools::shapeType(aSelectionType.c_str()));
217 updateSelectionList();
221 //********************************************************************
222 bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
223 const bool theToValidate)
225 AttributeSelectionListPtr aSelectionListAttr;
226 if (attribute()->attributeType() == ModelAPI_AttributeSelectionList::typeId())
227 aSelectionListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(attribute());
228 if (aSelectionListAttr.get())
229 aSelectionListAttr->cashValues(true);
231 /// remove unused objects from the model attribute.
232 /// It should be performed before new attributes append.
233 bool isDone = removeUnusedAttributeObjects(theValues);
235 QList<ModuleBase_ViewerPrsPtr> anInvalidValues;
236 QList<ModuleBase_ViewerPrsPtr> anAttributeValues;
237 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
238 for (; anIt != aLast; anIt++) {
239 ModuleBase_ViewerPrsPtr aValue = *anIt;
240 // do not validate and append to attribute selection presentation if it exists in the attribute
243 getGeomSelection(aValue, anObject, aShape);
244 if (ModuleBase_Tools::hasObject(attribute(), anObject, aShape, myWorkshop, myIsInValidate)) {
245 anAttributeValues.append(aValue);
248 if (theToValidate && !isValidInFilters(aValue))
249 anInvalidValues.append(aValue);
251 bool aHasInvalidValues = anInvalidValues.size() > 0;
253 for (anIt = theValues.begin(); anIt != aLast; anIt++) {
254 ModuleBase_ViewerPrsPtr aValue = *anIt;
255 bool aProcessed = false;
256 if ((aHasInvalidValues && anInvalidValues.contains(aValue)) ||
257 anAttributeValues.contains(aValue))
259 aProcessed = setSelectionCustom(aValue); /// it is not optimal as hasObject() is already checked
260 // if there is at least one set, the result is true
261 isDone = isDone || aProcessed;
263 // updateObject - to update/redisplay feature
264 // it is commented in order to perfom it outside the method
266 //updateObject(myFeature);
267 // this emit is necessary to call store/restore method an restore type of selection
268 //emit valuesChanged();
271 if (aSelectionListAttr.get())
272 aSelectionListAttr->cashValues(false);
275 if (!anInvalidValues.empty())
276 theValues.append(anInvalidValues);
278 if (isDone) // may be the feature's result is not displayed, but attributes should be
279 myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments,
280 true);/// hope that something is redisplayed by object updated
285 //********************************************************************
286 void ModuleBase_WidgetMultiSelector::getHighlighted(QList<ModuleBase_ViewerPrsPtr>& theValues)
288 std::set<int> anAttributeIds;
289 getSelectedAttributeIndices(anAttributeIds);
290 if (!anAttributeIds.empty())
291 convertIndicesToViewerSelection(anAttributeIds, theValues);
294 //********************************************************************
295 bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
297 bool aValid = ModuleBase_WidgetSelector::isValidSelectionCustom(thePrs);
299 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
300 aValid = aResult.get() != NULL;
303 // We can not select a result of our feature
304 const std::list<ResultPtr>& aResList = myFeature->results();
305 std::list<ResultPtr>::const_iterator aIt;
306 bool isSkipSelf = false;
307 for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
308 if ((*aIt) == aResult) {
321 //********************************************************************
322 bool ModuleBase_WidgetMultiSelector::processDelete()
324 // find attribute indices to delete
325 std::set<int> anAttributeIds;
326 getSelectedAttributeIndices(anAttributeIds);
328 QModelIndexList aIndexes = myListControl->selectionModel()->selectedIndexes();
329 //foreach(QModelIndex aIndex, aIndexes) {
333 // refill attribute by the items which indices are not in the list of ids
335 DataPtr aData = myFeature->data();
336 AttributePtr anAttribute = aData->attribute(attributeID());
337 std::string aType = anAttribute->attributeType();
338 aDone = !anAttributeIds.empty();
339 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
340 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
341 aSelectionListAttr->remove(anAttributeIds);
344 else if (aType == ModelAPI_AttributeRefList::typeId()) {
345 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
346 aRefListAttr->remove(anAttributeIds);
348 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
349 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
350 aRefAttrListAttr->remove(anAttributeIds);
354 // update object is necessary to flush update signal. It leads to objects references map update
355 // and the operation presentation will not contain deleted items visualized as parameters of
357 updateObject(myFeature);
360 myWorkshop->setSelected(getAttributeSelection());
362 // may be the feature's result is not displayed, but attributes should be
363 myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments,
364 true); /// hope that something is redisplayed by object updated
366 foreach(QModelIndex aIndex, aIndexes) {
367 myListControl->selectionModel()->select(aIndex, QItemSelectionModel::Select);
372 //********************************************************************
373 QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
375 QList<QWidget*> result;
376 //result << myTypeCombo;
377 result << myListControl;
381 //********************************************************************
382 void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
384 activateSelectionAndFilters(true);
385 QList<ModuleBase_ViewerPrsPtr> anEmptyList;
386 // This method will call Selection changed event which will call onSelectionChanged
387 // To clear mySelection, myListControl and storeValue()
388 // So, we don't need to call it
389 myWorkshop->setSelected(anEmptyList);
392 //********************************************************************
393 void ModuleBase_WidgetMultiSelector::onSelectionChanged()
395 if (!myIsNeutralPointClear) {
396 QList<ModuleBase_ViewerPrsPtr> aSelected = getFilteredSelected();
397 if (aSelected.size() == 0)
400 ModuleBase_WidgetSelector::onSelectionChanged();
403 void ModuleBase_WidgetMultiSelector::updateFocus()
405 // Set focus to List control in order to make possible
406 // to use Tab key for transfer the focus to next widgets
407 myListControl->setCurrentRow(myListControl->model()->rowCount() - 1);
408 ModuleBase_Tools::setFocus(myListControl,
409 "ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()");
412 //********************************************************************
413 void ModuleBase_WidgetMultiSelector::updateSelectionName()
417 //********************************************************************
418 QIntList ModuleBase_WidgetMultiSelector::getShapeTypes() const
420 QIntList aShapeTypes;
422 if (myTypeCombo->count() > 1 && myIsUseChoice) {
423 aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->currentText()));
426 for (int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) {
427 TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->itemText(i));
428 aShapeTypes.append(aType);
429 if (aType == TopAbs_SOLID)
430 aShapeTypes.append(TopAbs_COMPSOLID);
436 //********************************************************************
437 void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType)
439 QString aShapeTypeName;
441 for (int idx = 0; idx < myTypeCombo->count(); ++idx) {
442 aShapeTypeName = myTypeCombo->itemText(idx);
443 TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
444 if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
445 bool aWasActivated = activateSelectionAndFilters(false);
446 bool isBlocked = myTypeCombo->blockSignals(true);
447 myTypeCombo->setCurrentIndex(idx);
448 myTypeCombo->blockSignals(isBlocked);
450 activateSelectionAndFilters(true);
456 QList<ModuleBase_ViewerPrsPtr> ModuleBase_WidgetMultiSelector::getAttributeSelection() const
458 QList<ModuleBase_ViewerPrsPtr> aSelected;
459 convertIndicesToViewerSelection(std::set<int>(), aSelected);
463 //********************************************************************
464 void ModuleBase_WidgetMultiSelector::updateSelectionList()
466 myListControl->clear();
468 DataPtr aData = myFeature->data();
469 AttributePtr anAttribute = aData->attribute(attributeID());
470 std::string aType = anAttribute->attributeType();
471 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
472 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
473 for (int i = 0; i < aSelectionListAttr->size(); i++) {
474 AttributeSelectionPtr aAttr = aSelectionListAttr->value(i);
475 QListWidgetItem* anItem = new QListWidgetItem(aAttr->namingName().c_str(), myListControl);
476 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
477 myListControl->addItem(anItem);
480 else if (aType == ModelAPI_AttributeRefList::typeId()) {
481 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
482 for (int i = 0; i < aRefListAttr->size(); i++) {
483 ObjectPtr anObject = aRefListAttr->object(i);
484 if (anObject.get()) {
485 QListWidgetItem* anItem = new QListWidgetItem(anObject->data()->name().c_str(),
487 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
488 myListControl->addItem(anItem);
492 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
493 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
494 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
495 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
497 if (anAttribute.get()) {
498 std::string anAttrName = generateName(anAttribute, myWorkshop);
499 aName = QString::fromStdString(anAttrName);
502 ObjectPtr anObject = aRefAttrListAttr->object(i);
503 if (anObject.get()) {
504 aName = anObject->data()->name().c_str();
507 QListWidgetItem* anItem = new QListWidgetItem(aName, myListControl);
508 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
509 myListControl->addItem(anItem);
513 // We have to call repaint because sometimes the List control is not updated
514 myListControl->repaint();
517 //********************************************************************
518 std::string ModuleBase_WidgetMultiSelector::validatorType(const QString& theType) const
522 if (theType == "Vertices")
524 else if (theType == "Edges")
526 else if (theType == "Faces")
528 else if (theType == "Solids")
534 //********************************************************************
535 void ModuleBase_WidgetMultiSelector::onCopyItem()
537 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
539 foreach(QListWidgetItem* aItem, aItems) {
542 aRes += aItem->text();
544 if (!aRes.isEmpty()) {
545 QClipboard *clipboard = QApplication::clipboard();
546 clipboard->setText(aRes);
550 //********************************************************************
551 void ModuleBase_WidgetMultiSelector::onDeleteItem()
556 //********************************************************************
557 void ModuleBase_WidgetMultiSelector::onListSelection()
559 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
560 myCopyAction->setEnabled(!aItems.isEmpty());
561 myDeleteAction->setEnabled(!aItems.isEmpty());
563 myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects,
567 //********************************************************************
568 void ModuleBase_WidgetMultiSelector::getSelectedAttributeIndices(std::set<int>& theAttributeIds)
570 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
571 foreach(QListWidgetItem* anItem, aItems) {
572 int anIndex = anItem->data(ATTRIBUTE_SELECTION_INDEX_ROLE).toInt();
573 if (theAttributeIds.find(anIndex) == theAttributeIds.end())
574 theAttributeIds.insert(anIndex);
578 void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<int> theAttributeIds,
579 QList<ModuleBase_ViewerPrsPtr>& theValues) const
581 if(myFeature.get() == NULL)
584 DataPtr aData = myFeature->data();
585 AttributePtr anAttribute = aData->attribute(attributeID());
586 std::string aType = anAttribute->attributeType();
587 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
588 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
589 for (int i = 0; i < aSelectionListAttr->size(); i++) {
590 // filter by attribute indices only if the container is not empty otherwise return all items
591 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
593 AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
594 ResultPtr anObject = anAttr->context();
596 theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
597 new ModuleBase_ViewerPrs(anObject, anAttr->value(), NULL)));
600 else if (aType == ModelAPI_AttributeRefList::typeId()) {
601 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
602 for (int i = 0; i < aRefListAttr->size(); i++) {
603 // filter by attribute indices only if the container is not empty otherwise return all items
604 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
606 ObjectPtr anObject = aRefListAttr->object(i);
607 if (anObject.get()) {
608 theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
609 new ModuleBase_ViewerPrs(anObject, GeomShapePtr(), NULL)));
613 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
614 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
615 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
616 // filter by attribute indices only if the container is not empty otherwise return all items
617 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
619 ObjectPtr anObject = aRefAttrListAttr->object(i);
623 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
624 if (anAttribute.get()) {
625 GeomShapePtr aGeomShape = ModuleBase_Tools::getShape(anAttribute, myWorkshop);
626 theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
627 new ModuleBase_ViewerPrs(anObject, aGeomShape, NULL)));
633 bool ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
634 (QList<ModuleBase_ViewerPrsPtr>& theValues)
638 std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection = convertSelection(theValues);
639 DataPtr aData = myFeature->data();
640 AttributePtr anAttribute = aData->attribute(attributeID());
641 std::string aType = anAttribute->attributeType();
642 std::set<GeomShapePtr> aShapes;
643 std::set<int> anIndicesToBeRemoved;
644 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
645 // iteration through data model to find not selected elements to remove them
646 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
647 for (int i = 0; i < aSelectionListAttr->size(); i++) {
648 AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
649 bool aFound = findInSelection(anAttr->context(), anAttr->value(), aGeomSelection);
651 anIndicesToBeRemoved.insert(i);
653 isDone = anIndicesToBeRemoved.size() > 0;
654 aSelectionListAttr->remove(anIndicesToBeRemoved);
656 else if (aType == ModelAPI_AttributeRefList::typeId()) {
657 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
658 for (int i = 0; i < aRefListAttr->size(); i++) {
659 ObjectPtr anObject = aRefListAttr->object(i);
660 if (anObject.get()) {
661 bool aFound = findInSelection(anObject, GeomShapePtr(), aGeomSelection);
663 anIndicesToBeRemoved.insert(i);
666 isDone = anIndicesToBeRemoved.size() > 0;
667 aRefListAttr->remove(anIndicesToBeRemoved);
669 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
670 std::set<AttributePtr> anAttributes;
671 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
674 for (; anIt != aLast; anIt++) {
675 ModuleBase_ViewerPrsPtr aPrs = *anIt;
676 getGeomSelection(aPrs, anObject, aShape);
677 AttributePtr anAttr = myWorkshop->module()->findAttribute(anObject, aShape);
678 if (anAttr.get() && anAttributes.find(anAttr) == anAttributes.end())
679 anAttributes.insert(anAttr);
682 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
683 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
685 if (aRefAttrListAttr->isAttribute(i)) {
686 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
687 aFound = anAttributes.find(anAttribute) != anAttributes.end();
690 aFound = findInSelection(aRefAttrListAttr->object(i), GeomShapePtr(), aGeomSelection);
693 anIndicesToBeRemoved.insert(i);
695 isDone = anIndicesToBeRemoved.size() > 0;
696 aRefAttrListAttr->remove(anIndicesToBeRemoved);
702 std::map<ObjectPtr, std::set<GeomShapePtr> > ModuleBase_WidgetMultiSelector::convertSelection
703 (QList<ModuleBase_ViewerPrsPtr>& theValues)
705 // convert prs list to objects map
706 std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection;
707 std::set<GeomShapePtr> aShapes;
708 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
711 GeomShapePtr anEmptyShape(new GeomAPI_Shape());
712 for (; anIt != aLast; anIt++) {
713 ModuleBase_ViewerPrsPtr aPrs = *anIt;
714 getGeomSelection(aPrs, anObject, aShape);
716 if (aGeomSelection.find(anObject) != aGeomSelection.end()) // found
717 aShapes = aGeomSelection[anObject];
718 // we need to know if there was an empty shape in selection for the object
720 aShape = anEmptyShape;
721 if (aShape.get() && aShapes.find(aShape) == aShapes.end()) // not found
722 aShapes.insert(aShape);
723 aGeomSelection[anObject] = aShapes;
725 return aGeomSelection;
728 bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject,
729 const GeomShapePtr& theShape,
730 const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection)
733 GeomShapePtr anEmptyShape(new GeomAPI_Shape());
734 GeomShapePtr aShape = theShape.get() ? theShape : anEmptyShape;
735 if (theGeomSelection.find(theObject) != theGeomSelection.end()) {// found
736 const std::set<GeomShapePtr>& aShapes = theGeomSelection.at(theObject);
737 std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
738 for (; anIt != aLast && !aFound; anIt++) {
739 GeomShapePtr aCShape = *anIt;
741 aFound = aCShape->isEqual(aShape);