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