Salome HOME
Issue #3073: Show filters for Group feature in information panel.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelectionFilter.cpp
index bccb9032b8a1f90bda986ca375bd0356625f64c5..500bd5b68ff21f3737233b55515e9469d0c6038f 100644 (file)
@@ -20,6 +20,7 @@
 #include "ModuleBase_WidgetSelectionFilter.h"
 #include "ModuleBase_Tools.h"
 #include "ModuleBase_IWorkshop.h"
+#include "ModuleBase_ISelectionActivate.h"
 #include "ModuleBase_IModule.h"
 #include "ModuleBase_IViewer.h"
 #include "ModuleBase_IPropertyPanel.h"
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_FiltersFactory.h>
+#include <ModelAPI_ResultBody.h>
 #include <GeomAPI_ShapeExplorer.h>
 
+#include <Events_Loop.h>
+#include <Config_ValidatorReader.h>
+
 #include <AIS_InteractiveContext.hxx>
 #include <StdSelect_BRepOwner.hxx>
 #include <TopoDS_Compound.hxx>
 #include <BRep_Builder.hxx>
+#include <TopExp_Explorer.hxx>
 
 #include <QLayout>
 #include <QPushButton>
 #include <QDialog>
 #include <QToolButton>
 #include <QCheckBox>
+#include <QDir>
 
-static FeaturePtr SelectorFeature;
-static std::string AttributeId;
+FeaturePtr ModuleBase_WidgetSelectionFilter::SelectorFeature;
+std::string ModuleBase_WidgetSelectionFilter::AttributeId;
 
 
 GeomAPI_Shape::ShapeType selectionType(const QString& theType)
@@ -87,22 +96,19 @@ ModuleBase_FilterStarter::ModuleBase_FilterStarter(const std::string& theFeature
   QPushButton* aLaunchBtn = new QPushButton(tr("Selection by filters"), this);
   connect(aLaunchBtn, SIGNAL(clicked()), SLOT(onFiltersLaunch()));
   aMainLayout->addWidget(aLaunchBtn);
-
-  myFilterLbl = new QLabel(this);
-  myFilterLbl->setPixmap(QPixmap(":pictures/filter.png"));
-  aMainLayout->addWidget(myFilterLbl);
-
-  myModifyLbl = new QLabel(this);
-  myModifyLbl->setPixmap(QPixmap(":pictures/plus_minus.png"));
-  aMainLayout->addWidget(myModifyLbl);
-  aMainLayout->addStretch(1);
-
-  myFilterLbl->hide();
-  myModifyLbl->hide();
 }
 
 void ModuleBase_FilterStarter::onFiltersLaunch()
 {
+  static QString aHelpFileName = QString("FiltersPlugin") + QDir::separator() +
+    QString("FiltersPlugin.html");
+
+  ModuleBase_Operation* aParentOp = myWorkshop->currentOperation();
+  ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(aParentOp);
+  if (aFeatureOp)
+    // Open transaction on filters operation finish
+    aFeatureOp->openTransactionOnResume();
+
   QWidget* aParent = parentWidget();
   ModuleBase_WidgetMultiSelector* aSelector =
     dynamic_cast<ModuleBase_WidgetMultiSelector*>(aParent);
@@ -112,12 +118,20 @@ void ModuleBase_FilterStarter::onFiltersLaunch()
   }
   if (!aSelector)
     return;
-  SelectorFeature = aSelector->feature();
-  AttributeId = aSelector->attributeID();
+  ModuleBase_WidgetSelectionFilter::SelectorFeature = aSelector->feature();
+  ModuleBase_WidgetSelectionFilter::AttributeId = aSelector->attributeID();
 
   // Launch Filters operation
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
     (myWorkshop->module()->createOperation(myFeatureName));
+
+  AttributeSelectionListPtr aAttrList =
+    ModuleBase_WidgetSelectionFilter::SelectorFeature->selectionList(
+      ModuleBase_WidgetSelectionFilter::AttributeId);
+  FiltersFeaturePtr aFilters = aAttrList->filters();
+  if (aFilters.get())
+    aFOperation->setFeature(aFilters);
+  aFOperation->setHelpFileName(aHelpFileName);
   myWorkshop->processLaunchOperation(aFOperation);
 }
 
