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::PlugIn_Route_Ex* proute,
167 bool b_permanent) {
168 Route* route = new Route();
169
170 PlugIn_Waypoint_ExV2* pwaypointex;
171 RoutePoint *pWP, *pWP_src;
172 int ip = 0;
173 wxDateTime plannedDeparture;
174
175 wxPlugin_WaypointExV2ListNode* pwpnode = proute->pWaypointList->GetFirst();
176 while (pwpnode) {
177 pwaypointex = pwpnode->GetData();
178
179 pWP = pWayPointMan->FindRoutePointByGUID(pwaypointex->m_GUID);
180 if (!pWP) {
181 pWP = CreateNewPoint(pwaypointex, b_permanent);
182 pWP->m_bIsolatedMark = false;
183 }
184
185 route->AddPoint(pWP);
186
187 pSelect->AddSelectableRoutePoint(pWP->m_lat, pWP->m_lon, pWP);
188
189 if (ip > 0)
190 pSelect->AddSelectableRouteSegment(pWP_src->m_lat, pWP_src->m_lon,
191 pWP->m_lat, pWP->m_lon, pWP_src, pWP,
192 route);
193
194 plannedDeparture = pwaypointex->m_CreateTime;
195 ip++;
196 pWP_src = pWP;
197
198 pwpnode = pwpnode->GetNext(); // PlugInWaypoint
199 }
200
201 route->m_PlannedDeparture = plannedDeparture;
202
203 route->m_RouteNameString = proute->m_NameString;
204 route->m_RouteStartString = proute->m_StartString;
205 route->m_RouteEndString = proute->m_EndString;
206 if (!proute->m_GUID.IsEmpty()) {
207 route->m_GUID = proute->m_GUID;
208 }
209 route->m_btemp = (b_permanent == false);
210 route->SetVisible(proute->m_isVisible);
211 route->m_RouteDescription = proute->m_Description;
212
213 route->m_PlannedSpeed = proute->m_PlannedSpeed;
214 route->m_Colour = proute->m_Colour;
215 route->m_style = proute->m_style;
216 route->m_PlannedDeparture = proute->m_PlannedDeparture;
217 route->m_TimeDisplayFormat = proute->m_TimeDisplayFormat;
218
219 pRouteList->push_back(route);
220
221 if (b_permanent) {
222 // pConfig->AddNewRoute(route);
223 NavObj_dB::GetInstance().InsertRoute(route);
224 }
225
227
228 return true;
229}
230
231static bool UpdatePlugInRouteExV3(HostApi121::PlugIn_Route_Ex* proute) {
232 bool b_found = false;
233
234 // Find the Route
235 Route* pRoute = g_pRouteMan->FindRouteByGUID(proute->m_GUID);
236 if (pRoute) b_found = true;
237
238 if (b_found) {
239 bool b_permanent = !pRoute->m_btemp;
240 g_pRouteMan->DeleteRoute(pRoute);
241
242 b_found = AddPlugInRouteExV3(proute, b_permanent);
243 }
244
245 return b_found;
246}
247
248// translate O route class to PlugIn_Waypoint_Ex
249static void PlugInExFromRoutePoint(PlugIn_Waypoint_Ex* dst,
250 /* const*/ RoutePoint* src) {
251 dst->m_lat = src->m_lat;
252 dst->m_lon = src->m_lon;
253 dst->IconName = src->GetIconName();
254 dst->m_MarkName = src->GetName();
255 dst->m_MarkDescription = src->GetDescription();
256 dst->IconDescription = pWayPointMan->GetIconDescription(src->GetIconName());
257 dst->IsVisible = src->IsVisible();
258 dst->m_CreateTime = src->GetCreateTime(); // not const
259 dst->m_GUID = src->m_GUID;
260
261 // Transcribe (clone) the html HyperLink List, if present
262 if (src->m_HyperlinkList) {
263 delete dst->m_HyperlinkList;
264 dst->m_HyperlinkList = nullptr;
265
266 if (src->m_HyperlinkList->size() > 0) {
267 dst->m_HyperlinkList = new Plugin_HyperlinkList;
268 for (Hyperlink* link : *src->m_HyperlinkList) {
270 h->DescrText = link->DescrText;
271 h->Link = link->Link;
272 h->Type = link->LType;
273 dst->m_HyperlinkList->Append(h);
274 }
275 }
276 }
277
278 // Get the range ring info
282
283 // Get other extended info
284 dst->IsNameVisible = src->m_bShowName;
285 dst->scamin = src->GetScaMin();
286 dst->b_useScamin = src->GetUseSca();
287 dst->IsActive = src->m_bIsActive;
288}
289
290static void cloneHyperlinkListEx(RoutePoint* dst,
291 const PlugIn_Waypoint_Ex* src) {
292 // Transcribe (clone) the html HyperLink List, if present
293 if (src->m_HyperlinkList == nullptr) return;
294
295 if (src->m_HyperlinkList->GetCount() > 0) {
296 wxPlugin_HyperlinkListNode* linknode = src->m_HyperlinkList->GetFirst();
297 while (linknode) {
298 Plugin_Hyperlink* link = linknode->GetData();
299
300 Hyperlink* h = new Hyperlink();
301 h->DescrText = link->DescrText;
302 h->Link = link->Link;
303 h->LType = link->Type;
304
305 dst->m_HyperlinkList->push_back(h);
306
307 linknode = linknode->GetNext();
308 }
309 }
310}
311
312static wxString DropMarkPI(double lat, double lon) {
313 if ((fabs(lat) > 80.0) || (fabs(lon) > 180.)) return "";
314
315 RoutePoint* pWP =
316 new RoutePoint(lat, lon, g_default_wp_icon, wxEmptyString, wxEmptyString);
317 pWP->m_bIsolatedMark = true; // This is an isolated mark
318 pSelect->AddSelectableRoutePoint(lat, lon, pWP);
319 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
320 return pWP->m_GUID;
321}
322
323static wxString RouteCreatePI(int canvas_index, bool start) {
324 if ((size_t)canvas_index < g_canvasArray.GetCount()) {
325 ChartCanvas* cc = g_canvasArray.Item(canvas_index);
326 if (cc) {
327 if (start) {
328 cc->StartRoute();
329 return "0";
330 } else {
331 return cc->FinishRoute();
332 }
333 }
334 }
335 return "-1";
336}
337
338static bool DoMeasurePI(int canvas_index, bool start) {
339 if ((size_t)canvas_index < g_canvasArray.GetCount()) {
340 ChartCanvas* cc = g_canvasArray.Item(canvas_index);
341 if (cc) {
342 if (start) {
343 cc->StartMeasureRoute();
344 return true;
345 } else {
346 cc->CancelMeasureRoute();
347 cc->Refresh(false);
348 return true;
349 }
350 }
351 }
352 return false;
353}
354
355static void EnableDefaultConsole(bool enable) {
356 g_bhide_route_console = !enable;
357}
358
359static wxString NavToHerePI(double lat, double lon) {
360 RoutePoint* pWP_dest =
361 new RoutePoint(lat, lon, g_default_wp_icon, wxEmptyString, wxEmptyString);
362 pSelect->AddSelectableRoutePoint(lat, lon, pWP_dest);
363
364 RoutePoint* pWP_src = new RoutePoint(gLat, gLon, g_default_wp_icon,
365 wxEmptyString, wxEmptyString);
366 pSelect->AddSelectableRoutePoint(gLat, gLon, pWP_src);
367
368 Route* temp_route = new Route();
369 pRouteList->push_back(temp_route);
370
371 temp_route->AddPoint(pWP_src);
372 temp_route->AddPoint(pWP_dest);
373
374 pSelect->AddSelectableRouteSegment(gLat, gLon, lat, lon, pWP_src, pWP_dest,
375 temp_route);
376
377 temp_route->m_RouteNameString = _("Temporary GOTO Route");
378 temp_route->m_RouteStartString = _("Here");
379 temp_route->m_RouteEndString = _("There");
380 temp_route->m_bDeleteOnArrival = true;
381
382 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
383
384 g_pRouteMan->ActivateRoute(temp_route, pWP_dest);
385 return temp_route->m_GUID;
386}
387
388static bool ActivateRoutePI(wxString route_guid, bool activate) {
389 Route* route = g_pRouteMan->FindRouteByGUID(route_guid);
390 if (!route) return false;
391
392 if (activate) {
393 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
394 RoutePoint* best_point =
395 g_pRouteMan->FindBestActivatePoint(route, gLat, gLon, gCog, gSog);
396 g_pRouteMan->ActivateRoute(route, best_point);
397 route->m_bRtIsSelected = false;
398 return true;
399 } else {
400 g_pRouteMan->DeactivateRoute();
401 route->m_bRtIsSelected = false;
402 return true;
403 }
404 return false;
405}
406
407static void SetMaxZoomScale(double max_scale) {
408 g_maxzoomin = wxRound(wxMax(max_scale, 100.));
409}
410
411static void EnableDefaultContextMenus(bool enable) {
412 g_bhide_context_menus = !enable;
413}
414
415static void SetMinZoomScale(double min_scale) {
416 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
417 ChartCanvas* cc = g_canvasArray.Item(i);
418 cc->SetAbsoluteMinScale(min_scale);
419 }
420}
421
422static std::shared_ptr<HostApi121::PiPointContext> GetContextAtPoint(
423 int x, int y, int canvas_index) {
424 ChartCanvas* cc = g_canvasArray.Item(canvas_index);
425 if (cc) {
426 return cc->GetCanvasContextAtPoint(x, y);
427 } else {
428 auto rstruct = std::make_shared<HostApi121::PiPointContext>();
429 rstruct->object_type = HostApi121::PiContextObjectType::kObjectUnknown;
430 rstruct->object_ident = "";
431 return rstruct;
432 }
433}
434
435static wxBitmap GetObjectIcon_PlugIn(const wxString& name) {
436 if (pWayPointMan)
437 return *pWayPointMan->GetIconBitmap(name);
438 else
439 return wxNullBitmap;
440}
441
442static bool IsRouteActive(wxString route_guid) {
443 if (g_pRouteMan->GetpActiveRoute())
444 return (route_guid.IsSameAs(g_pRouteMan->GetpActiveRoute()->m_GUID));
445 else
446 return false;
447}
448
449static void SetBoatPosition(double zlat, double zlon) {
450 gLat = zlat;
451 gLon = zlon;
452 GuiEvents::GetInstance().gframe_update_status_bar.Notify();
453}
454
455static void RouteInsertWaypoint(int canvas_index, wxString route_guid,
456 double zlat, double zlon) {
457 ChartCanvas* parent =
458 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
459 if (!parent) return;
460
461 Route* route = g_pRouteMan->FindRouteByGUID(route_guid);
462 if (!route) return;
463
464 if (route->m_bIsInLayer) return;
465
466 int seltype = parent->PrepareContextSelections(zlat, zlon);
467 if ((seltype & SELTYPE_ROUTESEGMENT) != SELTYPE_ROUTESEGMENT) return;
468
469 bool rename = false;
470 route->InsertPointAfter(parent->GetFoundRoutepoint(), zlat, zlon, rename);
471
472 pSelect->DeleteAllSelectableRoutePoints(route);
473 pSelect->DeleteAllSelectableRouteSegments(route);
474 pSelect->AddAllSelectableRouteSegments(route);
475 pSelect->AddAllSelectableRoutePoints(route);
476
477 NavObj_dB::GetInstance().UpdateRoute(route);
478}
479
480static void RouteAppendWaypoint(int canvas_index, wxString route_guid) {
481 Route* route = g_pRouteMan->FindRouteByGUID(route_guid);
482 if (!route) return;
483
484 ChartCanvas* parent =
485 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
486 if (!parent) return;
487
488 parent->m_pMouseRoute = route;
489 parent->m_routeState = route->GetnPoints() + 1;
490 parent->m_pMouseRoute->m_lastMousePointIndex = route->GetnPoints();
491 parent->m_pMouseRoute->SetHiLite(50);
492
493 auto pLast = route->GetLastPoint();
494
495 parent->m_prev_rlat = pLast->m_lat;
496 parent->m_prev_rlon = pLast->m_lon;
497 parent->m_prev_pMousePoint = pLast;
498
499 parent->m_bAppendingRoute = true;
500}
501
502static void FinishRoute(int canvas_index) {
503 ChartCanvas* parent =
504 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
505 if (!parent) return;
506
507 parent->FinishRoute();
508}
509
510static bool IsRouteBeingCreated(int canvas_index) {
511 ChartCanvas* parent =
512 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
513 if (!parent) return false;
514 return !(parent->m_pMouseRoute == NULL);
515}
516
517static bool AreRouteWaypointNamesVisible(wxString route_guid) {
518 Route* route = g_pRouteMan->FindRouteByGUID(route_guid);
519 if (!route) return false;
520 return route->AreWaypointNamesVisible();
521}
522
523static void ShowRouteWaypointNames(wxString route_guid, bool show) {
524 Route* route = g_pRouteMan->FindRouteByGUID(route_guid);
525 if (!route) return;
526 route->ShowWaypointNames(show);
527}
528
529static void NavigateToWaypoint(wxString waypoint_guid) {
530 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(waypoint_guid);
531 if (!prp) return;
532
533 RoutePoint* pWP_src = new RoutePoint(gLat, gLon, g_default_wp_icon,
534 wxEmptyString, wxEmptyString);
535 pSelect->AddSelectableRoutePoint(gLat, gLon, pWP_src);
536
537 Route* temp_route = new Route();
538 pRouteList->push_back(temp_route);
539
540 temp_route->AddPoint(pWP_src);
541 temp_route->AddPoint(prp);
542 prp->SetShared(true);
543
544 pSelect->AddSelectableRouteSegment(gLat, gLon, prp->m_lat, prp->m_lon,
545 pWP_src, prp, temp_route);
546
547 wxString name = prp->GetName();
548 if (name.IsEmpty()) name = _("(Unnamed Waypoint)");
549 wxString rteName = _("Go to ");
550 rteName.Append(name);
551 temp_route->m_RouteNameString = rteName;
552 temp_route->m_RouteStartString = _("Here");
553 temp_route->m_RouteEndString = name;
554 temp_route->m_bDeleteOnArrival = true;
555
556 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
557 g_pRouteMan->ActivateRoute(temp_route, prp);
558}
559
560// AIS related
561static bool IsAISTrackVisible(wxString ais_mmsi) {
562 long mmsi = 0;
563 ais_mmsi.ToLong(&mmsi);
564 auto myptarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
565 if (myptarget)
566 return myptarget->b_show_track;
567 else
568 return false;
569}
570
571static void AISToggleShowTrack(wxString ais_mmsi) {
572 long mmsi = 0;
573 ais_mmsi.ToLong(&mmsi);
574 auto myptarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
575 if (myptarget) myptarget->ToggleShowTrack();
576}
577
578static void AISToggleShowCPA(wxString ais_mmsi) {
579 long mmsi = 0;
580 ais_mmsi.ToLong(&mmsi);
581 auto myptarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
582 if (myptarget) myptarget->Toggle_AIS_CPA();
583}
584
585static void ShowAISTargetQueryDialog(int canvas_index, wxString ais_mmsi) {
586 ChartCanvas* parent =
587 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
588 if (!parent) return;
589
590 long mmsi = 0;
591 ais_mmsi.ToLong(&mmsi);
592 ShowAISTargetQueryDialog(parent, mmsi);
593}
594
595static void ShowAISTargetList(int canvas_index) {
596 ChartCanvas* parent =
597 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
598 if (!parent) return;
599 parent->ShowAISTargetList();
600}
601
602static bool IsMeasureActive(int canvas_index) {
603 ChartCanvas* parent =
604 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
605 if (!parent) return false;
606 return parent->m_bMeasure_Active;
607}
608
609static void CancelMeasure(int canvas_index) {
610 ChartCanvas* parent =
611 static_cast<ChartCanvas*>(GetCanvasByIndex(canvas_index));
612 if (!parent) return;
613 parent->CancelMeasureRoute();
614}
615
616static void SetDepthUnitVisible(bool bviz) { g_bhide_depth_units = !bviz; }
617
618static void SetOverzoomFlagVisible(bool bviz) { g_bhide_overzoom_flag = !bviz; }
619
620// Extended Chart table management support
621static void AddNoShowDirectory(std::string chart_dir) {
622 ChartDirectoryExcludedVector.push_back(chart_dir);
623}
624
625static void RemoveNoShowDirectory(std::string chart_dir) {
626 auto it = std::find(ChartDirectoryExcludedVector.begin(),
627 ChartDirectoryExcludedVector.end(), chart_dir);
628 if (it != ChartDirectoryExcludedVector.end())
629 ChartDirectoryExcludedVector.erase(it); // Erase the element
630}
631
632static void ClearNoShowVector() { ChartDirectoryExcludedVector.clear(); }
633
634static const std::vector<std::string>& GetNoShowVector() {
636}
637
638static void CenterToAisTarget(wxString ais_mmsi) {
639 long mmsi = 0;
640 if (ais_mmsi.ToLong(&mmsi)) {
641 std::shared_ptr<AisTargetData> pAISTarget = nullptr;
642 if (g_pAIS) pAISTarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
643
644 if (pAISTarget)
645 GuiEvents::GetInstance().on_center_ais_target.Notify(pAISTarget);
646 }
647} // same as AISTargetListDialog::CenterToTarget ( false )
648
649static void AisTargetCreateWpt(wxString ais_mmsi) {
650 long mmsi = 0;
651 if (ais_mmsi.ToLong(&mmsi)) {
652 std::shared_ptr<AisTargetData> pAISTarget = NULL;
653 if (g_pAIS) pAISTarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
654
655 if (pAISTarget) {
656 RoutePoint* pWP =
657 new RoutePoint(pAISTarget->Lat, pAISTarget->Lon, g_default_wp_icon,
658 wxEmptyString, wxEmptyString);
659 pWP->m_bIsolatedMark = true; // This is an isolated mark
660 pSelect->AddSelectableRoutePoint(pAISTarget->Lat, pAISTarget->Lon, pWP);
661 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
662
664 }
665 }
666} // same as AISTargetListDialog::OnTargetCreateWpt
667
668static void AisShowAllTracks(bool show) {
669 if (g_pAIS) {
670 for (const auto& it : g_pAIS->GetTargetList()) {
671 auto pAISTarget = it.second;
672 if (NULL != pAISTarget) {
673 pAISTarget->b_show_track = show;
674
675 // Check for any persistently tracked target, force b_show_track_old
676 std::map<int, Track*>::iterator itt;
677 itt = g_pAIS->m_persistent_tracks.find(pAISTarget->MMSI);
678 if (itt != g_pAIS->m_persistent_tracks.end()) {
679 pAISTarget->b_show_track_old = show;
680 }
681 }
682 }
683 } // same as AISTargetListDialog::OnHideAllTracks /
684 // AISTargetListDialog::OnShowAllTracks
685}
686
687static void AisToggleTrack(wxString ais_mmsi) {
688 long mmsi = 0;
689 if (ais_mmsi.ToLong(&mmsi)) {
690 std::shared_ptr<AisTargetData> pAISTarget = NULL;
691 if (g_pAIS) pAISTarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
692
693 if (pAISTarget) {
694 pAISTarget->b_show_track_old =
695 pAISTarget->b_show_track; // Store current state before toggling
696 pAISTarget->b_show_track =
697 !pAISTarget->b_show_track; // Toggle visibility
698 }
699 }
700}
701
702static int GetContextMenuMask() { return g_canvas_context_menu_disable_mask; }
703
704static void SetContextMenuMask(int mask) {
705 g_canvas_context_menu_disable_mask = mask;
706}
707
708static bool IsAIS_CPAVisible(wxString ais_mmsi) {
709 long mmsi = 0;
710 ais_mmsi.ToLong(&mmsi);
711 auto myptarget = g_pAIS->Get_Target_Data_From_MMSI(mmsi);
712 if (myptarget)
713 return myptarget->b_show_AIS_CPA;
714 else
715 return false;
716}
717
718std::unique_ptr<HostApi> GetHostApi() {
719 return std::make_unique<HostApi121>(HostApi121());
720}
721
722HostApi121::PlugIn_Route_Ex::PlugIn_Route_Ex() {
723 m_PlannedSpeed = 0;
724 m_Colour = "";
725 m_style = wxPENSTYLE_SOLID;
726 m_PlannedDeparture = wxDateTime::Now();
727 m_TimeDisplayFormat = RTE_TIME_DISP_UTC;
728}
729
730HostApi121::PlugIn_Route_Ex::~PlugIn_Route_Ex() {
731 if (pWaypointList) {
732 pWaypointList->DeleteContents(true);
733 delete pWaypointList;
734 pWaypointList = NULL;
735 }
736}
737
739 bool b_permanent) {
740 return ::AddPlugInRouteExV3(proute, b_permanent);
741}
742
744 return ::UpdatePlugInRouteExV3(proute);
745}
746
747wxString HostApi121::DropMarkPI(double lat, double lon) {
748 return ::DropMarkPI(lat, lon);
749}
750
751wxString HostApi121::RouteCreatePI(int canvas_index, bool start) {
752 return ::RouteCreatePI(canvas_index, start);
753}
754
755bool HostApi121::DoMeasurePI(int canvas_index, bool start) {
756 return ::DoMeasurePI(canvas_index, start);
757}
758
759wxString HostApi121::NavToHerePI(double lat, double lon) {
760 return ::NavToHerePI(lat, lon);
761}
762
763bool HostApi121::ActivateRoutePI(wxString route_guid, bool activate) {
764 return ::ActivateRoutePI(route_guid, activate);
765}
766
767void HostApi121::EnableDefaultConsole(bool enable) {
768 ::EnableDefaultConsole(enable);
769}
770
771void HostApi121::EnableDefaultContextMenus(bool enable) {
772 ::EnableDefaultContextMenus(enable);
773}
774
775void HostApi121::SetMinZoomScale(double min_scale) {
776 ::SetMinZoomScale(min_scale);
777}
778
779void HostApi121::SetMaxZoomScale(double max_scale) {
780 ::SetMaxZoomScale(max_scale);
781}
782
783std::shared_ptr<HostApi121::PiPointContext> HostApi121::GetContextAtPoint(
784 int x, int y, int canvas_index) {
785 return ::GetContextAtPoint(x, y, canvas_index);
786}
787
788wxBitmap HostApi121::GetObjectIcon_PlugIn(const wxString& name) {
789 return ::GetObjectIcon_PlugIn(name);
790}
791
792bool HostApi121::IsRouteActive(wxString route_guid) {
793 return ::IsRouteActive(route_guid);
794}
795
796void HostApi121::SetBoatPosition(double zlat, double zlon) {
797 ::SetBoatPosition(zlat, zlon);
798}
799
800void HostApi121::RouteInsertWaypoint(int canvas_index, wxString route_guid,
801 double zlat, double zlon) {
802 ::RouteInsertWaypoint(canvas_index, route_guid, zlat, zlon);
803}
804
805void HostApi121::RouteAppendWaypoint(int canvas_index, wxString route_guid) {
806 ::RouteAppendWaypoint(canvas_index, route_guid);
807}
808
809void HostApi121::FinishRoute(int canvas_index) { ::FinishRoute(canvas_index); }
810
811bool HostApi121::IsRouteBeingCreated(int canvas_index) {
812 return ::IsRouteBeingCreated(canvas_index);
813}
814
815bool HostApi121::AreRouteWaypointNamesVisible(wxString route_guid) {
816 return ::AreRouteWaypointNamesVisible(route_guid);
817}
818
819void HostApi121::ShowRouteWaypointNames(wxString route_guid, bool show) {
820 ::ShowRouteWaypointNames(route_guid, show);
821}
822
823void HostApi121::NavigateToWaypoint(wxString waypoint_guid) {
824 ::NavigateToWaypoint(waypoint_guid);
825}
826
827bool HostApi121::IsAISTrackVisible(const wxString& ais_mmsi) const {
828 return ::IsAISTrackVisible(ais_mmsi);
829}
830
831void HostApi121::AISToggleShowTrack(const wxString& ais_mmsi) {
832 ::AISToggleShowTrack(ais_mmsi);
833}
834
835bool HostApi121::IsAIS_CPAVisible(const wxString& ais_mmsi) const {
836 return ::IsAIS_CPAVisible(ais_mmsi);
837}
838
839void HostApi121::AISToggleShowCPA(const wxString& ais_mmsi) {
840 ::AISToggleShowCPA(ais_mmsi);
841}
842
843void HostApi121::ShowAISTargetQueryDialog(int canvas_index,
844 const wxString& ais_mmsi) {
845 ::ShowAISTargetQueryDialog(canvas_index, ais_mmsi);
846}
847
848void HostApi121::ShowAISTargetList(int canvas_index) {
849 ::ShowAISTargetList(canvas_index);
850}
851
852bool HostApi121::IsMeasureActive(int canvas_index) {
853 return ::IsMeasureActive(canvas_index);
854}
855
856void HostApi121::CancelMeasure(int canvas_index) {
857 ::CancelMeasure(canvas_index);
858}
859
860void HostApi121::SetDepthUnitVisible(bool bviz) { ::SetDepthUnitVisible(bviz); }
861
862void HostApi121::SetOverzoomFlagVisible(bool viz) {
863 ::SetOverzoomFlagVisible(viz);
864}
865
866void HostApi121::AddNoShowDirectory(std::string chart_dir) {
867 ::AddNoShowDirectory(chart_dir);
868}
869
870void HostApi121::RemoveNoShowDirectory(std::string chart_dir) {
871 ::RemoveNoShowDirectory(chart_dir);
872}
873
874void HostApi121::ClearNoShowVector() { ::ClearNoShowVector(); }
875
876const std::vector<std::string>& HostApi121::GetNoShowVector() {
877 return ::GetNoShowVector();
878}
879
880// Enhanced AIS Target List support
881
882void HostApi121::CenterToAisTarget(wxString ais_mmsi) {
883 ::CenterToAisTarget(ais_mmsi);
884}
885
886void HostApi121::AisTargetCreateWpt(wxString ais_mmsi) {
887 ::AisTargetCreateWpt(ais_mmsi);
888}
889
890void HostApi121::AisShowAllTracks(bool show) { ::AisShowAllTracks(show); }
891
892void HostApi121::AisToggleTrack(wxString ais_mmsi) {
893 ::AisToggleTrack(ais_mmsi);
894}
895
896// Context menu enable/disable, by object type
897int HostApi121::GetContextMenuMask() { return ::GetContextMenuMask(); }
898
899void HostApi121::SetContextMenuMask(int mask) { ::SetContextMenuMask(mask); }
AisDecoder * g_pAIS
Global instance.
Class AisDecoder and helpers.
AIS target definitions.
std::unique_ptr< HostApi > GetHostApi()
HostApi factory,.
Definition api_121.cpp:718
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:7950
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(PlugIn_Route_Ex *proute, bool b_permanent=true)
Add route to database, updated version of AddPlugInRouteExV2.
Definition api_121.cpp:738
virtual bool UpdateRoute(PlugIn_Route_Ex *proute)
Update database route, updated version of UpdatePlugInRouteExV2.
Definition api_121.cpp:743
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
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
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.
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
Recorded track abstraction.