GlsRSOLoader API
gls_rso_loader.h
Go to the documentation of this file.
1 /*! \file gls_rso_loader.h
2 \brief The main class for loading an RSO.
3 
4 \par Copyright Information
5 
6  Copyright (c) 2013 The DiSTI Corporation.<br>
7  11301 Corporate Blvd.; Suite 100<br>
8  Orlando, Florida 32817<br>
9  USA<br>
10  <br>
11  All rights reserved.<br>
12 
13 This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36 The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38 */
39 
40 #ifndef GLS_RSO_LOADER_H_INCLUDED
41 #define GLS_RSO_LOADER_H_INCLUDED
42 
43 #include "rso_interface_2.h"
44 
45 #include <vector>
46 #include <string>
47 
48 namespace GlsRSOLoader
49 {
50  class LiveComponentLibRef;
51 
52  /** RSOReference class. Main interface for GlsRSOLoader */
54  {
56  unsigned int _rsoVersion;
57  LiveComponentLibRef* _liveComponentLibRef;
58 
59  RSOReference(const RSOReference&);
60  RSOReference& operator=(const RSOReference&);
61 
62  public:
63  /** Constructor */
64  RSOReference(disti::RSOInterface1*, LiveComponentLibRef*, unsigned int);
65 
66  /** Destructor */
67  ~RSOReference();
68 
69  /** Accessor for RSOInterface contained within this RSO Reference
70  * \return Pointer to RSOInterface instance
71  */
72  inline disti::RSOInterface1* GetRSOInterface1() { return _rso; }
73 
74  /** Gets the version number for the RSO
75  * \return The RSO version number
76  */
77  inline unsigned int GetRSOVersion() { return _rsoVersion; }
78 
79  /** Sets a resource contained within the RSO
80  * \param resourceName Resource name
81  * \param resourceVal Resource value
82  */
83  inline void SetResource(const char* resourceName, const char* resourceVal) { _rso->SetResource(resourceName, resourceVal); }
84 
85  /** CRT Insensitive version of SetResources()
86  * Parse a buffer of resource value pairs.
87  * \param buf String containing resource data
88  */
89  void SetResources(const char* buf);
90 
91  /** Gets a resource value by name
92  * \param resourceName Resource name
93  * \return Value of given resource
94  */
95  inline const char* GetResource(const char* resourceName) { return _rso->GetResource(resourceName); }
96 
97  /** Calculate method. Should be called every frame for normal operation.
98  * \param time Elapsed time, in seconds
99  */
100  inline void Calculate(double time) { _rso->Calculate(time); }
101 
102  /** Calculate transformations and perform culling. Call this before Draw()
103  * \param current Transformation matrices (Projection and Modelview) to apply
104  * \param culler Culler operation to apply on this RSO
105  */
106  inline void PreDraw(const disti::RSOInterface1::OpenGLMatrices& current, disti::RSOInterface1::Culler& culler) { _rso->PreDraw(current, culler); }
107 
108  /** Draw the object via OpenGL. Call this after PreDraw() */
109  inline void Draw() { _rso->Draw(); }
110 
111  /** Allow the object to handle an event.
112  * \param ev Event to be handled by the RSO
113  * \return true if the event was handled by the RSO
114  */
115  inline bool HandleInput(disti::RSOInterface1::Event *ev) { return _rso->HandleInput(ev); }
116 
117  /** Allow for handling events from inside the object.
118  * The emitted event handler will be passed events that are from inside the component
119  * \param handler pointer to the EmittedEventHandler object to use or NULL to remove the current event handler.
120  * \return true if this component may emit events, false if this component will never emit events.
121  */
123 
124  /** Sets the "AbsolutePlacement" property on the RSO
125  * \param value true to enable AbsolutePlacement property, false to disable it
126  */
127  void AbsolutePlacement(bool value);
128 
129  /** Gets the background color of the RSO's display frame
130  * \param r Red color component (0-255)
131  * \param g Green color component (0-255)
132  * \param b Blue color component (0-255)
133  * \param a Alpha color component (0-255)
134  */
135  void GetBackgroundColor(unsigned char &r, unsigned char &g, unsigned char &b, unsigned char &a);
136 
137  /** Get the extents of the RSO when drawn with the given transformation matrix, as a coordinate system-aligned box
138  * \param min If the method returns true, contains the point corresponding with the 1st corner of the box. If the method returns false, value is undefined.
139  * \param max If the method returns true, contains the point corresponding with the 2nd corner of the box. If the method returns false, value is undefined.
140  * \param transform Transformation matrix from A to B where A is the component’s coordinate system and B is the coordinate system to compute the bounding box in. (If NULL then identity matrix is assumed)
141  * \return true if the extents were calculated, false if the extents could not be calculated.
142  */
144 
145  /** Sets the projection of the RSO using glOrtho or gluSetPerspective. Sets the application's projection globally.
146  * \param controlWidth Width of the RSO (in pixels)
147  * \param controlHeight Height of the RSO (in pixels)
148  * \param depthFactor
149  */
150  void SetProjection(int controlWidth, int controlHeight, float depthFactor = 4.0f, float fov = 90.0f, bool perspective = false);
151 
152  /** Mouse button down event handler
153  * \param x X screen coordinate of mouse cursor's current location
154  * \param y Y screen coordinate of mouse cursor's current location
155  * \param button Mouse button pressed (see RSOInterface1::MouseEvent::MouseButtonType)
156  * \return true if event handled successfully, false otherwise
157  */
158  bool HandleMouseDown(int x, int y, int button);
159 
160  /** Mouse button up event handler
161  * \param x X screen coordinate of mouse cursor's current location
162  * \param y Y screen coordinate of mouse cursor's current location
163  * \param button Mouse button released (see RSOInterface1::MouseEvent::MouseButtonType)
164  */
165  bool HandleMouseUp(int x, int y, int button);
166 
167  /** Mouse wheel plus event handler
168  * \param x X screen coordinate of mouse cursor's current location
169  * \param y Y screen coordinate of mouse cursor's current location
170  * \param buttonMask bitfield of which mouse buttons are currently held down (see RSOInterface1::MouseEvent::MouseButtonType)
171  * \return true if event handled successfully, false otherwise
172  */
173  bool HandleMouseWheelPlus(int x, int y, int buttonMask);
174 
175  /** Mouse wheel minus event handler
176  * \param x X screen coordinate of mouse cursor's current location
177  * \param y Y screen coordinate of mouse cursor's current location
178  * \param buttonMask bitfield of which mouse buttons are currently held down (see RSOInterface1::MouseEvent::MouseButtonType)
179  * \return true if event handled successfully, false otherwise
180  */
181  bool HandleMouseWheelMinus(int x, int y, int buttonMask);
182 
183  /** Mouse button up event handler
184  * \param x X screen coordinate of mouse cursor's current location
185  * \param y Y screen coordinate of mouse cursor's current location
186  * \param buttonMask bitfield of which mouse buttons are currently held down (see RSOInterface1::MouseEvent::MouseButtonType)
187  * \return true if event handled successfully, false otherwise
188  */
189  bool HandleMouseMove(int x, int y, int buttonMask);
190 
191  /** Keyboard key down event handler
192  * \param key Key code pressed. Either ascii value or RSOInterface1::KeyboardEvent::KeySymCodeEnum (for any non-ascii key).
193  * \param x X screen coordinate of mouse cursor's current location
194  * \param y Y screen coordinate of mouse cursor's current location
195  * \return true if event handled successfully, false otherwise
196  */
197  bool HandleKeyDown(int key, int x, int y);
198 
199  /** Keyboard key up event handler
200  * \param key Key code released. Either ascii value or RSOInterface1::KeyboardEvent::KeySymCodeEnum (for any non-ascii key).
201  * \param x X screen coordinate of mouse cursor's current location
202  * \param y Y screen coordinate of mouse cursor's current location
203  * \return true if event handled successfully, false otherwise
204  */
205  bool HandleKeyUp(int key, int x, int y);
206 
207  // Additions for RSO version 2
208 
209  /** Constructs a resource handle for rapid access to the named resource (RSO v2)
210  * \param resourceName resource name
211  * \param[out] resourceHandle reference to resource handle output location
212  * \return true if successful
213  */
214  bool CreateResourceHandle(const char *resourceName, disti::RSOInterface2::ResourceHandle &resourceHandle);
215 
216  /** Frees the given resource handle (RSO v2)
217  * \param resourceHandle resource handle
218  * \return true if successful
219  */
220  bool ReleaseResourceHandle(disti::RSOInterface2::ResourceHandle resourceHandle);
221 
222  /** Checks the given resource handle for validity (RSO v2)
223  * \param resourceHandle resource handle
224  * \return true if the given resource handle is connected to a valid resource
225  */
226  bool IsResourceHandleValid(disti::RSOInterface2::ResourceHandle resourceHandle);
227 
228  /** Sets a string resource by handle (RSO v2)
229  * \param resourceHandle resource handle
230  * \param resourceVal resource value
231  * \return true if successful
232  */
233  bool SetResource(disti::RSOInterface2::ResourceHandle resourceHandle, const char *resourceVal);
234 
235  /** Gets a string resource by handle (RSO v2)
236  * \param resourceHandle resource handle
237  * \param[out] resourceValue reference to resource value output location
238  * \return true if successful
239  */
240  bool GetResource(disti::RSOInterface2::ResourceHandle resourceHandle, const char *&resourceValue);
241 
242  /** Sets an integer resource by name (RSO v2)
243  * \param resourceName resource name
244  * \param resourceVal resource value
245  * \return true if successful
246  */
247  bool SetIntResource(const char *resourceName, long resourceVal);
248  /** Sets an integer resource by handle (RSO v2)
249  * \param resourceHandle resource handle
250  * \param resourceVal resource value
251  * \return true if successful
252  */
253  bool SetIntResource(disti::RSOInterface2::ResourceHandle resourceHandle, long resourceVal);
254 
255  /** Gets an integer resource by name (RSO v2)
256  * \param resourceName resource name
257  * \param[out] resourceVal reference to resource value output location
258  * \return true if successful
259  */
260  bool GetIntResource(const char *resourceName, long &resourceVal);
261  /** Gets an integer resource by handle (RSO v2)
262  * \param resourceHandle resource handle
263  * \param[out] resourceVal reference to resource value output location
264  * \return true if successful
265  */
266  bool GetIntResource(disti::RSOInterface2::ResourceHandle resourceHandle, long &resourceVal);
267 
268  /** Sets a float resource by name (RSO v2)
269  * \param resourceName resource name
270  * \param resourceVal resource value
271  * \return true if successful
272  */
273  bool SetFloatResource(const char *resourceName, double resourceVal);
274  /** Sets a float resource by handle (RSO v2)
275  * \param resourceHandle resource handle
276  * \param resourceVal resource value
277  * \return true if successful
278  */
279  bool SetFloatResource(disti::RSOInterface2::ResourceHandle resourceHandle, double resourceVal);
280 
281  /** Gets a float resource by name (RSO v2)
282  * \param resourceName resource name
283  * \param[out] resourceVal reference to resource value output location
284  * \return true if successful
285  */
286  bool GetFloatResource(const char *resourceName, double &resourceVal);
287  /** Gets a float resource by handle (RSO v2)
288  * \param resourceHandle resource name
289  * \param[out] resourceVal reference to resource value output location
290  * \return true if successful
291  */
292  bool GetFloatResource(disti::RSOInterface2::ResourceHandle resourceHandle, double &resourceVal);
293  };
294 
295  /** Create RSO static
296  * This will load the specified DLL and try to create the specified class.
297  * It will return the RSO1Reference* on success, and NULL on failure.
298  * \param fileName The name of the DLL
299  * \param className The class name to create. If NULL, the default class will be created.
300  * \param absolutePlacement Initial value of AbsolutePlacement
301  * \return NULL on failure.*/
302  RSOReference* LoadRSO(const char* fileName, const char* className = 0, bool absolutePlacement = true);
303 
304  /** Delete an RSO reference */
305  void DestroyRSO(RSOReference*);
306 
307  /** Sets up the OpenGL Pipeline to the state expected by RSO drawing.
308  * \param pushState Whether or not to save values. If true, this will call
309  * glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS) and glPushAttrib(GL_ALL_ATTRIB_BITS). You should call
310  * RestoreOpenGLState() after drawing to pop the attributes.
311  */
312  void SetOpenGLDefaultState(bool pushState);
313 
314  /** Call this after calling SetOpenGLDefaultState with saveVal == true.
315  * DO NOT call this after calling SetOpenGLDefaultState with saveVal == false
316  * because this will pop the attribute stack.
317  */
318  void RestoreOpenGLState();
319 
320  /** OpenGLMatrices is used to pass the current OpenGL matrices to PreDraw */
322  {
323  protected:
324  bool _needsDelete;
325  public:
326  /** Constructor */
327  OpenGLMatrices();
328  /** Destructor */
329  ~OpenGLMatrices();
330 
331  /** Retrieves the current OpenGL Matrices from the
332  * OpenGL Subsystem */
333  void GetCurrent();
334  };
335 
336  /** Defines culling parameters (ie- clipping planes for frustum culling) for PreDraw */
338  {
339  public:
340  /** Culler constructor
341  * \param enabled Whether or not to actually do the culling test
342  */
343  Culler(bool enabled=true);
344 
345  /** Reads the current OpenGL projection matrices and determines the six frustum planes.
346  * \param currentMatrices Transformation matrices to apply to culling planes
347  */
349  };
350 
351  /** Used for specifiying a filter for accessing resources
352  */
354  {
355  public:
356  int _levelsUp;
357  int _groupLevelsDown;
358  std::vector<std::string> _excludeList;
359  std::vector<std::string> _includeList;
360  bool _namesOnly;
361 
362  public:
364  /// Copy constructor
366 
367  virtual ~GlsResourceFilter();
368 
369  /** How many levels of qualification above the starting point to show in the attribute names.
370  * This is based on the component heirarchy, not the draw hierarchy.
371  * For example if you call Altimeter->GetResources() with:
372  * LevelsUp = 0, expect:
373  * Altitude: 1000
374  * LevelsUp = 1, expect:
375  * Altimeter.Altitude:
376  * LevelsUp = 2, expect:
377  * Cockpit.Altimeter.Altitude:
378  * -1 means full qualification.
379  */
380  inline int LevelsUp() const { return _levelsUp; }
381  inline void LevelsUp(int value) { _levelsUp = value; }
382 
383  /** How many levels of children to show.
384  * This is different from LevelsUp because this is based on the draw
385  * heirarchy (Groups rather than components).
386  * For example with:
387  * GroupLevelsDown = 0, only the specified object's resources will be shown.
388  * GroupLevelsDown = 1, only the immeadiate children of the object's resources will be shown.
389  * GroupLevelsDown = -1, means all children will be shown.
390  * Note that the name stays fully qualified for the children. For example:
391  * if GroupLevelsDown == 1 the results would include:
392  * Altimeter.Visible: 1
393  * Altimeter.Group1.Visible: 1
394  * but NOT:
395  * Altimeter.Group1.Poly.Visible: 1
396  */
397  inline int GroupLevelsDown() const { return _groupLevelsDown; }
398  inline void GroupLevelsDown(int value) { _groupLevelsDown = value; }
399 
400  /** If true, only a list of names will be returned.
401  * Values will not be returned.
402  * The format changes to not include the ":".
403  */
404  inline bool NamesOnly() const { return _namesOnly; }
405  inline void NamesOnly(bool value) { _namesOnly = value; }
406 
407  /** Add a resource name to the exclude filter
408  * Resources on the exclude list will not pass the filter.
409  * Excludes take precedence over includes
410  */
411  void AddExclude(const char* name);
412 
413  /// Returns the number of exclude entries in the filter
414  int ExcludeCount() const;
415 
416  /** Returns the resource name for the given exclude list entry
417  * \pre index < ExcludeCount()
418  */
419  const char* GetExclude(int index) const;
420 
421  /** Removes a entry from the exclude list
422  * This will reduce the ExcludeCount()
423  * \pre index < ExcludeCount()
424  */
425  void RemoveExclude(unsigned int index);
426 
427  /// Removes all entries from the exclude list
428  void ClearExcludes();
429 
430  /** Add a resource name to the include filter
431  * If there are no includes specified, all resources
432  * will pass the filter by default.
433  * If IncludeCount() > 0, then only resources that
434  * are included will pass the filter.
435  */
436  void AddInclude(const char* name);
437 
438  /// Returns the number of includes in the filter
439  int IncludeCount() const;
440 
441  /** Returns the resource name for the given include list entry
442  * \pre index < IncludeCount()
443  */
444  const char* GetInclude(int index) const;
445 
446  /** Removes a entry from the include list
447  * This will reduce the IncludeCount()
448  * \pre index < IncludeCount()
449  */
450  void RemoveInclude(unsigned int index);
451 
452  /// Removes all entries from the include list
453  void ClearIncludes();
454 
455  /// Test a resource name against the filter
456  virtual bool PassFilter(const char* name) const;
457 
458  /// assignment operator
459  GlsResourceFilter& operator=( const GlsResourceFilter &rhs );
460  };
461 } // end namespace GlsRSOLoader
462 
463 #endif
Definition: rso_interface_1.h:551
bool SetIntResource(const char *resourceName, long resourceVal)
bool HandleInput(disti::RSOInterface1::Event *ev)
Definition: gls_rso_loader.h:115
void Draw()
Definition: gls_rso_loader.h:109
virtual bool SetEmittedEventHandler(EmittedEventHandler *handler)=0
Definition: rso_interface_1.h:264
bool HandleKeyDown(int key, int x, int y)
Culler()
Definition: rso_interface_1.h:270
int LevelsUp() const
Definition: gls_rso_loader.h:380
bool GetBoundingBox(disti::RSOInterface1::Vector *min, disti::RSOInterface1::Vector *max, disti::RSOInterface1::MatrixD *transform=0)
virtual void SetResource(const char *resourceName, const char *resourceVal)=0
Set the string value for a given named resource.
bool GetFloatResource(const char *resourceName, double &resourceVal)
virtual bool HandleInput(Event *ev)=0
int IncludeCount() const
Returns the number of includes in the filter.
bool HandleMouseDown(int x, int y, int button)
void AbsolutePlacement(bool value)
void ClearExcludes()
Removes all entries from the exclude list.
void RemoveExclude(unsigned int index)
const char * GetInclude(int index) const
bool CreateResourceHandle(const char *resourceName, disti::RSOInterface2::ResourceHandle &resourceHandle)
void AddInclude(const char *name)
bool IsResourceHandleValid(disti::RSOInterface2::ResourceHandle resourceHandle)
Definition: gls_rso_loader.h:337
virtual const char * GetResource(const char *resourceName)=0
Get the string value for the given resource.
bool HandleMouseWheelPlus(int x, int y, int buttonMask)
Definition: gls_rso_loader.h:321
void GetBackgroundColor(unsigned char &r, unsigned char &g, unsigned char &b, unsigned char &a)
void RemoveInclude(unsigned int index)
Definition: rso_interface_1.h:276
virtual void PreDraw(const OpenGLMatrices &current, Culler &culler)=0
Definition: gls_rso_loader.h:353
void Calculate(double time)
Definition: gls_rso_loader.h:100
void SetResource(const char *resourceName, const char *resourceVal)
Definition: gls_rso_loader.h:83
Definition: gls_rso_loader.h:53
Definition: rso_interface_1.h:564
bool ReleaseResourceHandle(disti::RSOInterface2::ResourceHandle resourceHandle)
bool HandleMouseUp(int x, int y, int button)
void SetResources(const char *buf)
int GroupLevelsDown() const
Definition: gls_rso_loader.h:397
void SetProjection(int controlWidth, int controlHeight, float depthFactor=4.0f, float fov=90.0f, bool perspective=false)
bool HandleMouseWheelMinus(int x, int y, int buttonMask)
Definition: rso_interface_1.h:63
Definition: gls_rso_loader.h:48
Definition: rso_interface_1.h:204
const char * GetResource(const char *resourceName)
Definition: gls_rso_loader.h:95
bool SetEmittedEventHandler(disti::RSOInterface1::EmittedEventHandler *handler)
Definition: gls_rso_loader.h:122
virtual void Draw()=0
disti::RSOInterface1 * GetRSOInterface1()
Definition: gls_rso_loader.h:72
Definition: rso_interface_1.h:187
bool HandleMouseMove(int x, int y, int buttonMask)
virtual void Calculate(double time)=0
bool HandleKeyUp(int key, int x, int y)
virtual bool PassFilter(const char *name) const
Test a resource name against the filter.
Definition: rso_interface_1.h:225
void PreDraw(const disti::RSOInterface1::OpenGLMatrices &current, disti::RSOInterface1::Culler &culler)
Definition: gls_rso_loader.h:106
bool NamesOnly() const
Definition: gls_rso_loader.h:404
Defines the RSO interface v2, which provides a generic way of accessing RSOs and other content...
bool SetFloatResource(const char *resourceName, double resourceVal)
int ExcludeCount() const
Returns the number of exclude entries in the filter.
bool GetIntResource(const char *resourceName, long &resourceVal)
void ClearIncludes()
Removes all entries from the include list.
unsigned int GetRSOVersion()
Definition: gls_rso_loader.h:77
const char * GetExclude(int index) const
void AddExclude(const char *name)
void ExtractFrustum(disti::RSOInterface1::OpenGLMatrices &currentMatrices)
GlsResourceFilter & operator=(const GlsResourceFilter &rhs)
assignment operator