OpenCPN Partial API docs
connection_edit.h
1 /******************************************************************************
2  *
3  * Project: OpenCPN
4  * Purpose:
5  * Author: David Register
6  *
7  ***************************************************************************
8  * Copyright (C) 2022 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 
27 #ifndef _CONNECT_EDIT_H
28 #define _CONNECT_EDIT_H
29 
30 #include <wx/checkbox.h>
31 #include <wx/listctrl.h>
32 #include <wx/radiobut.h>
33 #include <wx/stattext.h>
34 #include <wx/timer.h>
35 
36 #include "model/conn_params.h"
37 #include "model/comm_util.h"
38 
39 #include "observable.h"
40 
41 class options;
43 
44 //----------------------------------------------------------------------------
45 // ConnectionEditDialog
46 //----------------------------------------------------------------------------
47 class ConnectionEditDialog : public wxDialog {
48 public:
49  const wxString DEFAULT_TCP_PORT = "10110";
50  const wxString DEFAULT_UDP_PORT = "10110";
51  const wxString DEFAULT_GPSD_PORT = "2947";
52  const wxString DEFAULT_SIGNALK_PORT = "3000";
53  const wxString DEFAULT_IP_ADDRESS = "localhost";
54  // "LIMITED BROADCAST" address
55  // Deprecated, but still useful on simple mobile networks.
56  const wxString DEFAULT_UDP_OUT_ADDRESS = "255.255.255.255";
57 
59  // ConnectionEditDialog(wxScrolledWindow *container, options *parent);
61 
63 
64  void Init(void);
65  void SetInitialSettings(void);
66  void PreloadControls(ConnectionParams *cp);
67  ConnectionParams *GetParamsFromControls();
68  void SetPropsLabel(wxString label);
69 
70  void ApplySettings();
71  ConnectionParams *CreateConnectionParamsFromSelectedItem();
72  ConnectionParams *UpdateConnectionParamsFromControls(
73  ConnectionParams *pConnectionParams);
74  void SetSelectedConnectionPanel(ConnectionParamsPanel *panel);
75  void OnSelectDatasource(wxListEvent &event);
76  void OnAddDatasourceClick(wxCommandEvent &event);
77  void OnRemoveDatasourceClick(wxCommandEvent &event);
78 
79  void OnTypeSerialSelected(wxCommandEvent &event);
80  void OnTypeNetSelected(wxCommandEvent &event);
81  void OnTypeGPSSelected(wxCommandEvent &event);
82  void OnTypeBTSelected(wxCommandEvent &event);
83  void OnTypeCANSelected(wxCommandEvent &event);
84 
85  void OnNetProtocolSelected(wxCommandEvent &event);
86  void OnBaudrateChoice(wxCommandEvent &event) { OnConnValChange(event); }
87  void OnProtocolChoice(wxCommandEvent &event);
88  void OnCrcCheck(wxCommandEvent &event) { OnConnValChange(event); }
89  void OnRbAcceptInput(wxCommandEvent &event);
90  void OnRbIgnoreInput(wxCommandEvent &event);
91  void OnBtnIStcs(wxCommandEvent &event);
92  void OnCbInput(wxCommandEvent &event);
93  void OnCbOutput(wxCommandEvent &event);
94  void OnCbMultiCast(wxCommandEvent &event);
95  void OnCbAdvanced(wxCommandEvent &event);
96  void OnClickMore(wxMouseEvent &event);
97  void OnRbOutput(wxCommandEvent &event);
98  void OnBtnOStcs(wxCommandEvent &event);
99  void OnConnValChange(wxCommandEvent &event);
100  void OnValChange(wxCommandEvent &event);
101  void OnUploadFormatChange(wxCommandEvent &event);
102  void OnShowGpsWindowCheckboxClick(wxCommandEvent &event);
103  void EnableConnection(ConnectionParams *conn, bool value);
104  void OnDiscoverButton(wxCommandEvent &event);
105  void UpdateDiscoverStatus(wxString stat);
106  void OnPriorityDialog(wxCommandEvent &event);
107 
108  void SetConnectionParams(ConnectionParams *cp);
109  void SetDefaultConnectionParams(void);
110  void SetDSFormRWStates();
111  void SetDSFormOptionVizStates();
112  void FillSourceList();
113  void UpdateSourceList(bool bResort);
114  bool SortSourceList(void);
115  void SetUDPNetAddressVisiblity(void);
116  bool IsAddressMultiCast(wxString ip);
117  bool IsAddressBroadcast(wxString ip);
118  bool IsDefaultPort(wxString address);
119 
120  void ClearNMEAForm(void);
121  void SetNMEAFormToSerial(void);
122  void SetNMEAFormToNet(void);
123  void SetNMEAFormToGPS(void);
124  void SetNMEAFormToBT(void);
125  void SetNMEAFormToCAN(void);
126  void SetNMEAFormForSerialProtocol();
127  void SetNMEAFormForNetProtocol();
128 
129  void ShowTypeCommon(bool visible = true);
130  void ShowNMEACommon(bool visible);
131  void ShowNMEASerial(bool visible);
132  void ShowNMEANet(bool visible);
133  void ShowNMEAGPS(bool visible);
134  void ShowNMEABT(bool visible);
135  void ShowNMEACAN(bool visible);
136 
137  void OnScanBTClick(wxCommandEvent &event);
138  void onBTScanTimer(wxTimerEvent &event);
139  void StopBTScan(void);
140 
141  void OnWheelChoice(wxMouseEvent &event);
142 
143  void ShowInFilter(bool bshow = true);
144  void ShowOutFilter(bool bshow = true);
145  void LayoutDialog();
146 
147  void CreateControls();
148  void ConnectControls();
149 
150  // private:
151  options *m_parent;
152  wxScrolledWindow *m_scrolledwin;
153 
154  wxGridSizer *gSizerNetProps, *gSizerSerProps, *gSizerCanProps;
155  wxTextCtrl *m_tNetAddress, *m_tNetPort, *m_tFilterSec, *m_tcInputStc;
156  wxTextCtrl *m_tcOutputStc;
157  wxCheckBox *m_cbCheckCRC, *m_cbGarminHost, *m_cbGarminUploadHost,
158  *m_cbCheckSKDiscover;
159  wxCheckBox *m_cbFurunoGP3X, *m_cbNMEADebug, *m_cbFilterSogCog, *m_cbInput;
160  wxCheckBox *m_cbMultiCast, *m_cbAdvanced;
161  wxCheckBox *m_cbOutput, *m_cbAPBMagnetic;
162  wxComboBox *m_comboPort;
163  wxStdDialogButtonSizer *m_sdbSizerDlgButtons;
164  wxButton *m_ButtonSKDiscover, *m_ButtonPriorityDialog;
165  wxStaticText *m_StaticTextSKServerStatus;
166 
167  wxButton *m_buttonAdd, *m_buttonRemove, *m_buttonScanBT, *m_btnInputStcList;
168  wxButton *m_btnOutputStcList, *m_sdbSizerDlgButtonsOK;
169  wxButton *m_sdbSizerDlgButtonsApply, *m_sdbSizerDlgButtonsCancel;
170  wxStaticBoxSizer *sbSizerConnectionProps, *sbSizerInFilter;
171  wxStaticBoxSizer *sbSizerOutFilter;
172  wxRadioButton *m_rbTypeSerial, *m_rbTypeNet, *m_rbTypeInternalGPS;
173  wxRadioButton *m_rbTypeInternalBT, *m_rbNetProtoTCP, *m_rbNetProtoUDP;
174  wxRadioButton *m_rbNetProtoGPSD, *m_rbIAccept, *m_rbIIgnore, *m_rbOAccept;
175  wxRadioButton *m_rbNetProtoSignalK;
176  wxRadioButton *m_rbOIgnore, *m_rbTypeCAN;
177  wxStaticText *m_stBTPairs, *m_stNetProto, *m_stNetAddr, *m_stNetPort;
178  wxStaticText *m_stSerPort, *m_stSerBaudrate, *m_stSerProtocol;
179  wxStaticText *m_stPriority, *m_stFilterSec, *m_stPrecision;
180  wxStaticText *m_stTalkerIdText;
181  wxStaticText *m_stNetComment, *m_stSerialComment, *m_stCANSource,
182  *m_stAuthToken;
183  wxTextCtrl *m_tNetComment, *m_tSerialComment, *m_tAuthToken;
184  wxStaticBox *m_sbConnEdit;
185  wxChoice *m_choiceBTDataSources, *m_choiceBaudRate, *m_choiceSerialProtocol;
186  wxChoice *m_choicePriority, *m_choicePrecision, *m_choiceCANSource;
187  wxChoice *m_choiceNetDataProtocol;
188 
189  wxBoxSizer *boxSizerConnections;
190  wxStaticText *m_stNetDataProtocol;
191 
192  ConnectionParams *mSelectedConnection;
193 
194 #ifdef __ANDROID__
195  wxPanel *m_scrollWinConnections;
196 #else
197  wxScrolledWindow *m_scrollWinConnections;
198 #endif
199 
200  bool connectionsaved;
201  bool m_advanced = false;
202  bool m_connection_enabled;
203  bool m_bNMEAParams_shown;
204  int m_btNoChangeCounter, m_btlastResultCount, m_BTscanning;
205  wxArrayString m_BTscan_results;
206  wxTimer m_BTScanTimer;
207  wxArrayString m_choice_CANSource_choices;
208 
209  ObsListener new_device_listener;
210 
211  // DECLARE_EVENT_TABLE()
212 protected:
213  wxString MORE, LESS;
214  wxStaticText *m_more;
215 };
216 
217 class SentenceListDlg : public wxDialog {
218 public:
219  explicit SentenceListDlg(wxWindow *parent, FilterDirection dir, ListType type,
220  const wxArrayString &list);
221  wxString GetSentences(void);
222 
223 private:
224  void OnAddClick(wxCommandEvent &event);
225  void OnDeleteClick(wxCommandEvent &event);
226  void OnCLBSelect(wxCommandEvent &event);
227  void OnCheckAllClick(wxCommandEvent &event);
228  void OnClearAllClick(wxCommandEvent &event);
229 
230  void Populate(const wxArrayString &list);
231  wxString GetBoxLabel(void) const;
232 
233  wxCheckListBox *m_clbSentences;
234  wxButton *m_btnDel;
235 
236  ListType m_type;
237  FilterDirection m_dir;
238  wxArrayString m_sentences;
239 };
240 
241 #endif //_CONNECT_DIALOG_H
Define an action to be performed when a KeyProvider is notified.
Definition: observable.h:210