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