1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include <ModuleBase_WidgetValidated.h>
4 #include <ModuleBase_FilterFactory.h>
5 #include <ModuleBase_IViewer.h>
7 #include <ModelAPI_Session.h>
8 #include <ModelAPI_Validator.h>
9 #include <ModelAPI_AttributeValidator.h>
11 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
12 #include <SelectMgr_EntityOwner.hxx>
16 ModuleBase_WidgetValidated::ModuleBase_WidgetValidated(QWidget* theParent,
17 const Config_WidgetAPI* theData,
18 const std::string& theParentId)
19 : ModuleBase_ModelWidget(theParent, theData, theParentId)
23 ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated()
27 //********************************************************************
28 bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue)
32 Handle(SelectMgr_EntityOwner) anOwner = theValue.owner();
33 if (isValid(anOwner)) {
34 setSelection(anOwner);
35 updateObject(myFeature);
41 //********************************************************************
42 bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& theOwner)
44 // stores the current values of the widget attribute
45 backupAttributeValue(true);
47 // saves the owner value to the widget attribute
48 setSelection(theOwner);
50 // checks the attribute validity
51 bool aValid = isValidAttribute();
53 // restores the current values of the widget attribute
54 backupAttributeValue(false);
59 //********************************************************************
60 bool ModuleBase_WidgetValidated::isValidAttribute() const
62 SessionPtr aMgr = ModelAPI_Session::get();
63 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
64 std::list<ModelAPI_Validator*> aValidators;
65 std::list<std::list<std::string> > anArguments;
66 aFactory->validators(myFeature->getKind(), attributeID(), aValidators, anArguments);
68 DataPtr aData = myFeature->data();
69 AttributePtr anAttribute = myFeature->attribute(attributeID());
71 aData->blockSendAttributeUpdated(true);
73 // 3. check the acceptability of the current values
74 std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
75 std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
77 for (; aValidator != aValidators.end() && aValid; aValidator++, aArgs++) {
78 const ModelAPI_AttributeValidator* aAttrValidator =
79 dynamic_cast<const ModelAPI_AttributeValidator*>(*aValidator);
81 aValid = aAttrValidator->isValid(anAttribute, *aArgs);
84 aData->blockSendAttributeUpdated(false);
89 void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop,
90 const bool toActivate) const
92 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
94 Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter();
96 aViewer->addSelectionFilter(aSelFilter);
98 aViewer->removeSelectionFilter(aSelFilter);