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