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