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();
68 /// Checks whether all active viewer filters validate the presentation
69 /// \param thePrs a selected presentation in the view
70 /// \return a boolean value
71 bool isValidInFilters(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
73 /// Checks all attribute validators returns valid. It tries on the given selection
74 /// to current attribute by setting the value inside and calling validators. After this,
75 /// the previous attribute value is restored.The valid/invalid value is cashed.
76 /// \param theValue a selected presentation in the view
77 /// \return a boolean value
78 bool isValidSelectionForAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
79 const AttributePtr& theAttribute);
81 /// Retunrs attribute, which should be validated. In default implementation,
82 /// this is an attribute of ID
83 /// \return an attribute
84 virtual AttributePtr attribute() const;
86 /// Creates a backup of the current values of the attribute
87 /// It should be realized in the specific widget because of different
88 /// parameters of the current attribute
89 /// \param theAttribute an attribute to be stored
90 virtual void storeAttributeValue(const AttributePtr& theAttribute);
92 /// Creates a backup of the current values of the attribute
93 /// It should be realized in the specific widget because of different
94 /// parameters of the current attribute
95 /// \param theAttribute an attribute to be restored
96 /// \param theValid a boolean flag, if restore happens for valid parameters
97 virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
99 /// Checks the widget validity. By default, it returns true.
100 /// \param thePrs a selected presentation in the view
101 /// \return a boolean value
102 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
104 /// Fills the attribute with the value of the selected owner
105 /// \param thePrs a selected owner
106 virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs) = 0;
108 /// Returns a list of selected presentations in the viewer and object browser
109 /// The presentations from the object browser are filtered by the AIS context filters
110 /// \return a list of presentations
111 QList<std::shared_ptr<ModuleBase_ViewerPrs>> getFilteredSelected();
113 /// It obtains selection filters from the workshop and activates them in the active viewer
114 /// \param toActivate a flag about activation or deactivation the filters
115 /// \return true if the selection filter of the widget is activated in viewer context
116 bool activateFilters(const bool toActivate);
118 /// Block the model flush of update and intialization of attribute
119 /// \param theAttribute an attribute of blocking
120 /// \param theToBlock flag whether the model is blocked or unblocked
121 /// \param isActive out value if model is blocked, in value if model is unblocked
122 /// to be used to restore flush state when unblocked
123 /// \param isAttributeSetInitializedBlocked out value if model is blocked
124 /// in value if model is unblocked to be used to restore previous state when unblocked
125 virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
126 bool& isFlushesActived, bool& isAttributeSetInitializedBlocked);
129 /// Checks the current attibute in all attribute validators
130 /// \param theAttribute an attribute to be validated
131 /// \return true if all validators return that the attribute is valid
132 bool isValidAttribute(const AttributePtr& theAttribute) const;
134 /// Returns true if the workshop validator filter has been already activated
135 /// \return boolean value
136 bool isFilterActivated() const;
139 /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
140 /// \param theValue a viewer presentation
141 /// \param theValid a valid state
142 bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
144 /// Store the validity state of the presentation in an internal map
145 /// \param theValue a viewer presentation
146 /// \param theValid a valid state
147 void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
150 /// Applies AIS context filters to the parameter list. The not approved presentations are
151 /// removed from the parameters.
152 /// \param theValues a list of presentations.
153 void filterPresentations(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
155 /// Remove subshapes of compsolids if whole compsolid is present.
156 /// \param theValues a list of presentations.
157 void filterCompSolids(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
160 /// Reference to workshop
161 ModuleBase_IWorkshop* myWorkshop;
162 /// The widget is in validation mode: store is performed, restore is not
166 ObjectPtr myPresentedObject; /// back up of the filtered object
167 #ifdef LIST_OF_VALID_PRS
168 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs; /// cash of valid selection presentations
169 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs; /// cash of invalid selection presentations
171 // assume that one presentation selection presentation corresponds only one shape
172 NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myValidPrs;
173 NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myInvalidPrs;
176 /// store to backup parameters of the model
177 ModuleBase_WidgetSelectorStore* myAttributeStore;
180 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */