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