OpenCPN Partial API docs
Loading...
Searching...
No Matches
dashboard_pi.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2010 by Jean-Eudes Onfray *
3 * Copyright (C) 2010 by David S. Register *
4 * Copyright (C) 2023 by Bernd Cirotzki -- special color design *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
18 **************************************************************************/
19
26#ifndef DASHBOARDPI_H_
27#define DASHBOARDPI_H_
28
29#include <wx/wxprec.h>
30
31#ifndef WX_PRECOMP
32#include <wx/wx.h>
33#endif
34
35#include <wx/aui/aui.h>
36#include <wx/clrpicker.h>
37#include <wx/fileconf.h>
38#include <wx/fontpicker.h>
39#include <wx/jsonval.h>
40#include <wx/listctrl.h>
41#include <wx/notebook.h>
42#include <wx/spinctrl.h>
43#include <wx/statline.h>
44
45#ifdef __ANDROID__
46#include <wx/qt/private/wxQtGesture.h>
47#endif
48
49#include "iir_filter.h"
50#include "instrument.h"
51#include "nmea0183/nmea0183.h"
52#include "ocpn_plugin.h"
53#include "rudder_angle.h"
54#include "speedometer.h"
55#include "wind.h"
56#include "wind_history.h"
57
58#ifndef PI
59#define PI 3.1415926535897931160E0 /* pi */
60#endif
61
62#define PLUGIN_VERSION_MAJOR 1
63#define PLUGIN_VERSION_MINOR 2
64
65#define MY_API_VERSION_MAJOR 1
66#define MY_API_VERSION_MINOR 8
67
68// Request default positioning of toolbar tool
69#define DASHBOARD_TOOL_POSITION -1
70
71// Set watchdog to comply with OCPN WD.
72#define gps_watchdog_timeout_ticks GetGlobalWatchdogTimoutSeconds()
73
74// SignalK motor & environ instr defaults 30 sec update frequency
75#define no_nav_watchdog_timeout_ticks 40
76#define GEODESIC_RAD2DEG(r) ((r) * (180.0 / M_PI))
77#define MS2KNOTS(r) ((r) * (1.9438444924406))
78#define KELVIN2C(r) ((r) - (273.15))
79#define PA2HPA(r) ((r) / (100))
80#define METERS2NM(r) ((r) / (1852))
81
82#define wxFontPickerCtrl OCPNFontButton
83
84class DashboardWindow;
87class OCPNFontButton;
88
89WX_DEFINE_ARRAY(InstrumentProperties *, wxArrayOfInstrumentProperties);
90
91class EditDialog : public wxDialog {
92private:
93protected:
94 wxStaticText *m_staticText1;
95 wxStaticText *m_staticText5;
96 wxStaticText *m_staticText2;
97 wxStaticText *m_staticText6;
98 wxStaticText *m_staticText3;
99 wxStaticText *m_staticText4;
100 wxStaticLine *m_staticline1;
101 wxStaticLine *m_staticline2;
102 wxStaticText *m_staticText7;
103 wxStaticText *m_staticText9;
104 wxStaticText *m_staticText10;
105 wxStdDialogButtonSizer *m_sdbSizer3;
106 wxButton *m_sdbSizer3OK;
107 wxButton *m_sdbSizer3Cancel;
108
109 // Virtual event handlers, override them in your derived class
110 virtual void OnSetdefault(wxCommandEvent &event);
111
112public:
113 wxFontPickerCtrl *m_fontPicker2;
114 wxColourPickerCtrl *m_colourPicker1;
115 wxFontPickerCtrl *m_fontPicker4;
116 wxColourPickerCtrl *m_colourPicker2;
117 wxFontPickerCtrl *m_fontPicker5;
118 wxFontPickerCtrl *m_fontPicker6;
119 wxColourPickerCtrl *m_colourPicker3;
120 wxColourPickerCtrl *m_colourPicker4;
121 wxButton *m_button1;
122
123 EditDialog(wxWindow *parent, InstrumentProperties &Properties,
124 wxWindowID id = wxID_ANY,
125 const wxString &title = "Edit Instrument",
126 const wxPoint &pos = wxDefaultPosition,
127 const wxSize &size = wxSize(-1, -1),
128 long style = wxDEFAULT_DIALOG_STYLE);
129
130 ~EditDialog() override;
131};
132
134public:
135 DashboardWindowContainer(DashboardWindow *dashboard_window, wxString name,
136 wxString caption, wxString orientation,
137 wxArrayInt inst,
138 wxArrayOfInstrumentProperties inProberty) {
139 m_pDashboardWindow = dashboard_window;
140 m_sName = name;
141 m_sCaption = caption;
142 m_sOrientation = orientation;
143 m_aInstrumentList = inst;
144 m_aInstrumentPropertyList = inProberty;
145 m_bIsVisible = false;
146 m_bIsDeleted = false;
147 }
148
150 for (unsigned int i = 0; i < m_aInstrumentPropertyList.GetCount(); i++) {
151 InstrumentProperties *Inst = m_aInstrumentPropertyList.Item(i);
152 delete Inst;
153 }
154 }
155 DashboardWindow *m_pDashboardWindow;
156 bool m_bIsVisible;
157 bool m_bIsDeleted;
158 bool m_bPersVisible; // Persists visibility, even when Dashboard tool is
159 // toggled off.
160 wxString m_sName;
161 wxString m_sCaption;
162 wxString m_sOrientation;
163 wxArrayInt m_aInstrumentList;
164 wxArrayOfInstrumentProperties m_aInstrumentPropertyList;
165 wxSize m_best_size;
166 wxSize m_conf_best_size;
167 wxSize m_persist_size;
168};
169
171public:
173 CapType capa) {
174 m_ID = id;
175 m_pInstrument = instrument;
176 m_cap_flag = capa;
177 }
178 ~DashboardInstrumentContainer() { delete m_pInstrument; }
179
180 DashboardInstrument *m_pInstrument;
181 int m_ID;
182 CapType m_cap_flag;
183};
184
185// Dynamic arrays of pointers need explicit macros in wx261
186#ifdef __WX261
187WX_DEFINE_ARRAY_PTR(DashboardWindowContainer *, wxArrayOfDashboard);
188WX_DEFINE_ARRAY_PTR(DashboardInstrumentContainer *, wxArrayOfInstrument);
189#else
190WX_DEFINE_ARRAY(DashboardWindowContainer *, wxArrayOfDashboard);
191WX_DEFINE_ARRAY(DashboardInstrumentContainer *, wxArrayOfInstrument);
192#endif
193
194//----------------------------------------------------------------------------------------------------------
195// The PlugIn Class Definition
196//----------------------------------------------------------------------------------------------------------
197
198class dashboard_pi : public wxTimer, opencpn_plugin_18 {
199public:
200 dashboard_pi(void *ppimgr);
201 ~dashboard_pi() override;
202
203 // The required PlugIn Methods
204 int Init() override; // Hides wxTimer::Init()...
205 bool DeInit() override;
206
207 void Notify() override;
208
209 int GetAPIVersionMajor() override;
210 int GetAPIVersionMinor() override;
211 int GetPlugInVersionMajor() override;
212 int GetPlugInVersionMinor() override;
213 wxBitmap *GetPlugInBitmap() override;
214 wxString GetCommonName() override;
215 wxString GetShortDescription() override;
216 wxString GetLongDescription() override;
217
218 // The optional method overrides
219 void SetNMEASentence(wxString &sentence) override;
220 void SetPositionFixEx(PlugIn_Position_Fix_Ex &pfix) override;
221 void SetCursorLatLon(double lat, double lon) override;
222 int GetToolbarToolCount() override;
223 void OnToolbarToolCallback(int id) override;
224 void ShowPreferencesDialog(wxWindow *parent) override;
225 void SetColorScheme(PI_ColorScheme cs) override;
226 void OnPaneClose(wxAuiManagerEvent &event);
227 void UpdateAuiStatus() override;
228 bool SaveConfig();
229 void PopulateContextMenu(wxMenu *menu);
230 void ShowDashboard(size_t id, bool visible);
231 [[nodiscard]] int GetToolbarItemId() const { return m_toolbar_item_id; }
232 int GetDashboardWindowShownCount();
233 void SetPluginMessage(wxString &message_id, wxString &message_body) override;
234 void UpdateSumLog(bool);
235
236private:
237 bool LoadConfig();
238 void LoadFont(wxFont **target, const wxString &native_info);
239
240 void ApplyConfig();
241 void SendSentenceToAllInstruments(DASH_CAP st, double value,
242 const wxString &unit);
243 void SendSatInfoToAllInstruments(int cnt, int seq, const wxString &talk,
244 SAT_INFO sats[4]);
245 void SendUtcTimeToAllInstruments(wxDateTime value);
246
247 void CalculateAndUpdateTWDS(double awsKnots, double awaDegrees);
248
249 void ParseSignalK(wxString &msg);
250 void handleSKUpdate(wxJSONValue &update);
251 void updateSKItem(wxJSONValue &item, wxString &talker, wxString &sfixtime);
252
253 void HandleN2K_127245(ObservedEvt &ev);
254 void HandleN2K_127257(ObservedEvt &ev);
255 void HandleN2K_128259(ObservedEvt &ev);
256 void HandleN2K_128267(ObservedEvt &ev);
257 void HandleN2K_128275(ObservedEvt &ev);
258 void HandleN2K_128777(ObservedEvt &ev);
259 void HandleN2K_129029(ObservedEvt &ev);
260 void HandleN2K_129540(ObservedEvt &ev);
261 void HandleN2K_130306(ObservedEvt &ev);
262 void HandleN2K_130310(ObservedEvt &ev);
263 void HandleN2K_130313(ObservedEvt &ev);
264 std::shared_ptr<ObservableListener> listener_127245;
265 std::shared_ptr<ObservableListener> listener_127257;
266 std::shared_ptr<ObservableListener> listener_128259;
267 std::shared_ptr<ObservableListener> listener_128267;
268 std::shared_ptr<ObservableListener> listener_128275;
269 std::shared_ptr<ObservableListener> listener_128777;
270 std::shared_ptr<ObservableListener> listener_129029;
271 std::shared_ptr<ObservableListener> listener_129540;
272 std::shared_ptr<ObservableListener> listener_130306;
273 std::shared_ptr<ObservableListener> listener_130310;
274 std::shared_ptr<ObservableListener> listener_130313;
275
276 std::string prio127245;
277 std::string prio127257;
278 std::string prio128259;
279 std::string prio128267;
280 std::string prio129029;
281 std::string prioN2kPGNsat;
282 std::string prio130306;
283
284 wxString m_self;
285
286 wxFileConfig *m_pconfig;
287 wxAuiManager *m_pauimgr;
288 int m_toolbar_item_id;
289
290 wxArrayOfDashboard m_ArrayOfDashboardWindow;
291 int m_show_id;
292 int m_hide_id;
293
294 NMEA0183 m_nmea0183; // Used to parse NMEA Sentences
295 short m_pri_position, m_pri_cogsog, m_pri_heading_m, m_pri_heading_t;
296 short m_pri_var, m_pri_date_time, m_pri_awa, m_pri_twa, m_pri_depth;
297 short m_pri_stw, m_pri_wtp, m_pri_atmp, m_pri_wdn, m_pri_sat_status;
298 short m_pri_mda, m_pri_hum;
299 // Prio: Pos from O, SK gnss.satellites, GGA sats in use, SK gnss
300 // satellitesinView, GSV sats in view
301 short m_pri_sat_used, m_pri_alt, m_pri_rsa, m_pri_pitch_roll;
302 double m_var;
303 // FFU
304 int m_sats_in_use;
305 int m_sats_in_view;
306 double m_hdm;
307
322 wxDateTime m_utc_date_time;
323 int m_config_version;
324 wxString m_vdo_accumulator;
325 int m_h_dx_watchdog;
326 int m_hdt_watchdog;
327 int m_sats_used_wdog;
328 int m_sat_status_wdog;
329 int m_pri_n2_k_talker;
330 int m_var_watchdog;
331 int m_mwva_watchdog;
332 int m_mwvt_watchdog;
333 int m_dpt_dbt_watchdog;
334 int m_stw_watchdog;
335 int m_wtp_watchdog;
336 int m_rsa_watchdog;
337 int m_vmg_watchdog;
338 int m_vmgw_watchdog;
339 int m_utc_watchdog;
340 int m_atmp_watchdog;
341 int m_wdn_watchdog;
342 int m_mda_watchdog;
343 int m_pitch_watchdog;
344 int m_heel_watchdog;
345 int m_alt_watchdog;
346 int m_log_watchdog;
347 int m_tr_log_watchdog;
348 int m_hum_watchdog;
349 int m_wcc_watchdog;
350
351 IirFilter m_sog_filter;
352 IirFilter m_cog_filter;
353 IirFilter m_aws_filter;
354 IirFilter m_awa_filter;
355
356 // protected:
357 // DECLARE_EVENT_TABLE();
358};
359
360class DashboardPreferencesDialog : public wxDialog {
361public:
362 DashboardPreferencesDialog(wxWindow *pparent, wxWindowID id,
363 wxArrayOfDashboard config);
364 ~DashboardPreferencesDialog() override = default;
365
366 void OnCloseDialog(wxCloseEvent &event);
367 void OnDashboardSelected(wxListEvent &event);
368 void OnDashboardAdd(wxCommandEvent &event);
369 void OnDashboardDelete(wxCommandEvent &event);
370 void OnInstrumentSelected(wxListEvent &event);
371 void OnInstrumentAdd(wxCommandEvent &event);
372 void OnInstrumentEdit(wxCommandEvent &event);
373 void OnInstrumentDelete(wxCommandEvent &event);
374 void OnInstrumentUp(wxCommandEvent &event);
375 void OnInstrumentDown(wxCommandEvent &event);
376 void OnDashboarddefaultFont(wxCommandEvent &event);
377 void OnDistanceUnitSelect(wxCommandEvent &event);
378 void SaveDashboardConfig();
379 void RecalculateSize();
380
381 wxArrayOfDashboard m_config;
382 wxFontPickerCtrl *m_font_picker_title;
383 wxFontPickerCtrl *m_font_picker_data;
384 wxFontPickerCtrl *m_font_picker_label;
385 wxFontPickerCtrl *m_font_picker_small;
386 wxSpinCtrl *m_spin_speed_max;
387 wxSpinCtrl *m_spin_cog_damp;
388 wxSpinCtrl *m_spin_sog_damp;
389 wxSpinCtrl *m_spin_aws_damp;
390 wxSpinCtrl *m_spin_awa_damp;
391 wxChoice *m_choice_utc_offset;
392 wxChoice *m_choice_speed_unit;
393 wxChoice *m_choice_depth_unit;
394 wxSpinCtrlDouble *m_spin_dbt_offset;
395 wxChoice *m_choice_distance_unit;
396 wxChoice *m_choice_wind_speed_unit;
397 wxCheckBox *m_use_intern_sum_log;
398 wxStaticText *m_sum_log_unit;
399 wxTextCtrl *m_sum_log_value;
400 wxCheckBox *m_use_true_winddata;
401 wxChoice *m_choice_temp_unit;
402
403private:
404 void UpdateDashboardButtonsState();
405 void UpdateButtonsState();
406 int curSel;
407 wxListCtrl *m_pListCtrlDashboards;
408 wxBitmapButton *m_pButtonAddDashboard;
409 wxBitmapButton *m_pButtonDeleteDashboard;
410 wxPanel *m_pPanelDashboard;
411 wxTextCtrl *m_pTextCtrlCaption;
412 wxCheckBox *m_pCheckBoxIsVisible;
413 wxChoice *m_pChoiceOrientation;
414 wxListCtrl *m_pListCtrlInstruments;
415 wxButton *m_pButtonAdd;
416 wxButton *m_pButtonEdit;
417 wxButton *m_pButtonDelete;
418 wxButton *m_pButtonUp;
419 wxButton *m_pButtonDown;
420 wxButton *m_pButtondefaultFont;
421};
422
423class AddInstrumentDlg : public wxDialog {
424public:
425 AddInstrumentDlg(wxWindow *pparent, wxWindowID id);
426 ~AddInstrumentDlg() override = default;
427
428 unsigned int GetInstrumentAdded();
429
430private:
431 wxListCtrl *m_pListCtrlInstruments;
432};
433
434enum { ID_DASHBOARD_WINDOW };
435
436enum {
437 ID_DASH_PREFS = 999,
438 ID_DASH_VERTICAL,
439 ID_DASH_HORIZONTAL,
440 ID_DASH_RESIZE,
441 ID_DASH_UNDOCK
442};
443
444class DashboardWindow : public wxWindow {
445public:
446 DashboardWindow(wxWindow *pparent, wxWindowID id, wxAuiManager *auimgr,
447 dashboard_pi *plugin, int orient,
449 ~DashboardWindow() override;
450
451 void SetColorScheme(PI_ColorScheme cs);
452 void SetSizerOrientation(int orient);
453 int GetSizerOrientation();
454 void OnSize(wxSizeEvent &evt);
455 void OnContextMenu(wxContextMenuEvent &evt);
456 void OnContextMenuSelect(wxCommandEvent &evt);
457
458 void OnMouseEvent(wxMouseEvent &event);
459
460#ifdef __ANDROID__
461 void OnEvtPinchGesture(wxQT_PinchGestureEvent &event);
462 void OnEvtPanGesture(wxQT_PanGestureEvent &event);
463#endif
464
465 bool isInstrumentListEqual(const wxArrayInt &list);
466 void SetInstrumentList(wxArrayInt list,
467 wxArrayOfInstrumentProperties *InstrumentPropertyList);
468 void SendSentenceToAllInstruments(DASH_CAP st, double value, wxString unit);
469 void SendSatInfoToAllInstruments(int cnt, int seq, wxString talk,
470 SAT_INFO sats[4]);
471 void SendUtcTimeToAllInstruments(wxDateTime value);
472
473 // Default FloatingPosition (100.100) included.
474 void ChangePaneOrientation(int orient, bool updateAUImgr, int fpx = 100,
475 int fpy = 100);
476 /*TODO: OnKeyPress pass event to main window or disable focus*/
477
478 DashboardWindowContainer *m_Container;
479
480 bool m_binPinch;
481 bool m_binPan;
482
483 wxPoint m_resizeStartPoint;
484 wxSize m_resizeStartSize;
485 bool m_binResize;
486 bool m_binResize2;
487
488private:
489 wxAuiManager *m_pauimgr;
490 dashboard_pi *m_plugin;
491
492 // wx2.9 wxWrapSizer* itemBoxSizer;
493 wxBoxSizer *itemBoxSizer;
494 wxArrayOfInstrument m_ArrayOfInstrument;
495
496 wxButton *m_tButton;
497};
498
499#include "wx/button.h"
500#include "wx/fontdata.h"
501
502//-----------------------------------------------------------------------------
503// OCPNFontButton: a button which brings up a wxFontDialog
504//-----------------------------------------------------------------------------
505
506class OCPNFontButton : public wxButton {
507public:
508 OCPNFontButton() = default;
509 OCPNFontButton(wxWindow *parent, wxWindowID id, const wxFontData &initial,
510 const wxPoint &pos = wxDefaultPosition,
511 const wxSize &size = wxDefaultSize,
512 long style = wxFONTBTN_DEFAULT_STYLE,
513 const wxValidator &validator = wxDefaultValidator,
514 const wxString &name = wxFontPickerWidgetNameStr) {
515 Create(parent, id, initial, pos, size, style, validator, name);
516 }
517
518 [[nodiscard]] virtual wxColour GetSelectedColour() const {
519 return m_data.GetColour();
520 }
521 virtual void SetSelectedFont(const wxFont &font) {
522 m_data.SetChosenFont(font);
523 m_selectedFont = m_data.GetChosenFont();
524 UpdateFont();
525 }
526 virtual void SetSelectedColour(const wxColour &colour) {
527 m_data.SetColour(colour);
528 UpdateFont();
529 }
530
531 ~OCPNFontButton() override = default;
532
533public: // API extensions specific for OCPNFontButton
534 // user can override this to init font data in a different way
535 // virtual void InitFontData();
536
537 // returns the font data shown in wxFontDialog
538 wxFontData *GetFontData() { return &m_data; }
539
540 // get the font chosen
541 [[nodiscard]] wxFont GetSelectedFont() const { return m_selectedFont; }
542
543public:
544 bool Create(wxWindow *parent, wxWindowID id, const wxFontData &initial,
545 const wxPoint &pos = wxDefaultPosition,
546 const wxSize &size = wxDefaultSize,
547 long style = wxFONTBTN_DEFAULT_STYLE,
548 const wxValidator &validator = wxDefaultValidator,
549 const wxString &name = wxFontPickerWidgetNameStr);
550
551 void OnButtonClick(wxCommandEvent &);
552
553protected:
554 void UpdateFont();
555
556 wxFontData m_data;
557
558 wxFont m_selectedFont;
559};
560
561#endif // DASHBOARDPI_H_
Custom event class for OpenCPN's notification system.
Extended position fix information.
int GetAPIVersionMajor() override
Returns the major version number of the plugin API that this plugin supports.
void SetNMEASentence(wxString &sentence) override
Receive all NMEA 0183 sentences from OpenCPN.
void SetPositionFixEx(PlugIn_Position_Fix_Ex &pfix) override
Updates plugin with extended position fix data at regular intervals.
void UpdateAuiStatus() override
Updates AUI manager status.
int GetPlugInVersionMajor() override
Returns the major version number of the plugin itself.
bool DeInit() override
Clean up plugin resources.
void OnToolbarToolCallback(int id) override
Handles toolbar tool clicks.
wxString GetLongDescription() override
Get detailed plugin information.
void ShowPreferencesDialog(wxWindow *parent) override
Shows the plugin preferences dialog.
wxString GetCommonName() override
Get the plugin's common (short) name.
wxString GetShortDescription() override
Get a brief description of the plugin.
int Init() override
Initialize the plugin and declare its capabilities.
int GetPlugInVersionMinor() override
Returns the minor version number of the plugin itself.
int GetToolbarToolCount() override
Returns the number of toolbar tools this plugin provides.
int GetAPIVersionMinor() override
Returns the minor version number of the plugin API that this plugin supports.
void SetCursorLatLon(double lat, double lon) override
Receives cursor lat/lon position updates.
void SetColorScheme(PI_ColorScheme cs) override
Updates plugin color scheme.
wxBitmap * GetPlugInBitmap() override
Get the plugin's icon bitmap.
The JSON value class implementation.
Definition jsonval.h:79
Single order inifinite-impulse-response filter.
Dashboard instrument base class.
DASH_CAP
Definition instrument.h:77
PlugIn Object Definition/API.
PI_ColorScheme
Color schemes for different lighting conditions.
Dashboard rudder angle instrument.
Dashboard speed instrument.
Dashboard wind instrument implementation.
Dashboard wind history instrument.