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 Model_Validator_H_
22 #define Model_Validator_H_
25 #include <ModelAPI_Validator.h>
29 /**\class Model_ValidatorsFactory
31 * \brief Manages the registered validators
33 * Allows to get a validator by the feature identifier and
34 * the attribute identifier (if attribute is validated).
35 * All accessible validators mustbe registered by the ID string first.
36 * The instance of this factory can be get in the Session.
37 * Keeps the validator objects alive and just returns one of it by request.
38 * All the needed information is provided to the validator as an argument,
39 * this allows to work with them independently from the feature specific object.
41 class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
44 std::map<std::string, ModelAPI_Validator*> myIDs; ///< map from ID to registered validator
45 /// validators IDs to list of arguments
46 typedef std::map<std::string, std::list<std::string> > AttrValidators;
47 /// validators IDs by feature ID
48 std::map<std::string, AttrValidators> myFeatures;
49 /// validators IDs and arguments by feature and attribute IDs
50 std::map<std::string, std::map<std::string, AttrValidators> > myAttrs;
51 /// Stores the registered attributes that leads to the concealment of referenced objects in
52 /// data tree. Map from feature kind to set of attribute IDs.
53 std::map<std::string, std::set<std::string> > myConcealed;
54 /// Stores the registered attributes must be checked only if the particular case is activated
55 /// Map from feature kind to map of attribute IDs to pair
56 // (switchId (ID of the attribute) and case Ids (possible values of the switch attribute))
57 std::map<std::string, std::map<std::string,
58 std::map<std::string, std::set<std::string> > > > myCases;
59 /// Stores main attribute for each feature
60 std::map<std::string, std::string> myMainArgument;
61 std::map<std::string, std::set<std::string> > myGeometricalSelection;
64 /// Registers the instance of the validator by the ID
65 MODEL_EXPORT virtual void registerValidator(const std::string& theID,
66 ModelAPI_Validator* theValidator);
68 /// Assigns validator to the feature
69 MODEL_EXPORT virtual void assignValidator(const std::string& theID,
70 const std::string& theFeatureID);
72 /// Assigns validator to the feature with arguments of the validator
73 MODEL_EXPORT virtual void assignValidator(const std::string& theID,
74 const std::string& theFeatureID,
75 const std::list<std::string>& theArguments);
77 /// Assigns validator to the attribute of the feature
78 MODEL_EXPORT virtual void assignValidator(const std::string& theID,
79 const std::string& theFeatureID,
80 const std::string& theAttrID,
81 const std::list<std::string>& theArguments);
83 /// Provides a validator for the feature, returns NULL if no validator
84 MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
85 Validators& theResult) const;
86 /// Provides a validator for the attribute, returns NULL if no validator
87 MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
88 const std::string& theAttrID, Validators& theResult) const;
90 /// Returns registered validator by its Id
91 MODEL_EXPORT virtual const ModelAPI_Validator* validator(const std::string& theID) const;
93 /// Returns true if feature and all its attributes are valid.
94 MODEL_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
96 /// Returns true if the attribute is valid.
97 MODEL_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
98 std::string& theValidator, Events_InfoMessage& theError) const;
100 /// register that this attribute in feature is not obligatory for the feature execution
101 /// so, it is not needed for the standard validation mechanism
102 virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
104 /// Returns true if the attribute in feature is not obligatory for the feature execution
105 virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
107 /// register that this attribute conceals in the object browser
108 /// all referenced features after execution
109 virtual void registerConcealment(std::string theFeature, std::string theAttribute);
111 /// Returns true that it was registered that attribute conceals the referenced result
112 virtual bool isConcealed(std::string theFeature, std::string theAttribute);
114 /// register the case-attribute (\a myCases set definition)
115 virtual void registerCase(std::string theFeature, std::string theAttribute,
116 const std::list<std::pair<std::string, std::string> >& theCases);
118 /// Returns true if the attribute must be checked (the case is selected)
119 virtual bool isCase(FeaturePtr theFeature, std::string theAttribute);
121 /// Register the attribute as a main argument of the feature
122 virtual void registerMainArgument(std::string theFeature, std::string theAttribute);
124 /// Returns true is the attribute is a main argument of the feature
125 virtual bool isMainArgument(std::string theFeature, std::string theAttribute);
127 /// Register the selection attribute as geometrical selection
128 virtual void registerGeometricalSelection(std::string theFeature, std::string theAttribute);
130 /// Returns true if the attribute is a geometrical selection
131 virtual bool isGeometricalSelection(std::string theFeature, std::string theAttribute);
135 /// Adds the defualt validators that are usefull for all features.
136 void addDefaultValidators(Validators& theValidators) const;
137 /// Adds the defualt validators that are usefull for all attributes.
138 void addDefaultAttributeValidators(Validators& theValidators) const;
139 /// Get instance from Session
140 Model_ValidatorsFactory();
142 friend class Model_Session;