@@ -129,11 +143,16 @@ ModuleBase_FilterItem::ModuleBase_FilterItem(
   : QWidget(theParent->filtersWidget()), myFilterID(theFilter),
     mySelection(std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(theParent->feature()))
 {
-  std::string aXmlString = ModelAPI_Session::get()->filters()->filter(theFilter)->xmlRepresentation();
+  std::string aXmlString =
+      ModelAPI_Session::get()->filters()->filter(theFilter)->xmlRepresentation();
   if (aXmlString.length() == 0)
     addItemRow(this);
   else {
     ModuleBase_WidgetFactory aFactory(aXmlString, theParent->workshop());
+    Config_ValidatorReader aValidatorReader(aXmlString, true);
+    aValidatorReader.setFeatureId(mySelection->getKind());
+    aValidatorReader.readAll();
+
     QVBoxLayout* aLayout = new QVBoxLayout(this);
     ModuleBase_Tools::zeroMargins(aLayout);
 
@@ -142,11 +161,17 @@ ModuleBase_FilterItem::ModuleBase_FilterItem(
     aLayout->addWidget(aItemRow);
 
     ModuleBase_PageWidget* aParamsWgt = new ModuleBase_PageWidget(this);
+    aParamsWgt->setFrameStyle(QFrame::Box | QFrame::Raised);
     aFactory.createWidget(aParamsWgt);
     ModuleBase_Tools::zeroMargins(aParamsWgt->layout());
-    QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
-    foreach(ModuleBase_ModelWidget* aWidget, aWidgets) {
+    myWidgets = aFactory.getModelWidgets();
+    foreach(ModuleBase_ModelWidget* aWidget, myWidgets) {
       aWidget->setFeature(theParent->feature());
+      connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
+        theParent, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)));
+      connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
+        theParent, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)));
+      connect(aWidget, SIGNAL(objectUpdated()), theParent, SLOT(onObjectUpdated()));
     }
     aLayout->addWidget(aParamsWgt);
   }
@@ -160,9 +185,13 @@ void ModuleBase_FilterItem::addItemRow(QWidget* theParent)
   // Reverse filter button
   myRevBtn = new QToolButton(theParent);
   myRevBtn->setCheckable(true);
-  myRevBtn->setChecked(false);
+  bool isReversed = mySelection->isReversed(myFilterID);
+  myRevBtn->setChecked(isReversed);
   myRevBtn->setAutoRaise(true);
-  myRevBtn->setIcon(QIcon(":pictures/add.png"));
+  if (isReversed)
+    myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
+  else
+    myRevBtn->setIcon(QIcon(":pictures/add.png"));
   myRevBtn->setToolTip(tr("Reverse the filter"));
   connect(myRevBtn, SIGNAL(toggled(bool)), SLOT(onReverse(bool)));
   aLayout->addWidget(myRevBtn);
@@ -198,18 +227,18 @@ void ModuleBase_FilterItem::onDelete()
 //*****************************************************************************
 //*****************************************************************************
 ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theParent,
-  ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData)
+  ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, bool theReadOnly)
   : ModuleBase_ModelWidget(theParent, theData),
   myWorkshop(theWorkshop),
-  mySelectorFeature(SelectorFeature),
-  mySelectorAttribute(AttributeId)
+  mySelectorFeature(ModuleBase_WidgetSelectionFilter::SelectorFeature),
+  mySelectorAttribute(ModuleBase_WidgetSelectionFilter::AttributeId)
 {
   // Clear Old selection
-  AttributePtr aAttr = SelectorFeature->attribute(AttributeId);
-  AttributeSelectionListPtr aSelListAttr =
-    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
-  mySelectionType = selectionType(aSelListAttr->selectionType().c_str());
-  aSelListAttr->clear();
+    AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
+    mySelectionType = selectionType(aAttrList->selectionType().c_str());
+  if (!theReadOnly) {
+    aAttrList->clear();
+  }
 
   // Define widgets
   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
@@ -275,6 +304,12 @@ ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theP
   aMainLayout->addStretch(1);
 
   updateSelectBtn();
+  if (theReadOnly) {
+    myFiltersCombo->hide();
+    mySelectBtn->hide();
+    aLblWgt->hide();
+    myShowBtn->hide();
+  }
 }
 
 ModuleBase_WidgetSelectionFilter::~ModuleBase_WidgetSelectionFilter()
