Debian Codegraph @

include/ifilter.h

raw
1 #pragma once
2
3 #include "imodule.h"
4 #include "inode.h"
5
6 #include <memory>
7 #include <vector>
8 #include <cassert>
9
10 #include <sigc++/signal.h>
11
12 /**
13 * This structure defines a simple filtercriterion as used by the Filtersystem
14 */
15 class FilterRule
16 {
17 public:
18 enum Type
19 {
20 TYPE_TEXTURE,
21 TYPE_ENTITYCLASS,
22 TYPE_OBJECT,
23 TYPE_ENTITYKEYVALUE,
24 };
25
26 // The rule type
27 Type type;
28
29 // The entity key, only applies for type "entitykeyvalue"
30 std::string entityKey;
31
32 // the match expression regex
33 std::string match;
34
35 // true for action="show", false for action="hide"
36 bool show;
37
38 private:
39 // Private Constructor, use the named constructors below
40 FilterRule(const Type type_, const std::string& match_, bool show_) :
41 type(type_),
42 match(match_),
43 show(show_)
44 {}
45
46 // Alternative private constructor for the entityKeyValue type
47 FilterRule(const Type type_, const std::string& entityKey_, const std::string& match_, bool show_) :
48 type(type_),
49 entityKey(entityKey_),
50 match(match_),
51 show(show_)
52 {}
53
54 public:
55 // Named constructors
56
57 // Regular constructor for the non-entitykeyvalue types
58 static FilterRule Create(const Type type, const std::string& match, bool show)
59 {
60 assert(type != TYPE_ENTITYKEYVALUE);
61
62 return FilterRule(type, match, show);
63 }
64
65 // Constructor for the entity key value type
66 static FilterRule CreateEntityKeyValueRule(const std::string& key, const std::string& match, bool show)
67 {
68 return FilterRule(TYPE_ENTITYKEYVALUE, key, match, show);
69 }
70 };
71 typedef std::vector<FilterRule> FilterRules;
72
73 const char* const MODULE_FILTERSYSTEM = "FilterSystem";
74
75 // Forward declaration
76 class Entity;
77
78 namespace filters
79 {
80
81 const char* const SELECT_OBJECTS_BY_FILTER_CMD = "SelectObjectsByFilter";
82 const char* const DESELECT_OBJECTS_BY_FILTER_CMD = "DeselectObjectsByFilter";
83
84 /**
85 * \brief
86 * Interface for the FilterSystem
87 *
88 * The filter system provides a mechanism by which certain objects or materials
89 * can be hidden from rendered views.
90 */
91 class IFilterSystem :
92 public RegisterableModule
93 {
94 public:
95
96 // Signal emitted when the state of filters has changed,
97 // filters have been added or removed, or when rules have been altered
98 virtual sigc::signal<void> filterConfigChangedSignal() const = 0;
99
100 // Signal emitted when filters are added, removed or renamed
101 virtual sigc::signal<void> filterCollectionChangedSignal() const = 0;
102
103 /**
104 * greebo: Updates all the "Filtered" status of all Instances
105 * in the scenegraph based on the current filter settings.
106 */
107 virtual void update() = 0;
108
109 /**
110 * greebo: Lets the filtersystem update the specified subgraph only,
111 * which includes the given node and all children.
112 */
113 virtual void updateSubgraph(const scene::INodePtr& root) = 0;
114
115 /**
116 * Visit the available filters, passing each filter's text name to the visitor.
117 *
118 * @param visitor
119 * Function object called with the filter name as argument.
120 */
121 virtual void forEachFilter(const std::function<void(const std::string & name)>& func) = 0;
122
123 /** Set the state of the named filter.
124 *
125 * @param filter
126 * The filter to toggle.
127 *
128 * @param state
129 * true if the filter should be active, false otherwise.
130 */
131 virtual void setFilterState(const std::string& filter, bool state) = 0;
132
133 /** greebo: Returns the state of the given filter.
134 *
135 * @returns: true or false, depending on the filter state.
136 */
137 virtual bool getFilterState(const std::string& filter) = 0;
138
139 /**
140 * Activates or deactivates all known filters.
141 */
142 virtual void setAllFilterStates(bool state) = 0;
143
144 /** greebo: Returns the event name of the given filter. This is needed
145 * to create the toggle event to menus/etc.
146 */
147 virtual std::string getFilterEventName(const std::string& filter) = 0;
148
149 /** Test if a given item should be visible or not, based on the currently-
150 * active filters.
151 *
152 * @param item
153 * The filter type to query
154 *
155 * @param name
156 * String name of the item to query.
157 *
158 * @returns
159 * true if the item is visible, false otherwise.
160 */
161 virtual bool isVisible(const FilterRule::Type type, const std::string& name) = 0;
162
163 /**
164 * Test if a given entity should be visible or not, based on the currently active filters.
165 *
166 * @param type
167 * The filter type to query
168 *
169 * @param entity
170 * The Entity to test
171 *
172 * @returns
173 * true if the entity is visible, false otherwise.
174 */
175 virtual bool isEntityVisible(const FilterRule::Type type, const Entity& entity) = 0;
176
177 // ===== API for Filter management and editing =====
178
179 /**
180 * greebo: Returns TRUE if the filter is read-only and can't be deleted.
181 */
182 virtual bool filterIsReadOnly(const std::string& filter) = 0;
183
184 /**
185 * greebo: Adds a new filter to the system with the given ruleset. The new filter
186 * is not set to read-only.
187 *
188 * @returns: TRUE on success, FALSE if the filter name already exists.
189 */
190 virtual bool addFilter(const std::string& filterName, const FilterRules& ruleSet) = 0;
191
192 /**
193 * greebo: Removes the filter, returns TRUE on success.
194 */
195 virtual bool removeFilter(const std::string& filter) = 0;
196
197 /**
198 * greebo: Renames the specified filter. This also takes care of renaming the corresponding command in the
199 * EventManager class.
200 *
201 * @returns: TRUE on success, FALSE if the filter hasn't been found or is read-only.
202 */
203 virtual bool renameFilter(const std::string& oldFilterName, const std::string& newFilterName) = 0;
204
205 /**
206 * greebo: Returns the ruleset of this filter, order is important.
207 */
208 virtual FilterRules getRuleSet(const std::string& filter) = 0;
209
210 /**
211 * greebo: Applies the given criteria set to the named filter, replacing the existing set.
212 * This applies to non-read-only filters only.
213 *
214 * @returns: TRUE on success, FALSE if filter not found or read-only.
215 */
216 virtual bool setFilterRules(const std::string& filter, const FilterRules& ruleSet) = 0;
217 };
218
219 }
220
221 inline filters::IFilterSystem& GlobalFilterSystem()
222 {
223 static module::InstanceReference<filters::IFilterSystem> _reference(MODULE_FILTERSYSTEM);
224 return _reference;
225 }