Salome HOME
Issue #1343. Improvement of Extrusion and Revolution operations: sketch creator setSe...
[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
21 #include <QList>
22
23 class QWidget;
24 class ModuleBase_IWorkshop;
25 class ModuleBase_ISelection;
26 class ModuleBase_WidgetSelectorStore;
27 class ModelAPI_Validator;
28 class Config_WidgetAPI;
29 class Handle_SelectMgr_EntityOwner;
30
31 /**
32 * \ingroup GUI
33 * Implementation of widget with validators and filters processing.
34 */
35 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
36 {
37   Q_OBJECT
38  public:
39   /// Constructor
40   /// \param theParent the parent object
41   /// \param theWorkshop a reference to workshop
42   /// \param theData the widget configuation. The attribute of the model widget is obtained from
43   ModuleBase_WidgetValidated(QWidget* theParent,
44                              ModuleBase_IWorkshop* theWorkshop,
45                              const Config_WidgetAPI* theData);
46   virtual ~ModuleBase_WidgetValidated();
47
48   /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
49   /// next, the attribute's validating. It trying on the give selection to current attribute by
50   /// setting the value inside and calling validators. After this, the previous attribute value is
51   /// restored.The valid/invalid value is cashed.
52   /// \param theValue a selected presentation in the view
53   /// \return a boolean value
54   virtual bool isValidSelection(const ModuleBase_ViewerPrs& theValue);
55
56   //! Returns data object by AIS
57   ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
58
59   //! Clear all validated cash in the widget
60   void clearValidatedCash();
61
62 protected:
63   /// Checks whether all active viewer filters validate the presentation
64   /// \param thePrs a selected presentation in the view
65   /// \return a boolean value
66   bool isValidInFilters(const ModuleBase_ViewerPrs& thePrs);
67
68   /// Checks all attribute validators returns valid. It tries on the given selection
69   /// to current attribute by setting the value inside and calling validators. After this,
70   /// the previous attribute value is restored.The valid/invalid value is cashed.
71   /// \param theValue a selected presentation in the view
72   /// \return a boolean value
73   bool isValidSelectionForAttribute(const ModuleBase_ViewerPrs& theValue,
74                                     const AttributePtr& theAttribute);
75
76   /// Retunrs attribute, which should be validated. In default implementation,
77   /// this is an attribute of ID
78   /// \return an attribute
79   virtual AttributePtr attribute() const;
80
81   /// Creates a backup of the current values of the attribute
82   /// It should be realized in the specific widget because of different
83   /// parameters of the current attribute
84   /// \param theAttribute an attribute to be stored
85   virtual void storeAttributeValue(const AttributePtr& theAttribute);
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 restored
91   /// \param theValid a boolean flag, if restore happens for valid parameters
92   virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
93
94   /// Checks the widget validity. By default, it returns true.
95   /// \param thePrs a selected presentation in the view
96   /// \return a boolean value
97   virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
98
99   /// Fills the attribute with the value of the selected owner
100   /// \param thePrs a selected owner
101   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) = 0;
102
103   /// Returns a list of selected presentations in the viewer and object browser
104   /// The presentations from the object browser are filtered by the AIS context filters
105   /// \return a list of presentations
106   QList<ModuleBase_ViewerPrs> getFilteredSelected();
107
108   /// It obtains selection filters from the workshop and activates them in the active viewer
109   /// \param toActivate a flag about activation or deactivation the filters
110   /// \return true if the selection filter of the widget is activated in viewer context
111   bool activateFilters(const bool toActivate);
112
113   /// Block the model flush of update and intialization of attribute
114   /// \param theAttribute an attribute of blocking
115   /// \param theToBlock flag whether the model is blocked or unblocked
116   /// \param isActive out value if model is blocked, in value if model is unblocked
117   /// to be used to restore flush state when unblocked
118   /// \param isAttributeSetInitializedBlocked out value if model is blocked
119   /// in value if model is unblocked to be used to restore previous state when unblocked
120   virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
121                               bool& isFlushesActived, bool& isAttributeSetInitializedBlocked);
122
123 private:
124   /// Checks the current attibute in all attribute validators
125   /// \param theAttribute an attribute to be validated
126   /// \return true if all validators return that the attribute is valid
127   bool isValidAttribute(const AttributePtr& theAttribute) const;
128
129   /// Returns true if the workshop validator filter has been already activated
130   /// \return boolean value
131   bool isFilterActivated() const;
132
133 protected:
134   /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
135   /// \param theValue a viewer presentation
136   /// \param theValid a valid state
137   bool getValidState(const ModuleBase_ViewerPrs& theValue, bool& theValid);
138
139   /// Store the validity state of the presentation in an internal map
140   /// \param theValue a viewer presentation
141   /// \param theValid a valid state
142   void storeValidState(const ModuleBase_ViewerPrs& theValue, const bool theValid);
143
144 private:
145   /// Applies AIS context filters to the parameter list. The not approved presentations are
146   /// removed from the parameters.
147   /// \param theValues a list of presentations.
148   void filterPresentations(QList<ModuleBase_ViewerPrs>& theValues);
149
150   /// Remove subshapes of compsolids if whole compsolid is present.
151   /// \param theValues a list of presentations.
152   void filterCompSolids(QList<ModuleBase_ViewerPrs>& theValues);
153
154 protected:
155   /// Reference to workshop
156   ModuleBase_IWorkshop* myWorkshop;
157   /// The widget is in validation mode: store is performed, restore is not
158   bool myIsInValidate;
159
160 private:
161   ObjectPtr myPresentedObject; /// back up of the filtered object
162   QList<ModuleBase_ViewerPrs> myValidPrs; /// cash of valid selection presentations
163   QList<ModuleBase_ViewerPrs> myInvalidPrs; /// cash of invalid selection presentations
164
165   /// store to backup parameters of the model
166   ModuleBase_WidgetSelectorStore* myAttributeStore;
167 };
168
169 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */