OpenCPN Partial API docs
Loading...
Searching...
No Matches
ocpn_plugin_gui.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 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
25#include "dychart.h" // Must be ahead due to buggy GL includes handling
26
27#include <wx/wx.h>
28#include <wx/arrstr.h>
29#include <wx/dc.h>
30#include <wx/dcmemory.h>
31#include <wx/event.h>
32#include <wx/glcanvas.h>
33#include <wx/notebook.h>
34#include <wx/string.h>
35#include <wx/window.h>
36
37#include "model/ais_decoder.h"
39#include "model/idents.h"
40#include "model/multiplexer.h"
42#include "model/own_ship.h"
43#include "model/plugin_comm.h"
44#include "model/route.h"
45#include "model/track.h"
46
47#include "ais.h"
48#include "chartdb.h"
49#include "chcanv.h"
50#include "ConfigMgr.h"
51#include "FontMgr.h"
52#include "glChartCanvas.h"
53#include "gui_lib.h"
54#include "navutil.h"
55#include "ocpn_app.h"
56#include "OCPN_AUIManager.h"
57#include "ocpn_frame.h"
58#include "OCPNPlatform.h"
59#include "ocpn_plugin.h"
60#include "options.h"
61#include "piano.h"
62#include "pluginmanager.h"
63#include "routemanagerdialog.h"
64#include "routeman_gui.h"
65#include "s52plib.h"
66#include "SoundFactory.h"
67#include "svg_utils.h"
68#include "SystemCmdSound.h"
69#include "toolbar.h"
70#include "waypointman_gui.h"
71#include "shapefile_basemap.h"
72#include "model/navobj_db.h"
73
74extern PlugInManager* s_ppim;
75extern MyConfig* pConfig;
76extern OCPN_AUIManager* g_pauimgr;
77
78#if wxUSE_XLOCALE || !wxCHECK_VERSION(3, 0, 0)
79extern wxLocale* plocale_def_lang;
80#endif
81
82extern OCPNPlatform* g_Platform;
83extern ChartDB* ChartData;
84extern MyFrame* gFrame;
85extern ocpnStyle::StyleManager* g_StyleManager;
86extern options* g_pOptions;
87extern Multiplexer* g_pMUX;
88extern bool g_bShowChartBar;
89extern Routeman* g_pRouteMan;
90extern Select* pSelect;
91extern RouteManagerDialog* pRouteManagerDialog;
92extern RouteList* pRouteList;
93extern std::vector<Track*> g_TrackList;
94extern PlugInManager* g_pi_manager;
95extern s52plib* ps52plib;
96extern wxString ChartListFileName;
97extern options* g_options;
98extern ColorScheme global_color_scheme;
99extern wxArrayString g_locale_catalog_array;
100extern int g_GUIScaleFactor;
101extern int g_ChartScaleFactor;
102extern wxString g_locale;
103extern ocpnFloatingToolbarDialog* g_MainToolbar;
104
105extern int g_chart_zoom_modifier_raster;
106extern int g_chart_zoom_modifier_vector;
107extern double g_display_size_mm;
108extern bool g_bopengl;
109extern AisDecoder* g_pAIS;
110extern ChartGroupArray* g_pGroupArray;
111extern ShapeBaseChartSet gShapeBasemap;
112
113// extern ChartGroupArray* g_pGroupArray;
114extern unsigned int g_canvasConfig;
115
116extern wxString g_CmdSoundString;
117
118unsigned int gs_plib_flags;
119extern ChartCanvas* g_focusCanvas;
120extern ChartCanvas* g_overlayCanvas;
121extern bool g_bquiting;
122extern bool g_disable_main_toolbar;
123extern bool g_btenhertz;
124extern bool g_CanvasHideNotificationIcon;
125extern wxString g_default_wp_icon;
126extern bool g_bhide_route_console;
127extern bool g_bhide_context_menus;
128extern int g_maxzoomin;
129
130WX_DEFINE_ARRAY_PTR(ChartCanvas*, arrayofCanvasPtr);
131extern arrayofCanvasPtr g_canvasArray;
132
133void NotifySetupOptionsPlugin(const PlugInData* pic);
134
135//---------------------------------------------------------------------------
136/* Implementation of OCPN core functions callable by plugins
137 * Sorted by API version number
138 * The definitions of this API are found in ocpn_plugin.h
139 * PlugIns may call these static functions as necessary for system services
140 */
141//---------------------------------------------------------------------------
142
143//---------------------------------------------------------------------------
144// API 1.6
145//---------------------------------------------------------------------------
146/* Main Toolbar support */
147int InsertPlugInTool(wxString label, wxBitmap* bitmap, wxBitmap* bmpRollover,
148 wxItemKind kind, wxString shortHelp, wxString longHelp,
149 wxObject* clientData, int position, int tool_sel,
150 opencpn_plugin* pplugin) {
151 if (s_ppim)
152 return s_ppim->AddToolbarTool(label, bitmap, bmpRollover, kind, shortHelp,
153 longHelp, clientData, position, tool_sel,
154 pplugin);
155 else
156 return -1;
157}
158
159void RemovePlugInTool(int tool_id) {
160 if (s_ppim) s_ppim->RemoveToolbarTool(tool_id);
161}
162
163void SetToolbarToolViz(int item, bool viz) {
164 if (s_ppim) s_ppim->SetToolbarToolViz(item, viz);
165}
166
167void SetToolbarItemState(int item, bool toggle) {
168 if (s_ppim) s_ppim->SetToolbarItemState(item, toggle);
169}
170
171void SetToolbarToolBitmaps(int item, wxBitmap* bitmap, wxBitmap* bmpRollover) {
172 if (s_ppim) s_ppim->SetToolbarItemBitmaps(item, bitmap, bmpRollover);
173}
174
175int InsertPlugInToolSVG(wxString label, wxString SVGfile,
176 wxString SVGfileRollover, wxString SVGfileToggled,
177 wxItemKind kind, wxString shortHelp, wxString longHelp,
178 wxObject* clientData, int position, int tool_sel,
179 opencpn_plugin* pplugin) {
180 if (s_ppim)
181 return s_ppim->AddToolbarTool(label, SVGfile, SVGfileRollover,
182 SVGfileToggled, kind, shortHelp, longHelp,
183 clientData, position, tool_sel, pplugin);
184 else
185 return -1;
186}
187
188void SetToolbarToolBitmapsSVG(int item, wxString SVGfile,
189 wxString SVGfileRollover,
190 wxString SVGfileToggled) {
191 if (s_ppim)
192 s_ppim->SetToolbarItemBitmaps(item, SVGfile, SVGfileRollover,
193 SVGfileToggled);
194}
195
196/* Canvas Context Menu support */
197int AddCanvasMenuItem(wxMenuItem* pitem, opencpn_plugin* pplugin,
198 const char* name) {
199 if (s_ppim)
200 return s_ppim->AddCanvasContextMenuItemPIM(pitem, pplugin, name, false);
201 else
202 return -1;
203}
204
205void SetCanvasMenuItemViz(int item, bool viz, const char* name) {
206 if (s_ppim) s_ppim->SetCanvasContextMenuItemViz(item, viz, name);
207}
208
209void SetCanvasMenuItemGrey(int item, bool grey, const char* name) {
210 if (s_ppim) s_ppim->SetCanvasContextMenuItemGrey(item, grey, name);
211}
212
213void RemoveCanvasMenuItem(int item, const char* name) {
214 if (s_ppim) s_ppim->RemoveCanvasContextMenuItem(item, name);
215}
216
217int AddCanvasContextMenuItem(wxMenuItem* pitem, opencpn_plugin* pplugin) {
218 /* main context popup menu */
219 if (s_ppim)
220 return s_ppim->AddCanvasContextMenuItemPIM(pitem, pplugin, "", false);
221 else
222 return -1;
223}
224
225void SetCanvasContextMenuItemViz(int item, bool viz) {
226 SetCanvasMenuItemViz(item, viz);
227}
228
229void SetCanvasContextMenuItemGrey(int item, bool grey) {
230 SetCanvasMenuItemGrey(item, grey);
231}
232
234
235int AddCanvasContextMenuItemExt(wxMenuItem* pitem, opencpn_plugin* pplugin,
236 const std::string object_type) {
237 /* main context popup menu */
238 if (s_ppim)
239 return s_ppim->AddCanvasContextMenuItemPIM(pitem, pplugin,
240 object_type.c_str(), true);
241 else
242 return -1;
243}
244
245/* Utility functions */
246wxFileConfig* GetOCPNConfigObject(void) {
247 if (s_ppim)
248 return reinterpret_cast<wxFileConfig*>(
249 pConfig); // return the global application config object
250 else
251 return NULL;
252}
253
255 wxWindow* pret = NULL;
256 if (s_ppim) {
257 MyFrame* pFrame = s_ppim->GetParentFrame();
258 pret = (wxWindow*)pFrame->GetPrimaryCanvas();
259 }
260 return pret;
261}
262
263void RequestRefresh(wxWindow* win) {
264 if (win) win->Refresh(true);
265}
266
267void GetCanvasPixLL(PlugIn_ViewPort* vp, wxPoint* pp, double lat, double lon) {
268 // Make enough of an application viewport to run its method....
269 ViewPort ocpn_vp;
270 ocpn_vp.clat = vp->clat;
271 ocpn_vp.clon = vp->clon;
272 ocpn_vp.m_projection_type = vp->m_projection_type;
273 ocpn_vp.view_scale_ppm = vp->view_scale_ppm;
274 ocpn_vp.skew = vp->skew;
275 ocpn_vp.rotation = vp->rotation;
276 ocpn_vp.pix_width = vp->pix_width;
277 ocpn_vp.pix_height = vp->pix_height;
278
279 wxPoint ret = ocpn_vp.GetPixFromLL(lat, lon);
280 pp->x = ret.x;
281 pp->y = ret.y;
282}
283
284void GetDoubleCanvasPixLL(PlugIn_ViewPort* vp, wxPoint2DDouble* pp, double lat,
285 double lon) {
286 // Make enough of an application viewport to run its method....
287 ViewPort ocpn_vp;
288 ocpn_vp.clat = vp->clat;
289 ocpn_vp.clon = vp->clon;
290 ocpn_vp.m_projection_type = vp->m_projection_type;
291 ocpn_vp.view_scale_ppm = vp->view_scale_ppm;
292 ocpn_vp.skew = vp->skew;
293 ocpn_vp.rotation = vp->rotation;
294 ocpn_vp.pix_width = vp->pix_width;
295 ocpn_vp.pix_height = vp->pix_height;
296
297 *pp = ocpn_vp.GetDoublePixFromLL(lat, lon);
298}
299
300void GetCanvasLLPix(PlugIn_ViewPort* vp, wxPoint p, double* plat,
301 double* plon) {
302 // Make enough of an application viewport to run its method....
303 ViewPort ocpn_vp;
304 ocpn_vp.clat = vp->clat;
305 ocpn_vp.clon = vp->clon;
306 ocpn_vp.m_projection_type = vp->m_projection_type;
307 ocpn_vp.view_scale_ppm = vp->view_scale_ppm;
308 ocpn_vp.skew = vp->skew;
309 ocpn_vp.rotation = vp->rotation;
310 ocpn_vp.pix_width = vp->pix_width;
311 ocpn_vp.pix_height = vp->pix_height;
312
313 return ocpn_vp.GetLLFromPix(p, plat, plon);
314}
315
316bool GetGlobalColor(wxString colorName, wxColour* pcolour) {
317 wxColour c = GetGlobalColor(colorName);
318 *pcolour = c;
319
320 return true;
321}
322
323wxFont* OCPNGetFont(wxString TextElement, int default_size) {
324 return FontMgr::Get().GetFontLegacy(TextElement, default_size);
325}
326
327wxFont* GetOCPNScaledFont_PlugIn(wxString TextElement, int default_size) {
328 return FontMgr::Get().GetFontLegacy(TextElement, default_size);
329}
330
331double GetOCPNGUIToolScaleFactor_PlugIn(int GUIScaleFactor) {
332 return g_Platform->GetToolbarScaleFactor(GUIScaleFactor);
333}
334
336 return g_Platform->GetToolbarScaleFactor(g_GUIScaleFactor);
337}
338
340 return g_Platform->GetChartScaleFactorExp(g_ChartScaleFactor);
341}
342
343wxFont GetOCPNGUIScaledFont_PlugIn(wxString item) {
344 return GetOCPNGUIScaledFont(item);
345}
346
347bool AddPersistentFontKey(wxString TextElement) {
348 return FontMgr::Get().AddAuxKey(TextElement);
349}
350
352 if (g_StyleManager)
353 return g_StyleManager->GetCurrentStyle()->name;
354 else
355 return _T("");
356}
357
358wxBitmap GetBitmapFromSVGFile(wxString filename, unsigned int width,
359 unsigned int height) {
360 wxBitmap bmp = LoadSVG(filename, width, height);
361
362 if (bmp.IsOk())
363 return bmp;
364 else {
365 // On error in requested width/height parameters,
366 // try to find and use dimensions embedded in the SVG file
367 unsigned int w, h;
368 SVGDocumentPixelSize(filename, w, h);
369 if (w == 0 || h == 0) {
370 // We did not succeed in deducing the size from SVG (svg element
371 // x misses width, height or both attributes), let's use some "safe"
372 // default
373 w = 32;
374 h = 32;
375 }
376 return LoadSVG(filename, w, h);
377 }
378}
379
380bool IsTouchInterface_PlugIn(void) { return g_btouch; }
381
382wxColour GetFontColour_PlugIn(wxString TextElement) {
383 return FontMgr::Get().GetFontColor(TextElement);
384}
385
386wxString* GetpSharedDataLocation(void) {
387 return g_Platform->GetSharedDataDirPtr();
388}
389
390ArrayOfPlugIn_AIS_Targets* GetAISTargetArray(void) {
391 if (!g_pAIS) return NULL;
392
393 ArrayOfPlugIn_AIS_Targets* pret = new ArrayOfPlugIn_AIS_Targets;
394
395 // Iterate over the AIS Target Hashmap
396 for (const auto& it : g_pAIS->GetTargetList()) {
397 auto td = it.second;
398 PlugIn_AIS_Target* ptarget = Create_PI_AIS_Target(td.get());
399 pret->Add(ptarget);
400 }
401
402// Test one alarm target
403#if 0
404 AisTargetData td;
405 td.n_alarm_state = AIS_ALARM_SET;
406 PlugIn_AIS_Target *ptarget = Create_PI_AIS_Target(&td);
407 pret->Add(ptarget);
408#endif
409 return pret;
410}
411
412wxAuiManager* GetFrameAuiManager(void) { return g_pauimgr; }
413
414void SendPluginMessage(wxString message_id, wxString message_body) {
415 SendMessageToAllPlugins(message_id, message_body);
416
417 // We will send an event to the main application frame (gFrame)
418 // for informational purposes.
419 // Of course, gFrame is encouraged to use any or all the
420 // data flying by if judged useful and dependable....
421
422 OCPN_MsgEvent Nevent(wxEVT_OCPN_MSG, 0);
423 Nevent.SetID(message_id);
424 Nevent.SetJSONText(message_body);
425 gFrame->GetEventHandler()->AddPendingEvent(Nevent);
426}
427
428void DimeWindow(wxWindow* win) { DimeControl(win); }
429
430void JumpToPosition(double lat, double lon, double scale) {
431 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), lat, lon, scale);
432}
433
434/* Locale (i18N) support */
435bool AddLocaleCatalog(wxString catalog) {
436#if wxUSE_XLOCALE || !wxCHECK_VERSION(3, 0, 0)
437
438 if (plocale_def_lang) {
439 // Add this catalog to the persistent catalog array
440 g_locale_catalog_array.Add(catalog);
441
442 return plocale_def_lang->AddCatalog(catalog);
443 } else
444#endif
445 return false;
446}
447
448wxString GetLocaleCanonicalName() { return g_locale; }
449
450/* NMEA interface support */
451void PushNMEABuffer(wxString buf) {
452 std::string full_sentence = buf.ToStdString();
453
454 if ((full_sentence[0] == '$') || (full_sentence[0] == '!')) { // Sanity check
455 std::string identifier;
456 // We notify based on full message, including the Talker ID
457 identifier = full_sentence.substr(1, 5);
458
459 // notify message listener and also "ALL" N0183 messages, to support plugin
460 // API using original talker id
461 auto address = std::make_shared<NavAddr0183>("virtual");
462 auto msg =
463 std::make_shared<const Nmea0183Msg>(identifier, full_sentence, address);
464 auto msg_all = std::make_shared<const Nmea0183Msg>(*msg, "ALL");
465
466 auto& msgbus = NavMsgBus::GetInstance();
467
468 msgbus.Notify(std::move(msg));
469 msgbus.Notify(std::move(msg_all));
470 }
471}
472
473/* Chart database access support */
474wxXmlDocument GetChartDatabaseEntryXML(int dbIndex, bool b_getGeom) {
475 wxXmlDocument doc = ChartData->GetXMLDescription(dbIndex, b_getGeom);
476
477 return doc;
478}
479
480bool UpdateChartDBInplace(wxArrayString dir_array, bool b_force_update,
481 bool b_ProgressDialog) {
482 // Make an array of CDI
483 ArrayOfCDI ChartDirArray;
484 for (unsigned int i = 0; i < dir_array.GetCount(); i++) {
485 wxString dirname = dir_array[i];
486 ChartDirInfo cdi;
487 cdi.fullpath = dirname;
488 cdi.magic_number = _T("");
489 ChartDirArray.Add(cdi);
490 }
491 bool b_ret = gFrame->UpdateChartDatabaseInplace(ChartDirArray, b_force_update,
492 b_ProgressDialog,
493 ChartData->GetDBFileName());
494 gFrame->ChartsRefresh();
495 return b_ret;
496}
497
499 return ChartData->GetChartDirArrayString();
500}
501
502int AddChartToDBInPlace(wxString& full_path, bool b_RefreshCanvas) {
503 // extract the path from the chart name
504 wxFileName fn(full_path);
505 wxString fdir = fn.GetPath();
506
507 bool bret = false;
508 if (ChartData) {
509 bret = ChartData->AddSingleChart(full_path);
510
511 if (bret) {
512 // Save to disk
513 pConfig->UpdateChartDirs(ChartData->GetChartDirArray());
514 ChartData->SaveBinary(ChartListFileName);
515
516 // Completely reload the chart database, for a fresh start
517 ArrayOfCDI XnewChartDirArray;
518 pConfig->LoadChartDirArray(XnewChartDirArray);
519 delete ChartData;
520 ChartData = new ChartDB();
521 ChartData->LoadBinary(ChartListFileName, XnewChartDirArray);
522
523 // Update group contents
524 if (g_pGroupArray) ChartData->ApplyGroupArray(g_pGroupArray);
525
526 if (g_options && g_options->IsShown())
527 g_options->UpdateDisplayedChartDirList(ChartData->GetChartDirArray());
528
529 if (b_RefreshCanvas || !gFrame->GetPrimaryCanvas()->GetQuiltMode()) {
530 gFrame->ChartsRefresh();
531 }
532 }
533 }
534 return bret;
535}
536
537int RemoveChartFromDBInPlace(wxString& full_path) {
538 bool bret = false;
539 if (ChartData) {
540 bret = ChartData->RemoveSingleChart(full_path);
541
542 // Save to disk
543 pConfig->UpdateChartDirs(ChartData->GetChartDirArray());
544 ChartData->SaveBinary(ChartListFileName);
545
546 // Completely reload the chart database, for a fresh start
547 ArrayOfCDI XnewChartDirArray;
548 pConfig->LoadChartDirArray(XnewChartDirArray);
549 delete ChartData;
550 ChartData = new ChartDB();
551 ChartData->LoadBinary(ChartListFileName, XnewChartDirArray);
552
553 // Update group contents
554 if (g_pGroupArray) ChartData->ApplyGroupArray(g_pGroupArray);
555
556 if (g_options && g_options->IsShown())
557 g_options->UpdateDisplayedChartDirList(ChartData->GetChartDirArray());
558
559 gFrame->ChartsRefresh();
560 }
561
562 return bret;
563}
564
565//---------------------------------------------------------------------------
566// API 1.9
567//---------------------------------------------------------------------------
568wxScrolledWindow* AddOptionsPage(OptionsParentPI parent, wxString title) {
569 if (!g_pOptions) return NULL;
570
571 size_t parentid;
572 switch (parent) {
574 parentid = g_pOptions->m_pageDisplay;
575 break;
577 parentid = g_pOptions->m_pageConnections;
578 break;
580 parentid = g_pOptions->m_pageCharts;
581 break;
583 parentid = g_pOptions->m_pageShips;
584 break;
586 parentid = g_pOptions->m_pageUI;
587 break;
589 parentid = g_pOptions->m_pagePlugins;
590 break;
591 default:
592 wxLogMessage(
593 _T("Error in PluginManager::AddOptionsPage: Unknown parent"));
594 return NULL;
595 break;
596 }
597
598 return g_pOptions->AddPage(parentid, title);
599}
600
601bool DeleteOptionsPage(wxScrolledWindow* page) {
602 if (!g_pOptions) return false;
603 return g_pOptions->DeletePluginPage(page);
604}
605
606bool DecodeSingleVDOMessage(const wxString& str, PlugIn_Position_Fix_Ex* pos,
607 wxString* accumulator) {
608 if (!pos) return false;
609
610 GenericPosDatEx gpd;
611 AisError nerr = AIS_GENERIC_ERROR;
612 if (g_pAIS) nerr = g_pAIS->DecodeSingleVDO(str, &gpd, accumulator);
613 if (nerr == AIS_NoError) {
614 pos->Lat = gpd.kLat;
615 pos->Lon = gpd.kLon;
616 pos->Cog = gpd.kCog;
617 pos->Sog = gpd.kSog;
618 pos->Hdt = gpd.kHdt;
619
620 // Fill in the dummy values
621 pos->FixTime = 0;
622 pos->Hdm = 1000;
623 pos->Var = 1000;
624 pos->nSats = 0;
625
626 return true;
627 }
628
629 return false;
630}
631
633 int val = 0;
634 if (g_bShowChartBar) {
635 ChartCanvas* cc = gFrame->GetPrimaryCanvas();
636 if (cc && cc->GetPiano()) {
637 val = cc->GetPiano()->GetHeight();
638 }
639 }
640 return val;
641}
642
643bool GetRoutepointGPX(RoutePoint* pRoutePoint, char* buffer,
644 unsigned int buffer_length) {
645 bool ret = false;
646
648 pgpx->AddGPXWaypoint(pRoutePoint);
649 wxString gpxfilename = wxFileName::CreateTempFileName(wxT("gpx"));
650 pgpx->SaveFile(gpxfilename);
651 delete pgpx;
652
653 wxFFile gpxfile(gpxfilename);
654 wxString s;
655 if (gpxfile.ReadAll(&s)) {
656 if (s.Length() < buffer_length) {
657 strncpy(buffer, (const char*)s.mb_str(wxConvUTF8), buffer_length - 1);
658 ret = true;
659 }
660 }
661
662 gpxfile.Close();
663 ::wxRemoveFile(gpxfilename);
664
665 return ret;
666}
667
668bool GetActiveRoutepointGPX(char* buffer, unsigned int buffer_length) {
669 if (g_pRouteMan->IsAnyRouteActive())
670 return GetRoutepointGPX(g_pRouteMan->GetpActivePoint(), buffer,
671 buffer_length);
672 else
673 return false;
674}
675
676void PositionBearingDistanceMercator_Plugin(double lat, double lon, double brg,
677 double dist, double* dlat,
678 double* dlon) {
679 PositionBearingDistanceMercator(lat, lon, brg, dist, dlat, dlon);
680}
681
682void DistanceBearingMercator_Plugin(double lat0, double lon0, double lat1,
683 double lon1, double* brg, double* dist) {
684 DistanceBearingMercator(lat0, lon0, lat1, lon1, brg, dist);
685}
686
687double DistGreatCircle_Plugin(double slat, double slon, double dlat,
688 double dlon) {
689 return DistGreatCircle(slat, slon, dlat, dlon);
690}
691
692void toTM_Plugin(float lat, float lon, float lat0, float lon0, double* x,
693 double* y) {
694 toTM(lat, lon, lat0, lon0, x, y);
695}
696
697void fromTM_Plugin(double x, double y, double lat0, double lon0, double* lat,
698 double* lon) {
699 fromTM(x, y, lat0, lon0, lat, lon);
700}
701
702void toSM_Plugin(double lat, double lon, double lat0, double lon0, double* x,
703 double* y) {
704 toSM(lat, lon, lat0, lon0, x, y);
705}
706
707void fromSM_Plugin(double x, double y, double lat0, double lon0, double* lat,
708 double* lon) {
709 fromSM(x, y, lat0, lon0, lat, lon);
710}
711
712void toSM_ECC_Plugin(double lat, double lon, double lat0, double lon0,
713 double* x, double* y) {
714 toSM_ECC(lat, lon, lat0, lon0, x, y);
715}
716
717void fromSM_ECC_Plugin(double x, double y, double lat0, double lon0,
718 double* lat, double* lon) {
719 fromSM_ECC(x, y, lat0, lon0, lat, lon);
720}
721
722double toUsrDistance_Plugin(double nm_distance, int unit) {
723 return toUsrDistance(nm_distance, unit);
724}
725
726double fromUsrDistance_Plugin(double usr_distance, int unit) {
727 return fromUsrDistance(usr_distance, unit);
728}
729
730double toUsrSpeed_Plugin(double kts_speed, int unit) {
731 return toUsrSpeed(kts_speed, unit);
732}
733
734double toUsrWindSpeed_Plugin(double kts_speed, int unit) {
735 return toUsrWindSpeed(kts_speed, unit);
736}
737
738double fromUsrSpeed_Plugin(double usr_speed, int unit) {
739 return fromUsrSpeed(usr_speed, unit);
740}
741
742double fromUsrWindSpeed_Plugin(double usr_wspeed, int unit) {
743 return fromUsrWindSpeed(usr_wspeed, unit);
744}
745
746double toUsrTemp_Plugin(double cel_temp, int unit) {
747 return toUsrTemp(cel_temp, unit);
748}
749
750double fromUsrTemp_Plugin(double usr_temp, int unit) {
751 return fromUsrTemp(usr_temp, unit);
752}
753
755 return getUsrDistanceUnit(unit);
756}
757
758wxString getUsrSpeedUnit_Plugin(int unit) { return getUsrSpeedUnit(unit); }
759
761 return getUsrWindSpeedUnit(unit);
762}
763
764wxString getUsrTempUnit_Plugin(int unit) { return getUsrTempUnit(unit); }
765
766/*
767 * Depth Conversion Functions
768 */
769double toUsrDepth_Plugin(double m_depth, int unit) {
770 return toUsrDepth(m_depth, unit);
771}
772
773double fromUsrDepth_Plugin(double usr_depth, int unit) {
774 return fromUsrDepth(usr_depth, unit);
775}
776
777wxString getUsrDepthUnit_Plugin(int unit) { return getUsrDepthUnit(unit); }
778
779double fromDMM_PlugIn(wxString sdms) { return fromDMM(sdms); }
780
781bool PlugIn_GSHHS_CrossesLand(double lat1, double lon1, double lat2,
782 double lon2) {
783 // TODO: Enable call to gShapeBasemap.CrossesLand after fixing performance
784 // issues. if (gShapeBasemap.IsUsable()) {
785 // return gShapeBasemap.CrossesLand(lat1, lon1, lat2, lon2);
786 // } else {
787 // Fall back to the GSHHS data.
788 static bool loaded = false;
789 if (!loaded) {
790 gshhsCrossesLandInit();
791 loaded = true;
792 }
793 return gshhsCrossesLand(lat1, lon1, lat2, lon2);
794 //}
795}
796
797void PlugInPlaySound(wxString& sound_file) {
798 PlugInPlaySoundEx(sound_file, -1);
799}
800
801//---------------------------------------------------------------------------
802// API 1.10
803//---------------------------------------------------------------------------
804
805// API Route and Waypoint Support
807
808PlugIn_Waypoint::PlugIn_Waypoint(double lat, double lon,
809 const wxString& icon_ident,
810 const wxString& wp_name,
811 const wxString& GUID) {
812 wxDateTime now = wxDateTime::Now();
813 m_CreateTime = now.ToUTC();
814 m_HyperlinkList = NULL;
815
816 m_lat = lat;
817 m_lon = lon;
818 m_IconName = icon_ident;
819 m_MarkName = wp_name;
820 m_GUID = GUID;
821}
822
823PlugIn_Waypoint::~PlugIn_Waypoint() {}
824
825// PlugInRoute implementation
826PlugIn_Route::PlugIn_Route(void) { pWaypointList = new Plugin_WaypointList; }
827
828PlugIn_Route::~PlugIn_Route(void) {
829 pWaypointList->DeleteContents(false); // do not delete Waypoints
830 pWaypointList->Clear();
831
832 delete pWaypointList;
833}
834
835// PlugInTrack implementation
836PlugIn_Track::PlugIn_Track(void) { pWaypointList = new Plugin_WaypointList; }
837
838PlugIn_Track::~PlugIn_Track(void) {
839 pWaypointList->DeleteContents(false); // do not delete Waypoints
840 pWaypointList->Clear();
841
842 delete pWaypointList;
843}
844
845wxString GetNewGUID(void) { return GpxDocument::GetUUID(); }
846
847bool AddCustomWaypointIcon(wxBitmap* pimage, wxString key,
848 wxString description) {
849 wxImage image = pimage->ConvertToImage();
850 WayPointmanGui(*pWayPointMan).ProcessIcon(image, key, description);
851 return true;
852}
853
854static void cloneHyperlinkList(RoutePoint* dst, const PlugIn_Waypoint* src) {
855 // Transcribe (clone) the html HyperLink List, if present
856 if (src->m_HyperlinkList == nullptr) return;
857
858 if (src->m_HyperlinkList->GetCount() > 0) {
859 wxPlugin_HyperlinkListNode* linknode = src->m_HyperlinkList->GetFirst();
860 while (linknode) {
861 Plugin_Hyperlink* link = linknode->GetData();
862
863 Hyperlink* h = new Hyperlink();
864 h->DescrText = link->DescrText;
865 h->Link = link->Link;
866 h->LType = link->Type;
867
868 dst->m_HyperlinkList->Append(h);
869
870 linknode = linknode->GetNext();
871 }
872 }
873}
874
875bool AddSingleWaypoint(PlugIn_Waypoint* pwaypoint, bool b_permanent) {
876 // Validate the waypoint parameters a little bit
877
878 // GUID
879 // Make sure that this GUID is indeed unique in the Routepoint list
880 bool b_unique = true;
881 wxRoutePointListNode* prpnode = pWayPointMan->GetWaypointList()->GetFirst();
882 while (prpnode) {
883 RoutePoint* prp = prpnode->GetData();
884
885 if (prp->m_GUID == pwaypoint->m_GUID) {
886 b_unique = false;
887 break;
888 }
889 prpnode = prpnode->GetNext(); // RoutePoint
890 }
891
892 if (!b_unique) return false;
893
894 RoutePoint* pWP =
895 new RoutePoint(pwaypoint->m_lat, pwaypoint->m_lon, pwaypoint->m_IconName,
896 pwaypoint->m_MarkName, pwaypoint->m_GUID);
897
898 pWP->m_bIsolatedMark = true; // This is an isolated mark
899
900 cloneHyperlinkList(pWP, pwaypoint);
901
902 pWP->m_MarkDescription = pwaypoint->m_MarkDescription;
903
904 if (pwaypoint->m_CreateTime.IsValid())
905 pWP->SetCreateTime(pwaypoint->m_CreateTime);
906 else {
907 pWP->SetCreateTime(wxDateTime::Now().ToUTC());
908 }
909
910 pWP->m_btemp = (b_permanent == false);
911
912 pSelect->AddSelectableRoutePoint(pwaypoint->m_lat, pwaypoint->m_lon, pWP);
913 if (b_permanent) {
914 // pConfig->AddNewWayPoint(pWP, -1);
915 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
916 }
917
918 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
919 pRouteManagerDialog->UpdateWptListCtrl();
920
921 return true;
922}
923
924bool DeleteSingleWaypoint(wxString& GUID) {
925 // Find the RoutePoint
926 bool b_found = false;
927 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(GUID);
928
929 if (prp) b_found = true;
930
931 if (b_found) {
932 pWayPointMan->DestroyWaypoint(prp);
933 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
934 pRouteManagerDialog->UpdateWptListCtrl();
935 }
936
937 return b_found;
938}
939
941 // Find the RoutePoint
942 bool b_found = false;
943 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(pwaypoint->m_GUID);
944
945 if (prp) b_found = true;
946
947 if (b_found) {
948 double lat_save = prp->m_lat;
949 double lon_save = prp->m_lon;
950
951 prp->m_lat = pwaypoint->m_lat;
952 prp->m_lon = pwaypoint->m_lon;
953 prp->SetIconName(pwaypoint->m_IconName);
954 prp->SetName(pwaypoint->m_MarkName);
955 prp->m_MarkDescription = pwaypoint->m_MarkDescription;
956 prp->SetVisible(pwaypoint->m_IsVisible);
957 if (pwaypoint->m_CreateTime.IsValid())
958 prp->SetCreateTime(pwaypoint->m_CreateTime);
959
960 // Transcribe (clone) the html HyperLink List, if present
961
962 if (pwaypoint->m_HyperlinkList) {
963 prp->m_HyperlinkList->Clear();
964 if (pwaypoint->m_HyperlinkList->GetCount() > 0) {
965 wxPlugin_HyperlinkListNode* linknode =
966 pwaypoint->m_HyperlinkList->GetFirst();
967 while (linknode) {
968 Plugin_Hyperlink* link = linknode->GetData();
969
970 Hyperlink* h = new Hyperlink();
971 h->DescrText = link->DescrText;
972 h->Link = link->Link;
973 h->LType = link->Type;
974
975 prp->m_HyperlinkList->Append(h);
976
977 linknode = linknode->GetNext();
978 }
979 }
980 }
981
982 if (prp) prp->ReLoadIcon();
983
984 auto canvas = gFrame->GetPrimaryCanvas();
985 SelectCtx ctx(canvas->m_bShowNavobjects, canvas->GetCanvasTrueScale(),
986 canvas->GetScaleValue());
987 SelectItem* pFind =
988 pSelect->FindSelection(ctx, lat_save, lon_save, SELTYPE_ROUTEPOINT);
989 if (pFind) {
990 pFind->m_slat = pwaypoint->m_lat; // update the SelectList entry
991 pFind->m_slon = pwaypoint->m_lon;
992 }
993
994 if (!prp->m_btemp) {
995 // pConfig->UpdateWayPoint(prp);
996 NavObj_dB::GetInstance().UpdateRoutePoint(prp);
997 }
998
999 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
1000 pRouteManagerDialog->UpdateWptListCtrl();
1001 }
1002
1003 return b_found;
1004}
1005
1006// translate O route class to Plugin one
1007static void PlugInFromRoutePoint(PlugIn_Waypoint* dst,
1008 /* const*/ RoutePoint* src) {
1009 dst->m_lat = src->m_lat;
1010 dst->m_lon = src->m_lon;
1011 dst->m_IconName = src->GetIconName();
1012 dst->m_MarkName = src->GetName();
1014 dst->m_IsVisible = src->IsVisible();
1015 dst->m_CreateTime = src->GetCreateTime(); // not const
1016 dst->m_GUID = src->m_GUID;
1017
1018 // Transcribe (clone) the html HyperLink List, if present
1019 if (src->m_HyperlinkList == nullptr) return;
1020
1021 delete dst->m_HyperlinkList;
1022 dst->m_HyperlinkList = nullptr;
1023
1024 if (src->m_HyperlinkList->GetCount() > 0) {
1025 dst->m_HyperlinkList = new Plugin_HyperlinkList;
1026
1027 wxHyperlinkListNode* linknode = src->m_HyperlinkList->GetFirst();
1028 while (linknode) {
1029 Hyperlink* link = linknode->GetData();
1030
1032 h->DescrText = link->DescrText;
1033 h->Link = link->Link;
1034 h->Type = link->LType;
1035
1036 dst->m_HyperlinkList->Append(h);
1037
1038 linknode = linknode->GetNext();
1039 }
1040 }
1041}
1042
1043bool GetSingleWaypoint(wxString GUID, PlugIn_Waypoint* pwaypoint) {
1044 // Find the RoutePoint
1045 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(GUID);
1046
1047 if (!prp) return false;
1048
1049 PlugInFromRoutePoint(pwaypoint, prp);
1050
1051 return true;
1052}
1053
1054wxArrayString GetWaypointGUIDArray(void) {
1055 wxArrayString result;
1056 const RoutePointList* list = pWayPointMan->GetWaypointList();
1057
1058 wxRoutePointListNode* prpnode = list->GetFirst();
1059 while (prpnode) {
1060 RoutePoint* prp = prpnode->GetData();
1061 result.Add(prp->m_GUID);
1062
1063 prpnode = prpnode->GetNext(); // RoutePoint
1064 }
1065
1066 return result;
1067}
1068
1069wxArrayString GetRouteGUIDArray(void) {
1070 wxArrayString result;
1071 RouteList* list = pRouteList;
1072
1073 wxRouteListNode* prpnode = list->GetFirst();
1074 while (prpnode) {
1075 Route* proute = prpnode->GetData();
1076 result.Add(proute->m_GUID);
1077
1078 prpnode = prpnode->GetNext(); // Route
1079 }
1080
1081 return result;
1082}
1083
1084wxArrayString GetTrackGUIDArray(void) {
1085 wxArrayString result;
1086 for (Track* ptrack : g_TrackList) {
1087 result.Add(ptrack->m_GUID);
1088 }
1089
1090 return result;
1091}
1092
1094 wxArrayString result;
1095 const RoutePointList* list = pWayPointMan->GetWaypointList();
1096
1097 wxRoutePointListNode* prpnode = list->GetFirst();
1098 while (prpnode) {
1099 RoutePoint* prp = prpnode->GetData();
1100 switch (req) {
1101 case OBJECTS_ALL:
1102 result.Add(prp->m_GUID);
1103 break;
1104 case OBJECTS_NO_LAYERS:
1105 if (!prp->m_bIsInLayer) result.Add(prp->m_GUID);
1106 break;
1108 if (prp->m_bIsInLayer) result.Add(prp->m_GUID);
1109 break;
1110 }
1111
1112 prpnode = prpnode->GetNext(); // RoutePoint
1113 }
1114
1115 return result;
1116}
1117
1119 wxArrayString result;
1120 RouteList* list = pRouteList;
1121
1122 wxRouteListNode* prpnode = list->GetFirst();
1123 while (prpnode) {
1124 Route* proute = prpnode->GetData();
1125 switch (req) {
1126 case OBJECTS_ALL:
1127 result.Add(proute->m_GUID);
1128 break;
1129 case OBJECTS_NO_LAYERS:
1130 if (!proute->m_bIsInLayer) result.Add(proute->m_GUID);
1131 break;
1133 if (proute->m_bIsInLayer) result.Add(proute->m_GUID);
1134 break;
1135 }
1136
1137 prpnode = prpnode->GetNext(); // Route
1138 }
1139
1140 return result;
1141}
1142
1144 wxArrayString result;
1145 for (Track* ptrack : g_TrackList) {
1146 switch (req) {
1147 case OBJECTS_ALL:
1148 result.Add(ptrack->m_GUID);
1149 break;
1150 case OBJECTS_NO_LAYERS:
1151 if (!ptrack->m_bIsInLayer) result.Add(ptrack->m_GUID);
1152 break;
1154 if (ptrack->m_bIsInLayer) result.Add(ptrack->m_GUID);
1155 break;
1156 }
1157 }
1158
1159 return result;
1160}
1161
1162wxArrayString GetIconNameArray(void) {
1163 wxArrayString result;
1164
1165 for (int i = 0; i < pWayPointMan->GetNumIcons(); i++) {
1166 wxString* ps = pWayPointMan->GetIconKey(i);
1167 result.Add(*ps);
1168 }
1169 return result;
1170}
1171
1172bool AddPlugInRoute(PlugIn_Route* proute, bool b_permanent) {
1173 Route* route = new Route();
1174
1175 PlugIn_Waypoint* pwp;
1176 RoutePoint* pWP_src;
1177 int ip = 0;
1178 wxDateTime plannedDeparture;
1179
1180 wxPlugin_WaypointListNode* pwpnode = proute->pWaypointList->GetFirst();
1181 while (pwpnode) {
1182 pwp = pwpnode->GetData();
1183
1184 RoutePoint* pWP = new RoutePoint(pwp->m_lat, pwp->m_lon, pwp->m_IconName,
1185 pwp->m_MarkName, pwp->m_GUID);
1186
1187 // Transcribe (clone) the html HyperLink List, if present
1188 cloneHyperlinkList(pWP, pwp);
1190 pWP->m_bShowName = false;
1191 pWP->SetCreateTime(pwp->m_CreateTime);
1192
1193 route->AddPoint(pWP);
1194
1195 pSelect->AddSelectableRoutePoint(pWP->m_lat, pWP->m_lon, pWP);
1196
1197 if (ip > 0)
1198 pSelect->AddSelectableRouteSegment(pWP_src->m_lat, pWP_src->m_lon,
1199 pWP->m_lat, pWP->m_lon, pWP_src, pWP,
1200 route);
1201 else
1202 plannedDeparture = pwp->m_CreateTime;
1203 ip++;
1204 pWP_src = pWP;
1205
1206 pwpnode = pwpnode->GetNext(); // PlugInWaypoint
1207 }
1208
1209 route->m_PlannedDeparture = plannedDeparture;
1210
1211 route->m_RouteNameString = proute->m_NameString;
1212 route->m_RouteStartString = proute->m_StartString;
1213 route->m_RouteEndString = proute->m_EndString;
1214 if (!proute->m_GUID.IsEmpty()) {
1215 route->m_GUID = proute->m_GUID;
1216 }
1217 route->m_btemp = (b_permanent == false);
1218
1219 pRouteList->Append(route);
1220
1221 if (b_permanent) {
1222 // pConfig->AddNewRoute(route);
1223 NavObj_dB::GetInstance().InsertRoute(route);
1224 }
1225 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
1226 pRouteManagerDialog->UpdateRouteListCtrl();
1227
1228 return true;
1229}
1230
1231bool DeletePlugInRoute(wxString& GUID) {
1232 bool b_found = false;
1233
1234 // Find the Route
1235 Route* pRoute = g_pRouteMan->FindRouteByGUID(GUID);
1236 if (pRoute) {
1237 g_pRouteMan->DeleteRoute(pRoute);
1238 b_found = true;
1239 }
1240 return b_found;
1241}
1242
1244 bool b_found = false;
1245
1246 // Find the Route
1247 Route* pRoute = g_pRouteMan->FindRouteByGUID(proute->m_GUID);
1248 if (pRoute) b_found = true;
1249
1250 if (b_found) {
1251 bool b_permanent = (pRoute->m_btemp == false);
1252 g_pRouteMan->DeleteRoute(pRoute);
1253 b_found = AddPlugInRoute(proute, b_permanent);
1254 }
1255
1256 return b_found;
1257}
1258
1259bool AddPlugInTrack(PlugIn_Track* ptrack, bool b_permanent) {
1260 Track* track = new Track();
1261
1262 PlugIn_Waypoint* pwp = 0;
1263 TrackPoint* pWP_src = 0;
1264 int ip = 0;
1265
1266 wxPlugin_WaypointListNode* pwpnode = ptrack->pWaypointList->GetFirst();
1267 while (pwpnode) {
1268 pwp = pwpnode->GetData();
1269
1270 TrackPoint* pWP = new TrackPoint(pwp->m_lat, pwp->m_lon);
1271 pWP->SetCreateTime(pwp->m_CreateTime);
1272
1273 track->AddPoint(pWP);
1274
1275 if (ip > 0)
1276 pSelect->AddSelectableTrackSegment(pWP_src->m_lat, pWP_src->m_lon,
1277 pWP->m_lat, pWP->m_lon, pWP_src, pWP,
1278 track);
1279 ip++;
1280 pWP_src = pWP;
1281
1282 pwpnode = pwpnode->GetNext(); // PlugInWaypoint
1283 }
1284
1285 track->SetName(ptrack->m_NameString);
1286 track->m_TrackStartString = ptrack->m_StartString;
1287 track->m_TrackEndString = ptrack->m_EndString;
1288 track->m_GUID = ptrack->m_GUID;
1289 track->m_btemp = (b_permanent == false);
1290
1291 g_TrackList.push_back(track);
1292 if (b_permanent) NavObj_dB::GetInstance().InsertTrack(track);
1293 // if (b_permanent) pConfig->AddNewTrack(track);
1294
1295 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
1296 pRouteManagerDialog->UpdateTrkListCtrl();
1297
1298 return true;
1299}
1300
1301bool DeletePlugInTrack(wxString& GUID) {
1302 bool b_found = false;
1303
1304 // Find the Route
1305 Track* pTrack = g_pRouteMan->FindTrackByGUID(GUID);
1306 if (pTrack) {
1307 NavObj_dB::GetInstance().DeleteTrack(pTrack);
1308 RoutemanGui(*g_pRouteMan).DeleteTrack(pTrack);
1309 b_found = true;
1310 }
1311
1312 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
1313 pRouteManagerDialog->UpdateTrkListCtrl();
1314
1315 return b_found;
1316}
1317
1319 bool b_found = false;
1320
1321 // Find the Track
1322 Track* pTrack = g_pRouteMan->FindTrackByGUID(ptrack->m_GUID);
1323 if (pTrack) b_found = true;
1324
1325 if (b_found) {
1326 bool b_permanent = (pTrack->m_btemp == false);
1327 NavObj_dB::GetInstance().DeleteTrack(pTrack);
1328 RoutemanGui(*g_pRouteMan).DeleteTrack(pTrack);
1329
1330 b_found = AddPlugInTrack(ptrack, b_permanent);
1331 }
1332
1333 return b_found;
1334}
1335
1337#ifdef ocpnUSE_GL
1338 ViewPort ocpn_vp;
1339 ocpn_vp.m_projection_type = vp->m_projection_type;
1340
1341 return glChartCanvas::HasNormalizedViewPort(ocpn_vp);
1342#else
1343 return false;
1344#endif
1345}
1346
1347void PlugInMultMatrixViewport(PlugIn_ViewPort* vp, float lat, float lon) {
1348#ifdef ocpnUSE_GL
1349 ViewPort ocpn_vp;
1350 ocpn_vp.clat = vp->clat;
1351 ocpn_vp.clon = vp->clon;
1352 ocpn_vp.m_projection_type = vp->m_projection_type;
1353 ocpn_vp.view_scale_ppm = vp->view_scale_ppm;
1354 ocpn_vp.skew = vp->skew;
1355 ocpn_vp.rotation = vp->rotation;
1356 ocpn_vp.pix_width = vp->pix_width;
1357 ocpn_vp.pix_height = vp->pix_height;
1358
1359// TODO fix for multicanvas glChartCanvas::MultMatrixViewPort(ocpn_vp, lat,
1360// lon);
1361#endif
1362}
1363
1364void PlugInNormalizeViewport(PlugIn_ViewPort* vp, float lat, float lon) {
1365#ifdef ocpnUSE_GL
1366 ViewPort ocpn_vp;
1367 glChartCanvas::NormalizedViewPort(ocpn_vp, lat, lon);
1368
1369 vp->clat = ocpn_vp.clat;
1370 vp->clon = ocpn_vp.clon;
1371 vp->view_scale_ppm = ocpn_vp.view_scale_ppm;
1372 vp->rotation = ocpn_vp.rotation;
1373 vp->skew = ocpn_vp.skew;
1374#endif
1375}
1376
1377// Helper and interface classes
1378
1379//-------------------------------------------------------------------------------
1380// PlugIn_AIS_Target Implementation
1381//-------------------------------------------------------------------------------
1382
1383PlugIn_AIS_Target* Create_PI_AIS_Target(AisTargetData* ptarget) {
1385
1386 pret->MMSI = ptarget->MMSI;
1387 pret->Class = ptarget->Class;
1388 pret->NavStatus = ptarget->NavStatus;
1389 pret->SOG = ptarget->SOG;
1390 pret->COG = ptarget->COG;
1391 pret->HDG = ptarget->HDG;
1392 pret->Lon = ptarget->Lon;
1393 pret->Lat = ptarget->Lat;
1394 pret->ROTAIS = ptarget->ROTAIS;
1395 pret->ShipType = ptarget->ShipType;
1396 pret->IMO = ptarget->IMO;
1397
1398 pret->Range_NM = ptarget->Range_NM;
1399 pret->Brg = ptarget->Brg;
1400
1401 // Per target collision parameters
1402 pret->bCPA_Valid = ptarget->bCPA_Valid;
1403 pret->TCPA = ptarget->TCPA; // Minutes
1404 pret->CPA = ptarget->CPA; // Nautical Miles
1405
1406 pret->alarm_state = (plugin_ais_alarm_type)ptarget->n_alert_state;
1407
1408 memcpy(pret->CallSign, ptarget->CallSign, sizeof(ptarget->CallSign) - 1);
1409 memcpy(pret->ShipName, ptarget->ShipName, sizeof(ptarget->ShipName) - 1);
1410
1411 return pret;
1412}
1413
1414//---------------------------------------------------------------------------
1415// API 1.11
1416//---------------------------------------------------------------------------
1417
1418//---------------------------------------------------------------------------
1419// API 1.12
1420//---------------------------------------------------------------------------
1421
1422//---------------------------------------------------------------------------
1423// API 1.13
1424//---------------------------------------------------------------------------
1425double fromDMM_Plugin(wxString sdms) { return fromDMM(sdms); }
1426
1427void SetCanvasRotation(double rotation) {
1428 gFrame->GetPrimaryCanvas()->DoRotateCanvas(rotation);
1429}
1430
1431double GetCanvasTilt() { return gFrame->GetPrimaryCanvas()->GetVPTilt(); }
1432
1433void SetCanvasTilt(double tilt) {
1434 gFrame->GetPrimaryCanvas()->DoTiltCanvas(tilt);
1435}
1436
1437void SetCanvasProjection(int projection) {
1438 gFrame->GetPrimaryCanvas()->SetVPProjection(projection);
1439}
1440
1441OcpnSound* g_PluginSound = SoundFactory();
1442static void onPlugInPlaySoundExFinished(void* ptr) {}
1443
1444// Start playing a sound to a given device and return status to plugin
1445bool PlugInPlaySoundEx(wxString& sound_file, int deviceIndex) {
1446 bool ok = g_PluginSound->Load(sound_file, deviceIndex);
1447 if (!ok) {
1448 wxLogWarning("Cannot load sound file: %s", sound_file);
1449 return false;
1450 }
1451 auto cmd_sound = dynamic_cast<SystemCmdSound*>(g_PluginSound);
1452 if (cmd_sound) cmd_sound->SetCmd(g_CmdSoundString.mb_str(wxConvUTF8));
1453
1454 g_PluginSound->SetFinishedCallback(onPlugInPlaySoundExFinished, NULL);
1455 ok = g_PluginSound->Play();
1456 if (!ok) {
1457 wxLogWarning("Cannot play sound file: %s", sound_file);
1458 }
1459 return ok;
1460}
1461
1462bool CheckEdgePan_PlugIn(int x, int y, bool dragging, int margin, int delta) {
1463 return gFrame->GetPrimaryCanvas()->CheckEdgePan(x, y, dragging, margin,
1464 delta);
1465}
1466
1467wxBitmap GetIcon_PlugIn(const wxString& name) {
1468 ocpnStyle::Style* style = g_StyleManager->GetCurrentStyle();
1469 return style->GetIcon(name);
1470}
1471
1472void SetCursor_PlugIn(wxCursor* pCursor) {
1473 gFrame->GetPrimaryCanvas()->pPlugIn_Cursor = pCursor;
1474}
1475
1476void AddChartDirectory(wxString& path) {
1477 if (g_options) {
1478 g_options->AddChartDir(path);
1479 }
1480}
1481
1483 if (g_options) {
1484 g_options->pScanCheckBox->SetValue(true);
1485 g_options->pUpdateCheckBox->SetValue(true);
1486 }
1487}
1488
1490 if (g_options) {
1491 g_options->pUpdateCheckBox->SetValue(true);
1492 }
1493}
1494
1495wxDialog* GetActiveOptionsDialog() { return g_options; }
1496
1497int PlatformDirSelectorDialog(wxWindow* parent, wxString* file_spec,
1498 wxString Title, wxString initDir) {
1499 return g_Platform->DoDirSelectorDialog(parent, file_spec, Title, initDir);
1500}
1501
1502int PlatformFileSelectorDialog(wxWindow* parent, wxString* file_spec,
1503 wxString Title, wxString initDir,
1504 wxString suggestedName, wxString wildcard) {
1505 return g_Platform->DoFileSelectorDialog(parent, file_spec, Title, initDir,
1506 suggestedName, wildcard);
1507}
1508
1509//---------------------------------------------------------------------------
1510// API 1.14
1511//---------------------------------------------------------------------------
1512
1513ViewPort CreateCompatibleViewportEx(const PlugIn_ViewPort& pivp) {
1514 // Create a system ViewPort
1515 ViewPort vp;
1516
1517 vp.clat = pivp.clat; // center point
1518 vp.clon = pivp.clon;
1520 vp.skew = pivp.skew;
1521 vp.rotation = pivp.rotation;
1522 vp.chart_scale = pivp.chart_scale;
1523 vp.pix_width = pivp.pix_width;
1524 vp.pix_height = pivp.pix_height;
1525 vp.rv_rect = pivp.rv_rect;
1526 vp.b_quilt = pivp.b_quilt;
1527 vp.m_projection_type = pivp.m_projection_type;
1528
1529 if (gFrame->GetPrimaryCanvas())
1530 vp.ref_scale = gFrame->GetPrimaryCanvas()->GetVP().ref_scale;
1531 else
1532 vp.ref_scale = vp.chart_scale;
1533
1534 vp.SetBoxes();
1535 vp.Validate(); // This VP is valid
1536
1537 return vp;
1538}
1539
1540void PlugInAISDrawGL(wxGLCanvas* glcanvas, const PlugIn_ViewPort& vp) {
1541 ViewPort ocpn_vp = CreateCompatibleViewportEx(vp);
1542
1543 ocpnDC dc(*glcanvas);
1544 dc.SetVP(ocpn_vp);
1545
1546 AISDraw(dc, ocpn_vp, NULL);
1547}
1548
1549bool PlugInSetFontColor(const wxString TextElement, const wxColour color) {
1550 return FontMgr::Get().SetFontColor(TextElement, color);
1551}
1552
1553//---------------------------------------------------------------------------
1554// API 1.15
1555//---------------------------------------------------------------------------
1556
1557double PlugInGetDisplaySizeMM() { return g_Platform->GetDisplaySizeMM(); }
1558
1559wxFont* FindOrCreateFont_PlugIn(int point_size, wxFontFamily family,
1560 wxFontStyle style, wxFontWeight weight,
1561 bool underline, const wxString& facename,
1562 wxFontEncoding encoding) {
1563 return FontMgr::Get().FindOrCreateFont(point_size, family, style, weight,
1564 underline, facename, encoding);
1565}
1566
1567int PluginGetMinAvailableGshhgQuality() {
1568 return gFrame->GetPrimaryCanvas()->GetMinAvailableGshhgQuality();
1569}
1570int PluginGetMaxAvailableGshhgQuality() {
1571 return gFrame->GetPrimaryCanvas()->GetMaxAvailableGshhgQuality();
1572}
1573
1574// disable builtin console canvas, and autopilot nmea sentences
1576 g_bPluginHandleAutopilotRoute = enable;
1577}
1578
1579bool LaunchDefaultBrowser_Plugin(wxString url) {
1580 if (g_Platform) g_Platform->platformLaunchDefaultBrowser(url);
1581
1582 return true;
1583}
1584
1585//---------------------------------------------------------------------------
1586// API 1.16
1587//---------------------------------------------------------------------------
1589 ChartCanvas* cc = gFrame->GetFocusCanvas();
1590 if (cc && cc->GetSelectedRoutePoint()) {
1591 return cc->GetSelectedRoutePoint()->m_GUID;
1592 }
1593 return wxEmptyString;
1594}
1595
1597 ChartCanvas* cc = gFrame->GetFocusCanvas();
1598 if (cc && cc->GetSelectedRoute()) {
1599 return cc->GetSelectedRoute()->m_GUID;
1600 }
1601 return wxEmptyString;
1602}
1603
1605 ChartCanvas* cc = gFrame->GetFocusCanvas();
1606 if (cc && cc->GetSelectedTrack()) {
1607 return cc->GetSelectedTrack()->m_GUID;
1608 }
1609 return wxEmptyString;
1610}
1611
1612std::unique_ptr<PlugIn_Waypoint> GetWaypoint_Plugin(const wxString& GUID) {
1613 std::unique_ptr<PlugIn_Waypoint> w(new PlugIn_Waypoint);
1614 GetSingleWaypoint(GUID, w.get());
1615 return w;
1616}
1617
1618std::unique_ptr<PlugIn_Route> GetRoute_Plugin(const wxString& GUID) {
1619 std::unique_ptr<PlugIn_Route> r;
1620 Route* route = g_pRouteMan->FindRouteByGUID(GUID);
1621 if (route == nullptr) return r;
1622
1623 r = std::unique_ptr<PlugIn_Route>(new PlugIn_Route);
1624 PlugIn_Route* dst_route = r.get();
1625
1626 // PlugIn_Waypoint *pwp;
1627 RoutePoint* src_wp;
1628 wxRoutePointListNode* node = route->pRoutePointList->GetFirst();
1629
1630 while (node) {
1631 src_wp = node->GetData();
1632
1633 PlugIn_Waypoint* dst_wp = new PlugIn_Waypoint();
1634 PlugInFromRoutePoint(dst_wp, src_wp);
1635
1636 dst_route->pWaypointList->Append(dst_wp);
1637
1638 node = node->GetNext();
1639 }
1640 dst_route->m_NameString = route->m_RouteNameString;
1641 dst_route->m_StartString = route->m_RouteStartString;
1642 dst_route->m_EndString = route->m_RouteEndString;
1643 dst_route->m_GUID = route->m_GUID;
1644
1645 return r;
1646}
1647
1648std::unique_ptr<PlugIn_Track> GetTrack_Plugin(const wxString& GUID) {
1649 std::unique_ptr<PlugIn_Track> t;
1650 // Find the Track
1651 Track* pTrack = g_pRouteMan->FindTrackByGUID(GUID);
1652 if (!pTrack) return t;
1653
1654 std::unique_ptr<PlugIn_Track> tk =
1655 std::unique_ptr<PlugIn_Track>(new PlugIn_Track);
1656 PlugIn_Track* dst_track = tk.get();
1657 dst_track->m_NameString = pTrack->GetName();
1658 dst_track->m_StartString = pTrack->m_TrackStartString;
1659 dst_track->m_EndString = pTrack->m_TrackEndString;
1660 dst_track->m_GUID = pTrack->m_GUID;
1661
1662 for (int i = 0; i < pTrack->GetnPoints(); i++) {
1663 TrackPoint* ptp = pTrack->GetPoint(i);
1664
1665 PlugIn_Waypoint* dst_wp = new PlugIn_Waypoint();
1666
1667 dst_wp->m_lat = ptp->m_lat;
1668 dst_wp->m_lon = ptp->m_lon;
1669 dst_wp->m_CreateTime = ptp->GetCreateTime(); // not const
1670
1671 dst_track->pWaypointList->Append(dst_wp);
1672 }
1673
1674 return tk;
1675}
1676
1677wxWindow* PluginGetFocusCanvas() { return g_focusCanvas; }
1678
1680 // if(g_overlayCanvas)
1681 return g_overlayCanvas;
1682 // else
1683}
1684
1685void CanvasJumpToPosition(wxWindow* canvas, double lat, double lon,
1686 double scale) {
1687 auto oCanvas = dynamic_cast<ChartCanvas*>(canvas);
1688 if (oCanvas) gFrame->JumpToPosition(oCanvas, lat, lon, scale);
1689}
1690
1691bool ShuttingDown(void) { return g_bquiting; }
1692
1693wxWindow* GetCanvasUnderMouse(void) { return gFrame->GetCanvasUnderMouse(); }
1694
1696 ChartCanvas* l_canvas = gFrame->GetCanvasUnderMouse();
1697 if (l_canvas) {
1698 for (unsigned int i = 0; i < g_canvasArray.GetCount(); ++i) {
1699 if (l_canvas == g_canvasArray[i]) return i;
1700 }
1701 }
1702 return 0;
1703}
1704
1705// std::vector<wxWindow *> GetCanvasArray()
1706// {
1707// std::vector<wxWindow *> rv;
1708// for(unsigned int i=0 ; i < g_canvasArray.GetCount() ; i++){
1709// ChartCanvas *cc = g_canvasArray.Item(i);
1710// rv.push_back(cc);
1711// }
1712//
1713// return rv;
1714// }
1715
1716wxWindow* GetCanvasByIndex(int canvasIndex) {
1717 if (g_canvasConfig == 0)
1718 return gFrame->GetPrimaryCanvas();
1719 else {
1720 if ((canvasIndex >= 0) && g_canvasArray[canvasIndex]) {
1721 return g_canvasArray[canvasIndex];
1722 }
1723 }
1724 return NULL;
1725}
1726
1727bool CheckMUIEdgePan_PlugIn(int x, int y, bool dragging, int margin, int delta,
1728 int canvasIndex) {
1729 if (g_canvasConfig == 0)
1730 return gFrame->GetPrimaryCanvas()->CheckEdgePan(x, y, dragging, margin,
1731 delta);
1732 else {
1733 if ((canvasIndex >= 0) && g_canvasArray[canvasIndex]) {
1734 return g_canvasArray[canvasIndex]->CheckEdgePan(x, y, dragging, margin,
1735 delta);
1736 }
1737 }
1738
1739 return false;
1740}
1741
1742void SetMUICursor_PlugIn(wxCursor* pCursor, int canvasIndex) {
1743 if (g_canvasConfig == 0)
1744 gFrame->GetPrimaryCanvas()->pPlugIn_Cursor = pCursor;
1745 else {
1746 if ((canvasIndex >= 0) && g_canvasArray[canvasIndex]) {
1747 g_canvasArray[canvasIndex]->pPlugIn_Cursor = pCursor;
1748 }
1749 }
1750}
1751
1753 if (g_canvasConfig == 1) return 2;
1754 // else
1755 return 1;
1756}
1757
1758int GetLatLonFormat() { return g_iSDMMFormat; }
1759
1761 if (g_MainToolbar)
1762 return g_MainToolbar->GetToolbarRect();
1763 else
1764 return wxRect(0, 0, 1, 1);
1765}
1766
1767//---------------------------------------------------------------------------
1768// API 1.17
1769//---------------------------------------------------------------------------
1770
1771void ZeroXTE() {
1772 if (g_pRouteMan) {
1773 g_pRouteMan->ZeroCurrentXTEToActivePoint();
1774 }
1775}
1776
1777static PlugIn_ViewPort CreatePlugInViewportEx(const ViewPort& vp) {
1778 // Create a PlugIn Viewport
1779 ViewPort tvp = vp;
1780 PlugIn_ViewPort pivp;
1781
1782 pivp.clat = tvp.clat; // center point
1783 pivp.clon = tvp.clon;
1784 pivp.view_scale_ppm = tvp.view_scale_ppm;
1785 pivp.skew = tvp.skew;
1786 pivp.rotation = tvp.rotation;
1787 pivp.chart_scale = tvp.chart_scale;
1788 pivp.pix_width = tvp.pix_width;
1789 pivp.pix_height = tvp.pix_height;
1790 pivp.rv_rect = tvp.rv_rect;
1791 pivp.b_quilt = tvp.b_quilt;
1792 pivp.m_projection_type = tvp.m_projection_type;
1793
1794 pivp.lat_min = tvp.GetBBox().GetMinLat();
1795 pivp.lat_max = tvp.GetBBox().GetMaxLat();
1796 pivp.lon_min = tvp.GetBBox().GetMinLon();
1797 pivp.lon_max = tvp.GetBBox().GetMaxLon();
1798
1799 pivp.bValid = tvp.IsValid(); // This VP is valid
1800
1801 return pivp;
1802}
1803
1804ListOfPI_S57Obj* PlugInManager::GetLightsObjRuleListVisibleAtLatLon(
1805 ChartPlugInWrapper* target, float zlat, float zlon, const ViewPort& vp) {
1806 ListOfPI_S57Obj* list = NULL;
1807 if (target) {
1808 PlugInChartBaseGLPlus2* picbgl =
1809 dynamic_cast<PlugInChartBaseGLPlus2*>(target->GetPlugInChart());
1810 if (picbgl) {
1811 PlugIn_ViewPort pi_vp = CreatePlugInViewportEx(vp);
1812 list = picbgl->GetLightsObjRuleListVisibleAtLatLon(zlat, zlon, &pi_vp);
1813
1814 return list;
1815 }
1817 dynamic_cast<PlugInChartBaseExtendedPlus2*>(target->GetPlugInChart());
1818 if (picbx) {
1819 PlugIn_ViewPort pi_vp = CreatePlugInViewportEx(vp);
1820 list = picbx->GetLightsObjRuleListVisibleAtLatLon(zlat, zlon, &pi_vp);
1821
1822 return list;
1823 } else
1824 return list;
1825 } else
1826 return list;
1827}
1828
1829// PlugInWaypointEx implementation
1830
1831#include <wx/listimpl.cpp>
1832WX_DEFINE_LIST(Plugin_WaypointExList)
1833
1834// The class implementations
1835PlugIn_Waypoint_Ex::PlugIn_Waypoint_Ex() { InitDefaults(); }
1836
1837PlugIn_Waypoint_Ex::PlugIn_Waypoint_Ex(
1838 double lat, double lon, const wxString& icon_ident, const wxString& wp_name,
1839 const wxString& GUID, const double ScaMin, const bool bNameVisible,
1840 const int nRangeRings, const double RangeDistance,
1841 const wxColor RangeColor) {
1842 InitDefaults();
1843
1844 m_lat = lat;
1845 m_lon = lon;
1846 IconName = icon_ident;
1847 m_MarkName = wp_name;
1848 m_GUID = GUID;
1849 scamin = ScaMin;
1850 IsNameVisible = bNameVisible;
1851 nrange_rings = nRangeRings;
1852 RangeRingSpace = RangeDistance;
1853 RangeRingColor = RangeColor;
1854}
1855
1857 m_HyperlinkList = nullptr;
1858 scamin = 1e9;
1859 b_useScamin = false;
1860 nrange_rings = 0;
1861 RangeRingSpace = 1;
1862 IsNameVisible = false;
1863 IsVisible = true;
1864 RangeRingColor = *wxBLACK;
1865 m_CreateTime = wxDateTime::Now().ToUTC();
1866 IsActive = false;
1867 m_lat = 0;
1868 m_lon = 0;
1869}
1870
1872 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(m_GUID);
1873 if (!prp) return false;
1874
1875 if (prp->m_bIsInRoute && !prp->IsShared()) return false;
1876
1877 return true;
1878}
1879
1881 // Search all routes to count the membership of this point
1882 RoutePoint* pWP = pWayPointMan->FindRoutePointByGUID(m_GUID);
1883 if (!pWP) return 0;
1884
1885 int nCount = 0;
1886 wxRouteListNode* node = pRouteList->GetFirst();
1887 while (node) {
1888 Route* proute = node->GetData();
1889 wxRoutePointListNode* pnode = (proute->pRoutePointList)->GetFirst();
1890 while (pnode) {
1891 RoutePoint* prp = pnode->GetData();
1892 if (prp == pWP) nCount++;
1893 pnode = pnode->GetNext();
1894 }
1895
1896 node = node->GetNext();
1897 }
1898
1899 return nCount;
1900}
1901
1902PlugIn_Waypoint_Ex::~PlugIn_Waypoint_Ex() {}
1903
1904WX_DEFINE_LIST(Plugin_WaypointExV2List)
1905
1906PlugIn_Waypoint_ExV2::PlugIn_Waypoint_ExV2() { InitDefaults(); }
1907
1908PlugIn_Waypoint_ExV2::PlugIn_Waypoint_ExV2(
1909 double lat, double lon, const wxString& icon_ident, const wxString& wp_name,
1910 const wxString& GUID, const double ScaMin, const double ScaMax,
1911 const bool bNameVisible, const int nRangeRings, const double RangeDistance,
1912 const int RangeDistanceUnits, const wxColor RangeColor,
1913 const double WaypointArrivalRadius, const bool ShowWaypointRangeRings,
1914 const double PlannedSpeed, const wxString TideStation) {
1915 // Initialize all to defaults first
1916 InitDefaults();
1917 // Then set the specific values provided
1918 m_lat = lat;
1919 m_lon = lon;
1920 IconName = icon_ident;
1921 m_MarkName = wp_name;
1922 m_GUID = GUID;
1923 scamin = ScaMin;
1924 scamax = ScaMax;
1925
1926 IsNameVisible = bNameVisible;
1927 nrange_rings = nRangeRings;
1928 RangeRingSpace = RangeDistance;
1929 RangeRingSpaceUnits = RangeDistanceUnits; // 0 = nm, 1 = km
1930 RangeRingColor = RangeColor;
1931 m_TideStation = TideStation;
1932
1933 m_PlannedSpeed = PlannedSpeed;
1934 m_WaypointArrivalRadius = WaypointArrivalRadius;
1935 m_bShowWaypointRangeRings = ShowWaypointRangeRings;
1936}
1937
1939 m_HyperlinkList = nullptr;
1940 scamin = 1e9;
1941 scamax = 1e6;
1942 b_useScamin = false;
1943 nrange_rings = 0;
1944 RangeRingSpace = 1;
1945 RangeRingSpaceUnits = 0; // 0 = nm, 1 = km
1946 m_TideStation = wxEmptyString;
1947 IsNameVisible = false;
1948 IsVisible = true;
1949 RangeRingColor = *wxBLACK;
1950 m_CreateTime = wxDateTime::Now().ToUTC();
1951 IsActive = false;
1952 m_lat = 0;
1953 m_lon = 0;
1954
1955 m_PlannedSpeed = 0.0;
1958}
1959
1960PlugIn_Waypoint_ExV2::~PlugIn_Waypoint_ExV2() {}
1961
1963 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(m_GUID);
1964 if (!prp) return false;
1965 if (prp->m_bIsInRoute && !prp->IsShared()) return false;
1966 return true;
1967}
1968
1970 // Search all routes to count the membership of this point
1971 RoutePoint* pWP = pWayPointMan->FindRoutePointByGUID(m_GUID);
1972 if (!pWP) return 0;
1973
1974 int nCount = 0;
1975 wxRouteListNode* node = pRouteList->GetFirst();
1976 while (node) {
1977 Route* proute = node->GetData();
1978 wxRoutePointListNode* pnode = (proute->pRoutePointList)->GetFirst();
1979 while (pnode) {
1980 RoutePoint* prp = pnode->GetData();
1981 if (prp == pWP) nCount++;
1982 pnode = pnode->GetNext();
1983 }
1984
1985 node = node->GetNext();
1986 }
1987
1988 return nCount;
1989}
1990
1991PlugIn_Route_ExV2::PlugIn_Route_ExV2() {
1992 pWaypointList = new Plugin_WaypointExV2List;
1993 m_GUID = wxEmptyString;
1994 m_NameString = wxEmptyString;
1995 m_StartString = wxEmptyString;
1996 m_EndString = wxEmptyString;
1997 m_isActive = false;
1998 m_isVisible = true;
1999 m_Description = wxEmptyString;
2000
2001 // Generate a unique GUID if none provided
2002 if (m_GUID.IsEmpty()) {
2003 wxDateTime now = wxDateTime::Now();
2004 m_GUID = wxString::Format("RT%d%d%d%d", (int)now.GetMillisecond(),
2005 (int)now.GetSecond(), (int)now.GetMinute(),
2006 (int)now.GetHour());
2007 }
2008}
2009
2010PlugIn_Route_ExV2::~PlugIn_Route_ExV2() {
2011 if (pWaypointList) {
2012 pWaypointList->DeleteContents(true);
2013 delete pWaypointList;
2014 }
2015}
2016
2017// translate O route class to PlugIn_Waypoint_ExV2
2018static void PlugInExV2FromRoutePoint(PlugIn_Waypoint_ExV2* dst,
2019 /* const*/ RoutePoint* src) {
2020 dst->m_lat = src->m_lat;
2021 dst->m_lon = src->m_lon;
2022 dst->IconName = src->GetIconName();
2023 dst->m_MarkName = src->GetName();
2024 dst->m_MarkDescription = src->GetDescription();
2025 dst->IconDescription = pWayPointMan->GetIconDescription(src->GetIconName());
2026 dst->IsVisible = src->IsVisible();
2027 dst->m_CreateTime = src->GetCreateTime(); // not const
2028 dst->m_GUID = src->m_GUID;
2029
2030 // Transcribe (clone) the html HyperLink List, if present
2031 if (src->m_HyperlinkList) {
2032 delete dst->m_HyperlinkList;
2033 dst->m_HyperlinkList = nullptr;
2034
2035 if (src->m_HyperlinkList->GetCount() > 0) {
2036 dst->m_HyperlinkList = new Plugin_HyperlinkList;
2037
2038 wxHyperlinkListNode* linknode = src->m_HyperlinkList->GetFirst();
2039 while (linknode) {
2040 Hyperlink* link = linknode->GetData();
2041
2043 h->DescrText = link->DescrText;
2044 h->Link = link->Link;
2045 h->Type = link->LType;
2046
2047 dst->m_HyperlinkList->Append(h);
2048
2049 linknode = linknode->GetNext();
2050 }
2051 }
2052 }
2053
2054 // Get the range ring info
2059 dst->m_TideStation = src->m_TideStation;
2060
2061 // Get other extended info
2062 dst->IsNameVisible = src->m_bShowName;
2063 dst->scamin = src->GetScaMin();
2064 dst->b_useScamin = src->GetUseSca();
2065 dst->IsActive = src->m_bIsActive;
2066
2067 dst->scamax = src->GetScaMax();
2068 dst->m_PlannedSpeed = src->GetPlannedSpeed();
2069 dst->m_ETD = src->GetManualETD();
2070 dst->m_WaypointArrivalRadius = src->GetWaypointArrivalRadius();
2071 dst->m_bShowWaypointRangeRings = src->GetShowWaypointRangeRings();
2072}
2073
2074bool GetSingleWaypointExV2(wxString GUID, PlugIn_Waypoint_ExV2* pwaypoint) {
2075 // Find the RoutePoint
2076 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(GUID);
2077
2078 if (!prp) return false;
2079
2080 PlugInExV2FromRoutePoint(pwaypoint, prp);
2081
2082 return true;
2083}
2084
2085static void cloneHyperlinkListExV2(RoutePoint* dst,
2086 const PlugIn_Waypoint_ExV2* src) {
2087 // Transcribe (clone) the html HyperLink List, if present
2088 if (src->m_HyperlinkList == nullptr) return;
2089
2090 if (src->m_HyperlinkList->GetCount() > 0) {
2091 wxPlugin_HyperlinkListNode* linknode = src->m_HyperlinkList->GetFirst();
2092 while (linknode) {
2093 Plugin_Hyperlink* link = linknode->GetData();
2094
2095 Hyperlink* h = new Hyperlink();
2096 h->DescrText = link->DescrText;
2097 h->Link = link->Link;
2098 h->LType = link->Type;
2099
2100 dst->m_HyperlinkList->Append(h);
2101
2102 linknode = linknode->GetNext();
2103 }
2104 }
2105}
2106
2107RoutePoint* CreateNewPoint(const PlugIn_Waypoint_ExV2* src, bool b_permanent) {
2108 RoutePoint* pWP = new RoutePoint(src->m_lat, src->m_lon, src->IconName,
2109 src->m_MarkName, src->m_GUID);
2110
2111 pWP->m_bIsolatedMark = true; // This is an isolated mark
2112
2113 cloneHyperlinkListExV2(pWP, src);
2114
2116
2117 if (src->m_CreateTime.IsValid())
2118 pWP->SetCreateTime(src->m_CreateTime);
2119 else {
2120 pWP->SetCreateTime(wxDateTime::Now().ToUTC());
2121 }
2122
2123 pWP->m_btemp = (b_permanent == false);
2124
2125 // Extended fields
2126 pWP->SetIconName(src->IconName);
2127 pWP->SetWaypointRangeRingsNumber(src->nrange_rings);
2128 pWP->SetWaypointRangeRingsStep(src->RangeRingSpace);
2129 pWP->SetWaypointRangeRingsStepUnits(src->RangeRingSpaceUnits);
2130 pWP->SetWaypointRangeRingsColour(src->RangeRingColor);
2131 pWP->SetTideStation(src->m_TideStation);
2132 pWP->SetScaMin(src->scamin);
2133 pWP->SetUseSca(src->b_useScamin);
2134 pWP->SetNameShown(src->IsNameVisible);
2135 pWP->SetVisible(src->IsVisible);
2136
2137 pWP->SetWaypointArrivalRadius(src->m_WaypointArrivalRadius);
2138 pWP->SetShowWaypointRangeRings(src->m_bShowWaypointRangeRings);
2139 pWP->SetScaMax(src->scamax);
2140 pWP->SetPlannedSpeed(src->m_PlannedSpeed);
2141 if (src->m_ETD.IsValid())
2142 pWP->SetETD(src->m_ETD);
2143 else
2144 pWP->SetETD(wxEmptyString);
2145 return pWP;
2146}
2147
2149 bool b_permanent) {
2150 // Validate the waypoint parameters a little bit
2151
2152 // GUID
2153 // Make sure that this GUID is indeed unique in the Routepoint list
2154 bool b_unique = true;
2155 wxRoutePointListNode* prpnode = pWayPointMan->GetWaypointList()->GetFirst();
2156 while (prpnode) {
2157 RoutePoint* prp = prpnode->GetData();
2158
2159 if (prp->m_GUID == pwaypointex->m_GUID) {
2160 b_unique = false;
2161 break;
2162 }
2163 prpnode = prpnode->GetNext(); // RoutePoint
2164 }
2165
2166 if (!b_unique) return false;
2167
2168 RoutePoint* pWP = CreateNewPoint(pwaypointex, b_permanent);
2169
2170 pWP->SetShowWaypointRangeRings(pwaypointex->nrange_rings > 0);
2171
2172 pSelect->AddSelectableRoutePoint(pWP->m_lat, pWP->m_lon, pWP);
2173 if (b_permanent) {
2174 // pConfig->AddNewWayPoint(pWP, -1);
2175 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
2176 }
2177
2178 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
2179 pRouteManagerDialog->UpdateWptListCtrl();
2180
2181 return true;
2182}
2183
2185 // Find the RoutePoint
2186 bool b_found = false;
2187 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(pwaypoint->m_GUID);
2188
2189 if (prp) b_found = true;
2190
2191 if (b_found) {
2192 double lat_save = prp->m_lat;
2193 double lon_save = prp->m_lon;
2194
2195 prp->m_lat = pwaypoint->m_lat;
2196 prp->m_lon = pwaypoint->m_lon;
2197 prp->SetIconName(pwaypoint->IconName);
2198 prp->SetName(pwaypoint->m_MarkName);
2199 prp->m_MarkDescription = pwaypoint->m_MarkDescription;
2200 prp->SetVisible(pwaypoint->IsVisible);
2201 if (pwaypoint->m_CreateTime.IsValid())
2202 prp->SetCreateTime(pwaypoint->m_CreateTime);
2203
2204 // Transcribe (clone) the html HyperLink List, if present
2205
2206 if (pwaypoint->m_HyperlinkList) {
2207 prp->m_HyperlinkList->Clear();
2208 if (pwaypoint->m_HyperlinkList->GetCount() > 0) {
2209 wxPlugin_HyperlinkListNode* linknode =
2210 pwaypoint->m_HyperlinkList->GetFirst();
2211 while (linknode) {
2212 Plugin_Hyperlink* link = linknode->GetData();
2213
2214 Hyperlink* h = new Hyperlink();
2215 h->DescrText = link->DescrText;
2216 h->Link = link->Link;
2217 h->LType = link->Type;
2218
2219 prp->m_HyperlinkList->Append(h);
2220
2221 linknode = linknode->GetNext();
2222 }
2223 }
2224 }
2225
2226 // Extended fields
2227 prp->SetWaypointRangeRingsNumber(pwaypoint->nrange_rings);
2228 prp->SetWaypointRangeRingsStep(pwaypoint->RangeRingSpace);
2229 prp->SetWaypointRangeRingsStepUnits(pwaypoint->RangeRingSpaceUnits);
2230 prp->SetWaypointRangeRingsColour(pwaypoint->RangeRingColor);
2231 prp->SetTideStation(pwaypoint->m_TideStation);
2232 prp->SetScaMin(pwaypoint->scamin);
2233 prp->SetUseSca(pwaypoint->b_useScamin);
2234 prp->SetNameShown(pwaypoint->IsNameVisible);
2235
2236 prp->SetShowWaypointRangeRings(pwaypoint->nrange_rings > 0);
2237
2238 if (prp) prp->ReLoadIcon();
2239
2240 auto canvas = gFrame->GetPrimaryCanvas();
2241 SelectCtx ctx(canvas->m_bShowNavobjects, canvas->GetCanvasTrueScale(),
2242 canvas->GetScaleValue());
2243 SelectItem* pFind =
2244 pSelect->FindSelection(ctx, lat_save, lon_save, SELTYPE_ROUTEPOINT);
2245 if (pFind) {
2246 pFind->m_slat = pwaypoint->m_lat; // update the SelectList entry
2247 pFind->m_slon = pwaypoint->m_lon;
2248 }
2249
2250 if (!prp->m_btemp) {
2251 // pConfig->UpdateWayPoint(prp);
2252 NavObj_dB::GetInstance().UpdateRoutePoint(prp);
2253 }
2254
2255 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
2256 pRouteManagerDialog->UpdateWptListCtrl();
2257
2258 prp->SetPlannedSpeed(pwaypoint->m_PlannedSpeed);
2259 if (pwaypoint->m_ETD.IsValid())
2260 prp->SetETD(pwaypoint->m_ETD);
2261 else
2262 prp->SetETD(wxEmptyString);
2263 prp->SetWaypointArrivalRadius(pwaypoint->m_WaypointArrivalRadius);
2264 prp->SetShowWaypointRangeRings(pwaypoint->m_bShowWaypointRangeRings);
2265 prp->SetScaMax(pwaypoint->scamax);
2266 }
2267
2268 return b_found;
2269}
2270
2271std::unique_ptr<PlugIn_Waypoint_ExV2> GetWaypointExV2_Plugin(
2272 const wxString& GUID) {
2273 std::unique_ptr<PlugIn_Waypoint_ExV2> w(new PlugIn_Waypoint_ExV2);
2274 GetSingleWaypointExV2(GUID, w.get());
2275 return w;
2276}
2277
2278bool AddPlugInRouteExV2(PlugIn_Route_ExV2* proute, bool b_permanent) {
2279 Route* route = new Route();
2280
2281 PlugIn_Waypoint_ExV2* pwaypointex;
2282 RoutePoint *pWP, *pWP_src;
2283 int ip = 0;
2284 wxDateTime plannedDeparture;
2285
2286 wxPlugin_WaypointExV2ListNode* pwpnode = proute->pWaypointList->GetFirst();
2287 while (pwpnode) {
2288 pwaypointex = pwpnode->GetData();
2289
2290 pWP = pWayPointMan->FindRoutePointByGUID(pwaypointex->m_GUID);
2291 if (!pWP) {
2292 pWP = CreateNewPoint(pwaypointex, b_permanent);
2293 pWP->m_bIsolatedMark = false;
2294 }
2295
2296 route->AddPoint(pWP);
2297
2298 pSelect->AddSelectableRoutePoint(pWP->m_lat, pWP->m_lon, pWP);
2299
2300 if (ip > 0)
2301 pSelect->AddSelectableRouteSegment(pWP_src->m_lat, pWP_src->m_lon,
2302 pWP->m_lat, pWP->m_lon, pWP_src, pWP,
2303 route);
2304
2305 plannedDeparture = pwaypointex->m_CreateTime;
2306 ip++;
2307 pWP_src = pWP;
2308
2309 pwpnode = pwpnode->GetNext(); // PlugInWaypoint
2310 }
2311
2312 route->m_PlannedDeparture = plannedDeparture;
2313
2314 route->m_RouteNameString = proute->m_NameString;
2315 route->m_RouteStartString = proute->m_StartString;
2316 route->m_RouteEndString = proute->m_EndString;
2317 if (!proute->m_GUID.IsEmpty()) {
2318 route->m_GUID = proute->m_GUID;
2319 }
2320 route->m_btemp = (b_permanent == false);
2321 route->SetVisible(proute->m_isVisible);
2322 route->m_RouteDescription = proute->m_Description;
2323
2324 pRouteList->Append(route);
2325
2326 if (b_permanent) {
2327 // pConfig->AddNewRoute(route);
2328 NavObj_dB::GetInstance().InsertRoute(route);
2329 }
2330
2331 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
2332 pRouteManagerDialog->UpdateRouteListCtrl();
2333
2334 return true;
2335}
2336
2338 bool b_found = false;
2339
2340 // Find the Route
2341 Route* pRoute = g_pRouteMan->FindRouteByGUID(proute->m_GUID);
2342 if (pRoute) b_found = true;
2343
2344 if (b_found) {
2345 bool b_permanent = !pRoute->m_btemp;
2346 g_pRouteMan->DeleteRoute(pRoute);
2347
2348 b_found = AddPlugInRouteExV2(proute, b_permanent);
2349 }
2350
2351 return b_found;
2352}
2353
2354std::unique_ptr<PlugIn_Route_ExV2> GetRouteExV2_Plugin(const wxString& GUID) {
2355 std::unique_ptr<PlugIn_Route_ExV2> r;
2356 Route* route = g_pRouteMan->FindRouteByGUID(GUID);
2357 if (route == nullptr) return r;
2358
2359 r = std::unique_ptr<PlugIn_Route_ExV2>(new PlugIn_Route_ExV2);
2360 PlugIn_Route_ExV2* dst_route = r.get();
2361
2362 RoutePoint* src_wp;
2363 wxRoutePointListNode* node = route->pRoutePointList->GetFirst();
2364
2365 while (node) {
2366 src_wp = node->GetData();
2367
2369 PlugInExV2FromRoutePoint(dst_wp, src_wp);
2370
2371 dst_route->pWaypointList->Append(dst_wp);
2372
2373 node = node->GetNext();
2374 }
2375 dst_route->m_NameString = route->m_RouteNameString;
2376 dst_route->m_StartString = route->m_RouteStartString;
2377 dst_route->m_EndString = route->m_RouteEndString;
2378 dst_route->m_GUID = route->m_GUID;
2379 dst_route->m_isActive = g_pRouteMan->GetpActiveRoute() == route;
2380 dst_route->m_isVisible = route->IsVisible();
2381 dst_route->m_Description = route->m_RouteDescription;
2382
2383 return r;
2384}
2385
2386// PlugInRouteExtended implementation
2387PlugIn_Route_Ex::PlugIn_Route_Ex(void) {
2388 pWaypointList = new Plugin_WaypointExList;
2389}
2390
2391PlugIn_Route_Ex::~PlugIn_Route_Ex(void) {
2392 pWaypointList->DeleteContents(false); // do not delete Waypoints
2393 pWaypointList->Clear();
2394
2395 delete pWaypointList;
2396}
2397
2398// The utility methods implementations
2399
2400// translate O route class to PlugIn_Waypoint_Ex
2401static void PlugInExFromRoutePoint(PlugIn_Waypoint_Ex* dst,
2402 /* const*/ RoutePoint* src) {
2403 dst->m_lat = src->m_lat;
2404 dst->m_lon = src->m_lon;
2405 dst->IconName = src->GetIconName();
2406 dst->m_MarkName = src->GetName();
2407 dst->m_MarkDescription = src->GetDescription();
2408 dst->IconDescription = pWayPointMan->GetIconDescription(src->GetIconName());
2409 dst->IsVisible = src->IsVisible();
2410 dst->m_CreateTime = src->GetCreateTime(); // not const
2411 dst->m_GUID = src->m_GUID;
2412
2413 // Transcribe (clone) the html HyperLink List, if present
2414 if (src->m_HyperlinkList) {
2415 delete dst->m_HyperlinkList;
2416 dst->m_HyperlinkList = nullptr;
2417
2418 if (src->m_HyperlinkList->GetCount() > 0) {
2419 dst->m_HyperlinkList = new Plugin_HyperlinkList;
2420
2421 wxHyperlinkListNode* linknode = src->m_HyperlinkList->GetFirst();
2422 while (linknode) {
2423 Hyperlink* link = linknode->GetData();
2424
2426 h->DescrText = link->DescrText;
2427 h->Link = link->Link;
2428 h->Type = link->LType;
2429
2430 dst->m_HyperlinkList->Append(h);
2431
2432 linknode = linknode->GetNext();
2433 }
2434 }
2435 }
2436
2437 // Get the range ring info
2441
2442 // Get other extended info
2443 dst->IsNameVisible = src->m_bShowName;
2444 dst->scamin = src->GetScaMin();
2445 dst->b_useScamin = src->GetUseSca();
2446 dst->IsActive = src->m_bIsActive;
2447}
2448
2449static void cloneHyperlinkListEx(RoutePoint* dst,
2450 const PlugIn_Waypoint_Ex* src) {
2451 // Transcribe (clone) the html HyperLink List, if present
2452 if (src->m_HyperlinkList == nullptr) return;
2453
2454 if (src->m_HyperlinkList->GetCount() > 0) {
2455 wxPlugin_HyperlinkListNode* linknode = src->m_HyperlinkList->GetFirst();
2456 while (linknode) {
2457 Plugin_Hyperlink* link = linknode->GetData();
2458
2459 Hyperlink* h = new Hyperlink();
2460 h->DescrText = link->DescrText;
2461 h->Link = link->Link;
2462 h->LType = link->Type;
2463
2464 dst->m_HyperlinkList->Append(h);
2465
2466 linknode = linknode->GetNext();
2467 }
2468 }
2469}
2470
2471RoutePoint* CreateNewPoint(const PlugIn_Waypoint_Ex* src, bool b_permanent) {
2472 RoutePoint* pWP = new RoutePoint(src->m_lat, src->m_lon, src->IconName,
2473 src->m_MarkName, src->m_GUID);
2474
2475 pWP->m_bIsolatedMark = true; // This is an isolated mark
2476
2477 cloneHyperlinkListEx(pWP, src);
2478
2480
2481 if (src->m_CreateTime.IsValid())
2482 pWP->SetCreateTime(src->m_CreateTime);
2483 else {
2484 pWP->SetCreateTime(wxDateTime::Now().ToUTC());
2485 }
2486
2487 pWP->m_btemp = (b_permanent == false);
2488
2489 // Extended fields
2490 pWP->SetIconName(src->IconName);
2491 pWP->SetWaypointRangeRingsNumber(src->nrange_rings);
2492 pWP->SetWaypointRangeRingsStep(src->RangeRingSpace);
2493 pWP->SetWaypointRangeRingsColour(src->RangeRingColor);
2494 pWP->SetScaMin(src->scamin);
2495 pWP->SetUseSca(src->b_useScamin);
2496 pWP->SetNameShown(src->IsNameVisible);
2497 pWP->SetVisible(src->IsVisible);
2498
2499 return pWP;
2500}
2501bool GetSingleWaypointEx(wxString GUID, PlugIn_Waypoint_Ex* pwaypoint) {
2502 // Find the RoutePoint
2503 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(GUID);
2504
2505 if (!prp) return false;
2506
2507 PlugInExFromRoutePoint(pwaypoint, prp);
2508
2509 return true;
2510}
2511
2512bool AddSingleWaypointEx(PlugIn_Waypoint_Ex* pwaypointex, bool b_permanent) {
2513 // Validate the waypoint parameters a little bit
2514
2515 // GUID
2516 // Make sure that this GUID is indeed unique in the Routepoint list
2517 bool b_unique = true;
2518 wxRoutePointListNode* prpnode = pWayPointMan->GetWaypointList()->GetFirst();
2519 while (prpnode) {
2520 RoutePoint* prp = prpnode->GetData();
2521
2522 if (prp->m_GUID == pwaypointex->m_GUID) {
2523 b_unique = false;
2524 break;
2525 }
2526 prpnode = prpnode->GetNext(); // RoutePoint
2527 }
2528
2529 if (!b_unique) return false;
2530
2531 RoutePoint* pWP = CreateNewPoint(pwaypointex, b_permanent);
2532
2533 pWP->SetShowWaypointRangeRings(pwaypointex->nrange_rings > 0);
2534
2535 pSelect->AddSelectableRoutePoint(pWP->m_lat, pWP->m_lon, pWP);
2536 if (b_permanent) {
2537 // pConfig->AddNewWayPoint(pWP, -1);
2538 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
2539 }
2540 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
2541 pRouteManagerDialog->UpdateWptListCtrl();
2542
2543 return true;
2544}
2545
2547 // Find the RoutePoint
2548 bool b_found = false;
2549 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(pwaypoint->m_GUID);
2550
2551 if (prp) b_found = true;
2552
2553 if (b_found) {
2554 double lat_save = prp->m_lat;
2555 double lon_save = prp->m_lon;
2556
2557 prp->m_lat = pwaypoint->m_lat;
2558 prp->m_lon = pwaypoint->m_lon;
2559 prp->SetIconName(pwaypoint->IconName);
2560 prp->SetName(pwaypoint->m_MarkName);
2561 prp->m_MarkDescription = pwaypoint->m_MarkDescription;
2562 prp->SetVisible(pwaypoint->IsVisible);
2563 if (pwaypoint->m_CreateTime.IsValid())
2564 prp->SetCreateTime(pwaypoint->m_CreateTime);
2565
2566 // Transcribe (clone) the html HyperLink List, if present
2567
2568 if (pwaypoint->m_HyperlinkList) {
2569 prp->m_HyperlinkList->Clear();
2570 if (pwaypoint->m_HyperlinkList->GetCount() > 0) {
2571 wxPlugin_HyperlinkListNode* linknode =
2572 pwaypoint->m_HyperlinkList->GetFirst();
2573 while (linknode) {
2574 Plugin_Hyperlink* link = linknode->GetData();
2575
2576 Hyperlink* h = new Hyperlink();
2577 h->DescrText = link->DescrText;
2578 h->Link = link->Link;
2579 h->LType = link->Type;
2580
2581 prp->m_HyperlinkList->Append(h);
2582
2583 linknode = linknode->GetNext();
2584 }
2585 }
2586 }
2587
2588 // Extended fields
2589 prp->SetWaypointRangeRingsNumber(pwaypoint->nrange_rings);
2590 prp->SetWaypointRangeRingsStep(pwaypoint->RangeRingSpace);
2591 prp->SetWaypointRangeRingsColour(pwaypoint->RangeRingColor);
2592 prp->SetScaMin(pwaypoint->scamin);
2593 prp->SetUseSca(pwaypoint->b_useScamin);
2594 prp->SetNameShown(pwaypoint->IsNameVisible);
2595
2596 prp->SetShowWaypointRangeRings(pwaypoint->nrange_rings > 0);
2597
2598 if (prp) prp->ReLoadIcon();
2599
2600 auto canvas = gFrame->GetPrimaryCanvas();
2601 SelectCtx ctx(canvas->m_bShowNavobjects, canvas->GetCanvasTrueScale(),
2602 canvas->GetScaleValue());
2603 SelectItem* pFind =
2604 pSelect->FindSelection(ctx, lat_save, lon_save, SELTYPE_ROUTEPOINT);
2605 if (pFind) {
2606 pFind->m_slat = pwaypoint->m_lat; // update the SelectList entry
2607 pFind->m_slon = pwaypoint->m_lon;
2608 }
2609
2610 if (!prp->m_btemp) {
2611 // pConfig->UpdateWayPoint(prp);
2612 NavObj_dB::GetInstance().UpdateRoutePoint(prp);
2613 }
2614
2615 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
2616 pRouteManagerDialog->UpdateWptListCtrl();
2617 }
2618
2619 return b_found;
2620}
2621
2622bool AddPlugInRouteEx(PlugIn_Route_Ex* proute, bool b_permanent) {
2623 Route* route = new Route();
2624
2625 PlugIn_Waypoint_Ex* pwaypointex;
2626 RoutePoint *pWP, *pWP_src;
2627 int ip = 0;
2628 wxDateTime plannedDeparture;
2629
2630 wxPlugin_WaypointExListNode* pwpnode = proute->pWaypointList->GetFirst();
2631 while (pwpnode) {
2632 pwaypointex = pwpnode->GetData();
2633
2634 pWP = pWayPointMan->FindRoutePointByGUID(pwaypointex->m_GUID);
2635 if (!pWP) {
2636 pWP = CreateNewPoint(pwaypointex, b_permanent);
2637 pWP->m_bIsolatedMark = false;
2638 }
2639
2640 route->AddPoint(pWP);
2641
2642 pSelect->AddSelectableRoutePoint(pWP->m_lat, pWP->m_lon, pWP);
2643
2644 if (ip > 0)
2645 pSelect->AddSelectableRouteSegment(pWP_src->m_lat, pWP_src->m_lon,
2646 pWP->m_lat, pWP->m_lon, pWP_src, pWP,
2647 route);
2648
2649 plannedDeparture = pwaypointex->m_CreateTime;
2650 ip++;
2651 pWP_src = pWP;
2652
2653 pwpnode = pwpnode->GetNext(); // PlugInWaypoint
2654 }
2655
2656 route->m_PlannedDeparture = plannedDeparture;
2657
2658 route->m_RouteNameString = proute->m_NameString;
2659 route->m_RouteStartString = proute->m_StartString;
2660 route->m_RouteEndString = proute->m_EndString;
2661 if (!proute->m_GUID.IsEmpty()) {
2662 route->m_GUID = proute->m_GUID;
2663 }
2664 route->m_btemp = (b_permanent == false);
2665 route->SetVisible(proute->m_isVisible);
2666 route->m_RouteDescription = proute->m_Description;
2667
2668 pRouteList->Append(route);
2669
2670 if (b_permanent) {
2671 // pConfig->AddNewRoute(route);
2672 NavObj_dB::GetInstance().InsertRoute(route);
2673 }
2674
2675 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
2676 pRouteManagerDialog->UpdateRouteListCtrl();
2677
2678 return true;
2679}
2680
2682 bool b_found = false;
2683
2684 // Find the Route
2685 Route* pRoute = g_pRouteMan->FindRouteByGUID(proute->m_GUID);
2686 if (pRoute) b_found = true;
2687
2688 if (b_found) {
2689 bool b_permanent = !pRoute->m_btemp;
2690 g_pRouteMan->DeleteRoute(pRoute);
2691 b_found = AddPlugInRouteEx(proute, b_permanent);
2692 }
2693
2694 return b_found;
2695}
2696
2697std::unique_ptr<PlugIn_Waypoint_Ex> GetWaypointEx_Plugin(const wxString& GUID) {
2698 std::unique_ptr<PlugIn_Waypoint_Ex> w(new PlugIn_Waypoint_Ex);
2699 GetSingleWaypointEx(GUID, w.get());
2700 return w;
2701}
2702
2703std::unique_ptr<PlugIn_Route_Ex> GetRouteEx_Plugin(const wxString& GUID) {
2704 std::unique_ptr<PlugIn_Route_Ex> r;
2705 Route* route = g_pRouteMan->FindRouteByGUID(GUID);
2706 if (route == nullptr) return r;
2707
2708 r = std::unique_ptr<PlugIn_Route_Ex>(new PlugIn_Route_Ex);
2709 PlugIn_Route_Ex* dst_route = r.get();
2710
2711 // PlugIn_Waypoint *pwp;
2712 RoutePoint* src_wp;
2713 wxRoutePointListNode* node = route->pRoutePointList->GetFirst();
2714
2715 while (node) {
2716 src_wp = node->GetData();
2717
2718 PlugIn_Waypoint_Ex* dst_wp = new PlugIn_Waypoint_Ex();
2719 PlugInExFromRoutePoint(dst_wp, src_wp);
2720
2721 dst_route->pWaypointList->Append(dst_wp);
2722
2723 node = node->GetNext();
2724 }
2725 dst_route->m_NameString = route->m_RouteNameString;
2726 dst_route->m_StartString = route->m_RouteStartString;
2727 dst_route->m_EndString = route->m_RouteEndString;
2728 dst_route->m_GUID = route->m_GUID;
2729 dst_route->m_isActive = g_pRouteMan->GetpActiveRoute() == route;
2730 dst_route->m_isVisible = route->IsVisible();
2731 dst_route->m_Description = route->m_RouteDescription;
2732
2733 return r;
2734}
2735
2737 void) { // if no active waypoint, returns wxEmptyString
2738 RoutePoint* rp = g_pRouteMan->GetpActivePoint();
2739 if (!rp)
2740 return wxEmptyString;
2741 else
2742 return rp->m_GUID;
2743}
2744
2746 void) { // if no active route, returns wxEmptyString
2747 Route* rt = g_pRouteMan->GetpActiveRoute();
2748 if (!rt)
2749 return wxEmptyString;
2750 else
2751 return rt->m_GUID;
2752}
2753
2755int GetGlobalWatchdogTimoutSeconds() { return gps_watchdog_timeout_ticks; }
2756
2758std::vector<std::string> GetPriorityMaps() {
2759 MyApp& app = wxGetApp();
2760 return (app.m_comm_bridge.GetPriorityMaps());
2761}
2762
2763void UpdateAndApplyPriorityMaps(std::vector<std::string> map) {
2764 MyApp& app = wxGetApp();
2765 app.m_comm_bridge.UpdateAndApplyMaps(map);
2766}
2767
2768std::vector<std::string> GetActivePriorityIdentifiers() {
2769 std::vector<std::string> result;
2770
2771 MyApp& app = wxGetApp();
2772
2773 std::string id =
2774 app.m_comm_bridge.GetPriorityContainer("position").active_source;
2775 result.push_back(id);
2776 id = app.m_comm_bridge.GetPriorityContainer("velocity").active_source;
2777 result.push_back(id);
2778 id = app.m_comm_bridge.GetPriorityContainer("heading").active_source;
2779 result.push_back(id);
2780 id = app.m_comm_bridge.GetPriorityContainer("variation").active_source;
2781 result.push_back(id);
2782 id = app.m_comm_bridge.GetPriorityContainer("satellites").active_source;
2783 result.push_back(id);
2784
2785 return result;
2786}
2787
2789 double rv = 1.0;
2790#if defined(__WXOSX__) || defined(__WXGTK3__)
2791 // Support scaled HDPI displays.
2792 if (gFrame) rv = gFrame->GetContentScaleFactor();
2793#endif
2794 return rv;
2795}
2797 double scaler = 1.0;
2798#ifdef __WXMSW__
2799 if (gFrame) scaler = (double)(gFrame->ToDIP(100)) / 100.;
2800#endif
2801 return scaler;
2802}
2803
2804//---------------------------------------------------------------------------
2805// API 1.18
2806//---------------------------------------------------------------------------
2807
2808//---------------------------------------------------------------------------
2809// API 1.19
2810//---------------------------------------------------------------------------
2811void ExitOCPN() {}
2812
2813bool GetFullScreen() { return gFrame->IsFullScreen(); }
2814
2815void SetFullScreen(bool set_full_screen_on) {
2816 bool state = gFrame->IsFullScreen();
2817 if (set_full_screen_on && !state)
2818 gFrame->ToggleFullScreen();
2819 else if (!set_full_screen_on && state)
2820 gFrame->ToggleFullScreen();
2821}
2822
2823extern bool g_useMUI;
2824void EnableMUIBar(bool enable, int CanvasIndex) {
2825 bool current_mui_state = g_useMUI;
2826
2827 g_useMUI = enable;
2828 if (enable && !current_mui_state) { // OFF going ON
2829 // ..For each canvas...
2830 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
2831 ChartCanvas* cc = g_canvasArray.Item(i);
2832 if (cc) cc->CreateMUIBar();
2833 }
2834 } else if (!enable && current_mui_state) { // ON going OFF
2835 // ..For each canvas...
2836 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
2837 ChartCanvas* cc = g_canvasArray.Item(i);
2838 if (cc) cc->DestroyMuiBar();
2839 }
2840 }
2841}
2842
2843bool GetEnableMUIBar(int CanvasIndex) { return g_useMUI; }
2844
2845void EnableCompassGPSIcon(bool enable, int CanvasIndex) {
2846 if (CanvasIndex < GetCanvasCount()) {
2847 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2848 if (cc) cc->SetShowGPSCompassWindow(enable);
2849 }
2850}
2851
2852bool GetEnableCompassGPSIcon(int CanvasIndex) {
2853 if (CanvasIndex < GetCanvasCount()) {
2854 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2855 if (cc)
2856 return cc->GetShowGPSCompassWindow();
2857 else
2858 return false;
2859 }
2860 return false;
2861}
2862
2863extern bool g_bShowStatusBar;
2864void EnableStatusBar(bool enable) {
2865 g_bShowStatusBar = enable;
2866 gFrame->ConfigureStatusBar();
2867}
2868
2869bool GetEnableStatusBar() { return g_bShowStatusBar; }
2870
2871void EnableChartBar(bool enable, int CanvasIndex) {
2872 bool current_chartbar_state = g_bShowChartBar;
2873 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
2874 ChartCanvas* cc = g_canvasArray.Item(i);
2875 if (current_chartbar_state && !enable) {
2876 gFrame->ToggleChartBar(cc);
2877 g_bShowChartBar = current_chartbar_state;
2878 } else if (!current_chartbar_state && enable) {
2879 gFrame->ToggleChartBar(cc);
2880 g_bShowChartBar = current_chartbar_state;
2881 }
2882 }
2883 g_bShowChartBar = enable;
2884}
2885
2886bool GetEnableChartBar(int CanvasIndex) { return g_bShowChartBar; }
2887
2888extern bool g_bShowMenuBar;
2889void EnableMenu(bool enable) {
2890 if (!enable) {
2891 if (g_bShowMenuBar) {
2892 g_bShowMenuBar = false;
2893 if (gFrame->m_pMenuBar) {
2894 gFrame->SetMenuBar(NULL);
2895 gFrame->m_pMenuBar->Destroy();
2896 gFrame->m_pMenuBar = NULL;
2897 }
2898 }
2899 } else {
2900 g_bShowMenuBar = true;
2901 gFrame->BuildMenuBar();
2902 }
2903}
2904
2905bool GetEnableMenu() { return g_bShowMenuBar; }
2906
2907void SetGlobalColor(std::string table, std::string name, wxColor color) {
2908 if (ps52plib) ps52plib->m_chartSymbols.UpdateTableColor(table, name, color);
2909}
2910
2911wxColor GetGlobalColorD(std::string map_name, std::string name) {
2912 wxColor ret = wxColor(*wxRED);
2913 if (ps52plib) {
2914 int i_table = ps52plib->m_chartSymbols.FindColorTable(map_name.c_str());
2915 ret = ps52plib->m_chartSymbols.GetwxColor(name.c_str(), i_table);
2916 }
2917 return ret;
2918}
2919
2920void EnableLatLonGrid(bool enable, int CanvasIndex) {
2921 if (CanvasIndex < GetCanvasCount()) {
2922 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2923 if (cc) cc->SetShowGrid(enable);
2924 }
2925}
2926
2927void EnableChartOutlines(bool enable, int CanvasIndex) {
2928 if (CanvasIndex < GetCanvasCount()) {
2929 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2930 if (cc) cc->SetShowOutlines(enable);
2931 }
2932}
2933
2934void EnableDepthUnitDisplay(bool enable, int CanvasIndex) {
2935 if (CanvasIndex < GetCanvasCount()) {
2936 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2937 if (cc) cc->SetShowDepthUnits(enable);
2938 }
2939}
2940
2941void EnableAisTargetDisplay(bool enable, int CanvasIndex) {
2942 if (CanvasIndex < GetCanvasCount()) {
2943 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2944 if (cc) cc->SetShowAIS(enable);
2945 }
2946}
2947
2948void EnableTideStationsDisplay(bool enable, int CanvasIndex) {
2949 if (CanvasIndex < GetCanvasCount()) {
2950 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2951 if (cc) cc->ShowTides(enable);
2952 }
2953}
2954
2955void EnableCurrentStationsDisplay(bool enable, int CanvasIndex) {
2956 if (CanvasIndex < GetCanvasCount()) {
2957 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2958 if (cc) cc->ShowCurrents(enable);
2959 }
2960}
2961
2962void EnableENCTextDisplay(bool enable, int CanvasIndex) {
2963 if (CanvasIndex < GetCanvasCount()) {
2964 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2965 if (cc) cc->SetShowENCText(enable);
2966 }
2967}
2968
2969void EnableENCDepthSoundingsDisplay(bool enable, int CanvasIndex) {
2970 if (CanvasIndex < GetCanvasCount()) {
2971 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2972 if (cc) cc->SetShowENCDepth(enable);
2973 }
2974}
2975
2976void EnableBuoyLightLabelsDisplay(bool enable, int CanvasIndex) {
2977 if (CanvasIndex < GetCanvasCount()) {
2978 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2979 if (cc) cc->SetShowENCBuoyLabels(enable);
2980 }
2981}
2982
2983void EnableLightsDisplay(bool enable, int CanvasIndex) {
2984 if (CanvasIndex < GetCanvasCount()) {
2985 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2986 if (cc) cc->SetShowENCLights(enable);
2987 }
2988}
2989
2990void EnableLightDescriptionsDisplay(bool enable, int CanvasIndex) {
2991 if (CanvasIndex < GetCanvasCount()) {
2992 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2993 if (cc) cc->SetShowENCLightDesc(enable);
2994 }
2995}
2996
2997void SetENCDisplayCategory(PI_DisCat cat, int CanvasIndex) {
2998 int valSet = STANDARD;
2999 switch (cat) {
3000 case PI_DISPLAYBASE:
3001 valSet = DISPLAYBASE;
3002 break;
3003 case PI_STANDARD:
3004 valSet = STANDARD;
3005 break;
3006 case PI_OTHER:
3007 valSet = OTHER;
3008 break;
3010 valSet = MARINERS_STANDARD;
3011 break;
3012 default:
3013 valSet = STANDARD;
3014 break;
3015 }
3016 if (CanvasIndex < GetCanvasCount()) {
3017 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3018 if (cc) cc->SetENCDisplayCategory(valSet);
3019 }
3020}
3022 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3023 if (cc)
3024 return ((PI_DisCat)cc->GetENCDisplayCategory());
3025 else
3026 return PI_DisCat::PI_STANDARD;
3027}
3028
3029void SetNavigationMode(PI_NavMode mode, int CanvasIndex) {
3030 int newMode = NORTH_UP_MODE;
3031 if (mode == PI_COURSE_UP_MODE)
3032 newMode = COURSE_UP_MODE;
3033 else if (mode == PI_HEAD_UP_MODE)
3034 newMode = HEAD_UP_MODE;
3035
3036 if (CanvasIndex < GetCanvasCount()) {
3037 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3038 if (cc) cc->SetUpMode(newMode);
3039 }
3040}
3042 if (CanvasIndex < GetCanvasCount()) {
3043 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3044 if (cc) return ((PI_NavMode)cc->GetUpMode());
3045 }
3046 return PI_NavMode::PI_NORTH_UP_MODE;
3047}
3048
3049bool GetEnableLatLonGrid(int CanvasIndex) {
3050 if (CanvasIndex < GetCanvasCount()) {
3051 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3052 if (cc) return (cc->GetShowGrid());
3053 }
3054 return false;
3055}
3056
3057bool GetEnableChartOutlines(int CanvasIndex) {
3058 if (CanvasIndex < GetCanvasCount()) {
3059 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3060 if (cc) return (cc->GetShowOutlines());
3061 }
3062 return false;
3063}
3064
3065bool GetEnableDepthUnitDisplay(int CanvasIndex) {
3066 if (CanvasIndex < GetCanvasCount()) {
3067 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3068 if (cc) return (cc->GetShowDepthUnits());
3069 }
3070 return false;
3071}
3072
3073bool GetEnableAisTargetDisplay(int CanvasIndex) {
3074 if (CanvasIndex < GetCanvasCount()) {
3075 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3076 if (cc) return (cc->GetShowAIS());
3077 }
3078 return false;
3079}
3080
3081bool GetEnableTideStationsDisplay(int CanvasIndex) {
3082 if (CanvasIndex < GetCanvasCount()) {
3083 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3084 if (cc) return (cc->GetbShowTide());
3085 }
3086 return false;
3087}
3088
3089bool GetEnableCurrentStationsDisplay(int CanvasIndex) {
3090 if (CanvasIndex < GetCanvasCount()) {
3091 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3092 if (cc) return (cc->GetbShowCurrent());
3093 }
3094 return false;
3095}
3096
3097bool GetEnableENCTextDisplay(int CanvasIndex) {
3098 if (CanvasIndex < GetCanvasCount()) {
3099 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3100 if (cc) return (cc->GetShowENCText());
3101 }
3102 return false;
3103}
3104
3106 if (CanvasIndex < GetCanvasCount()) {
3107 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3108 if (cc) return (cc->GetShowENCDepth());
3109 }
3110 return false;
3111}
3112
3113bool GetEnableBuoyLightLabelsDisplay(int CanvasIndex) {
3114 if (CanvasIndex < GetCanvasCount()) {
3115 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3116 if (cc) return (cc->GetShowENCBuoyLabels());
3117 }
3118 return false;
3119}
3120
3121bool GetEnableLightsDisplay(int CanvasIndex) {
3122 if (CanvasIndex < GetCanvasCount()) {
3123 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3124 if (cc) return (cc->GetShowENCLights());
3125 }
3126 return false;
3127}
3128
3129bool GetShowENCLightDesc(int CanvasIndex) {
3130 if (CanvasIndex < GetCanvasCount()) {
3131 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3132 if (cc) return (cc->GetbShowCurrent());
3133 }
3134 return false;
3135}
3136
3137void EnableTouchMode(bool enable) { g_btouch = enable; }
3138
3139bool GetTouchMode() { return g_btouch; }
3140
3141void EnableLookaheadMode(bool enable, int CanvasIndex) {
3142 if (CanvasIndex < GetCanvasCount()) {
3143 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3144 if (cc) cc->ToggleLookahead();
3145 }
3146}
3147
3148bool GetEnableLookaheadMode(int CanvasIndex) {
3149 if (CanvasIndex < GetCanvasCount()) {
3150 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3151 if (cc) return (cc->GetLookahead());
3152 }
3153 return false;
3154}
3155
3156extern bool g_bTrackActive;
3157void SetTrackingMode(bool enable) {
3158 if (!g_bTrackActive && enable)
3159 gFrame->TrackOn();
3160 else if (g_bTrackActive && !enable)
3161 gFrame->TrackOff();
3162}
3163bool GetTrackingMode() { return g_bTrackActive; }
3164
3166 gFrame->SetAndApplyColorScheme((ColorScheme)cs);
3167}
3169 return (PI_ColorScheme)global_color_scheme;
3170}
3171
3172void RequestWindowRefresh(wxWindow* win, bool eraseBackground) {
3173 if (win) win->Refresh(eraseBackground);
3174}
3175
3176void EnableSplitScreenLayout(bool enable) {
3177 if (g_canvasConfig == 1) {
3178 if (enable)
3179 return;
3180 else { // split to single
3181 g_canvasConfig = 0; // 0 => "single canvas"
3182 gFrame->CreateCanvasLayout();
3183 gFrame->DoChartUpdate();
3184 }
3185 } else {
3186 if (enable) { // single to split
3187 g_canvasConfig = 1; // 1 => "two canvas"
3188 gFrame->CreateCanvasLayout();
3189 gFrame->DoChartUpdate();
3190 } else {
3191 return;
3192 }
3193 }
3194}
3195
3196// ChartCanvas control utilities
3197
3198void PluginZoomCanvas(int CanvasIndex, double factor) {
3199 if (CanvasIndex < GetCanvasCount()) {
3200 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3201 if (cc) cc->ZoomCanvasSimple(factor);
3202 }
3203}
3204
3205bool GetEnableMainToolbar() { return (!g_disable_main_toolbar); }
3206void SetEnableMainToolbar(bool enable) {
3207 g_disable_main_toolbar = !enable;
3208 if (g_MainToolbar) g_MainToolbar->RefreshToolbar();
3209}
3210
3212 if (gFrame) gFrame->ScheduleSettingsDialog();
3213}
3214
3215void PluginCenterOwnship(int CanvasIndex) {
3216 if (CanvasIndex < GetCanvasCount()) {
3217 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3218 if (cc) {
3219 bool bfollow = cc->GetbFollow();
3220 cc->ResetOwnshipOffset();
3221 if (bfollow)
3222 cc->SetbFollow();
3223 else
3224 cc->JumpToPosition(gLat, gLon, cc->GetVPScale());
3225 }
3226 }
3227}
3228
3229void PluginSetFollowMode(int CanvasIndex, bool enable_follow) {
3230 if (CanvasIndex < GetCanvasCount()) {
3231 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3232 if (cc) {
3233 if (cc->GetbFollow() != enable_follow) cc->TogglebFollow();
3234 }
3235 }
3236}
3237
3238bool PluginGetFollowMode(int CanvasIndex) {
3239 if (CanvasIndex < GetCanvasCount()) {
3240 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3241 if (cc) return cc->GetbFollow();
3242 }
3243 return false;
3244}
3245
3246void EnableCanvasFocusBar(bool enable, int CanvasIndex) {
3247 if (CanvasIndex < GetCanvasCount()) {
3248 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3249 if (cc) cc->SetShowFocusBar(enable);
3250 }
3251}
3252bool GetEnableCanvasFocusBar(int CanvasIndex) {
3253 if (CanvasIndex < GetCanvasCount()) {
3254 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
3255 if (cc) return (cc->GetShowFocusBar());
3256 }
3257 return false;
3258}
3259
3260bool GetEnableTenHertzUpdate() { return g_btenhertz; }
3261
3262void EnableTenHertzUpdate(bool enable) { g_btenhertz = enable; }
3263
3265 if (pConfig) {
3266 pConfig->Flush();
3267
3268 // Handle system general configuration options
3269 pConfig->LoadMyConfigRaw(false);
3270
3271 // Handle chart canvas window configuration options
3272 pConfig->LoadCanvasConfigs(false);
3273 auto& config_array = ConfigMgr::Get().GetCanvasConfigArray();
3274 for (auto pcc : config_array) {
3275 if (pcc && pcc->canvas) {
3276 pcc->canvas->ApplyCanvasConfig(pcc);
3277 pcc->canvas->Refresh();
3278 }
3279 }
3280 }
3281}
3282
3287 g_CanvasHideNotificationIcon = !enable;
3288}
3289
3290//---------------------------------------------------------------------------
3291// API 1.21
3292//---------------------------------------------------------------------------
3293
3294// Plugin API121 Utility functions
3295
3296wxString DropMarkPI(double lat, double lon) {
3297 if ((fabs(lat) > 80.0) || (fabs(lon) > 180.)) return "";
3298
3299 RoutePoint* pWP =
3300 new RoutePoint(lat, lon, g_default_wp_icon, wxEmptyString, wxEmptyString);
3301 pWP->m_bIsolatedMark = true; // This is an isolated mark
3302 pSelect->AddSelectableRoutePoint(lat, lon, pWP);
3303 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
3304 return pWP->m_GUID;
3305}
3306
3307wxString RouteCreatePI(int canvas_index, bool start) {
3308 if ((size_t)canvas_index < g_canvasArray.GetCount()) {
3309 ChartCanvas* cc = g_canvasArray.Item(canvas_index);
3310 if (cc) {
3311 if (start) {
3312 cc->StartRoute();
3313 return "0";
3314 } else {
3315 return cc->FinishRoute();
3316 }
3317 }
3318 }
3319 return "-1";
3320}
3321
3322bool DoMeasurePI(int canvas_index, bool start) {
3323 if ((size_t)canvas_index < g_canvasArray.GetCount()) {
3324 ChartCanvas* cc = g_canvasArray.Item(canvas_index);
3325 if (cc) {
3326 if (start) {
3327 cc->StartMeasureRoute();
3328 return true;
3329 } else {
3330 cc->CancelMeasureRoute();
3331 cc->Refresh(false);
3332 return true;
3333 }
3334 }
3335 }
3336 return false;
3337}
3338
3339wxString NavToHerePI(double lat, double lon) {
3340 RoutePoint* pWP_dest =
3341 new RoutePoint(lat, lon, g_default_wp_icon, wxEmptyString, wxEmptyString);
3342 pSelect->AddSelectableRoutePoint(lat, lon, pWP_dest);
3343
3344 RoutePoint* pWP_src = new RoutePoint(gLat, gLon, g_default_wp_icon,
3345 wxEmptyString, wxEmptyString);
3346 pSelect->AddSelectableRoutePoint(gLat, gLon, pWP_src);
3347
3348 Route* temp_route = new Route();
3349 pRouteList->Append(temp_route);
3350
3351 temp_route->AddPoint(pWP_src);
3352 temp_route->AddPoint(pWP_dest);
3353
3354 pSelect->AddSelectableRouteSegment(gLat, gLon, lat, lon, pWP_src, pWP_dest,
3355 temp_route);
3356
3357 temp_route->m_RouteNameString = _("Temporary GOTO Route");
3358 temp_route->m_RouteStartString = _("Here");
3359 temp_route->m_RouteEndString = _("There");
3360 temp_route->m_bDeleteOnArrival = true;
3361
3362 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
3363
3364 g_pRouteMan->ActivateRoute(temp_route, pWP_dest);
3365 return temp_route->m_GUID;
3366}
3367
3368bool ActivateRoutePI(wxString route_guid, bool activate) {
3369 Route* route = g_pRouteMan->FindRouteByGUID(route_guid);
3370 if (!route) return false;
3371
3372 if (activate) {
3373 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
3374 RoutePoint* best_point =
3375 g_pRouteMan->FindBestActivatePoint(route, gLat, gLon, gCog, gSog);
3376 g_pRouteMan->ActivateRoute(route, best_point);
3377 route->m_bRtIsSelected = false;
3378 return true;
3379 } else {
3380 g_pRouteMan->DeactivateRoute();
3381 route->m_bRtIsSelected = false;
3382 return true;
3383 }
3384 return false;
3385}
3386
3387void EnableDefaultConsole(bool enable) { g_bhide_route_console = !enable; }
3388void EnableDefaultContextMenus(bool enable) { g_bhide_context_menus = !enable; }
3389
3390void SetMinZoomScale(double min_scale) {
3391 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
3392 ChartCanvas* cc = g_canvasArray.Item(i);
3393 cc->SetAbsoluteMinScale(min_scale);
3394 }
3395}
3396
3397void SetMaxZoomScale(double max_scale) {
3398 g_maxzoomin = wxRound(wxMax(max_scale, 100.));
3399}
3400
3401std::shared_ptr<PI_PointContext> GetContextAtPoint(int x, int y,
3402 int canvas_index) {
3403 ChartCanvas* cc = g_canvasArray.Item(canvas_index);
3404 if (cc) {
3405 return cc->GetCanvasContextAtPoint(x, y);
3406 } else {
3407 auto rstruct = std::make_shared<PI_PointContext>();
3408 rstruct->object_type = OBJECT_UNKNOWN;
3409 rstruct->object_ident = "";
3410 return rstruct;
3411 }
3412}
3413
3414wxBitmap GetObjectIcon_PlugIn(const wxString& name) {
3415 if (pWayPointMan) {
3416 return *pWayPointMan->GetIconBitmap(name);
3417 } else
3418 return wxNullBitmap;
3419}
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:153
float GetVPScale()
Return the ViewPort scale factor, in physical pixels per meter.
Definition chcanv.h:468
void ZoomCanvasSimple(double factor)
Perform an immediate zoom operation without smooth transitions.
Definition chcanv.cpp:4649
Manages the chart database and provides access to chart data.
Definition chartdb.h:95
bool LoadBinary(const wxString &filename, ArrayOfCDI &dir_array_check)
Load the chart database from a binary file.
Definition chartdb.cpp:233
Wrapper class for plugin-based charts.
Definition chartimg.h:392
wxFont * FindOrCreateFont(int point_size, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underline=false, const wxString &facename=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
Creates or finds a matching font in the font cache.
Definition FontMgr.cpp:467
wxColour GetFontColor(const wxString &TextElement) const
Gets the text color for a UI element.
Definition FontMgr.cpp:117
bool AddAuxKey(wxString key)
Adds new plugin-defined font configuration key.
Definition FontMgr.cpp:684
bool SetFontColor(const wxString &TextElement, const wxColour color) const
Sets the text color for a UI element.
Definition FontMgr.cpp:122
static wxString GetUUID(void)
Return a unique RFC4122 version 4 compliant GUID string.
Main application frame.
Definition ocpn_frame.h:136
Provides platform-specific support utilities for OpenCPN.
double GetDisplaySizeMM()
Get the width of the screen in millimeters.
Extended OpenGL-optimized chart base class with additional querying capabilities.
virtual ListOfPI_S57Obj * GetLightsObjRuleListVisibleAtLatLon(float lat, float lon, PlugIn_ViewPort *VPoint)
Gets list of visible light objects at specified position.
Basic data for a loaded plugin, trivially copyable.
AIS target information accessible to plugins.
double HDG
Heading in degrees true.
int ROTAIS
Rate of turn as indicated in AIS message.
unsigned char ShipType
Ship type as per ITU-R M.1371.
double Lat
Latitude in decimal degrees.
int MMSI
Maritime Mobile Service Identity number.
bool bCPA_Valid
True if CPA calculation is valid.
double Brg
Bearing to target in degrees true.
double Lon
Longitude in decimal degrees.
double CPA
Closest Point of Approach in nautical miles.
int Class
AIS class (Class A: 0, Class B: 1)
double SOG
Speed over ground in knots.
double Range_NM
Range to target in nautical miles.
int NavStatus
Navigational status (0-15 as per ITU-R M.1371)
int IMO
IMO ship identification number.
double TCPA
Time to Closest Point of Approach in minutes.
double COG
Course over ground in degrees.
plugin_ais_alarm_type alarm_state
Current alarm state for this target.
Extended position fix information.
int nSats
Number of satellites used in the fix.
double Var
Magnetic variation in degrees, typically from RMC message.
double Cog
Course over ground in degrees [0-360).
double Lat
Latitude in decimal degrees.
double Hdm
Heading magnetic in degrees [0-360).
time_t FixTime
UTC time of fix.
double Lon
Longitude in decimal degrees.
double Sog
Speed over ground in knots.
double Hdt
Heading true in degrees [0-360).
Enhanced route class for working with PlugIn_Waypoint_ExV2 waypoints.
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.
bool m_isActive
True if this is the active route.
wxString m_GUID
Globally unique identifier.
wxString m_EndString
Description of route end point.
Extended route class for managing complex route features.
wxString m_Description
Optional route description/notes.
wxString m_EndString
Description of route end point.
Plugin_WaypointExList * pWaypointList
List of waypoints making up this route in order.
wxString m_NameString
User-visible name of the route.
bool m_isVisible
True if route should be displayed.
wxString m_GUID
Globally unique identifier.
bool m_isActive
True if this is the active route.
wxString m_StartString
Description of route start point.
Plugin route class for managing ordered waypoint collections.
wxString m_GUID
Globally unique identifier.
wxString m_EndString
Name/description of ending point.
wxString m_NameString
Route name.
Plugin_WaypointList * pWaypointList
List of waypoints making up this route in order.
wxString m_StartString
Name/description of starting point.
Plugin track class for managing recorded track data.
Plugin_WaypointList * pWaypointList
List of waypoints making up this track in chronological order.
wxString m_GUID
Globally unique identifier.
wxString m_EndString
Description of track end point/time.
wxString m_StartString
Description of track start point/time.
wxString m_NameString
Display name of the track.
Contains view parameters and status information for a chart display viewport.
double view_scale_ppm
Display scale in pixels per meter.
wxRect rv_rect
Rectangle defining the rendered view area.
int pix_width
Viewport width in pixels.
double lon_max
Maximum longitude of the viewport.
double clon
Center longitude of the viewport in decimal degrees.
double lat_max
Maximum latitude of the viewport.
int pix_height
Viewport height in pixels.
double clat
Center latitude of the viewport in decimal degrees.
double skew
Display skew angle in radians.
double rotation
Display rotation angle in radians.
bool bValid
True if this viewport is valid and can be used for rendering.
double lon_min
Minimum longitude of the viewport.
double lat_min
Minimum latitude of the viewport.
int m_projection_type
Chart projection type (PROJECTION_MERCATOR, etc.)
bool b_quilt
True if the viewport is in quilt mode (showing multiple charts)
float chart_scale
Conventional chart displayed scale (e.g., 1:50000)
wxDateTime m_ETD
Estimated departure time in UTC, or wxInvalidDateTime if not set.
wxString m_MarkDescription
Optional description text.
int GetRouteMembershipCount()
Gets number of routes containing this waypoint.
wxString m_GUID
Globally unique identifier.
wxString m_TideStation
Tide Station Identifier.
void InitDefaults()
Initializes waypoint properties to default values.
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.
bool GetFSStatus()
Gets "free-standing" status of waypoint.
Extended waypoint class with additional navigation features.
bool GetFSStatus()
Gets "free-standing" status of waypoint.
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.
void InitDefaults()
Initializes waypoint properties to default values.
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.
int GetRouteMembershipCount()
Gets number of routes containing this waypoint.
bool IsActive
Active state (e.g. destination)
bool IsVisible
Visibility state on chart.
Plugin waypoint class providing core waypoint/mark functionality.
double m_lon
Longitude in decimal degrees.
wxString m_IconName
Icon identifier.
wxString m_MarkDescription
Optional description.
wxString m_GUID
Globally unique identifier.
bool m_IsVisible
Visibility state.
PlugIn_Waypoint()
Default constructor - creates waypoint at 0,0.
wxDateTime m_CreateTime
Creation timestamp in UTC.
wxString m_MarkName
Display name.
double m_lat
Latitude in decimal degrees.
Plugin_HyperlinkList * m_HyperlinkList
List of associated hyperlinks.
Represents a waypoint or mark within the navigation system.
Definition route_point.h:70
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_bIsInRoute
Flag indicating if this waypoint is part of a route.
bool m_bShowName
Flag indicating if the waypoint name should be shown.
double GetPlannedSpeed()
Return the planned speed associated with this waypoint.
bool m_bIsInLayer
Flag indicating if the waypoint belongs to a layer.
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:98
bool m_bRtIsSelected
Flag indicating whether this route is currently selected in the UI.
Definition route.h:202
wxString m_RouteStartString
Name or description of the route's starting point.
Definition route.h:251
wxString m_RouteDescription
Additional descriptive information about the route.
Definition route.h:261
RoutePointList * pRoutePointList
Ordered list of waypoints (RoutePoints) that make up this route.
Definition route.h:335
bool m_bDeleteOnArrival
Flag indicating whether the route should be deleted once navigation reaches the end.
Definition route.h:267
wxString m_RouteEndString
Name or description of the route's ending point.
Definition route.h:256
bool m_btemp
Flag indicating if this is a temporary route.
Definition route.h:350
wxString m_RouteNameString
User-assigned name for the route.
Definition route.h:246
wxString m_GUID
Globally unique identifier for this route.
Definition route.h:272
wxDateTime m_PlannedDeparture
Planned departure time for the route, in UTC.
Definition route.h:325
bool m_bIsInLayer
Flag indicating whether this route belongs to a layer.
Definition route.h:277
bool DeleteRoute(Route *pRoute)
Definition routeman.cpp:834
bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint=NULL)
Activates a route for navigation.
Definition routeman.cpp:279
Manages a set of ShapeBaseChart objects at different resolutions.
Represents a single point in a track.
Definition track.h:53
wxDateTime GetCreateTime(void)
Retrieves the creation timestamp of a track point as a wxDateTime object.
Definition track.cpp:140
void SetCreateTime(wxDateTime dt)
Sets the creation timestamp for a track point.
Definition track.cpp:146
Represents a track, which is a series of connected track points.
Definition track.h:111
ViewPort - Core geographic projection and coordinate transformation engine.
Definition viewport.h:81
double view_scale_ppm
Requested view scale in physical pixels per meter (ppm), before applying projections.
Definition viewport.h:229
double ref_scale
The nominal scale of the "reference chart" for this view.
Definition viewport.h:246
int pix_height
Height of the viewport in physical pixels.
Definition viewport.h:258
void SetBoxes(void)
Computes the bounding box coordinates for the current viewport.
Definition viewport.cpp:823
double rotation
Rotation angle of the viewport in radians.
Definition viewport.h:239
int pix_width
Width of the viewport in physical pixels.
Definition viewport.h:256
wxPoint2DDouble GetDoublePixFromLL(double lat, double lon)
Convert latitude and longitude on the ViewPort to physical pixel coordinates with double precision.
Definition viewport.cpp:145
double skew
Angular distortion (shear transform) applied to the viewport in radians.
Definition viewport.h:237
void GetLLFromPix(const wxPoint &p, double *lat, double *lon)
Convert physical pixel coordinates on the ViewPort to latitude and longitude.
Definition viewport.h:105
double clon
Center longitude of the viewport in degrees.
Definition viewport.h:224
double clat
Center latitude of the viewport in degrees.
Definition viewport.h:222
wxPoint GetPixFromLL(double lat, double lon)
Convert latitude and longitude on the ViewPort to physical pixel coordinates.
Definition viewport.cpp:136
double chart_scale
Chart scale denominator (e.g., 50000 for a 1:50000 scale).
Definition viewport.h:244
Device context class that can use either wxDC or OpenGL for drawing.
Definition ocpndc.h:64
Floating toolbar dialog for OpenCPN.
Definition toolbar.h:386
Base class for OpenCPN plugins.
Raw messages layer, supports sending and recieving navmsg messages.
wxFont GetOCPNGUIScaledFont(wxString item)
Retrieves a font optimized for touch and high-resolution interfaces.
Definition gui_lib.cpp:83
General purpose GUI support.
Class NavObj_dB.
Class NotificationManager.
PlugIn Object Definition/API.
@ OBJECTS_ALL
Return all objects including those in layers.
@ OBJECTS_ONLY_LAYERS
Return only objects that are in layers.
@ OBJECTS_NO_LAYERS
Exclude objects that are in layers.
plugin_ais_alarm_type
Enumeration of AIS alarm states.
enum _PI_DisCat PI_DisCat
Display categories for S52 chart features.
PI_ColorScheme
Enumeration of color schemes.
@ PI_COURSE_UP_MODE
Course Up Mode - Current course over ground at the top.
@ PI_HEAD_UP_MODE
Head Up Mode - Current vessel heading at the top.
@ PI_OTHER
Other - additional features for detailed navigation.
@ PI_DISPLAYBASE
Display Base - features that must always be shown.
@ PI_STANDARD
Standard - default features for safe navigation.
@ PI_MARINERS_STANDARD
Mariner specified standard features.
enum _PI_NavMode PI_NavMode
Navigation mode options for chart display orientation.
enum _OBJECT_LAYER_REQ OBJECT_LAYER_REQ
Filter options for object queries.
OptionsParentPI
Enum defining parent pages in OpenCPN options dialog where plugins can add panels.
@ PI_OPTIONS_PARENT_DISPLAY
Display settings section.
@ PI_OPTIONS_PARENT_UI
User Interface section.
@ PI_OPTIONS_PARENT_SHIPS
Ships section.
@ PI_OPTIONS_PARENT_CHARTS
Charts section.
@ PI_OPTIONS_PARENT_PLUGINS
Plugins section.
@ PI_OPTIONS_PARENT_CONNECTIONS
Connections section.
void EnableNotificationCanvasIcon(bool enable)
Plugin Notification Framework GUI support.
void SetCanvasContextMenuItemGrey(int item, bool grey)
Sets menu item enabled/disabled state.
bool UpdateSingleWaypoint(PlugIn_Waypoint *pwaypoint)
Updates a single waypoint.
bool PlugInHasNormalizedViewPort(PlugIn_ViewPort *vp)
Checks if viewport has been normalized.
void PluginCenterOwnship(int CanvasIndex)
Center the chart view on the own ship position for a specific canvas.
void SetCanvasRotation(double rotation)
Sets chart display rotation angle.
wxString GetSelectedWaypointGUID_Plugin()
Gets GUID of currently selected waypoint.
int GetChartbarHeight(void)
Gets height of chart bar in pixels.
void RemovePlugInTool(int tool_id)
Removes a tool from OpenCPN's toolbar.
void SetCanvasProjection(int projection)
Sets chart projection type.
wxString * GetpSharedDataLocation(void)
Gets shared application data location.
double toUsrTemp_Plugin(double cel_temp, int unit)
Converts Celsius to user's preferred temperature unit.
wxWindow * PluginGetFocusCanvas()
Gets the currently focused chart canvas.
int AddChartToDBInPlace(wxString &full_path, bool b_RefreshCanvas)
Adds a chart to the database without full rebuild.
void fromSM_Plugin(double x, double y, double lat0, double lon0, double *lat, double *lon)
Converts Simple Mercator coordinates to geographic.
wxWindow * GetOCPNCanvasWindow()
Gets OpenCPN's main canvas window.
bool GetEnableLatLonGrid(int CanvasIndex)
Gets latitude/longitude grid visibility state.
bool UpdatePlugInRouteEx(PlugIn_Route_Ex *proute)
Updates an existing extended route.
void SetCanvasContextMenuItemViz(int item, bool viz)
Temporarily changes context menu item visibility.
int PlatformDirSelectorDialog(wxWindow *parent, wxString *file_spec, wxString Title, wxString initDir)
Shows platform-optimized directory selector dialog.
bool GetTouchMode()
Gets touch interface mode state.
int GetCanvasCount()
Gets total number of chart canvases.
bool GetSingleWaypointExV2(wxString GUID, PlugIn_Waypoint_ExV2 *pwaypoint)
Gets extended waypoint data by GUID.
ArrayOfPlugIn_AIS_Targets * GetAISTargetArray(void)
Gets array of AIS targets.
wxString getUsrWindSpeedUnit_Plugin(int unit)
Gets display string for user's preferred wind speed unit.
void SetCanvasMenuItemViz(int item, bool viz, const char *name)
Temporarily changes context menu item visibility.
void PlugInMultMatrixViewport(PlugIn_ViewPort *vp, float lat, float lon)
Applies viewport transformation matrix.
wxFont * OCPNGetFont(wxString TextElement, int default_size)
Gets a font for UI elements.
bool GetEnableMainToolbar()
Check if the main toolbar is enabled.
bool GetEnableENCTextDisplay(int CanvasIndex)
Gets ENC text label visibility.
bool UpdateSingleWaypointEx(PlugIn_Waypoint_Ex *pwaypoint)
Updates an existing extended waypoint.
wxArrayString GetTrackGUIDArray(void)
Gets array of track GUIDs.
wxString getUsrDistanceUnit_Plugin(int unit)
Gets display string for user's preferred distance unit.
bool DeletePlugInTrack(wxString &GUID)
Deletes a track.
bool DeletePlugInRoute(wxString &GUID)
Deletes a route.
void EnableSplitScreenLayout(bool enable)
Enable or disable the split-screen layout.
double toUsrWindSpeed_Plugin(double kts_speed, int unit)
Converts knots to user's preferred wind speed unit.
bool GetEnableLightsDisplay(int CanvasIndex)
Gets light icon visibility.
wxFont GetOCPNGUIScaledFont_PlugIn(wxString item)
Gets a uniquely scaled font copy for responsive UI elements.
wxBitmap GetBitmapFromSVGFile(wxString filename, unsigned int width, unsigned int height)
Creates bitmap from SVG file.
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.
int GetGlobalWatchdogTimoutSeconds()
Comm Global Watchdog Query
wxColour GetFontColour_PlugIn(wxString TextElement)
Gets color configured for a UI text element.
void EnableChartBar(bool enable, int CanvasIndex)
Controls visibility of chart info bar.
void PositionBearingDistanceMercator_Plugin(double lat, double lon, double brg, double dist, double *dlat, double *dlon)
Calculates destination point given starting point, bearing and distance.
double toUsrDistance_Plugin(double nm_distance, int unit)
Converts nautical miles to user's preferred distance unit.
void SetENCDisplayCategory(PI_DisCat cat, int CanvasIndex)
Sets ENC (Electronic Navigation Chart) feature display category.
void toSM_Plugin(double lat, double lon, double lat0, double lon0, double *x, double *y)
Converts geographic coordinates to Simple Mercator projection.
PI_DisCat GetENCDisplayCategory(int CanvasIndex)
Gets current ENC display category.
void EnableTouchMode(bool enable)
Enables/disables touch interface mode.
void EnableCurrentStationsDisplay(bool enable, int CanvasIndex)
Controls current station icon display.
void EnableChartOutlines(bool enable, int CanvasIndex)
Controls chart outline display.
void EnableMUIBar(bool enable, int CanvasIndex)
Controls visibility of MUI (Mobile/Touch User Interface) bar.
double OCPN_GetDisplayContentScaleFactor()
Gets content scaling factor for current display.
double DistGreatCircle_Plugin(double slat, double slon, double dlat, double dlon)
Calculates great circle distance between two points.
bool AddSingleWaypointExV2(PlugIn_Waypoint_ExV2 *pwaypointex, bool b_permanent)
Adds a waypoint with extended V2 properties.
void EnableLookaheadMode(bool enable, int CanvasIndex)
Enables/disables look-ahead mode for a canvas.
bool PluginGetFollowMode(int CanvasIndex)
Get the current follow mode status for a specific canvas.
wxArrayString GetRouteGUIDArray(void)
Gets array of route GUIDs.
wxScrolledWindow * AddOptionsPage(OptionsParentPI parent, wxString title)
Adds a new preferences page to OpenCPN options dialog.
void EnableLightsDisplay(bool enable, int CanvasIndex)
Controls light icon display.
void PlugInHandleAutopilotRoute(bool enable)
Controls autopilot route handling.
wxString getUsrDepthUnit_Plugin(int unit)
Gets display string for user's preferred depth unit.
void RemoveCanvasMenuItem(int item, const char *name)
Removes a context menu item completely.
void JumpToPosition(double lat, double lon, double scale)
Centers chart display on specified position at given scale.
int InsertPlugInToolSVG(wxString label, wxString SVGfile, wxString SVGfileRollover, wxString SVGfileToggled, wxItemKind kind, wxString shortHelp, wxString longHelp, wxObject *clientData, int position, int tool_sel, opencpn_plugin *pplugin)
Adds a tool using SVG graphics.
bool GetEnableCurrentStationsDisplay(int CanvasIndex)
Gets current station icon visibility.
wxDialog * GetActiveOptionsDialog()
Gets pointer to active options dialog.
wxString getUsrSpeedUnit_Plugin(int unit)
Gets display string for user's preferred speed unit.
std::unique_ptr< PlugIn_Waypoint > GetWaypoint_Plugin(const wxString &GUID)
Gets waypoint details by GUID.
bool GetEnableLookaheadMode(int CanvasIndex)
Gets look-ahead mode state for a canvas.
void EnableTideStationsDisplay(bool enable, int CanvasIndex)
Controls tide station icon display.
bool GetEnableChartBar(int CanvasIndex)
Gets chart bar visibility state.
wxBitmap GetIcon_PlugIn(const wxString &name)
Gets icon bitmap by name.
wxArrayString GetIconNameArray(void)
Gets array of available waypoint icons.
bool PlugIn_GSHHS_CrossesLand(double lat1, double lon1, double lat2, double lon2)
Checks if a great circle route crosses land.
void SetNavigationMode(PI_NavMode mode, int CanvasIndex)
Sets the navigation mode for a specific chart canvas.
bool GetEnableStatusBar()
Gets status bar visibility state.
bool GetEnableDepthUnitDisplay(int CanvasIndex)
Gets depth unit display state.
int InsertPlugInTool(wxString label, wxBitmap *bitmap, wxBitmap *bmpRollover, wxItemKind kind, wxString shortHelp, wxString longHelp, wxObject *clientData, int position, int tool_sel, opencpn_plugin *pplugin)
Adds a tool to OpenCPN's toolbar.
void EnableENCDepthSoundingsDisplay(bool enable, int CanvasIndex)
Controls ENC depth sounding display.
void PlugInAISDrawGL(wxGLCanvas *glcanvas, const PlugIn_ViewPort &vp)
Renders AIS targets on a secondary OpenGL canvas.
double GetCanvasTilt()
Gets current canvas tilt angle.
void AddChartDirectory(wxString &path)
Adds a chart directory to OpenCPN's chart database.
double fromDMM_PlugIn(wxString sdms)
Parse a formatted coordinate string to get decimal degrees.
double toUsrDepth_Plugin(double m_depth, int unit)
Converts meters to user's preferred depth unit.
bool GetActiveRoutepointGPX(char *buffer, unsigned int buffer_length)
Gets GPX representation of active route waypoint.
std::unique_ptr< PlugIn_Waypoint_ExV2 > GetWaypointExV2_Plugin(const wxString &GUID)
Gets complete waypoint details by GUID.
double PlugInGetDisplaySizeMM()
Gets physical display size in millimeters.
bool UpdatePlugInRoute(PlugIn_Route *proute)
Updates an existing route.
void SetToolbarToolBitmaps(int item, wxBitmap *bitmap, wxBitmap *bmpRollover)
Updates toolbar tool bitmaps.
void EnableBuoyLightLabelsDisplay(bool enable, int CanvasIndex)
Controls buoy/light name label display.
wxString GetActiveWaypointGUID(void)
Gets GUID of currently active waypoint.
void ConfigFlushAndReload()
Flush configuration changes to disk and reload settings.
void EnableAisTargetDisplay(bool enable, int CanvasIndex)
Controls AIS target display.
int PlatformFileSelectorDialog(wxWindow *parent, wxString *file_spec, wxString Title, wxString initDir, wxString suggestedName, wxString wildcard)
Shows platform-optimized file selector dialog.
bool CheckMUIEdgePan_PlugIn(int x, int y, bool dragging, int margin, int delta, int canvasIndex)
Checks if chart should pan when cursor near edge.
std::unique_ptr< PlugIn_Route_ExV2 > GetRouteExV2_Plugin(const wxString &GUID)
Gets route details with V2 waypoints by GUID.
double fromUsrDepth_Plugin(double usr_depth, int unit)
Converts from user's preferred depth unit to meters.
bool AddPlugInRoute(PlugIn_Route *proute, bool b_permanent)
Adds a new route.
wxString GetNewGUID(void)
Generates a new globally unique identifier (GUID).
double fromDMM_Plugin(wxString sdms)
Converts degrees/decimal minutes string to decimal degrees.
void EnableENCTextDisplay(bool enable, int CanvasIndex)
Controls ENC text label display.
int GetCanvasIndexUnderMouse(void)
Gets index of chart canvas under mouse cursor.
void EnableTenHertzUpdate(bool enable)
Enable or disable 10 Hz update rate.
wxRect GetMasterToolbarRect()
Gets bounding rectangle of master toolbar.
void toTM_Plugin(float lat, float lon, float lat0, float lon0, double *x, double *y)
Converts geographic coordinates to Transverse Mercator projection.
void CanvasJumpToPosition(wxWindow *canvas, double lat, double lon, double scale)
Centers specified canvas on given position at given scale.
bool GetGlobalColor(wxString colorName, wxColour *pcolour)
Gets a global color value.
double fromUsrSpeed_Plugin(double usr_speed, int unit)
Converts from user's preferred speed unit to knots.
void GetDoubleCanvasPixLL(PlugIn_ViewPort *vp, wxPoint2DDouble *pp, double lat, double lon)
Converts lat/lon to canvas pixels with double precision.
std::unique_ptr< PlugIn_Track > GetTrack_Plugin(const wxString &GUID)
Gets track details by GUID.
bool PlugInPlaySoundEx(wxString &sound_file, int deviceIndex)
Start playing a sound file asynchronously.
void EnableCompassGPSIcon(bool enable, int CanvasIndex)
Controls visibility of compass/GPS status icon.
wxString GetActiveRouteGUID(void)
Gets GUID of currently active route.
void EnableDepthUnitDisplay(bool enable, int CanvasIndex)
Controls depth unit display.
bool GetEnableTideStationsDisplay(int CanvasIndex)
Gets tide station icon visibility.
bool PlugInSetFontColor(const wxString TextElement, const wxColour color)
Sets text color for a UI element.
wxWindow * GetCanvasUnderMouse(void)
Gets canvas window under mouse cursor.
std::unique_ptr< PlugIn_Waypoint_Ex > GetWaypointEx_Plugin(const wxString &GUID)
Gets extended waypoint by GUID.
bool GetTrackingMode()
Get the current tracking mode status.
bool GetEnableChartOutlines(int CanvasIndex)
Gets chart outline visibility state.
void GetCanvasPixLL(PlugIn_ViewPort *vp, wxPoint *pp, double lat, double lon)
Converts lat/lon to canvas physical pixel coordinates.
wxColor GetGlobalColorD(std::string map_name, std::string name)
Gets a color from the global color scheme.
bool GetEnableCompassGPSIcon(int CanvasIndex)
Gets compass icon visibility state.
void SetMUICursor_PlugIn(wxCursor *pCursor, int canvasIndex)
Sets mouse cursor for specific canvas.
void EnableMenu(bool enable)
Shows/hides the main menu bar.
void DimeWindow(wxWindow *win)
Applies system color scheme to window.
bool GetEnableAisTargetDisplay(int CanvasIndex)
Gets AIS target display state.
bool AddPlugInRouteExV2(PlugIn_Route_ExV2 *proute, bool b_permanent)
Adds a new route with V2 waypoints.
std::vector< std::string > GetPriorityMaps()
Comm Priority query support methods
double GetOCPNGUIToolScaleFactor_PlugIn()
Gets current global GUI scaling factor.
void SetToolbarToolBitmapsSVG(int item, wxString SVGfile, wxString SVGfileRollover, wxString SVGfileToggled)
Updates SVG graphics for toolbar tool.
wxString getUsrTempUnit_Plugin(int unit)
Gets display string for user's preferred temperature unit.
bool AddSingleWaypointEx(PlugIn_Waypoint_Ex *pwaypointex, bool b_permanent)
Adds a waypoint with extended properties.
wxArrayString GetWaypointGUIDArray(void)
Gets array of all waypoint/marks GUIDs.
int AddCanvasContextMenuItem(wxMenuItem *pitem, opencpn_plugin *pplugin)
Adds item to chart canvas context menu.
wxString GetActiveStyleName()
Gets name of currently active style sheet.
wxArrayString GetChartDBDirArrayString()
Gets chart database directory list.
void SetCursor_PlugIn(wxCursor *pCursor)
Sets mouse cursor.
bool GetEnableTenHertzUpdate()
Check if 10 Hz update rate is enabled.
wxString GetLocaleCanonicalName()
Gets system locale canonical name.
wxWindow * PluginGetOverlayRenderCanvas()
Gets the canvas currently designated for overlay rendering.
bool AddPersistentFontKey(wxString TextElement)
Registers a new font configuration element.
bool AddPlugInTrack(PlugIn_Track *ptrack, bool b_permanent)
Adds a new track.
bool UpdateChartDBInplace(wxArrayString dir_array, bool b_force_update, bool b_ProgressDialog)
Updates chart database in place.
void UpdateAndApplyPriorityMaps(std::vector< std::string > map)
Sets and applies new priority mapping scheme.
void RequestWindowRefresh(wxWindow *win, bool eraseBackground)
Requests window refresh.
void EnableLatLonGrid(bool enable, int CanvasIndex)
Controls latitude/longitude grid display.
void SetAppColorScheme(PI_ColorScheme cs)
Set the application color scheme.
bool DeleteSingleWaypoint(wxString &GUID)
Deletes a single waypoint.
void RemoveCanvasContextMenuItem(int item)
Removes a context menu item completely.
bool DecodeSingleVDOMessage(const wxString &str, PlugIn_Position_Fix_Ex *pos, wxString *accumulator)
Decodes a single VDO (Own Ship AIS) message.
bool AddCustomWaypointIcon(wxBitmap *pimage, wxString key, wxString description)
Adds a custom waypoint icon.
bool CheckEdgePan_PlugIn(int x, int y, bool dragging, int margin, int delta)
Checks if chart should pan when cursor near edge.
double toUsrSpeed_Plugin(double kts_speed, int unit)
Converts knots to user's preferred speed unit.
std::unique_ptr< PlugIn_Route_Ex > GetRouteEx_Plugin(const wxString &GUID)
Gets extended route by GUID.
bool UpdatePlugInRouteExV2(PlugIn_Route_ExV2 *proute)
Updates existing route with V2 waypoints.
std::vector< std::string > GetActivePriorityIdentifiers()
Gets list of active priority identifiers.
bool GetEnableENCDepthSoundingsDisplay(int CanvasIndex)
Gets ENC depth sounding visibility.
void SetToolbarItemState(int item, bool toggle)
Sets toolbar item toggle state.
bool DeleteOptionsPage(wxScrolledWindow *page)
Remove a previously added options page.
void EnableLightDescriptionsDisplay(bool enable, int CanvasIndex)
Controls light description text display.
float GetOCPNChartScaleFactor_Plugin()
Gets chart rendering scale factor.
PI_NavMode GetNavigationMode(int CanvasIndex)
Gets current navigation mode for a canvas.
int AddCanvasMenuItem(wxMenuItem *pitem, opencpn_plugin *pplugin, const char *name)
Adds item to canvas context menu.
int RemoveChartFromDBInPlace(wxString &full_path)
Removes a chart from database without full rebuild.
void PlugInNormalizeViewport(PlugIn_ViewPort *vp, float lat, float lon)
Normalizes viewport parameters.
PI_ColorScheme GetAppColorScheme()
Get the current application color scheme.
void ExitOCPN()
Exits OpenCPN application.
wxWindow * GetCanvasByIndex(int canvasIndex)
Gets chart canvas window by index.
void fromTM_Plugin(double x, double y, double lat0, double lon0, double *lat, double *lon)
Converts Transverse Mercator coordinates to geographic.
double OCPN_GetWinDIPScaleFactor()
Gets Windows-specific DPI scaling factor.
void PushNMEABuffer(wxString buf)
Pushes NMEA sentence to the system.
void SetEnableMainToolbar(bool enable)
Show or hide the main toolbar.
void SetFullScreen(bool set_full_screen_on)
Sets full screen mode.
bool GetEnableMenu()
Gets menu bar visibility state.
void SetCanvasMenuItemGrey(int item, bool grey, const char *name)
Sets menu item enabled/disabled state.
bool GetEnableBuoyLightLabelsDisplay(int CanvasIndex)
Gets buoy/light label visibility.
double fromUsrWindSpeed_Plugin(double usr_wspeed, int unit)
Converts from user's preferred wind speed unit to knots.
bool GetEnableCanvasFocusBar(int CanvasIndex)
Gets focus indicator visibility state.
wxXmlDocument GetChartDatabaseEntryXML(int dbIndex, bool b_getGeom)
Gets chart database entry as XML.
wxAuiManager * GetFrameAuiManager(void)
Gets main frame AUI manager.
void SendPluginMessage(wxString message_id, wxString message_body)
Sends message to other plugins.
bool AddPlugInRouteEx(PlugIn_Route_Ex *proute, bool b_permanent)
Adds a route with extended features.
void fromSM_ECC_Plugin(double x, double y, double lat0, double lon0, double *lat, double *lon)
Converts Elliptical Simple Mercator coordinates to geographic.
void EnableStatusBar(bool enable)
Shows/hides the status bar.
void RequestRefresh(wxWindow *win)
Requests window refresh.
bool UpdateSingleWaypointExV2(PlugIn_Waypoint_ExV2 *pwaypoint)
Updates an existing extended V2 waypoint.
void PluginZoomCanvas(int CanvasIndex, double factor)
Zoom a specific chart canvas by the given factor.
int GetLatLonFormat()
Gets currently selected latitude/longitude display format.
bool AddSingleWaypoint(PlugIn_Waypoint *pwaypoint, bool b_permanent)
Adds a single waypoint.
bool IsTouchInterface_PlugIn(void)
Checks if touch interface mode is enabled.
bool GetSingleWaypoint(wxString GUID, PlugIn_Waypoint *pwaypoint)
Gets waypoint data by GUID.
void SetToolbarToolViz(int item, bool viz)
Temporarily changes toolbar tool visibility.
double fromUsrTemp_Plugin(double usr_temp, int unit)
Converts from user's preferred temperature unit to Celsius.
void SetCanvasTilt(double tilt)
Gets current canvas tilt angle.
std::unique_ptr< PlugIn_Route > GetRoute_Plugin(const wxString &GUID)
Gets route details by GUID.
bool GetEnableMUIBar(int CanvasIndex)
Gets MUI bar visibility state.
bool AddLocaleCatalog(wxString catalog)
Adds a locale catalog for translations.
bool GetFullScreen()
Gets full screen state.
void SetTrackingMode(bool enable)
Enable or disable tracking mode.
wxString g_locale
Global locale setting for OpenCPN UI.
Definition ocpn_app.cpp:592
void PluginSetFollowMode(int CanvasIndex, bool enable_follow)
Set follow mode for a specific canvas.
void ShowGlobalSettingsDialog()
Display the global settings dialog.
void toSM_ECC_Plugin(double lat, double lon, double lat0, double lon0, double *x, double *y)
Converts geographic coordinates to Elliptical Simple Mercator projection.
bool UpdatePlugInTrack(PlugIn_Track *ptrack)
Updates an existing track.
double fromUsrDistance_Plugin(double usr_distance, int unit)
Converts from user's preferred distance unit to nautical miles.
wxString GetSelectedTrackGUID_Plugin()
Gets GUID of currently selected track.
wxFileConfig * GetOCPNConfigObject(void)
Gets OpenCPN's configuration object.
void DistanceBearingMercator_Plugin(double lat0, double lon0, double lat1, double lon1, double *brg, double *dist)
Calculates bearing and distance between two points using Mercator projection.
void SetGlobalColor(std::string table, std::string name, wxColor color)
Sets a color in the global color scheme.
void ZeroXTE()
Resets cross track error to zero.
void PlugInPlaySound(wxString &sound_file)
Plays a sound file asynchronously.
void GetCanvasLLPix(PlugIn_ViewPort *vp, wxPoint p, double *plat, double *plon)
Converts canvas physical pixel coordinates to lat/lon.
void EnableCanvasFocusBar(bool enable, int CanvasIndex)
Controls visibility of canvas focus indicator.
wxString GetSelectedRouteGUID_Plugin()
Gets GUID of currently selected route.
double g_display_size_mm
The width of the physical screen in millimeters.
Definition ocpn_app.cpp:394
void ForceChartDBUpdate()
Forces an update of the chart database.
bool GetSingleWaypointEx(wxString GUID, PlugIn_Waypoint_Ex *pwaypoint)
Gets extended waypoint data by GUID.
bool ShuttingDown(void)
Checks if OpenCPN is in shutdown process.
void ForceChartDBRebuild()
Forces complete rebuild of chart database.
Tools to send data to plugins.
A generic position and navigation data structure.
Definition ocpn_types.h:74
double kCog
Course over ground in degrees.
Definition ocpn_types.h:92
double kHdt
True heading in degrees.
Definition ocpn_types.h:117
double kLat
Latitude in decimal degrees.
Definition ocpn_types.h:81
double kSog
Speed over ground in knots.
Definition ocpn_types.h:98
double kLon
Longitude in decimal degrees.
Definition ocpn_types.h:89