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 "gui_lib.h"
44#include "load_errors_dlg.h"
45#include "observable_evtvar.h"
46#include "ocpn_print.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 ColorScheme GetColorScheme();
264 void SetAndApplyColorScheme(ColorScheme cs);
265
266 void OnFrameTCTimer(wxTimerEvent& event);
267 void OnFrameCOGTimer(wxTimerEvent& event);
268
269 void HandleBasicNavMsg(std::shared_ptr<const BasicNavDataMsg> msg);
270 void HandleGPSWatchdogMsg(std::shared_ptr<const GPSWatchdogMsg> msg);
271
272 void ChartsRefresh();
273
274 bool CheckGroup(int igroup);
275 double GetMag(double a, double lat, double lon);
276 bool SendJSON_WMM_Var_Request(double lat, double lon, wxDateTime date);
277
278 void DestroyPersistentDialogs();
279 void TouchAISActive(void);
280 void UpdateAISTool(void);
281
282 void ActivateAISMOBRoute(const AisTargetData* ptarget);
283 void UpdateAISMOBRoute(const AisTargetData* ptarget);
284
285 wxStatusBar* m_pStatusBar;
286 wxMenuBar* m_pMenuBar;
287 int nBlinkerTick;
288 bool m_bTimeIsSet;
289
290 wxTimer InitTimer;
291 int m_iInitCount;
292 bool m_initializing;
293
294 wxTimer FrameTCTimer;
295 wxTimer FrameTimer1;
296 wxTimer FrameCOGTimer;
297 wxTimer MemFootTimer;
298 wxTimer m_resizeTimer;
299 wxTimer FrameTenHzTimer;
300
301 int m_BellsToPlay;
302 wxTimer BellsTimer;
303
304 // PlugIn support
305 int GetNextToolbarToolId() { return m_next_available_plugin_tool_id; }
306 void RequestNewToolbarArgEvent(wxCommandEvent& WXUNUSED(event)) {
307 return RequestNewMasterToolbar();
308 }
309 void RequestNewToolbars(bool bforcenew = false);
310
311 void ActivateMOB(void);
312 void UpdateGPSCompassStatusBoxes(bool b_force_new = false);
313 void UpdateRotationState(double rotation);
314
315 bool UpdateChartDatabaseInplace(ArrayOfCDI& DirArray, bool b_force,
316 bool b_prog,
317 const wxString& ChartListFileName);
318
319 bool m_bdefer_resize;
320 wxSize m_defer_size;
321 double COGTable[MAX_COG_AVERAGE_SECONDS];
322
323 void FastClose();
324 void SetChartUpdatePeriod();
325 void CreateCanvasLayout(bool b_useStoredSize = false);
326 void LoadHarmonics();
327 void ReloadAllVP();
328 void SetCanvasSizes(wxSize frameSize);
329
330 ocpnToolBarSimple* CreateMasterToolbar();
331 void RequestNewMasterToolbar(bool bforcenew = true);
332 bool CheckAndAddPlugInTool();
333 bool AddDefaultPositionPlugInTools();
334
335 void NotifyChildrenResize(void);
336 void UpdateCanvasConfigDescriptors();
337 void ScheduleSettingsDialog();
338 void ScheduleSettingsDialogNew();
339 void ScheduleDeleteSettingsDialog();
340 void ScheduleReconfigAndSettingsReload(bool reload, bool new_dialog);
341 static void RebuildChartDatabase();
342 void PositionIENCToolbar();
343
344 void InitAppMsgBusListener();
345 void InitApiListeners();
346 void ReleaseApiListeners();
347 void UpdateStatusBar(void);
348 void ConfigureStatusBar();
349
350private:
351 void ProcessUnitTest();
352 void ProcessQuitFlag();
353 void ProcessDeferredTrackOn();
354 void SendFixToPlugins();
355 void ProcessAnchorWatch();
356 void ProcessLogAndBells();
357 void CalculateCOGAverage();
358 void CheckToolbarPosition();
359
360 void ODoSetSize(void);
361 void DoCOGSet(void);
362
363 void UpdateAllToolbars(ColorScheme cs);
364
365 void FilterCogSog(void);
366
367 void ApplyGlobalColorSchemetoStatusBar(void);
368
369 bool ScrubGroupArray();
370
371 void OnToolbarAnimateTimer(wxTimerEvent& event);
372 bool CollapseGlobalToolbar();
373
374 int m_StatusBarFieldCount;
375
376 wxDateTime m_MMEAeventTime;
377 unsigned long m_ulLastNMEATicktime;
378 int m_tick_idx;
379
380 wxString m_last_reported_chart_name;
381 wxString m_last_reported_chart_pubdate;
382
383 wxString m_lastAISiconName;
384
385 // Plugin Support
386 int m_next_available_plugin_tool_id;
387
388 double COGFilterTable[MAX_COGSOG_FILTER_SECONDS];
389 double SOGFilterTable[MAX_COGSOG_FILTER_SECONDS];
390
391 int m_ChartUpdatePeriod;
392 bool m_last_bGPSValid;
393 bool m_last_bVelocityValid;
394
395 wxString prev_locale;
396
404 time_t m_fixtime;
405 bool b_autofind;
406
407 time_t m_last_track_rotation_ts;
408 wxTimer ToolbarAnimateTimer;
409 int m_nMasterToolCountShown;
410 wxTimer m_recaptureTimer;
411
412 std::unique_ptr<LoadErrorsDlgCtrl> m_load_errors_dlg_ctrl;
413
414 ObservableListener listener_basic_navdata;
415 ObservableListener listener_gps_watchdog;
416 ObsListener m_on_raise_listener;
417 ObsListener m_on_quit_listener;
418 ObsListener m_routes_update_listener;
419 ObsListener m_evt_drv_msg_listener;
420
421 CommOverflowDlg comm_overflow_dlg;
422 ConnectionsDlg* m_connections_dlg;
423 bool m_need_new_options;
424 wxArrayString pathArray;
425 double restoreScale[4];
426 unsigned int last_canvasConfig;
427
428 DECLARE_EVENT_TABLE()
429};
430
431#endif // _OFRAME_H
Base class for all chart types.
Definition chartbase.h:119
Chart display canvas.
Definition chcanv.h:135
A dialog for handling communication overflow notifications.
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:78
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.
General purpose GUI support.