OpenCPN Partial API docs
Loading...
Searching...
No Matches
ocpn_frame.h
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: OpenCPN Main wxWidgets Program
5 * Author: David Register
6 *
7 ***************************************************************************
8 * Copyright (C) 2010 by David S. Register *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 **************************************************************************/
25
26#ifndef _OFRAME_H
27#define _OFRAME_H
28
29#include <wx/print.h>
30#include <wx/power.h>
31
32#include <memory>
33#ifdef __WXMSW__
34#include <wx/msw/private.h>
35#endif
36
37#include "model/ocpn_types.h"
38#include "model/comm_appmsg_bus.h"
39#include "bbox.h"
40#include "connections_dlg.h"
41#include "color_handler.h"
42#include "data_monitor.h"
43#include "gui_lib.h"
44#include "load_errors_dlg.h"
45#include "observable_evtvar.h"
46#include "s52s57.h"
47#include "s57registrar_mgr.h"
48#include "SencManager.h"
49#include "displays.h"
50
51wxColour GetGlobalColor(wxString colorName);
52wxColour GetDialogColor(DialogColor color);
53
54// Helper to create menu label + hotkey string when registering menus
55wxString _menuText(wxString name, wxString shortcut);
56
57// The point for anchor watch should really be a class...
58double AnchorDistFix(double const d, double const AnchorPointMinDist,
59 double const AnchorPointMaxDist); // pjotrc 2010.02.22
60
61bool TestGLCanvas(wxString prog_dir);
62bool ReloadLocale();
63void ApplyLocale(void);
64
65void LoadS57();
66
67// Fwd definitions
68class ChartCanvas;
70class OCPN_MsgEvent;
71class options;
72class Track;
73class wxHtmlWindow;
74class ArrayOfCDI;
75
76//----------------------------------------------------------------------------
77// constants
78//----------------------------------------------------------------------------
79
80#define TIMER_GFRAME_1 999
81
82#define ID_CM93ZOOMG 102
83
84// Command identifiers for wxCommandEvents coming from the outside world.
85// Removed from enum to facilitate constant definition
86//
87// NOLINTBEGIN
88#define ID_CMD_APPLY_SETTINGS 300
89#define ID_CMD_NULL_REFRESH 301
90#define ID_CMD_TRIGGER_RESIZE 302
91#define ID_CMD_SETVP 303
92#define ID_CMD_POST_JSON_TO_PLUGINS 304
93#define ID_CMD_SOUND_FINISHED 306
94// NOLINTEND
95
96#ifdef __ANDROID__
97#define STAT_FIELD_COUNT 2
98#define STAT_FIELD_TICK -1
99#define STAT_FIELD_SOGCOG 0
100#define STAT_FIELD_CURSOR_LL -1
101#define STAT_FIELD_CURSOR_BRGRNG -1
102#define STAT_FIELD_SCALE 1
103#else
104#define STAT_FIELD_COUNT 5
105#define STAT_FIELD_TICK 0
106#define STAT_FIELD_SOGCOG 1
107#define STAT_FIELD_CURSOR_LL 2
108#define STAT_FIELD_CURSOR_BRGRNG 3
109#define STAT_FIELD_SCALE 4
110#endif
111
112// Define a constant GPS signal watchdog timeout value
113#define GPS_TIMEOUT_SECONDS 10
114
115#define MAX_COG_AVERAGE_SECONDS 60
116#define MAX_COGSOG_FILTER_SECONDS 60
117//----------------------------------------------------------------------------
118// fwd class declarations
119//----------------------------------------------------------------------------
120class ChartBase;
121class wxSocketEvent;
123class OCPN_DataStreamEvent;
124class AisTargetData;
125
126class MyFrame; // forward
127extern MyFrame* gFrame;
129bool ShowNavWarning();
130
131bool isSingleChart(ChartBase* chart);
132
138class MyFrame : public wxFrame {
139public:
140 MyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos,
141 const wxSize& size, long style);
142
143 ~MyFrame();
144
145 int GetApplicationMemoryUse(void);
146
147 void OnEraseBackground(wxEraseEvent& event);
148 void OnMaximize(wxMaximizeEvent& event);
149 void OnCloseWindow(wxCloseEvent& event);
150 void OnExit(wxCommandEvent& event);
151 void OnSize(wxSizeEvent& event);
152 void OnMove(wxMoveEvent& event);
153 void OnInitTimer(wxTimerEvent& event);
154
163 void OnFrameTimer1(wxTimerEvent& event);
164
165 bool DoChartUpdate(void);
166 void OnEvtPlugInMessage(OCPN_MsgEvent& event);
167 void OnMemFootTimer(wxTimerEvent& event);
168 void OnRecaptureTimer(wxTimerEvent& event);
169 void OnSENCEvtThread(OCPN_BUILDSENC_ThreadEvent& event);
170 void OnIconize(wxIconizeEvent& event);
171 void OnBellsFinished(wxCommandEvent& event);
172
184 void OnFrameTenHzTimer(wxTimerEvent& event);
185
186#ifdef wxHAS_POWER_EVENTS
187 void OnSuspending(wxPowerEvent& event);
188 void OnSuspended(wxPowerEvent& event);
189 void OnSuspendCancel(wxPowerEvent& event);
190 void OnResume(wxPowerEvent& event);
191#endif // wxHAS_POWER_EVENTS
192
193 void RefreshCanvasOther(ChartCanvas* ccThis);
194 void UpdateAllFonts(void);
195 void PositionConsole(void);
196 void OnToolLeftClick(wxCommandEvent& event);
197 void DoStackUp(ChartCanvas* cc);
198 void DoStackDown(ChartCanvas* cc);
199 void selectChartDisplay(int type, int family);
200 void applySettingsString(wxString settings);
201 void setStringVP(wxString VPS);
202 void InvalidateAllGL();
203 void RefreshAllCanvas(bool bErase = true);
204 void CancelAllMouseRoute();
205 void InvalidateAllQuilts();
206
207 void SetUpMode(ChartCanvas* cc, int mode);
208
209 ChartCanvas* GetPrimaryCanvas();
210 ChartCanvas* GetFocusCanvas();
211
212 void DoStackDelta(ChartCanvas* cc, int direction);
213 void DoSettings(void);
214 void DoSettingsNew(void);
215 void SwitchKBFocus(ChartCanvas* pCanvas);
216 ChartCanvas* GetCanvasUnderMouse();
217 int GetCanvasIndexUnderMouse();
218
219 bool DropMarker(bool atOwnShip = true);
220
221 void TriggerRecaptureTimer();
222 bool SetGlobalToolbarViz(bool viz);
223
224 void MouseEvent(wxMouseEvent& event);
225 void CenterView(ChartCanvas* cc, const LLBBox& bbox);
226
227 void JumpToPosition(ChartCanvas* cc, double lat, double lon, double scale);
228
229 void ProcessCanvasResize(void);
230
231 void BuildMenuBar(void);
232 void ApplyGlobalSettings(bool bnewtoolbar);
233 void RegisterGlobalMenuItems();
234 void UpdateGlobalMenuItems();
235 void UpdateGlobalMenuItems(ChartCanvas* cc);
236 void DoOptionsDialog();
237 void ProcessOptionsDialog(int resultFlags, ArrayOfCDI* pNewDirArray);
238 void PrepareOptionsClose(options* settings, int settings_return_value);
239
240 void DoPrint(void);
241 void ToggleDataQuality(ChartCanvas* cc);
242 void TogglebFollow(ChartCanvas* cc);
243 void ToggleFullScreen();
244 void ToggleChartBar(ChartCanvas* cc);
245 void SetbFollow(ChartCanvas* cc);
246 void ClearbFollow(ChartCanvas* cc);
247 void ToggleChartOutlines(ChartCanvas* cc);
248 void ToggleENCText(ChartCanvas* cc);
249 void ToggleSoundings(ChartCanvas* cc);
250#if 0
251 void ToggleRocks(void);
252#endif
253 bool ToggleLights(ChartCanvas* cc);
254 void ToggleAnchor(ChartCanvas* cc);
255 void ToggleAISDisplay(ChartCanvas* cc);
256 void ToggleAISMinimizeTargets(ChartCanvas* cc);
257
258 void ToggleTestPause(void);
259 void TrackOn(void);
260 void SetENCDisplayCategory(ChartCanvas* cc, enum _DisCat nset);
261 void ToggleNavobjects(ChartCanvas* cc);
262
263 Track* TrackOff(bool do_add_point = false);
264 void TrackDailyRestart(void);
265 bool ShouldRestartTrack();
266 void ToggleColorScheme();
267 void SetMenubarItemState(int item_id, bool state);
268 void SetMasterToolbarItemState(int tool_id, bool state);
269
270 void SetToolbarItemBitmaps(int tool_id, wxBitmap* bitmap,
271 wxBitmap* bmpDisabled);
272 void SetToolbarItemSVG(int tool_id, wxString normalSVGfile,
273 wxString rolloverSVGfile, wxString toggledSVGfile);
274 void ToggleQuiltMode(ChartCanvas* cc);
275 void UpdateControlBar(ChartCanvas* cc);
276
277 void SubmergeAllCanvasToolbars(void);
278 void SurfaceAllCanvasToolbars(void);
279 void SetAllToolbarScale(void);
280 void SetGPSCompassScale(void);
281 void InvalidateAllCanvasUndo();
282
283 void RefreshGroupIndices(void);
284
285 double GetBestVPScale(ChartBase* pchart);
286
287 DataMonitor* GetDataMonitor() const { return m_data_monitor; }
288
289 ColorScheme GetColorScheme();
290 void SetAndApplyColorScheme(ColorScheme cs);
291
292 void OnFrameTCTimer(wxTimerEvent& event);
293 void OnFrameCOGTimer(wxTimerEvent& event);
294
295 void HandleBasicNavMsg(std::shared_ptr<const BasicNavDataMsg> msg);
296 void HandleGPSWatchdogMsg(std::shared_ptr<const GPSWatchdogMsg> msg);
297
298 void ChartsRefresh();
299
300 bool CheckGroup(int igroup);
301 double GetMag(double a, double lat, double lon);
302 bool SendJSON_WMM_Var_Request(double lat, double lon, wxDateTime date);
303
304 void DestroyPersistentDialogs();
305 void TouchAISActive(void);
306 void UpdateAISTool(void);
307
308 void ActivateAISMOBRoute(const AisTargetData* ptarget);
309 void UpdateAISMOBRoute(const AisTargetData* ptarget);
310
311 wxStatusBar* m_pStatusBar;
312 wxMenuBar* m_pMenuBar;
313 int nBlinkerTick;
314 bool m_bTimeIsSet;
315
316 wxTimer InitTimer;
317 int m_iInitCount;
318 bool m_initializing;
319
320 wxTimer FrameTCTimer;
321 wxTimer FrameTimer1;
322 wxTimer FrameCOGTimer;
323 wxTimer MemFootTimer;
324 wxTimer m_resizeTimer;
325 wxTimer FrameTenHzTimer;
326
327 int m_BellsToPlay;
328 wxTimer BellsTimer;
329
330 // PlugIn support
331 int GetNextToolbarToolId() { return m_next_available_plugin_tool_id; }
332 void RequestNewToolbarArgEvent(wxCommandEvent& WXUNUSED(event)) {
333 return RequestNewMasterToolbar();
334 }
335 void RequestNewToolbars(bool bforcenew = false);
336
337 void ActivateMOB(void);
338 void UpdateGPSCompassStatusBoxes(bool b_force_new = false);
339 void UpdateRotationState(double rotation);
340
341 bool UpdateChartDatabaseInplace(ArrayOfCDI& DirArray, bool b_force,
342 bool b_prog,
343 const wxString& ChartListFileName);
344
345 bool m_bdefer_resize;
346 wxSize m_defer_size;
347 double COGTable[MAX_COG_AVERAGE_SECONDS];
348
349 void FastClose();
350 void SetChartUpdatePeriod();
351 void CreateCanvasLayout(bool b_useStoredSize = false);
352 void LoadHarmonics();
353 void ReloadAllVP();
354 void SetCanvasSizes(wxSize frameSize);
355
356 ocpnToolBarSimple* CreateMasterToolbar();
357 void RequestNewMasterToolbar(bool bforcenew = true);
358 bool CheckAndAddPlugInTool();
359 bool AddDefaultPositionPlugInTools();
360
361 void NotifyChildrenResize(void);
362 void UpdateCanvasConfigDescriptors();
363 void ScheduleSettingsDialog();
364 void ScheduleSettingsDialogNew();
365 void ScheduleDeleteSettingsDialog();
366 void ScheduleReconfigAndSettingsReload(bool reload, bool new_dialog);
367 void ScheduleReloadCharts();
368 static void RebuildChartDatabase();
369 void PositionIENCToolbar();
370
371 void InitAppMsgBusListener();
372 void InitApiListeners();
373 void ReleaseApiListeners();
374 void UpdateStatusBar(void);
375 void ConfigureStatusBar();
376 void FreezeCharts();
377 void ThawCharts();
378
379private:
380 void ProcessUnitTest();
381 void ProcessQuitFlag();
382 void ProcessDeferredTrackOn();
383 void SendFixToPlugins();
384 void ProcessAnchorWatch();
385 void ProcessLogAndBells();
386 void CalculateCOGAverage();
387 void CheckToolbarPosition();
388
389 void ODoSetSize(void);
390 void DoCOGSet(void);
391
392 void UpdateAllToolbars(ColorScheme cs);
393
394 void FilterCogSog(void);
395
396 void ApplyGlobalColorSchemetoStatusBar(void);
397
398 bool ScrubGroupArray();
399
400 void OnToolbarAnimateTimer(wxTimerEvent& event);
401 bool CollapseGlobalToolbar();
402
403 int m_StatusBarFieldCount;
404
405 wxDateTime m_MMEAeventTime;
406 unsigned long m_ulLastNMEATicktime;
407 int m_tick_idx;
408 wxDateTime m_fix_start_time;
409
410 wxString m_last_reported_chart_name;
411 wxString m_last_reported_chart_pubdate;
412
413 wxString m_lastAISiconName;
414
415 // Plugin Support
416 int m_next_available_plugin_tool_id;
417
418 double COGFilterTable[MAX_COGSOG_FILTER_SECONDS];
419 double SOGFilterTable[MAX_COGSOG_FILTER_SECONDS];
420
421 int m_ChartUpdatePeriod;
422 bool m_last_bGPSValid;
423 bool m_last_bVelocityValid;
424 double m_last_hdt;
425
426 wxString prev_locale;
427
435 time_t m_fixtime;
436 bool b_autofind;
437
438 time_t m_last_track_rotation_ts;
439 wxTimer ToolbarAnimateTimer;
440 int m_nMasterToolCountShown;
441 wxTimer m_recaptureTimer;
442
443 std::unique_ptr<LoadErrorsDlgCtrl> m_load_errors_dlg_ctrl;
444
445 ObservableListener listener_basic_navdata;
446 ObservableListener listener_gps_watchdog;
447 ObsListener m_on_raise_listener;
448 ObsListener m_on_quit_listener;
449 ObsListener m_routes_update_listener;
450 ObsListener m_evt_drv_msg_listener;
451
452 ConnectionsDlg* m_connections_dlg;
453 bool m_need_new_options;
454 wxArrayString pathArray;
455 double restoreScale[4];
456 unsigned int last_canvasConfig;
457 DataMonitor* m_data_monitor;
458
459 DECLARE_EVENT_TABLE()
460};
461
462#endif // _OFRAME_H
Base class for all chart types.
Definition chartbase.h:125
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:151
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:138
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
Represents a track, which is a series of connected track points.
Definition track.h:114
Floating toolbar dialog for OpenCPN.
Definition toolbar.h:386
Generic toolbar implementation in pure wxWidgets adapted from wxToolBarSimple (deprecated).
Definition toolbar.h:103
wxColour GetDialogColor(DialogColor color)
Retrieves a dialog color based on its role in the application's dialogs.
Global color handling by name.
DialogColor
Enumeration of color types used in dialogs.
Options | Connections GUI tab managing connections
New NMEA Debugger successor main window.
General purpose GUI support.
A common variable shared between producer and consumer which supports Listen() and Notify().