@@ -284,17 +319,23 @@ ModuleBase_WidgetSelectionFilter::~ModuleBase_WidgetSelectionFilter()
     Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
     aCtx->Remove(myPreview, false);
     myPreview.Nullify();
-    if (myShowBtn->isChecked()) {
+    if (myListIO.Size() > 0) {
+      Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
       AIS_ListOfInteractive::const_iterator aIt;
       Handle(AIS_Shape) aShapeIO;
       for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
         aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
         if (!aShapeIO.IsNull()) {
           aCtx->Display(aShapeIO, false);
+          std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
+          anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
+          myWorkshop->applyCurrentSelectionModes(anAISObj);
         }
       }
+      myListIO.Clear();
+      myShowBtn->setChecked(false);
     }
-    aCtx->UpdateCurrentViewer();
+    myWorkshop->viewer()->update();
   }
   SelectorFeature = FeaturePtr();
   AttributeId = "";
@@ -311,33 +352,55 @@ void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex)
   for (aIt = myFilters.begin(), i = 0; aIt != myFilters.cend(); i++, aIt++) {
     if (i == (theIndex - 1)) {
       aFilter = (*aIt);
-      myFilters.erase(aIt);
       break;
     }
   }
-  if (!aFilter.empty()) {
-    myUseFilters.push_back(aFilter);
-    ModuleBase_FilterItem* aItem = new ModuleBase_FilterItem(aFilter, this);
-    connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)),
-      SLOT(onDeleteItem(ModuleBase_FilterItem*)));
-    connect(aItem, SIGNAL(reversedItem(ModuleBase_FilterItem*)),
-      SLOT(onReverseItem(ModuleBase_FilterItem*)));
-    myFiltersLayout->addWidget(aItem);
-
-    FiltersFeaturePtr aFiltersFeature =
-      std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
-    aFiltersFeature->addFilter(aFilter);
+  ModuleBase_FilterItem* aItem = onAddFilter(aFilter);
+  FiltersFeaturePtr aFiltersFeature =
+    std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
+  aFiltersFeature->addFilter(aFilter);
+
+  myFiltersCombo->setCurrentIndex(0);
+  myFiltersCombo->removeItem(theIndex);
+  updateObject(myFeature);
+
+  if (aItem && (aItem->widgets().size() > 0))
+    aItem->widgets().first()->emitFocusInWidget();
+  else
+    emitFocusInWidget();
+}
+
+ModuleBase_FilterItem* ModuleBase_WidgetSelectionFilter::onAddFilter(const std::string& theFilter)
+{
+  if (theFilter.length() == 0)
+    return 0;
+  std::list<std::string>::const_iterator aIt;
+  for (aIt = myUseFilters.cbegin(); aIt != myUseFilters.cend(); aIt++) {
+    if (theFilter == (*aIt))
+      return 0;
   }
+  myFilters.remove(theFilter);
+  myUseFilters.push_back(theFilter);
+  ModuleBase_FilterItem* aItem = new ModuleBase_FilterItem(theFilter, this);
+  connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)),
+    SLOT(onDeleteItem(ModuleBase_FilterItem*)));
+  connect(aItem, SIGNAL(reversedItem(ModuleBase_FilterItem*)),
+    SLOT(onReverseItem(ModuleBase_FilterItem*)));
+  myFiltersLayout->addWidget(aItem);
+
   updateSelectBtn();
   clearCurrentSelection(true);
   updateNumberSelected();
-  myFiltersCombo->setCurrentIndex(0);
-  myFiltersCombo->removeItem(theIndex);
+  return aItem;
 }
 
 void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theItem)
 {
   std::string aFilter = theItem->filter();
+  QList<ModuleBase_ModelWidget*> aWidgets = theItem->widgets();
+  foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
+    aWgt->deactivate();
+  }
   myFiltersLayout->removeWidget(theItem);
   theItem->deleteLater();
 
@@ -352,6 +415,21 @@ void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theIt
   updateSelectBtn();
   clearCurrentSelection(true);
   updateNumberSelected();
