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>
17 #include <ModelAPI_Attribute.h>
19 #include <SelectMgr_ListOfFilter.hxx>
24 class ModuleBase_IWorkshop;
25 class ModuleBase_ISelection;
26 class ModuleBase_WidgetSelectorStore;
27 class ModelAPI_Validator;
28 class Config_WidgetAPI;
29 class Handle_SelectMgr_EntityOwner;
33 * Implementation of widget with validators and filters processing.
35 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
40 /// \param theParent the parent object
41 /// \param theWorkshop a reference to workshop
42 /// \param theData the widget configuation. The attribute of the model widget is obtained from
43 ModuleBase_WidgetValidated(QWidget* theParent,
44 ModuleBase_IWorkshop* theWorkshop,
45 const Config_WidgetAPI* theData);
46 virtual ~ModuleBase_WidgetValidated();
48 /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
49 /// next, the attribute's validating. It trying on the give selection to current attribute by
50 /// setting the value inside and calling validators. After this, the previous attribute value is
51 /// restored.The valid/invalid value is cashed.
52 /// \param theValue a selected presentation in the view
53 /// \return a boolean value
54 virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
56 //! Returns data object by AIS
57 ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
59 //! Clear all validated cash in the widget
60 void clearValidatedCash();
63 /// Checks whether all active viewer filters validate the presentation
64 /// \param thePrs a selected presentation in the view
65 /// \return a boolean value
66 bool isValidInFilters(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
68 /// Checks all attribute validators returns valid. It tries on the given selection
69 /// to current attribute by setting the value inside and calling validators. After this,
70 /// the previous attribute value is restored.The valid/invalid value is cashed.
71 /// \param theValue a selected presentation in the view
72 /// \return a boolean value
73 bool isValidSelectionForAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
74 const AttributePtr& theAttribute);
76 /// Retunrs attribute, which should be validated. In default implementation,
77 /// this is an attribute of ID
78 /// \return an attribute
79 virtual AttributePtr attribute() const;
81 /// Creates a backup of the current values of the attribute
82 /// It should be realized in the specific widget because of different
83 /// parameters of the current attribute
84 /// \param theAttribute an attribute to be stored
85 virtual void storeAttributeValue(const AttributePtr& theAttribute);
87 /// Creates a backup of the current values of the attribute
88 /// It should be realized in the specific widget because of different
89 /// parameters of the current attribute
90 /// \param theAttribute an attribute to be restored
91 /// \param theValid a boolean flag, if restore happens for valid parameters
92 virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
94 /// Checks the widget validity. By default, it returns true.
95 /// \param thePrs a selected presentation in the view
96 /// \return a boolean value
97 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
99 /// Fills the attribute with the value of the selected owner
100 /// \param thePrs a selected owner
101 virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs) = 0;
103 /// Returns a list of selected presentations in the viewer and object browser
104 /// The presentations from the object browser are filtered by the AIS context filters
105 /// \return a list of presentations
106 QList<std::shared_ptr<ModuleBase_ViewerPrs>> getFilteredSelected();
108 /// It obtains selection filters from the workshop and activates them in the active viewer
109 /// \param toActivate a flag about activation or deactivation the filters
110 /// \return true if the selection filter of the widget is activated in viewer context
111 bool activateFilters(const bool toActivate);
113 /// Block the model flush of update and intialization of attribute
114 /// \param theAttribute an attribute of blocking
115 /// \param theToBlock flag whether the model is blocked or unblocked
116 /// \param isActive out value if model is blocked, in value if model is unblocked
117 /// to be used to restore flush state when unblocked
118 /// \param isAttributeSetInitializedBlocked out value if model is blocked
119 /// in value if model is unblocked to be used to restore previous state when unblocked
120 virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
121 bool& isFlushesActived, bool& isAttributeSetInitializedBlocked);
124 /// Checks the current attibute in all attribute validators
125 /// \param theAttribute an attribute to be validated
126 /// \return true if all validators return that the attribute is valid
127 bool isValidAttribute(const AttributePtr& theAttribute) const;
129 /// Returns true if the workshop validator filter has been already activated
130 /// \return boolean value
131 bool isFilterActivated() const;
134 /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
135 /// \param theValue a viewer presentation
136 /// \param theValid a valid state
137 bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
139 /// Store the validity state of the presentation in an internal map
140 /// \param theValue a viewer presentation
141 /// \param theValid a valid state
142 void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
145 /// Applies AIS context filters to the parameter list. The not approved presentations are
146 /// removed from the parameters.
147 /// \param theValues a list of presentations.
148 void filterPresentations(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
150 /// Remove subshapes of compsolids if whole compsolid is present.
151 /// \param theValues a list of presentations.
152 void filterCompSolids(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
155 /// Reference to workshop
156 ModuleBase_IWorkshop* myWorkshop;
157 /// The widget is in validation mode: store is performed, restore is not
161 ObjectPtr myPresentedObject; /// back up of the filtered object
162 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs; /// cash of valid selection presentations
163 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs; /// cash of invalid selection presentations
165 /// store to backup parameters of the model
166 ModuleBase_WidgetSelectorStore* myAttributeStore;
169 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */