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 = ModuleBase_Tools::createAction(QIcon(":pictures/copy.png"), tr("Copy"), this,
147 this, SLOT(onCopyItem()));
148 myCopyAction->setShortcut(QKeySequence::Copy);
149 myCopyAction->setEnabled(false);
150 myListControl->addAction(myCopyAction);
152 myDeleteAction = ModuleBase_Tools::createAction(QIcon(":pictures/delete.png"), tr("Delete"), this,
153 this, SLOT(onDeleteItem()));
154 myDeleteAction->setEnabled(false);
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();
330 // refill attribute by the items which indices are not in the list of ids
332 DataPtr aData = myFeature->data();
333 AttributePtr anAttribute = aData->attribute(attributeID());
334 std::string aType = anAttribute->attributeType();
335 aDone = !anAttributeIds.empty();
336 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
337 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
338 aSelectionListAttr->remove(anAttributeIds);
341 else if (aType == ModelAPI_AttributeRefList::typeId()) {
342 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
343 aRefListAttr->remove(anAttributeIds);
345 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
346 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
347 aRefAttrListAttr->remove(anAttributeIds);
351 // update object is necessary to flush update signal. It leads to objects references map update
352 // and the operation presentation will not contain deleted items visualized as parameters of
354 updateObject(myFeature);
357 myWorkshop->setSelected(getAttributeSelection());
359 // may be the feature's result is not displayed, but attributes should be
360 myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments,
361 true); /// hope that something is redisplayed by object updated
365 int aRows = myListControl->model()->rowCount();
367 foreach(QModelIndex aIndex, aIndexes) {
368 if (aIndex.row() < aRows)
369 myListControl->selectionModel()->select(aIndex, QItemSelectionModel::Select);
371 QModelIndex aIdx = myListControl->model()->index(aRows - 1, 0);
372 myListControl->selectionModel()->select(aIdx, QItemSelectionModel::Select);
379 //********************************************************************
380 QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
382 QList<QWidget*> result;
383 //result << myTypeCombo;
384 result << myListControl;
388 //********************************************************************
389 void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
391 activateSelectionAndFilters(true);
392 QList<ModuleBase_ViewerPrsPtr> anEmptyList;
393 // This method will call Selection changed event which will call onSelectionChanged
394 // To clear mySelection, myListControl and storeValue()
395 // So, we don't need to call it
396 myWorkshop->setSelected(anEmptyList);
399 //********************************************************************
400 void ModuleBase_WidgetMultiSelector::onSelectionChanged()
402 if (!myIsNeutralPointClear) {
403 QList<ModuleBase_ViewerPrsPtr> aSelected = getFilteredSelected();
404 if (aSelected.size() == 0)
407 ModuleBase_WidgetSelector::onSelectionChanged();
410 void ModuleBase_WidgetMultiSelector::updateFocus()
412 // Set focus to List control in order to make possible
413 // to use Tab key for transfer the focus to next widgets
414 myListControl->setCurrentRow(myListControl->model()->rowCount() - 1);
415 ModuleBase_Tools::setFocus(myListControl,
416 "ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()");
419 //********************************************************************
420 void ModuleBase_WidgetMultiSelector::updateSelectionName()
424 //********************************************************************
425 QIntList ModuleBase_WidgetMultiSelector::getShapeTypes() const
427 QIntList aShapeTypes;
429 if (myTypeCombo->count() > 1 && myIsUseChoice) {
430 aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->currentText()));
433 for (int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) {
434 TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->itemText(i));
435 aShapeTypes.append(aType);
436 if (aType == TopAbs_SOLID)
437 aShapeTypes.append(TopAbs_COMPSOLID);
443 //********************************************************************
444 void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType)
446 QString aShapeTypeName;
448 for (int idx = 0; idx < myTypeCombo->count(); ++idx) {
449 aShapeTypeName = myTypeCombo->itemText(idx);
450 TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
451 if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
452 bool aWasActivated = activateSelectionAndFilters(false);
453 bool isBlocked = myTypeCombo->blockSignals(true);
454 myTypeCombo->setCurrentIndex(idx);
455 myTypeCombo->blockSignals(isBlocked);
457 activateSelectionAndFilters(true);
463 QList<ModuleBase_ViewerPrsPtr> ModuleBase_WidgetMultiSelector::getAttributeSelection() const
465 QList<ModuleBase_ViewerPrsPtr> aSelected;
466 convertIndicesToViewerSelection(std::set<int>(), aSelected);
470 //********************************************************************
471 void ModuleBase_WidgetMultiSelector::updateSelectionList()
473 myListControl->clear();
475 DataPtr aData = myFeature->data();
476 AttributePtr anAttribute = aData->attribute(attributeID());
477 std::string aType = anAttribute->attributeType();
478 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
479 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
480 for (int i = 0; i < aSelectionListAttr->size(); i++) {
481 AttributeSelectionPtr aAttr = aSelectionListAttr->value(i);
482 QListWidgetItem* anItem = new QListWidgetItem(aAttr->namingName().c_str(), myListControl);
483 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
484 myListControl->addItem(anItem);
487 else if (aType == ModelAPI_AttributeRefList::typeId()) {
488 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
489 for (int i = 0; i < aRefListAttr->size(); i++) {
490 ObjectPtr anObject = aRefListAttr->object(i);
491 if (anObject.get()) {
492 QListWidgetItem* anItem = new QListWidgetItem(anObject->data()->name().c_str(),
494 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
495 myListControl->addItem(anItem);
499 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
500 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
501 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
502 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
504 if (anAttribute.get()) {
505 std::string anAttrName = generateName(anAttribute, myWorkshop);
506 aName = QString::fromStdString(anAttrName);
509 ObjectPtr anObject = aRefAttrListAttr->object(i);
510 if (anObject.get()) {
511 aName = anObject->data()->name().c_str();
514 QListWidgetItem* anItem = new QListWidgetItem(aName, myListControl);
515 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
516 myListControl->addItem(anItem);
520 // We have to call repaint because sometimes the List control is not updated
521 myListControl->repaint();
524 //********************************************************************
525 std::string ModuleBase_WidgetMultiSelector::validatorType(const QString& theType) const
529 if (theType == "Vertices")
531 else if (theType == "Edges")
533 else if (theType == "Faces")
535 else if (theType == "Solids")
541 //********************************************************************
542 void ModuleBase_WidgetMultiSelector::onCopyItem()
544 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
546 foreach(QListWidgetItem* aItem, aItems) {
549 aRes += aItem->text();
551 if (!aRes.isEmpty()) {
552 QClipboard *clipboard = QApplication::clipboard();
553 clipboard->setText(aRes);
557 //********************************************************************
558 void ModuleBase_WidgetMultiSelector::onDeleteItem()
563 //********************************************************************
564 void ModuleBase_WidgetMultiSelector::onListSelection()
566 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
567 myCopyAction->setEnabled(!aItems.isEmpty());
568 myDeleteAction->setEnabled(!aItems.isEmpty());
570 myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects,
574 //********************************************************************
575 void ModuleBase_WidgetMultiSelector::getSelectedAttributeIndices(std::set<int>& theAttributeIds)
577 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
578 foreach(QListWidgetItem* anItem, aItems) {
579 int anIndex = anItem->data(ATTRIBUTE_SELECTION_INDEX_ROLE).toInt();
580 if (theAttributeIds.find(anIndex) == theAttributeIds.end())
581 theAttributeIds.insert(anIndex);
585 void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<int> theAttributeIds,
586 QList<ModuleBase_ViewerPrsPtr>& theValues) const
588 if(myFeature.get() == NULL)
591 DataPtr aData = myFeature->data();
592 AttributePtr anAttribute = aData->attribute(attributeID());
593 std::string aType = anAttribute->attributeType();
594 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
595 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
596 for (int i = 0; i < aSelectionListAttr->size(); i++) {
597 // filter by attribute indices only if the container is not empty otherwise return all items
598 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
600 AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
601 ResultPtr anObject = anAttr->context();
603 theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
604 new ModuleBase_ViewerPrs(anObject, anAttr->value(), NULL)));
607 else if (aType == ModelAPI_AttributeRefList::typeId()) {
608 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
609 for (int i = 0; i < aRefListAttr->size(); i++) {
610 // filter by attribute indices only if the container is not empty otherwise return all items
611 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
613 ObjectPtr anObject = aRefListAttr->object(i);
614 if (anObject.get()) {
615 theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
616 new ModuleBase_ViewerPrs(anObject, GeomShapePtr(), NULL)));
620 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
621 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
622 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
623 // filter by attribute indices only if the container is not empty otherwise return all items
624 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
626 ObjectPtr anObject = aRefAttrListAttr->object(i);
630 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
631 if (anAttribute.get()) {
632 GeomShapePtr aGeomShape = ModuleBase_Tools::getShape(anAttribute, myWorkshop);
633 theValues.append(std::shared_ptr<ModuleBase_ViewerPrs>(
634 new ModuleBase_ViewerPrs(anObject, aGeomShape, NULL)));
640 bool ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
641 (QList<ModuleBase_ViewerPrsPtr>& theValues)
645 std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection = convertSelection(theValues);
646 DataPtr aData = myFeature->data();
647 AttributePtr anAttribute = aData->attribute(attributeID());
648 std::string aType = anAttribute->attributeType();
649 std::set<GeomShapePtr> aShapes;
650 std::set<int> anIndicesToBeRemoved;
651 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
652 // iteration through data model to find not selected elements to remove them
653 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
654 for (int i = 0; i < aSelectionListAttr->size(); i++) {
655 AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
656 bool aFound = findInSelection(anAttr->context(), anAttr->value(), aGeomSelection);
658 anIndicesToBeRemoved.insert(i);
660 isDone = anIndicesToBeRemoved.size() > 0;
661 aSelectionListAttr->remove(anIndicesToBeRemoved);
663 else if (aType == ModelAPI_AttributeRefList::typeId()) {
664 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
665 for (int i = 0; i < aRefListAttr->size(); i++) {
666 ObjectPtr anObject = aRefListAttr->object(i);
667 if (anObject.get()) {
668 bool aFound = findInSelection(anObject, GeomShapePtr(), aGeomSelection);
670 anIndicesToBeRemoved.insert(i);
673 isDone = anIndicesToBeRemoved.size() > 0;
674 aRefListAttr->remove(anIndicesToBeRemoved);
676 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
677 std::set<AttributePtr> anAttributes;
678 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
681 for (; anIt != aLast; anIt++) {
682 ModuleBase_ViewerPrsPtr aPrs = *anIt;
683 getGeomSelection(aPrs, anObject, aShape);
684 AttributePtr anAttr = myWorkshop->module()->findAttribute(anObject, aShape);
685 if (anAttr.get() && anAttributes.find(anAttr) == anAttributes.end())
686 anAttributes.insert(anAttr);
689 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
690 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
692 if (aRefAttrListAttr->isAttribute(i)) {
693 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
694 aFound = anAttributes.find(anAttribute) != anAttributes.end();
697 aFound = findInSelection(aRefAttrListAttr->object(i), GeomShapePtr(), aGeomSelection);
700 anIndicesToBeRemoved.insert(i);
702 isDone = anIndicesToBeRemoved.size() > 0;
703 aRefAttrListAttr->remove(anIndicesToBeRemoved);
709 std::map<ObjectPtr, std::set<GeomShapePtr> > ModuleBase_WidgetMultiSelector::convertSelection
710 (QList<ModuleBase_ViewerPrsPtr>& theValues)
712 // convert prs list to objects map
713 std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection;
714 std::set<GeomShapePtr> aShapes;
715 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
718 GeomShapePtr anEmptyShape(new GeomAPI_Shape());
719 for (; anIt != aLast; anIt++) {
720 ModuleBase_ViewerPrsPtr aPrs = *anIt;
721 getGeomSelection(aPrs, anObject, aShape);
723 if (aGeomSelection.find(anObject) != aGeomSelection.end()) // found
724 aShapes = aGeomSelection[anObject];
725 // we need to know if there was an empty shape in selection for the object
727 aShape = anEmptyShape;
728 if (aShape.get() && aShapes.find(aShape) == aShapes.end()) // not found
729 aShapes.insert(aShape);
730 aGeomSelection[anObject] = aShapes;
732 return aGeomSelection;
735 bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject,
736 const GeomShapePtr& theShape,
737 const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection)
740 GeomShapePtr anEmptyShape(new GeomAPI_Shape());
741 GeomShapePtr aShape = theShape.get() ? theShape : anEmptyShape;
742 if (theGeomSelection.find(theObject) != theGeomSelection.end()) {// found
743 const std::set<GeomShapePtr>& aShapes = theGeomSelection.at(theObject);
744 std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
745 for (; anIt != aLast && !aFound; anIt++) {
746 GeomShapePtr aCShape = *anIt;
748 aFound = aCShape->isEqual(aShape);