Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[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 <ModelAPI_Feature.h>
12 #include <memory>
13 #include <list>
14
15 class ModelAPI_Feature;
16
17 /**\class ModelAPI_Validator
18  * \ingroup DataModel
19  * \brief Allows to validate the attribute value of a feature or the whole feature.
20  *
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.
27  */
28 class MODELAPI_EXPORT ModelAPI_Validator
29 {
30  public:
31   // Make virtual destructor in order to make the class polymorphic
32   virtual ~ModelAPI_Validator()
33   {
34   }
35 };
36
37 typedef std::shared_ptr<ModelAPI_Validator> ValidatorPtr;
38
39 /**\class ModelAPI_ValidatorsFactory
40  * \ingroup DataModel
41  * \brief Manages the registered validators
42  *
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.
50  */
51 class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
52 {
53  public:
54   /// Registers the instance of the validator by the ID
55   virtual void registerValidator(const std::string& theID, ModelAPI_Validator* theValidator) = 0;
56
57   /// Assigns validator to the feature
58   virtual void assignValidator(const std::string& theID, const std::string& theFeatureID) = 0;
59
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;
64
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;
69
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;
78
79   /// Returns registered validator by its Id
80   virtual const ModelAPI_Validator* validator(const std::string& theID) const = 0;
81
82   /// Returns true if feature and all its attributes are valid.
83   virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
84
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;
88
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;
91
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;
95
96   /// Returns true that it was registered that attribute conceals the referenced result
97   virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0;
98
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;
102
103  /// Returns true if the attribute must be checked (the case is selected)
104   virtual bool isCase(FeaturePtr theFeature, std::string theAttribute) = 0;
105
106  protected:
107   /// Get instance from Session
108   ModelAPI_ValidatorsFactory()
109   {
110   }
111 };
112
113 #endif