1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_Validator.hxx
5 // Author: Mikhail PONIKAROV
7 #ifndef ModelAPI_Validator_H_
8 #define ModelAPI_Validator_H_
14 class ModelAPI_Feature;
16 /**\class ModelAPI_Validator
18 * \brief Allows to validate the attribute value of a feature or the whole feature.
20 * This object is assigned by the name
21 * in the XML file to the specific attribute or to the whole feature.
22 * If validator returns "false", it is signalized in user interface
23 * and feature is not executed.
24 * Validators must be registered in the validators factory to be
25 * correctly identified by the XML string-ID.
27 class MODELAPI_EXPORT ModelAPI_Validator
30 // Make virtual destructor in order to make the class polymorphic
31 virtual ~ModelAPI_Validator()
36 typedef std::shared_ptr<ModelAPI_Validator> ValidatorPtr;
38 /**\class ModelAPI_ValidatorsFactory
40 * \brief Manages the registered validators
42 * Allows to get a validator by the feature identifier and
43 * the attribute identifier (if attribute is validated).
44 * All accessible validators mustbe registered by the ID string first.
45 * The instance of this factory can be get in the Session.
46 * Keeps the validator objects alive and just returns one of it by request.
47 * All the needed information is provided to the validator as an argument,
48 * this allows to work with them independently from the feature specific object.
50 class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
53 /// Registers the instance of the validator by the ID
54 virtual void registerValidator(const std::string& theID, ModelAPI_Validator* theValidator) = 0;
56 /// Assigns validator to the feature
57 virtual void assignValidator(const std::string& theID, const std::string& theFeatureID) = 0;
59 /// Assigns validator to the feature with arguments of the validator
60 virtual void assignValidator(const std::string& theID,
61 const std::string& theFeatureID,
62 const std::list<std::string>& theArguments) = 0;
64 /// Assigns validator to the attribute of the feature
65 virtual void assignValidator(const std::string& theID, const std::string& theFeatureID,
66 const std::string& theAttrID,
67 const std::list<std::string>& theArguments) = 0;
69 /// Provides a validator for the feature, returns NULL if no validator
70 virtual void validators(const std::string& theFeatureID,
71 std::list<ModelAPI_Validator*>& theResult,
72 std::list<std::list<std::string> >& theArguments) const = 0;
73 /// Provides a validator for the attribute, returns NULL if no validator
74 virtual void validators(const std::string& theFeatureID, const std::string& theAttrID,
75 std::list<ModelAPI_Validator*>& theValidators,
76 std::list<std::list<std::string> >& theArguments) const = 0;
78 /// Returns registered validator by its Id
79 virtual const ModelAPI_Validator* validator(const std::string& theID) const = 0;
81 /// Returns true if feature and all its attributes are valid.
82 virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
84 /// register that this attribute in feature is not obligatory for the feature execution
85 /// so, it is not needed for the standard validation mechanism
86 virtual void registerNotObligatory(std::string theFeature, std::string theAttribute) = 0;
88 /// Returns true if the attribute in feature is not obligatory for the feature execution
89 virtual bool isNotObligatory(std::string theFeature, std::string theAttribute) = 0;
91 /// register that this attribute conceals in the object browser
92 /// all referenced features after execution
93 virtual void registerConcealment(std::string theFeature, std::string theAttribute) = 0;
95 /// Returns true that it was registered that attribute conceals the referenced result
96 virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0;
99 /// Get instance from Session
100 ModelAPI_ValidatorsFactory()