1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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"
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>
39 #include <Events_Loop.h>
40 #include <Config_ValidatorReader.h>
42 #include <AIS_InteractiveContext.hxx>
43 #include <StdSelect_BRepOwner.hxx>
44 #include <TopoDS_Compound.hxx>
45 #include <BRep_Builder.hxx>
46 #include <TopExp_Explorer.hxx>
49 #include <QPushButton>
54 #include <QToolButton>
58 static FeaturePtr SelectorFeature;
59 static std::string AttributeId;
62 GeomAPI_Shape::ShapeType selectionType(const QString& theType)
64 QString aType = theType.toUpper();
65 if ((aType == "VERTEX") || (aType == "VERTICES"))
66 return GeomAPI_Shape::VERTEX;
67 else if ((aType == "EDGE") || (aType == "EDGES"))
68 return GeomAPI_Shape::EDGE;
69 else if ((aType == "WIRE") || (aType == "WIRES"))
70 return GeomAPI_Shape::WIRE;
71 else if ((aType == "FACE") || (aType == "FACES"))
72 return GeomAPI_Shape::FACE;
73 else if ((aType == "SHELL") || (aType == "SHELLS"))
74 return GeomAPI_Shape::SHELL;
75 else if ((aType == "SOLID") || (aType == "SOLIDS"))
76 return GeomAPI_Shape::SOLID;
77 else if ((aType == "COMPSOLID") || (aType == "COMPSOLIDS"))
78 return GeomAPI_Shape::COMPSOLID;
79 else if ((aType == "COMPOUND") || (aType == "COMPOUNDS"))
80 return GeomAPI_Shape::COMPOUND;
82 return GeomAPI_Shape::SHAPE;
86 ModuleBase_FilterStarter::ModuleBase_FilterStarter(const std::string& theFeature,
87 QWidget* theParent, ModuleBase_IWorkshop* theWorkshop)
89 myFeatureName(theFeature),
90 myWorkshop(theWorkshop)
92 QHBoxLayout* aMainLayout = new QHBoxLayout(this);
93 ModuleBase_Tools::adjustMargins(aMainLayout);
95 aMainLayout->addStretch(1);
96 QPushButton* aLaunchBtn = new QPushButton(tr("Selection by filters"), this);
97 connect(aLaunchBtn, SIGNAL(clicked()), SLOT(onFiltersLaunch()));
98 aMainLayout->addWidget(aLaunchBtn);
101 void ModuleBase_FilterStarter::onFiltersLaunch()
103 static QString aHelpFileName = QString("FiltersPlugin") + QDir::separator() +
104 QString("FiltersPlugin.html");
106 ModuleBase_Operation* aParentOp = myWorkshop->currentOperation();
107 ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(aParentOp);
109 // Open transaction on filters operation finish
110 aFeatureOp->openTransactionOnResume();
112 QWidget* aParent = parentWidget();
113 ModuleBase_WidgetMultiSelector* aSelector =
114 dynamic_cast<ModuleBase_WidgetMultiSelector*>(aParent);
116 aParent = aParent->parentWidget();
117 aSelector = dynamic_cast<ModuleBase_WidgetMultiSelector*>(aParent);
121 SelectorFeature = aSelector->feature();
122 AttributeId = aSelector->attributeID();
124 // Launch Filters operation
125 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
126 (myWorkshop->module()->createOperation(myFeatureName));
128 AttributeSelectionListPtr aAttrList = SelectorFeature->selectionList(AttributeId);
129 FiltersFeaturePtr aFilters = aAttrList->filters();
131 aFOperation->setFeature(aFilters);
132 aFOperation->setHelpFileName(aHelpFileName);
133 myWorkshop->processLaunchOperation(aFOperation);
136 //*****************************************************************************
137 //*****************************************************************************
138 //*****************************************************************************
139 ModuleBase_FilterItem::ModuleBase_FilterItem(
140 const std::string& theFilter, ModuleBase_WidgetSelectionFilter* theParent)
141 : QWidget(theParent->filtersWidget()), myFilterID(theFilter),
142 mySelection(std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(theParent->feature()))
144 std::string aXmlString =
145 ModelAPI_Session::get()->filters()->filter(theFilter)->xmlRepresentation();
146 if (aXmlString.length() == 0)
149 ModuleBase_WidgetFactory aFactory(aXmlString, theParent->workshop());
150 Config_ValidatorReader aValidatorReader(aXmlString, true);
151 aValidatorReader.setFeatureId(mySelection->getKind());
152 aValidatorReader.readAll();
154 QVBoxLayout* aLayout = new QVBoxLayout(this);
155 ModuleBase_Tools::zeroMargins(aLayout);
157 QWidget* aItemRow = new QWidget(this);
158 addItemRow(aItemRow);
159 aLayout->addWidget(aItemRow);
161 ModuleBase_PageWidget* aParamsWgt = new ModuleBase_PageWidget(this);
162 aParamsWgt->setFrameStyle(QFrame::Box | QFrame::Raised);
163 aFactory.createWidget(aParamsWgt);
164 ModuleBase_Tools::zeroMargins(aParamsWgt->layout());
165 myWidgets = aFactory.getModelWidgets();
166 foreach(ModuleBase_ModelWidget* aWidget, myWidgets) {
167 aWidget->setFeature(theParent->feature());
168 connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
169 theParent, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)));
170 connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
171 theParent, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)));
172 connect(aWidget, SIGNAL(objectUpdated()), theParent, SLOT(onObjectUpdated()));
174 aLayout->addWidget(aParamsWgt);
178 void ModuleBase_FilterItem::addItemRow(QWidget* theParent)
180 QHBoxLayout* aLayout = new QHBoxLayout(theParent);
181 ModuleBase_Tools::zeroMargins(aLayout);
183 // Reverse filter button
184 myRevBtn = new QToolButton(theParent);
185 myRevBtn->setCheckable(true);
186 bool isReversed = mySelection->isReversed(myFilterID);
187 myRevBtn->setChecked(isReversed);
188 myRevBtn->setAutoRaise(true);
190 myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
192 myRevBtn->setIcon(QIcon(":pictures/add.png"));
193 myRevBtn->setToolTip(tr("Reverse the filter"));
194 connect(myRevBtn, SIGNAL(toggled(bool)), SLOT(onReverse(bool)));
195 aLayout->addWidget(myRevBtn);
197 const std::string& aFilterName = ModelAPI_Session::get()->filters()->filter(myFilterID)->name();
198 aLayout->addWidget(new QLabel(aFilterName.c_str(), theParent), 1);
200 QToolButton* aDelBtn = new QToolButton(theParent);
201 aDelBtn->setIcon(QIcon(":pictures/delete.png"));
202 aDelBtn->setAutoRaise(true);
203 aDelBtn->setToolTip(tr("Delete the filter"));
204 connect(aDelBtn, SIGNAL(clicked(bool)), SLOT(onDelete()));
205 aLayout->addWidget(aDelBtn);
208 void ModuleBase_FilterItem::onReverse(bool theCheck)
210 mySelection->setReversed(myFilterID, theCheck);
212 myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
214 myRevBtn->setIcon(QIcon(":pictures/add.png"));
215 emit reversedItem(this);
218 void ModuleBase_FilterItem::onDelete()
220 emit deleteItem(this);
224 //*****************************************************************************
225 //*****************************************************************************
226 //*****************************************************************************
227 ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theParent,
228 ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData)
229 : ModuleBase_ModelWidget(theParent, theData),
230 myWorkshop(theWorkshop),
231 mySelectorFeature(SelectorFeature),
232 mySelectorAttribute(AttributeId)
234 // Clear Old selection
235 AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
236 mySelectionType = selectionType(aAttrList->selectionType().c_str());
240 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
241 ModuleBase_Tools::adjustMargins(aMainLayout);
243 QGroupBox* aFiltersGroup = new QGroupBox(tr("Filters"), this);
244 QVBoxLayout* aGroupLayout = new QVBoxLayout(aFiltersGroup);
245 aGroupLayout->setContentsMargins(0, 0, 0, 0);
246 aGroupLayout->setSpacing(0);
248 myFiltersWgt = new QWidget();
249 myFiltersLayout = new QVBoxLayout(myFiltersWgt);
250 myFiltersLayout->setContentsMargins(0, 0, 0, 0);
251 aGroupLayout->addWidget(myFiltersWgt);
253 myFiltersCombo = new QComboBox(aFiltersGroup);
254 myFiltersCombo->addItem(tr("Add new filter..."));
255 SessionPtr aSession = ModelAPI_Session::get();
256 std::list<FilterPtr> allFilters =
257 aSession->filters()->filters((GeomAPI_Shape::ShapeType) mySelectionType);
259 std::list<FilterPtr>::const_iterator aIt;
260 for (aIt = allFilters.cbegin(); aIt != allFilters.cend(); aIt++) {
261 aItems.push_back((*aIt)->name().c_str());
262 myFilters.push_back(aSession->filters()->id(*aIt));
264 myFiltersCombo->addItems(aItems);
265 connect(myFiltersCombo, SIGNAL(currentIndexChanged(int)), SLOT(onAddFilter(int)));
267 aGroupLayout->addWidget(myFiltersCombo);
268 aMainLayout->addWidget(aFiltersGroup);
271 QWidget* aBtnWgt = new QWidget(this);
272 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnWgt);
273 ModuleBase_Tools::adjustMargins(aBtnLayout);
275 aBtnLayout->addStretch(1);
277 mySelectBtn = new QPushButton(tr("Select"), aBtnWgt);
278 connect(mySelectBtn, SIGNAL(clicked()), SLOT(onSelect()));
279 aBtnLayout->addWidget(mySelectBtn);
281 aMainLayout->addWidget(aBtnWgt);
284 QWidget* aLblWgt = new QWidget(this);
285 QHBoxLayout* aLblLayout = new QHBoxLayout(aLblWgt);
286 ModuleBase_Tools::zeroMargins(aLblLayout);
288 aLblLayout->addWidget(new QLabel(tr("Number of selected objects:"), aLblWgt));
290 myNbLbl = new QLabel("0", aLblWgt);
291 aLblLayout->addWidget(myNbLbl);
294 myShowBtn = new QCheckBox(tr("Show only"), this);
295 connect(myShowBtn, SIGNAL(toggled(bool)), SLOT(onShowOnly(bool)));
296 aLblLayout->addWidget(myShowBtn);
298 aMainLayout->addWidget(aLblWgt);
300 aMainLayout->addStretch(1);
305 ModuleBase_WidgetSelectionFilter::~ModuleBase_WidgetSelectionFilter()
308 if (!myPreview.IsNull()) {
309 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
310 aCtx->Remove(myPreview, false);
312 if (myListIO.Size() > 0) {
313 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
314 AIS_ListOfInteractive::const_iterator aIt;
315 Handle(AIS_Shape) aShapeIO;
316 for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
317 aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
318 if (!aShapeIO.IsNull()) {
319 aCtx->Display(aShapeIO, false);
320 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
321 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
322 myWorkshop->applyCurrentSelectionModes(anAISObj);
326 myShowBtn->setChecked(false);
328 myWorkshop->viewer()->update();
330 SelectorFeature = FeaturePtr();
334 void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex)
339 std::list<std::string>::iterator aIt;
342 for (aIt = myFilters.begin(), i = 0; aIt != myFilters.cend(); i++, aIt++) {
343 if (i == (theIndex - 1)) {
348 ModuleBase_FilterItem* aItem = onAddFilter(aFilter);
349 FiltersFeaturePtr aFiltersFeature =
350 std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
351 aFiltersFeature->addFilter(aFilter);
353 myFiltersCombo->setCurrentIndex(0);
354 myFiltersCombo->removeItem(theIndex);
355 updateObject(myFeature);
357 if (aItem && (aItem->widgets().size() > 0))
358 aItem->widgets().first()->emitFocusInWidget();
363 ModuleBase_FilterItem* ModuleBase_WidgetSelectionFilter::onAddFilter(const std::string& theFilter)
365 if (theFilter.length() == 0)
367 std::list<std::string>::const_iterator aIt;
368 for (aIt = myUseFilters.cbegin(); aIt != myUseFilters.cend(); aIt++) {
369 if (theFilter == (*aIt))
372 myFilters.remove(theFilter);
373 myUseFilters.push_back(theFilter);
374 ModuleBase_FilterItem* aItem = new ModuleBase_FilterItem(theFilter, this);
375 connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)),
376 SLOT(onDeleteItem(ModuleBase_FilterItem*)));
377 connect(aItem, SIGNAL(reversedItem(ModuleBase_FilterItem*)),
378 SLOT(onReverseItem(ModuleBase_FilterItem*)));
379 myFiltersLayout->addWidget(aItem);
382 clearCurrentSelection(true);
383 updateNumberSelected();
387 void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theItem)
389 std::string aFilter = theItem->filter();
390 QList<ModuleBase_ModelWidget*> aWidgets = theItem->widgets();
391 foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
394 myFiltersLayout->removeWidget(theItem);
395 theItem->deleteLater();
397 myUseFilters.remove(aFilter);
398 myFilters.push_back(aFilter);
399 myFiltersCombo->addItem(ModelAPI_Session::get()->filters()->filter(aFilter)->name().c_str());
401 FiltersFeaturePtr aFiltersFeature =
402 std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
403 aFiltersFeature->removeFilter(aFilter);
406 clearCurrentSelection(true);
407 updateNumberSelected();
409 myWorkshop->deactivateCurrentSelector();
410 myWorkshop->selectionActivate()->updateSelectionModes();
411 myWorkshop->selectionActivate()->updateSelectionFilters();
414 updateObject(myFeature);
418 void ModuleBase_WidgetSelectionFilter::redisplayFeature()
420 static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
421 ModelAPI_EventCreator::get()->sendUpdated(myFeature, aDispEvent);
422 Events_Loop::loop()->flush(aDispEvent);
425 void ModuleBase_WidgetSelectionFilter::onReverseItem(ModuleBase_FilterItem* theItem)
428 clearCurrentSelection(true);
429 updateNumberSelected();
432 void ModuleBase_WidgetSelectionFilter::onSelect()
434 if (myUseFilters.size() == 0)
436 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
440 clearCurrentSelection();
442 BRep_Builder aBuilder;
443 TopoDS_Compound aComp;
444 aBuilder.MakeCompound(aComp);
446 DocumentPtr aDoc = myFeature->document();
447 int aNb = aDoc->size(ModelAPI_ResultBody::group());
451 for (int i = 0; i < aNb; i++) {
452 aObj = aDoc->object(ModelAPI_ResultBody::group(), i);
453 aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
454 GeomShapePtr aShape = aBody->shape();
455 std::list<GeomShapePtr> aSubShapes =
456 aShape->subShapes((GeomAPI_Shape::ShapeType)mySelectionType);
457 TopTools_MapOfShape alreadyThere;
458 std::list<GeomShapePtr>::const_iterator aShapesIt;
459 for (aShapesIt = aSubShapes.cbegin(); aShapesIt != aSubShapes.cend(); aShapesIt++) {
460 GeomShapePtr aShape = (*aShapesIt);
461 TopoDS_Shape aTShape = aShape->impl<TopoDS_Shape>();
462 if (!alreadyThere.Add(aTShape))
464 static SessionPtr aSession = ModelAPI_Session::get();
465 bool isValid = aSession->filters()->isValid(myFeature, aBody, aShape);
467 aBuilder.Add(aComp, aTShape);
468 ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aShape));
469 myValues.append(aValue);
474 if (myValues.size() > 0)
475 updatePreview(aComp);
476 updateNumberSelected();
477 updateObject(myFeature);
478 onShowOnly(myShowBtn->isChecked());
481 void ModuleBase_WidgetSelectionFilter::updatePreview(const TopoDS_Shape& theShape)
483 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
487 if (myPreview.IsNull()) {
488 myPreview = new AIS_Shape(theShape);
489 myPreview->SetDisplayMode(AIS_Shaded);
490 myPreview->SetColor(Quantity_NOC_BLUE1);
491 Handle(Prs3d_Drawer) aDrawer = myPreview->Attributes();
492 if (aDrawer->HasOwnPointAspect()) {
493 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
494 aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
495 aDrawer->PointAspect()->SetScale(2.);
498 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2.));
499 myPreview->SetTransparency();
500 aCtx->Display(myPreview, true);
501 aCtx->Deactivate(myPreview);
504 myPreview->Set(theShape);
505 aCtx->Redisplay(myPreview, true);
510 void ModuleBase_WidgetSelectionFilter::onShowOnly(bool theShow)
512 if (myPreview.IsNull())
514 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
517 AIS_ListOfInteractive aList;
518 aCtx->DisplayedObjects(AIS_KOI_Shape, -1, aList);
519 aList.Remove(myPreview);
520 if (aList.Size() > 0)
523 AIS_ListOfInteractive::const_iterator aIt;
524 Handle(AIS_Shape) aShapeIO;
525 for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
526 aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
527 if (!aShapeIO.IsNull()) {
529 aCtx->Erase(aShapeIO, false);
531 aCtx->Display(aShapeIO, false);
532 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
533 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
534 myWorkshop->applyCurrentSelectionModes(anAISObj);
538 myWorkshop->viewer()->update();
541 void ModuleBase_WidgetSelectionFilter::updateSelectBtn()
543 mySelectBtn->setEnabled(myUseFilters.size() > 0);
546 void ModuleBase_WidgetSelectionFilter::updateNumberSelected()
548 int aNb = myValues.size();
549 myNbLbl->setText(QString::number(aNb));
550 //QString aErr = () ? tr("Selection is empty") : "";
552 myFeature->setError(tr("Selection is empty").toStdString(), false, false);
554 myFeature->setError("", false, false);
555 myFeature->data()->execState(ModelAPI_StateDone);
559 QList<QWidget*> ModuleBase_WidgetSelectionFilter::getControls() const
561 QList<QWidget*> aWidgets;
562 aWidgets.append(myFiltersCombo);
566 void ModuleBase_WidgetSelectionFilter::clearCurrentSelection(bool toUpdate)
569 if (!myPreview.IsNull()) {
570 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
571 aCtx->Remove(myPreview, toUpdate);
576 void replaceSubShapesByResult(QList<ModuleBase_ViewerPrsPtr>& theResults, int theShapeType)
578 QMap<ObjectPtr, QList<GeomShapePtr>> myResShapes;
579 // Sort sub-shapes by result
580 foreach (ModuleBase_ViewerPrsPtr aPrs, theResults) {
581 if (myResShapes.contains(aPrs->object()))
582 myResShapes[aPrs->object()].append(aPrs->shape());
584 QList<GeomShapePtr> aShapes;
585 aShapes << aPrs->shape();
586 myResShapes[aPrs->object()] = aShapes;
589 // Find Results to replace by whole result
590 QList<GeomShapePtr> aShapes;
591 QList<ObjectPtr> aToReplace;
592 std::list<GeomShapePtr> aSubShapes;
593 foreach(ObjectPtr aObj, myResShapes.keys()) {
594 aShapes = myResShapes[aObj];
595 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
596 TopTools_MapOfShape aShapesMap;
598 GeomShapePtr aSubShape = aRes->shape();
599 const TopoDS_Shape& aShape = aSubShape->impl<TopoDS_Shape>();
600 for (TopExp_Explorer anExp(aShape, (TopAbs_ShapeEnum)theShapeType);
601 anExp.More(); anExp.Next()) {
602 aShapesMap.Add(anExp.Current());
605 if (aShapes.count() == aShapesMap.Size())
606 aToReplace.append(aObj);
608 // Replace the found results
609 QList<ModuleBase_ViewerPrsPtr>::iterator aIt;
610 foreach(ObjectPtr aObj, aToReplace) {
611 for (aIt = theResults.begin(); aIt != theResults.end(); aIt++) {
612 if ((*aIt)->object() == aObj) {
613 theResults.removeAll(*aIt);
617 ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj));
618 theResults.append(aValue);
622 void ModuleBase_WidgetSelectionFilter::onFeatureAccepted()
624 AttributePtr aAttr = mySelectorFeature->attribute(mySelectorAttribute);
625 AttributeSelectionListPtr aSelListAttr =
626 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
627 aSelListAttr->clear();
628 if (aSelListAttr->isWholeResultAllowed())
629 replaceSubShapesByResult(myValues, selectionType(aSelListAttr->selectionType().c_str()));
630 foreach(ModuleBase_ViewerPrsPtr aPrs, myValues) {
631 aSelListAttr->append(aPrs->object(), aPrs->shape());
635 bool ModuleBase_WidgetSelectionFilter::storeValueCustom()
637 ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget();
639 return aActive->storeValue();
640 updateObject(myFeature);
644 bool ModuleBase_WidgetSelectionFilter::restoreValueCustom()
646 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
647 FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
648 std::list<std::string> aFilters = aFiltersFeature->filters();
649 std::list<std::string>::const_iterator aIt;
650 for (aIt = aFilters.cbegin(); aIt != aFilters.cend(); aIt++) {
651 std::string aStr = (*aIt);
653 FilterPtr aFilterObj = aFactory->filter(aStr);
654 int aId = myFiltersCombo->findText(aFilterObj->name().c_str());
656 myFiltersCombo->removeItem(aId);
658 // Init filters member of the parent attribute
659 AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
660 if (aAttrList->filters() != aFiltersFeature) {
661 aAttrList->setFilters(aFiltersFeature);
664 QList<QWidget*> aWidgets;
665 QList<ModuleBase_FilterItem*> aItems = myFiltersLayout->findChildren<ModuleBase_FilterItem*>();
666 foreach(ModuleBase_FilterItem* aItem, aItems) {
667 QList<ModuleBase_ModelWidget*> aSubList = aItem->widgets();
668 foreach(ModuleBase_ModelWidget* aWgt, aSubList) {
669 aWgt->restoreValue();
675 QString ModuleBase_WidgetSelectionFilter::getError(const bool theValueStateChecked) const
677 QString aErrorMsg = ModuleBase_ModelWidget::getError(theValueStateChecked);
678 if (aErrorMsg.isEmpty()) {
679 if (myValues.size() == 0)
680 aErrorMsg = tr("Selection is empty");
685 void ModuleBase_WidgetSelectionFilter::onObjectUpdated()
687 myShowBtn->setChecked(false);
688 clearCurrentSelection(true);
689 updateNumberSelected();
691 QList<ModuleBase_FilterItem*> aItemsList = myFiltersWgt->findChildren<ModuleBase_FilterItem*>();
692 foreach(ModuleBase_FilterItem* aItem, aItemsList) {
693 QList<ModuleBase_ModelWidget*> aWidgetsList = aItem->widgets();
694 foreach(ModuleBase_ModelWidget* aWidget, aWidgetsList) {
695 if (!aWidget->feature().get())
696 aWidget->setFeature(myFeature);
697 aWidget->restoreValue();
700 updateObject(myFeature);
702 // Redisplay the feature on order to Customize presentations from filters with selectors
703 static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
704 ModelAPI_EventCreator::get()->sendUpdated(myFeature, EVENT_DISP);
705 Events_Loop::loop()->flush(EVENT_DISP);