1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include <ModuleBase_WidgetValidator.h>
4 #include <ModuleBase_WidgetSelectorStore.h>
5 #include <ModuleBase_WidgetValidated.h>
7 #include <ModuleBase_ModelWidget.h>
8 #include <ModuleBase_ViewerPrs.h>
9 #include <ModuleBase_IViewer.h>
10 #include <ModuleBase_IWorkshop.h>
12 ModuleBase_WidgetValidator::ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget,
13 ModuleBase_IWorkshop* theWorkshop)
14 : myModelWidget(theModelWidget), myWorkshop(theWorkshop), myIsInValidate(false)
16 myAttributeStore = new ModuleBase_WidgetSelectorStore();
19 ModuleBase_WidgetValidator::~ModuleBase_WidgetValidator()
21 delete myAttributeStore;
24 //********************************************************************
25 bool ModuleBase_WidgetValidator::isValidSelection(const ModuleBase_ViewerPrsPtr& theValue)
28 if (getValidState(theValue, aValid))
31 aValid = myModelWidget->isValidSelectionCustom(theValue);
33 storeValidState(theValue, aValid);
37 bool ModuleBase_WidgetValidator::activateFilters(const bool toActivate)
39 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
41 Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
42 bool aHasSelectionFilter = aViewer->hasSelectionFilter(aSelFilter);
45 aViewer->addSelectionFilter(aSelFilter);
47 aViewer->removeSelectionFilter(aSelFilter);
51 return aHasSelectionFilter;
54 void ModuleBase_WidgetValidator::storeAttributeValue(const AttributePtr& theAttribute)
56 myIsInValidate = true;
57 myAttributeStore->storeAttributeValue(theAttribute, myWorkshop);
60 void ModuleBase_WidgetValidator::restoreAttributeValue(const AttributePtr& theAttribute,
63 myIsInValidate = false;
64 myAttributeStore->restoreAttributeValue(theAttribute, myWorkshop);
67 bool ModuleBase_WidgetValidator::isValidAttribute(const AttributePtr& theAttribute) const
69 return ModuleBase_WidgetValidated::isValidAttribute(theAttribute);
72 bool ModuleBase_WidgetValidator::isFilterActivated() const
74 bool isActivated = false;
76 Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
77 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
79 return aViewer->hasSelectionFilter(aSelFilter);
82 void ModuleBase_WidgetValidator::clearValidatedCash()
88 bool ModuleBase_WidgetValidator::getValidState(const ModuleBase_ViewerPrsPtr& theValue,
91 bool aValidPrs = myValidPrs.contains(theValue);
92 bool anInvalidPrs = myInvalidPrs.contains(theValue);
96 else if (anInvalidPrs)
99 return aValidPrs || anInvalidPrs;
102 //********************************************************************
103 void ModuleBase_WidgetValidator::storeValidState(const ModuleBase_ViewerPrsPtr& theValue,
106 bool aValidPrs = myInvalidPrs.contains(theValue);
107 bool anInvalidPrs = myInvalidPrs.contains(theValue);
111 myValidPrs.append(theValue);
112 // the commented code will be useful when the valid state of the presentation
113 // will be changable between activate/deactivate. Currently it does not happen.
115 // myInvalidPrs.removeOne(theValue);
119 myInvalidPrs.append(theValue);
121 // myValidPrs.removeOne(theValue);
123 #ifdef DEBUG_VALID_STATE
124 qDebug(QString("storeValidState: myValidPrs.size() = %1, myInvalidPrs.size() = %2")
125 .arg(myValidPrs.count())
126 .arg(myInvalidPrs.count()).toStdString().c_str());