GL Studio API
gls_linear_scale.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsLinearScale class.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2015 by 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_LINEAR_SCALE_H
41 #define _GLS_LINEAR_SCALE_H
42 
43 #include "glpolygon.h"
44 #include "gls_cpp_lang_support.h"
45 
46 #ifdef GLES
47 #include "gls_quad_storage.h"
48 #else
49 #include "gls_display_list.h"
50 #endif
51 
52 //////////////////// Provides support for creating DLLs ////////////////////////
53 #if (defined(GLSGEN_EXPORT_GLSLINEARSCALE) || \
54  defined(GLSGEN_IMPORT_GLSLINEARSCALE) || \
55  defined(GLS_EXPORT_GENERATED) || \
56  defined(GLS_IMPORT_GENERATED)) \
57  && defined(_MSC_VER)
58 # if defined(GLSGEN_EXPORT_GLSLINEARSCALE) || defined(GLS_EXPORT_GENERATED)
59 # define GLSGEN_GLSLINEARSCALE_EXPORT __declspec(dllexport)
60 # else
61 # define GLSGEN_GLSLINEARSCALE_EXPORT __declspec(dllimport)
62 # endif
63 #else
64 # define GLSGEN_GLSLINEARSCALE_EXPORT
65 #endif
66 ///////////////////////////////////////////////////////////////////////////////
67 
68 #define LIB_BASE_NAME "gls_linear_scale"
69 #include "gls_auto_lib.h"
70 #undef LIB_BASE_NAME
71 
72 namespace disti
73 {
74 
75 // SetValue enumerations
76 enum {
77  GLS_LINEAR_SCALE_FIRST_VALUE = GLS_LAST_INITIALIZER+1,
78  GLS_LINEAR_SCALE_RADII,
79  GLS_LINEAR_SCALE_DECONFLICT_TICKS,
80  GLS_LINEAR_SCALE_HALO_ENABLED,
81  GLS_LINEAR_SCALE_HALO_WIDTH,
82  GLS_LINEAR_SCALE_HALO_COLOR,
83  GLS_LINEAR_SCALE_TICK_ANCHOR,
84  GLS_LINEAR_SCALE_USE_SCALABLE_LINES,
85  GLS_LINEAR_SCALE_DATA
86 };
87 
88 typedef enum
89 {
90  GLS_TICK_ANCHOR_TOP,
91  GLS_TICK_ANCHOR_BOTTOM,
92  GLS_TICK_ANCHOR_CENTER
93 } GlsTickAnchor;
94 
96 {
97 protected:
98  DistiAttribDict _attribDict;
99 
100 public:
101  bool active; /**< True if this scale is active */
102  bool useLineColor; /**< True if this scale draws with line color */
103  unsigned int ticks; /**< Number of ticks on this scale */
104  float startingOffset; /**< Start offset in logical units */
105  float interval; /**< Interval between ticks in logical units */
106  float length; /**< Length of ticks in logical units */
107  float thickness; /**< Thickness of ticks in logical units */
108  glsColor color; /**< Color to draw ticks if line color is not being used*/
109 
110  GlsLinearScaleData(void) :
111  active(false),
112  useLineColor(false),
113  ticks(0),
114  startingOffset(0),
115  interval(0),
116  length(0),
117  thickness(1),
118  color(255,255,255,255)
119  {
120  InitMetaData();
121  }
122 
124  bool _active,
125  bool _useLineColor,
126  unsigned int _ticks,
127  float _startingOffset,
128  float _interval,
129  float _length,
130  float _thickness,
131  const glsColor &_color) :
132  active(_active),
133  useLineColor(_useLineColor),
134  ticks(_ticks),
135  startingOffset(_startingOffset),
136  interval(_interval),
137  length(_length),
138  thickness(_thickness),
139  color(_color)
140  {
141  InitMetaData();
142  }
143 
144  GlsLinearScaleData(const GlsLinearScaleData& src)
145  {
146  *this = src;
147  }
148 
149  ~GlsLinearScaleData(void)
150  {
151  }
152 
153  bool GLSGEN_GLSLINEARSCALE_EXPORT operator==( const GlsLinearScaleData& right ) const;
154 
155  bool GLSGEN_GLSLINEARSCALE_EXPORT operator!=( const GlsLinearScaleData& right ) const
156  {
157  return !( this->operator==( right ) );
158  }
159 
160  void GLSGEN_GLSLINEARSCALE_EXPORT InitMetaData(void);
161 
162  // Writes this to a stream
163  virtual GLSGEN_GLSLINEARSCALE_EXPORT std::ostream & WriteValue(std::ostream &outstr);
164 
165  // Reads this from a stream
166  virtual GLSGEN_GLSLINEARSCALE_EXPORT std::istream & ReadValue(std::istream &instr);
167 } ;
168 
169 #define GLS_LINEAR_SCALE_MAX 5
170 
171 typedef GlsLinearScaleData GlsLinearScaleDataArray[GLS_LINEAR_SCALE_MAX];
172 
173 #ifdef GLES
174 class GlsGloFileAttribute;
175 #endif
176 
177 /** Runtime implementation of a GlsLinearScale */
178 class GlsLinearScale : public GLPolygon
179 {
180  friend class GlsLinearScaleEditor;
181 private:
182  GlsLinearScale& operator=( const GlsLinearScale& ) DISTI_SPECIAL_MEM_FUN_DELETE;
183  GlsLinearScale( const GlsLinearScale& ) DISTI_SPECIAL_MEM_FUN_DELETE;
184 
185 public:
186  typedef GLPolygon _BaseClass;
187 
188  /** Create a new GlsLinearScale.
189  * \param generateInstance Whether or not to generate an instance name
190  * for this inputdevice */
191  GLSGEN_GLSLINEARSCALE_EXPORT GlsLinearScale(bool generateInstance=false);
192 
193  GLSGEN_GLSLINEARSCALE_EXPORT GlsLinearScale( const GlsLinearScale& that, const bool generateNames );
194 
195  /** Destructs a GlsLinearScale object */
196  virtual GLSGEN_GLSLINEARSCALE_EXPORT ~GlsLinearScale();
197 
198  static GLSGEN_GLSLINEARSCALE_EXPORT DisplayObject* CreateInstance();
199 
200  virtual GLSGEN_GLSLINEARSCALE_EXPORT void SetAvailableAttributes(unsigned int value);
201 
202  virtual GLSGEN_GLSLINEARSCALE_EXPORT DisplayObject* CloneObject(bool generateNames = false);
203 
204  virtual GLSGEN_GLSLINEARSCALE_EXPORT void CopyProperties(DisplayObject *src);
205 
206  virtual GLSGEN_GLSLINEARSCALE_EXPORT void CopyGeometry(DisplayObject *srcArg);
207 
208 #ifndef GLES
209  virtual GLSGEN_GLSLINEARSCALE_EXPORT InterfaceListType* GetCppInterfaceDescription(InterfaceListType* addToThisList= NULL );
210  virtual GLSGEN_GLSLINEARSCALE_EXPORT void GetCppInterfaceDescriptionFree(InterfaceListType* array);
211 #endif
212 
213  virtual GLSGEN_GLSLINEARSCALE_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices,Culler &culler );
214  virtual GLSGEN_GLSLINEARSCALE_EXPORT void Draw(void);
215 
216  virtual GLSGEN_GLSLINEARSCALE_EXPORT void Scale(float px, float py, float pz, Vertex *anchor, int handleBar);
217  virtual GLSGEN_GLSLINEARSCALE_EXPORT void Rotate(const Vector &orig,float angle,const Vector &axis);
218  virtual GLSGEN_GLSLINEARSCALE_EXPORT bool Hit(float x,float y,float z,float scale, const Vector& directionVector,Vector *collisionPoint);
219 
220  virtual GLSGEN_GLSLINEARSCALE_EXPORT void SetValue(int spec,va_list &args);
221 
222  virtual GLSGEN_GLSLINEARSCALE_EXPORT void SetColor(const glsColor& color);
223 
224  //////////////////////////////////////////////////
225  // GlsLinearScale specific operations
226  //////////////////////////////////////////////////
227 
228  /** Initializes data for one of the scales
229  * \param index Zero based index of the scale to set
230  * \param data The data to set
231  */
232  GLSGEN_GLSLINEARSCALE_EXPORT void SetScale(int index,const GlsLinearScaleData &data);
233 
234  /** Gets the data for one of the scales
235  * \param index Zero based index of the scale to get
236  * \param data The GlsLinearScaleData structure to fill
237  */
238  GLSGEN_GLSLINEARSCALE_EXPORT void GetScale(int index,GlsLinearScaleData &data);
239 
240  /** Sets the tick deconfliction state for this scale
241  * \param val Wether or not to enable tick deconfliction
242  */
243  GLSGEN_GLSLINEARSCALE_EXPORT void DeconflictTicks(const bool &val);
244 
245  /** Gets the tick deconfliction state for this scale
246  * \return Whether or not tick deconfliction is enabled
247  */
248  GLSGEN_GLSLINEARSCALE_EXPORT bool DeconflictTicks(void) { return _deconflictTicks; }
249 
250 
251  /** Gets the halo state for this scale
252  * \return Whether or not halo is enabled
253  */
254  GLSGEN_GLSLINEARSCALE_EXPORT bool HaloEnabled(void) { return _haloEnabled; }
255 
256  /** Sets the halo state for this scale
257  * \param val Wether or not to enable halo
258  */
259  GLSGEN_GLSLINEARSCALE_EXPORT void HaloEnabled(const bool &val);
260 
261  /** Gets the halo width for this scale
262  * \return The halo width for this scale
263  */
264  GLSGEN_GLSLINEARSCALE_EXPORT float HaloWidth(void) { return _haloWidth; }
265 
266  /** Sets the halo width for this scale
267  * \param val New halo width
268  */
269  GLSGEN_GLSLINEARSCALE_EXPORT void HaloWidth( const float& val );
270 
271  /** Gets the halo color for this scale
272  * \return The halo color for this scale
273  */
274  GLSGEN_GLSLINEARSCALE_EXPORT glsColor HaloColor(void) { return _haloColor; }
275 
276  /** Sets the halo color for this scale
277  * \param val New halo color
278  */
279  GLSGEN_GLSLINEARSCALE_EXPORT void HaloColor(const glsColor &val);
280 
281  /** Gets the tick anchor for this scale
282  * \return The tick anchor for this scale
283  */
284  GLSGEN_GLSLINEARSCALE_EXPORT GlsTickAnchor TickAnchor(void) { return _tickAnchor; }
285 
286  /** Sets the tick anchor for this scale
287  * \param val New tick anchor
288  */
289  GLSGEN_GLSLINEARSCALE_EXPORT void TickAnchor(const GlsTickAnchor val);
290 
291 #ifdef GLES
292  /** Causes the VBO for this object to be recomputed */
293  GLSGEN_GLSLINEARSCALE_EXPORT void InvalidateGeometry(void) { _geometryRefresh = true; }
294 #endif
295 
296 #ifndef GLES
297  /** Gets the drawing mode for this scale
298  * \return The drawing mode for this scale
299  */
300  GLSGEN_GLSLINEARSCALE_EXPORT bool UseScalableLines(void) { return _useScalableLines; }
301 
302  /** Sets the drawing mode for this scale
303  * \param val New drawing mode
304  */
305  GLSGEN_GLSLINEARSCALE_EXPORT void UseScalableLines( const bool& val );
306 
307  /** Causes the display list for this object to be recomputed */
308  GLSGEN_GLSLINEARSCALE_EXPORT void InvalidateGeometry( void ) { _displayList.Invalidate(); }
309 
310  /** Returns a reference to this object's display list */
311  GLSGEN_GLSLINEARSCALE_EXPORT GlsDisplayList& DisplayList( void ) { return _displayList; }
312 #endif
313 
314 protected:
315 #ifdef GLES
316  /** Manages a VBO for drawing the tick marks */
317  GlsQuadListVC_3D _quads;
318 
319  /** Updates the VBO when the object changes */
320  void BakeVBO();
321 #else
322  /** Minimizes calls to glColor when drawing the scale */
323  void CurrentColor(const glsColor &newColor);
324 
325  /** Minimizes calls to glLineWidth when drawing the scale */
326  void CurrentLineWidth(const float &newLineWidth);
327 
328  /** Stores the current color. Used when calculating a new display list so that redundant
329  * glColor calls are not made */
331 
332  /** Stores the current line width. Used when calculating a new display list so that redundant
333  * glLineWidth calls are not made */
335 
336  /** True if the current color has been set. Gets reset every time a new display list is
337  * recalculated. */
339 
340  /** True if the current line width has been set. Gets reset every time a new display list is
341  * recalculated. */
343 
344  /** Stores the scale in a display list for faster drawing */
346 #endif
347 
348  /** Recomputes the object's vertices from its radii */
349  void RecomputeVertices(void);
350 
351  /** Recomputes the object's vertices and its radii */
352  void UpdateScaleData(void);
353 
354  /** Determines if a tick with the given offset should be drawn or not. If a higher priority
355  * scale already has a tick at that level and deconfliction is enabled, then this method
356  * will return false */
357  bool TickNeeded(int currentLevel,float currentOffset);
358 
359 #ifdef GLES
360  /** Calculates and draws a single scale using the given halo length and thickness
361  * \param i The index of the scale to draw
362  * \param haloLength The length of the halo
363  * \param haloThickness The thickness of the halo
364  * \param color The color of the scale
365  */
366  void DrawScale(int i,float haloLength,float haloThickness,glsColor &color);
367 #else
368  /** Calculates and draws a single scale using the given halo length and thickness
369  * \param i The index of the scale to draw
370  * \param haloLength The length of the halo
371  * \param haloThickness The thickness of the halo
372  */
373  void DrawScale(int i,float haloLength,float haloThickness);
374 #endif
375 
376 #ifdef GLES
377  /** Set a single attribute from the GLO file.
378  * \param data The attribute to set and its associated data.
379  */
380  virtual GLSGEN_GLSLINEARSCALE_EXPORT void SetFromGloData(GlsGloFileAttribute &data);
381 #endif
382 
383 #ifndef GLES
384  /** Calculates current tick mark locations and performs OpenGL drawing commands */
385  virtual void DrawGeometry(void);
386 #endif
387 
388  /** Two radius vectors that are used to define the orientation of the scale */
390 
391  /** Normalized radius vectors, cached because they are needed often */
393 
394  /** The particulars of each scale */
395  GlsLinearScaleDataArray _scale;
396 
397  /** True if duplicated tick marks are removed */
399 
400  /** True if haloing is enabled */
402 
403  /** Width of the halo in logical units */
404  float _haloWidth;
405 
406  /** Color of the halo */
408 
409  /** Anchor to determine where ticks will draw */
410  GlsTickAnchor _tickAnchor;
411 
412 #ifndef GLES
413  /** True if scale is drawn with polygon quads instead of lines*/
415 #endif
416 };
417 
418 /** Metadata for scale data */
420 {
421 protected:
422  GlsLinearScaleDataArray* _attribPtr;
423  unsigned int _arraySize;
424 
425 public:
426 
427  DistiAttributeConnectionGlsLinearScaleDataArray(CallbackMethodCallerBase* callback, const AttributeName &name, GlsLinearScaleDataArray *attribPtr,int arraySize) :
428  DistiAttributeBase(callback,name,false),
429  _attribPtr(attribPtr),
430  _arraySize(arraySize)
431  {
432  }
433 
435  virtual bool OkToWrite() const;
436  virtual std::ostream & WriteValue(std::ostream &outstr);
437  virtual std::istream & ReadValue(std::istream &instr);
438 
439 };
440 
441 } // namespace disti
442 
443 #endif
444 
glsColor color
Definition: gls_linear_scale.h:108
Definition: cull.h:50
bool _haloEnabled
Definition: gls_linear_scale.h:401
void DrawScale(int i, float haloLength, float haloThickness)
glsColor _currentColor
Definition: gls_linear_scale.h:330
bool active
Definition: gls_linear_scale.h:101
float HaloWidth(void)
Definition: gls_linear_scale.h:264
Definition: vertex.h:365
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar)
void GetScale(int index, GlsLinearScaleData &data)
GlsTickAnchor TickAnchor(void)
Definition: gls_linear_scale.h:284
void InvalidateGeometry(void)
Definition: gls_linear_scale.h:308
bool TickNeeded(int currentLevel, float currentOffset)
virtual void Draw(void)
void Invalidate(void)
Definition: gls_display_list.h:83
bool useLineColor
Definition: gls_linear_scale.h:102
bool DeconflictTicks(void)
Definition: gls_linear_scale.h:248
Definition: dynamic_array.h:63
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:281
float _haloWidth
Definition: gls_linear_scale.h:404
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
The Polygon class. Implements Polygons.
Definition: glpolygon.h:56
virtual void Rotate(const Vector &orig, float angle, const Vector &axis)
void CurrentLineWidth(const float &newLineWidth)
Definition: gls_linear_scale.h:95
Definition: display.h:98
The disti::GLPolygon class. Implements Polygons.
float startingOffset
Definition: gls_linear_scale.h:104
bool UseScalableLines(void)
Definition: gls_linear_scale.h:300
bool _useScalableLines
Definition: gls_linear_scale.h:414
Definition: gls_display_list.h:51
unsigned int ticks
Definition: gls_linear_scale.h:103
GlsLinearScaleDataArray _scale
Definition: gls_linear_scale.h:395
virtual void SetValue(int spec, va_list &args)
bool HaloEnabled(void)
Definition: gls_linear_scale.h:254
void UpdateScaleData(void)
float interval
Definition: gls_linear_scale.h:105
glsColor _haloColor
Definition: gls_linear_scale.h:407
Vector _radiiNormalized[2]
Definition: gls_linear_scale.h:392
virtual void DrawGeometry(void)
bool _deconflictTicks
Definition: gls_linear_scale.h:398
Definition: disti_metadata.h:179
void SetScale(int index, const GlsLinearScaleData &data)
glsColor HaloColor(void)
Definition: gls_linear_scale.h:274
virtual void CopyProperties(DisplayObject *src)
virtual void SetAvailableAttributes(unsigned int value)
bool _currentLineWidthSet
Definition: gls_linear_scale.h:342
virtual DisplayObject * CloneObject(bool generateNames=false)
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler)
Definition: disti_metadata.h:676
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
Definition: callback_caller_base.h:56
The gls_auto_lib.
Definition: gls_color.h:54
Definition: gls_linear_scale.h:178
virtual void SetColor(const glsColor &color)
virtual std::istream & ReadValue(std::istream &instr)
GlsTickAnchor _tickAnchor
Definition: gls_linear_scale.h:410
virtual std::ostream & WriteValue(std::ostream &outstr)
float _currentLineWidth
Definition: gls_linear_scale.h:334
Definition: vertex.h:84
float thickness
Definition: gls_linear_scale.h:107
GlsDisplayList & DisplayList(void)
Definition: gls_linear_scale.h:311
void CurrentColor(const glsColor &newColor)
Vector _radii[2]
Definition: gls_linear_scale.h:389
void RecomputeVertices(void)
float length
Definition: gls_linear_scale.h:106
Macros and helper code to determine what subset of C++11/14/17 is available.
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint)
GlsDisplayList _displayList
Definition: gls_linear_scale.h:345
Definition: disti_metadata.h:83
Definition: bmpimage.h:46
The disti::GlsDisplayList class.
virtual void CopyGeometry(DisplayObject *srcArg)
bool _currentColorSet
Definition: gls_linear_scale.h:338