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