Salome HOME
Issue #2024: Redesign of circle and arc of circle (validate preselected object)
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidator.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetValidator.h
4 // Created:     12 Mar 2015
5 // Author:      Natalia ERMOLAEVA
6
7
8 #ifndef ModuleBase_WidgetValidator_H_
9 #define ModuleBase_WidgetValidator_H_
10
11 #include <ModuleBase.h>
12
13 #include <QList>
14 #include <memory>
15
16 class ModelAPI_Attribute;
17
18 class ModuleBase_ModelWidget;
19 class ModuleBase_IWorkshop;
20 class ModuleBase_ViewerPrs;
21 class ModuleBase_WidgetSelectorStore;
22
23 /**
24 * \ingroup GUI
25 * Implementation of widget with validators and filters processing.
26 */
27 class MODULEBASE_EXPORT ModuleBase_WidgetValidator
28 {
29  public:
30   /// Constructor
31   /// \param theModelWidget the model widget to be validated
32   /// \param theWorkshop the current workshop
33   ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget,
34                              ModuleBase_IWorkshop* theWorkshop);
35   virtual ~ModuleBase_WidgetValidator();
36
37   /// Returns true if the validation is activated
38   bool isInValidate() const { return myIsInValidate; }
39
40   /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
41   /// next, the attribute's validating. It trying on the give selection to current attribute by
42   /// setting the value inside and calling validators. After this, the previous attribute value is
43   /// restored.The valid/invalid value is cashed.
44   /// \param theValue a selected presentation in the view
45   /// \return a boolean value
46   virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
47
48   /// It obtains selection filters from the workshop and activates them in the active viewer
49   /// \param toActivate a flag about activation or deactivation the filters
50   /// \return true if the selection filter of the widget is activated in viewer context
51   bool activateFilters(const bool toActivate);
52
53     /// Creates a backup of the current values of the attribute
54   /// It should be realized in the specific widget because of different
55   /// parameters of the current attribute
56   /// \param theAttribute an attribute to be stored
57   virtual void storeAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
58
59   /// Creates a backup of the current values of the attribute
60   /// It should be realized in the specific widget because of different
61   /// parameters of the current attribute
62   /// \param theAttribute an attribute to be restored
63   /// \param theValid a boolean flag, if restore happens for valid parameters
64   virtual void restoreAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
65                                      const bool theValid);
66
67   /// Checks the current attibute in all attribute validators
68   /// \param theAttribute an attribute to be validated
69   /// \return true if all validators return that the attribute is valid
70   bool isValidAttribute(const std::shared_ptr<ModelAPI_Attribute>& theAttribute) const;
71
72 private:
73   /// Returns true if the workshop validator filter has been already activated
74   /// \return boolean value
75   bool isFilterActivated() const;
76
77   //! Clear all validated cash in the widget
78   void clearValidatedCash();
79
80   /// Gets the validity state of the presentation in an internal map.
81   /// Returns true if the valid state of value is stored
82   /// \param theValue a viewer presentation
83   /// \param theValid a valid state
84   bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
85
86   /// Store the validity state of the presentation in an internal map
87   /// \param theValue a viewer presentation
88   /// \param theValid a valid state
89   void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
90
91 protected:
92   bool myIsInValidate; ///< cashed if the value is processed in validation
93   /// Reference to workshop
94   ModuleBase_ModelWidget* myModelWidget; ///< the current widget to be validated
95   ModuleBase_IWorkshop* myWorkshop; ///< the active workshop
96   ModuleBase_WidgetSelectorStore* myAttributeStore; //< store/restore attribute values
97
98   /// cash of valid selection presentations
99   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
100
101   /// cash of invalid selection presentations
102   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
103 };
104
105 #endif /* ModuleBase_WidgetValidator_H_ */