Salome HOME
Fix for hang up (and crash after) on remove of all features in the complicated model...
[modules/shaper.git] / src / ModelAPI / ModelAPI_Validator.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Validator.hxx
4 // Created:     2 Jul 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef ModelAPI_Validator_H_
8 #define ModelAPI_Validator_H_
9
10 #include <ModelAPI.h>
11 #include <ModelAPI_Feature.h>
12 #include <memory>
13 #include <list>
14
15 class ModelAPI_Feature;
16
17 /**\class ModelAPI_Validator
18  * \ingroup DataModel
19  * \brief Allows to validate the attribute value of a feature or the whole feature.
20  *
21  * This object is assigned by the name
22  * in the XML file to the specific attribute or to the whole feature.
23  * If validator returns "false", it is signalized in user interface
24  * and feature is not executed.
25  * Validators must be registered in the validators factory to be
26  * correctly identified by the XML string-ID.
27  */
28 class MODELAPI_EXPORT ModelAPI_Validator
29 {
30  public:
31   // Make virtual destructor in order to make the class polymorphic
32   virtual ~ModelAPI_Validator()
33   {
34   }
35 };
36
37 typedef std::shared_ptr<ModelAPI_Validator> ValidatorPtr;
38
39 /**\class ModelAPI_ValidatorsFactory
40  * \ingroup DataModel
41  * \brief Manages the registered validators
42  *
43  * Allows to get a validator by the feature identifier and 
44  * the attribute identifier (if attribute is validated).
45  * All accessible validators mustbe registered by the ID string first.
46  * The instance of this factory can be get in the Session.
47  * Keeps the validator objects alive and just returns one of it by request.
48  * All the needed information is provided to the validator as an argument,
49  * this allows to work with them independently from the feature specific object.
50  */
51 class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
52 {
53  public:
54   /// Registers the instance of the validator by the ID
55   virtual void registerValidator(const std::string& theID, ModelAPI_Validator* theValidator) = 0;
56
57   /// Assigns validator to the feature
58   virtual void assignValidator(const std::string& theID, const std::string& theFeatureID) = 0;
59
60   /// Assigns validator to the feature with arguments of the validator
61   virtual void assignValidator(const std::string& theID,
62                                             const std::string& theFeatureID,
63                                             const std::list<std::string>& theArguments) = 0;
64
65   /// Assigns validator to the attribute of the feature
66   virtual void assignValidator(const std::string& theID, const std::string& theFeatureID,
67                                const std::string& theAttrID,
68                                const std::list<std::string>& theArguments) = 0;
69
70   /// Validators is a list of pairs <Validator, list of arguments>
71   typedef std::list<std::pair<std::string, std::list<std::string> > > Validators;
72   /// Provides a validator for the feature, returns NULL if no validator
73   virtual void validators(const std::string& theFeatureID,
74                           Validators& theResult) const = 0;
75   /// Provides a validator for the attribute, returns NULL if no validator
76   virtual void validators(const std::string& theFeatureID, const std::string& theAttrID,
77                           Validators& theResult) const = 0;
78
79   /// Returns registered validator by its Id
80   virtual const ModelAPI_Validator* validator(const std::string& theID) const = 0;
81
82   /// Returns true if feature and all its attributes are valid.
83   virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
84
85   /// Returns true if the attribute is valid.
86   virtual bool validate(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
87                         std::string& theValidator, std::string& theError) const = 0;
88
89   /// register that this attribute in feature is not obligatory for the feature execution
90   /// so, it is not needed for the standard validation mechanism
91   virtual void registerNotObligatory(std::string theFeature, std::string theAttribute) = 0;
92
93   /// Returns true if the attribute in feature is not obligatory for the feature execution
94   virtual bool isNotObligatory(std::string theFeature, std::string theAttribute) = 0;
95
96   /// register that this attribute conceals in the object browser
97   /// all referenced features after execution
98   virtual void registerConcealment(std::string theFeature, std::string theAttribute) = 0;
99
100   /// Returns true that it was registered that attribute conceals the referenced result
101   virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0;
102
103   /// Register the case-attribute: this attribute is checked only if its case is selected
104   virtual void registerCase(std::string theFeature, std::string theAttribute,
105     std::string theSwitchId, std::string theCaseId) = 0;
106
107  /// Returns true if the attribute must be checked (the case is selected)
108   virtual bool isCase(FeaturePtr theFeature, std::string theAttribute) = 0;
109
110  protected:
111   /// Get instance from Session
112   ModelAPI_ValidatorsFactory()
113   {
114   }
115 };
116
117 #endif