OpenCPN Partial API docs
Loading...
Searching...
No Matches
s57chart.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2010 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifndef S57CHART_H_
25#define S57CHART_H_
26
27#include <memory>
28#include <unordered_map>
29
30#include <wx/wx.h>
31#include <wx/dir.h>
32#include <wx/dynarray.h>
33#include <wx/filename.h>
34#include <wx/stream.h>
35#include <wx/wfstream.h>
36
37#include "gdal/ogrsf_frmts.h"
38
39#include "model/gui_vars.h"
40
41#include "chartbase.h" // ChartBase
42#include "chartimg.h"
43#include "ocpn_pixel.h"
44#include "ocpn_region.h"
45#include "ogr_s57.h"
46#include "s52s57.h" // ObjRazRules
47#include "s57.h"
48#include "s57_light.h"
49#include "s57_object_desc.h"
50#include "s57_sector.h"
51#include "viewport.h"
52
53extern bool chain_broken_mssage_shown;
55class ChartCanvas; // circular
56
57enum {
58 BUILD_SENC_OK,
59 BUILD_SENC_NOK_RETRY,
60 BUILD_SENC_NOK_PERMANENT,
61 BUILD_SENC_PENDING
62};
63
64WX_DECLARE_OBJARRAY(S57Obj, ArrayOfS57Obj);
65
66bool s57_CheckExtendedLightSectors(ChartCanvas *cc, int mx, int my,
67 ViewPort &VPoint,
68 std::vector<s57Sector_t> &sectorlegs);
69
70bool s57_GetVisibleLightSectors(ChartCanvas *cc, double lat, double lon,
71 ViewPort &viewport,
72 std::vector<s57Sector_t> &sectorlegs);
73
90class s57chart : public ChartBase {
91public:
92 s57chart();
93 ~s57chart();
94
95 virtual InitReturn Init(const wxString &name, ChartInitFlag flags);
96
97 // Accessors
98
99 virtual ThumbData *GetThumbData(int tnx, int tny, float lat, float lon);
100 virtual ThumbData *GetThumbData() { return pThumbData; }
101 bool UpdateThumbData(double lat, double lon);
102
103 virtual int GetNativeScale() { return m_Chart_Scale; }
104 virtual double GetNormalScaleMin(double canvas_scale_factor,
105 bool b_allow_overzoom);
106 virtual double GetNormalScaleMax(double canvas_scale_factor,
107 int canvas_width);
108
109 void SetNativeScale(int s) { m_Chart_Scale = s; }
110
111 virtual bool RenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
112 const OCPNRegion &Region);
113 virtual bool RenderOverlayRegionViewOnDC(wxMemoryDC &dc,
114 const ViewPort &VPoint,
115 const OCPNRegion &Region);
116
117 virtual bool RenderRegionViewOnDCNoText(wxMemoryDC &dc,
118 const ViewPort &VPoint,
119 const OCPNRegion &Region);
120 virtual bool RenderRegionViewOnDCTextOnly(wxMemoryDC &dc,
121 const ViewPort &VPoint,
122 const OCPNRegion &Region);
123
124 virtual void GetValidCanvasRegion(const ViewPort &VPoint,
125 OCPNRegion *pValidRegion);
126 virtual LLRegion GetValidRegion();
127
128 virtual void GetPointPix(ObjRazRules *rzRules, float rlat, float rlon,
129 wxPoint *r);
130 virtual void GetPointPix(ObjRazRules *rzRules, wxPoint2DDouble *en,
131 wxPoint *r, int nPoints);
132 virtual void GetPixPoint(int pixx, int pixy, double *plat, double *plon,
133 ViewPort *vpt);
134
135 virtual void SetVPParms(const ViewPort &vpt);
136
137 virtual bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed);
138 // virtual bool IsRenderDelta(ViewPort &vp_last, ViewPort &vp_proposed);
139
140 virtual double GetNearestPreferredScalePPM(double target_scale_ppm) {
141 return target_scale_ppm;
142 }
143
144 void SetFullExtent(Extent &ext);
145 bool GetChartExtent(Extent *pext);
146
147 void SetColorScheme(ColorScheme cs, bool bApplyImmediate = true);
148 virtual void UpdateLUPs(s57chart *pOwner);
149
150 int _insertRules(S57Obj *obj, LUPrec *LUP, s57chart *pOwner);
151
152 virtual ListOfObjRazRules *GetObjRuleListAtLatLon(
153 float lat, float lon, float select_radius, ViewPort *VPoint,
154 int selection_mask = MASK_ALL);
155 bool DoesLatLonSelectObject(float lat, float lon, float select_radius,
156 S57Obj *obj);
157 bool IsPointInObjArea(float lat, float lon, float select_radius, S57Obj *obj);
158 virtual ListOfObjRazRules *GetLightsObjRuleListVisibleAtLatLon(
159 float lat, float lon, ViewPort *VPoint);
160
161 wxString GetObjectAttributeValueAsString(S57Obj *obj, int iatt,
162 wxString curAttrName);
163 static wxString GetAttributeValueAsString(S57attVal *pAttrVal,
164 wxString AttrName);
165 static bool CompareLights(const S57Light *l1, const S57Light *l2);
166 wxString CreateObjDescriptions(ListOfObjRazRules *rule);
167 static wxString GetAttributeDecode(wxString &att, int ival);
168
169 int BuildRAZFromSENCFile(const wxString &SENCPath);
170 static void GetChartNameFromTXT(const wxString &FullPath, wxString &Name);
171 wxString buildSENCName(const wxString &name);
172
173 // DEPCNT VALDCO array access
174 bool GetNearestSafeContour(double safe_cnt, double &next_safe_cnt);
175
176 virtual std::list<S57Obj *> *GetAssociatedObjects(S57Obj *obj);
177
178 virtual std::unordered_map<unsigned, VE_Element *> &Get_ve_hash() {
179 return m_ve_hash;
180 }
181 virtual std::unordered_map<unsigned, VC_Element *> &Get_vc_hash() {
182 return m_vc_hash;
183 }
184
185 virtual void ForceEdgePriorityEvaluate();
186
187 float *GetLineVertexBuffer() { return m_line_vertex_buffer; }
188
189 void ClearRenderedTextCache();
190
191 double GetCalculatedSafetyContour() { return m_next_safe_cnt; }
192
193 virtual bool RenderRegionViewOnGL(const wxGLContext &glc,
194 const ViewPort &VPoint,
195 const OCPNRegion &RectRegion,
196 const LLRegion &Region);
197 virtual bool RenderOverlayRegionViewOnGL(const wxGLContext &glc,
198 const ViewPort &VPoint,
199 const OCPNRegion &RectRegion,
200 const LLRegion &Region);
201 virtual bool RenderRegionViewOnGLNoText(const wxGLContext &glc,
202 const ViewPort &VPoint,
203 const OCPNRegion &RectRegion,
204 const LLRegion &Region);
205 virtual bool RenderViewOnGLTextOnly(const wxGLContext &glc,
206 const ViewPort &VPoint);
207
208 // Public data
209 // Todo Accessors here
210 // Object arrays used by S52PLIB TOPMAR rendering logic
211 wxArrayPtrVoid *pFloatingATONArray;
212 wxArrayPtrVoid *pRigidATONArray;
213
214 double ref_lat, ref_lon; // Common reference point, derived from FullExtent
215 double m_LOD_meters;
216 Extent m_FullExtent;
217 bool m_bExtentSet;
218 bool m_bLinePrioritySet;
219
220 // SM Projection parms, stored as convenience to expedite pixel conversions
221 double m_easting_vp_center, m_northing_vp_center;
222 double m_pixx_vp_center, m_pixy_vp_center;
223 double m_view_scale_ppm;
224
225 // Last ViewPort succesfully rendered, stored as an aid to calculating
226 // pixel cache address offsets and regions
227 ViewPort m_last_vp;
228 OCPNRegion m_last_Region;
229
230 virtual bool IsCacheValid() { return (pDIB != nullptr); }
231 virtual void InvalidateCache();
232 virtual bool RenderViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint);
233
234 virtual void ClearDepthContourArray();
235 virtual void BuildDepthContourArray();
236 int ValidateAndCountUpdates(const wxFileName file000, const wxString CopyDir,
237 wxString &LastUpdateDate, bool b_copyfiles);
238 static int GetUpdateFileArray(const wxFileName file000,
239 wxArrayString *UpFiles, wxDateTime date000,
240 wxString edtn000);
241 wxString GetISDT();
242 InitReturn PostInit(ChartInitFlag flags, ColorScheme cs);
243
244 char GetUsageChar() { return m_usage_char; }
245 static bool IsCellOverlayType(const wxString &pFullPath);
246
247 bool m_b2pointLUPS;
248 bool m_b2lineLUPS;
249 bool m_RAZBuilt;
250
251 chart_context *m_this_chart_context;
252
253 int FindOrCreateSenc(const wxString &name, bool b_progress = true);
254 void DisableBackgroundSENC() { m_disableBackgroundSENC = true; }
255 void EnableBackgroundSENC() { m_disableBackgroundSENC = false; }
256
257protected:
258 void AssembleLineGeometry();
259
260 ObjRazRules *razRules[PRIO_NUM][LUPNAME_NUM];
261 double m_next_safe_cnt;
262
263private:
264 int GetLineFeaturePointArray(S57Obj *obj, void **ret_array);
265 void SetSafetyContour();
266
267 bool DoRenderViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
268 RenderTypeEnum option, bool force_new_view);
269
270 bool DoRenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
271 const OCPNRegion &Region, bool b_overlay);
272
273 int DCRenderRect(wxMemoryDC &dcinput, const ViewPort &vp, wxRect *rect);
274 bool DCRenderLPB(wxMemoryDC &dcinput, const ViewPort &vp, wxRect *rect);
275 bool DCRenderText(wxMemoryDC &dcinput, const ViewPort &vp);
276
277 int BuildSENCFile(const wxString &FullPath000, const wxString &SENCFileName,
278 bool b_progress = true);
279
280 void SetLinePriorities();
281
282 bool BuildThumbnail(const wxString &bmpname);
283 bool CreateHeaderDataFromENC();
284 bool CreateHeaderDataFromSENC();
285 bool CreateHeaderDataFromoSENC();
286 bool GetBaseFileAttr(const wxString &file000);
287
288 void ResetPointBBoxes(const ViewPort &vp_last, const ViewPort &vp_this);
289
290 // Access to raw ENC DataSet
291 bool InitENCMinimal(const wxString &FullPath);
292 int GetENCScale();
293 OGRFeature *GetChartFirstM_COVR(int &catcov);
294 OGRFeature *GetChartNextM_COVR(int &catcov);
295
296 void FreeObjectsAndRules();
297 const char *getName(OGRFeature *feature);
298
299 bool DoRenderOnGL(const wxGLContext &glc, const ViewPort &VPoint);
300 bool DoRenderOnGLText(const wxGLContext &glc, const ViewPort &VPoint);
301 bool DoRenderRegionViewOnGL(const wxGLContext &glc, const ViewPort &VPoint,
302 const OCPNRegion &RectRegion,
303 const LLRegion &Region, bool b_overlay);
304
305 void BuildLineVBO();
306
307 void ChangeThumbColor(ColorScheme cs);
308 void LoadThumb();
309 void CreateChartContext();
310 void PopulateObjectsWithContext();
311
312 // Private Data
313 char *hdr_buf;
314 char *mybuf_ptr;
315 int hdr_len;
316 wxString m_SENCFileName;
317
318 wxArrayString *m_tmpup_array;
319 PixelCache *pDIB;
320
321 wxBitmap *m_pCloneBM;
322 wxMask *m_pMask;
323
324 bool bGLUWarningSent;
325
326 wxBitmap *m_pDIBThumbDay;
327 wxBitmap *m_pDIBThumbDim;
328 wxBitmap *m_pDIBThumbOrphan;
329 bool m_bneed_new_thumbnail;
330
331 bool m_bbase_file_attr_known;
332 wxDateTime m_date000; // extracted from DSID:ISDT
333 wxString m_edtn000; // extracted from DSID:EDTN
334 int m_nGeoRecords; // extracted from DSSI:NOGR
335 int m_native_scale; // extracted from DSPM:CSCL
336
337 // Raw ENC DataSet members
338 OGRS57DataSource *m_pENCDS;
339
340 // DEPCNT VALDCO array members
341 int m_nvaldco;
342 int m_nvaldco_alloc;
343 double *m_pvaldco_array;
344
345 float *m_line_vertex_buffer;
346 size_t m_vbo_byte_length;
347
348 bool m_blastS57TextRender;
349 wxString m_lastColorScheme;
350 wxRect m_last_vprect;
351 long m_plib_state_hash;
352 bool m_btex_mem;
353 char m_usage_char;
354
355 int m_LineVBO_name;
356
357 std::unordered_map<unsigned, VE_Element *> m_ve_hash;
358 std::unordered_map<unsigned, VC_Element *> m_vc_hash;
359 std::vector<connector_segment *> m_pcs_vector;
360 std::vector<VE_Element *> m_pve_vector;
361
362 wxString m_TempFilePath;
363 bool m_disableBackgroundSENC;
364
365protected:
366 sm_parms vp_transform;
367};
368
369#endif // S57CHART_H_
General chart base definitions.
BSB chart management.
Base class for all chart types.
Definition chartbase.h:126
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:174
A wrapper class for wxRegion with additional functionality.
Definition ocpn_region.h:37
Represents a light feature in an S57 chart.
Definition s57_light.h:35
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:56
Represents an S57 format electronic navigational chart in OpenCPN.
Definition s57chart.h:90
Miscellaneous globals primarely used by gui layer, not persisted in configuration file.
Optimized wxBitmap Object.
OpenCPN region handling.
Declarations for classes binding S57 support onto OGRLayer, OGRDataSource and OGRDriver.
Declarations for S-57 translator not including the binding onto OGRLayer/DataSource/Driver which are ...
S57 light encapsulation.
S57 object encapsulation.
S57 chart sector encapsulation.
bool chain_broken_mssage_shown
Global instance.
Geographic projection and coordinate transformations.