1 // Copyright (C) 2014-2022 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>
61 #pragma warning(disable : 4456) // for nested foreach
64 FeaturePtr ModuleBase_WidgetSelectionFilter::SelectorFeature;
65 std::string ModuleBase_WidgetSelectionFilter::AttributeId;
68 GeomAPI_Shape::ShapeType selectionType(const QString& theType)
70 QString aType = theType.toUpper();
71 if ((aType == "VERTEX") || (aType == "VERTICES"))
72 return GeomAPI_Shape::VERTEX;
73 else if ((aType == "EDGE") || (aType == "EDGES"))
74 return GeomAPI_Shape::EDGE;
75 else if ((aType == "WIRE") || (aType == "WIRES"))
76 return GeomAPI_Shape::WIRE;
77 else if ((aType == "FACE") || (aType == "FACES"))
78 return GeomAPI_Shape::FACE;
79 else if ((aType == "SHELL") || (aType == "SHELLS"))
80 return GeomAPI_Shape::SHELL;
81 else if ((aType == "SOLID") || (aType == "SOLIDS"))
82 return GeomAPI_Shape::SOLID;
83 else if ((aType == "COMPSOLID") || (aType == "COMPSOLIDS"))
84 return GeomAPI_Shape::COMPSOLID;
85 else if ((aType == "COMPOUND") || (aType == "COMPOUNDS"))
86 return GeomAPI_Shape::COMPOUND;
88 return GeomAPI_Shape::SHAPE;
92 ModuleBase_FilterStarter::ModuleBase_FilterStarter(const std::string& theFeature,
93 QWidget* theParent, ModuleBase_IWorkshop* theWorkshop)
95 myFeatureName(theFeature),
96 myWorkshop(theWorkshop)
98 QHBoxLayout* aMainLayout = new QHBoxLayout(this);
99 ModuleBase_Tools::adjustMargins(aMainLayout);
101 aMainLayout->addStretch(1);
102 QPushButton* aLaunchBtn = new QPushButton(
103 ModuleBase_Tools::translate("FiltersSelection", "Selection by filters"), this);
104 connect(aLaunchBtn, SIGNAL(clicked()), SLOT(onFiltersLaunch()));
105 aMainLayout->addWidget(aLaunchBtn);
108 void ModuleBase_FilterStarter::onFiltersLaunch()
110 static QString aHelpFileName = QString("FiltersPlugin") + QDir::separator() +
111 QString("FiltersPlugin.html");
113 ModuleBase_Operation* aParentOp = myWorkshop->currentOperation();
114 ModuleBase_OperationFeature* aFeatureOp = dynamic_cast<ModuleBase_OperationFeature*>(aParentOp);
116 // Open transaction on filters operation finish
117 aFeatureOp->openTransactionOnResume();
119 QWidget* aParent = parentWidget();
120 ModuleBase_WidgetMultiSelector* aSelector =
121 dynamic_cast<ModuleBase_WidgetMultiSelector*>(aParent);
123 aParent = aParent->parentWidget();
124 aSelector = dynamic_cast<ModuleBase_WidgetMultiSelector*>(aParent);
128 ModuleBase_WidgetSelectionFilter::SelectorFeature = aSelector->feature();
129 ModuleBase_WidgetSelectionFilter::AttributeId = aSelector->attributeID();
131 // Launch Filters operation
132 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
133 (myWorkshop->module()->createOperation(myFeatureName));
135 AttributeSelectionListPtr aAttrList =
136 ModuleBase_WidgetSelectionFilter::SelectorFeature->selectionList(
137 ModuleBase_WidgetSelectionFilter::AttributeId);
138 FiltersFeaturePtr aFilters = aAttrList->filters();
140 aFOperation->setFeature(aFilters);
141 aFOperation->setHelpFileName(aHelpFileName);
142 myWorkshop->processLaunchOperation(aFOperation);
145 //*****************************************************************************
146 //*****************************************************************************
147 //*****************************************************************************
148 ModuleBase_FilterItem::ModuleBase_FilterItem(
149 const std::string& theFilter, ModuleBase_WidgetSelectionFilter* theParent)
150 : QWidget(theParent->filtersWidget()), myFilterID(theFilter),
151 mySelection(std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(theParent->feature()))
153 FilterPtr aFilter = ModelAPI_Session::get()->filters()->filter(theFilter);
154 std::string aXmlString = aFilter->xmlRepresentation();
155 if (aXmlString.length() == 0)
158 std::string anAttrPrefix; // this must be added to the attributes names for multiple filters
159 std::string aFilterKind = ModelAPI_Session::get()->filters()->id(aFilter);
160 if (theFilter != aFilterKind) {
161 anAttrPrefix = theFilter.substr(0, theFilter.size() - aFilterKind.size());
163 ModuleBase_WidgetFactory aFactory(aXmlString, theParent->workshop(), anAttrPrefix);
164 Config_ValidatorReader aValidatorReader(aXmlString, true);
165 aValidatorReader.setFeatureId(mySelection->getKind());
166 aValidatorReader.readAll();
168 QVBoxLayout* aLayout = new QVBoxLayout(this);
169 ModuleBase_Tools::zeroMargins(aLayout);
171 QWidget* aItemRow = new QWidget(this);
172 addItemRow(aItemRow);
173 aLayout->addWidget(aItemRow);
175 ModuleBase_PageWidget* aParamsWgt = new ModuleBase_PageWidget(this);
176 aParamsWgt->setFrameStyle(QFrame::Box | QFrame::Raised);
177 aFactory.createWidget(aParamsWgt);
178 ModuleBase_Tools::zeroMargins(aParamsWgt->layout());
179 myWidgets = aFactory.getModelWidgets();
180 foreach(ModuleBase_ModelWidget* aWidget, myWidgets) {
181 aWidget->setFeature(theParent->feature());
182 connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
183 theParent, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)));
184 connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
185 theParent, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)));
186 connect(aWidget, SIGNAL(objectUpdated()), theParent, SLOT(onObjectUpdated()));
187 aWidget->enableFocusProcessing();
189 aLayout->addWidget(aParamsWgt);
193 void ModuleBase_FilterItem::addItemRow(QWidget* theParent)
195 std::string aContext = mySelection->getKind();
196 QHBoxLayout* aLayout = new QHBoxLayout(theParent);
197 ModuleBase_Tools::zeroMargins(aLayout);
199 // Reverse filter button
200 myRevBtn = new QToolButton(theParent);
201 myRevBtn->setCheckable(true);
202 bool isReversed = mySelection->isReversed(myFilterID);
203 myRevBtn->setChecked(isReversed);
204 myRevBtn->setAutoRaise(true);
206 myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
208 myRevBtn->setIcon(QIcon(":pictures/add.png"));
209 myRevBtn->setToolTip(ModuleBase_Tools::translate(aContext, "Reverse the filter"));
210 connect(myRevBtn, SIGNAL(toggled(bool)), SLOT(onReverse(bool)));
211 aLayout->addWidget(myRevBtn);
213 const std::string& aFilterName = ModelAPI_Session::get()->filters()->filter(myFilterID)->name();
214 aLayout->addWidget(new QLabel(ModuleBase_Tools::translate(aContext, aFilterName), theParent), 1);
216 QToolButton* aDelBtn = new QToolButton(theParent);
217 aDelBtn->setIcon(QIcon(":pictures/delete.png"));
218 aDelBtn->setAutoRaise(true);
219 aDelBtn->setToolTip(ModuleBase_Tools::translate(aContext, "Delete the filter"));
220 connect(aDelBtn, SIGNAL(clicked(bool)), SLOT(onDelete()));
221 aLayout->addWidget(aDelBtn);
224 void ModuleBase_FilterItem::onReverse(bool theCheck)
226 mySelection->setReversed(myFilterID, theCheck);
228 myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
230 myRevBtn->setIcon(QIcon(":pictures/add.png"));
231 emit reversedItem(this);
234 void ModuleBase_FilterItem::onDelete()
236 emit deleteItem(this);
240 //*****************************************************************************
241 //*****************************************************************************
242 //*****************************************************************************
243 ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theParent,
244 ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, bool theReadOnly)
245 : ModuleBase_ModelWidget(theParent, theData),
246 myWorkshop(theWorkshop),
247 mySelectorFeature(ModuleBase_WidgetSelectionFilter::SelectorFeature),
248 mySelectorAttribute(ModuleBase_WidgetSelectionFilter::AttributeId)
250 // Clear Old selection
251 AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
252 mySelectionType = selectionType(aAttrList->selectionType().c_str());
258 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
259 ModuleBase_Tools::adjustMargins(aMainLayout);
261 QGroupBox* aFiltersGroup = new QGroupBox(translate("Filters"), this);
262 QVBoxLayout* aGroupLayout = new QVBoxLayout(aFiltersGroup);
263 aGroupLayout->setContentsMargins(0, 0, 0, 0);
264 aGroupLayout->setSpacing(0);
266 myFiltersWgt = new QWidget();
267 myFiltersLayout = new QVBoxLayout(myFiltersWgt);
268 myFiltersLayout->setContentsMargins(0, 0, 0, 0);
269 aGroupLayout->addWidget(myFiltersWgt);
271 myFiltersCombo = new QComboBox(aFiltersGroup);
272 myFiltersCombo->addItem(translate("Add new filter..."));
273 SessionPtr aSession = ModelAPI_Session::get();
274 std::list<FilterPtr> allFilters =
275 aSession->filters()->filters((GeomAPI_Shape::ShapeType) mySelectionType);
276 storeFilters(allFilters);
278 std::list<FilterPtr>::const_iterator aIt;
279 for (aIt = allFilters.cbegin(); aIt != allFilters.cend(); aIt++) {
280 aItems.push_back(translate((*aIt)->name().c_str()));
282 myFiltersCombo->addItems(aItems);
283 connect(myFiltersCombo, SIGNAL(currentIndexChanged(int)), SLOT(onAddFilter(int)));
285 aGroupLayout->addWidget(myFiltersCombo);
286 aMainLayout->addWidget(aFiltersGroup);
289 QWidget* aBtnWgt = new QWidget(this);
290 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnWgt);
291 ModuleBase_Tools::adjustMargins(aBtnLayout);
293 aBtnLayout->addStretch(1);
295 mySelectBtn = new QPushButton(translate("Select"), aBtnWgt);
296 connect(mySelectBtn, SIGNAL(clicked()), SLOT(onSelect()));
297 aBtnLayout->addWidget(mySelectBtn);
299 aMainLayout->addWidget(aBtnWgt);
302 QWidget* aLblWgt = new QWidget(this);
303 QHBoxLayout* aLblLayout = new QHBoxLayout(aLblWgt);
304 ModuleBase_Tools::zeroMargins(aLblLayout);
306 aLblLayout->addWidget(new QLabel(translate("Number of selected objects:"), aLblWgt));
308 myNbLbl = new QLabel("0", aLblWgt);
309 aLblLayout->addWidget(myNbLbl);
312 myShowBtn = new QCheckBox(translate("Show only"), this);
313 connect(myShowBtn, SIGNAL(toggled(bool)), SLOT(onShowOnly(bool)));
314 aLblLayout->addWidget(myShowBtn);
316 aMainLayout->addWidget(aLblWgt);
318 aMainLayout->addStretch(1);
322 myFiltersCombo->hide();
329 ModuleBase_WidgetSelectionFilter::~ModuleBase_WidgetSelectionFilter()
332 if (!myPreview.IsNull()) {
333 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
334 aCtx->Remove(myPreview, false);
336 if (myListIO.Size() > 0) {
337 aCtx = myWorkshop->viewer()->AISContext();
338 AIS_ListOfInteractive::const_iterator aIt;
339 Handle(AIS_Shape) aShapeIO;
340 for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
341 aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
342 if (!aShapeIO.IsNull()) {
343 aCtx->Display(aShapeIO, false);
344 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
345 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
346 myWorkshop->applyCurrentSelectionModes(anAISObj);
350 myShowBtn->setChecked(false);
352 myWorkshop->viewer()->update();
354 SelectorFeature = FeaturePtr();
358 void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex)
363 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
364 FiltersFeaturePtr aFiltersFeature =
365 std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
367 std::string aText = myFiltersCombo->itemText(theIndex).toStdString();
369 std::list<FilterPtr>::iterator aIt;
371 std::map<std::string, FilterPtr>::const_iterator aFound = myFilters.find(aText);
372 if (aFound == myFilters.end()) {
373 std::list<FilterPtr> aFilters = aFactory->filters((GeomAPI_Shape::ShapeType) mySelectionType);
374 storeFilters(aFilters);
375 aFound = myFilters.find(aText);
377 if (aFound != myFilters.end())
378 aFilter = aFactory->id(aFound->second);
380 aFiltersFeature->addFilter(aFilter);
381 updateObject(myFeature);
383 QList<ModuleBase_FilterItem*> aList = itemsList();
384 if (!aList.isEmpty() && (aList.last()->widgets().size() > 0))
385 aList.last()->widgets().first()->emitFocusInWidget();
390 ModuleBase_FilterItem* ModuleBase_WidgetSelectionFilter::onAddFilter(const std::string& theFilter)
392 if (theFilter.length() == 0)
394 ModuleBase_FilterItem* aItem = new ModuleBase_FilterItem(theFilter, this);
395 connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)),
396 SLOT(onDeleteItem(ModuleBase_FilterItem*)));
397 connect(aItem, SIGNAL(reversedItem(ModuleBase_FilterItem*)),
398 SLOT(onReverseItem(ModuleBase_FilterItem*)));
399 myFiltersLayout->addWidget(aItem);
402 clearCurrentSelection(true);
403 updateNumberSelected();
407 void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theItem)
409 std::string aFilter = theItem->filter();
410 QList<ModuleBase_ModelWidget*> aWidgets = theItem->widgets();
411 foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
414 myFiltersLayout->removeWidget(theItem);
415 theItem->deleteLater();
417 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
418 if (!aFactory->filter(aFilter)->isMultiple()) {
419 //myFilters.push_back(aFilter);
420 myFiltersCombo->addItem(ModelAPI_Session::get()->filters()->filter(aFilter)->name().c_str());
422 FiltersFeaturePtr aFiltersFeature =
423 std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
424 aFiltersFeature->removeFilter(aFilter);
427 clearCurrentSelection(true);
428 updateNumberSelected();
430 myWorkshop->deactivateCurrentSelector();
431 myWorkshop->selectionActivate()->updateSelectionModes();
432 myWorkshop->selectionActivate()->updateSelectionFilters();
435 updateObject(myFeature);
439 void ModuleBase_WidgetSelectionFilter::redisplayFeature()
441 static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
442 ModelAPI_EventCreator::get()->sendUpdated(myFeature, aDispEvent);
443 Events_Loop::loop()->flush(aDispEvent);
446 void ModuleBase_WidgetSelectionFilter::onReverseItem(ModuleBase_FilterItem* theItem)
449 clearCurrentSelection(true);
450 updateNumberSelected();
453 void ModuleBase_WidgetSelectionFilter::onSelect()
455 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
459 clearCurrentSelection();
461 FiltersFeaturePtr aFiltersFeature =
462 std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
463 static SessionPtr aSession = ModelAPI_Session::get();
464 std::list< std::pair<ResultPtr, GeomShapePtr> > aResList =
465 aSession->filters()->select(aFiltersFeature, (GeomAPI_Shape::ShapeType)mySelectionType);
467 BRep_Builder aBuilder;
468 TopoDS_Compound aComp;
469 aBuilder.MakeCompound(aComp);
471 std::list< std::pair<ResultPtr, GeomShapePtr> >::const_iterator itSelected = aResList.cbegin();
472 for (; itSelected != aResList.cend(); itSelected++) {
473 ResultPtr aCurRes = (*itSelected).first;
474 GeomShapePtr aSubShape = (*itSelected).second;
475 TopoDS_Shape aTShape = aSubShape->impl<TopoDS_Shape>();
476 aBuilder.Add(aComp, aTShape);
477 ModuleBase_ViewerPrsPtr aValue (new ModuleBase_ViewerPrs(aCurRes, aSubShape));
478 myValues.append(aValue);
481 if (myValues.size() > 0)
482 updatePreview(aComp);
483 updateNumberSelected();
484 updateObject(myFeature);
485 onShowOnly(myShowBtn->isChecked());
488 void ModuleBase_WidgetSelectionFilter::updatePreview(const TopoDS_Shape& theShape)
490 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
494 if (myPreview.IsNull()) {
495 myPreview = new AIS_Shape(theShape);
496 myPreview->SetDisplayMode(AIS_Shaded);
497 myPreview->SetColor(Quantity_NOC_BLUE1);
498 Handle(Prs3d_Drawer) aDrawer = myPreview->Attributes();
499 if (aDrawer->HasOwnPointAspect()) {
500 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
501 aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
502 aDrawer->PointAspect()->SetScale(2.);
505 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2.));
506 myPreview->SetTransparency();
507 aCtx->Display(myPreview, true);
508 aCtx->Deactivate(myPreview);
511 myPreview->Set(theShape);
512 aCtx->Redisplay(myPreview, true);
517 void ModuleBase_WidgetSelectionFilter::onShowOnly(bool theShow)
519 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
521 AIS_ListOfInteractive aList;
522 aCtx->DisplayedObjects(AIS_KOI_Shape, -1, aList);
523 if (!myPreview.IsNull())
524 aList.Remove(myPreview);
525 if (aList.Size() > 0)
528 AIS_ListOfInteractive::const_iterator aIt;
529 Handle(AIS_Shape) aShapeIO;
530 bool isModified = false;
531 for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
532 aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
533 if (!aShapeIO.IsNull()) {
535 if (aCtx->IsDisplayed(aShapeIO)) {
536 aCtx->Erase(aShapeIO, false);
541 if (!aCtx->IsDisplayed(aShapeIO)) {
542 aCtx->Display(aShapeIO, false);
543 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
544 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
545 myWorkshop->applyCurrentSelectionModes(anAISObj);
552 myWorkshop->viewer()->update();
555 void ModuleBase_WidgetSelectionFilter::updateSelectBtn()
557 FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
558 mySelectBtn->setEnabled(aFiltersFeature.get() && (aFiltersFeature->filters().size() > 0));
561 void ModuleBase_WidgetSelectionFilter::updateNumberSelected()
563 int aNb = myValues.size();
564 myNbLbl->setText(QString::number(aNb));
566 myFeature->setError(translate("Selection is empty").toStdString(), false, false);
567 myShowBtn->setChecked(false);
569 myShowBtn->setEnabled(false);
572 myFeature->setError("", false, false);
573 myFeature->data()->execState(ModelAPI_StateDone);
574 myShowBtn->setEnabled(true);
578 QList<QWidget*> ModuleBase_WidgetSelectionFilter::getControls() const
580 QList<QWidget*> aWidgets;
581 aWidgets.append(myFiltersCombo);
585 void ModuleBase_WidgetSelectionFilter::clearCurrentSelection(bool toUpdate)
588 if (!myPreview.IsNull()) {
589 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
590 aCtx->Remove(myPreview, toUpdate);
595 void replaceSubShapesByResult(QList<ModuleBase_ViewerPrsPtr>& theResults, int theShapeType)
597 QMap<ObjectPtr, QList<GeomShapePtr>> myResShapes;
598 // Sort sub-shapes by result
599 foreach (ModuleBase_ViewerPrsPtr aPrs, theResults) {
600 if (myResShapes.contains(aPrs->object()))
601 myResShapes[aPrs->object()].append(aPrs->shape());
603 QList<GeomShapePtr> aShapes;
604 aShapes << aPrs->shape();
605 myResShapes[aPrs->object()] = aShapes;
608 // Find Results to replace by whole result
609 QList<GeomShapePtr> aShapes;
610 QList<ObjectPtr> aToReplace;
611 std::list<GeomShapePtr> aSubShapes;
612 foreach(ObjectPtr aObj, myResShapes.keys()) {
613 aShapes = myResShapes[aObj];
614 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
615 TopTools_MapOfShape aShapesMap;
617 GeomShapePtr aSubShape = aRes->shape();
618 const TopoDS_Shape& aShape = aSubShape->impl<TopoDS_Shape>();
619 for (TopExp_Explorer anExp(aShape, (TopAbs_ShapeEnum)theShapeType);
620 anExp.More(); anExp.Next()) {
621 aShapesMap.Add(anExp.Current());
624 if (aShapes.count() == aShapesMap.Size())
625 aToReplace.append(aObj);
627 // Replace the found results
628 QList<ModuleBase_ViewerPrsPtr>::iterator aIt;
629 foreach(ObjectPtr aObj, aToReplace) {
630 for (aIt = theResults.begin(); aIt != theResults.end(); aIt++) {
631 if ((*aIt)->object() == aObj) {
632 theResults.removeAll(*aIt);
636 ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj));
637 theResults.append(aValue);
641 void ModuleBase_WidgetSelectionFilter::onFeatureAccepted()
643 AttributePtr aAttr = mySelectorFeature->attribute(mySelectorAttribute);
644 AttributeSelectionListPtr aSelListAttr =
645 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
646 aSelListAttr->clear();
647 if (aSelListAttr->isWholeResultAllowed())
648 replaceSubShapesByResult(myValues, selectionType(aSelListAttr->selectionType().c_str()));
649 foreach(ModuleBase_ViewerPrsPtr aPrs, myValues) {
650 aSelListAttr->append(aPrs->object(), aPrs->shape());
654 bool ModuleBase_WidgetSelectionFilter::storeValueCustom()
656 ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget();
658 return aActive->storeValue();
659 updateObject(myFeature);
663 QList<ModuleBase_FilterItem*> ModuleBase_WidgetSelectionFilter::itemsList() const
665 return myFiltersWgt->findChildren<ModuleBase_FilterItem*>();
669 bool ModuleBase_WidgetSelectionFilter::restoreValueCustom()
671 ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
672 FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
674 // Init filters member of the parent attribute
675 AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
676 if (aAttrList->filters() != aFiltersFeature) {
677 aAttrList->setFilters(aFiltersFeature);
680 QList<ModuleBase_FilterItem*> aItemsList = itemsList();
681 std::list<std::string> aFilters = aFiltersFeature->filters();
683 std::list<std::string>::const_iterator aIt;
685 int aNbItems = aItemsList.size();
686 ModuleBase_FilterItem* aItem = 0;
687 bool isBlocked = myFiltersCombo->blockSignals(true);
688 for (aIt = aFilters.cbegin(); aIt != aFilters.cend(); aIt++, i++) {
689 std::string aStr = (*aIt);
692 aItem = onAddFilter(aStr);
693 FilterPtr aFilterObj = aFactory->filter(aStr);
694 int aId = myFiltersCombo->findText(aFilterObj->name().c_str());
695 if ((aId != -1) && !aFilterObj->isMultiple())
696 myFiltersCombo->removeItem(aId);
698 QList<ModuleBase_ModelWidget*> aSubList = aItem->widgets();
699 foreach(ModuleBase_ModelWidget* aWgt, aSubList) {
700 aWgt->restoreValue();
705 myFiltersCombo->setCurrentIndex(0);
706 myFiltersCombo->blockSignals(isBlocked);
710 QString ModuleBase_WidgetSelectionFilter::getError(const bool theValueStateChecked) const
712 QString aErrorMsg = ModuleBase_ModelWidget::getError(theValueStateChecked);
713 if (aErrorMsg.isEmpty()) {
714 if (myValues.size() == 0)
715 aErrorMsg = translate("Selection is empty");
720 void ModuleBase_WidgetSelectionFilter::onObjectUpdated()
722 myShowBtn->setChecked(false);
723 clearCurrentSelection(true);
724 updateNumberSelected();
726 QList<ModuleBase_FilterItem*> aItemsList = itemsList();
727 foreach(ModuleBase_FilterItem* aItem, aItemsList) {
728 QList<ModuleBase_ModelWidget*> aWidgetsList = aItem->widgets();
729 foreach(ModuleBase_ModelWidget* aWidget, aWidgetsList) {
730 if (!aWidget->feature().get())
731 aWidget->setFeature(myFeature);
732 aWidget->restoreValue();
735 updateObject(myFeature);
737 // Redisplay the feature on order to Customize presentations from filters with selectors
738 static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
739 ModelAPI_EventCreator::get()->sendUpdated(myFeature, EVENT_DISP);
740 Events_Loop::loop()->flush(EVENT_DISP);
743 void ModuleBase_WidgetSelectionFilter::storeFilters(const std::list<FilterPtr>& theFilters)
745 for (std::list<FilterPtr>::const_iterator anIt = theFilters.begin();
746 anIt != theFilters.end(); ++anIt) {
747 std::string aName = translate((*anIt)->name()).toStdString();
748 myFilters[aName] = *anIt;
752 QString ModuleBase_WidgetSelectionFilter::translate(const std::string& theString) const
754 return ModuleBase_Tools::translate(myFeatureId, theString);