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 <wx/wx.h>
30#include <wx/progdlg.h>
31#include "s52s57.h"
32#include "chartbase.h"
33#include "wx/dir.h"
34#include "wx/filename.h"
35#include "wx/file.h"
36#include "wx/stream.h"
37#include "wx/wfstream.h"
38#include "gdal/ogrsf_frmts.h"
39
40#include "iso8211.h"
41
42#include "gdal/gdal.h"
43#include "s57RegistrarMgr.h"
44#include "S57ClassRegistrar.h"
45#include "S57Light.h"
46#include "S57Sector.h"
47#include "OCPNRegion.h"
48#include "ocpndc.h"
49#include "viewport.h"
50#include "SencManager.h"
51#include <memory>
52#include "ocpn_plugin.h"
53#include <unordered_map>
54
55// ----------------------------------------------------------------------------
56// Useful Prototypes
57// ----------------------------------------------------------------------------
58class ChartCanvas;
59
60// ----------------------------------------------------------------------------
61// S57 Utility Prototypes
62// ----------------------------------------------------------------------------
63extern "C" bool s57_GetChartExtent(const wxString &FullPath, Extent *pext);
64
65void s57_DrawExtendedLightSectors(ocpnDC &temp_dc, ViewPort &VPoint,
66 std::vector<s57Sector_t> &sectorlegs);
67void s57_DrawExtendedLightSectorsGL(ocpnDC &temp_dc, ViewPort &VPoint,
68 std::vector<s57Sector_t> &sectorlegs);
69bool s57_CheckExtendedLightSectors(ChartCanvas *cc, int mx, int my,
70 ViewPort &VPoint,
71 std::vector<s57Sector_t> &sectorlegs);
72bool s57_GetVisibleLightSectors(ChartCanvas *cc, double lat, double lon,
73 ViewPort &viewport,
74 std::vector<s57Sector_t> &sectorlegs);
75
76//----------------------------------------------------------------------------
77// Constants
78//----------------------------------------------------------------------------
79
80enum {
81 BUILD_SENC_OK,
82 BUILD_SENC_NOK_RETRY,
83 BUILD_SENC_NOK_PERMANENT,
84 BUILD_SENC_PENDING
85};
86
87//----------------------------------------------------------------------------
88// Fwd Defns
89//----------------------------------------------------------------------------
90
91class ChartBase;
92class ViewPort;
93class ocpnBitmap;
94class PixelCache;
95class S57ObjectDesc;
96class S57Reader;
99class S57Obj;
100class VE_Element;
101class VC_Element;
102class connector_segment;
104
105#include <wx/dynarray.h>
106
107// Declare the Array of S57Obj
108WX_DECLARE_OBJARRAY(S57Obj, ArrayOfS57Obj);
109
110WX_DECLARE_LIST(ObjRazRules, ListOfObjRazRules);
111
112//----------------------------------------------------------------------------
113// s57 Chart object class
114//----------------------------------------------------------------------------
115class s57chart : public ChartBase {
116public:
117 s57chart();
118 ~s57chart();
119
120 virtual InitReturn Init(const wxString &name, ChartInitFlag flags);
121
122 // Accessors
123
124 virtual ThumbData *GetThumbData(int tnx, int tny, float lat, float lon);
125 virtual ThumbData *GetThumbData() { return pThumbData; }
126 bool UpdateThumbData(double lat, double lon);
127
128 virtual int GetNativeScale() { return m_Chart_Scale; }
129 virtual double GetNormalScaleMin(double canvas_scale_factor,
130 bool b_allow_overzoom);
131 virtual double GetNormalScaleMax(double canvas_scale_factor,
132 int canvas_width);
133
134 void SetNativeScale(int s) { m_Chart_Scale = s; }
135
136 virtual bool RenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
137 const OCPNRegion &Region);
138 virtual bool RenderOverlayRegionViewOnDC(wxMemoryDC &dc,
139 const ViewPort &VPoint,
140 const OCPNRegion &Region);
141
142 virtual bool RenderRegionViewOnDCNoText(wxMemoryDC &dc,
143 const ViewPort &VPoint,
144 const OCPNRegion &Region);
145 virtual bool RenderRegionViewOnDCTextOnly(wxMemoryDC &dc,
146 const ViewPort &VPoint,
147 const OCPNRegion &Region);
148
149 virtual void GetValidCanvasRegion(const ViewPort &VPoint,
150 OCPNRegion *pValidRegion);
151 virtual LLRegion GetValidRegion();
152
153 virtual void GetPointPix(ObjRazRules *rzRules, float rlat, float rlon,
154 wxPoint *r);
155 virtual void GetPointPix(ObjRazRules *rzRules, wxPoint2DDouble *en,
156 wxPoint *r, int nPoints);
157 virtual void GetPixPoint(int pixx, int pixy, double *plat, double *plon,
158 ViewPort *vpt);
159
160 virtual void SetVPParms(const ViewPort &vpt);
161
162 virtual bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed);
163 // virtual bool IsRenderDelta(ViewPort &vp_last, ViewPort &vp_proposed);
164
165 virtual double GetNearestPreferredScalePPM(double target_scale_ppm) {
166 return target_scale_ppm;
167 }
168
169 void SetFullExtent(Extent &ext);
170 bool GetChartExtent(Extent *pext);
171
172 void SetColorScheme(ColorScheme cs, bool bApplyImmediate = true);
173 virtual void UpdateLUPs(s57chart *pOwner);
174
175 int _insertRules(S57Obj *obj, LUPrec *LUP, s57chart *pOwner);
176
177 virtual ListOfObjRazRules *GetObjRuleListAtLatLon(
178 float lat, float lon, float select_radius, ViewPort *VPoint,
179 int selection_mask = MASK_ALL);
180 bool DoesLatLonSelectObject(float lat, float lon, float select_radius,
181 S57Obj *obj);
182 bool IsPointInObjArea(float lat, float lon, float select_radius, S57Obj *obj);
183 virtual ListOfObjRazRules *GetLightsObjRuleListVisibleAtLatLon(
184 float lat, float lon, ViewPort *VPoint);
185
186 wxString GetObjectAttributeValueAsString(S57Obj *obj, int iatt,
187 wxString curAttrName);
188 static wxString GetAttributeValueAsString(S57attVal *pAttrVal,
189 wxString AttrName);
190 static bool CompareLights(const S57Light *l1, const S57Light *l2);
191 wxString CreateObjDescriptions(ListOfObjRazRules *rule);
192 static wxString GetAttributeDecode(wxString &att, int ival);
193
194 int BuildRAZFromSENCFile(const wxString &SENCPath);
195 static void GetChartNameFromTXT(const wxString &FullPath, wxString &Name);
196 wxString buildSENCName(const wxString &name);
197
198 // DEPCNT VALDCO array access
199 bool GetNearestSafeContour(double safe_cnt, double &next_safe_cnt);
200
201 virtual std::list<S57Obj*> *GetAssociatedObjects(S57Obj *obj);
202
203 virtual std::unordered_map<unsigned, VE_Element *> &Get_ve_hash(void) {
204 return m_ve_hash;
205 }
206 virtual std::unordered_map<unsigned, VC_Element *> &Get_vc_hash(void) {
207 return m_vc_hash;
208 }
209
210 virtual void ForceEdgePriorityEvaluate(void);
211
212 float *GetLineVertexBuffer(void) { return m_line_vertex_buffer; }
213
214 void ClearRenderedTextCache();
215
216 double GetCalculatedSafetyContour(void) { return m_next_safe_cnt; }
217
218 virtual bool RenderRegionViewOnGL(const wxGLContext &glc,
219 const ViewPort &VPoint,
220 const OCPNRegion &RectRegion,
221 const LLRegion &Region);
222 virtual bool RenderOverlayRegionViewOnGL(const wxGLContext &glc,
223 const ViewPort &VPoint,
224 const OCPNRegion &RectRegion,
225 const LLRegion &Region);
226 virtual bool RenderRegionViewOnGLNoText(const wxGLContext &glc,
227 const ViewPort &VPoint,
228 const OCPNRegion &RectRegion,
229 const LLRegion &Region);
230 virtual bool RenderViewOnGLTextOnly(const wxGLContext &glc,
231 const ViewPort &VPoint);
232
233 // Public data
234 // Todo Accessors here
235 // Object arrays used by S52PLIB TOPMAR rendering logic
236 wxArrayPtrVoid *pFloatingATONArray;
237 wxArrayPtrVoid *pRigidATONArray;
238
239 double ref_lat, ref_lon; // Common reference point, derived from FullExtent
240 double m_LOD_meters;
241 Extent m_FullExtent;
242 bool m_bExtentSet;
243 bool m_bLinePrioritySet;
244
245 // SM Projection parms, stored as convenience to expedite pixel conversions
246 double m_easting_vp_center, m_northing_vp_center;
247 double m_pixx_vp_center, m_pixy_vp_center;
248 double m_view_scale_ppm;
249
250 // Last ViewPort succesfully rendered, stored as an aid to calculating
251 // pixel cache address offsets and regions
252 ViewPort m_last_vp;
253 OCPNRegion m_last_Region;
254
255 virtual bool IsCacheValid() { return (pDIB != nullptr); }
256 virtual void InvalidateCache();
257 virtual bool RenderViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint);
258
259 virtual void ClearDepthContourArray(void);
260 virtual void BuildDepthContourArray(void);
261 int ValidateAndCountUpdates(const wxFileName file000, const wxString CopyDir,
262 wxString &LastUpdateDate, bool b_copyfiles);
263 static int GetUpdateFileArray(const wxFileName file000,
264 wxArrayString *UpFiles, wxDateTime date000,
265 wxString edtn000);
266 wxString GetISDT(void);
267 InitReturn PostInit(ChartInitFlag flags, ColorScheme cs);
268
269 char GetUsageChar(void) { return m_usage_char; }
270 static bool IsCellOverlayType(const wxString &pFullPath);
271
272 bool m_b2pointLUPS;
273 bool m_b2lineLUPS;
274 bool m_RAZBuilt;
275
276 chart_context *m_this_chart_context;
277
278 int FindOrCreateSenc(const wxString &name, bool b_progress = true);
279 void DisableBackgroundSENC() { m_disableBackgroundSENC = true; }
280 void EnableBackgroundSENC() { m_disableBackgroundSENC = false; }
281
282 SENCThreadStatus m_SENCthreadStatus;
283
284protected:
285 void AssembleLineGeometry(void);
286
287 ObjRazRules *razRules[PRIO_NUM][LUPNAME_NUM];
288
289private:
290 int GetLineFeaturePointArray(S57Obj *obj, void **ret_array);
291 void SetSafetyContour(void);
292
293 bool DoRenderViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
294 RenderTypeEnum option, bool force_new_view);
295
296 bool DoRenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
297 const OCPNRegion &Region, bool b_overlay);
298
299 int DCRenderRect(wxMemoryDC &dcinput, const ViewPort &vp, wxRect *rect);
300 bool DCRenderLPB(wxMemoryDC &dcinput, const ViewPort &vp, wxRect *rect);
301 bool DCRenderText(wxMemoryDC &dcinput, const ViewPort &vp);
302
303 int BuildSENCFile(const wxString &FullPath000, const wxString &SENCFileName,
304 bool b_progress = true);
305
306 void SetLinePriorities(void);
307
308 bool BuildThumbnail(const wxString &bmpname);
309 bool CreateHeaderDataFromENC(void);
310 bool CreateHeaderDataFromSENC(void);
311 bool CreateHeaderDataFromoSENC(void);
312 bool GetBaseFileAttr(const wxString &file000);
313
314 void ResetPointBBoxes(const ViewPort &vp_last, const ViewPort &vp_this);
315
316 // Access to raw ENC DataSet
317 bool InitENCMinimal(const wxString &FullPath);
318 int GetENCScale();
319 OGRFeature *GetChartFirstM_COVR(int &catcov);
320 OGRFeature *GetChartNextM_COVR(int &catcov);
321
322 void FreeObjectsAndRules();
323 const char *getName(OGRFeature *feature);
324
325 bool DoRenderOnGL(const wxGLContext &glc, const ViewPort &VPoint);
326 bool DoRenderOnGLText(const wxGLContext &glc, const ViewPort &VPoint);
327 bool DoRenderRegionViewOnGL(const wxGLContext &glc, const ViewPort &VPoint,
328 const OCPNRegion &RectRegion,
329 const LLRegion &Region, bool b_overlay);
330
331 void BuildLineVBO(void);
332
333 void ChangeThumbColor(ColorScheme cs);
334 void LoadThumb();
335 bool s57_ProcessExtendedLightSectors(ChartCanvas *cc,
336 ChartPlugInWrapper *target_plugin_chart,
337 s57chart *Chs57,
338 ListOfObjRazRules *rule_list,
339 std::list<S57Obj*> *pi_rule_list,
340 std::vector<s57Sector_t> &sectorlegs);
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 double m_next_safe_cnt;
386
387 int m_LineVBO_name;
388
389 std::unordered_map<unsigned, VE_Element *> m_ve_hash;
390 std::unordered_map<unsigned, VC_Element *> m_vc_hash;
391 std::vector<connector_segment *> m_pcs_vector;
392 std::vector<VE_Element *> m_pve_vector;
393
394 wxString m_TempFilePath;
395 bool m_disableBackgroundSENC;
396
397protected:
398 sm_parms vp_transform;
399};
400
401#endif
Definition: s57.h:144
Definition: ocpndc.h:55