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