Salome HOME
Boolean correction: clean the validation cash by other widget value change if it...
[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
18 #include <SelectMgr_ListOfFilter.hxx>
19
20 #include <QList>
21
22 class QWidget;
23 class ModuleBase_IWorkshop;
24 class ModuleBase_ISelection;
25 class ModelAPI_Validator;
26 class Config_WidgetAPI;
27 class Handle_SelectMgr_EntityOwner;
28
29 /**
30 * \ingroup GUI
31 * Implementation of widget with validators and filters processing.
32 */
33 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
34 {
35   Q_OBJECT
36  public:
37   /// Constructor
38   /// \param theParent the parent object
39   /// \param theWorkshop a reference to workshop
40   /// \param theData the widget configuation. The attribute of the model widget is obtained from
41   /// \param theParentId is Id of a parent of the current attribute
42   ModuleBase_WidgetValidated(QWidget* theParent,
43                              ModuleBase_IWorkshop* theWorkshop,
44                              const Config_WidgetAPI* theData,
45                              const std::string& theParentId);
46   virtual ~ModuleBase_WidgetValidated();
47
48   /// Checks whether all active viewer filters validate the presentation
49   /// \param thePrs a selected presentation in the view
50   /// \return a boolean value
51   bool isValidInFilters(const ModuleBase_ViewerPrs& thePrs);
52
53   /// Checks all widget validator if the owner is valid
54   /// \param theValue a selected presentation in the view
55   /// \return a boolean value
56   bool isValidSelection(const ModuleBase_ViewerPrs& theValue);
57
58   /// Set the given wrapped value to the current widget
59   /// This value should be processed in the widget according to the needs
60   /// The method is called by the current operation to process the operation preselection.
61   /// It is redefined to check the value validity and if it is, fill the attribute with by value
62   /// \param theValues the wrapped selection values
63   /// \param theToValidate a flag on validation of the values
64   virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
65                             const bool theToValidate);
66
67   //! Returns data object by AIS
68   ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
69
70   //! Clear all validated cash in the widget
71   void clearValidatedCash();
72
73 protected:
74   /// Creates a backup of the current values of the attribute
75   /// It should be realized in the specific widget because of different
76   /// parameters of the current attribute
77   virtual void storeAttributeValue();
78
79   /// Creates a backup of the current values of the attribute
80   /// It should be realized in the specific widget because of different
81   /// parameters of the current attribute
82   /// \param theValid a boolean flag, if restore happens for valid parameters
83   virtual void restoreAttributeValue(const bool theValid);
84
85   /// Checks the widget validity. By default, it returns true.
86   /// \param thePrs a selected presentation in the view
87   /// \return a boolean value
88   virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
89
90   /// Fills the attribute with the value of the selected owner
91   /// \param thePrs a selected owner
92   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) = 0;
93
94   /// Checks the current attibute in all attribute validators
95   // \return true if all validators return that the attribute is valid
96   bool isValidAttribute() const;
97
98   /// Returns true if the workshop validator filter has been already activated
99   /// \return boolean value
100   bool isFilterActivated() const;
101
102   /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
103   /// \param theValue a viewer presentation
104   /// \param theValid a valid state
105   bool getValidState(const ModuleBase_ViewerPrs& theValue, bool& theValid);
106
107   /// Store the validity state of the presentation in an internal map
108   /// \param theValue a viewer presentation
109   /// \param theValid a valid state
110   void storeValidState(const ModuleBase_ViewerPrs& theValue, const bool theValid);
111
112   /// Removes all presentations from internal maps.
113   void clearValidState();
114
115   /// Returns a list of selected presentations in the viewer and object browser
116   /// The presentations from the object browser are filtered by the AIS context filters
117   /// \return a list of presentations
118   QList<ModuleBase_ViewerPrs> getFilteredSelected();
119
120   /// Applies AIS context filters to the parameter list. The not approved presentations are
121   /// removed from the parameters.
122   /// \param theValues a list of presentations.
123   void filterPresentations(QList<ModuleBase_ViewerPrs>& theValues);
124
125   /// It obtains selection filters from the workshop and activates them in the active viewer
126   /// \param toActivate a flag about activation or deactivation the filters
127   void activateFilters(const bool toActivate);
128
129   /// Block the model flush of update and intialization of attribute
130   /// \param theToBlock flag whether the model is blocked or unblocked
131   /// \param isActive out value if model is blocked, in value if model is unblocked
132   /// to be used to restore flush state when unblocked
133   /// \param isAttributeSetInitializedBlocked out value if model is blocked
134   /// in value if model is unblocked to be used to restore previous state when unblocked
135   virtual void blockAttribute(const bool& theToBlock, bool& isFlushesActived,
136                               bool& isAttributeSetInitializedBlocked);
137
138 protected:
139   /// Reference to workshop
140   ModuleBase_IWorkshop* myWorkshop; 
141
142   /// The widget is in validation mode: store is performed, restore is not
143   bool myIsInValidate; 
144
145 private:
146   ObjectPtr myPresentedObject; /// back up of the filtered object
147   QList<ModuleBase_ViewerPrs> myValidPrs;
148   QList<ModuleBase_ViewerPrs> myInvalidPrs;
149 };
150
151 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */