OpenCPN Partial API docs
Loading...
Searching...
No Matches
s57chart.h
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: S57 Chart Object
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 __S57CHART_H__
27#define __S57CHART_H__
28
29#include <memory>
30#include <unordered_map>
31
32#include <wx/wx.h>
33#include <wx/dir.h>
34#include <wx/dynarray.h>
35#include <wx/filename.h>
36#include <wx/stream.h>
37#include <wx/wfstream.h>
38
39#include "gdal/ogrsf_frmts.h"
40
41#include "S57Light.h"
42#include "S57Sector.h"
43
44#include "s52s57.h" // ObjRazRules
45
46#include "OCPNRegion.h"
47#include "chartbase.h" // ChartBase
48
49// ----------------------------------------------------------------------------
50// Useful Prototypes
51// ----------------------------------------------------------------------------
52class ChartCanvas;
53
54// ----------------------------------------------------------------------------
55// S57 Utility Prototypes
56// ----------------------------------------------------------------------------
57extern "C" bool s57_GetChartExtent(const wxString &FullPath, Extent *pext);
58
59bool s57_CheckExtendedLightSectors(ChartCanvas *cc, int mx, int my,
60 ViewPort &VPoint,
61 std::vector<s57Sector_t> &sectorlegs);
62bool s57_GetVisibleLightSectors(ChartCanvas *cc, double lat, double lon,
63 ViewPort &viewport,
64 std::vector<s57Sector_t> &sectorlegs);
65// bool s57_ProcessExtendedLightSectors(ChartCanvas *cc,
66// ChartPlugInWrapper *target_plugin_chart,
67// s57chart *Chs57,
68// ListOfObjRazRules *rule_list,
69// std::list<S57Obj *> *pi_rule_list,
70// std::vector<s57Sector_t> &sectorlegs);
71//
72//----------------------------------------------------------------------------
73// Constants
74//----------------------------------------------------------------------------
75
76enum {
77 BUILD_SENC_OK,
78 BUILD_SENC_NOK_RETRY,
79 BUILD_SENC_NOK_PERMANENT,
80 BUILD_SENC_PENDING
81};
82
83//----------------------------------------------------------------------------
84// Fwd Defns
85//----------------------------------------------------------------------------
86
87class ChartBase;
88class ViewPort;
89class ocpnBitmap;
90class PixelCache;
91class S57ObjectDesc;
92class S57Reader;
93class OGRS57DataSource;
94class S57ClassRegistrar;
95class S57Obj;
96class VE_Element;
97class VC_Element;
98class connector_segment;
100
101// Declare the Array of S57Obj
102WX_DECLARE_OBJARRAY(S57Obj, ArrayOfS57Obj);
103
120class s57chart : public ChartBase {
121public:
122 s57chart();
123 ~s57chart();
124
125 virtual InitReturn Init(const wxString &name, ChartInitFlag flags);
126
127 // Accessors
128
129 virtual ThumbData *GetThumbData(int tnx, int tny, float lat, float lon);
130 virtual ThumbData *GetThumbData() { return pThumbData; }
131 bool UpdateThumbData(double lat, double lon);
132
133 virtual int GetNativeScale() { return m_Chart_Scale; }
134 virtual double GetNormalScaleMin(double canvas_scale_factor,
135 bool b_allow_overzoom);
136 virtual double GetNormalScaleMax(double canvas_scale_factor,
137 int canvas_width);
138
139 void SetNativeScale(int s) { m_Chart_Scale = s; }
140
141 virtual bool RenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
142 const OCPNRegion &Region);
143 virtual bool RenderOverlayRegionViewOnDC(wxMemoryDC &dc,
144 const ViewPort &VPoint,
145 const OCPNRegion &Region);
146
147 virtual bool RenderRegionViewOnDCNoText(wxMemoryDC &dc,
148 const ViewPort &VPoint,
149 const OCPNRegion &Region);
150 virtual bool RenderRegionViewOnDCTextOnly(wxMemoryDC &dc,
151 const ViewPort &VPoint,
152 const OCPNRegion &Region);
153
154 virtual void GetValidCanvasRegion(const ViewPort &VPoint,
155 OCPNRegion *pValidRegion);
156 virtual LLRegion GetValidRegion();
157
158 virtual void GetPointPix(ObjRazRules *rzRules, float rlat, float rlon,
159 wxPoint *r);
160 virtual void GetPointPix(ObjRazRules *rzRules, wxPoint2DDouble *en,
161 wxPoint *r, int nPoints);
162 virtual void GetPixPoint(int pixx, int pixy, double *plat, double *plon,
163 ViewPort *vpt);
164
165 virtual void SetVPParms(const ViewPort &vpt);
166
167 virtual bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed);
168 // virtual bool IsRenderDelta(ViewPort &vp_last, ViewPort &vp_proposed);
169
170 virtual double GetNearestPreferredScalePPM(double target_scale_ppm) {
171 return target_scale_ppm;
172 }
173
174 void SetFullExtent(Extent &ext);
175 bool GetChartExtent(Extent *pext);
176
177 void SetColorScheme(ColorScheme cs, bool bApplyImmediate = true);
178 virtual void UpdateLUPs(s57chart *pOwner);
179
180 int _insertRules(S57Obj *obj, LUPrec *LUP, s57chart *pOwner);
181
182 virtual ListOfObjRazRules *GetObjRuleListAtLatLon(
183 float lat, float lon, float select_radius, ViewPort *VPoint,
184 int selection_mask = MASK_ALL);
185 bool DoesLatLonSelectObject(float lat, float lon, float select_radius,
186 S57Obj *obj);
187 bool IsPointInObjArea(float lat, float lon, float select_radius, S57Obj *obj);
188 virtual ListOfObjRazRules *GetLightsObjRuleListVisibleAtLatLon(
189 float lat, float lon, ViewPort *VPoint);
190
191 wxString GetObjectAttributeValueAsString(S57Obj *obj, int iatt,
192 wxString curAttrName);
193 static wxString GetAttributeValueAsString(S57attVal *pAttrVal,
194 wxString AttrName);
195 static bool CompareLights(const S57Light *l1, const S57Light *l2);
196 wxString CreateObjDescriptions(ListOfObjRazRules *rule);
197 static wxString GetAttributeDecode(wxString &att, int ival);
198
199 int BuildRAZFromSENCFile(const wxString &SENCPath);
200 static void GetChartNameFromTXT(const wxString &FullPath, wxString &Name);
201 wxString buildSENCName(const wxString &name);
202
203 // DEPCNT VALDCO array access
204 bool GetNearestSafeContour(double safe_cnt, double &next_safe_cnt);
205
206 virtual std::list<S57Obj *> *GetAssociatedObjects(S57Obj *obj);
207
208 virtual std::unordered_map<unsigned, VE_Element *> &Get_ve_hash(void) {
209 return m_ve_hash;
210 }
211 virtual std::unordered_map<unsigned, VC_Element *> &Get_vc_hash(void) {
212 return m_vc_hash;
213 }
214
215 virtual void ForceEdgePriorityEvaluate(void);
216
217 float *GetLineVertexBuffer(void) { return m_line_vertex_buffer; }
218
219 void ClearRenderedTextCache();
220
221 double GetCalculatedSafetyContour(void) { return m_next_safe_cnt; }
222
223 virtual bool RenderRegionViewOnGL(const wxGLContext &glc,
224 const ViewPort &VPoint,
225 const OCPNRegion &RectRegion,
226 const LLRegion &Region);
227 virtual bool RenderOverlayRegionViewOnGL(const wxGLContext &glc,
228 const ViewPort &VPoint,
229 const OCPNRegion &RectRegion,
230 const LLRegion &Region);
231 virtual bool RenderRegionViewOnGLNoText(const wxGLContext &glc,
232 const ViewPort &VPoint,
233 const OCPNRegion &RectRegion,
234 const LLRegion &Region);
235 virtual bool RenderViewOnGLTextOnly(const wxGLContext &glc,
236 const ViewPort &VPoint);
237
238 // Public data
239 // Todo Accessors here
240 // Object arrays used by S52PLIB TOPMAR rendering logic
241 wxArrayPtrVoid *pFloatingATONArray;
242 wxArrayPtrVoid *pRigidATONArray;
243
244 double ref_lat, ref_lon; // Common reference point, derived from FullExtent
245 double m_LOD_meters;
246 Extent m_FullExtent;
247 bool m_bExtentSet;
248 bool m_bLinePrioritySet;
249
250 // SM Projection parms, stored as convenience to expedite pixel conversions
251 double m_easting_vp_center, m_northing_vp_center;
252 double m_pixx_vp_center, m_pixy_vp_center;
253 double m_view_scale_ppm;
254
255 // Last ViewPort succesfully rendered, stored as an aid to calculating
256 // pixel cache address offsets and regions
257 ViewPort m_last_vp;
258 OCPNRegion m_last_Region;
259
260 virtual bool IsCacheValid() { return (pDIB != nullptr); }
261 virtual void InvalidateCache();
262 virtual bool RenderViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint);
263
264 virtual void ClearDepthContourArray(void);
265 virtual void BuildDepthContourArray(void);
266 int ValidateAndCountUpdates(const wxFileName file000, const wxString CopyDir,
267 wxString &LastUpdateDate, bool b_copyfiles);
268 static int GetUpdateFileArray(const wxFileName file000,
269 wxArrayString *UpFiles, wxDateTime date000,
270 wxString edtn000);
271 wxString GetISDT(void);
272 InitReturn PostInit(ChartInitFlag flags, ColorScheme cs);
273
274 char GetUsageChar(void) { return m_usage_char; }
275 static bool IsCellOverlayType(const wxString &pFullPath);
276
277 bool m_b2pointLUPS;
278 bool m_b2lineLUPS;
279 bool m_RAZBuilt;
280
281 chart_context *m_this_chart_context;
282
283 int FindOrCreateSenc(const wxString &name, bool b_progress = true);
284 void DisableBackgroundSENC() { m_disableBackgroundSENC = true; }
285 void EnableBackgroundSENC() { m_disableBackgroundSENC = false; }
286
287protected:
288 void AssembleLineGeometry(void);
289
290 ObjRazRules *razRules[PRIO_NUM][LUPNAME_NUM];
291 double m_next_safe_cnt;
292
293private:
294 int GetLineFeaturePointArray(S57Obj *obj, void **ret_array);
295 void SetSafetyContour(void);
296
297 bool DoRenderViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
298 RenderTypeEnum option, bool force_new_view);
299
300 bool DoRenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
301 const OCPNRegion &Region, bool b_overlay);
302
303 int DCRenderRect(wxMemoryDC &dcinput, const ViewPort &vp, wxRect *rect);
304 bool DCRenderLPB(wxMemoryDC &dcinput, const ViewPort &vp, wxRect *rect);
305 bool DCRenderText(wxMemoryDC &dcinput, const ViewPort &vp);
306
307 int BuildSENCFile(const wxString &FullPath000, const wxString &SENCFileName,
308 bool b_progress = true);
309
310 void SetLinePriorities(void);
311
312 bool BuildThumbnail(const wxString &bmpname);
313 bool CreateHeaderDataFromENC(void);
314 bool CreateHeaderDataFromSENC(void);
315 bool CreateHeaderDataFromoSENC(void);
316 bool GetBaseFileAttr(const wxString &file000);
317
318 void ResetPointBBoxes(const ViewPort &vp_last, const ViewPort &vp_this);
319
320 // Access to raw ENC DataSet
321 bool InitENCMinimal(const wxString &FullPath);
322 int GetENCScale();
323 OGRFeature *GetChartFirstM_COVR(int &catcov);
324 OGRFeature *GetChartNextM_COVR(int &catcov);
325
326 void FreeObjectsAndRules();
327 const char *getName(OGRFeature *feature);
328
329 bool DoRenderOnGL(const wxGLContext &glc, const ViewPort &VPoint);
330 bool DoRenderOnGLText(const wxGLContext &glc, const ViewPort &VPoint);
331 bool DoRenderRegionViewOnGL(const wxGLContext &glc, const ViewPort &VPoint,
332 const OCPNRegion &RectRegion,
333 const LLRegion &Region, bool b_overlay);
334
335 void BuildLineVBO(void);
336
337 void ChangeThumbColor(ColorScheme cs);
338 void LoadThumb();
339 void CreateChartContext();
340 void PopulateObjectsWithContext();
341
342 // Private Data
343 char *hdr_buf;
344 char *mybuf_ptr;
345 int hdr_len;
346 wxString m_SENCFileName;
347
348 wxArrayString *m_tmpup_array;
349 PixelCache *pDIB;
350
351 wxBitmap *m_pCloneBM;
352 wxMask *m_pMask;
353
354 bool bGLUWarningSent;
355
356 wxBitmap *m_pDIBThumbDay;
357 wxBitmap *m_pDIBThumbDim;
358 wxBitmap *m_pDIBThumbOrphan;
359 bool m_bneed_new_thumbnail;
360
361 bool m_bbase_file_attr_known;
362 wxDateTime m_date000; // extracted from DSID:ISDT
363 wxString m_edtn000; // extracted from DSID:EDTN
364 int m_nGeoRecords; // extracted from DSSI:NOGR
365 int m_native_scale; // extracted from DSPM:CSCL
366
367 // Raw ENC DataSet members
368 OGRS57DataSource *m_pENCDS;
369
370 // DEPCNT VALDCO array members
371 int m_nvaldco;
372 int m_nvaldco_alloc;
373 double *m_pvaldco_array;
374
375 float *m_line_vertex_buffer;
376 size_t m_vbo_byte_length;
377
378 bool m_blastS57TextRender;
379 wxString m_lastColorScheme;
380 wxRect m_last_vprect;
381 long m_plib_state_hash;
382 bool m_btex_mem;
383 char m_usage_char;
384
385 int m_LineVBO_name;
386
387 std::unordered_map<unsigned, VE_Element *> m_ve_hash;
388 std::unordered_map<unsigned, VC_Element *> m_vc_hash;
389 std::vector<connector_segment *> m_pcs_vector;
390 std::vector<VE_Element *> m_pve_vector;
391
392 wxString m_TempFilePath;
393 bool m_disableBackgroundSENC;
394
395protected:
396 sm_parms vp_transform;
397};
398
399#endif
Base class for all chart types.
Definition chartbase.h:119
Chart display canvas.
Definition chcanv.h:135
Wrapper class for plugin-based charts.
Definition chartimg.h:392
A wrapper class for wxRegion with additional functionality.
Definition OCPNRegion.h:56
Represents a light feature in an S57 chart.
Definition S57Light.h:35
Describes an S57 object (feature) in an Electronic Navigational Chart.
Represents the view port for chart display in OpenCPN.
Definition viewport.h:84
Represents an S57 format electronic navigational chart in OpenCPN.
Definition s57chart.h:120