26#include <wx/combobox.h>
28#include <wx/dynarray.h>
32#include <wx/stattext.h>
49EVT_BUTTON(ID_STG_CANCEL, SendToGpsDlg::OnCancelClick)
50EVT_BUTTON(ID_STG_OK, SendToGpsDlg::OnSendClick)
54 m_itemCommListBox = NULL;
57 m_CancelButton = NULL;
63SendToGpsDlg::SendToGpsDlg(wxWindow* parent, wxWindowID
id,
64 const wxString& caption,
const wxString& hint,
65 const wxPoint& pos,
const wxSize& size,
long style) {
66 Create(parent,
id, caption, hint, pos, size, style);
69SendToGpsDlg::~SendToGpsDlg() {
70 delete m_itemCommListBox;
73 delete m_CancelButton;
76bool SendToGpsDlg::Create(wxWindow* parent, wxWindowID
id,
77 const wxString& caption,
const wxString& hint,
78 const wxPoint& pos,
const wxSize& size,
long style) {
79 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
80 wxDialog::Create(parent,
id, caption, pos, size, style);
83 GetSizer()->Fit(
this);
84 GetSizer()->SetSizeHints(
this);
90void SendToGpsDlg::CreateControls(
const wxString& hint) {
93 wxBoxSizer* itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
94 itemDialog1->SetSizer(itemBoxSizer2);
98 wxStaticBox* comm_box =
99 new wxStaticBox(
this, wxID_ANY, _(
"GPS/Plotter Port"));
101 wxStaticBoxSizer* comm_box_sizer =
new wxStaticBoxSizer(comm_box, wxVERTICAL);
102 itemBoxSizer2->Add(comm_box_sizer, 0, wxEXPAND | wxALL, 5);
106 m_itemCommListBox =
new wxComboBox(
this, ID_STG_CHOICE_COMM);
109 for (
unsigned int iPortIndex = 0; iPortIndex < pSerialArray->GetCount();
111 wxString full_port = pSerialArray->Item(iPortIndex);
112 full_port.Prepend(
"Serial:");
113 m_itemCommListBox->Append(full_port);
119 wxArrayString netconns;
120 for (
auto* cp : TheConnectionParams()) {
123 if ((cp->IOSelect != DS_TYPE_INPUT) && cp->Type == NETWORK &&
124 (cp->NetProtocol == TCP)) {
125 netident <<
"TCP:" << cp->NetworkAddress <<
":" << cp->NetworkPort;
126 m_itemCommListBox->Append(netident);
127 netconns.Add(netident);
129 if ((cp->IOSelect != DS_TYPE_INPUT) && cp->Type == NETWORK &&
130 (cp->NetProtocol == UDP)) {
131 netident <<
"UDP:" << cp->NetworkAddress <<
":" << cp->NetworkPort;
132 m_itemCommListBox->Append(netident);
133 netconns.Add(netident);
139 if (g_Platform->startBluetoothScan()) {
141 wxArrayString btscanResults = g_Platform->getBluetoothScanResults();
144 while ((i + 1) < btscanResults.GetCount()) {
145 wxString item1 = btscanResults[i] +
";";
146 wxString item2 = btscanResults.Item(i + 1);
147 wxString port = item1 + item2;
148 port.Prepend(
"Bluetooth:");
149 m_itemCommListBox->Append(port);
154 g_Platform->stopBluetoothScan();
159 if (!g_uploadConnection.IsEmpty()) {
160 if (g_uploadConnection.Lower().StartsWith(
"tcp") ||
161 g_uploadConnection.Lower().StartsWith(
"udp")) {
162 bool b_connExists =
false;
163 for (
unsigned int i = 0; i < netconns.GetCount(); i++) {
164 if (g_uploadConnection.IsSameAs(netconns[i])) {
169 if (b_connExists) m_itemCommListBox->SetValue(g_uploadConnection);
171 m_itemCommListBox->SetValue(g_uploadConnection);
173 m_itemCommListBox->SetSelection(0);
175 comm_box_sizer->Add(m_itemCommListBox, 0, wxEXPAND | wxALL, 5);
178 itemBoxSizer2->AddSpacer(20);
180 premtext =
new wxStaticText(
181 this, -1, _(
"Prepare GPS for Route/Waypoint upload and press Send..."));
182 itemBoxSizer2->Add(premtext, 0, wxEXPAND | wxALL, 10);
185 wxStaticBox* prog_box =
new wxStaticBox(
this, wxID_ANY, _(
"Progress..."));
187 wxStaticBoxSizer* prog_box_sizer =
new wxStaticBoxSizer(prog_box, wxVERTICAL);
188 itemBoxSizer2->Add(prog_box_sizer, 0, wxEXPAND | wxALL, 5);
190 m_pgauge =
new wxGauge(
this, -1, 100);
191 prog_box_sizer->Add(m_pgauge, 0, wxEXPAND | wxALL, 5);
194 wxBoxSizer* itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
195 itemBoxSizer2->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
197 m_CancelButton =
new wxButton(itemDialog1, ID_STG_CANCEL, _(
"Cancel"),
198 wxDefaultPosition, wxDefaultSize, 0);
199 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
201 m_SendButton =
new wxButton(itemDialog1, ID_STG_OK, _(
"Send"),
202 wxDefaultPosition, wxDefaultSize, 0);
203 itemBoxSizer16->Add(m_SendButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
204 m_SendButton->SetDefault();
207void SendToGpsDlg::SetMessage(wxString msg) {
209 premtext->SetLabel(msg);
210 premtext->Refresh(
true);
214void SendToGpsDlg::OnSendClick(wxCommandEvent& event) {
216 wxString src = m_itemCommListBox->GetValue();
217 int tail = src.Find(
" - ");
218 if (tail != wxNOT_FOUND) {
219 src = src.SubString(0, tail);
221 if (!src.Lower().StartsWith(
"tcp") && !src.Lower().StartsWith(
"udp") &&
222 !src.Lower().StartsWith(
"serial") && !src.Lower().StartsWith(
"usb:") &&
223 !src.Lower().StartsWith(
"bluetooth")) {
224 src = src.Prepend(
"Serial:");
226 g_uploadConnection = src;
228 wxString destPort = src.BeforeFirst(
' ');
231 if (src.Lower().Find(
"bluetooth") != wxNOT_FOUND) destPort = src;
234 if (m_pRoute)
RouteGui(*m_pRoute).SendToGPS(destPort,
true,
this);
235 if (m_pRoutePoint)
RoutePointGui(*m_pRoutePoint).SendToGPS(destPort,
this);
242void SendToGpsDlg::OnCancelClick(wxCommandEvent& event) {
Dialog for sending routes/waypoints to a GPS device.
Global variables stored in configuration file.
Waypoint or mark abstraction.
Purpose: Track and Trackpoint drawing stuff.
Send route/waypoint to GPS dialog.
Serial ports support, notably enumeration.
wxArrayString * EnumerateSerialPorts(void)
Enumerate all serial ports.