]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_FilterFactory.h
Salome HOME
It is a filters implementation to be set in the XML file.
[modules/shaper.git] / src / ModuleBase / ModuleBase_FilterFactory.h
1 // File:        ModuleBase_FilterFactory.h
2 // Created:     10 Dec 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #ifndef ModuleBase_FilterFactory_H
6 #define ModeleBase_SelectionFilterFactory_H
7
8 #include "ModuleBase.h"
9 #include "ModuleBase_IWorkshop.h"
10
11 #include <map>
12 #include <set>
13
14 class ModuleBase_Filter;
15
16 /**\class ModuleBase_FilterFactory
17  * \ingroup ModelBase
18  * \breif Manages the registered selection filters
19  *
20  * Allows to get a selection filter by the feature identifier and 
21  * the attribute identifier (if attribute is validated).
22  * All accessible filters must be registered by the ID string first.
23  * The instance of this factory can be get in the Workshop.
24  * Keeps the validator objects alive and just returns one of it by request.
25  * All the needed information is provided to the validator as an argument,
26  * this allows to work with them independently from the feature specific object.
27  */
28 class ModuleBase_FilterFactory : public QObject
29 {
30  public:
31
32    //ModuleBase_FilterFactory();
33    //virtual ~ModuleBase_FilterFactory() {}
34
35
36  private:
37   std::map<std::string, ModuleBase_Filter*> myIDs;  ///< map from ID to registered validator
38   /// validators IDs to list of arguments
39   typedef std::map<std::string, std::list<std::string> > AttrValidators;
40   /// validators IDs by feature ID
41   std::map<std::string, AttrValidators> myFeatures;
42   /// validators IDs and arguments by feature and attribute IDs
43   std::map<std::string, std::map<std::string, AttrValidators> > myAttrs;
44   /// Stores the registered attributes that leads to the concealment of referenced objects in 
45   /// data tree. Map from feature kind to set of attribute IDs.
46   std::map<std::string, std::set<std::string> > myConcealed;
47
48  public:
49   /// Registers the instance of the validator by the ID
50   MODULEBASE_EXPORT virtual void registerFilter(const std::string& theID,
51                                                 ModuleBase_Filter* theValidator);
52
53   /// Assigns validator to the attribute of the feature
54   MODULEBASE_EXPORT virtual void assignFilter(const std::string& theID,
55                                             const std::string& theFeatureID,
56                                             const std::string& theAttrID);
57
58   /// Provides a validator for the feature, returns NULL if no validator
59   MODULEBASE_EXPORT virtual void validators(const std::string& theFeatureID,
60                                        std::list<ModuleBase_Filter*>& theResult,
61                                        std::list<std::list<std::string> >& theArguments) const;
62   /// Provides a validator for the attribute, returns NULL if no validator
63   MODULEBASE_EXPORT virtual void validators(const std::string& theFeatureID,
64                                        const std::string& theAttrID,
65                                        std::list<ModuleBase_Filter*>& theValidators,
66                                        std::list<std::list<std::string> >& theArguments) const;
67
68   /// Returns registered validator by its Id
69   MODULEBASE_EXPORT virtual const ModuleBase_Filter* validator(const std::string& theID) const;
70
71   /// Returns true if feature and all its attributes are valid.
72   MODULEBASE_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
73
74   /// register that this attribute in feature is not obligatory for the feature execution
75   /// so, it is not needed for the standard validation mechanism
76   virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
77
78   /// Returns true if the attribute in feature is not obligatory for the feature execution
79   virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
80
81   /// register that this attribute conceals in the object browser
82   /// all referenced features after execution
83   virtual void registerConcealment(std::string theFeature, std::string theAttribute);
84
85   /// Returns true that it was registered that attribute conceals the referenced result
86   virtual bool isConcealed(std::string theFeature, std::string theAttribute);
87
88 protected:
89   void addDefaultValidators(std::list<ModuleBase_Filter*>& theValidators) const;
90   /// Get instance from workshop
91
92   ModuleBase_FilterFactory();
93
94   ~ModuleBase_FilterFactory() {}
95
96   friend class ModuleBase_IWorkshop;
97
98 };
99
100 #endif //ModuleBase_FilterFactory