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;
33 //#define LIST_OF_VALID_PRS
37 * Implementation of widget with validators and filters processing.
39 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
44 /// \param theParent the parent object
45 /// \param theWorkshop a reference to workshop
46 /// \param theData the widget configuation. The attribute of the model widget is obtained from
47 ModuleBase_WidgetValidated(QWidget* theParent,
48 ModuleBase_IWorkshop* theWorkshop,
49 const Config_WidgetAPI* theData);
50 virtual ~ModuleBase_WidgetValidated();
52 /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
53 /// next, the attribute's validating. It trying on the give selection to current attribute by
54 /// setting the value inside and calling validators. After this, the previous attribute value is
55 /// restored.The valid/invalid value is cashed.
56 /// \param theValue a selected presentation in the view
57 /// \return a boolean value
58 virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
60 //! Returns data object by AIS
61 ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
63 //! Clear all validated cash in the widget
64 void clearValidatedCash();
66 /// Returns true if the workshop validator filter has been already activated
67 /// \return boolean value
68 bool isFilterActivated() const;
70 /// Block the model flush of update and intialization of attribute
71 /// \param theAttribute an attribute of blocking
72 /// \param theFeature a feature
73 /// \param theToBlock flag whether the model is blocked or unblocked
74 /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
75 /// to be used to restore flush state when unblocked
76 /// \param isAttributeSetInitializedBlocked out value if model is blocked
77 /// in value if model is unblocked to be used to restore previous state when unblocked
78 /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
79 static void blockFeatureAttribute(const AttributePtr& theAttribute,
80 const FeaturePtr& theFeature,
81 const bool& theToBlock,
82 bool& isFlushesActived,
83 bool& isAttributeSetInitializedBlocked,
84 bool& isAttributeSendUpdatedBlocked);
86 /// Checks the current attibute in all attribute validators
87 /// \param theAttribute an attribute to be validated
88 /// \return true if all validators return that the attribute is valid
89 static bool isValidAttribute(const AttributePtr& theAttribute);
92 /// Checks whether all active viewer filters validate the presentation
93 /// \param thePrs a selected presentation in the view
94 /// \return a boolean value
95 virtual bool isValidInFilters(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
97 /// Checks all attribute validators returns valid. It tries on the given selection
98 /// to current attribute by setting the value inside and calling validators. After this,
99 /// the previous attribute value is restored.The valid/invalid value is cashed.
100 /// \param theValue a selected presentation in the view
101 /// \param theAttribute the attribute
102 /// \return a boolean value
103 bool isValidSelectionForAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
104 const AttributePtr& theAttribute);
106 /// Retunrs attribute, which should be validated. In default implementation,
107 /// this is an attribute of ID
108 /// \return an attribute
109 virtual AttributePtr attribute() const;
111 /// Creates a backup of the current values of the attribute
112 /// It should be realized in the specific widget because of different
113 /// parameters of the current attribute
114 /// \param theAttribute an attribute to be stored
115 virtual void storeAttributeValue(const AttributePtr& theAttribute);
117 /// Creates a backup of the current values of the attribute
118 /// It should be realized in the specific widget because of different
119 /// parameters of the current attribute
120 /// \param theAttribute an attribute to be restored
121 /// \param theValid a boolean flag, if restore happens for valid parameters
122 virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
124 /// Checks the widget validity. By default, it returns true.
125 /// \param thePrs a selected presentation in the view
126 /// \return a boolean value
127 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
129 /// Fills the attribute with the value of the selected owner
130 /// \param thePrs a selected owner
131 virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs) = 0;
133 /// Returns a list of selected presentations in the viewer and object browser
134 /// The presentations from the object browser are filtered by the AIS context filters
135 /// \return a list of presentations
136 QList<std::shared_ptr<ModuleBase_ViewerPrs>> getFilteredSelected();
138 /// It obtains selection filters from the workshop and activates them in the active viewer
139 /// \param toActivate a flag about activation or deactivation the filters
140 /// \return true if the selection filter of the widget is activated in viewer context
141 bool activateFilters(const bool toActivate);
143 /// Block the model flush of update and intialization of attribute
144 /// \param theAttribute an attribute of blocking
145 /// \param theToBlock flag whether the model is blocked or unblocked
146 /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
147 /// to be used to restore flush state when unblocked
148 /// \param isAttributeSetInitializedBlocked out value if model is blocked
149 /// in value if model is unblocked to be used to restore previous state when unblocked
150 /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
151 virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
152 bool& isFlushesActived, bool& isAttributeSetInitializedBlocked,
153 bool& isAttributeSendUpdatedBlocked);
156 /// Gets the validity state of the presentation in an internal map.
157 /// Returns true if the valid state of value is stored
158 /// \param theValue a viewer presentation
159 /// \param theValid a valid state
160 bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
162 /// Store the validity state of the presentation in an internal map
163 /// \param theValue a viewer presentation
164 /// \param theValid a valid state
165 void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
168 /// Applies AIS context filters to the parameter list. The not approved presentations are
169 /// removed from the parameters.
170 /// \param theValues a list of presentations.
171 void filterPresentations(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
173 /// Remove subshapes of compsolids if whole compsolid is present.
174 /// \param theValues a list of presentations.
175 void filterCompSolids(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
178 /// Reference to workshop
179 ModuleBase_IWorkshop* myWorkshop;
180 /// The widget is in validation mode: store is performed, restore is not
184 ObjectPtr myPresentedObject; /// back up of the filtered object
185 #ifdef LIST_OF_VALID_PRS
186 /// cash of valid selection presentations
187 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
189 /// cash of invalid selection presentations
190 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
192 // assume that one presentation selection presentation corresponds only one shape
193 NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myValidPrs;
194 NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myInvalidPrs;
197 /// store to backup parameters of the model
198 ModuleBase_WidgetSelectorStore* myAttributeStore;
201 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */