]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/ModelAPI_Validator.h
Salome HOME
Processing of "Validators" in XML
[modules/shaper.git] / src / ModelAPI / ModelAPI_Validator.h
1 // File:        ModelAPI_Validator.hxx
2 // Created:     2 Jul 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef ModelAPI_Validator_HeaderFile
6 #define ModelAPI_Validator_HeaderFile
7
8 #include <ModelAPI.h>
9 #include <boost/shared_ptr.hpp>
10 #include <list>
11
12 class ModelAPI_Feature;
13
14 /**\class ModelAPI_Validator
15  * \ingroup DataModel
16  * \brief Allows to validate the attribute value of a feature or the whole feature.
17  *
18  * This object is assigned by the name
19  * in the XML file to the specific attribute or to the whole feature.
20  * If validator returns "false", it is signalized in user interface
21  * and feature is not executed.
22  * Validators must be registered in the validators factory to be
23  * correctly identified by the XML string-ID.
24  */
25 class MODELAPI_EXPORT ModelAPI_Validator
26 {
27 public:
28   /// Returns true if feature and/or attributes are valid
29   /// \param theFeature the validated feature
30   /// \param theAttr the validated attribute ID, empty string of feature is validated
31   /// \param theArguments list of string, feature attribute names: dependent attributes
32   virtual bool validate(const boost::shared_ptr<ModelAPI_Feature>& theFeature,
33     const std::string theAttr, std::list<std::string> theArguments) const = 0;
34 };
35
36 typedef boost::shared_ptr<ModelAPI_Validator> ValidatorPtr;
37
38 /**\class ModelAPI_ValidatorsFactory
39  * \ingroup DataModel
40  * \breif Manages the registered validators
41  *
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 PluginManager.
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.
49  */
50 class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
51 {
52 public:
53   /// Registers the instance of the validator by the ID
54   virtual void registerValidator(const std::string& theID, ModelAPI_Validator* theValidator) = 0;
55
56   /// Assigns validator to the feature
57   virtual void assignValidator(const std::string& theID, const std::string& theFeatureID) = 0;
58
59   /// Assigns validator to the attribute of the feature
60   virtual void assignValidator(const std::string& theID, 
61     const std::string& theFeatureID, const std::string& theAttrID,
62     const std::list<std::string>& theArguments) = 0;
63
64   /// Provides a validator for the feature, returns NULL if no validator
65   virtual const ModelAPI_Validator* validator(const std::string& theFeatureID) const = 0;
66
67   /// Returns the result of "validate" method for attribute of validator.
68   /// If validator is not exists, returns true: everything is valid by default.
69   virtual bool validate(
70     const boost::shared_ptr<ModelAPI_Feature>& theFeature, const std::string& theAttrID) const = 0;
71
72 protected:
73   /// Get instance from PluginManager
74   ModelAPI_ValidatorsFactory() {}
75 };
76
77 #endif