OpenCPN Partial API docs
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 // ----------------------------------------------------------------------------
58 class ChartCanvas;
59 
60 // ----------------------------------------------------------------------------
61 // S57 Utility Prototypes
62 // ----------------------------------------------------------------------------
63 extern "C" bool s57_GetChartExtent(const wxString &FullPath, Extent *pext);
64 
65 void s57_DrawExtendedLightSectors(ocpnDC &temp_dc, ViewPort &VPoint,
66  std::vector<s57Sector_t> &sectorlegs);
67 void s57_DrawExtendedLightSectorsGL(ocpnDC &temp_dc, ViewPort &VPoint,
68  std::vector<s57Sector_t> &sectorlegs);
69 bool s57_CheckExtendedLightSectors(ChartCanvas *cc, int mx, int my,
70  ViewPort &VPoint,
71  std::vector<s57Sector_t> &sectorlegs);
72 bool s57_GetVisibleLightSectors(ChartCanvas *cc, double lat, double lon,
73  ViewPort &viewport,
74  std::vector<s57Sector_t> &sectorlegs);
75 
76 //----------------------------------------------------------------------------
77 // Constants
78 //----------------------------------------------------------------------------
79 
80 enum {
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 
91 class ChartBase;
92 class ViewPort;
93 class ocpnBitmap;
94 class PixelCache;
95 class S57ObjectDesc;
96 class S57Reader;
97 class OGRS57DataSource;
98 class S57ClassRegistrar;
99 class S57Obj;
100 class VE_Element;
101 class VC_Element;
102 class connector_segment;
103 class ChartPlugInWrapper;
104 
105 #include <wx/dynarray.h>
106 
107 // Declare the Array of S57Obj
108 WX_DECLARE_OBJARRAY(S57Obj, ArrayOfS57Obj);
109 
110 WX_DECLARE_LIST(ObjRazRules, ListOfObjRazRules);
111 
112 //----------------------------------------------------------------------------
113 // s57 Chart object class
114 //----------------------------------------------------------------------------
115 class s57chart : public ChartBase {
116 public:
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 
284 protected:
285  void AssembleLineGeometry(void);
286 
287  ObjRazRules *razRules[PRIO_NUM][LUPNAME_NUM];
288  double m_next_safe_cnt;
289 
290 private:
291  int GetLineFeaturePointArray(S57Obj *obj, void **ret_array);
292  void SetSafetyContour(void);
293 
294  bool DoRenderViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
295  RenderTypeEnum option, bool force_new_view);
296 
297  bool DoRenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
298  const OCPNRegion &Region, bool b_overlay);
299 
300  int DCRenderRect(wxMemoryDC &dcinput, const ViewPort &vp, wxRect *rect);
301  bool DCRenderLPB(wxMemoryDC &dcinput, const ViewPort &vp, wxRect *rect);
302  bool DCRenderText(wxMemoryDC &dcinput, const ViewPort &vp);
303 
304  int BuildSENCFile(const wxString &FullPath000, const wxString &SENCFileName,
305  bool b_progress = true);
306 
307  void SetLinePriorities(void);
308 
309  bool BuildThumbnail(const wxString &bmpname);
310  bool CreateHeaderDataFromENC(void);
311  bool CreateHeaderDataFromSENC(void);
312  bool CreateHeaderDataFromoSENC(void);
313  bool GetBaseFileAttr(const wxString &file000);
314 
315  void ResetPointBBoxes(const ViewPort &vp_last, const ViewPort &vp_this);
316 
317  // Access to raw ENC DataSet
318  bool InitENCMinimal(const wxString &FullPath);
319  int GetENCScale();
320  OGRFeature *GetChartFirstM_COVR(int &catcov);
321  OGRFeature *GetChartNextM_COVR(int &catcov);
322 
323  void FreeObjectsAndRules();
324  const char *getName(OGRFeature *feature);
325 
326  bool DoRenderOnGL(const wxGLContext &glc, const ViewPort &VPoint);
327  bool DoRenderOnGLText(const wxGLContext &glc, const ViewPort &VPoint);
328  bool DoRenderRegionViewOnGL(const wxGLContext &glc, const ViewPort &VPoint,
329  const OCPNRegion &RectRegion,
330  const LLRegion &Region, bool b_overlay);
331 
332  void BuildLineVBO(void);
333 
334  void ChangeThumbColor(ColorScheme cs);
335  void LoadThumb();
336  bool s57_ProcessExtendedLightSectors(ChartCanvas *cc,
337  ChartPlugInWrapper *target_plugin_chart,
338  s57chart *Chs57,
339  ListOfObjRazRules *rule_list,
340  std::list<S57Obj*> *pi_rule_list,
341  std::vector<s57Sector_t> &sectorlegs);
342  void CreateChartContext();
343  void PopulateObjectsWithContext();
344 
345  // Private Data
346  char *hdr_buf;
347  char *mybuf_ptr;
348  int hdr_len;
349  wxString m_SENCFileName;
350 
351  wxArrayString *m_tmpup_array;
352  PixelCache *pDIB;
353 
354  wxBitmap *m_pCloneBM;
355  wxMask *m_pMask;
356 
357  bool bGLUWarningSent;
358 
359  wxBitmap *m_pDIBThumbDay;
360  wxBitmap *m_pDIBThumbDim;
361  wxBitmap *m_pDIBThumbOrphan;
362  bool m_bneed_new_thumbnail;
363 
364  bool m_bbase_file_attr_known;
365  wxDateTime m_date000; // extracted from DSID:ISDT
366  wxString m_edtn000; // extracted from DSID:EDTN
367  int m_nGeoRecords; // extracted from DSSI:NOGR
368  int m_native_scale; // extracted from DSPM:CSCL
369 
370  // Raw ENC DataSet members
371  OGRS57DataSource *m_pENCDS;
372 
373  // DEPCNT VALDCO array members
374  int m_nvaldco;
375  int m_nvaldco_alloc;
376  double *m_pvaldco_array;
377 
378  float *m_line_vertex_buffer;
379  size_t m_vbo_byte_length;
380 
381  bool m_blastS57TextRender;
382  wxString m_lastColorScheme;
383  wxRect m_last_vprect;
384  long m_plib_state_hash;
385  bool m_btex_mem;
386  char m_usage_char;
387 
388 
389  int m_LineVBO_name;
390 
391  std::unordered_map<unsigned, VE_Element *> m_ve_hash;
392  std::unordered_map<unsigned, VC_Element *> m_vc_hash;
393  std::vector<connector_segment *> m_pcs_vector;
394  std::vector<VE_Element *> m_pve_vector;
395 
396  wxString m_TempFilePath;
397  bool m_disableBackgroundSENC;
398 
399 protected:
400  sm_parms vp_transform;
401 };
402 
403 #endif
Definition: ocpndc.h:58