1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #ifndef ModuleBase_WidgetValidator_H_
21 #define ModuleBase_WidgetValidator_H_
23 #include "ModuleBase.h"
25 #include "ModuleBase_Definitions.h"
27 #include <SelectMgr_ListOfFilter.hxx>
32 class ModelAPI_Attribute;
34 class ModuleBase_ModelWidget;
35 class ModuleBase_IWorkshop;
36 class ModuleBase_ViewerPrs;
37 class ModuleBase_WidgetSelectorStore;
41 * Implementation of widget with validators and filters processing.
43 class MODULEBASE_EXPORT ModuleBase_WidgetValidator
47 /// \param theModelWidget the model widget to be validated
48 /// \param theWorkshop the current workshop
49 ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget,
50 ModuleBase_IWorkshop* theWorkshop);
51 virtual ~ModuleBase_WidgetValidator();
53 /// Fills given container with selection modes if the widget has it
54 /// \param [out] theModuleSelectionModes module additional modes, -1 means all default modes
55 /// \param theModes [out] a container of modes
56 virtual void selectionModes(int& theModuleSelectionModes, QIntList& theModes) {}
58 /// Appends into container of workshop selection filters
59 /// \param [out] theModuleSelectionFilters module additional modes, -1 means all default modes
60 /// \param [out] selection filters
61 virtual void selectionFilters(QIntList& theModuleSelectionFilters,
62 SelectMgr_ListOfFilter& theSelectionFilters);
64 /// Returns true if the validation is activated
65 bool isInValidate() const { return myIsInValidate; }
67 /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
68 /// next, the attribute's validating. It trying on the give selection to current attribute by
69 /// setting the value inside and calling validators. After this, the previous attribute value is
70 /// restored.The valid/invalid value is cashed.
71 /// \param theValue a selected presentation in the view
72 /// \return a boolean value
73 virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
75 /// Creates a backup of the current values of the attribute
76 /// It should be realized in the specific widget because of different
77 /// parameters of the current attribute
78 /// \param theAttribute an attribute to be stored
79 virtual void storeAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
81 /// Creates a backup of the current values of the attribute
82 /// It should be realized in the specific widget because of different
83 /// parameters of the current attribute
84 /// \param theAttribute an attribute to be restored
85 /// \param theValid a boolean flag, if restore happens for valid parameters
86 virtual void restoreAttributeValue(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
89 /// Checks the current attibute in all attribute validators
90 /// \param theAttribute an attribute to be validated
91 /// \return true if all validators return that the attribute is valid
92 bool isValidAttribute(const std::shared_ptr<ModelAPI_Attribute>& theAttribute) const;
94 //! Clear all validated cash in the widget
95 void clearValidatedCash();
98 /// Returns true if the workshop validator filter has been already activated
99 /// \return boolean value
100 bool isFilterActivated() const;
102 /// Gets the validity state of the presentation in an internal map.
103 /// Returns true if the valid state of value is stored
104 /// \param theValue a viewer presentation
105 /// \param theValid a valid state
106 bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
108 /// Store the validity state of the presentation in an internal map
109 /// \param theValue a viewer presentation
110 /// \param theValid a valid state
111 void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
114 bool myIsInValidate; ///< cashed if the value is processed in validation
115 /// Reference to workshop
116 ModuleBase_ModelWidget* myModelWidget; ///< the current widget to be validated
117 ModuleBase_IWorkshop* myWorkshop; ///< the active workshop
118 ModuleBase_WidgetSelectorStore* myAttributeStore; ///< store/restore attribute values
120 /// cash of valid selection presentations
121 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
123 /// cash of invalid selection presentations
124 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
127 #endif /* ModuleBase_WidgetValidator_H_ */