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