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"
26 #include "ModuleBase_Definitions.h"
28 #include <SelectMgr_ListOfFilter.hxx>
33 class ModelAPI_Attribute;
35 class ModuleBase_ModelWidget;
36 class ModuleBase_IWorkshop;
37 class ModuleBase_ViewerPrs;
38 class ModuleBase_WidgetSelectorStore;
42 * Implementation of widget with validators and filters processing.
44 class MODULEBASE_EXPORT ModuleBase_WidgetValidator
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();
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) {}
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(QIntList& theModuleSelectionFilters,
63 SelectMgr_ListOfFilter& theSelectionFilters);
65 /// Returns true if the validation is activated
66 bool isInValidate() const { return myIsInValidate; }
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);
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);
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,
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;
95 //! Clear all validated cash in the widget
96 void clearValidatedCash();
99 /// Returns true if the workshop validator filter has been already activated
100 /// \return boolean value
101 bool isFilterActivated() const;
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);
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);
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
121 /// cash of valid selection presentations
122 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
124 /// cash of invalid selection presentations
125 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
128 #endif /* ModuleBase_WidgetValidator_H_ */