1 // Copyright (C) 2014-2021 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>
38 #include <GeomAPI_ShapeExplorer.h>
39 #include <GeomAPI_Edge.h>
41 #include <Events_Loop.h>
42 #include <Config_ValidatorReader.h>
44 #include <AIS_InteractiveContext.hxx>
45 #include <StdSelect_BRepOwner.hxx>
46 #include <TopoDS_Compound.hxx>
47 #include <BRep_Builder.hxx>
48 #include <TopExp_Explorer.hxx>
51 #include <QPushButton>
56 #include <QToolButton>
60 FeaturePtr ModuleBase_WidgetSelectionFilter::SelectorFeature;
61 std::string ModuleBase_WidgetSelectionFilter::AttributeId;
64 GeomAPI_Shape::ShapeType selectionType(const QString& theType)
66 QString aType = theType.toUpper();
67 if ((aType == "VERTEX") || (aType == "VERTICES"))
68 return GeomAPI_Shape::VERTEX;
69 else if ((aType == "EDGE") || (aType == "EDGES"))
70 return GeomAPI_Shape::EDGE;
71 else if ((aType == "WIRE") || (aType == "WIRES"))
72 return GeomAPI_Shape::WIRE;
73 else if ((aType == "FACE") || (aType == "FACES"))
74 return GeomAPI_Shape::FACE;
75 else if ((aType == "SHELL") || (aType == "SHELLS"))
76 return GeomAPI_Shape::SHELL;
77 else if ((aType == "SOLID") || (aType == "SOLIDS"))
78 return GeomAPI_Shape::SOLID;
79 else if ((aType == "COMPSOLID") || (aType == "COMPSOLIDS"))
80 return GeomAPI_Shape::COMPSOLID;
81 else if ((aType == "COMPOUND") || (aType == "COMPOUNDS"))
82 return GeomAPI_Shape::COMPOUND;
84 return GeomAPI_Shape::SHAPE;
88 ModuleBase_FilterStarter::ModuleBase_FilterStarter(const std::string& theFeature,
89 QWidget* theParent, ModuleBase_IWorkshop* theWorkshop)
91 myFeatureName(theFeature),
92 myWorkshop(theWorkshop)
94 QHBoxLayout* aMainLayout = new QHBoxLayout(this);
95 ModuleBase_Tools::adjustMargins(aMainLayout);
97 aMainLayout->addStretch(1);
98 QPushButton* aLaunchBtn = new QPushButton(
99 ModuleBase_Tools::translate("FiltersSelection", "Selection by filters"), this);
100 connect(aLaunchBtn, SIGNAL(clicked()), SLOT(onFiltersLaunch()));
101 aMainLayout->addWidget(aLaunchBtn);
104 void ModuleBase_FilterStarter::onFiltersLaunch()
106 static QString aHelpFileName = QString("FiltersPlugin") + QDir::separator() +
107 QString("FiltersPlugin.html");
109 ModuleBase_Operation* aParentOp = myWorkshop->currentOperation();
110 ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(aParentOp);
112 // Open transaction on filters operation finish
113 aFeatureOp->openTransactionOnResume();
115 QWidget* aParent = parentWidget();
116 ModuleBase_WidgetMultiSelector* aSelector =
117 dynamic_cast<ModuleBase_WidgetMultiSelector*>(aParent);
119 aParent = aParent->parentWidget();
120 aSelector = dynamic_cast<ModuleBase_WidgetMultiSelector*>(aParent);
124 ModuleBase_WidgetSelectionFilter::SelectorFeature = aSelector->feature();
125 ModuleBase_WidgetSelectionFilter::AttributeId = aSelector->attributeID();
127 // Launch Filters operation
128 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
129 (myWorkshop->module()->createOperation(myFeatureName));
131 AttributeSelectionListPtr aAttrList =
132 ModuleBase_WidgetSelectionFilter::SelectorFeature->selectionList(
133 ModuleBase_WidgetSelectionFilter::AttributeId);
134 FiltersFeaturePtr aFilters = aAttrList->filters();
136 aFOperation->setFeature(aFilters);
137 aFOperation->setHelpFileName(aHelpFileName);
138 myWorkshop->processLaunchOperation(aFOperation);
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()))
149 FilterPtr aFilter = ModelAPI_Session::get()->filters()->filter(theFilter);
150 std::string aXmlString = aFilter->xmlRepresentation();
151 if (aXmlString.length() == 0)
154 std::string anAttrPrefix; // this must be added to the attributes names for multiple filters
155 std::string aFilterKind = ModelAPI_Session::get()->filters()->id(aFilter);
156 if (theFilter != aFilterKind) {
157 anAttrPrefix = theFilter.substr(0, theFilter.size() - aFilterKind.size());
159 ModuleBase_WidgetFactory aFactory(aXmlString, theParent->workshop(), anAttrPrefix);
160 Config_ValidatorReader aValidatorReader(aXmlString, true);
161 aValidatorReader.setFeatureId(mySelection->getKind());
162 aValidatorReader.readAll();
164 QVBoxLayout* aLayout = new QVBoxLayout(this);
165 ModuleBase_Tools::zeroMargins(aLayout);
167 QWidget* aItemRow = new QWidget(this);
168 addItemRow(aItemRow);
169 aLayout->addWidget(aItemRow);
171 ModuleBase_PageWidget* aParamsWgt = new ModuleBase_PageWidget(this);
172 aParamsWgt->setFrameStyle(QFrame::Box | QFrame::Raised);
173 aFactory.createWidget(aParamsWgt);
174 ModuleBase_Tools::zeroMargins(aParamsWgt->layout());
175 myWidgets = aFactory.getModelWidgets();
176 foreach(ModuleBase_ModelWidget* aWidget, myWidgets) {
177 aWidget->setFeature(theParent->feature());
178 connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
179 theParent, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)));
180 connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
181 theParent, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)));
182 connect(aWidget, SIGNAL(objectUpdated()), theParent, SLOT(onObjectUpdated()));
183 aWidget->enableFocusProcessing();
185 aLayout->addWidget(aParamsWgt);
189 void ModuleBase_FilterItem::addItemRow(QWidget* theParent)
191 std::string aContext = mySelection->getKind();
192 QHBoxLayout* aLayout = new QHBoxLayout(theParent);
193 ModuleBase_Tools::zeroMargins(aLayout);
195 // Reverse filter button
196 myRevBtn = new QToolButton(theParent);
197 myRevBtn->setCheckable(true);
198 bool isReversed = mySelection->isReversed(myFilterID);
199 myRevBtn->setChecked(isReversed);
200 myRevBtn->setAutoRaise(true);
202 myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
204 myRevBtn->setIcon(QIcon(":pictures/add.png"));
205 myRevBtn->setToolTip(ModuleBase_Tools::translate(aContext, "Reverse the filter"));
206 connect(myRevBtn, SIGNAL(toggled(bool)), SLOT(onReverse(bool)));
207 aLayout->addWidget(myRevBtn);
209 const std::string& aFilterName = ModelAPI_Session::get()->filters()->filter(myFilterID)->name();
210 aLayout->addWidget(new QLabel(ModuleBase_Tools::translate(aContext, aFilterName), theParent), 1);
212 QToolButton* aDelBtn = new QToolButton(theParent);
213 aDelBtn->setIcon(QIcon(":pictures/delete.png"));
214 aDelBtn->setAutoRaise(true);
215 aDelBtn->setToolTip(ModuleBase_Tools::translate(aContext, "Delete the filter"));
216 connect(aDelBtn, SIGNAL(clicked(bool)), SLOT(onDelete()));
217 aLayout->addWidget(aDelBtn);
220 void ModuleBase_FilterItem::onReverse(bool theCheck)
222 mySelection->setReversed(myFilterID, theCheck);
224 myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
226 myRevBtn->setIcon(QIcon(":pictures/add.png"));
227 emit reversedItem(this);
230 void ModuleBase_FilterItem::onDelete()
232 emit deleteItem(this);
236 //*****************************************************************************
237 //*****************************************************************************
238 //*****************************************************************************
239 ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theParent,
240 ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, bool theReadOnly)
241 : ModuleBase_ModelWidget(theParent, theData),
242 myWorkshop(theWorkshop),
243 mySelectorFeature(ModuleBase_WidgetSelectionFilter::SelectorFeature),
244 mySelectorAttribute(ModuleBase_WidgetSelectionFilter::AttributeId)
246 // Clear Old selection
247 AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
248 mySelectionType = selectionType(aAttrList->selectionType().c_str());
254 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
255 ModuleBase_Tools::adjustMargins(aMainLayout);
257 QGroupBox* aFiltersGroup = new QGroupBox(translate("Filters"), this);
258 QVBoxLayout* aGroupLayout = new QVBoxLayout(aFiltersGroup);
259 aGroupLayout->setContentsMargins(0, 0, 0, 0);
260 aGroupLayout->setSpacing(0);
262 myFiltersWgt = new QWidget();
263 myFiltersLayout = new QVBoxLayout(myFiltersWgt);
264 myFiltersLayout->setContentsMargins(0, 0, 0, 0);
265 aGroupLayout->addWidget(myFiltersWgt);
267 myFiltersCombo = new QComboBox(aFiltersGroup);
268 myFiltersCombo->addItem(translate("Add new filter..."));
269 SessionPtr aSession = ModelAPI_Session::get();
270 std::list<FilterPtr> allFilters =
271 aSession->filters()->filters((GeomAPI_Shape::ShapeType) mySelectionType);
272 storeFilters(allFilters);
274 std::list<FilterPtr>::const_iterator aIt;
275 for (aIt = allFilters.cbegin(); aIt != allFilters.cend(); aIt++) {
276 aItems.push_back(translate((*aIt)->name().c_str()));
278 myFiltersCombo->addItems(aItems);
279 connect(myFiltersCombo, SIGNAL(currentIndexChanged(int)), SLOT(onAddFilter(int)));
281 aGroupLayout->addWidget(myFiltersCombo);
282 aMainLayout->addWidget(aFiltersGroup);
285 QWidget* aBtnWgt = new QWidget(this);
286 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnWgt);
287 ModuleBase_Tools::adjustMargins(aBtnLayout);
289 aBtnLayout->addStretch(1);
291 mySelectBtn = new QPushButton(translate("Select"), aBtnWgt);
292 connect(mySelectBtn, SIGNAL(clicked()), SLOT(onSelect()));
293 aBtnLayout->addWidget(mySelectBtn);
295 aMainLayout->addWidget(aBtnWgt);
298 QWidget* aLblWgt = new QWidget(this);
299 QHBoxLayout* aLblLayout = new QHBoxLayout(aLblWgt);
300 ModuleBase_Tools::zeroMargins(aLblLayout);
302 aLblLayout->addWidget(new QLabel(translate("Number of selected objects:"), aLblWgt));
304 myNbLbl = new QLabel("0", aLblWgt);
305 aLblLayout->addWidget(myNbLbl);
308 myShowBtn = new QCheckBox(translate("Show only"), this);
309 connect(myShowBtn, SIGNAL(toggled(bool)), SLOT(onShowOnly(bool)));
310 aLblLayout->addWidget(myShowBtn);
312 aMainLayout->addWidget(aLblWgt);
314 aMainLayout->addStretch(1);
318 myFiltersCombo->hide();
325 ModuleBase_WidgetSelectionFilter::~ModuleBase_WidgetSelectionFilter()
328 if (!myPreview.IsNull()) {
329 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
330 aCtx->Remove(myPreview, false);
332 if (myListIO.Size() > 0) {
333 aCtx = myWorkshop->viewer()->AISContext();
334 AIS_ListOfInteractive::const_iterator aIt;
335 Handle(AIS_Shape) aShapeIO;
336 for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
337 aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
338 if (!aShapeIO.IsNull()) {
339 aCtx->Display(aShapeIO, false);
340 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
341 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
342 myWorkshop->applyCurrentSelectionModes(anAISObj);
346 myShowBtn->setChecked(false);
348 myWorkshop->viewer()->update();
350 SelectorFeature = FeaturePtr();
354 void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex)
359 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
360 FiltersFeaturePtr aFiltersFeature =
361 std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
363 std::string aText = myFiltersCombo->itemText(theIndex).toStdString();
365 std::list<FilterPtr>::iterator aIt;
367 std::map<std::string, FilterPtr>::const_iterator aFound = myFilters.find(aText);
368 if (aFound == myFilters.end()) {
369 std::list<FilterPtr> aFilters = aFactory->filters((GeomAPI_Shape::ShapeType) mySelectionType);
370 storeFilters(aFilters);
371 aFound = myFilters.find(aText);
373 if (aFound != myFilters.end())
374 aFilter = aFactory->id(aFound->second);
376 aFiltersFeature->addFilter(aFilter);
377 updateObject(myFeature);
379 QList<ModuleBase_FilterItem*> aList = itemsList();
380 if (!aList.isEmpty() && (aList.last()->widgets().size() > 0))
381 aList.last()->widgets().first()->emitFocusInWidget();
386 ModuleBase_FilterItem* ModuleBase_WidgetSelectionFilter::onAddFilter(const std::string& theFilter)
388 if (theFilter.length() == 0)
390 ModuleBase_FilterItem* aItem = new ModuleBase_FilterItem(theFilter, this);
391 connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)),
392 SLOT(onDeleteItem(ModuleBase_FilterItem*)));
393 connect(aItem, SIGNAL(reversedItem(ModuleBase_FilterItem*)),
394 SLOT(onReverseItem(ModuleBase_FilterItem*)));
395 myFiltersLayout->addWidget(aItem);
398 clearCurrentSelection(true);
399 updateNumberSelected();
403 void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theItem)
405 std::string aFilter = theItem->filter();
406 QList<ModuleBase_ModelWidget*> aWidgets = theItem->widgets();
407 foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
410 myFiltersLayout->removeWidget(theItem);
411 theItem->deleteLater();
413 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
414 if (!aFactory->filter(aFilter)->isMultiple()) {
415 //myFilters.push_back(aFilter);
416 myFiltersCombo->addItem(ModelAPI_Session::get()->filters()->filter(aFilter)->name().c_str());
418 FiltersFeaturePtr aFiltersFeature =
419 std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
420 aFiltersFeature->removeFilter(aFilter);
423 clearCurrentSelection(true);
424 updateNumberSelected();
426 myWorkshop->deactivateCurrentSelector();
427 myWorkshop->selectionActivate()->updateSelectionModes();
428 myWorkshop->selectionActivate()->updateSelectionFilters();
431 updateObject(myFeature);
435 void ModuleBase_WidgetSelectionFilter::redisplayFeature()
437 static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
438 ModelAPI_EventCreator::get()->sendUpdated(myFeature, aDispEvent);
439 Events_Loop::loop()->flush(aDispEvent);
442 void ModuleBase_WidgetSelectionFilter::onReverseItem(ModuleBase_FilterItem* theItem)
445 clearCurrentSelection(true);
446 updateNumberSelected();
449 void ModuleBase_WidgetSelectionFilter::onSelect()
451 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
455 clearCurrentSelection();
457 FiltersFeaturePtr aFiltersFeature =
458 std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
459 static SessionPtr aSession = ModelAPI_Session::get();
460 std::list< std::pair<ResultPtr, GeomShapePtr> > aResList =
461 aSession->filters()->select(aFiltersFeature, (GeomAPI_Shape::ShapeType)mySelectionType);
463 BRep_Builder aBuilder;
464 TopoDS_Compound aComp;
465 aBuilder.MakeCompound(aComp);
467 std::list< std::pair<ResultPtr, GeomShapePtr> >::const_iterator itSelected = aResList.cbegin();
468 for (; itSelected != aResList.cend(); itSelected++) {
469 ResultPtr aCurRes = (*itSelected).first;
470 GeomShapePtr aSubShape = (*itSelected).second;
471 TopoDS_Shape aTShape = aSubShape->impl<TopoDS_Shape>();
472 aBuilder.Add(aComp, aTShape);
473 ModuleBase_ViewerPrsPtr aValue (new ModuleBase_ViewerPrs(aCurRes, aSubShape));
474 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 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
517 AIS_ListOfInteractive aList;
518 aCtx->DisplayedObjects(AIS_KOI_Shape, -1, aList);
519 if (!myPreview.IsNull())
520 aList.Remove(myPreview);
521 if (aList.Size() > 0)
524 AIS_ListOfInteractive::const_iterator aIt;
525 Handle(AIS_Shape) aShapeIO;
526 bool isModified = false;
527 for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
528 aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
529 if (!aShapeIO.IsNull()) {
531 if (aCtx->IsDisplayed(aShapeIO)) {
532 aCtx->Erase(aShapeIO, false);
537 if (!aCtx->IsDisplayed(aShapeIO)) {
538 aCtx->Display(aShapeIO, false);
539 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
540 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
541 myWorkshop->applyCurrentSelectionModes(anAISObj);
548 myWorkshop->viewer()->update();
551 void ModuleBase_WidgetSelectionFilter::updateSelectBtn()
553 FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
554 mySelectBtn->setEnabled(aFiltersFeature.get() && (aFiltersFeature->filters().size() > 0));
557 void ModuleBase_WidgetSelectionFilter::updateNumberSelected()
559 int aNb = myValues.size();
560 myNbLbl->setText(QString::number(aNb));
562 myFeature->setError(translate("Selection is empty").toStdString(), false, false);
563 myShowBtn->setChecked(false);
565 myShowBtn->setEnabled(false);
568 myFeature->setError("", false, false);
569 myFeature->data()->execState(ModelAPI_StateDone);
570 myShowBtn->setEnabled(true);
574 QList<QWidget*> ModuleBase_WidgetSelectionFilter::getControls() const
576 QList<QWidget*> aWidgets;
577 aWidgets.append(myFiltersCombo);
581 void ModuleBase_WidgetSelectionFilter::clearCurrentSelection(bool toUpdate)
584 if (!myPreview.IsNull()) {
585 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
586 aCtx->Remove(myPreview, toUpdate);
591 void replaceSubShapesByResult(QList<ModuleBase_ViewerPrsPtr>& theResults, int theShapeType)
593 QMap<ObjectPtr, QList<GeomShapePtr>> myResShapes;
594 // Sort sub-shapes by result
595 foreach (ModuleBase_ViewerPrsPtr aPrs, theResults) {
596 if (myResShapes.contains(aPrs->object()))
597 myResShapes[aPrs->object()].append(aPrs->shape());
599 QList<GeomShapePtr> aShapes;
600 aShapes << aPrs->shape();
601 myResShapes[aPrs->object()] = aShapes;
604 // Find Results to replace by whole result
605 QList<GeomShapePtr> aShapes;
606 QList<ObjectPtr> aToReplace;
607 std::list<GeomShapePtr> aSubShapes;
608 foreach(ObjectPtr aObj, myResShapes.keys()) {
609 aShapes = myResShapes[aObj];
610 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
611 TopTools_MapOfShape aShapesMap;
613 GeomShapePtr aSubShape = aRes->shape();
614 const TopoDS_Shape& aShape = aSubShape->impl<TopoDS_Shape>();
615 for (TopExp_Explorer anExp(aShape, (TopAbs_ShapeEnum)theShapeType);
616 anExp.More(); anExp.Next()) {
617 aShapesMap.Add(anExp.Current());
620 if (aShapes.count() == aShapesMap.Size())
621 aToReplace.append(aObj);
623 // Replace the found results
624 QList<ModuleBase_ViewerPrsPtr>::iterator aIt;
625 foreach(ObjectPtr aObj, aToReplace) {
626 for (aIt = theResults.begin(); aIt != theResults.end(); aIt++) {
627 if ((*aIt)->object() == aObj) {
628 theResults.removeAll(*aIt);
632 ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj));
633 theResults.append(aValue);
637 void ModuleBase_WidgetSelectionFilter::onFeatureAccepted()
639 AttributePtr aAttr = mySelectorFeature->attribute(mySelectorAttribute);
640 AttributeSelectionListPtr aSelListAttr =
641 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
642 aSelListAttr->clear();
643 if (aSelListAttr->isWholeResultAllowed())
644 replaceSubShapesByResult(myValues, selectionType(aSelListAttr->selectionType().c_str()));
645 foreach(ModuleBase_ViewerPrsPtr aPrs, myValues) {
646 aSelListAttr->append(aPrs->object(), aPrs->shape());
650 bool ModuleBase_WidgetSelectionFilter::storeValueCustom()
652 ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget();
654 return aActive->storeValue();
655 updateObject(myFeature);
659 QList<ModuleBase_FilterItem*> ModuleBase_WidgetSelectionFilter::itemsList() const
661 return myFiltersWgt->findChildren<ModuleBase_FilterItem*>();
665 bool ModuleBase_WidgetSelectionFilter::restoreValueCustom()
667 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
668 FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
670 // Init filters member of the parent attribute
671 AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
672 if (aAttrList->filters() != aFiltersFeature) {
673 aAttrList->setFilters(aFiltersFeature);
676 QList<ModuleBase_FilterItem*> aItemsList = itemsList();
677 std::list<std::string> aFilters = aFiltersFeature->filters();
679 std::list<std::string>::const_iterator aIt;
681 int aNbItems = aItemsList.size();
682 ModuleBase_FilterItem* aItem = 0;
683 bool isBlocked = myFiltersCombo->blockSignals(true);
684 for (aIt = aFilters.cbegin(); aIt != aFilters.cend(); aIt++, i++) {
685 std::string aStr = (*aIt);
688 aItem = onAddFilter(aStr);
689 FilterPtr aFilterObj = aFactory->filter(aStr);
690 int aId = myFiltersCombo->findText(aFilterObj->name().c_str());
691 if ((aId != -1) && !aFilterObj->isMultiple())
692 myFiltersCombo->removeItem(aId);
694 QList<ModuleBase_ModelWidget*> aSubList = aItem->widgets();
695 foreach(ModuleBase_ModelWidget* aWgt, aSubList) {
696 aWgt->restoreValue();
701 myFiltersCombo->setCurrentIndex(0);
702 myFiltersCombo->blockSignals(isBlocked);
706 QString ModuleBase_WidgetSelectionFilter::getError(const bool theValueStateChecked) const
708 QString aErrorMsg = ModuleBase_ModelWidget::getError(theValueStateChecked);
709 if (aErrorMsg.isEmpty()) {
710 if (myValues.size() == 0)
711 aErrorMsg = translate("Selection is empty");
716 void ModuleBase_WidgetSelectionFilter::onObjectUpdated()
718 myShowBtn->setChecked(false);
719 clearCurrentSelection(true);
720 updateNumberSelected();
722 QList<ModuleBase_FilterItem*> aItemsList = itemsList();
723 foreach(ModuleBase_FilterItem* aItem, aItemsList) {
724 QList<ModuleBase_ModelWidget*> aWidgetsList = aItem->widgets();
725 foreach(ModuleBase_ModelWidget* aWidget, aWidgetsList) {
726 if (!aWidget->feature().get())
727 aWidget->setFeature(myFeature);
728 aWidget->restoreValue();
731 updateObject(myFeature);
733 // Redisplay the feature on order to Customize presentations from filters with selectors
734 static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
735 ModelAPI_EventCreator::get()->sendUpdated(myFeature, EVENT_DISP);
736 Events_Loop::loop()->flush(EVENT_DISP);
739 void ModuleBase_WidgetSelectionFilter::storeFilters(const std::list<FilterPtr>& theFilters)
741 for (std::list<FilterPtr>::const_iterator anIt = theFilters.begin();
742 anIt != theFilters.end(); ++anIt) {
743 std::string aName = translate((*anIt)->name()).toStdString();
744 myFilters[aName] = *anIt;
748 QString ModuleBase_WidgetSelectionFilter::translate(const std::string& theString) const
750 return ModuleBase_Tools::translate(myFeatureId, theString);