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 std::string aXmlString =
147 ModelAPI_Session::get()->filters()->filter(theFilter)->xmlRepresentation();
148 if (aXmlString.length() == 0)
151 ModuleBase_WidgetFactory aFactory(aXmlString, theParent->workshop());
152 Config_ValidatorReader aValidatorReader(aXmlString, true);
153 aValidatorReader.setFeatureId(mySelection->getKind());
154 aValidatorReader.readAll();
156 QVBoxLayout* aLayout = new QVBoxLayout(this);
157 ModuleBase_Tools::zeroMargins(aLayout);
159 QWidget* aItemRow = new QWidget(this);
160 addItemRow(aItemRow);
161 aLayout->addWidget(aItemRow);
163 ModuleBase_PageWidget* aParamsWgt = new ModuleBase_PageWidget(this);
164 aParamsWgt->setFrameStyle(QFrame::Box | QFrame::Raised);
165 aFactory.createWidget(aParamsWgt);
166 ModuleBase_Tools::zeroMargins(aParamsWgt->layout());
167 myWidgets = aFactory.getModelWidgets();
168 foreach(ModuleBase_ModelWidget* aWidget, myWidgets) {
169 aWidget->setFeature(theParent->feature());
170 connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
171 theParent, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)));
172 connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
173 theParent, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)));
174 connect(aWidget, SIGNAL(objectUpdated()), theParent, SLOT(onObjectUpdated()));
176 aLayout->addWidget(aParamsWgt);
180 void ModuleBase_FilterItem::addItemRow(QWidget* theParent)
182 QHBoxLayout* aLayout = new QHBoxLayout(theParent);
183 ModuleBase_Tools::zeroMargins(aLayout);
185 // Reverse filter button
186 myRevBtn = new QToolButton(theParent);
187 myRevBtn->setCheckable(true);
188 bool isReversed = mySelection->isReversed(myFilterID);
189 myRevBtn->setChecked(isReversed);
190 myRevBtn->setAutoRaise(true);
192 myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
194 myRevBtn->setIcon(QIcon(":pictures/add.png"));
195 myRevBtn->setToolTip(tr("Reverse the filter"));
196 connect(myRevBtn, SIGNAL(toggled(bool)), SLOT(onReverse(bool)));
197 aLayout->addWidget(myRevBtn);
199 const std::string& aFilterName = ModelAPI_Session::get()->filters()->filter(myFilterID)->name();
200 aLayout->addWidget(new QLabel(aFilterName.c_str(), theParent), 1);
202 QToolButton* aDelBtn = new QToolButton(theParent);
203 aDelBtn->setIcon(QIcon(":pictures/delete.png"));
204 aDelBtn->setAutoRaise(true);
205 aDelBtn->setToolTip(tr("Delete the filter"));
206 connect(aDelBtn, SIGNAL(clicked(bool)), SLOT(onDelete()));
207 aLayout->addWidget(aDelBtn);
210 void ModuleBase_FilterItem::onReverse(bool theCheck)
212 mySelection->setReversed(myFilterID, theCheck);
214 myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
216 myRevBtn->setIcon(QIcon(":pictures/add.png"));
217 emit reversedItem(this);
220 void ModuleBase_FilterItem::onDelete()
222 emit deleteItem(this);
226 //*****************************************************************************
227 //*****************************************************************************
228 //*****************************************************************************
229 ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theParent,
230 ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, bool theReadOnly)
231 : ModuleBase_ModelWidget(theParent, theData),
232 myWorkshop(theWorkshop),
233 mySelectorFeature(ModuleBase_WidgetSelectionFilter::SelectorFeature),
234 mySelectorAttribute(ModuleBase_WidgetSelectionFilter::AttributeId)
236 // Clear Old selection
237 AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
238 mySelectionType = selectionType(aAttrList->selectionType().c_str());
244 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
245 ModuleBase_Tools::adjustMargins(aMainLayout);
247 QGroupBox* aFiltersGroup = new QGroupBox(tr("Filters"), this);
248 QVBoxLayout* aGroupLayout = new QVBoxLayout(aFiltersGroup);
249 aGroupLayout->setContentsMargins(0, 0, 0, 0);
250 aGroupLayout->setSpacing(0);
252 myFiltersWgt = new QWidget();
253 myFiltersLayout = new QVBoxLayout(myFiltersWgt);
254 myFiltersLayout->setContentsMargins(0, 0, 0, 0);
255 aGroupLayout->addWidget(myFiltersWgt);
257 myFiltersCombo = new QComboBox(aFiltersGroup);
258 myFiltersCombo->addItem(tr("Add new filter..."));
259 SessionPtr aSession = ModelAPI_Session::get();
260 std::list<FilterPtr> allFilters =
261 aSession->filters()->filters((GeomAPI_Shape::ShapeType) mySelectionType);
263 std::list<FilterPtr>::const_iterator aIt;
264 for (aIt = allFilters.cbegin(); aIt != allFilters.cend(); aIt++) {
265 aItems.push_back((*aIt)->name().c_str());
267 myFiltersCombo->addItems(aItems);
268 connect(myFiltersCombo, SIGNAL(currentIndexChanged(int)), SLOT(onAddFilter(int)));
270 aGroupLayout->addWidget(myFiltersCombo);
271 aMainLayout->addWidget(aFiltersGroup);
274 QWidget* aBtnWgt = new QWidget(this);
275 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnWgt);
276 ModuleBase_Tools::adjustMargins(aBtnLayout);
278 aBtnLayout->addStretch(1);
280 mySelectBtn = new QPushButton(tr("Select"), aBtnWgt);
281 connect(mySelectBtn, SIGNAL(clicked()), SLOT(onSelect()));
282 aBtnLayout->addWidget(mySelectBtn);
284 aMainLayout->addWidget(aBtnWgt);
287 QWidget* aLblWgt = new QWidget(this);
288 QHBoxLayout* aLblLayout = new QHBoxLayout(aLblWgt);
289 ModuleBase_Tools::zeroMargins(aLblLayout);
291 aLblLayout->addWidget(new QLabel(tr("Number of selected objects:"), aLblWgt));
293 myNbLbl = new QLabel("0", aLblWgt);
294 aLblLayout->addWidget(myNbLbl);
297 myShowBtn = new QCheckBox(tr("Show only"), this);
298 connect(myShowBtn, SIGNAL(toggled(bool)), SLOT(onShowOnly(bool)));
299 aLblLayout->addWidget(myShowBtn);
301 aMainLayout->addWidget(aLblWgt);
303 aMainLayout->addStretch(1);
307 myFiltersCombo->hide();
314 ModuleBase_WidgetSelectionFilter::~ModuleBase_WidgetSelectionFilter()
317 if (!myPreview.IsNull()) {
318 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
319 aCtx->Remove(myPreview, false);
321 if (myListIO.Size() > 0) {
322 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
323 AIS_ListOfInteractive::const_iterator aIt;
324 Handle(AIS_Shape) aShapeIO;
325 for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
326 aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
327 if (!aShapeIO.IsNull()) {
328 aCtx->Display(aShapeIO, false);
329 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
330 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
331 myWorkshop->applyCurrentSelectionModes(anAISObj);
335 myShowBtn->setChecked(false);
337 myWorkshop->viewer()->update();
339 SelectorFeature = FeaturePtr();
343 void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex)
348 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
349 std::list<FilterPtr> aFilters = aFactory->filters((GeomAPI_Shape::ShapeType) mySelectionType);
350 FiltersFeaturePtr aFiltersFeature =
351 std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
353 std::string aText = myFiltersCombo->itemText(theIndex).toStdString();
355 std::list<FilterPtr>::iterator aIt;
358 for (aIt = aFilters.begin(), i = 0; aIt != aFilters.cend(); i++, aIt++) {
359 if (aText == (*aIt)->name()) {
360 aFilter = aFactory->id(*aIt);
364 aFiltersFeature->addFilter(aFilter);
365 updateObject(myFeature);
367 QList<ModuleBase_FilterItem*> aList = itemsList();
368 if (!aList.isEmpty() && (aList.last()->widgets().size() > 0))
369 aList.last()->widgets().first()->emitFocusInWidget();
374 ModuleBase_FilterItem* ModuleBase_WidgetSelectionFilter::onAddFilter(const std::string& theFilter)
376 if (theFilter.length() == 0)
378 ModuleBase_FilterItem* aItem = new ModuleBase_FilterItem(theFilter, this);
379 connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)),
380 SLOT(onDeleteItem(ModuleBase_FilterItem*)));
381 connect(aItem, SIGNAL(reversedItem(ModuleBase_FilterItem*)),
382 SLOT(onReverseItem(ModuleBase_FilterItem*)));
383 myFiltersLayout->addWidget(aItem);
386 clearCurrentSelection(true);
387 updateNumberSelected();
391 void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theItem)
393 std::string aFilter = theItem->filter();
394 QList<ModuleBase_ModelWidget*> aWidgets = theItem->widgets();
395 foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
398 myFiltersLayout->removeWidget(theItem);
399 theItem->deleteLater();
401 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
402 if (!aFactory->filter(aFilter)->isMultiple()) {
403 //myFilters.push_back(aFilter);
404 myFiltersCombo->addItem(ModelAPI_Session::get()->filters()->filter(aFilter)->name().c_str());
406 FiltersFeaturePtr aFiltersFeature =
407 std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
408 aFiltersFeature->removeFilter(aFilter);
411 clearCurrentSelection(true);
412 updateNumberSelected();
414 myWorkshop->deactivateCurrentSelector();
415 myWorkshop->selectionActivate()->updateSelectionModes();
416 myWorkshop->selectionActivate()->updateSelectionFilters();
419 updateObject(myFeature);
423 void ModuleBase_WidgetSelectionFilter::redisplayFeature()
425 static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
426 ModelAPI_EventCreator::get()->sendUpdated(myFeature, aDispEvent);
427 Events_Loop::loop()->flush(aDispEvent);
430 void ModuleBase_WidgetSelectionFilter::onReverseItem(ModuleBase_FilterItem* theItem)
433 clearCurrentSelection(true);
434 updateNumberSelected();
437 void ModuleBase_WidgetSelectionFilter::onSelect()
439 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
443 clearCurrentSelection();
445 BRep_Builder aBuilder;
446 TopoDS_Compound aComp;
447 aBuilder.MakeCompound(aComp);
449 DocumentPtr aDoc = myFeature->document();
450 int aNb = aDoc->size(ModelAPI_ResultBody::group());
454 for (int i = 0; i < aNb; i++) {
455 aObj = aDoc->object(ModelAPI_ResultBody::group(), i);
456 aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
457 GeomShapePtr aShape = aBody->shape();
458 std::list<GeomShapePtr> aSubShapes =
459 aShape->subShapes((GeomAPI_Shape::ShapeType)mySelectionType);
460 TopTools_MapOfShape alreadyThere;
461 std::list<GeomShapePtr>::const_iterator aShapesIt;
462 for (aShapesIt = aSubShapes.cbegin(); aShapesIt != aSubShapes.cend(); aShapesIt++) {
463 GeomShapePtr aShape = (*aShapesIt);
464 TopoDS_Shape aTShape = aShape->impl<TopoDS_Shape>();
465 if (!alreadyThere.Add(aTShape))
467 static SessionPtr aSession = ModelAPI_Session::get();
468 bool isValid = aSession->filters()->isValid(myFeature, aBody, aShape);
470 aBuilder.Add(aComp, aTShape);
471 ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aShape));
472 myValues.append(aValue);
477 if (myValues.size() > 0)
478 updatePreview(aComp);
479 updateNumberSelected();
480 updateObject(myFeature);
481 onShowOnly(myShowBtn->isChecked());
484 void ModuleBase_WidgetSelectionFilter::updatePreview(const TopoDS_Shape& theShape)
486 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
490 if (myPreview.IsNull()) {
491 myPreview = new AIS_Shape(theShape);
492 myPreview->SetDisplayMode(AIS_Shaded);
493 myPreview->SetColor(Quantity_NOC_BLUE1);
494 Handle(Prs3d_Drawer) aDrawer = myPreview->Attributes();
495 if (aDrawer->HasOwnPointAspect()) {
496 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
497 aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
498 aDrawer->PointAspect()->SetScale(2.);
501 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2.));
502 myPreview->SetTransparency();
503 aCtx->Display(myPreview, true);
504 aCtx->Deactivate(myPreview);
507 myPreview->Set(theShape);
508 aCtx->Redisplay(myPreview, true);
513 void ModuleBase_WidgetSelectionFilter::onShowOnly(bool theShow)
515 if (myPreview.IsNull())
517 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
520 AIS_ListOfInteractive aList;
521 aCtx->DisplayedObjects(AIS_KOI_Shape, -1, aList);
522 aList.Remove(myPreview);
523 if (aList.Size() > 0)
526 AIS_ListOfInteractive::const_iterator aIt;
527 Handle(AIS_Shape) aShapeIO;
528 for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
529 aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
530 if (!aShapeIO.IsNull()) {
532 aCtx->Erase(aShapeIO, false);
534 aCtx->Display(aShapeIO, false);
535 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
536 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
537 myWorkshop->applyCurrentSelectionModes(anAISObj);
541 myWorkshop->viewer()->update();
544 void ModuleBase_WidgetSelectionFilter::updateSelectBtn()
546 FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
547 mySelectBtn->setEnabled(aFiltersFeature.get() && (aFiltersFeature->filters().size() > 0));
550 void ModuleBase_WidgetSelectionFilter::updateNumberSelected()
552 int aNb = myValues.size();
553 myNbLbl->setText(QString::number(aNb));
554 //QString aErr = () ? tr("Selection is empty") : "";
556 myFeature->setError(tr("Selection is empty").toStdString(), false, false);
558 myFeature->setError("", false, false);
559 myFeature->data()->execState(ModelAPI_StateDone);
563 QList<QWidget*> ModuleBase_WidgetSelectionFilter::getControls() const
565 QList<QWidget*> aWidgets;
566 aWidgets.append(myFiltersCombo);
570 void ModuleBase_WidgetSelectionFilter::clearCurrentSelection(bool toUpdate)
573 if (!myPreview.IsNull()) {
574 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
575 aCtx->Remove(myPreview, toUpdate);
580 void replaceSubShapesByResult(QList<ModuleBase_ViewerPrsPtr>& theResults, int theShapeType)
582 QMap<ObjectPtr, QList<GeomShapePtr>> myResShapes;
583 // Sort sub-shapes by result
584 foreach (ModuleBase_ViewerPrsPtr aPrs, theResults) {
585 if (myResShapes.contains(aPrs->object()))
586 myResShapes[aPrs->object()].append(aPrs->shape());
588 QList<GeomShapePtr> aShapes;
589 aShapes << aPrs->shape();
590 myResShapes[aPrs->object()] = aShapes;
593 // Find Results to replace by whole result
594 QList<GeomShapePtr> aShapes;
595 QList<ObjectPtr> aToReplace;
596 std::list<GeomShapePtr> aSubShapes;
597 foreach(ObjectPtr aObj, myResShapes.keys()) {
598 aShapes = myResShapes[aObj];
599 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
600 TopTools_MapOfShape aShapesMap;
602 GeomShapePtr aSubShape = aRes->shape();
603 const TopoDS_Shape& aShape = aSubShape->impl<TopoDS_Shape>();
604 for (TopExp_Explorer anExp(aShape, (TopAbs_ShapeEnum)theShapeType);
605 anExp.More(); anExp.Next()) {
606 aShapesMap.Add(anExp.Current());
609 if (aShapes.count() == aShapesMap.Size())
610 aToReplace.append(aObj);
612 // Replace the found results
613 QList<ModuleBase_ViewerPrsPtr>::iterator aIt;
614 foreach(ObjectPtr aObj, aToReplace) {
615 for (aIt = theResults.begin(); aIt != theResults.end(); aIt++) {
616 if ((*aIt)->object() == aObj) {
617 theResults.removeAll(*aIt);
621 ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj));
622 theResults.append(aValue);
626 void ModuleBase_WidgetSelectionFilter::onFeatureAccepted()
628 AttributePtr aAttr = mySelectorFeature->attribute(mySelectorAttribute);
629 AttributeSelectionListPtr aSelListAttr =
630 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
631 aSelListAttr->clear();
632 if (aSelListAttr->isWholeResultAllowed())
633 replaceSubShapesByResult(myValues, selectionType(aSelListAttr->selectionType().c_str()));
634 foreach(ModuleBase_ViewerPrsPtr aPrs, myValues) {
635 aSelListAttr->append(aPrs->object(), aPrs->shape());
639 bool ModuleBase_WidgetSelectionFilter::storeValueCustom()
641 ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget();
643 return aActive->storeValue();
644 updateObject(myFeature);
648 QList<ModuleBase_FilterItem*> ModuleBase_WidgetSelectionFilter::itemsList() const
650 return myFiltersWgt->findChildren<ModuleBase_FilterItem*>();
654 bool ModuleBase_WidgetSelectionFilter::restoreValueCustom()
656 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
657 FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
659 // Init filters member of the parent attribute
660 AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
661 if (aAttrList->filters() != aFiltersFeature) {
662 aAttrList->setFilters(aFiltersFeature);
665 QList<ModuleBase_FilterItem*> aItemsList = itemsList();
666 std::list<std::string> aFilters = aFiltersFeature->filters();
668 std::list<std::string>::const_iterator aIt;
670 int aNbItems = aItemsList.size();
671 ModuleBase_FilterItem* aItem = 0;
672 bool isBlocked = myFiltersCombo->blockSignals(true);
673 for (aIt = aFilters.cbegin(); aIt != aFilters.cend(); aIt++, i++) {
674 std::string aStr = (*aIt);
677 aItem = onAddFilter(aStr);
678 FilterPtr aFilterObj = aFactory->filter(aStr);
679 int aId = myFiltersCombo->findText(aFilterObj->name().c_str());
680 if ((aId != -1) && !aFilterObj->isMultiple())
681 myFiltersCombo->removeItem(aId);
683 QList<ModuleBase_ModelWidget*> aSubList = aItem->widgets();
684 foreach(ModuleBase_ModelWidget* aWgt, aSubList) {
685 aWgt->restoreValue();
690 myFiltersCombo->setCurrentIndex(0);
691 myFiltersCombo->blockSignals(isBlocked);
695 QString ModuleBase_WidgetSelectionFilter::getError(const bool theValueStateChecked) const
697 QString aErrorMsg = ModuleBase_ModelWidget::getError(theValueStateChecked);
698 if (aErrorMsg.isEmpty()) {
699 if (myValues.size() == 0)
700 aErrorMsg = tr("Selection is empty");
705 void ModuleBase_WidgetSelectionFilter::onObjectUpdated()
707 myShowBtn->setChecked(false);
708 clearCurrentSelection(true);
709 updateNumberSelected();
711 QList<ModuleBase_FilterItem*> aItemsList = itemsList();
712 foreach(ModuleBase_FilterItem* aItem, aItemsList) {
713 QList<ModuleBase_ModelWidget*> aWidgetsList = aItem->widgets();
714 foreach(ModuleBase_ModelWidget* aWidget, aWidgetsList) {
715 if (!aWidget->feature().get())
716 aWidget->setFeature(myFeature);
717 aWidget->restoreValue();
720 updateObject(myFeature);
722 // Redisplay the feature on order to Customize presentations from filters with selectors
723 static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
724 ModelAPI_EventCreator::get()->sendUpdated(myFeature, EVENT_DISP);
725 Events_Loop::loop()->flush(EVENT_DISP);