OpenCPN Partial API docs
chartbase.h
1 /***************************************************************************
2  *
3  * Project: OpenCPN
4  * Purpose: ChartBase Definition
5  * Author: David Register
6  *
7  ***************************************************************************
8  * Copyright (C) 2010 by David S. Register *
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  * This program is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18  * GNU General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU General Public License *
21  * along with this program; if not, write to the *
22  * Free Software Foundation, Inc., *
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24  **************************************************************************/
25 
26 #ifndef _CHARTBASE_H_
27 #define _CHARTBASE_H_
28 
29 #include "bbox.h"
30 #include "model/ocpn_types.h"
31 #include "color_types.h"
32 #include "LLRegion.h"
33 
34 //----------------------------------------------------------------------------
35 // Forward Declarations
36 //----------------------------------------------------------------------------
37 class ViewPort;
38 class wxGLContext;
39 class OCPNRegion;
40 
41 //----------------------------------------------------------------------------
42 // Constants. etc
43 //----------------------------------------------------------------------------
44 
45 // ChartBase::Init() init_flags constants
46 typedef enum ChartInitFlag {
47  FULL_INIT = 0,
48  HEADER_ONLY,
49  THUMB_ONLY
50 } _ChartInitFlag;
51 
52 typedef enum RenderTypeEnum {
53  DC_RENDER_ONLY = 0,
54  DC_RENDER_RETURN_DIB,
55  DC_RENDER_RETURN_IMAGE
56 } _RenderTypeEnum;
57 
58 typedef enum InitReturn {
59  INIT_OK = 0,
60  INIT_FAIL_RETRY, // Init failed, retry suggested
61  INIT_FAIL_REMOVE, // Init failed, suggest remove from further use
62  INIT_FAIL_NOERROR // Init failed, request no explicit error message
63 } _InitReturn;
64 
65 class ThumbData {
66 public:
67  ThumbData();
68  virtual ~ThumbData();
69 
70  wxBitmap *pDIBThumb;
71  int ShipX;
72  int ShipY;
73  int Thumb_Size_X;
74  int Thumb_Size_Y;
75 };
76 
77 typedef struct _Extent {
78  float SLAT;
79  float WLON;
80  float NLAT;
81  float ELON;
82 } Extent;
83 
84 // Depth unit type enum
85 typedef enum ChartDepthUnitType {
86  DEPTH_UNIT_UNKNOWN,
87  DEPTH_UNIT_FEET,
88  DEPTH_UNIT_METERS,
89  DEPTH_UNIT_FATHOMS
90 } _ChartDepthUnitType;
91 
92 // Projection type enum
93 typedef enum OcpnProjType {
94  PROJECTION_UNKNOWN,
95  PROJECTION_MERCATOR,
96  PROJECTION_TRANSVERSE_MERCATOR,
97  PROJECTION_POLYCONIC,
98 
99  PROJECTION_ORTHOGRAPHIC,
100  PROJECTION_POLAR,
101  PROJECTION_STEREOGRAPHIC,
102  PROJECTION_GNOMONIC,
103  PROJECTION_EQUIRECTANGULAR,
104  PROJECTION_WEB_MERCATOR
105 } _OcpnProjType;
106 
107 class Plypoint {
108 public:
109  float ltp;
110  float lnp;
111 };
112 
113 // ----------------------------------------------------------------------------
114 // ChartBase
115 // ----------------------------------------------------------------------------
116 
117 class ChartBase {
118 public:
119  ChartBase();
120  virtual ~ChartBase() = 0;
121 
122  virtual InitReturn Init(const wxString &name, ChartInitFlag init_flags) = 0;
123 
124  virtual void Activate(void){};
125  virtual void Deactivate(void){};
126 
127  // Accessors
128  virtual ThumbData *GetThumbData(int tnx, int tny, float lat, float lon) = 0;
129  virtual ThumbData *GetThumbData() = 0;
130  virtual bool UpdateThumbData(double lat, double lon) = 0;
131 
132  virtual double GetNormalScaleMin(double canvas_scale_factor,
133  bool b_allow_overzoom) = 0;
134  virtual double GetNormalScaleMax(double canvas_scale_factor,
135  int canvas_width) = 0;
136 
137  virtual bool GetChartExtent(Extent *pext) = 0;
138 
139  virtual OcpnProjType GetChartProjectionType() { return m_projection; }
140  virtual wxDateTime GetEditionDate(void) { return m_EdDate; }
141 
142  virtual wxString GetPubDate() { return m_PubYear; }
143  virtual int GetNativeScale() { return m_Chart_Scale; }
144  wxString GetFullPath() const { return m_FullPath; }
145  wxString GetHashKey() const;
146  wxString GetName() { return m_Name; }
147  wxString GetDescription() { return m_Description; }
148  wxString GetID() { return m_ID; }
149  wxString GetSE() { return m_SE; }
150  wxString GetDepthUnits() { return m_DepthUnits; }
151  wxString GetSoundingsDatum() { return m_SoundingsDatum; }
152  wxString GetDatumString() { return m_datum_str; }
153  wxString GetExtraInfo() { return m_ExtraInfo; }
154  double GetChart_Error_Factor() { return Chart_Error_Factor; }
155  ChartTypeEnum GetChartType() { return m_ChartType; }
156  ChartFamilyEnum GetChartFamily() { return m_ChartFamily; }
157  double GetChartSkew() { return m_Chart_Skew; }
158 
159  virtual ChartDepthUnitType GetDepthUnitType(void) { return m_depth_unit_id; }
160 
161  virtual bool IsReadyToRender() { return bReadyToRender; }
162  virtual bool RenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
163  const OCPNRegion &Region) = 0;
164 
165  virtual bool RenderRegionViewOnGL(const wxGLContext &glc,
166  const ViewPort &VPoint,
167  const OCPNRegion &RectRegion,
168  const LLRegion &Region) = 0;
169 
170  virtual bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed) = 0;
171 
172  virtual void GetValidCanvasRegion(const ViewPort &VPoint,
173  OCPNRegion *pValidRegion) = 0;
174  virtual LLRegion GetValidRegion() = 0;
175 
176  virtual void SetColorScheme(ColorScheme cs, bool bApplyImmediate = true) = 0;
177 
178  virtual double GetNearestPreferredScalePPM(double target_scale_ppm) = 0;
179 
180  virtual int GetCOVREntries() { return m_nCOVREntries; }
181  virtual int GetCOVRTablePoints(int iTable) {
182  return m_pCOVRTablePoints[iTable];
183  }
184  virtual int GetCOVRTablenPoints(int iTable) {
185  return m_pCOVRTablePoints[iTable];
186  }
187  virtual float *GetCOVRTableHead(int iTable) { return m_pCOVRTable[iTable]; }
188 
189  virtual int GetNoCOVREntries() { return m_nNoCOVREntries; }
190  virtual int GetNoCOVRTablePoints(int iTable) {
191  return m_pNoCOVRTablePoints[iTable];
192  }
193  virtual int GetNoCOVRTablenPoints(int iTable) {
194  return m_pNoCOVRTablePoints[iTable];
195  }
196  virtual float *GetNoCOVRTableHead(int iTable) {
197  return m_pNoCOVRTable[iTable];
198  }
199 
200 protected:
201  int m_Chart_Scale;
202  ChartTypeEnum m_ChartType;
203  ChartFamilyEnum m_ChartFamily;
204 
205  wxString m_FullPath;
206  wxString m_Name;
207  wxString m_Description;
208  wxString m_ID;
209  wxString m_SE;
210  wxString m_SoundingsDatum;
211  wxString m_datum_str;
212  wxString m_ExtraInfo;
213  wxString m_PubYear;
214  wxString m_DepthUnits;
215 
216  OcpnProjType m_projection;
217  ChartDepthUnitType m_depth_unit_id;
218 
219  wxDateTime m_EdDate;
220 
221  ThumbData *pThumbData;
222 
223  ColorScheme m_global_color_scheme;
224  bool bReadyToRender;
225 
226  double Chart_Error_Factor;
227 
228  double m_lon_datum_adjust; // Add these numbers to WGS84 position to obtain
229  // internal chart position
230  double m_lat_datum_adjust;
231 
232  double m_Chart_Skew;
233 
234  // Chart region coverage information
235  // Charts may have multiple valid regions within the lat/lon box described
236  // by the chart extent The following table structure contains this embedded
237  // information
238 
239  // Typically, BSB charts will contain only one entry, corresponding to the
240  // PLY information in the chart header ENC charts often contain multiple
241  // entries
242 
243  int m_nCOVREntries; // number of coverage table entries
244  int *m_pCOVRTablePoints; // int table of number of points in each coverage
245  // table entry
246  float **m_pCOVRTable; // table of pointers to list of floats describing valid
247  // COVR
248 
249  int m_nNoCOVREntries; // number of NoCoverage table entries
250  int *m_pNoCOVRTablePoints; // int table of number of points in each
251  // NoCoverage table entry
252  float **m_pNoCOVRTable; // table of pointers to list of floats describing
253  // valid NOCOVR
254 };
255 
256 // ----------------------------------------------------------------------------
257 // ChartDummy
258 // ----------------------------------------------------------------------------
259 
260 class ChartDummy : public ChartBase {
261 public:
262  ChartDummy();
263  virtual ~ChartDummy();
264 
265  virtual InitReturn Init(const wxString &name, ChartInitFlag init_flags);
266 
267  // Accessors
268  virtual ThumbData *GetThumbData(int tnx, int tny, float lat, float lon);
269  virtual ThumbData *GetThumbData() { return pThumbData; }
270  virtual bool UpdateThumbData(double lat, double lon);
271 
272  double GetNormalScaleMin(double canvas_scale_factor, bool b_allow_overzoom) {
273  return 1.0;
274  }
275  double GetNormalScaleMax(double canvas_scale_factor, int canvas_width) {
276  return 2.0e7;
277  }
278 
279  virtual bool GetChartExtent(Extent *pext);
280 
281  virtual bool RenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
282  const OCPNRegion &Region);
283 
284  virtual bool RenderRegionViewOnGL(const wxGLContext &glc,
285  const ViewPort &VPoint,
286  const OCPNRegion &RectRegion,
287  const LLRegion &Region);
288 
289  virtual bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed);
290 
291  virtual void GetValidCanvasRegion(const ViewPort &VPoint,
292  OCPNRegion *pValidRegion);
293  virtual LLRegion GetValidRegion();
294 
295  virtual void SetColorScheme(ColorScheme cs, bool bApplyImmediate);
296 
297  virtual double GetNearestPreferredScalePPM(double target_scale_ppm) {
298  return target_scale_ppm;
299  }
300 
301 private:
302  bool RenderViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint);
303 
304  wxBitmap *m_pBM;
305 };
306 
307 #endif