+
+//********************************************************************
+bool ModuleBase_WidgetMultiSelector::eventFilter(QObject* theObj, QEvent* theEvent)
+{
+ //TODO: Remove maybe?
+ return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::activateSelection(bool toActivate)
+{
+ myIsActive = toActivate;
+ if (myIsActive) {
+ connect(myWorkshop, SIGNAL(selectionChanged()),
+ this, SLOT(onSelectionChanged()),
+ Qt::UniqueConnection);
+ activateShapeSelection();
+ } else {
+ disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ myWorkshop->deactivateSubShapesSelection();
+ }
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
+{
+ activateShapeSelection();
+ QObjectPtrList anEmptyList;
+ myWorkshop->setSelected(anEmptyList);
+ // Clear mySelection, myListControl and storeValue()
+ onSelectionChanged();
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onSelectionChanged()
+{
+ ModuleBase_ISelection* aSelection = myWorkshop->selection();
+ NCollection_List<TopoDS_Shape> aSelectedShapes; //, aFilteredShapes;
+ std::list<ObjectPtr> aOwnersList;
+ aSelection->selectedShapes(aSelectedShapes, aOwnersList);
+
+ mySelection.clear();
+ std::list<ObjectPtr>::const_iterator aIt;
+ NCollection_List<TopoDS_Shape>::Iterator aShpIt(aSelectedShapes);
+ GeomShapePtr aShape;
+ for (aIt = aOwnersList.cbegin(); aIt != aOwnersList.cend(); aShpIt.Next(), aIt++) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(*aIt);
+ if (myFeature) {
+ // We can not select a result of our feature
+ const std::list<ResultPtr>& aResList = myFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ bool isSkipSelf = false;
+ for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
+ if ((*aIt) == aResult) {
+ isSkipSelf = true;
+ break;
+ }
+ }
+ if(isSkipSelf)
+ continue;
+ }
+ aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(aShpIt.Value()));
+ mySelection.append(GeomSelection(aResult, aShape));
+ }
+ //updateSelectionList();
+ emit valuesChanged();
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
+ NCollection_List<TopoDS_Shape>& theResult)
+{
+ if(myTypeCombo->count() == 0 || theShapesToFilter.IsEmpty())
+ return;
+ TopAbs_ShapeEnum aReferenceType =
+ ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText());
+ NCollection_List<TopoDS_Shape>::Iterator anIter(theShapesToFilter);
+ for (; anIter.More(); anIter.Next()) {
+ TopoDS_Shape aShape = anIter.Value();
+ if (aShape.IsNull() || aShape.ShapeType() != aReferenceType)
+ continue;
+ theResult.Append(aShape);
+ }
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum theShapeType)
+{
+ QString aShapeTypeName;
+
+ for (int idx = 0; idx < myTypeCombo->count(); ++idx) {
+ aShapeTypeName = myTypeCombo->itemText(idx);
+ TopAbs_ShapeEnum aRefType = ModuleBase_WidgetShapeSelector::shapeType(aShapeTypeName);
+ if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
+ activateSelection(false);
+ bool isBlocked = myTypeCombo->blockSignals(true);
+ myTypeCombo->setCurrentIndex(idx);
+ myTypeCombo->blockSignals(isBlocked);
+ activateSelection(true);
+ break;
+ }
+ }
+}
+
+void ModuleBase_WidgetMultiSelector::activateShapeSelection()
+{
+ QString aNewType = myTypeCombo->currentText();
+ QIntList aList;
+ aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType));
+ myWorkshop->activateSubShapesSelection(aList);
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::updateSelectionList(AttributeSelectionListPtr theList)
+{
+ myListControl->clear();
+ for (int i = 0; i < theList->size(); i++) {
+ AttributeSelectionPtr aAttr = theList->value(i);
+ myListControl->addItem(aAttr->namingName().c_str());
+ }
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onCopyItem()
+{
+ QList<QListWidgetItem*> aItems = myListControl->selectedItems();
+ QString aRes;
+ foreach(QListWidgetItem* aItem, aItems) {
+ if (!aRes.isEmpty())
+ aRes += "\n";
+ aRes += aItem->text();
+ }
+ if (!aRes.isEmpty()) {
+ QClipboard *clipboard = QApplication::clipboard();
+ clipboard->setText(aRes);
+ }
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onListSelection()
+{
+ QList<QListWidgetItem*> aItems = myListControl->selectedItems();
+ myCopyAction->setEnabled(!aItems.isEmpty());
+}
+