OpenCPN Partial API docs
Loading...
Searching...
No Matches
ais.cpp
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: AIS Decoder 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
27#include <stdlib.h>
28#include <math.h>
29#include <time.h>
30
31#ifdef __MINGW32__
32#undef IPV6STRICT // mingw FTBS fix: missing struct ip_mreq
33#include <windows.h>
34#endif
35
36#include <wx/wx.h>
37#include <wx/tokenzr.h>
38#include <wx/datetime.h>
39#include <wx/wfstream.h>
40#include <wx/imaglist.h>
41#include <wx/window.h>
42
43#include "gl_headers.h" // Must come before anything including GL stuff
44
45#include "model/ais_decoder.h"
48#include "model/cutil.h"
49#include "model/georef.h"
50#include "model/gui_vars.h"
51#include "model/own_ship.h"
52#include "model/select.h"
53
54#include "ais.h"
57#include "chcanv.h"
58#include "font_mgr.h"
59#include "line_clip.h"
60#include "navutil.h" // for Select
61#include "ocpn_platform.h"
62#include "ocpn_plugin.h"
63#include "styles.h"
64#include "top_frame.h"
65#include "color_handler.h"
66
67extern OCPNPlatform *g_Platform;
68
69extern AISTargetQueryDialog *g_pais_query_dialog_active;
70
71int ImportanceSwitchPoint = 100;
72
73extern ArrayOfMmsiProperties g_MMSI_Props_Array;
74extern bool g_bopengl;
75
76extern float g_ShipScaleFactorExp;
77extern float g_MarkScaleFactorExp;
78
79float AISImportanceSwitchPoint = 0.0;
80
81#if !defined(NAN)
82static const long long lNaN = 0xfff8000000000000;
83#define NAN (*(double *)&lNaN)
84#endif
85
86wxString ais8_001_22_notice_names[] = {
87 // 128] = {
88 _("Caution Area: Marine mammals habitat (implies whales NOT "
89 "observed)"), // 0 - WARNING: extra text by Kurt
90 _("Caution Area: Marine mammals in area - reduce speed"), // 1
91 _("Caution Area: Marine mammals in area - stay clear"), // 2
92 _("Caution Area: Marine mammals in area - report sightings"), // 3
93 _("Caution Area: Protected habitat - reduce speed"), // 4
94 _("Caution Area: Protected habitat - stay clear"), // 5
95 _("Caution Area: Protected habitat - no fishing or anchoring"), // 6
96 _("Caution Area: Derelicts (drifting objects)"), // 7
97 _("Caution Area: Traffic congestion"), // 8
98 _("Caution Area: Marine event"), // 9
99 _("Caution Area: Divers down"), // 10
100 _("Caution Area: Swim area"), // 11
101 _("Caution Area: Dredge operations"), // 12
102 _("Caution Area: Survey operations"), // 13
103 _("Caution Area: Underwater operation"), // 14
104 _("Caution Area: Seaplane operations"), // 15
105 _("Caution Area: Fishery - nets in water"), // 16
106 _("Caution Area: Cluster of fishing vessels"), // 17
107 _("Caution Area: Fairway closed"), // 18
108 _("Caution Area: Harbour closed"), // 19
109 _("Caution Area: Risk (define in Associated text field)"), // 20
110 _("Caution Area: Underwater vehicle operation"), // 21
111 _("(reserved for future use)"), // 22
112 _("Environmental Caution Area: Storm front (line squall)"), // 23
113 _("Environmental Caution Area: Hazardous sea ice"), // 24
114 _("Environmental Caution Area: Storm warning (storm cell or line "
115 "of storms)"), // 25
116 _("Environmental Caution Area: High wind"), // 26
117 _("Environmental Caution Area: High waves"), // 27
118 _("Environmental Caution Area: Restricted visibility (fog, rain, "
119 "etc.)"), // 28
120 _("Environmental Caution Area: Strong currents"), // 29
121 _("Environmental Caution Area: Heavy icing"), // 30
122 _("(reserved for future use)"), // 31
123 _("Restricted Area: Fishing prohibited"), // 32
124 _("Restricted Area: No anchoring."), // 33
125 _("Restricted Area: Entry approval required prior to transit"), // 34
126 _("Restricted Area: Entry prohibited"), // 35
127 _("Restricted Area: Active military OPAREA"), // 36
128 _("Restricted Area: Firing - danger area."), // 37
129 _("Restricted Area: Drifting Mines"), // 38
130 _("(reserved for future use)"), // 39
131 _("Anchorage Area: Anchorage open"), // 40
132 _("Anchorage Area: Anchorage closed"), // 41
133 _("Anchorage Area: Anchoring prohibited"), // 42
134 _("Anchorage Area: Deep draft anchorage"), // 43
135 _("Anchorage Area: Shallow draft anchorage"), // 44
136 _("Anchorage Area: Vessel transfer operations"), // 45
137 _("(reserved for future use)"), // 46
138 _("(reserved for future use)"), // 47
139 _("(reserved for future use)"), // 48
140 _("(reserved for future use)"), // 49
141 _("(reserved for future use)"), // 50
142 _("(reserved for future use)"), // 51
143 _("(reserved for future use)"), // 52
144 _("(reserved for future use)"), // 53
145 _("(reserved for future use)"), // 54
146 _("(reserved for future use)"), // 55
147 _("Security Alert - Level 1"), // 56
148 _("Security Alert - Level 2"), // 57
149 _("Security Alert - Level 3"), // 58
150 _("(reserved for future use)"), // 59
151 _("(reserved for future use)"), // 60
152 _("(reserved for future use)"), // 61
153 _("(reserved for future use)"), // 62
154 _("(reserved for future use)"), // 63
155 _("Distress Area: Vessel disabled and adrift"), // 64
156 _("Distress Area: Vessel sinking"), // 65
157 _("Distress Area: Vessel abandoning ship"), // 66
158 _("Distress Area: Vessel requests medical assistance"), // 67
159 _("Distress Area: Vessel flooding"), // 68
160 _("Distress Area: Vessel fire/explosion"), // 69
161 _("Distress Area: Vessel grounding"), // 70
162 _("Distress Area: Vessel collision"), // 71
163 _("Distress Area: Vessel listing/capsizing"), // 72
164 _("Distress Area: Vessel under assault"), // 73
165 _("Distress Area: Person overboard"), // 74
166 _("Distress Area: SAR area"), // 75
167 _("Distress Area: Pollution response area"), // 76
168 _("(reserved for future use)"), // 77
169 _("(reserved for future use)"), // 78
170 _("(reserved for future use)"), // 79
171 _("Instruction: Contact VTS at this point/juncture"), // 80
172 _("Instruction: Contact Port Administration at this "
173 "point/juncture"), // 81
174 _("Instruction: Do not proceed beyond this point/juncture"), // 82
175 _("Instruction: Await instructions prior to proceeding beyond this "
176 "point/juncture"), // 83
177 _("Proceed to this location - await instructions"), // 84
178 _("Clearance granted - proceed to berth"), // 85
179 _("(reserved for future use)"), // 86
180 _("(reserved for future use)"), // 87
181 _("Information: Pilot boarding position"), // 88
182 _("Information: Icebreaker waiting area"), // 89
183 _("Information: Places of refuge"), // 90
184 _("Information: Position of icebreakers"), // 91
185 _("Information: Location of response units"), // 92
186 _("VTS active target"), // 93
187 _("Rogue or suspicious vessel"), // 94
188 _("Vessel requesting non-distress assistance"), // 95
189 _("Chart Feature: Sunken vessel"), // 96
190 _("Chart Feature: Submerged object"), // 97
191 _("Chart Feature: Semi-submerged object"), // 98
192 _("Chart Feature: Shoal area"), // 99
193 _("Chart Feature: Shoal area due north"), // 100
194 _("Chart Feature: Shoal area due east"), // 101
195 _("Chart Feature: Shoal area due south"), // 102
196 _("Chart Feature: Shoal area due west"), // 103
197 _("Chart Feature: Channel obstruction"), // 104
198 _("Chart Feature: Reduced vertical clearance"), // 105
199 _("Chart Feature: Bridge closed"), // 106
200 _("Chart Feature: Bridge partially open"), // 107
201 _("Chart Feature: Bridge fully open"), // 108
202 _("(reserved for future use)"), // 109
203 _("(reserved for future use)"), // 110
204 _("(reserved for future use)"), // 111
205 _("Report from ship: Icing info"), // 112
206 _("(reserved for future use)"), // 113
207 _("Report from ship: Miscellaneous information - define in "
208 "Associated text field"), // 114
209 _("(reserved for future use)"), // 115
210 _("(reserved for future use)"), // 116
211 _("(reserved for future use)"), // 117
212 _("(reserved for future use)"), // 118
213 _("(reserved for future use)"), // 119
214 _("Route: Recommended route"), // 120
215 _("Route: Alternative route"), // 121
216 _("Route: Recommended route through ice"), // 122
217 _("(reserved for future use)"), // 123
218 _("(reserved for future use)"), // 124
219 _("Other - Define in associated text field"), // 125
220 _("Cancellation - cancel area as identified by Message Linkage "
221 "ID"), // 126
222 _("Undefined (default)") //, // 127
223};
224
225static bool GetCanvasPointPix(ViewPort &vp, ChartCanvas *cp, double rlat,
226 double rlon, wxPoint *r) {
227 if (cp != NULL) {
228 return cp->GetCanvasPointPix(rlat, rlon, r);
229 }
230 *r = vp.GetPixFromLL(rlat, rlon);
231 return true;
232}
233
234static wxPoint transrot(wxPoint pt, float sin_theta, float cos_theta,
235 wxPoint offset = wxPoint(0, 0)) {
236 wxPoint ret;
237 float px = (float)(pt.x * sin_theta) + (float)(pt.y * cos_theta);
238 float py = (float)(pt.y * sin_theta) - (float)(pt.x * cos_theta);
239 ret.x = (int)wxRound(px);
240 ret.y = (int)wxRound(py);
241 ret.x += offset.x;
242 ret.y += offset.y;
243
244 return ret;
245}
246
247static void transrot_pts(int n, wxPoint *pt, float sin_theta, float cos_theta,
248 wxPoint offset = wxPoint(0, 0)) {
249 for (int i = 0; i < n; i++)
250 pt[i] = transrot(pt[i], sin_theta, cos_theta, offset);
251}
252
253void AISDrawAreaNotices(ocpnDC &dc, ViewPort &vp, ChartCanvas *cp) {
254 if (cp == NULL) return;
255 if (!g_pAIS || !cp->GetShowAIS() || !g_bShowAreaNotices) return;
256
257 wxDateTime now = wxDateTime::Now();
258 now.MakeGMT();
259
260 bool b_pens_set = false;
261 wxPen pen_save;
262 wxBrush brush_save;
263 wxColour yellow;
264 wxColour green;
265 wxPen pen;
266 wxBrush *yellow_brush = wxTheBrushList->FindOrCreateBrush(
267 wxColour(0, 0, 0), wxBRUSHSTYLE_TRANSPARENT);
268 wxBrush *green_brush = wxTheBrushList->FindOrCreateBrush(
269 wxColour(0, 0, 0), wxBRUSHSTYLE_TRANSPARENT);
270 ;
271 wxBrush *brush;
272
273 float vp_scale = vp.view_scale_ppm;
274
275 for (const auto &target : g_pAIS->GetAreaNoticeSourcesList()) {
276 auto target_data = target.second;
277 if (!target_data->area_notices.empty()) {
278 if (!b_pens_set) {
279 pen_save = dc.GetPen();
280 brush_save = dc.GetBrush();
281
282 yellow = GetGlobalColor("YELO1");
283 yellow.Set(yellow.Red(), yellow.Green(), yellow.Blue(), 64);
284
285 green = GetGlobalColor("GREEN4");
286 green.Set(green.Red(), green.Green(), green.Blue(), 64);
287
288 pen.SetColour(yellow);
289 pen.SetWidth(2);
290
291 yellow_brush = wxTheBrushList->FindOrCreateBrush(
292 yellow, wxBRUSHSTYLE_CROSSDIAG_HATCH);
293 green_brush =
294 wxTheBrushList->FindOrCreateBrush(green, wxBRUSHSTYLE_TRANSPARENT);
295 brush = yellow_brush;
296
297 b_pens_set = true;
298 }
299
300 for (auto &ani : target_data->area_notices) {
301 Ais8_001_22 &area_notice = ani.second;
302
303 if (area_notice.expiry_time > now) {
304 std::vector<wxPoint> points;
305 bool draw_polygon = false;
306
307 switch (area_notice.notice_type) {
308 case 0:
309 pen.SetColour(green);
310 brush = green_brush;
311 break;
312 case 1:
313 pen.SetColour(yellow);
314 brush = yellow_brush;
315 break;
316 default:
317 pen.SetColour(yellow);
318 brush = yellow_brush;
319 }
320 dc.SetPen(pen);
321 dc.SetBrush(*brush);
322
323 for (Ais8_001_22_SubAreaList::iterator sa =
324 area_notice.sub_areas.begin();
325 sa != area_notice.sub_areas.end(); ++sa) {
326 switch (sa->shape) {
327 case AIS8_001_22_SHAPE_CIRCLE: {
328 wxPoint target_point;
329 GetCanvasPointPix(vp, cp, sa->latitude, sa->longitude,
330 &target_point);
331 points.push_back(target_point);
332 if (sa->radius_m > 0.0)
333 dc.DrawCircle(target_point, sa->radius_m * vp_scale);
334 break;
335 }
336 case AIS8_001_22_SHAPE_RECT: {
337 wxPoint target_point;
338 double lat = sa->latitude;
339 double lon = sa->longitude;
340 int orient_east = 90 + sa->orient_deg;
341 if (orient_east > 360) orient_east -= 360;
342 GetCanvasPointPix(vp, cp, lat, lon, &target_point);
343 points.push_back(target_point);
344 ll_gc_ll(lat, lon, orient_east, sa->e_dim_m / 1852.0, &lat,
345 &lon);
346 GetCanvasPointPix(vp, cp, lat, lon, &target_point);
347 points.push_back(target_point);
348 ll_gc_ll(lat, lon, sa->orient_deg, sa->n_dim_m / 1852.0, &lat,
349 &lon);
350 GetCanvasPointPix(vp, cp, lat, lon, &target_point);
351 points.push_back(target_point);
352 ll_gc_ll(sa->latitude, sa->longitude, sa->orient_deg,
353 sa->n_dim_m / 1852.0, &lat, &lon);
354 GetCanvasPointPix(vp, cp, lat, lon, &target_point);
355 points.push_back(target_point);
356 draw_polygon = true;
357 break;
358 }
359 case AIS8_001_22_SHAPE_SECTOR: {
360 wxPoint target_point;
361 double lat, lon;
362 double lat1 = sa->latitude;
363 double lon1 = sa->longitude;
364 GetCanvasPointPix(vp, cp, lat1, lon1, &target_point);
365 points.push_back(target_point);
366
367 for (int i = 0; i < 18; ++i) {
368 ll_gc_ll(
369 lat1, lon1,
370 sa->left_bound_deg +
371 i * (sa->right_bound_deg - sa->left_bound_deg) / 18,
372 sa->radius_m / 1852.0, &lat, &lon);
373 GetCanvasPointPix(vp, cp, lat, lon, &target_point);
374 points.push_back(target_point);
375 }
376 // Last angle explicitly to avoid any rounding errors
377 ll_gc_ll(lat1, lon1, sa->right_bound_deg, sa->radius_m / 1852.0,
378 &lat, &lon);
379 GetCanvasPointPix(vp, cp, lat, lon, &target_point);
380 points.push_back(target_point);
381
382 draw_polygon = true;
383 break;
384 }
385 case AIS8_001_22_SHAPE_POLYGON:
386 draw_polygon = true;
387 // FALL THROUGH
388 case AIS8_001_22_SHAPE_POLYLINE: {
389 double lat = sa->latitude;
390 double lon = sa->longitude;
391 for (int i = 0; i < 4; ++i) {
392 ll_gc_ll(lat, lon, sa->angles[i], sa->dists_m[i] / 1852.0,
393 &lat, &lon);
394 wxPoint target_point;
395 GetCanvasPointPix(vp, cp, lat, lon, &target_point);
396 points.push_back(target_point);
397 }
398 dc.DrawLines(points.size(), &points.front());
399 }
400 }
401 }
402 if (draw_polygon) dc.DrawPolygon(points.size(), &points.front());
403 }
404 }
405 }
406 }
407
408 if (b_pens_set) {
409 dc.SetPen(pen_save);
410 dc.SetBrush(brush_save);
411 }
412}
413
414static void TargetFrame(ocpnDC &dc, wxPen pen, int x, int y, int radius) {
415 // Constants?
416 int gap2 = 2 * radius / 6;
417
418 wxPen pen_save = dc.GetPen();
419
420 dc.SetPen(pen);
421
422 dc.DrawLine(x - radius, y + gap2, x - radius, y + radius);
423 dc.DrawLine(x - radius, y + radius, x - gap2, y + radius);
424 dc.DrawLine(x + gap2, y + radius, x + radius, y + radius);
425 dc.DrawLine(x + radius, y + radius, x + radius, y + gap2);
426 dc.DrawLine(x + radius, y - gap2, x + radius, y - radius);
427 dc.DrawLine(x + radius, y - radius, x + gap2, y - radius);
428 dc.DrawLine(x - gap2, y - radius, x - radius, y - radius);
429 dc.DrawLine(x - radius, y - radius, x - radius, y - gap2);
430
431 dc.SetPen(pen_save);
432}
433
434static void AtoN_Diamond(ocpnDC &dc, wxPen pen, int x, int y, int radius,
435 AisTargetData *td) {
436 // Apply any specific monitor scaling. e.g. MacOS
437 radius *= top_frame::Get()->GetContentScaleFactor();
438
439 // Constants?
440 wxPen pen_save = dc.GetPen();
441
442 wxPen aton_DrawPen;
443 wxPen aton_WhiteBorderPen;
444 wxBrush aton_Brush;
445
446 int rad1a = radius / 2; // size off topmarks of AtoN
447 int rad2a = radius / 4;
448 int rad3a =
449 rad1a -
450 1; // slightly smaller size off topmarks to look better for the eye
451
452 // Set the Pen for what is needed
453 if ((td->NavStatus == ATON_VIRTUAL_OFFPOSITION) ||
454 (td->NavStatus == ATON_REAL_OFFPOSITION))
455 aton_DrawPen = wxPen(GetGlobalColor("URED"), pen.GetWidth());
456 else
457 aton_DrawPen = wxPen(GetGlobalColor("UBLCK"), pen.GetWidth());
458
459 bool b_virt = (td->NavStatus == ATON_VIRTUAL) |
460 (td->NavStatus == ATON_VIRTUAL_ONPOSITION) |
461 (td->NavStatus == ATON_VIRTUAL_OFFPOSITION);
462
463 if (b_virt) aton_DrawPen.SetStyle(wxPENSTYLE_SHORT_DASH);
464
465 aton_WhiteBorderPen =
466 wxPen(GetGlobalColor("CHWHT"), aton_DrawPen.GetWidth() + 2);
467
468 // Draw Base Diamond. First with Thick White pen then custom pen io to get a
469 // white border around the line.
470 wxPoint diamond[5];
471 diamond[0] = wxPoint(radius, 0);
472 diamond[1] = wxPoint(0, -radius);
473 diamond[2] = wxPoint(-radius, 0);
474 diamond[3] = wxPoint(0, radius);
475 diamond[4] = wxPoint(radius, 0);
476 dc.SetPen(aton_WhiteBorderPen);
477 dc.DrawLines(5, diamond, x, y);
478 dc.SetPen(aton_DrawPen);
479 dc.DrawLines(5, diamond, x, y);
480
481 aton_DrawPen =
482 wxPen(GetGlobalColor("UBLCK"),
483 pen.GetWidth()); // Change drawing pen to Solid and width 1
484 aton_WhiteBorderPen =
485 wxPen(GetGlobalColor("CHWHT"), aton_DrawPen.GetWidth() + 2);
486
487 // draw cross inside
488 wxPoint cross[5];
489 cross[0] = wxPoint(-rad2a, 0);
490 cross[1] = wxPoint(rad2a, 0);
491 cross[2] = wxPoint(0, 0);
492 cross[3] = wxPoint(0, rad2a);
493 cross[4] = wxPoint(0, -rad2a);
494 dc.SetPen(aton_WhiteBorderPen);
495 dc.DrawLines(5, cross, x, y);
496 dc.SetPen(aton_DrawPen);
497 dc.DrawLines(5, cross, x, y);
498
499 wxPoint TriPointUp[4]; // Declare triangles here for multiple use
500 TriPointUp[0] = wxPoint(-rad1a, 0);
501 TriPointUp[1] = wxPoint(rad1a, 0);
502 TriPointUp[2] = wxPoint(0, -rad1a);
503 TriPointUp[3] = wxPoint(-rad1a, 0);
504
505 wxPoint TriPointDown[4]; // Declare triangles here for multiple use
506 TriPointDown[0] = wxPoint(-rad1a, -rad1a);
507 TriPointDown[1] = wxPoint(rad1a, -rad1a);
508 TriPointDown[2] = wxPoint(0, 0);
509 TriPointDown[3] = wxPoint(-rad1a, -rad1a);
510
511 wxPoint CircleOpen[16]; // Workaround to draw transparent circles
512 CircleOpen[0] = wxPoint(-1, 5);
513 CircleOpen[1] = wxPoint(1, 5);
514 CircleOpen[2] = wxPoint(3, 4);
515 CircleOpen[3] = wxPoint(4, 3);
516 CircleOpen[4] = wxPoint(5, 1);
517 CircleOpen[5] = wxPoint(5, -1);
518 CircleOpen[6] = wxPoint(4, -3);
519 CircleOpen[7] = wxPoint(3, -4);
520 CircleOpen[8] = wxPoint(1, -5);
521 CircleOpen[9] = wxPoint(-1, -5);
522 CircleOpen[10] = wxPoint(-3, -4);
523 CircleOpen[11] = wxPoint(-4, -3);
524 CircleOpen[12] = wxPoint(-5, -1);
525 CircleOpen[13] = wxPoint(-4, 3);
526 CircleOpen[14] = wxPoint(-3, 4);
527 CircleOpen[15] = wxPoint(-1, 5);
528
529 switch (td->ShipType) {
530 case 9:
531 case 20: // Card. N
532 dc.SetPen(aton_WhiteBorderPen);
533 dc.DrawLines(4, TriPointUp, x, y - radius - 1);
534 dc.DrawLines(4, TriPointUp, x, y - radius - rad1a - 3);
535 dc.SetPen(aton_DrawPen);
536 dc.DrawLines(4, TriPointUp, x, y - radius - 1);
537 dc.DrawLines(4, TriPointUp, x, y - radius - rad1a - 3);
538 break;
539 case 10:
540 case 21: // Card E
541 dc.SetPen(aton_WhiteBorderPen);
542 dc.DrawLines(4, TriPointDown, x, y - radius - 1);
543 dc.DrawLines(4, TriPointUp, x, y - radius - rad1a - 3);
544 dc.SetPen(aton_DrawPen);
545 dc.DrawLines(4, TriPointDown, x, y - radius - 1);
546 dc.DrawLines(4, TriPointUp, x, y - radius - rad1a - 3);
547 break;
548 case 11:
549 case 22: // Card S
550 dc.SetPen(aton_WhiteBorderPen);
551 dc.DrawLines(4, TriPointDown, x, y - radius - 1);
552 dc.DrawLines(4, TriPointDown, x, y - radius - rad1a - 3);
553 dc.SetPen(aton_DrawPen);
554 dc.DrawLines(4, TriPointDown, x, y - radius - 1);
555 dc.DrawLines(4, TriPointDown, x, y - radius - rad1a - 3);
556 break;
557 case 12:
558 case 23: // Card W
559 dc.SetPen(aton_WhiteBorderPen);
560 dc.DrawLines(4, TriPointUp, x, y - radius - 1);
561 dc.DrawLines(4, TriPointDown, x, y - radius - rad1a - 3);
562 dc.SetPen(aton_DrawPen);
563 dc.DrawLines(4, TriPointUp, x, y - radius - 1);
564 dc.DrawLines(4, TriPointDown, x, y - radius - rad1a - 3);
565 break;
566 case 13: // PortHand Beacon IALA-A
567 case 24: { // StarboardHand Beacon IALA-B
568 wxPoint aRect[5]; // Square topmark
569 aRect[0] = wxPoint(-rad3a, 0);
570 aRect[1] = wxPoint(-rad3a, -rad3a - rad3a);
571 aRect[2] = wxPoint(rad3a, -rad3a - rad3a);
572 aRect[3] = wxPoint(rad3a, 0);
573 aRect[4] = wxPoint(-rad3a, 0);
574 dc.SetPen(aton_WhiteBorderPen);
575 dc.DrawLines(5, aRect, x, y - radius - 1);
576 dc.SetPen(aton_DrawPen);
577 dc.DrawLines(5, aRect, x, y - radius - 1);
578 } break;
579 case 14: // StarboardHand Beacon IALA-A
580 case 25: // PortHand Beacon IALA-B
581 dc.SetPen(aton_WhiteBorderPen);
582 dc.DrawLines(4, TriPointUp, x, y - radius);
583 dc.SetPen(aton_DrawPen);
584 dc.DrawLines(4, TriPointUp, x, y - radius);
585 break;
586 case 17:
587 case 28: // Isolated danger
588 dc.SetPen(aton_WhiteBorderPen);
589 dc.DrawLines(16, CircleOpen, x, y - radius - 5);
590 dc.SetPen(aton_DrawPen);
591 dc.DrawLines(16, CircleOpen, x, y - radius - 5);
592 dc.SetPen(aton_WhiteBorderPen);
593 dc.DrawLines(16, CircleOpen, x, y - radius - 16);
594 dc.SetPen(aton_DrawPen);
595 dc.DrawLines(16, CircleOpen, x, y - radius - 16);
596 break;
597 case 18:
598 case 29: // Safe water
599 dc.SetPen(aton_WhiteBorderPen);
600 dc.DrawLines(16, CircleOpen, x, y - radius - 5);
601 dc.SetPen(aton_DrawPen);
602 dc.DrawLines(16, CircleOpen, x, y - radius - 5);
603 break;
604 case 19:
605 case 30: { // Special Mark
606 cross[0] = wxPoint(-rad2a, -rad2a); // reuse of cross array
607 cross[1] = wxPoint(rad2a, rad2a);
608 cross[2] = wxPoint(0, 0);
609 cross[3] = wxPoint(-rad2a, rad2a);
610 cross[4] = wxPoint(rad2a, -rad2a);
611 dc.SetPen(aton_WhiteBorderPen);
612 dc.DrawLines(5, cross, x, y - radius - rad3a);
613 dc.SetPen(aton_DrawPen);
614 dc.DrawLines(5, cross, x, y - radius - rad3a);
615 } break;
616 default:
617 break;
618 }
619 dc.SetPen(pen_save);
620}
621
622static void Base_Square(ocpnDC &dc, wxPen pen, int x, int y, int radius) {
623 // Constants?
624 int gap2 = 2 * radius / 6;
625 int pen_width = pen.GetWidth();
626
627 wxPen pen_save = dc.GetPen();
628
629 dc.SetPen(pen); // draw square
630
631 dc.DrawLine(x - radius, y - radius, x - radius, y + radius);
632 dc.DrawLine(x - radius, y + radius, x + radius, y + radius);
633 dc.DrawLine(x + radius, y + radius, x + radius, y - radius);
634 dc.DrawLine(x + radius, y - radius, x - radius, y - radius);
635
636 if (pen_width > 1) {
637 pen_width -= 1;
638 pen.SetWidth(pen_width);
639 } // draw cross inside
640
641 dc.DrawLine(x - gap2, y, x + gap2, y);
642 dc.DrawLine(x, y - gap2, x, y + gap2);
643
644 dc.SetPen(pen_save);
645}
646
647static void SART_Render(ocpnDC &dc, wxPen pen, int x, int y, int radius) {
648 // Constants
649 int gap = (radius * 12) / 10;
650 int pen_width = pen.GetWidth();
651
652 wxPen pen_save = dc.GetPen();
653
654 dc.SetPen(pen);
655
656 wxBrush brush_save = dc.GetBrush();
657 wxBrush *ppBrush = wxTheBrushList->FindOrCreateBrush(
658 wxColour(0, 0, 0), wxBRUSHSTYLE_TRANSPARENT);
659 dc.SetBrush(*ppBrush);
660
661 dc.DrawCircle(x, y, radius);
662
663 if (pen_width > 1) {
664 pen_width -= 1;
665 pen.SetWidth(pen_width);
666 } // draw cross inside
667
668 dc.DrawLine(x - gap, y - gap, x + gap, y + gap);
669 dc.DrawLine(x - gap, y + gap, x + gap, y - gap);
670
671 dc.SetBrush(brush_save);
672 dc.SetPen(pen_save);
673}
674
675// spherical coordinates is sufficient for visually plotting with relatively
676// small distances and about 6x faster than ll_gc_ll
677static void spherical_ll_gc_ll(float lat, float lon, float brg, float dist,
678 float *dlat, float *dlon) {
679 float angr = brg / 180 * M_PI;
680 float latr = lat * M_PI / 180;
681 float D = dist / 3443; // earth radius in nm
682 float sD = sinf(D), cD = cosf(D);
683 float sy = sinf(latr), cy = cosf(latr);
684 float sa = sinf(angr), ca = cosf(angr);
685
686 *dlon = lon + asinf(sa * sD / cy) * 180 / M_PI;
687 *dlat = asinf(sy * cD + cy * sD * ca) * 180 / M_PI;
688}
689
690// Global static AIS target rendering metrics
691float AIS_scale_factor;
692float AIS_ATON_scale_factor;
693float AIS_nominal_target_size_mm;
694float AIS_nominal_icon_size_pixels;
695float AIS_pix_factor;
696float AIS_user_scale_factor;
697double AIS_nominal_line_width_pix;
698
699float AIS_width_interceptbar_base;
700float AIS_width_interceptbar_top;
701float AIS_intercept_bar_circle_diameter;
702float AIS_width_interceptline;
703float AIS_width_cogpredictor_base;
704float AIS_width_cogpredictor_line;
705float AIS_width_target_outline;
706float AIS_icon_diameter;
707float AIS_ATON_reference;
708
709wxFont *AIS_NameFont;
710
711static void AISSetMetrics() {
712 AIS_scale_factor = g_current_monitor_dip_px_ratio;
713 // Adapt for possible scaled display (Win)
714 double DPIscale = 1.0;
715 DPIscale = g_Platform->GetDisplayDIPMult(wxTheApp->GetTopWindow());
716
717 // Set the onscreen size of the symbol
718 // Compensate for various display resolutions
719 // Develop empirically, making a "diamond ATON" symbol about 4 mm square
720
721 // By experience, it is found that specifying target size in pixels, then
722 // bounding rendered size for high or lo resolution displays, gives the best
723 // compromise.
724
725 AIS_nominal_target_size_mm = 30.0 / g_Platform->GetDisplayDPmm();
726 // nominal_target_size_mm = gFrame->GetPrimaryCanvas()->GetDisplaySizeMM()
727 // / 60.0;
728
729 AIS_nominal_target_size_mm = wxMin(AIS_nominal_target_size_mm, 10.0);
730 AIS_nominal_target_size_mm = wxMax(AIS_nominal_target_size_mm, 5.0);
731
732 AIS_nominal_icon_size_pixels =
733 wxMax(4.0, g_Platform->GetDisplayDPmm() *
734 AIS_nominal_target_size_mm); // nominal size, but not
735 // less than 4 pixel
736 AIS_pix_factor = AIS_nominal_icon_size_pixels /
737 30.0; // generic A/B icons are 30 units in size
738
739 AIS_scale_factor *= AIS_pix_factor;
740
741 AIS_user_scale_factor = g_ShipScaleFactorExp;
742 if (g_ShipScaleFactorExp > 1.0)
743 AIS_user_scale_factor = (log(g_ShipScaleFactorExp) + 1.0) *
744 1.2; // soften the scale factor a bit
745 AIS_scale_factor *= AIS_user_scale_factor;
746
747 // All ATONs, including AIS virtuals, scale with chart objects.
748 AIS_ATON_scale_factor = g_MarkScaleFactorExp;
749 if (g_MarkScaleFactorExp > 1.0)
750 AIS_ATON_scale_factor = (log(g_MarkScaleFactorExp) + 1.0) *
751 1.2; // soften the scale factor a bit
752
753 // Establish some graphic element line widths dependent on the platform
754 // display resolution
755 AIS_nominal_line_width_pix =
756 wxMax(2, g_Platform->GetDisplayDPmm() / (4.0 / DPIscale));
757 // 0.25 mm nominal, but not less than 2 pixels
758
759 AIS_width_interceptbar_base = 3 * AIS_nominal_line_width_pix;
760 AIS_width_interceptbar_top = 1.5 * AIS_nominal_line_width_pix;
761 AIS_intercept_bar_circle_diameter = 3.5 * AIS_nominal_line_width_pix;
762 AIS_width_interceptline = 2 * AIS_nominal_line_width_pix;
763 AIS_width_cogpredictor_base = 3 * AIS_nominal_line_width_pix;
764 AIS_width_cogpredictor_line = 1.3 * AIS_nominal_line_width_pix;
765 AIS_width_target_outline = 1.4 * AIS_nominal_line_width_pix;
766 AIS_icon_diameter = AIS_intercept_bar_circle_diameter * AIS_user_scale_factor;
767
768 // Reference dimension for AIS ATONs
769 AIS_ATON_reference =
770 AIS_intercept_bar_circle_diameter * AIS_ATON_scale_factor;
771
772 wxFont *font = FontMgr::Get().GetFont(_("AIS Target Name"), 0);
773 double scaler = DPIscale;
774
775 AIS_NameFont = FindOrCreateFont_PlugIn(
776 font->GetPointSize() / scaler, font->GetFamily(), font->GetStyle(),
777 font->GetWeight(), false, font->GetFaceName());
778}
779
780static void AISDrawTarget(AisTargetData *td, ocpnDC &dc, ViewPort &vp,
781 ChartCanvas *cp) {
782 // Target data must be valid
783 if (NULL == td) return;
784
785 static bool firstTimeUse = true;
786 // First time AIS received
787 if (firstTimeUse && cp) {
788 g_AisFirstTimeUse = true;
789 // Show Status Bar CPA warning status
790 cp->ToggleCPAWarn();
791 g_AisFirstTimeUse = false;
792 firstTimeUse = false;
793 }
794
795 // Target is lost due to position report time-out, but still in Target List
796 if (td->b_lost) return;
797
798 // Skip anchored/moored (interpreted as low speed) targets if requested
799 // unless the target is NUC or AtoN, in which case it is always
800 // displayed.
801 if ((g_bHideMoored) && (td->SOG <= g_ShowMoored_Kts) &&
802 (td->NavStatus != NOT_UNDER_COMMAND) &&
803 ((td->Class == AIS_CLASS_A) || (td->Class == AIS_CLASS_B)))
804 return;
805
806 // Target data position must have been valid once
807 if (!td->b_positionOnceValid) return;
808
809 // And we never draw ownship
810 if (td->b_OwnShip) return;
811
812 // If target's speed is unavailable, use zero for further calculations
813 float target_sog = td->SOG;
814 if ((td->SOG > 102.2) && !td->b_SarAircraftPosnReport) target_sog = 0.;
815
816 int drawit = 0;
817 wxPoint TargetPoint, PredPoint;
818
819 // Always draw alert targets, even if they are off the screen
820 if (td->n_alert_state == AIS_ALERT_SET) {
821 drawit++;
822 } else {
823 // Is target in Vpoint?
824 if (vp.GetBBox().Contains(td->Lat, td->Lon))
825 drawit++; // yep
826 else {
827 // If AIS tracks are shown, is the first point of the track on-screen?
828 if (1 /*g_bAISShowTracks*/ && td->b_show_track) {
829 if (td->m_ptrack.size() > 0) {
830 const AISTargetTrackPoint &ptrack_point = td->m_ptrack.front();
831 if (vp.GetBBox().Contains(ptrack_point.m_lat, ptrack_point.m_lon))
832 drawit++;
833 }
834 }
835 }
836 }
837
838 // Calculate AIS target Position Predictor, using global static variable
839 // for length of vector
840
841 float pred_lat, pred_lon;
842 spherical_ll_gc_ll(td->Lat, td->Lon, td->COG,
843 target_sog * g_ShowCOG_Mins / 60., &pred_lat, &pred_lon);
844
845 // Is predicted point in the VPoint?
846 if (vp.GetBBox().Contains(pred_lat, pred_lon))
847 drawit++; // yep
848 else {
849 LLBBox box;
850 box.SetFromSegment(td->Lat, td->Lon, pred_lat, pred_lon);
851 // And one more test to catch the case where target COG line crosses the
852 // screen, but the target itself and its pred point are both off-screen
853 if (!vp.GetBBox().IntersectOut(box)) drawit++;
854 }
855
856 // Do the draw if conditions indicate
857 if (!drawit) return;
858
859 GetCanvasPointPix(vp, cp, td->Lat, td->Lon, &TargetPoint);
860 GetCanvasPointPix(vp, cp, pred_lat, pred_lon, &PredPoint);
861
862 bool b_hdgValid = true;
863
864 float theta = (float)-PI / 2.;
865 // If the target reported a valid HDG, then use it for icon
866 if ((int)(td->HDG) != 511) {
867 theta = ((td->HDG - 90) * PI / 180.) + vp.rotation;
868 } else {
869 b_hdgValid = false; // tentative judgement
870
871 if (!g_bInlandEcdis) {
872 // question: why can we not compute similar to above using COG instead of
873 // HDG?
874 // Calculate the relative angle for this chart orientation
875 // Use a 100 pixel vector to calculate angle
876 float angle_distance_nm = (100. / vp.view_scale_ppm) / 1852.;
877 float angle_lat, angle_lon;
878 spherical_ll_gc_ll(td->Lat, td->Lon, td->COG, angle_distance_nm,
879 &angle_lat, &angle_lon);
880
881 wxPoint AnglePoint;
882 GetCanvasPointPix(vp, cp, angle_lat, angle_lon, &AnglePoint);
883
884 if (abs(AnglePoint.x - TargetPoint.x) > 0) {
885 if (target_sog > g_SOGminCOG_kts) {
886 theta = atan2f((double)(AnglePoint.y - TargetPoint.y),
887 (double)(AnglePoint.x - TargetPoint.x));
888 b_hdgValid = true;
889 } else
890 theta = (float)-PI / 2.;
891 } else {
892 if (AnglePoint.y > TargetPoint.y)
893 theta = (float)PI / 2.; // valid COG 180
894 else {
895 theta = (float)-PI /
896 2.; // valid COG 000 or speed is too low to resolve course
897 if (td->SOG >= g_SOGminCOG_kts) // valid COG 000 or speed is too
898 // low to resolve course
899 b_hdgValid = true;
900 }
901 }
902 }
903 }
904
905 // only need to compute this once;
906 float sin_theta = sinf(theta), cos_theta = cosf(theta);
907
908 wxDash dash_long[2];
909 // Long dash <---------+
910 dash_long[0] = (int)(1.0 * top_frame::Get()->GetPixPerMM());
911 // Short gap |
912 dash_long[1] = (int)(0.5 * top_frame::Get()->GetPixPerMM());
913
914 int targetscale = 100;
915 int idxCC = 0;
916 if (cp != NULL) {
917 idxCC = cp->m_canvasIndex;
918
919 if (idxCC > AIS_TARGETDATA_MAX_CANVAS - 1)
920 return; // If more then n canvasses do not draw AIS anymore as we are
921 // running out of array index
922 if (cp->GetAttenAIS()) {
923 if (td->NavStatus <= 15) { // NavStatus > 15 is AtoN, and we don want
924 // AtoN being counted for attenuation
925 // with one tick per second targets can slink from 100 to 50 in abt 25
926 // seconds
927 if (td->importance < AISImportanceSwitchPoint)
928 targetscale = td->last_scale[idxCC] - 2;
929 // growing from 50 till 100% goes faster in 10 seconds
930 if (td->importance > AISImportanceSwitchPoint)
931 targetscale = td->last_scale[idxCC] + 5;
932 if (targetscale > 100) targetscale = 100;
933 if (targetscale < 50) targetscale = 50;
934 td->last_scale[idxCC] = targetscale;
935 }
936 }
937 }
938
939 // Draw the icon rotated to the COG
940 wxPoint ais_real_size[6];
941 bool bcan_draw_size = true;
942 if (g_bDrawAISSize) {
943 if (td->DimA + td->DimB == 0 || td->DimC + td->DimD == 0) {
944 bcan_draw_size = false;
945 } else {
946 double ref_lat, ref_lon;
947 ll_gc_ll(td->Lat, td->Lon, 0, 100. / 1852., &ref_lat, &ref_lon);
948 wxPoint2DDouble b_point = vp.GetDoublePixFromLL(td->Lat, td->Lon);
949 wxPoint2DDouble r_point = vp.GetDoublePixFromLL(ref_lat, ref_lon);
950 double ppm = r_point.GetDistance(b_point) / 100.;
951 double offwid = (td->DimC + td->DimD) * ppm * 0.25;
952 double offlen = (td->DimA + td->DimB) * ppm * 0.15;
953 ais_real_size[0].x = -td->DimD * ppm;
954 ais_real_size[0].y = -td->DimB * ppm;
955 ais_real_size[1].x = -td->DimD * ppm;
956 ais_real_size[1].y = td->DimA * ppm - offlen;
957 ais_real_size[2].x = -td->DimD * ppm + offwid;
958 ais_real_size[2].y = td->DimA * ppm;
959 ais_real_size[3].x = td->DimC * ppm - offwid;
960 ais_real_size[3].y = td->DimA * ppm;
961 ais_real_size[4].x = td->DimC * ppm;
962 ais_real_size[4].y = td->DimA * ppm - offlen;
963 ais_real_size[5].x = td->DimC * ppm;
964 ais_real_size[5].y = -td->DimB * ppm;
965
966 if (ais_real_size[4].x - ais_real_size[0].x < 16 ||
967 ais_real_size[2].y - ais_real_size[0].y < 30)
968 bcan_draw_size = false; // drawing too small does not make sense
969 else {
970 bcan_draw_size = true;
971 transrot_pts(6, ais_real_size, sin_theta, cos_theta);
972 }
973 }
974 }
975
976 wxPoint *iconPoints;
977 int nPoints;
978 wxPoint ais_quad_icon[4] = {wxPoint(-8, -6), wxPoint(0, 24), wxPoint(8, -6),
979 wxPoint(0, -6)};
980 wxPoint ais_octo_icon[8] = {wxPoint(4, 8), wxPoint(8, 4), wxPoint(8, -4),
981 wxPoint(4, -8), wxPoint(-4, -8), wxPoint(-8, -4),
982 wxPoint(-8, 4), wxPoint(-4, 8)};
983
984 if (!g_bInlandEcdis) {
985 // to speed up we only calculate scale when not max or minimal
986 if (targetscale == 50) {
987 ais_quad_icon[0] = wxPoint(-4, -3);
988 ais_quad_icon[1] = wxPoint(0, 12);
989 ais_quad_icon[2] = wxPoint(4, -3);
990 ais_quad_icon[3] = wxPoint(0, -3);
991 } else if (targetscale != 100) {
992 ais_quad_icon[0] =
993 wxPoint((int)-8 * targetscale / 100, (int)-6 * targetscale / 100);
994 ais_quad_icon[1] = wxPoint(0, (int)24 * targetscale / 100);
995 ais_quad_icon[2] =
996 wxPoint((int)8 * targetscale / 100, (int)-6 * targetscale / 100);
997 ais_quad_icon[3] = wxPoint(0, (int)-6 * targetscale / 100);
998 }
999
1000 // If this is an AIS Class B target, so symbolize it differently
1001 if (td->Class == AIS_CLASS_B) ais_quad_icon[3].y = 0;
1002
1003 if ((td->Class == AIS_GPSG_BUDDY) || (td->b_isFollower)) {
1004 ais_quad_icon[0] = wxPoint(-5, -12);
1005 ais_quad_icon[1] = wxPoint(-3, 12);
1006 ais_quad_icon[2] = wxPoint(3, 12);
1007 ais_quad_icon[3] = wxPoint(5, -12);
1008 } else if (td->Class == AIS_DSC) {
1009 ais_quad_icon[0].y = 0;
1010 ais_quad_icon[1].y = 8;
1011 ais_quad_icon[2].y = 0;
1012 ais_quad_icon[3].y = -8;
1013 } else if (td->Class == AIS_APRS) {
1014 ais_quad_icon[0] = wxPoint(-8, -8);
1015 ais_quad_icon[1] = wxPoint(-8, 8);
1016 ais_quad_icon[2] = wxPoint(8, 8);
1017 ais_quad_icon[3] = wxPoint(8, -8);
1018 }
1019
1020 transrot_pts(4, ais_quad_icon, sin_theta, cos_theta);
1021
1022 nPoints = 4;
1023 iconPoints = ais_quad_icon;
1024
1025 } else { // iENC
1026 if (b_hdgValid) {
1027 transrot_pts(4, ais_quad_icon, sin_theta, cos_theta);
1028 nPoints = 4;
1029 iconPoints = ais_quad_icon;
1030 } else {
1031 nPoints = 8;
1032 iconPoints = ais_octo_icon;
1033 }
1034 }
1035
1036 wxColour UBLCK = GetGlobalColor("UBLCK");
1037 dc.SetPen(wxPen(UBLCK));
1038
1039 // Default color is green
1040 wxColour UINFG = GetGlobalColor("UINFG");
1041 wxBrush target_brush = wxBrush(UINFG);
1042
1043 // Euro Inland targets render slightly differently, unless in InlandENC mode
1044 if (td->b_isEuroInland && !g_bInlandEcdis)
1045 target_brush = wxBrush(GetGlobalColor("TEAL1"));
1046
1047 // Target name comes from cache
1048 if (td->b_nameFromCache) target_brush = wxBrush(GetGlobalColor("GREEN5"));
1049
1050 // and....
1051 wxColour URED = GetGlobalColor("URED");
1052 if (!td->b_nameValid) target_brush = wxBrush(GetGlobalColor("CHYLW"));
1053
1054 if ((td->Class == AIS_DSC) &&
1055 ((td->ShipType == 12) || (td->ShipType == 16))) // distress(relayed)
1056 target_brush = wxBrush(URED);
1057
1058 if (td->b_SarAircraftPosnReport) target_brush = wxBrush(UINFG);
1059
1060 if ((td->n_alert_state == AIS_ALERT_SET) && (td->bCPA_Valid))
1061 target_brush = wxBrush(URED);
1062
1063 if ((td->n_alert_state == AIS_ALERT_NO_DIALOG_SET) && (td->bCPA_Valid) &&
1064 (!td->b_isFollower))
1065 target_brush = wxBrush(URED);
1066
1067 if (td->b_positionDoubtful) target_brush = wxBrush(GetGlobalColor("UINFF"));
1068
1069 wxPen target_outline_pen(UBLCK, AIS_width_target_outline);
1070
1071 // Check for alarms here, maintained by AIS class timer tick
1072 if (((td->n_alert_state == AIS_ALERT_SET) && (td->bCPA_Valid)) ||
1073 (td->b_show_AIS_CPA && (td->bCPA_Valid))) {
1074 // Project further from the target's projected position to CPA time.
1075 double tcpa_lat, tcpa_lon;
1076 ll_gc_ll(td->Lat_projected, td->Lon_projected, td->COG,
1077 target_sog * td->TCPA / 60.,
1078 &tcpa_lat, &tcpa_lon);
1079 wxPoint tCPAPoint;
1080 wxPoint TPoint = TargetPoint;
1081 GetCanvasPointPix(vp, cp, tcpa_lat, tcpa_lon, &tCPAPoint);
1082
1083 // Draw the intercept line from target
1084 ClipResult res = cohen_sutherland_line_clip_i(
1085 &TPoint.x, &TPoint.y, &tCPAPoint.x, &tCPAPoint.y, 0, vp.pix_width, 0,
1086 vp.pix_height);
1087
1088 if (res != Invisible) {
1089 wxPen ppPen2(URED, AIS_width_cogpredictor_line, wxPENSTYLE_USER_DASH);
1090 ppPen2.SetDashes(2, dash_long);
1091 dc.SetPen(ppPen2);
1092
1093 dc.StrokeLine(TPoint.x, TPoint.y, tCPAPoint.x, tCPAPoint.y);
1094 }
1095
1096 // Calculate the point of CPA for ownship
1097 double ocpa_lat, ocpa_lon;
1098
1099 // Detect and handle the case where ownship COG is undefined....
1100 if (std::isnan(gCog) || std::isnan(gSog)) {
1101 ocpa_lat = gLat;
1102 ocpa_lon = gLon;
1103 } else {
1104 ll_gc_ll(gLat, gLon, gCog, gSog * td->TCPA / 60., &ocpa_lat, &ocpa_lon);
1105 }
1106
1107 wxPoint oCPAPoint;
1108
1109 GetCanvasPointPix(vp, cp, ocpa_lat, ocpa_lon, &oCPAPoint);
1110 GetCanvasPointPix(vp, cp, tcpa_lat, tcpa_lon, &tCPAPoint);
1111
1112 // Save a copy of these unclipped points
1113 wxPoint oCPAPoint_unclipped = oCPAPoint;
1114 wxPoint tCPAPoint_unclipped = tCPAPoint;
1115
1116 // Draw a line from target CPA point to ownship CPA point
1117 ClipResult ores = cohen_sutherland_line_clip_i(
1118 &tCPAPoint.x, &tCPAPoint.y, &oCPAPoint.x, &oCPAPoint.y, 0, vp.pix_width,
1119 0, vp.pix_height);
1120
1121 if (ores != Invisible) {
1122 wxColour yellow = GetGlobalColor("YELO1");
1123 dc.SetPen(wxPen(yellow, AIS_width_interceptbar_base));
1124 dc.StrokeLine(tCPAPoint.x, tCPAPoint.y, oCPAPoint.x, oCPAPoint.y);
1125
1126 wxPen ppPen2(URED, AIS_width_interceptbar_top, wxPENSTYLE_USER_DASH);
1127 ppPen2.SetDashes(2, dash_long);
1128 dc.SetPen(ppPen2);
1129 dc.StrokeLine(tCPAPoint.x, tCPAPoint.y, oCPAPoint.x, oCPAPoint.y);
1130
1131 // Draw little circles at the ends of the CPA alert line
1132 wxBrush br(GetGlobalColor("BLUE3"));
1133 dc.SetBrush(br);
1134 dc.SetPen(wxPen(UBLCK, AIS_width_target_outline));
1135
1136 // Using the true ends, not the clipped ends
1137 dc.StrokeCircle(
1138 tCPAPoint_unclipped.x, tCPAPoint_unclipped.y,
1139 AIS_intercept_bar_circle_diameter * AIS_user_scale_factor);
1140 dc.StrokeCircle(
1141 oCPAPoint_unclipped.x, oCPAPoint_unclipped.y,
1142 AIS_intercept_bar_circle_diameter * AIS_user_scale_factor);
1143 }
1144
1145 // Draw the intercept line from ownship
1146 wxPoint oShipPoint;
1147 GetCanvasPointPix(vp, cp, gLat, gLon, &oShipPoint);
1148 oCPAPoint = oCPAPoint_unclipped; // recover the unclipped point
1149
1150 ClipResult ownres = cohen_sutherland_line_clip_i(
1151 &oShipPoint.x, &oShipPoint.y, &oCPAPoint.x, &oCPAPoint.y, 0,
1152 vp.pix_width, 0, vp.pix_height);
1153
1154 if (ownres != Invisible) {
1155 wxPen ppPen2(URED, AIS_width_interceptline, wxPENSTYLE_USER_DASH);
1156 ppPen2.SetDashes(2, dash_long);
1157 dc.SetPen(ppPen2);
1158
1159 dc.StrokeLine(oShipPoint.x, oShipPoint.y, oCPAPoint.x, oCPAPoint.y);
1160 } // TR : till here
1161
1162 dc.SetPen(wxPen(UBLCK));
1163 dc.SetBrush(wxBrush(URED));
1164 }
1165
1166 // Highlight the AIS target symbol if an alert dialog is currently open for
1167 // it
1168 if (cp != NULL) {
1169 auto alert_dlg_active =
1170 dynamic_cast<AISTargetAlertDialog *>(g_pais_alert_dialog_active);
1171 if (alert_dlg_active && alert_dlg_active->IsShown() && cp) {
1172 if (alert_dlg_active->Get_Dialog_MMSI() == td->MMSI)
1173 cp->JaggyCircle(dc, wxPen(URED, 2), TargetPoint.x, TargetPoint.y, 100);
1174 }
1175 }
1176
1177 // Highlight the AIS target symbol if a query dialog is currently open for it
1178 if (g_pais_query_dialog_active && g_pais_query_dialog_active->IsShown()) {
1179 if (g_pais_query_dialog_active->GetMMSI() == td->MMSI)
1180 TargetFrame(dc, wxPen(UBLCK, 2), TargetPoint.x, TargetPoint.y, 25);
1181 }
1182
1183 // Render the COG line if the speed is greater than moored speed defined
1184 // by ais options dialog
1185 if ((g_bShowCOG) && (target_sog > g_SOGminCOG_kts) && td->b_active) {
1186 int pixx = TargetPoint.x;
1187 int pixy = TargetPoint.y;
1188 int pixx1 = PredPoint.x;
1189 int pixy1 = PredPoint.y;
1190
1191 // Don't draw the COG line and predictor point if zoomed far out.... or if
1192 // target lost/inactive
1193 float l = sqrtf(powf((float)(PredPoint.x - TargetPoint.x), 2) +
1194 powf((float)(PredPoint.y - TargetPoint.y), 2));
1195
1196 if (l > 24) {
1197 ClipResult res = cohen_sutherland_line_clip_i(
1198 &pixx, &pixy, &pixx1, &pixy1, 0, vp.pix_width, 0, vp.pix_height);
1199
1200 if (res != Invisible) {
1201 // Draw a wider coloured line
1202 if (targetscale >= 75) {
1203 wxPen wide_pen(target_brush.GetColour(), AIS_width_cogpredictor_base);
1204 dc.SetPen(wide_pen);
1205 dc.StrokeLine(pixx, pixy, pixx1, pixy1);
1206 }
1207
1208 if (AIS_width_cogpredictor_base > 1) {
1209 // Draw narrow black line
1210 wxPen narrow_pen(UBLCK, AIS_width_cogpredictor_line);
1211 if (targetscale < 75) {
1212 narrow_pen.SetWidth(1);
1213 narrow_pen.SetStyle(wxPENSTYLE_USER_DASH);
1214 wxDash dash_dot[2];
1215 dash_dot[0] = 2;
1216 dash_dot[1] = 2;
1217 narrow_pen.SetDashes(2, dash_dot);
1218 }
1219 dc.SetPen(narrow_pen);
1220 dc.StrokeLine(pixx, pixy, pixx1, pixy1);
1221 }
1222
1223 if (dc.GetDC()) {
1224 dc.SetBrush(target_brush);
1225 dc.StrokeCircle(PredPoint.x, PredPoint.y, 5 * targetscale / 100);
1226 } else {
1227#ifdef ocpnUSE_GL
1228
1229// #ifndef USE_ANDROID_GLES2
1230#if !defined(USE_ANDROID_GLES2) && !defined(ocpnUSE_GLSL)
1231
1232 glPushMatrix();
1233 glTranslated(PredPoint.x, PredPoint.y, 0);
1234 glScalef(AIS_scale_factor, AIS_scale_factor, AIS_scale_factor);
1235 // draw circle
1236 float points[] = {0.0f, 5.0f, 2.5f, 4.330127f, 4.330127f,
1237 2.5f, 5.0f, 0, 4.330127f, -2.5f,
1238 2.5f, -4.330127f, 0, -5.1f, -2.5f,
1239 -4.330127f, -4.330127f, -2.5f, -5.0f, 0,
1240 -4.330127f, 2.5f, -2.5f, 4.330127f, 0,
1241 5.0f};
1242 if (targetscale <= 75) {
1243 for (unsigned int i = 0; i < (sizeof points) / (sizeof *points);
1244 i++)
1245 points[i] = points[i] / 2;
1246 }
1247
1248 wxColour c = target_brush.GetColour();
1249 glColor3ub(c.Red(), c.Green(), c.Blue());
1250
1251 glBegin(GL_TRIANGLE_FAN);
1252 for (unsigned int i = 0; i < (sizeof points) / (sizeof *points);
1253 i += 2)
1254 glVertex2i(points[i], points[i + 1]);
1255 glEnd();
1256
1257 glColor3ub(0, 0, 0);
1258 glLineWidth(AIS_width_target_outline);
1259 glBegin(GL_LINE_LOOP);
1260 for (unsigned int i = 0; i < (sizeof points) / (sizeof *points);
1261 i += 2)
1262 glVertex2i(points[i], points[i + 1]);
1263 glEnd();
1264 glPopMatrix();
1265#else
1266
1267 dc.SetBrush(target_brush);
1268 dc.StrokeCircle(PredPoint.x, PredPoint.y,
1269 AIS_intercept_bar_circle_diameter *
1270 AIS_user_scale_factor * targetscale / 100);
1271#endif
1272#endif
1273 }
1274 }
1275
1276 // Draw RateOfTurn Vector
1277 if ((td->ROTAIS != 0) && (td->ROTAIS != -128) && (!g_bShowScaled)) {
1278 float cog_angle = td->COG * PI / 180.;
1279
1280 float theta2 = theta; // ownship drawn angle
1281 if (td->SOG >= g_SOGminCOG_kts)
1282 theta2 = cog_angle - (PI / 2); // actual cog angle
1283
1284 float nv = 10;
1285 if (td->ROTAIS > 0)
1286 theta2 += (float)PI / 2;
1287 else
1288 theta2 -= (float)PI / 2;
1289
1290 int xrot = (int)round(pixx1 + (nv * cosf(theta2)));
1291 int yrot = (int)round(pixy1 + (nv * sinf(theta2)));
1292 dc.StrokeLine(pixx1, pixy1, xrot, yrot);
1293 }
1294 }
1295 }
1296
1297 // Actually Draw the target
1298 if (td->Class == AIS_ARPA || td->Class == AIS_BUOY) {
1299 wxPen target_pen(UBLCK, 2);
1300
1301 dc.SetPen(target_pen);
1302 dc.SetBrush(target_brush);
1303 dc.StrokeCircle(TargetPoint.x, TargetPoint.y, 1.8 * AIS_icon_diameter);
1304
1305 dc.StrokeCircle(TargetPoint.x, TargetPoint.y, 1);
1306 // Draw the inactive cross-out line
1307 if (!td->b_active) {
1308 dc.SetPen(wxPen(UBLCK, 2));
1309 dc.StrokeLine(TargetPoint.x - 14, TargetPoint.y, TargetPoint.x + 14,
1310 TargetPoint.y);
1311 dc.SetPen(wxPen(UBLCK, 1));
1312 }
1313
1314 } else if (td->Class == AIS_METEO) { // Meteorologic
1315 wxPen met(UBLCK, (wxMax(target_outline_pen.GetWidth(), 2.5)));
1316 dc.SetPen(met);
1317 dc.SetBrush(wxBrush(UBLCK, wxBRUSHSTYLE_TRANSPARENT));
1318 double met_radius = 1.5 * AIS_ATON_reference;
1319 dc.StrokeCircle(TargetPoint.x, TargetPoint.y, met_radius);
1320
1321 /* Inscribed "W" in the circle. */
1322 dc.SetPen(wxPen(wxMax(target_outline_pen.GetWidth(), 1)));
1323 // Left part
1324 dc.StrokeLine(TargetPoint.x, TargetPoint.y - met_radius / 4,
1325 TargetPoint.x - met_radius / 3,
1326 TargetPoint.y + met_radius / 2);
1327 dc.StrokeLine(
1328 TargetPoint.x - met_radius / 3, TargetPoint.y + met_radius / 2,
1329 TargetPoint.x - met_radius / 2, TargetPoint.y - met_radius / 2);
1330 // Right part
1331 dc.StrokeLine(TargetPoint.x, TargetPoint.y - met_radius / 4,
1332 TargetPoint.x + met_radius / 3,
1333 TargetPoint.y + met_radius / 2);
1334 dc.StrokeLine(
1335 TargetPoint.x + met_radius / 3, TargetPoint.y + met_radius / 2,
1336 TargetPoint.x + met_radius / 2, TargetPoint.y - met_radius / 2);
1337
1338 } else if (td->Class == AIS_ATON) { // Aid to Navigation
1339 AtoN_Diamond(dc, wxPen(UBLCK, AIS_width_target_outline), TargetPoint.x,
1340 TargetPoint.y, AIS_ATON_reference * 1.5, td);
1341 } else if (td->Class == AIS_BASE) { // Base Station
1342 Base_Square(dc, wxPen(UBLCK, AIS_width_target_outline), TargetPoint.x,
1343 TargetPoint.y, AIS_ATON_reference);
1344 } else if (td->Class == AIS_SART) { // SART Target
1345 if (td->NavStatus == 14) // active
1346 SART_Render(dc, wxPen(URED, AIS_width_target_outline), TargetPoint.x,
1347 TargetPoint.y, AIS_ATON_reference);
1348 else
1349 SART_Render(dc, wxPen(GetGlobalColor("UGREN"), AIS_width_target_outline),
1350 TargetPoint.x, TargetPoint.y, AIS_ATON_reference);
1351
1352 } else if (td->b_SarAircraftPosnReport) {
1353 int airtype = (td->MMSI % 1000) / 100; // xxxyyy5zz >> helicopter
1354 int ar = airtype == 5 ? 15 : 9; // array size
1355 wxPoint SarIcon[15];
1356 wxPoint SarRot[15];
1357 double scaleplus = 1.4;
1358 if (airtype == 5) {
1359 SarIcon[0] = wxPoint(0, 9) * AIS_scale_factor * scaleplus;
1360 SarIcon[1] = wxPoint(1, 1) * AIS_scale_factor * scaleplus;
1361 SarIcon[2] = wxPoint(2, 1) * AIS_scale_factor * scaleplus;
1362 SarIcon[3] = wxPoint(9, 8) * AIS_scale_factor * scaleplus;
1363 SarIcon[4] = wxPoint(9, 7) * AIS_scale_factor * scaleplus;
1364 SarIcon[5] = wxPoint(3, 0) * AIS_scale_factor * scaleplus;
1365 SarIcon[6] = wxPoint(3, -5) * AIS_scale_factor * scaleplus;
1366 SarIcon[7] = wxPoint(9, -12) * AIS_scale_factor * scaleplus;
1367 SarIcon[8] = wxPoint(9, -13) * AIS_scale_factor * scaleplus;
1368 SarIcon[9] = wxPoint(2, -5) * AIS_scale_factor * scaleplus;
1369 SarIcon[10] = wxPoint(1, -15) * AIS_scale_factor * scaleplus;
1370 SarIcon[11] = wxPoint(3, -16) * AIS_scale_factor * scaleplus;
1371 SarIcon[12] = wxPoint(4, -18) * AIS_scale_factor * scaleplus;
1372 SarIcon[13] = wxPoint(1, -18) * AIS_scale_factor * scaleplus;
1373 SarIcon[14] = wxPoint(0, -19) * AIS_scale_factor * scaleplus;
1374 } else {
1375 SarIcon[0] = wxPoint(0, 12) * AIS_scale_factor;
1376 SarIcon[1] = wxPoint(4, 2) * AIS_scale_factor;
1377 SarIcon[2] = wxPoint(16, -2) * AIS_scale_factor;
1378 SarIcon[3] = wxPoint(16, -8) * AIS_scale_factor;
1379 SarIcon[4] = wxPoint(4, -8) * AIS_scale_factor;
1380 SarIcon[5] = wxPoint(3, -16) * AIS_scale_factor;
1381 SarIcon[6] = wxPoint(10, -18) * AIS_scale_factor;
1382 SarIcon[7] = wxPoint(10, -22) * AIS_scale_factor;
1383 SarIcon[8] = wxPoint(0, -22) * AIS_scale_factor;
1384 }
1385
1386 if (airtype == 5) { // helicopter
1387 // Draw icon as two halves
1388 // First half
1389
1390 for (int i = 0; i < ar; i++) SarRot[i] = SarIcon[i];
1391 transrot_pts(ar, SarRot, sin_theta, cos_theta);
1392
1393 wxPen tri_pen(target_brush.GetColour(), 1);
1394 dc.SetPen(tri_pen);
1395 dc.SetBrush(target_brush);
1396
1397 // Manual tesselation
1398 int mappings[14][3] = {
1399 {0, 1, 10}, {0, 10, 14}, {1, 2, 9}, {1, 9, 10}, {10, 13, 14},
1400 {10, 11, 13}, {11, 12, 13}, {1, 14, 10}, {2, 5, 9}, {5, 6, 9},
1401 {2, 3, 5}, {3, 4, 5}, {6, 7, 8}, {6, 9, 8}};
1402
1403 int nmap = 14;
1404 for (int i = 0; i < nmap; i++) {
1405 wxPoint ais_tri_icon[3];
1406 for (int j = 0; j < 3; j++) ais_tri_icon[j] = SarRot[mappings[i][j]];
1407 dc.StrokePolygon(3, ais_tri_icon, TargetPoint.x, TargetPoint.y);
1408 }
1409
1410 dc.SetPen(target_outline_pen);
1411 dc.SetBrush(wxBrush(UBLCK, wxBRUSHSTYLE_TRANSPARENT));
1412 dc.StrokePolygon(ar, SarRot, TargetPoint.x, TargetPoint.y);
1413
1414 // second half
1415
1416 for (int i = 0; i < ar; i++)
1417 SarRot[i] =
1418 wxPoint(-SarIcon[i].x, SarIcon[i].y); // mirror the icon (x -> -x)
1419
1420 transrot_pts(ar, SarRot, sin_theta, cos_theta);
1421
1422 dc.SetPen(tri_pen);
1423 dc.SetBrush(target_brush);
1424
1425 for (int i = 0; i < nmap; i++) {
1426 wxPoint ais_tri_icon[3];
1427 for (int j = 0; j < 3; j++) ais_tri_icon[j] = SarRot[mappings[i][j]];
1428 dc.StrokePolygon(3, ais_tri_icon, TargetPoint.x, TargetPoint.y);
1429 }
1430
1431 dc.SetPen(target_outline_pen);
1432 dc.SetBrush(wxBrush(UBLCK, wxBRUSHSTYLE_TRANSPARENT));
1433 dc.StrokePolygon(ar, SarRot, TargetPoint.x, TargetPoint.y);
1434 } else {
1435 // Draw icon as two halves
1436 // First half
1437
1438 for (int i = 0; i < ar; i++) SarRot[i] = SarIcon[i];
1439 transrot_pts(ar, SarRot, sin_theta, cos_theta);
1440
1441 wxPen tri_pen(target_brush.GetColour(), 1);
1442 dc.SetPen(tri_pen);
1443 dc.SetBrush(target_brush);
1444
1445 // Manual tesselation
1446 int mappings[7][3] = {{0, 1, 4}, {1, 2, 3}, {1, 3, 4}, {0, 4, 5},
1447 {0, 5, 8}, {5, 6, 7}, {5, 7, 8}};
1448 for (int i = 0; i < 7; i++) {
1449 wxPoint ais_tri_icon[3];
1450 for (int j = 0; j < 3; j++) ais_tri_icon[j] = SarRot[mappings[i][j]];
1451 dc.StrokePolygon(3, ais_tri_icon, TargetPoint.x, TargetPoint.y);
1452 }
1453
1454 dc.SetPen(target_outline_pen);
1455 dc.SetBrush(wxBrush(UBLCK, wxBRUSHSTYLE_TRANSPARENT));
1456 dc.StrokePolygon(ar, SarRot, TargetPoint.x, TargetPoint.y);
1457
1458 // second half
1459
1460 for (int i = 0; i < ar; i++)
1461 SarRot[i] =
1462 wxPoint(-SarIcon[i].x, SarIcon[i].y); // mirror the icon (x -> -x)
1463
1464 transrot_pts(ar, SarRot, sin_theta, cos_theta);
1465
1466 dc.SetPen(tri_pen);
1467 dc.SetBrush(target_brush);
1468
1469 for (int i = 0; i < 7; i++) {
1470 wxPoint ais_tri_icon[3];
1471 for (int j = 0; j < 3; j++) ais_tri_icon[j] = SarRot[mappings[i][j]];
1472 dc.StrokePolygon(3, ais_tri_icon, TargetPoint.x, TargetPoint.y);
1473 }
1474
1475 dc.SetPen(target_outline_pen);
1476 dc.SetBrush(wxBrush(UBLCK, wxBRUSHSTYLE_TRANSPARENT));
1477 dc.StrokePolygon(ar, SarRot, TargetPoint.x, TargetPoint.y);
1478 }
1479
1480 // Draw the inactive cross-out line
1481 if (!td->b_active) {
1482 wxPoint linepoint = TargetPoint;
1483 wxPoint p1 = transrot(
1484 wxPoint((int)-14 * targetscale / 100, (int)-5 * targetscale / 100),
1485 sin_theta, cos_theta, TargetPoint);
1486 wxPoint p2 = transrot(
1487 wxPoint((int)14 * targetscale / 100, (int)-5 * targetscale / 100),
1488 sin_theta, cos_theta, TargetPoint);
1489
1490 dc.SetPen(wxPen(UBLCK, 2));
1491 dc.StrokeLine(p1.x, p1.y, p2.x, p2.y);
1492 }
1493
1494 } else { // ship class A or B or a Buddy or DSC
1495 wxPen target_pen(UBLCK, 1);
1496 dc.SetPen(target_pen);
1497
1498 wxPoint Point = TargetPoint;
1499 if (g_bDrawAISRealtime &&
1500 (td->Class == AIS_CLASS_A || td->Class == AIS_CLASS_B) &&
1501 td->SOG > g_AIS_RealtPred_Kts && td->SOG < 102.2) {
1502 GetCanvasPointPix(vp, cp, td->Lat_projected, td->Lon_projected, &Point);
1503
1504 wxBrush realtime_brush = wxBrush(GetGlobalColor("GREY1"));
1505 dc.SetBrush(realtime_brush);
1506 dc.StrokePolygon(nPoints, iconPoints, Point.x, Point.y, AIS_scale_factor);
1507 }
1508 dc.SetBrush(target_brush);
1509
1510 if (dc.GetDC()) {
1511 dc.StrokePolygon(nPoints, iconPoints, TargetPoint.x, TargetPoint.y,
1512 AIS_scale_factor);
1513 } else {
1514#ifdef ocpnUSE_GL
1515// #ifndef USE_ANDROID_GLES2
1516#if !defined(USE_ANDROID_GLES2) && !defined(ocpnUSE_GLSL)
1517
1518 wxColour c = target_brush.GetColour();
1519 glColor3ub(c.Red(), c.Green(), c.Blue());
1520
1521 glPushMatrix();
1522 glTranslated(TargetPoint.x, TargetPoint.y, 0);
1523 glScalef(AIS_scale_factor, AIS_scale_factor, AIS_scale_factor);
1524
1525 glBegin(GL_TRIANGLE_FAN);
1526
1527 if (nPoints == 4) {
1528 glVertex2i(ais_quad_icon[3].x, ais_quad_icon[3].y);
1529 glVertex2i(ais_quad_icon[0].x, ais_quad_icon[0].y);
1530 glVertex2i(ais_quad_icon[1].x, ais_quad_icon[1].y);
1531 glVertex2i(ais_quad_icon[2].x, ais_quad_icon[2].y);
1532 } else {
1533 for (int i = 0; i < 8; i++) {
1534 glVertex2i(iconPoints[i].x, iconPoints[i].y);
1535 }
1536 }
1537
1538 glEnd();
1539 glLineWidth(AIS_width_target_outline);
1540
1541 glColor3ub(UBLCK.Red(), UBLCK.Green(), UBLCK.Blue());
1542
1543 glBegin(GL_LINE_LOOP);
1544 for (int i = 0; i < nPoints; i++)
1545 glVertex2i(iconPoints[i].x, iconPoints[i].y);
1546 glEnd();
1547 glPopMatrix();
1548
1549#else
1550 dc.SetPen(target_outline_pen);
1551 dc.DrawPolygon(nPoints, iconPoints, TargetPoint.x, TargetPoint.y,
1552 AIS_scale_factor);
1553#endif
1554#endif
1555 }
1556 // Draw stroke "inverted v" for GPS Follower
1557 if (td->b_isFollower) {
1558 wxPoint ais_follow_stroke[3];
1559 ais_follow_stroke[0] = wxPoint(-3, -20) * AIS_scale_factor;
1560 ais_follow_stroke[1] = wxPoint(0, 0) * AIS_scale_factor;
1561 ais_follow_stroke[2] = wxPoint(3, -20) * AIS_scale_factor;
1562
1563 transrot_pts(3, ais_follow_stroke, sin_theta, cos_theta);
1564
1565 int penWidth = wxMax(target_outline_pen.GetWidth(), 2);
1566 dc.SetPen(wxPen(UBLCK, penWidth));
1567 dc.StrokeLine(ais_follow_stroke[0].x + TargetPoint.x,
1568 ais_follow_stroke[0].y + TargetPoint.y,
1569 ais_follow_stroke[1].x + TargetPoint.x,
1570 ais_follow_stroke[1].y + TargetPoint.y);
1571 dc.StrokeLine(ais_follow_stroke[1].x + TargetPoint.x,
1572 ais_follow_stroke[1].y + TargetPoint.y,
1573 ais_follow_stroke[2].x + TargetPoint.x,
1574 ais_follow_stroke[2].y + TargetPoint.y);
1575 }
1576
1577 if (g_bDrawAISSize && bcan_draw_size) {
1578 dc.SetPen(target_outline_pen);
1579 dc.SetBrush(wxBrush(UBLCK, wxBRUSHSTYLE_TRANSPARENT));
1580 if (!g_bInlandEcdis) {
1581 dc.StrokePolygon(6, ais_real_size, TargetPoint.x, TargetPoint.y, 1.0);
1582 } else {
1583 if (b_hdgValid) {
1584 dc.StrokePolygon(6, ais_real_size, TargetPoint.x, TargetPoint.y, 1.0);
1585 }
1586 }
1587 }
1588
1589 dc.SetBrush(wxBrush(GetGlobalColor("SHIPS")));
1590 int navstatus = td->NavStatus;
1591
1592 // HSC usually have correct ShipType but navstatus == 0...
1593 // Class B can have (HSC)ShipType but never navstatus.
1594 if (((td->ShipType >= 40) && (td->ShipType < 50)) &&
1595 (navstatus == UNDERWAY_USING_ENGINE || td->Class == AIS_CLASS_B))
1596 navstatus = HSC;
1597
1598 if (targetscale > 90) {
1599 switch (navstatus) {
1600 case MOORED:
1601 case AT_ANCHOR: {
1602 dc.StrokeCircle(TargetPoint.x, TargetPoint.y, 4 * AIS_scale_factor);
1603 break;
1604 }
1605 case RESTRICTED_MANOEUVRABILITY: {
1606 wxPoint diamond[4];
1607 diamond[0] = wxPoint(4, 0) * AIS_scale_factor;
1608 diamond[1] = wxPoint(0, -6) * AIS_scale_factor;
1609 diamond[2] = wxPoint(-4, 0) * AIS_scale_factor;
1610 diamond[3] = wxPoint(0, 6) * AIS_scale_factor;
1611 dc.StrokePolygon(4, diamond, TargetPoint.x,
1612 TargetPoint.y - (11 * AIS_scale_factor));
1613 dc.StrokeCircle(TargetPoint.x, TargetPoint.y, 4 * AIS_scale_factor);
1614 dc.StrokeCircle(TargetPoint.x,
1615 TargetPoint.y - (22 * AIS_scale_factor),
1616 4 * AIS_scale_factor);
1617 break;
1618 break;
1619 }
1620 case CONSTRAINED_BY_DRAFT: {
1621 wxPoint can[4] = {wxPoint(-3, 0) * AIS_scale_factor,
1622 wxPoint(3, 0) * AIS_scale_factor,
1623 wxPoint(3, -16) * AIS_scale_factor,
1624 wxPoint(-3, -16) * AIS_scale_factor};
1625 dc.StrokePolygon(4, can, TargetPoint.x, TargetPoint.y);
1626 break;
1627 }
1628 case NOT_UNDER_COMMAND: {
1629 dc.StrokeCircle(TargetPoint.x, TargetPoint.y, 4 * AIS_scale_factor);
1630 dc.StrokeCircle(TargetPoint.x, TargetPoint.y - 9,
1631 4 * AIS_scale_factor);
1632 break;
1633 }
1634 case FISHING: {
1635 wxPoint tri[3];
1636 tri[0] = wxPoint(-4, 0) * AIS_scale_factor;
1637 tri[1] = wxPoint(4, 0) * AIS_scale_factor;
1638 tri[2] = wxPoint(0, -9) * AIS_scale_factor;
1639 dc.StrokePolygon(3, tri, TargetPoint.x, TargetPoint.y);
1640 tri[0] = wxPoint(0, -9) * AIS_scale_factor;
1641 tri[1] = wxPoint(4, -18) * AIS_scale_factor;
1642 tri[2] = wxPoint(-4, -18) * AIS_scale_factor;
1643 dc.StrokePolygon(3, tri, TargetPoint.x, TargetPoint.y);
1644 break;
1645 }
1646 case AGROUND: {
1647 dc.StrokeCircle(TargetPoint.x, TargetPoint.y, 4 * AIS_scale_factor);
1648 dc.StrokeCircle(TargetPoint.x, TargetPoint.y - 9,
1649 4 * AIS_scale_factor);
1650 dc.StrokeCircle(TargetPoint.x, TargetPoint.y - 18,
1651 4 * AIS_scale_factor);
1652 break;
1653 }
1654 case HSC:
1655 case WIG: {
1656 dc.SetBrush(target_brush);
1657
1658 wxPoint arrow1[3] = {wxPoint(-4, 20) * AIS_scale_factor,
1659 wxPoint(0, 27) * AIS_scale_factor,
1660 wxPoint(4, 20) * AIS_scale_factor};
1661 transrot_pts(3, arrow1, sin_theta, cos_theta, TargetPoint);
1662 dc.StrokePolygon(3, arrow1);
1663
1664 wxPoint arrow2[3] = {wxPoint(-4, 27) * AIS_scale_factor,
1665 wxPoint(0, 34) * AIS_scale_factor,
1666 wxPoint(4, 27) * AIS_scale_factor};
1667 transrot_pts(3, arrow2, sin_theta, cos_theta, TargetPoint);
1668 dc.StrokePolygon(3, arrow2);
1669 break;
1670 }
1671 }
1672 } // end if (targetscale > 75)
1673
1674 // Draw the inactive cross-out line
1675 if (!td->b_active) {
1676 wxPoint p1 = transrot(wxPoint((int)-14 * targetscale / 100, 0), sin_theta,
1677 cos_theta, TargetPoint);
1678 wxPoint p2 = transrot(wxPoint((int)14 * targetscale / 100, 0), sin_theta,
1679 cos_theta, TargetPoint);
1680
1681 dc.SetPen(wxPen(UBLCK, 2));
1682 dc.StrokeLine(p1.x, p1.y, p2.x, p2.y);
1683 }
1684
1685 // European Inland AIS define a "stbd-stbd" meeting sign, a blue paddle.
1686 // Symbolize it if set by most recent message
1687 // Blue paddel is used while "not engaged"(1) or "engaged"(2) (3 ==
1688 // "reserved")
1689 if (td->blue_paddle && td->blue_paddle < 3) {
1690 wxPoint ais_flag_icon[4];
1691 int penWidth = 2;
1692
1693 if (g_bInlandEcdis) {
1694 if (b_hdgValid) {
1695 ais_flag_icon[0] = wxPoint(-4, 4);
1696 ais_flag_icon[1] = wxPoint(-4, 11);
1697 ais_flag_icon[2] = wxPoint(-11, 11);
1698 ais_flag_icon[3] = wxPoint(-11, 4);
1699 transrot_pts(4, ais_flag_icon, sin_theta, cos_theta, TargetPoint);
1700 } else {
1701 ais_flag_icon[0] = wxPoint(TargetPoint.x - 4, TargetPoint.y + 4);
1702 ais_flag_icon[1] = wxPoint(TargetPoint.x - 4, TargetPoint.y - 3);
1703 ais_flag_icon[2] = wxPoint(TargetPoint.x + 3, TargetPoint.y - 3);
1704 ais_flag_icon[3] = wxPoint(TargetPoint.x + 3, TargetPoint.y + 4);
1705 }
1706
1707 dc.SetPen(wxPen(GetGlobalColor("CHWHT"), penWidth));
1708
1709 } else {
1710 ais_flag_icon[0] =
1711 wxPoint((int)-8 * targetscale / 100, (int)-6 * targetscale / 100);
1712 ais_flag_icon[1] =
1713 wxPoint((int)-2 * targetscale / 100, (int)18 * targetscale / 100);
1714 ais_flag_icon[2] = wxPoint((int)-2 * targetscale / 100, 0);
1715 ais_flag_icon[3] =
1716 wxPoint((int)-2 * targetscale / 100, (int)-6 * targetscale / 100);
1717 transrot_pts(4, ais_flag_icon, sin_theta, cos_theta, TargetPoint);
1718
1719 if (targetscale < 100) penWidth = 1;
1720 dc.SetPen(wxPen(GetGlobalColor("CHWHT"), penWidth));
1721 }
1722 if (td->blue_paddle == 1) {
1723 ais_flag_icon[1] = ais_flag_icon[0];
1724 ais_flag_icon[2] = ais_flag_icon[3];
1725 }
1726
1727 dc.SetBrush(wxBrush(GetGlobalColor("UINFB")));
1728 dc.StrokePolygon(4, ais_flag_icon);
1729 }
1730 }
1731
1732 if ((g_bShowAISName) && (targetscale > 75)) {
1733 int true_scale_display = (int)(floor(vp.chart_scale / 100.) * 100);
1734 if (true_scale_display <
1735 g_Show_Target_Name_Scale) { // from which scale to display name
1736
1737 wxString tgt_name = td->GetFullName();
1738 tgt_name = tgt_name.substr(0, tgt_name.find("Unknown", 0));
1739
1740 if (tgt_name != wxEmptyString) {
1741 dc.SetFont(*AIS_NameFont);
1742 dc.SetTextForeground(FontMgr::Get().GetFontColor(_("AIS Target Name")));
1743
1744 int w, h;
1745 dc.GetTextExtent("W", &w, &h);
1746 h *= g_Platform->GetDisplayDIPMult(wxTheApp->GetTopWindow());
1747 w *= g_Platform->GetDisplayDIPMult(wxTheApp->GetTopWindow());
1748
1749 if ((td->COG > 90) && (td->COG < 180))
1750 dc.DrawText(tgt_name, TargetPoint.x + w, TargetPoint.y - h);
1751 else
1752 dc.DrawText(tgt_name, TargetPoint.x + w,
1753 TargetPoint.y /*+ (0.5 * h)*/);
1754
1755 } // If name do not empty
1756 } // if scale
1757 }
1758
1759 // Draw tracks if enabled
1760 // Check the Special MMSI Properties array
1761 bool b_noshow = false;
1762 bool b_forceshow = false;
1763 for (unsigned int i = 0; i < g_MMSI_Props_Array.GetCount(); i++) {
1764 if (td->MMSI == g_MMSI_Props_Array[i]->MMSI) {
1766 if (TRACKTYPE_NEVER == props->TrackType) {
1767 b_noshow = true;
1768 break;
1769 } else if (TRACKTYPE_ALWAYS == props->TrackType) {
1770 b_forceshow = true;
1771 break;
1772 } else
1773 break;
1774 }
1775 }
1776
1777 int TrackLength = td->m_ptrack.size();
1778 if (((!b_noshow && td->b_show_track) || b_forceshow) && (TrackLength > 1)) {
1779 // create vector of x-y points
1780 int TrackPointCount;
1781 wxPoint *TrackPoints = 0;
1782 TrackPoints = new wxPoint[TrackLength];
1783 auto it = td->m_ptrack.begin();
1784 for (TrackPointCount = 0;
1785 it != td->m_ptrack.end() && (TrackPointCount < TrackLength);
1786 TrackPointCount++, ++it) {
1787 const AISTargetTrackPoint &ptrack_point = *it;
1788 GetCanvasPointPix(vp, cp, ptrack_point.m_lat, ptrack_point.m_lon,
1789 &TrackPoints[TrackPointCount]);
1790 }
1791
1792 wxColour c = GetGlobalColor("CHMGD");
1793 dc.SetPen(wxPen(c, 1.5 * AIS_nominal_line_width_pix));
1794
1795 // Check for any persistently tracked target
1796 // Render persistently tracked targets slightly differently.
1797 std::map<int, Track *>::iterator itt;
1798 itt = g_pAIS->m_persistent_tracks.find(td->MMSI);
1799 if (itt != g_pAIS->m_persistent_tracks.end()) {
1800 auto *ptrack = itt->second;
1801 if (ptrack->m_Colour == wxEmptyString) {
1802 c = GetGlobalColor("TEAL1");
1803 dc.SetPen(wxPen(c, 2.0 * AIS_nominal_line_width_pix));
1804 } else {
1805 for (unsigned int i = 0;
1806 i < sizeof(::GpxxColorNames) / sizeof(wxString); i++) {
1807 if (ptrack->m_Colour == ::GpxxColorNames[i]) {
1808 c = ::GpxxColors[i];
1809 dc.SetPen(wxPen(c, 2.0 * AIS_nominal_line_width_pix));
1810 break;
1811 }
1812 }
1813 }
1814 }
1815
1816#ifdef ocpnUSE_GL
1817#if !defined(USE_ANDROID_GLES2) && !defined(ocpnUSE_GLSL)
1818
1819 if (!dc.GetDC()) {
1820 glLineWidth(2);
1821 glColor3ub(c.Red(), c.Green(), c.Blue());
1822 glBegin(GL_LINE_STRIP);
1823
1824 for (TrackPointCount = 0; TrackPointCount < TrackLength;
1825 TrackPointCount++)
1826 glVertex2i(TrackPoints[TrackPointCount].x,
1827 TrackPoints[TrackPointCount].y);
1828
1829 glEnd();
1830 } else {
1831 dc.DrawLines(TrackPointCount, TrackPoints);
1832 }
1833#else
1834 dc.DrawLines(TrackPointCount, TrackPoints);
1835#endif
1836
1837#else
1838 if (dc.GetDC()) dc.StrokeLines(TrackPointCount, TrackPoints);
1839
1840#endif
1841
1842 delete[] TrackPoints;
1843
1844 } // Draw tracks
1845}
1846
1847void AISDraw(ocpnDC &dc, ViewPort &vp, ChartCanvas *cp) {
1848 if (!g_pAIS) return;
1849
1850 // Toggling AIS display on and off
1851 if (cp != NULL) {
1852 if (!cp->GetShowAIS()) return;
1853 }
1854
1855 AISSetMetrics();
1856
1857 const auto &current_targets = g_pAIS->GetTargetList();
1858
1859 // Iterate over the AIS Target Hashmap but only for the main chartcanvas.
1860 // For secundairy canvasses we use the same value for the AIS importance
1861 bool go = false;
1862
1863 if (cp == NULL) {
1864 go = true;
1865 } else if (cp->m_canvasIndex == 0) {
1866 go = true;
1867 }
1868
1869 if (go) {
1870 for (const auto &it : current_targets) {
1871 // calculate the importancefactor for each target
1872 auto td = it.second;
1873 double So, Cpa, Rang, Siz = 0.0;
1874 So = g_ScaledNumWeightSOG / 12 *
1875 td->SOG; // 0 - 12 knts gives 0 - g_ScaledNumWeightSOG weight
1876 if (So > g_ScaledNumWeightSOG) So = g_ScaledNumWeightSOG;
1877
1878 if (td->bCPA_Valid) {
1879 Cpa = g_ScaledNumWeightCPA - g_ScaledNumWeightCPA / 4 * td->CPA;
1880 // if TCPA is positief (target is coming closer), make weight of CPA
1881 // bigger
1882 if (td->TCPA > .0) Cpa = Cpa + Cpa * g_ScaledNumWeightTCPA / 100;
1883 if (Cpa < .0) Cpa = .0; // if CPA is > 4
1884 } else
1885 Cpa = .0;
1886
1887 Rang = g_ScaledNumWeightRange / 10 * td->Range_NM;
1888 if (Rang > g_ScaledNumWeightRange) Rang = g_ScaledNumWeightRange;
1889 Rang = g_ScaledNumWeightRange - Rang;
1890
1891 Siz = g_ScaledNumWeightSizeOfT / 30 * (td->DimA + td->DimB);
1892 if (Siz > g_ScaledNumWeightSizeOfT) Siz = g_ScaledNumWeightSizeOfT;
1893 td->importance = (float)So + Cpa + Rang + Siz;
1894 }
1895 }
1896
1897 // If needed iterate over all targets, check if they fit in the viewport and
1898 // if yes add the importancefactor to a sorted list
1899 AISImportanceSwitchPoint = 0.0;
1900
1901 float *Array = new float[g_ShowScaled_Num];
1902 for (int i = 0; i < g_ShowScaled_Num; i++) Array[i] = 0.0;
1903
1904 int LowestInd = 0;
1905 if (cp != NULL) {
1906 if (cp->GetAttenAIS()) {
1907 for (const auto &it : current_targets) {
1908 auto td = it.second;
1909 if (vp.GetBBox().Contains(td->Lat, td->Lon)) {
1910 if (td->importance > AISImportanceSwitchPoint) {
1911 Array[LowestInd] = td->importance;
1912
1913 AISImportanceSwitchPoint = Array[0];
1914 LowestInd = 0;
1915 for (int i = 1; i < g_ShowScaled_Num; i++) {
1916 if (Array[i] < AISImportanceSwitchPoint) {
1917 AISImportanceSwitchPoint = Array[i];
1918 LowestInd = i;
1919 }
1920 }
1921 }
1922 }
1923 }
1924 }
1925 }
1926 delete[] Array;
1927
1928 // Draw all targets in three pass loop, sorted on SOG, GPSGate & DSC on
1929 // top This way, fast targets are not obscured by slow/stationary targets
1930 for (const auto &it : current_targets) {
1931 auto td = it.second;
1932 if ((td->SOG < g_SOGminCOG_kts) &&
1933 !((td->Class == AIS_GPSG_BUDDY) || (td->Class == AIS_DSC))) {
1934 AISDrawTarget(td.get(), dc, vp, cp);
1935 }
1936 }
1937
1938 for (const auto &it : current_targets) {
1939 auto td = it.second;
1940 if ((td->SOG >= g_SOGminCOG_kts) &&
1941 !((td->Class == AIS_GPSG_BUDDY) || (td->Class == AIS_DSC))) {
1942 AISDrawTarget(td.get(), dc, vp,
1943 cp); // yes this is a doubling of code;(
1944 if (td->importance > 0) AISDrawTarget(td.get(), dc, vp, cp);
1945 }
1946 }
1947
1948 for (const auto &it : current_targets) {
1949 auto td = it.second;
1950 if ((td->Class == AIS_GPSG_BUDDY) || (td->Class == AIS_DSC))
1951 AISDrawTarget(td.get(), dc, vp, cp);
1952 }
1953}
1954
1955bool AnyAISTargetsOnscreen(ChartCanvas *cc, ViewPort &vp) {
1956 if (!g_pAIS) return false;
1957
1958 if (!cc->GetShowAIS()) return false; //
1959
1960 // Iterate over the AIS Target Hashmap
1961 for (const auto &it : g_pAIS->GetTargetList()) {
1962 auto td = it.second;
1963 if (vp.GetBBox().Contains(td->Lat, td->Lon)) return true; // yep
1964 }
1965
1966 return false;
1967}
ArrayOfMmsiProperties g_MMSI_Props_Array
Global instance.
AisDecoder * g_pAIS
Global instance.
Class AisDecoder and helpers.
Global state for AIS decoder.
Class AISTargetAlertDialog and helpers.
AIS target definitions.
Class AISTargetQueryDialog.
Generic Chart canvas base.
Dialog for displaying AIS target alerts.
Dialog for querying detailed information about an AIS target.
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:174
bool GetCanvasPointPix(double rlat, double rlon, wxPoint *r)
Convert latitude/longitude to canvas pixel coordinates (physical pixels) rounded to nearest integer.
Definition chcanv.cpp:4607
Process incoming AIS messages.
Definition ais_decoder.h:76
Provides platform-specific support utilities for OpenCPN.
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:56
double view_scale_ppm
Requested view scale in physical pixels per meter (ppm), before applying projections.
Definition viewport.h:204
int pix_height
Height of the viewport in physical pixels.
Definition viewport.h:233
double rotation
Rotation angle of the viewport in radians.
Definition viewport.h:214
int pix_width
Width of the viewport in physical pixels.
Definition viewport.h:231
wxPoint2DDouble GetDoublePixFromLL(double lat, double lon)
Convert latitude and longitude on the ViewPort to physical pixel coordinates with double precision.
Definition viewport.cpp:133
wxPoint GetPixFromLL(double lat, double lon)
Convert latitude and longitude on the ViewPort to physical pixel coordinates.
Definition viewport.cpp:124
double chart_scale
Chart scale denominator (e.g., 50000 for a 1:50000 scale).
Definition viewport.h:219
Device context class that can use either wxDC or OpenGL for drawing.
Definition ocpndc.h:60
void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, bool b_hiqual=true)
Draw a line between two points using either wxDC or OpenGL.
Definition ocpndc.cpp:473
Global color handling by name.
Extern C linked utilities.
Font list manager.
OpenCPN Georef utility.
Platform independent GL includes.
double g_current_monitor_dip_px_ratio
ratio to convert between DIP and physical pixels.
Definition gui_vars.cpp:69
Miscellaneous globals primarely used by gui layer, not persisted in configuration file.
Utility functions.
OpenCPN Platform specific support utilities.
PlugIn Object Definition/API.
wxFont * FindOrCreateFont_PlugIn(int point_size, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underline, const wxString &facename, wxFontEncoding encoding)
Creates or finds a font in the font cache.
double gLat
Vessel's current latitude in decimal degrees.
Definition own_ship.cpp:26
double gCog
Course over ground in degrees (0-359.99).
Definition own_ship.cpp:28
double gSog
Speed over ground in knots.
Definition own_ship.cpp:29
double gLon
Vessel's current longitude in decimal degrees.
Definition own_ship.cpp:27
Position, course, speed, etc.
Selected route, segment, waypoint, etc.
Chart Symbols.
Abstract gFrame/MyFrame interface.