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>
14 #include <Events_Loop.h>
18 ModuleBase_WidgetValidated::ModuleBase_WidgetValidated(QWidget* theParent,
19 const Config_WidgetAPI* theData,
20 const std::string& theParentId)
21 : ModuleBase_ModelWidget(theParent, theData, theParentId)
25 ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated()
29 //********************************************************************
30 bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue)
34 Handle(SelectMgr_EntityOwner) anOwner = theValue.owner();
35 if (isValid(anOwner)) {
36 isDone = setSelection(anOwner);
37 updateObject(myFeature);
43 //********************************************************************
44 bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& theOwner)
46 DataPtr aData = myFeature->data();
47 AttributePtr anAttribute = myFeature->attribute(attributeID());
49 // stores the current values of the widget attribute
50 Events_Loop* aLoop = Events_Loop::loop();
51 // blocks the flush signals to avoid the temporary objects visualization in the viewer
52 // they should not be shown in order to do not lose highlight by erasing them
53 aLoop->activateFlushes(false);
55 aData->blockSendAttributeUpdated(true);
56 bool isAttributeBlocked = anAttribute->blockSetInitialized(true);
57 storeAttributeValue();
59 // saves the owner value to the widget attribute
60 bool aValid = setSelection(theOwner);
63 // checks the attribute validity
64 aValid = isValidAttribute();
66 // restores the current values of the widget attribute
67 restoreAttributeValue(aValid);
68 aData->blockSendAttributeUpdated(false);
69 anAttribute->blockSetInitialized(isAttributeBlocked);
70 aLoop->activateFlushes(true);
75 //********************************************************************
76 bool ModuleBase_WidgetValidated::isValidAttribute() const
78 SessionPtr aMgr = ModelAPI_Session::get();
79 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
80 std::list<ModelAPI_Validator*> aValidators;
81 std::list<std::list<std::string> > anArguments;
82 aFactory->validators(myFeature->getKind(), attributeID(), aValidators, anArguments);
84 DataPtr aData = myFeature->data();
85 AttributePtr anAttribute = myFeature->attribute(attributeID());
87 std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
88 std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
90 for (; aValidator != aValidators.end() && aValid; aValidator++, aArgs++) {
91 const ModelAPI_AttributeValidator* aAttrValidator =
92 dynamic_cast<const ModelAPI_AttributeValidator*>(*aValidator);
94 aValid = aAttrValidator->isValid(anAttribute, *aArgs);
100 void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop,
101 const bool toActivate) const
103 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
105 Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter();
107 aViewer->addSelectionFilter(aSelFilter);
109 aViewer->removeSelectionFilter(aSelFilter);