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  *this = src;
144  }
145 
146  ~GlsLinearScaleData( void )
147  {
148  }
149 
150  bool GLSGEN_GLSLINEARSCALE_EXPORT operator==( const GlsLinearScaleData& right ) const;
151 
152  bool GLSGEN_GLSLINEARSCALE_EXPORT operator!=( const GlsLinearScaleData& right ) const
153  {
154  return !( this->operator==( right ) );
155  }
156 
157  void GLSGEN_GLSLINEARSCALE_EXPORT InitMetaData( void );
158 
159  // Writes this to a stream
160  virtual GLSGEN_GLSLINEARSCALE_EXPORT std::ostream& WriteValue( std::ostream& outstr );
161 
162  // Reads this from a stream
163  virtual GLSGEN_GLSLINEARSCALE_EXPORT std::istream& ReadValue( std::istream& instr );
164 };
165 
166 #define GLS_LINEAR_SCALE_MAX 5
167 
168 typedef GlsLinearScaleData GlsLinearScaleDataArray[ GLS_LINEAR_SCALE_MAX ];
169 
170 #ifdef GLES
171 class GlsGloFileAttribute;
172 #endif
173 
174 /** Runtime implementation of a GlsLinearScale */
175 class GlsLinearScale : public GLPolygon
176 {
177  friend class GlsLinearScaleEditor;
178 
179 private:
180  GlsLinearScale& operator=( const GlsLinearScale& ) DISTI_SPECIAL_MEM_FUN_DELETE;
181  GlsLinearScale( const GlsLinearScale& ) DISTI_SPECIAL_MEM_FUN_DELETE;
182 
183 public:
184  typedef GLPolygon _BaseClass;
185 
186  /** Create a new GlsLinearScale.
187  * \param generateInstance Whether or not to generate an instance name
188  * for this inputdevice */
189  GLSGEN_GLSLINEARSCALE_EXPORT GlsLinearScale( bool generateInstance = false );
190 
191  GLSGEN_GLSLINEARSCALE_EXPORT GlsLinearScale( const GlsLinearScale& that, const bool generateNames );
192 
193  /** Destructs a GlsLinearScale object */
194  virtual GLSGEN_GLSLINEARSCALE_EXPORT ~GlsLinearScale();
195 
196  static GLSGEN_GLSLINEARSCALE_EXPORT DisplayObject* CreateInstance();
197 
198  virtual GLSGEN_GLSLINEARSCALE_EXPORT void SetAvailableAttributes( unsigned int value );
199 
200  virtual GLSGEN_GLSLINEARSCALE_EXPORT DisplayObject* CloneObject( bool generateNames = false );
201 
202  virtual GLSGEN_GLSLINEARSCALE_EXPORT void CopyProperties( DisplayObject* src );
203 
204  virtual GLSGEN_GLSLINEARSCALE_EXPORT void CopyGeometry( DisplayObject* srcArg );
205 
206 #ifndef GLES
207  virtual GLSGEN_GLSLINEARSCALE_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL );
208  virtual GLSGEN_GLSLINEARSCALE_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array );
209 #endif
210 
211  virtual GLSGEN_GLSLINEARSCALE_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler );
212  virtual GLSGEN_GLSLINEARSCALE_EXPORT void Draw( void );
213 
214  virtual GLSGEN_GLSLINEARSCALE_EXPORT void Scale( float px, float py, float pz, Vertex* anchor, int handleBar );
215  virtual GLSGEN_GLSLINEARSCALE_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis );
216  virtual GLSGEN_GLSLINEARSCALE_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint );
217 
218  virtual GLSGEN_GLSLINEARSCALE_EXPORT void SetValue( int spec, va_list& args );
219 
220  virtual GLSGEN_GLSLINEARSCALE_EXPORT void SetColor( const GlsColor& color );
221 
222  //////////////////////////////////////////////////
223  // GlsLinearScale specific operations
224  //////////////////////////////////////////////////
225 
226  /** Initializes data for one of the scales
227  * \param index Zero based index of the scale to set
228  * \param data The data to set
229  */
230  GLSGEN_GLSLINEARSCALE_EXPORT void SetScale( int index, const GlsLinearScaleData& data );
231 
232  /** Gets the data for one of the scales
233  * \param index Zero based index of the scale to get
234  * \param data The GlsLinearScaleData structure to fill
235  */
236  GLSGEN_GLSLINEARSCALE_EXPORT void GetScale( int index, GlsLinearScaleData& data );
237 
238  /** Sets the tick deconfliction state for this scale
239  * \param val Wether or not to enable tick deconfliction
240  */
241  GLSGEN_GLSLINEARSCALE_EXPORT void DeconflictTicks( const bool& val );
242 
243  /** Gets the tick deconfliction state for this scale
244  * \return Whether or not tick deconfliction is enabled
245  */
246  GLSGEN_GLSLINEARSCALE_EXPORT bool DeconflictTicks( void ) { return _deconflictTicks; }
247 
248  /** Gets the halo state for this scale
249  * \return Whether or not halo is enabled
250  */
251  GLSGEN_GLSLINEARSCALE_EXPORT bool HaloEnabled( void ) { return _haloEnabled; }
252 
253  /** Sets the halo state for this scale
254  * \param val Wether or not to enable halo
255  */
256  GLSGEN_GLSLINEARSCALE_EXPORT void HaloEnabled( const bool& val );
257 
258  /** Gets the halo width for this scale
259  * \return The halo width for this scale
260  */
261  GLSGEN_GLSLINEARSCALE_EXPORT float HaloWidth( void ) { return _haloWidth; }
262 
263  /** Sets the halo width for this scale
264  * \param val New halo width
265  */
266  GLSGEN_GLSLINEARSCALE_EXPORT void HaloWidth( const float& val );
267 
268  /** Gets the halo color for this scale
269  * \return The halo color for this scale
270  */
271  GLSGEN_GLSLINEARSCALE_EXPORT GlsColor HaloColor( void ) { return _haloColor; }
272 
273  /** Sets the halo color for this scale
274  * \param val New halo color
275  */
276  GLSGEN_GLSLINEARSCALE_EXPORT void HaloColor( const GlsColor& val );
277 
278  /** Gets the tick anchor for this scale
279  * \return The tick anchor for this scale
280  */
281  GLSGEN_GLSLINEARSCALE_EXPORT GlsTickAnchor TickAnchor( void ) { return _tickAnchor; }
282 
283  /** Sets the tick anchor for this scale
284  * \param val New tick anchor
285  */
286  GLSGEN_GLSLINEARSCALE_EXPORT void TickAnchor( const GlsTickAnchor val );
287 
288 #ifdef GLES
289  /** Causes the VBO for this object to be recomputed */
290  GLSGEN_GLSLINEARSCALE_EXPORT void InvalidateGeometry( void ) { _geometryRefresh = true; }
291 #endif
292 
293 #ifndef GLES
294  /** Gets the drawing mode for this scale
295  * \return The drawing mode for this scale
296  */
297  GLSGEN_GLSLINEARSCALE_EXPORT bool UseScalableLines( void ) { return _useScalableLines; }
298 
299  /** Sets the drawing mode for this scale
300  * \param val New drawing mode
301  */
302  GLSGEN_GLSLINEARSCALE_EXPORT void UseScalableLines( const bool& val );
303 
304  /** Causes the display list for this object to be recomputed */
305  GLSGEN_GLSLINEARSCALE_EXPORT void InvalidateGeometry( void ) { _displayList.Invalidate(); }
306 
307  /** Returns a reference to this object's display list */
308  GLSGEN_GLSLINEARSCALE_EXPORT GlsDisplayList& DisplayList( void ) { return _displayList; }
309 #endif
310 
311 protected:
312 #ifdef GLES
313  /** Manages a VBO for drawing the tick marks */
314  GlsQuadListVC_3D _quads;
315 
316  /** Updates the VBO when the object changes */
317  void BakeVBO();
318 #else
319  /** Minimizes calls to glColor when drawing the scale */
320  void CurrentColor( const GlsColor& newColor );
321 
322  /** Minimizes calls to glLineWidth when drawing the scale */
323  void CurrentLineWidth( const float& newLineWidth );
324 
325  /** Stores the current color. Used when calculating a new display list so that redundant
326  * glColor calls are not made */
328 
329  /** Stores the current line width. Used when calculating a new display list so that redundant
330  * glLineWidth calls are not made */
332 
333  /** True if the current color has been set. Gets reset every time a new display list is
334  * recalculated. */
336 
337  /** True if the current line width has been set. Gets reset every time a new display list is
338  * recalculated. */
340 
341  /** Stores the scale in a display list for faster drawing */
343 #endif
344 
345  /** Recomputes the object's vertices from its radii */
346  void RecomputeVertices( void );
347 
348  /** Recomputes the object's vertices and its radii */
349  void UpdateScaleData( void );
350 
351  /** Determines if a tick with the given offset should be drawn or not. If a higher priority
352  * scale already has a tick at that level and deconfliction is enabled, then this method
353  * will return false */
354  bool TickNeeded( int currentLevel, float currentOffset );
355 
356 #ifdef GLES
357  /** Calculates and draws a single scale using the given halo length and thickness
358  * \param i The index of the scale to draw
359  * \param haloLength The length of the halo
360  * \param haloThickness The thickness of the halo
361  * \param color The color of the scale
362  */
363  void DrawScale( int i, float haloLength, float haloThickness, GlsColor& color );
364 #else
365  /** Calculates and draws a single scale using the given halo length and thickness
366  * \param i The index of the scale to draw
367  * \param haloLength The length of the halo
368  * \param haloThickness The thickness of the halo
369  */
370  void DrawScale( int i, float haloLength, float haloThickness );
371 #endif
372 
373 #ifdef GLES
374  /** Set a single attribute from the GLO file.
375  * \param data The attribute to set and its associated data.
376  */
377  virtual GLSGEN_GLSLINEARSCALE_EXPORT void SetFromGloData( GlsGloFileAttribute& data );
378 #endif
379 
380 #ifndef GLES
381  /** Calculates current tick mark locations and performs OpenGL drawing commands */
382  virtual void DrawGeometry( void );
383 #endif
384 
385  /** Two radius vectors that are used to define the orientation of the scale */
387 
388  /** Normalized radius vectors, cached because they are needed often */
390 
391  /** The particulars of each scale */
392  GlsLinearScaleDataArray _scale;
393 
394  /** True if duplicated tick marks are removed */
396 
397  /** True if haloing is enabled */
399 
400  /** Width of the halo in logical units */
401  float _haloWidth;
402 
403  /** Color of the halo */
405 
406  /** Anchor to determine where ticks will draw */
407  GlsTickAnchor _tickAnchor;
408 
409 #ifndef GLES
410  /** True if scale is drawn with polygon quads instead of lines*/
412 #endif
413 };
414 
415 /** Metadata for scale data */
417 {
418 protected:
419  GlsLinearScaleDataArray* _attribPtr;
420  unsigned int _arraySize;
421 
422 public:
423  DistiAttributeConnectionGlsLinearScaleDataArray( CallbackMethodCallerBase* callback, const AttributeName& name, GlsLinearScaleDataArray* attribPtr, int arraySize )
424  : DistiAttributeBase( callback, name, false )
425  , _attribPtr( attribPtr )
426  , _arraySize( arraySize )
427  {
428  }
429 
431  virtual bool OkToWrite() const;
432  virtual std::ostream& WriteValue( std::ostream& outstr );
433  virtual std::istream& ReadValue( std::istream& instr );
434 };
435 
436 } // namespace disti
437 
438 #endif
Definition: cull.h:49
bool _haloEnabled
Definition: gls_linear_scale.h:398
void DrawScale(int i, float haloLength, float haloThickness)
bool active
Definition: gls_linear_scale.h:98
float HaloWidth(void)
Definition: gls_linear_scale.h:261
Definition: vertex.h:408
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar)
void GetScale(int index, GlsLinearScaleData &data)
GlsColor _currentColor
Definition: gls_linear_scale.h:327
GlsTickAnchor TickAnchor(void)
Definition: gls_linear_scale.h:281
void InvalidateGeometry(void)
Definition: gls_linear_scale.h:305
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:246
Definition: dynamic_array.h:62
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:278
float _haloWidth
Definition: gls_linear_scale.h:401
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:97
The disti::GLPolygon class. Implements Polygons.
float startingOffset
Definition: gls_linear_scale.h:101
bool UseScalableLines(void)
Definition: gls_linear_scale.h:297
bool _useScalableLines
Definition: gls_linear_scale.h:411
Definition: gls_display_list.h:50
unsigned int ticks
Definition: gls_linear_scale.h:100
Definition: gls_glo_file.h:835
GlsLinearScaleDataArray _scale
Definition: gls_linear_scale.h:392
virtual void SetValue(int spec, va_list &args)
GlsColor HaloColor(void)
Definition: gls_linear_scale.h:271
bool HaloEnabled(void)
Definition: gls_linear_scale.h:251
void UpdateScaleData(void)
float interval
Definition: gls_linear_scale.h:102
void CurrentColor(const GlsColor &newColor)
Vector _radiiNormalized[2]
Definition: gls_linear_scale.h:389
virtual void DrawGeometry(void)
bool _deconflictTicks
Definition: gls_linear_scale.h:395
Definition: disti_metadata.h:174
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:339
Definition: gls_color.h:53
virtual DisplayObject * CloneObject(bool generateNames=false)
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler)
Definition: disti_metadata.h:667
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
Definition: callback_caller_base.h:55
The gls_auto_lib.
Definition: gls_linear_scale.h:175
virtual std::istream & ReadValue(std::istream &instr)
GlsTickAnchor _tickAnchor
Definition: gls_linear_scale.h:407
virtual std::ostream & WriteValue(std::ostream &outstr)
float _currentLineWidth
Definition: gls_linear_scale.h:331
Definition: vertex.h:83
float thickness
Definition: gls_linear_scale.h:104
GlsColor _haloColor
Definition: gls_linear_scale.h:404
virtual void SetColor(const GlsColor &color)
GlsColor color
Definition: gls_linear_scale.h:105
GlsDisplayList & DisplayList(void)
Definition: gls_linear_scale.h:308
Vector _radii[2]
Definition: gls_linear_scale.h:386
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:342
Definition: disti_metadata.h:79
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:335