OpenCPN Partial API docs
Loading...
Searching...
No Matches
ocpn_frame.h
Go to the documentation of this file.
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
24#ifndef _OFRAME_H
25#define _OFRAME_H
26
27#include <wx/print.h>
28#include <wx/power.h>
29#include <wx/artprov.h>
30#include <wx/socket.h>
31#include <wx/html/htmlwin.h>
32#include <wx/aui/aui.h>
33#include <wx/aui/dockart.h>
34
35#include <memory>
36#ifdef __WXMSW__
37#include <wx/msw/private.h>
38#endif
39
40#include "ocpn_plugin.h"
41
43#include "model/gui.h"
44#include "model/ocpn_types.h"
45#include "model/track.h"
47#include "model/rest_server.h"
48
49#include "bbox.h"
50#include "canvas_menu.h"
51#include "chartbase.h"
52#include "chartdbs.h"
53#include "chcanv.h"
54#include "color_handler.h"
55#include "connections_dlg.h"
56#include "data_monitor.h"
57#include "displays.h"
58#include "gui_lib.h"
59#include "load_errors_dlg.h"
60#include "observable_evtvar.h"
61#include "options.h"
62#include "pluginmanager.h"
63#include "s52_plib_utils.h"
64#include "s52s57.h"
65#include "s57registrar_mgr.h"
66#include "senc_manager.h"
67#include "toolbar.h"
68#include "top_frame.h"
69#include "undo_defs.h"
70
71//----------------------------------------------------------------------------
72// constants
73//----------------------------------------------------------------------------
74
75#define TIMER_GFRAME_1 999
76
77// Command identifiers for wxCommandEvents coming from the outside world.
78// Removed from enum to facilitate constant definition
79//
80// NOLINTBEGIN
81#define ID_CMD_APPLY_SETTINGS 300
82#define ID_CMD_NULL_REFRESH 301
83#define ID_CMD_TRIGGER_RESIZE 302
84#define ID_CMD_SETVP 303
85#define ID_CMD_POST_JSON_TO_PLUGINS 304
86#define ID_CMD_SOUND_FINISHED 306
87// NOLINTEND
88
89using OpenFileFunc = std::function<bool(const std::string& path)>;
90//----------------------------------------------------------------------------
91// fwd class declarations
92//----------------------------------------------------------------------------
93
94class MyFrame; // forward
95extern MyFrame* gFrame;
97class options; // circular
98
99// FIXME (leamas) to have utility functions in top window is a really bad idea.
100bool ShowNavWarning();
101
102void ApplyLocale(void);
103
109class MyFrame : public AbstractTopFrame, public S52PlibUtils {
110public:
111 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
112 RestServer& rest_server, wxAuiDefaultDockArt* pauidockart,
113 OpenFileFunc open_gpx_file);
114
115 ~MyFrame();
116
117 void SetGPSCompassScale() override;
118 void FastClose() override;
119 void RefreshAllCanvas(bool bErase = true) override;
120 void UpdateStatusBar() override;
121 void ToggleFullScreen() override;
122 Track* TrackOff(bool do_add_point = false) override;
123 void TrackOn(void) override;
124 void ProcessOptionsDialog(int resultFlags) override {
125 ProcessOptionsDialog(resultFlags, nullptr);
126 }
127
128 void SetAlertString(wxString msg) override {
129 GetPrimaryCanvas()->SetAlertString(msg);
130 }
131
132 void JumpToPosition(double lat, double lon) override {
133 if (!GetFocusCanvas()) return;
134 JumpToPosition(GetFocusCanvas(), lat, lon, GetFocusCanvas()->GetVPScale());
135 }
136
137 void JumpToPosition(double lat, double lon, double scale) override {
138 if (!GetFocusCanvas()) return;
139 JumpToPosition(GetFocusCanvas(), lat, lon, scale);
140 }
141
142 void JumpToPosition(AbstractChartCanvas* acc, double lat, double lon,
143 double scale) override {
144 if (!acc) return;
145 auto cc = dynamic_cast<ChartCanvas*>(acc);
146 assert(cc);
147 JumpToPosition(cc, lat, lon, scale);
148 }
149 void JumpToPosition(AbstractChartCanvas* acc, double lat,
150 double lon) override {
151 if (!acc) return;
152 auto cc = dynamic_cast<ChartCanvas*>(acc);
153 assert(cc);
154 JumpToPosition(cc, lat, lon, GetFocusCanvas()->GetVPScale());
155 }
156
157 AbstractChartCanvas* GetAbstractPrimaryCanvas() override {
158 return GetPrimaryCanvas();
159 }
160
161 AbstractChartCanvas* GetAbstractFocusCanvas() override {
162 return GetFocusCanvas();
163 }
164
165 void SwitchKBFocus(AbstractChartCanvas* acc) override {
166 return SwitchKBFocus(dynamic_cast<ChartCanvas*>(acc));
167 }
168
169 double GetCanvasTrueScale() override {
170 return GetPrimaryCanvas()->GetCanvasTrueScale();
171 }
172
173 double GetPixPerMM() override { return GetPrimaryCanvas()->GetPixPerMM(); }
174
175 double GetContentScaleFactor() override {
176 if (GetPrimaryCanvas())
177 return GetPrimaryCanvas()->GetContentScaleFactor();
178 else
179 return 1.0;
180 }
181
182 void RequestNewToolbars(bool bforcenew = false) override;
183
184 bool GetCanvasPointPix(double rlat, double rlon, wxPoint* r) override {
185 return GetFocusCanvas()->GetCanvasPointPix(rlat, rlon, r);
186 }
187
188 virtual wxSize GetFocusCanvasSize() override {
189 return GetFocusCanvas() ? GetFocusCanvas()->GetSize() : wxSize(0, 0);
190 }
191
192 void CancelAllMouseRoute() override;
193 void InvalidateAllCanvasUndo() override;
194 void PositionConsole() override;
195 void InvalidateAllGL() override;
196 double GetBestVPScale(AbstractChart* arg) override {
197 auto chart = dynamic_cast<ChartBase*>(arg);
198 assert(chart);
199 return GetPrimaryCanvas()->GetBestVPScale(chart);
200 }
201
202 void DoStackUp(AbstractChartCanvas* cc) override;
203 void DoStackDown(AbstractChartCanvas* cc) override;
204 void LoadHarmonics() override;
205
206 bool DropMarker(bool atOwnShip = true) override;
207 double GetMag(double a, double lat, double lon) override;
208 void SetMasterToolbarItemState(int tool_id, bool state) override;
209 bool DoChartUpdate() override;
210 void ProcessCanvasResize() override;
211 bool SetGlobalToolbarViz(bool viz) override;
212 void ToggleQuiltMode(AbstractChartCanvas* acc) override {
213 auto cc = dynamic_cast<ChartCanvas*>(acc);
214 ToggleQuiltMode(cc);
215 }
216 void UpdateGlobalMenuItems(AbstractChartCanvas* acc) override {
217 UpdateGlobalMenuItems(dynamic_cast<ChartCanvas*>(acc));
218 }
219 void UpdateGlobalMenuItems() override;
220 void RefreshCanvasOther(AbstractChartCanvas* ccThis) override {
221 RefreshCanvasOther(dynamic_cast<ChartCanvas*>(ccThis));
222 }
223 virtual double* GetCOGTable() override { return COGTable; }
224 virtual void StartCogTimer() override {
225 FrameCOGTimer.Start(100, wxTIMER_CONTINUOUS);
226 }
227
228 wxWindow* GetPrimaryCanvasWindow() override { return GetPrimaryCanvas(); }
229 void ApplyGlobalSettings(bool bnewtoolbar) override;
230 void SetMenubarItemState(int item_id, bool state) override;
231 void ToggleColorScheme() override;
232 void ActivateMOB() override;
233 void ToggleTestPause() override;
234
235 void ToggleChartBar(AbstractChartCanvas* acc) override {
236 ToggleChartBar(dynamic_cast<ChartCanvas*>(acc));
237 }
238 void DoSettings() override;
239
240 void UpdateRotationState(double rotation) override;
241 void SetChartUpdatePeriod() override;
242 wxStatusBar* GetStatusBar() override { return wxFrame::GetStatusBar(); }
243 wxStatusBar* GetFrameStatusBar() const override { return m_pStatusBar; }
244 void SetENCDisplayCategory(AbstractChartCanvas* acc,
245 enum _DisCat nset) override {
246 SetENCDisplayCategory(dynamic_cast<ChartCanvas*>(acc), nset);
247 }
248 int GetCanvasIndexUnderMouse() override;
249
250 double GetCanvasRefScale() override {
251 return GetPrimaryCanvas()->GetVP().ref_scale;
252 ;
253 }
254
255#ifdef ocpnUSE_GL
256 void SendGlJsonConfigMsg() override {
257 if (GetPrimaryCanvas() && GetPrimaryCanvas()->GetglCanvas())
258 GetPrimaryCanvas()->GetglCanvas()->SendJSONConfigMessage();
259 }
260 bool CanAccelerateGlPanning() override {
261 return GetPrimaryCanvas()->GetglCanvas()->CanAcceleratePanning();
262 }
263 void SetupGlCompression() override {
264 GetPrimaryCanvas()->GetglCanvas()->SetupCompression();
265 }
266 wxString GetGlVersionString() override {
267 return GetPrimaryCanvas()->GetglCanvas()->GetVersionString();
268 }
269 wxGLCanvas* GetWxGlCanvas() override {
270 return GetPrimaryCanvas()->GetglCanvas();
271 }
272
273#else
274 void SendGlJsonConfigMsg() override {}
275 bool CanAccelerateGlPanning() override { return false; }
276 void SetupGlCompression() override {}
277 wxString GetGlVersionString() override { return ""; }
278 wxGLCanvas* GetWxGlCanvas() override { return nullptr; }
279#endif
280 void SwitchKBFocus(ChartCanvas* pCanvas);
281 int GetNextToolbarToolId() override {
282 return m_next_available_plugin_tool_id;
283 }
284 void SetToolbarItemBitmaps(int tool_id, wxBitmap* bitmap,
285 wxBitmap* bmpDisabled) override;
286 void SetToolbarItemSVG(int tool_id, wxString normalSVGfile,
287 wxString rolloverSVGfile,
288 wxString toggledSVGfile) override;
289 void UpdateAllFonts() override;
290 void ScheduleReconfigAndSettingsReload(bool reload, bool new_dialog) override;
291 void ScheduleReloadCharts() override;
292 void ChartsRefresh() override;
293 void FreezeCharts() override;
294 void ThawCharts() override;
295
296 void ScheduleDeleteSettingsDialog() override;
297
298 void BeforeUndoableAction(UndoType undo_type, RoutePoint* point,
299 UndoBeforePointerType pointer_type,
300 UndoItemPointer pointer) override {
301 if (!GetPrimaryCanvas()) return;
302 GetPrimaryCanvas()->undo->BeforeUndoableAction(undo_type, point,
303 pointer_type, pointer);
304 }
305
306 virtual void AfterUndoableAction(UndoItemPointer pointer) override {
307 GetPrimaryCanvas()->undo->AfterUndoableAction(pointer);
308 }
309 virtual void TouchAISActive() override;
310 virtual void UpdateAISMOBRoute(const AisTargetData* ptarget) override;
311 virtual void ActivateAISMOBRoute(const AisTargetData* ptarget) override;
312 void OnToolLeftClick(wxCommandEvent& event) override;
313
314 void SetENCDisplayCategory(ChartCanvas* cc, enum _DisCat nset);
315 void ToggleQuiltMode(ChartCanvas* cc);
316
317 wxFont* GetFont(wxFont* font, double scale) override;
318 int GetApplicationMemoryUse(void);
319
320 void OnEraseBackground(wxEraseEvent& event);
321 void OnMaximize(wxMaximizeEvent& event);
322 void OnCloseWindow(wxCloseEvent& event);
323 void OnExit(wxCommandEvent& event);
324 void OnSize(wxSizeEvent& event);
325 void OnMove(wxMoveEvent& event);
326 void OnInitTimer(wxTimerEvent& event);
327
336 void OnFrameTimer1(wxTimerEvent& event);
337
338 void OnEvtPlugInMessage(OCPN_MsgEvent& event);
339 void OnMemFootTimer(wxTimerEvent& event);
340 void OnRecaptureTimer(wxTimerEvent& event);
341 void OnSENCEvtThread(OCPN_BUILDSENC_ThreadEvent& event);
342 void OnIconize(wxIconizeEvent& event);
343 void OnBellsFinished(wxCommandEvent& event);
344
356 void OnFrameTenHzTimer(wxTimerEvent& event);
357
358#ifdef wxHAS_POWER_EVENTS
359 void OnSuspending(wxPowerEvent& event);
360 void OnSuspended(wxPowerEvent& event);
361 void OnSuspendCancel(wxPowerEvent& event);
362 void OnResume(wxPowerEvent& event);
363#endif // wxHAS_POWER_EVENTS
364
365 void RefreshCanvasOther(ChartCanvas* ccThis);
366 void selectChartDisplay(int type, int family);
367 void applySettingsString(wxString settings);
368 void setStringVP(wxString VPS);
369 void InvalidateAllQuilts();
370
371 void SetUpMode(ChartCanvas* cc, int mode);
372
373 ChartCanvas* GetPrimaryCanvas();
374 ChartCanvas* GetFocusCanvas();
375 void DoStackUp(ChartCanvas* cc);
376 void DoStackDown(ChartCanvas* cc);
377 void NotifyChildrenResize();
378
379 void DoStackDelta(ChartCanvas* cc, int direction);
380 void DoSettingsNew(void);
381 ChartCanvas* GetCanvasUnderMouse();
382
383 void TriggerRecaptureTimer();
384
385 void MouseEvent(wxMouseEvent& event);
386 void CenterView(ChartCanvas* cc, const LLBBox& bbox);
387
388 void JumpToPosition(ChartCanvas* cc, double lat, double lon, double scale);
389
390 void BuildMenuBar(void);
391 void RegisterGlobalMenuItems();
392 void UpdateGlobalMenuItems(ChartCanvas* cc);
393 void DoOptionsDialog();
394 void ProcessOptionsDialog(int resultFlags, ArrayOfCDI* pNewDirArray);
395 void PrepareOptionsClose(options* settings, int settings_return_value);
396
397 void DoPrint(void);
398 void ToggleDataQuality(ChartCanvas* cc);
399 void TogglebFollow(ChartCanvas* cc);
400 void ToggleChartBar(ChartCanvas* cc);
401 void SetbFollow(ChartCanvas* cc);
402 void ClearbFollow(ChartCanvas* cc);
403 void ToggleChartOutlines(ChartCanvas* cc);
404 void ToggleENCText(ChartCanvas* cc);
405 void ToggleSoundings(ChartCanvas* cc);
406#if 0
407 void ToggleRocks(void);
408#endif
409 bool ToggleLights(ChartCanvas* cc);
410 void ToggleAnchor(ChartCanvas* cc);
411 void ToggleAISDisplay(ChartCanvas* cc);
412 void ToggleAISMinimizeTargets(ChartCanvas* cc);
413
414 void ToggleNavobjects(ChartCanvas* cc);
415
416 void TrackDailyRestart(void);
417 bool ShouldRestartTrack();
418 void InitializeTrackRestart();
419
420 void UpdateControlBar(ChartCanvas* cc);
421
422 void SubmergeAllCanvasToolbars(void);
423 void SurfaceAllCanvasToolbars(void);
424 void SetAllToolbarScale(void);
425
426 void RefreshGroupIndices(void);
427
428 double GetBestVPScale(ChartBase* pchart);
429
430 DataMonitor* GetDataMonitor() const { return m_data_monitor; }
431
432 void SetAndApplyColorScheme(ColorScheme cs);
433
434 void OnFrameTCTimer(wxTimerEvent& event);
435 void OnFrameCOGTimer(wxTimerEvent& event);
436
437 void HandleBasicNavMsg(std::shared_ptr<const BasicNavDataMsg> msg);
438 void HandleGPSWatchdogMsg(std::shared_ptr<const GPSWatchdogMsg> msg);
439
440 bool CheckGroup(int igroup);
441 bool SendJSON_WMM_Var_Request(double lat, double lon, wxDateTime date);
442
443 void DestroyPersistentDialogs();
444 void UpdateAISTool(void);
445
446 wxMenuBar* m_pMenuBar;
447 bool m_bTimeIsSet;
448
449 wxTimer InitTimer;
450 int m_iInitCount;
451 bool m_initializing;
452
453 wxTimer FrameTCTimer;
454 wxTimer FrameTimer1;
455 wxTimer FrameCOGTimer;
456 wxTimer MemFootTimer;
457 wxTimer m_resizeTimer;
458 wxTimer FrameTenHzTimer;
459
460 int m_BellsToPlay;
461 wxTimer BellsTimer;
462
463 wxGenericProgressDialog* Updateprog = nullptr;
464
465 // PlugIn support
466 void RequestNewToolbarArgEvent(wxCommandEvent& WXUNUSED(event)) {
467 return RequestNewMasterToolbar();
468 }
469
470 void UpdateGPSCompassStatusBoxes(bool b_force_new = false);
471
472 bool UpdateChartDatabaseInplace(ArrayOfCDI& DirArray, bool b_force,
473 bool b_prog,
474 const wxString& ChartListFileName);
475 void FinalizeChartDBUpdate();
476
477 bool m_bdefer_resize;
478 wxSize m_defer_size;
479 double COGTable[kMaxCogAverageSeconds];
480
481 void CreateCanvasLayout(bool b_useStoredSize = false);
482 void ReloadAllVP();
483 void SetCanvasSizes(wxSize frameSize);
484
485 ocpnToolBarSimple* CreateMasterToolbar();
486 void RequestNewMasterToolbar(bool bforcenew = true);
487 bool CheckAndAddPlugInTool();
488 bool AddDefaultPositionPlugInTools();
489
490 void UpdateCanvasConfigDescriptors();
491 void ScheduleSettingsDialog();
492 void ScheduleSettingsDialogNew();
493 static void RebuildChartDatabase();
494 void PositionIENCToolbar();
495
496 void InitAppMsgBusListener();
497 void InitApiListeners();
498 void ReleaseApiListeners();
499 void ConfigureStatusBar();
500
501private:
502 void ProcessUnitTest();
503 bool ProcessQuitFlag();
504 void ProcessDeferredTrackOn();
505 void SendFixToPlugins();
506 void ProcessAnchorWatch();
507 void ProcessLogAndBells();
508 void CalculateCOGAverage();
509 void CheckToolbarPosition();
510
511 void ODoSetSize(void);
512 void DoCOGSet(void);
513
514 void UpdateAllToolbars(ColorScheme cs);
515
516 void FilterCogSog(void);
517
518 void ApplyGlobalColorSchemetoStatusBar(void);
519
520 bool ScrubGroupArray();
521
522 void OnToolbarAnimateTimer(wxTimerEvent& event);
523 bool CollapseGlobalToolbar();
524
525 int m_StatusBarFieldCount;
526
527 wxDateTime m_MMEAeventTime;
528 unsigned long m_ulLastNMEATicktime;
529 int m_tick_idx;
530 wxDateTime m_fix_start_time;
531
532 wxString m_last_reported_chart_name;
533 wxString m_last_reported_chart_pubdate;
534
535 wxString m_lastAISiconName;
536
537 // Plugin Support
538 int m_next_available_plugin_tool_id;
539
540 double COGFilterTable[kMaxCogsogFilterSeconds];
541 double SOGFilterTable[kMaxCogsogFilterSeconds];
542
543 int m_ChartUpdatePeriod;
544 bool m_last_bGPSValid;
545 bool m_last_bVelocityValid;
546 double m_last_hdt;
547
548 wxString prev_locale;
549
557 time_t m_fixtime;
558 bool b_autofind;
559
560 wxDateTime m_target_rotate_time;
561
562 wxTimer ToolbarAnimateTimer;
563 int m_nMasterToolCountShown;
564 wxTimer m_recaptureTimer;
565
566 std::unique_ptr<LoadErrorsDlgCtrl> m_load_errors_dlg_ctrl;
567 wxString m_gshhg_chart_loc;
568
569private:
570 ObservableListener listener_basic_navdata;
571 ObservableListener listener_gps_watchdog;
572 ObsListener m_on_raise_listener;
573 ObsListener m_on_quit_listener;
574 ObsListener m_routes_update_listener;
575 ObsListener m_evt_drv_msg_listener;
576 ObsListener m_update_statusbar_listener;
577 ObsListener m_center_aistarget_listener;
578 ObsListener m_reload_charts_listener;
579 ToolbarDlgCallbacks m_toolbar_callbacks;
580
581 wxStatusBar* m_pStatusBar;
582 ConnectionsDlg* m_connections_dlg;
583 bool m_need_new_options;
584 wxArrayString pathArray;
585 double restoreScale[4];
586 unsigned int last_canvasConfig;
587 DataMonitor* m_data_monitor;
588 wxAuiDefaultDockArt* m_pauidockart;
589 RestServer& m_rest_server;
590 OpenFileFunc m_open_gpx_file;
591
592 void CenterAisTarget(const std::shared_ptr<const AisTargetData>& ais_target);
593
594 DECLARE_EVENT_TABLE()
595};
596
597#endif // _OFRAME_H
AIS target definitions.
Canvas context (right click) menu handler.
General chart base definitions.
Basic chart info storage.
Generic Chart canvas base.
Minimal ChartCAnvas interface with very little dependencies.
Minimal Chart interface, for now just an anonymous pointer.
Base class for all chart types.
Definition chartbase.h:126
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:173
bool GetCanvasPointPix(double rlat, double rlon, wxPoint *r)
Convert latitude/longitude to canvas pixel coordinates (physical pixels) rounded to nearest integer.
Definition chcanv.cpp:4547
double GetPixPerMM()
Get the number of logical pixels per millimeter on the screen.
Definition chcanv.h:542
Options | Connections tab implementation, basically a UI for maintaining the list of connections.
Overall logging handler, outputs to screen and log file.
Main application frame.
Definition ocpn_frame.h:109
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.
Define an action to be performed when a KeyProvider is notified.
Definition observable.h:257
Keeps listening over its lifespan, removes itself on destruction.
Definition observable.h:155
AbstractRestServer implementation and interface to underlying IO thread.
Represents a waypoint or mark within the navigation system.
Definition route_point.h:71
Represents a track, which is a series of connected track points.
Definition track.h:117
double ref_scale
The nominal scale of the "reference chart" for this view.
Definition viewport.h:221
Generic toolbar implementation in pure wxWidgets adapted from wxToolBarSimple (deprecated).
Definition toolbar.h:109
Global color handling by name.
Decoded messages send/receive support.
Options | Connections GUI tab managing connections
New NMEA Debugger successor main window.
Display utilities.
Hooks into gui available in model.
General purpose GUI support.
A common variable shared between producer and consumer which supports Listen() and Notify().
MyFrame * gFrame
Global instance.
PlugIn Object Definition/API.
Navigation data types.
Options dialog.
PlugInManager and helper classes – Mostly gui parts (dialogs) and plugin API stuff.
REST API server.
S57 Chart Object.
OpenCPN Toolbar.
Abstract gFrame/MyFrame interface.
Recorded track abstraction.
Undo features argument definitions.