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"
41#include "model/own_ship.h"
42#include "model/plugin_comm.h"
43#include "model/route.h"
44#include "model/track.h"
45
46#include "ais.h"
47#include "chartdb.h"
48#include "chcanv.h"
49#include "ConfigMgr.h"
50#include "FontMgr.h"
51#include "glChartCanvas.h"
52#include "gui_lib.h"
53#include "navutil.h"
54#include "ocpn_app.h"
55#include "OCPN_AUIManager.h"
56#include "ocpn_frame.h"
57#include "OCPNPlatform.h"
58#include "ocpn_plugin.h"
59#include "options.h"
60#include "piano.h"
61#include "pluginmanager.h"
62#include "routemanagerdialog.h"
63#include "routeman_gui.h"
64#include "s52plib.h"
65#include "SoundFactory.h"
66#include "svg_utils.h"
67#include "SystemCmdSound.h"
68#include "toolbar.h"
69#include "waypointman_gui.h"
70#include "shapefile_basemap.h"
71
72extern PlugInManager* s_ppim;
73extern MyConfig* pConfig;
74extern OCPN_AUIManager* g_pauimgr;
75
76#if wxUSE_XLOCALE || !wxCHECK_VERSION(3, 0, 0)
77extern wxLocale* plocale_def_lang;
78#endif
79
80extern OCPNPlatform* g_Platform;
81extern ChartDB* ChartData;
82extern MyFrame* gFrame;
83extern ocpnStyle::StyleManager* g_StyleManager;
84extern options* g_pOptions;
85extern Multiplexer* g_pMUX;
86extern bool g_bShowChartBar;
87extern Routeman* g_pRouteMan;
88extern Select* pSelect;
89extern RouteManagerDialog* pRouteManagerDialog;
90extern RouteList* pRouteList;
91extern std::vector<Track*> g_TrackList;
92extern PlugInManager* g_pi_manager;
93extern s52plib* ps52plib;
94extern wxString ChartListFileName;
95extern options* g_options;
96extern ColorScheme global_color_scheme;
97extern wxArrayString g_locale_catalog_array;
98extern int g_GUIScaleFactor;
99extern int g_ChartScaleFactor;
100extern wxString g_locale;
101extern ocpnFloatingToolbarDialog* g_MainToolbar;
102
103extern int g_chart_zoom_modifier_raster;
104extern int g_chart_zoom_modifier_vector;
105extern double g_display_size_mm;
106extern bool g_bopengl;
107extern AisDecoder* g_pAIS;
108extern ChartGroupArray* g_pGroupArray;
109extern ShapeBaseChartSet gShapeBasemap;
110
111// extern ChartGroupArray* g_pGroupArray;
112extern unsigned int g_canvasConfig;
113
114extern wxString g_CmdSoundString;
115
116unsigned int gs_plib_flags;
117extern ChartCanvas* g_focusCanvas;
118extern ChartCanvas* g_overlayCanvas;
119extern bool g_bquiting;
120extern bool g_disable_main_toolbar;
121extern bool g_btenhertz;
122
123WX_DEFINE_ARRAY_PTR(ChartCanvas*, arrayofCanvasPtr);
124extern arrayofCanvasPtr g_canvasArray;
125
126void NotifySetupOptionsPlugin(const PlugInData* pic);
127
128//---------------------------------------------------------------------------
129/* Implementation of OCPN core functions callable by plugins
130 * Sorted by API version number
131 * The definitions of this API are found in ocpn_plugin.h
132 * PlugIns may call these static functions as necessary for system services
133 */
134//---------------------------------------------------------------------------
135
136//---------------------------------------------------------------------------
137// API 1.6
138//---------------------------------------------------------------------------
139/* Main Toolbar support */
140int InsertPlugInTool(wxString label, wxBitmap* bitmap, wxBitmap* bmpRollover,
141 wxItemKind kind, wxString shortHelp, wxString longHelp,
142 wxObject* clientData, int position, int tool_sel,
143 opencpn_plugin* pplugin) {
144 if (s_ppim)
145 return s_ppim->AddToolbarTool(label, bitmap, bmpRollover, kind, shortHelp,
146 longHelp, clientData, position, tool_sel,
147 pplugin);
148 else
149 return -1;
150}
151
152void RemovePlugInTool(int tool_id) {
153 if (s_ppim) s_ppim->RemoveToolbarTool(tool_id);
154}
155
156void SetToolbarToolViz(int item, bool viz) {
157 if (s_ppim) s_ppim->SetToolbarToolViz(item, viz);
158}
159
160void SetToolbarItemState(int item, bool toggle) {
161 if (s_ppim) s_ppim->SetToolbarItemState(item, toggle);
162}
163
164void SetToolbarToolBitmaps(int item, wxBitmap* bitmap, wxBitmap* bmpRollover) {
165 if (s_ppim) s_ppim->SetToolbarItemBitmaps(item, bitmap, bmpRollover);
166}
167
168int InsertPlugInToolSVG(wxString label, wxString SVGfile,
169 wxString SVGfileRollover, wxString SVGfileToggled,
170 wxItemKind kind, wxString shortHelp, wxString longHelp,
171 wxObject* clientData, int position, int tool_sel,
172 opencpn_plugin* pplugin) {
173 if (s_ppim)
174 return s_ppim->AddToolbarTool(label, SVGfile, SVGfileRollover,
175 SVGfileToggled, kind, shortHelp, longHelp,
176 clientData, position, tool_sel, pplugin);
177 else
178 return -1;
179}
180
181void SetToolbarToolBitmapsSVG(int item, wxString SVGfile,
182 wxString SVGfileRollover,
183 wxString SVGfileToggled) {
184 if (s_ppim)
185 s_ppim->SetToolbarItemBitmaps(item, SVGfile, SVGfileRollover,
186 SVGfileToggled);
187}
188
189/* Canvas Context Menu support */
190int AddCanvasMenuItem(wxMenuItem* pitem, opencpn_plugin* pplugin,
191 const char* name) {
192 if (s_ppim)
193 return s_ppim->AddCanvasContextMenuItem(pitem, pplugin, name);
194 else
195 return -1;
196}
197
198void SetCanvasMenuItemViz(int item, bool viz, const char* name) {
199 if (s_ppim) s_ppim->SetCanvasContextMenuItemViz(item, viz, name);
200}
201
202void SetCanvasMenuItemGrey(int item, bool grey, const char* name) {
203 if (s_ppim) s_ppim->SetCanvasContextMenuItemGrey(item, grey, name);
204}
205
206void RemoveCanvasMenuItem(int item, const char* name) {
207 if (s_ppim) s_ppim->RemoveCanvasContextMenuItem(item, name);
208}
209
210int AddCanvasContextMenuItem(wxMenuItem* pitem, opencpn_plugin* pplugin) {
211 /* main context popup menu */
212 return AddCanvasMenuItem(pitem, pplugin, "");
213}
214
215void SetCanvasContextMenuItemViz(int item, bool viz) {
216 SetCanvasMenuItemViz(item, viz);
217}
218
219void SetCanvasContextMenuItemGrey(int item, bool grey) {
220 SetCanvasMenuItemGrey(item, grey);
221}
222
224
225/* Utility functions */
226wxFileConfig* GetOCPNConfigObject(void) {
227 if (s_ppim)
228 return reinterpret_cast<wxFileConfig*>(
229 pConfig); // return the global application config object
230 else
231 return NULL;
232}
233
235 wxWindow* pret = NULL;
236 if (s_ppim) {
237 MyFrame* pFrame = s_ppim->GetParentFrame();
238 pret = (wxWindow*)pFrame->GetPrimaryCanvas();
239 }
240 return pret;
241}
242
243void RequestRefresh(wxWindow* win) {
244 if (win) win->Refresh(true);
245}
246
247void GetCanvasPixLL(PlugIn_ViewPort* vp, wxPoint* pp, double lat, double lon) {
248 // Make enough of an application viewport to run its method....
249 ViewPort ocpn_vp;
250 ocpn_vp.clat = vp->clat;
251 ocpn_vp.clon = vp->clon;
252 ocpn_vp.m_projection_type = vp->m_projection_type;
253 ocpn_vp.view_scale_ppm = vp->view_scale_ppm;
254 ocpn_vp.skew = vp->skew;
255 ocpn_vp.rotation = vp->rotation;
256 ocpn_vp.pix_width = vp->pix_width;
257 ocpn_vp.pix_height = vp->pix_height;
258
259 wxPoint ret = ocpn_vp.GetPixFromLL(lat, lon);
260 pp->x = ret.x;
261 pp->y = ret.y;
262}
263
264void GetDoubleCanvasPixLL(PlugIn_ViewPort* vp, wxPoint2DDouble* pp, double lat,
265 double lon) {
266 // Make enough of an application viewport to run its method....
267 ViewPort ocpn_vp;
268 ocpn_vp.clat = vp->clat;
269 ocpn_vp.clon = vp->clon;
270 ocpn_vp.m_projection_type = vp->m_projection_type;
271 ocpn_vp.view_scale_ppm = vp->view_scale_ppm;
272 ocpn_vp.skew = vp->skew;
273 ocpn_vp.rotation = vp->rotation;
274 ocpn_vp.pix_width = vp->pix_width;
275 ocpn_vp.pix_height = vp->pix_height;
276
277 *pp = ocpn_vp.GetDoublePixFromLL(lat, lon);
278}
279
280void GetCanvasLLPix(PlugIn_ViewPort* vp, wxPoint p, double* plat,
281 double* plon) {
282 // Make enough of an application viewport to run its method....
283 ViewPort ocpn_vp;
284 ocpn_vp.clat = vp->clat;
285 ocpn_vp.clon = vp->clon;
286 ocpn_vp.m_projection_type = vp->m_projection_type;
287 ocpn_vp.view_scale_ppm = vp->view_scale_ppm;
288 ocpn_vp.skew = vp->skew;
289 ocpn_vp.rotation = vp->rotation;
290 ocpn_vp.pix_width = vp->pix_width;
291 ocpn_vp.pix_height = vp->pix_height;
292
293 return ocpn_vp.GetLLFromPix(p, plat, plon);
294}
295
296bool GetGlobalColor(wxString colorName, wxColour* pcolour) {
297 wxColour c = GetGlobalColor(colorName);
298 *pcolour = c;
299
300 return true;
301}
302
303wxFont* OCPNGetFont(wxString TextElement, int default_size) {
304 return FontMgr::Get().GetFont(TextElement, default_size);
305}
306
307wxFont* GetOCPNScaledFont_PlugIn(wxString TextElement, int default_size) {
308 return GetOCPNScaledFont(TextElement, default_size);
309}
310
311double GetOCPNGUIToolScaleFactor_PlugIn(int GUIScaleFactor) {
312 return g_Platform->GetToolbarScaleFactor(GUIScaleFactor);
313}
314
316 return g_Platform->GetToolbarScaleFactor(g_GUIScaleFactor);
317}
318
320 return g_Platform->GetChartScaleFactorExp(g_ChartScaleFactor);
321}
322
323wxFont GetOCPNGUIScaledFont_PlugIn(wxString item) {
324 return GetOCPNGUIScaledFont(item);
325}
326
327bool AddPersistentFontKey(wxString TextElement) {
328 return FontMgr::Get().AddAuxKey(TextElement);
329}
330
332 if (g_StyleManager)
333 return g_StyleManager->GetCurrentStyle()->name;
334 else
335 return _T("");
336}
337
338wxBitmap GetBitmapFromSVGFile(wxString filename, unsigned int width,
339 unsigned int height) {
340 wxBitmap bmp = LoadSVG(filename, width, height);
341
342 if (bmp.IsOk())
343 return bmp;
344 else {
345 // On error in requested width/height parameters,
346 // try to find and use dimensions embedded in the SVG file
347 unsigned int w, h;
348 SVGDocumentPixelSize(filename, w, h);
349 if (w == 0 || h == 0) {
350 // We did not succeed in deducing the size from SVG (svg element
351 // x misses width, height or both attributes), let's use some "safe"
352 // default
353 w = 32;
354 h = 32;
355 }
356 return LoadSVG(filename, w, h);
357 }
358}
359
360bool IsTouchInterface_PlugIn(void) { return g_btouch; }
361
362wxColour GetFontColour_PlugIn(wxString TextElement) {
363 return FontMgr::Get().GetFontColor(TextElement);
364}
365
366wxString* GetpSharedDataLocation(void) {
367 return g_Platform->GetSharedDataDirPtr();
368}
369
370ArrayOfPlugIn_AIS_Targets* GetAISTargetArray(void) {
371 if (!g_pAIS) return NULL;
372
373 ArrayOfPlugIn_AIS_Targets* pret = new ArrayOfPlugIn_AIS_Targets;
374
375 // Iterate over the AIS Target Hashmap
376 for (const auto& it : g_pAIS->GetTargetList()) {
377 auto td = it.second;
378 PlugIn_AIS_Target* ptarget = Create_PI_AIS_Target(td.get());
379 pret->Add(ptarget);
380 }
381
382// Test one alarm target
383#if 0
384 AisTargetData td;
385 td.n_alarm_state = AIS_ALARM_SET;
386 PlugIn_AIS_Target *ptarget = Create_PI_AIS_Target(&td);
387 pret->Add(ptarget);
388#endif
389 return pret;
390}
391
392wxAuiManager* GetFrameAuiManager(void) { return g_pauimgr; }
393
394void SendPluginMessage(wxString message_id, wxString message_body) {
395 SendMessageToAllPlugins(message_id, message_body);
396
397 // We will send an event to the main application frame (gFrame)
398 // for informational purposes.
399 // Of course, gFrame is encouraged to use any or all the
400 // data flying by if judged useful and dependable....
401
402 OCPN_MsgEvent Nevent(wxEVT_OCPN_MSG, 0);
403 Nevent.SetID(message_id);
404 Nevent.SetJSONText(message_body);
405 gFrame->GetEventHandler()->AddPendingEvent(Nevent);
406}
407
408void DimeWindow(wxWindow* win) { DimeControl(win); }
409
410void JumpToPosition(double lat, double lon, double scale) {
411 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), lat, lon, scale);
412}
413
414/* Locale (i18N) support */
415bool AddLocaleCatalog(wxString catalog) {
416#if wxUSE_XLOCALE || !wxCHECK_VERSION(3, 0, 0)
417
418 if (plocale_def_lang) {
419 // Add this catalog to the persistent catalog array
420 g_locale_catalog_array.Add(catalog);
421
422 return plocale_def_lang->AddCatalog(catalog);
423 } else
424#endif
425 return false;
426}
427
428wxString GetLocaleCanonicalName() { return g_locale; }
429
430/* NMEA interface support */
431void PushNMEABuffer(wxString buf) {
432 std::string full_sentence = buf.ToStdString();
433
434 if ((full_sentence[0] == '$') || (full_sentence[0] == '!')) { // Sanity check
435 std::string identifier;
436 // We notify based on full message, including the Talker ID
437 identifier = full_sentence.substr(1, 5);
438
439 // notify message listener and also "ALL" N0183 messages, to support plugin
440 // API using original talker id
441 auto address = std::make_shared<NavAddr0183>("virtual");
442 auto msg =
443 std::make_shared<const Nmea0183Msg>(identifier, full_sentence, address);
444 auto msg_all = std::make_shared<const Nmea0183Msg>(*msg, "ALL");
445
446 auto& msgbus = NavMsgBus::GetInstance();
447
448 msgbus.Notify(std::move(msg));
449 msgbus.Notify(std::move(msg_all));
450 }
451}
452
453/* Chart database access support */
454wxXmlDocument GetChartDatabaseEntryXML(int dbIndex, bool b_getGeom) {
455 wxXmlDocument doc = ChartData->GetXMLDescription(dbIndex, b_getGeom);
456
457 return doc;
458}
459
460bool UpdateChartDBInplace(wxArrayString dir_array, bool b_force_update,
461 bool b_ProgressDialog) {
462 // Make an array of CDI
463 ArrayOfCDI ChartDirArray;
464 for (unsigned int i = 0; i < dir_array.GetCount(); i++) {
465 wxString dirname = dir_array[i];
466 ChartDirInfo cdi;
467 cdi.fullpath = dirname;
468 cdi.magic_number = _T("");
469 ChartDirArray.Add(cdi);
470 }
471 bool b_ret = gFrame->UpdateChartDatabaseInplace(ChartDirArray, b_force_update,
472 b_ProgressDialog,
473 ChartData->GetDBFileName());
474 gFrame->ChartsRefresh();
475 return b_ret;
476}
477
479 return ChartData->GetChartDirArrayString();
480}
481
482int AddChartToDBInPlace(wxString& full_path, bool b_RefreshCanvas) {
483 // extract the path from the chart name
484 wxFileName fn(full_path);
485 wxString fdir = fn.GetPath();
486
487 bool bret = false;
488 if (ChartData) {
489 bret = ChartData->AddSingleChart(full_path);
490
491 if (bret) {
492 // Save to disk
493 pConfig->UpdateChartDirs(ChartData->GetChartDirArray());
494 ChartData->SaveBinary(ChartListFileName);
495
496 // Completely reload the chart database, for a fresh start
497 ArrayOfCDI XnewChartDirArray;
498 pConfig->LoadChartDirArray(XnewChartDirArray);
499 delete ChartData;
500 ChartData = new ChartDB();
501 ChartData->LoadBinary(ChartListFileName, XnewChartDirArray);
502
503 // Update group contents
504 if (g_pGroupArray) ChartData->ApplyGroupArray(g_pGroupArray);
505
506 if (g_options && g_options->IsShown())
507 g_options->UpdateDisplayedChartDirList(ChartData->GetChartDirArray());
508
509 if (b_RefreshCanvas || !gFrame->GetPrimaryCanvas()->GetQuiltMode()) {
510 gFrame->ChartsRefresh();
511 }
512 }
513 }
514 return bret;
515}
516
517int RemoveChartFromDBInPlace(wxString& full_path) {
518 bool bret = false;
519 if (ChartData) {
520 bret = ChartData->RemoveSingleChart(full_path);
521
522 // Save to disk
523 pConfig->UpdateChartDirs(ChartData->GetChartDirArray());
524 ChartData->SaveBinary(ChartListFileName);
525
526 // Completely reload the chart database, for a fresh start
527 ArrayOfCDI XnewChartDirArray;
528 pConfig->LoadChartDirArray(XnewChartDirArray);
529 delete ChartData;
530 ChartData = new ChartDB();
531 ChartData->LoadBinary(ChartListFileName, XnewChartDirArray);
532
533 // Update group contents
534 if (g_pGroupArray) ChartData->ApplyGroupArray(g_pGroupArray);
535
536 if (g_options && g_options->IsShown())
537 g_options->UpdateDisplayedChartDirList(ChartData->GetChartDirArray());
538
539 gFrame->ChartsRefresh();
540 }
541
542 return bret;
543}
544
545//---------------------------------------------------------------------------
546// API 1.9
547//---------------------------------------------------------------------------
548wxScrolledWindow* AddOptionsPage(OptionsParentPI parent, wxString title) {
549 if (!g_pOptions) return NULL;
550
551 size_t parentid;
552 switch (parent) {
554 parentid = g_pOptions->m_pageDisplay;
555 break;
557 parentid = g_pOptions->m_pageConnections;
558 break;
560 parentid = g_pOptions->m_pageCharts;
561 break;
563 parentid = g_pOptions->m_pageShips;
564 break;
566 parentid = g_pOptions->m_pageUI;
567 break;
569 parentid = g_pOptions->m_pagePlugins;
570 break;
571 default:
572 wxLogMessage(
573 _T("Error in PluginManager::AddOptionsPage: Unknown parent"));
574 return NULL;
575 break;
576 }
577
578 return g_pOptions->AddPage(parentid, title);
579}
580
581bool DeleteOptionsPage(wxScrolledWindow* page) {
582 if (!g_pOptions) return false;
583 return g_pOptions->DeletePluginPage(page);
584}
585
586bool DecodeSingleVDOMessage(const wxString& str, PlugIn_Position_Fix_Ex* pos,
587 wxString* accumulator) {
588 if (!pos) return false;
589
590 GenericPosDatEx gpd;
591 AisError nerr = AIS_GENERIC_ERROR;
592 if (g_pAIS) nerr = g_pAIS->DecodeSingleVDO(str, &gpd, accumulator);
593 if (nerr == AIS_NoError) {
594 pos->Lat = gpd.kLat;
595 pos->Lon = gpd.kLon;
596 pos->Cog = gpd.kCog;
597 pos->Sog = gpd.kSog;
598 pos->Hdt = gpd.kHdt;
599
600 // Fill in the dummy values
601 pos->FixTime = 0;
602 pos->Hdm = 1000;
603 pos->Var = 1000;
604 pos->nSats = 0;
605
606 return true;
607 }
608
609 return false;
610}
611
613 int val = 0;
614 if (g_bShowChartBar) {
615 ChartCanvas* cc = gFrame->GetPrimaryCanvas();
616 if (cc && cc->GetPiano()) {
617 val = cc->GetPiano()->GetHeight();
618 }
619 }
620 return val;
621}
622
623bool GetRoutepointGPX(RoutePoint* pRoutePoint, char* buffer,
624 unsigned int buffer_length) {
625 bool ret = false;
626
628 pgpx->AddGPXWaypoint(pRoutePoint);
629 wxString gpxfilename = wxFileName::CreateTempFileName(wxT("gpx"));
630 pgpx->SaveFile(gpxfilename);
631 delete pgpx;
632
633 wxFFile gpxfile(gpxfilename);
634 wxString s;
635 if (gpxfile.ReadAll(&s)) {
636 if (s.Length() < buffer_length) {
637 strncpy(buffer, (const char*)s.mb_str(wxConvUTF8), buffer_length - 1);
638 ret = true;
639 }
640 }
641
642 gpxfile.Close();
643 ::wxRemoveFile(gpxfilename);
644
645 return ret;
646}
647
648bool GetActiveRoutepointGPX(char* buffer, unsigned int buffer_length) {
649 if (g_pRouteMan->IsAnyRouteActive())
650 return GetRoutepointGPX(g_pRouteMan->GetpActivePoint(), buffer,
651 buffer_length);
652 else
653 return false;
654}
655
656void PositionBearingDistanceMercator_Plugin(double lat, double lon, double brg,
657 double dist, double* dlat,
658 double* dlon) {
659 PositionBearingDistanceMercator(lat, lon, brg, dist, dlat, dlon);
660}
661
662void DistanceBearingMercator_Plugin(double lat0, double lon0, double lat1,
663 double lon1, double* brg, double* dist) {
664 DistanceBearingMercator(lat0, lon0, lat1, lon1, brg, dist);
665}
666
667double DistGreatCircle_Plugin(double slat, double slon, double dlat,
668 double dlon) {
669 return DistGreatCircle(slat, slon, dlat, dlon);
670}
671
672void toTM_Plugin(float lat, float lon, float lat0, float lon0, double* x,
673 double* y) {
674 toTM(lat, lon, lat0, lon0, x, y);
675}
676
677void fromTM_Plugin(double x, double y, double lat0, double lon0, double* lat,
678 double* lon) {
679 fromTM(x, y, lat0, lon0, lat, lon);
680}
681
682void toSM_Plugin(double lat, double lon, double lat0, double lon0, double* x,
683 double* y) {
684 toSM(lat, lon, lat0, lon0, x, y);
685}
686
687void fromSM_Plugin(double x, double y, double lat0, double lon0, double* lat,
688 double* lon) {
689 fromSM(x, y, lat0, lon0, lat, lon);
690}
691
692void toSM_ECC_Plugin(double lat, double lon, double lat0, double lon0,
693 double* x, double* y) {
694 toSM_ECC(lat, lon, lat0, lon0, x, y);
695}
696
697void fromSM_ECC_Plugin(double x, double y, double lat0, double lon0,
698 double* lat, double* lon) {
699 fromSM_ECC(x, y, lat0, lon0, lat, lon);
700}
701
702double toUsrDistance_Plugin(double nm_distance, int unit) {
703 return toUsrDistance(nm_distance, unit);
704}
705
706double fromUsrDistance_Plugin(double usr_distance, int unit) {
707 return fromUsrDistance(usr_distance, unit);
708}
709
710double toUsrSpeed_Plugin(double kts_speed, int unit) {
711 return toUsrSpeed(kts_speed, unit);
712}
713
714double toUsrWindSpeed_Plugin(double kts_speed, int unit) {
715 return toUsrWindSpeed(kts_speed, unit);
716}
717
718double fromUsrSpeed_Plugin(double usr_speed, int unit) {
719 return fromUsrSpeed(usr_speed, unit);
720}
721
722double fromUsrWindSpeed_Plugin(double usr_wspeed, int unit) {
723 return fromUsrWindSpeed(usr_wspeed, unit);
724}
725
726double toUsrTemp_Plugin(double cel_temp, int unit) {
727 return toUsrTemp(cel_temp, unit);
728}
729
730double fromUsrTemp_Plugin(double usr_temp, int unit) {
731 return fromUsrTemp(usr_temp, unit);
732}
733
735 return getUsrDistanceUnit(unit);
736}
737
738wxString getUsrSpeedUnit_Plugin(int unit) { return getUsrSpeedUnit(unit); }
739
741 return getUsrWindSpeedUnit(unit);
742}
743
744wxString getUsrTempUnit_Plugin(int unit) { return getUsrTempUnit(unit); }
745
746/*
747 * Depth Conversion Functions
748 */
749double toUsrDepth_Plugin(double m_depth, int unit) {
750 return toUsrDepth(m_depth, unit);
751}
752
753double fromUsrDepth_Plugin(double usr_depth, int unit) {
754 return fromUsrDepth(usr_depth, unit);
755}
756
757wxString getUsrDepthUnit_Plugin(int unit) { return getUsrDepthUnit(unit); }
758
759double fromDMM_PlugIn(wxString sdms) { return fromDMM(sdms); }
760
761bool PlugIn_GSHHS_CrossesLand(double lat1, double lon1, double lat2,
762 double lon2) {
763 // TODO: Enable call to gShapeBasemap.CrossesLand after fixing performance
764 // issues. if (gShapeBasemap.IsUsable()) {
765 // return gShapeBasemap.CrossesLand(lat1, lon1, lat2, lon2);
766 // } else {
767 // Fall back to the GSHHS data.
768 static bool loaded = false;
769 if (!loaded) {
770 gshhsCrossesLandInit();
771 loaded = true;
772 }
773 return gshhsCrossesLand(lat1, lon1, lat2, lon2);
774 //}
775}
776
777void PlugInPlaySound(wxString& sound_file) {
778 PlugInPlaySoundEx(sound_file, -1);
779}
780
781//---------------------------------------------------------------------------
782// API 1.10
783//---------------------------------------------------------------------------
784
785// API Route and Waypoint Support
787
788PlugIn_Waypoint::PlugIn_Waypoint(double lat, double lon,
789 const wxString& icon_ident,
790 const wxString& wp_name,
791 const wxString& GUID) {
792 wxDateTime now = wxDateTime::Now();
793 m_CreateTime = now.ToUTC();
794 m_HyperlinkList = NULL;
795
796 m_lat = lat;
797 m_lon = lon;
798 m_IconName = icon_ident;
799 m_MarkName = wp_name;
800 m_GUID = GUID;
801}
802
803PlugIn_Waypoint::~PlugIn_Waypoint() {}
804
805// PlugInRoute implementation
806PlugIn_Route::PlugIn_Route(void) { pWaypointList = new Plugin_WaypointList; }
807
808PlugIn_Route::~PlugIn_Route(void) {
809 pWaypointList->DeleteContents(false); // do not delete Waypoints
810 pWaypointList->Clear();
811
812 delete pWaypointList;
813}
814
815// PlugInTrack implementation
816PlugIn_Track::PlugIn_Track(void) { pWaypointList = new Plugin_WaypointList; }
817
818PlugIn_Track::~PlugIn_Track(void) {
819 pWaypointList->DeleteContents(false); // do not delete Waypoints
820 pWaypointList->Clear();
821
822 delete pWaypointList;
823}
824
825wxString GetNewGUID(void) { return GpxDocument::GetUUID(); }
826
827bool AddCustomWaypointIcon(wxBitmap* pimage, wxString key,
828 wxString description) {
829 wxImage image = pimage->ConvertToImage();
830 WayPointmanGui(*pWayPointMan).ProcessIcon(image, key, description);
831 return true;
832}
833
834static void cloneHyperlinkList(RoutePoint* dst, const PlugIn_Waypoint* src) {
835 // Transcribe (clone) the html HyperLink List, if present
836 if (src->m_HyperlinkList == nullptr) return;
837
838 if (src->m_HyperlinkList->GetCount() > 0) {
839 wxPlugin_HyperlinkListNode* linknode = src->m_HyperlinkList->GetFirst();
840 while (linknode) {
841 Plugin_Hyperlink* link = linknode->GetData();
842
843 Hyperlink* h = new Hyperlink();
844 h->DescrText = link->DescrText;
845 h->Link = link->Link;
846 h->LType = link->Type;
847
848 dst->m_HyperlinkList->Append(h);
849
850 linknode = linknode->GetNext();
851 }
852 }
853}
854
855bool AddSingleWaypoint(PlugIn_Waypoint* pwaypoint, bool b_permanent) {
856 // Validate the waypoint parameters a little bit
857
858 // GUID
859 // Make sure that this GUID is indeed unique in the Routepoint list
860 bool b_unique = true;
861 wxRoutePointListNode* prpnode = pWayPointMan->GetWaypointList()->GetFirst();
862 while (prpnode) {
863 RoutePoint* prp = prpnode->GetData();
864
865 if (prp->m_GUID == pwaypoint->m_GUID) {
866 b_unique = false;
867 break;
868 }
869 prpnode = prpnode->GetNext(); // RoutePoint
870 }
871
872 if (!b_unique) return false;
873
874 RoutePoint* pWP =
875 new RoutePoint(pwaypoint->m_lat, pwaypoint->m_lon, pwaypoint->m_IconName,
876 pwaypoint->m_MarkName, pwaypoint->m_GUID);
877
878 pWP->m_bIsolatedMark = true; // This is an isolated mark
879
880 cloneHyperlinkList(pWP, pwaypoint);
881
882 pWP->m_MarkDescription = pwaypoint->m_MarkDescription;
883
884 if (pwaypoint->m_CreateTime.IsValid())
885 pWP->SetCreateTime(pwaypoint->m_CreateTime);
886 else {
887 wxDateTime dtnow(wxDateTime::Now());
888 pWP->SetCreateTime(dtnow);
889 }
890
891 pWP->m_btemp = (b_permanent == false);
892
893 pSelect->AddSelectableRoutePoint(pwaypoint->m_lat, pwaypoint->m_lon, pWP);
894 if (b_permanent) pConfig->AddNewWayPoint(pWP, -1);
895
896 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
897 pRouteManagerDialog->UpdateWptListCtrl();
898
899 return true;
900}
901
902bool DeleteSingleWaypoint(wxString& GUID) {
903 // Find the RoutePoint
904 bool b_found = false;
905 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(GUID);
906
907 if (prp) b_found = true;
908
909 if (b_found) {
910 pWayPointMan->DestroyWaypoint(prp);
911 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
912 pRouteManagerDialog->UpdateWptListCtrl();
913 }
914
915 return b_found;
916}
917
919 // Find the RoutePoint
920 bool b_found = false;
921 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(pwaypoint->m_GUID);
922
923 if (prp) b_found = true;
924
925 if (b_found) {
926 double lat_save = prp->m_lat;
927 double lon_save = prp->m_lon;
928
929 prp->m_lat = pwaypoint->m_lat;
930 prp->m_lon = pwaypoint->m_lon;
931 prp->SetIconName(pwaypoint->m_IconName);
932 prp->SetName(pwaypoint->m_MarkName);
933 prp->m_MarkDescription = pwaypoint->m_MarkDescription;
934 prp->SetVisible(pwaypoint->m_IsVisible);
935 if (pwaypoint->m_CreateTime.IsValid())
936 prp->SetCreateTime(pwaypoint->m_CreateTime);
937
938 // Transcribe (clone) the html HyperLink List, if present
939
940 if (pwaypoint->m_HyperlinkList) {
941 prp->m_HyperlinkList->Clear();
942 if (pwaypoint->m_HyperlinkList->GetCount() > 0) {
943 wxPlugin_HyperlinkListNode* linknode =
944 pwaypoint->m_HyperlinkList->GetFirst();
945 while (linknode) {
946 Plugin_Hyperlink* link = linknode->GetData();
947
948 Hyperlink* h = new Hyperlink();
949 h->DescrText = link->DescrText;
950 h->Link = link->Link;
951 h->LType = link->Type;
952
953 prp->m_HyperlinkList->Append(h);
954
955 linknode = linknode->GetNext();
956 }
957 }
958 }
959
960 if (prp) prp->ReLoadIcon();
961
962 auto canvas = gFrame->GetPrimaryCanvas();
963 SelectCtx ctx(canvas->m_bShowNavobjects, canvas->GetCanvasTrueScale(),
964 canvas->GetScaleValue());
965 SelectItem* pFind =
966 pSelect->FindSelection(ctx, lat_save, lon_save, SELTYPE_ROUTEPOINT);
967 if (pFind) {
968 pFind->m_slat = pwaypoint->m_lat; // update the SelectList entry
969 pFind->m_slon = pwaypoint->m_lon;
970 }
971
972 if (!prp->m_btemp) pConfig->UpdateWayPoint(prp);
973
974 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
975 pRouteManagerDialog->UpdateWptListCtrl();
976 }
977
978 return b_found;
979}
980
981// translate O route class to Plugin one
982static void PlugInFromRoutePoint(PlugIn_Waypoint* dst,
983 /* const*/ RoutePoint* src) {
984 dst->m_lat = src->m_lat;
985 dst->m_lon = src->m_lon;
986 dst->m_IconName = src->GetIconName();
987 dst->m_MarkName = src->GetName();
988 dst->m_MarkDescription = src->m_MarkDescription;
989 dst->m_IsVisible = src->IsVisible();
990 dst->m_CreateTime = src->GetCreateTime(); // not const
991 dst->m_GUID = src->m_GUID;
992
993 // Transcribe (clone) the html HyperLink List, if present
994 if (src->m_HyperlinkList == nullptr) return;
995
996 delete dst->m_HyperlinkList;
997 dst->m_HyperlinkList = nullptr;
998
999 if (src->m_HyperlinkList->GetCount() > 0) {
1000 dst->m_HyperlinkList = new Plugin_HyperlinkList;
1001
1002 wxHyperlinkListNode* linknode = src->m_HyperlinkList->GetFirst();
1003 while (linknode) {
1004 Hyperlink* link = linknode->GetData();
1005
1007 h->DescrText = link->DescrText;
1008 h->Link = link->Link;
1009 h->Type = link->LType;
1010
1011 dst->m_HyperlinkList->Append(h);
1012
1013 linknode = linknode->GetNext();
1014 }
1015 }
1016}
1017
1018bool GetSingleWaypoint(wxString GUID, PlugIn_Waypoint* pwaypoint) {
1019 // Find the RoutePoint
1020 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(GUID);
1021
1022 if (!prp) return false;
1023
1024 PlugInFromRoutePoint(pwaypoint, prp);
1025
1026 return true;
1027}
1028
1029wxArrayString GetWaypointGUIDArray(void) {
1030 wxArrayString result;
1031 const RoutePointList* list = pWayPointMan->GetWaypointList();
1032
1033 wxRoutePointListNode* prpnode = list->GetFirst();
1034 while (prpnode) {
1035 RoutePoint* prp = prpnode->GetData();
1036 result.Add(prp->m_GUID);
1037
1038 prpnode = prpnode->GetNext(); // RoutePoint
1039 }
1040
1041 return result;
1042}
1043
1044wxArrayString GetRouteGUIDArray(void) {
1045 wxArrayString result;
1046 RouteList* list = pRouteList;
1047
1048 wxRouteListNode* prpnode = list->GetFirst();
1049 while (prpnode) {
1050 Route* proute = prpnode->GetData();
1051 result.Add(proute->m_GUID);
1052
1053 prpnode = prpnode->GetNext(); // Route
1054 }
1055
1056 return result;
1057}
1058
1059wxArrayString GetTrackGUIDArray(void) {
1060 wxArrayString result;
1061 for (Track* ptrack : g_TrackList) {
1062 result.Add(ptrack->m_GUID);
1063 }
1064
1065 return result;
1066}
1067
1069 wxArrayString result;
1070 const RoutePointList* list = pWayPointMan->GetWaypointList();
1071
1072 wxRoutePointListNode* prpnode = list->GetFirst();
1073 while (prpnode) {
1074 RoutePoint* prp = prpnode->GetData();
1075 switch (req) {
1076 case OBJECTS_ALL:
1077 result.Add(prp->m_GUID);
1078 break;
1079 case OBJECTS_NO_LAYERS:
1080 if (!prp->m_bIsInLayer) result.Add(prp->m_GUID);
1081 break;
1083 if (prp->m_bIsInLayer) result.Add(prp->m_GUID);
1084 break;
1085 }
1086
1087 prpnode = prpnode->GetNext(); // RoutePoint
1088 }
1089
1090 return result;
1091}
1092
1094 wxArrayString result;
1095 RouteList* list = pRouteList;
1096
1097 wxRouteListNode* prpnode = list->GetFirst();
1098 while (prpnode) {
1099 Route* proute = prpnode->GetData();
1100 switch (req) {
1101 case OBJECTS_ALL:
1102 result.Add(proute->m_GUID);
1103 break;
1104 case OBJECTS_NO_LAYERS:
1105 if (!proute->m_bIsInLayer) result.Add(proute->m_GUID);
1106 break;
1108 if (proute->m_bIsInLayer) result.Add(proute->m_GUID);
1109 break;
1110 }
1111
1112 prpnode = prpnode->GetNext(); // Route
1113 }
1114
1115 return result;
1116}
1117
1119 wxArrayString result;
1120 for (Track* ptrack : g_TrackList) {
1121 switch (req) {
1122 case OBJECTS_ALL:
1123 result.Add(ptrack->m_GUID);
1124 break;
1125 case OBJECTS_NO_LAYERS:
1126 if (!ptrack->m_bIsInLayer) result.Add(ptrack->m_GUID);
1127 break;
1129 if (ptrack->m_bIsInLayer) result.Add(ptrack->m_GUID);
1130 break;
1131 }
1132 }
1133
1134 return result;
1135}
1136
1137wxArrayString GetIconNameArray(void) {
1138 wxArrayString result;
1139
1140 for (int i = 0; i < pWayPointMan->GetNumIcons(); i++) {
1141 wxString* ps = pWayPointMan->GetIconKey(i);
1142 result.Add(*ps);
1143 }
1144 return result;
1145}
1146
1147bool AddPlugInRoute(PlugIn_Route* proute, bool b_permanent) {
1148 Route* route = new Route();
1149
1150 PlugIn_Waypoint* pwp;
1151 RoutePoint* pWP_src;
1152 int ip = 0;
1153 wxDateTime plannedDeparture;
1154
1155 wxPlugin_WaypointListNode* pwpnode = proute->pWaypointList->GetFirst();
1156 while (pwpnode) {
1157 pwp = pwpnode->GetData();
1158
1159 RoutePoint* pWP = new RoutePoint(pwp->m_lat, pwp->m_lon, pwp->m_IconName,
1160 pwp->m_MarkName, pwp->m_GUID);
1161
1162 // Transcribe (clone) the html HyperLink List, if present
1163 cloneHyperlinkList(pWP, pwp);
1164 pWP->m_MarkDescription = pwp->m_MarkDescription;
1165 pWP->m_bShowName = false;
1166 pWP->SetCreateTime(pwp->m_CreateTime);
1167
1168 route->AddPoint(pWP);
1169
1170 pSelect->AddSelectableRoutePoint(pWP->m_lat, pWP->m_lon, pWP);
1171
1172 if (ip > 0)
1173 pSelect->AddSelectableRouteSegment(pWP_src->m_lat, pWP_src->m_lon,
1174 pWP->m_lat, pWP->m_lon, pWP_src, pWP,
1175 route);
1176 else
1177 plannedDeparture = pwp->m_CreateTime;
1178 ip++;
1179 pWP_src = pWP;
1180
1181 pwpnode = pwpnode->GetNext(); // PlugInWaypoint
1182 }
1183
1184 route->m_PlannedDeparture = plannedDeparture;
1185
1186 route->m_RouteNameString = proute->m_NameString;
1187 route->m_RouteStartString = proute->m_StartString;
1188 route->m_RouteEndString = proute->m_EndString;
1189 if (!proute->m_GUID.IsEmpty()) {
1190 route->m_GUID = proute->m_GUID;
1191 }
1192 route->m_btemp = (b_permanent == false);
1193
1194 pRouteList->Append(route);
1195
1196 if (b_permanent) pConfig->AddNewRoute(route);
1197
1198 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
1199 pRouteManagerDialog->UpdateRouteListCtrl();
1200
1201 return true;
1202}
1203
1204bool DeletePlugInRoute(wxString& GUID) {
1205 bool b_found = false;
1206
1207 // Find the Route
1208 Route* pRoute = g_pRouteMan->FindRouteByGUID(GUID);
1209 if (pRoute) {
1210 g_pRouteMan->DeleteRoute(pRoute, NavObjectChanges::getInstance());
1211 b_found = true;
1212 }
1213 return b_found;
1214}
1215
1217 bool b_found = false;
1218
1219 // Find the Route
1220 Route* pRoute = g_pRouteMan->FindRouteByGUID(proute->m_GUID);
1221 if (pRoute) b_found = true;
1222
1223 if (b_found) {
1224 bool b_permanent = (pRoute->m_btemp == false);
1225 g_pRouteMan->DeleteRoute(pRoute, NavObjectChanges::getInstance());
1226
1227 b_found = AddPlugInRoute(proute, b_permanent);
1228 }
1229
1230 return b_found;
1231}
1232
1233bool AddPlugInTrack(PlugIn_Track* ptrack, bool b_permanent) {
1234 Track* track = new Track();
1235
1236 PlugIn_Waypoint* pwp = 0;
1237 TrackPoint* pWP_src = 0;
1238 int ip = 0;
1239
1240 wxPlugin_WaypointListNode* pwpnode = ptrack->pWaypointList->GetFirst();
1241 while (pwpnode) {
1242 pwp = pwpnode->GetData();
1243
1244 TrackPoint* pWP = new TrackPoint(pwp->m_lat, pwp->m_lon);
1245 pWP->SetCreateTime(pwp->m_CreateTime);
1246
1247 track->AddPoint(pWP);
1248
1249 if (ip > 0)
1250 pSelect->AddSelectableTrackSegment(pWP_src->m_lat, pWP_src->m_lon,
1251 pWP->m_lat, pWP->m_lon, pWP_src, pWP,
1252 track);
1253 ip++;
1254 pWP_src = pWP;
1255
1256 pwpnode = pwpnode->GetNext(); // PlugInWaypoint
1257 }
1258
1259 track->SetName(ptrack->m_NameString);
1260 track->m_TrackStartString = ptrack->m_StartString;
1261 track->m_TrackEndString = ptrack->m_EndString;
1262 track->m_GUID = ptrack->m_GUID;
1263 track->m_btemp = (b_permanent == false);
1264
1265 g_TrackList.push_back(track);
1266
1267 if (b_permanent) pConfig->AddNewTrack(track);
1268
1269 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
1270 pRouteManagerDialog->UpdateTrkListCtrl();
1271
1272 return true;
1273}
1274
1275bool DeletePlugInTrack(wxString& GUID) {
1276 bool b_found = false;
1277
1278 // Find the Route
1279 Track* pTrack = g_pRouteMan->FindTrackByGUID(GUID);
1280 if (pTrack) {
1281 RoutemanGui(*g_pRouteMan).DeleteTrack(pTrack);
1282 b_found = true;
1283 }
1284
1285 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
1286 pRouteManagerDialog->UpdateTrkListCtrl();
1287
1288 return b_found;
1289}
1290
1292 bool b_found = false;
1293
1294 // Find the Track
1295 Track* pTrack = g_pRouteMan->FindTrackByGUID(ptrack->m_GUID);
1296 if (pTrack) b_found = true;
1297
1298 if (b_found) {
1299 bool b_permanent = (pTrack->m_btemp == false);
1300 RoutemanGui(*g_pRouteMan).DeleteTrack(pTrack);
1301
1302 b_found = AddPlugInTrack(ptrack, b_permanent);
1303 }
1304
1305 return b_found;
1306}
1307
1309#ifdef ocpnUSE_GL
1310 ViewPort ocpn_vp;
1311 ocpn_vp.m_projection_type = vp->m_projection_type;
1312
1313 return glChartCanvas::HasNormalizedViewPort(ocpn_vp);
1314#else
1315 return false;
1316#endif
1317}
1318
1319void PlugInMultMatrixViewport(PlugIn_ViewPort* vp, float lat, float lon) {
1320#ifdef ocpnUSE_GL
1321 ViewPort ocpn_vp;
1322 ocpn_vp.clat = vp->clat;
1323 ocpn_vp.clon = vp->clon;
1324 ocpn_vp.m_projection_type = vp->m_projection_type;
1325 ocpn_vp.view_scale_ppm = vp->view_scale_ppm;
1326 ocpn_vp.skew = vp->skew;
1327 ocpn_vp.rotation = vp->rotation;
1328 ocpn_vp.pix_width = vp->pix_width;
1329 ocpn_vp.pix_height = vp->pix_height;
1330
1331// TODO fix for multicanvas glChartCanvas::MultMatrixViewPort(ocpn_vp, lat,
1332// lon);
1333#endif
1334}
1335
1336void PlugInNormalizeViewport(PlugIn_ViewPort* vp, float lat, float lon) {
1337#ifdef ocpnUSE_GL
1338 ViewPort ocpn_vp;
1339 glChartCanvas::NormalizedViewPort(ocpn_vp, lat, lon);
1340
1341 vp->clat = ocpn_vp.clat;
1342 vp->clon = ocpn_vp.clon;
1343 vp->view_scale_ppm = ocpn_vp.view_scale_ppm;
1344 vp->rotation = ocpn_vp.rotation;
1345 vp->skew = ocpn_vp.skew;
1346#endif
1347}
1348
1349// Helper and interface classes
1350
1351//-------------------------------------------------------------------------------
1352// PlugIn_AIS_Target Implementation
1353//-------------------------------------------------------------------------------
1354
1355PlugIn_AIS_Target* Create_PI_AIS_Target(AisTargetData* ptarget) {
1357
1358 pret->MMSI = ptarget->MMSI;
1359 pret->Class = ptarget->Class;
1360 pret->NavStatus = ptarget->NavStatus;
1361 pret->SOG = ptarget->SOG;
1362 pret->COG = ptarget->COG;
1363 pret->HDG = ptarget->HDG;
1364 pret->Lon = ptarget->Lon;
1365 pret->Lat = ptarget->Lat;
1366 pret->ROTAIS = ptarget->ROTAIS;
1367 pret->ShipType = ptarget->ShipType;
1368 pret->IMO = ptarget->IMO;
1369
1370 pret->Range_NM = ptarget->Range_NM;
1371 pret->Brg = ptarget->Brg;
1372
1373 // Per target collision parameters
1374 pret->bCPA_Valid = ptarget->bCPA_Valid;
1375 pret->TCPA = ptarget->TCPA; // Minutes
1376 pret->CPA = ptarget->CPA; // Nautical Miles
1377
1378 pret->alarm_state = (plugin_ais_alarm_type)ptarget->n_alert_state;
1379
1380 memcpy(pret->CallSign, ptarget->CallSign, sizeof(ptarget->CallSign) - 1);
1381 memcpy(pret->ShipName, ptarget->ShipName, sizeof(ptarget->ShipName) - 1);
1382
1383 return pret;
1384}
1385
1386//---------------------------------------------------------------------------
1387// API 1.11
1388//---------------------------------------------------------------------------
1389
1390//---------------------------------------------------------------------------
1391// API 1.12
1392//---------------------------------------------------------------------------
1393
1394//---------------------------------------------------------------------------
1395// API 1.13
1396//---------------------------------------------------------------------------
1397double fromDMM_Plugin(wxString sdms) { return fromDMM(sdms); }
1398
1399void SetCanvasRotation(double rotation) {
1400 gFrame->GetPrimaryCanvas()->DoRotateCanvas(rotation);
1401}
1402
1403double GetCanvasTilt() { return gFrame->GetPrimaryCanvas()->GetVPTilt(); }
1404
1405void SetCanvasTilt(double tilt) {
1406 gFrame->GetPrimaryCanvas()->DoTiltCanvas(tilt);
1407}
1408
1409void SetCanvasProjection(int projection) {
1410 gFrame->GetPrimaryCanvas()->SetVPProjection(projection);
1411}
1412
1413OcpnSound* g_PluginSound = SoundFactory();
1414static void onPlugInPlaySoundExFinished(void* ptr) {}
1415
1416// Start playing a sound to a given device and return status to plugin
1417bool PlugInPlaySoundEx(wxString& sound_file, int deviceIndex) {
1418 bool ok = g_PluginSound->Load(sound_file, deviceIndex);
1419 if (!ok) {
1420 wxLogWarning("Cannot load sound file: %s", sound_file);
1421 return false;
1422 }
1423 auto cmd_sound = dynamic_cast<SystemCmdSound*>(g_PluginSound);
1424 if (cmd_sound) cmd_sound->SetCmd(g_CmdSoundString.mb_str(wxConvUTF8));
1425
1426 g_PluginSound->SetFinishedCallback(onPlugInPlaySoundExFinished, NULL);
1427 ok = g_PluginSound->Play();
1428 if (!ok) {
1429 wxLogWarning("Cannot play sound file: %s", sound_file);
1430 }
1431 return ok;
1432}
1433
1434bool CheckEdgePan_PlugIn(int x, int y, bool dragging, int margin, int delta) {
1435 return gFrame->GetPrimaryCanvas()->CheckEdgePan(x, y, dragging, margin,
1436 delta);
1437}
1438
1439wxBitmap GetIcon_PlugIn(const wxString& name) {
1440 ocpnStyle::Style* style = g_StyleManager->GetCurrentStyle();
1441 return style->GetIcon(name);
1442}
1443
1444void SetCursor_PlugIn(wxCursor* pCursor) {
1445 gFrame->GetPrimaryCanvas()->pPlugIn_Cursor = pCursor;
1446}
1447
1448void AddChartDirectory(wxString& path) {
1449 if (g_options) {
1450 g_options->AddChartDir(path);
1451 }
1452}
1453
1455 if (g_options) {
1456 g_options->pScanCheckBox->SetValue(true);
1457 g_options->pUpdateCheckBox->SetValue(true);
1458 }
1459}
1460
1462 if (g_options) {
1463 g_options->pUpdateCheckBox->SetValue(true);
1464 }
1465}
1466
1467wxDialog* GetActiveOptionsDialog() { return g_options; }
1468
1469int PlatformDirSelectorDialog(wxWindow* parent, wxString* file_spec,
1470 wxString Title, wxString initDir) {
1471 return g_Platform->DoDirSelectorDialog(parent, file_spec, Title, initDir);
1472}
1473
1474int PlatformFileSelectorDialog(wxWindow* parent, wxString* file_spec,
1475 wxString Title, wxString initDir,
1476 wxString suggestedName, wxString wildcard) {
1477 return g_Platform->DoFileSelectorDialog(parent, file_spec, Title, initDir,
1478 suggestedName, wildcard);
1479}
1480
1481//---------------------------------------------------------------------------
1482// API 1.14
1483//---------------------------------------------------------------------------
1484
1485ViewPort CreateCompatibleViewportEx(const PlugIn_ViewPort& pivp) {
1486 // Create a system ViewPort
1487 ViewPort vp;
1488
1489 vp.clat = pivp.clat; // center point
1490 vp.clon = pivp.clon;
1492 vp.skew = pivp.skew;
1493 vp.rotation = pivp.rotation;
1494 vp.chart_scale = pivp.chart_scale;
1495 vp.pix_width = pivp.pix_width;
1496 vp.pix_height = pivp.pix_height;
1497 vp.rv_rect = pivp.rv_rect;
1498 vp.b_quilt = pivp.b_quilt;
1499 vp.m_projection_type = pivp.m_projection_type;
1500
1501 if (gFrame->GetPrimaryCanvas())
1502 vp.ref_scale = gFrame->GetPrimaryCanvas()->GetVP().ref_scale;
1503 else
1504 vp.ref_scale = vp.chart_scale;
1505
1506 vp.SetBoxes();
1507 vp.Validate(); // This VP is valid
1508
1509 return vp;
1510}
1511
1512void PlugInAISDrawGL(wxGLCanvas* glcanvas, const PlugIn_ViewPort& vp) {
1513 ViewPort ocpn_vp = CreateCompatibleViewportEx(vp);
1514
1515 ocpnDC dc(*glcanvas);
1516 dc.SetVP(ocpn_vp);
1517
1518 AISDraw(dc, ocpn_vp, NULL);
1519}
1520
1521bool PlugInSetFontColor(const wxString TextElement, const wxColour color) {
1522 return FontMgr::Get().SetFontColor(TextElement, color);
1523}
1524
1525//---------------------------------------------------------------------------
1526// API 1.15
1527//---------------------------------------------------------------------------
1528
1529double PlugInGetDisplaySizeMM() { return g_Platform->GetDisplaySizeMM(); }
1530
1531wxFont* FindOrCreateFont_PlugIn(int point_size, wxFontFamily family,
1532 wxFontStyle style, wxFontWeight weight,
1533 bool underline, const wxString& facename,
1534 wxFontEncoding encoding) {
1535 return FontMgr::Get().FindOrCreateFont(point_size, family, style, weight,
1536 underline, facename, encoding);
1537}
1538
1539int PluginGetMinAvailableGshhgQuality() {
1540 return gFrame->GetPrimaryCanvas()->GetMinAvailableGshhgQuality();
1541}
1542int PluginGetMaxAvailableGshhgQuality() {
1543 return gFrame->GetPrimaryCanvas()->GetMaxAvailableGshhgQuality();
1544}
1545
1546// disable builtin console canvas, and autopilot nmea sentences
1548 g_bPluginHandleAutopilotRoute = enable;
1549}
1550
1551bool LaunchDefaultBrowser_Plugin(wxString url) {
1552 if (g_Platform) g_Platform->platformLaunchDefaultBrowser(url);
1553
1554 return true;
1555}
1556
1557//---------------------------------------------------------------------------
1558// API 1.16
1559//---------------------------------------------------------------------------
1561 ChartCanvas* cc = gFrame->GetFocusCanvas();
1562 if (cc && cc->GetSelectedRoutePoint()) {
1563 return cc->GetSelectedRoutePoint()->m_GUID;
1564 }
1565 return wxEmptyString;
1566}
1567
1569 ChartCanvas* cc = gFrame->GetFocusCanvas();
1570 if (cc && cc->GetSelectedRoute()) {
1571 return cc->GetSelectedRoute()->m_GUID;
1572 }
1573 return wxEmptyString;
1574}
1575
1577 ChartCanvas* cc = gFrame->GetFocusCanvas();
1578 if (cc && cc->GetSelectedTrack()) {
1579 return cc->GetSelectedTrack()->m_GUID;
1580 }
1581 return wxEmptyString;
1582}
1583
1584std::unique_ptr<PlugIn_Waypoint> GetWaypoint_Plugin(const wxString& GUID) {
1585 std::unique_ptr<PlugIn_Waypoint> w(new PlugIn_Waypoint);
1586 GetSingleWaypoint(GUID, w.get());
1587 return w;
1588}
1589
1590std::unique_ptr<PlugIn_Route> GetRoute_Plugin(const wxString& GUID) {
1591 std::unique_ptr<PlugIn_Route> r;
1592 Route* route = g_pRouteMan->FindRouteByGUID(GUID);
1593 if (route == nullptr) return r;
1594
1595 r = std::unique_ptr<PlugIn_Route>(new PlugIn_Route);
1596 PlugIn_Route* dst_route = r.get();
1597
1598 // PlugIn_Waypoint *pwp;
1599 RoutePoint* src_wp;
1600 wxRoutePointListNode* node = route->pRoutePointList->GetFirst();
1601
1602 while (node) {
1603 src_wp = node->GetData();
1604
1605 PlugIn_Waypoint* dst_wp = new PlugIn_Waypoint();
1606 PlugInFromRoutePoint(dst_wp, src_wp);
1607
1608 dst_route->pWaypointList->Append(dst_wp);
1609
1610 node = node->GetNext();
1611 }
1612 dst_route->m_NameString = route->m_RouteNameString;
1613 dst_route->m_StartString = route->m_RouteStartString;
1614 dst_route->m_EndString = route->m_RouteEndString;
1615 dst_route->m_GUID = route->m_GUID;
1616
1617 return r;
1618}
1619
1620std::unique_ptr<PlugIn_Track> GetTrack_Plugin(const wxString& GUID) {
1621 std::unique_ptr<PlugIn_Track> t;
1622 // Find the Track
1623 Track* pTrack = g_pRouteMan->FindTrackByGUID(GUID);
1624 if (!pTrack) return t;
1625
1626 std::unique_ptr<PlugIn_Track> tk =
1627 std::unique_ptr<PlugIn_Track>(new PlugIn_Track);
1628 PlugIn_Track* dst_track = tk.get();
1629 dst_track->m_NameString = pTrack->GetName();
1630 dst_track->m_StartString = pTrack->m_TrackStartString;
1631 dst_track->m_EndString = pTrack->m_TrackEndString;
1632 dst_track->m_GUID = pTrack->m_GUID;
1633
1634 for (int i = 0; i < pTrack->GetnPoints(); i++) {
1635 TrackPoint* ptp = pTrack->GetPoint(i);
1636
1637 PlugIn_Waypoint* dst_wp = new PlugIn_Waypoint();
1638
1639 dst_wp->m_lat = ptp->m_lat;
1640 dst_wp->m_lon = ptp->m_lon;
1641 dst_wp->m_CreateTime = ptp->GetCreateTime(); // not const
1642
1643 dst_track->pWaypointList->Append(dst_wp);
1644 }
1645
1646 return tk;
1647}
1648
1649wxWindow* PluginGetFocusCanvas() { return g_focusCanvas; }
1650
1652 // if(g_overlayCanvas)
1653 return g_overlayCanvas;
1654 // else
1655}
1656
1657void CanvasJumpToPosition(wxWindow* canvas, double lat, double lon,
1658 double scale) {
1659 auto oCanvas = dynamic_cast<ChartCanvas*>(canvas);
1660 if (oCanvas) gFrame->JumpToPosition(oCanvas, lat, lon, scale);
1661}
1662
1663bool ShuttingDown(void) { return g_bquiting; }
1664
1665wxWindow* GetCanvasUnderMouse(void) { return gFrame->GetCanvasUnderMouse(); }
1666
1668 ChartCanvas* l_canvas = gFrame->GetCanvasUnderMouse();
1669 if (l_canvas) {
1670 for (unsigned int i = 0; i < g_canvasArray.GetCount(); ++i) {
1671 if (l_canvas == g_canvasArray[i]) return i;
1672 }
1673 }
1674 return 0;
1675}
1676
1677// std::vector<wxWindow *> GetCanvasArray()
1678// {
1679// std::vector<wxWindow *> rv;
1680// for(unsigned int i=0 ; i < g_canvasArray.GetCount() ; i++){
1681// ChartCanvas *cc = g_canvasArray.Item(i);
1682// rv.push_back(cc);
1683// }
1684//
1685// return rv;
1686// }
1687
1688wxWindow* GetCanvasByIndex(int canvasIndex) {
1689 if (g_canvasConfig == 0)
1690 return gFrame->GetPrimaryCanvas();
1691 else {
1692 if ((canvasIndex >= 0) && g_canvasArray[canvasIndex]) {
1693 return g_canvasArray[canvasIndex];
1694 }
1695 }
1696 return NULL;
1697}
1698
1699bool CheckMUIEdgePan_PlugIn(int x, int y, bool dragging, int margin, int delta,
1700 int canvasIndex) {
1701 if (g_canvasConfig == 0)
1702 return gFrame->GetPrimaryCanvas()->CheckEdgePan(x, y, dragging, margin,
1703 delta);
1704 else {
1705 if ((canvasIndex >= 0) && g_canvasArray[canvasIndex]) {
1706 return g_canvasArray[canvasIndex]->CheckEdgePan(x, y, dragging, margin,
1707 delta);
1708 }
1709 }
1710
1711 return false;
1712}
1713
1714void SetMUICursor_PlugIn(wxCursor* pCursor, int canvasIndex) {
1715 if (g_canvasConfig == 0)
1716 gFrame->GetPrimaryCanvas()->pPlugIn_Cursor = pCursor;
1717 else {
1718 if ((canvasIndex >= 0) && g_canvasArray[canvasIndex]) {
1719 g_canvasArray[canvasIndex]->pPlugIn_Cursor = pCursor;
1720 }
1721 }
1722}
1723
1725 if (g_canvasConfig == 1) return 2;
1726 // else
1727 return 1;
1728}
1729
1730int GetLatLonFormat() { return g_iSDMMFormat; }
1731
1733 if (g_MainToolbar)
1734 return g_MainToolbar->GetToolbarRect();
1735 else
1736 return wxRect(0, 0, 1, 1);
1737}
1738
1739//---------------------------------------------------------------------------
1740// API 1.17
1741//---------------------------------------------------------------------------
1742
1743void ZeroXTE() {
1744 if (g_pRouteMan) {
1745 g_pRouteMan->ZeroCurrentXTEToActivePoint();
1746 }
1747}
1748
1749static PlugIn_ViewPort CreatePlugInViewportEx(const ViewPort& vp) {
1750 // Create a PlugIn Viewport
1751 ViewPort tvp = vp;
1752 PlugIn_ViewPort pivp;
1753
1754 pivp.clat = tvp.clat; // center point
1755 pivp.clon = tvp.clon;
1756 pivp.view_scale_ppm = tvp.view_scale_ppm;
1757 pivp.skew = tvp.skew;
1758 pivp.rotation = tvp.rotation;
1759 pivp.chart_scale = tvp.chart_scale;
1760 pivp.pix_width = tvp.pix_width;
1761 pivp.pix_height = tvp.pix_height;
1762 pivp.rv_rect = tvp.rv_rect;
1763 pivp.b_quilt = tvp.b_quilt;
1764 pivp.m_projection_type = tvp.m_projection_type;
1765
1766 pivp.lat_min = tvp.GetBBox().GetMinLat();
1767 pivp.lat_max = tvp.GetBBox().GetMaxLat();
1768 pivp.lon_min = tvp.GetBBox().GetMinLon();
1769 pivp.lon_max = tvp.GetBBox().GetMaxLon();
1770
1771 pivp.bValid = tvp.IsValid(); // This VP is valid
1772
1773 return pivp;
1774}
1775
1776ListOfPI_S57Obj* PlugInManager::GetLightsObjRuleListVisibleAtLatLon(
1777 ChartPlugInWrapper* target, float zlat, float zlon, const ViewPort& vp) {
1778 ListOfPI_S57Obj* list = NULL;
1779 if (target) {
1780 PlugInChartBaseGLPlus2* picbgl =
1781 dynamic_cast<PlugInChartBaseGLPlus2*>(target->GetPlugInChart());
1782 if (picbgl) {
1783 PlugIn_ViewPort pi_vp = CreatePlugInViewportEx(vp);
1784 list = picbgl->GetLightsObjRuleListVisibleAtLatLon(zlat, zlon, &pi_vp);
1785
1786 return list;
1787 }
1789 dynamic_cast<PlugInChartBaseExtendedPlus2*>(target->GetPlugInChart());
1790 if (picbx) {
1791 PlugIn_ViewPort pi_vp = CreatePlugInViewportEx(vp);
1792 list = picbx->GetLightsObjRuleListVisibleAtLatLon(zlat, zlon, &pi_vp);
1793
1794 return list;
1795 } else
1796 return list;
1797 } else
1798 return list;
1799}
1800
1801// PlugInWaypointEx implementation
1802
1803#include <wx/listimpl.cpp>
1804WX_DEFINE_LIST(Plugin_WaypointExList)
1805
1806// The class implementations
1807PlugIn_Waypoint_Ex::PlugIn_Waypoint_Ex() { InitDefaults(); }
1808
1809PlugIn_Waypoint_Ex::PlugIn_Waypoint_Ex(
1810 double lat, double lon, const wxString& icon_ident, const wxString& wp_name,
1811 const wxString& GUID, const double ScaMin, const bool bNameVisible,
1812 const int nRangeRings, const double RangeDistance,
1813 const wxColor RangeColor) {
1814 InitDefaults();
1815
1816 wxDateTime now = wxDateTime::Now();
1817 m_CreateTime = now.ToUTC();
1818 m_HyperlinkList = NULL;
1819
1820 m_lat = lat;
1821 m_lon = lon;
1822 IconName = icon_ident;
1823 m_MarkName = wp_name;
1824 m_GUID = GUID;
1825 scamin = ScaMin;
1826 IsNameVisible = bNameVisible;
1827 nrange_rings = nRangeRings;
1828 RangeRingSpace = RangeDistance;
1829 RangeRingColor = RangeColor;
1830}
1831
1833 m_HyperlinkList = NULL;
1834 scamin = 1e9;
1835 b_useScamin = false;
1836 nrange_rings = 0;
1837 RangeRingSpace = 1;
1838 IsNameVisible = false;
1839 IsVisible = true;
1840 RangeRingColor = *wxBLACK;
1841 m_CreateTime = wxDateTime::Now();
1842 IsActive = false;
1843 m_lat = 0;
1844 m_lon = 0;
1845}
1846
1848 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(m_GUID);
1849 if (!prp) return false;
1850
1851 if (prp->m_bIsInRoute && !prp->IsShared()) return false;
1852
1853 return true;
1854}
1855
1857 // Search all routes to count the membership of this point
1858 RoutePoint* pWP = pWayPointMan->FindRoutePointByGUID(m_GUID);
1859 if (!pWP) return 0;
1860
1861 int nCount = 0;
1862 wxRouteListNode* node = pRouteList->GetFirst();
1863 while (node) {
1864 Route* proute = node->GetData();
1865 wxRoutePointListNode* pnode = (proute->pRoutePointList)->GetFirst();
1866 while (pnode) {
1867 RoutePoint* prp = pnode->GetData();
1868 if (prp == pWP) nCount++;
1869 pnode = pnode->GetNext();
1870 }
1871
1872 node = node->GetNext();
1873 }
1874
1875 return nCount;
1876}
1877
1878PlugIn_Waypoint_Ex::~PlugIn_Waypoint_Ex() {}
1879
1880// PlugInRouteExtended implementation
1881PlugIn_Route_Ex::PlugIn_Route_Ex(void) {
1882 pWaypointList = new Plugin_WaypointExList;
1883}
1884
1885PlugIn_Route_Ex::~PlugIn_Route_Ex(void) {
1886 pWaypointList->DeleteContents(false); // do not delete Waypoints
1887 pWaypointList->Clear();
1888
1889 delete pWaypointList;
1890}
1891
1892// The utility methods implementations
1893
1894// translate O route class to PlugIn_Waypoint_Ex
1895static void PlugInExFromRoutePoint(PlugIn_Waypoint_Ex* dst,
1896 /* const*/ RoutePoint* src) {
1897 dst->m_lat = src->m_lat;
1898 dst->m_lon = src->m_lon;
1899 dst->IconName = src->GetIconName();
1900 dst->m_MarkName = src->GetName();
1901 dst->m_MarkDescription = src->GetDescription();
1902 dst->IconDescription = pWayPointMan->GetIconDescription(src->GetIconName());
1903 dst->IsVisible = src->IsVisible();
1904 dst->m_CreateTime = src->GetCreateTime(); // not const
1905 dst->m_GUID = src->m_GUID;
1906
1907 // Transcribe (clone) the html HyperLink List, if present
1908 if (src->m_HyperlinkList == nullptr) return;
1909
1910 delete dst->m_HyperlinkList;
1911 dst->m_HyperlinkList = nullptr;
1912
1913 if (src->m_HyperlinkList->GetCount() > 0) {
1914 dst->m_HyperlinkList = new Plugin_HyperlinkList;
1915
1916 wxHyperlinkListNode* linknode = src->m_HyperlinkList->GetFirst();
1917 while (linknode) {
1918 Hyperlink* link = linknode->GetData();
1919
1921 h->DescrText = link->DescrText;
1922 h->Link = link->Link;
1923 h->Type = link->LType;
1924
1925 dst->m_HyperlinkList->Append(h);
1926
1927 linknode = linknode->GetNext();
1928 }
1929 }
1930
1931 // Get the range ring info
1932 dst->nrange_rings = src->m_iWaypointRangeRingsNumber;
1933 dst->RangeRingSpace = src->m_fWaypointRangeRingsStep;
1934 dst->RangeRingColor = src->m_wxcWaypointRangeRingsColour;
1935
1936 // Get other extended info
1937 dst->IsNameVisible = src->m_bShowName;
1938 dst->scamin = src->GetScaMin();
1939 dst->b_useScamin = src->GetUseSca();
1940 dst->IsActive = src->m_bIsActive;
1941}
1942
1943static void cloneHyperlinkListEx(RoutePoint* dst,
1944 const PlugIn_Waypoint_Ex* src) {
1945 // Transcribe (clone) the html HyperLink List, if present
1946 if (src->m_HyperlinkList == nullptr) return;
1947
1948 if (src->m_HyperlinkList->GetCount() > 0) {
1949 wxPlugin_HyperlinkListNode* linknode = src->m_HyperlinkList->GetFirst();
1950 while (linknode) {
1951 Plugin_Hyperlink* link = linknode->GetData();
1952
1953 Hyperlink* h = new Hyperlink();
1954 h->DescrText = link->DescrText;
1955 h->Link = link->Link;
1956 h->LType = link->Type;
1957
1958 dst->m_HyperlinkList->Append(h);
1959
1960 linknode = linknode->GetNext();
1961 }
1962 }
1963}
1964
1965RoutePoint* CreateNewPoint(const PlugIn_Waypoint_Ex* src, bool b_permanent) {
1966 RoutePoint* pWP = new RoutePoint(src->m_lat, src->m_lon, src->IconName,
1967 src->m_MarkName, src->m_GUID);
1968
1969 pWP->m_bIsolatedMark = true; // This is an isolated mark
1970
1971 cloneHyperlinkListEx(pWP, src);
1972
1973 pWP->m_MarkDescription = src->m_MarkDescription;
1974
1975 if (src->m_CreateTime.IsValid())
1976 pWP->SetCreateTime(src->m_CreateTime);
1977 else {
1978 wxDateTime dtnow(wxDateTime::Now());
1979 pWP->SetCreateTime(dtnow);
1980 }
1981
1982 pWP->m_btemp = (b_permanent == false);
1983
1984 // Extended fields
1985 pWP->SetIconName(src->IconName);
1986 pWP->SetWaypointRangeRingsNumber(src->nrange_rings);
1987 pWP->SetWaypointRangeRingsStep(src->RangeRingSpace);
1988 pWP->SetWaypointRangeRingsColour(src->RangeRingColor);
1989 pWP->SetScaMin(src->scamin);
1990 pWP->SetUseSca(src->b_useScamin);
1991 pWP->SetNameShown(src->IsNameVisible);
1992 pWP->SetVisible(src->IsVisible);
1993
1994 return pWP;
1995}
1996bool GetSingleWaypointEx(wxString GUID, PlugIn_Waypoint_Ex* pwaypoint) {
1997 // Find the RoutePoint
1998 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(GUID);
1999
2000 if (!prp) return false;
2001
2002 PlugInExFromRoutePoint(pwaypoint, prp);
2003
2004 return true;
2005}
2006
2007bool AddSingleWaypointEx(PlugIn_Waypoint_Ex* pwaypointex, bool b_permanent) {
2008 // Validate the waypoint parameters a little bit
2009
2010 // GUID
2011 // Make sure that this GUID is indeed unique in the Routepoint list
2012 bool b_unique = true;
2013 wxRoutePointListNode* prpnode = pWayPointMan->GetWaypointList()->GetFirst();
2014 while (prpnode) {
2015 RoutePoint* prp = prpnode->GetData();
2016
2017 if (prp->m_GUID == pwaypointex->m_GUID) {
2018 b_unique = false;
2019 break;
2020 }
2021 prpnode = prpnode->GetNext(); // RoutePoint
2022 }
2023
2024 if (!b_unique) return false;
2025
2026 RoutePoint* pWP = CreateNewPoint(pwaypointex, b_permanent);
2027
2028 pWP->SetShowWaypointRangeRings(pwaypointex->nrange_rings > 0);
2029
2030 pSelect->AddSelectableRoutePoint(pWP->m_lat, pWP->m_lon, pWP);
2031 if (b_permanent) pConfig->AddNewWayPoint(pWP, -1);
2032
2033 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
2034 pRouteManagerDialog->UpdateWptListCtrl();
2035
2036 return true;
2037}
2038
2040 // Find the RoutePoint
2041 bool b_found = false;
2042 RoutePoint* prp = pWayPointMan->FindRoutePointByGUID(pwaypoint->m_GUID);
2043
2044 if (prp) b_found = true;
2045
2046 if (b_found) {
2047 double lat_save = prp->m_lat;
2048 double lon_save = prp->m_lon;
2049
2050 prp->m_lat = pwaypoint->m_lat;
2051 prp->m_lon = pwaypoint->m_lon;
2052 prp->SetIconName(pwaypoint->IconName);
2053 prp->SetName(pwaypoint->m_MarkName);
2054 prp->m_MarkDescription = pwaypoint->m_MarkDescription;
2055 prp->SetVisible(pwaypoint->IsVisible);
2056 if (pwaypoint->m_CreateTime.IsValid())
2057 prp->SetCreateTime(pwaypoint->m_CreateTime);
2058
2059 // Transcribe (clone) the html HyperLink List, if present
2060
2061 if (pwaypoint->m_HyperlinkList) {
2062 prp->m_HyperlinkList->Clear();
2063 if (pwaypoint->m_HyperlinkList->GetCount() > 0) {
2064 wxPlugin_HyperlinkListNode* linknode =
2065 pwaypoint->m_HyperlinkList->GetFirst();
2066 while (linknode) {
2067 Plugin_Hyperlink* link = linknode->GetData();
2068
2069 Hyperlink* h = new Hyperlink();
2070 h->DescrText = link->DescrText;
2071 h->Link = link->Link;
2072 h->LType = link->Type;
2073
2074 prp->m_HyperlinkList->Append(h);
2075
2076 linknode = linknode->GetNext();
2077 }
2078 }
2079 }
2080
2081 // Extended fields
2082 prp->SetWaypointRangeRingsNumber(pwaypoint->nrange_rings);
2083 prp->SetWaypointRangeRingsStep(pwaypoint->RangeRingSpace);
2084 prp->SetWaypointRangeRingsColour(pwaypoint->RangeRingColor);
2085 prp->SetScaMin(pwaypoint->scamin);
2086 prp->SetUseSca(pwaypoint->b_useScamin);
2087 prp->SetNameShown(pwaypoint->IsNameVisible);
2088
2089 prp->SetShowWaypointRangeRings(pwaypoint->nrange_rings > 0);
2090
2091 if (prp) prp->ReLoadIcon();
2092
2093 auto canvas = gFrame->GetPrimaryCanvas();
2094 SelectCtx ctx(canvas->m_bShowNavobjects, canvas->GetCanvasTrueScale(),
2095 canvas->GetScaleValue());
2096 SelectItem* pFind =
2097 pSelect->FindSelection(ctx, lat_save, lon_save, SELTYPE_ROUTEPOINT);
2098 if (pFind) {
2099 pFind->m_slat = pwaypoint->m_lat; // update the SelectList entry
2100 pFind->m_slon = pwaypoint->m_lon;
2101 }
2102
2103 if (!prp->m_btemp) pConfig->UpdateWayPoint(prp);
2104
2105 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
2106 pRouteManagerDialog->UpdateWptListCtrl();
2107 }
2108
2109 return b_found;
2110}
2111
2112bool AddPlugInRouteEx(PlugIn_Route_Ex* proute, bool b_permanent) {
2113 Route* route = new Route();
2114
2115 PlugIn_Waypoint_Ex* pwaypointex;
2116 RoutePoint *pWP, *pWP_src;
2117 int ip = 0;
2118 wxDateTime plannedDeparture;
2119
2120 wxPlugin_WaypointExListNode* pwpnode = proute->pWaypointList->GetFirst();
2121 while (pwpnode) {
2122 pwaypointex = pwpnode->GetData();
2123
2124 pWP = pWayPointMan->FindRoutePointByGUID(pwaypointex->m_GUID);
2125 if (!pWP) {
2126 pWP = CreateNewPoint(pwaypointex, b_permanent);
2127 pWP->m_bIsolatedMark = false;
2128 }
2129
2130 route->AddPoint(pWP);
2131
2132 pSelect->AddSelectableRoutePoint(pWP->m_lat, pWP->m_lon, pWP);
2133
2134 if (ip > 0)
2135 pSelect->AddSelectableRouteSegment(pWP_src->m_lat, pWP_src->m_lon,
2136 pWP->m_lat, pWP->m_lon, pWP_src, pWP,
2137 route);
2138
2139 plannedDeparture = pwaypointex->m_CreateTime;
2140 ip++;
2141 pWP_src = pWP;
2142
2143 pwpnode = pwpnode->GetNext(); // PlugInWaypoint
2144 }
2145
2146 route->m_PlannedDeparture = plannedDeparture;
2147
2148 route->m_RouteNameString = proute->m_NameString;
2149 route->m_RouteStartString = proute->m_StartString;
2150 route->m_RouteEndString = proute->m_EndString;
2151 if (!proute->m_GUID.IsEmpty()) {
2152 route->m_GUID = proute->m_GUID;
2153 }
2154 route->m_btemp = (b_permanent == false);
2155 route->SetVisible(proute->m_isVisible);
2156 route->m_RouteDescription = proute->m_Description;
2157
2158 pRouteList->Append(route);
2159
2160 if (b_permanent) pConfig->AddNewRoute(route);
2161
2162 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
2163 pRouteManagerDialog->UpdateRouteListCtrl();
2164
2165 return true;
2166}
2167
2169 bool b_found = false;
2170
2171 // Find the Route
2172 Route* pRoute = g_pRouteMan->FindRouteByGUID(proute->m_GUID);
2173 if (pRoute) b_found = true;
2174
2175 if (b_found) {
2176 bool b_permanent = !pRoute->m_btemp;
2177 g_pRouteMan->DeleteRoute(pRoute, NavObjectChanges::getInstance());
2178
2179 b_found = AddPlugInRouteEx(proute, b_permanent);
2180 }
2181
2182 return b_found;
2183}
2184
2185// std::unique_ptr<PlugIn_Waypoint_Ex> GetWaypointEx_Plugin(const wxString &)
2186// {
2187// }
2188
2189// std::unique_ptr<PlugIn_Route_Ex> GetRouteEx_Plugin(const wxString &)
2190// {
2191// }
2192
2193std::unique_ptr<PlugIn_Waypoint_Ex> GetWaypointEx_Plugin(const wxString& GUID) {
2194 std::unique_ptr<PlugIn_Waypoint_Ex> w(new PlugIn_Waypoint_Ex);
2195 GetSingleWaypointEx(GUID, w.get());
2196 return w;
2197}
2198
2199std::unique_ptr<PlugIn_Route_Ex> GetRouteEx_Plugin(const wxString& GUID) {
2200 std::unique_ptr<PlugIn_Route_Ex> r;
2201 Route* route = g_pRouteMan->FindRouteByGUID(GUID);
2202 if (route == nullptr) return r;
2203
2204 r = std::unique_ptr<PlugIn_Route_Ex>(new PlugIn_Route_Ex);
2205 PlugIn_Route_Ex* dst_route = r.get();
2206
2207 // PlugIn_Waypoint *pwp;
2208 RoutePoint* src_wp;
2209 wxRoutePointListNode* node = route->pRoutePointList->GetFirst();
2210
2211 while (node) {
2212 src_wp = node->GetData();
2213
2214 PlugIn_Waypoint_Ex* dst_wp = new PlugIn_Waypoint_Ex();
2215 PlugInExFromRoutePoint(dst_wp, src_wp);
2216
2217 dst_route->pWaypointList->Append(dst_wp);
2218
2219 node = node->GetNext();
2220 }
2221 dst_route->m_NameString = route->m_RouteNameString;
2222 dst_route->m_StartString = route->m_RouteStartString;
2223 dst_route->m_EndString = route->m_RouteEndString;
2224 dst_route->m_GUID = route->m_GUID;
2225 dst_route->m_isActive = g_pRouteMan->GetpActiveRoute() == route;
2226 dst_route->m_isVisible = route->IsVisible();
2227 dst_route->m_Description = route->m_RouteDescription;
2228
2229 return r;
2230}
2231
2233 void) { // if no active waypoint, returns wxEmptyString
2234 RoutePoint* rp = g_pRouteMan->GetpActivePoint();
2235 if (!rp)
2236 return wxEmptyString;
2237 else
2238 return rp->m_GUID;
2239}
2240
2242 void) { // if no active route, returns wxEmptyString
2243 Route* rt = g_pRouteMan->GetpActiveRoute();
2244 if (!rt)
2245 return wxEmptyString;
2246 else
2247 return rt->m_GUID;
2248}
2249
2251int GetGlobalWatchdogTimoutSeconds() { return gps_watchdog_timeout_ticks; }
2252
2254std::vector<std::string> GetPriorityMaps() {
2255 MyApp& app = wxGetApp();
2256 return (app.m_comm_bridge.GetPriorityMaps());
2257}
2258
2259std::vector<std::string> GetActivePriorityIdentifiers() {
2260 std::vector<std::string> result;
2261
2262 MyApp& app = wxGetApp();
2263
2264 std::string id =
2265 app.m_comm_bridge.GetPriorityContainer("position").active_source;
2266 result.push_back(id);
2267 id = app.m_comm_bridge.GetPriorityContainer("velocity").active_source;
2268 result.push_back(id);
2269 id = app.m_comm_bridge.GetPriorityContainer("heading").active_source;
2270 result.push_back(id);
2271 id = app.m_comm_bridge.GetPriorityContainer("variation").active_source;
2272 result.push_back(id);
2273 id = app.m_comm_bridge.GetPriorityContainer("satellites").active_source;
2274 result.push_back(id);
2275
2276 return result;
2277}
2278
2280 double rv = 1.0;
2281#if defined(__WXOSX__) || defined(__WXGTK3__)
2282 // Support scaled HDPI displays.
2283 if (gFrame) rv = gFrame->GetContentScaleFactor();
2284#endif
2285 return rv;
2286}
2288 double scaler = 1.0;
2289#ifdef __WXMSW__
2290 if (gFrame) scaler = (double)(gFrame->ToDIP(100)) / 100.;
2291#endif
2292 return scaler;
2293}
2294
2295//---------------------------------------------------------------------------
2296// API 1.18
2297//---------------------------------------------------------------------------
2298
2299//---------------------------------------------------------------------------
2300// API 1.19
2301//---------------------------------------------------------------------------
2302void ExitOCPN() {}
2303
2304bool GetFullScreen() { return gFrame->IsFullScreen(); }
2305
2306void SetFullScreen(bool set_full_screen_on) {
2307 bool state = gFrame->IsFullScreen();
2308 if (set_full_screen_on && !state)
2309 gFrame->ToggleFullScreen();
2310 else if (!set_full_screen_on && state)
2311 gFrame->ToggleFullScreen();
2312}
2313
2314extern bool g_useMUI;
2315void EnableMUIBar(bool enable, int CanvasIndex) {
2316 bool current_mui_state = g_useMUI;
2317
2318 g_useMUI = enable;
2319 if (enable && !current_mui_state) { // OFF going ON
2320 // ..For each canvas...
2321 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
2322 ChartCanvas* cc = g_canvasArray.Item(i);
2323 if (cc) cc->CreateMUIBar();
2324 }
2325 } else if (!enable && current_mui_state) { // ON going OFF
2326 // ..For each canvas...
2327 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
2328 ChartCanvas* cc = g_canvasArray.Item(i);
2329 if (cc) cc->DestroyMuiBar();
2330 }
2331 }
2332}
2333
2334bool GetEnableMUIBar(int CanvasIndex) { return g_useMUI; }
2335
2336void EnableCompassGPSIcon(bool enable, int CanvasIndex) {
2337 if (CanvasIndex < GetCanvasCount()) {
2338 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2339 if (cc) cc->SetShowGPSCompassWindow(enable);
2340 }
2341}
2342
2343bool GetEnableCompassGPSIcon(int CanvasIndex) {
2344 if (CanvasIndex < GetCanvasCount()) {
2345 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2346 if (cc)
2347 return cc->GetShowGPSCompassWindow();
2348 else
2349 return false;
2350 }
2351 return false;
2352}
2353
2354extern bool g_bShowStatusBar;
2355void EnableStatusBar(bool enable) {
2356 g_bShowStatusBar = enable;
2357 gFrame->ConfigureStatusBar();
2358}
2359
2360bool GetEnableStatusBar() { return g_bShowStatusBar; }
2361
2362void EnableChartBar(bool enable, int CanvasIndex) {
2363 bool current_chartbar_state = g_bShowChartBar;
2364 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
2365 ChartCanvas* cc = g_canvasArray.Item(i);
2366 if (current_chartbar_state && !enable) {
2367 gFrame->ToggleChartBar(cc);
2368 g_bShowChartBar = current_chartbar_state;
2369 } else if (!current_chartbar_state && enable) {
2370 gFrame->ToggleChartBar(cc);
2371 g_bShowChartBar = current_chartbar_state;
2372 }
2373 }
2374 g_bShowChartBar = enable;
2375}
2376
2377bool GetEnableChartBar(int CanvasIndex) { return g_bShowChartBar; }
2378
2379extern bool g_bShowMenuBar;
2380void EnableMenu(bool enable) {
2381 if (!enable) {
2382 if (g_bShowMenuBar) {
2383 g_bShowMenuBar = false;
2384 if (gFrame->m_pMenuBar) {
2385 gFrame->SetMenuBar(NULL);
2386 gFrame->m_pMenuBar->Destroy();
2387 gFrame->m_pMenuBar = NULL;
2388 }
2389 }
2390 } else {
2391 g_bShowMenuBar = true;
2392 gFrame->BuildMenuBar();
2393 }
2394}
2395
2396bool GetEnableMenu() { return g_bShowMenuBar; }
2397
2398void SetGlobalColor(std::string table, std::string name, wxColor color) {
2399 if (ps52plib) ps52plib->m_chartSymbols.UpdateTableColor(table, name, color);
2400}
2401
2402wxColor GetGlobalColorD(std::string map_name, std::string name) {
2403 wxColor ret = wxColor(*wxRED);
2404 if (ps52plib) {
2405 int i_table = ps52plib->m_chartSymbols.FindColorTable(map_name.c_str());
2406 ret = ps52plib->m_chartSymbols.GetwxColor(name.c_str(), i_table);
2407 }
2408 return ret;
2409}
2410
2411void EnableLatLonGrid(bool enable, int CanvasIndex) {
2412 if (CanvasIndex < GetCanvasCount()) {
2413 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2414 if (cc) cc->SetShowGrid(enable);
2415 }
2416}
2417
2418void EnableChartOutlines(bool enable, int CanvasIndex) {
2419 if (CanvasIndex < GetCanvasCount()) {
2420 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2421 if (cc) cc->SetShowOutlines(enable);
2422 }
2423}
2424
2425void EnableDepthUnitDisplay(bool enable, int CanvasIndex) {
2426 if (CanvasIndex < GetCanvasCount()) {
2427 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2428 if (cc) cc->SetShowDepthUnits(enable);
2429 }
2430}
2431
2432void EnableAisTargetDisplay(bool enable, int CanvasIndex) {
2433 if (CanvasIndex < GetCanvasCount()) {
2434 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2435 if (cc) cc->SetShowAIS(enable);
2436 }
2437}
2438
2439void EnableTideStationsDisplay(bool enable, int CanvasIndex) {
2440 if (CanvasIndex < GetCanvasCount()) {
2441 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2442 if (cc) cc->ShowTides(enable);
2443 }
2444}
2445
2446void EnableCurrentStationsDisplay(bool enable, int CanvasIndex) {
2447 if (CanvasIndex < GetCanvasCount()) {
2448 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2449 if (cc) cc->ShowCurrents(enable);
2450 }
2451}
2452
2453void EnableENCTextDisplay(bool enable, int CanvasIndex) {
2454 if (CanvasIndex < GetCanvasCount()) {
2455 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2456 if (cc) cc->SetShowENCText(enable);
2457 }
2458}
2459
2460void EnableENCDepthSoundingsDisplay(bool enable, int CanvasIndex) {
2461 if (CanvasIndex < GetCanvasCount()) {
2462 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2463 if (cc) cc->SetShowENCDepth(enable);
2464 }
2465}
2466
2467void EnableBuoyLightLabelsDisplay(bool enable, int CanvasIndex) {
2468 if (CanvasIndex < GetCanvasCount()) {
2469 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2470 if (cc) cc->SetShowENCBuoyLabels(enable);
2471 }
2472}
2473
2474void EnableLightsDisplay(bool enable, int CanvasIndex) {
2475 if (CanvasIndex < GetCanvasCount()) {
2476 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2477 if (cc) cc->SetShowENCLights(enable);
2478 }
2479}
2480
2481void EnableLightDescriptionsDisplay(bool enable, int CanvasIndex) {
2482 if (CanvasIndex < GetCanvasCount()) {
2483 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2484 if (cc) cc->SetShowENCLightDesc(enable);
2485 }
2486}
2487
2488void SetENCDisplayCategory(PI_DisCat cat, int CanvasIndex) {
2489 int valSet = STANDARD;
2490 switch (cat) {
2491 case PI_DISPLAYBASE:
2492 valSet = DISPLAYBASE;
2493 break;
2494 case PI_STANDARD:
2495 valSet = STANDARD;
2496 break;
2497 case PI_OTHER:
2498 valSet = OTHER;
2499 break;
2501 valSet = MARINERS_STANDARD;
2502 break;
2503 default:
2504 valSet = STANDARD;
2505 break;
2506 }
2507 if (CanvasIndex < GetCanvasCount()) {
2508 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2509 if (cc) cc->SetENCDisplayCategory(valSet);
2510 }
2511}
2513 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2514 if (cc)
2515 return ((PI_DisCat)cc->GetENCDisplayCategory());
2516 else
2517 return PI_DisCat::PI_STANDARD;
2518}
2519
2520void SetNavigationMode(PI_NavMode mode, int CanvasIndex) {
2521 int newMode = NORTH_UP_MODE;
2522 if (mode == PI_COURSE_UP_MODE)
2523 newMode = COURSE_UP_MODE;
2524 else if (mode == PI_HEAD_UP_MODE)
2525 newMode = HEAD_UP_MODE;
2526
2527 if (CanvasIndex < GetCanvasCount()) {
2528 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2529 if (cc) cc->SetUpMode(newMode);
2530 }
2531}
2533 if (CanvasIndex < GetCanvasCount()) {
2534 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2535 if (cc) return ((PI_NavMode)cc->GetUpMode());
2536 }
2537 return PI_NavMode::PI_NORTH_UP_MODE;
2538}
2539
2540bool GetEnableLatLonGrid(int CanvasIndex) {
2541 if (CanvasIndex < GetCanvasCount()) {
2542 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2543 if (cc) return (cc->GetShowGrid());
2544 }
2545 return false;
2546}
2547
2548bool GetEnableChartOutlines(int CanvasIndex) {
2549 if (CanvasIndex < GetCanvasCount()) {
2550 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2551 if (cc) return (cc->GetShowOutlines());
2552 }
2553 return false;
2554}
2555
2556bool GetEnableDepthUnitDisplay(int CanvasIndex) {
2557 if (CanvasIndex < GetCanvasCount()) {
2558 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2559 if (cc) return (cc->GetShowDepthUnits());
2560 }
2561 return false;
2562}
2563
2564bool GetEnableAisTargetDisplay(int CanvasIndex) {
2565 if (CanvasIndex < GetCanvasCount()) {
2566 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2567 if (cc) return (cc->GetShowAIS());
2568 }
2569 return false;
2570}
2571
2572bool GetEnableTideStationsDisplay(int CanvasIndex) {
2573 if (CanvasIndex < GetCanvasCount()) {
2574 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2575 if (cc) return (cc->GetbShowTide());
2576 }
2577 return false;
2578}
2579
2580bool GetEnableCurrentStationsDisplay(int CanvasIndex) {
2581 if (CanvasIndex < GetCanvasCount()) {
2582 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2583 if (cc) return (cc->GetbShowCurrent());
2584 }
2585 return false;
2586}
2587
2588bool GetEnableENCTextDisplay(int CanvasIndex) {
2589 if (CanvasIndex < GetCanvasCount()) {
2590 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2591 if (cc) return (cc->GetShowENCText());
2592 }
2593 return false;
2594}
2595
2597 if (CanvasIndex < GetCanvasCount()) {
2598 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2599 if (cc) return (cc->GetShowENCDepth());
2600 }
2601 return false;
2602}
2603
2604bool GetEnableBuoyLightLabelsDisplay(int CanvasIndex) {
2605 if (CanvasIndex < GetCanvasCount()) {
2606 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2607 if (cc) return (cc->GetShowENCBuoyLabels());
2608 }
2609 return false;
2610}
2611
2612bool GetEnableLightsDisplay(int CanvasIndex) {
2613 if (CanvasIndex < GetCanvasCount()) {
2614 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2615 if (cc) return (cc->GetShowENCLights());
2616 }
2617 return false;
2618}
2619
2620bool GetShowENCLightDesc(int CanvasIndex) {
2621 if (CanvasIndex < GetCanvasCount()) {
2622 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2623 if (cc) return (cc->GetbShowCurrent());
2624 }
2625 return false;
2626}
2627
2628void EnableTouchMode(bool enable) { g_btouch = enable; }
2629
2630bool GetTouchMode() { return g_btouch; }
2631
2632void EnableLookaheadMode(bool enable, int CanvasIndex) {
2633 if (CanvasIndex < GetCanvasCount()) {
2634 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2635 if (cc) cc->ToggleLookahead();
2636 }
2637}
2638
2639bool GetEnableLookaheadMode(int CanvasIndex) {
2640 if (CanvasIndex < GetCanvasCount()) {
2641 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2642 if (cc) return (cc->GetLookahead());
2643 }
2644 return false;
2645}
2646
2647extern bool g_bTrackActive;
2648void SetTrackingMode(bool enable) {
2649 if (!g_bTrackActive && enable)
2650 gFrame->TrackOn();
2651 else if (g_bTrackActive && !enable)
2652 gFrame->TrackOff();
2653}
2654bool GetTrackingMode() { return g_bTrackActive; }
2655
2657 gFrame->SetAndApplyColorScheme((ColorScheme)cs);
2658}
2660 return (PI_ColorScheme)global_color_scheme;
2661}
2662
2663void RequestWindowRefresh(wxWindow* win, bool eraseBackground) {
2664 if (win) win->Refresh(eraseBackground);
2665}
2666
2667void EnableSplitScreenLayout(bool enable) {
2668 if (g_canvasConfig == 1) {
2669 if (enable)
2670 return;
2671 else { // split to single
2672 g_canvasConfig = 0; // 0 => "single canvas"
2673 gFrame->CreateCanvasLayout();
2674 gFrame->DoChartUpdate();
2675 }
2676 } else {
2677 if (enable) { // single to split
2678 g_canvasConfig = 1; // 1 => "two canvas"
2679 gFrame->CreateCanvasLayout();
2680 gFrame->DoChartUpdate();
2681 } else {
2682 return;
2683 }
2684 }
2685}
2686
2687// ChartCanvas control utilities
2688
2689void PluginZoomCanvas(int CanvasIndex, double factor) {
2690 if (CanvasIndex < GetCanvasCount()) {
2691 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2692 if (cc) cc->ZoomCanvasSimple(factor);
2693 }
2694}
2695
2696bool GetEnableMainToolbar() { return (!g_disable_main_toolbar); }
2697void SetEnableMainToolbar(bool enable) {
2698 g_disable_main_toolbar = !enable;
2699 if (g_MainToolbar) g_MainToolbar->RefreshToolbar();
2700}
2701
2703 if (gFrame) gFrame->ScheduleSettingsDialog();
2704}
2705
2706void PluginCenterOwnship(int CanvasIndex) {
2707 if (CanvasIndex < GetCanvasCount()) {
2708 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2709 if (cc) {
2710 bool bfollow = cc->GetbFollow();
2711 cc->ResetOwnshipOffset();
2712 if (bfollow)
2713 cc->SetbFollow();
2714 else
2715 cc->JumpToPosition(gLat, gLon, cc->GetVPScale());
2716 }
2717 }
2718}
2719
2720void PluginSetFollowMode(int CanvasIndex, bool enable_follow) {
2721 if (CanvasIndex < GetCanvasCount()) {
2722 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2723 if (cc) {
2724 if (cc->GetbFollow() != enable_follow) cc->TogglebFollow();
2725 }
2726 }
2727}
2728
2729bool PluginGetFollowMode(int CanvasIndex) {
2730 if (CanvasIndex < GetCanvasCount()) {
2731 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2732 if (cc) return cc->GetbFollow();
2733 }
2734 return false;
2735}
2736
2737void EnableCanvasFocusBar(bool enable, int CanvasIndex) {
2738 if (CanvasIndex < GetCanvasCount()) {
2739 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2740 if (cc) cc->SetShowFocusBar(enable);
2741 }
2742}
2743bool GetEnableCanvasFocusBar(int CanvasIndex) {
2744 if (CanvasIndex < GetCanvasCount()) {
2745 ChartCanvas* cc = g_canvasArray.Item(CanvasIndex);
2746 if (cc) return (cc->GetShowFocusBar());
2747 }
2748 return false;
2749}
2750
2751bool GetEnableTenHertzUpdate() { return g_btenhertz; }
2752
2753void EnableTenHertzUpdate(bool enable) { g_btenhertz = enable; }
2754
2756 if (pConfig) {
2757 pConfig->Flush();
2758
2759 // Handle system general configuration options
2760 pConfig->LoadMyConfigRaw(false);
2761
2762 // Handle chart canvas window configuration options
2763 pConfig->LoadCanvasConfigs(false);
2764 auto& config_array = ConfigMgr::Get().GetCanvasConfigArray();
2765 for (auto pcc : config_array) {
2766 if (pcc && pcc->canvas) {
2767 pcc->canvas->ApplyCanvasConfig(pcc);
2768 pcc->canvas->Refresh();
2769 }
2770 }
2771 }
2772}
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:151
float GetVPScale()
Return the ViewPort scale factor, in physical pixels per meter.
Definition chcanv.h:450
void ZoomCanvasSimple(double factor)
Perform an immediate zoom operation without smooth transitions.
Definition chcanv.cpp:4644
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:450
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:667
bool SetFontColor(const wxString &TextElement, const wxColour color) const
Sets the text color for a UI element.
Definition FontMgr.cpp:122
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Gets a font object for a UI element.
Definition FontMgr.cpp:186
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.
double Lat
Latitude in decimal degrees.
double Hdm
Heading magnetic in degrees.
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.
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)
Extended waypoint class with additional navigation features.
bool GetFSStatus()
Gets "free-standing" status of waypoint.
wxDateTime m_CreateTime
Creation timestamp.
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.
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:68
bool m_bIsolatedMark
Flag indicating if the waypoint is a standalone mark.
Represents a navigational route in the navigation system.
Definition route.h:96
wxDateTime m_PlannedDeparture
The departure time of the route, in UTC.
Definition route.h:213
bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes)
Definition routeman.cpp:836
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:139
void SetCreateTime(wxDateTime dt)
Sets the creation timestamp for a track point.
Definition track.cpp:145
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 * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
Definition gui_lib.cpp:54
wxFont GetOCPNGUIScaledFont(wxString item)
Retrieves a font optimized for touch and high-resolution interfaces.
Definition gui_lib.cpp:83
General purpose GUI support.
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 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.
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 start 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.
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.
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.
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.
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 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.
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)
Removes 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.
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:589
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.
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:392
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