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_
11 #include <ModelAPI_Feature.h>
15 class ModelAPI_Feature;
16 class Events_InfoMessage;
18 /**\class ModelAPI_Validator
20 * \brief Allows to validate the attribute value of a feature or the whole feature.
22 * This object is assigned by the name
23 * in the XML file to the specific attribute or to the whole feature.
24 * If validator returns "false", it is signalized in user interface
25 * and feature is not executed.
26 * Validators must be registered in the validators factory to be
27 * correctly identified by the XML string-ID.
29 class MODELAPI_EXPORT ModelAPI_Validator
32 // Make virtual destructor in order to make the class polymorphic
33 virtual ~ModelAPI_Validator()
38 typedef std::shared_ptr<ModelAPI_Validator> ValidatorPtr;
40 /**\class ModelAPI_ValidatorsFactory
42 * \brief Manages the registered validators
44 * Allows to get a validator by the feature identifier and
45 * the attribute identifier (if attribute is validated).
46 * All accessible validators mustbe registered by the ID string first.
47 * The instance of this factory can be get in the Session.
48 * Keeps the validator objects alive and just returns one of it by request.
49 * All the needed information is provided to the validator as an argument,
50 * this allows to work with them independently from the feature specific object.
52 class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
55 /// Registers the instance of the validator by the ID
56 virtual void registerValidator(const std::string& theID, ModelAPI_Validator* theValidator) = 0;
58 /// Assigns validator to the feature
59 virtual void assignValidator(const std::string& theID, const std::string& theFeatureID) = 0;
61 /// Assigns validator to the feature with arguments of the validator
62 virtual void assignValidator(const std::string& theID,
63 const std::string& theFeatureID,
64 const std::list<std::string>& theArguments) = 0;
66 /// Assigns validator to the attribute of the feature
67 virtual void assignValidator(const std::string& theID, const std::string& theFeatureID,
68 const std::string& theAttrID,
69 const std::list<std::string>& theArguments) = 0;
71 /// Validators is a list of pairs <Validator, list of arguments>
72 typedef std::list<std::pair<std::string, std::list<std::string> > > Validators;
73 /// Provides a validator for the feature, returns NULL if no validator
74 virtual void validators(const std::string& theFeatureID,
75 Validators& theResult) const = 0;
76 /// Provides a validator for the attribute, returns NULL if no validator
77 virtual void validators(const std::string& theFeatureID, const std::string& theAttrID,
78 Validators& theResult) const = 0;
80 /// Returns registered validator by its Id
81 virtual const ModelAPI_Validator* validator(const std::string& theID) const = 0;
83 /// Returns true if feature and all its attributes are valid.
84 virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
86 /// Returns true if the attribute is valid.
87 virtual bool validate(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
88 std::string& theValidator, Events_InfoMessage& theError) const = 0;
90 /// register that this attribute in feature is not obligatory for the feature execution
91 /// so, it is not needed for the standard validation mechanism
92 virtual void registerNotObligatory(std::string theFeature, std::string theAttribute) = 0;
94 /// Returns true if the attribute in feature is not obligatory for the feature execution
95 virtual bool isNotObligatory(std::string theFeature, std::string theAttribute) = 0;
97 /// register that this attribute conceals in the object browser
98 /// all referenced features after execution
99 virtual void registerConcealment(std::string theFeature, std::string theAttribute) = 0;
101 /// Returns true that it was registered that attribute conceals the referenced result
102 virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0;
104 /// Register the case-attribute: this attribute is checked only if its case is selected
105 virtual void registerCase(std::string theFeature, std::string theAttribute,
106 const std::list<std::pair<std::string, std::string> >& theCases) = 0;
108 /// Returns true if the attribute must be checked (the case is selected)
109 virtual bool isCase(FeaturePtr theFeature, std::string theAttribute) = 0;
112 /// Get instance from Session
113 ModelAPI_ValidatorsFactory()