GL Studio C++ Runtime API
gls_map_symbology_basic_data_source.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsMapSymbologyBasicDataSource class.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2017 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 INCLUDED_GLS_MAP_SYMBOLOGY_BASIC_DATA_SOURCE_H_
41 #define INCLUDED_GLS_MAP_SYMBOLOGY_BASIC_DATA_SOURCE_H_
42 
43 #include "gls_map_symbology.h"
45 
46 #include "events.h"
47 #include "group.h"
48 
49 namespace disti
50 {
51 /* This section defines the standard symbology data source classes.
52  * The user may use one of these classes to store the symbology data
53  * or define their own MapSymbologyDataSource to provide direct access
54  * to another database. */
55 
56 ////////////////////////////////////////////////////////
57 // GlsMapSymbologyBasicDataSource template
58 ////////////////////////////////////////////////////////
59 
60 /// Basic icon data storage that may be used with the GlsMapSymbologyBasicDataSource class
62 {
63 public:
64  /// Set the icon location
65  inline void SetLocation( const GeoCoord& value ) { _location = value; }
66  /// Get the icon location
67  inline const GeoCoord& GetLocation() { return _location; }
68  /// Set the icon type (geometry index)
69  inline void SetType( int value ) { _type = value; }
70  /// Get the icon type (geometry index)
71  inline int GetType() { return _type; }
72 
74  : _type( 0 )
75  {}
76 
77 protected:
78  GeoCoord _location;
79  int _type;
80 };
81 
82 /// Basic path data storage that may be used with the GlsMapSymbologyBasicDataSource class
84 {
85 public:
86  /// Set the number of points in the path.
87  /// Point locations will be uninitialized.
88  inline void SetPointCount( unsigned int value )
89  {
90  _points.Count( value );
91  InvalidateBoundingRect();
92  }
93 
94  /// \returns the number of points in the path
95  inline unsigned int GetPointCount() { return _points.Count(); }
96 
97  /// Set the location of a given point
98  /// If the point does not exist, the point count will be increased
99  /// to point+1. Any other new points allocated as a result of the
100  /// increased count will be uninitialized.
101  inline void SetPointLocation( int point, const GeoCoord& location )
102  {
103  _points[ point ] = location;
104  InvalidateBoundingRect();
105  }
106 
107  /// \returns the location of the given point
108  inline const GeoCoord& GetPointLocation( int point ) { return _points[ point ]; }
109 
110  /// Set the path type (geometry index)
111  /// Set to -1 to use the default path appearance.
112  inline void SetType( int value ) { _type = value; }
113 
114  /// Get the path type (geometry index)
115  inline int GetType() { return _type; }
116 
117  /// return the bounding rectangle for the given path
118  inline const GeoRect& GetBoundingRect()
119  {
120  if( !_boundingRectIsValid )
121  {
122  CalculateBoundingRect();
123  }
124  return _boundingRect;
125  }
126 
127  inline void InvalidateBoundingRect() { _boundingRectIsValid = false; }
128 
129  GlsMapSymbologyBasicPath()
130  : _type( -1 )
131  , _boundingRectIsValid( false )
132  {}
133 
134 protected:
135  inline void CalculateBoundingRect()
136  {
137  _boundingRect.SetToNull();
138  for( unsigned int i = 0; i < _points.Count(); i++ )
139  {
140  _boundingRect.GrowToContainPoint( _points[ i ] );
141  }
142  }
143 
144  DynamicArray<GeoCoord, false> _points;
145  int _type;
146  bool _boundingRectIsValid;
147  GeoRect _boundingRect;
148 };
149 
150 // This is a basic implementation of the
151 // MapSymbologyDataSource that users can derive from.
152 // Users may also create a data source that derives
153 // directly from the MapSymbologyDataSource
154 // interface if they prefer.
155 // This is a template class to allow the user to use
156 // their own icon and path storage classes if desired.
157 // The GlsMapSymbologyBasicIcon and GlsMapSymbologyBasicPath
158 // classes are provided as a possible starting point
159 // for the icon and path storage implementation.
160 template<class IconT, class PathT>
162 {
163 public:
164  ////////////////////////////////////////////////////////
165  // MapSymbologyDataSource interface
166  ////////////////////////////////////////////////////////
167 
168  /// See base class
169  virtual void GetSymbolsInRegion( GlsMapSymbology* symbology, const GeoRect& region, IconIDList& icons, PathIDList& paths )
170  {
171  icons.Count( 0 );
172  paths.Count( 0 );
173 
174  // Iterate through the icons and return the list of icons that are
175  // inside the region.
176  {
177  const unsigned int iconCount = GetIconCount();
178  IconT* current;
179  IconID iconID;
180  for( unsigned int iconIdx = 0; iconIdx < iconCount; iconIdx++ )
181  {
182  iconID = _iconIDArray[ iconIdx ];
183  current = GetIcon( iconID );
184  if( current && IconIsVisible( current ) && region.ContainsPoint( current->GetLocation() ) )
185  {
186  icons.PushBack( iconID );
187  }
188  }
189  }
190 
191  // Iterate through the paths and return the list of paths that
192  // intersect the region.
193  {
194  const unsigned int pathCount = GetPathCount();
195  PathT* current;
196  PathID pathID;
197  for( unsigned int pathIdx = 0; pathIdx < pathCount; pathIdx++ )
198  {
199  pathID = _pathIDArray[ pathIdx ];
200  current = GetPath( pathID );
201  if( current && PathIsVisible( current ) && region.Intersects( current->GetBoundingRect() ) )
202  {
203  paths.PushBack( pathID );
204  }
205  }
206  }
207  }
208 
209  /// See base class
210  virtual DisplayObject* GetIconGeometry( IconID iconID, GlsMapSymbology* symbology )
211  {
212  // Return the DisplayObject in the symbology group
213  // that should be used to draw the given icon.
214  IconT* icon = GetIcon( iconID );
215  if( icon )
216  {
217  int geomIndex = icon->GetType();
218  if( symbology && geomIndex > -1 && ( (unsigned int)geomIndex ) < symbology->Count() )
219  {
220  return symbology->Item( geomIndex );
221  }
222  }
223 
224  return NULL; // No icon found
225  }
226 
227  /// See base class
228  virtual void GetIconLocation( IconID iconID, GeoCoord& location )
229  {
230  IconT* icon = GetIcon( iconID );
231  if( icon )
232  {
233  location = icon->GetLocation();
234  }
235  }
236 
237  /// See base class
238  virtual DisplayObject* GetPathGeometry( PathID pathID, GlsMapSymbology* symbology )
239  {
240  // Return the DisplayObject in the symbology group
241  // that should be used to draw the given path.
242  PathT* path = GetPath( pathID );
243  if( path )
244  {
245  int geomIndex = path->GetType();
246  if( geomIndex > -1 && symbology && ( (unsigned int)geomIndex ) < symbology->Count() )
247  {
248  return symbology->Item( geomIndex );
249  }
250  }
251 
252  return NULL; // Use the default path geometry
253  }
254 
255  /// See base class
256  virtual long GetPathPointCount( PathID pathID )
257  {
258  PathT* path = GetPath( pathID );
259  if( path )
260  return path->GetPointCount();
261  else
262  return 0;
263  }
264 
265  /// See base class
266  virtual void GetPathPointLocation( PathID pathID, long point, GeoCoord& locationOut )
267  {
268  PathT* path = GetPath( pathID );
269  if( path )
270  {
271  locationOut = path->GetPointLocation( point );
272  }
273  }
274 
275  /// See base class
276  virtual void SetupIconForRendering( GlsMapSymbology*, IconID iconID, DisplayObject* iconGeometry )
277  {
278  // Override this to apply any custom data to the icons when they draw
279  }
280 
281  /// See base class
282  virtual void SetupPathForRendering( GlsMapSymbology*, PathID pathID, DisplayObject* iconGeometry )
283  {
284  // Override this to apply any custom data to the paths when they draw
285  }
286 
287  /// See base class
288  virtual void PostDraw( disti::GlsMapView* view, disti::GlsMapSymbology* symbology )
289  {
290  // Override this to perform additional rendering if needed.
291  }
292 
293  ////////////////////////////////////////////////////////
294  // GlsMapSymbologyBasicDataSource functionality...
295  ////////////////////////////////////////////////////////
296 
297  /// Derived classes can override this method
298  /// to disable drawing of certain icon types.
299  virtual bool IconIsVisible( IconT* icon )
300  {
301  return true;
302  }
303 
304  /// Derived classes can override this method
305  /// to disable drawing of certain path types.
306  virtual bool PathIsVisible( PathT* path )
307  {
308  return true;
309  }
310 
311  /// Add an icon to the data source
312  /// \param location The location of the new icon
313  /// \param geometryIndex The geometry index to use for drawing. (-1 indicates do not draw)
314  /// \returns the IconID for the new icon
315  virtual IconID AddIcon( const GeoCoord& location, int geometryIndex )
316  {
317  IconT icon;
318 
319  icon.SetLocation( location );
320  icon.SetType( geometryIndex );
321 
322  IconID id = GetNextIconID();
323  _iconArray.PushBack( icon );
324  _iconIDArray.PushBack( id );
325  return id;
326  }
327 
328  /// Access an icon in the data source
329  /// \param iconID IconID of the desired icon
330  /// \returns Pointer to the given icon, or NULL if not found
331  virtual IconT* GetIcon( IconID iconID )
332  {
333  int idx = FindIconByID( iconID );
334  if( idx == -1 )
335  return NULL;
336 
337  return &( _iconArray[ idx ] );
338  }
339 
340  /// \returns The number of icons in the data source
341  virtual unsigned int GetIconCount()
342  {
343  return _iconArray.Count();
344  }
345 
346  /// Updates the given icon if it exists
347  /// \param iconID The identifier of the icon to update
348  /// \param location The new location of the icon
349  virtual void UpdateIcon( IconID iconID, GeoCoord& location )
350  {
351  IconT* icon = GetIcon( iconID );
352  if( icon )
353  {
354  icon->SetLocation( location );
355  }
356  }
357 
358  /// Updates the given icon if it exists
359  /// \param iconID The identifier of the icon to update
360  /// \param location The new location of the icon
361  /// \param geometryIndex The geometry index to use for drawing.
362  virtual void UpdateIcon( IconID iconID, GeoCoord& location, int geometryIndex )
363  {
364  IconT* icon = GetIcon( iconID );
365  if( icon )
366  {
367  icon->SetLocation( location );
368  icon->SetType( geometryIndex );
369  }
370  }
371 
372  /// Add a path to the data source
373  /// Call GetPath() with the returned PathID to
374  /// access the new path and add/modify points in the path.
375  /// \sa GetPath
376  /// \returns the PathID of the new path
377  virtual PathID AddPath()
378  {
379  PathT path;
380 
381  PathID id = GetNextPathID();
382  _pathArray.PushBack( path );
383  _pathIDArray.PushBack( id );
384  return id;
385  }
386 
387  /// Access a path in the data source
388  /// \param pathID PathID of the desired path
389  /// \returns Pointer to the given path, or NULL if not found
390  virtual PathT* GetPath( PathID pathID )
391  {
392  int idx = FindPathByID( pathID );
393  if( idx == -1 )
394  return NULL;
395 
396  return &( _pathArray[ idx ] );
397  }
398 
399  /// \returns The number of paths in the data source
400  virtual unsigned int GetPathCount()
401  {
402  return _pathArray.Count();
403  }
404 
405  /// Remove a icon from the data source
406  virtual void RemoveIcon( IconID iconID )
407  {
408  int idx = FindIconByID( iconID );
409  if( idx > -1 )
410  {
411  _iconArray.EraseAt( idx );
412  _iconIDArray.EraseAt( idx );
413  }
414  }
415 
416  /// Remove a path from the data source
417  virtual void RemovePath( PathID pathID )
418  {
419  int idx = FindPathByID( pathID );
420  if( idx > -1 )
421  {
422  _pathArray.EraseAt( idx );
423  _pathIDArray.EraseAt( idx );
424  }
425  }
426 
427  /// Remove all icons from the data source
428  virtual void RemoveAllIcons()
429  {
430  _iconArray.Count( 0 );
431  _iconIDArray.Count( 0 );
432  }
433 
434  /// Remove all paths from the data source
435  virtual void RemoveAllPaths()
436  {
437  _pathArray.Count( 0 );
438  _pathIDArray.Count( 0 );
439  }
440 
442  {
443  _nextIconID = 1;
444  _nextPathID = 1;
445  }
446 
447  virtual ~GlsMapSymbologyBasicDataSource()
448  {
449  RemoveAllIcons();
450  RemoveAllPaths();
451  }
452 
453 protected:
454  DynamicArray<IconT, false> _iconArray;
455  DynamicArray<IconID> _iconIDArray; // Parallel array contains Icon IDs for Icon entries
456  IconID _nextIconID;
457  IconID GetNextIconID() { return _nextIconID++; }
458 
459  int FindIconByID( IconID id )
460  {
461  for( unsigned int i = 0; i < _iconIDArray.Count(); i++ )
462  if( _iconIDArray[ i ] == id )
463  return (int)i;
464 
465  return -1;
466  }
467 
468  DynamicArray<PathT, false> _pathArray;
469  DynamicArray<PathID> _pathIDArray; // Parallel array contains Path IDs for Path entries
470  PathID _nextPathID;
471  PathID GetNextPathID() { return _nextPathID++; }
472 
473  int FindPathByID( PathID id )
474  {
475  for( unsigned int i = 0; i < _pathIDArray.Count(); i++ )
476  if( _pathIDArray[ i ] == id )
477  return (int)i;
478 
479  return -1;
480  }
481 };
482 
483 } // namespace disti
484 #endif
bool Intersects(const GeoRect &other) const
Definition: gls_map_util.h:522
unsigned int Count(void) const
Definition: group.h:173
virtual unsigned int GetIconCount()
Definition: gls_map_symbology_basic_data_source.h:341
virtual void UpdateIcon(IconID iconID, GeoCoord &location)
Definition: gls_map_symbology_basic_data_source.h:349
virtual void RemoveAllPaths()
Remove all paths from the data source.
Definition: gls_map_symbology_basic_data_source.h:435
unsigned Count() const
Definition: dynamic_array.h:204
The disti::Group class. Implements groups of objects.
The disti::MapSymbologyDataSource class.
Definition: gls_map_util.h:414
Basic icon data storage that may be used with the GlsMapSymbologyBasicDataSource class.
Definition: gls_map_symbology_basic_data_source.h:61
unsigned int GetPointCount()
Definition: gls_map_symbology_basic_data_source.h:95
Definition: display.h:98
The GlsMapView is a special group that controls the map view parameters. It contains all of the objec...
Definition: gls_map_view.h:86
virtual IconT * GetIcon(IconID iconID)
Definition: gls_map_symbology_basic_data_source.h:331
DisplayObject * Item(unsigned int index)
virtual void SetupIconForRendering(GlsMapSymbology *, IconID iconID, DisplayObject *iconGeometry)
See base class.
Definition: gls_map_symbology_basic_data_source.h:276
Definition: gls_map_util.h:67
virtual void GetIconLocation(IconID iconID, GeoCoord &location)
See base class.
Definition: gls_map_symbology_basic_data_source.h:228
bool ContainsPoint(const GeoCoord &point) const
Definition: gls_map_util.h:448
Definition: gls_map_symbology_data_source.h:58
void SetToNull()
Definition: gls_map_util.h:462
Basic path data storage that may be used with the GlsMapSymbologyBasicDataSource class.
Definition: gls_map_symbology_basic_data_source.h:83
void SetLocation(const GeoCoord &value)
Set the icon location.
Definition: gls_map_symbology_basic_data_source.h:65
const GeoRect & GetBoundingRect()
return the bounding rectangle for the given path
Definition: gls_map_symbology_basic_data_source.h:118
virtual void RemovePath(PathID pathID)
Remove a path from the data source.
Definition: gls_map_symbology_basic_data_source.h:417
Definition: gls_map_symbology_basic_data_source.h:161
virtual void RemoveIcon(IconID iconID)
Remove a icon from the data source.
Definition: gls_map_symbology_basic_data_source.h:406
The disti::GlsMapSymbology class.
The standard Mouse and keyboard events and event structures.
virtual bool PathIsVisible(PathT *path)
Definition: gls_map_symbology_basic_data_source.h:306
virtual void UpdateIcon(IconID iconID, GeoCoord &location, int geometryIndex)
Definition: gls_map_symbology_basic_data_source.h:362
virtual IconID AddIcon(const GeoCoord &location, int geometryIndex)
Definition: gls_map_symbology_basic_data_source.h:315
const GeoCoord & GetLocation()
Get the icon location.
Definition: gls_map_symbology_basic_data_source.h:67
int GetType()
Get the path type (geometry index)
Definition: gls_map_symbology_basic_data_source.h:115
virtual PathT * GetPath(PathID pathID)
Definition: gls_map_symbology_basic_data_source.h:390
const GeoCoord & GetPointLocation(int point)
Definition: gls_map_symbology_basic_data_source.h:108
virtual void SetupPathForRendering(GlsMapSymbology *, PathID pathID, DisplayObject *iconGeometry)
See base class.
Definition: gls_map_symbology_basic_data_source.h:282
virtual DisplayObject * GetPathGeometry(PathID pathID, GlsMapSymbology *symbology)
See base class.
Definition: gls_map_symbology_basic_data_source.h:238
virtual void RemoveAllIcons()
Remove all icons from the data source.
Definition: gls_map_symbology_basic_data_source.h:428
virtual PathID AddPath()
Definition: gls_map_symbology_basic_data_source.h:377
virtual bool IconIsVisible(IconT *icon)
Definition: gls_map_symbology_basic_data_source.h:299
void SetPointCount(unsigned int value)
Definition: gls_map_symbology_basic_data_source.h:88
virtual void GetPathPointLocation(PathID pathID, long point, GeoCoord &locationOut)
See base class.
Definition: gls_map_symbology_basic_data_source.h:266
unsigned PushBack(const T &object)
Definition: dynamic_array.h:325
Definition: gls_map_symbology.h:86
bool EraseAt(const unsigned index)
Definition: dynamic_array.h:409
virtual long GetPathPointCount(PathID pathID)
See base class.
Definition: gls_map_symbology_basic_data_source.h:256
virtual unsigned int GetPathCount()
Definition: gls_map_symbology_basic_data_source.h:400
void GrowToContainPoint(const GeoCoord &point)
Definition: gls_map_util.h:493
void SetPointLocation(int point, const GeoCoord &location)
Definition: gls_map_symbology_basic_data_source.h:101
virtual void GetSymbolsInRegion(GlsMapSymbology *symbology, const GeoRect &region, IconIDList &icons, PathIDList &paths)
See base class.
Definition: gls_map_symbology_basic_data_source.h:169
void SetType(int value)
Set the icon type (geometry index)
Definition: gls_map_symbology_basic_data_source.h:69
Definition: bmpimage.h:46
virtual void PostDraw(disti::GlsMapView *view, disti::GlsMapSymbology *symbology)
See base class.
Definition: gls_map_symbology_basic_data_source.h:288
int GetType()
Get the icon type (geometry index)
Definition: gls_map_symbology_basic_data_source.h:71
virtual DisplayObject * GetIconGeometry(IconID iconID, GlsMapSymbology *symbology)
See base class.
Definition: gls_map_symbology_basic_data_source.h:210
void SetType(int value)
Definition: gls_map_symbology_basic_data_source.h:112