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;
17 /**\class ModelAPI_Validator
19 * \brief Allows to validate the attribute value of a feature or the whole feature.
21 * This object is assigned by the name
22 * in the XML file to the specific attribute or to the whole feature.
23 * If validator returns "false", it is signalized in user interface
24 * and feature is not executed.
25 * Validators must be registered in the validators factory to be
26 * correctly identified by the XML string-ID.
28 class MODELAPI_EXPORT ModelAPI_Validator
31 // Make virtual destructor in order to make the class polymorphic
32 virtual ~ModelAPI_Validator()
37 typedef std::shared_ptr<ModelAPI_Validator> ValidatorPtr;
39 /**\class ModelAPI_ValidatorsFactory
41 * \brief Manages the registered validators
43 * Allows to get a validator by the feature identifier and
44 * the attribute identifier (if attribute is validated).
45 * All accessible validators mustbe registered by the ID string first.
46 * The instance of this factory can be get in the Session.
47 * Keeps the validator objects alive and just returns one of it by request.
48 * All the needed information is provided to the validator as an argument,
49 * this allows to work with them independently from the feature specific object.
51 class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
54 /// Registers the instance of the validator by the ID
55 virtual void registerValidator(const std::string& theID, ModelAPI_Validator* theValidator) = 0;
57 /// Assigns validator to the feature
58 virtual void assignValidator(const std::string& theID, const std::string& theFeatureID) = 0;
60 /// Assigns validator to the feature with arguments of the validator
61 virtual void assignValidator(const std::string& theID,
62 const std::string& theFeatureID,
63 const std::list<std::string>& theArguments) = 0;
65 /// Assigns validator to the attribute of the feature
66 virtual void assignValidator(const std::string& theID, const std::string& theFeatureID,
67 const std::string& theAttrID,
68 const std::list<std::string>& theArguments) = 0;
70 /// Provides a validator for the feature, returns NULL if no validator
71 virtual void validators(const std::string& theFeatureID,
72 std::list<ModelAPI_Validator*>& theResult,
73 std::list<std::list<std::string> >& theArguments) const = 0;
74 /// Provides a validator for the attribute, returns NULL if no validator
75 virtual void validators(const std::string& theFeatureID, const std::string& theAttrID,
76 std::list<ModelAPI_Validator*>& theValidators,
77 std::list<std::list<std::string> >& theArguments) const = 0;
79 /// Returns registered validator by its Id
80 virtual const ModelAPI_Validator* validator(const std::string& theID) const = 0;
82 /// Returns true if feature and all its attributes are valid.
83 virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
85 /// register that this attribute in feature is not obligatory for the feature execution
86 /// so, it is not needed for the standard validation mechanism
87 virtual void registerNotObligatory(std::string theFeature, std::string theAttribute) = 0;
89 /// Returns true if the attribute in feature is not obligatory for the feature execution
90 virtual bool isNotObligatory(std::string theFeature, std::string theAttribute) = 0;
92 /// register that this attribute conceals in the object browser
93 /// all referenced features after execution
94 virtual void registerConcealment(std::string theFeature, std::string theAttribute) = 0;
96 /// Returns true that it was registered that attribute conceals the referenced result
97 virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0;
99 /// Register the case-attribute: this attribute is checked only if its case is selected
100 virtual void registerCase(std::string theFeature, std::string theAttribute,
101 std::string theSwitchId, std::string theCaseId) = 0;
103 /// Returns true if the attribute must be checked (the case is selected)
104 virtual bool isCase(FeaturePtr theFeature, std::string theAttribute) = 0;
107 /// Get instance from Session
108 ModelAPI_ValidatorsFactory()