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