+
+  myWorkshop->deactivateCurrentSelector();
+  myWorkshop->selectionActivate()->updateSelectionModes();
+  myWorkshop->selectionActivate()->updateSelectionFilters();
+  redisplayFeature();
+  emitFocusInWidget();
+  updateObject(myFeature);
+}
+
+
+void ModuleBase_WidgetSelectionFilter::redisplayFeature()
+{
+  static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  ModelAPI_EventCreator::get()->sendUpdated(myFeature, aDispEvent);
+  Events_Loop::loop()->flush(aDispEvent);
 }
 
 void ModuleBase_WidgetSelectionFilter::onReverseItem(ModuleBase_FilterItem* theItem)
@@ -375,40 +453,39 @@ void ModuleBase_WidgetSelectionFilter::onSelect()
   TopoDS_Compound aComp;
   aBuilder.MakeCompound(aComp);
 
-  if (!myShowBtn->isChecked()) {
-    myListIO.Clear();
-    aCtx->DisplayedObjects(AIS_KOI_Shape, -1, myListIO);
-    if (!myPreview.IsNull())
-      myListIO.Remove(myPreview);
-  }
-  AIS_ListOfInteractive::const_iterator aIt;
-  Handle(ModuleBase_ResultPrs) aShapeIO;
-  for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
-    aShapeIO = Handle(ModuleBase_ResultPrs)::DownCast(*aIt);
-    if (!aShapeIO.IsNull()) {
-      GeomShapePtr aShape(new GeomAPI_Shape);
-      aShape->setImpl(new TopoDS_Shape(aShapeIO->Shape()));
-      std::list<GeomShapePtr> aSubShapes =
-        aShape->subShapes((GeomAPI_Shape::ShapeType)mySelectionType);
-      std::list<GeomShapePtr>::const_iterator aShapesIt;
-      for (aShapesIt = aSubShapes.cbegin(); aShapesIt != aSubShapes.cend(); aShapesIt++) {
-        GeomShapePtr aShape = (*aShapesIt);
-        SessionPtr aSession = ModelAPI_Session::get();
-        bool isValid = aSession->filters()->isValid(myFeature, aShape);
-        if (isValid) {
-          TopoDS_Shape aTShape = aShape->impl<TopoDS_Shape>();
-          Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(aTShape, aShapeIO, true);
-          aBuilder.Add(aComp, aTShape);
-
-          ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aShapeIO->getResult(), aShape, aOwner));
-          myValues.append(aValue);
-        }
+  DocumentPtr aDoc = myFeature->document();
+  int aNb = aDoc->size(ModelAPI_ResultBody::group());
+  ObjectPtr aObj;
+  ResultBodyPtr aBody;
+  GeomShapePtr aShape;
+  for (int i = 0; i < aNb; i++) {
+    aObj = aDoc->object(ModelAPI_ResultBody::group(), i);
+    aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
+    GeomShapePtr aShape = aBody->shape();
+    std::list<GeomShapePtr> aSubShapes =
+      aShape->subShapes((GeomAPI_Shape::ShapeType)mySelectionType);
+    TopTools_MapOfShape alreadyThere;
+    std::list<GeomShapePtr>::const_iterator aShapesIt;
+    for (aShapesIt = aSubShapes.cbegin(); aShapesIt != aSubShapes.cend(); aShapesIt++) {
+      GeomShapePtr aShape = (*aShapesIt);
+      TopoDS_Shape aTShape = aShape->impl<TopoDS_Shape>();
+      if (!alreadyThere.Add(aTShape))
+        continue;
+      static SessionPtr aSession = ModelAPI_Session::get();
+      bool isValid = aSession->filters()->isValid(myFeature, aBody, aShape);
+      if (isValid) {
+        aBuilder.Add(aComp, aTShape);
+        ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aShape));
+        myValues.append(aValue);
       }
     }
   }
+
   if (myValues.size() > 0)
     updatePreview(aComp);
   updateNumberSelected();
+  updateObject(myFeature);
+  onShowOnly(myShowBtn->isChecked());
 }
 
 void ModuleBase_WidgetSelectionFilter::updatePreview(const TopoDS_Shape& theShape)
