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