GL Studio C++ Runtime API
gls_map_chart_data_source.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsMapChartDataSource class.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2017 The DiSTI Corporation.<br>
7  11301 Corporate Blvd; Suite 190<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_CHART_DATA_SOURCE_H
41 #define INCLUDED_GLS_MAP_CHART_DATA_SOURCE_H
42 
43 #include "dynamic_array.h"
44 #include "gls_cpp_lang_support.h"
45 #include "gls_map_util.h"
46 
47 #include <iosfwd>
48 
49 namespace disti
50 {
51 class GlsMapView;
52 class GlsMapChart;
53 class GlsMapChartDataSource;
54 
55 /// \brief The MapChartCell class represents an area within a 2D map.
56 ///
57 /// MapChartCells are obtained from a GlsMapChartDataSource by calling the
58 /// GlsMapChartDataSource::GetCellList() method.
59 /// Each MapChartCell may provide a texture for rendering or it may use
60 /// it's own custom rendering method to draw its data.
61 /// The data needed to render the cell may not have been loaded yet,
62 /// the caller can set the priority of various cells to control the order
63 /// in which they are loaded.
65 {
66 public:
67  /// Constructor
68  /// \param logicalHeight The viewing height in logical space.
70  : _loadPriority( 0 )
71  , _referenceCount( 1 )
72  , _geoRectSet( false )
73  {
74  }
75 
76  /// Use this method to increment the reference count of the MapDataSource.
77  virtual void AddRef()
78  {
79  _referenceCount++;
80  }
81 
82  /// MapCells cannot be deleted directly
83  /// Use this method to decrement the reference count of the MapDataSource.
84  virtual void Release()
85  {
86  _referenceCount--;
87  if( _referenceCount < 1 )
88  {
89  delete this;
90  }
91  }
92 
93  /// Instructs the MapChart Cell Manager whether to calculate and display cell outlines.
94  /// \return True if the outlines should be drawn.
95  ///
96  virtual bool AllowOutlines() const { return true; }
97 
98  /// Determine if this cell is still valid. Invalid cells are cells that are no longer
99  /// relevant for a given data source (e.g. backing data for cell is unloaded).
100  /// \return true if the cell is valid, false if the cell is not valid
101  virtual bool IsCellValid() const { return true; }
102 
103  /// Returns the MapDataSource for this MapCell
104  virtual GlsMapChartDataSource* GetSource() const = 0;
105 
106  /// Integer representing the layer of this image.
107  /// Images from the same MapDataSource with the same Layer number all contain data
108  /// at the same resolution (i.e. 'zoom level') and can be drawn together.
109  virtual unsigned long GetLayerID() const { return 0; }
110 
111  /// \returns The GeoRect that describes the coverage area for the cell.
112  const GeoRect& GetGeoRect() const
113  {
114  if( !_geoRectSet )
115  {
116  MapChartCell* nonConst = const_cast<MapChartCell*>( this );
117  nonConst->_geoRect.SetToPoint( _lowerLeft );
118  nonConst->_geoRect.GrowToContainPoint( _upperRight );
119  nonConst->_geoRectSet = true;
120  }
121 
122  return _geoRect;
123  }
124 
125  GeoCoord& GetLowerLeftCoord() { return _lowerLeft; }
126  GeoCoord& GetLowerRightCoord() { return _lowerRight; }
127  GeoCoord& GetUpperLeftCoord() { return _upperLeft; }
128  GeoCoord& GetUpperRightCoord() { return _upperRight; }
129 
130  /// The priority of this cell in the loading order.
131  /// 0 is the highest priority.
132  /// This is typically set by the CellMgr.
133  virtual void SetLoadPriority( unsigned int val ) { _loadPriority = val; }
134  virtual unsigned int GetLoadPriority() const { return _loadPriority; }
135 
136  /// Determine if this cell displays a texture.
137  /// If this returns true, you should call TextureIsReady() to determine
138  /// if the texture data has loaded and BindTexture() to bind the texture
139  /// to the current OpenGL context.
140  /// \returns true if this cell is capable of loading a texture
141  virtual bool HasTexture() const = 0;
142 
143  /// \returns true if BindTexture will apply a texture when called.
144  virtual bool TextureIsReady() const = 0;
145 
146  /// If TextureIsReady() is true, this method will bind the texture for the cell. You must call UnbindTexture() to unbind the texture
147  /// If TextureIsReady() is false, this method does nothing.
148  virtual void BindTexture() = 0;
149 
150  /// Use this method to force the texture to be recreated on the next call to BindTexture().
151  virtual void InvalidateTexture() = 0;
152 
153  /// The post draw callback for each cell should be called after all
154  /// of the MapCell textures have been drawn to allow the MapCells to
155  /// render any overlay geometry
156  /// \param view The GlsMapView used to draw the chart
157  /// \param chart The GlsMapChart that is being drawn
158  virtual void PostDraw( GlsMapView* view, GlsMapChart* chart ) {}
159 
160  /// Determine if two MapCells are equivalent
161  /// \param other Reference to the MapChartCell to compare to
162  /// \returns true if the cells are equivalent, false otherwise
163  virtual bool IsSameCell( const MapChartCell& other ) const = 0;
164 
165  /// Prints some information about the cell
166  /// \sa MapChartCell::Write()
167  friend std::ostream& operator<<( std::ostream& os, const MapChartCell& cell )
168  {
169  cell.Write( os ); // Call virtual function
170  return os;
171  }
172 
173 protected:
174  int _referenceCount;
175  unsigned int _loadPriority;
176  GeoRect _geoRect;
177  bool _geoRectSet;
178  GeoCoord _lowerLeft;
179  GeoCoord _lowerRight;
180  GeoCoord _upperLeft;
181  GeoCoord _upperRight;
182 
183  /// Destructor for abstract base class
184  /// \note Protected for proper reference counting -- call Release() instead of destroying directly.
185  virtual ~MapChartCell() {}
186 
187  /// Method to override for printing to a stream
188  virtual void Write( std::ostream& os ) const;
189 
190 private:
191  MapChartCell( const MapChartCell& ) DISTI_SPECIAL_MEM_FUN_DELETE;
192  void operator=( const MapChartCell& ) DISTI_SPECIAL_MEM_FUN_DELETE;
193 };
194 
195 /// See MapChartCell::IsSameCell
196 inline bool operator==( const MapChartCell& rhs, const MapChartCell& lhs )
197 {
198  return rhs.IsSameCell( lhs );
199 }
200 
201 typedef DynamicArray<MapChartCell*> MapChartCellList;
202 
203 /** /class MapDataSource
204  *
205  * Abstract base class to encapsulate map library specific code and data.
206  *
207  * Provides a list of MapCells for a given coverage area and layer.
208  * A MapDataSource may have just one layer or many layers of MapCells available.
209  */
211 {
212 public:
213  /// Destructor for abstract base class
214  virtual ~GlsMapChartDataSource();
215 
216  /// Sets a GeoRect to describe the area containing all areas
217  /// covered by this MapDataSource. This area may change as different
218  /// databases are loaded. Calling this method may be slow.
219  /// \dest Pointer to a GeoRect to recieve the coverage.
220  /// \returns true on success (dest contains the coverage description) or false if there was an error (dest is undefined)
221  virtual bool GetAvailableCoverage( GeoRect* dest ) = 0;
222 
223  /// Returns the cell layer ('zoom level') that best matches the given area
224  /// \param view The GlsMapView used to draw the chart
225  /// \param chart The GlsMapChart that is being drawn
226  /// \returns The recommended layer to use
227  /// \note Data sources that do not support layers should always return 0.
228  virtual unsigned long GetBestLayer( GlsMapView* view, GlsMapChart* chart ) const { return 0; }
229 
230  /// Get the list of the available cells in a given coverage area
231  /// The caller will AddRef() any of the cells that it will be holding a reference to
232  /// \param coverage GeoRect describing the requested area
233  /// \param layerID Which layer to return MapCells from
234  /// \param viewLogicalHeight The height of the view in logical units
235  /// \param viewGeoHeight The height of the view in geographic units
236  /// \param viewList Pointer MapChartCellList to recieve the list of available cells
237  virtual void GetCellList( const GeoRect& coverage, unsigned long layerID, double viewLogicalHeight, double viewGeoHeight, MapChartCellList& viewList ) = 0;
238 
239  /// Called after all the cells have been drawn to allow the
240  /// data source to perform additional rendering if needed
241  /// \param view The GlsMapView used to draw the chart
242  /// \param chart The GlsMapChart that is being drawn
243  virtual void PostDraw( GlsMapView* view, GlsMapChart* chart ) {}
244 
245  /// Returns if all of the visible cells have finished loading and will be visible
246  /// on the next frame
247  /// \param view The GlsMapView used to draw the chart
248  /// \param chart The GlsMapChart that is being drawn
249  /// \return If all cells are loaded in a view
250  virtual bool AreAllCellsLoaded( GlsMapView* view, GlsMapChart* chart );
251 
252 protected:
253  /// Constructor for subclasses
255 
256 private:
257  GlsMapChartDataSource( const GlsMapChartDataSource& ) DISTI_SPECIAL_MEM_FUN_DELETE;
258  void operator=( const GlsMapChartDataSource& ) DISTI_SPECIAL_MEM_FUN_DELETE;
259 };
260 
261 // Must be defined outside the class body in C++11, but not C++14
264 
265 } // namespace disti
266 
267 #endif
void SetToPoint(const GeoCoord &point)
Definition: gls_map_util.h:477
virtual void InvalidateTexture()=0
Use this method to force the texture to be recreated on the next call to BindTexture().
virtual void BindTexture()=0
virtual void PostDraw(GlsMapView *view, GlsMapChart *chart)
Definition: gls_map_chart_data_source.h:158
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
Definition: gls_map_chart_data_source.h:210
virtual unsigned long GetLayerID() const
Definition: gls_map_chart_data_source.h:109
virtual bool TextureIsReady() const =0
Definition: gls_map_util.h:414
virtual void Write(std::ostream &os) const
Method to override for printing to a stream.
virtual unsigned long GetBestLayer(GlsMapView *view, GlsMapChart *chart) const
Definition: gls_map_chart_data_source.h:228
virtual bool IsSameCell(const MapChartCell &other) const =0
const GeoRect & GetGeoRect() const
Definition: gls_map_chart_data_source.h:112
The GlsMapView is a special group that controls the map view parameters. It contains all of the objec...
Definition: gls_map_view.h:86
Definition: gls_map_util.h:67
Utility classes for GL Studio Map toolkit.
virtual bool IsCellValid() const
Definition: gls_map_chart_data_source.h:101
virtual GlsMapChartDataSource * GetSource() const =0
Returns the MapDataSource for this MapCell.
MapChartCell()
Definition: gls_map_chart_data_source.h:69
virtual bool HasTexture() const =0
virtual bool AllowOutlines() const
Definition: gls_map_chart_data_source.h:96
The MapChartCell class represents an area within a 2D map.
Definition: gls_map_chart_data_source.h:64
virtual void SetLoadPriority(unsigned int val)
Definition: gls_map_chart_data_source.h:133
virtual ~MapChartCell()
Definition: gls_map_chart_data_source.h:185
virtual void AddRef()
Use this method to increment the reference count of the MapDataSource.
Definition: gls_map_chart_data_source.h:77
virtual void Release()
Definition: gls_map_chart_data_source.h:84
friend std::ostream & operator<<(std::ostream &os, const MapChartCell &cell)
Definition: gls_map_chart_data_source.h:167
void GrowToContainPoint(const GeoCoord &point)
Definition: gls_map_util.h:493
virtual ~GlsMapChartDataSource()
Destructor for abstract base class.
Definition: gls_map_chart_data_source.h:263
Macros and helper code to determine what subset of C++11/14/17 is available.
Definition: gls_map_chart.h:70
Definition: bmpimage.h:46
virtual void PostDraw(GlsMapView *view, GlsMapChart *chart)
Definition: gls_map_chart_data_source.h:243