Salome HOME
Issue #1786 : make Recover feature duplicate the result, not re-create a previous...
[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 <map>
13 #include <set>
14
15 /**\class Model_ValidatorsFactory
16  * \ingroup DataModel
17  * \brief Manages the registered validators
18  *
19  * Allows to get a validator by the feature identifier and 
20  * the attribute identifier (if attribute is validated).
21  * All accessible validators mustbe registered by the ID string first.
22  * The instance of this factory can be get in the Session.
23  * Keeps the validator objects alive and just returns one of it by request.
24  * All the needed information is provided to the validator as an argument,
25  * this allows to work with them independently from the feature specific object.
26  */
27 class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
28 {
29  private:
30   std::map<std::string, ModelAPI_Validator*> myIDs;  ///< map from ID to registered validator
31   /// validators IDs to list of arguments
32   typedef std::map<std::string, std::list<std::string> > AttrValidators;
33   /// validators IDs by feature ID
34   std::map<std::string, AttrValidators> myFeatures;
35   /// validators IDs and arguments by feature and attribute IDs
36   std::map<std::string, std::map<std::string, AttrValidators> > myAttrs;
37   /// Stores the registered attributes that leads to the concealment of referenced objects in
38   /// data tree. Map from feature kind to set of attribute IDs.
39   std::map<std::string, std::set<std::string> > myConcealed;
40   /// Stores the registered attributes must be checked only if the particular case is activated
41   /// Map from feature kind to map of attribute IDs to pair
42   // (switchId (ID of the attribute) and case Ids (possible values of the switch attribute))
43   std::map<std::string, std::map<std::string,
44           std::map<std::string, std::set<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                                        Validators& theResult) const;
69   /// Provides a validator for the attribute, returns NULL if no validator
70   MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
71     const std::string& theAttrID, Validators& theResult) const;
72
73   /// Returns registered validator by its Id
74   MODEL_EXPORT virtual const ModelAPI_Validator* validator(const std::string& theID) const;
75
76   /// Returns true if feature and all its attributes are valid.
77   MODEL_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
78
79   /// Returns true if the attribute is valid.
80   MODEL_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
81                                      std::string& theValidator, Events_InfoMessage& theError) const;
82
83   /// register that this attribute in feature is not obligatory for the feature execution
84   /// so, it is not needed for the standard validation mechanism
85   virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
86
87   /// Returns true if the attribute in feature is not obligatory for the feature execution
88   virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
89
90   /// register that this attribute conceals in the object browser
91   /// all referenced features after execution
92   virtual void registerConcealment(std::string theFeature, std::string theAttribute);
93
94   /// Returns true that it was registered that attribute conceals the referenced result
95   virtual bool isConcealed(std::string theFeature, std::string theAttribute);
96
97   /// register the case-attribute (\a myCases set definition)
98   virtual void registerCase(std::string theFeature, std::string theAttribute,
99                             const std::list<std::pair<std::string, std::string> >& theCases);
100
101   /// Returns true if the attribute must be checked (the case is selected)
102   virtual bool isCase(FeaturePtr theFeature, std::string theAttribute);
103
104
105 protected:
106   /// Adds the defualt validators that are usefull for all features.
107   void addDefaultValidators(Validators& theValidators) const;
108   /// Adds the defualt validators that are usefull for all attributes.
109   void addDefaultAttributeValidators(Validators& theValidators) const;
110   /// Get instance from Session
111   Model_ValidatorsFactory();
112
113   friend class Model_Session;
114 };
115
116 #endif