1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetValidated.h
4 // Created: 12 Mar 2015
5 // Author: Natalia ERMOLAEVA
8 #ifndef MODULEBASE_WIDGETVALIDATED_H_
9 #define MODULEBASE_WIDGETVALIDATED_H_
11 #include <ModuleBase.h>
12 #include <ModuleBase_ModelWidget.h>
14 #include <GeomAPI_Shape.h>
15 #include <GeomAPI_AISObject.h>
16 #include <ModelAPI_Object.h>
18 #include <SelectMgr_ListOfFilter.hxx>
23 class ModuleBase_IWorkshop;
24 class ModuleBase_ISelection;
25 class ModelAPI_Validator;
26 class Config_WidgetAPI;
27 class Handle_SelectMgr_EntityOwner;
31 * Implementation of widget with validators and filters processing.
33 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
38 /// \param theParent the parent object
39 /// \param theWorkshop a reference to workshop
40 /// \param theData the widget configuation. The attribute of the model widget is obtained from
41 ModuleBase_WidgetValidated(QWidget* theParent,
42 ModuleBase_IWorkshop* theWorkshop,
43 const Config_WidgetAPI* theData);
44 virtual ~ModuleBase_WidgetValidated();
46 /// Checks all widget validator if the owner is valid
47 /// \param theValue a selected presentation in the view
48 /// \return a boolean value
49 bool isValidSelection(const ModuleBase_ViewerPrs& theValue);
51 //! Returns data object by AIS
52 ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
54 //! Clear all validated cash in the widget
55 void clearValidatedCash();
58 /// Checks whether all active viewer filters validate the presentation
59 /// \param thePrs a selected presentation in the view
60 /// \return a boolean value
61 bool isValidInFilters(const ModuleBase_ViewerPrs& thePrs);
63 /// Creates a backup of the current values of the attribute
64 /// It should be realized in the specific widget because of different
65 /// parameters of the current attribute
66 virtual void storeAttributeValue();
68 /// Creates a backup of the current values of the attribute
69 /// It should be realized in the specific widget because of different
70 /// parameters of the current attribute
71 /// \param theValid a boolean flag, if restore happens for valid parameters
72 virtual void restoreAttributeValue(const bool theValid);
74 /// Checks the widget validity. By default, it returns true.
75 /// \param thePrs a selected presentation in the view
76 /// \return a boolean value
77 virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
79 /// Fills the attribute with the value of the selected owner
80 /// \param thePrs a selected owner
81 virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) = 0;
83 /// Returns a list of selected presentations in the viewer and object browser
84 /// The presentations from the object browser are filtered by the AIS context filters
85 /// \return a list of presentations
86 QList<ModuleBase_ViewerPrs> getFilteredSelected();
88 /// It obtains selection filters from the workshop and activates them in the active viewer
89 /// \param toActivate a flag about activation or deactivation the filters
90 /// \return true if the selection filter of the widget is activated in viewer context
91 bool activateFilters(const bool toActivate);
93 /// Block the model flush of update and intialization of attribute
94 /// \param theToBlock flag whether the model is blocked or unblocked
95 /// \param isActive out value if model is blocked, in value if model is unblocked
96 /// to be used to restore flush state when unblocked
97 /// \param isAttributeSetInitializedBlocked out value if model is blocked
98 /// in value if model is unblocked to be used to restore previous state when unblocked
99 virtual void blockAttribute(const bool& theToBlock, bool& isFlushesActived,
100 bool& isAttributeSetInitializedBlocked);
103 /// Checks the current attibute in all attribute validators
104 // \return true if all validators return that the attribute is valid
105 bool isValidAttribute() const;
107 /// Returns true if the workshop validator filter has been already activated
108 /// \return boolean value
109 bool isFilterActivated() const;
111 /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
112 /// \param theValue a viewer presentation
113 /// \param theValid a valid state
114 bool getValidState(const ModuleBase_ViewerPrs& theValue, bool& theValid);
116 /// Store the validity state of the presentation in an internal map
117 /// \param theValue a viewer presentation
118 /// \param theValid a valid state
119 void storeValidState(const ModuleBase_ViewerPrs& theValue, const bool theValid);
121 /// Applies AIS context filters to the parameter list. The not approved presentations are
122 /// removed from the parameters.
123 /// \param theValues a list of presentations.
124 void filterPresentations(QList<ModuleBase_ViewerPrs>& theValues);
126 /// Remove subshapes of compsolids if whole compsolid is present.
127 /// \param theValues a list of presentations.
128 void filterCompSolids(QList<ModuleBase_ViewerPrs>& theValues);
131 /// Reference to workshop
132 ModuleBase_IWorkshop* myWorkshop;
133 /// The widget is in validation mode: store is performed, restore is not
137 ObjectPtr myPresentedObject; /// back up of the filtered object
138 QList<ModuleBase_ViewerPrs> myValidPrs; /// cash of valid selection presentations
139 QList<ModuleBase_ViewerPrs> myInvalidPrs; /// cash of invalid selection presentations
142 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */