OpenCPN Partial API docs
Loading...
Searching...
No Matches
connection_edit.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2022 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 ***************************************************************************/
17
24#ifndef _CONNECT_EDIT_H
25#define _CONNECT_EDIT_H
26
27#include <functional>
28
29#include <wx/checkbox.h>
30#include <wx/listctrl.h>
31#include <wx/radiobut.h>
32#include <wx/stattext.h>
33#include <wx/timer.h>
34
35#include "model/conn_params.h"
36
37#include "observable.h"
38#include "expand_icon.h"
39#include "options.h"
40#include "conn_params_panel.h"
41
46class ConnectionEditDialog : public wxPanel {
47public:
48 const wxString DEFAULT_TCP_PORT = "10110";
49 const wxString DEFAULT_UDP_PORT = "10110";
50 const wxString DEFAULT_GPSD_PORT = "2947";
51 const wxString DEFAULT_SIGNALK_PORT = "3000";
52 const wxString DEFAULT_IP_ADDRESS = "localhost";
53 // "LIMITED BROADCAST" address
54 // Deprecated, but still useful on simple mobile networks.
55 const wxString DEFAULT_UDP_OUT_ADDRESS = "255.255.255.255";
56
59 wxWindow *parent,
60 std::function<void(ConnectionParams *p, bool editing, bool ok_cancel)>
61 on_edit_click);
62
64
65 void Init(void);
66 void SetInitialSettings(void);
67 void PreloadControls(ConnectionParams *cp);
68 ConnectionParams *GetParamsFromControls();
69 void SetPropsLabel(wxString label);
70
71 void ApplySettings();
72 ConnectionParams *CreateConnectionParamsFromSelectedItem();
73 ConnectionParams *UpdateConnectionParamsFromControls(
74 ConnectionParams *pConnectionParams);
75 void SetSelectedConnectionPanel(ConnectionParamsPanel *panel);
76 void OnSelectDatasource(wxListEvent &event);
77 void OnAddDatasourceClick(wxCommandEvent &event);
78 void OnRemoveDatasourceClick(wxCommandEvent &event);
79
80 void OnTypeSerialSelected(wxCommandEvent &event);
81 void OnTypeNetSelected(wxCommandEvent &event);
82 void OnTypeGPSSelected(wxCommandEvent &event);
83 void OnTypeBTSelected(wxCommandEvent &event);
84 void OnTypeCANSelected(wxCommandEvent &event);
85
86 void OnNetProtocolSelected(wxCommandEvent &event);
87 void OnBaudrateChoice(wxCommandEvent &event) { OnConnValChange(event); }
88 void OnProtocolChoice(wxCommandEvent &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 OnCollapsedToggle(bool collapsed);
103 void OnShowGpsWindowCheckboxClick(wxCommandEvent &event);
104 void EnableConnection(ConnectionParams *conn, bool value);
105 void OnDiscoverButton(wxCommandEvent &event);
106 void UpdateDiscoverStatus(wxString stat);
107 void OnPriorityDialog(wxCommandEvent &event);
108
109 void SetConnectionParams(ConnectionParams *cp);
110 void SetDefaultConnectionParams(void);
111 void SetDSFormRWStates();
112 void SetDSFormOptionVizStates();
113 void FillSourceList();
114 void UpdateSourceList(bool bResort);
115 bool SortSourceList(void);
116 void SetUDPNetAddressVisiblity(void);
117 bool IsAddressMultiCast(wxString ip);
118 bool IsAddressBroadcast(wxString ip);
119 bool IsDefaultPort(wxString address);
120
121 void ClearNMEAForm(void);
122 void SetNMEAFormToSerial(void);
123 void SetNMEAFormToNet(void);
124 void SetNMEAFormToGPS(void);
125 void SetNMEAFormToBT(void);
126 void SetNMEAFormToCAN(void);
127 void SetNMEAFormForSerialProtocol();
128 void SetNMEAFormForNetProtocol();
129
130 void ShowTypeCommon(bool visible = true);
131 void ShowNMEACommon(bool visible);
132 void ShowNMEASerial(bool visible);
133 void ShowNMEANet(bool visible);
134 void ShowNMEAGPS(bool visible);
135 void ShowNMEABT(bool visible);
136 void ShowNMEACAN(bool visible);
137
138 void OnScanBTClick(wxCommandEvent &event);
139 void onBTScanTimer(wxTimerEvent &event);
140 void StopBTScan(void);
141
142 void OnWheelChoice(wxMouseEvent &event);
143
144 void ShowInFilter(bool bshow = true);
145 void ShowOutFilter(bool bshow = true);
146 void LayoutDialog();
147
148 void CreateControls();
149 void ConnectControls();
150
151 void SetNewMode(bool mode) { new_mode = mode; }
152
153 void AddOKCancelButtons();
154 wxStdDialogButtonSizer *m_btnSizer;
155 wxBoxSizer *m_btnSizerBox;
156
157 wxButton *m_btnOK;
158 wxButton *m_btnCancel;
159 bool new_mode;
160
161 void OnOKClick();
162 void OnCancelClick();
163
164 // private:
165 wxWindow *m_parent;
166 // wxScrolledWindow *m_scrolledwin;
167
168 wxGridSizer *gSizerNetProps, *gSizerSerProps, *gSizerCanProps;
169 wxTextCtrl *m_tNetAddress, *m_tNetPort, *m_tFilterSec, *m_tcInputStc;
170 wxTextCtrl *m_tcOutputStc;
171 wxCheckBox *m_cbGarminHost, *m_cbGarminUploadHost, *m_cbCheckSKDiscover;
172 wxCheckBox *m_cbFurunoGP3X, *m_cbNMEADebug, *m_cbFilterSogCog, *m_cbInput;
173 wxCheckBox *m_cbMultiCast, *m_cbAdvanced;
174 wxCheckBox *m_cbOutput, *m_cbAPBMagnetic;
175 wxComboBox *m_comboPort;
176 wxStdDialogButtonSizer *m_sdbSizerDlgButtons;
177 wxButton *m_ButtonSKDiscover, *m_ButtonPriorityDialog;
178 wxStaticText *m_StaticTextSKServerStatus;
179
180 wxButton *m_buttonAdd, *m_buttonRemove, *m_buttonScanBT, *m_btnInputStcList;
181 wxButton *m_btnOutputStcList, *m_sdbSizerDlgButtonsOK;
182 wxButton *m_sdbSizerDlgButtonsApply, *m_sdbSizerDlgButtonsCancel;
183 wxStaticBoxSizer *sbSizerConnectionProps, *sbSizerInFilter;
184 wxStaticBoxSizer *sbSizerOutFilter;
185 wxRadioButton *m_rbTypeSerial, *m_rbTypeNet, *m_rbTypeInternalGPS;
186 wxRadioButton *m_rbTypeInternalBT, *m_rbNetProtoTCP, *m_rbNetProtoUDP;
187 wxRadioButton *m_rbNetProtoGPSD, *m_rbIAccept, *m_rbIIgnore, *m_rbOAccept;
188 wxRadioButton *m_rbNetProtoSignalK;
189 wxRadioButton *m_rbOIgnore, *m_rbTypeCAN;
190 wxStaticText *m_stBTPairs, *m_stNetProto, *m_stNetAddr, *m_stNetPort;
191 wxStaticText *m_stSerPort, *m_stSerBaudrate, *m_stSerProtocol;
192 wxStaticText *m_stFilterSec, *m_stPrecision;
193 wxStaticText *m_stTalkerIdText;
194 wxStaticText *m_stNetComment, *m_stSerialComment, *m_stCANSource,
195 *m_stAuthToken;
196 wxTextCtrl *m_tNetComment, *m_tSerialComment, *m_tAuthToken;
197 wxStaticBox *m_sbConnEdit;
198 wxChoice *m_choiceBTDataSources, *m_choiceBaudRate, *m_choiceSerialProtocol;
199 wxChoice *m_choicePriority, *m_choicePrecision, *m_choiceCANSource;
200 wxChoice *m_choiceNetDataProtocol;
201
202 wxBoxSizer *boxSizerConnections;
203 wxStaticText *m_stNetDataProtocol;
204
205 ConnectionParams *mSelectedConnection;
206
207#ifdef __ANDROID__
208 wxPanel *m_scrollWinConnections;
209#else
210 wxScrolledWindow *m_scrollWinConnections;
211#endif
212
213 bool connectionsaved;
214 bool m_advanced = false;
215 bool m_connection_enabled;
216 bool m_bNMEAParams_shown;
217 int m_btNoChangeCounter, m_btlastResultCount, m_BTscanning;
218 wxArrayString m_BTscan_results;
219 wxTimer m_BTScanTimer;
220 wxArrayString m_choice_CANSource_choices;
221
222 ObsListener new_device_listener;
223 ConnectionParams *m_cp_original;
224
225 std::function<void(ConnectionParams *, bool, bool)> m_on_edit_click;
226
227protected:
228 wxSizer *m_collapse_box;
229};
230
231class SentenceListDlg : public wxDialog {
232public:
233 explicit SentenceListDlg(wxWindow *parent, FilterDirection dir, ListType type,
234 const wxArrayString &list);
235 wxString GetSentences(void);
236
237private:
238 void OnAddClick(wxCommandEvent &event);
239 void OnDeleteClick(wxCommandEvent &event);
240 void OnCLBSelect(wxCommandEvent &event);
241 void OnCheckAllClick(wxCommandEvent &event);
242 void OnClearAllClick(wxCommandEvent &event);
243
244 void Populate(const wxArrayString &list);
245 wxString GetBoxLabel(void) const;
246
247 wxCheckListBox *m_clbSentences;
248 wxButton *m_btnDel;
249
250 ListType m_type;
251 FilterDirection m_dir;
252 wxArrayString m_sentences;
253};
254
255#endif //_CONNECT_DIALOG_H
Dialog for editing connection parameters.
Panel for displaying and editing connection parameters.
Define an action to be performed when a KeyProvider is notified.
Definition observable.h:257
Panel for editing a connection.
General observable implementation with several specializations.