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 "dychart.h"
30 
31 #include "bbox.h"
32 #include "ocpn_types.h"
33 #include "LLRegion.h"
34 
35 //----------------------------------------------------------------------------
36 //  Forward Declarations
37 //----------------------------------------------------------------------------
38 class ViewPort;
39 class wxGLContext;
40 class OCPNRegion;
41 
42 //----------------------------------------------------------------------------
43 // Constants. etc
44 //----------------------------------------------------------------------------
45 
46 //    ChartBase::Init()  init_flags constants
47 typedef enum ChartInitFlag
48 {
49       FULL_INIT = 0,
50       HEADER_ONLY,
51       THUMB_ONLY
52 }_ChartInitFlag;
53 
54 
55 typedef enum RenderTypeEnum
56 {
57       DC_RENDER_ONLY = 0,
58       DC_RENDER_RETURN_DIB,
59       DC_RENDER_RETURN_IMAGE
60 }_RenderTypeEnum;
61 
62 typedef enum InitReturn
63 {
64       INIT_OK = 0,
65       INIT_FAIL_RETRY,        // Init failed, retry suggested
66       INIT_FAIL_REMOVE,       // Init failed, suggest remove from further use
67       INIT_FAIL_NOERROR       // Init failed, request no explicit error message
68 }_InitReturn;
69 
70 
71 
72 class ThumbData
73 {
74 public:
75     ThumbData();
76     virtual ~ThumbData();
77 
78       wxBitmap    *pDIBThumb;
79       int         ShipX;
80       int         ShipY;
81       int         Thumb_Size_X;
82       int         Thumb_Size_Y;
83 };
84 
85 
86 
87 typedef struct _Extent{
88   float SLAT;
89   float WLON;
90   float NLAT;
91   float ELON;
92 }Extent;
93 
94 //          Depth unit type enum
95 typedef enum ChartDepthUnitType
96 {
97     DEPTH_UNIT_UNKNOWN,
98     DEPTH_UNIT_FEET,
99     DEPTH_UNIT_METERS,
100     DEPTH_UNIT_FATHOMS
101 }_ChartDepthUnitType;
102 
103 //          Projection type enum
104 typedef enum OcpnProjType
105 {
106       PROJECTION_UNKNOWN,
107       PROJECTION_MERCATOR,
108       PROJECTION_TRANSVERSE_MERCATOR,
109       PROJECTION_POLYCONIC,
110 
111       PROJECTION_ORTHOGRAPHIC,
112       PROJECTION_POLAR,
113       PROJECTION_STEREOGRAPHIC,
114       PROJECTION_GNOMONIC,
115       PROJECTION_EQUIRECTANGULAR,
116       PROJECTION_WEB_MERCATOR
117 }_OcpnProjType;
118 
119 
120 
121 class Plypoint
122 {
123       public:
124             float ltp;
125             float lnp;
126 };
127 
128 
129 // ----------------------------------------------------------------------------
130 // ChartBase
131 // ----------------------------------------------------------------------------
132 
133 class ChartBase
134 {
135 
136 public:
137       ChartBase();
138       virtual ~ChartBase() = 0;
139 
140       virtual InitReturn Init( const wxString& name, ChartInitFlag init_flags) = 0;
141 
Activate(void)142       virtual void Activate(void) {};
Deactivate(void)143       virtual void Deactivate(void) {};
144 
145 //    Accessors
146       virtual ThumbData *GetThumbData(int tnx, int tny, float lat, float lon) = 0;
147       virtual ThumbData *GetThumbData() = 0;
148       virtual bool UpdateThumbData(double lat, double lon) = 0;
149 
150       virtual double GetNormalScaleMin(double canvas_scale_factor, bool b_allow_overzoom) = 0;
151       virtual double GetNormalScaleMax(double canvas_scale_factor, int canvas_width) = 0;
152 
153       virtual bool GetChartExtent(Extent *pext) = 0;
154 
155 
GetChartProjectionType()156       virtual OcpnProjType GetChartProjectionType(){ return m_projection;}
GetEditionDate(void)157       virtual wxDateTime GetEditionDate(void){ return m_EdDate;}
158 
GetPubDate()159       virtual wxString GetPubDate(){ return m_PubYear;}
GetNativeScale()160       virtual int GetNativeScale(){ return m_Chart_Scale;}
GetFullPath()161       wxString GetFullPath() const { return m_FullPath;}
162       wxString GetHashKey() const;
GetName()163       wxString GetName(){ return m_Name;}
GetDescription()164       wxString GetDescription() { return m_Description;}
GetID()165       wxString GetID(){ return m_ID;}
GetSE()166       wxString GetSE(){ return m_SE;}
GetDepthUnits()167       wxString GetDepthUnits(){ return m_DepthUnits;}
GetSoundingsDatum()168       wxString GetSoundingsDatum(){ return m_SoundingsDatum;}
GetDatumString()169       wxString GetDatumString(){ return m_datum_str;}
GetExtraInfo()170       wxString GetExtraInfo(){ return m_ExtraInfo; }
GetChart_Error_Factor()171       double GetChart_Error_Factor(){ return Chart_Error_Factor; }
GetChartType()172       ChartTypeEnum GetChartType(){ return m_ChartType;}
GetChartFamily()173       ChartFamilyEnum GetChartFamily(){ return m_ChartFamily;}
GetChartSkew()174       double GetChartSkew(){ return m_Chart_Skew; }
175 
176 
GetDepthUnitType(void)177       virtual ChartDepthUnitType GetDepthUnitType(void) { return m_depth_unit_id;}
178 
IsReadyToRender()179       virtual bool IsReadyToRender(){ return bReadyToRender;}
180       virtual bool RenderRegionViewOnDC(wxMemoryDC& dc, const ViewPort& VPoint,
181                                         const OCPNRegion &Region) = 0;
182 
183       virtual bool RenderRegionViewOnGL(const wxGLContext &glc, const ViewPort& VPoint,
184                                         const OCPNRegion &RectRegion, const LLRegion &Region) = 0;
185 
186       virtual bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed) = 0;
187 
188       virtual void GetValidCanvasRegion(const ViewPort& VPoint, OCPNRegion *pValidRegion) = 0;
189       virtual LLRegion GetValidRegion() = 0;
190 
191       virtual void SetColorScheme(ColorScheme cs, bool bApplyImmediate = true ) = 0;
192 
193       virtual double GetNearestPreferredScalePPM(double target_scale_ppm) = 0;
194 
GetCOVREntries()195       virtual int GetCOVREntries(){ return  m_nCOVREntries; }
GetCOVRTablePoints(int iTable)196       virtual int GetCOVRTablePoints(int iTable) { return m_pCOVRTablePoints[iTable]; }
GetCOVRTablenPoints(int iTable)197       virtual int  GetCOVRTablenPoints(int iTable){ return m_pCOVRTablePoints[iTable]; }
GetCOVRTableHead(int iTable)198       virtual float *GetCOVRTableHead(int iTable){ return m_pCOVRTable[iTable]; }
199 
GetNoCOVREntries()200       virtual int GetNoCOVREntries(){ return  m_nNoCOVREntries; }
GetNoCOVRTablePoints(int iTable)201       virtual int GetNoCOVRTablePoints(int iTable) { return m_pNoCOVRTablePoints[iTable]; }
GetNoCOVRTablenPoints(int iTable)202       virtual int  GetNoCOVRTablenPoints(int iTable){ return m_pNoCOVRTablePoints[iTable]; }
GetNoCOVRTableHead(int iTable)203       virtual float *GetNoCOVRTableHead(int iTable){ return m_pNoCOVRTable[iTable]; }
204 
205 protected:
206 
207       int               m_Chart_Scale;
208       ChartTypeEnum     m_ChartType;
209       ChartFamilyEnum   m_ChartFamily;
210 
211       wxString          m_FullPath;
212       wxString          m_Name;
213       wxString          m_Description;
214       wxString          m_ID;
215       wxString          m_SE;
216       wxString          m_SoundingsDatum;
217       wxString          m_datum_str;
218       wxString          m_ExtraInfo;
219       wxString          m_PubYear;
220       wxString          m_DepthUnits;
221 
222       OcpnProjType      m_projection;
223       ChartDepthUnitType m_depth_unit_id;
224 
225       wxDateTime        m_EdDate;
226 
227       ThumbData         *pThumbData;
228 
229       ColorScheme       m_global_color_scheme;
230       bool              bReadyToRender;
231 
232       double            Chart_Error_Factor;
233 
234       double            m_lon_datum_adjust;             // Add these numbers to WGS84 position to obtain internal chart position
235       double            m_lat_datum_adjust;
236 
237       double            m_Chart_Skew;
238 
239 
240       //    Chart region coverage information
241       //    Charts may have multiple valid regions within the lat/lon box described by the chart extent
242       //    The following table structure contains this embedded information
243 
244       //    Typically, BSB charts will contain only one entry, corresponding to the PLY information in the chart header
245       //    ENC charts often contain multiple entries
246 
247       int         m_nCOVREntries;                       // number of coverage table entries
248       int         *m_pCOVRTablePoints;                  // int table of number of points in each coverage table entry
249       float       **m_pCOVRTable;                       // table of pointers to list of floats describing valid COVR
250 
251       int         m_nNoCOVREntries;                       // number of NoCoverage table entries
252       int         *m_pNoCOVRTablePoints;                  // int table of number of points in each NoCoverage table entry
253       float       **m_pNoCOVRTable;                       // table of pointers to list of floats describing valid NOCOVR
254 
255 };
256 
257 
258 // ----------------------------------------------------------------------------
259 // ChartDummy
260 // ----------------------------------------------------------------------------
261 
262 class ChartDummy : public ChartBase
263 {
264 
265 public:
266       ChartDummy();
267       virtual ~ChartDummy();
268 
269       virtual InitReturn Init( const wxString& name, ChartInitFlag init_flags );
270 
271 //    Accessors
272       virtual ThumbData *GetThumbData(int tnx, int tny, float lat, float lon);
GetThumbData()273       virtual ThumbData *GetThumbData() {return pThumbData;}
274       virtual bool UpdateThumbData(double lat, double lon);
275 
GetNormalScaleMin(double canvas_scale_factor,bool b_allow_overzoom)276       double GetNormalScaleMin(double canvas_scale_factor, bool b_allow_overzoom){return 1.0;}
GetNormalScaleMax(double canvas_scale_factor,int canvas_width)277       double GetNormalScaleMax(double canvas_scale_factor, int canvas_width){ return 2.0e7;}
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, const ViewPort& VPoint,
285                                         const OCPNRegion &RectRegion, const LLRegion &Region);
286 
287       virtual bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed);
288 
289       virtual void GetValidCanvasRegion(const ViewPort& VPoint, OCPNRegion *pValidRegion);
290       virtual LLRegion GetValidRegion();
291 
292       virtual void SetColorScheme(ColorScheme cs, bool bApplyImmediate);
293 
GetNearestPreferredScalePPM(double target_scale_ppm)294       virtual double GetNearestPreferredScalePPM(double target_scale_ppm){ return target_scale_ppm; }
295 
296 private:
297       bool RenderViewOnDC(wxMemoryDC& dc, const ViewPort& VPoint);
298 
299       wxBitmap    *m_pBM;
300 };
301 
302 
303 #endif
304