25 #include <wx/arrstr.h>
26 #include <wx/button.h>
27 #include <wx/combobox.h>
28 #include <wx/dialog.h>
29 #include <wx/dynarray.h>
31 #include <wx/gdicmn.h>
33 #include <wx/stattext.h>
34 #include <wx/string.h>
35 #include <wx/window.h>
37 #include "model/conn_params.h"
38 #include "OCPNPlatform.h"
39 #include "model/rest_server.h"
40 #include "route_gui.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"
48 extern wxString g_uploadConnection;
53 EVT_BUTTON(ID_STG_CANCEL, SendToGpsDlg::OnCancelClick)
54 EVT_BUTTON(ID_STG_OK, SendToGpsDlg::OnSendClick) END_EVENT_TABLE()
57 m_itemCommListBox = NULL;
60 m_CancelButton = NULL;
66 SendToGpsDlg::SendToGpsDlg(wxWindow* parent, wxWindowID
id,
67 const wxString& caption,
const wxString& hint,
68 const wxPoint& pos,
const wxSize& size,
long style) {
69 Create(parent,
id, caption, hint, pos, size, style);
72 SendToGpsDlg::~SendToGpsDlg() {
73 delete m_itemCommListBox;
76 delete m_CancelButton;
79 bool SendToGpsDlg::Create(wxWindow* parent, wxWindowID
id,
80 const wxString& caption,
const wxString& hint,
81 const wxPoint& pos,
const wxSize& size,
long style) {
82 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
83 wxDialog::Create(parent,
id, caption, pos, size, style);
86 GetSizer()->Fit(
this);
87 GetSizer()->SetSizeHints(
this);
93 void SendToGpsDlg::CreateControls(
const wxString& hint) {
96 wxBoxSizer* itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
97 itemDialog1->SetSizer(itemBoxSizer2);
101 wxStaticBox* comm_box =
102 new wxStaticBox(
this, wxID_ANY, _(
"GPS/Plotter Port"));
104 wxStaticBoxSizer* comm_box_sizer =
new wxStaticBoxSizer(comm_box, wxVERTICAL);
105 itemBoxSizer2->Add(comm_box_sizer, 0, wxEXPAND | wxALL, 5);
107 wxArrayString* pSerialArray = EnumerateSerialPorts();
109 m_itemCommListBox =
new wxComboBox(
this, ID_STG_CHOICE_COMM);
112 for (
unsigned int iPortIndex = 0; iPortIndex < pSerialArray->GetCount();
114 wxString full_port = pSerialArray->Item(iPortIndex);
115 full_port.Prepend(_T(
"Serial:"));
116 m_itemCommListBox->Append(full_port);
122 wxArrayString netconns;
123 for (
size_t i = 0; i < TheConnectionParams()->Count(); i++) {
127 if ((cp->IOSelect != DS_TYPE_INPUT) && cp->Type == NETWORK &&
128 (cp->NetProtocol == TCP)) {
129 netident << _T(
"TCP:") << cp->NetworkAddress << _T(
":")
131 m_itemCommListBox->Append(netident);
132 netconns.Add(netident);
134 if ((cp->IOSelect != DS_TYPE_INPUT) && cp->Type == NETWORK &&
135 (cp->NetProtocol == UDP)) {
136 netident << _T(
"UDP:") << cp->NetworkAddress << _T(
":")
138 m_itemCommListBox->Append(netident);
139 netconns.Add(netident);
145 if (g_Platform->startBluetoothScan()) {
147 wxArrayString btscanResults = g_Platform->getBluetoothScanResults();
150 while ((i + 1) < btscanResults.GetCount()) {
151 wxString item1 = btscanResults[i] + _T(
";");
152 wxString item2 = btscanResults.Item(i + 1);
153 wxString port = item1 + item2;
154 port.Prepend(_T(
"Bluetooth:"));
155 m_itemCommListBox->Append(port);
160 g_Platform->stopBluetoothScan();
165 if (!g_uploadConnection.IsEmpty()) {
166 if (g_uploadConnection.Lower().StartsWith(
"tcp") ||
167 g_uploadConnection.Lower().StartsWith(
"udp")) {
168 bool b_connExists =
false;
169 for (
unsigned int i = 0; i < netconns.GetCount(); i++) {
170 if (g_uploadConnection.IsSameAs(netconns[i])) {
175 if (b_connExists) m_itemCommListBox->SetValue(g_uploadConnection);
177 m_itemCommListBox->SetValue(g_uploadConnection);
179 m_itemCommListBox->SetSelection(0);
181 comm_box_sizer->Add(m_itemCommListBox, 0, wxEXPAND | wxALL, 5);
184 itemBoxSizer2->AddSpacer(20);
186 premtext =
new wxStaticText(
187 this, -1, _(
"Prepare GPS for Route/Waypoint upload and press Send..."));
188 itemBoxSizer2->Add(premtext, 0, wxEXPAND | wxALL, 10);
191 wxStaticBox* prog_box =
new wxStaticBox(
this, wxID_ANY, _(
"Progress..."));
193 wxStaticBoxSizer* prog_box_sizer =
new wxStaticBoxSizer(prog_box, wxVERTICAL);
194 itemBoxSizer2->Add(prog_box_sizer, 0, wxEXPAND | wxALL, 5);
196 m_pgauge =
new wxGauge(
this, -1, 100);
197 prog_box_sizer->Add(m_pgauge, 0, wxEXPAND | wxALL, 5);
200 wxBoxSizer* itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
201 itemBoxSizer2->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
203 m_CancelButton =
new wxButton(itemDialog1, ID_STG_CANCEL, _(
"Cancel"),
204 wxDefaultPosition, wxDefaultSize, 0);
205 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
207 m_SendButton =
new wxButton(itemDialog1, ID_STG_OK, _(
"Send"),
208 wxDefaultPosition, wxDefaultSize, 0);
209 itemBoxSizer16->Add(m_SendButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
210 m_SendButton->SetDefault();
213 void SendToGpsDlg::SetMessage(wxString msg) {
215 premtext->SetLabel(msg);
216 premtext->Refresh(
true);
220 void SendToGpsDlg::OnSendClick(wxCommandEvent& event) {
222 wxString src = m_itemCommListBox->GetValue();
223 int tail = src.Find(
" - ");
224 if (tail != wxNOT_FOUND) {
225 src = src.SubString(0, tail);
227 if (!src.Lower().StartsWith(
"tcp") && !src.Lower().StartsWith(
"udp") &&
228 !src.Lower().StartsWith(
"serial") && !src.Lower().StartsWith(
"usb:") &&
229 !src.Lower().StartsWith(
"bluetooth")) {
230 src = src.Prepend(
"Serial:");
232 g_uploadConnection = src;
234 wxString destPort = src.BeforeFirst(
' ');
237 if (src.Lower().Find(_T(
"bluetooth")) != wxNOT_FOUND) destPort = src;
240 if (m_pRoute)
RouteGui(*m_pRoute).SendToGPS(destPort,
true,
this);
241 if (m_pRoutePoint)
RoutePointGui(*m_pRoutePoint).SendToGPS(destPort,
this);
248 void SendToGpsDlg::OnCancelClick(wxCommandEvent& event) {
Route "Send to GPS..." Dialog Definition.