27#include <wx/combobox.h>
29#include <wx/dynarray.h>
33#include <wx/stattext.h>
37#include "model/conn_params.h"
38#include "OCPNPlatform.h"
39#include "model/rest_server.h"
41#include "model/route.h"
42#include "route_point_gui.h"
43#include "model/route_point.h"
44#include "SendToGpsDlg.h"
45#include "model/ser_ports.h"
48extern wxString g_uploadConnection;
51EVT_BUTTON(ID_STG_CANCEL, SendToGpsDlg::OnCancelClick)
52EVT_BUTTON(ID_STG_OK, SendToGpsDlg::OnSendClick)
56 m_itemCommListBox = NULL;
59 m_CancelButton = NULL;
65SendToGpsDlg::SendToGpsDlg(wxWindow* parent, wxWindowID
id,
66 const wxString& caption,
const wxString& hint,
67 const wxPoint& pos,
const wxSize& size,
long style) {
68 Create(parent,
id, caption, hint, pos, size, style);
71SendToGpsDlg::~SendToGpsDlg() {
72 delete m_itemCommListBox;
75 delete m_CancelButton;
78bool SendToGpsDlg::Create(wxWindow* parent, wxWindowID
id,
79 const wxString& caption,
const wxString& hint,
80 const wxPoint& pos,
const wxSize& size,
long style) {
81 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
82 wxDialog::Create(parent,
id, caption, pos, size, style);
85 GetSizer()->Fit(
this);
86 GetSizer()->SetSizeHints(
this);
92void SendToGpsDlg::CreateControls(
const wxString& hint) {
95 wxBoxSizer* itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
96 itemDialog1->SetSizer(itemBoxSizer2);
100 wxStaticBox* comm_box =
101 new wxStaticBox(
this, wxID_ANY, _(
"GPS/Plotter Port"));
103 wxStaticBoxSizer* comm_box_sizer =
new wxStaticBoxSizer(comm_box, wxVERTICAL);
104 itemBoxSizer2->Add(comm_box_sizer, 0, wxEXPAND | wxALL, 5);
106 wxArrayString* pSerialArray = EnumerateSerialPorts();
108 m_itemCommListBox =
new wxComboBox(
this, ID_STG_CHOICE_COMM);
111 for (
unsigned int iPortIndex = 0; iPortIndex < pSerialArray->GetCount();
113 wxString full_port = pSerialArray->Item(iPortIndex);
114 full_port.Prepend(_T(
"Serial:"));
115 m_itemCommListBox->Append(full_port);
121 wxArrayString netconns;
122 for (
auto* cp : TheConnectionParams()) {
125 if ((cp->IOSelect != DS_TYPE_INPUT) && cp->Type == NETWORK &&
126 (cp->NetProtocol == TCP)) {
127 netident << _T(
"TCP:") << cp->NetworkAddress << _T(
":")
129 m_itemCommListBox->Append(netident);
130 netconns.Add(netident);
132 if ((cp->IOSelect != DS_TYPE_INPUT) && cp->Type == NETWORK &&
133 (cp->NetProtocol == UDP)) {
134 netident << _T(
"UDP:") << cp->NetworkAddress << _T(
":")
136 m_itemCommListBox->Append(netident);
137 netconns.Add(netident);
143 if (g_Platform->startBluetoothScan()) {
145 wxArrayString btscanResults = g_Platform->getBluetoothScanResults();
148 while ((i + 1) < btscanResults.GetCount()) {
149 wxString item1 = btscanResults[i] + _T(
";");
150 wxString item2 = btscanResults.Item(i + 1);
151 wxString port = item1 + item2;
152 port.Prepend(_T(
"Bluetooth:"));
153 m_itemCommListBox->Append(port);
158 g_Platform->stopBluetoothScan();
163 if (!g_uploadConnection.IsEmpty()) {
164 if (g_uploadConnection.Lower().StartsWith(
"tcp") ||
165 g_uploadConnection.Lower().StartsWith(
"udp")) {
166 bool b_connExists =
false;
167 for (
unsigned int i = 0; i < netconns.GetCount(); i++) {
168 if (g_uploadConnection.IsSameAs(netconns[i])) {
173 if (b_connExists) m_itemCommListBox->SetValue(g_uploadConnection);
175 m_itemCommListBox->SetValue(g_uploadConnection);
177 m_itemCommListBox->SetSelection(0);
179 comm_box_sizer->Add(m_itemCommListBox, 0, wxEXPAND | wxALL, 5);
182 itemBoxSizer2->AddSpacer(20);
184 premtext =
new wxStaticText(
185 this, -1, _(
"Prepare GPS for Route/Waypoint upload and press Send..."));
186 itemBoxSizer2->Add(premtext, 0, wxEXPAND | wxALL, 10);
189 wxStaticBox* prog_box =
new wxStaticBox(
this, wxID_ANY, _(
"Progress..."));
191 wxStaticBoxSizer* prog_box_sizer =
new wxStaticBoxSizer(prog_box, wxVERTICAL);
192 itemBoxSizer2->Add(prog_box_sizer, 0, wxEXPAND | wxALL, 5);
194 m_pgauge =
new wxGauge(
this, -1, 100);
195 prog_box_sizer->Add(m_pgauge, 0, wxEXPAND | wxALL, 5);
198 wxBoxSizer* itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
199 itemBoxSizer2->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
201 m_CancelButton =
new wxButton(itemDialog1, ID_STG_CANCEL, _(
"Cancel"),
202 wxDefaultPosition, wxDefaultSize, 0);
203 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
205 m_SendButton =
new wxButton(itemDialog1, ID_STG_OK, _(
"Send"),
206 wxDefaultPosition, wxDefaultSize, 0);
207 itemBoxSizer16->Add(m_SendButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
208 m_SendButton->SetDefault();
211void SendToGpsDlg::SetMessage(wxString msg) {
213 premtext->SetLabel(msg);
214 premtext->Refresh(
true);
218void SendToGpsDlg::OnSendClick(wxCommandEvent& event) {
220 wxString src = m_itemCommListBox->GetValue();
221 int tail = src.Find(
" - ");
222 if (tail != wxNOT_FOUND) {
223 src = src.SubString(0, tail);
225 if (!src.Lower().StartsWith(
"tcp") && !src.Lower().StartsWith(
"udp") &&
226 !src.Lower().StartsWith(
"serial") && !src.Lower().StartsWith(
"usb:") &&
227 !src.Lower().StartsWith(
"bluetooth")) {
228 src = src.Prepend(
"Serial:");
230 g_uploadConnection = src;
232 wxString destPort = src.BeforeFirst(
' ');
235 if (src.Lower().Find(_T(
"bluetooth")) != wxNOT_FOUND) destPort = src;
238 if (m_pRoute)
RouteGui(*m_pRoute).SendToGPS(destPort,
true,
this);
239 if (m_pRoutePoint)
RoutePointGui(*m_pRoutePoint).SendToGPS(destPort,
this);
246void SendToGpsDlg::OnCancelClick(wxCommandEvent& event) {
Dialog for sending routes/waypoints to a GPS device.