1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include <ModuleBase_WidgetValidator.h>
5 #include <ModuleBase_ModelWidget.h>
6 #include <ModuleBase_ViewerPrs.h>
7 #include <ModuleBase_IViewer.h>
8 #include <ModuleBase_IWorkshop.h>
10 ModuleBase_WidgetValidator::ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget,
11 ModuleBase_IWorkshop* theWorkshop)
12 : myModelWidget(theModelWidget), myWorkshop(theWorkshop)
16 ModuleBase_WidgetValidator::~ModuleBase_WidgetValidator()
20 //********************************************************************
21 bool ModuleBase_WidgetValidator::isValidSelection(const ModuleBase_ViewerPrsPtr& theValue)
24 if (getValidState(theValue, aValid))
27 aValid = myModelWidget->isValidSelectionCustom(theValue);
29 storeValidState(theValue, aValid);
33 bool ModuleBase_WidgetValidator::activateFilters(const bool toActivate)
35 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
37 Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
38 bool aHasSelectionFilter = aViewer->hasSelectionFilter(aSelFilter);
41 aViewer->addSelectionFilter(aSelFilter);
43 aViewer->removeSelectionFilter(aSelFilter);
47 return aHasSelectionFilter;
50 bool ModuleBase_WidgetValidator::isFilterActivated() const
52 bool isActivated = false;
54 Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
55 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
57 return aViewer->hasSelectionFilter(aSelFilter);
60 void ModuleBase_WidgetValidator::clearValidatedCash()
66 bool ModuleBase_WidgetValidator::getValidState(const ModuleBase_ViewerPrsPtr& theValue, bool& theValid)
68 bool aValidPrs = myValidPrs.contains(theValue);
69 bool anInvalidPrs = myInvalidPrs.contains(theValue);
73 else if (anInvalidPrs)
76 return aValidPrs || anInvalidPrs;
79 //********************************************************************
80 void ModuleBase_WidgetValidator::storeValidState(const ModuleBase_ViewerPrsPtr& theValue, const bool theValid)
82 bool aValidPrs = myInvalidPrs.contains(theValue);
83 bool anInvalidPrs = myInvalidPrs.contains(theValue);
87 myValidPrs.append(theValue);
88 // the commented code will be useful when the valid state of the presentation
89 // will be changable between activate/deactivate. Currently it does not happen.
91 // myInvalidPrs.removeOne(theValue);
95 myInvalidPrs.append(theValue);
97 // myValidPrs.removeOne(theValue);
99 #ifdef DEBUG_VALID_STATE
100 qDebug(QString("storeValidState: myValidPrs.size() = %1, myInvalidPrs.size() = %2").arg(myValidPrs.count())
101 .arg(myInvalidPrs.count()).toStdString().c_str());