Salome HOME
Allows to append the naming name in the group.
[modules/shaper.git] / src / ModelAPI / ModelAPI_Validator.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Validator.hxx
4 // Created:     2 Jul 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef ModelAPI_Validator_H_
8 #define ModelAPI_Validator_H_
9
10 #include <ModelAPI.h>
11 #include <memory>
12 #include <list>
13
14 class ModelAPI_Feature;
15
16 /**\class ModelAPI_Validator
17  * \ingroup DataModel
18  * \brief Allows to validate the attribute value of a feature or the whole feature.
19  *
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.
26  */
27 class MODELAPI_EXPORT ModelAPI_Validator
28 {
29  public:
30   // Make virtual destructor in order to make the class polymorphic
31   virtual ~ModelAPI_Validator()
32   {
33   }
34 };
35
36 typedef std::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 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.
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 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;
63
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;
68
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;
77
78   /// Returns registered validator by its Id
79   virtual const ModelAPI_Validator* validator(const std::string& theID) const = 0;
80
81   /// Returns true if feature and all its attributes are valid.
82   virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
83
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;
87
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;
90
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;
94
95   /// Returns true that it was registered that attribute conceals the referenced result
96   virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0;
97
98  protected:
99   /// Get instance from Session
100   ModelAPI_ValidatorsFactory()
101   {
102   }
103 };
104
105 #endif