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