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>
24 #include <ModelAPI_Tools.h>
26 #include <Config_WidgetAPI.h>
28 #include <QGridLayout>
30 #include <QListWidget>
36 #include <QApplication>
43 const int ATTRIBUTE_SELECTION_INDEX_ROLE = Qt::UserRole + 1;
46 * Customization of a List Widget to make it to be placed on full width of container
48 class CustomListWidget : public QListWidget
52 /// \param theParent a parent widget
53 CustomListWidget( QWidget* theParent )
54 : QListWidget( theParent )
58 /// Redefinition of virtual method
59 virtual QSize sizeHint() const
61 int aHeight = 2*QFontMetrics( font() ).height();
62 QSize aSize = QListWidget::sizeHint();
63 return QSize( aSize.width(), aHeight );
66 /// Redefinition of virtual method
67 virtual QSize minimumSizeHint() const
69 int aHeight = 4/*2*/*QFontMetrics( font() ).height();
70 QSize aSize = QListWidget::minimumSizeHint();
71 return QSize( aSize.width(), aHeight );
75 // The code is necessary only for Linux because
76 //it can not update viewport on widget resize
78 void resizeEvent(QResizeEvent* theEvent)
80 QListWidget::resizeEvent(theEvent);
81 QTimer::singleShot(5, viewport(), SLOT(repaint()));
86 ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
87 ModuleBase_IWorkshop* theWorkshop,
88 const Config_WidgetAPI* theData)
89 : ModuleBase_WidgetSelector(theParent, theWorkshop, theData),
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", false);
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 theObject,
276 GeomShapePtr theShape)
278 DataPtr aData = myFeature->data();
279 ModuleBase_Tools::setObject(aData->attribute(attributeID()), theObject, theShape,
280 myWorkshop, myIsInValidate);
283 //********************************************************************
284 bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
285 const bool theToValidate)
287 QList<ModuleBase_ViewerPrs> aSkippedValues;
289 /// remove unused objects from the model attribute.
290 /// It should be performed before new attributes append.
291 removeUnusedAttributeObjects(theValues);
293 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
295 for (; anIt != aLast; anIt++) {
296 ModuleBase_ViewerPrs aValue = *anIt;
297 bool aProcessed = false;
298 if (!theToValidate || isValidInFilters(aValue)) {
299 aProcessed = setSelectionCustom(aValue);
302 aSkippedValues.append(aValue);
303 // if there is at least one set, the result is true
304 isDone = isDone || aProcessed;
306 // updateObject - to update/redisplay feature
307 // it is commented in order to perfom it outside the method
309 //updateObject(myFeature);
310 // this emit is necessary to call store/restore method an restore type of selection
311 //emit valuesChanged();
315 if (!aSkippedValues.empty())
316 theValues.append(aSkippedValues);
321 //********************************************************************
322 void ModuleBase_WidgetMultiSelector::getHighlighted(QList<ModuleBase_ViewerPrs>& theValues)
324 std::set<int> anAttributeIds;
325 getSelectedAttributeIndices(anAttributeIds);
326 if (!anAttributeIds.empty())
327 convertIndicesToViewerSelection(anAttributeIds, theValues);
330 //********************************************************************
331 bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
333 bool aValid = ModuleBase_WidgetSelector::isValidSelectionCustom(thePrs);
335 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
336 aValid = aResult.get() != NULL;
339 // We can not select a result of our feature
340 const std::list<ResultPtr>& aResList = myFeature->results();
341 std::list<ResultPtr>::const_iterator aIt;
342 bool isSkipSelf = false;
343 for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
344 if ((*aIt) == aResult) {
357 //********************************************************************
358 bool ModuleBase_WidgetMultiSelector::processDelete()
360 // find attribute indices to delete
361 std::set<int> anAttributeIds;
362 getSelectedAttributeIndices(anAttributeIds);
364 // refill attribute by the items which indices are not in the list of ids
366 DataPtr aData = myFeature->data();
367 AttributePtr anAttribute = aData->attribute(attributeID());
368 std::string aType = anAttribute->attributeType();
369 aDone = !anAttributeIds.empty();
370 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
371 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
372 aSelectionListAttr->remove(anAttributeIds);
375 else if (aType == ModelAPI_AttributeRefList::typeId()) {
376 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
377 aRefListAttr->remove(anAttributeIds);
379 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
380 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
381 aRefAttrListAttr->remove(anAttributeIds);
385 // update object is necessary to flush update signal. It leads to objects references map update
386 // and the operation presentation will not contain deleted items visualized as parameters of
388 updateObject(myFeature);
391 myWorkshop->setSelected(getAttributeSelection());
396 //********************************************************************
397 QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
399 QList<QWidget*> result;
400 //result << myTypeCombo;
401 result << myListControl;
405 //********************************************************************
406 void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
408 activateSelectionAndFilters(true);
409 QList<ModuleBase_ViewerPrs> anEmptyList;
410 // This method will call Selection changed event which will call onSelectionChanged
411 // To clear mySelection, myListControl and storeValue()
412 // So, we don't need to call it
413 myWorkshop->setSelected(anEmptyList);
416 void ModuleBase_WidgetMultiSelector::updateFocus()
418 // Set focus to List control in order to make possible
419 // to use Tab key for transfer the focus to next widgets
420 myListControl->setCurrentRow(myListControl->model()->rowCount() - 1);
421 ModuleBase_Tools::setFocus(myListControl,
422 "ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()");
425 //********************************************************************
426 void ModuleBase_WidgetMultiSelector::updateSelectionName()
430 //********************************************************************
431 QIntList ModuleBase_WidgetMultiSelector::getShapeTypes() const
433 QIntList aShapeTypes;
435 if (myTypeCombo->count() > 1 && myIsUseChoice) {
436 aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->currentText()));
439 for (int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) {
440 TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->itemText(i));
441 aShapeTypes.append(aType);
442 if (aType == TopAbs_SOLID)
443 aShapeTypes.append(TopAbs_COMPSOLID);
449 //********************************************************************
450 void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType)
452 QString aShapeTypeName;
454 for (int idx = 0; idx < myTypeCombo->count(); ++idx) {
455 aShapeTypeName = myTypeCombo->itemText(idx);
456 TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
457 if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
458 bool aWasActivated = activateSelectionAndFilters(false);
459 bool isBlocked = myTypeCombo->blockSignals(true);
460 myTypeCombo->setCurrentIndex(idx);
461 myTypeCombo->blockSignals(isBlocked);
463 activateSelectionAndFilters(true);
469 QList<ModuleBase_ViewerPrs> ModuleBase_WidgetMultiSelector::getAttributeSelection() const
471 QList<ModuleBase_ViewerPrs> aSelected;
472 convertIndicesToViewerSelection(std::set<int>(), aSelected);
476 //********************************************************************
477 void ModuleBase_WidgetMultiSelector::updateSelectionList()
479 myListControl->clear();
481 DataPtr aData = myFeature->data();
482 AttributePtr anAttribute = aData->attribute(attributeID());
483 std::string aType = anAttribute->attributeType();
484 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
485 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
486 for (int i = 0; i < aSelectionListAttr->size(); i++) {
487 AttributeSelectionPtr aAttr = aSelectionListAttr->value(i);
488 QListWidgetItem* anItem = new QListWidgetItem(aAttr->namingName().c_str(), myListControl);
489 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
490 myListControl->addItem(anItem);
493 else if (aType == ModelAPI_AttributeRefList::typeId()) {
494 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
495 for (int i = 0; i < aRefListAttr->size(); i++) {
496 ObjectPtr anObject = aRefListAttr->object(i);
497 if (anObject.get()) {
498 QListWidgetItem* anItem = new QListWidgetItem(anObject->data()->name().c_str(),
500 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
501 myListControl->addItem(anItem);
505 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
506 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
507 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
508 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
510 if (anAttribute.get()) {
511 std::string anAttrName = generateName(anAttribute, myWorkshop);
512 aName = QString::fromStdString(anAttrName);
515 ObjectPtr anObject = aRefAttrListAttr->object(i);
516 if (anObject.get()) {
517 aName = anObject->data()->name().c_str();
520 QListWidgetItem* anItem = new QListWidgetItem(aName, myListControl);
521 anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i);
522 myListControl->addItem(anItem);
526 // We have to call repaint because sometimes the List control is not updated
527 myListControl->repaint();
530 //********************************************************************
531 std::string ModuleBase_WidgetMultiSelector::validatorType(const QString& theType) const
535 if (theType == "Vertices")
537 else if (theType == "Edges")
539 else if (theType == "Faces")
541 else if (theType == "Solids")
547 //********************************************************************
548 void ModuleBase_WidgetMultiSelector::onCopyItem()
550 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
552 foreach(QListWidgetItem* aItem, aItems) {
555 aRes += aItem->text();
557 if (!aRes.isEmpty()) {
558 QClipboard *clipboard = QApplication::clipboard();
559 clipboard->setText(aRes);
563 //********************************************************************
564 void ModuleBase_WidgetMultiSelector::onDeleteItem()
569 //********************************************************************
570 void ModuleBase_WidgetMultiSelector::onListSelection()
572 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
573 myCopyAction->setEnabled(!aItems.isEmpty());
574 myDeleteAction->setEnabled(!aItems.isEmpty());
576 myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeHighlightedObjects,
580 //********************************************************************
581 void ModuleBase_WidgetMultiSelector::getSelectedAttributeIndices(std::set<int>& theAttributeIds)
583 QList<QListWidgetItem*> aItems = myListControl->selectedItems();
584 foreach(QListWidgetItem* anItem, aItems) {
585 int anIndex = anItem->data(ATTRIBUTE_SELECTION_INDEX_ROLE).toInt();
586 if (theAttributeIds.find(anIndex) == theAttributeIds.end())
587 theAttributeIds.insert(anIndex);
591 void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<int> theAttributeIds,
592 QList<ModuleBase_ViewerPrs>& theValues) const
594 if(myFeature.get() == NULL)
597 DataPtr aData = myFeature->data();
598 AttributePtr anAttribute = aData->attribute(attributeID());
599 std::string aType = anAttribute->attributeType();
600 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
601 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
602 for (int i = 0; i < aSelectionListAttr->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 AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
607 ResultPtr anObject = anAttr->context();
609 theValues.append(ModuleBase_ViewerPrs(anObject, anAttr->value(), NULL));
612 else if (aType == ModelAPI_AttributeRefList::typeId()) {
613 AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
614 for (int i = 0; i < aRefListAttr->size(); i++) {
615 // filter by attribute indices only if the container is not empty otherwise return all items
616 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
618 ObjectPtr anObject = aRefListAttr->object(i);
619 if (anObject.get()) {
620 theValues.append(ModuleBase_ViewerPrs(anObject, GeomShapePtr(), NULL));
624 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
625 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
626 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
627 // filter by attribute indices only if the container is not empty otherwise return all items
628 if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end())
630 ObjectPtr anObject = aRefAttrListAttr->object(i);
634 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
635 if (anAttribute.get()) {
636 GeomShapePtr aGeomShape = myWorkshop->module()->findShape(anAttribute);
637 theValues.append(ModuleBase_ViewerPrs(anObject, aGeomShape, NULL));
643 void ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
644 (QList<ModuleBase_ViewerPrs>& theValues)
646 std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection = convertSelection(theValues);
647 DataPtr aData = myFeature->data();
648 AttributePtr anAttribute = aData->attribute(attributeID());
649 std::string aType = anAttribute->attributeType();
650 std::set<GeomShapePtr> aShapes;
651 std::set<int> anIndicesToBeRemoved;
652 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
653 // iteration through data model to find not selected elements to remove them
654 AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
655 for (int i = 0; i < aSelectionListAttr->size(); i++) {
656 AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
657 bool aFound = findInSelection(anAttr->context(), anAttr->value(), aGeomSelection);
659 anIndicesToBeRemoved.insert(i);
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 aRefListAttr->remove(anIndicesToBeRemoved);
675 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
676 std::set<AttributePtr> anAttributes;
677 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
680 for (; anIt != aLast; anIt++) {
681 ModuleBase_ViewerPrs aPrs = *anIt;
682 getGeomSelection(aPrs, anObject, aShape);
683 AttributePtr anAttr = myWorkshop->module()->findAttribute(anObject, aShape);
684 if (anAttr.get() && anAttributes.find(anAttr) == anAttributes.end())
685 anAttributes.insert(anAttr);
688 AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
689 for (int i = 0; i < aRefAttrListAttr->size(); i++) {
691 if (aRefAttrListAttr->isAttribute(i)) {
692 AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
693 aFound = anAttributes.find(anAttribute) != anAttributes.end();
696 aFound = findInSelection(aRefAttrListAttr->object(i), GeomShapePtr(), aGeomSelection);
699 anIndicesToBeRemoved.insert(i);
701 aRefAttrListAttr->remove(anIndicesToBeRemoved);
705 std::map<ObjectPtr, std::set<GeomShapePtr> > ModuleBase_WidgetMultiSelector::convertSelection
706 (QList<ModuleBase_ViewerPrs>& theValues)
708 // convert prs list to objects map
709 std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection;
710 std::set<GeomShapePtr> aShapes;
711 QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
714 GeomShapePtr anEmptyShape(new GeomAPI_Shape());
715 for (; anIt != aLast; anIt++) {
716 ModuleBase_ViewerPrs aPrs = *anIt;
717 getGeomSelection(aPrs, anObject, aShape);
719 if (aGeomSelection.find(anObject) != aGeomSelection.end()) // found
720 aShapes = aGeomSelection[anObject];
721 // we need to know if there was an empty shape in selection for the object
723 aShape = anEmptyShape;
724 if (aShape.get() && aShapes.find(aShape) == aShapes.end()) // not found
725 aShapes.insert(aShape);
726 aGeomSelection[anObject] = aShapes;
728 return aGeomSelection;
731 bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject,
732 const GeomShapePtr& theShape,
733 const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection)
736 GeomShapePtr anEmptyShape(new GeomAPI_Shape());
737 GeomShapePtr aShape = theShape.get() ? theShape : anEmptyShape;
738 if (theGeomSelection.find(theObject) != theGeomSelection.end()) {// found
739 const std::set<GeomShapePtr>& aShapes = theGeomSelection.at(theObject);
740 std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
741 for (; anIt != aLast && !aFound; anIt++) {
742 GeomShapePtr aCShape = *anIt;
744 aFound = aCShape->isEqual(aShape);