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 "comm_overflow_dlg.h"
41#include "connections_dlg.h"
42#include "color_handler.h"
43#include "data_monitor.h"
44#include "gui_lib.h"
45#include "load_errors_dlg.h"
46#include "observable_evtvar.h"
47#include "s52s57.h"
48#include "s57registrar_mgr.h"
49#include "SencManager.h"
50#include "displays.h"
51
52wxColour GetGlobalColor(wxString colorName);
53wxColour GetDialogColor(DialogColor color);
54
55// Helper to create menu label + hotkey string when registering menus
56wxString _menuText(wxString name, wxString shortcut);
57
58// The point for anchor watch should really be a class...
59double AnchorDistFix(double const d, double const AnchorPointMinDist,
60 double const AnchorPointMaxDist); // pjotrc 2010.02.22
61
62bool TestGLCanvas(wxString prog_dir);
63bool ReloadLocale();
64void ApplyLocale(void);
65
66void LoadS57();
67
68// Fwd definitions
69class ChartCanvas;
71class OCPN_MsgEvent;
72class options;
73class Track;
74class wxHtmlWindow;
75class ArrayOfCDI;
76
77//----------------------------------------------------------------------------
78// constants
79//----------------------------------------------------------------------------
80
81#define TIMER_GFRAME_1 999
82
83#define ID_CM93ZOOMG 102
84
85// Command identifiers for wxCommandEvents coming from the outside world.
86// Removed from enum to facilitate constant definition
87//
88// NOLINTBEGIN
89#define ID_CMD_APPLY_SETTINGS 300
90#define ID_CMD_NULL_REFRESH 301
91#define ID_CMD_TRIGGER_RESIZE 302
92#define ID_CMD_SETVP 303
93#define ID_CMD_POST_JSON_TO_PLUGINS 304
94#define ID_CMD_SOUND_FINISHED 306
95// NOLINTEND
96
97#ifdef __ANDROID__
98#define STAT_FIELD_COUNT 2
99#define STAT_FIELD_TICK -1
100#define STAT_FIELD_SOGCOG 0
101#define STAT_FIELD_CURSOR_LL -1
102#define STAT_FIELD_CURSOR_BRGRNG -1
103#define STAT_FIELD_SCALE 1
104#else
105#define STAT_FIELD_COUNT 5
106#define STAT_FIELD_TICK 0
107#define STAT_FIELD_SOGCOG 1
108#define STAT_FIELD_CURSOR_LL 2
109#define STAT_FIELD_CURSOR_BRGRNG 3
110#define STAT_FIELD_SCALE 4
111#endif
112
113// Define a constant GPS signal watchdog timeout value
114#define GPS_TIMEOUT_SECONDS 10
115
116#define MAX_COG_AVERAGE_SECONDS 60
117#define MAX_COGSOG_FILTER_SECONDS 60
118//----------------------------------------------------------------------------
119// fwd class declarations
120//----------------------------------------------------------------------------
121class ChartBase;
122class wxSocketEvent;
124class OCPN_DataStreamEvent;
125class AisTargetData;
126
127bool ShowNavWarning();
128
129bool isSingleChart(ChartBase* chart);
130
136class MyFrame : public wxFrame {
137public:
138 MyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos,
139 const wxSize& size, long style);
140
141 ~MyFrame();
142
143 int GetApplicationMemoryUse(void);
144
145 void OnEraseBackground(wxEraseEvent& event);
146 void OnMaximize(wxMaximizeEvent& event);
147 void OnCloseWindow(wxCloseEvent& event);
148 void OnExit(wxCommandEvent& event);
149 void OnSize(wxSizeEvent& event);
150 void OnMove(wxMoveEvent& event);
151 void OnInitTimer(wxTimerEvent& event);
152 void OnFrameTimer1(wxTimerEvent& event);
153 bool DoChartUpdate(void);
154 void OnEvtPlugInMessage(OCPN_MsgEvent& event);
155 void OnMemFootTimer(wxTimerEvent& event);
156 void OnRecaptureTimer(wxTimerEvent& event);
157 void OnSENCEvtThread(OCPN_BUILDSENC_ThreadEvent& event);
158 void OnIconize(wxIconizeEvent& event);
159 void OnBellsFinished(wxCommandEvent& event);
160 void OnFrameTenHzTimer(wxTimerEvent& event);
161
162#ifdef wxHAS_POWER_EVENTS
163 void OnSuspending(wxPowerEvent& event);
164 void OnSuspended(wxPowerEvent& event);
165 void OnSuspendCancel(wxPowerEvent& event);
166 void OnResume(wxPowerEvent& event);
167#endif // wxHAS_POWER_EVENTS
168
169 void RefreshCanvasOther(ChartCanvas* ccThis);
170 void UpdateAllFonts(void);
171 void PositionConsole(void);
172 void OnToolLeftClick(wxCommandEvent& event);
173 void DoStackUp(ChartCanvas* cc);
174 void DoStackDown(ChartCanvas* cc);
175 void selectChartDisplay(int type, int family);
176 void applySettingsString(wxString settings);
177 void setStringVP(wxString VPS);
178 void InvalidateAllGL();
179 void RefreshAllCanvas(bool bErase = true);
180 void CancelAllMouseRoute();
181 void InvalidateAllQuilts();
182
183 void SetUpMode(ChartCanvas* cc, int mode);
184
185 ChartCanvas* GetPrimaryCanvas();
186 ChartCanvas* GetFocusCanvas();
187
188 void DoStackDelta(ChartCanvas* cc, int direction);
189 void DoSettings(void);
190 void DoSettingsNew(void);
191 void SwitchKBFocus(ChartCanvas* pCanvas);
192 ChartCanvas* GetCanvasUnderMouse();
193 int GetCanvasIndexUnderMouse();
194
195 bool DropMarker(bool atOwnShip = true);
196
197 void TriggerRecaptureTimer();
198 bool SetGlobalToolbarViz(bool viz);
199
200 void MouseEvent(wxMouseEvent& event);
201 void CenterView(ChartCanvas* cc, const LLBBox& bbox);
202
203 void JumpToPosition(ChartCanvas* cc, double lat, double lon, double scale);
204
205 void ProcessCanvasResize(void);
206
207 void BuildMenuBar(void);
208 void ApplyGlobalSettings(bool bnewtoolbar);
209 void RegisterGlobalMenuItems();
210 void UpdateGlobalMenuItems();
211 void UpdateGlobalMenuItems(ChartCanvas* cc);
212 void DoOptionsDialog();
213 void ProcessOptionsDialog(int resultFlags, ArrayOfCDI* pNewDirArray);
214 void PrepareOptionsClose(options* settings, int settings_return_value);
215
216 void DoPrint(void);
217 void ToggleDataQuality(ChartCanvas* cc);
218 void TogglebFollow(ChartCanvas* cc);
219 void ToggleFullScreen();
220 void ToggleChartBar(ChartCanvas* cc);
221 void SetbFollow(ChartCanvas* cc);
222 void ClearbFollow(ChartCanvas* cc);
223 void ToggleChartOutlines(ChartCanvas* cc);
224 void ToggleENCText(ChartCanvas* cc);
225 void ToggleSoundings(ChartCanvas* cc);
226#if 0
227 void ToggleRocks(void);
228#endif
229 bool ToggleLights(ChartCanvas* cc);
230 void ToggleAnchor(ChartCanvas* cc);
231 void ToggleAISDisplay(ChartCanvas* cc);
232 void ToggleAISMinimizeTargets(ChartCanvas* cc);
233
234 void ToggleTestPause(void);
235 void TrackOn(void);
236 void SetENCDisplayCategory(ChartCanvas* cc, enum _DisCat nset);
237 void ToggleNavobjects(ChartCanvas* cc);
238
239 Track* TrackOff(bool do_add_point = false);
240 void TrackDailyRestart(void);
241 bool ShouldRestartTrack();
242 void ToggleColorScheme();
243 void SetMenubarItemState(int item_id, bool state);
244 void SetMasterToolbarItemState(int tool_id, bool state);
245
246 void SetToolbarItemBitmaps(int tool_id, wxBitmap* bitmap,
247 wxBitmap* bmpDisabled);
248 void SetToolbarItemSVG(int tool_id, wxString normalSVGfile,
249 wxString rolloverSVGfile, wxString toggledSVGfile);
250 void ToggleQuiltMode(ChartCanvas* cc);
251 void UpdateControlBar(ChartCanvas* cc);
252
253 void SubmergeAllCanvasToolbars(void);
254 void SurfaceAllCanvasToolbars(void);
255 void SetAllToolbarScale(void);
256 void SetGPSCompassScale(void);
257 void InvalidateAllCanvasUndo();
258
259 void RefreshGroupIndices(void);
260
261 double GetBestVPScale(ChartBase* pchart);
262
263 DataMonitor* GetDataMonitor() const { return m_data_monitor; }
264
265 ColorScheme GetColorScheme();
266 void SetAndApplyColorScheme(ColorScheme cs);
267
268 void OnFrameTCTimer(wxTimerEvent& event);
269 void OnFrameCOGTimer(wxTimerEvent& event);
270
271 void HandleBasicNavMsg(std::shared_ptr<const BasicNavDataMsg> msg);
272 void HandleGPSWatchdogMsg(std::shared_ptr<const GPSWatchdogMsg> msg);
273
274 void ChartsRefresh();
275
276 bool CheckGroup(int igroup);
277 double GetMag(double a, double lat, double lon);
278 bool SendJSON_WMM_Var_Request(double lat, double lon, wxDateTime date);
279
280 void DestroyPersistentDialogs();
281 void TouchAISActive(void);
282 void UpdateAISTool(void);
283
284 void ActivateAISMOBRoute(const AisTargetData* ptarget);
285 void UpdateAISMOBRoute(const AisTargetData* ptarget);
286
287 wxStatusBar* m_pStatusBar;
288 wxMenuBar* m_pMenuBar;
289 int nBlinkerTick;
290 bool m_bTimeIsSet;
291
292 wxTimer InitTimer;
293 int m_iInitCount;
294 bool m_initializing;
295
296 wxTimer FrameTCTimer;
297 wxTimer FrameTimer1;
298 wxTimer FrameCOGTimer;
299 wxTimer MemFootTimer;
300 wxTimer m_resizeTimer;
301 wxTimer FrameTenHzTimer;
302
303 int m_BellsToPlay;
304 wxTimer BellsTimer;
305
306 // PlugIn support
307 int GetNextToolbarToolId() { return m_next_available_plugin_tool_id; }
308 void RequestNewToolbarArgEvent(wxCommandEvent& WXUNUSED(event)) {
309 return RequestNewMasterToolbar();
310 }
311 void RequestNewToolbars(bool bforcenew = false);
312
313 void ActivateMOB(void);
314 void UpdateGPSCompassStatusBoxes(bool b_force_new = false);
315 void UpdateRotationState(double rotation);
316
317 bool UpdateChartDatabaseInplace(ArrayOfCDI& DirArray, bool b_force,
318 bool b_prog,
319 const wxString& ChartListFileName);
320
321 bool m_bdefer_resize;
322 wxSize m_defer_size;
323 double COGTable[MAX_COG_AVERAGE_SECONDS];
324
325 void FastClose();
326 void SetChartUpdatePeriod();
327 void CreateCanvasLayout(bool b_useStoredSize = false);
328 void LoadHarmonics();
329 void ReloadAllVP();
330 void SetCanvasSizes(wxSize frameSize);
331
332 ocpnToolBarSimple* CreateMasterToolbar();
333 void RequestNewMasterToolbar(bool bforcenew = true);
334 bool CheckAndAddPlugInTool();
335 bool AddDefaultPositionPlugInTools();
336
337 void NotifyChildrenResize(void);
338 void UpdateCanvasConfigDescriptors();
339 void ScheduleSettingsDialog();
340 void ScheduleSettingsDialogNew();
341 void ScheduleDeleteSettingsDialog();
342 void ScheduleReconfigAndSettingsReload(bool reload, bool new_dialog);
343 static void RebuildChartDatabase();
344 void PositionIENCToolbar();
345
346 void InitAppMsgBusListener();
347 void InitApiListeners();
348 void ReleaseApiListeners();
349 void UpdateStatusBar(void);
350 void ConfigureStatusBar();
351
352private:
353 void ProcessUnitTest();
354 void ProcessQuitFlag();
355 void ProcessDeferredTrackOn();
356 void SendFixToPlugins();
357 void ProcessAnchorWatch();
358 void ProcessLogAndBells();
359 void CalculateCOGAverage();
360 void CheckToolbarPosition();
361
362 void ODoSetSize(void);
363 void DoCOGSet(void);
364
365 void UpdateAllToolbars(ColorScheme cs);
366
367 void FilterCogSog(void);
368
369 void ApplyGlobalColorSchemetoStatusBar(void);
370
371 bool ScrubGroupArray();
372
373 void OnToolbarAnimateTimer(wxTimerEvent& event);
374 bool CollapseGlobalToolbar();
375
376 int m_StatusBarFieldCount;
377
378 wxDateTime m_MMEAeventTime;
379 unsigned long m_ulLastNMEATicktime;
380 int m_tick_idx;
381 wxDateTime m_fix_start_time;
382
383 wxString m_last_reported_chart_name;
384 wxString m_last_reported_chart_pubdate;
385
386 wxString m_lastAISiconName;
387
388 // Plugin Support
389 int m_next_available_plugin_tool_id;
390
391 double COGFilterTable[MAX_COGSOG_FILTER_SECONDS];
392 double SOGFilterTable[MAX_COGSOG_FILTER_SECONDS];
393
394 int m_ChartUpdatePeriod;
395 bool m_last_bGPSValid;
396 bool m_last_bVelocityValid;
397 double m_last_hdt;
398
399 wxString prev_locale;
400
408 time_t m_fixtime;
409 bool b_autofind;
410
411 time_t m_last_track_rotation_ts;
412 wxTimer ToolbarAnimateTimer;
413 int m_nMasterToolCountShown;
414 wxTimer m_recaptureTimer;
415
416 std::unique_ptr<LoadErrorsDlgCtrl> m_load_errors_dlg_ctrl;
417
418 ObservableListener listener_basic_navdata;
419 ObservableListener listener_gps_watchdog;
420 ObsListener m_on_raise_listener;
421 ObsListener m_on_quit_listener;
422 ObsListener m_routes_update_listener;
423 ObsListener m_evt_drv_msg_listener;
424
425 CommOverflowDlg comm_overflow_dlg;
426 ConnectionsDlg* m_connections_dlg;
427 bool m_need_new_options;
428 wxArrayString pathArray;
429 double restoreScale[4];
430 unsigned int last_canvasConfig;
431 DataMonitor* m_data_monitor;
432
433 DECLARE_EVENT_TABLE()
434};
435
436#endif // _OFRAME_H
Base class for all chart types.
Definition chartbase.h:119
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:151
A dialog for handling communication overflow notifications.
Overall logging handler, outputs to screen and log file.
Main application frame.
Definition ocpn_frame.h:136
void InitApiListeners()
Setup handling of events from the local ipc/dbus API.
Define an action to be performed when a KeyProvider is notified.
Definition observable.h:228
Keeps listening over it's lifespan, removes itself on destruction.
Definition observable.h:131
Represents a track, which is a series of connected track points.
Definition track.h:111
Floating toolbar dialog for OpenCPN.
Definition toolbar.h:386
Generic toolbar implementation in pure wxWidgets adapted from wxToolBarSimple (deprecated).
Definition toolbar.h:103
Popup dialog on communication overflows.
New NMEA Debugger successor main window.
General purpose GUI support.