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 void UpdateSumLog(bool);
246
247private:
248 bool LoadConfig(void);
249 void LoadFont(wxFont **target, wxString native_info);
250
251 void ApplyConfig(void);
252 void SendSentenceToAllInstruments(DASH_CAP st, double value, wxString unit);
253 void SendSatInfoToAllInstruments(int cnt, int seq, wxString talk,
254 SAT_INFO sats[4]);
255 void SendUtcTimeToAllInstruments(wxDateTime value);
256
257 void CalculateAndUpdateTWDS(double awsKnots, double awaDegrees);
258
259 void ParseSignalK(wxString &msg);
260 void handleSKUpdate(wxJSONValue &update);
261 void updateSKItem(wxJSONValue &item, wxString &talker, wxString &sfixtime);
262
263 void HandleN2K_127245(ObservedEvt ev);
264 void HandleN2K_127257(ObservedEvt ev);
265 void HandleN2K_128259(ObservedEvt ev);
266 void HandleN2K_128267(ObservedEvt ev);
267 void HandleN2K_128275(ObservedEvt ev);
268 void HandleN2K_128777(ObservedEvt ev);
269 void HandleN2K_129029(ObservedEvt ev);
270 void HandleN2K_129540(ObservedEvt ev);
271 void HandleN2K_130306(ObservedEvt ev);
272 void HandleN2K_130310(ObservedEvt ev);
273 void HandleN2K_130313(ObservedEvt ev);
274 std::shared_ptr<ObservableListener> listener_127245;
275 std::shared_ptr<ObservableListener> listener_127257;
276 std::shared_ptr<ObservableListener> listener_128259;
277 std::shared_ptr<ObservableListener> listener_128267;
278 std::shared_ptr<ObservableListener> listener_128275;
279 std::shared_ptr<ObservableListener> listener_128777;
280 std::shared_ptr<ObservableListener> listener_129029;
281 std::shared_ptr<ObservableListener> listener_129540;
282 std::shared_ptr<ObservableListener> listener_130306;
283 std::shared_ptr<ObservableListener> listener_130310;
284 std::shared_ptr<ObservableListener> listener_130313;
285
286 std::string prio127245;
287 std::string prio127257;
288 std::string prio128259;
289 std::string prio128267;
290 std::string prio129029;
291 std::string prioN2kPGNsat;
292 std::string prio130306;
293
294 wxString m_self;
295
296 wxFileConfig *m_pconfig;
297 wxAuiManager *m_pauimgr;
298 int m_toolbar_item_id;
299
300 wxArrayOfDashboard m_ArrayOfDashboardWindow;
301 int m_show_id;
302 int m_hide_id;
303
304 NMEA0183 m_NMEA0183; // Used to parse NMEA Sentences
305 short mPriPosition, mPriCOGSOG, mPriHeadingM, mPriHeadingT;
306 short mPriVar, mPriDateTime, mPriAWA, mPriTWA, mPriDepth;
307 short mPriSTW, mPriWTP, mPriATMP, mPriWDN, mPriSatStatus;
308 short mPriMDA, mPriHUM;
309 // Prio: Pos from O, SK gnss.satellites, GGA sats in use, SK gnss
310 // satellitesinView, GSV sats in view
311 short mPriSatUsed, mPriAlt, mPriRSA, mPriPitchRoll;
312 double mVar;
313 // FFU
314 int mSatsInUse;
315 int mSatsInView;
316 double mHdm;
317
332 wxDateTime mUTCDateTime;
333 int m_config_version;
334 wxString m_VDO_accumulator;
335 int mHDx_Watchdog;
336 int mHDT_Watchdog;
337 int mSatsUsed_Wdog;
338 int mSatStatus_Wdog;
339 int m_PriN2kTalker;
340 int mVar_Watchdog;
341 int mMWVA_Watchdog;
342 int mMWVT_Watchdog;
343 int mDPT_DBT_Watchdog;
344 int mSTW_Watchdog;
345 int mWTP_Watchdog;
346 int mRSA_Watchdog;
347 int mVMG_Watchdog;
348 int mVMGW_Watchdog;
349 int mUTC_Watchdog;
350 int mATMP_Watchdog;
351 int mWDN_Watchdog;
352 int mMDA_Watchdog;
353 int mPITCH_Watchdog;
354 int mHEEL_Watchdog;
355 int mALT_Watchdog;
356 int mLOG_Watchdog;
357 int mTrLOG_Watchdog;
358 int mHUM_Watchdog;
359 int mWCC_Watchdog;
360
361 iirfilter mSOGFilter;
362 iirfilter mCOGFilter;
363 iirfilter mAWSFilter;
364 iirfilter mAWAFilter;
365
366 // protected:
367 // DECLARE_EVENT_TABLE();
368};
369
370class DashboardPreferencesDialog : public wxDialog {
371public:
372 DashboardPreferencesDialog(wxWindow *pparent, wxWindowID id,
373 wxArrayOfDashboard config);
375
376 void OnCloseDialog(wxCloseEvent &event);
377 void OnDashboardSelected(wxListEvent &event);
378 void OnDashboardAdd(wxCommandEvent &event);
379 void OnDashboardDelete(wxCommandEvent &event);
380 void OnInstrumentSelected(wxListEvent &event);
381 void OnInstrumentAdd(wxCommandEvent &event);
382 void OnInstrumentEdit(wxCommandEvent &event);
383 void OnInstrumentDelete(wxCommandEvent &event);
384 void OnInstrumentUp(wxCommandEvent &event);
385 void OnInstrumentDown(wxCommandEvent &event);
386 void OnDashboarddefaultFont(wxCommandEvent &event);
387 void OnDistanceUnitSelect(wxCommandEvent &event);
388 void SaveDashboardConfig();
389 void RecalculateSize(void);
390
391 wxArrayOfDashboard m_Config;
392 wxFontPickerCtrl *m_pFontPickerTitle;
393 wxFontPickerCtrl *m_pFontPickerData;
394 wxFontPickerCtrl *m_pFontPickerLabel;
395 wxFontPickerCtrl *m_pFontPickerSmall;
396 wxSpinCtrl *m_pSpinSpeedMax;
397 wxSpinCtrl *m_pSpinCOGDamp;
398 wxSpinCtrl *m_pSpinSOGDamp;
399 wxSpinCtrl *m_pSpinAWSDamp;
400 wxSpinCtrl *m_pSpinAWADamp;
401 wxChoice *m_pChoiceUTCOffset;
402 wxChoice *m_pChoiceSpeedUnit;
403 wxChoice *m_pChoiceDepthUnit;
404 wxSpinCtrlDouble *m_pSpinDBTOffset;
405 wxChoice *m_pChoiceDistanceUnit;
406 wxChoice *m_pChoiceWindSpeedUnit;
407 wxCheckBox *m_pUseInternSumLog;
408 wxStaticText *m_SumLogUnit;
409 wxTextCtrl *m_pSumLogValue;
410 wxCheckBox *m_pUseTrueWinddata;
411 wxChoice *m_pChoiceTempUnit;
412
413private:
414 void UpdateDashboardButtonsState(void);
415 void UpdateButtonsState(void);
416 int curSel;
417 wxListCtrl *m_pListCtrlDashboards;
418 wxBitmapButton *m_pButtonAddDashboard;
419 wxBitmapButton *m_pButtonDeleteDashboard;
420 wxPanel *m_pPanelDashboard;
421 wxTextCtrl *m_pTextCtrlCaption;
422 wxCheckBox *m_pCheckBoxIsVisible;
423 wxChoice *m_pChoiceOrientation;
424 wxListCtrl *m_pListCtrlInstruments;
425 wxButton *m_pButtonAdd;
426 wxButton *m_pButtonEdit;
427 wxButton *m_pButtonDelete;
428 wxButton *m_pButtonUp;
429 wxButton *m_pButtonDown;
430 wxButton *m_pButtondefaultFont;
431};
432
433class AddInstrumentDlg : public wxDialog {
434public:
435 AddInstrumentDlg(wxWindow *pparent, wxWindowID id);
437
438 unsigned int GetInstrumentAdded();
439
440private:
441 wxListCtrl *m_pListCtrlInstruments;
442};
443
444enum { ID_DASHBOARD_WINDOW };
445
446enum {
447 ID_DASH_PREFS = 999,
448 ID_DASH_VERTICAL,
449 ID_DASH_HORIZONTAL,
450 ID_DASH_RESIZE,
451 ID_DASH_UNDOCK
452};
453
454class DashboardWindow : public wxWindow {
455public:
456 DashboardWindow(wxWindow *pparent, wxWindowID id, wxAuiManager *auimgr,
457 dashboard_pi *plugin, int orient,
460
461 void SetColorScheme(PI_ColorScheme cs);
462 void SetSizerOrientation(int orient);
463 int GetSizerOrientation();
464 void OnSize(wxSizeEvent &evt);
465 void OnContextMenu(wxContextMenuEvent &evt);
466 void OnContextMenuSelect(wxCommandEvent &evt);
467
468 void OnMouseEvent(wxMouseEvent &event);
469
470#ifdef __OCPN__ANDROID__
471 void OnEvtPinchGesture(wxQT_PinchGestureEvent &event);
472 void OnEvtPanGesture(wxQT_PanGestureEvent &event);
473#endif
474
475 bool isInstrumentListEqual(const wxArrayInt &list);
476 void SetInstrumentList(wxArrayInt list,
477 wxArrayOfInstrumentProperties *InstrumentPropertyList);
478 void SendSentenceToAllInstruments(DASH_CAP st, double value, wxString unit);
479 void SendSatInfoToAllInstruments(int cnt, int seq, wxString talk,
480 SAT_INFO sats[4]);
481 void SendUtcTimeToAllInstruments(wxDateTime value);
482
483 // Default FloatingPosition (100.100) included.
484 void ChangePaneOrientation(int orient, bool updateAUImgr, int fpx = 100,
485 int fpy = 100);
486 /*TODO: OnKeyPress pass event to main window or disable focus*/
487
488 DashboardWindowContainer *m_Container;
489
490 bool m_binPinch;
491 bool m_binPan;
492
493 wxPoint m_resizeStartPoint;
494 wxSize m_resizeStartSize;
495 bool m_binResize;
496 bool m_binResize2;
497
498private:
499 wxAuiManager *m_pauimgr;
500 dashboard_pi *m_plugin;
501
502 // wx2.9 wxWrapSizer* itemBoxSizer;
503 wxBoxSizer *itemBoxSizer;
504 wxArrayOfInstrument m_ArrayOfInstrument;
505
506 wxButton *m_tButton;
507};
508
509#include "wx/button.h"
510#include "wx/fontdata.h"
511
512//-----------------------------------------------------------------------------
513// OCPNFontButton: a button which brings up a wxFontDialog
514//-----------------------------------------------------------------------------
515
516class OCPNFontButton : public wxButton {
517public:
518 OCPNFontButton() {}
519 OCPNFontButton(wxWindow *parent, wxWindowID id, const wxFontData &initial,
520 const wxPoint &pos = wxDefaultPosition,
521 const wxSize &size = wxDefaultSize,
522 long style = wxFONTBTN_DEFAULT_STYLE,
523 const wxValidator &validator = wxDefaultValidator,
524 const wxString &name = wxFontPickerWidgetNameStr) {
525 Create(parent, id, initial, pos, size, style, validator, name);
526 }
527
528 virtual wxColour GetSelectedColour() const { return m_data.GetColour(); }
529 virtual void SetSelectedFont(const wxFont &font) {
530 m_data.SetChosenFont(font);
531 m_selectedFont = m_data.GetChosenFont();
532 UpdateFont();
533 }
534 virtual void SetSelectedColour(const wxColour &colour) {
535 m_data.SetColour(colour);
536 UpdateFont();
537 }
538
539 virtual ~OCPNFontButton() {}
540
541public: // API extensions specific for OCPNFontButton
542 // user can override this to init font data in a different way
543 // virtual void InitFontData();
544
545 // returns the font data shown in wxFontDialog
546 wxFontData *GetFontData() { return &m_data; }
547
548 // get the font chosen
549 wxFont GetSelectedFont() const { return m_selectedFont; }
550
551public:
552 bool Create(wxWindow *parent, wxWindowID id, const wxFontData &initial,
553 const wxPoint &pos = wxDefaultPosition,
554 const wxSize &size = wxDefaultSize,
555 long style = wxFONTBTN_DEFAULT_STYLE,
556 const wxValidator &validator = wxDefaultValidator,
557 const wxString &name = wxFontPickerWidgetNameStr);
558
559 void OnButtonClick(wxCommandEvent &);
560
561protected:
562 void UpdateFont();
563
564 wxFontData m_data;
565
566 wxFont m_selectedFont;
567};
568
569#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 at regular intervals.
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.