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>
6 #include <ModuleBase_ISelection.h>
8 #include <ModelAPI_Session.h>
9 #include <ModelAPI_Validator.h>
10 #include <ModelAPI_AttributeValidator.h>
11 #include <ModelAPI_Events.h>
13 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
14 #include <SelectMgr_EntityOwner.hxx>
16 #include <Events_Loop.h>
20 ModuleBase_WidgetValidated::ModuleBase_WidgetValidated(QWidget* theParent,
21 const Config_WidgetAPI* theData,
22 const std::string& theParentId)
23 : ModuleBase_ModelWidget(theParent, theData, theParentId)
27 ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated()
31 //********************************************************************
32 bool ModuleBase_WidgetValidated::setSelection(QList<ModuleBase_ViewerPrs>& theValues)
34 if (theValues.empty())
36 // it removes the processed value from the parameters list
37 ModuleBase_ViewerPrs aValue = theValues.takeFirst();
40 if (isValidSelection(aValue)) {
41 isDone = setSelectionCustom(aValue);
42 // updateObject - to update/redisplay feature
43 // it is commented in order to perfom it outside the method
44 //updateObject(myFeature);
46 //emit valuesChanged();
51 //********************************************************************
52 bool ModuleBase_WidgetValidated::isValidSelection(const ModuleBase_ViewerPrs& theValue)
54 bool aValid = isValidSelectionCustom(theValue);
58 DataPtr aData = myFeature->data();
59 AttributePtr anAttribute = myFeature->attribute(attributeID());
61 // stores the current values of the widget attribute
62 Events_Loop* aLoop = Events_Loop::loop();
63 // blocks the flush signals to avoid the temporary objects visualization in the viewer
64 // they should not be shown in order to do not lose highlight by erasing them
65 aLoop->activateFlushes(false);
67 aData->blockSendAttributeUpdated(true);
68 bool isAttributeBlocked = anAttribute->blockSetInitialized(true);
69 storeAttributeValue();
71 // saves the owner value to the widget attribute
72 aValid = setSelectionCustom(theValue);
74 // checks the attribute validity
75 aValid = isValidAttribute();
77 // restores the current values of the widget attribute
78 restoreAttributeValue(aValid);
79 aData->blockSendAttributeUpdated(false);
80 anAttribute->blockSetInitialized(isAttributeBlocked);
81 aLoop->activateFlushes(true);
83 // In particular case the results are deleted and called as redisplayed inside of this
84 // highlight-selection, to they must be flushed as soon as possible.
85 // Example: selection of group-vertices subshapes with shift pressend on body. Without
86 // these 4 lines below the application crashes because of left presentations on
87 // removed results still in the viewer.
88 static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
89 static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
90 aLoop->flush(aDeletedEvent);
91 aLoop->flush(aRedispEvent);
96 //********************************************************************
97 bool ModuleBase_WidgetValidated::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
102 //********************************************************************
103 bool ModuleBase_WidgetValidated::isValidAttribute() const
105 SessionPtr aMgr = ModelAPI_Session::get();
106 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
107 std::list<ModelAPI_Validator*> aValidators;
108 std::list<std::list<std::string> > anArguments;
109 aFactory->validators(myFeature->getKind(), attributeID(), aValidators, anArguments);
111 customValidators(aValidators, anArguments);
113 DataPtr aData = myFeature->data();
114 AttributePtr anAttribute = myFeature->attribute(attributeID());
116 std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
117 std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
119 for (; aValidator != aValidators.end() && aValid; aValidator++, aArgs++) {
120 const ModelAPI_AttributeValidator* aAttrValidator =
121 dynamic_cast<const ModelAPI_AttributeValidator*>(*aValidator);
122 if (aAttrValidator) {
123 aValid = aAttrValidator->isValid(anAttribute, *aArgs);
129 void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop,
130 const bool toActivate) const
132 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
134 Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter();
136 aViewer->addSelectionFilter(aSelFilter);
138 aViewer->removeSelectionFilter(aSelFilter);
141 void ModuleBase_WidgetValidated::customValidators(std::list<ModelAPI_Validator*>& theValidators,
142 std::list<std::list<std::string> >& theArguments) const