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>
41 #include <QMainWindow>
46 const int ATTRIBUTE_SELECTION_INDEX_ROLE = Qt::UserRole + 1;
49 * Customization of a List Widget to make it to be placed on full width of container
51 class CustomListWidget : public QListWidget
55 /// \param theParent a parent widget
56 CustomListWidget( QWidget* theParent )
57 : QListWidget( theParent )
61 /// Redefinition of virtual method
62 virtual QSize sizeHint() const
64 int aHeight = 2*QFontMetrics( font() ).height();
65 QSize aSize = QListWidget::sizeHint();
66 return QSize( aSize.width(), aHeight );
69 /// Redefinition of virtual method
70 virtual QSize minimumSizeHint() const
72 int aHeight = 4/*2*/*QFontMetrics( font() ).height();
73 QSize aSize = QListWidget::minimumSizeHint();
74 return QSize( aSize.width(), aHeight );
78 // The code is necessary only for Linux because
79 //it can not update viewport on widget resize
81 void resizeEvent(QResizeEvent* theEvent)
83 QListWidget::resizeEvent(theEvent);
84 QTimer::singleShot(5, viewport(), SLOT(repaint()));
89 ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
90 ModuleBase_IWorkshop* theWorkshop,
91 const Config_WidgetAPI* theData)
92 : ModuleBase_WidgetSelector(theParent, theWorkshop, theData)
94 QGridLayout* aMainLay = new QGridLayout(this);
95 ModuleBase_Tools::adjustMargins(aMainLay);
97 QLabel* aTypeLabel = new QLabel(tr("Type"), this);
98 aMainLay->addWidget(aTypeLabel, 0, 0);
100 myTypeCombo = new QComboBox(this);
101 // There is no sense to parameterize list of types while we can not parameterize selection mode
103 std::string aPropertyTypes = theData->getProperty("type_choice");
104 QString aTypesStr = aPropertyTypes.c_str();
105 QStringList aShapeTypes = aTypesStr.split(' ', QString::SkipEmptyParts);
107 myIsUseChoice = theData->getBooleanAttribute("use_choice", false);
109 if (!aShapeTypes.empty())
110 myTypeCombo->addItems(aShapeTypes);
111 aMainLay->addWidget(myTypeCombo, 0, 1);
112 // if the xml definition contains one type, the controls to select a type should not be shown
113 if (aShapeTypes.size() <= 1 || !myIsUseChoice) {
114 aTypeLabel->setVisible(false);
115 myTypeCombo->setVisible(false);
118 std::string aLabelText = theData->getProperty("label");
119 QLabel* aListLabel = new QLabel(!aLabelText.empty() ? aLabelText.c_str()
120 : tr("Selected objects:"), this);
121 aMainLay->addWidget(aListLabel, 1, 0);
122 // if the xml definition contains one type, an information label should be shown near to the latest
123 if (aShapeTypes.size() <= 1) {
124 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
125 if (!aLabelIcon.isEmpty()) {
126 QLabel* aSelectedLabel = new QLabel("", this);
127 aSelectedLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
128 aMainLay->addWidget(aSelectedLabel, 1, 1);
130 aMainLay->setColumnStretch(2, 1);
133 QString aToolTip = QString::fromStdString(theData->widgetTooltip());
134 myListControl = new CustomListWidget(this);
135 QString anObjName = QString::fromStdString(attributeID());
136 myListControl->setObjectName(anObjName);
137 myListControl->setToolTip(aToolTip);
138 myListControl->setSelectionMode(QAbstractItemView::ExtendedSelection);
140 aMainLay->addWidget(myListControl, 2, 0, 1, -1);
141 aMainLay->setRowStretch(2, 1);
142 //aMainLay->addWidget(new QLabel(this)); //FIXME(sbh)???
143 //aMainLay->setRowMinimumHeight(3, 20);
144 //this->setLayout(aMainLay);
145 connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectionTypeChanged()));
147 myCopyAction = ModuleBase_Tools::createAction(QIcon(":pictures/copy.png"), tr("Copy"),
148 myWorkshop->desktop(), this, SLOT(onCopyItem()));
149 myCopyAction->setShortcut(QKeySequence::Copy);
150 myCopyAction->setEnabled(false);
151 myListControl->addAction(myCopyAction);
153 myDeleteAction = ModuleBase_Tools::createAction(QIcon(":pictures/delete.png"), tr("Delete"),
154 myWorkshop->desktop(), this, SLOT(onDeleteItem()));
155 myDeleteAction->setEnabled(false);
156 myListControl->addAction(myDeleteAction);
158 myListControl->setContextMenuPolicy(Qt::ActionsContextMenu);
159 connect(myListControl, SIGNAL(itemSelectionChanged()), SLOT(onListSelection()));
161 myIsNeutralPointClear = theData->getBooleanAttribute("clear_in_neutral_point", true);
164 ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector()
168 //********************************************************************
169 void ModuleBase_WidgetMultiSelector::activateCustom()
171 ModuleBase_WidgetSelector::activateCustom();
173 myWorkshop->module()->activateCustomPrs(myFeature,
174 ModuleBase_IModule::CustomizeHighlightedObjects, true);
177 //********************************************************************
178 void ModuleBase_WidgetMultiSelector::deactivate()
180 ModuleBase_WidgetSelector::deactivate();
182 myWorkshop->module()->deactivateCustomPrs(ModuleBase_IModule::CustomizeHighlightedObjects, true);
185 //********************************************************************
186 bool ModuleBase_WidgetMultiSelector::storeValueCustom()
188 // the value is stored on the selection changed signal processing
189 // A rare case when plugin was not loaded.
193 AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
194 std::string aType = anAttribute->attributeType();
195 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
196 AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
197 aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
202 //********************************************************************
203 bool ModuleBase_WidgetMultiSelector::restoreValueCustom()
205 // A rare case when plugin was not loaded.
209 AttributePtr anAttribute = myFeature->data()->attribute(attributeID());
210 std::string aType = anAttribute->attributeType();
211 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
212 AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
213 // Restore shape type
214 std::string aSelectionType = aSelectionListAttr->selectionType().c_str();
215 if (!aSelectionType.empty())
216 setCurrentShapeType(ModuleBase_Tools::shapeType(aSelectionType.c_str()));
218 updateSelectionList();
222 //********************************************************************
223 bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
224 const bool theToValidate)
226 AttributeSelectionListPtr aSelectionListAttr;
227 if (attribute()->attributeType() == ModelAPI_AttributeSelectionList::typeId())
228 aSelectionListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(attribute());
229 if (aSelectionListAttr.get())
230 aSelectionListAttr->cashValues(true);
232 /// remove unused objects from the model attribute.
233 /// It should be performed before new attributes append.
234 bool isDone = removeUnusedAttributeObjects(theValues);
236 QList<ModuleBase_ViewerPrsPtr> anInvalidValues;
237 QList<ModuleBase_ViewerPrsPtr> anAttributeValues;
238 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
239 for (; anIt != aLast; anIt++) {
240 ModuleBase_ViewerPrsPtr aValue = *anIt;
241 // do not validate and append to attribute selection presentation if it exists in the attribute
244 getGeomSelection(aValue, anObject, aShape);
245 if (ModuleBase_Tools::hasObject(attribute(), anObject, aShape, myWorkshop, myIsInValidate)) {
246 anAttributeValues.append(aValue);
249 if (theToValidate && !isValidInFilters(aValue))
250 anInvalidValues.append(aValue);
252 bool aHasInvalidValues = anInvalidValues.size() > 0;
254 for (anIt = theValues.begin(); anIt != aLast; anIt++) {
255 ModuleBase_ViewerPrsPtr aValue = *anIt;
256 bool aProcessed = false;
257 if ((aHasInvalidValues && anInvalidValues.contains(aValue)) ||
258 anAttributeValues.contains(aValue))
260 aProcessed = setSelectionCustom(aValue); /// it is not optimal as hasObject() is already checked
261 // if there is at least one set, the result is true
262 isDone = isDone || aProcessed;
264 // updateObject - to update/redisplay feature
265 // it is commented in order to perfom it outside the method
267 //updateObject(myFeature);
268 // this emit is necessary to call store/restore method an restore type of selection
269 //emit valuesChanged();
272 if (aSelectionListAttr.get())
273 aSelectionListAttr->cashValues(false);
276 if (!anInvalidValues.empty())
277 theValues.append(anInvalidValues);
279 if (isDone) // may be the feature's result is not displayed, but attributes should be
280 myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments,
281 true);/// hope that something is redisplayed by object updated
286 //********************************************************************
287 void ModuleBase_WidgetMultiSelector::getHighlighted(QList<ModuleBase_ViewerPrsPtr>& theValues)
289 std::set<int> anAttributeIds;
290 getSelectedAttributeIndices(anAttributeIds);
291 if (!anAttributeIds.empty())
292 convertIndicesToViewerSelection(anAttributeIds, theValues);
295 //********************************************************************
296 bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
298 bool aValid = ModuleBase_WidgetSelector::isValidSelectionCustom(thePrs);
300 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
301 aValid = aResult.get() != NULL;
304 // We can not select a result of our feature
305 const std::list<ResultPtr>& aResList = myFeature->results();
306 std::list<ResultPtr>::const_iterator aIt;
307 bool isSkipSelf = false;
308 for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
309 if ((*aIt) == aResult) {
322 //********************************************************************
323 bool ModuleBase_WidgetMultiSelector::processDelete()
325 // find attribute indices to delete
326 std::set<int> anAttributeIds;
327 getSelectedAttributeIndices(anAttributeIds);
329 QModelIndexList aIndexes = myListControl->selectionModel()->selectedIndexes();
331 // refill attribute by the items which indices are not in the list of ids
333 DataPtr aData = myFeature->data();
334 AttributePtr anAttribute = aData->attribute(attributeID());
335 std::string aType = anAttribute->attributeType();
336 aDone = !anAttributeIds.empty();
337 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
338 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
339 aSelectionListAttr->remove(anAttributeIds);
342 else if (aType == ModelAPI_AttributeRefList::typeId()) {
343 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
344 aRefListAttr->remove(anAttributeIds);
346 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
347 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
348 aRefAttrListAttr->remove(anAttributeIds);
352 // update object is necessary to flush update signal. It leads to objects references map update
353 // and the operation presentation will not contain deleted items visualized as parameters of
355 updateObject(myFeature);
358 myWorkshop->setSelected(getAttributeSelection());
360 // may be the feature's result is not displayed, but attributes should be
361 myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments,
362 true); /// hope that something is redisplayed by object updated
366 int aRows = myListControl->model()->rowCount();
368 foreach(QModelIndex aIndex, aIndexes) {
369 if (aIndex.row() < aRows)
370 myListControl->selectionModel()->select(aIndex, QItemSelectionModel::Select);
372 QModelIndex aIdx = myListControl->model()->index(aRows - 1, 0);
373 myListControl->selectionModel()->select(aIdx, QItemSelectionModel::Select);
380 //********************************************************************
381 QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
383 QList<QWidget*> result;
384 //result << myTypeCombo;
385 result << myListControl;
389 //********************************************************************
390 void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
392 activateSelectionAndFilters(true);
393 QList<ModuleBase_ViewerPrsPtr> anEmptyList;
394 // This method will call Selection changed event which will call onSelectionChanged
395 // To clear mySelection, myListControl and storeValue()
396 // So, we don't need to call it
397 myWorkshop->setSelected(anEmptyList);
400 //********************************************************************
401 void ModuleBase_WidgetMultiSelector::onSelectionChanged()
403 if (!myIsNeutralPointClear) {
404 QList<ModuleBase_ViewerPrsPtr> aSelected = getFilteredSelected();
405 if (aSelected.size() == 0)
408 ModuleBase_WidgetSelector::onSelectionChanged();
411 void ModuleBase_WidgetMultiSelector::updateFocus()
413 // Set focus to List control in order to make possible
414 // to use Tab key for transfer the focus to next widgets
415 myListControl->setCurrentRow(myListControl->model()->rowCount() - 1);
416 ModuleBase_Tools::setFocus(myListControl,
417 "ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()");
420 //********************************************************************
421 void ModuleBase_WidgetMultiSelector::updateSelectionName()
425 //********************************************************************
426 QIntList ModuleBase_WidgetMultiSelector::shapeTypes() const
428 QIntList aShapeTypes;
430 if (myTypeCombo->count() > 1 && myIsUseChoice) {
431 aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->currentText()));
434 for (int i = 0, aCount = myTypeCombo->count(); i < aCount; i++)
435 aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->itemText(i)));
440 //********************************************************************
441 void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType)
443 QString aShapeTypeName;
445 for (int idx = 0; idx < myTypeCombo->count(); ++idx) {
446 aShapeTypeName = myTypeCombo->itemText(idx);
447 TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
448 if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
449 bool aWasActivated = activateSelectionAndFilters(false);
450 bool isBlocked = myTypeCombo->blockSignals(true);
451 myTypeCombo->setCurrentIndex(idx);
452 myTypeCombo->blockSignals(isBlocked);
454 activateSelectionAndFilters(true);
460 QList<ModuleBase_ViewerPrsPtr> ModuleBase_WidgetMultiSelector::getAttributeSelection() const
462 QList<ModuleBase_ViewerPrsPtr> aSelected;
463 convertIndicesToViewerSelection(std::set<int>(), aSelected);
467 //********************************************************************
468 void ModuleBase_WidgetMultiSelector::updateSelectionList()
470 myListControl->clear();
472 DataPtr aData = myFeature->data();
473 AttributePtr anAttribute = aData->attribute(attributeID());
474 std::string aType = anAttribute->attributeType();
475 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
476 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
477 for (int i = 0; i < aSelectionListAttr->size(); i++) {
478 AttributeSelectionPtr aAttr = aSelectionListAttr->value(i);
479 QListWidgetItem* anItem = new QListWidgetItem(aAttr->namingName().c_str(), myListControl);
480 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
481 myListControl->addItem(anItem);
484 else if (aType == ModelAPI_AttributeRefList::typeId()) {
485 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
486 for (int i = 0; i < aRefListAttr->size(); i++) {
487 ObjectPtr anObject = aRefListAttr->object(i);
488 if (anObject.get()) {
489 QListWidgetItem* anItem = new QListWidgetItem(anObject->data()->name().c_str(),
491 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
492 myListControl->addItem(anItem);
496 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
497 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
498 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
499 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
501 if (anAttribute.get()) {
502 std::string anAttrName = generateName(anAttribute, myWorkshop);
503 aName = QString::fromStdString(anAttrName);
506 ObjectPtr anObject = aRefAttrListAttr->object(i);
507 if (anObject.get()) {
508 aName = anObject->data()->name().c_str();
511 QListWidgetItem* anItem = new QListWidgetItem(aName, myListControl);
512 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
513 myListControl->addItem(anItem);
517 // We have to call repaint because sometimes the List control is not updated
518 myListControl->repaint();
521 //********************************************************************
522 std::string ModuleBase_WidgetMultiSelector::validatorType(const QString& theType) const
526 if (theType == "Vertices")
528 else if (theType == "Edges")
530 else if (theType == "Faces")
532 else if (theType == "Solids")
538 //********************************************************************
539 void ModuleBase_WidgetMultiSelector::onCopyItem()
541 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
543 foreach(QListWidgetItem* aItem, aItems) {
546 aRes += aItem->text();
548 if (!aRes.isEmpty()) {
549 QClipboard *clipboard = QApplication::clipboard();
550 clipboard->setText(aRes);
554 //********************************************************************
555 void ModuleBase_WidgetMultiSelector::onDeleteItem()
560 //********************************************************************
561 void ModuleBase_WidgetMultiSelector::onListSelection()
563 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
564 myCopyAction->setEnabled(!aItems.isEmpty());
565 myDeleteAction->setEnabled(!aItems.isEmpty());
567 myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects,
571 //********************************************************************
572 void ModuleBase_WidgetMultiSelector::getSelectedAttributeIndices(std::set<int>& theAttributeIds)
574 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
575 foreach(QListWidgetItem* anItem, aItems) {
576 int anIndex = anItem->data(ATTRIBUTE_SELECTION_INDEX_ROLE).toInt();
577 if (theAttributeIds.find(anIndex) == theAttributeIds.end())
578 theAttributeIds.insert(anIndex);
582 void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<int> theAttributeIds,
583 QList<ModuleBase_ViewerPrsPtr>& theValues) const
585 if(myFeature.get() == NULL)
588 DataPtr aData = myFeature->data();
589 AttributePtr anAttribute = aData->attribute(attributeID());
590 std::string aType = anAttribute->attributeType();
591 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
592 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
593 for (int i = 0; i < aSelectionListAttr->size(); i++) {
594 // filter by attribute indices only if the container is not empty otherwise return all items
595 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
597 AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
598 ResultPtr anObject = anAttr->context();
600 theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
601 new ModuleBase_ViewerPrs(anObject, anAttr->value(), NULL)));
604 else if (aType == ModelAPI_AttributeRefList::typeId()) {
605 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
606 for (int i = 0; i < aRefListAttr->size(); i++) {
607 // filter by attribute indices only if the container is not empty otherwise return all items
608 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
610 ObjectPtr anObject = aRefListAttr->object(i);
611 if (anObject.get()) {
612 theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
613 new ModuleBase_ViewerPrs(anObject, GeomShapePtr(), NULL)));
617 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
618 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
619 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
620 // filter by attribute indices only if the container is not empty otherwise return all items
621 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
623 ObjectPtr anObject = aRefAttrListAttr->object(i);
627 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
628 if (anAttribute.get()) {
629 GeomShapePtr aGeomShape = ModuleBase_Tools::getShape(anAttribute, myWorkshop);
630 theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
631 new ModuleBase_ViewerPrs(anObject, aGeomShape, NULL)));
637 bool ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
638 (QList<ModuleBase_ViewerPrsPtr>& theValues)
642 std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection = convertSelection(theValues);
643 DataPtr aData = myFeature->data();
644 AttributePtr anAttribute = aData->attribute(attributeID());
645 std::string aType = anAttribute->attributeType();
646 std::set<GeomShapePtr> aShapes;
647 std::set<int> anIndicesToBeRemoved;
648 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
649 // iteration through data model to find not selected elements to remove them
650 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
651 for (int i = 0; i < aSelectionListAttr->size(); i++) {
652 AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
653 bool aFound = findInSelection(anAttr->context(), anAttr->value(), aGeomSelection);
655 anIndicesToBeRemoved.insert(i);
657 isDone = anIndicesToBeRemoved.size() > 0;
658 aSelectionListAttr->remove(anIndicesToBeRemoved);
660 else if (aType == ModelAPI_AttributeRefList::typeId()) {
661 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
662 for (int i = 0; i < aRefListAttr->size(); i++) {
663 ObjectPtr anObject = aRefListAttr->object(i);
664 if (anObject.get()) {
665 bool aFound = findInSelection(anObject, GeomShapePtr(), aGeomSelection);
667 anIndicesToBeRemoved.insert(i);
670 isDone = anIndicesToBeRemoved.size() > 0;
671 aRefListAttr->remove(anIndicesToBeRemoved);
673 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
674 std::set<AttributePtr> anAttributes;
675 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
678 for (; anIt != aLast; anIt++) {
679 ModuleBase_ViewerPrsPtr aPrs = *anIt;
680 getGeomSelection(aPrs, anObject, aShape);
681 AttributePtr anAttr = myWorkshop->module()->findAttribute(anObject, aShape);
682 if (anAttr.get() && anAttributes.find(anAttr) == anAttributes.end())
683 anAttributes.insert(anAttr);
686 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
687 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
689 if (aRefAttrListAttr->isAttribute(i)) {
690 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
691 aFound = anAttributes.find(anAttribute) != anAttributes.end();
694 aFound = findInSelection(aRefAttrListAttr->object(i), GeomShapePtr(), aGeomSelection);
697 anIndicesToBeRemoved.insert(i);
699 isDone = anIndicesToBeRemoved.size() > 0;
700 aRefAttrListAttr->remove(anIndicesToBeRemoved);
706 std::map<ObjectPtr, std::set<GeomShapePtr> > ModuleBase_WidgetMultiSelector::convertSelection
707 (QList<ModuleBase_ViewerPrsPtr>& theValues)
709 // convert prs list to objects map
710 std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection;
711 std::set<GeomShapePtr> aShapes;
712 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
715 GeomShapePtr anEmptyShape(new GeomAPI_Shape());
716 for (; anIt != aLast; anIt++) {
717 ModuleBase_ViewerPrsPtr aPrs = *anIt;
718 getGeomSelection(aPrs, anObject, aShape);
720 if (aGeomSelection.find(anObject) != aGeomSelection.end()) // found
721 aShapes = aGeomSelection[anObject];
722 // we need to know if there was an empty shape in selection for the object
724 aShape = anEmptyShape;
725 if (aShape.get() && aShapes.find(aShape) == aShapes.end()) // not found
726 aShapes.insert(aShape);
727 aGeomSelection[anObject] = aShapes;
729 return aGeomSelection;
732 bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject,
733 const GeomShapePtr& theShape,
734 const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection)
737 GeomShapePtr anEmptyShape(new GeomAPI_Shape());
738 GeomShapePtr aShape = theShape.get() ? theShape : anEmptyShape;
739 if (theGeomSelection.find(theObject) != theGeomSelection.end()) {// found
740 const std::set<GeomShapePtr>& aShapes = theGeomSelection.at(theObject);
741 std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
742 for (; anIt != aLast && !aFound; anIt++) {
743 GeomShapePtr aCShape = *anIt;
745 aFound = aCShape->isEqual(aShape);