OpenCPN Partial API docs
Loading...
Searching...
No Matches
ocpn_frame.cpp
1/**************************************************************************
2 * Copyright (C) 2010 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, see <https://www.gnu.org/licenses/ *
16 **************************************************************************/
17
18/*
19 * \file
20 *
21 * OpenCPN top window
22 */
23#include "config.h"
24#include "gl_headers.h" // Must be included before anything using GL stuff
25
26#ifdef __MINGW32__
27#undef IPV6STRICT // mingw FTBS fix: missing struct ip_mreq
28#include <windows.h>
29#endif
30
31#include <wx/wxprec.h>
32
33#ifndef WX_PRECOMP
34#include <wx/wx.h>
35#endif // precompiled headers
36
37#ifdef __WXMSW__
38// #include "c:\\Program Files\\visual leak detector\\include\\vld.h"
39#endif
40
41#ifdef __WXMSW__
42#include <math.h>
43#include <psapi.h>
44#include <stdlib.h>
45#include <time.h>
46#endif
47
48#ifdef OCPN_HAVE_X11
49#include <X11/Xatom.h>
50#include <X11/Xlib.h>
51#endif
52
53#include <wx/stdpaths.h>
54#include <wx/tokenzr.h>
55#include <wx/display.h>
56#include <wx/jsonreader.h>
57
58#include "o_sound/o_sound.h"
59
60#include "model/ais_decoder.h"
64#include "model/cmdline.h"
65#include "model/comm_drv_factory.h" //FIXME(dave) this one goes away
69#include "model/comm_vars.h"
70#include "model/config_vars.h"
71#include "model/cutil.h"
72#include "model/georef.h"
73#include "model/gui.h"
74#include "model/gui_vars.h"
75#include "model/gui_events.h"
76#include "model/gui_vars.h"
77#include "model/idents.h"
78#include "model/local_api.h"
79#include "model/logger.h"
80#include "model/multiplexer.h"
81#include "model/navobj_db.h"
82#include "model/nav_object_database.h"
83#include "model/navutil_base.h"
85#include "model/own_ship.h"
86#include "model/plugin_comm.h"
87#include "model/plugin_loader.h"
88#include "model/routeman.h"
89#include "model/select.h"
90#include "model/std_icon.h"
91#include "model/sys_events.h"
92#include "model/track.h"
93
94#include "ais_info_gui.h"
95#include "dialog_alert.h"
96#include "about_frame_impl.h"
97#include "about.h"
98#include "ais.h"
99#include "ais_info_gui.h"
100#include "ais_target_alert_dlg.h"
101#include "ais_target_list_dlg.h"
102#include "ais_target_query_dlg.h"
103#include "canvas_config.h"
104#include "chartbase.h"
105#include "chart_ctx_factory.h"
106#include "chartdb.h"
107#include "chcanv.h"
108#include "tc_win.h"
109#include "cm93.h"
110#include "color_handler.h"
111#include "compass.h"
112#include "concanv.h"
113#include "connections_dlg.h"
114#include "config_mgr.h"
115#include "data_monitor.h"
116#include "dychart.h"
117#include "font_mgr.h"
118#include "gl_chart_canvas.h"
119#include "go_to_position_dlg.h"
120#include "gui_lib.h"
121#include "ienc_toolbar.h"
122#include "layer.h"
123#include "load_errors_dlg.h"
124#include "mark_info.h"
125#include "mui_bar.h"
126#include "N2KParser.h"
127#include "navutil.h"
128#include "ocpn_app.h"
129#include "ocpn_plugin.h"
130#include "ocpn_aui_manager.h"
131#include "ocpn_frame.h"
132#include "ocpn_platform.h"
133#include "o_senc.h"
134#include "options.h"
135#include "pluginmanager.h"
136#include "print_dialog.h"
137#include "printout_chart.h"
138#include "routemanagerdialog.h"
139#include "routeman_gui.h"
140#include "route_point_gui.h"
141#include "route_prop_dlg_impl.h"
142#include "s52plib.h"
143#include "s57chart.h"
144#include "s57_query_dlg.h"
145#include "tcmgr.h"
146#include "timers.h"
147#include "toolbar.h"
148#include "track_prop_dlg.h"
149#include "waypointman_gui.h"
150#include "canvas_options.h"
151#include "udev_rule_mgr.h"
152
153#ifdef __ANDROID__
154#include "androidUTIL.h"
155#endif
156
157//------------------------------------------------------------------------------
158// Static variable definition
159//------------------------------------------------------------------------------
160//
161
162arrayofCanvasPtr g_canvasArray;
163
164extern options *g_pOptions; // FIXME (leamas) same as g_options, merge
165MyFrame *gFrame;
166
167#ifdef ocpnUSE_GL
168GLenum g_texture_rectangle_format;
169#endif
170
171#if wxUSE_XLOCALE || !wxCHECK_VERSION(3, 0, 0)
172extern wxLocale *plocale_def_lang;
173#endif
174
175#ifdef ocpnUSE_GL
176extern bool g_b_EnableVBO;
177extern GLenum g_texture_rectangle_format;
178extern OCPN_GLCaps *GL_Caps;
179#endif
180
181static int g_last_ChartScaleFactor;
182static char nmea_tick_chars[] = {'|', '/', '-', '\\', '|', '/', '-', '\\'};
183static int options_subpage = 0;
184static bool b_reloadForPlugins;
185
186static wxSize options_lastWindowSize(0, 0);
187static wxPoint options_lastWindowPos(0, 0);
188
189// Values returned from WMM_PI for variation computation request.
190// Initialize to invalid so we don't use it if WMM hasn't updated yet
191static double gQueryVar = 361.0;
192
193static char bells_sound_file_name[2][12] = {"1bells.wav", "2bells.wav"};
194static o_sound::Sound *_bells_sounds[] = {o_sound::Factory(),
195 o_sound::Factory()};
196static std::vector<o_sound::Sound *> bells_sound(_bells_sounds,
197 _bells_sounds + 2);
198
199static wxArrayPtrVoid *UserColourHashTableArray;
200
201#ifdef __WXMSW__
202// System color control support
203
204typedef DWORD(WINAPI *SetSysColors_t)(DWORD, DWORD *, DWORD *);
205typedef DWORD(WINAPI *GetSysColor_t)(DWORD);
206
207static SetSysColors_t pSetSysColors;
208static GetSysColor_t pGetSysColor;
209
210void SaveSystemColors();
211void RestoreSystemColors();
212
213DWORD color_3dface;
214DWORD color_3dhilite;
215DWORD color_3dshadow;
216DWORD color_3ddkshadow;
217DWORD color_3dlight;
218DWORD color_activecaption;
219DWORD color_gradientactivecaption;
220DWORD color_captiontext;
221DWORD color_windowframe;
222DWORD color_inactiveborder;
223
224#endif
225
226#ifdef __VISUALC__
227#include <wx/msw/msvcrt.h>
228#endif
229
230#if !defined(NAN)
231static const long long lNaN = 0xfff8000000000000;
232#define NAN (*(double *)&lNaN)
233#endif
234
235static wxArrayPtrVoid *UserColorTableArray = 0;
236
237// Latest "ground truth" fix, and auxiliaries
238static double gLat_gt, gLon_gt;
239static double gLat_gt_m1, gLon_gt_m1;
240static uint64_t fix_time_gt;
241static uint64_t fix_time_gt_last;
242
243static double gSog_gt, gHdt_gt;
244static double gCog_gt_m1, gHdt_gt_m1;
245static uint64_t hdt_time_gt;
246static double cog_rate_gt, hdt_rate_gt;
247
248void InitializeUserColors();
249void DeInitializeUserColors();
250void SetSystemColors(ColorScheme cs);
251
252static bool LoadAllPlugIns(bool load_enabled) {
253 AbstractPlatform::ShowBusySpinner();
254 bool b = PluginLoader::GetInstance()->LoadAllPlugIns(load_enabled);
255 AbstractPlatform::HideBusySpinner();
256 return b;
257}
258
259static void LaunchLocalHelp() {
260#ifdef __ANDROID__
261 androidLaunchHelpView();
262#else
263 wxString def_lang_canonical = "en_US";
264
265#if wxUSE_XLOCALE
266 if (plocale_def_lang)
267 def_lang_canonical = plocale_def_lang->GetCanonicalName();
268#endif
269
270 wxString help_locn = g_Platform->GetSharedDataDir() + "doc/help_";
271
272 wxString help_try = help_locn + def_lang_canonical + ".html";
273
274 if (!::wxFileExists(help_try)) {
275 help_try = help_locn + "en_US" + ".html";
276
277 if (!::wxFileExists(help_try)) {
278 help_try = help_locn + "web" + ".html";
279 }
280
281 if (!::wxFileExists(help_try)) return;
282 }
283
284 wxLaunchDefaultBrowser(wxString("file:///") + help_try);
285#endif
286}
287
288static void DoHelpDialog() {
289#ifndef __ANDROID__
290 if (!g_pAboutDlg) {
291 g_pAboutDlg = new AboutFrameImpl(gFrame);
292 } else {
293 g_pAboutDlg->SetFocus();
294 }
295 g_pAboutDlg->Show();
296
297#else
299 g_pAboutDlgLegacy = new About(gFrame, g_Platform->GetSharedDataDir(),
300 [] { LaunchLocalHelp(); });
301 else
302 g_pAboutDlgLegacy->SetFocus();
303 g_pAboutDlgLegacy->Show();
304
305#endif
306}
307
308//------------------------------------------------------------------------------
309// PNG Icon resources
310//------------------------------------------------------------------------------
311
312#if defined(__WXGTK__) || defined(__WXQT__)
313#include "bitmaps/opencpn.xpm"
314#endif
315
316//------------------------------------------------------------------------------
317// Local constants
318//------------------------------------------------------------------------------
319// enum {
320// ID_PIANO_DISABLE_QUILT_CHART = 32000, ID_PIANO_ENABLE_QUILT_CHART
321// };
322
323//------------------------------------------------------------------------------
324// Fwd Refs
325//------------------------------------------------------------------------------
326
327void BuildiENCToolbar(bool bnew) {
328 if (g_bInlandEcdis) {
329 if (bnew) {
330 if (g_iENCToolbar) {
331 wxPoint locn = g_iENCToolbar->GetToolbarPosition();
332 wxPoint tbp_incanvas =
333 locn; // gFrame->GetPrimaryCanvas()->ScreenToClient(locn);
334
335 g_iENCToolbarPosY = tbp_incanvas.y;
336 g_iENCToolbarPosX = tbp_incanvas.x;
337
338 delete g_iENCToolbar;
339 g_iENCToolbar = 0;
340 }
341 }
342
343 if (!g_iENCToolbar) {
344 wxPoint posn(g_iENCToolbarPosX, g_iENCToolbarPosY);
345
346 // Overlapping main toolbar?
347 if (g_MainToolbar) {
348 if ((g_iENCToolbarPosY > g_maintoolbar_y) &&
349 (g_iENCToolbarPosY <
350 g_maintoolbar_y + g_MainToolbar->GetToolSize().y))
351 g_iENCToolbarPosY = -1; // force a reposition
352 }
353
354 if ((g_iENCToolbarPosX < 0) || (g_iENCToolbarPosY < 0)) {
355 posn.x = 0;
356 posn.y = 100;
357
358 if (g_MainToolbar)
359 posn =
360 wxPoint(g_maintoolbar_x + g_MainToolbar->GetToolbarSize().x + 4,
361 g_maintoolbar_y);
362 }
363
364 double tool_scale_factor =
365 g_Platform->GetToolbarScaleFactor(g_GUIScaleFactor);
366
368 new iENCToolbar(gFrame, posn, wxTB_HORIZONTAL, tool_scale_factor);
369 g_iENCToolbar->SetColorScheme(global_color_scheme);
370 g_iENCToolbar->EnableSubmerge(false);
371 }
372 } else {
373 delete g_iENCToolbar;
374 g_iENCToolbar = NULL;
375 }
376}
377
378bool isSingleChart(ChartBase *chart) {
379 if (chart == nullptr) return false;
380
381 // ..For each canvas...
382 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
383 ChartCanvas *cc = g_canvasArray.Item(i);
384 if (cc && cc->m_singleChart == chart) {
385 return true;
386 }
387 }
388 return false;
389}
390
391#if defined(__WXGTK__) && defined(OCPN_HAVE_X11)
392
393// Note: use XFree to free this pointer. Use unique_ptr in the future.
394static char *get_X11_property(Display *disp, Window win, Atom xa_prop_type,
395 const char *prop_name) {
396 Atom xa_prop_name;
397 Atom xa_ret_type;
398 int ret_format;
399 unsigned long ret_nitems;
400 unsigned long ret_bytes_after;
401 unsigned char *ret_prop;
402
403 xa_prop_name = XInternAtom(disp, prop_name, False);
404
405 // For XGetWindowProperty source see
406 // https://github.com/mirror/libX11/blob/master/src/GetProp.c#L107
407 // it is quite tricky. Some notes.
408 // + Results are already NULL terminated.
409 // + 32 as a ret_format means sizeof(long) in the API...
410 // + but as xlib does the null termination we can just ignore the sizes.
411 if (XGetWindowProperty(disp, win, xa_prop_name, 0, 1024, False, xa_prop_type,
412 &xa_ret_type, &ret_format, &ret_nitems,
413 &ret_bytes_after, &ret_prop) != Success)
414 return NULL;
415
416 if (xa_ret_type != xa_prop_type) {
417 XFree(ret_prop);
418 return NULL;
419 }
420 return (char *)ret_prop;
421}
422#endif
423
424// Determine if a transparent toolbar is possible under linux with opengl
425static bool isTransparentToolbarInOpenGLOK() {
426#ifdef __WXOSX__
427 return true;
428#else
429 bool status = false;
430#ifndef __WXQT__
431#ifdef OCPN_HAVE_X11
432 if (!g_bdisable_opengl) {
433 Display *disp = XOpenDisplay(NULL);
434 Window *sup_window;
435 if ((sup_window = (Window *)get_X11_property(disp, DefaultRootWindow(disp),
436 XA_WINDOW,
437 "_NET_SUPPORTING_WM_CHECK")) ||
438 (sup_window = (Window *)get_X11_property(disp, DefaultRootWindow(disp),
439 XA_CARDINAL,
440 "_WIN_SUPPORTING_WM_CHECK"))) {
441 /* WM_NAME */
442 char *wm_name;
443 if ((wm_name = get_X11_property(disp, *sup_window,
444 XInternAtom(disp, "UTF8_STRING", False),
445 "_NET_WM_NAME")) ||
446 (wm_name = get_X11_property(disp, *sup_window, XA_STRING,
447 "_NET_WM_NAME"))) {
448 // we know it works in xfce4, add other checks as we can validate them
449 if (strstr(wm_name, "Xfwm4") || strstr(wm_name, "Compiz"))
450 status = true;
451
452 XFree(wm_name);
453 }
454 XFree(sup_window);
455 }
456 XCloseDisplay(disp);
457 }
458#endif
459#endif
460 return status;
461#endif
462}
463
464//------------------------------------------------------------------------------
465// MyFrame
466//------------------------------------------------------------------------------
467
468// Frame implementation
469// NOLINTBEGIN
470wxDEFINE_EVENT(BELLS_PLAYED_EVTYPE, wxCommandEvent);
471
472BEGIN_EVENT_TABLE(MyFrame, wxFrame)
473EVT_CLOSE(MyFrame::OnCloseWindow)
474EVT_MENU(wxID_EXIT, MyFrame::OnExit)
475EVT_SIZE(MyFrame::OnSize)
476EVT_MOVE(MyFrame::OnMove)
477EVT_ICONIZE(MyFrame::OnIconize)
478EVT_MENU(-1, MyFrame::OnToolLeftClick)
479EVT_TIMER(INIT_TIMER, MyFrame::OnInitTimer)
480EVT_TIMER(FRAME_TIMER_1, MyFrame::OnFrameTimer1)
481EVT_TIMER(FRAME_TC_TIMER, MyFrame::OnFrameTCTimer)
482EVT_TIMER(FRAME_COG_TIMER, MyFrame::OnFrameCOGTimer)
483EVT_TIMER(MEMORY_FOOTPRINT_TIMER, MyFrame::OnMemFootTimer)
484EVT_TIMER(FRANE_TENHZ_TIMER, MyFrame::OnFrameTenHzTimer)
485EVT_MAXIMIZE(MyFrame::OnMaximize)
486EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_TOOL_RCLICKED,
487 MyFrame::RequestNewToolbarArgEvent)
488EVT_ERASE_BACKGROUND(MyFrame::OnEraseBackground)
489// EVT_TIMER(RESIZE_TIMER, MyFrame::OnResizeTimer)
490EVT_TIMER(RECAPTURE_TIMER, MyFrame::OnRecaptureTimer)
491EVT_TIMER(TOOLBAR_ANIMATE_TIMER, MyFrame::OnToolbarAnimateTimer)
492EVT_COMMAND(wxID_ANY, BELLS_PLAYED_EVTYPE, MyFrame::OnBellsFinished)
493
494#ifdef wxHAS_POWER_EVENTS
495EVT_POWER_SUSPENDING(MyFrame::OnSuspending)
496EVT_POWER_SUSPENDED(MyFrame::OnSuspended)
497EVT_POWER_SUSPEND_CANCEL(MyFrame::OnSuspendCancel)
498EVT_POWER_RESUME(MyFrame::OnResume)
499#endif // wxHAS_POWER_EVENTS
500
501END_EVENT_TABLE()
502
503// NOLINTEND
504
505/*
506 * Direct callback from completed sound, possibly in an interrupt
507 * context. Just post an event to be processed in main thread.
508 */
509static void onBellsFinishedCB(void *ptr) {
510 auto framePtr = static_cast<MyFrame *>(ptr);
511 if (framePtr) {
512 wxCommandEvent ev(BELLS_PLAYED_EVTYPE);
513 wxPostEvent(framePtr, ev);
514 }
515}
516
517static void OnDriverMsg(const ObservedEvt &ev) {
518 auto msg = ev.GetString().ToStdString();
519 auto &noteman = NotificationManager::GetInstance();
520 noteman.AddNotification(NotificationSeverity::kInformational, msg, 60);
521}
522
523static NmeaLog *GetDataMonitor() {
524 auto w = wxWindow::FindWindowByName(kDataMonitorWindowName);
525 return dynamic_cast<NmeaLog *>(w);
526}
527
528// My frame constructor
529MyFrame::MyFrame(wxFrame *frame, const wxString &title, const wxPoint &pos,
530 const wxSize &size, long style,
531 wxAuiDefaultDockArt *pauidockart)
532 : wxFrame(frame, -1, title, pos, size, style, kTopLevelWindowName),
533 m_connections_dlg(nullptr),
534 m_data_monitor(new DataMonitor(this)),
535 m_pauidockart(pauidockart) {
536 g_current_monitor = wxDisplay::GetFromWindow(this);
537#ifdef __WXOSX__
538 // On retina displays there is a difference between the physical size of the
539 // OpenGL canvas and the DIP This is not observed anywhere else so far, so
540 // g_current_monitor_dip_px_ratio cna be kept 1.0 everywhere else
541 if (g_bopengl) {
545 }
546#endif
547 m_last_track_rotation_ts = 0;
548 m_ulLastNMEATicktime = 0;
549 m_data_monitor->Hide();
550 m_pStatusBar = NULL;
551 m_StatusBarFieldCount = g_Platform->GetStatusBarFieldCount();
552
553 m_pMenuBar = NULL;
554 g_options = NULL;
555 m_load_errors_dlg_ctrl = std::make_unique<LoadErrorsDlgCtrl>(this);
556
557 // Redirect the initialization timer to this frame
558 InitTimer.SetOwner(this, INIT_TIMER);
559 m_iInitCount = 0;
560 m_initializing = false;
561
562 // Redirect the global heartbeat timer to this frame
563 FrameTimer1.SetOwner(this, FRAME_TIMER_1);
564
565 // Redirect the Tide/Current update timer to this frame
566 FrameTCTimer.SetOwner(this, FRAME_TC_TIMER);
567
568 // Redirect the COG Averager timer to this frame
569 FrameCOGTimer.SetOwner(this, FRAME_COG_TIMER);
570
571 // Redirect the Memory Footprint Management timer to this frame
572 MemFootTimer.SetOwner(this, MEMORY_FOOTPRINT_TIMER);
573
574 // Direct the Toolbar Animation timer to this frame
575 ToolbarAnimateTimer.SetOwner(this, TOOLBAR_ANIMATE_TIMER);
576
577 FrameTenHzTimer.SetOwner(this, FRANE_TENHZ_TIMER);
578
579#ifdef __ANDROID__
580// m_PrefTimer.SetOwner( this, ANDROID_PREF_TIMER );
581// Connect( m_PrefTimer.GetId(), wxEVT_TIMER, wxTimerEventHandler(
582// MyFrame::OnPreferencesResultTimer ), NULL, this );
583#endif
584
585 // Set up some assorted member variables
586 m_bTimeIsSet = false;
587 nBlinkerTick = 0;
588
589 m_bdefer_resize = false;
590
591 // Clear the NMEA Filter tables
592 for (int i = 0; i < MAX_COGSOG_FILTER_SECONDS; i++) {
593 COGFilterTable[i] = NAN;
594 SOGFilterTable[i] = NAN;
595 }
596 m_last_bGPSValid = false;
597 m_last_bVelocityValid = false;
598
599 gHdt = NAN;
600 gHdm = NAN;
601 gVar = NAN;
602 gSog = NAN;
603 gCog = NAN;
604 gHdt_gt = NAN;
605 gCog_gt = NAN;
606
607 for (int i = 0; i < MAX_COG_AVERAGE_SECONDS; i++) COGTable[i] = NAN;
608
609 m_fixtime = -1;
610
611 double dt = 2.0; // Time interval
612 double process_noise_std = 1.0; // Process noise standard deviation
613 double measurement_noise_std = 0.5; // Measurement noise standard deviation
614
615 m_ChartUpdatePeriod = 1; // set the default (1 sec.) period
616 initIXNetSystem();
617
618 // Establish my children
619 struct MuxLogCallbacks log_callbacks;
620 log_callbacks.log_is_active = [&]() {
621 auto log = GetDataMonitor();
622 return log && log->IsVisible();
623 };
624 log_callbacks.log_message = [&](Logline ll) {
625 NmeaLog *monitor = GetDataMonitor();
626 if (monitor && monitor->IsVisible()) monitor->Add(ll);
627 };
628 g_pMUX = new Multiplexer(log_callbacks, g_b_legacy_input_filter_behaviour);
629
630 struct AisDecoderCallbacks ais_callbacks;
631 ais_callbacks.confirm_stop_track = []() {
632 int r = OCPNMessageBox(
633 NULL,
634 _("This AIS target has Persistent tracking selected by MMSI "
635 "properties\n"
636 "A Persistent track recording will therefore be restarted for this "
637 "target.\n\n"
638 "Do you instead want to stop Persistent tracking for this target?"),
639 _("OpenCPN Info"), wxYES_NO | wxCENTER, 60);
640 return r == wxID_YES;
641 };
642 ais_callbacks.get_target_mmsi = []() {
643 auto alert_dlg_active =
644 dynamic_cast<AISTargetAlertDialog *>(g_pais_alert_dialog_active);
645 assert(alert_dlg_active);
646 return alert_dlg_active->Get_Dialog_MMSI();
647 };
648
649 g_pAIS = new AisDecoder(ais_callbacks);
650
651 g_pAISGUI = new AisInfoGui();
652
653 // Create/connect a dynamic event handler slot
654 wxLogMessage(" **** Connect stuff");
655
656 b_autofind = false;
657
658 // Create/connect a dynamic event handler slot for OCPN_MsgEvent(s) coming
659 // from PlugIn system
660 Connect(wxEVT_OCPN_MSG,
661 (wxObjectEventFunction)(wxEventFunction)&MyFrame::OnEvtPlugInMessage);
662
663 // FIXME (dave)
664 // Connect(wxEVT_OCPN_THREADMSG,
665 // (wxObjectEventFunction)(wxEventFunction)&MyFrame::OnEvtTHREADMSG);
666
667 // And from the thread SENC creator
669 (wxObjectEventFunction)(wxEventFunction)&MyFrame::OnSENCEvtThread);
670 // Establish the system icons for the frame.
671
672#ifdef __WXMSW__
673 SetIcon(wxICON(
674 0)); // this grabs the first icon in the integrated MSW resource file
675#endif
676
677#if defined(__WXGTK__) || defined(__WXQT__)
678 wxIcon app_icon(opencpn); // This comes from opencpn.xpm inclusion above
679 SetIcon(app_icon);
680#endif
681
682#ifdef __WXMSW__
683
684 // Establish the entry points in USER32.DLL for system color control
685
686 wxDynamicLibrary dllUser32("user32.dll");
687
688 pSetSysColors = (SetSysColors_t)dllUser32.GetSymbol("SetSysColors");
689 pGetSysColor = (GetSysColor_t)dllUser32.GetSymbol("GetSysColor");
690
691 SaveSystemColors();
692#endif
693
694 m_next_available_plugin_tool_id = ID_PLUGIN_BASE;
695
696 g_sticky_chart = -1;
697 m_BellsToPlay = 0;
698
699 m_resizeTimer.SetOwner(this, RESIZE_TIMER);
700 m_recaptureTimer.SetOwner(this, RECAPTURE_TIMER);
701 m_tick_idx = 0;
702 assert(g_pRouteMan != 0 && "g_pRouteMan not available");
703 m_routes_update_listener.Init(g_pRouteMan->on_routes_update,
704 [&](wxCommandEvent) { Refresh(); });
705 m_evt_drv_msg_listener.Init(CommDriverRegistry::GetInstance().evt_driver_msg,
706 [&](ObservedEvt &ev) { OnDriverMsg(ev); });
707
708#ifdef __WXOSX__
709 // Enable native fullscreen on macOS
710 EnableFullScreenView();
711#endif
712 int is_day = GetColorScheme() == GLOBAL_COLOR_SCHEME_DAY ? 1 : 0;
713 GuiEvents::GetInstance().color_scheme_change.Notify(is_day, "");
714}
715
716MyFrame::~MyFrame() {
717 FrameTimer1.Stop();
718 FrameTenHzTimer.Stop();
720
721 delete ChartData;
722 // delete pCurrentStack;
723
724 // Free the Route List
725 for (Route *pRouteDelete : *pRouteList) {
726 delete pRouteDelete;
727 }
728 delete pRouteList;
729 pRouteList = NULL;
730
731 Disconnect(
732 wxEVT_OCPN_MSG,
733 (wxObjectEventFunction)(wxEventFunction)&MyFrame::OnEvtPlugInMessage);
734 // FIXME (dave) Was in some datastream file?
735 // Disconnect(wxEVT_OCPN_THREADMSG,
736 // (wxObjectEventFunction)(wxEventFunction)&MyFrame::OnEvtTHREADMSG);
737}
738
739void MyFrame::FreezeCharts() {
740 // ..For each canvas,
741#ifndef __WXMAC__
742 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
743 ChartCanvas *cc = g_canvasArray.Item(i);
744 if (cc && !cc->IsFrozen()) cc->Freeze();
745 }
746#endif
747}
748
749void MyFrame::ThawCharts() {
750 // ..For each canvas,
751#ifndef __WXMAC__
752 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
753 ChartCanvas *cc = g_canvasArray.Item(i);
754 if (cc && cc->IsFrozen()) cc->Thaw();
755 }
756#endif
757}
758
759void MyFrame::OnSENCEvtThread(OCPN_BUILDSENC_ThreadEvent &event) {
760 s57chart *chart;
761 switch (event.type) {
762 case SENC_BUILD_STARTED:
763 // printf("Myframe SENC build started\n");
764 break;
765 case SENC_BUILD_DONE_NOERROR:
766 // printf("Myframe SENC build done no error\n");
767 chart = event.m_ticket->m_chart;
768 if (chart) {
769 chart->PostInit(FULL_INIT, global_color_scheme);
770 // ..For each canvas, force an S52PLIB reconfig...
771 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
772 ChartCanvas *cc = g_canvasArray.Item(i);
773 if (cc) cc->ClearS52PLIBStateHash(); // Force a S52 PLIB re-configure
774 }
775 }
776
777 ReloadAllVP();
778 delete event.m_ticket;
779 break;
780 case SENC_BUILD_DONE_ERROR:
781 // printf("Myframe SENC build done ERROR\n");
782 break;
783 default:
784 break;
785 }
786}
787
788void MyFrame::RebuildChartDatabase() {
789 bool b_SetInitialPoint = false;
790
791 // Build the initial chart dir array
792 ArrayOfCDI ChartDirArray;
793 pConfig->LoadChartDirArray(ChartDirArray);
794
795 if (ChartDirArray.GetCount()) {
796 // Create and Save a new Chart Database based on the hints
797 // given in the config file
798 if (g_NeedDBUpdate == 1) {
799 wxString msg1(
800 _("OpenCPN needs to update the chart database from config file "
801 "entries...."));
802
803 OCPNMessageDialog mdlg(gFrame, msg1, wxString(_("OpenCPN Info")),
804 wxICON_INFORMATION | wxOK);
805 mdlg.ShowModal();
806 }
807
808 delete ChartData;
809 ChartData = new ChartDB();
810
811 wxString line(
812 _("Rebuilding chart database from configuration file entries..."));
813 /* The following 3 strings are embeded in wxProgressDialog but must be
814 * included by xgettext to be localized properly. See
815 * {wxWidgets}src/generic/progdlgg.cpp:190 */
816 wxString dummy1 = _("Elapsed time : ");
817 wxString dummy2 = _("Estimated time : ");
818 wxString dummy3 = _("Remaining time : ");
819 wxGenericProgressDialog *pprog = new wxGenericProgressDialog(
820 _("OpenCPN Chart Update"), line, 100, NULL,
821 wxPD_SMOOTH | wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME |
822 wxPD_REMAINING_TIME);
823
824 ChartData->Create(ChartDirArray, pprog);
825 ChartData->SaveBinary(ChartListFileName);
826
827 delete pprog;
828
829 // Apply the inital Group Array structure to the chart database
830 ChartData->ApplyGroupArray(g_pGroupArray);
831 }
832}
833
834// play an arbitrary number of bells by using 1 and 2 bell sounds
835void MyFrame::OnBellsFinished(wxCommandEvent &event) {
836 int bells = wxMin(m_BellsToPlay, 2);
837 if (bells <= 0) return;
838
839 wxString soundfile = "sounds";
840 appendOSDirSlash(&soundfile);
841 soundfile += wxString(bells_sound_file_name[bells - 1], wxConvUTF8);
842 soundfile.Prepend(g_Platform->GetSharedDataDir());
843 wxLogMessage("Using bells sound file: " + soundfile);
844
845 o_sound::Sound *sound = bells_sound[bells - 1];
846 sound->SetFinishedCallback(onBellsFinishedCB, this);
847 auto cmd_sound = dynamic_cast<o_sound::SystemCmdSound *>(sound);
848 if (cmd_sound) cmd_sound->SetCmd(g_CmdSoundString.mb_str(wxConvUTF8));
849 sound->Load(soundfile);
850 if (!sound->IsOk()) {
851 wxLogMessage("Failed to load bells sound file: " + soundfile);
852 return;
853 }
854 sound->Play();
855 m_BellsToPlay -= bells;
856}
857
858void MyFrame::OnEraseBackground(wxEraseEvent &event) {}
859
860void MyFrame::OnMaximize(wxMaximizeEvent &event) {
861 g_click_stop = 0;
862#ifdef __WXOSX__
863 event.Skip();
864#endif
865}
866
867ColorScheme GetColorScheme() { return global_color_scheme; }
868
869ColorScheme MyFrame::GetColorScheme() { return global_color_scheme; }
870
871void MyFrame::ReloadAllVP() {
872 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
873 ChartCanvas *cc = g_canvasArray.Item(i);
874 if (cc) cc->ReloadVP();
875 }
876}
877
878void MyFrame::SetAndApplyColorScheme(ColorScheme cs) {
879 int is_day = cs == GLOBAL_COLOR_SCHEME_DAY ? 1 : 0;
880 GuiEvents::GetInstance().color_scheme_change.Notify(is_day, "");
881
882 global_color_scheme = cs;
883 wxString SchemeName;
884 switch (cs) {
885 case GLOBAL_COLOR_SCHEME_DAY:
886 SchemeName = "DAY";
887 break;
888 case GLOBAL_COLOR_SCHEME_DUSK:
889 SchemeName = "DUSK";
890 break;
891 case GLOBAL_COLOR_SCHEME_NIGHT:
892 SchemeName = "NIGHT";
893 break;
894 default:
895 SchemeName = "DAY";
896 break;
897 }
898
899 m_pauidockart->SetMetric(wxAUI_DOCKART_GRADIENT_TYPE, wxAUI_GRADIENT_NONE);
900
901 m_pauidockart->SetColour(wxAUI_DOCKART_BORDER_COLOUR, wxColour(0, 0, 0));
902 m_pauidockart->SetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE, 1);
903 m_pauidockart->SetColour(wxAUI_DOCKART_SASH_COLOUR, wxColour(0, 0, 0));
904 m_pauidockart->SetMetric(wxAUI_DOCKART_SASH_SIZE, 0);
905 m_pauidockart->SetColour(wxAUI_DOCKART_INACTIVE_CAPTION_COLOUR,
906 wxColour(0, 0, 0));
907 m_pauidockart->SetColour(wxAUI_DOCKART_BACKGROUND_COLOUR, wxColour(0, 0, 0));
908
909 // if( cs == GLOBAL_COLOR_SCHEME_DUSK || cs == GLOBAL_COLOR_SCHEME_NIGHT )
910 // {
911 // m_pauidockart->SetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE, 0);
912 // m_pauidockart->SetColour(wxAUI_DOCKART_BACKGROUND_COLOUR,
913 // wxColour(0,0,0));
914 // m_pauidockart->SetColour(wxAUI_DOCKART_BORDER_COLOUR,
915 // wxColour(0,0,0));
916 // }
917
918 // else{
919 // m_pauidockart->SetMetric(wxAUI_DOCKART_GRADIENT_TYPE,
920 // g_grad_default);
921 // m_pauidockart->SetColour(wxAUI_DOCKART_BORDER_COLOUR,
922 // g_border_color_default);
923 // m_pauidockart->SetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE,
924 // g_border_size_default);
925 // m_pauidockart->SetColour(wxAUI_DOCKART_SASH_COLOUR,
926 // g_sash_color_default);
927 // m_pauidockart->SetMetric(wxAUI_DOCKART_SASH_SIZE,
928 // g_sash_size_default);
929 // m_pauidockart->SetColour(wxAUI_DOCKART_INACTIVE_CAPTION_COLOUR,
930 // g_caption_color_default);
931 // m_pauidockart->SetColour(wxAUI_DOCKART_BACKGROUND_COLOUR,
932 // g_background_color_default);
933 //
934 // }
935
936 m_pauidockart->SetColour(wxAUI_DOCKART_SASH_COLOUR, wxColour(0, 0, 0));
937 m_pauidockart->SetMetric(wxAUI_DOCKART_SASH_SIZE, 6);
938
939 g_pauimgr->Update();
940
941 g_StyleManager->GetCurrentStyle()->SetColorScheme(cs);
942
943 // Search the user color table array to find the proper hash table
944 unsigned Usercolortable_index = 0;
945 for (unsigned int i = 0; i < UserColorTableArray->GetCount(); i++) {
946 colTable *ct = (colTable *)UserColorTableArray->Item(i);
947 if (SchemeName.IsSameAs(*ct->tableName)) {
948 Usercolortable_index = i;
949 break;
950 }
951 }
952
953 if (ps52plib) ps52plib->SetPLIBColorScheme(SchemeName, ChartCtxFactory());
954
955 // Set up a pointer to the proper hash table
957 (wxColorHashMap *)UserColourHashTableArray->Item(Usercolortable_index);
958
959 SetSystemColors(cs);
960
961 // ..For each canvas...
962 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
963 ChartCanvas *cc = g_canvasArray.Item(i);
964 if (cc) {
965 cc->SetColorScheme(cs);
966 cc->GetWorldBackgroundChart()->SetColorScheme(cs);
967 cc->HideChartInfoWindow();
968 cc->SetQuiltChartHiLiteIndex(-1);
969 }
970 }
971
972 if (pWayPointMan)
973 WayPointmanGui(*pWayPointMan)
974 .SetColorScheme(cs, g_Platform->GetDisplayDPmm());
975 if (ChartData) ChartData->ApplyColorSchemeToCachedCharts(cs);
976
977 if (g_options) {
978 g_options->SetColorScheme(cs);
979 }
980
981 if (console) {
982 console->SetColorScheme(cs);
983 }
984
985 if (g_pRouteMan) {
986 g_pRouteMan->SetColorScheme(cs, g_Platform->GetDisplayDPmm());
987 }
988
989 if (g_pMarkInfoDialog) {
990 g_pMarkInfoDialog->SetColorScheme(cs);
991 }
992
993 if (pRoutePropDialog) {
994 pRoutePropDialog->SetColorScheme(cs);
995 }
996
997 // For the AIS target query dialog, we must rebuild it to incorporate the
998 // style desired for the colorscheme selected
999 if (g_pais_query_dialog_active) {
1000 bool b_isshown = g_pais_query_dialog_active->IsShown();
1001 int n_mmsi = g_pais_query_dialog_active->GetMMSI();
1002 if (b_isshown) g_pais_query_dialog_active->Show(false); // dismiss it
1003
1004 g_pais_query_dialog_active->Close();
1005
1006 g_pais_query_dialog_active = new AISTargetQueryDialog();
1007 g_pais_query_dialog_active->Create(
1008 this, -1, _("AIS Target Query"),
1009 wxPoint(g_ais_query_dialog_x, g_ais_query_dialog_y));
1010 g_pais_query_dialog_active->SetMMSI(n_mmsi);
1011 g_pais_query_dialog_active->UpdateText();
1012 if (b_isshown) g_pais_query_dialog_active->Show();
1013 }
1014
1015 if (pRouteManagerDialog) pRouteManagerDialog->SetColorScheme();
1016
1017 if (g_pAISTargetList) g_pAISTargetList->SetColorScheme();
1018
1019 if (g_pObjectQueryDialog) g_pObjectQueryDialog->SetColorScheme();
1020
1021 ApplyGlobalColorSchemetoStatusBar();
1022
1023 UpdateAllToolbars(cs);
1024
1025 if (g_MainToolbar) {
1026 if (g_MainToolbar->GetColorScheme() != cs) {
1027 // capture the current toolbar collapse state
1028 bool btoolbarFull = g_bmasterToolbarFull;
1029
1030 g_MainToolbar->SetColorScheme(cs);
1031 // g_MainToolbar->DestroyToolBar();
1032 // CreateMasterToolbar();
1033
1034 if (!btoolbarFull) {
1035 // g_MainToolbar->Hide();
1036 RequestNewMasterToolbar();
1037 g_MainToolbar->SetColorScheme(cs);
1038 CollapseGlobalToolbar();
1039 // g_MainToolbar->Show();
1040 } else {
1041 RequestNewMasterToolbar();
1042 g_MainToolbar->SetColorScheme(cs);
1043 }
1044 }
1045 }
1046
1047 if (g_pi_manager) g_pi_manager->SetColorSchemeForAllPlugIns(cs);
1048}
1049
1050void MyFrame::ApplyGlobalColorSchemetoStatusBar() {
1051 if (m_pStatusBar != NULL) {
1052 m_pStatusBar->SetBackgroundColour(GetGlobalColor("UIBDR")); // UINFF
1053 m_pStatusBar->ClearBackground();
1054 }
1055}
1056
1057ChartCanvas *MyFrame::GetPrimaryCanvas() {
1058 if (g_canvasArray.GetCount() > 0)
1059 return g_canvasArray.Item(0);
1060 else
1061 return NULL;
1062}
1063void MyFrame::CancelAllMouseRoute() {
1064 // ..For each canvas...
1065 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
1066 ChartCanvas *cc = g_canvasArray.Item(i);
1067 if (cc) cc->CancelMouseRoute();
1068 }
1069}
1070
1071void MyFrame::NotifyChildrenResize() {}
1072
1073void MyFrame::CreateCanvasLayout(bool b_useStoredSize) {
1074 // Clear the cache, and thus close all charts to avoid memory leaks
1075 if (ChartData) ChartData->PurgeCache();
1076
1077 // If it exists, hide the console, in preparation for re-creation
1078 if (console) console->Show(false);
1079
1080 // Detach all canvases from AUI manager
1081 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
1082 ChartCanvas *cc = g_canvasArray[i];
1083 if (cc) {
1084 g_pauimgr->DetachPane(cc);
1085 }
1086 }
1087
1088 // Destroy any existing canvases, except for Primary canvas
1089 for (unsigned int i = 1; i < g_canvasArray.GetCount(); i++) {
1090 ChartCanvas *cc = g_canvasArray.Item(i);
1091 if (cc) {
1092 // pthumbwin = NULL; // TODO
1093 // cc->DestroyToolbar();
1094 cc->Destroy();
1095 }
1096 }
1097
1098 auto &config_array = ConfigMgr::Get().GetCanvasConfigArray();
1099
1100 // Canvas pointers in config array are now invalid
1101 for (unsigned int i = 1; i < config_array.GetCount(); i++) {
1102 config_array.Item(i)->canvas = NULL;
1103 }
1104
1105 // g_canvasArray.Clear();
1106
1107 // Clear the canvas Array, except for Primary canvas
1108 for (unsigned int i = 1; i < g_canvasArray.GetCount(); i++) {
1109 g_canvasArray.RemoveAt(i);
1110 }
1111
1112 ChartCanvas *cc = NULL;
1113 switch (g_canvasConfig) {
1114 default:
1115 case 0: // a single canvas
1116 if (!g_canvasArray.GetCount() || !config_array.Item(0)) {
1117 cc = new ChartCanvas(this, 0,
1118 m_data_monitor); // the chart display canvas
1119 g_canvasArray.Add(cc);
1120 } else {
1121 cc = g_canvasArray[0];
1122 }
1123
1124#ifdef ocpnUSE_GL
1125 // Verify that glCanvas is ready, if necessary
1126 if (g_bopengl) {
1127 if (!cc->GetglCanvas()) cc->SetupGlCanvas();
1128 cc->GetglCanvas()->Show();
1129 }
1130#endif
1131 config_array.Item(0)->canvas = cc;
1132
1134
1135 cc->ApplyCanvasConfig(config_array.Item(0));
1136
1137 // cc->SetToolbarPosition(wxPoint( g_maintoolbar_x,
1138 // g_maintoolbar_y ));
1139 cc->ConfigureChartBar();
1140 cc->SetColorScheme(global_color_scheme);
1141 cc->GetCompass()->SetScaleFactor(g_compass_scalefactor);
1142 cc->SetShowGPS(true);
1143
1144 g_pauimgr->AddPane(cc);
1145 g_pauimgr->GetPane(cc).Name("ChartCanvas");
1146 g_pauimgr->GetPane(cc).Fixed();
1147 g_pauimgr->GetPane(cc).CaptionVisible(false);
1148 g_pauimgr->GetPane(cc).CenterPane();
1149
1150 break;
1151
1152 case 1: { // two canvas, horizontal
1153 if (!g_canvasArray.GetCount() || !g_canvasArray[0]) {
1154 cc = new ChartCanvas(this, 0, m_data_monitor); // chart display canvas
1155 g_canvasArray.Add(cc);
1156 } else {
1157 cc = g_canvasArray[0];
1158 }
1159
1160 // Verify that glCanvas is ready, if not already built
1161#ifdef ocpnUSE_GL
1162 if (g_bopengl) {
1163 if (!cc->GetglCanvas()) cc->SetupGlCanvas();
1164 }
1165#endif
1166 config_array.Item(0)->canvas = cc;
1167
1168 cc->ApplyCanvasConfig(config_array.Item(0));
1169
1171 cc->ConfigureChartBar();
1172 cc->SetColorScheme(global_color_scheme);
1173 cc->GetCompass()->SetScaleFactor(g_compass_scalefactor);
1174 cc->SetShowGPS(false);
1175
1176 g_pauimgr->AddPane(cc);
1177 g_pauimgr->GetPane(cc).Name("ChartCanvas");
1178 g_pauimgr->GetPane(cc)
1179 .CaptionVisible(false)
1180 .PaneBorder(false)
1181 .CloseButton(false);
1182
1183 g_pauimgr->GetPane(cc).CenterPane();
1184
1185 cc = new ChartCanvas(this, 1, m_data_monitor); // chart display canvas
1186 g_canvasArray.Add(cc);
1187
1188 // There is not yet a config descriptor for canvas 2, so create one by
1189 // copy ctor from canvas {0}.
1190 if (config_array.GetCount() < 2) {
1191 canvasConfig *pcc = new canvasConfig(*config_array.Item(0));
1192 pcc->configIndex = 1;
1193
1194 // Arbitrarily establish the initial size of the new canvas to be
1195 // half the screen width.
1196 pcc->canvasSize = wxSize(GetClientSize().x / 2, GetClientSize().y);
1197 config_array.Add(pcc);
1198 }
1199
1200 config_array.Item(1)->canvas = cc;
1201
1202 cc->ApplyCanvasConfig(config_array.Item(1));
1203
1205 cc->ConfigureChartBar();
1206 cc->SetColorScheme(global_color_scheme);
1207 cc->SetShowGPS(true);
1208 cc->CreateMUIBar();
1209
1210 g_pauimgr->AddPane(cc);
1211 g_pauimgr->GetPane(cc).Name("ChartCanvas2");
1212 g_pauimgr->GetPane(cc)
1213 .CaptionVisible(false)
1214 .PaneBorder(false)
1215 .CloseButton(false);
1216 g_pauimgr->GetPane(cc).RightDockable(true);
1217 g_pauimgr->GetPane(cc).Right();
1218
1219#ifdef __ANDROID__
1220 config_array.Item(1)->canvasSize =
1221 wxSize(GetClientSize().x / 2, GetClientSize().y);
1222 g_pauimgr->GetPane(cc).BestSize(GetClientSize().x / 2, GetClientSize().y);
1223#endif
1224
1225 // If switching fromsingle canvas to 2-canvas mode dynamically,
1226 // try to use the latest persisted size for the new second canvas.
1227 if (b_useStoredSize) {
1228 int ccw = config_array.Item(1)->canvasSize.x;
1229 int cch = config_array.Item(1)->canvasSize.y;
1230
1231 // Check for undefined size, and set a nice default size if necessary.
1232 if (ccw < GetClientSize().x / 10) {
1233 ccw = GetClientSize().x / 2;
1234 cch = GetClientSize().y;
1235 }
1236
1237 g_pauimgr->GetPane(cc).BestSize(ccw, cch);
1238 cc->SetSize(ccw, cch);
1239 }
1240
1241 break;
1242 }
1243
1244 case 2: // two canvas, vertical
1245
1246 break;
1247 }
1248
1249 g_focusCanvas = GetPrimaryCanvas();
1250
1251 delete console;
1252 if (g_canvasArray.size() > 1)
1253 console = new APConsole(g_canvasArray.Item(1)); // the console
1254 else
1255 console = new APConsole(g_canvasArray.Item(0));
1256 console->SetColorScheme(global_color_scheme);
1257
1258 // Draw console if persisted route is active
1259 if (g_pRouteMan) {
1260 if (g_pRouteMan->IsAnyRouteActive()) {
1261 g_pRouteMan->GetDlgContext().show_with_fresh_fonts();
1262 }
1263 }
1264 PositionConsole();
1265}
1266
1267void MyFrame::RequestNewToolbars(bool bforcenew) {
1268 if (b_inCloseWindow) {
1269 return;
1270 }
1271
1272 BuildiENCToolbar(bforcenew);
1273 PositionIENCToolbar();
1274
1275#ifdef __ANDROID__
1276 DoChartUpdate();
1277#endif
1278}
1279
1280// Update inplace the various controls with bitmaps corresponding to the
1281// current color scheme
1282void MyFrame::UpdateAllToolbars(ColorScheme cs) {
1283 if (g_iENCToolbar) g_iENCToolbar->SetColorScheme(cs);
1284
1285 return;
1286}
1287
1288void MyFrame::SetAllToolbarScale() {
1289 g_toolbar_scalefactor = g_Platform->GetToolbarScaleFactor(g_GUIScaleFactor);
1290}
1291
1292void MyFrame::SetGPSCompassScale() {
1293 g_compass_scalefactor = g_Platform->GetCompassScaleFactor(g_GUIScaleFactor);
1294}
1295
1296ChartCanvas *MyFrame::GetCanvasUnderMouse() {
1297 wxPoint screenPoint = ::wxGetMousePosition();
1298 canvasConfig *cc;
1299
1300 switch (g_canvasConfig) {
1301 case 1:
1302 cc = ConfigMgr::Get().GetCanvasConfigArray().Item(0);
1303 if (cc) {
1304 ChartCanvas *canvas = cc->canvas;
1305 if (canvas->GetScreenRect().Contains(
1306 /*canvas->ScreenToClient*/ (screenPoint)))
1307 return canvas;
1308 }
1309 cc = ConfigMgr::Get().GetCanvasConfigArray().Item(1);
1310 if (cc) {
1311 ChartCanvas *canvas = cc->canvas;
1312 if (canvas->GetScreenRect().Contains(
1313 /*canvas->ScreenToClient*/ (screenPoint)))
1314 return canvas;
1315 }
1316 break;
1317
1318 default:
1319 cc = ConfigMgr::Get().GetCanvasConfigArray().Item(0);
1320 if (cc) {
1321 ChartCanvas *canvas = cc->canvas;
1322 if (canvas->GetScreenRect().Contains(
1323 canvas->ScreenToClient(screenPoint)))
1324 return canvas;
1325 }
1326 }
1327
1328 return NULL;
1329}
1330
1331int MyFrame::GetCanvasIndexUnderMouse() {
1332 wxPoint screenPoint = ::wxGetMousePosition();
1333 canvasConfig *cc;
1334
1335 switch (g_canvasConfig) {
1336 case 1:
1337 cc = ConfigMgr::Get().GetCanvasConfigArray().Item(0);
1338 if (cc) {
1339 ChartCanvas *canvas = cc->canvas;
1340 if (canvas->GetScreenRect().Contains(
1341 /*canvas->ScreenToClient*/ (screenPoint)))
1342 return 0;
1343 }
1344 cc = ConfigMgr::Get().GetCanvasConfigArray().Item(1);
1345 if (cc) {
1346 ChartCanvas *canvas = cc->canvas;
1347 if (canvas->GetScreenRect().Contains(
1348 /*canvas->ScreenToClient*/ (screenPoint)))
1349 return 1;
1350 }
1351 break;
1352
1353 default:
1354 cc = ConfigMgr::Get().GetCanvasConfigArray().Item(0);
1355 if (cc) {
1356 ChartCanvas *canvas = cc->canvas;
1357 if (canvas->GetScreenRect().Contains(
1358 canvas->ScreenToClient(screenPoint)))
1359 return 0;
1360 }
1361 }
1362
1363 return -1;
1364}
1365
1366bool MyFrame::DropMarker(bool atOwnShip) {
1367 double lat, lon;
1368 ChartCanvas *canvas = GetCanvasUnderMouse();
1369 if (atOwnShip) {
1370 lat = gLat;
1371 lon = gLon;
1372 } else {
1373 if (!canvas) return false;
1374
1375 lat = canvas->m_cursor_lat;
1376 lon = canvas->m_cursor_lon;
1377 }
1378
1379 RoutePoint *pWP =
1380 new RoutePoint(lat, lon, g_default_wp_icon, wxEmptyString, wxEmptyString);
1381 pWP->m_bIsolatedMark = true; // This is an isolated mark
1382 pSelect->AddSelectableRoutePoint(lat, lon, pWP);
1383 // pConfig->AddNewWayPoint(pWP, -1); // use auto next num
1384 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
1385
1386 if (canvas)
1387 if (!RoutePointGui(*pWP).IsVisibleSelectable(canvas))
1388 RoutePointGui(*pWP).ShowScaleWarningMessage(canvas);
1389 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
1390 pRouteManagerDialog->UpdateWptListCtrl();
1391 // undo->BeforeUndoableAction( Undo_CreateWaypoint, pWP, Undo_HasParent,
1392 // NULL ); undo->AfterUndoableAction( NULL );
1393
1394 InvalidateAllGL();
1395 RefreshAllCanvas(false);
1396
1397 return true;
1398}
1399
1400void MyFrame::SwitchKBFocus(ChartCanvas *pCanvas) {
1401 if (g_canvasConfig != 0) { // multi-canvas?
1402 canvasConfig *cc;
1403 int nTarget = -1;
1404 int nTargetGTK = -1;
1405 ChartCanvas *target;
1406 wxWindow *source = FindFocus();
1407 auto test = dynamic_cast<ChartCanvas *>(source);
1408 if (!test) return;
1409
1410 // On linux(GTK), the TAB key causes a loss of focus immediately
1411 // So the logic needs a switch
1412 switch (g_canvasConfig) {
1413 case 1:
1414 cc = ConfigMgr::Get().GetCanvasConfigArray().Item(0);
1415 if (cc) {
1416 ChartCanvas *canvas = cc->canvas;
1417 if (canvas && (canvas == test)) {
1418 nTarget = 1;
1419 nTargetGTK = 0;
1420 }
1421 }
1422 cc = ConfigMgr::Get().GetCanvasConfigArray().Item(1);
1423 if (cc) {
1424 ChartCanvas *canvas = cc->canvas;
1425 if (canvas && (canvas == test)) {
1426 nTarget = 0;
1427 nTargetGTK = 1;
1428 }
1429 }
1430
1431 if (nTarget >= 0) {
1432 // printf("sw %d\n", nTarget);
1433 int nfinalTarget = nTarget;
1434#ifdef __WXGTK__
1435 nfinalTarget = nTargetGTK;
1436#endif
1437 target = ConfigMgr::Get()
1438 .GetCanvasConfigArray()
1439 .Item(nfinalTarget)
1440 ->canvas;
1441 if (target) {
1442 target->SetFocus();
1443 target->Refresh(true);
1444 }
1445 }
1446 break;
1447
1448 default:
1449 break;
1450 }
1451 }
1452}
1453
1454void MyFrame::FastClose() {
1455 FrameTimer1.Stop();
1456 FrameTenHzTimer.Stop();
1457 quitflag++; // signal to the timer loop
1458 FrameTimer1.Start(1); // real quick now...
1459}
1460
1461// Intercept menu commands
1462void MyFrame::OnExit(wxCommandEvent &event) {
1463 quitflag++; // signal to the timer loop
1464}
1465
1466void MyFrame::OnCloseWindow(wxCloseEvent &event) {
1467 // It is possible that double clicks on application exit box could cause
1468 // re-entrance here Not good, and don't need it anyway, so simply return.
1469 if (b_inCloseWindow) {
1470 // wxLogMessage(_T("opencpn::MyFrame re-entering
1471 // OnCloseWindow"));
1472 return;
1473 }
1474
1475 // The Options dialog, and other deferred init items, are not fully
1476 // initialized. Best to just cancel the close request. This is probably only
1477 // reachable on slow hardware, or on Android life-cycle events...
1478#ifndef __ANDROID__
1479 if (!g_bDeferredInitDone) return;
1480#endif
1481
1482#ifndef __WXOSX__
1483 if (g_options) {
1484 delete g_options;
1485 g_options = NULL;
1486 g_pOptions = NULL;
1487 }
1488#endif
1489
1490 // If the multithread chart compressor engine is running, cancel the close
1491 // command
1493 return;
1494 }
1495
1496 if (bDBUpdateInProgress) return;
1497
1498 b_inCloseWindow = true;
1499
1500 ::wxSetCursor(wxCURSOR_WAIT);
1501
1502 // If we happen to have the measure tool open on Ctrl-Q quit
1503 // ..For each canvas...
1504 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
1505 ChartCanvas *cc = g_canvasArray.Item(i);
1506 if (cc && cc->IsMeasureActive()) {
1507 cc->CancelMeasureRoute();
1508 }
1509 }
1510
1511 // Give any requesting plugins a PreShutdownHook call
1512 SendPreShutdownHookToPlugins();
1513
1514 // We save perspective before closing to restore position next time
1515 // Pane is not closed so the child is not notified (OnPaneClose)
1516 if (g_pAISTargetList) {
1517 wxAuiPaneInfo &pane = g_pauimgr->GetPane(g_pAISTargetList);
1518 g_AisTargetList_perspective = g_pauimgr->SavePaneInfo(pane);
1519 g_pauimgr->DetachPane(g_pAISTargetList);
1520 }
1521
1522 // Make sure the saved perspective minimum canvas sizes are essentially
1523 // undefined
1524 // for(unsigned int i=0 ; i < g_canvasArray.GetCount() ; i++){
1525 // ChartCanvas *cc = g_canvasArray.Item(i);
1526 // if(cc)
1527 // g_pauimgr->GetPane( cc ).MinSize(10,10);
1528 // }
1529
1530 pConfig->SetPath("/AUI");
1531 pConfig->Write("AUIPerspective", g_pauimgr->SavePerspective());
1532
1533 g_bquiting = true;
1534
1535#ifdef ocpnUSE_GL
1536 // cancel compression jobs
1537 if (g_bopengl) {
1538 if (g_glTextureManager) {
1539 g_glTextureManager->PurgeJobList();
1540
1541 if (g_glTextureManager->GetRunningJobCount()) g_bcompression_wait = true;
1542 }
1543 }
1544#endif
1545
1546 SetCursor(wxCURSOR_WAIT);
1547
1548 RefreshAllCanvas(true);
1549
1550 // This yield is not necessary, since the Update() proceeds syncronously...
1551 // wxYield();
1552
1553 // Save the saved Screen Brightness
1554 RestoreScreenBrightness();
1555
1556 // Persist the toolbar locations
1557 // if (g_MainToolbar) {
1558 // g_MainToolbar->GetFrameRelativePosition(&g_maintoolbar_x,
1559 // &g_maintoolbar_y);
1560 // }
1561
1562#if 0
1563 if (g_iENCToolbar) {
1564 wxPoint locn = g_iENCToolbar->GetPosition();
1565 wxPoint tbp_incanvas = GetPrimaryCanvas()->ScreenToClient(locn);
1566 g_iENCToolbarPosY = tbp_incanvas.y;
1567 g_iENCToolbarPosX = tbp_incanvas.x;
1568 }
1569#endif
1570
1571 g_bframemax = IsMaximized();
1572
1573 FrameTimer1.Stop();
1574 FrameTenHzTimer.Stop();
1575
1576 FrameCOGTimer.Stop();
1577
1578 TrackOff();
1579
1580 /*
1581 Automatically drop an anchorage waypoint, if enabled
1582 On following conditions:
1583 1. In "Cruising" mode, meaning that speed has at some point exceeded 3.0 kts.
1584 2. Current speed is less than 0.5 kts.
1585 3. Opencpn has been up at least 30 minutes
1586 4. And, of course, opencpn is going down now.
1587 5. And if there is no anchor watch set on "anchor..." icon mark //
1588 pjotrc 2010.02.15
1589 */
1590 if (g_bAutoAnchorMark) {
1591 bool watching_anchor = false; // pjotrc 2010.02.15
1592 if (pAnchorWatchPoint1) // pjotrc 2010.02.15
1593 watching_anchor = (pAnchorWatchPoint1->GetIconName().StartsWith(
1594 "anchor")); // pjotrc 2010.02.15
1595 if (pAnchorWatchPoint2) // pjotrc 2010.02.15
1596 watching_anchor |= (pAnchorWatchPoint2->GetIconName().StartsWith(
1597 "anchor")); // pjotrc 2010.02.15
1598
1599 wxDateTime now = wxDateTime::Now();
1600 wxTimeSpan uptime = now.Subtract(g_start_time);
1601
1602 if (!watching_anchor && (g_bCruising) && (gSog < 0.5) &&
1603 (uptime.IsLongerThan(wxTimeSpan(0, 30, 0, 0)))) // pjotrc 2010.02.15
1604 {
1605 // First, if enabled, delete any single anchorage waypoints closer
1606 // than 0.25 NM from this point
1607 // This will prevent screen clutter and database congestion.
1608 if (g_declutter_anchorage) {
1609 for (RoutePoint *pr : *pWayPointMan->GetWaypointList()) {
1610 if (pr->GetName().StartsWith("Anchorage")) {
1611 double a = gLat - pr->m_lat;
1612 double b = gLon - pr->m_lon;
1613 double l = sqrt((a * a) + (b * b));
1614
1615 // caveat: this is accurate only on the Equator
1616 if ((l * 60. * 1852.) < (.25 * 1852.)) {
1617 // pConfig->DeleteWayPoint(pr);
1618 NavObj_dB::GetInstance().DeleteRoutePoint(pr);
1619 pSelect->DeleteSelectablePoint(pr, SELTYPE_ROUTEPOINT);
1620 delete pr;
1621 break;
1622 }
1623 }
1624 }
1625 }
1626
1627 wxString name = now.Format();
1628 name.Prepend(_("Anchorage created "));
1629 RoutePoint *pWP =
1630 new RoutePoint(gLat, gLon, "anchorage", name, wxEmptyString);
1631 pWP->m_bShowName = false;
1632 pWP->m_bIsolatedMark = true;
1633
1634 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
1635 }
1636 }
1637
1638 // Provisionally save all settings before deactivating plugins
1639 pConfig->UpdateSettings();
1640
1641 // Deactivate the PlugIns
1642 PluginLoader::GetInstance()->DeactivateAllPlugIns();
1643 wxLogMessage("opencpn::MyFrame exiting cleanly.");
1644
1645 quitflag++;
1646
1647 NavObj_dB::GetInstance().Close();
1648
1649 // Remove any leftover Routes and Waypoints from config file as they were
1650 // saved to navobj before
1651 pConfig->DeleteGroup("/Routes");
1652 pConfig->DeleteGroup("/Marks");
1653 pConfig->Flush();
1654
1655 if (g_pAboutDlg) g_pAboutDlg->Destroy();
1656 if (g_pAboutDlgLegacy) g_pAboutDlgLegacy->Destroy();
1657
1658 // Explicitely Close some children, especially the ones with event
1659 // handlers or that call GUI methods
1660
1661 if (g_pCM93OffsetDialog) {
1662 g_pCM93OffsetDialog->Destroy();
1663 g_pCM93OffsetDialog = NULL;
1664 }
1665
1666#ifndef __ANDROID__
1667 // if (g_MainToolbar) g_MainToolbar->Destroy();
1668 // g_MainToolbar = NULL;
1669#endif
1670
1671 if (g_iENCToolbar) {
1672 // wxPoint locn = g_iENCToolbar->GetPosition();
1673 // g_iENCToolbarPosY = locn.y;
1674 // g_iENCToolbarPosX = locn.x;
1675 // g_iENCToolbar->Destroy();
1676 }
1677
1678 if (g_pAISTargetList) {
1679 g_pAISTargetList->Disconnect_decoder();
1680 g_pAISTargetList->Destroy();
1681 }
1682
1683#ifndef __WXQT__
1684 SetStatusBar(NULL);
1685#endif
1686
1687 if (RouteManagerDialog::getInstanceFlag()) {
1688 if (pRouteManagerDialog) {
1689 pRouteManagerDialog->Destroy();
1690 pRouteManagerDialog = NULL;
1691 }
1692 }
1693
1694 // Clear the cache, and thus close all charts to avoid memory leaks
1695 if (ChartData) ChartData->PurgeCache();
1696
1697 // pthumbwin is a canvas child
1698 // pthumbwin = NULL;
1699
1700 // Finally ready to destroy the canvases
1701 g_focusCanvas = NULL;
1702
1703 // ..For each canvas...
1704 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
1705 ChartCanvas *cc = g_canvasArray.Item(i);
1706 if (cc) cc->Destroy();
1707 }
1708
1709 g_canvasArray.Clear();
1710
1711 g_pauimgr->UnInit();
1712 delete g_pauimgr;
1713 g_pauimgr = NULL;
1714
1715 // Unload the PlugIns
1716 // Note that we are waiting until after the canvas is destroyed,
1717 // since some PlugIns may have created children of canvas.
1718 // Such a PlugIn must stay intact for the canvas dtor to call
1719 // DestoryChildren()
1720
1721 if (ChartData) ChartData->PurgeCachePlugins();
1722
1723 PluginLoader::GetInstance()->UnLoadAllPlugIns();
1724
1725 if (g_pi_manager) {
1726 delete g_pi_manager;
1727 g_pi_manager = NULL;
1728 }
1729
1730 MyApp &app = wxGetApp();
1731 app.m_comm_bridge.SaveConfig();
1732
1733 delete pConfig; // All done
1734 pConfig = NULL;
1735 InitBaseConfig(0);
1736
1737 if (g_pAIS) {
1738 delete g_pAIS;
1739 g_pAIS = NULL;
1740 }
1741
1742 if (g_pAISGUI) {
1743 delete g_pAISGUI;
1744 g_pAISGUI = NULL;
1745 }
1746
1747 delete g_pMUX;
1748 g_pMUX = NULL;
1749
1750 // Close and delete all comm drivers
1751 auto &registry = CommDriverRegistry::GetInstance();
1752 registry.CloseAllDrivers();
1753
1754 // Clear some global arrays, lists, and hash maps...
1755 for (auto *cp : TheConnectionParams()) {
1756 delete cp;
1757 }
1758
1759 if (pLayerList) {
1760 while (pLayerList->size()) delete *pLayerList->begin();
1761 // automatically removes the layer from list, see Layer dtor
1762 }
1763
1764 ReleaseApiListeners();
1765
1766 g_MainToolbar = NULL;
1767 g_bTempShowMenuBar = false;
1768
1769#define THREAD_WAIT_SECONDS 5
1770#ifdef ocpnUSE_GL
1771 // The last thing we do is finish the compression threads.
1772 // This way the main window is already invisible and to the user
1773 // it appears to have finished rather than hanging for several seconds
1774 // while the compression threads exit
1775 if (g_bopengl && g_glTextureManager &&
1776 g_glTextureManager->GetRunningJobCount()) {
1777 g_glTextureManager->ClearAllRasterTextures();
1778
1779 wxLogMessage("Starting compressor pool drain");
1780 wxDateTime now = wxDateTime::Now();
1781 time_t stall = now.GetTicks();
1782 time_t end = stall + THREAD_WAIT_SECONDS;
1783
1784 int n_comploop = 0;
1785 while (stall < end) {
1786 wxDateTime later = wxDateTime::Now();
1787 stall = later.GetTicks();
1788
1789 wxString msg;
1790 msg.Printf("Time: %d Job Count: %d", n_comploop,
1791 g_glTextureManager->GetRunningJobCount());
1792 wxLogMessage(msg);
1793 if (!g_glTextureManager->GetRunningJobCount()) break;
1794 wxYield();
1795 wxSleep(1);
1796 }
1797
1798 wxString fmsg;
1799 fmsg.Printf("Finished compressor pool drain..Time: %d Job Count: %d",
1800 n_comploop, g_glTextureManager->GetRunningJobCount());
1801 wxLogMessage(fmsg);
1802 }
1803 delete g_glTextureManager;
1804#endif
1805 uninitIXNetSystem();
1806 this->Destroy();
1807 gFrame = NULL;
1808
1809 wxLogMessage("gFrame destroyed.");
1810
1811#ifdef __ANDROID__
1812#ifndef USE_ANDROID_GLES2
1813 qDebug() << "Calling OnExit()";
1814 wxTheApp->OnExit();
1815#endif
1816#endif
1817 wxTheApp->ExitMainLoop();
1818}
1819
1820void MyFrame::OnMove(wxMoveEvent &event) {
1821 auto idx = wxDisplay::GetFromWindow(this);
1822 if (idx != wxNOT_FOUND && g_current_monitor != static_cast<size_t>(idx) &&
1823 static_cast<size_t>(idx) < g_monitor_info.size()) {
1824 g_current_monitor = idx;
1825#ifdef __WXOSX__
1826 // On retina displays there is a difference between the physical size of the
1827 // OpenGL canvas and the DIP This is not observed anywhere else so far, so
1828 // g_current_monitor_dip_px_ratio cna be kept 1.0 everywhere else
1829 if (g_bopengl) {
1831 g_monitor_info[idx].width_px / g_monitor_info[idx].width;
1832 }
1833#endif
1834 DEBUG_LOG << "Moved to " << idx
1835#if wxCHECK_VERSION(3, 1, 6)
1836 << " PPI: " << wxDisplay(idx).GetPPI().GetX() << "x"
1837 << wxDisplay(idx).GetPPI().GetY()
1838 << " SF wxDisplay: " << wxDisplay(idx).GetScaleFactor()
1839#endif
1840 << " Size wxDisplay: " << wxDisplay(idx).GetGeometry().GetWidth()
1841 << "x" << wxDisplay(idx).GetGeometry().GetHeight()
1842 << " MM wxDisplay: " << wxGetDisplaySizeMM().GetX() << "x"
1843 << wxGetDisplaySizeMM().GetY()
1844 << " Name wxDisplay: " << wxDisplay(idx).GetName().c_str()
1845 << " Real: " << g_monitor_info[idx].width_mm << "x"
1846 << g_monitor_info[idx].height_mm << "mm "
1847 << g_monitor_info[idx].width_mm << "x"
1848 << g_monitor_info[idx].height_mm << "mm "
1849 << g_monitor_info[idx].width << "x" << g_monitor_info[idx].height
1850 << "DIP " << g_monitor_info[idx].width_px << "x"
1851 << g_monitor_info[idx].height_px << "px"
1852 << g_monitor_info[idx].scale << "%";
1853 if (g_config_display_size_manual) {
1854 if (g_config_display_size_mm.size() > static_cast<size_t>(idx)) {
1856 } // Do nothing if the user did not set any value for this monitor
1857 } else {
1858 g_display_size_mm = g_monitor_info[idx].width_mm;
1859 }
1860 }
1861 // ..For each canvas...
1862 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
1863 ChartCanvas *cc = g_canvasArray.Item(i);
1864 if (cc) {
1865 cc->SetMUIBarPosition();
1867 }
1868 }
1869
1870#ifdef __WXOSX__
1871 SendSizeEvent();
1872#endif
1873
1874 UpdateGPSCompassStatusBoxes();
1875
1876 if (console && console->IsShown()) PositionConsole();
1877
1878 // If global toolbar is shown, reposition it...
1879 // if (g_MainToolbar) {
1880 // g_MainToolbar->RestoreRelativePosition(g_maintoolbar_x, g_maintoolbar_y);
1881 // g_MainToolbar->Realize();
1882 //}
1883
1884 PositionIENCToolbar();
1885
1886 // Somehow, this method does not work right on Windows....
1887 // g_nframewin_posx = event.GetPosition().x;
1888 // g_nframewin_posy = event.GetPosition().y;
1889
1890 g_nframewin_posx = GetPosition().x;
1891 g_nframewin_posy = GetPosition().y;
1892}
1893
1894void MyFrame::ProcessCanvasResize() {
1895 UpdateGPSCompassStatusBoxes(true);
1896
1897 if (console && console->IsShown()) PositionConsole();
1898
1899 PositionIENCToolbar();
1900
1901#ifndef __ANDROID__
1902 TriggerRecaptureTimer();
1903#endif
1904}
1905
1906void MyFrame::TriggerRecaptureTimer() {
1907 m_recaptureTimer.Start(
1908 1000, wxTIMER_ONE_SHOT); // One second seems enough, on average
1909}
1910
1911void MyFrame::OnRecaptureTimer(wxTimerEvent &event) { /*Raise();*/ }
1912
1913void MyFrame::SetCanvasSizes(wxSize frameSize) {
1914 if (!g_canvasArray.GetCount()) return;
1915
1916#if 0
1917 int cccw = frameSize.x;
1918 int ccch = frameSize.y;
1919#endif
1920
1921 // .. for each canvas...
1922 switch (g_canvasConfig) {
1923 default:
1924 case 0:
1925#if 0
1926 cc = g_canvasArray.Item(0);
1927 if( cc ) {
1928 cc->GetSize( &cur_width, &cur_height );
1929 if( ( cur_width != cccw ) || ( cur_height != ccch ) ) {
1930 if( g_pauimgr->GetPane( cc ).IsOk() )
1931 g_pauimgr->GetPane( cc ).BestSize( cccw, ccch );
1932 else
1933 cc->SetSize( 0, 0, cccw, ccch );
1934 }
1935 }
1936#endif
1937 break;
1938
1939 case 1:
1940#if 0
1941 cc = g_canvasArray.Item(1);
1942 if( cc ) {
1943 int ccw = g_canvasConfigArray.Item(1)->canvasSize.x;
1944 int cch = g_canvasConfigArray.Item(1)->canvasSize.y;
1945
1946 ccw = wxMin(ccw, cccw * 8 / 10);
1947 ccw = wxMax(ccw, cccw * 2 / 10);
1948 if(cccw < 100)
1949 ccw = 20;
1950
1951 g_canvasConfigArray.Item(1)->canvasSize = wxSize(ccw, cch);
1952// g_pauimgr->GetPane(cc).MinSize(cccw * 2 / 10, ccch);
1953
1954#if 1 // ndef __WXMSW__
1955 // wxAUI hack: This is needed to explicietly set a docked pane size
1956 // Set MinSize to desired value, then call wxAuiPaneInfo::Fixed() to
1957 // apply it
1958 g_pauimgr->GetPane(cc).MinSize(ccw, cch);
1959 g_pauimgr->GetPane(cc).Fixed();
1960 g_pauimgr->Update();
1961
1962 //now make resizable again
1963 g_pauimgr->GetPane(cc).Resizable();
1965 //g_pauimgr->Update(); //Deferred
1966 //g_pauimgr->GetPane( cc ).BestSize( ccw, cch );
1967#endif
1968 }
1969#endif
1970
1971 break;
1972 }
1973}
1974
1975void MyFrame::OnIconize(wxIconizeEvent &event) {
1976#if 0
1977 if (g_MainToolbar) {
1978 g_MainToolbar->Show(!event.IsIconized());
1979 }
1980 if (g_iENCToolbar) {
1981 g_iENCToolbar->Show(!event.IsIconized());
1982 }
1983
1984 // .. for each canvas...
1985 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
1986 ChartCanvas *cc = g_canvasArray.Item(i);
1987 if (cc && cc->GetMUIBar()) {
1988 if (cc->GetMUIBar()->GetCanvasOptions()) {
1989 if (cc->GetMUIBar()->GetCanvasOptions()->IsShown()) {
1990 cc->GetMUIBar()->PushCanvasOptions(); // hide it
1991 }
1992 }
1993 }
1994 }
1995
1996#endif
1997}
1998
1999void MyFrame::OnSize(wxSizeEvent &event) { ODoSetSize(); }
2000
2001void MyFrame::ODoSetSize() {
2002 int x, y;
2003 GetClientSize(&x, &y);
2004 // Resize the children
2005
2006 if (m_pStatusBar != NULL) {
2007 m_StatusBarFieldCount = g_Platform->GetStatusBarFieldCount();
2008 int currentCount = m_pStatusBar->GetFieldsCount();
2009 if (currentCount != m_StatusBarFieldCount) {
2010 if ((currentCount > 0) && (currentCount < 7)) {
2011 // reset the widths very small to avoid auto-resizing of the frame
2012 // The sizes will be reset later in this method
2013 int widths[] = {2, 2, 2, 2, 2, 2};
2014 m_pStatusBar->SetStatusWidths(currentCount, widths);
2015 }
2016
2017 m_pStatusBar->SetFieldsCount(m_StatusBarFieldCount);
2018 }
2019
2020 if (m_StatusBarFieldCount) {
2021 // If the status bar layout is "complex", meaning more than two columns,
2022 // then use custom crafted relative widths for the fields.
2023 // Otherwise, just split the frame client width into equal spaces
2024
2025 if (m_StatusBarFieldCount > 2) {
2026 int widths[] = {-6, -5, -5, -6, -4};
2027 m_pStatusBar->SetStatusWidths(m_StatusBarFieldCount, widths);
2028 } else if (m_StatusBarFieldCount == 2) {
2029 int cwidth = x * 90 / 100;
2030 int widths[] = {100, 100};
2031 widths[0] = cwidth * 6.4 / 10.0;
2032 widths[1] = cwidth * 3.6 / 10.0;
2033 m_pStatusBar->SetStatusWidths(m_StatusBarFieldCount, widths);
2034 } else {
2035 int widths[] = {100, 100};
2036 widths[0] = x * 90 / 100;
2037 m_pStatusBar->SetStatusWidths(m_StatusBarFieldCount, widths);
2038 }
2039
2040 int styles[] = {wxSB_FLAT, wxSB_FLAT, wxSB_FLAT,
2041 wxSB_FLAT, wxSB_FLAT, wxSB_FLAT};
2042 m_pStatusBar->SetStatusStyles(m_StatusBarFieldCount, styles);
2043
2044 wxString sogcog("SOG --- " + getUsrSpeedUnit() + +" " +
2045 " COG ---\u00B0");
2046 m_pStatusBar->SetStatusText(sogcog, STAT_FIELD_SOGCOG);
2047 }
2048 }
2049
2050 if (m_pStatusBar) {
2051 // Maybe resize the font so the text fits in the boxes
2052
2053 wxRect stat_box;
2054 m_pStatusBar->GetFieldRect(0, stat_box);
2055 // maximum size is 1/28 of the box width, or the box height - whicever is
2056 // less
2057 int max_font_size = wxMin((stat_box.width / 28), (stat_box.height));
2058
2059 wxFont sys_font = *wxNORMAL_FONT;
2060 int try_font_size = sys_font.GetPointSize();
2061
2062#ifdef __WXOSX__
2063 int min_font_size = 10; // much less than 10pt is unreadably small on OS X
2064 try_font_size += 1; // default to 1pt larger than system UI font
2065#else
2066 int min_font_size =
2067 7; // on Win/Linux the text does not shrink quite so fast
2068 try_font_size += 2; // default to 2pt larger than system UI font
2069#endif
2070
2071 // get the user's preferred font, or if none set then the system default
2072 // with the size overridden
2073 wxFont *statusBarFont =
2074 FontMgr::Get().GetFont(_("StatusBar"), try_font_size);
2075 int font_size = statusBarFont->GetPointSize();
2076
2077 font_size = wxMin(font_size,
2078 max_font_size); // maximum to fit in the statusbar boxes
2079 font_size =
2080 wxMax(font_size, min_font_size); // minimum to stop it being unreadable
2081
2082#ifdef __ANDROID__
2083 font_size = statusBarFont->GetPointSize();
2084#endif
2085
2086 // Accomodate HDPI displays
2087 font_size /= OCPN_GetDisplayContentScaleFactor();
2088
2089 wxFont *pstat_font = FontMgr::Get().FindOrCreateFont(
2090 font_size, statusBarFont->GetFamily(), statusBarFont->GetStyle(),
2091 statusBarFont->GetWeight(), false, statusBarFont->GetFaceName());
2092
2093 int min_height = stat_box.height;
2094
2095 m_pStatusBar->SetFont(*pstat_font);
2096 m_pStatusBar->SetForegroundColour(
2097 FontMgr::Get().GetFontColor(_("StatusBar")));
2098#ifdef __ANDROID__
2099 min_height = (pstat_font->GetPointSize() * getAndroidDisplayDensity()) + 10;
2100 min_height =
2101 (min_height >> 1) * 2; // force even number, makes GLCanvas happier...
2102 m_pStatusBar->SetMinHeight(min_height);
2103// qDebug() <<"StatusBar min height:" << min_height << "StatusBar font
2104// points:" << pstat_font->GetPointSize();
2105#endif
2106 // wxString msg;
2107 // msg.Printf(_T("StatusBar min height: %d StatusBar font points:
2108 // %d"), min_height, pstat_font->GetPointSize()); wxLogMessage(msg);
2109 }
2110
2111 SetCanvasSizes(GetClientSize());
2112
2113 UpdateGPSCompassStatusBoxes(true);
2114
2115 if (console) PositionConsole();
2116
2117 // .. for each canvas...
2118 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
2119 ChartCanvas *cc = g_canvasArray.Item(i);
2120 if (cc) cc->FormatPianoKeys();
2121 }
2122
2123 // If global toolbar is shown, resize it...
2124 if (g_MainToolbar) {
2125 wxSize szBefore = g_MainToolbar->GetToolbarSize();
2126 g_MainToolbar->SetGeometry(GetPrimaryCanvas()->GetCompass()->IsShown(),
2127 GetPrimaryCanvas()->GetCompass()->GetRect());
2128 g_MainToolbar->Realize();
2129
2130 if (szBefore != g_MainToolbar->GetToolbarSize())
2131 g_MainToolbar->RefreshToolbar();
2132 }
2133
2134 // Update the stored window size
2135 GetSize(&x, &y);
2136 g_nframewin_x = x;
2137 g_nframewin_y = y;
2138
2139 // Inform the PlugIns
2140 if (g_pi_manager) g_pi_manager->SendResizeEventToAllPlugIns(x, y);
2141
2142 // Force redraw if in lookahead mode
2143 // TODO is this all right?
2144 // if( g_bLookAhead ) {
2145 // DoCOGSet();
2146 // DoChartUpdate();
2147 // }
2148
2149 // FIXME (dave) Thumbwins are gone...
2150 // if (pthumbwin) pthumbwin->SetMaxSize(GetClientSize());
2151
2152 // Reset the options dialog size logic
2153 options_lastWindowSize = wxSize(0, 0);
2154 options_lastWindowPos = wxPoint(0, 0);
2155
2156#ifdef __ANDROID__
2157 // If the options dialog is displayed, this will have the effect of
2158 // raising the dialog above the main and canvas-GUI toolbars.
2159 // If the dialog is not shown, no harm done
2160
2161 if (!b_inCloseWindow) {
2162 if (g_options) g_options->Raise();
2163
2164 resizeAndroidPersistents();
2165 }
2166
2167#endif
2168 if (GetPrimaryCanvas() && GetPrimaryCanvas()->GetNotificationsList()) {
2169 GetPrimaryCanvas()->GetNotificationsList()->RecalculateSize();
2170 }
2171
2172 if (g_pauimgr) g_pauimgr->Update();
2173}
2174
2175void MyFrame::PositionConsole() {
2176#if defined(__WXMSW__) || defined(__WXMAC__)
2177 if (NULL == GetPrimaryCanvas()) return;
2178 // Reposition console based on its size and chartcanvas size
2179 int ccx, ccy, ccsx, ccsy, consx, consy;
2180 ChartCanvas *consoleHost = GetPrimaryCanvas();
2181 if (g_canvasConfig > 0) consoleHost = g_canvasArray[1];
2182
2183 if (consoleHost) {
2184 consoleHost->GetSize(&ccsx, &ccsy);
2185 consoleHost->GetPosition(&ccx, &ccy);
2186 } else {
2187 GetPrimaryCanvas()->GetSize(&ccsx, &ccsy);
2188 GetPrimaryCanvas()->GetPosition(&ccx, &ccy);
2189 consoleHost = GetPrimaryCanvas();
2190 }
2191
2192 int yOffset = 60;
2193 if (consoleHost) {
2194 if (consoleHost->GetCompass()) {
2195 wxRect compass_rect = consoleHost->GetCompass()->GetRect();
2196 // Compass is normal upper right position.
2197 if (compass_rect.y < 100)
2198 yOffset = compass_rect.y + compass_rect.height + 45;
2199 }
2200 }
2201
2202 wxSize csz = console->GetSize();
2203 consx = csz.x;
2204 consy = csz.y;
2205
2206 wxPoint screen_pos =
2207 ClientToScreen(wxPoint(ccx + ccsx - consx - 2, ccy + yOffset));
2208 console->Move(screen_pos);
2209#else
2210 if (NULL == GetPrimaryCanvas()) return;
2211 // Reposition console based on its size and chartcanvas size
2212 int ccx, ccy, ccsx, ccsy, consx, consy;
2213 ChartCanvas *consoleHost = GetPrimaryCanvas();
2214 if (g_canvasConfig > 0) consoleHost = g_canvasArray[1];
2215
2216 if (consoleHost) {
2217 consoleHost->GetSize(&ccsx, &ccsy);
2218 consoleHost->GetPosition(&ccx, &ccy);
2219 } else {
2220 GetPrimaryCanvas()->GetSize(&ccsx, &ccsy);
2221 GetPrimaryCanvas()->GetPosition(&ccx, &ccy);
2222 consoleHost = GetPrimaryCanvas();
2223 }
2224
2225 int yTopOffset = 60;
2226 int yBottomOffset = 0;
2227 if (consoleHost) {
2228 if (consoleHost->GetCompass()) {
2229 wxRect compass_rect = consoleHost->GetCompass()->GetRect();
2230 // Compass is normal upper right position.
2231 if (compass_rect.y < 100)
2232 yTopOffset = compass_rect.y + compass_rect.height;
2233 }
2234 if (consoleHost->GetMUIBar()) {
2235 wxRect mui_rect = consoleHost->GetMUIBarRect();
2236 yBottomOffset = ccsy - mui_rect.y;
2237 }
2238 }
2239
2240 wxSize csz = console->GetSize();
2241 consx = csz.x;
2242 consy = csz.y;
2243 int yAvail = ccsy - (yTopOffset + yBottomOffset);
2244 int yFinal = 30;
2245 if (consy < yAvail) {
2246 yFinal = (yAvail - consy) / 2;
2247 yFinal += yTopOffset;
2248 } else if (console->GetCDI()->IsShown()) {
2249 int cdi_height = console->GetCDI()->GetSize().y;
2250 int consy_no_cdi = consy - cdi_height;
2251 yFinal = (yAvail - consy_no_cdi) / 2;
2252 yFinal += yTopOffset;
2253 console->ToggleShowHighway();
2254 }
2255
2256 wxPoint in_canvas_pos = wxPoint(ccsx - consx - 2, yFinal);
2257 console->Move(in_canvas_pos);
2258#endif
2259}
2260
2261void MyFrame::UpdateAllFonts() {
2262 if (console) {
2263 console->UpdateFonts();
2264 // Reposition console
2265 PositionConsole();
2266 }
2267
2268 // Close and destroy any persistent dialogs, so that new fonts will be
2269 // utilized
2270 DestroyPersistentDialogs();
2271
2272 if (pWayPointMan) pWayPointMan->ClearRoutePointFonts();
2273
2274 RefreshAllCanvas();
2275}
2276
2277void MyFrame::DestroyPersistentDialogs() {
2278 if (g_pais_query_dialog_active) {
2279 g_pais_query_dialog_active->Hide();
2280 g_pais_query_dialog_active->Destroy();
2281 g_pais_query_dialog_active = NULL;
2282 }
2283
2284 if (RoutePropDlgImpl::getInstanceFlag() && pRoutePropDialog) {
2285 pRoutePropDialog->Hide();
2286 pRoutePropDialog->Destroy();
2287 pRoutePropDialog = NULL;
2288 }
2289
2290 if (TrackPropDlg::getInstanceFlag() && pTrackPropDialog) {
2291 pTrackPropDialog->Hide();
2292 pTrackPropDialog->Destroy();
2293 pTrackPropDialog = NULL;
2294 }
2295
2296 if (g_pMarkInfoDialog) {
2297 g_pMarkInfoDialog->Hide();
2298 g_pMarkInfoDialog->Destroy();
2299 g_pMarkInfoDialog = NULL;
2300 }
2301
2303 g_pObjectQueryDialog->Hide();
2304 g_pObjectQueryDialog->Destroy();
2305 g_pObjectQueryDialog = NULL;
2306 }
2307}
2308
2309void MyFrame::RefreshGroupIndices() {
2310 // ..For each canvas...
2311 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
2312 ChartCanvas *cc = g_canvasArray.Item(i);
2313 if (cc) cc->canvasRefreshGroupIndex();
2314 }
2315}
2316
2317void MyFrame::OnToolLeftClick(wxCommandEvent &event) {
2318 if (g_MainToolbar) g_MainToolbar->HideTooltip();
2319
2320 switch (event.GetId()) {
2321 case ID_MENU_SCALE_OUT:
2322 DoStackDelta(GetPrimaryCanvas(), 1);
2323 DoChartUpdate();
2324 break;
2325
2326 case ID_MENU_SCALE_IN:
2327 DoStackDelta(GetPrimaryCanvas(), -1);
2328 DoChartUpdate();
2329 break;
2330
2331 case ID_MENU_ZOOM_IN: {
2332 if (GetFocusCanvas()) {
2333 GetFocusCanvas()->ZoomCanvas(g_plus_minus_zoom_factor, false);
2334 }
2335 break;
2336 }
2337
2338 case ID_MENU_ZOOM_OUT: {
2339 if (GetFocusCanvas()) {
2340 GetFocusCanvas()->ZoomCanvas(1.0 / g_plus_minus_zoom_factor, false);
2341 }
2342 break;
2343 }
2344
2345 case ID_MENU_ROUTE_NEW: {
2346 if (GetFocusCanvas()) {
2347 if (0 == GetFocusCanvas()->m_routeState) {
2348 GetFocusCanvas()->StartRoute();
2349 } else {
2350 GetFocusCanvas()->FinishRoute();
2351 }
2352 }
2353 break;
2354 }
2355
2356 case ID_MENU_TOOL_MEASURE: {
2357 GetPrimaryCanvas()->StartMeasureRoute();
2358 break;
2359 }
2360
2361 case ID_MENU_TOOL_NMEA_DBG_LOG:
2362 m_data_monitor->Show();
2363 m_data_monitor->Raise();
2364 break;
2365
2366 case ID_MENU_TOOL_IO_MONITOR:
2367 m_data_monitor->Show();
2368 break;
2369
2370 case ID_MENU_MARK_BOAT: {
2371 DropMarker(true);
2372 break;
2373 }
2374
2375 case ID_MENU_MARK_CURSOR: {
2376 DropMarker(false);
2377 break;
2378 }
2379
2380 case ID_MENU_NAV_FOLLOW: {
2381 if (gFrame->GetPrimaryCanvas())
2382 gFrame->GetPrimaryCanvas()->TogglebFollow();
2383 break;
2384 }
2385
2386 case ID_MENU_CHART_OUTLINES: {
2387 ToggleChartOutlines(GetFocusCanvas());
2388 break;
2389 }
2390
2391 case ID_MENU_CHART_QUILTING: {
2392 ToggleQuiltMode(GetFocusCanvas());
2393 break;
2394 }
2395
2396 case ID_MENU_UI_CHARTBAR: {
2397 ToggleChartBar(GetFocusCanvas());
2398 break;
2399 }
2400
2401 case ID_MENU_ENC_TEXT:
2402 case ID_ENC_TEXT: {
2403 ToggleENCText(GetFocusCanvas());
2404 break;
2405 }
2406 case ID_MENU_ENC_LIGHTS: {
2407 ToggleLights(GetFocusCanvas());
2408 break;
2409 }
2410 case ID_MENU_ENC_SOUNDINGS: {
2411 ToggleSoundings(GetFocusCanvas());
2412 break;
2413 }
2414 case ID_MENU_ENC_ANCHOR: {
2415 ToggleAnchor(GetFocusCanvas());
2416 break;
2417 }
2418 case ID_MENU_ENC_DATA_QUALITY: {
2419 ToggleDataQuality(GetFocusCanvas());
2420 break;
2421 }
2422 case ID_MENU_SHOW_NAVOBJECTS: {
2423 ToggleNavobjects(GetFocusCanvas());
2424 break;
2425 }
2426
2427 case ID_MENU_AIS_TARGETS: {
2428 ToggleAISDisplay(GetFocusCanvas());
2429 break;
2430 }
2431 case ID_MENU_AIS_MOORED_TARGETS: {
2432 g_bHideMoored = !g_bHideMoored;
2433 break;
2434 }
2435 case ID_MENU_AIS_SCALED_TARGETS: {
2436 ToggleAISMinimizeTargets(GetFocusCanvas());
2437 break;
2438 }
2439
2440 case ID_MENU_AIS_TARGETLIST: {
2441 if (GetPrimaryCanvas()) GetPrimaryCanvas()->ShowAISTargetList();
2442 break;
2443 }
2444
2445 case ID_MENU_AIS_TRACKS: {
2446 g_bAISShowTracks = !g_bAISShowTracks;
2447 SetMenubarItemState(ID_MENU_AIS_TRACKS, g_bAISShowTracks);
2448 break;
2449 }
2450
2451 case ID_MENU_AIS_CPADIALOG: {
2452 g_bAIS_CPA_Alert = !g_bAIS_CPA_Alert;
2453 SetMenubarItemState(ID_MENU_AIS_CPADIALOG, g_bAIS_CPA_Alert);
2454 m_pMenuBar->Enable(ID_MENU_AIS_CPASOUND, g_bAIS_CPA_Alert);
2455 if (g_bAIS_CPA_Alert) {
2456 SetMenubarItemState(ID_MENU_AIS_CPASOUND, g_bAIS_CPA_Alert_Audio);
2457 }
2458 break;
2459 }
2460
2461 case ID_MENU_AIS_CPASOUND: {
2462 g_bAIS_CPA_Alert_Audio = !g_bAIS_CPA_Alert_Audio;
2463 SetMenubarItemState(ID_MENU_AIS_CPASOUND, g_bAIS_CPA_Alert_Audio);
2464 break;
2465 }
2466
2467 case ID_MENU_AIS_CPAWARNING: {
2468 if (GetPrimaryCanvas()) GetPrimaryCanvas()->ToggleCPAWarn();
2469 SetMenubarItemState(ID_MENU_AIS_CPAWARNING, g_bCPAWarn);
2470 break;
2471 }
2472
2473 case wxID_PREFERENCES:
2474 case ID_SETTINGS: {
2475 g_MainToolbar->HideTooltip();
2476 DoSettings();
2477 break;
2478 }
2479
2480 case ID_SETTINGS_NEW: {
2481 DoSettingsNew();
2482 break;
2483 }
2484
2485 case ID_SETTINGS_DELETE: {
2486 delete g_options;
2487 g_options = nullptr;
2488 g_pOptions = nullptr;
2489 break;
2490 }
2491
2492 case ID_RELOAD_CHARTS: {
2493 ReloadAllVP();
2494 break;
2495 }
2496
2497 case ID_MENU_SETTINGS_BASIC: {
2498#ifdef __ANDROID__
2500 androidDisableFullScreen();
2501 g_MainToolbar->HideTooltip();
2502 DoAndroidPreferences();
2503#else
2504 DoSettings();
2505#endif
2506 break;
2507 }
2508
2509 case ID_MENU_UI_FULLSCREEN: {
2510 ToggleFullScreen();
2511 break;
2512 }
2513
2514 case ID_MENU_SHOW_CURRENTS: {
2515 GetFocusCanvas()->ShowCurrents(!GetFocusCanvas()->GetbShowCurrent());
2516 GetFocusCanvas()->ReloadVP();
2517 GetFocusCanvas()->Refresh(false);
2518 break;
2519 }
2520
2521 case ID_MENU_SHOW_TIDES: {
2522 GetFocusCanvas()->ShowTides(!GetFocusCanvas()->GetbShowTide());
2523 GetFocusCanvas()->ReloadVP();
2524 GetFocusCanvas()->Refresh(false);
2525 break;
2526 }
2527
2528 case wxID_ABOUT:
2529 case ID_ABOUT: {
2530 DoHelpDialog();
2531 break;
2532 }
2533
2534 case wxID_HELP: {
2535 LaunchLocalHelp();
2536 break;
2537 }
2538
2539 case ID_PRINT: {
2540 DoPrint();
2541 break;
2542 }
2543
2544 case ID_MENU_UI_COLSCHEME:
2545 case ID_COLSCHEME: {
2546 ToggleColorScheme();
2547 break;
2548 }
2549
2550 case ID_TBEXIT: {
2551 Close();
2552 break;
2553 }
2554
2555 case ID_MENU_OQUIT: {
2556 Close();
2557 break;
2558 }
2559
2560 case ID_MENU_ROUTE_MANAGER:
2561 case ID_ROUTEMANAGER: {
2562 pRouteManagerDialog = RouteManagerDialog::getInstance(
2563 this); // There is one global instance of the Dialog
2564
2565 if (pRouteManagerDialog->IsShown())
2566 pRouteManagerDialog->Hide();
2567 else {
2568 pRouteManagerDialog->UpdateRouteListCtrl();
2569 pRouteManagerDialog->UpdateTrkListCtrl();
2570 pRouteManagerDialog->UpdateWptListCtrl();
2571 pRouteManagerDialog->UpdateLayListCtrl();
2572
2573 pRouteManagerDialog->Show();
2574
2575 // Required if RMDialog is not STAY_ON_TOP
2576#ifdef __WXOSX__
2577 pRouteManagerDialog->Centre();
2578 pRouteManagerDialog->Raise();
2579#endif
2580 }
2581 break;
2582 }
2583
2584 case ID_MENU_NAV_TRACK:
2585 case ID_TRACK: {
2586 if (!g_bTrackActive) {
2587 TrackOn();
2588 g_bTrackCarryOver = true;
2589 } else {
2590 TrackOff(true); // catch the last point
2591 g_bTrackCarryOver = false;
2592 RefreshAllCanvas(true);
2593 }
2594 break;
2595 }
2596
2597 case ID_MENU_CHART_NORTHUP: {
2598 SetUpMode(GetPrimaryCanvas(), NORTH_UP_MODE);
2599 break;
2600 }
2601 case ID_MENU_CHART_COGUP: {
2602 SetUpMode(GetPrimaryCanvas(), COURSE_UP_MODE);
2603 break;
2604 }
2605 case ID_MENU_CHART_HEADUP: {
2606 SetUpMode(GetPrimaryCanvas(), HEAD_UP_MODE);
2607 break;
2608 }
2609
2610 case ID_MENU_MARK_MOB:
2611 case ID_MOB: {
2612 ActivateMOB();
2613 break;
2614 }
2615
2616 case ID_MASTERTOGGLE: {
2617 if (g_MainToolbar) {
2618 wxString tip = _("Show Toolbar");
2619 if (!g_bmasterToolbarFull) tip = _("Hide Toolbar");
2620 if (g_MainToolbar->GetToolbar())
2621 g_MainToolbar->GetToolbar()->SetToolShortHelp(ID_MASTERTOGGLE, tip);
2622
2623 g_bmasterToolbarFull = !g_bmasterToolbarFull;
2624
2625#ifdef __WXOSX__
2626 if (g_bmasterToolbarFull)
2627 m_nMasterToolCountShown =
2628 g_MainToolbar->GetToolCount() -
2629 1; // TODO disable animation on OSX. Maybe use fade effect?
2630 else
2631 m_nMasterToolCountShown = 2;
2632#else
2633 m_nMasterToolCountShown =
2634 g_MainToolbar->GetToolShowCount(); // Current state
2635#endif
2636 ToolbarAnimateTimer.Start(10, wxTIMER_ONE_SHOT);
2637 }
2638 break;
2639 }
2640
2641 // Various command events coming from (usually) other threads,
2642 // used to control OCPN modes in a thread-safe way.
2643
2644 case ID_CMD_SELECT_CHART_TYPE: {
2645 selectChartDisplay(event.GetExtraLong(), -1);
2646 break;
2647 }
2648
2649 case ID_CMD_SELECT_CHART_FAMILY: {
2650 selectChartDisplay(-1, event.GetExtraLong());
2651 break;
2652 }
2653
2654 case ID_CMD_APPLY_SETTINGS: {
2655 applySettingsString(event.GetString());
2656#ifdef __ANDROID__
2657 androidRestoreFullScreen();
2658#endif
2659
2660 break;
2661 }
2662
2663 case ID_CMD_NULL_REFRESH: {
2664 Refresh(true);
2665 break;
2666 }
2667
2668 case ID_CMD_SETVP: {
2669 setStringVP(event.GetString());
2670 break;
2671 }
2672
2673 case ID_CMD_INVALIDATE: {
2674 InvalidateAllGL();
2675 Refresh(true);
2676 break;
2677 }
2678
2679 case ID_CMD_POST_JSON_TO_PLUGINS: {
2680 // Extract the Message ID which is embedded in the JSON string passed in
2681 // the event
2682 wxJSONValue root;
2683 wxJSONReader reader;
2684
2685 int numErrors = reader.Parse(event.GetString(), &root);
2686 if (numErrors == 0) {
2687 if (root["MessageID"].IsString()) {
2688 wxString MsgID = root["MessageID"].AsString();
2689 SendPluginMessage(MsgID, event.GetString()); // Send to all PlugIns
2690 }
2691 }
2692
2693 break;
2694 }
2695
2696 case ID_DENSITY:
2697 case ID_RMINUS:
2698 case ID_RPLUS: {
2699 if (g_iENCToolbar) {
2700 g_iENCToolbar->OnToolLeftClick(event);
2701 }
2702 break;
2703 }
2704
2705 default: {
2706 // Look for PlugIn tools
2707 // If found, make the callback.
2708 // TODO Modify this to allow multiple tools per plugin
2709 if (g_pi_manager) {
2710 g_MainToolbar->HideTooltip();
2711
2712 ArrayOfPlugInToolbarTools tool_array =
2713 g_pi_manager->GetPluginToolbarToolArray();
2714 for (unsigned int i = 0; i < tool_array.size(); i++) {
2715 PlugInToolbarToolContainer *pttc = tool_array[i];
2716 if (event.GetId() == pttc->id) {
2717 if (pttc->m_pplugin)
2718 pttc->m_pplugin->OnToolbarToolCallback(pttc->id);
2719 return; // required to prevent event.Skip() being called
2720 }
2721 }
2722 }
2723
2724 // If we didn't handle the event, allow it to bubble up to other handlers.
2725 // This is required for the system menu items (Hide, etc.) on OS X to
2726 // work. This must only be called if we did NOT handle the event,
2727 // otherwise it stops the menu items from working on Windows.
2728 event.Skip();
2729
2730 break;
2731 }
2732
2733 } // switch
2734
2735 // Finally, force a refresh of the main toolbar
2736 if (g_MainToolbar) g_MainToolbar->Realize();
2737}
2738
2739bool MyFrame::SetGlobalToolbarViz(bool viz) {
2740 bool viz_now = g_bmasterToolbarFull;
2741
2742 g_MainToolbar->HideTooltip();
2743 wxString tip = _("Show Toolbar");
2744 if (viz) {
2745 tip = _("Hide Toolbar");
2746 if (g_MainToolbar->GetToolbar())
2747 g_MainToolbar->GetToolbar()->SetToolShortHelp(ID_MASTERTOGGLE, tip);
2748 }
2749
2750 bool toggle = false;
2751 if (viz && !g_bmasterToolbarFull)
2752 toggle = true;
2753
2754 else if (!viz && g_bmasterToolbarFull)
2755 toggle = true;
2756
2757 if (toggle) {
2758 g_bmasterToolbarFull = !g_bmasterToolbarFull;
2759
2760#ifdef __WXOSX__
2761 if (g_bmasterToolbarFull)
2762 m_nMasterToolCountShown =
2763 g_MainToolbar->GetToolCount() -
2764 1; // TODO disable animation on OSX. Maybe use fade effect?
2765 else
2766 m_nMasterToolCountShown = 2;
2767#else
2768 m_nMasterToolCountShown =
2769 g_MainToolbar->GetToolShowCount(); // Current state
2770#endif
2771 ToolbarAnimateTimer.Start(10, wxTIMER_ONE_SHOT);
2772 }
2773
2774 return viz_now;
2775}
2776
2777void MyFrame::ScheduleReloadCharts() {
2778 wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED);
2779 evt.SetId(ID_RELOAD_CHARTS);
2780 GetEventHandler()->AddPendingEvent(evt);
2781}
2782
2783void MyFrame::ScheduleDeleteSettingsDialog() {
2784 wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED);
2785 evt.SetId(ID_SETTINGS_DELETE);
2786 GetEventHandler()->AddPendingEvent(evt);
2787}
2788
2789void MyFrame::ScheduleSettingsDialog() {
2790 wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED);
2791 evt.SetId(ID_SETTINGS);
2792 GetEventHandler()->AddPendingEvent(evt);
2793}
2794
2795void MyFrame::ScheduleSettingsDialogNew() {
2796 wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED);
2797 evt.SetId(ID_SETTINGS_NEW);
2798 GetEventHandler()->AddPendingEvent(evt);
2799}
2800
2801void MyFrame::ScheduleReconfigAndSettingsReload(bool reload, bool new_dialog) {
2802 UpdateCanvasConfigDescriptors();
2803
2804 if ((g_canvasConfig > 0) && (last_canvasConfig == 0))
2805 CreateCanvasLayout(true);
2806 else
2807 CreateCanvasLayout();
2808 SendSizeEvent();
2809 g_pauimgr->Update();
2810
2811 ConfigureStatusBar();
2812 wxSize lastOptSize = options_lastWindowSize;
2813 SendSizeEvent();
2814
2815 BuildMenuBar();
2816 SendSizeEvent();
2817 options_lastWindowSize = lastOptSize;
2818
2819 if (reload) {
2820 if (new_dialog)
2821 ScheduleSettingsDialogNew();
2822 else
2823 ScheduleSettingsDialog();
2824 }
2825 // Trying to reload the previously displayed chart by name as saved in
2826 // pathArray Also, restoring the previous chart VPScale, if possible
2827 // ..For each canvas...
2828 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
2829 ChartCanvas *cc = g_canvasArray.Item(i);
2830 if (cc) {
2831 int index_hint = -1;
2832 if (i < pathArray.GetCount())
2833 index_hint = ChartData->FinddbIndex(pathArray.Item(i));
2834 cc->canvasChartsRefresh(index_hint);
2835 if (index_hint != -1) cc->SetVPScale(restoreScale[i]);
2836 }
2837 }
2838}
2839
2840ChartCanvas *MyFrame::GetFocusCanvas() {
2841 if ((g_canvasConfig != 0) && g_focusCanvas) // multi-canvas?
2842 return g_focusCanvas;
2843 else
2844 return GetPrimaryCanvas();
2845}
2846
2847void MyFrame::OnToolbarAnimateTimer(wxTimerEvent &event) {
2848 if (g_bmasterToolbarFull) {
2849#ifndef OCPN_TOOLBAR_ANIMATE
2850 m_nMasterToolCountShown = (int)g_MainToolbar->GetToolCount();
2851#endif
2852
2853 if (m_nMasterToolCountShown < (int)g_MainToolbar->GetToolCount()) {
2854 m_nMasterToolCountShown++;
2855 g_MainToolbar->SetToolShowCount(m_nMasterToolCountShown);
2856 g_MainToolbar->Realize();
2857 g_MainToolbar->RefreshToolbar();
2858
2859 ToolbarAnimateTimer.Start(20, wxTIMER_ONE_SHOT);
2860 } else {
2861 g_MainToolbar->SetToolShowCount(m_nMasterToolCountShown);
2862 g_MainToolbar->GetToolbar()->InvalidateBitmaps();
2863 g_MainToolbar->Realize();
2864 g_MainToolbar->RefreshToolbar();
2865 }
2866 } else {
2867#ifndef OCPN_TOOLBAR_ANIMATE
2868 m_nMasterToolCountShown = 1;
2869#endif
2870 if (m_nMasterToolCountShown > 1) {
2871 m_nMasterToolCountShown--;
2872 g_MainToolbar->SetToolShowCount(m_nMasterToolCountShown);
2873 g_MainToolbar->Realize();
2874 g_MainToolbar->RefreshToolbar();
2875 ToolbarAnimateTimer.Start(10, wxTIMER_ONE_SHOT);
2876 } else {
2877 g_MainToolbar->SetToolShowCount(m_nMasterToolCountShown);
2878 g_MainToolbar->GetToolbar()->InvalidateBitmaps();
2879 g_MainToolbar->Realize();
2880 g_MainToolbar->RefreshToolbar();
2881 }
2882 }
2883}
2884
2885void MyFrame::InvalidateAllGL() {
2886#ifdef ocpnUSE_GL
2887 // For each canvas
2888 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
2889 ChartCanvas *cc = g_canvasArray.Item(i);
2890 if (cc) {
2891 cc->InvalidateGL();
2892 cc->Refresh();
2893 }
2894 }
2895#endif
2896}
2897
2898void MyFrame::RefreshAllCanvas(bool bErase) {
2899 // For each canvas
2900 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
2901 ChartCanvas *cc = g_canvasArray.Item(i);
2902 if (cc) {
2903 cc->Refresh(bErase);
2904 }
2905 }
2906}
2907
2908void MyFrame::setStringVP(wxString VPS) {
2909 ChartCanvas *cc = GetPrimaryCanvas();
2910
2911 if (!cc) return;
2912
2913 wxStringTokenizer tkz(VPS, ";");
2914
2915 wxString token = tkz.GetNextToken();
2916 double lat = gLat;
2917 token.ToDouble(&lat);
2918
2919 token = tkz.GetNextToken();
2920 double lon = gLon;
2921 token.ToDouble(&lon);
2922
2923 token = tkz.GetNextToken();
2924 double scale_ppm = cc->GetVP().view_scale_ppm;
2925 token.ToDouble(&scale_ppm);
2926
2927 cc->SetViewPoint(lat, lon, scale_ppm, 0, cc->GetVPRotation());
2928}
2929
2930void MyFrame::DoSettingsNew() {
2931 delete g_options;
2932 g_options = nullptr;
2933
2934 DoSettings();
2935}
2936
2937void MyFrame::DoSettings() {
2938 DoOptionsDialog();
2939
2940 // Apply various system settings
2941 ApplyGlobalSettings(true);
2942
2943 // ..For each canvas...
2944 bool b_loadHarmonics = false;
2945 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
2946 ChartCanvas *cc = g_canvasArray.Item(i);
2947 if (cc) {
2948 if (cc->GetbShowCurrent() || cc->GetbShowTide()) b_loadHarmonics = true;
2949 }
2950 }
2951 if (b_loadHarmonics) LoadHarmonics();
2952
2953 // The chart display options may have changed, especially on S57 ENC,
2954 // So, flush the cache and redraw
2955 ReloadAllVP();
2956}
2957
2958void MyFrame::ToggleChartBar(ChartCanvas *cc) {
2959 g_bShowChartBar = !g_bShowChartBar;
2960
2961 if (g_bShowChartBar) cc->m_brepaint_piano = true;
2962
2963 cc->ReloadVP(); // needed to set VP.pix_height
2964 Refresh();
2965
2966 if (g_bShowChartBar) {
2967 DoChartUpdate();
2968 UpdateControlBar(cc);
2969 }
2970
2971 SetMenubarItemState(ID_MENU_UI_CHARTBAR, g_bShowChartBar);
2972}
2973
2974void MyFrame::ToggleColorScheme() {
2975 static bool lastIsNight;
2976 ColorScheme s = GetColorScheme();
2977 int is = (int)s;
2978 is++;
2979 if (lastIsNight && is == 3) // Back from step 3
2980 {
2981 is = 1;
2982 lastIsNight = false;
2983 } // Goto to Day
2984 if (lastIsNight) is = 2; // Back to Dusk on step 3
2985 if (is == 3) lastIsNight = true; // Step 2 Night
2986 s = (ColorScheme)is;
2987 if (s == N_COLOR_SCHEMES) s = GLOBAL_COLOR_SCHEME_RGB;
2988
2989 SetAndApplyColorScheme(s);
2990}
2991
2992void MyFrame::ToggleFullScreen() {
2993 bool to = !IsFullScreen();
2994
2995#ifdef __WXOSX__
2996 ShowFullScreen(to);
2997#else
2998 long style = wxFULLSCREEN_NOBORDER | wxFULLSCREEN_NOCAPTION;
2999 ; // | wxFULLSCREEN_NOMENUBAR;
3000 ShowFullScreen(to, style);
3001#endif
3002
3003 UpdateAllToolbars(global_color_scheme);
3004 // SurfaceAllCanvasToolbars();
3005 UpdateControlBar(GetPrimaryCanvas());
3006 Layout();
3007 TriggerRecaptureTimer();
3008}
3009
3010void MyFrame::ActivateMOB() {
3011 // The MOB point
3012 wxDateTime mob_time = wxDateTime::Now();
3013 wxString mob_label(_("MAN OVERBOARD"));
3014 mob_label += _(" on ");
3015 mob_label += ocpn::toUsrDateTimeFormat(mob_time);
3016
3017 RoutePoint *pWP_MOB =
3018 new RoutePoint(gLat, gLon, "mob", mob_label, wxEmptyString);
3019 pWP_MOB->SetShared(true);
3020 pWP_MOB->m_bIsolatedMark = true;
3021 pWP_MOB->SetWaypointArrivalRadius(
3022 -1.0); // Negative distance is code to signal "Never Arrive"
3023 pWP_MOB->SetUseSca(false); // Do not use scaled hiding for MOB
3024 pSelect->AddSelectableRoutePoint(gLat, gLon, pWP_MOB);
3025 NavObj_dB::GetInstance().InsertRoutePoint(pWP_MOB);
3026
3027 if (bGPSValid && !std::isnan(gCog) && !std::isnan(gSog)) {
3028 // Create a point that is one mile along the present course
3029 double zlat, zlon;
3030 ll_gc_ll(gLat, gLon, gCog, 1.0, &zlat, &zlon);
3031
3032 RoutePoint *pWP_src =
3033 new RoutePoint(zlat, zlon, g_default_wp_icon,
3034 wxString(_("1.0 NM along COG")), wxEmptyString);
3035 pSelect->AddSelectableRoutePoint(zlat, zlon, pWP_src);
3036
3037 Route *temp_route = new Route();
3038 pRouteList->push_back(temp_route);
3039
3040 temp_route->AddPoint(pWP_src);
3041 temp_route->AddPoint(pWP_MOB);
3042
3043 pSelect->AddSelectableRouteSegment(gLat, gLon, zlat, zlon, pWP_src, pWP_MOB,
3044 temp_route);
3045
3046 temp_route->m_RouteNameString = _("Temporary MOB Route");
3047 temp_route->m_RouteStartString = _("Assumed 1 Mile Point");
3048 ;
3049 temp_route->m_RouteEndString = mob_label;
3050
3051 temp_route->m_bDeleteOnArrival = false;
3052
3053 temp_route->SetRouteArrivalRadius(-1.0); // never arrives
3054
3055 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
3056 g_pRouteMan->ActivateRoute(temp_route, pWP_MOB);
3057
3058 wxJSONValue v;
3059 v["GUID"] = temp_route->m_GUID;
3060 wxString msg_id("OCPN_MAN_OVERBOARD");
3061 SendJSONMessageToAllPlugins(msg_id, v);
3062 }
3063
3064 if (RouteManagerDialog::getInstanceFlag()) {
3065 if (pRouteManagerDialog && pRouteManagerDialog->IsShown()) {
3066 pRouteManagerDialog->UpdateRouteListCtrl();
3067 pRouteManagerDialog->UpdateWptListCtrl();
3068 }
3069 }
3070
3071 InvalidateAllGL();
3072 RefreshAllCanvas(false);
3073
3074 wxString mob_message(_("MAN OVERBOARD"));
3075 mob_message += _(" Time: ");
3076 mob_message += ocpn::toUsrDateTimeFormat(mob_time);
3077 mob_message += _(" Position: ");
3078 mob_message += toSDMM(1, gLat);
3079 mob_message += " ";
3080 mob_message += toSDMM(2, gLon);
3081 wxLogMessage(mob_message);
3082}
3083void MyFrame::TrackOn() {
3084 g_bTrackActive = true;
3086
3087 g_TrackList.push_back(g_pActiveTrack);
3088 NavObj_dB::GetInstance().InsertTrack(g_pActiveTrack);
3089 g_pActiveTrack->Start();
3090
3091 // The main toolbar may still be NULL here, and we will do nothing...
3092 SetMasterToolbarItemState(ID_TRACK, g_bTrackActive);
3093 if (g_MainToolbar)
3094 g_MainToolbar->SetToolShortHelp(ID_TRACK, _("Disable Tracking"));
3095
3096 SetMenubarItemState(ID_MENU_NAV_TRACK, g_bTrackActive);
3097
3098#ifdef __ANDROID__
3099 androidSetTrackTool(true);
3100#endif
3101
3102 if (RouteManagerDialog::getInstanceFlag()) {
3103 if (pRouteManagerDialog && pRouteManagerDialog->IsShown()) {
3104 pRouteManagerDialog->UpdateTrkListCtrl();
3105 pRouteManagerDialog->UpdateRouteListCtrl();
3106 }
3107 }
3108
3109 wxJSONValue v;
3110 wxString name = g_pActiveTrack->GetName();
3111 if (name.IsEmpty()) {
3112 TrackPoint *tp = g_pActiveTrack->GetPoint(0);
3113 if (tp->GetCreateTime().IsValid())
3114 name = tp->GetCreateTime().FormatISODate() + " " +
3115 tp->GetCreateTime().FormatISOTime();
3116 else
3117 name = _("(Unnamed Track)");
3118 }
3119 v["Name"] = name;
3120 v["GUID"] = g_pActiveTrack->m_GUID;
3121 wxString msg_id("OCPN_TRK_ACTIVATED");
3122 SendJSONMessageToAllPlugins(msg_id, v);
3123 g_FlushNavobjChangesTimeout =
3124 30; // Every thirty seconds, consider flushing navob changes
3125}
3126
3127Track *MyFrame::TrackOff(bool do_add_point) {
3128 Track *return_val = g_pActiveTrack;
3129
3130 if (g_pActiveTrack) {
3131 wxJSONValue v;
3132 wxString msg_id("OCPN_TRK_DEACTIVATED");
3133 v["GUID"] = g_pActiveTrack->m_GUID;
3134 SendJSONMessageToAllPlugins(msg_id, v);
3135
3136 g_pActiveTrack->Stop(do_add_point);
3137
3138 if (g_pActiveTrack->GetnPoints() < 2) {
3139 NavObj_dB::GetInstance().DeleteTrack(g_pActiveTrack);
3140 RoutemanGui(*g_pRouteMan).DeleteTrack(g_pActiveTrack);
3141 return_val = NULL;
3142 } else {
3143 if (g_bTrackDaily) {
3144 Track *pExtendTrack = g_pActiveTrack->DoExtendDaily();
3145 if (pExtendTrack) {
3146 NavObj_dB::GetInstance().DeleteTrack(g_pActiveTrack);
3147 RoutemanGui(*g_pRouteMan).DeleteTrack(g_pActiveTrack);
3148 NavObj_dB::GetInstance().UpdateTrack(pExtendTrack);
3149 return_val = pExtendTrack;
3150 }
3151 }
3152 }
3153 g_pActiveTrack = NULL;
3154 }
3155
3156 g_bTrackActive = false;
3157
3158 if (RouteManagerDialog::getInstanceFlag()) {
3159 if (pRouteManagerDialog && pRouteManagerDialog->IsShown()) {
3160 pRouteManagerDialog->UpdateTrkListCtrl();
3161 pRouteManagerDialog->UpdateRouteListCtrl();
3162 }
3163 }
3164
3165 SetMasterToolbarItemState(ID_TRACK, g_bTrackActive);
3166 if (g_MainToolbar)
3167 g_MainToolbar->SetToolShortHelp(ID_TRACK, _("Enable Tracking"));
3168 SetMenubarItemState(ID_MENU_NAV_TRACK, g_bTrackActive);
3169
3170#ifdef __ANDROID__
3171 androidSetTrackTool(false);
3172#endif
3173
3174 g_FlushNavobjChangesTimeout =
3175 600; // Revert to checking/flushing navob changes every 5 minutes
3176
3177 return return_val;
3178}
3179
3180bool MyFrame::ShouldRestartTrack() {
3181 if (!g_pActiveTrack || !g_bTrackDaily) return false;
3182 time_t now = wxDateTime::Now().GetTicks();
3183 time_t today = wxDateTime::Today().GetTicks();
3184 int rotate_at = 0;
3185 switch (g_track_rotate_time_type) {
3186 case TIME_TYPE_LMT:
3187 rotate_at = g_track_rotate_time + wxRound(gLon * 3600. / 15.);
3188 break;
3189 case TIME_TYPE_COMPUTER:
3190 rotate_at = g_track_rotate_time;
3191 break;
3192 case TIME_TYPE_UTC:
3193 int utc_offset =
3194 wxDateTime::Now().GetTicks() - wxDateTime::Now().ToUTC().GetTicks();
3195 rotate_at = g_track_rotate_time + utc_offset;
3196 break;
3197 }
3198 if (rotate_at > 86400)
3199 rotate_at -= 86400;
3200 else if (rotate_at < 0)
3201 rotate_at += 86400;
3202 if (now >= m_last_track_rotation_ts + 86400 - 3600 &&
3203 now - today >= rotate_at) {
3204 if (m_last_track_rotation_ts == 0) {
3205 if (now - today > rotate_at)
3206 m_last_track_rotation_ts = today + rotate_at;
3207 else
3208 m_last_track_rotation_ts = today + rotate_at - 86400;
3209 return false;
3210 }
3211 m_last_track_rotation_ts = now;
3212 return true;
3213 }
3214 return false;
3215}
3216
3217void MyFrame::TrackDailyRestart() {
3218 if (!g_pActiveTrack) return;
3219 Track *pPreviousTrack = TrackOff(true);
3220 TrackOn();
3221
3222 // Set the restarted track's current state such that the current track
3223 // point's attributes match the attributes of the last point of the track
3224 // that was just stopped at midnight.
3225
3226 if (pPreviousTrack) {
3227 TrackPoint *pMidnightPoint = pPreviousTrack->GetLastPoint();
3228 g_pActiveTrack->AdjustCurrentTrackPoint(pMidnightPoint);
3229 }
3230
3231 if (RouteManagerDialog::getInstanceFlag()) {
3232 if (pRouteManagerDialog && pRouteManagerDialog->IsShown()) {
3233 pRouteManagerDialog->UpdateTrkListCtrl();
3234 pRouteManagerDialog->UpdateRouteListCtrl();
3235 }
3236 }
3237}
3238
3239void MyFrame::SetUpMode(ChartCanvas *cc, int mode) {
3240 if (cc) {
3241 cc->SetUpMode(mode);
3242
3243 SetMenubarItemState(ID_MENU_CHART_COGUP, mode == COURSE_UP_MODE);
3244 SetMenubarItemState(ID_MENU_CHART_NORTHUP, mode == NORTH_UP_MODE);
3245 SetMenubarItemState(ID_MENU_CHART_HEADUP, mode == HEAD_UP_MODE);
3246
3247 if (m_pMenuBar)
3248 m_pMenuBar->SetLabel(ID_MENU_CHART_NORTHUP, _("North Up Mode"));
3249 }
3250}
3251
3252void MyFrame::ToggleENCText(ChartCanvas *cc) {
3253 cc->SetShowENCText(!cc->GetShowENCText());
3254
3255 SetMenubarItemState(ID_MENU_ENC_TEXT, cc->GetShowENCText());
3256
3257 // if(g_pi_manager)
3258 // g_pi_manager->SendConfigToAllPlugIns();
3259
3260 ReloadAllVP();
3261}
3262
3263void MyFrame::SetENCDisplayCategory(ChartCanvas *cc, enum _DisCat nset) {
3264 if (ps52plib) {
3265 if (cc) {
3266 cc->SetENCDisplayCategory(nset);
3267
3268 UpdateGlobalMenuItems();
3269
3270 /* if(g_pi_manager)
3271 g_pi_manager->SendConfigToAllPlugIns();
3272 */
3273 ReloadAllVP();
3274 }
3275 }
3276}
3277
3278void MyFrame::ToggleSoundings(ChartCanvas *cc) {
3279 cc->SetShowENCDepth(!cc->GetShowENCDepth());
3280
3281 SetMenubarItemState(ID_MENU_ENC_SOUNDINGS, cc->GetShowENCDepth());
3282
3283 // if(g_pi_manager)
3284 // g_pi_manager->SendConfigToAllPlugIns();
3285
3286 ReloadAllVP();
3287}
3288
3289bool MyFrame::ToggleLights(ChartCanvas *cc) {
3290 cc->SetShowENCLights(!cc->GetShowENCLights());
3291
3292 SetMenubarItemState(ID_MENU_ENC_LIGHTS, cc->GetShowENCLights());
3293
3294 if (g_pi_manager) g_pi_manager->SendS52ConfigToAllPlugIns(true);
3295
3296 ReloadAllVP();
3297
3298 return true;
3299}
3300
3301#if 0
3302void MyFrame::ToggleRocks( void )
3303{
3304 if( ps52plib ) {
3305 int vis = 0;
3306 // Need to loop once for UWTROC, which is our "master", then for
3307 // other categories, since order is unknown?
3308 for( unsigned int iPtr = 0; iPtr < ps52plib->pOBJLArray->GetCount(); iPtr++ ) {
3309 OBJLElement *pOLE = (OBJLElement *) ( ps52plib->pOBJLArray->Item( iPtr ) );
3310 if( !strncmp( pOLE->OBJLName, "UWTROC", 6 ) ) {
3311 pOLE->nViz = !pOLE->nViz;
3312 vis = pOLE->nViz;
3313 }
3314 }
3315 for( unsigned int iPtr = 0; iPtr < ps52plib->pOBJLArray->GetCount(); iPtr++ ) {
3316 OBJLElement *pOLE = (OBJLElement *) ( ps52plib->pOBJLArray->Item( iPtr ) );
3317 if( !strncmp( pOLE->OBJLName, "OBSTRN", 6 ) ) {
3318 pOLE->nViz = vis;
3319 }
3320 if( !strncmp( pOLE->OBJLName, "WRECKS", 6 ) ) {
3321 pOLE->nViz = vis;
3322 }
3323 }
3324 ps52plib->GenerateStateHash();
3325 ReloadAllVP();
3326 }
3327}
3328#endif
3329
3330void MyFrame::ToggleAnchor(ChartCanvas *cc) {
3331 cc->SetShowENCAnchor(!cc->GetShowENCAnchor());
3332
3333 SetMenubarItemState(ID_MENU_ENC_ANCHOR, cc->GetShowENCAnchor());
3334
3335 if (g_pi_manager) g_pi_manager->SendS52ConfigToAllPlugIns();
3336
3337 ReloadAllVP();
3338}
3339
3340void MyFrame::ToggleDataQuality(ChartCanvas *cc) {
3341 cc->SetShowENCDataQual(!cc->GetShowENCDataQual());
3342
3343 SetMenubarItemState(ID_MENU_ENC_DATA_QUALITY, cc->GetShowENCDataQual());
3344
3345 if (g_pi_manager) g_pi_manager->SendS52ConfigToAllPlugIns();
3346
3347 ReloadAllVP();
3348}
3349
3350void MyFrame::TogglebFollow(ChartCanvas *cc) {
3351 if (!cc->m_bFollow)
3352 SetbFollow(cc);
3353 else
3354 ClearbFollow(cc);
3355}
3356
3357void MyFrame::ToggleNavobjects(ChartCanvas *cc) {
3358 cc->m_bShowNavobjects = !cc->m_bShowNavobjects;
3359 SetMenubarItemState(ID_MENU_SHOW_NAVOBJECTS, cc->m_bShowNavobjects);
3360 cc->Refresh();
3361}
3362
3363void MyFrame::ToggleAISDisplay(ChartCanvas *cc) {
3364 cc->SetShowAIS(!cc->GetShowAIS());
3365 SetMenubarItemState(ID_MENU_AIS_TARGETS, cc->GetShowAIS());
3366 cc->Refresh();
3367}
3368
3369void MyFrame::ToggleAISMinimizeTargets(ChartCanvas *cc) {
3370 cc->SetAttenAIS(!cc->GetAttenAIS());
3371 SetMenubarItemState(ID_MENU_AIS_SCALED_TARGETS, cc->GetAttenAIS());
3372 cc->Refresh();
3373}
3374
3375void MyFrame::SetbFollow(ChartCanvas *cc) {
3376 JumpToPosition(cc, gLat, gLon, cc->GetVPScale());
3377 cc->m_bFollow = true;
3378
3379 // cc->SetCanvasToolbarItemState(ID_FOLLOW, true);
3380 SetMenubarItemState(ID_MENU_NAV_FOLLOW, true);
3381
3382 DoChartUpdate();
3383 cc->ReloadVP();
3384 SetChartUpdatePeriod();
3385}
3386
3387void MyFrame::ClearbFollow(ChartCanvas *cc) {
3388 // Center the screen on the GPS position, for lack of a better place
3389 vLat = gLat;
3390 vLon = gLon;
3391
3392 cc->m_bFollow = false;
3393 // cc->SetCanvasToolbarItemState(ID_FOLLOW, false);
3394 SetMenubarItemState(ID_MENU_NAV_FOLLOW, false);
3395
3396 DoChartUpdate();
3397 cc->ReloadVP();
3398 SetChartUpdatePeriod();
3399}
3400
3401void MyFrame::ToggleChartOutlines(ChartCanvas *cc) {
3402 cc->SetShowOutlines(!cc->GetShowOutlines());
3403
3404 RefreshAllCanvas(false);
3405
3406#ifdef ocpnUSE_GL // opengl renders chart outlines as part of the chart this
3407 // needs a full refresh
3408 if (g_bopengl) InvalidateAllGL();
3409#endif
3410
3411 SetMenubarItemState(ID_MENU_CHART_OUTLINES, cc->GetShowOutlines());
3412}
3413
3414void MyFrame::ToggleTestPause() { g_bPauseTest = !g_bPauseTest; }
3415
3416void MyFrame::SetMenubarItemState(int item_id, bool state) {
3417 if (m_pMenuBar) {
3418 bool enabled = m_pMenuBar->IsEnabled(item_id);
3419 m_pMenuBar->Enable(item_id, false);
3420 m_pMenuBar->Check(item_id, state);
3421 m_pMenuBar->Enable(item_id, enabled);
3422 }
3423}
3424
3425void MyFrame::SetMasterToolbarItemState(int tool_id, bool state) {
3426 if (g_MainToolbar && g_MainToolbar->GetToolbar()) {
3427 g_MainToolbar->GetToolbar()->ToggleTool(tool_id, state);
3428 g_MainToolbar->Realize();
3429 }
3430}
3431
3432void MyFrame::SetToolbarItemBitmaps(int tool_id, wxBitmap *bmp,
3433 wxBitmap *bmpRollover) {
3434 if (g_MainToolbar && g_MainToolbar->GetToolbar()) {
3435 g_MainToolbar->GetToolbar()->SetToolBitmaps(tool_id, bmp, bmpRollover);
3436 g_MainToolbar->Realize();
3437 }
3438}
3439
3440void MyFrame::SetToolbarItemSVG(int tool_id, wxString normalSVGfile,
3441 wxString rolloverSVGfile,
3442 wxString toggledSVGfile) {
3443 if (g_MainToolbar && g_MainToolbar->GetToolbar()) {
3444 g_MainToolbar->GetToolbar()->SetToolBitmapsSVG(
3445 tool_id, normalSVGfile, rolloverSVGfile, toggledSVGfile);
3446 }
3447}
3448
3449void MyFrame::ConfigureStatusBar() {
3450 // ShowDebugWindow as a wxStatusBar
3451 m_StatusBarFieldCount = g_Platform->GetStatusBarFieldCount();
3452
3453#ifdef __WXMSW__
3454 UseNativeStatusBar(false); // better for MSW, undocumented in frame.cpp
3455#endif
3456
3457 if (g_bShowStatusBar) {
3458 if (!m_pStatusBar) {
3459 m_pStatusBar =
3460 CreateStatusBar(m_StatusBarFieldCount, 0); // No wxST_SIZEGRIP needed
3461 ApplyGlobalColorSchemetoStatusBar();
3462 }
3463
3464 } else {
3465 if (m_pStatusBar) {
3466 m_pStatusBar->Destroy();
3467 m_pStatusBar = NULL;
3468 SetStatusBar(NULL);
3469 }
3470 }
3471}
3472
3473void MyFrame::ApplyGlobalSettings(bool bnewtoolbar) {
3474 ConfigureStatusBar();
3475
3476 wxSize lastOptSize = options_lastWindowSize;
3477 SendSizeEvent();
3478
3479 BuildMenuBar();
3480
3481 SendSizeEvent();
3482 options_lastWindowSize = lastOptSize;
3483
3484 if (bnewtoolbar) UpdateAllToolbars(global_color_scheme);
3485}
3486
3487wxString _menuText(wxString name, wxString shortcut) {
3488 wxString menutext;
3489 menutext << name;
3490#ifndef __ANDROID__
3491 menutext << "\t" << shortcut;
3492#endif
3493 return menutext;
3494}
3495
3496void MyFrame::BuildMenuBar() {
3497 /*
3498 * Menu Bar - add or remove it if necessary, and update the state of the menu
3499 * items
3500 */
3501#ifdef __WXOSX__
3502 bool showMenuBar = true; // the menu bar is always visible in OS X
3503#else
3504 bool showMenuBar = g_bShowMenuBar; // get visibility from options
3505
3506 if (!showMenuBar &&
3507 g_bTempShowMenuBar) // allows pressing alt to temporarily show
3508 showMenuBar = true;
3509#endif
3510
3511 if (showMenuBar) {
3512 // Menu bar has some dependencies on S52 PLIB, so be sure it is loaded.
3513 LoadS57();
3514
3515 if (!m_pMenuBar) { // add the menu bar if it is enabled
3516 m_pMenuBar = new wxMenuBar();
3517 RegisterGlobalMenuItems();
3518 SetMenuBar(m_pMenuBar); // must be after RegisterGlobalMenuItems for wx
3519 // to populate the OS X App Menu correctly
3520 }
3521
3522 UpdateGlobalMenuItems(); // update the state of the menu items (checkmarks
3523 // etc.)
3524 } else {
3525 if (m_pMenuBar) { // remove the menu bar if it is disabled
3526 SetMenuBar(NULL);
3527 m_pMenuBar->Destroy();
3528 m_pMenuBar = NULL;
3529 }
3530 }
3531}
3532
3533void MyFrame::RegisterGlobalMenuItems() {
3534 if (!m_pMenuBar) return; // if there isn't a menu bar
3535
3536 wxMenu *nav_menu = new wxMenu();
3537 nav_menu->AppendCheckItem(ID_MENU_NAV_FOLLOW,
3538 _menuText(_("Auto Follow"), "Ctrl-A"));
3539 nav_menu->AppendCheckItem(ID_MENU_NAV_TRACK, _("Enable Tracking"));
3540 nav_menu->AppendSeparator();
3541 nav_menu->AppendRadioItem(ID_MENU_CHART_NORTHUP, _("North Up Mode"));
3542 nav_menu->AppendRadioItem(ID_MENU_CHART_COGUP, _("Course Up Mode"));
3543 nav_menu->AppendRadioItem(ID_MENU_CHART_HEADUP, _("Head Up Mode"));
3544 nav_menu->AppendSeparator();
3545#ifndef __WXOSX__
3546 nav_menu->Append(ID_MENU_ZOOM_IN, _menuText(_("Zoom In"), "+"));
3547 nav_menu->Append(ID_MENU_ZOOM_OUT, _menuText(_("Zoom Out"), "-"));
3548#else
3549 nav_menu->Append(ID_MENU_ZOOM_IN, _menuText(_("Zoom In"), "Alt-+"));
3550 nav_menu->Append(ID_MENU_ZOOM_OUT, _menuText(_("Zoom Out"), "Alt--"));
3551#endif
3552 nav_menu->AppendSeparator();
3553 nav_menu->Append(ID_MENU_SCALE_IN,
3554 _menuText(_("Larger Scale Chart"), "Ctrl-Left"));
3555 nav_menu->Append(ID_MENU_SCALE_OUT,
3556 _menuText(_("Smaller Scale Chart"), "Ctrl-Right"));
3557#ifndef __WXOSX__
3558 nav_menu->AppendSeparator();
3559 nav_menu->Append(ID_MENU_OQUIT, _menuText(_("Exit OpenCPN"), "Ctrl-Q"));
3560#endif
3561 m_pMenuBar->Append(nav_menu, _("&Navigate"));
3562
3563 wxMenu *view_menu = new wxMenu();
3564#ifndef __WXOSX__
3565 view_menu->AppendCheckItem(ID_MENU_CHART_QUILTING,
3566 _menuText(_("Enable Chart Quilting"), "Q"));
3567 view_menu->AppendCheckItem(ID_MENU_CHART_OUTLINES,
3568 _menuText(_("Show Chart Outlines"), "O"));
3569#else
3570 view_menu->AppendCheckItem(ID_MENU_CHART_QUILTING,
3571 _menuText(_("Enable Chart Quilting"), "Alt-Q"));
3572 view_menu->AppendCheckItem(ID_MENU_CHART_OUTLINES,
3573 _menuText(_("Show Chart Outlines"), "Alt-O"));
3574#endif
3575 view_menu->AppendCheckItem(ID_MENU_UI_CHARTBAR,
3576 _menuText(_("Show Chart Bar"), "Ctrl-B"));
3577
3578 view_menu->AppendSeparator();
3579#ifndef __WXOSX__
3580 view_menu->AppendCheckItem(ID_MENU_ENC_TEXT,
3581 _menuText(_("Show ENC text"), "T"));
3582 view_menu->AppendCheckItem(ID_MENU_ENC_LIGHTS,
3583 _menuText(_("Show ENC Lights"), "L"));
3584 view_menu->AppendCheckItem(ID_MENU_ENC_SOUNDINGS,
3585 _menuText(_("Show ENC Soundings"), "S"));
3586 view_menu->AppendCheckItem(ID_MENU_ENC_ANCHOR,
3587 _menuText(_("Show ENC Anchoring Info"), "A"));
3588 view_menu->AppendCheckItem(ID_MENU_ENC_DATA_QUALITY,
3589 _menuText(_("Show ENC Data Quality"), "U"));
3590 view_menu->AppendCheckItem(ID_MENU_SHOW_NAVOBJECTS,
3591 _menuText(_("Show Navobjects"), "V"));
3592#else
3593 view_menu->AppendCheckItem(ID_MENU_ENC_TEXT,
3594 _menuText(_("Show ENC text"), "Alt-T"));
3595 view_menu->AppendCheckItem(ID_MENU_ENC_LIGHTS,
3596 _menuText(_("Show ENC Lights"), "Alt-L"));
3597 view_menu->AppendCheckItem(ID_MENU_ENC_SOUNDINGS,
3598 _menuText(_("Show ENC Soundings"), "Alt-S"));
3599 view_menu->AppendCheckItem(ID_MENU_ENC_ANCHOR,
3600 _menuText(_("Show ENC Anchoring Info"), "Alt-A"));
3601 view_menu->AppendCheckItem(ID_MENU_ENC_DATA_QUALITY,
3602 _menuText(_("Show ENC Data Quality"), "Alt-U"));
3603 view_menu->AppendCheckItem(ID_MENU_SHOW_NAVOBJECTS,
3604 _menuText(_("Show Navobjects"), "Alt-V"));
3605#endif
3606 view_menu->AppendSeparator();
3607 view_menu->AppendCheckItem(ID_MENU_SHOW_TIDES, _("Show Tides"));
3608 view_menu->AppendCheckItem(ID_MENU_SHOW_CURRENTS, _("Show Currents"));
3609 view_menu->AppendSeparator();
3610#ifndef __WXOSX__
3611 view_menu->Append(ID_MENU_UI_COLSCHEME,
3612 _menuText(_("Change Color Scheme"), "C"));
3613#else
3614 view_menu->Append(ID_MENU_UI_COLSCHEME,
3615 _menuText(_("Change Color Scheme"), "Alt-C"));
3616#endif
3617
3618 view_menu->AppendSeparator();
3619#ifndef __WXOSX__
3620 view_menu->Append(ID_MENU_UI_FULLSCREEN,
3621 _menuText(_("Toggle Full Screen"), "F11"));
3622#endif
3623 m_pMenuBar->Append(view_menu, _("&View"));
3624
3625 wxMenu *ais_menu = new wxMenu();
3626 ais_menu->AppendCheckItem(ID_MENU_AIS_TARGETS, _("Show AIS Targets"));
3627 ais_menu->AppendCheckItem(ID_MENU_AIS_SCALED_TARGETS,
3628 _("Attenuate less critical AIS targets"));
3629 ais_menu->AppendSeparator();
3630 ais_menu->AppendCheckItem(ID_MENU_AIS_MOORED_TARGETS,
3631 _("Hide Moored AIS Targets"));
3632 ais_menu->AppendCheckItem(ID_MENU_AIS_TRACKS, _("Show AIS Target Tracks"));
3633 ais_menu->AppendCheckItem(ID_MENU_AIS_CPADIALOG, _("Show CPA Alert Dialogs"));
3634 ais_menu->AppendCheckItem(ID_MENU_AIS_CPASOUND, _("Sound CPA Alarms"));
3635
3636#ifndef __WXOSX__
3637 ais_menu->AppendCheckItem(ID_MENU_AIS_CPAWARNING,
3638 _menuText(_("Show CPA Warnings"), "W"));
3639#else
3640 ais_menu->AppendCheckItem(ID_MENU_AIS_CPAWARNING,
3641 _menuText(_("Show CPA Warnings"), "Alt-W"));
3642#endif
3643
3644 ais_menu->AppendSeparator();
3645 ais_menu->Append(ID_MENU_AIS_TARGETLIST, _("AIS target list") + "...");
3646 m_pMenuBar->Append(ais_menu, _("&AIS"));
3647
3648 wxMenu *tools_menu = new wxMenu();
3649 tools_menu->Append(ID_MENU_TOOL_NMEA_DBG_LOG,
3650 _menuText(_("Data Monitor"), "Alt-C"));
3651#ifndef __WXOSX__
3652 tools_menu->Append(ID_MENU_TOOL_MEASURE,
3653 _menuText(_("Measure Distance"), "M"));
3654#else
3655 tools_menu->Append(ID_MENU_TOOL_MEASURE,
3656 _menuText(_("Measure Distance"), "Alt-M"));
3657#endif
3658
3659 tools_menu->AppendSeparator();
3660 tools_menu->Append(ID_MENU_ROUTE_MANAGER, _("Route && Mark Manager..."));
3661 tools_menu->Append(ID_MENU_ROUTE_NEW, _menuText(_("Create Route"), "Ctrl-R"));
3662 tools_menu->AppendSeparator();
3663 tools_menu->Append(ID_MENU_MARK_BOAT,
3664 _menuText(_("Drop Mark at Boat"), "Ctrl-O"));
3665 tools_menu->Append(ID_MENU_MARK_CURSOR,
3666 _menuText(_("Drop Mark at Cursor"), "Ctrl-M"));
3667 tools_menu->AppendSeparator();
3668#ifdef __WXOSX__
3669 tools_menu->Append(
3670 ID_MENU_MARK_MOB,
3671 _menuText(_("Drop MOB Marker"),
3672 "RawCtrl-Space")); // NOTE Cmd+Space is reserved for Spotlight
3673 tools_menu->AppendSeparator();
3674 tools_menu->Append(wxID_PREFERENCES,
3675 _menuText(_("Preferences") + "...", "Ctrl-,"));
3676#else
3677 tools_menu->Append(ID_MENU_MARK_MOB,
3678 _menuText(_("Drop MOB Marker"), "Ctrl-Space"));
3679 tools_menu->AppendSeparator();
3680 tools_menu->Append(wxID_PREFERENCES,
3681 _menuText(_("Options") + "...", "Ctrl-,"));
3682#endif
3683 m_pMenuBar->Append(tools_menu, _("&Tools"));
3684
3685#ifdef __WXOSX__
3686 wxMenu *window_menu = new wxMenu();
3687 m_pMenuBar->Append(window_menu, _("&Window"));
3688#endif
3689
3690 wxMenu *help_menu = new wxMenu();
3691 help_menu->Append(wxID_ABOUT, _("About OpenCPN"));
3692 help_menu->Append(wxID_HELP, _("OpenCPN Help"));
3693 m_pMenuBar->Append(help_menu, _("&Help"));
3694
3695 // Set initial values for menu check items and radio items
3696 UpdateGlobalMenuItems();
3697}
3698
3699void MyFrame::UpdateGlobalMenuItems() {
3700 if (!m_pMenuBar) return; // if there isn't a menu bar
3701
3702 m_pMenuBar->FindItem(ID_MENU_NAV_FOLLOW)
3703 ->Check(GetPrimaryCanvas()->m_bFollow);
3704 m_pMenuBar->FindItem(ID_MENU_CHART_NORTHUP)
3705 ->Check(GetPrimaryCanvas()->GetUpMode() == NORTH_UP_MODE);
3706 m_pMenuBar->FindItem(ID_MENU_CHART_COGUP)
3707 ->Check(GetPrimaryCanvas()->GetUpMode() == COURSE_UP_MODE);
3708 m_pMenuBar->FindItem(ID_MENU_CHART_HEADUP)
3709 ->Check(GetPrimaryCanvas()->GetUpMode() == HEAD_UP_MODE);
3710 m_pMenuBar->FindItem(ID_MENU_NAV_TRACK)->Check(g_bTrackActive);
3711 m_pMenuBar->FindItem(ID_MENU_CHART_OUTLINES)->Check(g_bShowOutlines);
3712 m_pMenuBar->FindItem(ID_MENU_CHART_QUILTING)->Check(g_bQuiltEnable);
3713 m_pMenuBar->FindItem(ID_MENU_UI_CHARTBAR)->Check(g_bShowChartBar);
3714 m_pMenuBar->FindItem(ID_MENU_AIS_TARGETS)->Check(g_bShowAIS);
3715 m_pMenuBar->FindItem(ID_MENU_AIS_MOORED_TARGETS)->Check(g_bHideMoored);
3716 m_pMenuBar->FindItem(ID_MENU_AIS_SCALED_TARGETS)->Check(g_bShowScaled);
3717 m_pMenuBar->FindItem(ID_MENU_AIS_SCALED_TARGETS)->Enable(g_bAllowShowScaled);
3718 m_pMenuBar->FindItem(ID_MENU_AIS_TRACKS)->Check(g_bAISShowTracks);
3719 m_pMenuBar->FindItem(ID_MENU_AIS_CPADIALOG)->Check(g_bAIS_CPA_Alert);
3720 if (g_bAIS_CPA_Alert) {
3721 m_pMenuBar->FindItem(ID_MENU_AIS_CPASOUND)->Check(g_bAIS_CPA_Alert_Audio);
3722 m_pMenuBar->Enable(ID_MENU_AIS_CPASOUND, true);
3723 } else {
3724 m_pMenuBar->FindItem(ID_MENU_AIS_CPASOUND)->Check(false);
3725 m_pMenuBar->Enable(ID_MENU_AIS_CPASOUND, false);
3726 }
3727
3728 m_pMenuBar->FindItem(ID_MENU_AIS_CPAWARNING)->Check(g_bCPAWarn);
3729 m_pMenuBar->FindItem(ID_MENU_SHOW_NAVOBJECTS)
3730 ->Check(GetPrimaryCanvas()->m_bShowNavobjects);
3731
3732 if (ps52plib) {
3733 m_pMenuBar->FindItem(ID_MENU_ENC_TEXT)->Check(ps52plib->GetShowS57Text());
3734 m_pMenuBar->FindItem(ID_MENU_ENC_SOUNDINGS)
3735 ->Check(ps52plib->GetShowSoundings());
3736
3737 bool light_state = false;
3738 if (ps52plib) {
3739 for (unsigned int iPtr = 0; iPtr < ps52plib->pOBJLArray->GetCount();
3740 iPtr++) {
3741 OBJLElement *pOLE = (OBJLElement *)(ps52plib->pOBJLArray->Item(iPtr));
3742 if (!strncmp(pOLE->OBJLName, "LIGHTS", 6)) {
3743 light_state = (pOLE->nViz == 1);
3744 break;
3745 }
3746 }
3747 }
3748 m_pMenuBar->FindItem(ID_MENU_ENC_LIGHTS)
3749 ->Check((!ps52plib->IsObjNoshow("LIGHTS")) && light_state);
3750
3751 // Menu "Anchor Info" entry is only accessible in "All" or "User Standard"
3752 // categories
3753 DisCat nset = ps52plib->GetDisplayCategory();
3754 if ((nset == MARINERS_STANDARD) || (nset == OTHER)) {
3755 m_pMenuBar->FindItem(ID_MENU_ENC_ANCHOR)
3756 ->Check(!ps52plib->IsObjNoshow("SBDARE"));
3757 m_pMenuBar->Enable(ID_MENU_ENC_ANCHOR, true);
3758 m_pMenuBar->FindItem(ID_MENU_ENC_DATA_QUALITY)
3759 ->Check(!ps52plib->IsObjNoshow("M_QUAL"));
3760 m_pMenuBar->Enable(ID_MENU_ENC_DATA_QUALITY, true);
3761 } else {
3762 m_pMenuBar->FindItem(ID_MENU_ENC_ANCHOR)->Check(false);
3763 m_pMenuBar->Enable(ID_MENU_ENC_ANCHOR, false);
3764 m_pMenuBar->Enable(ID_MENU_ENC_DATA_QUALITY, false);
3765 }
3766 }
3767}
3768
3769void MyFrame::UpdateGlobalMenuItems(ChartCanvas *cc) {
3770 if (!m_pMenuBar) return; // if there isn't a menu bar
3771
3772 m_pMenuBar->FindItem(ID_MENU_NAV_FOLLOW)->Check(cc->m_bFollow);
3773
3774 if (cc->GetUpMode() == NORTH_UP_MODE)
3775 m_pMenuBar->FindItem(ID_MENU_CHART_NORTHUP)->Check(true);
3776 else if (cc->GetUpMode() == COURSE_UP_MODE)
3777 m_pMenuBar->FindItem(ID_MENU_CHART_COGUP)->Check(true);
3778 else
3779 m_pMenuBar->FindItem(ID_MENU_CHART_HEADUP)->Check(true);
3780
3781 m_pMenuBar->FindItem(ID_MENU_NAV_TRACK)->Check(g_bTrackActive);
3782 m_pMenuBar->FindItem(ID_MENU_CHART_OUTLINES)->Check(cc->GetShowOutlines());
3783 m_pMenuBar->FindItem(ID_MENU_CHART_QUILTING)->Check(cc->GetQuiltMode());
3784 m_pMenuBar->FindItem(ID_MENU_UI_CHARTBAR)->Check(cc->GetShowChartbar());
3785 m_pMenuBar->FindItem(ID_MENU_AIS_TARGETS)->Check(cc->GetShowAIS());
3786 m_pMenuBar->FindItem(ID_MENU_AIS_MOORED_TARGETS)->Check(g_bHideMoored);
3787 m_pMenuBar->FindItem(ID_MENU_AIS_SCALED_TARGETS)->Check(cc->GetAttenAIS());
3788 m_pMenuBar->FindItem(ID_MENU_AIS_SCALED_TARGETS)->Enable(g_bAllowShowScaled);
3789 m_pMenuBar->FindItem(ID_MENU_AIS_TRACKS)->Check(g_bAISShowTracks);
3790 m_pMenuBar->FindItem(ID_MENU_AIS_CPADIALOG)->Check(g_bAIS_CPA_Alert);
3791 m_pMenuBar->FindItem(ID_MENU_AIS_CPASOUND)->Check(g_bAIS_CPA_Alert_Audio);
3792 m_pMenuBar->FindItem(ID_MENU_AIS_CPAWARNING)->Check(g_bCPAWarn);
3793 m_pMenuBar->FindItem(ID_MENU_SHOW_NAVOBJECTS)->Check(cc->m_bShowNavobjects);
3794 m_pMenuBar->FindItem(ID_MENU_SHOW_TIDES)->Check(cc->GetbShowTide());
3795 m_pMenuBar->FindItem(ID_MENU_SHOW_CURRENTS)->Check(cc->GetbShowCurrent());
3796
3797 if (ps52plib) {
3798 m_pMenuBar->FindItem(ID_MENU_ENC_TEXT)->Check(cc->GetShowENCText());
3799 m_pMenuBar->FindItem(ID_MENU_ENC_SOUNDINGS)->Check(cc->GetShowENCDepth());
3800
3801 if (ps52plib) {
3802 for (unsigned int iPtr = 0; iPtr < ps52plib->pOBJLArray->GetCount();
3803 iPtr++) {
3804 OBJLElement *pOLE = (OBJLElement *)(ps52plib->pOBJLArray->Item(iPtr));
3805 if (!strncmp(pOLE->OBJLName, "LIGHTS", 6)) {
3806 break;
3807 }
3808 }
3809 }
3810 m_pMenuBar->FindItem(ID_MENU_ENC_LIGHTS)->Check(cc->GetShowENCLights());
3811
3812 // Menu "Anchor Info" entry is only accessible in "All" or "UserStandard"
3813 // categories
3814 DisCat nset = (DisCat)cc->GetENCDisplayCategory();
3815 if ((nset == MARINERS_STANDARD) || (nset == OTHER)) {
3816 m_pMenuBar->FindItem(ID_MENU_ENC_ANCHOR)->Check(cc->GetShowENCAnchor());
3817 m_pMenuBar->Enable(ID_MENU_ENC_ANCHOR, true);
3818 m_pMenuBar->FindItem(ID_MENU_ENC_DATA_QUALITY)
3819 ->Check(cc->GetShowENCDataQual());
3820 m_pMenuBar->Enable(ID_MENU_ENC_DATA_QUALITY, true);
3821 } else {
3822 m_pMenuBar->FindItem(ID_MENU_ENC_ANCHOR)->Check(false);
3823 m_pMenuBar->Enable(ID_MENU_ENC_ANCHOR, false);
3824 m_pMenuBar->Enable(ID_MENU_ENC_DATA_QUALITY, false);
3825 }
3826 }
3827}
3828
3829void MyFrame::InvalidateAllCanvasUndo() {
3830 // .. for each canvas...
3831 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
3832 ChartCanvas *cc = g_canvasArray.Item(i);
3833 if (cc) cc->undo->InvalidateUndo();
3834 }
3835}
3836#if 0
3837void MyFrame::SubmergeAllCanvasToolbars() {
3838 // .. for each canvas...
3839 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
3840 ChartCanvas *cc = g_canvasArray.Item(i);
3841 if (cc) cc->SubmergeToolbar();
3842 }
3843}
3844
3845void MyFrame::SurfaceAllCanvasToolbars() {
3846 if (g_bshowToolbar) {
3847 // .. for each canvas...
3848 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
3849 ChartCanvas *cc = g_canvasArray.Item(i);
3850 if (cc && cc->GetToolbarEnable()) cc->SurfaceToolbar();
3851 }
3852 }
3853
3854}
3855#endif
3856
3857void MyFrame::JumpToPosition(ChartCanvas *cc, double lat, double lon,
3858 double scale) {
3859 if (lon > 180.0) lon -= 360.0;
3860 // XXX is vLat/vLon always equal to cc m_vLat, m_vLon after SetViewPoint? Does
3861 // it matter?
3862 vLat = lat;
3863 vLon = lon;
3864 cc->JumpToPosition(lat, lon, scale);
3865
3866 if (g_pi_manager) {
3867 g_pi_manager->SendViewPortToRequestingPlugIns(cc->GetVP());
3868 }
3869}
3870
3871void MyFrame::UpdateCanvasConfigDescriptors() {
3872 // ..For each canvas...
3873 for (unsigned int i = 0;
3874 i < ConfigMgr::Get().GetCanvasConfigArray().GetCount(); i++) {
3875 canvasConfig *cc = ConfigMgr::Get().GetCanvasConfigArray().Item(i);
3876 if (cc) {
3877 ChartCanvas *chart = cc->canvas;
3878 if (chart) {
3879 cc->iLat = chart->GetVP().clat;
3880 cc->iLon = chart->GetVP().clon;
3881 cc->iRotation = chart->GetVP().rotation;
3882 cc->iScale = chart->GetVP().view_scale_ppm;
3883 cc->DBindex = chart->GetQuiltReferenceChartIndex();
3884 cc->GroupID = chart->m_groupIndex;
3885 cc->canvasSize = chart->GetSize();
3886
3887 cc->bQuilt = chart->GetQuiltMode();
3888 cc->bShowTides = chart->GetbShowTide();
3889 cc->bShowCurrents = chart->GetbShowCurrent();
3890 cc->bShowGrid = chart->GetShowGrid();
3891 cc->bShowOutlines = chart->GetShowOutlines();
3892 cc->bShowDepthUnits = chart->GetShowDepthUnits();
3893
3894 cc->bFollow = chart->m_bFollow;
3895 cc->bLookahead = chart->m_bLookAhead;
3896 cc->bCourseUp = false;
3897 cc->bHeadUp = false;
3898 ;
3899 int upmode = chart->GetUpMode();
3900 if (upmode == COURSE_UP_MODE)
3901 cc->bCourseUp = true;
3902 else if (upmode == HEAD_UP_MODE)
3903 cc->bHeadUp = true;
3904 }
3905 }
3906 }
3907}
3908
3909void MyFrame::CenterView(ChartCanvas *cc, const LLBBox &RBBox) {
3910 if (!RBBox.GetValid()) return;
3911 // Calculate bbox center
3912 double clat = (RBBox.GetMinLat() + RBBox.GetMaxLat()) / 2;
3913 double clon = (RBBox.GetMinLon() + RBBox.GetMaxLon()) / 2;
3914 double ppm; // final ppm scale to use
3915
3916 if (RBBox.GetMinLat() == RBBox.GetMaxLat() &&
3917 RBBox.GetMinLon() == RBBox.GetMaxLon()) {
3918 // only one point, (should be a box?)
3919 ppm = cc->GetVPScale();
3920 } else {
3921 // Calculate ppm
3922 double rw, rh; // route width, height
3923 int ww, wh; // chart window width, height
3924 // route bbox width in nm
3925 DistanceBearingMercator(RBBox.GetMinLat(), RBBox.GetMinLon(),
3926 RBBox.GetMinLat(), RBBox.GetMaxLon(), NULL, &rw);
3927 // route bbox height in nm
3928 DistanceBearingMercator(RBBox.GetMinLat(), RBBox.GetMinLon(),
3929 RBBox.GetMaxLat(), RBBox.GetMinLon(), NULL, &rh);
3930
3931 cc->GetSize(&ww, &wh);
3932
3933 ppm = wxMin(ww / (rw * 1852), wh / (rh * 1852)) * (100 - fabs(clat)) / 90;
3934
3935 ppm = wxMin(ppm, 1.0);
3936 }
3937
3938 JumpToPosition(cc, clat, clon, ppm);
3939}
3940
3941void MyFrame::PrepareOptionsClose(options *settings,
3942 int settings_return_value) {
3943 // Capture som values from options dialog before closure
3944 options_lastPage = settings->lastPage;
3945#ifdef __ANDROID__
3946 // This is necessary to force a manual change to charts page,
3947 // in order to properly refresh the chart directory list.
3948 // Root cause: In Android, trouble with clearing the wxScrolledWindow
3949 if (options_lastPage == 1) options_lastPage = 0;
3950#endif
3951 options_subpage = settings->lastSubPage;
3952 options_lastWindowPos = settings->lastWindowPos;
3953 options_lastWindowSize = settings->lastWindowSize;
3954
3955#ifdef __ANDROID__
3956 androidEnableBackButton(true);
3957 androidEnableOptionsMenu(true);
3958 androidRestoreFullScreen();
3959 androidEnableRotation();
3960#endif
3961 ThawCharts();
3962}
3963
3964void MyFrame::DoOptionsDialog() {
3965 if (NULL == g_options) {
3966 AbstractPlatform::ShowBusySpinner();
3967
3968 int sx, sy;
3969 pConfig->SetPath("/Settings");
3970 pConfig->Read("OptionsSizeX", &sx, -1);
3971 pConfig->Read("OptionsSizeY", &sy, -1);
3972
3973 wxWindow *optionsParent = this;
3974#ifdef __WXOSX__
3975 optionsParent = GetPrimaryCanvas();
3976#endif
3977 g_options = new options(optionsParent, -1, _("Options"), wxPoint(-1, -1),
3978 wxSize(sx, sy));
3979
3980 AbstractPlatform::HideBusySpinner();
3981 }
3982
3983 // Set initial Chart Dir
3984 g_options->SetInitChartDir(*pInit_Chart_Dir);
3985
3986 // Pass two working pointers for Chart Dir Dialog
3987 g_options->SetCurrentDirList(ChartData->GetChartDirArray());
3988 ArrayOfCDI *pWorkDirArray = new ArrayOfCDI;
3989 g_options->SetWorkDirListPtr(pWorkDirArray);
3990
3991 // Pass a ptr to MyConfig, for updates
3992 g_options->SetConfigPtr(pConfig);
3993 g_options->SetInitialSettings();
3994
3995 prev_locale = g_locale;
3996 g_options->SetInitialPage(options_lastPage, options_subpage);
3997
3998#ifndef __ANDROID__ // if(!g_bresponsive){
3999 g_options->lastWindowPos = options_lastWindowPos;
4000 if (options_lastWindowPos != wxPoint(0, 0)) {
4001 g_options->Move(options_lastWindowPos);
4002 g_options->SetSize(options_lastWindowSize);
4003 } else {
4004 g_options->CenterOnScreen();
4005 }
4006 if (options_lastWindowSize != wxSize(0, 0)) {
4007 g_options->SetSize(options_lastWindowSize);
4008 }
4009#endif
4010
4011#ifdef __ANDROID__
4012 androidEnableBackButton(false);
4013 androidEnableOptionsMenu(false);
4014 androidDisableFullScreen();
4015#endif
4016
4017 // Capture the full path names and VPScale of charts currently shown in all
4018 // canvases
4019 pathArray.Clear();
4020 // ..For each canvas.
4021 // TODO FIX ANDROID codepath..
4022 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4023 ChartCanvas *cc = g_canvasArray.Item(i);
4024 if (cc) {
4025 wxString chart_file_name;
4026 if (cc->GetQuiltMode()) {
4027 int dbi = cc->GetQuiltRefChartdbIndex();
4028 chart_file_name = ChartData->GetDBChartFileName(dbi);
4029 } else {
4030 if (cc->m_singleChart)
4031 chart_file_name = cc->m_singleChart->GetFullPath();
4032 }
4033
4034 pathArray.Add(chart_file_name);
4035 restoreScale[i] = cc->GetVPScale();
4036 }
4037 }
4038
4039 // Record current canvas config
4040 last_canvasConfig = g_canvasConfig;
4041
4042 // Record current chart scale factor
4043 g_last_ChartScaleFactor = g_ChartScaleFactor;
4044
4045 g_options->Show();
4046 return;
4047}
4048
4049void MyFrame::ProcessOptionsDialog(int rr, ArrayOfCDI *pNewDirArray) {
4050 bool b_need_refresh = false; // Do we need a full reload?
4051
4052 if ((rr & VISIT_CHARTS) &&
4053 ((rr & CHANGE_CHARTS) || (rr & FORCE_UPDATE) || (rr & SCAN_UPDATE))) {
4054 if (pNewDirArray) {
4055 UpdateChartDatabaseInplace(*pNewDirArray,
4056 ((rr & FORCE_UPDATE) == FORCE_UPDATE), true,
4057 ChartListFileName);
4058
4059 b_need_refresh = true;
4060 }
4061 }
4062
4063 if (rr & STYLE_CHANGED) {
4064 OCPNMessageBox(
4065 NULL,
4066 _("Please restart OpenCPN to activate language or style changes."),
4067 _("OpenCPN Info"), wxOK | wxICON_INFORMATION);
4068 }
4069
4070 bool b_groupchange = false;
4071 if (((rr & VISIT_CHARTS) &&
4072 ((rr & CHANGE_CHARTS) || (rr & FORCE_UPDATE) || (rr & SCAN_UPDATE))) ||
4073 (rr & GROUPS_CHANGED)) {
4074 b_groupchange = ScrubGroupArray();
4075 ChartData->ApplyGroupArray(g_pGroupArray);
4076 RefreshGroupIndices();
4077 }
4078
4079 if (rr & GROUPS_CHANGED || b_groupchange) {
4080 pConfig->DestroyConfigGroups();
4081 pConfig->CreateConfigGroups(g_pGroupArray);
4082 }
4083
4084 if (rr & TIDES_CHANGED) {
4085 LoadHarmonics();
4086 }
4087
4088 // S52_CHANGED is a byproduct of a change in the chart object render scale
4089 // So, applies to RoutePoint icons also
4090 if (rr & S52_CHANGED) {
4091 WayPointmanGui(*pWayPointMan).ReloadAllIcons(g_Platform->GetDisplayDPmm());
4092 }
4093
4094 pConfig->UpdateSettings();
4095
4096 if (g_pActiveTrack) {
4097 g_pActiveTrack->SetPrecision(g_nTrackPrecision);
4098 }
4099
4100 // reload pens and brushes
4101 g_pRouteMan->SetColorScheme(global_color_scheme,
4102 g_Platform->GetDisplayDPmm());
4103
4104 // Stuff the Filter tables
4105 double stuffcog = NAN;
4106 double stuffsog = NAN;
4107 if (!std::isnan(gCog)) stuffcog = gCog;
4108 if (!std::isnan(gSog)) stuffsog = gSog;
4109
4110 for (int i = 0; i < MAX_COGSOG_FILTER_SECONDS; i++) {
4111 COGFilterTable[i] = stuffcog;
4112 SOGFilterTable[i] = stuffsog;
4113 }
4114
4115 SetChartUpdatePeriod(); // Pick up changes to skew compensator
4116
4117 if (rr & GL_CHANGED) {
4118 // Refresh the chart display, after flushing cache.
4119 // This will allow all charts to recognise new OpenGL configuration, if
4120 // any
4121 b_need_refresh = true;
4122 }
4123
4124 if (rr & S52_CHANGED) {
4125 b_need_refresh = true;
4126 }
4127
4128#ifdef ocpnUSE_GL
4129 if (rr & REBUILD_RASTER_CACHE) {
4130 if (g_glTextureManager) {
4131 GetPrimaryCanvas()->Disable();
4132 g_glTextureManager->BuildCompressedCache();
4133 GetPrimaryCanvas()->Enable();
4134 }
4135 }
4136#endif
4137
4138 if (g_config_display_size_manual &&
4142 } else {
4143 g_display_size_mm = wxMax(50, g_Platform->GetDisplaySizeMM());
4144 }
4145
4146 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4147 ChartCanvas *cc = g_canvasArray.Item(i);
4149 }
4150
4151 if (g_pi_manager) {
4152 g_pi_manager->SendBaseConfigToAllPlugIns();
4153 int rrt = rr & S52_CHANGED;
4154 g_pi_manager->SendS52ConfigToAllPlugIns(
4155 (rrt == S52_CHANGED) ||
4156 (g_last_ChartScaleFactor != g_ChartScaleFactor));
4157 }
4158
4159 if (g_MainToolbar) {
4160 g_MainToolbar->SetAutoHide(g_bAutoHideToolbar);
4161 g_MainToolbar->SetAutoHideTimer(g_nAutoHideToolbar);
4162 }
4163
4164 // update S52 PLIB scale factors
4165 if (ps52plib) {
4166 ps52plib->SetScaleFactorExp(
4167 g_Platform->GetChartScaleFactorExp(g_ChartScaleFactor));
4168 ps52plib->SetScaleFactorZoomMod(g_chart_zoom_modifier_vector);
4169 }
4170
4171 // Apply any needed updates to each canvas
4172 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4173 ChartCanvas *cc = g_canvasArray.Item(i);
4174 if (cc) cc->ApplyGlobalSettings();
4175 }
4176
4177 // The zoom-scale factor may have changed
4178 // so, trigger a recalculation of the reference chart
4179 bool ztc = g_bEnableZoomToCursor; // record the present state
4180 g_bEnableZoomToCursor =
4181 false; // since we don't want to pan to an unknown cursor position
4182
4183 // This is needed to recognise changes in zoom-scale factors
4184 if (!GetPrimaryCanvas()->IsFrozen())
4185 GetPrimaryCanvas()->ZoomCanvasSimple(1.0001);
4186 g_bEnableZoomToCursor = ztc;
4187
4188 // Pick up chart object icon size changes (g_ChartScaleFactorExp)
4189 if (g_last_ChartScaleFactor != g_ChartScaleFactor) {
4190 if (g_pMarkInfoDialog) {
4191 g_pMarkInfoDialog->Hide();
4192 g_pMarkInfoDialog->Destroy();
4193 g_pMarkInfoDialog = NULL;
4194 }
4195 }
4196
4197 // We set the compass size
4198 SetGPSCompassScale();
4199 // ..For each canvas...
4200 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4201 ChartCanvas *cc = g_canvasArray.Item(i);
4202 if (cc) {
4203 cc->GetCompass()->SetScaleFactor(g_compass_scalefactor);
4204 cc->UpdateCanvasControlBar();
4205 }
4206 }
4207 UpdateGPSCompassStatusBoxes();
4208
4209 SetAllToolbarScale();
4210 RequestNewToolbars();
4211
4212 // Rebuild cursors
4213 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4214 ChartCanvas *cc = g_canvasArray.Item(i);
4215 if (cc) {
4216 cc->RebuildCursors();
4217 }
4218 }
4219
4220 // Change of master toolbar scale?
4221 bool b_masterScaleChange = false;
4222 if (fabs(g_MainToolbar->GetScaleFactor() - g_toolbar_scalefactor) > 0.01f)
4223 b_masterScaleChange = true;
4224
4225 if ((rr & TOOLBAR_CHANGED) || b_masterScaleChange)
4226 RequestNewMasterToolbar(true);
4227
4228 bool bMuiChange = false;
4229#ifdef __ANDROID__
4230 bMuiChange = true; // to pick up possible "zoom" button visibility change
4231#endif
4232
4233 // Inform the canvases
4234 if (b_masterScaleChange || bMuiChange) {
4235 // ..For each canvas...
4236 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4237 ChartCanvas *cc = g_canvasArray.Item(i);
4238 if (cc) {
4239 cc->ProcessNewGUIScale();
4240 }
4241 }
4242 }
4243
4244#if wxUSE_XLOCALE
4245 if (rr & LOCALE_CHANGED) {
4246 g_Platform->ChangeLocale(g_locale, plocale_def_lang, &plocale_def_lang);
4247 ApplyLocale();
4248 rr |= NEED_NEW_OPTIONS;
4249 }
4250#endif
4251
4252#ifdef __ANDROID__
4253 if (g_pi_manager) g_pi_manager->NotifyAuiPlugIns();
4254#endif
4255
4256 // Reset chart scale factor trigger
4257 g_last_ChartScaleFactor = g_ChartScaleFactor;
4258
4259 if (rr & FORCE_RELOAD) ScheduleReloadCharts();
4260
4261 return;
4262}
4263
4264bool MyFrame::CheckGroup(int igroup) {
4265 if (igroup == 0) return true; // "all charts" is always OK
4266
4267 ChartGroup *pGroup = g_pGroupArray->Item(igroup - 1);
4268
4269 if (!pGroup->m_element_array.size()) // truly empty group is OK
4270 return true;
4271
4272 for (const auto &elem : pGroup->m_element_array) {
4273 for (unsigned int ic = 0;
4274 ic < (unsigned int)ChartData->GetChartTableEntries(); ic++) {
4275 ChartTableEntry *pcte = ChartData->GetpChartTableEntry(ic);
4276 wxString chart_full_path(pcte->GetpFullPath(), wxConvUTF8);
4277
4278 if (chart_full_path.StartsWith(elem.m_element_name)) return true;
4279 }
4280 }
4281
4282 return false; // this group is empty
4283}
4284
4285bool MyFrame::ScrubGroupArray() {
4286 // For each group,
4287 // make sure that each group element (dir or chart) references at least
4288 // oneitem in the database. If not, remove the element.
4289
4290 bool b_change = false;
4291 unsigned int igroup = 0;
4292 while (igroup < g_pGroupArray->GetCount()) {
4293 bool b_chart_in_element = false;
4294 ChartGroup *pGroup = g_pGroupArray->Item(igroup);
4295
4296 for (unsigned int j = 0; j < pGroup->m_element_array.size(); j++) {
4297 const wxString &element_root = pGroup->m_element_array[j].m_element_name;
4298
4299 for (unsigned int ic = 0;
4300 ic < (unsigned int)ChartData->GetChartTableEntries(); ic++) {
4301 ChartTableEntry *pcte = ChartData->GetpChartTableEntry(ic);
4302 wxString chart_full_path = pcte->GetFullSystemPath();
4303
4304 if (chart_full_path.StartsWith(element_root)) {
4305 b_chart_in_element = true;
4306 break;
4307 }
4308 }
4309
4310 // Explicit check to avoid removing a group containing only GSHHS
4311 if (!b_chart_in_element) {
4312 wxString test_string = "GSHH";
4313 if (element_root.Upper().Contains(test_string))
4314 b_chart_in_element = true;
4315 }
4316
4317 if (!b_chart_in_element) // delete the element
4318 {
4319 pGroup->m_element_array.erase(pGroup->m_element_array.begin() + j);
4320 j--;
4321 b_change = true;
4322 }
4323 }
4324
4325 igroup++; // next group
4326 }
4327
4328 return b_change;
4329}
4330
4331void MyFrame::RefreshCanvasOther(ChartCanvas *ccThis) {
4332 // ..For each canvas...
4333 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4334 ChartCanvas *cc = g_canvasArray.Item(i);
4335 if (cc && (cc != ccThis)) cc->Refresh();
4336 }
4337}
4338
4339// Flav: This method reloads all charts for convenience
4340void MyFrame::ChartsRefresh() {
4341 if (!ChartData) return;
4342
4343 AbstractPlatform::ShowBusySpinner();
4344
4345 bool b_run = FrameTimer1.IsRunning();
4346
4347 FrameTimer1.Stop(); // stop other asynchronous activity
4348 FrameTenHzTimer.Stop();
4349
4350 // ..For each canvas...
4351 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4352 ChartCanvas *cc = g_canvasArray.Item(i);
4353 if (cc) {
4354 int currentIndex = cc->GetpCurrentStack()->GetCurrentEntrydbIndex();
4355 if (cc->GetQuiltMode()) {
4356 currentIndex = cc->GetQuiltReferenceChartIndex();
4357 }
4358 cc->canvasChartsRefresh(currentIndex);
4359 }
4360 }
4361
4362 if (b_run) FrameTimer1.Start(TIMER_GFRAME_1, wxTIMER_CONTINUOUS);
4363 if (b_run) FrameTenHzTimer.Start(100, wxTIMER_CONTINUOUS);
4364
4365 AbstractPlatform::HideBusySpinner();
4366}
4367
4368void MyFrame::InvalidateAllQuilts() {
4369 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4370 ChartCanvas *cc = g_canvasArray.Item(i);
4371 if (cc) {
4372 cc->InvalidateQuilt();
4373 cc->SetQuiltRefChart(-1);
4374 cc->m_singleChart = NULL;
4375 }
4376 }
4377}
4378
4379bool MyFrame::UpdateChartDatabaseInplace(ArrayOfCDI &DirArray, bool b_force,
4380 bool b_prog,
4381 const wxString &ChartListFileName) {
4382 bool b_run = FrameTimer1.IsRunning();
4383 FrameTimer1.Stop(); // stop other asynchronous activity
4384 FrameTenHzTimer.Stop();
4385
4386 bool b_runCOGTimer = FrameCOGTimer.IsRunning();
4387 FrameCOGTimer.Stop();
4388
4389 // ..For each canvas...
4390 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4391 ChartCanvas *cc = g_canvasArray.Item(i);
4392 if (cc) {
4393 cc->InvalidateQuilt();
4394 cc->SetQuiltRefChart(-1);
4395 cc->m_singleChart = NULL;
4396 }
4397 }
4398
4399 ChartData->PurgeCache();
4400
4401 // TODO
4402 // delete pCurrentStack;
4403 // pCurrentStack = NULL;
4404
4405 AbstractPlatform::ShowBusySpinner();
4406
4407 wxGenericProgressDialog *pprog = nullptr;
4408 if (b_prog) {
4409 wxString longmsg = _("OpenCPN Chart Update");
4410 longmsg +=
4411 ".................................................................."
4412 "........";
4413
4414 pprog = new wxGenericProgressDialog();
4415
4416 wxFont *qFont = GetOCPNScaledFont(_("Dialog"));
4417 pprog->SetFont(*qFont);
4418
4419 pprog->Create(_("OpenCPN Chart Update"), longmsg, 100, gFrame,
4420 wxPD_SMOOTH | wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME |
4421 wxPD_REMAINING_TIME);
4422
4423 DimeControl(pprog);
4424 pprog->Show();
4425 }
4426
4427 wxLogMessage(" ");
4428 wxLogMessage("Starting chart database Update...");
4429 wxString gshhg_chart_loc = gWorldMapLocation;
4430 gWorldMapLocation = wxEmptyString;
4431 // The Update() function may set gWorldMapLocation if at least one of the
4432 // directories contains GSHHS files.
4433 ChartData->Update(DirArray, b_force, pprog);
4434 ChartData->SaveBinary(ChartListFileName);
4435 wxLogMessage("Finished chart database Update");
4436 wxLogMessage(" ");
4437 if (gWorldMapLocation.empty()) { // Last resort. User might have deleted all
4438 // GSHHG data, but we still might have the
4439 // default dataset distributed with OpenCPN
4440 // or from the package repository...
4441 gWorldMapLocation = gDefaultWorldMapLocation;
4442 gshhg_chart_loc = wxEmptyString;
4443 }
4444
4445 if (gWorldMapLocation != gshhg_chart_loc) {
4446 // ..For each canvas...
4447 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4448 ChartCanvas *cc = g_canvasArray.Item(i);
4449 if (cc) cc->ResetWorldBackgroundChart();
4450 }
4451 // Reset the GSHHS singleton which is used to detect land crossing.
4452 gshhsCrossesLandReset();
4453 }
4454
4455 delete pprog;
4456
4457 AbstractPlatform::HideBusySpinner();
4458
4459 pConfig->UpdateChartDirs(DirArray);
4460
4461 // Restart timers, if necessary
4462 if (b_run) FrameTimer1.Start(TIMER_GFRAME_1, wxTIMER_CONTINUOUS);
4463 if (b_run) FrameTenHzTimer.Start(100, wxTIMER_CONTINUOUS);
4464
4465 if (b_runCOGTimer) {
4466 // Restart the COG rotation timer, max frequency is 10 hz.
4467 int period_ms = 100;
4468 if (g_COGAvgSec > 0) period_ms = g_COGAvgSec * 1000;
4469 FrameCOGTimer.Start(period_ms, wxTIMER_CONTINUOUS);
4470 }
4471 return true;
4472}
4473
4474void MyFrame::ToggleQuiltMode(ChartCanvas *cc) {
4475 if (cc) {
4476 cc->ToggleCanvasQuiltMode();
4477#if 0
4478 bool cur_mode = cc->GetQuiltMode();
4479
4480 if( !cc->GetQuiltMode() )
4481 cc->SetQuiltMode( true );
4482 else
4483 if( cc->GetQuiltMode() ) {
4484 cc->SetQuiltMode( false );
4485 g_sticky_chart = cc->GetQuiltReferenceChartIndex();
4486 }
4487
4488
4489 if( cur_mode != cc->GetQuiltMode() ){
4490 //TODO >>SetupQuiltMode();
4491 DoChartUpdate();
4492 cc->InvalidateGL();
4493 Refresh();
4494 }
4495 g_bQuiltEnable = cc->GetQuiltMode();
4496
4497 // Recycle the S52 PLIB so that vector charts will flush caches and re-render
4498 if(ps52plib)
4499 ps52plib->GenerateStateHash();
4500#endif
4501 }
4502}
4503
4504void MyFrame::DoStackDown(ChartCanvas *cc) { DoStackDelta(cc, -1); }
4505
4506void MyFrame::DoStackUp(ChartCanvas *cc) { DoStackDelta(cc, 1); }
4507
4508void MyFrame::DoStackDelta(ChartCanvas *cc, int direction) {
4509 if (cc) {
4510 cc->DoCanvasStackDelta(direction);
4511 }
4512}
4513
4514void MyFrame::PositionIENCToolbar() {
4515#if 0
4516 if (g_iENCToolbar) {
4517 wxPoint posn;
4518 posn.x = (GetPrimaryCanvas()->GetSize().x - g_iENCToolbar->GetSize().x) / 2;
4519 posn.y = 4;
4520 g_iENCToolbar->Move(GetPrimaryCanvas()->ClientToScreen(posn));
4521 }
4522#endif
4523}
4524
4525// Defered initialization for anything that is not required to render the
4526// initial frame and takes a while to initialize. This gets opencpn up and
4527// running much faster.
4528void MyFrame::OnInitTimer(wxTimerEvent &event) {
4529 InitTimer.Stop();
4530 wxString msg;
4531 msg.Printf("OnInitTimer...%d", m_iInitCount);
4532 wxLogMessage(msg);
4533 // printf("init-%d\n", m_iInitCount);
4534
4535 wxLog::FlushActive();
4536
4537 switch (m_iInitCount++) {
4538 case 0: {
4539 FontMgr::Get()
4540 .ScrubList(); // Clean the font list, removing nonsensical entries
4541
4542 if (g_bInlandEcdis) {
4543 double range = GetPrimaryCanvas()->GetCanvasRangeMeters();
4544 double range_set = 500.;
4545
4546 range = wxRound(range * 10) / 10.;
4547
4548 if (range > 4000.)
4549 range_set = 4000.;
4550 else if (range > 2000.)
4551 range_set = 2000.;
4552 else if (range > 1600.)
4553 range_set = 1600.;
4554 else if (range > 1200.)
4555 range_set = 1200.;
4556 else if (range > 800.)
4557 range_set = 800.;
4558 else
4559 range_set = 500.;
4560
4561 GetPrimaryCanvas()->SetCanvasRangeMeters(range_set);
4562 }
4563
4564 // Set persistent Fullscreen mode
4565 g_Platform->SetFullscreen(g_bFullscreen);
4566
4567 // Rebuild chart database, if necessary
4568 if (g_NeedDBUpdate > 0) {
4569 RebuildChartDatabase();
4570 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4571 ChartCanvas *cc = g_canvasArray.Item(i);
4572 if (cc) {
4573 cc->SetGroupIndex(0, false); // all charts
4574 }
4575 }
4576
4577 // As a favor to new users, poll the database and
4578 // move the initial viewport so that a chart will come up.
4579
4580 double clat, clon;
4581 if (ChartData->GetCentroidOfLargestScaleChart(&clat, &clon,
4582 CHART_FAMILY_RASTER)) {
4583 gLat = clat;
4584 gLon = clon;
4585 gFrame->ClearbFollow(gFrame->GetPrimaryCanvas());
4586 } else {
4587 if (ChartData->GetCentroidOfLargestScaleChart(&clat, &clon,
4588 CHART_FAMILY_VECTOR)) {
4589 gLat = clat;
4590 gLon = clon;
4591 gFrame->ClearbFollow(gFrame->GetPrimaryCanvas());
4592 }
4593 }
4594
4595 g_NeedDBUpdate = 0;
4596 }
4597
4598#if 0
4599 // Load the waypoints. Both of these routines are very slow to execute
4600 // which is why they have been to defered until here
4601 auto colour_func = [](wxString c) { return GetGlobalColor(c); };
4602 pWayPointMan = new WayPointman(colour_func);
4603 WayPointmanGui(*pWayPointMan)
4604 .SetColorScheme(global_color_scheme, g_Platform->GetDisplayDPmm());
4605 // Reload the ownship icon from UserIcons, if present
4606 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4607 ChartCanvas *cc = g_canvasArray.Item(i);
4608 if (cc) {
4609 if (cc->SetUserOwnship()) cc->SetColorScheme(global_color_scheme);
4610 }
4611 }
4612
4613 NavObj_dB::GetInstance().ImportLegacyNavobj(this);
4614 NavObj_dB::GetInstance().LoadNavObjects();
4615
4616 // Re-enable anchor watches if set in config file
4617 if (!g_AW1GUID.IsEmpty()) {
4618 pAnchorWatchPoint1 = pWayPointMan->FindRoutePointByGUID(g_AW1GUID);
4619 }
4620 if (!g_AW2GUID.IsEmpty()) {
4621 pAnchorWatchPoint2 = pWayPointMan->FindRoutePointByGUID(g_AW2GUID);
4622 }
4623
4624 // Import Layer-wise any .gpx files from /layers directory
4625 wxString layerdir = g_Platform->GetPrivateDataDir();
4626 appendOSDirSlash(&layerdir);
4627 layerdir.Append("layers");
4628
4629 if (wxDir::Exists(layerdir)) {
4630 wxString laymsg;
4631 laymsg.Printf("Getting .gpx layer files from: %s", layerdir.c_str());
4632 wxLogMessage(laymsg);
4633 pConfig->LoadLayers(layerdir);
4634 }
4635#endif
4636
4637 break;
4638 }
4639 case 1:
4640 break;
4641
4642 case 2: {
4643 if (g_pi_manager->IsAnyPlugInChartEnabled()) b_reloadForPlugins = true;
4644 break;
4645 }
4646
4647 case 3: {
4648 if (g_MainToolbar) {
4649 g_MainToolbar->SetAutoHide(g_bAutoHideToolbar);
4650 g_MainToolbar->SetAutoHideTimer(g_nAutoHideToolbar);
4651 }
4652
4653#ifdef ANDROID
4654 if (g_MainToolbar)
4655 m_data_monitor->Move(g_MainToolbar->GetToolbarRect().x +
4656 g_MainToolbar->GetToolbarRect().width,
4657 3 * GetCharHeight());
4658#else
4659 m_data_monitor->Center();
4660#endif
4661
4662 break;
4663 }
4664
4665 case 4: {
4666 int sx, sy;
4667 pConfig->SetPath("/Settings");
4668 pConfig->Read("OptionsSizeX", &sx, -1);
4669 pConfig->Read("OptionsSizeY", &sy, -1);
4670
4671 wxWindow *optionsParent = this;
4672#ifdef __WXOSX__
4673 optionsParent = GetPrimaryCanvas();
4674#endif
4675 // g_options = new options(optionsParent, -1, _("Options"), wxPoint(-1,
4676 // -1),
4677 // wxSize(sx, sy));
4678
4679 BuildiENCToolbar(true);
4680
4681 break;
4682 }
4683
4684 case 5: {
4685 // FIXME (leamas) Remove, delegate to CmdlineClient ctor
4686 if (!g_params.empty()) {
4687 for (size_t n = 0; n < g_params.size(); n++) {
4688 wxString path = g_params[n];
4689 if (::wxFileExists(path)) {
4691 pSet->load_file(path.fn_str());
4692 int wpt_dups;
4693
4694 pSet->LoadAllGPXObjects(
4695 !pSet->IsOpenCPN(), wpt_dups,
4696 true); // Import with full vizibility of names and objects
4697 LLBBox box = pSet->GetBBox();
4698 if (box.GetValid()) {
4699 CenterView(GetPrimaryCanvas(), box);
4700 }
4701 delete pSet;
4702 }
4703 }
4704 }
4705 break;
4706 }
4707 case 6: {
4708 InitAppMsgBusListener();
4710
4711 // if WMM is not in use..
4712 // set the Mag Variation to the user specified value
4713 auto loader = PluginLoader::GetInstance();
4714 bool b_haveWMM = loader && loader->IsPlugInAvailable("WMM");
4715 if (!b_haveWMM) gVar = g_UserVar;
4716
4717 break;
4718 }
4719
4720 case 7: {
4721 // Load the waypoints. Both of these routines are very slow to execute
4722 // which is why they have been to defered until here
4723 auto colour_func = [](wxString c) { return GetGlobalColor(c); };
4724 pWayPointMan = new WayPointman(colour_func);
4725 WayPointmanGui(*pWayPointMan)
4726 .SetColorScheme(global_color_scheme, g_Platform->GetDisplayDPmm());
4727 // Reload the ownship icon from UserIcons, if present
4728 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4729 ChartCanvas *cc = g_canvasArray.Item(i);
4730 if (cc) {
4731 if (cc->SetUserOwnship()) cc->SetColorScheme(global_color_scheme);
4732 }
4733 }
4734
4735 NavObj_dB::GetInstance().ImportLegacyNavobj(this);
4736 NavObj_dB::GetInstance().LoadNavObjects();
4737
4738 // Re-enable anchor watches if set in config file
4739 if (!g_AW1GUID.IsEmpty()) {
4740 pAnchorWatchPoint1 = pWayPointMan->FindRoutePointByGUID(g_AW1GUID);
4741 }
4742 if (!g_AW2GUID.IsEmpty()) {
4743 pAnchorWatchPoint2 = pWayPointMan->FindRoutePointByGUID(g_AW2GUID);
4744 }
4745
4746 // Import Layer-wise any .gpx files from /layers directory
4747 wxString layerdir = g_Platform->GetPrivateDataDir();
4748 appendOSDirSlash(&layerdir);
4749 layerdir.Append("layers");
4750
4751 if (wxDir::Exists(layerdir)) {
4752 wxString laymsg;
4753 laymsg.Printf("Getting .gpx layer files from: %s", layerdir.c_str());
4754 wxLogMessage(laymsg);
4755 pConfig->LoadLayers(layerdir);
4756 }
4757 break;
4758 }
4759
4760 default: {
4761 // Last call....
4762 wxLogMessage("OnInitTimer...Last Call");
4763
4764 RequestNewMasterToolbar();
4765
4766 PositionIENCToolbar();
4767
4768 g_bDeferredInitDone = true;
4769
4770 gFrame->DoChartUpdate();
4771 FontMgr::Get()
4772 .ScrubList(); // Clean the font list, removing nonsensical entries
4773
4774 gFrame->ReloadAllVP(); // once more, and good to go
4775 // gFrame->Refresh(false);
4776 // gFrame->Raise();
4777
4778 GetPrimaryCanvas()->SetFocus();
4779 GetPrimaryCanvas()->Enable();
4780 g_focusCanvas = GetPrimaryCanvas();
4781
4782#ifndef __ANDROID__
4783 // gFrame->Raise();
4784#endif
4785
4786 if (b_reloadForPlugins) {
4787 // If any PlugIn implements PlugIn Charts, we need to re-run the
4788 // initial chart load logic to select the correct chart as saved from
4789 // the last run of the app. This will be triggered at the next
4790 // DoChartUpdate()
4791 if (g_pi_manager->IsAnyPlugInChartEnabled()) {
4792 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4793 ChartCanvas *cc = g_canvasArray.Item(i);
4794 if (cc) cc->SetFirstAuto(true);
4795 }
4796 }
4797
4798 DoChartUpdate();
4799 ChartsRefresh();
4800 }
4801
4802 wxLogMessage("OnInitTimer...Finalize Canvases");
4803
4804 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
4805 ChartCanvas *cc = g_canvasArray.Item(i);
4806 if (cc) {
4807 cc->CreateMUIBar();
4808 cc->CheckGroupValid();
4809 }
4810 }
4811
4812#ifdef __ANDROID__
4813 androidEnableBackButton(true);
4814 androidEnableRotation();
4815 androidEnableOptionItems(true);
4816 androidLastCall();
4817#endif
4818
4819 // if (g_MainToolbar) g_MainToolbar->EnableTool(ID_SETTINGS, true);
4820
4821 if (g_start_fullscreen) ToggleFullScreen();
4822
4823 UpdateStatusBar();
4824 SendSizeEvent();
4825
4826 // Start up the tickers....
4827 gFrame->FrameTimer1.Start(TIMER_GFRAME_1, wxTIMER_CONTINUOUS);
4828 // Start up the ViewPort Rotation angle Averaging Timer....
4829 gFrame->FrameCOGTimer.Start(2000, wxTIMER_CONTINUOUS);
4830 // Start up the Ten Hz timer....
4831 gFrame->FrameTenHzTimer.Start(100, wxTIMER_CONTINUOUS);
4832
4833 break;
4834 }
4835 } // switch
4836
4837 if (!g_bDeferredInitDone) InitTimer.Start(10, wxTIMER_ONE_SHOT);
4838
4839 wxLog::FlushActive();
4840
4841 RefreshAllCanvas(true);
4842 wxGetApp().m_usb_watcher.Start();
4843}
4844
4845wxDEFINE_EVENT(EVT_BASIC_NAV_DATA, ObservedEvt);
4846wxDEFINE_EVENT(EVT_GPS_WATCHDOG, ObservedEvt);
4847
4848void MyFrame::InitAppMsgBusListener() {
4849 auto &msgbus = AppMsgBus::GetInstance();
4850
4851 // BasicNavData
4852 AppMsg msg_basic(AppMsg::Type::BasicNavData);
4853 listener_basic_navdata.Listen(msg_basic, this, EVT_BASIC_NAV_DATA);
4854
4855 Bind(EVT_BASIC_NAV_DATA, [&](ObservedEvt ev) {
4856 auto ptr = ev.GetSharedPtr();
4857 auto basicnav_msg = std::static_pointer_cast<const BasicNavDataMsg>(ptr);
4858 HandleBasicNavMsg(basicnav_msg);
4859 });
4860
4861 // GPS Watchdog expiry status
4862 AppMsg msg_watchdog(AppMsg::Type::GPSWatchdog);
4863 listener_gps_watchdog.Listen(msg_watchdog, this, EVT_GPS_WATCHDOG);
4864
4865 Bind(EVT_GPS_WATCHDOG, [&](ObservedEvt ev) {
4866 auto ptr = ev.GetSharedPtr();
4867 auto msg = std::static_pointer_cast<const GPSWatchdogMsg>(ptr);
4868 HandleGPSWatchdogMsg(msg);
4869 });
4870}
4871
4873#ifdef __ANDROID__
4875void MyFrame::ReleaseApiListeners() {}
4876
4877#else
4879 auto &server = LocalServerApi::GetInstance();
4880 m_on_raise_listener.Init(server.on_raise, [&](ObservedEvt) { Raise(); });
4881 m_on_quit_listener.Init(server.on_quit, [&](ObservedEvt) { FastClose(); });
4882 server.SetGetRestApiEndpointCb(
4883 [&] { return wxGetApp().m_rest_server.GetEndpoint(); });
4884 server.open_file_cb = [](const std::string &path) {
4885 return wxGetApp().OpenFile(path);
4886 };
4887}
4888
4889void MyFrame::ReleaseApiListeners() { LocalServerApi::ReleaseInstance(); }
4890#endif
4891
4892void MyFrame::HandleGPSWatchdogMsg(std::shared_ptr<const GPSWatchdogMsg> msg) {
4893 if (msg->gps_watchdog <= 0) {
4894 if (msg->wd_source == GPSWatchdogMsg::WDSource::position) {
4895 bool last_bGPSValid = bGPSValid;
4896 bGPSValid = false;
4897 m_fixtime = 0; // Invalidate fix time
4898 if (last_bGPSValid != bGPSValid) UpdateGPSCompassStatusBoxes(true);
4899
4900 // Possible notification on position watchdog timeout...
4901 // if fix has been valid for at least 5 minutes, and then lost,
4902 // then post a critical notification
4903 if (m_fix_start_time.IsValid()) {
4904 wxDateTime now = wxDateTime::Now();
4905 wxTimeSpan span = now - m_fix_start_time;
4906 if (span.IsLongerThan(wxTimeSpan(0, 5))) {
4907 auto &noteman = NotificationManager::GetInstance();
4908 wxString msg = _("GNSS Position fix lost");
4909 noteman.AddNotification(NotificationSeverity::kCritical,
4910 msg.ToStdString());
4911 m_fix_start_time = wxInvalidDateTime;
4912 }
4913 }
4914
4915 } else if (msg->wd_source == GPSWatchdogMsg::WDSource::velocity) {
4916 bool last_bVelocityValid = bVelocityValid;
4917 bVelocityValid = false;
4918 }
4919
4920 UpdateStatusBar();
4921 }
4922}
4923
4924void MyFrame::CalculateCOGAverage() {
4925 // Maintain average COG for Course Up Mode
4926 if (!std::isnan(gCog)) {
4927 if (g_COGAvgSec > 0) {
4928 // Make a hole
4929 for (int i = g_COGAvgSec - 1; i > 0; i--) COGTable[i] = COGTable[i - 1];
4930 COGTable[0] = gCog;
4931
4932 double sum = 0., count = 0;
4933 for (int i = 0; i < g_COGAvgSec; i++) {
4934 double adder = COGTable[i];
4935 if (std::isnan(adder)) continue;
4936
4937 if (fabs(adder - g_COGAvg) > 180.) {
4938 if ((adder - g_COGAvg) > 0.)
4939 adder -= 360.;
4940 else
4941 adder += 360.;
4942 }
4943
4944 sum += adder;
4945 count++;
4946 }
4947 sum /= count;
4948
4949 if (sum < 0.)
4950 sum += 360.;
4951 else if (sum >= 360.)
4952 sum -= 360.;
4953
4954 g_COGAvg = sum;
4955 } else
4956 g_COGAvg = gCog;
4957 }
4958}
4959
4960void MyFrame::HandleBasicNavMsg(std::shared_ptr<const BasicNavDataMsg> msg) {
4961 m_fixtime = msg->time;
4962 double hdt_data_interval = 0;
4963 double fix_time_interval = 0;
4964
4965 double msgtime = msg->set_time.tv_sec;
4966 double m1 = msg->set_time.tv_nsec / 1e9;
4967 msgtime += m1;
4968
4969 if (((msg->vflag & POS_UPDATE) == POS_UPDATE) &&
4970 ((msg->vflag & POS_VALID) == POS_VALID)) {
4971 // Maintain valid fix start time
4972 if (!m_fix_start_time.IsValid()) {
4973 m_fix_start_time = wxDateTime::Now();
4974 }
4975
4976 // Check the position change, looking for a valid new fix.
4977 double dist, brg;
4978 DistanceBearingMercator(gLat, gLon, gLat_gt, gLon_gt, &brg, &dist);
4979
4980 if (dist > .0001) { // Avoid duplicate position report
4981 fix_time_gt_last = fix_time_gt;
4982 uint64_t fix_time_gt_now =
4983 msg->set_time.tv_sec * 1e9 + msg->set_time.tv_nsec;
4984 fix_time_interval = (fix_time_gt_now - fix_time_gt_last) / (double)1e9;
4985 // printf("interval: %g\n", fix_time_interval);
4986
4987 // Calculate an implied SOG from the position change and time interval
4988 double implied_sog = dist / (fix_time_interval / 3600);
4989
4990 // printf ("Fix Interval: %g\n", fix_time_interval);
4991 // printf("SOG est: %g %g\n", gSog, implied_sog);
4992 // shuffle history data
4993 gLat_gt_m1 = gLat_gt;
4994 gLon_gt_m1 = gLon_gt;
4995 gLat_gt = gLat;
4996 gLon_gt = gLon;
4997
4998 fix_time_gt = fix_time_gt_now;
4999 }
5000 }
5001
5002 if (((msg->vflag & COG_UPDATE) == COG_UPDATE) &&
5003 ((msg->vflag & SOG_UPDATE) == SOG_UPDATE)) {
5004 gCog_gt_m1 = gCog_gt;
5005 gCog_gt = gCog;
5006 gSog_gt = gSog;
5007
5008 // In every case, if SOG is too slow, the COG is undefined.
5009 if (gSog < 0.1) {
5010 gCog_gt = NAN;
5011 gCog_gt_m1 = NAN;
5012 }
5013
5014 if (!std::isnan(gCog_gt_m1)) { // Startup
5015#if 0
5016 if ((fabs(gSog - implied_sog) / gSog) > 0.5) {
5017 // Probably a synthetic data stream, with multiple position sources.
5018 // Do not try to interpolate position at 10 Hz.
5019 gSog_gt = 0;
5020 cog_rate_gt = 0;
5021 } else
5022#endif
5023 if ((fix_time_gt - fix_time_gt_last) > .08) {
5024 // Calculate an estimated Rate-of-turn
5025 int dir = 0;
5026 double diff = 0;
5027 double difft = 0;
5028 if (gCog_gt > gCog_gt_m1) {
5029 if ((gCog_gt - gCog_gt_m1) > 180.)
5030 dir = 1; // left
5031 else
5032 dir = 2; // right
5033 } else {
5034 if ((gCog_gt_m1 - gCog_gt) > 180.)
5035 dir = 2; // right
5036 else
5037 dir = 1; // left
5038 }
5039 difft = fabs(gCog_gt - gCog_gt_m1);
5040 if (fabs(difft > 180.)) difft = fabs(difft - 360.);
5041 if (dir == 1)
5042 diff = -difft;
5043 else
5044 diff = difft;
5045
5046 // double diff = gCog_gt - gCog_gt_m1;
5047 // printf("diff %g %d\n", diff, dir);
5048 double tentative_cog_rate_gt = diff / (fix_time_gt - fix_time_gt_last);
5049 tentative_cog_rate_gt *= 1e9; // degrees / sec
5050 cog_rate_gt = tentative_cog_rate_gt;
5051 }
5052
5053 gCog = gCog_gt_m1;
5054 }
5055 // printf("cog_rate_gt %g %g\n", gCog, cog_rate_gt);
5056 }
5057
5058 if ((msg->vflag & HDT_UPDATE) == HDT_UPDATE) {
5059#if 0
5060// Lowpass filter, 10 samples
5061static double hdt_avg;
5062 double hdt_norm = gHdt;
5063 if(gHdt > 180) hdt_norm -= 360;
5064
5065 hdt_avg *= 0.9;
5066 hdt_avg += hdt_norm * 0.1;
5067 gHdt = hdt_avg;
5068 if( gHdt < 0) gHdt += 360.;
5069#endif
5070
5071 if (!std::isnan(gHdt)) {
5072 // Prepare to estimate the gHdt from prior ground truth measurements
5073 uint64_t hdt_time_gt_last = hdt_time_gt;
5074 hdt_time_gt = msg->set_time.tv_sec * 1e9 + msg->set_time.tv_nsec;
5075 hdt_data_interval = (hdt_time_gt - hdt_time_gt_last) / 1e9;
5076
5077 // Skip data reports that come too frequently
5078 if (hdt_data_interval > .09) {
5079 // shuffle points
5080 gHdt_gt_m1 = gHdt_gt;
5081 gHdt_gt = gHdt;
5082
5083 if (!std::isnan(gHdt_gt_m1)) { // startup
5084 // Calculate an estimated Rate-of-change of gHdt
5085 double tentative_hdt_rate_gt =
5086 (gHdt_gt - gHdt_gt_m1) / (hdt_time_gt - hdt_time_gt_last);
5087 tentative_hdt_rate_gt *= 1e9; // degrees / sec
5088 // Sanity check, and resolve the "phase" problem at +/- North
5089 if (fabs(tentative_hdt_rate_gt - hdt_rate_gt) < 180.)
5090 hdt_rate_gt = tentative_hdt_rate_gt;
5091
5092 gHdt = gHdt_gt_m1;
5093 }
5094 }
5095 }
5096 }
5097
5098 if (std::isnan(gHdt)) gHdt_gt = NAN; // Handle loss of signal
5099
5100 // Some housekeeping
5101 CalculateCOGAverage();
5102 FilterCogSog();
5103
5104 // Maintain the GPS position validity flag
5105 // Determined by source validity of RMC, GGA, GLL (N0183)
5106 // or PGNs 129029, 129025 (N2K)
5107 // Positions by sK and AIVDO are assumed valid
5108 bool last_bGPSValid = bGPSValid;
5109 if ((msg->vflag & POS_UPDATE) == POS_UPDATE) {
5110 if ((msg->vflag & POS_VALID) == POS_VALID)
5111 bGPSValid = true;
5112 else
5113 bGPSValid = false;
5114 }
5115 if (last_bGPSValid != bGPSValid) UpdateGPSCompassStatusBoxes(true);
5116
5117 bVelocityValid = true;
5118 UpdateStatusBar();
5119}
5120
5121void MyFrame::UpdateStatusBar() {
5122 // Show a little heartbeat tick in StatusWindow0 on NMEA events
5123 // But no faster than 10 hz.
5124 unsigned long uiCurrentTickCount;
5125 m_MMEAeventTime.SetToCurrent();
5126 uiCurrentTickCount =
5127 m_MMEAeventTime.GetMillisecond() / 100; // tenths of a second
5128 uiCurrentTickCount += m_MMEAeventTime.GetTicks() * 10;
5129 if (uiCurrentTickCount > m_ulLastNMEATicktime + 1) {
5130 m_ulLastNMEATicktime = uiCurrentTickCount;
5131
5132 if (m_tick_idx++ > 6) m_tick_idx = 0;
5133 }
5134
5135 // Show gLat/gLon in StatusWindow0
5136
5137 if (NULL != GetStatusBar()) {
5138 if (1 /*pos_valid*/) {
5139 char tick_buf[2];
5140 tick_buf[0] = nmea_tick_chars[m_tick_idx];
5141 tick_buf[1] = 0;
5142
5143 wxString s1(tick_buf, wxConvUTF8);
5144 s1 += _(" Ship ");
5145 s1 += toSDMM(1, gLat);
5146 s1 += " ";
5147 s1 += toSDMM(2, gLon);
5148
5149 if (STAT_FIELD_TICK >= 0) SetStatusText(s1, STAT_FIELD_TICK);
5150 }
5151
5152 wxString sogcog;
5153 if (!std::isnan(gSog))
5154 sogcog.Printf("SOG %2.2f " + getUsrSpeedUnit() + " ", toUsrSpeed(gSog));
5155 else
5156 sogcog.Printf("SOG --- ");
5157
5158 wxString cogs;
5159 // We show COG only if SOG is > 0.05
5160 if (!std::isnan(gCog) && !std::isnan(gSog) && (gSog > 0.05)) {
5161 if (g_bShowTrue)
5162 cogs << wxString::Format(wxString("COG %03d%c "), (int)gCog, 0x00B0);
5163 if (g_bShowMag)
5164 cogs << wxString::Format(wxString("COG %03d%c(M) "),
5165 (int)toMagnetic(gCog), 0x00B0);
5166 } else
5167 cogs.Printf(("COG ---%c"), 0x00B0);
5168
5169 sogcog.Append(cogs);
5170 SetStatusText(sogcog, STAT_FIELD_SOGCOG);
5171 }
5172}
5173
5174// Manage the application memory footprint on a periodic schedule
5175void MyFrame::OnMemFootTimer(wxTimerEvent &event) {
5176 MemFootTimer.Stop();
5177
5178 int memsize = GetApplicationMemoryUse();
5179
5180 g_MemFootMB = 100;
5181 printf("Memsize: %d \n", memsize);
5182 // The application memory usage has exceeded the target, so try to manage it
5183 // down....
5184 if (memsize > (g_MemFootMB * 1000)) {
5185 ChartCanvas *cc = GetPrimaryCanvas();
5186 if (ChartData && cc) {
5187 // Get a local copy of the cache info
5188 wxArrayPtrVoid *pCache = ChartData->GetChartCache();
5189 unsigned int nCache = pCache->GetCount();
5190 CacheEntry *pcea = new CacheEntry[nCache];
5191
5192 for (unsigned int i = 0; i < nCache; i++) {
5193 CacheEntry *pce = (CacheEntry *)(pCache->Item(i));
5194 pcea[i] = *pce; // ChartBase *Ch = (ChartBase *)pce->pChart;
5195 }
5196
5197 if (nCache > 1) {
5198 // Bubble Sort the local cache entry array
5199 bool b_cont = true;
5200 while (b_cont) {
5201 b_cont = false;
5202 for (unsigned int i = 0; i < nCache - 1; i++) {
5203 if (pcea[i].RecentTime > pcea[i + 1].RecentTime) {
5204 CacheEntry tmp = pcea[i];
5205 pcea[i] = pcea[i + 1];
5206 pcea[i + 1] = tmp;
5207 b_cont = true;
5208 break;
5209 }
5210 }
5211 }
5212
5213 // Free up some chart cache entries until the memory footprint target
5214 // is realized
5215
5216 unsigned int idelete = 0; // starting at top. which is oldest
5217 unsigned int idelete_max = pCache->GetCount();
5218
5219 // How many can be deleted?
5220 unsigned int minimum_cache = 1;
5221 if (cc->GetQuiltMode()) minimum_cache = cc->GetQuiltChartCount();
5222
5223 while ((memsize > (g_MemFootMB * 1000)) &&
5224 (pCache->GetCount() > minimum_cache) &&
5225 (idelete < idelete_max)) {
5226 int memsizeb = memsize;
5227
5228 ChartData->DeleteCacheChart((ChartBase *)pcea[idelete].pChart);
5229 idelete++;
5230 memsize = GetApplicationMemoryUse();
5231 printf("delete, before: %d after: %d\n", memsizeb, memsize);
5232 }
5233 }
5234
5235 delete[] pcea;
5236 }
5237 }
5238
5239 MemFootTimer.Start(9000, wxTIMER_CONTINUOUS);
5240}
5241
5242int ut_index;
5243
5244void MyFrame::CheckToolbarPosition() {
5245#ifdef __WXMAC__
5246 // Manage Full Screen mode on Mac Mojave 10.14
5247 static bool bMaximized;
5248
5249 if (IsMaximized() && !bMaximized) {
5250 bMaximized = true;
5251 if (g_MainToolbar) {
5252 g_MainToolbar->SetYAuxOffset(g_MainToolbar->GetToolSize().y * 15 / 10);
5253 g_MainToolbar->SetDefaultPosition();
5254 g_MainToolbar->Realize();
5255 }
5256 PositionIENCToolbar();
5257 } else if (!IsMaximized() && bMaximized) {
5258 bMaximized = false;
5259 if (g_MainToolbar) {
5260 g_MainToolbar->SetYAuxOffset(0);
5261 g_MainToolbar->SetDockY(-1);
5262 g_MainToolbar->SetDefaultPosition();
5263 g_MainToolbar->Realize();
5264 }
5265 PositionIENCToolbar();
5266 }
5267#endif
5268}
5269
5270void MyFrame::ProcessUnitTest() {
5271 if (!g_bPauseTest && (g_unit_test_1 || g_unit_test_2)) {
5272 // if((0 == ut_index) && GetQuiltMode())
5273 // ToggleQuiltMode();
5274
5275 // We use only one canvas for the unit tests, so far...
5276 ChartCanvas *cc = GetPrimaryCanvas();
5277
5278 cc->m_bFollow = false;
5279 if (g_MainToolbar && g_MainToolbar->GetToolbar())
5280 g_MainToolbar->GetToolbar()->ToggleTool(ID_FOLLOW, cc->m_bFollow);
5281 int ut_index_max = ((g_unit_test_1 > 0) ? (g_unit_test_1 - 1) : INT_MAX);
5282
5283 if (ChartData) {
5284 if (cc->m_groupIndex > 0) {
5285 while (ut_index < ChartData->GetChartTableEntries() &&
5286 !ChartData->IsChartInGroup(ut_index, cc->m_groupIndex)) {
5287 ut_index++;
5288 }
5289 }
5290 if (ut_index < ChartData->GetChartTableEntries()) {
5291 // printf("%d / %d\n", ut_index, ChartData->GetChartTableEntries());
5292 const ChartTableEntry *cte = &ChartData->GetChartTableEntry(ut_index);
5293
5294 double clat = (cte->GetLatMax() + cte->GetLatMin()) / 2;
5295 double clon = (cte->GetLonMax() + cte->GetLonMin()) / 2;
5296
5297 vLat = clat;
5298 vLon = clon;
5299
5300 cc->SetViewPoint(clat, clon);
5301
5302 if (cc->GetQuiltMode()) {
5303 if (cc->IsChartQuiltableRef(ut_index))
5304 cc->SelectQuiltRefdbChart(ut_index);
5305 } else
5306 cc->SelectdbChart(ut_index);
5307
5308 double ppm; // final ppm scale to use
5309 if (g_unit_test_1) {
5310 ppm = cc->GetCanvasScaleFactor() / cte->GetScale();
5311 ppm /= 2;
5312 } else {
5313 double rw, rh; // width, height
5314 int ww, wh; // chart window width, height
5315
5316 // width in nm
5317 DistanceBearingMercator(cte->GetLatMin(), cte->GetLonMin(),
5318 cte->GetLatMin(), cte->GetLonMax(), NULL,
5319 &rw);
5320
5321 // height in nm
5322 DistanceBearingMercator(cte->GetLatMin(), cte->GetLonMin(),
5323 cte->GetLatMax(), cte->GetLonMin(), NULL,
5324 &rh);
5325
5326 cc->GetSize(&ww, &wh);
5327 ppm = wxMin(ww / (rw * 1852), wh / (rh * 1852)) * (100 - fabs(clat)) /
5328 90;
5329 ppm = wxMin(ppm, 1.0);
5330 }
5331 cc->SetVPScale(ppm);
5332
5333 cc->ReloadVP();
5334
5335 ut_index++;
5336 if (ut_index > ut_index_max) exit(0);
5337 } else {
5338 _exit(0);
5339 }
5340 }
5341 }
5342}
5343double gCog_last;
5344
5345void MyFrame::OnFrameTenHzTimer(wxTimerEvent &event) {
5346 // Check to see if in non-North-Up mode
5347 bool b_rotate = false;
5348 for (ChartCanvas *cc : g_canvasArray) {
5349 if (cc) b_rotate |= (cc->GetUpMode() != NORTH_UP_MODE);
5350 }
5351
5352 if (!b_rotate && !g_btenhertz) return; // Nothing to do
5353
5354 bool b_update = false;
5355 if (g_btenhertz) {
5356 if (!std::isnan(gCog) && !std::isnan(gSog)) {
5357 // Estimate current state by extrapolating from last "ground truth" state
5358
5359 struct timespec now;
5360 clock_gettime(CLOCK_MONOTONIC, &now);
5361 uint64_t diff = 1e9 * (now.tv_sec) + now.tv_nsec - fix_time_gt;
5362 double diffc = diff / 1e9; // sec
5363
5364 // Set gCog as estimated from last two ground truth fixes
5365 double gCog_tentative = gCog_gt_m1 + (cog_rate_gt * diffc);
5366 if (gCog_tentative >= 360.) gCog_tentative -= 360.;
5367 if (gCog_tentative < 0.) gCog_tentative += 360.;
5368 gCog = gCog_tentative;
5369
5370 // printf(" cog: %g\n", gCog);
5371 // And the same for gHdt
5372 if (!std::isnan(gHdt_gt) && !std::isnan(gHdt_gt_m1)) {
5373 uint64_t diff = 1e9 * (now.tv_sec) + now.tv_nsec - hdt_time_gt;
5374 double diffc = diff / 1e9; // sec
5375 gHdt = gHdt_gt_m1 + (hdt_rate_gt * diffc);
5376 }
5377
5378 // Estimate lat/lon position
5379 if (gSog_gt && !std::isnan(gCog_gt)) {
5380 double delta_t = diffc / 3600; // hours
5381 double distance = gSog_gt * delta_t; // NMi
5382
5383 // spherical (close enough)
5384 double angr = gCog_gt / 180 * M_PI;
5385 double latr = gLat_gt * M_PI / 180;
5386 double D = distance / 3443; // earth radius in nm
5387 double sD = sin(D), cD = cos(D);
5388 double sy = sin(latr), cy = cos(latr);
5389 double sa = sin(angr), ca = cos(angr);
5390
5391 gLon = gLon_gt + asin(sa * sD / cy) * 180 / M_PI;
5392 gLat = asin(sy * cD + cy * sD * ca) * 180 / M_PI;
5393 }
5394 }
5395
5396 b_update = true;
5397 }
5398
5399 // In a valid rotation mode ?
5400 if (b_rotate) {
5401 for (ChartCanvas *cc : g_canvasArray) {
5402 if (cc) cc->DoCanvasCOGSet();
5403 }
5404 b_update = true;
5405 }
5406
5407 if (b_update) {
5408 // printf(" gCog: %g %g\n", gCog, gCog - gCog_last);
5409
5410 for (ChartCanvas *cc : g_canvasArray) {
5411 if (cc) {
5412 if (g_bopengl) {
5413 if (cc->GetUpMode() != NORTH_UP_MODE || cc->m_bFollow) {
5414 cc->DoCanvasUpdate();
5415 } else
5416 cc->Refresh();
5417 }
5418 }
5419 }
5420 }
5421
5422 gCog_last = gCog;
5423 FrameTenHzTimer.Start(100, wxTIMER_CONTINUOUS);
5424}
5425
5426void MyFrame::ProcessQuitFlag() {
5427 // Listen for quitflag to be set, requesting application close
5428 if (quitflag) {
5429 wxLogMessage("Got quitflag from SIGNAL");
5430 FrameTimer1.Stop();
5431 FrameTenHzTimer.Stop();
5432
5433 Close();
5434 return;
5435 }
5436}
5437
5438void MyFrame::ProcessDeferredTrackOn() {
5439 // If tracking carryover was found in config file, enable tracking as soon as
5440 // GPS become valid
5441 if (g_bDeferredStartTrack) {
5442 if (!g_bTrackActive) {
5443 if (bGPSValid) {
5444 gFrame->TrackOn();
5445 g_bDeferredStartTrack = false;
5446 }
5447 } else { // tracking has been manually activated
5448 g_bDeferredStartTrack = false;
5449 }
5450 }
5451}
5452
5453void MyFrame::ProcessAnchorWatch() {
5454 // Check for anchorwatch alarms // pjotrc
5455 // 2010.02.15
5456 if (pAnchorWatchPoint1) {
5457 double dist;
5458 double brg;
5459 DistanceBearingMercator(pAnchorWatchPoint1->m_lat,
5460 pAnchorWatchPoint1->m_lon, gLat, gLon, &brg, &dist);
5461 double d = g_nAWMax;
5462 (pAnchorWatchPoint1->GetName()).ToDouble(&d);
5463 d = AnchorDistFix(d, AnchorPointMinDist, g_nAWMax);
5464 bool toofar = false;
5465 bool tooclose = false;
5466 if (d >= 0.0) toofar = (dist * 1852. > d);
5467 if (d < 0.0) tooclose = (dist * 1852 < -d);
5468
5469 if (tooclose || toofar)
5470 AnchorAlertOn1 = true;
5471 else
5472 AnchorAlertOn1 = false;
5473 } else
5474 AnchorAlertOn1 = false;
5475
5476 if (pAnchorWatchPoint2) {
5477 double dist;
5478 double brg;
5479 DistanceBearingMercator(pAnchorWatchPoint2->m_lat,
5480 pAnchorWatchPoint2->m_lon, gLat, gLon, &brg, &dist);
5481
5482 double d = g_nAWMax;
5483 (pAnchorWatchPoint2->GetName()).ToDouble(&d);
5484 d = AnchorDistFix(d, AnchorPointMinDist, g_nAWMax);
5485 bool toofar = false;
5486 bool tooclose = false;
5487 if (d >= 0) toofar = (dist * 1852. > d);
5488 if (d < 0) tooclose = (dist * 1852 < -d);
5489
5490 if (tooclose || toofar)
5491 AnchorAlertOn2 = true;
5492 else
5493 AnchorAlertOn2 = false;
5494 } else
5495 AnchorAlertOn2 = false;
5496
5498 AnchorAlertOn1 = true;
5499}
5500
5501void MyFrame::SendFixToPlugins() {
5502 // Build and send a Position Fix event to PlugIns
5503 if (g_pi_manager) {
5504 GenericPosDatEx GPSData;
5505 GPSData.kLat = gLat;
5506 GPSData.kLon = gLon;
5507 GPSData.kCog = gCog;
5508 GPSData.kSog = gSog;
5509 GPSData.kVar = gVar;
5510 GPSData.kHdm = gHdm;
5511 GPSData.kHdt = gHdt;
5512 GPSData.nSats = g_SatsInView;
5513
5514 wxDateTime tCheck((time_t)m_fixtime);
5515 if (tCheck.IsValid()) {
5516 // As a special case, when no GNSS data is available, m_fixtime is set to
5517 // zero. Note wxDateTime(0) is valid, so the zero value is passed to the
5518 // plugins. The plugins should check for zero and not use the time in that
5519 // case.
5520 GPSData.FixTime = m_fixtime;
5521 } else {
5522 // Note: I don't think this is ever reached, as m_fixtime can never be set
5523 // to wxLongLong(wxINT64_MIN), which is the only way to get here.
5524 GPSData.FixTime = wxDateTime::Now().GetTicks();
5525 }
5526
5527 SendPositionFixToAllPlugIns(&GPSData);
5528 }
5529}
5530
5531void MyFrame::ProcessLogAndBells() {
5532 // Send current nav status data to log file on every half hour // pjotrc
5533 // 2010.02.09
5534 wxDateTime lognow = wxDateTime::Now(); // pjotrc 2010.02.09
5535 int hourLOC = lognow.GetHour();
5536 int minuteLOC = lognow.GetMinute();
5537 lognow.MakeGMT();
5538 int minuteUTC = lognow.GetMinute();
5539 int second = lognow.GetSecond();
5540
5541 wxTimeSpan logspan = lognow.Subtract(g_loglast_time);
5542 if ((logspan.IsLongerThan(wxTimeSpan(0, 30, 0, 0))) || (minuteUTC == 0) ||
5543 (minuteUTC == 30)) {
5544 if (logspan.IsLongerThan(wxTimeSpan(0, 1, 0, 0))) {
5545 wxString day = lognow.FormatISODate();
5546 wxString utc = lognow.FormatISOTime();
5547 wxString navmsg = "LOGBOOK: ";
5548 navmsg += day;
5549 navmsg += " ";
5550 navmsg += utc;
5551 navmsg += " UTC ";
5552
5553 if (bGPSValid) {
5554 wxString data;
5555 data.Printf(" GPS Lat %10.5f Lon %10.5f ", gLat, gLon);
5556 navmsg += data;
5557
5558 wxString cog;
5559 if (std::isnan(gCog))
5560 cog.Printf("COG ----- ");
5561 else
5562 cog.Printf("COG %10.5f ", gCog);
5563
5564 wxString sog;
5565 if (std::isnan(gSog))
5566 sog.Printf("SOG ----- ");
5567 else
5568 sog.Printf("SOG %6.2f " + getUsrSpeedUnit(), toUsrSpeed(gSog));
5569
5570 navmsg += cog;
5571 navmsg += sog;
5572 } else {
5573 wxString data;
5574 data.Printf(" DR Lat %10.5f Lon %10.5f", gLat, gLon);
5575 navmsg += data;
5576 }
5577 wxLogMessage(navmsg);
5578 g_loglast_time = lognow;
5579
5580 int bells = (hourLOC % 4) * 2; // 2 bells each hour
5581 if (minuteLOC != 0) bells++; // + 1 bell on 30 minutes
5582 if (!bells) bells = 8; // 0 is 8 bells
5583
5584 if (g_bPlayShipsBells && ((minuteLOC == 0) || (minuteLOC == 30))) {
5585 m_BellsToPlay = bells;
5586 wxCommandEvent ev(BELLS_PLAYED_EVTYPE);
5587 wxPostEvent(this, ev);
5588 }
5589 }
5590 }
5591}
5592
5593void MyFrame::OnFrameTimer1(wxTimerEvent &event) {
5594 CheckToolbarPosition();
5595
5596 ProcessUnitTest();
5597 g_tick++;
5598 ProcessQuitFlag();
5599
5600 if (bDBUpdateInProgress) return;
5601
5602 FrameTimer1.Stop();
5603 FrameTenHzTimer.Stop();
5604
5605 ProcessDeferredTrackOn();
5606 SendFixToPlugins();
5607 ProcessAnchorWatch();
5608 ProcessLogAndBells();
5609
5610 if (ShouldRestartTrack()) TrackDailyRestart();
5611
5612 // If no alerts are on, then safe to resume sleeping
5613 if (g_bSleep && !AnchorAlertOn1 && !AnchorAlertOn2) {
5614 FrameTimer1.Start(TIMER_GFRAME_1, wxTIMER_CONTINUOUS);
5615 FrameTenHzTimer.Start(100, wxTIMER_CONTINUOUS);
5616 return;
5617 }
5618
5619 // If gSog is greater than some threshold,
5620 // we determine that we are"cruising"
5621 if (gSog > 3.0) g_bCruising = true;
5622
5623 // Update the Toolbar Status windows and lower status bar
5624 // just after start of ticks.
5625
5626 if (g_tick == 2) {
5627 wxString sogcog("SOG --- " + getUsrSpeedUnit() + +" " +
5628 " COG ---\u00B0");
5629 if (GetStatusBar()) SetStatusText(sogcog, STAT_FIELD_SOGCOG);
5630
5631 gCog = 0.0; // say speed is zero to kill ownship predictor
5632 }
5633
5634 // Update the chart database and displayed chart
5635 bool bnew_view = false;
5636 if (!g_btenhertz) bnew_view = DoChartUpdate();
5637
5638 nBlinkerTick++;
5639
5641
5642 // This call sends autopilot output strings to output ports.
5643 bool bactiveRouteUpdate = RoutemanGui(*g_pRouteMan).UpdateProgress();
5644
5645 // For each canvas....
5646 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
5647 ChartCanvas *cc = g_canvasArray.Item(i);
5648 if (cc) {
5649 cc->DrawBlinkObjects();
5650
5651 // Update the active route, if any, as determined above
5652 if (bactiveRouteUpdate) {
5653 // This RefreshRect will cause any active routepoint to blink
5654 if (g_pRouteMan->GetpActiveRoute())
5655 cc->RefreshRect(g_blink_rect, false);
5656 }
5657
5658 // Force own-ship drawing parameters
5659 cc->SetOwnShipState(SHIP_NORMAL);
5660
5661 if (cc->GetQuiltMode()) {
5662 double erf = cc->GetQuiltMaxErrorFactor();
5663 if (erf > 0.02) cc->SetOwnShipState(SHIP_LOWACCURACY);
5664 } else {
5665 if (cc->m_singleChart) {
5666 if (cc->m_singleChart->GetChart_Error_Factor() > 0.02)
5667 cc->SetOwnShipState(SHIP_LOWACCURACY);
5668 }
5669 }
5670
5671 if (!bGPSValid) cc->SetOwnShipState(SHIP_INVALID);
5672
5673 if ((bGPSValid != m_last_bGPSValid) ||
5674 (bVelocityValid != m_last_bVelocityValid) ||
5675 (!isnan(gHdt) && (gHdt != m_last_hdt))) {
5676 if (!g_bopengl) cc->UpdateShips();
5677
5678 bnew_view = true; // force a full Refresh()
5679 }
5680 }
5681 }
5682
5683 m_last_bGPSValid = bGPSValid;
5684 m_last_bVelocityValid = bVelocityValid;
5685 m_last_hdt = gHdt;
5686
5687 // If any PlugIn requested dynamic overlay callbacks, force a full canvas
5688 // refresh thus, ensuring at least 1 Hz. callback.
5689 bool brq_dynamic = false;
5690 if (g_pi_manager) {
5691 auto *pplugin_array = PluginLoader::GetInstance()->GetPlugInArray();
5692 for (unsigned int i = 0; i < pplugin_array->GetCount(); i++) {
5693 PlugInContainer *pic = pplugin_array->Item(i);
5694 if (pic->m_enabled && pic->m_init_state) {
5695 if (pic->m_cap_flag & WANTS_DYNAMIC_OPENGL_OVERLAY_CALLBACK) {
5696 brq_dynamic = true;
5697 break;
5698 }
5699 }
5700 }
5701
5702 if (brq_dynamic) bnew_view = true;
5703 }
5704
5705 // Make sure we get a redraw and alert sound on AnchorWatch excursions.
5706 if (AnchorAlertOn1 || AnchorAlertOn2) bnew_view = true;
5707
5708 // For each canvas....
5709 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
5710 ChartCanvas *cc = g_canvasArray.Item(i);
5711 if (cc) {
5712 if (g_bopengl) {
5713#ifdef ocpnUSE_GL
5714 if (cc->GetglCanvas()) {
5715 // Rotation is handled by 10Hz timer, do not duplicate here
5716 bool b_rotate = cc->GetUpMode() != NORTH_UP_MODE;
5717 if (!b_rotate) {
5718 if (!g_btenhertz) {
5719 if (cc->m_bFollow) {
5720 cc->DoCanvasUpdate();
5721 if (bnew_view)
5722 cc->Refresh(false); // honor ownship state update
5723 } else
5724 cc->Refresh(false);
5725 } else {
5726 // Pick up SOG=0, COG=NAN report at 10Hz.
5727 if (std::isnan(gCog)) cc->Refresh(false);
5728 }
5729 }
5730 }
5731#endif
5732 } else {
5733 // Invalidate the ChartCanvas window appropriately
5734 // In non-follow mode, invalidate the rectangles containing the AIS
5735 // targets and the ownship, etc... In follow mode, if there has
5736 // already been a full screen refresh, there is no need to check
5737 // ownship or AIS,
5738 // since they will be always drawn on the full screen paint.
5739
5740 if ((!cc->m_bFollow) || (cc->GetUpMode() != NORTH_UP_MODE)) {
5741 cc->UpdateShips();
5742 cc->UpdateAIS();
5743 cc->UpdateAlerts();
5744 } else {
5745 if (!bnew_view) { // There has not been a Refresh() yet.....
5746 cc->UpdateAIS();
5747 cc->UpdateAlerts();
5748 }
5749 }
5750 }
5751 }
5752 }
5753
5754 if (g_pais_query_dialog_active && g_pais_query_dialog_active->IsShown())
5755 g_pais_query_dialog_active->UpdateText();
5756
5757 // Refresh AIS target list every 5 seconds to avoid blinking
5758 if (g_pAISTargetList && (0 == (g_tick % (5))))
5759 g_pAISTargetList->UpdateAISTargetList();
5760
5761 // Pick up any change Toolbar status displays
5762 UpdateGPSCompassStatusBoxes();
5763 UpdateAISTool();
5764
5765 if (console && console->IsShown()) {
5766 // console->Raise();
5767 console->RefreshConsoleData();
5768 }
5769
5770 // This little hack fixes a problem seen with some UniChrome OpenGL drivers
5771 // We need a deferred resize to get glDrawPixels() to work right.
5772 // So we set a trigger to generate a resize after 5 seconds....
5773 // See the "UniChrome" hack elsewhere
5774 if (m_bdefer_resize) {
5775 if (0 == (g_tick % (5))) {
5776 printf("___RESIZE\n");
5777 SetSize(m_defer_size);
5778 g_pauimgr->Update();
5779 m_bdefer_resize = false;
5780 }
5781 }
5782
5783 // Reset pending next AppMsgBus notification
5784
5785 if (g_unit_test_2)
5786 FrameTimer1.Start(TIMER_GFRAME_1 * 3, wxTIMER_CONTINUOUS);
5787 else {
5788 FrameTimer1.Start(TIMER_GFRAME_1, wxTIMER_CONTINUOUS);
5789 FrameTenHzTimer.Start(100, wxTIMER_CONTINUOUS);
5790 }
5791}
5792
5793double MyFrame::GetMag(double a, double lat, double lon) {
5794 double Variance = std::isnan(gVar) ? g_UserVar : gVar;
5795 auto loader = PluginLoader::GetInstance();
5796 if (loader && loader->IsPlugInAvailable("WMM")) {
5797 // Request variation at a specific lat/lon
5798
5799 // Note that the requested value is returned sometime later in the event
5800 // stream, so there may be invalid data returned on the first call to this
5801 // method. In the case of rollover windows, the value is requested
5802 // continuously, so will be correct very soon.
5803 wxDateTime now = wxDateTime::Now();
5804 SendJSON_WMM_Var_Request(lat, lon, now);
5805 if (fabs(gQueryVar) < 360.0) // Don't use WMM variance if not updated yet
5806 Variance = gQueryVar;
5807 }
5808 return toMagnetic(a, Variance);
5809}
5810
5811bool MyFrame::SendJSON_WMM_Var_Request(double lat, double lon,
5812 wxDateTime date) {
5813 if (g_pi_manager) {
5814 wxJSONValue v;
5815 v["Lat"] = lat;
5816 v["Lon"] = lon;
5817 v["Year"] = date.GetYear();
5818 v["Month"] = date.GetMonth();
5819 v["Day"] = date.GetDay();
5820
5821 SendJSONMessageToAllPlugins("WMM_VARIATION_REQUEST", v);
5822 return true;
5823 } else
5824 return false;
5825}
5826
5827void MyFrame::TouchAISActive() {
5828 // .. for each canvas...
5829 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
5830 ChartCanvas *cc = g_canvasArray.Item(i);
5831 if (cc) cc->TouchAISToolActive();
5832 }
5833}
5834
5835void MyFrame::UpdateAISTool() {
5836 if (!g_pAIS) return;
5837
5838 // .. for each canvas...
5839 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
5840 ChartCanvas *cc = g_canvasArray.Item(i);
5841 if (cc) cc->UpdateAISTBTool();
5842 }
5843}
5844
5845// Cause refresh of active Tide/Current data, if displayed
5846void MyFrame::OnFrameTCTimer(wxTimerEvent &event) {
5847 // ..For each canvas...
5848 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
5849 ChartCanvas *cc = g_canvasArray.Item(i);
5850 if (cc) cc->SetbTCUpdate(true);
5851 }
5852
5853 RefreshAllCanvas(false);
5854}
5855
5856// Keep and update the Viewport rotation angle according to average COG for
5857// COGUP mode
5858void MyFrame::OnFrameCOGTimer(wxTimerEvent &event) {
5859 return;
5860
5861 // ..For each canvas...
5862 bool b_rotate = false;
5863 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
5864 ChartCanvas *cc = g_canvasArray.Item(i);
5865 if (cc) b_rotate |= (cc->GetUpMode() != NORTH_UP_MODE);
5866 }
5867
5868 if (!b_rotate) {
5869 FrameCOGTimer.Stop();
5870 return;
5871 }
5872
5873 DoCOGSet();
5874
5875 // Restart the timer, max frequency is 10 hz.
5876 int period_ms = 100;
5877 // if (g_COGAvgSec > 0) period_ms = g_COGAvgSec * 1000;
5878 FrameCOGTimer.Start(period_ms, wxTIMER_CONTINUOUS);
5879}
5880
5881void MyFrame::DoCOGSet() {
5882 // ..For each canvas...
5883 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
5884 ChartCanvas *cc = g_canvasArray.Item(i);
5885 if (cc) cc->DoCanvasCOGSet();
5886 }
5887}
5888
5889void RenderShadowText(wxDC *pdc, wxFont *pFont, wxString &str, int x, int y) {
5890#ifdef DrawText
5891#undef DrawText
5892#define FIXIT
5893#endif
5894
5895 wxFont oldfont = pdc->GetFont(); // save current font
5896
5897 pdc->SetFont(*pFont);
5898 pdc->SetTextForeground(GetGlobalColor("CHGRF"));
5899 pdc->SetBackgroundMode(wxTRANSPARENT);
5900
5901 pdc->DrawText(str, x, y + 1);
5902 pdc->DrawText(str, x, y - 1);
5903 pdc->DrawText(str, x + 1, y);
5904 pdc->DrawText(str, x - 1, y);
5905
5906 pdc->SetTextForeground(GetGlobalColor("CHBLK"));
5907
5908 pdc->DrawText(str, x, y);
5909
5910 pdc->SetFont(oldfont); // restore last font
5911}
5912
5913// TODO How does this relate to per-canvas rotation?
5914void MyFrame::UpdateRotationState(double rotation) {
5915 // If rotated manually, we switch to NORTHUP
5916 g_bCourseUp = false;
5917
5918 if (fabs(rotation) > .001) {
5919 SetMenubarItemState(ID_MENU_CHART_COGUP, false);
5920 SetMenubarItemState(ID_MENU_CHART_NORTHUP, true);
5921 if (m_pMenuBar) {
5922 m_pMenuBar->SetLabel(ID_MENU_CHART_NORTHUP, _("Rotated Mode"));
5923 }
5924 } else {
5925 SetMenubarItemState(ID_MENU_CHART_COGUP, g_bCourseUp);
5926 SetMenubarItemState(ID_MENU_CHART_NORTHUP, !g_bCourseUp);
5927 if (m_pMenuBar) {
5928 m_pMenuBar->SetLabel(ID_MENU_CHART_NORTHUP, _("North Up Mode"));
5929 }
5930 }
5931
5932 UpdateGPSCompassStatusBoxes(true);
5933 DoChartUpdate();
5934}
5935
5936void MyFrame::UpdateGPSCompassStatusBoxes(bool b_force_new) {
5937 // ..For each canvas...
5938 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
5939 ChartCanvas *cc = g_canvasArray.Item(i);
5940 if (cc) cc->UpdateGPSCompassStatusBox(b_force_new);
5941 }
5942}
5943
5944// Application memory footprint management
5945
5946int MyFrame::GetApplicationMemoryUse() {
5947 int memsize = -1;
5948#ifdef __linux__
5949
5950 // Use a contrived ps command to get the virtual memory size associated
5951 // with this process
5952 wxWindow *fWin = wxWindow::FindFocus();
5953
5954 wxArrayString outputArray;
5955 wxString cmd("ps --no-headers -o vsize ");
5956 unsigned long pid = wxGetProcessId();
5957 wxString cmd1;
5958 cmd1.Printf("%ld", pid);
5959 cmd += cmd1;
5960 wxExecute(cmd, outputArray);
5961
5962 if (outputArray.GetCount()) {
5963 wxString s = outputArray.Item(0);
5964 long vtmp;
5965 if (s.ToLong(&vtmp)) memsize = vtmp;
5966 }
5967
5968 if (fWin) fWin->SetFocus();
5969
5970#endif
5971
5972#ifdef __WXMSW__
5973 HANDLE hProcess;
5974 PROCESS_MEMORY_COUNTERS pmc;
5975
5976 unsigned long processID = wxGetProcessId();
5977
5978 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE,
5979 processID);
5980 if (NULL == hProcess) return 0;
5981
5982 if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc))) {
5983 /*
5984 printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount );
5985 printf( "\tPeakWorkingSetSize: 0x%08X\n",
5986 pmc.PeakWorkingSetSize );
5987 printf( "\tWorkingSetSize: 0x%08X\n", pmc.WorkingSetSize );
5988 printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n",
5989 pmc.QuotaPeakPagedPoolUsage );
5990 printf( "\tQuotaPagedPoolUsage: 0x%08X\n",
5991 pmc.QuotaPagedPoolUsage );
5992 printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n",
5993 pmc.QuotaPeakNonPagedPoolUsage );
5994 printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n",
5995 pmc.QuotaNonPagedPoolUsage );
5996 printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage );
5997 printf( "\tPeakPagefileUsage: 0x%08X\n",
5998 pmc.PeakPagefileUsage );
5999 */
6000 memsize = pmc.WorkingSetSize / 1024;
6001 }
6002
6003 CloseHandle(hProcess);
6004
6005#endif
6006
6007 return memsize;
6008}
6009
6010double MyFrame::GetBestVPScale(ChartBase *pchart) {
6011 return GetPrimaryCanvas()->GetBestVPScale(pchart);
6012}
6013
6014void MyFrame::SetChartUpdatePeriod() {
6015 // Set the chart update period based upon chart skew and skew compensator
6016
6017 g_ChartUpdatePeriod = 0; // General default
6018
6019 // In non-GL, singlele-chart mode, rotation of skewed charts is very slow
6020 // So we need to use a slower update time constant to preserve adequate UI
6021 // performance
6022 bool bskewdc = false;
6023 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
6024 ChartCanvas *cc = g_canvasArray.Item(i);
6025 if (cc) {
6026 if (!g_bopengl && !cc->GetVP().b_quilt) {
6027 if (fabs(cc->GetVP().skew) > 0.0001) bskewdc = true;
6028 }
6029 if (cc->m_bFollow) g_ChartUpdatePeriod = 1;
6030 }
6031 }
6032
6033 if (bskewdc) g_ChartUpdatePeriod = g_SkewCompUpdatePeriod;
6034
6035 m_ChartUpdatePeriod = g_ChartUpdatePeriod;
6036}
6037
6038void MyFrame::UpdateControlBar(ChartCanvas *cc) {
6039 if (!cc) return;
6040 cc->UpdateCanvasControlBar();
6041}
6042
6043void MyFrame::selectChartDisplay(int type, int family) {
6044 // ..For each canvas...
6045 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
6046 ChartCanvas *cc = g_canvasArray.Item(i);
6047 if (cc) cc->selectCanvasChartDisplay(type, family);
6048 }
6049
6050 UpdateGlobalMenuItems(); // update the state of the menu items (checkmarks
6051 // etc.)
6052}
6053
6054//----------------------------------------------------------------------------------
6055// DoChartUpdate
6056// Create a chartstack based on current lat/lon.
6057// Return true if a Refresh(false) was called within.
6058//----------------------------------------------------------------------------------
6059bool MyFrame::DoChartUpdate() {
6060 bool return_val = false;
6061
6062 // ..For each canvas...
6063 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
6064 ChartCanvas *cc = g_canvasArray.Item(i);
6065 if (cc) return_val |= cc->DoCanvasUpdate();
6066 }
6067
6068 return return_val;
6069}
6070
6071void MyFrame::MouseEvent(wxMouseEvent &event) {
6072 int x, y;
6073 event.GetPosition(&x, &y);
6074}
6075
6076// Memory monitor support
6077#ifdef __WXMAC__
6078#include <mach/mach.h>
6079#include <mach/message.h> // for mach_msg_type_number_t
6080#include <mach/kern_return.h> // for kern_return_t
6081#include <mach/task_info.h>
6082#include <stdio.h>
6083#include <malloc/malloc.h>
6084#endif
6085
6086#ifdef __WXGTK__
6087#include <malloc.h>
6088#endif
6089
6090#if defined(__linux__)
6091#include "sys/types.h"
6092#include "sys/sysinfo.h"
6093#endif /* __linux__ */
6094
6095void MyFrame::DoPrint(void) {
6096 // avoid toolbars being printed
6097 g_PrintingInProgress = true;
6098#ifdef ocpnUSE_GL
6099 if (g_bopengl) {
6100 GetPrimaryCanvas()->GetglCanvas()->Render();
6101 GetPrimaryCanvas()->GetglCanvas()->SwapBuffers();
6102 } else
6103#endif
6104 Refresh();
6105
6106 ChartPrintout printout;
6107 if (g_bopengl) {
6108 printout.GenerateGLbmp();
6109 }
6110 auto &printer = PrintDialog::GetInstance();
6111 printer.Initialize(wxLANDSCAPE);
6112 printer.EnablePageNumbers(false);
6113 printer.Print(this, &printout);
6114
6115 // Pass two printout objects: for preview, and possible printing.
6116 /*
6117 wxPrintDialogData printDialogData(* g_printData);
6118 wxPrintPreview *preview = new wxPrintPreview(new MyPrintout, new
6119 MyPrintout, & printDialogData); if (!preview->Ok())
6120 {
6121 delete preview;
6122 OCPNMessageBox(_T("There was a problem previewing.\nPerhaps your current
6123 printer is not set correctly?"), "Previewing", wxOK); return;
6124 }
6125
6126 wxPreviewFrame *frame = new wxPreviewFrame(preview, this, _T("Demo Print
6127 Preview"), wxPoint(100, 100), wxSize(600, 650)); frame->Centre(wxBOTH);
6128 frame->Initialize();
6129 frame->Show();
6130 */
6131 g_PrintingInProgress = false;
6132 Refresh();
6133#ifdef __WXGTK__
6134 GetPrimaryCanvas()->SetFocus();
6135 // Raise(); // I dunno why...
6136#endif
6137}
6138
6139void MyFrame::OnEvtPlugInMessage(OCPN_MsgEvent &event) {
6140 wxString message_ID = event.GetID();
6141 wxString message_JSONText = event.GetJSONText();
6142
6143 // We are free to use or ignore any or all of the PlugIn messages flying
6144 // through this pipe tee.
6145
6146 // We can possibly use the estimated magnetic variation if WMM_pi is
6147 // present, active, and we have no other source of Variation
6148 if (!g_bVAR_Rx) {
6149 if (message_ID == "WMM_VARIATION_BOAT") {
6150 // construct the JSON root object
6151 wxJSONValue root;
6152 // construct a JSON parser
6153 wxJSONReader reader;
6154
6155 // now read the JSON text and store it in the 'root' structure
6156 // check for errors before retreiving values...
6157 int numErrors = reader.Parse(message_JSONText, &root);
6158 if (numErrors > 0) {
6159 // const wxArrayString& errors = reader.GetErrors();
6160 return;
6161 }
6162
6163 // get the DECL value from the JSON message
6164 wxString decl = root["Decl"].AsString();
6165 double decl_val;
6166 decl.ToDouble(&decl_val);
6167
6168 gVar = decl_val;
6169 }
6170 }
6171
6172 if (message_ID == "WMM_VARIATION") {
6173 // construct the JSON root object
6174 wxJSONValue root;
6175 // construct a JSON parser
6176 wxJSONReader reader;
6177
6178 // now read the JSON text and store it in the 'root' structure
6179 // check for errors before retreiving values...
6180 int numErrors = reader.Parse(message_JSONText, &root);
6181 if (numErrors > 0) {
6182 // const wxArrayString& errors = reader.GetErrors();
6183 return;
6184 }
6185
6186 // get the DECL value from the JSON message
6187 wxString decl = root["Decl"].AsString();
6188 double decl_val;
6189 decl.ToDouble(&decl_val);
6190
6191 gQueryVar = decl_val;
6192 }
6193
6194 if (message_ID == "GRIB_TIMELINE") {
6195 wxJSONReader r;
6196 wxJSONValue v;
6197 int numErrors = r.Parse(message_JSONText, &v);
6198
6199 if (numErrors > 0) {
6200 wxLogMessage("GRIB_TIMELINE: JSON parse error");
6201 return;
6202 }
6203
6204 // Store old time source for comparison
6205 wxDateTime oldTimeSource = gTimeSource;
6206
6207 if (v["Day"].AsInt() == -1) {
6208 gTimeSource = wxInvalidDateTime;
6209 wxLogMessage("GRIB_TIMELINE: Reset to system time");
6210 } else {
6211 gTimeSource.Set(v["Day"].AsInt(), (wxDateTime::Month)v["Month"].AsInt(),
6212 v["Year"].AsInt(), v["Hour"].AsInt(), v["Minute"].AsInt(),
6213 v["Second"].AsInt());
6214 }
6215
6216 // Refresh tide displays if time source changed
6217 if (oldTimeSource != gTimeSource) {
6218 // Refresh all canvases that might show tide info
6219 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
6220 ChartCanvas *cc = g_canvasArray.Item(i);
6221 if (cc && (cc->GetbShowTide() || cc->GetbShowCurrent())) {
6222 cc->Refresh(false);
6223
6224 // Also refresh any open tide dialog windows
6225 if (cc->pCwin) { // pCwin is the tide window pointer
6226 cc->pCwin->Refresh(false);
6227 }
6228 }
6229 }
6230 }
6231 }
6232 if (message_ID == "OCPN_TRACK_REQUEST") {
6233 wxJSONValue root;
6234 wxJSONReader reader;
6235 wxString trk_id = wxEmptyString;
6236
6237 int numErrors = reader.Parse(message_JSONText, &root);
6238 if (numErrors > 0) return;
6239
6240 if (root.HasMember("Track_ID")) trk_id = root["Track_ID"].AsString();
6241
6242 wxJSONValue v;
6243 v["Track_ID"] = trk_id;
6244 for (Track *ptrack : g_TrackList) {
6245 wxString name = wxEmptyString;
6246 if (ptrack->m_GUID == trk_id) {
6247 name = ptrack->GetName();
6248 if (name.IsEmpty()) {
6249 TrackPoint *rp = ptrack->GetPoint(0);
6250 if (rp && rp->GetCreateTime().IsValid())
6251 name = rp->GetCreateTime().FormatISODate() + " " +
6252 rp->GetCreateTime().FormatISOTime();
6253 else
6254 name = _("(Unnamed Track)");
6255 }
6256
6257 /* To avoid memory problems send a single trackpoint.
6258 * It's up to the plugin to collect the data. */
6259 int i = 1;
6260 v["error"] = false;
6261 v["TotalNodes"] = ptrack->GetnPoints();
6262 for (int j = 0; j < ptrack->GetnPoints(); j++) {
6263 TrackPoint *tp = ptrack->GetPoint(j);
6264 v["lat"] = tp->m_lat;
6265 v["lon"] = tp->m_lon;
6266 v["NodeNr"] = i;
6267 i++;
6268 wxString msg_id("OCPN_TRACKPOINTS_COORDS");
6269 SendJSONMessageToAllPlugins(msg_id, v);
6270 }
6271 return;
6272 }
6273 v["error"] = true;
6274
6275 wxString msg_id("OCPN_TRACKPOINTS_COORDS");
6276 SendJSONMessageToAllPlugins(msg_id, v);
6277 }
6278 } else if (message_ID == "OCPN_ROUTE_REQUEST") {
6279 wxJSONValue root;
6280 wxJSONReader reader;
6281 wxString guid = wxEmptyString;
6282
6283 int numErrors = reader.Parse(message_JSONText, &root);
6284 if (numErrors > 0) {
6285 return;
6286 }
6287
6288 if (root.HasMember("GUID")) guid = root["GUID"].AsString();
6289
6290 wxJSONValue v;
6291 v["GUID"] = guid;
6292 for (auto it = pRouteList->begin(); it != pRouteList->end(); ++it) {
6293 wxString name = wxEmptyString;
6294
6295 if ((*it)->m_GUID == guid) {
6296 name = (*it)->m_RouteNameString;
6297 if (name.IsEmpty()) name = _("(Unnamed Route)");
6298
6299 v["Name"] = name;
6300 v["error"] = false;
6301 wxJSONValue w;
6302 int i = 0;
6303 for (RoutePointList::iterator itp = (*it)->pRoutePointList->begin();
6304 itp != (*it)->pRoutePointList->end(); itp++) {
6305 w[i]["lat"] = (*itp)->m_lat;
6306 w[i]["lon"] = (*itp)->m_lon;
6307 w[i]["Name"] = (*itp)->GetName();
6308 w[i]["Description"] = (*itp)->GetDescription();
6309 w[i]["GUID"] = (*itp)->m_GUID;
6310 w[i]["ArrivalRadius"] = (*itp)->GetWaypointArrivalRadius();
6311
6312 auto node = (*itp)->m_HyperlinkList->begin();
6313 if (node != (*itp)->m_HyperlinkList->end()) {
6314 int n = 1;
6315 while (node != (*itp)->m_HyperlinkList->end()) {
6316 Hyperlink *httpLink = *node;
6317 v[i]["WPLink" + wxString::Format("%d", n)] = httpLink->Link;
6318 v[i]["WPLinkDesciption" + wxString::Format("%d", n++)] =
6319 httpLink->DescrText;
6320 ++node;
6321 }
6322 }
6323 i++;
6324 }
6325 v["waypoints"] = w;
6326 wxString msg_id("OCPN_ROUTE_RESPONSE");
6327 SendJSONMessageToAllPlugins(msg_id, v);
6328 return;
6329 }
6330 }
6331
6332 v["error"] = true;
6333
6334 wxString msg_id("OCPN_ROUTE_RESPONSE");
6335 SendJSONMessageToAllPlugins(msg_id, v);
6336 } else if (message_ID == "OCPN_ROUTELIST_REQUEST") {
6337 wxJSONValue root;
6338 wxJSONReader reader;
6339 bool route = true;
6340
6341 int numErrors = reader.Parse(message_JSONText, &root);
6342 if (numErrors > 0) return;
6343
6344 if (root.HasMember("mode")) {
6345 wxString str = root["mode"].AsString();
6346 if (str == "Track") route = false;
6347
6348 wxJSONValue v;
6349 int i = 1;
6350 if (route) {
6351 for (RouteList::iterator it = pRouteList->begin();
6352 it != pRouteList->end(); it++) {
6353 wxString name = (*it)->m_RouteNameString;
6354 if (name.IsEmpty()) name = _("(Unnamed Route)");
6355
6356 v[i]["error"] = false;
6357 v[i]["name"] = name;
6358 v[i]["GUID"] = (*it)->m_GUID;
6359 v[i]["active"] = (*it)->IsActive();
6360 i++;
6361 }
6362 } else { // track
6363 for (Track *ptrack : g_TrackList) {
6364 wxString name = ptrack->GetName();
6365 if (name.IsEmpty()) {
6366 TrackPoint *tp = ptrack->GetPoint(0);
6367 if (tp && tp->GetCreateTime().IsValid())
6368 name = tp->GetCreateTime().FormatISODate() + " " +
6369 tp->GetCreateTime().FormatISOTime();
6370 else
6371 name = _("(Unnamed Track)");
6372 }
6373 v[i]["error"] = false;
6374 v[i]["name"] = name;
6375 v[i]["GUID"] = ptrack->m_GUID;
6376 v[i]["active"] = g_pActiveTrack == ptrack;
6377 i++;
6378 }
6379 }
6380 wxString msg_id("OCPN_ROUTELIST_RESPONSE");
6381 SendJSONMessageToAllPlugins(msg_id, v);
6382 } else {
6383 wxJSONValue v;
6384 v[0]["error"] = true;
6385 wxString msg_id("OCPN_ROUTELIST_RESPONSE");
6386 SendJSONMessageToAllPlugins(msg_id, v);
6387 }
6388 } else if (message_ID == "OCPN_ACTIVE_ROUTELEG_REQUEST") {
6389 wxJSONValue v;
6390 v[0]["error"] = true;
6391 if (g_pRouteMan->GetpActiveRoute()) {
6392 if (g_pRouteMan->m_bDataValid) {
6393 v[0]["error"] = false;
6394 v[0]["range"] = g_pRouteMan->GetCurrentRngToActivePoint();
6395 v[0]["bearing"] = g_pRouteMan->GetCurrentBrgToActivePoint();
6396 v[0]["XTE"] = g_pRouteMan->GetCurrentXTEToActivePoint();
6397 v[0]["active_route_GUID"] = g_pRouteMan->GetpActiveRoute()->GetGUID();
6398 v[0]["active_waypoint_lat"] =
6399 g_pRouteMan->GetpActiveRoute()->m_pRouteActivePoint->GetLatitude();
6400 v[0]["active_waypoint_lon"] =
6401 g_pRouteMan->GetpActiveRoute()->m_pRouteActivePoint->GetLongitude();
6402 }
6403 }
6404 wxString msg_id("OCPN_ACTIVE_ROUTELEG_RESPONSE");
6405 SendJSONMessageToAllPlugins(msg_id, v);
6406 }
6407}
6408
6409void MyFrame::FilterCogSog() {
6410 if (g_bfilter_cogsog && !g_own_ship_sog_cog_calc) {
6411 // Simple averaging filter for COG
6412 double cog_last = gCog; // most recent reported value
6413
6414 // Make a hole in array
6415 for (int i = g_COGFilterSec - 1; i > 0; i--)
6416 COGFilterTable[i] = COGFilterTable[i - 1];
6417 COGFilterTable[0] = cog_last;
6418
6419 // If the lastest data is undefined, leave it
6420 if (!std::isnan(cog_last)) {
6421 //
6422 double sum = 0., count = 0;
6423 for (int i = 0; i < g_COGFilterSec; i++) {
6424 double adder = COGFilterTable[i];
6425 if (std::isnan(adder)) continue;
6426
6427 if (fabs(adder - cog_last) > 180.) {
6428 if ((adder - cog_last) > 0.)
6429 adder -= 360.;
6430 else
6431 adder += 360.;
6432 }
6433
6434 sum += adder;
6435 count++;
6436 }
6437 sum /= count;
6438
6439 if (sum < 0.)
6440 sum += 360.;
6441 else if (sum >= 360.)
6442 sum -= 360.;
6443
6444 gCog = sum;
6445 }
6446
6447 // Simple averaging filter for SOG
6448 double sog_last = gSog; // most recent reported value
6449
6450 // Make a hole in array
6451 for (int i = g_SOGFilterSec - 1; i > 0; i--)
6452 SOGFilterTable[i] = SOGFilterTable[i - 1];
6453 SOGFilterTable[0] = sog_last;
6454
6455 // If the data are undefined, leave the array intact
6456 if (!std::isnan(gSog)) {
6457 double sum = 0., count = 0;
6458 for (int i = 0; i < g_SOGFilterSec; i++) {
6459 if (std::isnan(SOGFilterTable[i])) continue;
6460
6461 sum += SOGFilterTable[i];
6462 count++;
6463 }
6464 sum /= count;
6465
6466 gSog = sum;
6467 }
6468 }
6469}
6470
6471void MyFrame::LoadHarmonics() {
6472 if (!ptcmgr) {
6473 ptcmgr = new TCMgr;
6474 ptcmgr->LoadDataSources(TideCurrentDataSet);
6475 } else {
6476 bool b_newdataset = false;
6477
6478 // Test both ways
6479 for (auto a : ptcmgr->GetDataSet()) {
6480 bool b_foundi = false;
6481 for (auto b : TideCurrentDataSet) {
6482 if (a == b) {
6483 b_foundi = true;
6484 break; // j loop
6485 }
6486 }
6487 if (!b_foundi) {
6488 b_newdataset = true;
6489 break; // i loop
6490 }
6491 }
6492
6493 for (auto a : TideCurrentDataSet) {
6494 bool b_foundi = false;
6495 for (auto b : ptcmgr->GetDataSet()) {
6496 if (a == b) {
6497 b_foundi = true;
6498 break; // j loop
6499 }
6500 }
6501 if (!b_foundi) {
6502 b_newdataset = true;
6503 break; // i loop
6504 }
6505 }
6506
6507 if (b_newdataset) ptcmgr->LoadDataSources(TideCurrentDataSet);
6508 }
6509}
6510
6511void MyFrame::ActivateAISMOBRoute(const AisTargetData *ptarget) {
6512 if (!ptarget) return;
6513
6514 // The MOB point
6515 wxDateTime mob_time = wxDateTime::Now();
6516 wxString mob_label(_("AIS MAN OVERBOARD"));
6517 mob_label += _(" on ");
6518 mob_label += ocpn::toUsrDateTimeFormat(mob_time);
6519
6520 RoutePoint *pWP_MOB = new RoutePoint(ptarget->Lat, ptarget->Lon, "mob",
6521 mob_label, wxEmptyString);
6522 pWP_MOB->SetShared(true);
6523 pWP_MOB->m_bIsolatedMark = true;
6524 pSelect->AddSelectableRoutePoint(ptarget->Lat, ptarget->Lon, pWP_MOB);
6525 // pConfig->AddNewWayPoint(pWP_MOB, -1); // use auto next num
6526 NavObj_dB::GetInstance().InsertRoutePoint(pWP_MOB);
6527
6528 pWP_MOB->SetUseSca(false); // Do not use scaled hiding for MOB
6529
6530 /* We want to start tracking any MOB in range (Which will trigger false alarms
6531 with messages received over the network etc., but will a) not discard nearby
6532 event even in case our GPS is momentarily unavailable and b) work even when
6533 the boat is stationary, in which case some GPS units do not provide COG) if(
6534 bGPSValid && !std::isnan(gCog) && !std::isnan(gSog) ) { */
6535 RoutePoint *pWP_src = new RoutePoint(gLat, gLon, g_default_wp_icon,
6536 wxString(_("Own ship")), wxEmptyString);
6537 pSelect->AddSelectableRoutePoint(gLat, gLon, pWP_src);
6538 pWP_MOB->SetUseSca(false); // Do not use scaled hiding for MOB
6539 pAISMOBRoute = new Route();
6540 pRouteList->push_back(pAISMOBRoute);
6541
6542 pAISMOBRoute->AddPoint(pWP_src);
6543 pAISMOBRoute->AddPoint(pWP_MOB);
6544
6545 pSelect->AddSelectableRouteSegment(ptarget->Lat, ptarget->Lon, gLat, gLon,
6546 pWP_src, pWP_MOB, pAISMOBRoute);
6547
6548 pAISMOBRoute->m_RouteNameString = _("Temporary AISMOB Route");
6549 pAISMOBRoute->m_RouteStartString = _("Present own ship");
6550 pAISMOBRoute->m_RouteEndString = mob_label;
6551
6553
6554 pAISMOBRoute->SetRouteArrivalRadius(-1.0); // never arrives
6555
6556 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
6557 // g_pRouteMan->ActivateRoute( pAISMOBRoute, pWP_MOB );
6558
6559 wxJSONValue v;
6560 v["GUID"] = pAISMOBRoute->m_GUID;
6561 wxString msg_id("OCPN_MAN_OVERBOARD");
6562 SendJSONMessageToAllPlugins(msg_id, v);
6563 //}
6564
6565 if (RouteManagerDialog::getInstanceFlag()) {
6566 if (pRouteManagerDialog && pRouteManagerDialog->IsShown()) {
6567 pRouteManagerDialog->UpdateRouteListCtrl();
6568 pRouteManagerDialog->UpdateWptListCtrl();
6569 }
6570 }
6571
6572 RefreshAllCanvas(false);
6573
6574 wxString mob_message(_("AIS MAN OVERBOARD"));
6575 mob_message += _(" Time: ");
6576 mob_message += ocpn::toUsrDateTimeFormat(mob_time);
6577 mob_message += _(" Ownship Position: ");
6578 mob_message += toSDMM(1, gLat);
6579 mob_message += " ";
6580 mob_message += toSDMM(2, gLon);
6581 mob_message += _(" MOB Position: ");
6582 mob_message += toSDMM(1, ptarget->Lat);
6583 mob_message += " ";
6584 mob_message += toSDMM(2, ptarget->Lon);
6585 wxLogMessage(mob_message);
6586}
6587
6588void MyFrame::UpdateAISMOBRoute(const AisTargetData *ptarget) {
6589 if (pAISMOBRoute && ptarget) {
6590 // Update Current Ownship point
6591 RoutePoint *OwnPoint = pAISMOBRoute->GetPoint(1);
6592 OwnPoint->m_lat = gLat;
6593 OwnPoint->m_lon = gLon;
6594
6595 pSelect->DeleteSelectableRoutePoint(OwnPoint);
6596 pSelect->AddSelectableRoutePoint(gLat, gLon, OwnPoint);
6597
6598 // Update Current MOB point
6599 RoutePoint *MOB_Point = pAISMOBRoute->GetPoint(2);
6600 MOB_Point->m_lat = ptarget->Lat;
6601 MOB_Point->m_lon = ptarget->Lon;
6602
6603 pSelect->DeleteSelectableRoutePoint(MOB_Point);
6604 pSelect->AddSelectableRoutePoint(ptarget->Lat, ptarget->Lon, MOB_Point);
6605
6606 pSelect->UpdateSelectableRouteSegments(OwnPoint);
6607 pSelect->UpdateSelectableRouteSegments(MOB_Point);
6608 }
6609
6610 RefreshAllCanvas(false);
6611
6612 if (ptarget) {
6613 wxDateTime mob_time = wxDateTime::Now();
6614
6615 wxString mob_message(_("AIS MAN OVERBOARD UPDATE"));
6616 mob_message += _(" Time: ");
6617 mob_message += ocpn::toUsrDateTimeFormat(mob_time);
6618 mob_message += _(" Ownship Position: ");
6619 mob_message += toSDMM(1, gLat);
6620 mob_message += " ";
6621 mob_message += toSDMM(2, gLon);
6622 mob_message += _(" MOB Position: ");
6623 mob_message += toSDMM(1, ptarget->Lat);
6624 mob_message += " ";
6625 mob_message += toSDMM(2, ptarget->Lon);
6626
6627 wxLogMessage(mob_message);
6628 }
6629}
6630
6631void MyFrame::applySettingsString(wxString settings) {
6632 // Save some present values
6633 int last_UIScaleFactor = g_GUIScaleFactor;
6634 bool previous_expert = g_bUIexpert;
6635 g_last_ChartScaleFactor = g_ChartScaleFactor;
6636 ArrayOfCDI *pNewDirArray = new ArrayOfCDI;
6637
6638 int rr =
6639 g_Platform->platformApplyPrivateSettingsString(settings, pNewDirArray);
6640
6641 // And apply the changes
6642 pConfig->UpdateSettings();
6643
6644 // Might need to rebuild symbols
6645 if (g_last_ChartScaleFactor != g_ChartScaleFactor) rr |= S52_CHANGED;
6646
6647 if (rr & S52_CHANGED) {
6648 if (ps52plib) {
6649 ps52plib->FlushSymbolCaches(ChartCtxFactory());
6650 ps52plib
6651 ->ClearCNSYLUPArray(); // some CNSY depends on renderer (e.g. CARC)
6652 ps52plib->GenerateStateHash();
6653 }
6654 }
6655
6656 ProcessOptionsDialog(rr, pNewDirArray);
6657
6658 // Try to detect if the toolbar is changing, to avoid a rebuild if not
6659 // necessary.
6660
6661 bool b_newToolbar = false;
6662
6663 if (g_GUIScaleFactor != last_UIScaleFactor) b_newToolbar = true;
6664
6665 if (previous_expert != g_bUIexpert) b_newToolbar = true;
6666
6667 if (rr & TOOLBAR_CHANGED) {
6668 b_newToolbar = true;
6669 }
6670
6671 // We do this is one case only to remove an orphan recovery window
6672#ifdef __ANDROID__
6673 if (previous_expert && !g_bUIexpert) {
6674 androidForceFullRepaint();
6675 }
6676#endif
6677
6678 if (previous_expert != g_bUIexpert) g_Platform->applyExpertMode(g_bUIexpert);
6679
6680 // We set the compass size first, since that establishes the available space
6681 // for the toolbar.
6682 SetGPSCompassScale();
6683 // ..For each canvas...
6684 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
6685 ChartCanvas *cc = g_canvasArray.Item(i);
6686 if (cc) cc->GetCompass()->SetScaleFactor(g_compass_scalefactor);
6687 }
6688 UpdateGPSCompassStatusBoxes(true);
6689
6690 if (b_newToolbar) {
6691 AbstractPlatform::ShowBusySpinner();
6692
6693 SetAllToolbarScale();
6694 RequestNewToolbars(
6695 true); // Force rebuild, to pick up bGUIexpert and scale settings.
6696
6697 AbstractPlatform::HideBusySpinner();
6698
6699 RequestNewMasterToolbar(true);
6700 }
6701
6702 // gFrame->Raise();
6703
6704 InvalidateAllGL();
6705 DoChartUpdate();
6706 UpdateControlBar(GetPrimaryCanvas());
6707 Refresh();
6708
6709 if (console) console->Raise();
6710
6711 Refresh(false);
6712 if (m_data_monitor->IsVisible()) m_data_monitor->Raise();
6713}
6714
6715#ifdef wxHAS_POWER_EVENTS
6716void MyFrame::OnSuspending(wxPowerEvent &event) {
6717 // wxDateTime now = wxDateTime::Now();
6718 // printf("OnSuspending...%d\n", now.GetTicks());
6719
6720 wxLogMessage("System suspend starting...");
6721}
6722
6723void MyFrame::OnSuspended(wxPowerEvent &WXUNUSED(event)) {
6724 // wxDateTime now = wxDateTime::Now();
6725 // printf("OnSuspended...%d\n", now.GetTicks());
6726 wxLogMessage("System is going to suspend.");
6727}
6728
6729void MyFrame::OnSuspendCancel(wxPowerEvent &WXUNUSED(event)) {
6730 // wxDateTime now = wxDateTime::Now();
6731 // printf("OnSuspendCancel...%d\n", now.GetTicks());
6732 wxLogMessage("System suspend was cancelled.");
6733}
6734
6735int g_last_resume_ticks;
6736void MyFrame::OnResume(wxPowerEvent &WXUNUSED(event)) {
6737 wxDateTime now = wxDateTime::Now();
6738 wxLogMessage("System resumed from suspend.");
6739
6740 if ((now.GetTicks() - g_last_resume_ticks) > 5) {
6741 SystemEvents::GetInstance().evt_resume.Notify();
6742
6743 wxLogMessage("Restarting streams.");
6744 g_last_resume_ticks = now.GetTicks();
6745// FIXME (dave)
6746#if 0
6747 if (g_pMUX) {
6748 g_pMUX->ClearStreams();
6749
6750 g_pMUX->StartAllStreams();
6751 }
6752#endif
6753 }
6754
6755 // If OpenGL is enabled, Windows Resume does not properly refresh the
6756 // application GL context. We need to force a Resize event that actually does
6757 // something.
6758 if (g_bopengl) {
6759 if (IsMaximized()) { // This is not real pretty on-screen, but works
6760 Maximize(false);
6761 wxYield();
6762 Maximize(true);
6763 } else {
6764 wxSize sz = GetSize();
6765 SetSize(wxSize(sz.x - 1, sz.y));
6766 wxYield();
6767 SetSize(sz);
6768 }
6769 }
6770}
6771#endif // wxHAS_POWER_EVENTS
6772
6773//----------------------------------------------------------------------------------------------------------
6774// Master Toolbar support
6775//----------------------------------------------------------------------------------------------------------
6776
6777void MyFrame::RequestNewMasterToolbar(bool bforcenew) {
6778 bool btbRebuild = false;
6779
6780 bool b_reshow = true;
6781 if (g_MainToolbar) {
6782 b_reshow = true; // g_MainToolbar->IsShown();
6783 float ff = fabs(g_MainToolbar->GetScaleFactor() - g_toolbar_scalefactor);
6784 if ((ff > 0.01f) || bforcenew) {
6785 g_MainToolbar->DestroyToolBar();
6786 delete g_MainToolbar;
6787 g_MainToolbar = NULL;
6788 }
6789
6790 btbRebuild = true;
6791 }
6792
6793 if (!g_MainToolbar) {
6794 long orient = g_Platform->GetDefaultToolbarOrientation();
6795 wxWindow *toolbarParent = this;
6796#ifdef __WXOSX__
6797 toolbarParent = GetPrimaryCanvas();
6798#endif
6800 toolbarParent, wxPoint(-1, -1), orient, g_toolbar_scalefactor);
6801 g_MainToolbar->SetBackGroundColorString("GREY3");
6802 g_MainToolbar->SetToolbarHideMethod(TOOLBAR_HIDE_TO_FIRST_TOOL);
6803 g_MainToolbar->SetToolConfigString(g_toolbarConfig);
6804 g_MainToolbar->EnableRolloverBitmaps(false);
6805
6806 g_MainToolbar->CreateConfigMenu();
6807 g_MainToolbar->SetDefaultPosition();
6808
6809 g_bmasterToolbarFull = true;
6810 }
6811
6812 if (g_MainToolbar) {
6813 CreateMasterToolbar();
6814 {
6815 // g_MainToolbar->RestoreRelativePosition(g_maintoolbar_x,
6816 // g_maintoolbar_y);
6817 g_MainToolbar->SetColorScheme(global_color_scheme);
6818 // g_MainToolbar->Show(b_reshow && g_bshowToolbar);
6819 }
6820 }
6821
6822 if (btbRebuild) {
6823 g_MainToolbar->SetAutoHide(g_bAutoHideToolbar);
6824 g_MainToolbar->SetAutoHideTimer(g_nAutoHideToolbar);
6825 }
6826}
6827
6828bool MyFrame::CollapseGlobalToolbar() {
6829 if (g_MainToolbar) {
6830 m_nMasterToolCountShown = 1;
6831 g_MainToolbar->SetToolShowCount(m_nMasterToolCountShown);
6832 g_MainToolbar->GetToolbar()->InvalidateBitmaps();
6833 g_MainToolbar->Realize();
6834 g_bmasterToolbarFull = false;
6835 return true;
6836 } else
6837 return false;
6838}
6839
6840ocpnToolBarSimple *MyFrame::CreateMasterToolbar() {
6841 ocpnToolBarSimple *tb = NULL;
6842
6843 if (g_MainToolbar) tb = g_MainToolbar->GetToolbar();
6844
6845 if (!tb) return 0;
6846
6847 ocpnStyle::Style *style = g_StyleManager->GetCurrentStyle();
6848
6850 ID_MASTERTOGGLE, style->GetToolIcon("MUI_menu", TOOLICON_NORMAL),
6851 wxITEM_NORMAL, _("Hide Toolbar"), "MUI_menu");
6852 tic->m_bRequired = true;
6853
6854 g_MainToolbar->AddToolItem(tic);
6855
6856 tic = new ToolbarItemContainer(
6857 ID_SETTINGS, style->GetToolIcon("MUI_settings", TOOLICON_NORMAL),
6858 wxITEM_NORMAL, _("Options"), "MUI_settings");
6859 g_MainToolbar->AddToolItem(tic);
6860
6861 tic = new ToolbarItemContainer(
6862 ID_MENU_ROUTE_NEW, style->GetToolIcon("MUI_route", TOOLICON_NORMAL),
6863 style->GetToolIcon("MUI_route", TOOLICON_TOGGLED), wxITEM_CHECK,
6864 wxString(_("Create Route")) << " (Ctrl-R)", "MUI_route");
6865
6866 g_MainToolbar->AddToolItem(tic);
6867
6868 tic = new ToolbarItemContainer(
6869 ID_ROUTEMANAGER, style->GetToolIcon("MUI_RMD", TOOLICON_NORMAL),
6870 wxITEM_NORMAL, _("Route & Mark Manager"), "MUI_RMD");
6871 g_MainToolbar->AddToolItem(tic);
6872
6873 tic = new ToolbarItemContainer(
6874 ID_TRACK, style->GetToolIcon("MUI_track", TOOLICON_NORMAL),
6875 style->GetToolIcon("MUI_track", TOOLICON_TOGGLED), wxITEM_CHECK,
6876 _("Enable Tracking"), "MUI_track");
6877 g_MainToolbar->AddToolItem(tic);
6878
6879 tic = new ToolbarItemContainer(
6880 ID_COLSCHEME, style->GetToolIcon("MUI_colorscheme", TOOLICON_NORMAL),
6881 wxITEM_NORMAL, _("Change Color Scheme"), "MUI_colorscheme");
6882 g_MainToolbar->AddToolItem(tic);
6883 // if( GetMasterToolItemShow(ID_COLSCHEME) ){
6884 // tb->AddTool( ID_COLSCHEME, "MUI_colorscheme", style->GetToolIcon(
6885 // "MUI_colorscheme", TOOLICON_NORMAL ),
6886 // tipString, wxITEM_NORMAL );
6887 // tb->SetToolTooltipHiViz( ID_COLSCHEME, true ); // cause the Tooltip to
6888 // always be visible, whatever
6889 // the colorscheme
6890 //}
6891
6892 tic = new ToolbarItemContainer(
6893 ID_PRINT, style->GetToolIcon("MUI_print", TOOLICON_NORMAL), wxITEM_NORMAL,
6894 _("Print Chart"), "MUI_print");
6895 g_MainToolbar->AddToolItem(tic);
6896
6897 tic = new ToolbarItemContainer(
6898 ID_ABOUT, style->GetToolIcon("MUI_help", TOOLICON_NORMAL), wxITEM_NORMAL,
6899 _("About OpenCPN"), "MUI_help");
6900 g_MainToolbar->AddToolItem(tic);
6901
6902 // Add any PlugIn toolbar tools that request default positioning
6903 AddDefaultPositionPlugInTools();
6904
6905 // And finally add the MOB tool
6906 tic = new ToolbarItemContainer(
6907 ID_MOB, style->GetToolIcon("mob_btn", TOOLICON_NORMAL), wxITEM_NORMAL,
6908 wxString(_("Drop MOB Marker")) << _(" (Ctrl-Space)"), "mob_btn");
6909 g_MainToolbar->AddToolItem(tic);
6910
6911 // Build the toolbar
6912 g_MainToolbar->RebuildToolbar();
6913
6914 // Realize() the toolbar for current geometry
6915 style->Unload();
6916 g_MainToolbar->Realize();
6917
6918 // Set PlugIn tool toggle states
6919 ArrayOfPlugInToolbarTools tool_array =
6920 g_pi_manager->GetPluginToolbarToolArray();
6921 for (unsigned int i = 0; i < tool_array.GetCount(); i++) {
6922 PlugInToolbarToolContainer *pttc = tool_array.Item(i);
6923 if (!pttc->b_viz) continue;
6924
6925 if (pttc->kind == wxITEM_CHECK) tb->ToggleTool(pttc->id, pttc->b_toggle);
6926 }
6927
6928 SetMasterToolbarItemState(ID_TRACK, g_bTrackActive);
6929 if (g_bTrackActive) {
6930 g_MainToolbar->SetToolShortHelp(ID_TRACK, _("Disable Tracking"));
6931 }
6932 g_MainToolbar->Realize();
6933
6934 return tb;
6935}
6936
6937bool MyFrame::CheckAndAddPlugInTool() {
6938 if (!g_pi_manager) return false;
6939
6940 bool bret = false;
6941 ocpnToolBarSimple *tb = NULL;
6942
6943 if (g_MainToolbar) tb = g_MainToolbar->GetToolbar();
6944
6945 if (!tb) return false;
6946
6947 int n_tools = tb->GetToolsCount();
6948
6949 // Walk the PlugIn tool spec array, checking the requested position
6950 // If a tool has been requested by a plugin at this position, add it
6951 ArrayOfPlugInToolbarTools tool_array =
6952 g_pi_manager->GetPluginToolbarToolArray();
6953
6954 for (unsigned int i = 0; i < tool_array.GetCount(); i++) {
6955 PlugInToolbarToolContainer *pttc = tool_array.Item(i);
6956 if (pttc->position == n_tools) {
6957 wxBitmap *ptool_bmp;
6958
6959 switch (global_color_scheme) {
6960 case GLOBAL_COLOR_SCHEME_DAY:
6961 ptool_bmp = pttc->bitmap_day;
6962 ;
6963 break;
6964 case GLOBAL_COLOR_SCHEME_DUSK:
6965 ptool_bmp = pttc->bitmap_dusk;
6966 break;
6967 case GLOBAL_COLOR_SCHEME_NIGHT:
6968 ptool_bmp = pttc->bitmap_night;
6969 break;
6970 default:
6971 ptool_bmp = pttc->bitmap_day;
6972 break;
6973 }
6974
6976 pttc->id, *(ptool_bmp), pttc->kind, pttc->shortHelp, "");
6977
6978 tic->m_NormalIconSVG = pttc->pluginNormalIconSVG;
6979 tic->m_RolloverIconSVG = pttc->pluginRolloverIconSVG;
6980 tic->m_ToggledIconSVG = pttc->pluginToggledIconSVG;
6981 tic->m_bPlugin = true;
6982
6983 bret = true;
6984 }
6985 }
6986
6987 // If we added a tool, call again (recursively) to allow for adding
6988 // adjacent tools
6989 if (bret)
6990 while (CheckAndAddPlugInTool()) { /* nothing to do */
6991 }
6992
6993 return bret;
6994}
6995
6996bool MyFrame::AddDefaultPositionPlugInTools() {
6997 if (!g_pi_manager) return false;
6998
6999 bool bret = false;
7000
7001 // Walk the PlugIn tool spec array, checking the requested position
7002 // If a tool has been requested by a plugin at this position, add it
7003 ArrayOfPlugInToolbarTools tool_array =
7004 g_pi_manager->GetPluginToolbarToolArray();
7005
7006 for (unsigned int i = 0; i < tool_array.GetCount(); i++) {
7007 PlugInToolbarToolContainer *pttc = tool_array.Item(i);
7008
7009 // Tool is currently tagged as invisible
7010 if (!pttc->b_viz) continue;
7011
7012 if (pttc->position == -1) // PlugIn has requested default positioning
7013 {
7014 wxBitmap *ptool_bmp;
7015
7016 switch (global_color_scheme) {
7017 case GLOBAL_COLOR_SCHEME_DAY:
7018 ptool_bmp = pttc->bitmap_day;
7019 break;
7020 case GLOBAL_COLOR_SCHEME_DUSK:
7021 ptool_bmp = pttc->bitmap_dusk;
7022 break;
7023 case GLOBAL_COLOR_SCHEME_NIGHT:
7024 ptool_bmp = pttc->bitmap_night;
7025 break;
7026 default:
7027 ptool_bmp = pttc->bitmap_day;
7028 break;
7029 }
7030
7032 pttc->id, *(ptool_bmp), pttc->kind, pttc->shortHelp, "");
7033
7034 tic->m_NormalIconSVG = pttc->pluginNormalIconSVG;
7035 tic->m_RolloverIconSVG = pttc->pluginRolloverIconSVG;
7036 tic->m_ToggledIconSVG = pttc->pluginToggledIconSVG;
7037 tic->m_bPlugin = true;
7038
7039 g_MainToolbar->AddToolItem(tic);
7040
7041 bret = true;
7042 }
7043 }
7044 return bret;
7045}
7046
7047/*************************************************************************
7048 * Global color management routines
7049 *
7050 *************************************************************************/
7051
7052wxColour GetGlobalColor(wxString colorName); // -> color_handler
7053
7054static const char *usercolors[] = {
7055 //======================================================================
7056 // Table:DAY - Bright daylight color scheme (full visibility mode)
7057 //======================================================================
7058 "Table:DAY",
7059
7060 // Standard palette colors - general purpose UI elements
7061 "GREEN1;120;255;120;", "GREEN2; 45;150; 45;", "GREEN3;200;220;200;",
7062 "GREEN4; 0;255; 0;", "GREEN5;170;254; 0;", "BLUE1; 170;170;255;",
7063 "BLUE2; 45; 45;170;", "BLUE3; 0; 0;255;", "GREY1; 200;200;200;",
7064 "GREY2; 230;230;230;", "RED1; 220;200;200;", "YELO1; 243;229; 47;",
7065 "YELO2; 128; 80; 0;", "TEAL1; 0;128;128;",
7066
7067 // Basic UI colors
7068 "UBLCK; 0; 0; 0;", // Universal black for text/lines
7069 "UWHIT; 255;255;255;", // Universal white for backgrounds
7070 "URED; 255; 0; 0;", // Own vessel color, AIS targets, predictor lines
7071 "UGREN; 0;255; 0;", // Universal green for general purpose green
7072 "COMPT; 245;247;244", // Compass rose background/details
7073
7074// Dialog system colors
7075#ifdef __WXOSX__
7076 "DILG0; 255;255;255;", // Dialog window background (macOS)
7077#else
7078 "DILG0; 238;239;242;", // Dialog window background (other platforms)
7079#endif
7080 "DILG1; 212;208;200;", // Background color for selected items
7081 "DILG2; 255;255;255;", // Control backgrounds for text boxes and input
7082 // fields
7083 "DILG3; 0; 0; 0;", // Dialog text color in dialogs and controls
7089 "DILG4; 0; 0; 0;",
7090 "UITX1; 0; 0; 0;", // Menu text color
7091
7092 // Chart and information display colors
7093 "CHGRF; 163; 180; 183;", // Chart gray foreground (grid lines, secondary
7094 // text)
7095 "CHYLW; 244; 218; 72;", // Chart yellow (AIS name invalid, warnings)
7096 "CHWHT; 212; 234; 238;", // Chart white (AIS outlines, contrast elements)
7097
7098 // Information status colors
7099 "UINFM; 197; 69; 195;", // Magenta - special indicators, chart magenta
7100 // features
7101 "UINFG; 104; 228; 86;", // Green - status indicators, tide/current
7102 // graphics
7103 "UINFR; 241; 84; 105;", // Red - alerts, errors, danger markers
7104 "UINFF; 125; 137; 140;", // Default foreground - general UI elements
7105 "SHIPS; 7; 7; 7;", // Other vessels/AIS target fills
7106
7107 // Route and navigation colors
7108 "UDKRD; 124; 16; 0;", // Dark red variant - reduced visibility alternative
7109 // to URED
7110 "UARTE; 200; 0; 0;", // Active route color (bright red in day mode)
7111
7112 // Chart data and measurement colors
7113 "NODTA; 163; 180; 183;", // No data available areas
7114 "CHBLK; 7; 7; 7;", // Chart black - text, lines, piano keys
7115 "SNDG1; 125; 137; 140;", // Sounding text (depth numbers) - primary
7116 "SNDG2; 7; 7; 7;", // Sounding text (depth numbers) - secondary
7117 "SCLBR; 235; 125; 54;", // Scale bar markings and text
7118
7119 // UI framework colors
7120 "UIBDR; 125; 137; 140;", // UI borders, status bar background
7121 "UIBCK; 212; 234; 238;", // Highlight backgrounds, info windows
7122 "UINFB; 58; 120; 240;", // Information blue - active/selected states, tide
7123 // markers
7124 "UINFD; 7; 7; 7;", // Information dark - borders, inactive elements
7125 "UINFO; 235; 125; 54;", // Information orange - warnings, highlights
7126
7127 // Route planning colors
7128 "PLRTE; 220; 64; 37;", // Planned route color (not yet active)
7129 "CHMGD; 197; 69; 195;", // Chart magenta - special chart features, AIS MMSI
7130 // text
7131
7132 // Dashboard instrument colors
7133 "DASHB; 255;255;255;", // Dashboard instrument background
7134 "DASHL; 175;175;175;", // Dashboard instrument labels and graduations
7135 "DASHF; 50; 50; 50;", // Dashboard foreground text and indicators
7136 "DASHR; 200; 0; 0;", // Dashboard red indicators (alarms, danger zones)
7137 "DASHG; 0;200; 0;", // Dashboard green indicators (normal status)
7138 "DASHN; 200;120; 0;", // Dashboard needle/pointer color
7139 "DASH1; 204;204;255;", // Dashboard graphic elements - primary
7140 "DASH2; 122;131;172;", // Dashboard graphic elements - secondary
7141 "COMP1; 211;211;211;", // Compass window background
7142
7143 // Window and canvas elements
7144 "GREY3; 40; 40; 40;", // MUI toolbar background
7145 "BLUE4; 100;100;200;", // Canvas focus indicator bar
7146 "VIO01; 171; 33;141;", // Violet - vector chart special elements
7147 "VIO02; 209;115;213;", // Violet variant - vector chart features
7148 "BLUEBACK; 212;234;238;", // Deep water background color for basemap
7149 "LANDBACK; 201;185;122;", // Land mass background color for basemap
7150
7151 //======================================================================
7152 // Table:DUSK - Reduced brightness for twilight conditions
7153 // Colors defined above are automatically dimmed for dusk visibility
7154 //======================================================================
7155 "Table:DUSK", "GREEN1; 60;128; 60;", "GREEN2; 22; 75; 22;",
7156 "GREEN3; 80;100; 80;", "GREEN4; 0;128; 0;", "BLUE1; 80; 80;160;",
7157 "BLUE2; 30; 30;120;", "BLUE3; 0; 0;128;", "GREY1; 100;100;100;",
7158 "GREY2; 128;128;128;", "RED1; 150;100;100;", "UBLCK; 0; 0; 0;",
7159 "UWHIT; 255;255;255;", "URED; 120; 54; 11;", "UGREN; 35;110; 20;",
7160 "YELO1; 120;115; 24;", "YELO2; 64; 40; 0;", "TEAL1; 0; 64; 64;",
7161 "GREEN5; 85;128; 0;", "COMPT; 124;126;121",
7162
7163 "CHGRF; 41; 46; 46;", "UINFM; 58; 20; 57;", "UINFG; 35; 76; 29;",
7164 "UINFF; 41; 46; 46;", "UINFR; 80; 28; 35;", "SHIPS; 71; 78; 79;",
7165 "CHYLW; 81; 73; 24;", "CHWHT; 71; 78; 79;",
7166
7167 "DILG0; 110;110;110;", // Dialog Background
7168 "DILG1; 110;110;110;", // Dialog Background
7169 "DILG2; 0; 0; 0;", // Control Background
7170 "DILG3; 130;130;130;", // Text
7171 "DILG4; 0; 0; 0;",
7172 "UITX1; 41; 46; 46;", // Menu text color
7173 "UDKRD; 80; 0; 0;", // Dark red variant - reduced visibility alternative
7174 // to URED
7175 "UARTE; 64; 64; 64;", // Active route color (grey for dusk/night modes)
7176
7177 "NODTA; 41; 46; 46;", "CHBLK; 54; 60; 61;", "SNDG1; 41; 46; 46;",
7178 "SNDG2; 71; 78; 79;", "SCLBR; 75; 38; 19;", "UIBDR; 54; 60; 61;",
7179 "UINFB; 19; 40; 80;", "UINFD; 71; 78; 79;", "UINFO; 75; 38; 19;",
7180 "PLRTE; 73; 21; 12;", "CHMGD; 74; 58; 81;", "UIBCK; 7; 7; 7;",
7181
7182 "DASHB; 77; 77; 77;", // Dashboard Instr background
7183 "DASHL; 54; 54; 54;", // Dashboard Instr Label
7184 "DASHF; 0; 0; 0;", // Dashboard Foreground
7185 "DASHR; 58; 21; 21;", // Dashboard Red
7186 "DASHG; 21; 58; 21;", // Dashboard Green
7187 "DASHN; 100; 50; 0;", // Dashboard Needle
7188 "DASH1; 76; 76;113;", // Dashboard Illustrations
7189 "DASH2; 48; 52; 72;", // Dashboard Illustrations
7190 "COMP1; 107;107;107;", // Compass Window Background
7191
7192 "GREY3; 20; 20; 20;", // MUIBar/TB background
7193 "BLUE4; 80; 80;160;", // Canvas Focus Bar
7194 "VIO01; 128; 25;108;", "VIO02; 171; 33;141;", "BLUEBACK; 186;213;235;",
7195 "LANDBACK; 201;185;122;",
7196
7197 //======================================================================
7198 // Table:NIGHT - Dark adapted colors preserving night vision
7199 // Colors are further dimmed and shifted toward red spectrum
7200 //======================================================================
7201 "Table:NIGHT", "GREEN1; 30; 80; 30;", "GREEN2; 15; 60; 15;",
7202 "GREEN3; 12; 23; 9;", "GREEN4; 0; 64; 0;", "BLUE1; 60; 60;100;",
7203 "BLUE2; 22; 22; 85;", "BLUE3; 0; 0; 40;", "GREY1; 48; 48; 48;",
7204 "GREY2; 32; 32; 32;", "RED1; 100; 50; 50;", "UWHIT; 255;255;255;",
7205 "UBLCK; 0; 0; 0;", "URED; 60; 27; 5;", "UGREN; 17; 55; 10;",
7206 "YELO1; 60; 65; 12;", "YELO2; 32; 20; 0;", "TEAL1; 0; 32; 32;",
7207 "GREEN5; 44; 64; 0;", "COMPT; 48; 49; 51",
7208 "DILG0; 80; 80; 80;", // Dialog Background
7209 "DILG1; 80; 80; 80;", // Dialog Background
7210 "DILG2; 0; 0; 0;", // Control Background
7211 "DILG3; 65; 65; 65;", // Text
7212 "DILG4; 220;220;220;",
7213 "UITX1; 31; 34; 35;", // Menu text color
7214 "UDKRD; 50; 0; 0;", // Dark red variant - reduced visibility alternative
7215 // to URED
7216 "UARTE; 64; 64; 64;", // Active route color (grey for dusk/night modes)
7217
7218 "CHGRF; 16; 18; 18;", "UINFM; 52; 18; 52;", "UINFG; 22; 24; 7;",
7219 "UINFF; 31; 34; 35;", "UINFR; 59; 17; 10;", "SHIPS; 37; 41; 41;",
7220 "CHYLW; 31; 33; 10;", "CHWHT; 37; 41; 41;",
7221
7222 "NODTA; 7; 7; 7;", "CHBLK; 31; 34; 35;", "SNDG1; 31; 34; 35;",
7223 "SNDG2; 43; 48; 48;", "SCLBR; 52; 28; 12;", "UIBDR; 31; 34; 35;",
7224 "UINFB; 21; 29; 69;", "UINFD; 43; 48; 58;", "UINFO; 52; 28; 12;",
7225 "PLRTE; 66; 19; 11;", "CHMGD; 52; 18; 52;", "UIBCK; 7; 7; 7;",
7226
7227 "DASHB; 0; 0; 0;", // Dashboard Instr background
7228 "DASHL; 20; 20; 20;", // Dashboard Instr Label
7229 "DASHF; 64; 64; 64;", // Dashboard Foreground
7230 "DASHR; 70; 15; 15;", // Dashboard Red
7231 "DASHG; 15; 70; 15;", // Dashboard Green
7232 "DASHN; 17; 80; 56;", // Dashboard Needle
7233 "DASH1; 48; 52; 72;", // Dashboard Illustrations
7234 "DASH2; 36; 36; 53;", // Dashboard Illustrations
7235 "COMP1; 24; 24; 24;", // Compass Window Background
7236
7237 "GREY3; 10; 10; 10;", // MUIBar/TB background
7238 "BLUE4; 70; 70;140;", // Canvas Focus Bar
7239 "VIO01; 85; 16; 72;", "VIO02; 128; 25;108;", "BLUEBACK; 186;213;235;",
7240 "LANDBACK; 201;185;122;",
7241
7242 "*****"};
7243
7244int get_static_line(char *d, const char **p, int index, int n) {
7245 if (!strcmp(p[index], "*****")) return 0;
7246
7247 strncpy(d, p[index], n);
7248 return strlen(d);
7249}
7250
7251void InitializeUserColors() {
7252 const char **p = usercolors;
7253 char buf[81];
7254 int index = 0;
7255 char TableName[20];
7256 colTable *ctp;
7257 colTable *ct;
7258 int R, G, B;
7259
7260 UserColorTableArray = new wxArrayPtrVoid;
7261 UserColourHashTableArray = new wxArrayPtrVoid;
7262
7263 // Create 3 color table entries
7264 ct = new colTable;
7265 ct->tableName = new wxString("DAY");
7266 ct->color = new wxArrayPtrVoid;
7267 UserColorTableArray->Add((void *)ct);
7268
7269 ct = new colTable;
7270 ct->tableName = new wxString("DUSK");
7271 ct->color = new wxArrayPtrVoid;
7272 UserColorTableArray->Add((void *)ct);
7273
7274 ct = new colTable;
7275 ct->tableName = new wxString("NIGHT");
7276 ct->color = new wxArrayPtrVoid;
7277 UserColorTableArray->Add((void *)ct);
7278
7279 while ((get_static_line(buf, p, index, sizeof(buf) - 1))) {
7280 if (!strncmp(buf, "Table", 5)) {
7281 sscanf(buf, "Table:%s", TableName);
7282
7283 for (unsigned int it = 0; it < UserColorTableArray->GetCount(); it++) {
7284 ctp = (colTable *)(UserColorTableArray->Item(it));
7285 if (!strcmp(TableName, ctp->tableName->mb_str())) {
7286 ct = ctp;
7287 break;
7288 }
7289 }
7290
7291 } else {
7292 char name[21];
7293 int j = 0;
7294 while (buf[j] != ';' && j < 20) {
7295 name[j] = buf[j];
7296 j++;
7297 }
7298 name[j] = 0;
7299
7300 S52color *c = new S52color;
7301 strcpy(c->colName, name);
7302
7303 sscanf(&buf[j], ";%i;%i;%i", &R, &G, &B);
7304 c->R = (char)R;
7305 c->G = (char)G;
7306 c->B = (char)B;
7307
7308 ct->color->Add(c);
7309 }
7310
7311 index++;
7312 }
7313
7314 // Now create the Hash tables
7315
7316 for (unsigned int its = 0; its < UserColorTableArray->GetCount(); its++) {
7317 wxColorHashMap *phash = new wxColorHashMap;
7318 UserColourHashTableArray->Add((void *)phash);
7319
7320 colTable *ctp = (colTable *)(UserColorTableArray->Item(its));
7321
7322 for (unsigned int ic = 0; ic < ctp->color->GetCount(); ic++) {
7323 S52color *c2 = (S52color *)(ctp->color->Item(ic));
7324
7325 wxColour c(c2->R, c2->G, c2->B);
7326 wxString key(c2->colName, wxConvUTF8);
7327 (*phash)[key] = c;
7328 }
7329 }
7330
7331 // Establish a default hash table pointer
7332 // in case a color is needed before ColorScheme is set
7334 (wxColorHashMap *)UserColourHashTableArray->Item(0);
7335}
7336
7337void DeInitializeUserColors() {
7338 if (!UserColorTableArray) return;
7339 for (unsigned i = 0; i < UserColorTableArray->GetCount(); i++) {
7340 colTable *ct = (colTable *)UserColorTableArray->Item(i);
7341
7342 for (unsigned int j = 0; j < ct->color->GetCount(); j++) {
7343 S52color *c = (S52color *)ct->color->Item(j);
7344 delete c; // color
7345 }
7346
7347 delete ct->tableName; // wxString
7348 delete ct->color; // wxArrayPtrVoid
7349
7350 delete ct; // colTable
7351 }
7352
7353 delete UserColorTableArray;
7354
7355 for (unsigned i = 0; i < UserColourHashTableArray->GetCount(); i++) {
7356 wxColorHashMap *phash = (wxColorHashMap *)UserColourHashTableArray->Item(i);
7357 delete phash;
7358 }
7359
7360 delete UserColourHashTableArray;
7361}
7362
7363#ifdef __WXMSW__
7364
7365#define NCOLORS 40
7366
7367typedef struct _MSW_COLOR_SPEC {
7368 int COLOR_NAME;
7369 wxString S52_RGB_COLOR;
7370 int SysRGB_COLOR;
7371} MSW_COLOR_SPEC;
7372
7373MSW_COLOR_SPEC color_spec[] = {{COLOR_MENU, "UIBCK", 0},
7374 {COLOR_MENUTEXT, "UITX1", 0},
7375 {COLOR_BTNSHADOW, "UIBCK", 0}, // Menu Frame
7376 {-1, "", 0}};
7377
7378void SaveSystemColors() {
7379 /*
7380 color_3dface = pGetSysColor(COLOR_3DFACE);
7381 color_3dhilite = pGetSysColor(COLOR_3DHILIGHT);
7382 color_3dshadow = pGetSysColor(COLOR_3DSHADOW);
7383 color_3ddkshadow = pGetSysColor(COLOR_3DDKSHADOW);
7384 color_3dlight = pGetSysColor(COLOR_3DLIGHT);
7385 color_activecaption = pGetSysColor(COLOR_ACTIVECAPTION);
7386 color_gradientactivecaption = pGetSysColor(27); //COLOR_3DLIGHT);
7387 color_captiontext = pGetSysColor(COLOR_CAPTIONTEXT);
7388 color_windowframe = pGetSysColor(COLOR_WINDOWFRAME);
7389 color_inactiveborder = pGetSysColor(COLOR_INACTIVEBORDER);
7390 */
7391 // Record the default system color in my substitution structure
7392 MSW_COLOR_SPEC *pcspec = &color_spec[0];
7393 while (pcspec->COLOR_NAME != -1) {
7394 pcspec->SysRGB_COLOR = pGetSysColor(pcspec->COLOR_NAME);
7395 pcspec++;
7396 }
7397}
7398
7399void RestoreSystemColors() {
7400 int element[NCOLORS];
7401 int rgbcolor[NCOLORS];
7402 int i = 0;
7403
7404 MSW_COLOR_SPEC *pcspec = &color_spec[0];
7405 while (pcspec->COLOR_NAME != -1) {
7406 element[i] = pcspec->COLOR_NAME;
7407 rgbcolor[i] = pcspec->SysRGB_COLOR;
7408
7409 pcspec++;
7410 i++;
7411 }
7412
7413 pSetSysColors(i, (unsigned long *)&element[0], (unsigned long *)&rgbcolor[0]);
7414}
7415
7416#endif
7417
7418void SetSystemColors(ColorScheme cs) { //---------------
7419#ifdef __WXMSW__
7420 int element[NCOLORS];
7421 int rgbcolor[NCOLORS];
7422 int i = 0;
7423 if ((GLOBAL_COLOR_SCHEME_DUSK == cs) || (GLOBAL_COLOR_SCHEME_NIGHT == cs)) {
7424 MSW_COLOR_SPEC *pcspec = &color_spec[0];
7425 while (pcspec->COLOR_NAME != -1) {
7426 wxColour color = GetGlobalColor(pcspec->S52_RGB_COLOR);
7427 rgbcolor[i] = (color.Red() << 16) + (color.Green() << 8) + color.Blue();
7428 element[i] = pcspec->COLOR_NAME;
7429
7430 i++;
7431 pcspec++;
7432 }
7433
7434 pSetSysColors(i, (unsigned long *)&element[0],
7435 (unsigned long *)&rgbcolor[0]);
7436
7437 } else { // for daylight colors, use default windows colors as saved....
7438
7439 RestoreSystemColors();
7440 }
7441#endif
7442}
7443
7444wxColor GetDimColor(wxColor c) {
7445 if ((global_color_scheme == GLOBAL_COLOR_SCHEME_DAY) ||
7446 (global_color_scheme == GLOBAL_COLOR_SCHEME_RGB))
7447 return c;
7448
7449 float factor = 1.0;
7450 if (global_color_scheme == GLOBAL_COLOR_SCHEME_DUSK) factor = 0.5;
7451 if (global_color_scheme == GLOBAL_COLOR_SCHEME_NIGHT) factor = 0.25;
7452
7453 wxImage::RGBValue rgb(c.Red(), c.Green(), c.Blue());
7454 wxImage::HSVValue hsv = wxImage::RGBtoHSV(rgb);
7455 hsv.value = hsv.value * factor;
7456 wxImage::RGBValue nrgb = wxImage::HSVtoRGB(hsv);
7457
7458 return wxColor(nrgb.red, nrgb.green, nrgb.blue);
7459}
7460
7461// A helper function to check for proper parameters of anchor
7462// watch
7463//
7464double AnchorDistFix(double const d, double const AnchorPointMinDist,
7465 double const AnchorPointMaxDist) // pjotrc 2010.02.22
7466{
7467 if (d >= 0.0)
7468 if (d < AnchorPointMinDist)
7469 return AnchorPointMinDist;
7470 else if (d > AnchorPointMaxDist)
7471 return AnchorPointMaxDist;
7472 else
7473 return d;
7474
7475 else
7476 // if ( d < 0.0 )
7477 if (d > -AnchorPointMinDist)
7478 return -AnchorPointMinDist;
7479 else if (d < -AnchorPointMaxDist)
7480 return -AnchorPointMaxDist;
7481 else
7482 return d;
7483}
7484// Console supporting printf functionality for Windows GUI app
7485
7486#ifdef __WXMSW__
7487static const WORD MAX_CONSOLE_LINES =
7488 500; // maximum mumber of lines the output console should have
7489
7490// #ifdef _DEBUG
7491
7492void RedirectIOToConsole()
7493
7494{
7495 int hConHandle;
7496
7497 wxIntPtr lStdHandle;
7498
7499 CONSOLE_SCREEN_BUFFER_INFO coninfo;
7500
7501 FILE *fp;
7502
7503 // allocate a console for this app
7504
7505 AllocConsole();
7506
7507 // set the screen buffer to be big enough to let us scroll text
7508
7509 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
7510 coninfo.dwSize.Y = MAX_CONSOLE_LINES;
7511 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
7512
7513 // redirect unbuffered STDOUT to the console
7514
7515 lStdHandle = (wxIntPtr)GetStdHandle(STD_OUTPUT_HANDLE);
7516 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
7517 fp = _fdopen(hConHandle, "w");
7518 *stdout = *fp;
7519 setvbuf(stdout, NULL, _IONBF, 0);
7520
7521 // redirect unbuffered STDIN to the console
7522
7523 lStdHandle = (wxIntPtr)GetStdHandle(STD_INPUT_HANDLE);
7524 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
7525 fp = _fdopen(hConHandle, "r");
7526 *stdin = *fp;
7527 setvbuf(stdin, NULL, _IONBF, 0);
7528
7529 // redirect unbuffered STDERR to the console
7530
7531 lStdHandle = (wxIntPtr)GetStdHandle(STD_ERROR_HANDLE);
7532 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
7533 fp = _fdopen(hConHandle, "w");
7534 *stderr = *fp;
7535 setvbuf(stderr, NULL, _IONBF, 0);
7536
7537 // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console
7538 // as well
7539
7540 // ios::sync_with_stdio();
7541}
7542
7543// #endif
7544#endif
7545
7546#ifdef __WXMSW__
7547bool TestGLCanvas(wxString prog_dir) {
7548#ifdef __MSVC__
7549 wxString test_app = prog_dir;
7550 test_app += "ocpn_gltest1.exe";
7551
7552 if (::wxFileExists(test_app)) {
7553 long proc_return = ::wxExecute(test_app, wxEXEC_SYNC);
7554 printf("OpenGL Test Process returned %0X\n", proc_return);
7555 if (proc_return == 0)
7556 printf("GLCanvas OK\n");
7557 else
7558 printf("GLCanvas failed to start, disabling OpenGL.\n");
7559
7560 return (proc_return == 0);
7561 } else
7562 return true;
7563#else
7564 /* until we can get the source to ocpn_gltest1 assume true for mingw */
7565 return true;
7566#endif
7567}
7568#endif
7569
7570bool ReloadLocale() {
7571 bool ret = false;
7572
7573#if wxUSE_XLOCALE
7574 ret =
7575 (!g_Platform->ChangeLocale(g_locale, plocale_def_lang, &plocale_def_lang)
7576 .IsEmpty());
7577#endif
7578 return ret;
7579}
7580
7581void ApplyLocale() {
7582 FontMgr::Get().SetLocale(g_locale);
7583 FontMgr::Get().ScrubList();
7584
7585 // Close and re-init various objects to allow new locale to show.
7586 // delete g_options;
7587 // g_options = NULL;
7588 // g_pOptions = NULL;
7589
7590 if (pRoutePropDialog) {
7591 pRoutePropDialog->Hide();
7592 pRoutePropDialog->Destroy();
7593 pRoutePropDialog = NULL;
7594 }
7595
7596 if (pRouteManagerDialog) {
7597 pRouteManagerDialog->Hide();
7598 pRouteManagerDialog->Destroy();
7599 pRouteManagerDialog = NULL;
7600 }
7601
7602 if (console) console->SetColorScheme(global_color_scheme);
7603 if (g_pais_query_dialog_active) {
7604 g_pais_query_dialog_active->Destroy();
7605 g_pais_query_dialog_active = NULL;
7606 }
7607
7608 auto alert_dlg_active =
7609 dynamic_cast<AISTargetAlertDialog *>(g_pais_alert_dialog_active);
7610 if (alert_dlg_active) {
7611 alert_dlg_active->Destroy();
7612 g_pais_alert_dialog_active = nullptr;
7613 }
7614
7615 if (g_pAISTargetList) {
7616 if (g_pauimgr) g_pauimgr->DetachPane(g_pAISTargetList);
7617 g_pAISTargetList->Disconnect_decoder();
7618 g_pAISTargetList->Destroy();
7619 g_pAISTargetList = NULL;
7620 }
7621
7622 // Process the menubar, if present.
7623 if (gFrame->m_pMenuBar) { // remove the menu bar if it is presently enabled
7624 gFrame->SetMenuBar(NULL);
7625 gFrame->m_pMenuBar->Destroy();
7626 gFrame->m_pMenuBar = NULL;
7627 }
7628 gFrame->BuildMenuBar();
7629
7630 // Give all canvas a chance to update, if needed
7631 for (unsigned int i = 0; i < g_canvasArray.GetCount(); i++) {
7632 ChartCanvas *cc = g_canvasArray.Item(i);
7633 if (cc) cc->CanvasApplyLocale();
7634 }
7635
7636 // Capture a copy of the current perspective
7637 // So that we may restore PlugIn window sizes, position, visibility, etc.
7638 wxString perspective;
7639 pConfig->SetPath("/AUI");
7640 pConfig->Read("AUIPerspective", &perspective);
7641
7642 // Compliant Plugins will reload their locale message catalog during the
7643 // Init() method. So it is sufficient to simply deactivate, and then
7644 // re-activate, all "active" plugins.
7645 PluginLoader::GetInstance()->DeactivateAllPlugIns();
7646 PluginLoader::GetInstance()->UpdatePlugIns();
7647
7648 // // Make sure the perspective saved in the config file is
7649 // "reasonable"
7650 // // In particular, the perspective should have an entry for every
7651 // // windows added to the AUI manager so far.
7652 // // If any are not found, then use the default layout
7653 //
7654 bool bno_load = false;
7655 wxAuiPaneInfoArray pane_array_val = g_pauimgr->GetAllPanes();
7656
7657 for (unsigned int i = 0; i < pane_array_val.GetCount(); i++) {
7658 wxAuiPaneInfo pane = pane_array_val[i];
7659 if (perspective.Find(pane.name) == wxNOT_FOUND) {
7660 bno_load = true;
7661 break;
7662 }
7663 }
7664
7665 if (!bno_load) g_pauimgr->LoadPerspective(perspective, false);
7666
7667 g_pauimgr->Update();
7668
7669 if (gFrame) {
7670 gFrame->RequestNewToolbars(true);
7671 gFrame->RequestNewMasterToolbar(true);
7672 }
7673}
7674
7675void LoadS57() {
7676 if (ps52plib) // already loaded?
7677 return;
7678
7679 // Start a SENC Thread manager
7681
7682 // Set up a useable CPL library error handler for S57 stuff
7683 // FIXME (dave) Verify after moving LoadS57
7684 // CPLSetErrorHandler(MyCPLErrorHandler);
7685
7686 // Init the s57 chart object, specifying the location of the required csv
7687 // files
7688 g_csv_locn = g_Platform->GetSharedDataDir();
7689 g_csv_locn.Append("s57data");
7690
7691 if (g_bportable) {
7692 g_csv_locn = ".";
7693 appendOSDirSlash(&g_csv_locn);
7694 g_csv_locn.Append("s57data");
7695 }
7696
7697 // If the config file contains an entry for SENC file prefix, use it.
7698 // Otherwise, default to PrivateDataDir
7699 if (g_SENCPrefix.IsEmpty()) {
7700 g_SENCPrefix = g_Platform->GetPrivateDataDir();
7701 appendOSDirSlash(&g_SENCPrefix);
7702 g_SENCPrefix.Append("SENC");
7703 }
7704
7705 if (g_bportable) {
7706 wxFileName f(g_SENCPrefix);
7707 if (f.MakeRelativeTo(g_Platform->GetPrivateDataDir()))
7708 g_SENCPrefix = f.GetFullPath();
7709 else
7710 g_SENCPrefix = "SENC";
7711 }
7712
7713 // If the config file contains an entry for PresentationLibraryData, use
7714 // it. Otherwise, default to conditionally set spot under g_pcsv_locn
7715 wxString plib_data;
7716 bool b_force_legacy = false;
7717
7718 if (g_UserPresLibData.IsEmpty()) {
7719 plib_data = g_csv_locn;
7720 appendOSDirSlash(&plib_data);
7721 plib_data.Append("S52RAZDS.RLE");
7722 } else {
7723 plib_data = g_UserPresLibData;
7724 b_force_legacy = true;
7725 }
7726
7727 ps52plib = new s52plib(plib_data, b_force_legacy);
7728
7729 // If the library load failed, try looking for the s57 data elsewhere
7730
7731 // First, look in UserDataDir
7732 /* From wxWidgets documentation
7733
7734 wxStandardPaths::GetUserDataDir
7735 wxString GetUserDataDir() const
7736 Return the directory for the user-dependent application data files:
7737 * Unix: ~/.appname
7738 * Windows: C:\Documents and Settings\username\Application Data\appname
7739 * Mac: ~/Library/Application Support/appname
7740 */
7741
7742 if (!ps52plib->m_bOK) {
7743 delete ps52plib;
7744
7745 wxStandardPaths &std_path = g_Platform->GetStdPaths();
7746
7747 wxString look_data_dir;
7748 look_data_dir.Append(std_path.GetUserDataDir());
7749 appendOSDirSlash(&look_data_dir);
7750 wxString tentative_SData_Locn = look_data_dir;
7751 look_data_dir.Append("s57data");
7752
7753 plib_data = look_data_dir;
7754 appendOSDirSlash(&plib_data);
7755 plib_data.Append("S52RAZDS.RLE");
7756
7757 wxLogMessage("Looking for s57data in " + look_data_dir);
7758 ps52plib = new s52plib(plib_data);
7759
7760 if (ps52plib->m_bOK) {
7761 g_csv_locn = look_data_dir;
7763 }
7764 }
7765
7766 // And if that doesn't work, look again in the original SData Location
7767 // This will cover the case in which the .ini file entry is corrupted or
7768 // moved
7769
7770 if (!ps52plib->m_bOK) {
7771 delete ps52plib;
7772
7773 wxString look_data_dir;
7774 look_data_dir = g_Platform->GetSharedDataDir();
7775 look_data_dir.Append("s57data");
7776
7777 plib_data = look_data_dir;
7778 appendOSDirSlash(&plib_data);
7779 plib_data.Append("S52RAZDS.RLE");
7780
7781 wxLogMessage("Looking for s57data in " + look_data_dir);
7782 ps52plib = new s52plib(plib_data);
7783
7784 if (ps52plib->m_bOK) g_csv_locn = look_data_dir;
7785 }
7786
7787 if (ps52plib->m_bOK) {
7788 wxLogMessage("Using s57data in " + g_csv_locn);
7790 new s57RegistrarMgr(g_csv_locn, g_Platform->GetLogFilePtr());
7791
7792 // Preset some object class visibilites for "User Standard" disply
7793 // category
7794 // They may be overridden in LoadS57Config
7795 for (unsigned int iPtr = 0; iPtr < ps52plib->pOBJLArray->GetCount();
7796 iPtr++) {
7797 OBJLElement *pOLE = (OBJLElement *)(ps52plib->pOBJLArray->Item(iPtr));
7798 if (!strncmp(pOLE->OBJLName, "DEPARE", 6)) pOLE->nViz = 1;
7799 if (!strncmp(pOLE->OBJLName, "LNDARE", 6)) pOLE->nViz = 1;
7800 if (!strncmp(pOLE->OBJLName, "COALNE", 6)) pOLE->nViz = 1;
7801 }
7802
7803 pConfig->LoadS57Config();
7804 ps52plib->SetPLIBColorScheme(global_color_scheme, ChartCtxFactory());
7805
7806 if (gFrame) {
7807 ps52plib->SetDisplayWidth(g_monitor_info[g_current_monitor].width);
7808 ps52plib->SetPPMM(g_BasePlatform->GetDisplayDPmm());
7809 double dip_factor = g_BasePlatform->GetDisplayDIPMult(gFrame);
7810 ps52plib->SetDIPFactor(dip_factor);
7811 ps52plib->SetContentScaleFactor(OCPN_GetDisplayContentScaleFactor());
7812 }
7813
7814 // preset S52 PLIB scale factors
7815 ps52plib->SetScaleFactorExp(
7816 g_Platform->GetChartScaleFactorExp(g_ChartScaleFactor));
7817 ps52plib->SetScaleFactorZoomMod(g_chart_zoom_modifier_vector);
7818
7819#ifdef ocpnUSE_GL
7820
7821 // Setup PLIB OpenGL options, if enabled
7822 if (g_bopengl) {
7823 if (GL_Caps) {
7824 wxString renderer = wxString(GL_Caps->Renderer.c_str());
7825 ps52plib->SetGLRendererString(renderer);
7826 }
7827
7828 ps52plib->SetGLOptions(
7829 glChartCanvas::s_b_useStencil, glChartCanvas::s_b_useStencilAP,
7830 glChartCanvas::s_b_useScissorTest, glChartCanvas::s_b_useFBO,
7831 g_b_EnableVBO, g_texture_rectangle_format, 1, 1);
7832 }
7833#endif
7834
7835 } else {
7836 wxLogMessage(" S52PLIB Initialization failed, disabling Vector charts.");
7837 delete ps52plib;
7838 ps52plib = NULL;
7839 }
7840}
7841
7842class ParseENCWorkerThread : public wxThread {
7843public:
7844 ParseENCWorkerThread(wxString filename, Extent &ext, int scale)
7845 : wxThread(wxTHREAD_JOINABLE) {
7846 m_filename = filename;
7847 m_ext = ext;
7848 m_scale = scale;
7849 Create();
7850 }
7851
7852 void *Entry() {
7853 // ChartBase *pchart = ChartData->OpenChartFromDB(m_filename,
7854 // FULL_INIT); ChartData->DeleteCacheChart(pchart);
7855 s57chart *newChart = new s57chart;
7856
7857 newChart->SetNativeScale(m_scale);
7858 newChart->SetFullExtent(m_ext);
7859
7860 newChart->FindOrCreateSenc(m_filename);
7861 delete newChart;
7862 return 0;
7863 }
7864
7865 wxString m_filename;
7866 Extent m_ext;
7867 int m_scale;
7868};
7869
7870// begin duplicated code
7871static double chart_dist(int index) {
7872 double d;
7873 float clon;
7874 float clat;
7875 const ChartTableEntry &cte = ChartData->GetChartTableEntry(index);
7876 // if the chart contains ownship position set the distance to 0
7877 if (cte.GetBBox().Contains(gLat, gLon))
7878 d = 0.;
7879 else {
7880 // find the nearest edge
7881 double t;
7882 clon = (cte.GetLonMax() + cte.GetLonMin()) / 2;
7883 d = DistGreatCircle(cte.GetLatMax(), clon, gLat, gLon);
7884 t = DistGreatCircle(cte.GetLatMin(), clon, gLat, gLon);
7885 if (t < d) d = t;
7886
7887 clat = (cte.GetLatMax() + cte.GetLatMin()) / 2;
7888 t = DistGreatCircle(clat, cte.GetLonMin(), gLat, gLon);
7889 if (t < d) d = t;
7890 t = DistGreatCircle(clat, cte.GetLonMax(), gLat, gLon);
7891 if (t < d) d = t;
7892 }
7893 return d;
7894}
7895
7896WX_DEFINE_SORTED_ARRAY_INT(int, MySortedArrayInt);
7897static int CompareInts(int n1, int n2) {
7898 double d1 = chart_dist(n1);
7899 double d2 = chart_dist(n2);
7900 return (int)(d1 - d2);
7901}
7902
7903class compress_target {
7904public:
7905 wxString chart_path;
7906 double distance;
7907};
7908
7909WX_DECLARE_OBJARRAY(compress_target, ArrayOfCompressTargets);
7910WX_DEFINE_OBJARRAY(ArrayOfCompressTargets);
7911
7912#include <wx/arrimpl.cpp>
7913// end duplicated code
7914
7915void ParseAllENC(wxWindow *parent) {
7916 MySortedArrayInt idx_sorted_by_distance(CompareInts);
7917
7918 // Building the cache may take a long time....
7919 // Be a little smarter.
7920 // Build a sorted array of chart database indices, sorted on distance from the
7921 // ownship currently. This way, a user may build a few chart SENCs for
7922 // immediate use, then "skip" or "cancel"out on the rest until later.
7923 int count = 0;
7924 for (int i = 0; i < ChartData->GetChartTableEntries(); i++) {
7925 /* skip if not ENC */
7926 const ChartTableEntry &cte = ChartData->GetChartTableEntry(i);
7927 if (CHART_TYPE_S57 != cte.GetChartType()) continue;
7928
7929 idx_sorted_by_distance.Add(i);
7930 count++;
7931 }
7932
7933 if (count == 0) return;
7934
7935 wxLogMessage(wxString::Format("ParseAllENC() count = %d", count));
7936
7937 // Build another array of sorted compression targets.
7938 // We need to do this, as the chart table will not be invariant
7939 // after the compression threads start, so our index array will be invalid.
7940
7941 ArrayOfCompressTargets ct_array;
7942 for (unsigned int j = 0; j < idx_sorted_by_distance.GetCount(); j++) {
7943 int i = idx_sorted_by_distance[j];
7944
7945 const ChartTableEntry &cte = ChartData->GetChartTableEntry(i);
7946 double distance = chart_dist(i);
7947
7948 wxString filename(cte.GetpFullPath(), wxConvUTF8);
7949
7951 pct->distance = distance;
7952 pct->chart_path = filename;
7953
7954 ct_array.push_back(pct);
7955 }
7956
7957 int thread_count = 0;
7958 ParseENCWorkerThread **workers = NULL;
7959
7960 if (g_nCPUCount > 0)
7961 thread_count = g_nCPUCount;
7962 else
7963 thread_count = wxThread::GetCPUCount();
7964
7965 if (thread_count < 1) {
7966 // obviously there's at least one CPU!
7967 thread_count = 1;
7968 }
7969
7970 // thread_count = 1; // for now because there is a problem with more than 1
7971
7972#if 0
7973 workers = new ParseENCWorkerThread*[thread_count];
7974 for(int t = 0; t < thread_count; t++)
7975 workers[t] = NULL;
7976#endif
7977
7978 wxGenericProgressDialog *prog = nullptr;
7979 wxSize csz = GetOCPNCanvasWindow()->GetClientSize();
7980
7981 if (1) {
7982 long style = wxPD_SMOOTH | wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME |
7983 wxPD_REMAINING_TIME | wxPD_CAN_SKIP;
7984
7985 prog = new wxGenericProgressDialog();
7986 wxFont *qFont = GetOCPNScaledFont(_("Dialog"));
7987 prog->SetFont(*qFont);
7988
7989 prog->Create(_("OpenCPN ENC Prepare"), "Longgggggggggggggggggggggggggggg",
7990 count + 1, parent, style);
7991
7992 // make wider to show long filenames
7993 // wxSize sz = prog->GetSize();
7994 // sz.x = csz.x * 8 / 10;
7995 // prog->SetSize( sz );
7996
7997 DimeControl(prog);
7998#ifdef __WXOSX__
7999 prog->ShowWindowModal();
8000#else
8001 prog->Show();
8002#endif
8003 }
8004
8005 // parse targets
8006 bool skip = false;
8007 count = 0;
8008 for (unsigned int j = 0; j < ct_array.size(); j++) {
8009 wxString filename = ct_array[j].chart_path;
8010 double distance = ct_array[j].distance;
8011 int index = ChartData->FinddbIndex(filename);
8012 if (index < 0) continue;
8013 const ChartTableEntry &cte = ChartData->GetChartTableEntry(index);
8014 Extent ext;
8015 ext.NLAT = cte.GetLatMax();
8016 ext.SLAT = cte.GetLatMin();
8017 ext.WLON = cte.GetLonMin();
8018 ext.ELON = cte.GetLonMax();
8019
8020 int scale = cte.GetScale();
8021
8022 wxString msg;
8023 msg.Printf(_("Distance from Ownship: %4.0f NMi"), distance);
8024
8025 count++;
8026 if (wxThread::IsMain()) {
8027 if (prog) {
8028 wxSize sz = prog->GetSize();
8029 if (sz.x > 600) {
8030 msg += " Chart:";
8031 msg += filename;
8032 }
8033 prog->Update(count, msg, &skip);
8034#ifndef __WXMSW__
8035 prog->Raise();
8036#endif
8037 }
8038 if (skip) break;
8039 }
8040
8041#if 1
8042 if (ps52plib) {
8043 s57chart *newChart = new s57chart;
8044
8045 newChart->SetNativeScale(scale);
8046 newChart->SetFullExtent(ext);
8047 newChart->DisableBackgroundSENC();
8048
8049 newChart->FindOrCreateSenc(filename,
8050 false); // no progress dialog required
8051 delete newChart;
8052
8053 if (wxThread::IsMain()) {
8054 msg.Printf(_("ENC Completed."));
8055 if (prog) {
8056 prog->Update(count, msg, &skip);
8057#ifndef __WXMSW__
8058 prog->Raise();
8059#endif
8060 }
8061 if (skip) break;
8062 }
8063 }
8064
8065#else
8066 for (int t = 0;; t = (t + 1) % thread_count) {
8067 if (!workers[t]) {
8068 workers[t] = new ParseENCWorkerThread(filename);
8069 workers[t]->Run();
8070 break;
8071 }
8072
8073 if (!workers[t]->IsAlive()) {
8074 workers[t]->Wait();
8075 delete workers[t];
8076 workers[t] = NULL;
8077 }
8078 if (t == 0) {
8079 // ::wxYield(); // allow ChartCanvas main
8080 // message loop to run
8081 wxThread::Sleep(1); /* wait for a worker to finish */
8082 }
8083 }
8084#endif
8085
8086#if defined(__WXMSW__) || defined(__WXOSX__)
8087 ::wxSafeYield();
8088#endif
8089 }
8090
8091#if 0
8092 /* wait for workers to finish, and clean up after then */
8093 for(int t = 0; t<thread_count; t++) {
8094 if(workers[t]) {
8095 workers[t]->Wait();
8096 delete workers[t];
8097 }
8098 }
8099 delete [] workers;
8100#endif
8101
8102 delete prog;
8103}
AboutFrameImpl * g_pAboutDlg
Global instance.
Definition about.cpp:60
About * g_pAboutDlgLegacy
Global instance.
Definition about.cpp:59
class About
Class AboutFrameImpl.
AisDecoder * g_pAIS
Global instance.
Class AisDecoder and helpers.
Global state for AIS decoder.
Class AISTargetAlertDialog and helpers.
AIS target definitions.
Class AISTargetListDialog.
Class AISTargetQueryDialog.
bool SendNoRouteRmbRmc(Routeman &routeman)
Send RMC + a faked RMB when there is no active route.
Autopilot output support.
BasePlatform * g_BasePlatform
points to g_platform, handles brain-dead MS linker.
Chart canvas configuration state
Class CanvasOptions and helpers – Canvas options Window/Dialog.
Wrapper for creating a ChartCtx based on global vars.
General chart base definitions.
ChartDB * ChartData
Global instance.
Definition chartdb.cpp:70
Charts database management
ChartGroupArray * g_pGroupArray
Global instance.
Definition chartdbs.cpp:56
ChartCanvas * g_focusCanvas
Global instance.
Definition chcanv.cpp:1310
Generic Chart canvas base.
Dialog for displaying AIS target alerts.
Dialog for querying detailed information about an AIS target.
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &caption=_("Object Query"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=AIS_TARGET_QUERY_STYLE)
Creation.
Extends AboutFrame, providing implementation for various event handlers and additional methods.
The OpenCPN About dialog displaying information including version, authors, license,...
Definition about.h:61
double GetDisplayDIPMult(wxWindow *win)
Get the display scaling factor for DPI-aware rendering.
wxString & GetPrivateDataDir()
Return dir path for opencpn.log, etc., respecting -c cli option.
Represents an active track that is currently being recorded.
Definition track.h:227
Handles the AIS information GUI and sound alerts.
Base class for all chart types.
Definition chartbase.h:125
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:157
double m_cursor_lat
The latitude in degrees corresponding to the most recently processed cursor position.
Definition chcanv.h:781
double GetCanvasScaleFactor()
Return the number of logical pixels per meter for the screen.
Definition chcanv.h:484
void SetDisplaySizeMM(double size)
Set the width of the screen in millimeters.
Definition chcanv.cpp:2338
float GetVPScale()
Return the ViewPort scale factor, in physical pixels per meter.
Definition chcanv.h:472
void ZoomCanvasSimple(double factor)
Perform an immediate zoom operation without smooth transitions.
Definition chcanv.cpp:4595
bool SetVPScale(double sc, bool b_refresh=true)
Sets the viewport scale while maintaining the center point.
Definition chcanv.cpp:5326
double m_cursor_lon
The longitude in degrees corresponding to the most recently processed cursor position.
Definition chcanv.h:765
void ZoomCanvas(double factor, bool can_zoom_to_cursor=true, bool stoptimer=true)
Perform a smooth zoom operation on the chart canvas by the specified factor.
Definition chcanv.cpp:4601
bool SetViewPoint(double lat, double lon)
Centers the view on a specific lat/lon position.
Definition chcanv.cpp:5345
Manages the chart database and provides access to chart data.
Definition chartdb.h:95
bool Create(ArrayOfCDI &dir_array, wxGenericProgressDialog *pprog)
Creates a new chart database from a list of directories.
bool Update(ArrayOfCDI &dir_array, bool bForce, wxGenericProgressDialog *pprog)
Updates the chart database.
Represents a user-defined collection of logically related charts.
Definition chartdbs.h:468
void GenerateGLbmp()
In OpenGL mode, make the bitmap capture of the screen before the print method starts as to be sure th...
Overall logging handler, outputs to screen and log file.
bool IsVisible() const override
Return true if log is visible i.e., if it's any point using Add().
void Notify() override
Notify all listeners, no data supplied.
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 font_mgr.cpp:442
void ScrubList()
Cleans up stale font entries after a locale change.
Definition font_mgr.cpp:557
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Get a font object for a UI element.
Definition font_mgr.cpp:193
EventVar color_scheme_change
Notified when the day/dusk/night color scheme changes.
Definition gui_events.h:45
static void ReleaseInstance()
Release Instance.
static LocalServerApi & GetInstance()
Handle logging and forwarding of incoming n0183/n2k messages.
Definition multiplexer.h:56
Main application frame.
Definition ocpn_frame.h:139
void OnFrameTimer1(wxTimerEvent &event)
Main application timer handler called approximately once per second.
void InitApiListeners()
Setup handling of events from the local ipc/dbus API.
void OnFrameTenHzTimer(wxTimerEvent &event)
High-frequency timer handler running at 10Hz for smooth navigation updates.
NMEA Log Interface.
Definition nmea_log.h:70
virtual bool IsVisible() const =0
Return true if log is visible i.e., if it's any point using Add().
virtual void Add(const Logline &l)=0
Add a formatted string to log output.
double GetDisplaySizeMM()
Get the width of the screen in millimeters.
void Init(const KeyProvider &kp, const std::function< void(ObservedEvt &ev)> &action)
Initiate an object yet not listening.
Definition observable.h:295
void Listen(const std::string &key, wxEvtHandler *listener, wxEventType evt)
Set object to send wxEventType ev to listener on changes in key.
Custom event class for OpenCPN's notification system.
std::shared_ptr< const void > GetSharedPtr() const
Gets the event's payload data.
Data for a loaded plugin, including dl-loaded library.
int m_cap_flag
PlugIn Capabilities descriptor.
bool LoadAllPlugIns(bool enabled_plugins, bool keep_orphans=false)
Update catalog with imported metadata and load all plugin library files.
bool UnLoadAllPlugIns()
Unload allplugins i.
bool UpdatePlugIns()
Update the GetPlugInArray() list by reloading all plugins from disk.
const ArrayOfPlugIns * GetPlugInArray()
Return list of currently loaded plugins.
bool DeactivateAllPlugIns()
Deactivate all plugins.
static PrintDialog & GetInstance()
Get instance to handle the print process,.
Represents a waypoint or mark within the navigation system.
Definition route_point.h:71
bool m_bIsolatedMark
Flag indicating if the waypoint is a standalone mark.
bool m_bShowName
Flag indicating if the waypoint name should be shown.
Represents a navigational route in the navigation system.
Definition route.h:99
wxString m_RouteStartString
Name or description of the route's starting point.
Definition route.h:252
bool m_bDeleteOnArrival
Flag indicating whether the route should be deleted once navigation reaches the end.
Definition route.h:268
wxString m_RouteEndString
Name or description of the route's ending point.
Definition route.h:257
RoutePoint * m_pRouteActivePoint
Pointer to the currently active waypoint within this route.
Definition route.h:214
wxString m_RouteNameString
User-assigned name for the route.
Definition route.h:247
wxString m_GUID
Globally unique identifier for this route.
Definition route.h:273
EventVar on_routes_update
Notified when list of routes is updated (no data in event)
Definition routeman.h:265
bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint=NULL)
Activates a route for navigation.
Definition routeman.cpp:222
Manager for S57 chart SENC creation threads.
EventVar evt_resume
Notified when resuming from hibernate.
Definition sys_events.h:39
Definition tcmgr.h:89
Container for toolbar item properties.
Definition toolbar.h:45
Represents a single point in a track.
Definition track.h:59
wxDateTime GetCreateTime(void)
Retrieves the creation timestamp of a track point as a wxDateTime object.
Definition track.cpp:138
Represents a track, which is a series of connected track points.
Definition track.h:117
double view_scale_ppm
Requested view scale in physical pixels per meter (ppm), before applying projections.
Definition viewport.h:204
double rotation
Rotation angle of the viewport in radians.
Definition viewport.h:214
double skew
Angular distortion (shear transform) applied to the viewport in radians.
Definition viewport.h:212
double clon
Center longitude of the viewport in degrees.
Definition viewport.h:199
double clat
Center latitude of the viewport in degrees.
Definition viewport.h:197
Encapsulates persistent canvas configuration.
double iLat
Latitude of the center of the chart, in degrees.
bool bShowOutlines
Display chart outlines.
wxSize canvasSize
Canvas dimensions.
bool bShowDepthUnits
Display depth unit indicators.
double iLon
Longitude of the center of the chart, in degrees.
double iRotation
Initial rotation angle in radians.
bool bCourseUp
Orient display to course up.
bool bQuilt
Enable chart quilting.
bool bFollow
Enable vessel following mode.
double iScale
Initial chart scale factor.
bool bShowGrid
Display coordinate grid.
ChartCanvas * canvas
Pointer to associated chart canvas.
bool bShowCurrents
Display current information.
bool bShowTides
Display tide information.
bool bLookahead
Enable lookahead mode.
bool bHeadUp
Orient display to heading up.
Floating toolbar for iENC (International Electronic Navigational Chart) functionality.
wxRect GetRect(void) const
Return the coordinates of the compass widget, in physical pixels relative to the canvas window.
Definition compass.h:63
Floating toolbar dialog for OpenCPN.
Definition toolbar.h:390
Generic toolbar implementation in pure wxWidgets adapted from wxToolBarSimple (deprecated).
Definition toolbar.h:108
virtual void OnToolbarToolCallback(int id)
Handles toolbar tool clicks.
Represents an S57 format electronic navigational chart in OpenCPN.
Definition s57chart.h:90
The JSON parser.
Definition jsonreader.h:50
int Parse(const wxString &doc, wxJSONValue *val)
Parse the JSON document.
The JSON value class implementation.
Definition jsonval.h:84
bool HasMember(unsigned index) const
Return TRUE if the object contains an element at the specified index.
Definition jsonval.cpp:1298
wxString AsString() const
Return the stored value as a wxWidget's string.
Definition jsonval.cpp:872
CM93OffsetDialog * g_pCM93OffsetDialog
Global instance.
Definition cm93.cpp:73
Class cm93chart and helpers – CM93 chart state.
Global variables reflecting command line options and arguments.
wxColorHashMap * pcurrent_user_color_hash
Global instance.
Global color handling by name.
Communication drivers factory and support.
Driver registration container, a singleton.
NMEA Data Multiplexer Object.
Raw messages layer, supports sending and recieving navmsg messages.
Variables maintained by comm stack, read-only access for others.
APConsole * console
Global instance.
Definition concanv.cpp:54
Primary navigation console display for route and vessel tracking.
Config file user configuration interface.
bool g_always_send_rmb_rmc
Always send RMB and RMC n0183 messages even if there is no active route.
double g_COGAvg
Debug only usage.
int g_COGAvgSec
COG average period for Course Up Mode (sec)
std::vector< size_t > g_config_display_size_mm
Size of pysical screen in millimeters.
double g_display_size_mm
Physical display width (mm)
Global variables stored in configuration file.
Options | Connections GUI tab managing connections
Extern C linked utilities.
New NMEA Debugger successor main window.
std::vector< OCPN_MonitorInfo > g_monitor_info
Information about the monitors connected to the system.
Definition displays.cpp:45
Font list manager.
OpenCPN Georef utility.
OpenGL chart rendering canvas.
Platform independent GL includes.
glTextureManager * g_glTextureManager
Global instance.
Go to position dialog...
Hooks into gui available in model.
Misc GUI event vars, a singleton.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
Definition gui_lib.cpp:61
General purpose GUI support.
size_t g_current_monitor
Current monitor displaying main application frame.
Definition gui_vars.cpp:75
double vLat
Virtual lat from chcanv popup.
Definition gui_vars.cpp:72
double vLon
Virtual lon from chcanv popup.
Definition gui_vars.cpp:73
bool b_inCompressAllCharts
Flag to control adaptive UI scaling.
Definition gui_vars.cpp:35
int g_NeedDBUpdate
0 - No update needed, 1 - Update needed because there is no chart database, inform user 2 - Start upd...
Definition gui_vars.cpp:94
double g_current_monitor_dip_px_ratio
ratio to convert between DIP and physical pixels.
Definition gui_vars.cpp:69
Miscellaneous globals primarely used by gui layer, not persisted in configuration file.
GUI constant definitions.
iENCToolbar * g_iENCToolbar
Global instance.
iENC specific chart operations floating toolbar extension
Chart object layer.
The local API has a server side handling commands and a client part issuing commands.
Enhanced logging interface on top of wx/log.h.
MarkInfoDlg * g_pMarkInfoDialog
global instance
Definition mark_info.cpp:77
Waypoint properties maintenance dialog.
MUI (Modern User Interface) Control bar.
Multiplexer class and helpers.
MySQL based storage for routes, tracks, etc.
Utility functions.
Navigation Utility Functions without GUI dependencies.
User notifications manager.
s57RegistrarMgr * m_pRegistrarMan
Global instance.
Definition o_senc.cpp:62
S57 SENC File Object.
OpenCPN main program.
OCPN_AUIManager * g_pauimgr
Global instance.
OCPN_AUIManager.
OpenCPN top window.
MyFrame * gFrame
Global instance.
void LoadS57()
OpenCPN Platform specific support utilities.
PlugIn Object Definition/API.
wxWindow * GetOCPNCanvasWindow()
Gets OpenCPN's main canvas window.
double OCPN_GetDisplayContentScaleFactor()
Gets content scaling factor for current display.
void JumpToPosition(double lat, double lon, double scale)
Centers chart display on specified position at given scale.
wxWindow * GetCanvasUnderMouse()
Gets canvas window under mouse cursor.
void SendPluginMessage(wxString message_id, wxString message_body)
Sends message to other plugins.
options * g_options
Global instance.
Definition options.cpp:180
Options dialog.
bool bGPSValid
Indicate whether the Global Navigation Satellite System (GNSS) has a valid position.
Definition own_ship.cpp:34
double gHdm
Magnetic heading in degrees (0-359.99).
Definition own_ship.cpp:31
double gVar
Magnetic variation in degrees.
Definition own_ship.cpp:32
double gHdt
True heading in degrees (0-359.99).
Definition own_ship.cpp:30
double gLat
Vessel's current latitude in decimal degrees.
Definition own_ship.cpp:26
double gCog
Course over ground in degrees (0-359.99).
Definition own_ship.cpp:28
double gSog
Speed over ground in knots.
Definition own_ship.cpp:29
double gLon
Vessel's current longitude in decimal degrees.
Definition own_ship.cpp:27
Position, course, speed, etc.
Tools to send data to plugins.
Low level code to load plugins from disk, notably the PluginLoader class.
PlugInManager * g_pi_manager
Global instance.
PlugInManager and helper classes – Mostly gui parts (dialogs) and plugin API stuff.
Generic, styled prit dialog.
Print chart canvas mix-in.
wxRect g_blink_rect
Global instance.
Purpose: Track and Trackpoint drawing stuff.
RoutePropDlgImpl * pRoutePropDialog
Global instance.
Route properties dialog.
RoutePoint * pAnchorWatchPoint2
Global instance.
Definition routeman.cpp:64
Routeman * g_pRouteMan
Global instance.
Definition routeman.cpp:60
RouteList * pRouteList
Global instance.
Definition routeman.cpp:66
RoutePoint * pAnchorWatchPoint1
Global instance.
Definition routeman.cpp:63
Route * pAISMOBRoute
Global instance.
Definition routeman.cpp:61
Route Manager.
Routeman drawing stuff.
Manage routes dialog.
S57QueryDialog * g_pObjectQueryDialog
Global instance.
S57 object query result window.
S57 Chart Object.
Select * pSelect
Global instance.
Definition select.cpp:36
Selected route, segment, waypoint, etc.
const wxEventType wxEVT_OCPN_BUILDSENCTHREAD
Global instance.
SENCThreadManager * g_SencThreadManager
Global instance.
Class StdIcon, typically a small monochrome svg icon.
Represents an entry in the chart table, containing information about a single chart.
Definition chartdbs.h:183
A generic position and navigation data structure.
Definition ocpn_types.h:68
double kCog
Course over ground in degrees.
Definition ocpn_types.h:86
double kHdt
True heading in degrees.
Definition ocpn_types.h:111
int nSats
Number of satellites used in the fix.
Definition ocpn_types.h:126
double kHdm
Magnetic heading in degrees.
Definition ocpn_types.h:104
time_t FixTime
UTC time of fix.
Definition ocpn_types.h:118
double kLat
Latitude in decimal degrees.
Definition ocpn_types.h:75
double kSog
Speed over ground in knots.
Definition ocpn_types.h:92
double kVar
Magnetic variation in degrees.
Definition ocpn_types.h:98
double kLon
Longitude in decimal degrees.
Definition ocpn_types.h:83
Item in the log window.
Definition nmea_log.h:32
Suspend/resume and new devices events exchange point.
Tide and currents window.
TCMgr * ptcmgr
Global instance.
Definition tcmgr.cpp:42
Tide and Current Manager @TODO Add original author copyright.
Timer identification constants.
ocpnFloatingToolbarDialog * g_MainToolbar
Global instance.
Definition toolbar.cpp:65
OpenCPN Toolbar.
ActiveTrack * g_pActiveTrack
global instance
Definition track.cpp:99
std::vector< Track * > g_TrackList
Global instance.
Definition track.cpp:96
Recorded track abstraction.
TrackPropDlg * pTrackPropDialog
Global instance.
Track Properties Dialog.
void DestroyDeviceNotFoundDialogs()
Destroy all open "Device not found" dialog windows.
Access checks for comm devices and dongle.
WaypointMan drawing stuff.