]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp
Salome HOME
Issue #2954: Provide activation/deactivation of filters
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelectionFilter.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ModuleBase_WidgetSelectionFilter.h"
21 #include "ModuleBase_Tools.h"
22 #include "ModuleBase_IWorkshop.h"
23 #include "ModuleBase_ISelectionActivate.h"
24 #include "ModuleBase_IModule.h"
25 #include "ModuleBase_IViewer.h"
26 #include "ModuleBase_IPropertyPanel.h"
27 #include "ModuleBase_PageWidget.h"
28 #include "ModuleBase_WidgetMultiSelector.h"
29 #include "ModuleBase_ResultPrs.h"
30 #include "ModuleBase_WidgetFactory.h"
31
32 #include <ModelAPI_Session.h>
33 #include <ModelAPI_AttributeSelectionList.h>
34 #include <ModelAPI_Events.h>
35 #include <ModelAPI_FiltersFactory.h>
36 #include <ModelAPI_ResultBody.h>
37 #include <GeomAPI_ShapeExplorer.h>
38
39 #include <Events_Loop.h>
40 #include <Config_ValidatorReader.h>
41
42 #include <AIS_InteractiveContext.hxx>
43 #include <StdSelect_BRepOwner.hxx>
44 #include <TopoDS_Compound.hxx>
45 #include <BRep_Builder.hxx>
46
47 #include <QLayout>
48 #include <QPushButton>
49 #include <QLabel>
50 #include <QComboBox>
51 #include <QGroupBox>
52 #include <QDialog>
53 #include <QToolButton>
54 #include <QCheckBox>
55
56 static FeaturePtr SelectorFeature;
57 static std::string AttributeId;
58
59
60 GeomAPI_Shape::ShapeType selectionType(const QString& theType)
61 {
62   QString aType = theType.toUpper();
63   if ((aType == "VERTEX") || (aType == "VERTICES"))
64     return GeomAPI_Shape::VERTEX;
65   else if ((aType == "EDGE") || (aType == "EDGES"))
66     return GeomAPI_Shape::EDGE;
67   else if ((aType == "WIRE") || (aType == "WIRES"))
68     return GeomAPI_Shape::WIRE;
69   else if ((aType == "FACE") || (aType == "FACES"))
70     return GeomAPI_Shape::FACE;
71   else if ((aType == "SHELL") || (aType == "SHELLS"))
72     return GeomAPI_Shape::SHELL;
73   else if ((aType == "SOLID") || (aType == "SOLIDS"))
74     return GeomAPI_Shape::SOLID;
75   else if ((aType == "COMPSOLID") || (aType == "COMPSOLIDS"))
76     return GeomAPI_Shape::COMPSOLID;
77   else if ((aType == "COMPOUND") || (aType == "COMPOUNDS"))
78     return GeomAPI_Shape::COMPOUND;
79   else
80     return GeomAPI_Shape::SHAPE;
81 }
82
83
84 ModuleBase_FilterStarter::ModuleBase_FilterStarter(const std::string& theFeature,
85   QWidget* theParent, ModuleBase_IWorkshop* theWorkshop)
86   : QWidget(theParent),
87   myFeatureName(theFeature),
88   myWorkshop(theWorkshop)
89 {
90   QHBoxLayout* aMainLayout = new QHBoxLayout(this);
91   ModuleBase_Tools::adjustMargins(aMainLayout);
92
93   aMainLayout->addStretch(1);
94   QPushButton* aLaunchBtn = new QPushButton(tr("Selection by filters"), this);
95   connect(aLaunchBtn, SIGNAL(clicked()), SLOT(onFiltersLaunch()));
96   aMainLayout->addWidget(aLaunchBtn);
97 }
98
99 void ModuleBase_FilterStarter::onFiltersLaunch()
100 {
101   ModuleBase_Operation* aParentOp = myWorkshop->currentOperation();
102   ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(aParentOp);
103   if (aFeatureOp)
104     // Open transaction on filters operation finish
105     aFeatureOp->openTransactionOnResume();
106
107   QWidget* aParent = parentWidget();
108   ModuleBase_WidgetMultiSelector* aSelector =
109     dynamic_cast<ModuleBase_WidgetMultiSelector*>(aParent);
110   while (!aSelector) {
111     aParent = aParent->parentWidget();
112     aSelector = dynamic_cast<ModuleBase_WidgetMultiSelector*>(aParent);
113   }
114   if (!aSelector)
115     return;
116   SelectorFeature = aSelector->feature();
117   AttributeId = aSelector->attributeID();
118
119   // Launch Filters operation
120   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
121     (myWorkshop->module()->createOperation(myFeatureName));
122
123   AttributeSelectionListPtr aAttrList = SelectorFeature->selectionList(AttributeId);
124   FiltersFeaturePtr aFilters = aAttrList->filters();
125   if (aFilters.get())
126     aFOperation->setFeature(aFilters);
127   myWorkshop->processLaunchOperation(aFOperation);
128 }
129
130 //*****************************************************************************
131 //*****************************************************************************
132 //*****************************************************************************
133 ModuleBase_FilterItem::ModuleBase_FilterItem(
134   const std::string& theFilter, ModuleBase_WidgetSelectionFilter* theParent)
135   : QWidget(theParent->filtersWidget()), myFilterID(theFilter),
136     mySelection(std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(theParent->feature()))
137 {
138   std::string aXmlString =
139       ModelAPI_Session::get()->filters()->filter(theFilter)->xmlRepresentation();
140   if (aXmlString.length() == 0)
141     addItemRow(this);
142   else {
143     ModuleBase_WidgetFactory aFactory(aXmlString, theParent->workshop());
144     Config_ValidatorReader aValidatorReader(aXmlString, true);
145     aValidatorReader.setFeatureId(mySelection->getKind());
146     aValidatorReader.readAll();
147
148     QVBoxLayout* aLayout = new QVBoxLayout(this);
149     ModuleBase_Tools::zeroMargins(aLayout);
150
151     QWidget* aItemRow = new QWidget(this);
152     addItemRow(aItemRow);
153     aLayout->addWidget(aItemRow);
154
155     ModuleBase_PageWidget* aParamsWgt = new ModuleBase_PageWidget(this);
156     aParamsWgt->setFrameStyle(QFrame::Box | QFrame::Raised);
157     aFactory.createWidget(aParamsWgt);
158     ModuleBase_Tools::zeroMargins(aParamsWgt->layout());
159     myWidgets = aFactory.getModelWidgets();
160     foreach(ModuleBase_ModelWidget* aWidget, myWidgets) {
161       aWidget->setFeature(theParent->feature());
162       connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
163         theParent, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)));
164       connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
165         theParent, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)));
166       connect(aWidget, SIGNAL(objectUpdated()), theParent, SLOT(onObjectUpdated()));
167     }
168     aLayout->addWidget(aParamsWgt);
169   }
170 }
171
172 void ModuleBase_FilterItem::addItemRow(QWidget* theParent)
173 {
174   QHBoxLayout* aLayout = new QHBoxLayout(theParent);
175   ModuleBase_Tools::zeroMargins(aLayout);
176
177   // Reverse filter button
178   myRevBtn = new QToolButton(theParent);
179   myRevBtn->setCheckable(true);
180   bool isReversed = mySelection->isReversed(myFilterID);
181   myRevBtn->setChecked(isReversed);
182   myRevBtn->setAutoRaise(true);
183   if (isReversed)
184     myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
185   else
186     myRevBtn->setIcon(QIcon(":pictures/add.png"));
187   myRevBtn->setToolTip(tr("Reverse the filter"));
188   connect(myRevBtn, SIGNAL(toggled(bool)), SLOT(onReverse(bool)));
189   aLayout->addWidget(myRevBtn);
190
191   const std::string& aFilterName = ModelAPI_Session::get()->filters()->filter(myFilterID)->name();
192   aLayout->addWidget(new QLabel(aFilterName.c_str(), theParent), 1);
193
194   QToolButton* aDelBtn = new QToolButton(theParent);
195   aDelBtn->setIcon(QIcon(":pictures/delete.png"));
196   aDelBtn->setAutoRaise(true);
197   aDelBtn->setToolTip(tr("Delete the filter"));
198   connect(aDelBtn, SIGNAL(clicked(bool)), SLOT(onDelete()));
199   aLayout->addWidget(aDelBtn);
200 }
201
202 void ModuleBase_FilterItem::onReverse(bool theCheck)
203 {
204   mySelection->setReversed(myFilterID, theCheck);
205   if (theCheck)
206     myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
207   else
208     myRevBtn->setIcon(QIcon(":pictures/add.png"));
209   emit reversedItem(this);
210 }
211
212 void ModuleBase_FilterItem::onDelete()
213 {
214   emit deleteItem(this);
215 }
216
217
218 //*****************************************************************************
219 //*****************************************************************************
220 //*****************************************************************************
221 ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theParent,
222   ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData)
223   : ModuleBase_ModelWidget(theParent, theData),
224   myWorkshop(theWorkshop),
225   mySelectorFeature(SelectorFeature),
226   mySelectorAttribute(AttributeId)
227 {
228   // Clear Old selection
229   AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
230   mySelectionType = selectionType(aAttrList->selectionType().c_str());
231   aAttrList->clear();
232
233   // Define widgets
234   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
235   ModuleBase_Tools::adjustMargins(aMainLayout);
236
237   QGroupBox* aFiltersGroup = new QGroupBox(tr("Filters"), this);
238   QVBoxLayout* aGroupLayout = new QVBoxLayout(aFiltersGroup);
239   aGroupLayout->setContentsMargins(0, 0, 0, 0);
240   aGroupLayout->setSpacing(0);
241
242   myFiltersWgt = new QWidget();
243   myFiltersLayout = new QVBoxLayout(myFiltersWgt);
244   myFiltersLayout->setContentsMargins(0, 0, 0, 0);
245   aGroupLayout->addWidget(myFiltersWgt);
246
247   myFiltersCombo = new QComboBox(aFiltersGroup);
248   myFiltersCombo->addItem(tr("Add new filter..."));
249   SessionPtr aSession = ModelAPI_Session::get();
250   std::list<FilterPtr> allFilters =
251     aSession->filters()->filters((GeomAPI_Shape::ShapeType) mySelectionType);
252   QStringList aItems;
253   std::list<FilterPtr>::const_iterator aIt;
254   for (aIt = allFilters.cbegin(); aIt != allFilters.cend(); aIt++) {
255     aItems.push_back((*aIt)->name().c_str());
256     myFilters.push_back(aSession->filters()->id(*aIt));
257   }
258   myFiltersCombo->addItems(aItems);
259   connect(myFiltersCombo, SIGNAL(currentIndexChanged(int)), SLOT(onAddFilter(int)));
260
261   aGroupLayout->addWidget(myFiltersCombo);
262   aMainLayout->addWidget(aFiltersGroup);
263
264   // Select Button
265   QWidget* aBtnWgt = new QWidget(this);
266   QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnWgt);
267   ModuleBase_Tools::adjustMargins(aBtnLayout);
268
269   aBtnLayout->addStretch(1);
270
271   mySelectBtn = new QPushButton(tr("Select"), aBtnWgt);
272   connect(mySelectBtn, SIGNAL(clicked()), SLOT(onSelect()));
273   aBtnLayout->addWidget(mySelectBtn);
274
275   aMainLayout->addWidget(aBtnWgt);
276
277   // Label widgets
278   QWidget* aLblWgt = new QWidget(this);
279   QHBoxLayout* aLblLayout = new QHBoxLayout(aLblWgt);
280   ModuleBase_Tools::zeroMargins(aLblLayout);
281
282   aLblLayout->addWidget(new QLabel(tr("Number of selected objects:"), aLblWgt));
283
284   myNbLbl = new QLabel("0", aLblWgt);
285   aLblLayout->addWidget(myNbLbl);
286
287   // Show only button
288   myShowBtn = new QCheckBox(tr("Show only"), this);
289   connect(myShowBtn, SIGNAL(toggled(bool)), SLOT(onShowOnly(bool)));
290   aLblLayout->addWidget(myShowBtn);
291
292   aMainLayout->addWidget(aLblWgt);
293
294   aMainLayout->addStretch(1);
295
296   updateSelectBtn();
297 }
298
299 ModuleBase_WidgetSelectionFilter::~ModuleBase_WidgetSelectionFilter()
300 {
301   myValues.clear();
302   if (!myPreview.IsNull()) {
303     Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
304     aCtx->Remove(myPreview, false);
305     myPreview.Nullify();
306     if (myShowBtn->isChecked()) {
307       AIS_ListOfInteractive::const_iterator aIt;
308       Handle(AIS_Shape) aShapeIO;
309       for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
310         aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
311         if (!aShapeIO.IsNull()) {
312           aCtx->Display(aShapeIO, false);
313         }
314       }
315     }
316     aCtx->UpdateCurrentViewer();
317   }
318   SelectorFeature = FeaturePtr();
319   AttributeId = "";
320 }
321
322 void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex)
323 {
324   if (theIndex == 0)
325     return;
326
327   std::list<std::string>::iterator aIt;
328   int i;
329   std::string aFilter;
330   for (aIt = myFilters.begin(), i = 0; aIt != myFilters.cend(); i++, aIt++) {
331     if (i == (theIndex - 1)) {
332       aFilter = (*aIt);
333       break;
334     }
335   }
336   ModuleBase_FilterItem* aItem = onAddFilter(aFilter);
337   FiltersFeaturePtr aFiltersFeature =
338     std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
339   aFiltersFeature->addFilter(aFilter);
340
341   myFiltersCombo->setCurrentIndex(0);
342   myFiltersCombo->removeItem(theIndex);
343   updateObject(myFeature);
344
345   if (aItem && (aItem->widgets().size() > 0))
346     aItem->widgets().first()->emitFocusInWidget();
347   else
348     emitFocusInWidget();
349 }
350
351 ModuleBase_FilterItem* ModuleBase_WidgetSelectionFilter::onAddFilter(const std::string& theFilter)
352 {
353   if (theFilter.length() == 0)
354     return 0;
355   std::list<std::string>::const_iterator aIt;
356   for (aIt = myUseFilters.cbegin(); aIt != myUseFilters.cend(); aIt++) {
357     if (theFilter == (*aIt))
358       return 0;
359   }
360   myFilters.remove(theFilter);
361   myUseFilters.push_back(theFilter);
362   ModuleBase_FilterItem* aItem = new ModuleBase_FilterItem(theFilter, this);
363   connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)),
364     SLOT(onDeleteItem(ModuleBase_FilterItem*)));
365   connect(aItem, SIGNAL(reversedItem(ModuleBase_FilterItem*)),
366     SLOT(onReverseItem(ModuleBase_FilterItem*)));
367   myFiltersLayout->addWidget(aItem);
368
369   updateSelectBtn();
370   clearCurrentSelection(true);
371   updateNumberSelected();
372   return aItem;
373 }
374
375 void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theItem)
376 {
377   std::string aFilter = theItem->filter();
378   QList<ModuleBase_ModelWidget*> aWidgets = theItem->widgets();
379   foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
380     aWgt->deactivate();
381   }
382   myFiltersLayout->removeWidget(theItem);
383   theItem->deleteLater();
384
385   myUseFilters.remove(aFilter);
386   myFilters.push_back(aFilter);
387   myFiltersCombo->addItem(ModelAPI_Session::get()->filters()->filter(aFilter)->name().c_str());
388
389   FiltersFeaturePtr aFiltersFeature =
390     std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
391   aFiltersFeature->removeFilter(aFilter);
392
393   updateSelectBtn();
394   clearCurrentSelection(true);
395   updateNumberSelected();
396
397   myWorkshop->deactivateCurrentSelector();
398   myWorkshop->selectionActivate()->updateSelectionModes();
399   myWorkshop->selectionActivate()->updateSelectionFilters();
400   redisplayFeature();
401   emitFocusInWidget();
402   updateObject(myFeature);
403 }
404
405
406 void ModuleBase_WidgetSelectionFilter::redisplayFeature()
407 {
408   static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
409   ModelAPI_EventCreator::get()->sendUpdated(myFeature, aDispEvent);
410   Events_Loop::loop()->flush(aDispEvent);
411 }
412
413 void ModuleBase_WidgetSelectionFilter::onReverseItem(ModuleBase_FilterItem* theItem)
414 {
415   updateSelectBtn();
416   clearCurrentSelection(true);
417   updateNumberSelected();
418 }
419
420 void ModuleBase_WidgetSelectionFilter::onSelect()
421 {
422   if (myUseFilters.size() == 0)
423     return;
424   Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
425   if (aCtx.IsNull())
426     return;
427
428   clearCurrentSelection();
429
430   BRep_Builder aBuilder;
431   TopoDS_Compound aComp;
432   aBuilder.MakeCompound(aComp);
433
434   DocumentPtr aDoc = myFeature->document();
435   int aNb = aDoc->size(ModelAPI_ResultBody::group());
436   ObjectPtr aObj;
437   ResultBodyPtr aBody;
438   GeomShapePtr aShape;
439   for (int i = 0; i < aNb; i++) {
440     aObj = aDoc->object(ModelAPI_ResultBody::group(), i);
441     aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
442     GeomShapePtr aShape = aBody->shape();
443     std::list<GeomShapePtr> aSubShapes =
444       aShape->subShapes((GeomAPI_Shape::ShapeType)mySelectionType);
445     TopTools_MapOfShape alreadyThere;
446     std::list<GeomShapePtr>::const_iterator aShapesIt;
447     for (aShapesIt = aSubShapes.cbegin(); aShapesIt != aSubShapes.cend(); aShapesIt++) {
448       GeomShapePtr aShape = (*aShapesIt);
449       TopoDS_Shape aTShape = aShape->impl<TopoDS_Shape>();
450       if (!alreadyThere.Add(aTShape))
451         continue;
452       static SessionPtr aSession = ModelAPI_Session::get();
453       bool isValid = aSession->filters()->isValid(myFeature, aBody, aShape);
454       if (isValid) {
455         aBuilder.Add(aComp, aTShape);
456         ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aShape));
457         myValues.append(aValue);
458       }
459     }
460   }
461
462   if (myValues.size() > 0)
463     updatePreview(aComp);
464   updateNumberSelected();
465   updateObject(myFeature);
466 }
467
468 void ModuleBase_WidgetSelectionFilter::updatePreview(const TopoDS_Shape& theShape)
469 {
470   Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
471   if (aCtx.IsNull())
472     return;
473
474   if (myPreview.IsNull()) {
475     myPreview = new AIS_Shape(theShape);
476     myPreview->SetDisplayMode(AIS_Shaded);
477     myPreview->SetColor(Quantity_NOC_BLUE1);
478     Handle(Prs3d_Drawer) aDrawer = myPreview->Attributes();
479     if (aDrawer->HasOwnPointAspect()) {
480       aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
481       aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
482       aDrawer->PointAspect()->SetScale(2.);
483     }
484     else
485       aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2.));
486     myPreview->SetTransparency();
487     aCtx->Display(myPreview, true);
488     aCtx->Deactivate(myPreview);
489   }
490   else {
491     myPreview->Set(theShape);
492     aCtx->Redisplay(myPreview, true);
493   }
494 }
495
496
497 void ModuleBase_WidgetSelectionFilter::onShowOnly(bool theShow)
498 {
499   if (myPreview.IsNull())
500     return;
501   Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
502
503   if (theShow) {
504     myListIO.Clear();
505     aCtx->DisplayedObjects(AIS_KOI_Shape, -1, myListIO);
506     myListIO.Remove(myPreview);
507   }
508   AIS_ListOfInteractive::const_iterator aIt;
509   Handle(AIS_Shape) aShapeIO;
510   for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
511     aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
512     if (!aShapeIO.IsNull()) {
513       if (theShow)
514         aCtx->Erase(aShapeIO, false);
515       else
516         aCtx->Display(aShapeIO, false);
517     }
518   }
519   aCtx->UpdateCurrentViewer();
520 }
521
522 void ModuleBase_WidgetSelectionFilter::updateSelectBtn()
523 {
524   mySelectBtn->setEnabled(myUseFilters.size() > 0);
525 }
526
527 void ModuleBase_WidgetSelectionFilter::updateNumberSelected()
528 {
529   int aNb = myValues.size();
530   myNbLbl->setText(QString::number(aNb));
531   //QString aErr = () ? tr("Selection is empty") : "";
532   if (aNb == 0)
533     myFeature->setError(tr("Selection is empty").toStdString(), false, false);
534   else {
535     myFeature->setError("", false, false);
536     myFeature->data()->execState(ModelAPI_StateDone);
537   }
538 }
539
540 QList<QWidget*> ModuleBase_WidgetSelectionFilter::getControls() const
541 {
542   QList<QWidget*> aWidgets;
543   aWidgets.append(myFiltersCombo);
544   return aWidgets;
545 }
546
547 void ModuleBase_WidgetSelectionFilter::clearCurrentSelection(bool toUpdate)
548 {
549   myValues.clear();
550   if (!myPreview.IsNull()) {
551     Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
552     aCtx->Remove(myPreview, toUpdate);
553     myPreview.Nullify();
554   }
555 }
556
557 void ModuleBase_WidgetSelectionFilter::onFeatureAccepted()
558 {
559   AttributePtr aAttr = mySelectorFeature->attribute(mySelectorAttribute);
560   AttributeSelectionListPtr aSelListAttr =
561     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
562   aSelListAttr->clear();
563   foreach(ModuleBase_ViewerPrsPtr aPrs, myValues) {
564     aSelListAttr->append(aPrs->object(), aPrs->shape());
565   }
566 }
567
568 bool ModuleBase_WidgetSelectionFilter::storeValueCustom()
569 {
570   ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget();
571   if (aActive)
572     return aActive->storeValue();
573   updateObject(myFeature);
574   return true;
575 }
576
577 bool ModuleBase_WidgetSelectionFilter::restoreValueCustom()
578 {
579   ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
580   FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
581   std::list<std::string> aFilters = aFiltersFeature->filters();
582   std::list<std::string>::const_iterator aIt;
583   for (aIt = aFilters.cbegin(); aIt != aFilters.cend(); aIt++) {
584     std::string aStr = (*aIt);
585     onAddFilter(aStr);
586     FilterPtr aFilterObj = aFactory->filter(aStr);
587     int aId = myFiltersCombo->findText(aFilterObj->name().c_str());
588     if (aId != -1)
589       myFiltersCombo->removeItem(aId);
590   }
591   // Init filters member of the parent attribute
592   AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
593   if (aAttrList->filters() != aFiltersFeature) {
594     aAttrList->setFilters(aFiltersFeature);
595   }
596
597   QList<QWidget*> aWidgets;
598   QList<ModuleBase_FilterItem*> aItems = myFiltersWgt->findChildren<ModuleBase_FilterItem*>();
599   foreach(ModuleBase_FilterItem* aItem, aItems) {
600     QList<ModuleBase_ModelWidget*> aSubList = aItem->widgets();
601     foreach(ModuleBase_ModelWidget* aWgt, aSubList) {
602       aWgt->restoreValue();
603     }
604   }
605   return true;
606 }
607
608 QString ModuleBase_WidgetSelectionFilter::getError(const bool theValueStateChecked) const
609 {
610   QString aErrorMsg = ModuleBase_ModelWidget::getError(theValueStateChecked);
611   if (aErrorMsg.isEmpty()) {
612     if (myValues.size() == 0)
613       aErrorMsg = tr("Selection is empty");
614   }
615   return aErrorMsg;
616 }
617
618 void ModuleBase_WidgetSelectionFilter::onObjectUpdated()
619 {
620   clearCurrentSelection(true);
621   updateNumberSelected();
622   updateObject(myFeature);
623 }