@@ -419,8 +496,16 @@ void ModuleBase_WidgetSelectionFilter::updatePreview(const TopoDS_Shape& theShap
 
   if (myPreview.IsNull()) {
     myPreview = new AIS_Shape(theShape);
-    myPreview->SetDisplayMode(myShowBtn->isChecked()? AIS_Shaded : AIS_WireFrame);
-    myPreview->SetColor(Quantity_NOC_YELLOW);
+    myPreview->SetDisplayMode(AIS_Shaded);
+    myPreview->SetColor(Quantity_NOC_BLUE1);
+    Handle(Prs3d_Drawer) aDrawer = myPreview->Attributes();
+    if (aDrawer->HasOwnPointAspect()) {
+      aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
+      aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
+      aDrawer->PointAspect()->SetScale(2.);
+    }
+    else
+      aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2.));
     myPreview->SetTransparency();
     aCtx->Display(myPreview, true);
     aCtx->Deactivate(myPreview);
@@ -439,13 +524,11 @@ void ModuleBase_WidgetSelectionFilter::onShowOnly(bool theShow)
   Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
 
   if (theShow) {
-    aCtx->SetDisplayMode(myPreview, AIS_Shaded, false);
-    myListIO.Clear();
-    aCtx->DisplayedObjects(AIS_KOI_Shape, -1, myListIO);
-    myListIO.Remove(myPreview);
-  }
-  else {
-    aCtx->SetDisplayMode(myPreview, AIS_WireFrame, false);
+    AIS_ListOfInteractive aList;
+    aCtx->DisplayedObjects(AIS_KOI_Shape, -1, aList);
+    aList.Remove(myPreview);
+    if (aList.Size() > 0)
+      myListIO = aList;
   }
   AIS_ListOfInteractive::const_iterator aIt;
   Handle(AIS_Shape) aShapeIO;
@@ -454,11 +537,15 @@ void ModuleBase_WidgetSelectionFilter::onShowOnly(bool theShow)
     if (!aShapeIO.IsNull()) {
       if (theShow)
         aCtx->Erase(aShapeIO, false);
-      else
+      else {
         aCtx->Display(aShapeIO, false);
+        std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
+        anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
+        myWorkshop->applyCurrentSelectionModes(anAISObj);
+      }
     }
   }
-  aCtx->UpdateCurrentViewer();
+  myWorkshop->viewer()->update();
 }
 
 void ModuleBase_WidgetSelectionFilter::updateSelectBtn()
@@ -468,11 +555,22 @@ void ModuleBase_WidgetSelectionFilter::updateSelectBtn()
 
 void ModuleBase_WidgetSelectionFilter::updateNumberSelected()
 {
-  myNbLbl->setText(QString::number(myValues.size()));
+  int aNb = myValues.size();
+  myNbLbl->setText(QString::number(aNb));
+  //QString aErr = () ? tr("Selection is empty") : "";
+  if (aNb == 0)
+    myFeature->setError(tr("Selection is empty").toStdString(), false, false);
+  else {
+    myFeature->setError("", false, false);
+    myFeature->data()->execState(ModelAPI_StateDone);
+  }
 }
+
 QList<QWidget*> ModuleBase_WidgetSelectionFilter::getControls() const
 {
-  return QList<QWidget*>();
+  QList<QWidget*> aWidgets;
+  aWidgets.append(myFiltersCombo);
+  return aWidgets;
 }
 
 void ModuleBase_WidgetSelectionFilter::clearCurrentSelection(bool toUpdate)
@@ -485,13 +583,134 @@ void ModuleBase_WidgetSelectionFilter::clearCurrentSelection(bool toUpdate)
   }
 }
 
