1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_Validator.hxx
5 // Author: Mikhail PONIKAROV
7 #ifndef Model_Validator_H_
8 #define Model_Validator_H_
11 #include <ModelAPI_Validator.h>
15 /**\class Model_ValidatorsFactory
17 * \brief Manages the registered validators
19 * Allows to get a validator by the feature identifier and
20 * the attribute identifier (if attribute is validated).
21 * All accessible validators mustbe registered by the ID string first.
22 * The instance of this factory can be get in the Session.
23 * Keeps the validator objects alive and just returns one of it by request.
24 * All the needed information is provided to the validator as an argument,
25 * this allows to work with them independently from the feature specific object.
27 class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
30 std::map<std::string, ModelAPI_Validator*> myIDs; ///< map from ID to registered validator
31 /// validators IDs to list of arguments
32 typedef std::map<std::string, std::list<std::string> > AttrValidators;
33 /// validators IDs by feature ID
34 std::map<std::string, AttrValidators> myFeatures;
35 /// validators IDs and arguments by feature and attribute IDs
36 std::map<std::string, std::map<std::string, AttrValidators> > myAttrs;
37 /// Stores the registered attributes that leads to the concealment of referenced objects in
38 /// data tree. Map from feature kind to set of attribute IDs.
39 std::map<std::string, std::set<std::string> > myConcealed;
40 /// Stored the unconcealed results and features that caused the canceled concealment (Recover).
41 /// If the feature is empty, unconcealment is persistent.
42 std::map<std::shared_ptr<ModelAPI_Result>, std::list<std::shared_ptr<ModelAPI_Feature> > >
44 /// Stores the registered attributes must be checked only if the particular case is activated
45 /// Map from feature kind to map of attribute IDs to pair
46 // (switchId (ID of the attribute) and case Ids (possible values of the switch attribute))
47 std::map<std::string, std::map<std::string,
48 std::map<std::string, std::set<std::string> > > > myCases;
51 /// Registers the instance of the validator by the ID
52 MODEL_EXPORT virtual void registerValidator(const std::string& theID,
53 ModelAPI_Validator* theValidator);
55 /// Assigns validator to the feature
56 MODEL_EXPORT virtual void assignValidator(const std::string& theID,
57 const std::string& theFeatureID);
59 /// Assigns validator to the feature with arguments of the validator
60 MODEL_EXPORT virtual void assignValidator(const std::string& theID,
61 const std::string& theFeatureID,
62 const std::list<std::string>& theArguments);
64 /// Assigns validator to the attribute of the feature
65 MODEL_EXPORT virtual void assignValidator(const std::string& theID,
66 const std::string& theFeatureID,
67 const std::string& theAttrID,
68 const std::list<std::string>& theArguments);
70 /// Provides a validator for the feature, returns NULL if no validator
71 MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
72 Validators& theResult) const;
73 /// Provides a validator for the attribute, returns NULL if no validator
74 MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
75 const std::string& theAttrID, Validators& theResult) const;
77 /// Returns registered validator by its Id
78 MODEL_EXPORT virtual const ModelAPI_Validator* validator(const std::string& theID) const;
80 /// Returns true if feature and all its attributes are valid.
81 MODEL_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
83 /// Returns true if the attribute is valid.
84 MODEL_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
85 std::string& theValidator, Events_InfoMessage& theError) const;
87 /// register that this attribute in feature is not obligatory for the feature execution
88 /// so, it is not needed for the standard validation mechanism
89 virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
91 /// Returns true if the attribute in feature is not obligatory for the feature execution
92 virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
94 /// register that this attribute conceals in the object browser
95 /// all referenced features after execution
96 virtual void registerConcealment(std::string theFeature, std::string theAttribute);
98 /// Returns true that it was registered that attribute conceals the referenced result
99 virtual bool isConcealed(std::string theFeature, std::string theAttribute);
101 /// Registers (by Recover feature) cancel of concealment of specific result by specific feature.
102 /// If theCanceledFeat is empty, the concealment is canceled for this result forever.
103 virtual void registerUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
104 std::shared_ptr<ModelAPI_Feature> theCanceledFeat);
106 /// Disables cancel of concealment of specific result by specific feature.
107 virtual void disableUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
108 std::shared_ptr<ModelAPI_Feature> theCanceledFeat);
110 /// Returns true if concealment is canceled.
111 virtual bool isUnconcealed(std::shared_ptr<ModelAPI_Result> theUnconcealed,
112 std::shared_ptr<ModelAPI_Feature> theCanceledFeat);
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);
123 /// Adds the defualt validators that are usefull for all features.
124 void addDefaultValidators(Validators& theValidators) const;
125 /// Adds the defualt validators that are usefull for all attributes.
126 void addDefaultAttributeValidators(Validators& theValidators) const;
127 /// Get instance from Session
128 Model_ValidatorsFactory();
130 friend class Model_Session;