Salome HOME
3a84b0658c2655fe4ae3a69709e1ba14fc584647
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidator.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef ModuleBase_WidgetValidator_H_
22 #define ModuleBase_WidgetValidator_H_
23
24 #include "ModuleBase.h"
25
26 #include "ModuleBase_Definitions.h"
27
28 #include <SelectMgr_ListOfFilter.hxx>
29
30 #include <QList>
31 #include <memory>
32
33 class ModelAPI_Attribute;
34
35 class ModuleBase_ModelWidget;
36 class ModuleBase_IWorkshop;
37 class ModuleBase_ViewerPrs;
38 class ModuleBase_WidgetSelectorStore;
39
40 /**
41 * \ingroup GUI
42 * Implementation of widget with validators and filters processing.
43 */
44 class MODULEBASE_EXPORT ModuleBase_WidgetValidator
45 {
46  public:
47   /// Constructor
48   /// \param theModelWidget the model widget to be validated
49   /// \param theWorkshop the current workshop
50   ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget,
51                              ModuleBase_IWorkshop* theWorkshop);
52   virtual ~ModuleBase_WidgetValidator();
53
54   /// Fills given container with selection modes if the widget has it
55   /// \param [out] theModuleSelectionModes module additional modes, -1 means all default modes
56   /// \param theModes [out] a container of modes
57   virtual void selectionModes(int& theModuleSelectionModes, QIntList& theModes) {}
58
59   /// Appends into container of workshop selection filters
60   /// \param [out] theModuleSelectionFilters module additional modes, -1 means all default modes
61   /// \param [out] selection filters
62   virtual void selectionFilters(int& theModuleSelectionFilters,
63                                 SelectMgr_ListOfFilter& theSelectionFilters);
64
65   /// Returns true if the validation is activated
66   bool isInValidate() const { return myIsInValidate; }
67
68   /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
69   /// next, the attribute's validating. It trying on the give selection to current attribute by
70   /// setting the value inside and calling validators. After this, the previous attribute value is
71   /// restored.The valid/invalid value is cashed.
72   /// \param theValue a selected presentation in the view
73   /// \return a boolean value
74   virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
75
76     /// Creates a backup of the current values of the attribute
77   /// It should be realized in the specific widget because of different
78   /// parameters of the current attribute
79   /// \param theAttribute an attribute to be stored
80   virtual void storeAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
81
82   /// Creates a backup of the current values of the attribute
83   /// It should be realized in the specific widget because of different
84   /// parameters of the current attribute
85   /// \param theAttribute an attribute to be restored
86   /// \param theValid a boolean flag, if restore happens for valid parameters
87   virtual void restoreAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
88                                      const bool theValid);
89
90   /// Checks the current attibute in all attribute validators
91   /// \param theAttribute an attribute to be validated
92   /// \return true if all validators return that the attribute is valid
93   bool isValidAttribute(const std::shared_ptr<ModelAPI_Attribute>& theAttribute) const;
94
95   //! Clear all validated cash in the widget
96   void clearValidatedCash();
97
98 private:
99   /// Returns true if the workshop validator filter has been already activated
100   /// \return boolean value
101   bool isFilterActivated() const;
102
103   /// Gets the validity state of the presentation in an internal map.
104   /// Returns true if the valid state of value is stored
105   /// \param theValue a viewer presentation
106   /// \param theValid a valid state
107   bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
108
109   /// Store the validity state of the presentation in an internal map
110   /// \param theValue a viewer presentation
111   /// \param theValid a valid state
112   void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
113
114 protected:
115   bool myIsInValidate; ///< cashed if the value is processed in validation
116   /// Reference to workshop
117   ModuleBase_ModelWidget* myModelWidget; ///< the current widget to be validated
118   ModuleBase_IWorkshop* myWorkshop; ///< the active workshop
119   ModuleBase_WidgetSelectorStore* myAttributeStore; ///< store/restore attribute values
120
121   /// cash of valid selection presentations
122   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
123
124   /// cash of invalid selection presentations
125   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
126 };
127
128 #endif /* ModuleBase_WidgetValidator_H_ */