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