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