Ocean
interaction/Library.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_LIBRARY_H
9 #define META_OCEAN_INTERACTION_LIBRARY_H
10 
13 
14 #include "ocean/base/Timestamp.h"
15 
16 #include "ocean/rendering/Engine.h"
17 
18 namespace Ocean
19 {
20 
21 namespace Interaction
22 {
23 
24 /**
25  * This class implements the base class for all interaction libraries.
26  * @ingroup interaction
27  */
28 class OCEAN_INTERACTION_EXPORT Library
29 {
30  friend class Manager;
31 
32  public:
33 
34  /**
35  * Definition of a map mapping file extensions to file type descriptions.
36  */
37  typedef std::map<std::string, std::string> FileExtensions;
38 
39  public:
40 
41  /**
42  * Returns the name of this library.
43  * @return Library name
44  */
45  inline const std::string& name() const;
46 
47  /**
48  * Returns whether a specified file extension is supported by this interaction plugin.
49  * @param extension File extension to check
50  * @return True, if suo
51  */
52  virtual bool isFileExtensionSupported(const std::string& extension) const;
53 
54  /**
55  * Loads a new interaction file.
56  * @param userInterface The application's UI elements
57  * @param engine Current engine
58  * @param timestamp Recent timestmap
59  * @param filename Name of the interaction file to load
60  * @return True, if succeeded
61  */
62  virtual bool load(const UserInterface& userInterface, const Rendering::EngineRef& engine, const Timestamp timestamp, const std::string& filename) = 0;
63 
64  /**
65  * Unloads one specific loaded interaction files.
66  * @param userInterface The application's UI elements
67  * @param engine Current engine
68  * @param timestamp Recent timestmap
69  * @param filename Filename of the interaction to be unloaded
70  * @return True, if succeeded
71  * @see Manager::unload().
72  */
73  virtual bool unload(const UserInterface& userInterface, const Rendering::EngineRef& engine, const Timestamp timestamp, const std::string& filename) = 0;
74 
75  /**
76  * Unloads all loaded scripts.
77  * @param userInterface The application's UI elements
78  * @param engine Current engine
79  * @param timestamp Recent timestmap
80  */
81  virtual void unload(const UserInterface& userInterface, const Rendering::EngineRef& engine, const Timestamp timestamp) = 0;
82 
83  /**
84  * Pre file load interaction function.
85  * @param userInterface The application's UI elements
86  * @param filename Filename of the file to be loaded
87  */
88  virtual void preFileLoad(const UserInterface& userInterface, const std::string& filename);
89 
90  /**
91  * Post file load interaction function.
92  * @param userInterface The application's UI elements
93  * @param filename Filename of the loaded filename
94  * @param succeeded State determining whether the file has been loaded successfully
95  */
96  virtual void postFileLoad(const UserInterface& userInterface, const std::string& filename, const bool succeeded);
97 
98  /**
99  * Pre update interaction function.
100  * This function is invoked before each update process, the application interaction module has the possibility to return a different preferred update timestamp.
101  * @param userInterface The application's UI elements
102  * @param engine Engine to be updated, must be valid
103  * @param view The view which will be used to render, must be valid
104  * @param timestamp Recent update timestmap
105  * @return Timestamp which should be used for the update process, if the timestamp is null any timestamp can be used
106  */
107  virtual Timestamp preUpdate(const UserInterface& userInterface, const Rendering::EngineRef& engine, const Rendering::ViewRef& view, const Timestamp timestamp);
108 
109  /**
110  * Post update interaction function.
111  * @param userInterface The application's UI elements
112  * @param engine Engine which has been updated, must be valid
113  * @param view The view which will be used to render, must be valid
114  * @param timestamp Recent update timestamp
115  */
116  virtual void postUpdate(const UserInterface& userInterface, const Rendering::EngineRef& engine, const Rendering::ViewRef& view, const Timestamp timestamp);
117 
118  /**
119  * Mouse press event function.
120  * @param userInterface The application's UI elements
121  * @param engine Rendering engine currently used
122  * @param button Pressed mouse button
123  * @param screenPosition 2D screen position of the mouse cursor
124  * @param ray 3D picking ray
125  * @param pickedObject Name of the possible picked object
126  * @param pickedPosition Possible intersection point between mouse-pick-ray and 3D object
127  * @param timestamp Event timestamp
128  */
129  virtual 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);
130 
131  /**
132  * Mouse move event function.
133  * @param userInterface The application's UI elements
134  * @param engine Rendering engine currently used
135  * @param button Pressed mouse button
136  * @param screenPosition 2D screen position of the mouse cursor
137  * @param ray 3D picking ray
138  * @param pickedObject Name of the possible picked object
139  * @param pickedPosition Possible intersection point between mouse-pick-ray and 3D object
140  * @param timestamp Event timestamp
141  */
142  virtual 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);
143 
144  /**
145  * Mouse release event function.
146  * @param userInterface The application's UI elements
147  * @param engine Rendering engine currently used
148  * @param button Released mouse button
149  * @param screenPosition 2D screen position of the mouse cursor
150  * @param ray 3D picking ray
151  * @param pickedObject Name of the possible picked object
152  * @param pickedPosition Possible intersection point between mouse-pick-ray and 3D object
153  * @param timestamp Event timestamp
154  */
155  virtual 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);
156 
157  /**
158  * Key press function.
159  * @param userInterface The application's UI elements
160  * @param engine Rendering engine currently used
161  * @param key Key which has been pressed
162  * @param timestamp Event timestamp
163  */
164  virtual void onKeyPress(const UserInterface& userInterface, const Rendering::EngineRef& engine, const std::string& key, const Timestamp timestamp);
165 
166  /**
167  * Key release 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  virtual void onKeyRelease(const UserInterface& userInterface, const Rendering::EngineRef& engine, const std::string& key, const Timestamp timestamp);
174 
175  /**
176  * Releases this library.
177  */
178  virtual void release();
179 
180  protected:
181 
182  /**
183  * Creates a new library object.
184  * @param name The name of the library
185  */
186  Library(const std::string& name);
187 
188  /**
189  * Destructs a library object.
190  */
191  virtual ~Library();
192 
193  /**
194  * Returns all registered file extensions.
195  * @return Registered file extensions
196  */
197  inline FileExtensions registeredFileExtensions() const;
198 
199  /**
200  * Registers an additional file extension.
201  * @param extension New file extension to register
202  * @param description Description of the file type
203  */
204  void registerFileExtension(const std::string& extension, const std::string& description);
205 
206  /**
207  * Registers a library at the manager.
208  * Each library should be registered at most once.
209  * @param library Library to register
210  * @return True, if the library hasn't been registered before
211  */
212  static bool registerFactory(Library& library);
213 
214  /**
215  * Unregisters a library at the manager.
216  * @param library Name of the library to unregister
217  * @return True, if succeeded
218  */
219  static bool unregisterLibrary(const std::string& library);
220 
221  protected:
222 
223  /**
224  * Disabled copy constructor.
225  * @param library Object which would be copied
226  */
227  Library(const Library& library) = delete;
228 
229  /**
230  * Disabled copy operator.
231  * @param library Object which would be copied
232  * @return Reference to this object
233  */
234  Library& operator=(const Library& library) = delete;
235 
236  protected:
237 
238  /// Library name.
239  std::string libraryName;
240 
241  /// Map holding accepted file extensions supported by this library.
243 };
244 
245 inline const std::string& Library::name() const
246 {
247  return libraryName;
248 }
249 
251 {
252  return libraryFileExtensions;
253 }
254 
255 }
256 
257 }
258 
259 #endif // META_OCEAN_INTERACTION_LIBRARY_H
This class implements the base class for all interaction libraries.
Definition: interaction/Library.h:29
void registerFileExtension(const std::string &extension, const std::string &description)
Registers an additional file extension.
virtual void onKeyRelease(const UserInterface &userInterface, const Rendering::EngineRef &engine, const std::string &key, const Timestamp timestamp)
Key release function.
virtual bool unload(const UserInterface &userInterface, const Rendering::EngineRef &engine, const Timestamp timestamp, const std::string &filename)=0
Unloads one specific loaded interaction files.
virtual 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.
Library(const Library &library)=delete
Disabled copy constructor.
virtual bool isFileExtensionSupported(const std::string &extension) const
Returns whether a specified file extension is supported by this interaction plugin.
FileExtensions libraryFileExtensions
Map holding accepted file extensions supported by this library.
Definition: interaction/Library.h:242
const std::string & name() const
Returns the name of this library.
Definition: interaction/Library.h:245
virtual void postFileLoad(const UserInterface &userInterface, const std::string &filename, const bool succeeded)
Post file load interaction function.
virtual 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.
virtual void preFileLoad(const UserInterface &userInterface, const std::string &filename)
Pre file load interaction function.
virtual 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.
virtual ~Library()
Destructs a library object.
Library & operator=(const Library &library)=delete
Disabled copy operator.
virtual Timestamp preUpdate(const UserInterface &userInterface, const Rendering::EngineRef &engine, const Rendering::ViewRef &view, const Timestamp timestamp)
Pre update interaction function.
virtual void release()
Releases this library.
static bool registerFactory(Library &library)
Registers a library at the manager.
std::string libraryName
Library name.
Definition: interaction/Library.h:239
static bool unregisterLibrary(const std::string &library)
Unregisters a library at the manager.
virtual void unload(const UserInterface &userInterface, const Rendering::EngineRef &engine, const Timestamp timestamp)=0
Unloads all loaded scripts.
FileExtensions registeredFileExtensions() const
Returns all registered file extensions.
Definition: interaction/Library.h:250
virtual void onKeyPress(const UserInterface &userInterface, const Rendering::EngineRef &engine, const std::string &key, const Timestamp timestamp)
Key press function.
Library(const std::string &name)
Creates a new library object.
std::map< std::string, std::string > FileExtensions
Definition of a map mapping file extensions to file type descriptions.
Definition: interaction/Library.h:37
virtual bool load(const UserInterface &userInterface, const Rendering::EngineRef &engine, const Timestamp timestamp, const std::string &filename)=0
Loads a new interaction file.
virtual void postUpdate(const UserInterface &userInterface, const Rendering::EngineRef &engine, const Rendering::ViewRef &view, const Timestamp timestamp)
Post update interaction function.
This class implements the manager for all interaction libraries / plugins.
Definition: interaction/Manager.h:32
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:70
This class implements a timestamp.
Definition: Timestamp.h:36
size_t ObjectId
Definition of a object id.
Definition: rendering/Rendering.h:59
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15