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());
266 myFilters.push_back(aSession->filters()->id(*aIt));
268 myFiltersCombo->addItems(aItems);
269 connect(myFiltersCombo, SIGNAL(currentIndexChanged(int)), SLOT(onAddFilter(int)));
271 aGroupLayout->addWidget(myFiltersCombo);
272 aMainLayout->addWidget(aFiltersGroup);
275 QWidget* aBtnWgt = new QWidget(this);
276 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnWgt);
277 ModuleBase_Tools::adjustMargins(aBtnLayout);
279 aBtnLayout->addStretch(1);
281 mySelectBtn = new QPushButton(tr("Select"), aBtnWgt);
282 connect(mySelectBtn, SIGNAL(clicked()), SLOT(onSelect()));
283 aBtnLayout->addWidget(mySelectBtn);
285 aMainLayout->addWidget(aBtnWgt);
288 QWidget* aLblWgt = new QWidget(this);
289 QHBoxLayout* aLblLayout = new QHBoxLayout(aLblWgt);
290 ModuleBase_Tools::zeroMargins(aLblLayout);
292 aLblLayout->addWidget(new QLabel(tr("Number of selected objects:"), aLblWgt));
294 myNbLbl = new QLabel("0", aLblWgt);
295 aLblLayout->addWidget(myNbLbl);
298 myShowBtn = new QCheckBox(tr("Show only"), this);
299 connect(myShowBtn, SIGNAL(toggled(bool)), SLOT(onShowOnly(bool)));
300 aLblLayout->addWidget(myShowBtn);
302 aMainLayout->addWidget(aLblWgt);
304 aMainLayout->addStretch(1);
308 myFiltersCombo->hide();
315 ModuleBase_WidgetSelectionFilter::~ModuleBase_WidgetSelectionFilter()
318 if (!myPreview.IsNull()) {
319 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
320 aCtx->Remove(myPreview, false);
322 if (myListIO.Size() > 0) {
323 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
324 AIS_ListOfInteractive::const_iterator aIt;
325 Handle(AIS_Shape) aShapeIO;
326 for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
327 aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
328 if (!aShapeIO.IsNull()) {
329 aCtx->Display(aShapeIO, false);
330 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
331 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
332 myWorkshop->applyCurrentSelectionModes(anAISObj);
336 myShowBtn->setChecked(false);
338 myWorkshop->viewer()->update();
340 SelectorFeature = FeaturePtr();
344 void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex)
349 std::list<std::string>::iterator aIt;
352 for (aIt = myFilters.begin(), i = 0; aIt != myFilters.cend(); i++, aIt++) {
353 if (i == (theIndex - 1)) {
358 ModuleBase_FilterItem* aItem = onAddFilter(aFilter);
359 FiltersFeaturePtr aFiltersFeature =
360 std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
361 aFiltersFeature->addFilter(aFilter);
363 myFiltersCombo->setCurrentIndex(0);
364 myFiltersCombo->removeItem(theIndex);
365 updateObject(myFeature);
367 if (aItem && (aItem->widgets().size() > 0))
368 aItem->widgets().first()->emitFocusInWidget();
373 ModuleBase_FilterItem* ModuleBase_WidgetSelectionFilter::onAddFilter(const std::string& theFilter)
375 if (theFilter.length() == 0)
377 std::list<std::string>::const_iterator aIt;
378 for (aIt = myUseFilters.cbegin(); aIt != myUseFilters.cend(); aIt++) {
379 if (theFilter == (*aIt))
382 myFilters.remove(theFilter);
383 myUseFilters.push_back(theFilter);
384 ModuleBase_FilterItem* aItem = new ModuleBase_FilterItem(theFilter, this);
385 connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)),
386 SLOT(onDeleteItem(ModuleBase_FilterItem*)));
387 connect(aItem, SIGNAL(reversedItem(ModuleBase_FilterItem*)),
388 SLOT(onReverseItem(ModuleBase_FilterItem*)));
389 myFiltersLayout->addWidget(aItem);
392 clearCurrentSelection(true);
393 updateNumberSelected();
397 void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theItem)
399 std::string aFilter = theItem->filter();
400 QList<ModuleBase_ModelWidget*> aWidgets = theItem->widgets();
401 foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
404 myFiltersLayout->removeWidget(theItem);
405 theItem->deleteLater();
407 myUseFilters.remove(aFilter);
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 if (myUseFilters.size() == 0)
446 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
450 clearCurrentSelection();
452 BRep_Builder aBuilder;
453 TopoDS_Compound aComp;
454 aBuilder.MakeCompound(aComp);
456 DocumentPtr aDoc = myFeature->document();
457 int aNb = aDoc->size(ModelAPI_ResultBody::group());
461 for (int i = 0; i < aNb; i++) {
462 aObj = aDoc->object(ModelAPI_ResultBody::group(), i);
463 aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
464 GeomShapePtr aShape = aBody->shape();
465 std::list<GeomShapePtr> aSubShapes =
466 aShape->subShapes((GeomAPI_Shape::ShapeType)mySelectionType);
467 TopTools_MapOfShape alreadyThere;
468 std::list<GeomShapePtr>::const_iterator aShapesIt;
469 for (aShapesIt = aSubShapes.cbegin(); aShapesIt != aSubShapes.cend(); aShapesIt++) {
470 GeomShapePtr aShape = (*aShapesIt);
471 TopoDS_Shape aTShape = aShape->impl<TopoDS_Shape>();
472 if (!alreadyThere.Add(aTShape))
474 static SessionPtr aSession = ModelAPI_Session::get();
475 bool isValid = aSession->filters()->isValid(myFeature, aBody, aShape);
477 aBuilder.Add(aComp, aTShape);
478 ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aShape));
479 myValues.append(aValue);
484 if (myValues.size() > 0)
485 updatePreview(aComp);
486 updateNumberSelected();
487 updateObject(myFeature);
488 onShowOnly(myShowBtn->isChecked());
491 void ModuleBase_WidgetSelectionFilter::updatePreview(const TopoDS_Shape& theShape)
493 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
497 if (myPreview.IsNull()) {
498 myPreview = new AIS_Shape(theShape);
499 myPreview->SetDisplayMode(AIS_Shaded);
500 myPreview->SetColor(Quantity_NOC_BLUE1);
501 Handle(Prs3d_Drawer) aDrawer = myPreview->Attributes();
502 if (aDrawer->HasOwnPointAspect()) {
503 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
504 aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
505 aDrawer->PointAspect()->SetScale(2.);
508 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2.));
509 myPreview->SetTransparency();
510 aCtx->Display(myPreview, true);
511 aCtx->Deactivate(myPreview);
514 myPreview->Set(theShape);
515 aCtx->Redisplay(myPreview, true);
520 void ModuleBase_WidgetSelectionFilter::onShowOnly(bool theShow)
522 if (myPreview.IsNull())
524 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
527 AIS_ListOfInteractive aList;
528 aCtx->DisplayedObjects(AIS_KOI_Shape, -1, aList);
529 aList.Remove(myPreview);
530 if (aList.Size() > 0)
533 AIS_ListOfInteractive::const_iterator aIt;
534 Handle(AIS_Shape) aShapeIO;
535 for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) {
536 aShapeIO = Handle(AIS_Shape)::DownCast(*aIt);
537 if (!aShapeIO.IsNull()) {
539 aCtx->Erase(aShapeIO, false);
541 aCtx->Display(aShapeIO, false);
542 std::shared_ptr<GeomAPI_AISObject> anAISObj = AISObjectPtr(new GeomAPI_AISObject());
543 anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO));
544 myWorkshop->applyCurrentSelectionModes(anAISObj);
548 myWorkshop->viewer()->update();
551 void ModuleBase_WidgetSelectionFilter::updateSelectBtn()
553 mySelectBtn->setEnabled(myUseFilters.size() > 0);
556 void ModuleBase_WidgetSelectionFilter::updateNumberSelected()
558 int aNb = myValues.size();
559 myNbLbl->setText(QString::number(aNb));
560 //QString aErr = () ? tr("Selection is empty") : "";
562 myFeature->setError(tr("Selection is empty").toStdString(), false, false);
564 myFeature->setError("", false, false);
565 myFeature->data()->execState(ModelAPI_StateDone);
569 QList<QWidget*> ModuleBase_WidgetSelectionFilter::getControls() const
571 QList<QWidget*> aWidgets;
572 aWidgets.append(myFiltersCombo);
576 void ModuleBase_WidgetSelectionFilter::clearCurrentSelection(bool toUpdate)
579 if (!myPreview.IsNull()) {
580 Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext();
581 aCtx->Remove(myPreview, toUpdate);
586 void replaceSubShapesByResult(QList<ModuleBase_ViewerPrsPtr>& theResults, int theShapeType)
588 QMap<ObjectPtr, QList<GeomShapePtr>> myResShapes;
589 // Sort sub-shapes by result
590 foreach (ModuleBase_ViewerPrsPtr aPrs, theResults) {
591 if (myResShapes.contains(aPrs->object()))
592 myResShapes[aPrs->object()].append(aPrs->shape());
594 QList<GeomShapePtr> aShapes;
595 aShapes << aPrs->shape();
596 myResShapes[aPrs->object()] = aShapes;
599 // Find Results to replace by whole result
600 QList<GeomShapePtr> aShapes;
601 QList<ObjectPtr> aToReplace;
602 std::list<GeomShapePtr> aSubShapes;
603 foreach(ObjectPtr aObj, myResShapes.keys()) {
604 aShapes = myResShapes[aObj];
605 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
606 TopTools_MapOfShape aShapesMap;
608 GeomShapePtr aSubShape = aRes->shape();
609 const TopoDS_Shape& aShape = aSubShape->impl<TopoDS_Shape>();
610 for (TopExp_Explorer anExp(aShape, (TopAbs_ShapeEnum)theShapeType);
611 anExp.More(); anExp.Next()) {
612 aShapesMap.Add(anExp.Current());
615 if (aShapes.count() == aShapesMap.Size())
616 aToReplace.append(aObj);
618 // Replace the found results
619 QList<ModuleBase_ViewerPrsPtr>::iterator aIt;
620 foreach(ObjectPtr aObj, aToReplace) {
621 for (aIt = theResults.begin(); aIt != theResults.end(); aIt++) {
622 if ((*aIt)->object() == aObj) {
623 theResults.removeAll(*aIt);
627 ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj));
628 theResults.append(aValue);
632 void ModuleBase_WidgetSelectionFilter::onFeatureAccepted()
634 AttributePtr aAttr = mySelectorFeature->attribute(mySelectorAttribute);
635 AttributeSelectionListPtr aSelListAttr =
636 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
637 aSelListAttr->clear();
638 if (aSelListAttr->isWholeResultAllowed())
639 replaceSubShapesByResult(myValues, selectionType(aSelListAttr->selectionType().c_str()));
640 foreach(ModuleBase_ViewerPrsPtr aPrs, myValues) {
641 aSelListAttr->append(aPrs->object(), aPrs->shape());
645 bool ModuleBase_WidgetSelectionFilter::storeValueCustom()
647 ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget();
649 return aActive->storeValue();
650 updateObject(myFeature);
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 std::list<std::string> aFilters = aFiltersFeature->filters();
666 std::list<std::string>::const_iterator aIt;
667 for (aIt = aFilters.cbegin(); aIt != aFilters.cend(); aIt++) {
668 std::string aStr = (*aIt);
669 ModuleBase_FilterItem* aItem = onAddFilter(aStr);
670 FilterPtr aFilterObj = aFactory->filter(aStr);
671 int aId = myFiltersCombo->findText(aFilterObj->name().c_str());
673 myFiltersCombo->removeItem(aId);
676 QList<ModuleBase_ModelWidget*> aSubList = aItem->widgets();
677 foreach(ModuleBase_ModelWidget* aWgt, aSubList) {
678 aWgt->restoreValue();
685 QString ModuleBase_WidgetSelectionFilter::getError(const bool theValueStateChecked) const
687 QString aErrorMsg = ModuleBase_ModelWidget::getError(theValueStateChecked);
688 if (aErrorMsg.isEmpty()) {
689 if (myValues.size() == 0)
690 aErrorMsg = tr("Selection is empty");
695 void ModuleBase_WidgetSelectionFilter::onObjectUpdated()
697 myShowBtn->setChecked(false);
698 clearCurrentSelection(true);
699 updateNumberSelected();
701 QList<ModuleBase_FilterItem*> aItemsList = myFiltersWgt->findChildren<ModuleBase_FilterItem*>();
702 foreach(ModuleBase_FilterItem* aItem, aItemsList) {
703 QList<ModuleBase_ModelWidget*> aWidgetsList = aItem->widgets();
704 foreach(ModuleBase_ModelWidget* aWidget, aWidgetsList) {
705 if (!aWidget->feature().get())
706 aWidget->setFeature(myFeature);
707 aWidget->restoreValue();
710 updateObject(myFeature);
712 // Redisplay the feature on order to Customize presentations from filters with selectors
713 static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
714 ModelAPI_EventCreator::get()->sendUpdated(myFeature, EVENT_DISP);
715 Events_Loop::loop()->flush(EVENT_DISP);