Salome HOME
No automatic rebuild: only on preview. Update of visualization behavior due to the...
[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_H_
6 #define ModelAPI_Validator_H_
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   // Make virtual destructor in order to make the class polymorphic
29   virtual ~ModelAPI_Validator()
30   {
31   }
32 };
33
34 typedef boost::shared_ptr<ModelAPI_Validator> ValidatorPtr;
35
36 /**\class ModelAPI_ValidatorsFactory
37  * \ingroup DataModel
38  * \breif Manages the registered validators
39  *
40  * Allows to get a validator by the feature identifier and 
41  * the attribute identifier (if attribute is validated).
42  * All accessible validators mustbe registered by the ID string first.
43  * The instance of this factory can be get in the Session.
44  * Keeps the validator objects alive and just returns one of it by request.
45  * All the needed information is provided to the validator as an argument,
46  * this allows to work with them independently from the feature specific object.
47  */
48 class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
49 {
50  public:
51   /// Registers the instance of the validator by the ID
52   virtual void registerValidator(const std::string& theID, ModelAPI_Validator* theValidator) = 0;
53
54   /// Assigns validator to the feature
55   virtual void assignValidator(const std::string& theID, const std::string& theFeatureID) = 0;
56
57   /// Assigns validator to the feature with arguments of the validator
58   virtual void assignValidator(const std::string& theID,
59                                             const std::string& theFeatureID,
60                                             const std::list<std::string>& theArguments) = 0;
61
62   /// Assigns validator to the attribute of the feature
63   virtual void assignValidator(const std::string& theID, const std::string& theFeatureID,
64                                const std::string& theAttrID,
65                                const std::list<std::string>& theArguments) = 0;
66
67   /// Provides a validator for the feature, returns NULL if no validator
68   virtual void validators(const std::string& theFeatureID,
69                           std::list<ModelAPI_Validator*>& theResult,
70                           std::list<std::list<std::string> >& theArguments) const = 0;
71   /// Provides a validator for the attribute, returns NULL if no validator
72   virtual void validators(const std::string& theFeatureID, const std::string& theAttrID,
73                           std::list<ModelAPI_Validator*>& theValidators,
74                           std::list<std::list<std::string> >& theArguments) const = 0;
75
76   /// Returns registered validator by its Id
77   virtual const ModelAPI_Validator* validator(const std::string& theID) const = 0;
78
79   /// Returns true if feature and all its attributes are valid.
80   virtual bool validate(const boost::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
81
82  protected:
83   /// Get instance from Session
84   ModelAPI_ValidatorsFactory()
85   {
86   }
87 };
88
89 #endif