]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_Validator.h
Salome HOME
473f8e4024d3cee29e330e3b2c46e56a44d111eb
[modules/shaper.git] / src / Model / Model_Validator.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #ifndef Model_Validator_H_
21 #define Model_Validator_H_
22
23 #include <Model.h>
24 #include <ModelAPI_Validator.h>
25 #include <map>
26 #include <set>
27
28 /**\class Model_ValidatorsFactory
29  * \ingroup DataModel
30  * \brief Manages the registered validators
31  *
32  * Allows to get a validator by the feature identifier and 
33  * the attribute identifier (if attribute is validated).
34  * All accessible validators mustbe registered by the ID string first.
35  * The instance of this factory can be get in the Session.
36  * Keeps the validator objects alive and just returns one of it by request.
37  * All the needed information is provided to the validator as an argument,
38  * this allows to work with them independently from the feature specific object.
39  */
40 class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
41 {
42  private:
43   std::map<std::string, ModelAPI_Validator*> myIDs;  ///< map from ID to registered validator
44   /// validators IDs to list of arguments
45   typedef std::map<std::string, std::list<std::string> > AttrValidators;
46   /// validators IDs by feature ID
47   std::map<std::string, AttrValidators> myFeatures;
48   /// validators IDs and arguments by feature and attribute IDs
49   std::map<std::string, std::map<std::string, AttrValidators> > myAttrs;
50   /// Stores the registered attributes that leads to the concealment of referenced objects in
51   /// data tree. Map from feature kind to set of attribute IDs.
52   std::map<std::string, std::set<std::string> > myConcealed;
53   /// Stores the registered attributes must be checked only if the particular case is activated
54   /// Map from feature kind to map of attribute IDs to pair
55   // (switchId (ID of the attribute) and case Ids (possible values of the switch attribute))
56   std::map<std::string, std::map<std::string,
57           std::map<std::string, std::set<std::string> > > > myCases;
58
59  public:
60   /// Registers the instance of the validator by the ID
61   MODEL_EXPORT virtual void registerValidator(const std::string& theID,
62                                               ModelAPI_Validator* theValidator);
63
64   /// Assigns validator to the feature
65   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
66                                             const std::string& theFeatureID);
67
68   /// Assigns validator to the feature with arguments of the validator
69   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
70                                             const std::string& theFeatureID,
71                                             const std::list<std::string>& theArguments);
72
73   /// Assigns validator to the attribute of the feature
74   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
75                                             const std::string& theFeatureID,
76                                             const std::string& theAttrID,
77                                             const std::list<std::string>& theArguments);
78
79   /// Provides a validator for the feature, returns NULL if no validator
80   MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
81                                        Validators& theResult) const;
82   /// Provides a validator for the attribute, returns NULL if no validator
83   MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
84     const std::string& theAttrID, Validators& theResult) const;
85
86   /// Returns registered validator by its Id
87   MODEL_EXPORT virtual const ModelAPI_Validator* validator(const std::string& theID) const;
88
89   /// Returns true if feature and all its attributes are valid.
90   MODEL_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
91
92   /// Returns true if the attribute is valid.
93   MODEL_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
94                                      std::string& theValidator, Events_InfoMessage& theError) const;
95
96   /// register that this attribute in feature is not obligatory for the feature execution
97   /// so, it is not needed for the standard validation mechanism
98   virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
99
100   /// Returns true if the attribute in feature is not obligatory for the feature execution
101   virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
102
103   /// register that this attribute conceals in the object browser
104   /// all referenced features after execution
105   virtual void registerConcealment(std::string theFeature, std::string theAttribute);
106
107   /// Returns true that it was registered that attribute conceals the referenced result
108   virtual bool isConcealed(std::string theFeature, std::string theAttribute);
109
110   /// register the case-attribute (\a myCases set definition)
111   virtual void registerCase(std::string theFeature, std::string theAttribute,
112                             const std::list<std::pair<std::string, std::string> >& theCases);
113
114   /// Returns true if the attribute must be checked (the case is selected)
115   virtual bool isCase(FeaturePtr theFeature, std::string theAttribute);
116
117
118 protected:
119   /// Adds the defualt validators that are usefull for all features.
120   void addDefaultValidators(Validators& theValidators) const;
121   /// Adds the defualt validators that are usefull for all attributes.
122   void addDefaultAttributeValidators(Validators& theValidators) const;
123   /// Get instance from Session
124   Model_ValidatorsFactory();
125
126   friend class Model_Session;
127 };
128
129 #endif