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 "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
126bool ShowNavWarning();
127
128bool isSingleChart(ChartBase* chart);
129
135class MyFrame : public wxFrame {
136public:
137 MyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos,
138 const wxSize& size, long style);
139
140 ~MyFrame();
141
142 int GetApplicationMemoryUse(void);
143
144 void OnEraseBackground(wxEraseEvent& event);
145 void OnMaximize(wxMaximizeEvent& event);
146 void OnCloseWindow(wxCloseEvent& event);
147 void OnExit(wxCommandEvent& event);
148 void OnSize(wxSizeEvent& event);
149 void OnMove(wxMoveEvent& event);
150 void OnInitTimer(wxTimerEvent& event);
151 void OnFrameTimer1(wxTimerEvent& event);
152 bool DoChartUpdate(void);
153 void OnEvtPlugInMessage(OCPN_MsgEvent& event);
154 void OnMemFootTimer(wxTimerEvent& event);
155 void OnRecaptureTimer(wxTimerEvent& event);
156 void OnSENCEvtThread(OCPN_BUILDSENC_ThreadEvent& event);
157 void OnIconize(wxIconizeEvent& event);
158 void OnBellsFinished(wxCommandEvent& event);
159 void OnFrameTenHzTimer(wxTimerEvent& event);
160
161#ifdef wxHAS_POWER_EVENTS
162 void OnSuspending(wxPowerEvent& event);
163 void OnSuspended(wxPowerEvent& event);
164 void OnSuspendCancel(wxPowerEvent& event);
165 void OnResume(wxPowerEvent& event);
166#endif // wxHAS_POWER_EVENTS
167
168 void RefreshCanvasOther(ChartCanvas* ccThis);
169 void UpdateAllFonts(void);
170 void PositionConsole(void);
171 void OnToolLeftClick(wxCommandEvent& event);
172 void DoStackUp(ChartCanvas* cc);
173 void DoStackDown(ChartCanvas* cc);
174 void selectChartDisplay(int type, int family);
175 void applySettingsString(wxString settings);
176 void setStringVP(wxString VPS);
177 void InvalidateAllGL();
178 void RefreshAllCanvas(bool bErase = true);
179 void CancelAllMouseRoute();
180 void InvalidateAllQuilts();
181
182 void SetUpMode(ChartCanvas* cc, int mode);
183
184 ChartCanvas* GetPrimaryCanvas();
185 ChartCanvas* GetFocusCanvas();
186
187 void DoStackDelta(ChartCanvas* cc, int direction);
188 void DoSettings(void);
189 void DoSettingsNew(void);
190 void SwitchKBFocus(ChartCanvas* pCanvas);
191 ChartCanvas* GetCanvasUnderMouse();
192 int GetCanvasIndexUnderMouse();
193
194 bool DropMarker(bool atOwnShip = true);
195
196 void TriggerRecaptureTimer();
197 bool SetGlobalToolbarViz(bool viz);
198
199 void MouseEvent(wxMouseEvent& event);
200 void CenterView(ChartCanvas* cc, const LLBBox& bbox);
201
202 void JumpToPosition(ChartCanvas* cc, double lat, double lon, double scale);
203
204 void ProcessCanvasResize(void);
205
206 void BuildMenuBar(void);
207 void ApplyGlobalSettings(bool bnewtoolbar);
208 void RegisterGlobalMenuItems();
209 void UpdateGlobalMenuItems();
210 void UpdateGlobalMenuItems(ChartCanvas* cc);
211 void DoOptionsDialog();
212 void ProcessOptionsDialog(int resultFlags, ArrayOfCDI* pNewDirArray);
213 void PrepareOptionsClose(options* settings, int settings_return_value);
214
215 void DoPrint(void);
216 void ToggleDataQuality(ChartCanvas* cc);
217 void TogglebFollow(ChartCanvas* cc);
218 void ToggleFullScreen();
219 void ToggleChartBar(ChartCanvas* cc);
220 void SetbFollow(ChartCanvas* cc);
221 void ClearbFollow(ChartCanvas* cc);
222 void ToggleChartOutlines(ChartCanvas* cc);
223 void ToggleENCText(ChartCanvas* cc);
224 void ToggleSoundings(ChartCanvas* cc);
225#if 0
226 void ToggleRocks(void);
227#endif
228 bool ToggleLights(ChartCanvas* cc);
229 void ToggleAnchor(ChartCanvas* cc);
230 void ToggleAISDisplay(ChartCanvas* cc);
231 void ToggleAISMinimizeTargets(ChartCanvas* cc);
232
233 void ToggleTestPause(void);
234 void TrackOn(void);
235 void SetENCDisplayCategory(ChartCanvas* cc, enum _DisCat nset);
236 void ToggleNavobjects(ChartCanvas* cc);
237
238 Track* TrackOff(bool do_add_point = false);
239 void TrackDailyRestart(void);
240 bool ShouldRestartTrack();
241 void ToggleColorScheme();
242 void SetMenubarItemState(int item_id, bool state);
243 void SetMasterToolbarItemState(int tool_id, bool state);
244
245 void SetToolbarItemBitmaps(int tool_id, wxBitmap* bitmap,
246 wxBitmap* bmpDisabled);
247 void SetToolbarItemSVG(int tool_id, wxString normalSVGfile,
248 wxString rolloverSVGfile, wxString toggledSVGfile);
249 void ToggleQuiltMode(ChartCanvas* cc);
250 void UpdateControlBar(ChartCanvas* cc);
251
252 void SubmergeAllCanvasToolbars(void);
253 void SurfaceAllCanvasToolbars(void);
254 void SetAllToolbarScale(void);
255 void SetGPSCompassScale(void);
256 void InvalidateAllCanvasUndo();
257
258 void RefreshGroupIndices(void);
259
260 double GetBestVPScale(ChartBase* pchart);
261
262 ColorScheme GetColorScheme();
263 void SetAndApplyColorScheme(ColorScheme cs);
264
265 void OnFrameTCTimer(wxTimerEvent& event);
266 void OnFrameCOGTimer(wxTimerEvent& event);
267
268 void HandleBasicNavMsg(std::shared_ptr<const BasicNavDataMsg> msg);
269 void HandleGPSWatchdogMsg(std::shared_ptr<const GPSWatchdogMsg> msg);
270
271 void ChartsRefresh();
272
273 bool CheckGroup(int igroup);
274 double GetMag(double a, double lat, double lon);
275 bool SendJSON_WMM_Var_Request(double lat, double lon, wxDateTime date);
276
277 void DestroyPersistentDialogs();
278 void TouchAISActive(void);
279 void UpdateAISTool(void);
280
281 void ActivateAISMOBRoute(const AisTargetData* ptarget);
282 void UpdateAISMOBRoute(const AisTargetData* ptarget);
283
284 wxStatusBar* m_pStatusBar;
285 wxMenuBar* m_pMenuBar;
286 int nBlinkerTick;
287 bool m_bTimeIsSet;
288
289 wxTimer InitTimer;
290 int m_iInitCount;
291 bool m_initializing;
292
293 wxTimer FrameTCTimer;
294 wxTimer FrameTimer1;
295 wxTimer FrameCOGTimer;
296 wxTimer MemFootTimer;
297 wxTimer m_resizeTimer;
298 wxTimer FrameTenHzTimer;
299
300 int m_BellsToPlay;
301 wxTimer BellsTimer;
302
303 // PlugIn support
304 int GetNextToolbarToolId() { return m_next_available_plugin_tool_id; }
305 void RequestNewToolbarArgEvent(wxCommandEvent& WXUNUSED(event)) {
306 return RequestNewMasterToolbar();
307 }
308 void RequestNewToolbars(bool bforcenew = false);
309
310 void ActivateMOB(void);
311 void UpdateGPSCompassStatusBoxes(bool b_force_new = false);
312 void UpdateRotationState(double rotation);
313
314 bool UpdateChartDatabaseInplace(ArrayOfCDI& DirArray, bool b_force,
315 bool b_prog,
316 const wxString& ChartListFileName);
317
318 bool m_bdefer_resize;
319 wxSize m_defer_size;
320 double COGTable[MAX_COG_AVERAGE_SECONDS];
321
322 void FastClose();
323 void SetChartUpdatePeriod();
324 void CreateCanvasLayout(bool b_useStoredSize = false);
325 void LoadHarmonics();
326 void ReloadAllVP();
327 void SetCanvasSizes(wxSize frameSize);
328
329 ocpnToolBarSimple* CreateMasterToolbar();
330 void RequestNewMasterToolbar(bool bforcenew = true);
331 bool CheckAndAddPlugInTool();
332 bool AddDefaultPositionPlugInTools();
333
334 void NotifyChildrenResize(void);
335 void UpdateCanvasConfigDescriptors();
336 void ScheduleSettingsDialog();
337 void ScheduleSettingsDialogNew();
338 void ScheduleDeleteSettingsDialog();
339 void ScheduleReconfigAndSettingsReload(bool reload, bool new_dialog);
340 static void RebuildChartDatabase();
341 void PositionIENCToolbar();
342
343 void InitAppMsgBusListener();
344 void InitApiListeners();
345 void ReleaseApiListeners();
346 void UpdateStatusBar(void);
347 void ConfigureStatusBar();
348
349private:
350 void ProcessUnitTest();
351 void ProcessQuitFlag();
352 void ProcessDeferredTrackOn();
353 void SendFixToPlugins();
354 void ProcessAnchorWatch();
355 void ProcessLogAndBells();
356 void CalculateCOGAverage();
357 void CheckToolbarPosition();
358
359 void ODoSetSize(void);
360 void DoCOGSet(void);
361
362 void UpdateAllToolbars(ColorScheme cs);
363
364 void FilterCogSog(void);
365
366 void ApplyGlobalColorSchemetoStatusBar(void);
367
368 bool ScrubGroupArray();
369
370 void OnToolbarAnimateTimer(wxTimerEvent& event);
371 bool CollapseGlobalToolbar();
372
373 int m_StatusBarFieldCount;
374
375 wxDateTime m_MMEAeventTime;
376 unsigned long m_ulLastNMEATicktime;
377 int m_tick_idx;
378
379 wxString m_last_reported_chart_name;
380 wxString m_last_reported_chart_pubdate;
381
382 wxString m_lastAISiconName;
383
384 // Plugin Support
385 int m_next_available_plugin_tool_id;
386
387 double COGFilterTable[MAX_COGSOG_FILTER_SECONDS];
388 double SOGFilterTable[MAX_COGSOG_FILTER_SECONDS];
389
390 int m_ChartUpdatePeriod;
391 bool m_last_bGPSValid;
392 bool m_last_bVelocityValid;
393 double m_last_hdt;
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
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:148
A dialog for handling communication overflow notifications.
Main application frame.
Definition ocpn_frame.h:135
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:79
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.