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 )
291  {
292  _geometryRefresh = true;
294  }
295 #endif
296 
297 #ifndef GLES
298  /** Gets the drawing mode for this scale
299  * \return The drawing mode for this scale
300  */
301  GLSGEN_GLSLINEARSCALE_EXPORT bool UseScalableLines( void ) { return _useScalableLines; }
302 
303  /** Sets the drawing mode for this scale
304  * \param val New drawing mode
305  */
306  GLSGEN_GLSLINEARSCALE_EXPORT void UseScalableLines( const bool& val );
307 
308  /** Causes the display list for this object to be recomputed */
309  GLSGEN_GLSLINEARSCALE_EXPORT void InvalidateGeometry( void )
310  {
313  }
314 
315  /** Returns a reference to this object's display list */
316  GLSGEN_GLSLINEARSCALE_EXPORT GlsDisplayList& DisplayList( void ) { return _displayList; }
317 #endif
318 
319 protected:
320 #ifdef GLES
321  /** Manages a VBO for drawing the tick marks */
322  GlsQuadListVC_3D _quads;
323 
324  /** Updates the VBO when the object changes */
325  void BakeVBO();
326 #else
327  /** Minimizes calls to glColor when drawing the scale */
328  void CurrentColor( const GlsColor& newColor );
329 
330  /** Minimizes calls to glLineWidth when drawing the scale */
331  void CurrentLineWidth( const float& newLineWidth );
332 
333  /** Stores the current color. Used when calculating a new display list so that redundant
334  * glColor calls are not made */
336 
337  /** Stores the current line width. Used when calculating a new display list so that redundant
338  * glLineWidth calls are not made */
340 
341  /** True if the current color has been set. Gets reset every time a new display list is
342  * recalculated. */
344 
345  /** True if the current line width has been set. Gets reset every time a new display list is
346  * recalculated. */
348 
349  /** Stores the scale in a display list for faster drawing */
351 #endif
352 
353  /** Recomputes the object's vertices from its radii */
354  void RecomputeVertices( void );
355 
356  /** Recomputes the object's vertices and its radii */
357  void UpdateScaleData( void );
358 
359  /** Determines if a tick with the given offset should be drawn or not. If a higher priority
360  * scale already has a tick at that level and deconfliction is enabled, then this method
361  * will return false */
362  bool TickNeeded( int currentLevel, float currentOffset );
363 
364 #ifdef GLES
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  * \param color The color of the scale
370  */
371  void DrawScale( int i, float haloLength, float haloThickness, GlsColor& color );
372 #else
373  /** Calculates and draws a single scale using the given halo length and thickness
374  * \param i The index of the scale to draw
375  * \param haloLength The length of the halo
376  * \param haloThickness The thickness of the halo
377  */
378  void DrawScale( int i, float haloLength, float haloThickness );
379 #endif
380 
381 #ifdef GLES
382  /** Set a single attribute from the GLO file.
383  * \param data The attribute to set and its associated data.
384  */
385  virtual GLSGEN_GLSLINEARSCALE_EXPORT void SetFromGloData( GlsGloFileAttribute& data );
386 #endif
387 
388 #ifndef GLES
389  /** Calculates current tick mark locations and performs OpenGL drawing commands */
390  virtual void DrawGeometry( void );
391 #endif
392 
393  /** Two radius vectors that are used to define the orientation of the scale */
395 
396  /** Normalized radius vectors, cached because they are needed often */
398 
399  /** The particulars of each scale */
400  GlsLinearScaleDataArray _scale;
401 
402  /** True if duplicated tick marks are removed */
404 
405  /** True if haloing is enabled */
407 
408  /** Width of the halo in logical units */
409  float _haloWidth;
410 
411  /** Color of the halo */
413 
414  /** Anchor to determine where ticks will draw */
415  GlsTickAnchor _tickAnchor;
416 
417 #ifndef GLES
418  /** True if scale is drawn with polygon quads instead of lines*/
420 #endif
421 };
422 
423 /** Metadata for scale data */
425 {
426 protected:
427  GlsLinearScaleDataArray* _attribPtr;
428  unsigned int _arraySize;
429 
430 public:
431  DistiAttributeConnectionGlsLinearScaleDataArray( CallbackMethodCallerBase* callback, const AttributeName& name, GlsLinearScaleDataArray* attribPtr, int arraySize )
432  : DistiAttributeBase( callback, name, false )
433  , _attribPtr( attribPtr )
434  , _arraySize( arraySize )
435  {
436  }
437 
438  virtual GLSGEN_GLSLINEARSCALE_EXPORT ~DistiAttributeConnectionGlsLinearScaleDataArray();
439  virtual GLSGEN_GLSLINEARSCALE_EXPORT bool OkToWrite() const;
440  virtual GLSGEN_GLSLINEARSCALE_EXPORT std::ostream& WriteValue( std::ostream& outstr );
441  virtual GLSGEN_GLSLINEARSCALE_EXPORT std::istream& ReadValue( std::istream& instr );
442 };
443 
444 } // namespace disti
445 
446 #endif
Definition: cull.h:49
bool _haloEnabled
Definition: gls_linear_scale.h:406
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:335
GlsTickAnchor TickAnchor(void)
Definition: gls_linear_scale.h:281
void InvalidateGeometry(void)
Definition: gls_linear_scale.h:309
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:276
float _haloWidth
Definition: gls_linear_scale.h:409
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:301
bool _useScalableLines
Definition: gls_linear_scale.h:419
Definition: gls_display_list.h:50
unsigned int ticks
Definition: gls_linear_scale.h:100
Definition: gls_glo_file.h:982
GlsLinearScaleDataArray _scale
Definition: gls_linear_scale.h:400
virtual void SetValue(int spec, va_list &args)
GlsColor HaloColor(void)
Definition: gls_linear_scale.h:271
void InvalidatePainter()
Definition: display.h:1717
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:397
virtual void DrawGeometry(void)
bool _deconflictTicks
Definition: gls_linear_scale.h:403
Definition: disti_metadata.h:180
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:347
Definition: gls_color.h:53
virtual DisplayObject * CloneObject(bool generateNames=false)
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler)
Definition: disti_metadata.h:673
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:415
virtual std::ostream & WriteValue(std::ostream &outstr)
float _currentLineWidth
Definition: gls_linear_scale.h:339
Definition: vertex.h:83
float thickness
Definition: gls_linear_scale.h:104
GlsColor _haloColor
Definition: gls_linear_scale.h:412
virtual void SetColor(const GlsColor &color)
GlsColor color
Definition: gls_linear_scale.h:105
GlsDisplayList & DisplayList(void)
Definition: gls_linear_scale.h:316
Vector _radii[2]
Definition: gls_linear_scale.h:394
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:350
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:343