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 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) {}
59 /// Appends into container of workshop selection filters
60 /// \param [out] selection filters
61 virtual void selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters);
63 /// Returns true if the validation is activated
64 bool isInValidate() const { return myIsInValidate; }
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);
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);
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,
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;
93 //! Clear all validated cash in the widget
94 void clearValidatedCash();
97 /// Returns true if the workshop validator filter has been already activated
98 /// \return boolean value
99 bool isFilterActivated() const;
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);
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);
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
119 /// cash of valid selection presentations
120 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
122 /// cash of invalid selection presentations
123 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
126 #endif /* ModuleBase_WidgetValidator_H_ */