Ocean
Loading...
Searching...
No Matches
interaction/Manager.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_INTERACTION_MANAGER_H
9#define META_OCEAN_INTERACTION_MANAGER_H
10
13
16
18
19namespace Ocean
20{
21
22namespace Interaction
23{
24
25/**
26 * This class implements the manager for all interaction libraries / plugins.
27 * @ingroup interaction
28 */
29class OCEAN_INTERACTION_EXPORT Manager :
30 public IO::FileManager,
31 public Singleton<Manager>
32{
33 friend class Singleton<Manager>;
34 friend class Library;
35
36 protected:
37
38 /**
39 * Definition of a set holding registered interaction libraries.
40 */
41 using LibrarySet = std::unordered_set<Library*>;
42
43 /**
44 * Definition of a set holding names of interaction libraries.
45 */
46 using NameSet = std::unordered_set<std::string>;
47
48 /**
49 * Definition of a vector holding names.
50 */
51 using Names = std::vector<std::string>;
52
53 public:
54
55 /**
56 * Loads a new interaction file.
57 * @param userInterface The application's UI elements
58 * @param engine Current engine
59 * @param timestamp Recent timestmap
60 * @param filename Filename of the interaction to load
61 * @return True, if succeeded
62 */
63 bool load(const UserInterface& userInterface, const Rendering::EngineRef& engine, const Timestamp timestamp, const std::string& filename);
64
65 /**
66 * Unloads one specific loaded interaction files.
67 * @param userInterface The application's UI elements
68 * @param engine Current engine
69 * @param timestamp Recent timestmap
70 * @param filename Filename of the interaction to be unloaded
71 * @return True, if succeeded
72 */
73 bool unload(const UserInterface& userInterface, const Rendering::EngineRef& engine, const Timestamp timestamp, const std::string& filename);
74
75 /**
76 * Unloads all loaded interaction files.
77 * @param userInterface The application's UI elements
78 * @param engine Current engine
79 * @param timestamp Recent timestmap
80 */
81 void unload(const UserInterface& userInterface, const Rendering::EngineRef& engine, const Timestamp timestamp);
82
83 /**
84 * Returns whether currently at least one interaction library handles mouse events.
85 * Because mouse events can produce high computational overhead this test can safe computational time.
86 * @return True, if so
87 */
88 inline bool handlesMouseEvents() const;
89
90 /**
91 * Pre file load interaction function.
92 * @param userInterface The application's UI elements
93 * @param filename Filename of the file to be loaded
94 */
95 void preFileLoad(const UserInterface& userInterface, const std::string& filename);
96
97 /**
98 * Post file load interaction function.
99 * @param userInterface The application's UI elements
100 * @param filename Filename of the loaded filename
101 * @param succeeded State determining whether the file has been loaded successfully
102 */
103 void postFileLoad(const UserInterface& userInterface, const std::string& filename, const bool succeeded);
104
105 /**
106 * Pre update interaction function.
107 * This function is invoked before each update process, the application interaction module has the possibility to return a different preferred update timestamp.<br>
108 * If several interaction modules are used and each is changing the timestamp each changed timestamp is given to the next module as preferred timestamp.<br>
109 * Therefore the last registered interaction module has the possiblity to define the used timestamp.<br>
110 * @param userInterface The application's UI elements
111 * @param engine Engine to be updated, must be valid
112 * @param view The view which will be used to render, must be valid
113 * @param timestamp Recent update timestmap
114 * @return Timestamp which should be used for the update process, if the timestamp is null any timestamp can be used
115 */
116 Timestamp preUpdate(const UserInterface& userInterface, const Rendering::EngineRef& engine, const Rendering::ViewRef& view, const Timestamp timestamp);
117
118 /**
119 * Post update interaction function.
120 * @param userInterface The application's UI elements
121 * @param engine Engine which has been updated, must be valid
122 * @param view The view which will be used to render, must be valid
123 * @param timestamp Recent update timestamp
124 */
125 void postUpdate(const UserInterface& userInterface, const Rendering::EngineRef& engine, const Rendering::ViewRef& view, const Timestamp timestamp);
126
127 /**
128 * Mouse press event function.
129 * @param userInterface The application's UI elements
130 * @param engine Rendering engine currently used
131 * @param button Pressed mouse button
132 * @param screenPosition 2D screen position of the mouse cursor
133 * @param ray 3D picking ray
134 * @param pickedObject Name of the possible picked object
135 * @param pickedPosition Possible intersection point between mouse-pick-ray and 3D object
136 * @param timestamp Event timestamp
137 */
138 void onMousePress(const UserInterface& userInterface, const Rendering::EngineRef& engine, const std::string& button, const Vector2& screenPosition, const Line3& ray, const Rendering::ObjectId pickedObject, const Vector3& pickedPosition, const Timestamp timestamp);
139
140 /**
141 * Mouse move event function.
142 * @param userInterface The application's UI elements
143 * @param engine Rendering engine currently used
144 * @param button Pressed mouse button
145 * @param screenPosition 2D screen position of the mouse cursor
146 * @param ray 3D picking ray
147 * @param pickedObject Name of the possible picked object
148 * @param pickedPosition Possible intersection point between mouse-pick-ray and 3D object
149 * @param timestamp Event timestamp
150 */
151 void onMouseMove(const UserInterface& userInterface, const Rendering::EngineRef& engine, const std::string& button, const Vector2& screenPosition, const Line3& ray, const Rendering::ObjectId pickedObject, const Vector3& pickedPosition, const Timestamp timestamp);
152
153 /**
154 * Mouse release event function.
155 * @param userInterface The application's UI elements
156 * @param engine Rendering engine currently used
157 * @param button Released mouse button
158 * @param screenPosition 2D screen position of the mouse cursor
159 * @param ray 3D picking ray
160 * @param pickedObject Name of the possible picked object
161 * @param pickedPosition Possible intersection point between mouse-pick-ray and 3D object
162 * @param timestamp Event timestamp
163 */
164 void onMouseRelease(const UserInterface& userInterface, const Rendering::EngineRef& engine, const std::string& button, const Vector2& screenPosition, const Line3& ray, const Rendering::ObjectId pickedObject, const Vector3& pickedPosition, const Timestamp timestamp);
165
166 /**
167 * Key press function.
168 * @param userInterface The application's UI elements
169 * @param engine Rendering engine currently used
170 * @param key Key which has been pressed
171 * @param timestamp Event timestamp
172 */
173 void onKeyPress(const UserInterface& userInterface, const Rendering::EngineRef& engine, const std::string& key, const Timestamp timestamp);
174
175 /**
176 * Key release function.
177 * @param userInterface The application's UI elements
178 * @param engine Rendering engine currently used
179 * @param key Key which has been pressed
180 * @param timestamp Event timestamp
181 */
182 void onKeyRelease(const UserInterface& userInterface, const Rendering::EngineRef& engine, const std::string& key, const Timestamp timestamp);
183
184 /**
185 * Returns all currently supported file extensions.
186 * @see FileManager::supportedExtensions().
187 */
189
190 /**
191 * Returns the names of all currently registered libraries.
192 * @return Library names
193 */
195
196
197 /**
198 * Releases all interaction libraries.
199 */
200 void release();
201
202 /**
203 * Registers an interaction library handling mouse events.
204 * @param name The name of the library interested in mouse events
205 */
206 void registerMouseEventLibrary(const std::string& name);
207
208 /**
209 * Unregisters an interaction library handling mouse events.
210 * @param name The name of the library not interested in mouse events anymore
211 * @return True, if succeeded
212 */
213 bool unregisterMouseEventLibrary(const std::string& name);
214
215 /**
216 * Retruns the lock object of this engine.
217 * Beware: Use this lock with caution.
218 * @return Engine lock object
219 */
220 inline Lock& lock() const;
221
222 protected:
223
224 /**
225 * Creates a new manager.
226 */
228
229 /**
230 * Destructs a manager.
231 */
232 virtual ~Manager();
233
234 /**
235 * Registers a new interaction library able to read a specific interaction format.
236 * @param library Library to register
237 */
238 void registerLibrary(Library& library);
239
240 /**
241 * Unregisters a library.
242 * @param name The name of the library to unregister
243 * @return True, if succeeded
244 */
245 bool unregisterLibrary(const std::string& name);
246
247 protected:
248
249 /// Set holding all registered interaction libraries.
251
252 /**
253 * Set holding all names of libraries interested in mouse events.
254 * This set is used to decided whether mouse events should be processed for this interaction libraries.
255 */
257
258 /// Manager lock.
259 mutable Lock lock_;
260};
261
263{
264 return mouseEventLibraries_.empty() == false;
265}
266
267inline Lock& Manager::lock() const
268{
269 return lock_;
270}
271
272}
273
274}
275
276#endif // META_OCEAN_INTERACTION_MANAGER_H
This class is the base class for all plugin manager able to load and manager files.
Definition FileManager.h:26
std::map< std::string, std::string > FileExtensions
Definition of a map mapping supported file extensions to file type descriptions.
Definition FileManager.h:32
This class implements the base class for all interaction libraries.
Definition interaction/Library.h:29
This class implements the manager for all interaction libraries / plugins.
Definition interaction/Manager.h:32
bool unload(const UserInterface &userInterface, const Rendering::EngineRef &engine, const Timestamp timestamp, const std::string &filename)
Unloads one specific loaded interaction files.
void onKeyRelease(const UserInterface &userInterface, const Rendering::EngineRef &engine, const std::string &key, const Timestamp timestamp)
Key release function.
Lock & lock() const
Retruns the lock object of this engine.
Definition interaction/Manager.h:267
std::vector< std::string > Names
Definition of a vector holding names.
Definition interaction/Manager.h:51
bool handlesMouseEvents() const
Returns whether currently at least one interaction library handles mouse events.
Definition interaction/Manager.h:262
void postFileLoad(const UserInterface &userInterface, const std::string &filename, const bool succeeded)
Post file load interaction function.
void onKeyPress(const UserInterface &userInterface, const Rendering::EngineRef &engine, const std::string &key, const Timestamp timestamp)
Key press function.
void registerMouseEventLibrary(const std::string &name)
Registers an interaction library handling mouse events.
bool unregisterLibrary(const std::string &name)
Unregisters a library.
void unload(const UserInterface &userInterface, const Rendering::EngineRef &engine, const Timestamp timestamp)
Unloads all loaded interaction files.
void onMouseRelease(const UserInterface &userInterface, const Rendering::EngineRef &engine, const std::string &button, const Vector2 &screenPosition, const Line3 &ray, const Rendering::ObjectId pickedObject, const Vector3 &pickedPosition, const Timestamp timestamp)
Mouse release event function.
void preFileLoad(const UserInterface &userInterface, const std::string &filename)
Pre file load interaction function.
NameSet mouseEventLibraries_
Set holding all names of libraries interested in mouse events.
Definition interaction/Manager.h:256
Lock lock_
Manager lock.
Definition interaction/Manager.h:259
void postUpdate(const UserInterface &userInterface, const Rendering::EngineRef &engine, const Rendering::ViewRef &view, const Timestamp timestamp)
Post update interaction function.
void registerLibrary(Library &library)
Registers a new interaction library able to read a specific interaction format.
virtual ~Manager()
Destructs a manager.
bool load(const UserInterface &userInterface, const Rendering::EngineRef &engine, const Timestamp timestamp, const std::string &filename)
Loads a new interaction file.
void onMouseMove(const UserInterface &userInterface, const Rendering::EngineRef &engine, const std::string &button, const Vector2 &screenPosition, const Line3 &ray, const Rendering::ObjectId pickedObject, const Vector3 &pickedPosition, const Timestamp timestamp)
Mouse move event function.
void release()
Releases all interaction libraries.
LibrarySet librarySet_
Set holding all registered interaction libraries.
Definition interaction/Manager.h:250
Manager()
Creates a new manager.
void onMousePress(const UserInterface &userInterface, const Rendering::EngineRef &engine, const std::string &button, const Vector2 &screenPosition, const Line3 &ray, const Rendering::ObjectId pickedObject, const Vector3 &pickedPosition, const Timestamp timestamp)
Mouse press event function.
bool unregisterMouseEventLibrary(const std::string &name)
Unregisters an interaction library handling mouse events.
std::unordered_set< Library * > LibrarySet
Definition of a set holding registered interaction libraries.
Definition interaction/Manager.h:41
Timestamp preUpdate(const UserInterface &userInterface, const Rendering::EngineRef &engine, const Rendering::ViewRef &view, const Timestamp timestamp)
Pre update interaction function.
virtual FileExtensions supportedExtensions()
Returns all currently supported file extensions.
std::unordered_set< std::string > NameSet
Definition of a set holding names of interaction libraries.
Definition interaction/Manager.h:46
Names libraries() const
Returns the names of all currently registered libraries.
This class holds UI elements of the application from which the interaction is executed.
Definition UserInterface.h:28
This class implements an infinite line in 3D space.
Definition Line3.h:68
This class implements a recursive lock object.
Definition Lock.h:31
This template class is the base class for all singleton objects.
Definition Singleton.h:71
This class implements a timestamp.
Definition Timestamp.h:63
The namespace covering the entire Ocean framework.
Definition Accessor.h:15