Salome HOME
Multiple fixes (issue #1757 , issue #1799 , issue #1842 , etc):
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidated.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D\r
2 \r
3 // File:        ModuleBase_WidgetValidated.h\r
4 // Created:     12 Mar 2015\r
5 // Author:      Natalia ERMOLAEVA\r
6 \r
7 \r
8 #ifndef MODULEBASE_WIDGETVALIDATED_H_\r
9 #define MODULEBASE_WIDGETVALIDATED_H_\r
10 \r
11 #include <ModuleBase.h>\r
12 #include <ModuleBase_ModelWidget.h>\r
13 \r
14 #include <GeomAPI_Shape.h>\r
15 #include <GeomAPI_AISObject.h>\r
16 #include <ModelAPI_Object.h>\r
17 #include <ModelAPI_Attribute.h>\r
18 \r
19 #include <SelectMgr_ListOfFilter.hxx>\r
20 #include <NCollection_DataMap.hxx>\r
21 #include <TopoDS_Shape.hxx>\r
22 \r
23 #include <QList>\r
24 #include <QMap>\r
25 \r
26 class QWidget;\r
27 class ModuleBase_IWorkshop;\r
28 class ModuleBase_ISelection;\r
29 class ModuleBase_WidgetSelectorStore;\r
30 class ModelAPI_Validator;\r
31 class Config_WidgetAPI;\r
32 class Handle_SelectMgr_EntityOwner;\r
33 \r
34 //#define LIST_OF_VALID_PRS\r
35 \r
36 /**\r
37 * \ingroup GUI\r
38 * Implementation of widget with validators and filters processing.\r
39 */\r
40 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget\r
41 {\r
42   Q_OBJECT\r
43  public:\r
44   /// Constructor\r
45   /// \param theParent the parent object\r
46   /// \param theWorkshop a reference to workshop\r
47   /// \param theData the widget configuation. The attribute of the model widget is obtained from\r
48   ModuleBase_WidgetValidated(QWidget* theParent,\r
49                              ModuleBase_IWorkshop* theWorkshop,\r
50                              const Config_WidgetAPI* theData);\r
51   virtual ~ModuleBase_WidgetValidated();\r
52 \r
53   /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,\r
54   /// next, the attribute's validating. It trying on the give selection to current attribute by\r
55   /// setting the value inside and calling validators. After this, the previous attribute value is\r
56   /// restored.The valid/invalid value is cashed.\r
57   /// \param theValue a selected presentation in the view\r
58   /// \return a boolean value\r
59   virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);\r
60 \r
61   //! Returns data object by AIS\r
62   ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;\r
63 \r
64   //! Clear all validated cash in the widget\r
65   void clearValidatedCash();\r
66 \r
67   /// Returns true if the workshop validator filter has been already activated\r
68   /// \return boolean value\r
69   bool isFilterActivated() const;\r
70 \r
71 protected:\r
72   /// Checks whether all active viewer filters validate the presentation\r
73   /// \param thePrs a selected presentation in the view\r
74   /// \return a boolean value\r
75   virtual bool isValidInFilters(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);\r
76 \r
77   /// Checks all attribute validators returns valid. It tries on the given selection\r
78   /// to current attribute by setting the value inside and calling validators. After this,\r
79   /// the previous attribute value is restored.The valid/invalid value is cashed.\r
80   /// \param theValue a selected presentation in the view\r
81   /// \param theAttribute the attribute\r
82   /// \return a boolean value\r
83   bool isValidSelectionForAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,\r
84                                     const AttributePtr& theAttribute);\r
85 \r
86   /// Retunrs attribute, which should be validated. In default implementation,\r
87   /// this is an attribute of ID\r
88   /// \return an attribute\r
89   virtual AttributePtr attribute() const;\r
90 \r
91   /// Creates a backup of the current values of the attribute\r
92   /// It should be realized in the specific widget because of different\r
93   /// parameters of the current attribute\r
94   /// \param theAttribute an attribute to be stored\r
95   virtual void storeAttributeValue(const AttributePtr& theAttribute);\r
96 \r
97   /// Creates a backup of the current values of the attribute\r
98   /// It should be realized in the specific widget because of different\r
99   /// parameters of the current attribute\r
100   /// \param theAttribute an attribute to be restored\r
101   /// \param theValid a boolean flag, if restore happens for valid parameters\r
102   virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);\r
103 \r
104   /// Checks the widget validity. By default, it returns true.\r
105   /// \param thePrs a selected presentation in the view\r
106   /// \return a boolean value\r
107   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);\r
108 \r
109   /// Fills the attribute with the value of the selected owner\r
110   /// \param thePrs a selected owner\r
111   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs) = 0;\r
112 \r
113   /// Returns a list of selected presentations in the viewer and object browser\r
114   /// The presentations from the object browser are filtered by the AIS context filters\r
115   /// \return a list of presentations\r
116   QList<std::shared_ptr<ModuleBase_ViewerPrs>> getFilteredSelected();\r
117 \r
118   /// It obtains selection filters from the workshop and activates them in the active viewer\r
119   /// \param toActivate a flag about activation or deactivation the filters\r
120   /// \return true if the selection filter of the widget is activated in viewer context\r
121   bool activateFilters(const bool toActivate);\r
122 \r
123   /// Block the model flush of update and intialization of attribute\r
124   /// \param theAttribute an attribute of blocking\r
125   /// \param theToBlock flag whether the model is blocked or unblocked\r
126   /// \param isFlushesActived out value if model is blocked, in value if model is unblocked\r
127   /// to be used to restore flush state when unblocked\r
128   /// \param isAttributeSetInitializedBlocked out value if model is blocked\r
129   /// in value if model is unblocked to be used to restore previous state when unblocked\r
130   virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,\r
131                               bool& isFlushesActived, bool& isAttributeSetInitializedBlocked);\r
132 \r
133 private:\r
134   /// Checks the current attibute in all attribute validators\r
135   /// \param theAttribute an attribute to be validated\r
136   /// \return true if all validators return that the attribute is valid\r
137   bool isValidAttribute(const AttributePtr& theAttribute) const;\r
138 \r
139 protected:\r
140   /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored\r
141   /// \param theValue a viewer presentation\r
142   /// \param theValid a valid state\r
143   bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);\r
144 \r
145   /// Store the validity state of the presentation in an internal map\r
146   /// \param theValue a viewer presentation\r
147   /// \param theValid a valid state\r
148   void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);\r
149 \r
150 private:\r
151   /// Applies AIS context filters to the parameter list. The not approved presentations are\r
152   /// removed from the parameters.\r
153   /// \param theValues a list of presentations.\r
154   void filterPresentations(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);\r
155 \r
156   /// Remove subshapes of compsolids if whole compsolid is present.\r
157   /// \param theValues a list of presentations.\r
158   void filterCompSolids(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);\r
159 \r
160 protected:\r
161   /// Reference to workshop\r
162   ModuleBase_IWorkshop* myWorkshop;\r
163   /// The widget is in validation mode: store is performed, restore is not\r
164   bool myIsInValidate;\r
165 \r
166 private:\r
167   ObjectPtr myPresentedObject; /// back up of the filtered object\r
168 #ifdef LIST_OF_VALID_PRS\r
169   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs; /// cash of valid selection presentations\r
170   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs; /// cash of invalid selection presentations\r
171 #else\r
172   // assume that one presentation selection presentation corresponds only one shape\r
173   NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myValidPrs;\r
174   NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myInvalidPrs;\r
175 #endif\r
176 \r
177   /// store to backup parameters of the model\r
178   ModuleBase_WidgetSelectorStore* myAttributeStore;\r
179 };\r
180 \r
181 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */\r