Salome HOME
Case-specific attributes validation implementation
[modules/shaper.git] / src / Model / Model_Validator.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_Validator.hxx
4 // Created:     2 Jul 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef Model_Validator_H_
8 #define Model_Validator_H_
9
10 #include <Model.h>
11 #include <ModelAPI_Validator.h>
12 #include <ModelAPI_Feature.h>
13 #include <map>
14 #include <set>
15
16 /**\class Model_ValidatorsFactory
17  * \ingroup DataModel
18  * \brief Manages the registered validators
19  *
20  * Allows to get a validator by the feature identifier and 
21  * the attribute identifier (if attribute is validated).
22  * All accessible validators mustbe registered by the ID string first.
23  * The instance of this factory can be get in the Session.
24  * Keeps the validator objects alive and just returns one of it by request.
25  * All the needed information is provided to the validator as an argument,
26  * this allows to work with them independently from the feature specific object.
27  */
28 class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
29 {
30  private:
31   std::map<std::string, ModelAPI_Validator*> myIDs;  ///< map from ID to registered validator
32   /// validators IDs to list of arguments
33   typedef std::map<std::string, std::list<std::string> > AttrValidators;
34   /// validators IDs by feature ID
35   std::map<std::string, AttrValidators> myFeatures;
36   /// validators IDs and arguments by feature and attribute IDs
37   std::map<std::string, std::map<std::string, AttrValidators> > myAttrs;
38   /// Stores the registered attributes that leads to the concealment of referenced objects in 
39   /// data tree. Map from feature kind to set of attribute IDs.
40   std::map<std::string, std::set<std::string> > myConcealed;
41   /// Stores the registered attributes must be checked only if the particular case is activated
42   /// Map from feature kind to map of attribute IDs to pair 
43   // (switchId (ID of the attribute) and case Id (possible values of the switch attribute))
44   std::map<std::string, std::map<std::string, std::pair<std::string, std::string> > > myCases;
45
46  public:
47   /// Registers the instance of the validator by the ID
48   MODEL_EXPORT virtual void registerValidator(const std::string& theID,
49                                               ModelAPI_Validator* theValidator);
50
51   /// Assigns validator to the feature
52   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
53                                             const std::string& theFeatureID);
54
55   /// Assigns validator to the feature with arguments of the validator
56   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
57                                             const std::string& theFeatureID,
58                                             const std::list<std::string>& theArguments);
59
60   /// Assigns validator to the attribute of the feature
61   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
62                                             const std::string& theFeatureID,
63                                             const std::string& theAttrID,
64                                             const std::list<std::string>& theArguments);
65
66   /// Provides a validator for the feature, returns NULL if no validator
67   MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
68                                        std::list<ModelAPI_Validator*>& theResult,
69                                        std::list<std::list<std::string> >& theArguments) const;
70   /// Provides a validator for the attribute, returns NULL if no validator
71   MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
72                                        const std::string& theAttrID,
73                                        std::list<ModelAPI_Validator*>& theValidators,
74                                        std::list<std::list<std::string> >& theArguments) const;
75
76   /// Returns registered validator by its Id
77   MODEL_EXPORT virtual const ModelAPI_Validator* validator(const std::string& theID) const;
78
79   /// Returns true if feature and all its attributes are valid.
80   MODEL_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
81
82   /// register that this attribute in feature is not obligatory for the feature execution
83   /// so, it is not needed for the standard validation mechanism
84   virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
85
86   /// Returns true if the attribute in feature is not obligatory for the feature execution
87   virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
88
89   /// register that this attribute conceals in the object browser
90   /// all referenced features after execution
91   virtual void registerConcealment(std::string theFeature, std::string theAttribute);
92
93   /// Returns true that it was registered that attribute conceals the referenced result
94   virtual bool isConcealed(std::string theFeature, std::string theAttribute);
95
96   /// register the case-attribute (\a myCases set definition)
97   virtual void registerCase(std::string theFeature, std::string theAttribute,
98     std::string theSwitchId, std::string theCaseId);
99
100   /// Returns true if the attribute must be checked (the case is selected)
101   virtual bool isCase(FeaturePtr theFeature, std::string theAttribute);
102
103
104 protected:
105   /// Adds the defualt validators that are usefull for all features.
106   void addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators,
107                             std::list<std::list<std::string> >& theArguments) const;
108   /// Get instance from Session
109   Model_ValidatorsFactory();
110
111   friend class Model_Session;
112 };
113
114 #endif