]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetValidated.h
Salome HOME
Update classes documentation
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidated.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetValidated.h
4 // Created:     12 Mar 2015
5 // Author:      Natalia ERMOLAEVA
6
7
8 #ifndef MODULEBASE_WIDGETVALIDATED_H_
9 #define MODULEBASE_WIDGETVALIDATED_H_
10
11 #include <ModuleBase.h>
12 #include <ModuleBase_ModelWidget.h>
13
14 #include <GeomAPI_Shape.h>
15 #include <GeomAPI_AISObject.h>
16 #include <ModelAPI_Object.h>
17 #include <ModelAPI_Attribute.h>
18
19 #include <SelectMgr_ListOfFilter.hxx>
20 #include <NCollection_DataMap.hxx>
21 #include <TopoDS_Shape.hxx>
22
23 #include <QList>
24 #include <QMap>
25
26 class QWidget;
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;
33
34 //#define LIST_OF_VALID_PRS
35
36 /**
37 * \ingroup GUI
38 * Implementation of widget with validators and filters processing.
39 */
40 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
41 {
42   Q_OBJECT
43  public:
44   /// Constructor
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();
52
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);
60
61   //! Returns data object by AIS
62   ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
63
64   //! Clear all validated cash in the widget
65   void clearValidatedCash();
66
67 protected:
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);
72
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   /// \param theAttribute the attribute
78   /// \return a boolean value
79   bool isValidSelectionForAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
80                                     const AttributePtr& theAttribute);
81
82   /// Retunrs attribute, which should be validated. In default implementation,
83   /// this is an attribute of ID
84   /// \return an attribute
85   virtual AttributePtr attribute() const;
86
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 stored
91   virtual void storeAttributeValue(const AttributePtr& theAttribute);
92
93   /// Creates a backup of the current values of the attribute
94   /// It should be realized in the specific widget because of different
95   /// parameters of the current attribute
96   /// \param theAttribute an attribute to be restored
97   /// \param theValid a boolean flag, if restore happens for valid parameters
98   virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
99
100   /// Checks the widget validity. By default, it returns true.
101   /// \param thePrs a selected presentation in the view
102   /// \return a boolean value
103   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
104
105   /// Fills the attribute with the value of the selected owner
106   /// \param thePrs a selected owner
107   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs) = 0;
108
109   /// Returns a list of selected presentations in the viewer and object browser
110   /// The presentations from the object browser are filtered by the AIS context filters
111   /// \return a list of presentations
112   QList<std::shared_ptr<ModuleBase_ViewerPrs>> getFilteredSelected();
113
114   /// It obtains selection filters from the workshop and activates them in the active viewer
115   /// \param toActivate a flag about activation or deactivation the filters
116   /// \return true if the selection filter of the widget is activated in viewer context
117   bool activateFilters(const bool toActivate);
118
119   /// Block the model flush of update and intialization of attribute
120   /// \param theAttribute an attribute of blocking
121   /// \param theToBlock flag whether the model is blocked or unblocked
122   /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
123   /// to be used to restore flush state when unblocked
124   /// \param isAttributeSetInitializedBlocked out value if model is blocked
125   /// in value if model is unblocked to be used to restore previous state when unblocked
126   virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
127                               bool& isFlushesActived, bool& isAttributeSetInitializedBlocked);
128
129 private:
130   /// Checks the current attibute in all attribute validators
131   /// \param theAttribute an attribute to be validated
132   /// \return true if all validators return that the attribute is valid
133   bool isValidAttribute(const AttributePtr& theAttribute) const;
134
135   /// Returns true if the workshop validator filter has been already activated
136   /// \return boolean value
137   bool isFilterActivated() const;
138
139 protected:
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);
144
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);
149
150 private:
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);
155
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);
159
160 protected:
161   /// Reference to workshop
162   ModuleBase_IWorkshop* myWorkshop;
163   /// The widget is in validation mode: store is performed, restore is not
164   bool myIsInValidate;
165
166 private:
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
171 #else
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;
175 #endif
176
177   /// store to backup parameters of the model
178   ModuleBase_WidgetSelectorStore* myAttributeStore;
179 };
180
181 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */