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