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 FeaturePtr ModuleBase_WidgetSelectionFilter::SelectorFeature;
59 std::string ModuleBase_WidgetSelectionFilter::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 ModuleBase_WidgetSelectionFilter::SelectorFeature = aSelector->feature();
122 ModuleBase_WidgetSelectionFilter::AttributeId = aSelector->attributeID();
124 // Launch Filters operation
125 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
126 (myWorkshop->module()->createOperation(myFeatureName));
128 AttributeSelectionListPtr aAttrList =
129 ModuleBase_WidgetSelectionFilter::SelectorFeature->selectionList(
130 ModuleBase_WidgetSelectionFilter::AttributeId);
131 FiltersFeaturePtr aFilters = aAttrList->filters();
133 aFOperation->setFeature(aFilters);
134 aFOperation->setHelpFileName(aHelpFileName);
135 myWorkshop->processLaunchOperation(aFOperation);
138 //*****************************************************************************
139 //*****************************************************************************
140 //*****************************************************************************
141 ModuleBase_FilterItem::ModuleBase_FilterItem(
142 const std::string& theFilter, ModuleBase_WidgetSelectionFilter* theParent)
143 : QWidget(theParent->filtersWidget()), myFilterID(theFilter),
144 mySelection(std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(theParent->feature()))
146 FilterPtr aFilter = ModelAPI_Session::get()->filters()->filter(theFilter);
147 std::string aXmlString = aFilter->xmlRepresentation();
148 if (aXmlString.length() == 0)
151 std::string anAttrPrefix; // this must be added to the attributes names for multiple filters
152 std::string aFilterKind = ModelAPI_Session::get()->filters()->id(aFilter);
153 if (theFilter != aFilterKind) {
154 anAttrPrefix = theFilter.substr(0, theFilter.size() - aFilterKind.size());
156 ModuleBase_WidgetFactory aFactory(aXmlString, theParent->workshop(), anAttrPrefix);
157 Config_ValidatorReader aValidatorReader(aXmlString, true);
158 aValidatorReader.setFeatureId(mySelection->getKind());
159 aValidatorReader.readAll();
161 QVBoxLayout* aLayout = new QVBoxLayout(this);
162 ModuleBase_Tools::zeroMargins(aLayout);
164 QWidget* aItemRow = new QWidget(this);
165 addItemRow(aItemRow);
166 aLayout->addWidget(aItemRow);
168 ModuleBase_PageWidget* aParamsWgt = new ModuleBase_PageWidget(this);
169 aParamsWgt->setFrameStyle(QFrame::Box | QFrame::Raised);
170 aFactory.createWidget(aParamsWgt);
171 ModuleBase_Tools::zeroMargins(aParamsWgt->layout());
172 myWidgets = aFactory.getModelWidgets();
173 foreach(ModuleBase_ModelWidget* aWidget, myWidgets) {
174 aWidget->setFeature(theParent->feature());
175 connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
176 theParent, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)));
177 connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
178 theParent, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)));
179 connect(aWidget, SIGNAL(objectUpdated()), theParent, SLOT(onObjectUpdated()));
181 aLayout->addWidget(aParamsWgt);
185 void ModuleBase_FilterItem::addItemRow(QWidget* theParent)
187 QHBoxLayout* aLayout = new QHBoxLayout(theParent);
188 ModuleBase_Tools::zeroMargins(aLayout);
190 // Reverse filter button
191 myRevBtn = new QToolButton(theParent);
192 myRevBtn->setCheckable(true);
193 bool isReversed = mySelection->isReversed(myFilterID);
194 myRevBtn->setChecked(isReversed);
195 myRevBtn->setAutoRaise(true);
197 myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
199 myRevBtn->setIcon(QIcon(":pictures/add.png"));
200 myRevBtn->setToolTip(tr("Reverse the filter"));
201 connect(myRevBtn, SIGNAL(toggled(bool)), SLOT(onReverse(bool)));
202 aLayout->addWidget(myRevBtn);
204 const std::string& aFilterName = ModelAPI_Session::get()->filters()->filter(myFilterID)->name();
205 aLayout->addWidget(new QLabel(aFilterName.c_str(), theParent), 1);
207 QToolButton* aDelBtn = new QToolButton(theParent);
208 aDelBtn->setIcon(QIcon(":pictures/delete.png"));
209 aDelBtn->setAutoRaise(true);
210 aDelBtn->setToolTip(tr("Delete the filter"));
211 connect(aDelBtn, SIGNAL(clicked(bool)), SLOT(onDelete()));
212 aLayout->addWidget(aDelBtn);
215 void ModuleBase_FilterItem::onReverse(bool theCheck)
217 mySelection->setReversed(myFilterID, theCheck);
219 myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
221 myRevBtn->setIcon(QIcon(":pictures/add.png"));
222 emit reversedItem(this);
225 void ModuleBase_FilterItem::onDelete()
227 emit deleteItem(this);
231 //*****************************************************************************
232 //*****************************************************************************
233 //*****************************************************************************
234 ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theParent,
235 ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, bool theReadOnly)
236 : ModuleBase_ModelWidget(theParent, theData),
237 myWorkshop(theWorkshop),
238 mySelectorFeature(ModuleBase_WidgetSelectionFilter::SelectorFeature),
239 mySelectorAttribute(ModuleBase_WidgetSelectionFilter::AttributeId)
241 // Clear Old selection
242 AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
243 mySelectionType = selectionType(aAttrList->selectionType().c_str());
249 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
250 ModuleBase_Tools::adjustMargins(aMainLayout);
252 QGroupBox* aFiltersGroup = new QGroupBox(tr("Filters"), this);
253 QVBoxLayout* aGroupLayout = new QVBoxLayout(aFiltersGroup);
254 aGroupLayout->setContentsMargins(0, 0, 0, 0);
255 aGroupLayout->setSpacing(0);
257 myFiltersWgt = new QWidget();
258 myFiltersLayout = new QVBoxLayout(myFiltersWgt);
259 myFiltersLayout->setContentsMargins(0, 0, 0, 0);
260 aGroupLayout->addWidget(myFiltersWgt);
262 myFiltersCombo = new QComboBox(aFiltersGroup);
263 myFiltersCombo->addItem(tr("Add new filter..."));
264 SessionPtr aSession = ModelAPI_Session::get();
265 std::list<FilterPtr> allFilters =
266 aSession->filters()->filters((GeomAPI_Shape::ShapeType) mySelectionType);
268 std::list<FilterPtr>::const_iterator aIt;
269 for (aIt = allFilters.cbegin(); aIt != allFilters.cend(); aIt++) {
270 aItems.push_back((*aIt)->name().c_str());
272 myFiltersCombo->addItems(aItems);
273 connect(myFiltersCombo, SIGNAL(currentIndexChanged(int)), SLOT(onAddFilter(int)));
275 aGroupLayout->addWidget(myFiltersCombo);
276 aMainLayout->addWidget(aFiltersGroup);
279 QWidget* aBtnWgt = new QWidget(this);
280 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnWgt);
281 ModuleBase_Tools::adjustMargins(aBtnLayout);
283 aBtnLayout->addStretch(1);
285 mySelectBtn = new QPushButton(tr("Select"), aBtnWgt);
286 connect(mySelectBtn, SIGNAL(clicked()), SLOT(onSelect()));
287 aBtnLayout->addWidget(mySelectBtn);
289 aMainLayout->addWidget(aBtnWgt);
292 QWidget* aLblWgt = new QWidget(this);
293 QHBoxLayout* aLblLayout = new QHBoxLayout(aLblWgt);
294 ModuleBase_Tools::zeroMargins(aLblLayout);
296 aLblLayout->addWidget(new QLabel(tr("Number of selected objects:"), aLblWgt));
298 myNbLbl = new QLabel("0", aLblWgt);
299 aLblLayout->addWidget(myNbLbl);
302 myShowBtn = new QCheckBox(tr("Show only"), this);
303 connect(myShowBtn, SIGNAL(toggled(bool)), SLOT(onShowOnly(bool)));
304 aLblLayout->addWidget(myShowBtn);
306 aMainLayout->addWidget(aLblWgt);
308 aMainLayout->addStretch(1);
312 myFiltersCombo->hide();
319 ModuleBase_WidgetSelectionFilter::~ModuleBase_WidgetSelectionFilter()
322 if (!myPreview.IsNull()) {
323 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
324 aCtx->Remove(myPreview, false);
326 if (myListIO.Size() > 0) {
327 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
328 AIS_ListOfInteractive::const_iterator aIt;
329 Handle(AIS_Shape) aShapeIO;
330 for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
331 aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
332 if (!aShapeIO.IsNull()) {
333 aCtx->Display(aShapeIO, false);
334 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
335 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
336 myWorkshop->applyCurrentSelectionModes(anAISObj);
340 myShowBtn->setChecked(false);
342 myWorkshop->viewer()->update();
344 SelectorFeature = FeaturePtr();
348 void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex)
353 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
354 std::list<FilterPtr> aFilters = aFactory->filters((GeomAPI_Shape::ShapeType) mySelectionType);
355 FiltersFeaturePtr aFiltersFeature =
356 std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
358 std::string aText = myFiltersCombo->itemText(theIndex).toStdString();
360 std::list<FilterPtr>::iterator aIt;
363 for (aIt = aFilters.begin(), i = 0; aIt != aFilters.cend(); i++, aIt++) {
364 if (aText == (*aIt)->name()) {
365 aFilter = aFactory->id(*aIt);
369 aFiltersFeature->addFilter(aFilter);
370 updateObject(myFeature);
372 QList<ModuleBase_FilterItem*> aList = itemsList();
373 if (!aList.isEmpty() && (aList.last()->widgets().size() > 0))
374 aList.last()->widgets().first()->emitFocusInWidget();
379 ModuleBase_FilterItem* ModuleBase_WidgetSelectionFilter::onAddFilter(const std::string& theFilter)
381 if (theFilter.length() == 0)
383 ModuleBase_FilterItem* aItem = new ModuleBase_FilterItem(theFilter, this);
384 connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)),
385 SLOT(onDeleteItem(ModuleBase_FilterItem*)));
386 connect(aItem, SIGNAL(reversedItem(ModuleBase_FilterItem*)),
387 SLOT(onReverseItem(ModuleBase_FilterItem*)));
388 myFiltersLayout->addWidget(aItem);
391 clearCurrentSelection(true);
392 updateNumberSelected();
396 void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theItem)
398 std::string aFilter = theItem->filter();
399 QList<ModuleBase_ModelWidget*> aWidgets = theItem->widgets();
400 foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
403 myFiltersLayout->removeWidget(theItem);
404 theItem->deleteLater();
406 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
407 if (!aFactory->filter(aFilter)->isMultiple()) {
408 //myFilters.push_back(aFilter);
409 myFiltersCombo->addItem(ModelAPI_Session::get()->filters()->filter(aFilter)->name().c_str());
411 FiltersFeaturePtr aFiltersFeature =
412 std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
413 aFiltersFeature->removeFilter(aFilter);
416 clearCurrentSelection(true);
417 updateNumberSelected();
419 myWorkshop->deactivateCurrentSelector();
420 myWorkshop->selectionActivate()->updateSelectionModes();
421 myWorkshop->selectionActivate()->updateSelectionFilters();
424 updateObject(myFeature);
428 void ModuleBase_WidgetSelectionFilter::redisplayFeature()
430 static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
431 ModelAPI_EventCreator::get()->sendUpdated(myFeature, aDispEvent);
432 Events_Loop::loop()->flush(aDispEvent);
435 void ModuleBase_WidgetSelectionFilter::onReverseItem(ModuleBase_FilterItem* theItem)
438 clearCurrentSelection(true);
439 updateNumberSelected();
442 void ModuleBase_WidgetSelectionFilter::onSelect()
444 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
448 clearCurrentSelection();
450 BRep_Builder aBuilder;
451 TopoDS_Compound aComp;
452 aBuilder.MakeCompound(aComp);
454 DocumentPtr aDoc = myFeature->document();
455 int aNb = aDoc->size(ModelAPI_ResultBody::group());
459 for (int i = 0; i < aNb; i++) {
460 aObj = aDoc->object(ModelAPI_ResultBody::group(), i);
461 aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
462 GeomShapePtr aShape = aBody->shape();
463 std::list<GeomShapePtr> aSubShapes =
464 aShape->subShapes((GeomAPI_Shape::ShapeType)mySelectionType);
465 TopTools_MapOfShape alreadyThere;
466 std::list<GeomShapePtr>::const_iterator aShapesIt;
467 for (aShapesIt = aSubShapes.cbegin(); aShapesIt != aSubShapes.cend(); aShapesIt++) {
468 GeomShapePtr aShape = (*aShapesIt);
469 TopoDS_Shape aTShape = aShape->impl<TopoDS_Shape>();
470 if (!alreadyThere.Add(aTShape))
472 static SessionPtr aSession = ModelAPI_Session::get();
473 bool isValid = aSession->filters()->isValid(myFeature, aBody, aShape);
475 aBuilder.Add(aComp, aTShape);
476 ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aShape));
477 myValues.append(aValue);
482 if (myValues.size() > 0)
483 updatePreview(aComp);
484 updateNumberSelected();
485 updateObject(myFeature);
486 onShowOnly(myShowBtn->isChecked());
489 void ModuleBase_WidgetSelectionFilter::updatePreview(const TopoDS_Shape& theShape)
491 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
495 if (myPreview.IsNull()) {
496 myPreview = new AIS_Shape(theShape);
497 myPreview->SetDisplayMode(AIS_Shaded);
498 myPreview->SetColor(Quantity_NOC_BLUE1);
499 Handle(Prs3d_Drawer) aDrawer = myPreview->Attributes();
500 if (aDrawer->HasOwnPointAspect()) {
501 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
502 aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
503 aDrawer->PointAspect()->SetScale(2.);
506 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2.));
507 myPreview->SetTransparency();
508 aCtx->Display(myPreview, true);
509 aCtx->Deactivate(myPreview);
512 myPreview->Set(theShape);
513 aCtx->Redisplay(myPreview, true);
518 void ModuleBase_WidgetSelectionFilter::onShowOnly(bool theShow)
520 if (myPreview.IsNull())
522 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
525 AIS_ListOfInteractive aList;
526 aCtx->DisplayedObjects(AIS_KOI_Shape, -1, aList);
527 aList.Remove(myPreview);
528 if (aList.Size() > 0)
531 AIS_ListOfInteractive::const_iterator aIt;
532 Handle(AIS_Shape) aShapeIO;
533 for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
534 aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
535 if (!aShapeIO.IsNull()) {
537 aCtx->Erase(aShapeIO, false);
539 aCtx->Display(aShapeIO, false);
540 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
541 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
542 myWorkshop->applyCurrentSelectionModes(anAISObj);
546 myWorkshop->viewer()->update();
549 void ModuleBase_WidgetSelectionFilter::updateSelectBtn()
551 FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
552 mySelectBtn->setEnabled(aFiltersFeature.get() && (aFiltersFeature->filters().size() > 0));
555 void ModuleBase_WidgetSelectionFilter::updateNumberSelected()
557 int aNb = myValues.size();
558 myNbLbl->setText(QString::number(aNb));
559 //QString aErr = () ? tr("Selection is empty") : "";
561 myFeature->setError(tr("Selection is empty").toStdString(), false, false);
563 myFeature->setError("", false, false);
564 myFeature->data()->execState(ModelAPI_StateDone);
568 QList<QWidget*> ModuleBase_WidgetSelectionFilter::getControls() const
570 QList<QWidget*> aWidgets;
571 aWidgets.append(myFiltersCombo);
575 void ModuleBase_WidgetSelectionFilter::clearCurrentSelection(bool toUpdate)
578 if (!myPreview.IsNull()) {
579 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
580 aCtx->Remove(myPreview, toUpdate);
585 void replaceSubShapesByResult(QList<ModuleBase_ViewerPrsPtr>& theResults, int theShapeType)
587 QMap<ObjectPtr, QList<GeomShapePtr>> myResShapes;
588 // Sort sub-shapes by result
589 foreach (ModuleBase_ViewerPrsPtr aPrs, theResults) {
590 if (myResShapes.contains(aPrs->object()))
591 myResShapes[aPrs->object()].append(aPrs->shape());
593 QList<GeomShapePtr> aShapes;
594 aShapes << aPrs->shape();
595 myResShapes[aPrs->object()] = aShapes;
598 // Find Results to replace by whole result
599 QList<GeomShapePtr> aShapes;
600 QList<ObjectPtr> aToReplace;
601 std::list<GeomShapePtr> aSubShapes;
602 foreach(ObjectPtr aObj, myResShapes.keys()) {
603 aShapes = myResShapes[aObj];
604 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
605 TopTools_MapOfShape aShapesMap;
607 GeomShapePtr aSubShape = aRes->shape();
608 const TopoDS_Shape& aShape = aSubShape->impl<TopoDS_Shape>();
609 for (TopExp_Explorer anExp(aShape, (TopAbs_ShapeEnum)theShapeType);
610 anExp.More(); anExp.Next()) {
611 aShapesMap.Add(anExp.Current());
614 if (aShapes.count() == aShapesMap.Size())
615 aToReplace.append(aObj);
617 // Replace the found results
618 QList<ModuleBase_ViewerPrsPtr>::iterator aIt;
619 foreach(ObjectPtr aObj, aToReplace) {
620 for (aIt = theResults.begin(); aIt != theResults.end(); aIt++) {
621 if ((*aIt)->object() == aObj) {
622 theResults.removeAll(*aIt);
626 ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj));
627 theResults.append(aValue);
631 void ModuleBase_WidgetSelectionFilter::onFeatureAccepted()
633 AttributePtr aAttr = mySelectorFeature->attribute(mySelectorAttribute);
634 AttributeSelectionListPtr aSelListAttr =
635 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
636 aSelListAttr->clear();
637 if (aSelListAttr->isWholeResultAllowed())
638 replaceSubShapesByResult(myValues, selectionType(aSelListAttr->selectionType().c_str()));
639 foreach(ModuleBase_ViewerPrsPtr aPrs, myValues) {
640 aSelListAttr->append(aPrs->object(), aPrs->shape());
644 bool ModuleBase_WidgetSelectionFilter::storeValueCustom()
646 ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget();
648 return aActive->storeValue();
649 updateObject(myFeature);
653 QList<ModuleBase_FilterItem*> ModuleBase_WidgetSelectionFilter::itemsList() const
655 return myFiltersWgt->findChildren<ModuleBase_FilterItem*>();
659 bool ModuleBase_WidgetSelectionFilter::restoreValueCustom()
661 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
662 FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
664 // Init filters member of the parent attribute
665 AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
666 if (aAttrList->filters() != aFiltersFeature) {
667 aAttrList->setFilters(aFiltersFeature);
670 QList<ModuleBase_FilterItem*> aItemsList = itemsList();
671 std::list<std::string> aFilters = aFiltersFeature->filters();
673 std::list<std::string>::const_iterator aIt;
675 int aNbItems = aItemsList.size();
676 ModuleBase_FilterItem* aItem = 0;
677 bool isBlocked = myFiltersCombo->blockSignals(true);
678 for (aIt = aFilters.cbegin(); aIt != aFilters.cend(); aIt++, i++) {
679 std::string aStr = (*aIt);
682 aItem = onAddFilter(aStr);
683 FilterPtr aFilterObj = aFactory->filter(aStr);
684 int aId = myFiltersCombo->findText(aFilterObj->name().c_str());
685 if ((aId != -1) && !aFilterObj->isMultiple())
686 myFiltersCombo->removeItem(aId);
688 QList<ModuleBase_ModelWidget*> aSubList = aItem->widgets();
689 foreach(ModuleBase_ModelWidget* aWgt, aSubList) {
690 aWgt->restoreValue();
695 myFiltersCombo->setCurrentIndex(0);
696 myFiltersCombo->blockSignals(isBlocked);
700 QString ModuleBase_WidgetSelectionFilter::getError(const bool theValueStateChecked) const
702 QString aErrorMsg = ModuleBase_ModelWidget::getError(theValueStateChecked);
703 if (aErrorMsg.isEmpty()) {
704 if (myValues.size() == 0)
705 aErrorMsg = tr("Selection is empty");
710 void ModuleBase_WidgetSelectionFilter::onObjectUpdated()
712 myShowBtn->setChecked(false);
713 clearCurrentSelection(true);
714 updateNumberSelected();
716 QList<ModuleBase_FilterItem*> aItemsList = itemsList();
717 foreach(ModuleBase_FilterItem* aItem, aItemsList) {
718 QList<ModuleBase_ModelWidget*> aWidgetsList = aItem->widgets();
719 foreach(ModuleBase_ModelWidget* aWidget, aWidgetsList) {
720 if (!aWidget->feature().get())
721 aWidget->setFeature(myFeature);
722 aWidget->restoreValue();
725 updateObject(myFeature);
727 // Redisplay the feature on order to Customize presentations from filters with selectors
728 static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
729 ModelAPI_EventCreator::get()->sendUpdated(myFeature, EVENT_DISP);
730 Events_Loop::loop()->flush(EVENT_DISP);