+void replaceSubShapesByResult(QList<ModuleBase_ViewerPrsPtr>& theResults, int theShapeType)
+{
+  QMap<ObjectPtr, QList<GeomShapePtr>> myResShapes;
+  // Sort sub-shapes by result
+  foreach (ModuleBase_ViewerPrsPtr aPrs, theResults) {
+    if (myResShapes.contains(aPrs->object()))
+      myResShapes[aPrs->object()].append(aPrs->shape());
+    else {
+      QList<GeomShapePtr> aShapes;
+      aShapes << aPrs->shape();
+      myResShapes[aPrs->object()] = aShapes;
+    }
+  }
+  // Find Results to replace by whole result
+  QList<GeomShapePtr> aShapes;
+  QList<ObjectPtr> aToReplace;
+  std::list<GeomShapePtr> aSubShapes;
+  foreach(ObjectPtr aObj, myResShapes.keys()) {
+    aShapes = myResShapes[aObj];
+    ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+    TopTools_MapOfShape aShapesMap;
+    if (aRes.get()) {
+      GeomShapePtr aSubShape = aRes->shape();
+      const TopoDS_Shape& aShape = aSubShape->impl<TopoDS_Shape>();
+      for (TopExp_Explorer anExp(aShape, (TopAbs_ShapeEnum)theShapeType);
+        anExp.More(); anExp.Next()) {
+        aShapesMap.Add(anExp.Current());
+      }
+    }
+    if (aShapes.count() == aShapesMap.Size())
+      aToReplace.append(aObj);
+  }
+  // Replace the found results
+  QList<ModuleBase_ViewerPrsPtr>::iterator aIt;
+  foreach(ObjectPtr aObj, aToReplace) {
+    for (aIt = theResults.begin(); aIt != theResults.end(); aIt++) {
+      if ((*aIt)->object() == aObj) {
+        theResults.removeAll(*aIt);
+        aIt--;
+      }
+    }
+    ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj));
+    theResults.append(aValue);
+  }
+}
+
 void ModuleBase_WidgetSelectionFilter::onFeatureAccepted()
 {
   AttributePtr aAttr = mySelectorFeature->attribute(mySelectorAttribute);
   AttributeSelectionListPtr aSelListAttr =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
   aSelListAttr->clear();
+  if (aSelListAttr->isWholeResultAllowed())
+    replaceSubShapesByResult(myValues, selectionType(aSelListAttr->selectionType().c_str()));
   foreach(ModuleBase_ViewerPrsPtr aPrs, myValues) {
     aSelListAttr->append(aPrs->object(), aPrs->shape());
   }
-}
\ No newline at end of file
+}
+
+bool ModuleBase_WidgetSelectionFilter::storeValueCustom()
+{
+  ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget();
+  if (aActive)
+    return aActive->storeValue();
+  updateObject(myFeature);
+  return true;
+}
+
+bool ModuleBase_WidgetSelectionFilter::restoreValueCustom()
+{
+  ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
+  FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
+
+  // Init filters member of the parent attribute
+  AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
+  if (aAttrList->filters() != aFiltersFeature) {
+    aAttrList->setFilters(aFiltersFeature);
+  }
+
+  std::list<std::string> aFilters = aFiltersFeature->filters();
+  std::list<std::string>::const_iterator aIt;
+  for (aIt = aFilters.cbegin(); aIt != aFilters.cend(); aIt++) {
+    std::string aStr = (*aIt);
+    ModuleBase_FilterItem* aItem = onAddFilter(aStr);
+    FilterPtr aFilterObj = aFactory->filter(aStr);
+    int aId = myFiltersCombo->findText(aFilterObj->name().c_str());
+    if (aId != -1)
+      myFiltersCombo->removeItem(aId);
+
+    if (aItem) {
+      QList<ModuleBase_ModelWidget*> aSubList = aItem->widgets();
+      foreach(ModuleBase_ModelWidget* aWgt, aSubList) {
+        aWgt->restoreValue();
+      }
+    }
+  }
+  return true;
+}
+
+QString ModuleBase_WidgetSelectionFilter::getError(const bool theValueStateChecked) const
+{
+  QString aErrorMsg = ModuleBase_ModelWidget::getError(theValueStateChecked);
+  if (aErrorMsg.isEmpty()) {
+    if (myValues.size() == 0)
+      aErrorMsg = tr("Selection is empty");
+  }
+  return aErrorMsg;
+}
+
+void ModuleBase_WidgetSelectionFilter::onObjectUpdated()
+{
+  myShowBtn->setChecked(false);
+  clearCurrentSelection(true);
+  updateNumberSelected();
+
+  QList<ModuleBase_FilterItem*> aItemsList = myFiltersWgt->findChildren<ModuleBase_FilterItem*>();
+  foreach(ModuleBase_FilterItem* aItem, aItemsList) {
+    QList<ModuleBase_ModelWidget*> aWidgetsList = aItem->widgets();
+    foreach(ModuleBase_ModelWidget* aWidget, aWidgetsList) {
+      if (!aWidget->feature().get())
+        aWidget->setFeature(myFeature);
+      aWidget->restoreValue();
+    }
+  }
+  updateObject(myFeature);
+
+  // Redisplay the feature on order to Customize presentations from filters with selectors
+  static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  ModelAPI_EventCreator::get()->sendUpdated(myFeature, EVENT_DISP);
+  Events_Loop::loop()->flush(EVENT_DISP);
+}