Salome HOME
Issue #1659 New widget for supporting optional inputs : correction for enclosed cases.
[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 class Events_InfoMessage;
17
18 /**\class ModelAPI_Validator
19  * \ingroup DataModel
20  * \brief Allows to validate the attribute value of a feature or the whole feature.
21  *
22  * This object is assigned by the name
23  * in the XML file to the specific attribute or to the whole feature.
24  * If validator returns "false", it is signalized in user interface
25  * and feature is not executed.
26  * Validators must be registered in the validators factory to be
27  * correctly identified by the XML string-ID.
28  */
29 class MODELAPI_EXPORT ModelAPI_Validator
30 {
31  public:
32   // Make virtual destructor in order to make the class polymorphic
33   virtual ~ModelAPI_Validator()
34   {
35   }
36 };
37
38 typedef std::shared_ptr<ModelAPI_Validator> ValidatorPtr;
39
40 /**\class ModelAPI_ValidatorsFactory
41  * \ingroup DataModel
42  * \brief Manages the registered validators
43  *
44  * Allows to get a validator by the feature identifier and 
45  * the attribute identifier (if attribute is validated).
46  * All accessible validators mustbe registered by the ID string first.
47  * The instance of this factory can be get in the Session.
48  * Keeps the validator objects alive and just returns one of it by request.
49  * All the needed information is provided to the validator as an argument,
50  * this allows to work with them independently from the feature specific object.
51  */
52 class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
53 {
54  public:
55   /// Registers the instance of the validator by the ID
56   virtual void registerValidator(const std::string& theID, ModelAPI_Validator* theValidator) = 0;
57
58   /// Assigns validator to the feature
59   virtual void assignValidator(const std::string& theID, const std::string& theFeatureID) = 0;
60
61   /// Assigns validator to the feature with arguments of the validator
62   virtual void assignValidator(const std::string& theID,
63                                             const std::string& theFeatureID,
64                                             const std::list<std::string>& theArguments) = 0;
65
66   /// Assigns validator to the attribute of the feature
67   virtual void assignValidator(const std::string& theID, const std::string& theFeatureID,
68                                const std::string& theAttrID,
69                                const std::list<std::string>& theArguments) = 0;
70
71   /// Validators is a list of pairs <Validator, list of arguments>
72   typedef std::list<std::pair<std::string, std::list<std::string> > > Validators;
73   /// Provides a validator for the feature, returns NULL if no validator
74   virtual void validators(const std::string& theFeatureID,
75                           Validators& theResult) const = 0;
76   /// Provides a validator for the attribute, returns NULL if no validator
77   virtual void validators(const std::string& theFeatureID, const std::string& theAttrID,
78                           Validators& theResult) const = 0;
79
80   /// Returns registered validator by its Id
81   virtual const ModelAPI_Validator* validator(const std::string& theID) const = 0;
82
83   /// Returns true if feature and all its attributes are valid.
84   virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
85
86   /// Returns true if the attribute is valid.
87   virtual bool validate(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
88                         std::string& theValidator, Events_InfoMessage& theError) const = 0;
89
90   /// register that this attribute in feature is not obligatory for the feature execution
91   /// so, it is not needed for the standard validation mechanism
92   virtual void registerNotObligatory(std::string theFeature, std::string theAttribute) = 0;
93
94   /// Returns true if the attribute in feature is not obligatory for the feature execution
95   virtual bool isNotObligatory(std::string theFeature, std::string theAttribute) = 0;
96
97   /// register that this attribute conceals in the object browser
98   /// all referenced features after execution
99   virtual void registerConcealment(std::string theFeature, std::string theAttribute) = 0;
100
101   /// Returns true that it was registered that attribute conceals the referenced result
102   virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0;
103
104   /// Register the case-attribute: this attribute is checked only if its case is selected
105   virtual void registerCase(std::string theFeature, std::string theAttribute,
106     const std::list<std::pair<std::string, std::string> >& theCases) = 0;
107
108  /// Returns true if the attribute must be checked (the case is selected)
109   virtual bool isCase(FeaturePtr theFeature, std::string theAttribute) = 0;
110
111  protected:
112   /// Get instance from Session
113   ModelAPI_ValidatorsFactory()
114   {
115   }
116 };
117
118 #endif