OpenCPN Partial API docs
Loading...
Searching...
No Matches
api_121.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2024 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, write to the *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
24#include <algorithm>
25#include <map>
26#include <memory>
27#include <string>
28#include <vector>
29
30#include <wx/wx.h>
31#include <wx/event.h>
32#include <wx/string.h>
33#include <wx/window.h>
34
35#include "model/ais_decoder.h"
37#include "model/gui_events.h"
38#include "model/gui_vars.h"
39#include "model/navobj_db.h"
41#include "model/own_ship.h"
42#include "model/route.h"
43#include "model/routeman.h"
44#include "model/track.h"
45
46#include "chcanv.h"
47#include "ocpn_plugin.h"
48
49extern arrayofCanvasPtr g_canvasArray; // FIXME (leamas) find new home
50
51// translate O route class to PlugIn_Waypoint_ExV2
52static void PlugInExV2FromRoutePoint(PlugIn_Waypoint_ExV2* dst,
53 /* const*/ RoutePoint* src) {
54 dst->m_lat = src->m_lat;
55 dst->m_lon = src->m_lon;
56 dst->IconName = src->GetIconName();
57 dst->m_MarkName = src->GetName();
58 dst->m_MarkDescription = src->GetDescription();
59 dst->IconDescription = pWayPointMan->GetIconDescription(src->GetIconName());
60 dst->IsVisible = src->IsVisible();
61 dst->m_CreateTime = src->GetCreateTime(); // not const
62 dst->m_GUID = src->m_GUID;
63
64 // Transcribe (clone) the html HyperLink List, if present
65 if (src->m_HyperlinkList) {
66 delete dst->m_HyperlinkList;
67 dst->m_HyperlinkList = nullptr;
68
69 if (src->m_HyperlinkList->size() > 0) {
70 dst->m_HyperlinkList = new Plugin_HyperlinkList;
71
72 for (Hyperlink* link : *src->m_HyperlinkList) {
74 h->DescrText = link->DescrText;
75 h->Link = link->Link;
76 h->Type = link->LType;
77 dst->m_HyperlinkList->Append(h);
78 }
79 }
80 }
81
82 // Get the range ring info
87 dst->m_TideStation = src->m_TideStation;
88
89 // Get other extended info
90 dst->IsNameVisible = src->m_bShowName;
91 dst->scamin = src->GetScaMin();
92 dst->b_useScamin = src->GetUseSca();
93 dst->IsActive = src->m_bIsActive;
94
95 dst->scamax = src->GetScaMax();
96 dst->m_PlannedSpeed = src->GetPlannedSpeed();
97 dst->m_ETD = src->GetManualETD();
98 dst->m_WaypointArrivalRadius = src->GetWaypointArrivalRadius();
99 dst->m_bShowWaypointRangeRings = src->GetShowWaypointRangeRings();
100}
101
102static void cloneHyperlinkListExV2(RoutePoint* dst,
103 const PlugIn_Waypoint_ExV2* src) {
104 // Transcribe (clone) the html HyperLink List, if present
105 if (src->m_HyperlinkList == nullptr) return;
106
107 if (src->m_HyperlinkList->GetCount() > 0) {
108 wxPlugin_HyperlinkListNode* linknode = src->m_HyperlinkList->GetFirst();
109 while (linknode) {
110 Plugin_Hyperlink* link = linknode->GetData();
111
112 Hyperlink* h = new Hyperlink();
113 h->DescrText = link->DescrText;
114 h->Link = link->Link;
115 h->LType = link->Type;
116
117 dst->m_HyperlinkList->push_back(h);
118
119 linknode = linknode->GetNext();
120 }
121 }
122}
123
124static RoutePoint* CreateNewPoint(const PlugIn_Waypoint_ExV2* src,
125 bool b_permanent) {
126 RoutePoint* pWP = new RoutePoint(src->m_lat, src->m_lon, src->IconName,
127 src->m_MarkName, src->m_GUID);
128
129 pWP->m_bIsolatedMark = true; // This is an isolated mark
130
131 cloneHyperlinkListExV2(pWP, src);
132
134
135 if (src->m_CreateTime.IsValid())
136 pWP->SetCreateTime(src->m_CreateTime);
137 else {
138 pWP->SetCreateTime(wxDateTime::Now().ToUTC());
139 }
140
141 pWP->m_btemp = (b_permanent == false);
142
143 // Extended fields
144 pWP->SetIconName(src->IconName);
145 pWP->SetWaypointRangeRingsNumber(src->nrange_rings);
146 pWP->SetWaypointRangeRingsStep(src->RangeRingSpace);
147 pWP->SetWaypointRangeRingsStepUnits(src->RangeRingSpaceUnits);
148 pWP->SetWaypointRangeRingsColour(src->RangeRingColor);
149 pWP->SetTideStation(src->m_TideStation);
150 pWP->SetScaMin(src->scamin);
151 pWP->SetUseSca(src->b_useScamin);
152 pWP->SetNameShown(src->IsNameVisible);
153 pWP->SetVisible(src->IsVisible);
154
155 pWP->SetWaypointArrivalRadius(src->m_WaypointArrivalRadius);
156 pWP->SetShowWaypointRangeRings(src->m_bShowWaypointRangeRings);
157 pWP->SetScaMax(src->scamax);
158 pWP->SetPlannedSpeed(src->m_PlannedSpeed);
159 if (src->m_ETD.IsValid())
160 pWP->SetETD(src->m_ETD);
161 else
162 pWP->SetETD(wxEmptyString);
163 return pWP;
164}
165
166static bool AddPlugInRouteExV3(HostApi121::Route* proute, bool b_permanent) {
167 ::Route* route = new ::Route();
168
169 PlugIn_Waypoint_ExV2* pwaypointex;
170 RoutePoint *pWP, *pWP_src;
171 int ip = 0;
172 wxDateTime plannedDeparture;
173
174 wxPlugin_WaypointExV2ListNode* pwpnode = proute->pWaypointList->GetFirst();
175 while (pwpnode) {
176 pwaypointex = pwpnode->GetData();
177
178 pWP = pWayPointMan->FindRoutePointByGUID(pwaypointex->m_GUID);
179 if (!pWP) {
180 pWP = CreateNewPoint(pwaypointex, b_permanent);
181 pWP->m_bIsolatedMark = false;
182 }
183
184 route->AddPoint(pWP);
185
186 pSelect->AddSelectableRoutePoint(pWP->m_lat, pWP->m_lon, pWP);
187
188 if (ip > 0)
189 pSelect->AddSelectableRouteSegment(pWP_src->m_lat, pWP_src->m_lon,
190 pWP->m_lat, pWP->m_lon, pWP_src, pWP,
191 route);
192
193 plannedDeparture = pwaypointex->m_CreateTime;
194 ip++;
195 pWP_src = pWP;
196
197 pwpnode = pwpnode->GetNext(); // PlugInWaypoint
198 }
199
200 route->m_PlannedDeparture = plannedDeparture;
201
202 route->m_RouteNameString = proute->m_NameString;
203 route->m_RouteStartString = proute->m_StartString;
204 route->m_RouteEndString = proute->m_EndString;
205 if (!proute->m_GUID.IsEmpty()) {
206 route->m_GUID = proute->m_GUID;
207 }
208 route->m_btemp = (b_permanent == false);
209 route->SetVisible(proute->m_isVisible);
210 route->m_RouteDescription = proute->m_Description;
211
212 route->m_PlannedSpeed = proute->m_PlannedSpeed;
213 route->m_Colour = proute->m_Colour;
214 route->m_style = proute->m_style;
215 route->m_PlannedDeparture = proute->m_PlannedDeparture;
216 route->m_TimeDisplayFormat = proute->m_TimeDisplayFormat;
217
218 pRouteList->push_back(route);
219
220 if (b_permanent) {
221 // pConfig->AddNewRoute(route);
222 NavObj_dB::GetInstance().InsertRoute(route);
223 }
224
226
227 return true;
228}
229
230static bool UpdatePlugInRouteExV3(HostApi121::Route* proute) {
231 bool b_found = false;
232
233 // Find the Route
234 Route* pRoute = g_pRouteMan->FindRouteByGUID(proute->m_GUID);
235 if (pRoute) b_found = true;
236
237 if (b_found) {
238 bool b_permanent = !pRoute->m_btemp;
239 g_pRouteMan->DeleteRoute(pRoute);
240
241 b_found = AddPlugInRouteExV3(proute, b_permanent);
242 }
243
244 return b_found;
245}
246
247// translate O route class to PlugIn_Waypoint_Ex
248static void PlugInExFromRoutePoint(PlugIn_Waypoint_Ex* dst,
249 /* const*/ RoutePoint* src) {
250 dst->m_lat = src->m_lat;
251 dst->m_lon = src->m_lon;
252 dst->IconName = src->GetIconName();
253 dst->m_MarkName = src->GetName();
254 dst->m_MarkDescription = src->GetDescription();
255 dst->IconDescription = pWayPointMan->GetIconDescription(src->GetIconName());
256 dst->IsVisible = src->IsVisible();
257 dst->m_CreateTime = src->GetCreateTime(); // not const
258 dst->m_GUID = src->m_GUID;
259
260 // Transcribe (clone) the html HyperLink List, if present
261 if (src->m_HyperlinkList) {
262 delete dst->m_HyperlinkList;
263 dst->m_HyperlinkList = nullptr;
264
265 if (src->m_HyperlinkList->size() > 0) {
266 dst->m_HyperlinkList = new Plugin_HyperlinkList;
267 for (Hyperlink* link : *src->m_HyperlinkList) {
269 h->DescrText = link->DescrText;
270 h->Link = link->Link;
271 h->Type = link->LType;
272 dst->m_HyperlinkList->Append(h);
273 }
274 }
275 }
276
277 // Get the range ring info
281
282 // Get other extended info
283 dst->IsNameVisible = src->m_bShowName;
284 dst->scamin = src->GetScaMin();
285 dst->b_useScamin = src->GetUseSca();
286 dst->IsActive = src->m_bIsActive;
287}
288
289static void cloneHyperlinkListEx(RoutePoint* dst,
290 const PlugIn_Waypoint_Ex* src) {
291 // Transcribe (clone) the html HyperLink List, if present
292 if (src->m_HyperlinkList == nullptr) return;
293
294 if (src->m_HyperlinkList->GetCount() > 0) {
295 wxPlugin_HyperlinkListNode* linknode = src->m_HyperlinkList->GetFirst();
296 while (linknode) {
297 Plugin_Hyperlink* link = linknode->GetData();
298
299 Hyperlink* h = new Hyperlink();
300 h->DescrText = link->DescrText;
301 h->Link = link->Link;
302 h->LType = link->Type;
303
304 dst->m_HyperlinkList->push_back(h);
305
306 linknode = linknode->GetNext();
307 }
308 }
309}
310
311static wxString DropMarkPI(double lat, double lon) {
312 if ((fabs(lat) > 80.0) || (fabs(lon) > 180.)) return "";
313
314 RoutePoint* pWP =
315 new RoutePoint(lat, lon, g_default_wp_icon, wxEmptyString, wxEmptyString);
316 pWP->m_bIsolatedMark = true; // This is an isolated mark
317 pSelect->AddSelectableRoutePoint(lat, lon, pWP);
318 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
319 return pWP->m_GUID;
320}
321
322static wxString RouteCreatePI(int canvas_index, bool start) {
323 if ((size_t)canvas_index < g_canvasArray.GetCount()) {
324 ChartCanvas* cc = g_canvasArray.Item(canvas_index);
325 if (cc) {
326 if (start) {
327 cc->StartRoute();
328 return "0";
329 } else {
330 return cc->FinishRoute();
331 }
332 }
333 }
334 return "-1";
335}
336
337static bool DoMeasurePI(int canvas_index, bool start) {
338 if ((size_t)canvas_index < g_canvasArray.GetCount()) {
339 ChartCanvas* cc = g_canvasArray.Item(canvas_index);
340 if (cc) {
341 if (start) {
342 cc->StartMeasureRoute();
343 return true;
344 } else {
345 cc->CancelMeasureRoute();
346 cc->Refresh(false);
347 return true;
348 }
349 }
350 }
351 return false;
352}
353
354static void EnableDefaultConsole(bool enable) {
355 g_bhide_route_console = !enable;
356}
357
358static wxString NavToHerePI(double lat, double lon) {
359 RoutePoint* pWP_dest =
360 new RoutePoint(lat, lon, g_default_wp_icon, wxEmptyString, wxEmptyString);
361 pSelect->AddSelectableRoutePoint(lat, lon, pWP_dest);
362
363 RoutePoint* pWP_src = new RoutePoint(gLat, gLon, g_default_wp_icon,
364 wxEmptyString, wxEmptyString);
365 pSelect->AddSelectableRoutePoint(gLat, gLon, pWP_src);
366
367 Route* temp_route = new Route();
368 pRouteList->push_back(temp_route);
369
370 temp_route->AddPoint(pWP_src);
371 temp_route->AddPoint(pWP_dest);
372
373 pSelect->AddSelectableRouteSegment(gLat, gLon, lat, lon, pWP_src, pWP_dest,
374 temp_route);
375
376 temp_route->m_RouteNameString = _("Temporary GOTO Route");
377 temp_route->m_RouteStartString = _("Here");
378 temp_route->m_RouteEndString = _("There");
379 temp_route->m_bDeleteOnArrival = true;
380
381 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
382
383 g_pRouteMan->ActivateRoute(temp_route, pWP_dest);
384 return temp_route->m_GUID;
385}
386
387static bool ActivateRoutePI(wxString route_guid, bool activate) {
388 Route* route = g_pRouteMan->FindRouteByGUID(route_guid);
389 if (!route) return false;
390
391 if (activate) {
392 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
393 RoutePoint* best_point =
394 g_pRouteMan->FindBestActivatePoint(route, gLat, gLon, gCog, gSog);
395 g_pRouteMan->ActivateRoute(route, best_point);
396 route->m_bRtIsSelected = false;
397 return true;
398 } else {
399 g_pRouteMan->DeactivateRoute();
400 route->m_bRtIsSelected = false;
401 return true;
402 }
403 return false;
404}
405
406static void SetMaxZoomScale(double max_scale) {
407 g_maxzoomin = wxRound(wxMax(max_scale, 100.));
408}
409
410static void EnableDefaultContextMenus(bool enable) {
411 g_bhide_context_menus = !enable;
412}
413
414static void SetMinZoomScale(double min_scale) {
415 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
416 ChartCanvas* cc = g_canvasArray.Item(i);
417 cc->SetAbsoluteMinScale(min_scale);
418 }
419}
420
421static std::shared_ptr<HostApi121::PiPointContext> GetContextAtPoint(
422 int x, int y, int canvas_index) {
423 ChartCanvas* cc = g_canvasArray.Item(canvas_index);
424 if (cc) {
425 return cc->GetCanvasContextAtPoint(x, y);
426 } else {
427 auto rstruct = std::make_shared<HostApi121::PiPointContext>();
428 rstruct->object_type = HostApi121::PiContextObjectType::kObjectUnknown;
429 rstruct->object_ident = "";
430 return rstruct;
431 }
432}
433
434static wxBitmap GetObjectIcon_PlugIn(const wxString& name) {
435 if (pWayPointMan)
436 return *pWayPointMan->GetIconBitmap(name);
437 else
438 return wxNullBitmap;
439}
440
441static bool IsRouteActive(wxString route_guid) {
442 if (g_pRouteMan->GetpActiveRoute())
443 return (route_guid.IsSameAs(g_pRouteMan->GetpActiveRoute()->m_GUID));
444 else
445 return false;
446}
447
448static void SetBoatPosition(double zlat, double zlon) {
449 gLat = zlat;
450 gLon = zlon;
451 GuiEvents::GetInstance().gframe_update_status_bar.Notify();
452}
453
454static void RouteInsertWaypoint(int canvas_index, wxString route_guid,
455 double zlat, double zlon) {
456 ChartCanvas* parent =
457 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
458 if (!parent) return;
459
460 Route* route = g_pRouteMan->FindRouteByGUID(route_guid);
461 if (!route) return;
462
463 if (route->m_bIsInLayer) return;
464
465 int seltype = parent->PrepareContextSelections(zlat, zlon);
466 if ((seltype & SELTYPE_ROUTESEGMENT) != SELTYPE_ROUTESEGMENT) return;
467
468 bool rename = false;
469 route->InsertPointAfter(parent->GetFoundRoutepoint(), zlat, zlon, rename);
470
471 pSelect->DeleteAllSelectableRoutePoints(route);
472 pSelect->DeleteAllSelectableRouteSegments(route);
473 pSelect->AddAllSelectableRouteSegments(route);
474 pSelect->AddAllSelectableRoutePoints(route);
475
476 NavObj_dB::GetInstance().UpdateRoute(route);
477}
478
479static void RouteAppendWaypoint(int canvas_index, wxString route_guid) {
480 Route* route = g_pRouteMan->FindRouteByGUID(route_guid);
481 if (!route) return;
482
483 ChartCanvas* parent =
484 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
485 if (!parent) return;
486
487 parent->m_pMouseRoute = route;
488 parent->m_routeState = route->GetnPoints() + 1;
489 parent->m_pMouseRoute->m_lastMousePointIndex = route->GetnPoints();
490 parent->m_pMouseRoute->SetHiLite(50);
491
492 auto pLast = route->GetLastPoint();
493
494 parent->m_prev_rlat = pLast->m_lat;
495 parent->m_prev_rlon = pLast->m_lon;
496 parent->m_prev_pMousePoint = pLast;
497
498 parent->m_bAppendingRoute = true;
499}
500
501static void FinishRoute(int canvas_index) {
502 ChartCanvas* parent =
503 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
504 if (!parent) return;
505
506 parent->FinishRoute();
507}
508
509static bool IsRouteBeingCreated(int canvas_index) {
510 ChartCanvas* parent =
511 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
512 if (!parent) return false;
513 return !(parent->m_pMouseRoute == NULL);
514}
515
516static bool AreRouteWaypointNamesVisible(wxString route_guid) {
517 Route* route = g_pRouteMan->FindRouteByGUID(route_guid);
518 if (!route) return false;
519 return route->AreWaypointNamesVisible();
520}
521
522static void ShowRouteWaypointNames(wxString route_guid, bool show) {
523 Route* route = g_pRouteMan->FindRouteByGUID(route_guid);
524 if (!route) return;
525 route->ShowWaypointNames(show);
526}
527
528static void NavigateToWaypoint(wxString waypoint_guid) {
529 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(waypoint_guid);
530 if (!prp) return;
531
532 RoutePoint* pWP_src = new RoutePoint(gLat, gLon, g_default_wp_icon,
533 wxEmptyString, wxEmptyString);
534 pSelect->AddSelectableRoutePoint(gLat, gLon, pWP_src);
535
536 Route* temp_route = new Route();
537 pRouteList->push_back(temp_route);
538
539 temp_route->AddPoint(pWP_src);
540 temp_route->AddPoint(prp);
541 prp->SetShared(true);
542
543 pSelect->AddSelectableRouteSegment(gLat, gLon, prp->m_lat, prp->m_lon,
544 pWP_src, prp, temp_route);
545
546 wxString name = prp->GetName();
547 if (name.IsEmpty()) name = _("(Unnamed Waypoint)");
548 wxString rteName = _("Go to ");
549 rteName.Append(name);
550 temp_route->m_RouteNameString = rteName;
551 temp_route->m_RouteStartString = _("Here");
552 temp_route->m_RouteEndString = name;
553 temp_route->m_bDeleteOnArrival = true;
554
555 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
556 g_pRouteMan->ActivateRoute(temp_route, prp);
557}
558
559// AIS related
560static bool IsAISTrackVisible(wxString ais_mmsi) {
561 long mmsi = 0;
562 ais_mmsi.ToLong(&mmsi);
563 auto myptarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
564 if (myptarget)
565 return myptarget->b_show_track;
566 else
567 return false;
568}
569
570static void AISToggleShowTrack(wxString ais_mmsi) {
571 long mmsi = 0;
572 ais_mmsi.ToLong(&mmsi);
573 auto myptarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
574 if (myptarget) myptarget->ToggleShowTrack();
575}
576
577static void AISToggleShowCPA(wxString ais_mmsi) {
578 long mmsi = 0;
579 ais_mmsi.ToLong(&mmsi);
580 auto myptarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
581 if (myptarget) myptarget->Toggle_AIS_CPA();
582}
583
584static void ShowAISTargetQueryDialog(int canvas_index, wxString ais_mmsi) {
585 ChartCanvas* parent =
586 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
587 if (!parent) return;
588
589 long mmsi = 0;
590 ais_mmsi.ToLong(&mmsi);
591 ShowAISTargetQueryDialog(parent, mmsi);
592}
593
594static void ShowAISTargetList(int canvas_index) {
595 ChartCanvas* parent =
596 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
597 if (!parent) return;
598 parent->ShowAISTargetList();
599}
600
601static bool IsMeasureActive(int canvas_index) {
602 ChartCanvas* parent =
603 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
604 if (!parent) return false;
605 return parent->m_bMeasure_Active;
606}
607
608static void CancelMeasure(int canvas_index) {
609 ChartCanvas* parent =
610 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
611 if (!parent) return;
612 parent->CancelMeasureRoute();
613}
614
615static void SetDepthUnitVisible(bool bviz) { g_bhide_depth_units = !bviz; }
616
617static void SetOverzoomFlagVisible(bool bviz) { g_bhide_overzoom_flag = !bviz; }
618
619// Extended Chart table management support
620static void AddNoShowDirectory(std::string chart_dir) {
621 ChartDirectoryExcludedVector.push_back(chart_dir);
622}
623
624static void RemoveNoShowDirectory(std::string chart_dir) {
625 auto it = std::find(ChartDirectoryExcludedVector.begin(),
626 ChartDirectoryExcludedVector.end(), chart_dir);
627 if (it != ChartDirectoryExcludedVector.end())
628 ChartDirectoryExcludedVector.erase(it); // Erase the element
629}
630
631static void ClearNoShowVector() { ChartDirectoryExcludedVector.clear(); }
632
633static const std::vector<std::string>& GetNoShowVector() {
635}
636
637static bool SelectChartFamily(int CanvasIndex, ChartFamilyEnumPI Family) {
638 auto window = GetCanvasByIndex(CanvasIndex);
639 auto oCanvas = dynamic_cast<ChartCanvas*>(window);
640 if (oCanvas) {
641 double scale = oCanvas->GetVP().view_scale_ppm;
642 int newref =
643 oCanvas->m_pQuilt->SelectRefChartByFamily((ChartFamilyEnum)Family);
644 if (newref >= 0) {
645 oCanvas->SelectQuiltRefdbChart(newref);
646 oCanvas->SetVPScale(scale);
647 oCanvas->DoCanvasUpdate();
648 oCanvas->ReloadVP(); // Pick up the new selections
649 return true;
650 }
651 }
652 return false;
653}
654
655static void CenterToAisTarget(wxString ais_mmsi) {
656 long mmsi = 0;
657 if (ais_mmsi.ToLong(&mmsi)) {
658 std::shared_ptr<AisTargetData> pAISTarget = nullptr;
659 if (g_pAIS) pAISTarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
660
661 if (pAISTarget)
662 GuiEvents::GetInstance().on_center_ais_target.Notify(pAISTarget);
663 }
664} // same as AISTargetListDialog::CenterToTarget ( false )
665
666static void AisTargetCreateWpt(wxString ais_mmsi) {
667 long mmsi = 0;
668 if (ais_mmsi.ToLong(&mmsi)) {
669 std::shared_ptr<AisTargetData> pAISTarget = NULL;
670 if (g_pAIS) pAISTarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
671
672 if (pAISTarget) {
673 RoutePoint* pWP =
674 new RoutePoint(pAISTarget->Lat, pAISTarget->Lon, g_default_wp_icon,
675 wxEmptyString, wxEmptyString);
676 pWP->m_bIsolatedMark = true; // This is an isolated mark
677 pSelect->AddSelectableRoutePoint(pAISTarget->Lat, pAISTarget->Lon, pWP);
678 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
679
681 }
682 }
683} // same as AISTargetListDialog::OnTargetCreateWpt
684
685static void AisShowAllTracks(bool show) {
686 if (g_pAIS) {
687 for (const auto& it : g_pAIS->GetTargetList()) {
688 auto pAISTarget = it.second;
689 if (NULL != pAISTarget) {
690 pAISTarget->b_show_track = show;
691
692 // Check for any persistently tracked target, force b_show_track_old
693 std::map<int, Track*>::iterator itt;
694 itt = g_pAIS->m_persistent_tracks.find(pAISTarget->MMSI);
695 if (itt != g_pAIS->m_persistent_tracks.end()) {
696 pAISTarget->b_show_track_old = show;
697 }
698 }
699 }
700 } // same as AISTargetListDialog::OnHideAllTracks /
701 // AISTargetListDialog::OnShowAllTracks
702}
703
704static void AisToggleTrack(wxString ais_mmsi) {
705 long mmsi = 0;
706 if (ais_mmsi.ToLong(&mmsi)) {
707 std::shared_ptr<AisTargetData> pAISTarget = NULL;
708 if (g_pAIS) pAISTarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
709
710 if (pAISTarget) {
711 pAISTarget->b_show_track_old =
712 pAISTarget->b_show_track; // Store current state before toggling
713 pAISTarget->b_show_track =
714 !pAISTarget->b_show_track; // Toggle visibility
715 }
716 }
717}
718
719static int GetContextMenuMask() { return g_canvas_context_menu_disable_mask; }
720
721static void SetContextMenuMask(int mask) {
722 g_canvas_context_menu_disable_mask = mask;
723}
724
725static bool IsAIS_CPAVisible(wxString ais_mmsi) {
726 long mmsi = 0;
727 ais_mmsi.ToLong(&mmsi);
728 auto myptarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
729 if (myptarget)
730 return myptarget->b_show_AIS_CPA;
731 else
732 return false;
733}
734
735static void SetTrackVisibility(const wxString& track_GUID, bool viz) {
736 for (Track* ptrack : g_TrackList) {
737 if (ptrack->m_GUID == track_GUID) {
738 ptrack->SetVisible(viz);
739 break;
740 }
741 }
742}
743
744std::unique_ptr<HostApi> GetHostApi() {
745 return std::make_unique<HostApi121>(HostApi121());
746}
747
748bool HostApi121::AddRoute(HostApi121::Route* route, bool permanent) {
749 return ::AddPlugInRouteExV3(route, permanent);
750}
751
753 return ::UpdatePlugInRouteExV3(route);
754}
755
756std::unique_ptr<HostApi121::Route> HostApi121::GetRoute(const wxString& guid) {
757 ::Route* route = g_pRouteMan->FindRouteByGUID(guid);
758 if (!route) return nullptr;
759
760 auto dst_route = std::make_unique<HostApi121::Route>();
761
762 for (RoutePoint* src_wp : *route->pRoutePointList) {
764 PlugInExV2FromRoutePoint(dst_wp, src_wp);
765 dst_route->pWaypointList->Append(dst_wp);
766 }
767 dst_route->m_NameString = route->m_RouteNameString;
768 dst_route->m_StartString = route->m_RouteStartString;
769 dst_route->m_EndString = route->m_RouteEndString;
770 dst_route->m_GUID = route->m_GUID;
771 dst_route->m_isActive = g_pRouteMan->GetpActiveRoute() == route;
772 dst_route->m_isVisible = route->IsVisible();
773 dst_route->m_Description = route->m_RouteDescription;
774 dst_route->m_PlannedSpeed = route->m_PlannedSpeed;
775 dst_route->m_Colour = route->m_Colour;
776 dst_route->m_style = route->m_style;
777 dst_route->m_PlannedDeparture = route->m_PlannedDeparture;
778 dst_route->m_TimeDisplayFormat = route->m_TimeDisplayFormat;
779
780 return dst_route;
781}
782
783wxString HostApi121::DropMarkPI(double lat, double lon) {
784 return ::DropMarkPI(lat, lon);
785}
786
787wxString HostApi121::RouteCreatePI(int canvas_index, bool start) {
788 return ::RouteCreatePI(canvas_index, start);
789}
790
791bool HostApi121::DoMeasurePI(int canvas_index, bool start) {
792 return ::DoMeasurePI(canvas_index, start);
793}
794
795wxString HostApi121::NavToHerePI(double lat, double lon) {
796 return ::NavToHerePI(lat, lon);
797}
798
799bool HostApi121::ActivateRoutePI(wxString route_guid, bool activate) {
800 return ::ActivateRoutePI(route_guid, activate);
801}
802
803void HostApi121::EnableDefaultConsole(bool enable) {
804 ::EnableDefaultConsole(enable);
805}
806
807void HostApi121::EnableDefaultContextMenus(bool enable) {
808 ::EnableDefaultContextMenus(enable);
809}
810
811void HostApi121::SetMinZoomScale(double min_scale) {
812 ::SetMinZoomScale(min_scale);
813}
814
815void HostApi121::SetMaxZoomScale(double max_scale) {
816 ::SetMaxZoomScale(max_scale);
817}
818
819std::shared_ptr<HostApi121::PiPointContext> HostApi121::GetContextAtPoint(
820 int x, int y, int canvas_index) {
821 return ::GetContextAtPoint(x, y, canvas_index);
822}
823
824wxBitmap HostApi121::GetObjectIcon_PlugIn(const wxString& name) {
825 return ::GetObjectIcon_PlugIn(name);
826}
827
828bool HostApi121::IsRouteActive(wxString route_guid) {
829 return ::IsRouteActive(route_guid);
830}
831
832void HostApi121::SetBoatPosition(double zlat, double zlon) {
833 ::SetBoatPosition(zlat, zlon);
834}
835
836void HostApi121::RouteInsertWaypoint(int canvas_index, wxString route_guid,
837 double zlat, double zlon) {
838 ::RouteInsertWaypoint(canvas_index, route_guid, zlat, zlon);
839}
840
841void HostApi121::RouteAppendWaypoint(int canvas_index, wxString route_guid) {
842 ::RouteAppendWaypoint(canvas_index, route_guid);
843}
844
845void HostApi121::FinishRoute(int canvas_index) { ::FinishRoute(canvas_index); }
846
847bool HostApi121::IsRouteBeingCreated(int canvas_index) {
848 return ::IsRouteBeingCreated(canvas_index);
849}
850
851bool HostApi121::AreRouteWaypointNamesVisible(wxString route_guid) {
852 return ::AreRouteWaypointNamesVisible(route_guid);
853}
854
855void HostApi121::ShowRouteWaypointNames(wxString route_guid, bool show) {
856 ::ShowRouteWaypointNames(route_guid, show);
857}
858
859void HostApi121::NavigateToWaypoint(wxString waypoint_guid) {
860 ::NavigateToWaypoint(waypoint_guid);
861}
862
863bool HostApi121::IsAISTrackVisible(const wxString& ais_mmsi) const {
864 return ::IsAISTrackVisible(ais_mmsi);
865}
866
867void HostApi121::AISToggleShowTrack(const wxString& ais_mmsi) {
868 ::AISToggleShowTrack(ais_mmsi);
869}
870
871bool HostApi121::IsAIS_CPAVisible(const wxString& ais_mmsi) const {
872 return ::IsAIS_CPAVisible(ais_mmsi);
873}
874
875void HostApi121::AISToggleShowCPA(const wxString& ais_mmsi) {
876 ::AISToggleShowCPA(ais_mmsi);
877}
878
879void HostApi121::ShowAISTargetQueryDialog(int canvas_index,
880 const wxString& ais_mmsi) {
881 ::ShowAISTargetQueryDialog(canvas_index, ais_mmsi);
882}
883
884void HostApi121::ShowAISTargetList(int canvas_index) {
885 ::ShowAISTargetList(canvas_index);
886}
887
888bool HostApi121::IsMeasureActive(int canvas_index) {
889 return ::IsMeasureActive(canvas_index);
890}
891
892void HostApi121::CancelMeasure(int canvas_index) {
893 ::CancelMeasure(canvas_index);
894}
895
896void HostApi121::SetDepthUnitVisible(bool bviz) { ::SetDepthUnitVisible(bviz); }
897
898void HostApi121::SetOverzoomFlagVisible(bool viz) {
899 ::SetOverzoomFlagVisible(viz);
900}
901
902void HostApi121::AddNoShowDirectory(std::string chart_dir) {
903 ::AddNoShowDirectory(chart_dir);
904}
905
906void HostApi121::RemoveNoShowDirectory(std::string chart_dir) {
907 ::RemoveNoShowDirectory(chart_dir);
908}
909
910void HostApi121::ClearNoShowVector() { ::ClearNoShowVector(); }
911
912const std::vector<std::string>& HostApi121::GetNoShowVector() {
913 return ::GetNoShowVector();
914}
915
916bool HostApi121::SelectChartFamily(int CanvasIndex, ChartFamilyEnumPI Family) {
917 return ::SelectChartFamily(CanvasIndex, Family);
918};
919
920// Enhanced AIS Target List support
921
922void HostApi121::CenterToAisTarget(wxString ais_mmsi) {
923 ::CenterToAisTarget(ais_mmsi);
924}
925
926void HostApi121::AisTargetCreateWpt(wxString ais_mmsi) {
927 ::AisTargetCreateWpt(ais_mmsi);
928}
929
930void HostApi121::AisShowAllTracks(bool show) { ::AisShowAllTracks(show); }
931
932void HostApi121::AisToggleTrack(wxString ais_mmsi) {
933 ::AisToggleTrack(ais_mmsi);
934}
935
936// Context menu enable/disable, by object type
937int HostApi121::GetContextMenuMask() { return ::GetContextMenuMask(); }
938
939void HostApi121::SetContextMenuMask(int mask) { ::SetContextMenuMask(mask); }
940
941void HostApi121::SetTrackVisibiiity(const wxString& track_GUID, bool viz) {
942 ::SetTrackVisibility(track_GUID, viz);
943}
AisDecoder * g_pAIS
Global instance.
Class AisDecoder and helpers.
AIS target definitions.
std::unique_ptr< HostApi > GetHostApi()
HostApi factory,.
Definition api_121.cpp:744
std::vector< std::string > ChartDirectoryExcludedVector
Global instance.
Definition chartdb.cpp:72
Generic Chart canvas base.
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:157
int PrepareContextSelections(double lat, double lon)
Definition chcanv.cpp:7969
void Notify() override
Notify all listeners, no data supplied.
EventVar on_center_ais_target
Notified with a shared_ptr<const AisTargetData> when gFrame should center the given AIS target.
Definition gui_events.h:56
EventVar gframe_update_status_bar
Notified when the top level status bas should be updated by gFrame.
Definition gui_events.h:50
virtual bool AddRoute(Route *route, bool permanent=true)
Add route to database, updated version of AddPlugInRouteExV2.
Definition api_121.cpp:748
virtual std::unique_ptr< HostApi121::Route > GetRoute(const wxString &guid)
Retrieve route from database.
Definition api_121.cpp:756
virtual bool UpdateRoute(Route *route)
Update database route, updated version of UpdatePlugInRouteExV2.
Definition api_121.cpp:752
bool m_isVisible
True if route should be displayed.
Plugin_WaypointExV2List * pWaypointList
List of waypoints making up this route in order.
wxString m_StartString
Description of route start point.
wxString m_Description
Optional route description/notes.
wxString m_NameString
User-visible name of the route.
wxString m_GUID
Globally unique identifier.
wxString m_EndString
Description of route end point.
wxDateTime m_ETD
Estimated departure time in UTC, or wxInvalidDateTime if not set.
wxString m_MarkDescription
Optional description text.
wxString m_GUID
Globally unique identifier.
wxString m_TideStation
Tide Station Identifier.
wxDateTime m_CreateTime
Creation timestamp in UTC.
bool m_bShowWaypointRangeRings
True to show range rings on chart.
wxString IconDescription
User-friendly description of icon.
double m_lat
Latitude in decimal degrees.
wxColour RangeRingColor
Color to draw range rings.
bool IsActive
Active state (e.g. destination)
Plugin_HyperlinkList * m_HyperlinkList
List of hyperlinks associated with this waypoint.
double scamin
Minimum display scale (1:X) for waypoint visibility.
double scamax
Maximum display scale (1:X) for waypoint visibility.
bool b_useScamin
True to enable scale-dependent visibility.
wxString IconName
Name of icon to use for waypoint symbol.
bool IsNameVisible
True to show waypoint name on chart.
double m_PlannedSpeed
Planned speed for next leg (knots)
double RangeRingSpace
Distance between range rings in preferred units.
double m_lon
Longitude in decimal degrees.
double m_WaypointArrivalRadius
Arrival radius in nautical miles.
int RangeRingSpaceUnits
Units for range ring spacing - 0:nm, 1:km.
wxString m_MarkName
Display name of waypoint.
bool IsVisible
Visibility state on chart.
int nrange_rings
Number of range rings to display around waypoint.
Extended waypoint class with additional navigation features.
wxDateTime m_CreateTime
Creation timestamp in UTC.
wxColour RangeRingColor
Color to draw range rings.
int nrange_rings
Number of range rings to display around waypoint.
wxString IconDescription
User-friendly description of icon.
bool b_useScamin
True to enable scale-dependent visibility.
double RangeRingSpace
Distance between range rings in preferred units.
Plugin_HyperlinkList * m_HyperlinkList
List of hyperlinks associated with this waypoint.
wxString m_MarkName
Display name of waypoint.
wxString m_GUID
Globally unique identifier.
double m_lon
Longitude in decimal degrees.
wxString IconName
Name of icon to use for waypoint symbol.
double scamin
Minimum display scale (1:X) for waypoint visibility.
bool IsNameVisible
True to show waypoint name on chart.
double m_lat
Latitude in decimal degrees.
wxString m_MarkDescription
Optional description text.
bool IsActive
Active state (e.g. destination)
bool IsVisible
Visibility state on chart.
Represents a waypoint or mark within the navigation system.
Definition route_point.h:71
HyperlinkList * m_HyperlinkList
List of hyperlinks associated with this waypoint.
wxColour m_wxcWaypointRangeRingsColour
Color for the range rings display.
wxString m_MarkDescription
Description text for the waypoint.
int m_iWaypointRangeRingsNumber
Number of range rings to display around the waypoint.
void SetCreateTime(wxDateTime dt)
Sets the create time of this RoutePoint in UTC.
wxString m_GUID
Globally Unique Identifier for the waypoint.
bool m_bIsolatedMark
Flag indicating if the waypoint is a standalone mark.
bool m_bIsActive
Flag indicating if this waypoint is active for navigation.
wxDateTime GetManualETD()
Retrieves the manually set Estimated Time of Departure for this waypoint, in UTC.
bool m_bShowName
Flag indicating if the waypoint name should be shown.
double GetPlannedSpeed()
Return the planned speed associated with this waypoint.
bool m_btemp
Flag indicating if this is a temporary waypoint.
int m_iWaypointRangeRingsStepUnits
Units for the range rings step (0=nm, 1=km).
wxDateTime GetCreateTime(void)
Returns the Create Time of this RoutePoint in UTC.
float m_fWaypointRangeRingsStep
Distance between consecutive range rings.
wxString m_TideStation
Associated tide station identifier.
void SetETD(const wxDateTime &etd)
Sets the Estimated Time of Departure for this waypoint, in UTC.
Represents a navigational route in the navigation system.
Definition route.h:99
bool m_bRtIsSelected
Flag indicating whether this route is currently selected in the UI.
Definition route.h:203
double m_PlannedSpeed
Default planned speed for the route in knots.
Definition route.h:321
wxString m_RouteStartString
Name or description of the route's starting point.
Definition route.h:252
wxString m_RouteDescription
Additional descriptive information about the route.
Definition route.h:262
RoutePointList * pRoutePointList
Ordered list of waypoints (RoutePoints) that make up this route.
Definition route.h:336
wxString m_Colour
Color name for rendering the route on the chart.
Definition route.h:346
bool m_bDeleteOnArrival
Flag indicating whether the route should be deleted once navigation reaches the end.
Definition route.h:268
wxString m_RouteEndString
Name or description of the route's ending point.
Definition route.h:257
bool m_btemp
Flag indicating if this is a temporary route.
Definition route.h:351
wxPenStyle m_style
Style of the route line when rendered on the chart.
Definition route.h:293
wxString m_TimeDisplayFormat
Format for displaying times in the UI.
Definition route.h:331
wxString m_RouteNameString
User-assigned name for the route.
Definition route.h:247
wxString m_GUID
Globally unique identifier for this route.
Definition route.h:273
wxDateTime m_PlannedDeparture
Planned departure time for the route, in UTC.
Definition route.h:326
bool m_bIsInLayer
Flag indicating whether this route belongs to a layer.
Definition route.h:278
int m_lastMousePointIndex
Index of the most recently interacted with route point.
Definition route.h:298
bool DeleteRoute(Route *pRoute)
Definition routeman.cpp:762
EventVar on_routes_update
Notified when list of routes is updated (no data in event)
Definition routeman.h:265
bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint=NULL)
Activates a route for navigation.
Definition routeman.cpp:222
Represents a track, which is a series of connected track points.
Definition track.h:117
Misc GUI event vars, a singleton.
Miscellaneous globals primarely used by gui layer, not persisted in configuration file.
MySQL based storage for routes, tracks, etc.
User notifications manager.
PlugIn Object Definition/API.
ChartFamilyEnumPI
Enumeration of chart families (broad categories).
wxWindow * GetCanvasByIndex(int canvasIndex)
Gets chart canvas window by index.
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.
Route abstraction.
Routeman * g_pRouteMan
Global instance.
Definition routeman.cpp:60
RouteList * pRouteList
Global instance.
Definition routeman.cpp:66
Route Manager.
Select * pSelect
Global instance.
Definition select.cpp:36
std::vector< Track * > g_TrackList
Global instance.
Definition track.cpp:96
Recorded track abstraction.