Salome HOME
f6c84426430e05229631e1faf7047320cbd078b8
[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 theModes [out] a container of modes
56   /// \param isAdditional if true, the modes are combinated with the module ones
57   virtual void selectionModes(QIntList& theModes, bool& isAdditional) {}
58
59   /// Appends into container of workshop selection filters
60   /// \param [out] selection filters
61   virtual void selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters);
62
63   /// Returns true if the validation is activated
64   bool isInValidate() const { return myIsInValidate; }
65
66   /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
67   /// next, the attribute's validating. It trying on the give selection to current attribute by
68   /// setting the value inside and calling validators. After this, the previous attribute value is
69   /// restored.The valid/invalid value is cashed.
70   /// \param theValue a selected presentation in the view
71   /// \return a boolean value
72   virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
73
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   /// \param theAttribute an attribute to be stored
78   virtual void storeAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
79
80   /// Creates a backup of the current values of the attribute
81   /// It should be realized in the specific widget because of different
82   /// parameters of the current attribute
83   /// \param theAttribute an attribute to be restored
84   /// \param theValid a boolean flag, if restore happens for valid parameters
85   virtual void restoreAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
86                                      const bool theValid);
87
88   /// Checks the current attibute in all attribute validators
89   /// \param theAttribute an attribute to be validated
90   /// \return true if all validators return that the attribute is valid
91   bool isValidAttribute(const std::shared_ptr<ModelAPI_Attribute>& theAttribute) const;
92
93   //! Clear all validated cash in the widget
94   void clearValidatedCash();
95
96 private:
97   /// Returns true if the workshop validator filter has been already activated
98   /// \return boolean value
99   bool isFilterActivated() const;
100
101   /// Gets the validity state of the presentation in an internal map.
102   /// 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 std::shared_ptr<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 std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
111
112 protected:
113   bool myIsInValidate; ///< cashed if the value is processed in validation
114   /// Reference to workshop
115   ModuleBase_ModelWidget* myModelWidget; ///< the current widget to be validated
116   ModuleBase_IWorkshop* myWorkshop; ///< the active workshop
117   ModuleBase_WidgetSelectorStore* myAttributeStore; ///< store/restore attribute values
118
119   /// cash of valid selection presentations
120   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
121
122   /// cash of invalid selection presentations
123   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
124 };
125
126 #endif /* ModuleBase_WidgetValidator_H_ */