1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef ModuleBase_WidgetValidator_H_
22 #define ModuleBase_WidgetValidator_H_
24 #include <ModuleBase.h>
29 class ModelAPI_Attribute;
31 class ModuleBase_ModelWidget;
32 class ModuleBase_IWorkshop;
33 class ModuleBase_ViewerPrs;
34 class ModuleBase_WidgetSelectorStore;
38 * Implementation of widget with validators and filters processing.
40 class MODULEBASE_EXPORT ModuleBase_WidgetValidator
44 /// \param theModelWidget the model widget to be validated
45 /// \param theWorkshop the current workshop
46 ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget,
47 ModuleBase_IWorkshop* theWorkshop);
48 virtual ~ModuleBase_WidgetValidator();
50 /// Returns true if the validation is activated
51 bool isInValidate() const { return myIsInValidate; }
53 /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
54 /// next, the attribute's validating. It trying on the give selection to current attribute by
55 /// setting the value inside and calling validators. After this, the previous attribute value is
56 /// restored.The valid/invalid value is cashed.
57 /// \param theValue a selected presentation in the view
58 /// \return a boolean value
59 virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
61 /// It obtains selection filters from the workshop and activates them in the active viewer
62 /// \param toActivate a flag about activation or deactivation the filters
63 /// \return true if the selection filter of the widget is activated in viewer context
64 bool activateFilters(const bool toActivate);
66 /// Creates a backup of the current values of the attribute
67 /// It should be realized in the specific widget because of different
68 /// parameters of the current attribute
69 /// \param theAttribute an attribute to be stored
70 virtual void storeAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
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 /// \param theAttribute an attribute to be restored
76 /// \param theValid a boolean flag, if restore happens for valid parameters
77 virtual void restoreAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
80 /// Checks the current attibute in all attribute validators
81 /// \param theAttribute an attribute to be validated
82 /// \return true if all validators return that the attribute is valid
83 bool isValidAttribute(const std::shared_ptr<ModelAPI_Attribute>& theAttribute) const;
86 /// Returns true if the workshop validator filter has been already activated
87 /// \return boolean value
88 bool isFilterActivated() const;
90 //! Clear all validated cash in the widget
91 void clearValidatedCash();
93 /// Gets the validity state of the presentation in an internal map.
94 /// Returns true if the valid state of value is stored
95 /// \param theValue a viewer presentation
96 /// \param theValid a valid state
97 bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
99 /// Store the validity state of the presentation in an internal map
100 /// \param theValue a viewer presentation
101 /// \param theValid a valid state
102 void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
105 bool myIsInValidate; ///< cashed if the value is processed in validation
106 /// Reference to workshop
107 ModuleBase_ModelWidget* myModelWidget; ///< the current widget to be validated
108 ModuleBase_IWorkshop* myWorkshop; ///< the active workshop
109 ModuleBase_WidgetSelectorStore* myAttributeStore; //< store/restore attribute values
111 /// cash of valid selection presentations
112 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
114 /// cash of invalid selection presentations
115 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
118 #endif /* ModuleBase_WidgetValidator_H_ */