DataDirector API
Fl_RSO_Window.H
Go to the documentation of this file.
1 /*! \file Fl_RSO_Window.H
2 
3  \par Copyright Information
4 
5  Copyright (c) 2012 The DiSTI Corporation.<br>
6  11301 Corporate Blvd; Suite 100<br>
7  Orlando, Florida 32817<br>
8  USA<br>
9  <br>
10  All rights reserved.<br>
11 
12  This Software contains proprietary trade secrets of DiSTI and may not be
13 reproduced, in whole or part, in any form, or by any means of electronic,
14 mechanical, or otherwise, without the written permission of DiSTI. Said
15 permission may be derived through the purchase of applicable DiSTI product
16 licenses which detail the distribution rights of this content and any
17 Derivative Works based on this or other copyrighted DiSTI Software.
18 
19  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
20 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
21 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
22 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
23 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
24 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
25 
26  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
27 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
28 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
29 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
30 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
31 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBLITY
32 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
33 EXCEED FIVE DOLLARS (US$5.00).
34 
35  The aforementioned terms and restrictions are governed by the laws of the
36 State of Florida and the United States of America.
37 
38 */
39 
40 #ifndef FL_RSO_WINDOW_H
41 #define FL_RSO_WINDOW_H
42 
43 
44 #include <FL/Fl_Gl_Window.H>
45 #include "rso_interface_1.h"
46 #include "component_base.h"
47 #include "group.h"
48 #include "glpolygon.h"
49 #include "DDD_RSOAsset.h"
50 #include "DDD_PerformanceMonitor.h"
51 #include "DDD_XMLConfigMgr.h"
52 #include "events.h"
53 
54 /** \brief Fl_Gl_Group. Parent FLTK group containing a Fl_RSO_Window; passes certain events to Fl_Gl_Window. */
55 class DDD_EXPORT Fl_Gl_Group : public Fl_Group
56 {
57 public:
58 
59  /** Constructor
60  * \param x X value for this group.
61  * \param y Y value for this group.
62  * \param w Width value for this group.
63  * \param h Height Value for this group.
64  * \param l Label to use for this group.
65  */
66  Fl_Gl_Group(int x, int y, int w, int h, const char *l=0);
67 
68  /** Handle events for this group
69  * \param evId The event id for the event that needs to be handled.
70  */
71  virtual int handle(int evId);
72 };
73 
74 
75 /** \brief Fl_RSO_Window. FLTK/OpenGL window that displays RSO Assets. */
76 class DDD_EXPORT Fl_RSO_Window : public Fl_Gl_Window
77 {
78 
79 public:
80 
81  /** Destructor */
82  virtual ~Fl_RSO_Window();
83 
84  /** Constructor
85  * \param W Width for the new window
86  * \param H Height for the new window
87  * \param l Label for the new window
88  */
89  Fl_RSO_Window(int W, int H, const char *l=0);
90 
91  /** Constructor
92  * \param X X position for the new window
93  * \param Y Y position for the new window
94  * \param W Width for the new window
95  * \param H Height for the new window
96  * \param l Label for the new window
97  */
98  Fl_RSO_Window(int X, int Y, int W, int H, const char *l=0);
99 
100  /** Initializes all members to their default settings
101  *
102  */
103  virtual void Clear();
104 
105  /** Recreates the canvas size based on the input width and height
106  * \param width Value for the canvas width
107  * \param height Value for the canvas height
108  */
109  virtual void InitializeCanvas(float width, float height);
110 
111  /** Iserts a component pointer into to the top of _object to be drawn first
112  * \param component Pointer to the component that's being added
113  */
114  void AddComponent(disti::ComponentBase *component);
115 
116  /* Sets the viewable region percentage
117  * \param scale Value to use for the vew scale
118  */
119  virtual void SetViewScale(float scale);
120 
121  /* Sets the viewable region to fit to the canvas size
122  *
123  */
124  virtual void SetViewFit();
125 
126  /* Sets the center of the view in logical coordinates
127  * \param center Vector position to use as the new vew center
128  */
129  virtual void SetViewCenter(disti::Vector center);
130 
131  /* Finds the first object collided with based on input X/Y values. The
132  * algorithm does a simple 2D collision check of all members of _objects
133  * based on reverse draw order (ie. objects drawn last will be collided
134  * with first).
135  * Sets _currentlySelectedAsset and _currentlySelectedRSO
136  * \param x Logical x pick value
137  * \param y Logical y pick value
138  */
139  void Pick2DByExtents(float x, float y);
140 
141  /* The callback for the live viewer window
142  * \param eventID event id for the event to handle
143  */
144  virtual int handle(int eventID);
145 
146  //
147  // Handle code
148  //
149 
150  /* Helper function that handles keyboard input
151  * \param key Key event that needs to be handled as reported by FLTK
152  * \return True if the input was handled False otherwise
153  */
154  virtual bool HandleKeyboardInput(int key);
155 
156  /* Helper function that handles mouse move events
157  * \param currentEventWinLoc Location of the event that needs to be handled in window coordinates
158  * \param previousLogicalCoords Location of the last handled event in logical coordinates
159  * \param currentLogicalCoords Location of the current event that needs to be handled in logical coordinates
160  */
161  virtual void HandleMouseMove(disti::Vector currentEventWinLoc, disti::Vector previousLogicalCoords, disti::Vector currentLogicalCoords);
162 
163  /* Helper function that handles mouse push events
164  * \param currentEventWinLoc Location of the event that needs to be handled in window coordinates
165  * \param currentLogicalCoords Location of the current event that needs to be handled in logical coordinates
166  * \return True if the event was handled and False otherwise
167  */
168  virtual bool HandleMousePush(disti::Vector currentEventWinLoc, disti::Vector currentLogicalCoords);
169 
170  /* Helper function that handles mouse drag events
171  * \param currentEventWinLoc Location of the event that needs to be handled in window coordinates
172  * \param previousLogicalCoords Location of the last handled event in logical coordinates
173  * \param currentLogicalCoords Location of the current event that needs to be handled in logical coordinates
174  */
175  virtual void HandleMouseDrag(disti::Vector currentEventWinLoc, disti::Vector previousLogicalCoords, disti::Vector currentLogicalCoords);
176 
177  /* Sets the currently selected object
178  * \param newObject Pointer to the object that just got selected
179  */
180  void SetCurrentlySelectedAsset(disti::DDD_AssetBase* newAsset);
181 
182  /* Helper function used to get the currently selected asset
183  * \return Pointer to the currently selected asset
184  */
185  disti::DDD_AssetBase* GetCurrentlySelectedAsset() { return _currentlySelectedAsset; }
186 
187  /* Helper function used to get the currently selected RSO
188  * NOTE: It's possible for _currentlySelectedAsset to be set and _currentlySelectedRSO to be NULL
189  * if the currently selected asset is not an RSO. (This should only happen in the Producer)
190  * \return Pointer to the currently selected RSO
191  */
192  disti::DDD_AssetBase* GetCurrentlySelectedRSO() { return _currentlySelectedRSO; }
193 
194  /* Helper function used to get the current list of objects
195  * \return Pointer to the current group of objects
196  */
197  disti::Group* GetObjects() { return &_objects; }
198 
199  /* Helper function used to get the current view scale
200  * \return Veiw scale value
201  */
202  float Scale() { return _viewScale; }
203 
204  /* Zoom in by 2, setting the new center point
205  * \param newCenter The new center point
206  */
207  virtual void ZoomIn(const disti::Vector &newCenter);
208 
209  /* Zoom out by 2, setting the new center point
210  * \param newCenter The new center point
211  */
212  virtual void ZoomOut(const disti::Vector &newCenter);
213 
214  /* Zoom in by 2, no recenter
215  *
216  */
217  virtual void ZoomIn();
218 
219  /* Zoom out by 2, no recenter
220  *
221  */
222  virtual void ZoomOut();
223 
224  /* Helper function to the set configuration target
225  * \param target Target to use for this window
226  */
227  void SetTarget(disti::XMLConfigTarget *target) { _target = target; }
228 
229  /* Helper function to get the frame interval value
230  * \return The frame interval value (in microseconds)
231  */
232  int FrameInterval() { return _frameInterval; };
233 
234  /* Helper function to set the frame interval
235  * \param microseconds Number of microseconds to use as the frame interval
236  */
237  void FrameInterval(int microseconds) { _frameInterval = microseconds; }
238 
239  /* Helper function used to set the redraw flag
240  *
241  */
242  virtual void SetRedraw();
243 
244  /* Helper function used to control when the frame is drawn
245  *
246  */
247  virtual bool FrameAnimate();
248 
249  /* Helper function that waits for an event to happen
250  * \return True if a window is being shown False otherwise
251  */
252  virtual bool UpdateAnimate();
253 
254  /* Helper function used to sync the multivew on all RSO Assets
255  *
256  */
257  virtual void SyncAllRSOAssetMultiViews();
258 
259 protected:
260 
261  /** Setup the OpenGL Context for drawing
262  * \return Returns true if states will need to be restored
263  */
264  bool SetupOpenGLState();
265 
266  /** Setup the OpenGL Context for drawing
267  * \return Returns true if states will need to be restored
268  */
269  void RestoreOpenGLState(bool saveVal);
270 
271  /** Draw the Canvas. */
272  void DrawCanvas();
273 
274  /** Draw performance statistics */
275  void DrawStats();
276 
277  /** Draw the objects
278  * \param previewMode When true, all objects are drawn.
279  * When false only objects on the canvas are drawn.
280  */
281  void DrawObjects(bool previewMode);
282 
283  /* Helper function used to populate a mouse event object
284  * \param eventButton Event button value as reported by FLTK
285  * \param eventSybtype Event subtime as reported by FLTK (i.e. FL_PUSH FL_RELEASE)
286  * \param logicalX Value for x in logical coordinates
287  * \param logicalY Value for y in logical coordinates
288  * \param logicalZ Value for z in logical coordinates
289  * \param mev MouseEvent reference to populate
290  */
291  void GenerateMouseEvent(int eventButton, int eventSubtype, float logicalX, float logicalY, disti::MouseEvent *mev);
292 
293  /* Helper function used to render components to the screen
294  *
295  */
296  virtual void draw();
297 
298  /* Helper function used to resize the window
299  * \param x X value for the location of the window in screen coordinates
300  * \param y Y value for the location of the window in screen coordinates
301  * \param w New window width value in screen coordinates
302  * \param h New window height value in screen coordinates
303  */
304  virtual void resize(int,int,int,int);
305 
306  //
307  // Sync Multiview's screen position up to rso asset's position
308  //
309 
310  /* Helper function used to sync the multiview
311  * \param rsoAsset
312  * \return True if the multivew was succesfully synced False otherwise
313  */
314  virtual bool SyncMultiViewPos(disti::DDD_RSOAsset* rsoAsset);
315 
316  /* Helper function for picking individual RSO
317  * \param component Component instance to check
318  * \param logicalCoords Picking ray, in logical coordinates
319  * \return true if ray has intersected Component, false otherwise
320  */
321  bool Pick2DUsingRSOExtents(disti::ComponentBase *component, const disti::Vector& logicalCoords);
322 
323  /* Helper function for picking individual eyepoint-enabled RSO
324  * \param asset Asset instance to check
325  * \param logicalCoords Picking ray, in logical coordinates
326  * \return true if ray has intersected Component, false otherwise
327  */
328  bool Pick2DUsingRSOEyepoint(disti::DDD_RSOAsset *asset, const disti::Vector& logicalCoords);
329 
330 protected:
331 
332 
333  disti::GLPolygon *_canvas; /**< Polygon that defines the canvas to be drawn. */
334  disti::Vector _viewTranslation; /**< The current translation for the view */
335  disti::Group _objects; /**< Contains a list of components that will be used to draw with */
336  float _viewScale; /**< Sets the viewing scale for the window */
337 
338 
339  disti::DDD_AssetBase *_currentlySelectedAsset; /**< The currently selected Asset */
340  disti::DDD_RSOAsset *_currentlySelectedRSO; /**< The currently selected RSO */
341 
342  disti::OpenGLMatrices _currentMatrices; /**< The current OpenGL Matrices */
343 
344  disti::Vector _previousMouseEventLocation; /**< The last mouse event location */
345 
346  disti::XMLConfigTarget *_target;
347 
348  disti::DDD_PerformanceMonitor *_drawProfiler, /**< Measures Draw performance */
349  *_renderProfiler, /**< Measures render(draw+predraw) performance */
350  *_fpsProfiler; /**< Measures FPS performance */
351 
352  // borrowed from GlsDisplayFrame
353  float _smoothedFrameDelay; /**< Frame interval, smoothed based on actual draw performance */
354  bool _redraw; /**< Flag indicating if the window should be redrawn */
355  int _frameInterval; /**< frame interval in microseconds */
356 
357 };
358 
359 #endif
360 
float _viewScale
Definition: Fl_RSO_Window.H:336
int _frameInterval
Definition: Fl_RSO_Window.H:355
A virtual interface class for all DataDirector assets.
Definition: DDD_AssetBase.h:115
disti::Vector _viewTranslation
Definition: Fl_RSO_Window.H:334
Fl_Gl_Group. Parent FLTK group containing a Fl_RSO_Window; passes certain events to Fl_Gl_Window...
Definition: Fl_RSO_Window.H:55
disti::OpenGLMatrices _currentMatrices
Definition: Fl_RSO_Window.H:342
float _smoothedFrameDelay
Definition: Fl_RSO_Window.H:353
disti::DDD_RSOAsset * _currentlySelectedRSO
Definition: Fl_RSO_Window.H:340
bool _redraw
Definition: Fl_RSO_Window.H:354
Fl_RSO_Window. FLTK/OpenGL window that displays RSO Assets.
Definition: Fl_RSO_Window.H:76
The DDD_RSOAsset class. DataDirector asset class that controls GL Studio RSOs.
Definition: DDD_RSOAsset.h:81
disti::DDD_AssetBase * _currentlySelectedAsset
Definition: Fl_RSO_Window.H:339
disti::Group _objects
Definition: Fl_RSO_Window.H:335
disti::Vector _previousMouseEventLocation
Definition: Fl_RSO_Window.H:344
disti::GLPolygon * _canvas
Definition: Fl_RSO_Window.H:333
Performance monitor class; profiles an individual task.
Definition: DDD_PerformanceMonitor.h:55
disti::DDD_PerformanceMonitor * _renderProfiler
Definition: Fl_RSO_Window.H:348
Abstract base class for any object that uses DDD_XMLConfigMgr.
Definition: DDD_XMLConfigMgr.h:74
classes for measuring application performance