30#include <wx/toolbar.h>
33#include "ocpn_print.h"
35#define TIMER_GFRAME_1 999
38#define ID_CM93ZOOMG 102
41const int ID_TOOLBAR = 500;
73static const long TOOLBAR_STYLE = wxTB_FLAT | wxTB_DOCKABLE | wxTB_TEXT;
76 IDM_TOOLBAR_TOGGLETOOLBARSIZE = 200,
77 IDM_TOOLBAR_TOGGLETOOLBARORIENT,
78 IDM_TOOLBAR_TOGGLETOOLBARROWS,
79 IDM_TOOLBAR_ENABLEPRINT,
80 IDM_TOOLBAR_DELETEPRINT,
81 IDM_TOOLBAR_INSERTPRINT,
82 IDM_TOOLBAR_TOGGLEHELP,
83 IDM_TOOLBAR_TOGGLE_TOOLBAR,
84 IDM_TOOLBAR_TOGGLE_ANOTHER_TOOLBAR,
85 IDM_TOOLBAR_CHANGE_TOOLTIP,
86 IDM_TOOLBAR_SHOW_TEXT,
87 IDM_TOOLBAR_SHOW_ICONS,
88 IDM_TOOLBAR_SHOW_BOTH,
95 ID_MENU_ZOOM_IN = 2000,
103 ID_MENU_CHART_NORTHUP,
105 ID_MENU_CHART_HEADUP,
106 ID_MENU_CHART_QUILTING,
107 ID_MENU_CHART_OUTLINES,
110 ID_MENU_UI_COLSCHEME,
111 ID_MENU_UI_FULLSCREEN,
115 ID_MENU_ENC_SOUNDINGS,
117 ID_MENU_ENC_DATA_QUALITY,
120 ID_MENU_SHOW_CURRENTS,
122 ID_MENU_TOOL_MEASURE,
123 ID_MENU_ROUTE_MANAGER,
130 ID_MENU_AIS_MOORED_TARGETS,
131 ID_MENU_AIS_SCALED_TARGETS,
133 ID_MENU_AIS_CPADIALOG,
134 ID_MENU_AIS_CPASOUND,
135 ID_MENU_AIS_TARGETLIST,
136 ID_MENU_AIS_CPAWARNING,
138 ID_MENU_SETTINGS_BASIC,
142 ID_CMD_SELECT_CHART_TYPE,
143 ID_CMD_SELECT_CHART_FAMILY,
145 ID_CMD_CLOSE_ALL_DIALOGS,
147 ID_MENU_SHOW_NAVOBJECTS,
152 ID_NMEA_WINDOW = wxID_HIGHEST,
164 MEMORY_FOOTPRINT_TIMER,
168 TOOLBAR_ANIMATE_TIMER,
175enum { TIME_TYPE_UTC = 1, TIME_TYPE_LMT, TIME_TYPE_COMPUTER };
177#define DS_SOCKET_ID 5001
178#define DS_SERVERSOCKET_ID 5002
179#define DS_ACTIVESERVERSOCKET_ID 5003
185#define ID_CMD_APPLY_SETTINGS 300
186#define ID_CMD_NULL_REFRESH 301
187#define ID_CMD_TRIGGER_RESIZE 302
188#define ID_CMD_SETVP 303
189#define ID_CMD_POST_JSON_TO_PLUGINS 304
190#define ID_CMD_SET_LOCALE 305
191#define ID_CMD_SOUND_FINISHED 306
193#define N_STATUS_BAR_FIELDS_MAX 20
195#ifdef __OCPN__ANDROID__
196#define STAT_FIELD_COUNT 2
197#define STAT_FIELD_TICK -1
198#define STAT_FIELD_SOGCOG 0
199#define STAT_FIELD_CURSOR_LL -1
200#define STAT_FIELD_CURSOR_BRGRNG -1
201#define STAT_FIELD_SCALE 1
203#define STAT_FIELD_COUNT 5
204#define STAT_FIELD_TICK 0
205#define STAT_FIELD_SOGCOG 1
206#define STAT_FIELD_CURSOR_LL 2
207#define STAT_FIELD_CURSOR_BRGRNG 3
208#define STAT_FIELD_SCALE 4
212#define GPS_TIMEOUT_SECONDS 6
217#define TIMER_TC_VALUE_SECONDS 300
219#define MAX_COG_AVERAGE_SECONDS 60
220#define MAX_COGSOG_FILTER_SECONDS 60
227class OCPN_DataStreamEvent;
228class OCPN_SignalKEvent;
237class NMEA_Msg_Container {
239 wxDateTime receipt_time;
240 int current_priority;
241 wxString stream_name;
251 void SetSString(std::string
string) { m_string = string; }
252 std::string GetSString() {
return m_string; }
255 wxEvent *Clone()
const;
258 std::string m_string;
261class MyApp :
public wxApp {
265 void OnInitCmdLine(wxCmdLineParser &parser);
266 bool OnCmdLineParsed(wxCmdLineParser &parser);
267 void OnActivateApp(wxActivateEvent &event);
271 void OnFatalException();
277 bool OnExceptionInMainLoop();
280 Track* TrackOff(
void);
282 wxSingleInstanceChecker *m_checker;
284 DECLARE_EVENT_TABLE()
288class MyFrame :
public wxFrame {
289 friend class SignalKEventHandler;
292 MyFrame(wxFrame *frame,
const wxString &title,
const wxPoint &pos,
293 const wxSize &size,
long style);
297 int GetApplicationMemoryUse(
void);
299 void OnEraseBackground(wxEraseEvent &event);
300 void OnMaximize(wxMaximizeEvent &event);
301 void OnCloseWindow(wxCloseEvent &event);
302 void OnExit(wxCommandEvent &event);
303 void OnSize(wxSizeEvent &event);
304 void OnMove(wxMoveEvent &event);
305 void OnInitTimer(wxTimerEvent &event);
307 bool DoChartUpdate(
void);
309 void OnEvtOCPN_NMEA(OCPN_DataStreamEvent &event);
310 void OnEvtOCPN_SignalK(OCPN_SignalKEvent &event);
311 void OnEvtOCPN_SIGNALK_Test(OCPN_SignalKEvent &event);
313 void OnMemFootTimer(wxTimerEvent &event);
314 void OnRecaptureTimer(wxTimerEvent &event);
316 void OnIconize(wxIconizeEvent &event);
317 void OnBellsFinished(wxCommandEvent &event);
319#ifdef wxHAS_POWER_EVENTS
320 void OnSuspending(wxPowerEvent &event);
321 void OnSuspended(wxPowerEvent &event);
322 void OnSuspendCancel(wxPowerEvent &event);
323 void OnResume(wxPowerEvent &event);
327 void UpdateAllFonts(
void);
328 void PositionConsole(
void);
329 void OnToolLeftClick(wxCommandEvent &event);
330 void ClearRouteTool();
333 void selectChartDisplay(
int type,
int family);
334 void applySettingsString(wxString settings);
335 void setStringVP(wxString VPS);
336 void InvalidateAllGL();
337 void RefreshAllCanvas(
bool bErase =
true);
338 void CancelAllMouseRoute();
339 void InvalidateAllQuilts();
343 wxMenuBar *GetMainMenuBar() {
return m_pMenuBar; }
349 void DoSettings(
void);
352 int GetCanvasIndexUnderMouse();
354 bool DropMarker(
bool atOwnShip =
true);
356 void TriggerResize(wxSize sz);
357 void OnResizeTimer(wxTimerEvent &event);
359 void TriggerRecaptureTimer();
360 bool SetGlobalToolbarViz(
bool viz);
362 void MouseEvent(wxMouseEvent &event);
368 void CenterView(
ChartCanvas *cc,
const LLBBox &bbox);
372 void ProcessCanvasResize(
void);
374 void BuildMenuBar(
void);
375 void ApplyGlobalSettings(
bool bnewtoolbar);
376 void RegisterGlobalMenuItems();
377 void UpdateGlobalMenuItems();
379 int DoOptionsDialog();
380 bool ProcessOptionsDialog(
int resultFlags, ArrayOfCDI *pNewDirArray);
382 void StopSockets(
void);
383 void ResumeSockets(
void);
386 void ToggleFullScreen();
393 void ToggleRocks(
void);
399 void ToggleTestPause(
void);
401 void SetENCDisplayCategory(
ChartCanvas *cc,
enum _DisCat nset);
404 Track *TrackOff(
bool do_add_point =
false);
405 void TrackDailyRestart(
void);
406 bool ShouldRestartTrack();
407 void ToggleColorScheme();
408 void SetMenubarItemState(
int item_id,
bool state);
409 void SetMasterToolbarItemState(
int tool_id,
bool state);
411 void SetToolbarItemBitmaps(
int tool_id, wxBitmap *bitmap,
412 wxBitmap *bmpDisabled);
413 void SetToolbarItemSVG(
int tool_id, wxString normalSVGfile,
414 wxString rolloverSVGfile, wxString toggledSVGfile);
418 void ShowTides(
bool bShow);
419 void ShowCurrents(
bool bShow);
421 void SubmergeAllCanvasToolbars(
void);
423 void ToggleAllToolbars(
bool b_smooth =
false);
424 void SetAllToolbarScale(
void);
425 void SetGPSCompassScale(
void);
426 void InvalidateAllCanvasUndo();
428 void RefreshGroupIndices(
void);
430 double GetBestVPScale(
ChartBase *pchart);
432 ColorScheme GetColorScheme();
433 void SetAndApplyColorScheme(ColorScheme cs);
435 void OnFrameTCTimer(wxTimerEvent &event);
436 void OnFrameCOGTimer(wxTimerEvent &event);
438 void ChartsRefresh();
440 bool CheckGroup(
int igroup);
441 double GetMag(
double a);
442 double GetMag(
double a,
double lat,
double lon);
443 bool SendJSON_WMM_Var_Request(
double lat,
double lon, wxDateTime date);
445 void DestroyPersistentDialogs();
446 void TouchAISActive(
void);
447 void UpdateAISTool(
void);
452 wxStatusBar *m_pStatusBar;
453 wxMenuBar *m_pMenuBar;
462 wxTimer FrameTCTimer;
464 wxTimer FrameCOGTimer;
465 wxTimer MemFootTimer;
466 wxTimer m_resizeTimer;
472 int GetNextToolbarToolId() {
return m_next_available_plugin_tool_id; }
473 void RequestNewToolbarArgEvent(wxCommandEvent &WXUNUSED(event)) {
474 return RequestNewMasterToolbar();
476 void RequestNewToolbars(
bool bforcenew =
false);
478 void ActivateMOB(
void);
479 void UpdateGPSCompassStatusBoxes(
bool b_force_new =
false);
480 void UpdateRotationState(
double rotation);
482 bool UpdateChartDatabaseInplace(ArrayOfCDI &DirArray,
bool b_force,
484 const wxString &ChartListFileName);
486 bool m_bdefer_resize;
489 double COGTable[MAX_COG_AVERAGE_SECONDS];
492 void SetChartUpdatePeriod();
493 void CreateCanvasLayout(
bool b_useStoredSize =
false);
494 void LoadHarmonics();
496 void SetCanvasSizes(wxSize frameSize);
499 void RequestNewMasterToolbar(
bool bforcenew =
true);
500 bool CheckAndAddPlugInTool();
501 bool AddDefaultPositionPlugInTools();
503 void NotifyChildrenResize(
void);
504 void UpdateCanvasConfigDescriptors();
505 void ScheduleSettingsDialog();
506 static void RebuildChartDatabase();
507 void PositionIENCToolbar();
509 bool ParsePosition(
const LATLONG &
Position);
510 void setSatelitesInView(
int no);
511 void setPosition(
double lat,
double lon);
512 void setSpeedOverGround(
double sog);
513 void setCourseOverGround(
double cog);
514 void setHeadingTrue(
double heading);
515 void setHeadingMagnetic(
double heading);
516 void setMagneticVariation(
double var);
518 void InitCommListeners();
520 bool HandleN2K_129029( std::shared_ptr <const Nmea2000Msg> n2k_msg );
521 bool HandleN2K_129026( std::shared_ptr <const Nmea2000Msg> n2k_msg );
523 bool HandleN0183_RMC( std::shared_ptr <const Nmea0183Msg> n0183_msg );
524 bool HandleN0183_HDT( std::shared_ptr <const Nmea0183Msg> n0183_msg );
525 bool HandleN0183_HDG( std::shared_ptr <const Nmea0183Msg> n0183_msg );
526 bool HandleN0183_HDM( std::shared_ptr <const Nmea0183Msg> n0183_msg );
527 bool HandleN0183_VTG( std::shared_ptr <const Nmea0183Msg> n0183_msg );
528 bool HandleN0183_GSV( std::shared_ptr <const Nmea0183Msg> n0183_msg );
529 bool HandleN0183_GGA( std::shared_ptr <const Nmea0183Msg> n0183_msg );
530 bool HandleN0183_GLL( std::shared_ptr <const Nmea0183Msg> n0183_msg );
531 bool HandleN0183_AIVDO( std::shared_ptr <const Nmea0183Msg> n0183_msg );
534 void CheckToolbarPosition();
535 void ODoSetSize(
void);
538 void UpdateAllToolbars(ColorScheme cs);
540 void FilterCogSog(
void);
542 void ApplyGlobalColorSchemetoStatusBar(
void);
543 void PostProcessNMEA(
bool pos_valid,
bool sog_valid,
544 bool cog_valid,
const wxString &sfixtime);
546 bool ScrubGroupArray();
547 wxString GetGroupName(
int igroup);
549 bool EvalPriority(
const wxString &message, DataStream *pDS);
550 void SetAISDisplayStyle(
ChartCanvas *cc,
int StyleIndx);
552 bool GetMasterToolItemShow(
int toolid);
553 void OnToolbarAnimateTimer(wxTimerEvent &event);
554 bool CollapseGlobalToolbar();
556 int m_StatusBarFieldCount;
560 wxDateTime m_MMEAeventTime;
561 unsigned long m_ulLastNMEATicktime;
563 wxMutex m_mutexNMEAEvent;
565 wxString m_last_reported_chart_name;
566 wxString m_last_reported_chart_pubdate;
568 wxString m_lastAISiconName;
571 int m_next_available_plugin_tool_id;
573 double COGFilterTable[MAX_COGSOG_FILTER_SECONDS];
574 double SOGFilterTable[MAX_COGSOG_FILTER_SECONDS];
576 bool m_bpersistent_quilt;
577 int m_ChartUpdatePeriod;
578 bool m_last_bGPSValid;
580 wxString prev_locale;
582 bool bPrevFullScreenQuilt;
585 MsgPriorityHash NMEA_Msg_Hash;
586 wxString m_VDO_accumulator;
589 wxMenu *piano_ctx_menu;
592 time_t m_last_track_rotation_ts;
593 wxRect m_mainlast_tb_rect;
594 wxTimer ToolbarAnimateTimer;
595 int m_nMasterToolCountShown;
596 wxTimer m_recaptureTimer;
598 SignalKEventHandler m_signalKHandler;
614 DECLARE_EVENT_TABLE()
void OnFrameTimer1(wxTimerEvent &event)
void SurfaceAllCanvasToolbars(void)
Keeps listening over it's lifespan, removes itself on destruction.