OpenCPN Partial API docs
Loading...
Searching...
No Matches
cm93.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 __CM93CHART_H__
25#define __CM93CHART_H__
26
27#include <wx/listctrl.h>
28#include <wx/spinctrl.h>
29
30#include "chcanv.h"
31#include "model/cutil.h" // for types
32#include "OCPNRegion.h"
33#include "poly_math.h"
34#include "s57chart.h"
35#include "viewport.h"
36
37#define CM93_ZOOM_FACTOR_MAX_RANGE 5
38
39class CM93OffsetDialog; // Forward
42class covr_set; // Forward
43
45public:
48
49 int GetWKBSize();
50 bool WriteWKB(void *p);
51 int ReadWKB(wxFFileInputStream &ifs);
52 void Update(M_COVR_Desc *pmcd);
53 OCPNRegion GetRegion(const ViewPort &vp, wxPoint *pwp);
54
55 int m_cell_index;
56 int m_object_id;
57 int m_subcell;
58
59 int m_nvertices;
60 float_2Dpt *pvertices;
61
62 int m_ngl_vertices;
63 float_2Dpt *gl_screen_vertices;
64 int gl_screen_projection_type;
65
66 int m_npub_year;
67 double transform_WGS84_offset_x;
68 double transform_WGS84_offset_y;
69 double m_covr_lat_min;
70 double m_covr_lat_max;
71 double m_covr_lon_min;
72 double m_covr_lon_max;
73 double user_xoff;
74 double user_yoff;
75 double m_centerlat_cos;
76
77 LLBBox m_covr_bbox;
78 bool m_buser_offsets;
79};
80
81WX_DECLARE_OBJARRAY(M_COVR_Desc, Array_Of_M_COVR_Desc);
82WX_DEFINE_ARRAY_PTR(M_COVR_Desc *, Array_Of_M_COVR_Desc_Ptr);
83
84WX_DECLARE_LIST(M_COVR_Desc, List_Of_M_COVR_Desc);
85
86// Georeferencing constants
87
88// This constant was developed empirically by looking at a
89// representative cell, comparing the cm93 point transform coefficients
90// to the stated lat/lon bounding box.
91// This value corresponds to the semi-major axis for the "International 1924"
92// geo-standard For WGS84, it should be 6378137.0......
93
94static const double CM93_semimajor_axis_meters =
95 6378388.0; // CM93 semimajor axis
96
97// CM93 Data structures
98
99class Extended_Geometry;
100
101// #pragma pack(push,1)
102
103typedef struct {
104 unsigned short x;
105 unsigned short y;
106} cm93_point;
107
108typedef struct {
109 unsigned short x;
110 unsigned short y;
111 unsigned short z;
113
114// #pragma pack(pop)
115
116typedef struct {
117 double lon_min;
118 double lat_min;
119 double lon_max;
120 double lat_max;
121 // Bounding Box, in Mercator transformed co-ordinates
122 double easting_min;
123 double northing_min;
124 double easting_max;
125 double northing_max;
126
127 unsigned short usn_vector_records; // number of spacial(vector) records
128 int n_vector_record_points; // number of cm93 points in vector record block
129 int m_46;
130 int m_4a;
131 unsigned short usn_point3d_records;
132 int m_50;
133 int m_54;
134 unsigned short usn_point2d_records; // m_58;
135 unsigned short m_5a;
136 unsigned short m_5c;
137 unsigned short usn_feature_records; // m_5e, number of feature records
138
139 int m_60;
140 int m_64;
141 unsigned short m_68;
142 unsigned short m_6a;
143 unsigned short m_6c;
144 int m_nrelated_object_pointers;
145
146 int m_72;
147 unsigned short m_76;
148
149 int m_78;
150 int m_7c;
151
153
154typedef struct {
155 unsigned short n_points;
156 unsigned short x_min;
157 unsigned short y_min;
158 unsigned short x_max;
159 unsigned short y_max;
160 int index;
161 cm93_point *p_points;
163
164typedef struct {
165 geometry_descriptor *pGeom_Description;
166 unsigned char segment_usage;
168
169typedef struct {
170 unsigned char otype;
171 unsigned char geotype;
172 unsigned short n_geom_elements;
173 void *pGeometry; // may be a (cm93_point*) or other geom;
174 unsigned char n_related_objects;
175 void *p_related_object_pointer_array;
176 unsigned char n_attributes; // number of attributes
177 unsigned char *attributes_block; // encoded attributes
178
179} Object;
180
181typedef struct {
182 // Georeferencing transform coefficients
183 double transform_x_rate;
184 double transform_y_rate;
185 double transform_x_origin;
186 double transform_y_origin;
187
188 cm93_point *p2dpoint_array;
189 Object **pprelated_object_block;
190 unsigned char *attribute_block_top; // attributes block
192 *edge_vector_descriptor_block; // edge vector descriptor block
193 geometry_descriptor *point3d_descriptor_block;
194 cm93_point *pvector_record_block_top;
195 cm93_point_3d *p3dpoint_array;
196
197 int m_nvector_records;
198 int m_nfeature_records;
199 int m_n_point3d_records;
200 int m_n_point2d_records;
201
202 List_Of_M_COVR_Desc m_cell_mcovr_list;
203 bool b_have_offsets;
204 bool b_have_user_offsets;
205
206 double user_xoff;
207 double user_yoff;
208
209 double min_lat, min_lon;
210
211 // Allocated working blocks
212 vector_record_descriptor *object_vector_record_descriptor_block;
213 Object *pobject_block;
214
216
217//----------------------------------------------------------------------------
218// cm93_dictionary class
219// Encapsulating the conversion between binary cm_93 object class,
220// attributes, etc to standard S57 text conventions
221//----------------------------------------------------------------------------
222
224public:
227
228 bool LoadDictionary(const wxString &dictionary_dir);
229 bool IsOk(void) { return m_ok; }
230 wxString GetDictDir(void) { return m_dict_dir; }
231
232 wxString GetClassName(int iclass);
233 wxString GetAttrName(int iattr);
234 char GetAttrType(int iattr);
235
236private:
237 int m_max_class;
238 int m_max_attr;
239 wxArrayString *m_S57ClassArray;
240 wxArrayString *m_AttrArray;
241 int *m_GeomTypeArray;
242 char *m_ValTypeArray;
243 bool m_ok;
244 wxString m_dict_dir;
245};
246
248public:
250 unsigned char *GetNextAttr();
251
252 int m_cptr;
253 unsigned char *m_block;
254
255 cm93_dictionary *m_pDict;
256};
257
258//----------------------------------------------------------------------------
259// cm93 Chart Manager class
260//----------------------------------------------------------------------------
262public:
263 cm93manager();
264 ~cm93manager();
265 bool Loadcm93Dictionary(const wxString &name);
266 cm93_dictionary *FindAndLoadDict(const wxString &file);
267
268 cm93_dictionary *m_pcm93Dict;
269
270 // Member variables used to record the calling of
271 // cm93chart::CreateHeaderDataFromCM93Cell() for each available scale value.
272 // This allows that routine to return quickly with no error for all cells
273 // other than the first, at each scale....
274
275 bool m_bfoundA;
276 bool m_bfoundB;
277 bool m_bfoundC;
278 bool m_bfoundD;
279 bool m_bfoundE;
280 bool m_bfoundF;
281 bool m_bfoundG;
282 bool m_bfoundZ;
283};
284
300class cm93chart : public s57chart {
301public:
302 cm93chart();
303 ~cm93chart();
304
305 cm93chart(int scale_index);
306 InitReturn Init(const wxString &name, ChartInitFlag flags);
307
308 void ResetSubcellKey() { m_loadcell_key = '0'; }
309
310 double GetNormalScaleMin(double canvas_scale_factor, bool b_allow_overzoom);
311 double GetNormalScaleMax(double canvas_scale_factor, int canvas_width);
312
313 bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed);
314 void SetVPParms(const ViewPort &vpt);
315 void GetPointPix(ObjRazRules *rzRules, float northing, float easting,
316 wxPoint *r);
317 void GetPointPix(ObjRazRules *rzRules, wxPoint2DDouble *en, wxPoint *r,
318 int nPoints);
319 void GetPixPoint(int pixx, int pixy, double *plat, double *plon,
320 ViewPort *vpt);
321
322 void SetCM93Dict(cm93_dictionary *pDict) { m_pDict = pDict; }
323 void SetCM93Prefix(const wxString &prefix) { m_prefix = prefix; }
324 void SetCM93Manager(cm93manager *pManager) { m_pManager = pManager; }
325
326 bool UpdateCovrSet(ViewPort *vpt);
327 bool IsPointInLoadedM_COVR(double xc, double yc);
328 covr_set *GetCoverSet() { return m_pcovr_set; }
329 LLRegion GetValidRegion();
330
331 const wxString &GetLastFileName(void) const { return m_LastFileName; }
332
333 std::vector<int> GetVPCellArray(const ViewPort &vpt);
334
335 Array_Of_M_COVR_Desc_Ptr m_pcovr_array_loaded;
336
337 void SetUserOffsets(int cell_index, int object_id, int subcell, int xoff,
338 int yoff);
339 wxString GetScaleChar() { return m_scalechar; }
340
341 wxPoint *GetDrawBuffer(int nSize);
342
343 OCPNRegion m_render_region;
344
345private:
346 InitReturn CreateHeaderDataFromCM93Cell(void);
347 int read_header_and_populate_cib(header_struct *ph, Cell_Info_Block *pCIB);
348 Extended_Geometry *BuildGeom(Object *pobject, wxFileOutputStream *postream,
349 int iobject);
350
351 S57Obj *CreateS57Obj(int cell_index, int iobject, int subcell,
352 Object *pobject, cm93_dictionary *pDict,
353 Extended_Geometry *xgeom, double ref_lat, double ref_lon,
354 double scale, double view_scale_ppm);
355
356 void ProcessMCOVRObjects(int cell_index, char subcell);
357
358 void translate_colmar(const wxString &sclass, S57attVal *pattValTmp);
359
360 int CreateObjChain(int cell_index, int subcell, double view_scale_ppm);
361
362 void Unload_CM93_Cell(void);
363
364 // cm93 point manipulation methods
365 void Transform(cm93_point *s, double trans_x, double trans_y, double *lat,
366 double *lon);
367
368 int loadcell_in_sequence(int, char);
369 int loadsubcell(int, wxChar);
370 void ProcessVectorEdges(void);
371
372 wxPoint2DDouble FindM_COVROffset(double lat, double lon);
373 M_COVR_Desc *FindM_COVR_InWorkingSet(double lat, double lon);
374
375 Cell_Info_Block m_CIB;
376
377 cm93_dictionary *m_pDict;
378 cm93manager *m_pManager;
379
380 wxString m_prefix;
381
382 double m_sfactor;
383
384 wxString m_scalechar;
385 std::vector<int> m_cells_loaded_array;
386
387 int m_current_cell_vearray_offset;
388 int *m_pcontour_array;
389 int m_ncontour_alloc;
390 ViewPort m_vp_current;
391 wxChar m_loadcell_key;
392 double m_dval;
393
394 covr_set *m_pcovr_set;
395
396 wxPoint *m_pDrawBuffer; // shared outline drawing buffer
397 int m_nDrawBufferSize;
398
399 wxString m_LastFileName;
400
401 LLRegion m_region;
402 wxArrayString m_noFindArray;
403};
404
405//----------------------------------------------------------------------------
406// cm93 Composite Chart object class
407//----------------------------------------------------------------------------
408class CM93OffsetDialog;
409
416class cm93compchart : public s57chart {
417public:
420
421 InitReturn Init(const wxString &name, ChartInitFlag flags);
422
423 void Activate(void);
424 void Deactivate(void);
425
426 double GetNormalScaleMin(double canvas_scale_factor, bool b_allow_overzoom);
427 double GetNormalScaleMax(double canvas_scale_factor, int canvas_width);
428 int GetNativeScale(void);
429
430 wxString GetPubDate();
431
432 void SetVPParms(const ViewPort &vpt);
433 void GetValidCanvasRegion(const ViewPort &VPoint, OCPNRegion *pValidRegion);
434 LLRegion GetValidRegion();
435
436 ThumbData *GetThumbData(int tnx, int tny, float lat, float lon);
437 ThumbData *GetThumbData() { return (ThumbData *)NULL; }
438
439 bool AdjustVP(ViewPort &vp_last, ViewPort &vp_proposed);
440
441 bool RenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
442 const OCPNRegion &Region);
443
444 virtual bool RenderRegionViewOnGL(const wxGLContext &glc,
445 const ViewPort &VPoint,
446 const OCPNRegion &RectRegion,
447 const LLRegion &Region);
448 void SetColorScheme(ColorScheme cs, bool bApplyImmediate);
449
450 bool RenderNextSmallerCellOutlines(ocpnDC &dc, ViewPort &vp, ChartCanvas *cc);
451
452 void GetPointPix(ObjRazRules *rzRules, float rlat, float rlon, wxPoint *r);
453 void GetPixPoint(int pixx, int pixy, double *plat, double *plon,
454 ViewPort *vpt);
455 void GetPointPix(ObjRazRules *rzRules, wxPoint2DDouble *en, wxPoint *r,
456 int nPoints);
457
458 ListOfObjRazRules *GetObjRuleListAtLatLon(float lat, float lon,
459 float select_radius,
460 ViewPort *VPoint,
461 int selection_mask = MASK_ALL);
462 S57ObjectDesc *CreateObjDescription(const ObjRazRules *obj);
463
464 std::unordered_map<unsigned, VE_Element *> &Get_ve_hash(void);
465 std::unordered_map<unsigned, VC_Element *> &Get_vc_hash(void);
466
467 void UpdateLUPs(s57chart *pOwner);
468 void ForceEdgePriorityEvaluate(void);
469 std::list<S57Obj *> *GetAssociatedObjects(S57Obj *obj);
470 cm93chart *GetCurrentSingleScaleChart() { return m_pcm93chart_current; }
471
472 void SetSpecialOutlineCellIndex(int cell_index, int object_id, int subcell) {
473 m_cell_index_special_outline = cell_index;
474 m_object_id_special_outline = object_id;
475 m_subcell_special_outline = subcell;
476 }
477
478 void SetSpecialCellIndexOffset(int cell_index, int object_id, int subcell,
479 int xoff, int yoff);
480 void CloseandReopenCurrentSubchart(void);
481
482 void InvalidateCache();
483
484private:
485 void UpdateRenderRegions(const ViewPort &VPoint);
486 OCPNRegion GetValidScreenCanvasRegion(const ViewPort &VPoint,
487 const OCPNRegion &ScreenRegion);
488
489 bool RenderViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint);
490
491 InitReturn CreateHeaderData();
492 cm93_dictionary *FindAndLoadDictFromDir(const wxString &dir);
493 void FillScaleArray(double lat, double lon);
494 int PrepareChartScale(const ViewPort &vpt, int cmscale,
495 bool bOZ_protect = true);
496 int GetCMScaleFromVP(const ViewPort &vpt);
497 bool DoRenderRegionViewOnDC(wxMemoryDC &dc, const ViewPort &VPoint,
498 const OCPNRegion &Region);
499
500 bool DoRenderRegionViewOnGL(const wxGLContext &glc, const ViewPort &VPoint,
501 const OCPNRegion &RectRegion,
502 const LLRegion &Region);
503
504 bool RenderCellOutlines(ocpnDC &dc, ViewPort &vp, wxPoint *pwp,
505 M_COVR_Desc *mcd);
506
507 // Data members
508
509 cm93_dictionary *m_pDictComposite;
510 cm93manager *m_pcm93mgr;
511
512 cm93chart *m_pcm93chart_array[8];
513 bool m_bScale_Array[8];
514 cm93chart *m_pcm93chart_current;
515 int m_cmscale;
516
517 wxString m_prefixComposite;
518
519 int m_current_cell_pub_date; // the (integer) publish date of the cell at the
520 // current VP
521
522 wxBitmap *m_pDummyBM;
523 int m_cell_index_special_outline;
524 int m_object_id_special_outline;
525 int m_subcell_special_outline;
526 int m_special_offset_x;
527 int m_special_offset_y;
528 ViewPort m_vpt;
529
530 cm93chart *m_last_cell_adjustvp;
531};
532
539class CM93OffsetDialog : public wxDialog {
540 DECLARE_CLASS(CM93OffsetDialog)
541 DECLARE_EVENT_TABLE()
542
543public:
544 CM93OffsetDialog(wxWindow *parent);
546
547 void OnClose(wxCloseEvent &event);
548 void OnOK(wxCommandEvent &event);
549
550 void SetCM93Chart(cm93compchart *pchart);
551 void SetColorScheme();
552 void UpdateMCOVRList(const ViewPort &vpt); // Rebuild MCOVR list
553
554 OCPNOffsetListCtrl *m_pListCtrlMCOVRs;
555 Array_Of_M_COVR_Desc_Ptr m_pcovr_array;
556
557 wxString m_selected_chart_scale_char;
558
559private:
560 void OnCellSelected(wxListEvent &event);
561 void OnOffSetSet(wxCommandEvent &event);
562
563 void UpdateOffsets(void);
564
565 wxSpinCtrl *m_pSpinCtrlXoff;
566 wxSpinCtrl *m_pSpinCtrlYoff;
567 wxButton *m_OKButton;
568
569 wxWindow *m_pparent;
570 cm93compchart *m_pcompchart;
571
572 int m_xoff;
573 int m_yoff;
574 int m_selected_cell_index;
575 int m_selected_object_id;
576 int m_selected_subcell;
577 int m_selected_list_index;
578 double m_centerlat_cos;
579};
580
581#endif
Generic Chart canvas base.
Dialog for managing CM93 chart offsets.
Definition cm93.h:539
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:151
A wrapper class for wxRegion with additional functionality.
Definition OCPNRegion.h:56
Describes an S57 object (feature) in an Electronic Navigational Chart.
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:84
Represents a single CM93 chart at a specific scale.
Definition cm93.h:300
Represents a composite CM93 chart covering multiple scales.
Definition cm93.h:416
Device context class that can use either wxDC or OpenGL for drawing.
Definition ocpndc.h:60
Represents an S57 format electronic navigational chart in OpenCPN.
Definition s57chart.h:122
CM93OffsetDialog * g_pCM93OffsetDialog
Global instance.
Definition cm93.cpp:73
Definition cm93.h:169
Runtime representation of a plugin block.