OpenCPN Partial API docs
Loading...
Searching...
No Matches
TrackPropDlg.cpp
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: Track Properties Dialog
5 * Author: David Register
6 *
7 ***************************************************************************
8 * Copyright (C) 2013 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#include "config.h"
26
27#include "model/georef.h"
28#include "model/navutil_base.h"
29#include "model/own_ship.h"
30#include "model/plugin_comm.h"
31#include "model/route.h"
32#include "model/routeman.h"
33#include "model/select.h"
34#include "model/track.h"
35
36#include "chcanv.h"
37#include "displays.h"
38#include "gui_lib.h"
39#include "navutil.h"
40#include "ocpn_frame.h"
41#include "OCPNPlatform.h"
42#include "pluginmanager.h"
43#include "routemanagerdialog.h"
44#include "routeman_gui.h"
45#include "trackprintout.h"
46#include "TrackPropDlg.h"
47
48#ifdef __ANDROID__
49#include "androidUTIL.h"
50#endif
51
52#define UTCINPUT 0
53#define LTINPUT \
54 1
55#define LMTINPUT \
56 2
58#define GLOBAL_SETTINGS_INPUT 3
59
60#define INPUT_FORMAT 1
61#define DISPLAY_FORMAT 2
62#define TIMESTAMP_FORMAT 3
63
64extern std::vector<Track*> g_TrackList;
65extern ActiveTrack* g_pActiveTrack;
66extern Routeman* g_pRouteMan;
67extern RouteManagerDialog* pRouteManagerDialog;
68extern MyConfig* pConfig;
69extern MyFrame* gFrame;
70
72bool TrackPropDlg::instanceFlag = false;
73TrackPropDlg* TrackPropDlg::single = NULL;
74TrackPropDlg* TrackPropDlg::getInstance(wxWindow* parent, wxWindowID id,
75 const wxString& title,
76 const wxPoint& pos, const wxSize& size,
77 long style) {
78 if (!instanceFlag) {
79 single = new TrackPropDlg(parent, id, title, pos, size, style);
80 instanceFlag = true;
81 return single;
82 } else {
83 return single;
84 }
85}
86
87TrackPropDlg::TrackPropDlg(wxWindow* parent, wxWindowID id,
88 const wxString& title, const wxPoint& pos,
89 const wxSize& size, long style)
90 : DIALOG_PARENT(parent, id, title, pos, size, style) {
91 wxFont* qFont = GetOCPNScaledFont(_("Dialog"));
92 SetFont(*qFont);
93
94 SetWindowStyleFlag(style);
95
96 m_scrolledWindowLinks = NULL;
97 m_tDescription = NULL;
98
99 m_bcompact = false;
100
101#ifdef __ANDROID__
102 m_bcompact = true;
103 CreateControlsCompact();
104#else
105 CreateControls();
106#endif
107
108 RecalculateSize();
109
110 // Centre( );
111
112 // Connect Events
113 m_sdbBtmBtnsSizerCancel->Connect(
114 wxEVT_COMMAND_BUTTON_CLICKED,
115 wxCommandEventHandler(TrackPropDlg::OnCancelBtnClick), NULL, this);
116 m_sdbBtmBtnsSizerOK->Connect(
117 wxEVT_COMMAND_BUTTON_CLICKED,
118 wxCommandEventHandler(TrackPropDlg::OnOKBtnClick), NULL, this);
119 if (m_sdbBtmBtnsSizerPrint)
120 m_sdbBtmBtnsSizerPrint->Connect(
121 wxEVT_COMMAND_BUTTON_CLICKED,
122 wxCommandEventHandler(TrackPropDlg::OnPrintBtnClick), NULL, this);
123 m_sdbBtmBtnsSizerSplit->Connect(
124 wxEVT_COMMAND_BUTTON_CLICKED,
125 wxCommandEventHandler(TrackPropDlg::OnSplitBtnClick), NULL, this);
126 m_sdbBtmBtnsSizerExtend->Connect(
127 wxEVT_COMMAND_BUTTON_CLICKED,
128 wxCommandEventHandler(TrackPropDlg::OnExtendBtnClick), NULL, this);
129 m_sdbBtmBtnsSizerToRoute->Connect(
130 wxEVT_COMMAND_BUTTON_CLICKED,
131 wxCommandEventHandler(TrackPropDlg::OnToRouteBtnClick), NULL, this);
132 if (m_sdbBtmBtnsSizerExport)
133 m_sdbBtmBtnsSizerExport->Connect(
134 wxEVT_COMMAND_BUTTON_CLICKED,
135 wxCommandEventHandler(TrackPropDlg::OnExportBtnClick), NULL, this);
136 m_lcPoints->Connect(wxEVT_COMMAND_LIST_ITEM_SELECTED,
137 wxListEventHandler(TrackPropDlg::OnTrackPropListClick),
138 NULL, this);
139 Connect(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
140 wxListEventHandler(TrackPropDlg::OnTrackPropRightClick), NULL, this);
141 Connect(wxEVT_COMMAND_MENU_SELECTED,
142 wxCommandEventHandler(TrackPropDlg::OnTrackPropMenuSelected), NULL,
143 this);
144
145#ifdef __WXOSX__
146 Connect(wxEVT_ACTIVATE, wxActivateEventHandler(TrackPropDlg::OnActivate),
147 NULL, this);
148#endif
149
150 if (!m_bcompact) {
151 m_buttonAddLink->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
152 wxCommandEventHandler(TrackPropDlg::OnAddLink),
153 NULL, this);
154 m_toggleBtnEdit->Connect(
155 wxEVT_COMMAND_TOGGLEBUTTON_CLICKED,
156 wxCommandEventHandler(TrackPropDlg::OnEditLinkToggle), NULL, this);
157 }
158
159 if (m_rbShowTimeUTC)
160 m_rbShowTimeUTC->Connect(wxEVT_COMMAND_RADIOBUTTON_SELECTED,
161 wxCommandEventHandler(TrackPropDlg::OnShowTimeTZ),
162 NULL, this);
163 if (m_rbShowTimePC)
164 m_rbShowTimePC->Connect(wxEVT_COMMAND_RADIOBUTTON_SELECTED,
165 wxCommandEventHandler(TrackPropDlg::OnShowTimeTZ),
166 NULL, this);
167 if (m_rbShowTimeLocal)
168 m_rbShowTimeLocal->Connect(
169 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
170 wxCommandEventHandler(TrackPropDlg::OnShowTimeTZ), NULL, this);
171
172 if (m_rbShowTimeGlobalSettings)
173 m_rbShowTimeGlobalSettings->Connect(
174 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
175 wxCommandEventHandler(TrackPropDlg::OnShowTimeTZ), NULL, this);
176
177 m_pMyLinkList = NULL;
178}
179
180TrackPropDlg::~TrackPropDlg() {
181 // Disconnect Events
182 m_sdbBtmBtnsSizerCancel->Disconnect(
183 wxEVT_COMMAND_BUTTON_CLICKED,
184 wxCommandEventHandler(TrackPropDlg::OnCancelBtnClick), NULL, this);
185 m_sdbBtmBtnsSizerOK->Disconnect(
186 wxEVT_COMMAND_BUTTON_CLICKED,
187 wxCommandEventHandler(TrackPropDlg::OnOKBtnClick), NULL, this);
188 if (m_sdbBtmBtnsSizerPrint)
189 m_sdbBtmBtnsSizerPrint->Disconnect(
190 wxEVT_COMMAND_BUTTON_CLICKED,
191 wxCommandEventHandler(TrackPropDlg::OnPrintBtnClick), NULL, this);
192 m_sdbBtmBtnsSizerSplit->Disconnect(
193 wxEVT_COMMAND_BUTTON_CLICKED,
194 wxCommandEventHandler(TrackPropDlg::OnSplitBtnClick), NULL, this);
195 m_sdbBtmBtnsSizerExtend->Disconnect(
196 wxEVT_COMMAND_BUTTON_CLICKED,
197 wxCommandEventHandler(TrackPropDlg::OnExtendBtnClick), NULL, this);
198 m_sdbBtmBtnsSizerToRoute->Disconnect(
199 wxEVT_COMMAND_BUTTON_CLICKED,
200 wxCommandEventHandler(TrackPropDlg::OnToRouteBtnClick), NULL, this);
201 if (m_sdbBtmBtnsSizerExport)
202 m_sdbBtmBtnsSizerExport->Disconnect(
203 wxEVT_COMMAND_BUTTON_CLICKED,
204 wxCommandEventHandler(TrackPropDlg::OnExportBtnClick), NULL, this);
205 m_lcPoints->Disconnect(wxEVT_COMMAND_LIST_ITEM_SELECTED,
206 wxListEventHandler(TrackPropDlg::OnTrackPropListClick),
207 NULL, this);
208 Disconnect(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
209 wxListEventHandler(TrackPropDlg::OnTrackPropRightClick), NULL,
210 this);
211 Disconnect(wxEVT_COMMAND_MENU_SELECTED,
212 wxCommandEventHandler(TrackPropDlg::OnTrackPropMenuSelected), NULL,
213 this);
214
215 Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
216 wxCommandEventHandler(TrackPropDlg::OnDeleteLink));
217 Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
218 wxCommandEventHandler(TrackPropDlg::OnEditLink));
219 Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
220 wxCommandEventHandler(TrackPropDlg::OnAddLink));
221
222 if (!m_bcompact) {
223 m_buttonAddLink->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED,
224 wxCommandEventHandler(TrackPropDlg::OnAddLink),
225 NULL, this);
226 m_toggleBtnEdit->Disconnect(
227 wxEVT_COMMAND_TOGGLEBUTTON_CLICKED,
228 wxCommandEventHandler(TrackPropDlg::OnEditLinkToggle), NULL, this);
229 }
230
231 if (m_rbShowTimeUTC)
232 m_rbShowTimeUTC->Disconnect(
233 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
234 wxCommandEventHandler(TrackPropDlg::OnShowTimeTZ), NULL, this);
235 if (m_rbShowTimePC)
236 m_rbShowTimePC->Disconnect(
237 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
238 wxCommandEventHandler(TrackPropDlg::OnShowTimeTZ), NULL, this);
240 m_rbShowTimeLocal->Disconnect(
241 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
242 wxCommandEventHandler(TrackPropDlg::OnShowTimeTZ), NULL, this);
244 m_rbShowTimeGlobalSettings->Disconnect(
245 wxEVT_COMMAND_RADIOBUTTON_SELECTED,
246 wxCommandEventHandler(TrackPropDlg::OnShowTimeTZ), NULL, this);
247
248 instanceFlag = false;
249}
250
251static wxString getDatetimeTimezoneSelector(int selection) {
252 switch (selection) {
253 case UTCINPUT:
254 return "UTC";
255 case LTINPUT:
256 return "Local Time";
257 case LMTINPUT:
258 return "LMT";
259 case GLOBAL_SETTINGS_INPUT:
260 default:
261 return wxEmptyString;
262 }
263}
264
265void TrackPropDlg::OnActivate(wxActivateEvent& event) {
266 auto pWin = dynamic_cast<DIALOG_PARENT*>(event.GetEventObject());
267 long int style = pWin->GetWindowStyle();
268 if (event.GetActive())
269 pWin->SetWindowStyle(style | wxSTAY_ON_TOP);
270 else
271 pWin->SetWindowStyle(style ^ wxSTAY_ON_TOP);
272}
273
274void TrackPropDlg::RecalculateSize(void) {
275 // Make an estimate of the dialog size, without scrollbars showing
276
277 wxSize esize;
278 esize.x = GetCharWidth() * 110;
279 esize.y = GetCharHeight() * 40;
280
281 wxSize dsize = GetParent()->GetClientSize();
282 esize.y = wxMin(esize.y, dsize.y - (2 * GetCharHeight()));
283 esize.x = wxMin(esize.x, dsize.x - (2 * GetCharHeight()));
284 SetClientSize(esize);
285
286 wxSize fsize = GetSize();
287 fsize.y = wxMin(fsize.y, dsize.y - (2 * GetCharHeight()));
288 fsize.x = wxMin(fsize.x, dsize.x - (2 * GetCharHeight()));
289 SetSize(fsize);
290
291 if (m_bcompact) {
292 int sy = GetCharHeight() * m_lcPoints->GetItemCount();
293 sy = wxMax(sy, 250);
294 sy = wxMin(sy, 500);
295 m_lcPoints->SetSize(wxSize(GetClientSize().x - 40, sy));
296
297 if (m_lcPoints->GetItemCount()) Layout();
298 }
299
300 Centre();
301}
302
303static void addColumns(wxListCtrl* lctrl, int dx) {
304 lctrl->InsertColumn(0, _("Leg"), wxLIST_FORMAT_LEFT, dx * 6);
305 lctrl->InsertColumn(1, _("Distance"), wxLIST_FORMAT_LEFT, dx * 11);
306 lctrl->InsertColumn(2, _("Bearing"), wxLIST_FORMAT_LEFT, dx * 8);
307 // Width of lat/lon may be up to 15 characters: 'DDD° MM.MMMM' W'.
308 lctrl->InsertColumn(3, _("Latitude"), wxLIST_FORMAT_LEFT, dx * 15);
309 lctrl->InsertColumn(4, _("Longitude"), wxLIST_FORMAT_LEFT, dx * 15);
310 // Width of timestamp may be be up to 26 characters: 'MM/DD/YYYY HH:MM:SS PM
311 // UTC'.
312 lctrl->InsertColumn(5, _("Timestamp"), wxLIST_FORMAT_LEFT, dx * 26);
313 lctrl->InsertColumn(6, _("Speed"), wxLIST_FORMAT_CENTER, dx * 8);
314
315 lctrl->SetMinSize(wxSize(-1, 50));
316}
317
318void TrackPropDlg::CreateControlsCompact() {
319 wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxVERTICAL);
320 SetSizer(itemBoxSizer1);
321
322 itemDialog1 = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition,
323 wxSize(-1, -1), wxVSCROLL);
324 itemDialog1->SetScrollRate(0, 1);
325
326#ifdef __ANDROID__
327 // Set Dialog Font by custom crafted Qt Stylesheet.
328 wxFont* qFont = GetOCPNScaledFont(_("Dialog"));
329
330 wxString wqs = getFontQtStylesheet(qFont);
331 wxCharBuffer sbuf = wqs.ToUTF8();
332 QString qsb = QString(sbuf.data());
333
334 QString qsbq = getQtStyleSheet(); // basic scrollbars, etc
335
336 itemDialog1->GetHandle()->setStyleSheet(qsb +
337 qsbq); // Concatenated style sheets
338
339#endif
340 itemBoxSizer1->Add(itemDialog1, 1, wxEXPAND | wxALL, 0);
341
342 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
343 itemDialog1->SetSizer(itemBoxSizer2);
344
345 wxStaticText* itemStaticText4 = new wxStaticText(
346 itemDialog1, wxID_STATIC, _("Name"), wxDefaultPosition, wxDefaultSize, 0);
347 itemBoxSizer2->Add(itemStaticText4, 0,
348 wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
349
350 m_tName = new wxTextCtrl(itemDialog1, wxID_ANY, _T(""), wxDefaultPosition,
351 wxSize(400, -1), 0);
352 itemBoxSizer2->Add(m_tName, 0, wxALIGN_LEFT | wxLEFT | wxRIGHT | wxBOTTOM, 5);
353
354 wxStaticText* itemStaticText7 =
355 new wxStaticText(itemDialog1, wxID_STATIC, _("Depart From"),
356 wxDefaultPosition, wxDefaultSize, 0);
357 itemBoxSizer2->Add(itemStaticText7, 0,
358 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT,
359 5);
360
361 m_tFrom = new wxTextCtrl(itemDialog1, wxID_ANY, _T(""), wxDefaultPosition,
362 wxSize(-1, -1), 0);
363 itemBoxSizer2->Add(m_tFrom, 0,
364 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
365 wxLEFT | wxRIGHT | wxBOTTOM,
366 5);
367
368 wxStaticText* itemStaticText8 =
369 new wxStaticText(itemDialog1, wxID_STATIC, _("Destination"),
370 wxDefaultPosition, wxDefaultSize, 0);
371 itemBoxSizer2->Add(itemStaticText8, 0,
372 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT,
373 5);
374
375 m_tTo = new wxTextCtrl(itemDialog1, wxID_ANY, _T(""), wxDefaultPosition,
376 wxSize(-1, -1), 0);
377 itemBoxSizer2->Add(m_tTo, 0,
378 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
379 wxLEFT | wxRIGHT | wxBOTTOM,
380 5);
381
382 m_cbShow = new wxCheckBox(itemDialog1, wxID_ANY, _("Show on chart"),
383 wxDefaultPosition, wxDefaultSize, 0);
384 itemBoxSizer2->Add(m_cbShow, 0, wxALL, 5);
385
386 wxFlexGridSizer* itemFlexGridSizer6a = new wxFlexGridSizer(4, 2, 0, 0);
387 itemFlexGridSizer6a->AddGrowableCol(1, 0);
388
389 itemBoxSizer2->Add(itemFlexGridSizer6a, 0, wxEXPAND | wxALIGN_LEFT | wxALL,
390 5);
391
392 wxStaticText* itemStaticText11 =
393 new wxStaticText(itemDialog1, wxID_STATIC, _("Total distance"),
394 wxDefaultPosition, wxDefaultSize, 0);
395 itemFlexGridSizer6a->Add(
396 itemStaticText11, 0,
397 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxTOP, 5);
398
399 m_tTotDistance =
400 new wxTextCtrl(itemDialog1, wxID_ANY, _T(""), wxDefaultPosition,
401 wxSize(-1, -1), wxTE_READONLY);
402 itemFlexGridSizer6a->Add(m_tTotDistance, 0,
403 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
404 wxLEFT | wxRIGHT | wxBOTTOM,
405 5);
406
407 m_stAvgSpeed = new wxStaticText(itemDialog1, wxID_STATIC, _("Avg. speed"),
408 wxDefaultPosition, wxDefaultSize, 0);
409 itemFlexGridSizer6a->Add(
410 m_stAvgSpeed, 0,
411 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxTOP, 5);
412
413 m_tAvgSpeed = new wxTextCtrl(itemDialog1, wxID_ANY, _T(""), wxDefaultPosition,
414 wxSize(150, -1), wxTE_PROCESS_ENTER);
415 itemFlexGridSizer6a->Add(
416 m_tAvgSpeed, 0,
417 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxBOTTOM, 5);
418
419 m_stTimeEnroute =
420 new wxStaticText(itemDialog1, wxID_STATIC, _("Time Enroute"),
421 wxDefaultPosition, wxDefaultSize, 0);
422 itemFlexGridSizer6a->Add(
423 m_stTimeEnroute, 0,
424 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxTOP, 5);
425
426 m_tTimeEnroute =
427 new wxTextCtrl(itemDialog1, wxID_ANY, _T(""), wxDefaultPosition,
428 wxSize(-1, -1), wxTE_READONLY);
429 itemFlexGridSizer6a->Add(m_tTimeEnroute, 0,
430 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
431 wxLEFT | wxRIGHT | wxBOTTOM,
432 5);
433
434 /*
435 m_StartTimeLabel = new wxStaticText( itemDialog1, wxID_STATIC,
436 _("Departure Time"), wxDefaultPosition, wxDefaultSize, 0 );
437 itemFlexGridSizer6a->Add( m_StartTimeLabel, 0,
438 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxTOP,
439 5 );
440
441 m_StartTimeCtl = new wxTextCtrl( itemDialog1, ID_STARTTIMECTL, _T(""),
442 wxDefaultPosition, wxSize( -1, -1 ), wxTE_PROCESS_ENTER );
443 itemFlexGridSizer6a->Add( m_StartTimeCtl, 0,
444 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT |
445 wxRIGHT | wxBOTTOM, 5 );
446 */
447
448 wxString pDispTimeZone[] = {_("UTC"), _("Local Time"), _("LMT@Location"),
449 _("Honor Global Settings")};
450
451 wxStaticText* itemStaticText12b =
452 new wxStaticText(itemDialog1, wxID_STATIC, _("Time shown as"),
453 wxDefaultPosition, wxDefaultSize, 0);
454 itemBoxSizer2->Add(itemStaticText12b, 0, wxEXPAND | wxALL, 5);
455
456 m_rbShowTimeUTC =
457 new wxRadioButton(itemDialog1, wxID_ANY, _("UTC"), wxDefaultPosition,
458 wxDefaultSize, wxRB_GROUP);
459 itemBoxSizer2->Add(
460 m_rbShowTimeUTC, 0,
461 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxBOTTOM, 5);
462
463 m_rbShowTimePC = new wxRadioButton(itemDialog1, wxID_ANY, _("Local Time"));
464 itemBoxSizer2->Add(
466 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxBOTTOM, 5);
467
469 new wxRadioButton(itemDialog1, wxID_ANY, _("LMT@Location"));
470 itemBoxSizer2->Add(
472 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxBOTTOM, 5);
473
475 new wxRadioButton(itemDialog1, wxID_ANY, _("Honor Global Settings"));
476 itemBoxSizer2->Add(
478 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxBOTTOM, 5);
479
480 wxFlexGridSizer* itemFlexGridSizer6b = new wxFlexGridSizer(3, 2, 0, 0);
481 itemBoxSizer2->Add(itemFlexGridSizer6b, 0, wxEXPAND | wxALIGN_LEFT | wxALL,
482 5);
483
484 wxStaticText* m_staticText1 =
485 new wxStaticText(itemDialog1, wxID_ANY, _("Color") + _T(":"),
486 wxDefaultPosition, wxDefaultSize, 0);
487 itemFlexGridSizer6b->Add(m_staticText1, 0, wxALIGN_CENTER_VERTICAL | wxALL,
488 5);
489
490 wxString m_chColorChoices[] = {
491 _("Default color"), _("Black"), _("Dark Red"), _("Dark Green"),
492 _("Dark Yellow"), _("Dark Blue"), _("Dark Magenta"), _("Dark Cyan"),
493 _("Light Gray"), _("Dark Gray"), _("Red"), _("Green"),
494 _("Yellow"), _("Blue"), _("Magenta"), _("Cyan"),
495 _("White")};
496 int m_chColorNChoices = sizeof(m_chColorChoices) / sizeof(wxString);
497 m_cColor =
498 new wxChoice(itemDialog1, wxID_ANY, wxDefaultPosition, wxSize(250, -1),
499 m_chColorNChoices, m_chColorChoices, 0);
500 m_cColor->SetSelection(0);
501 itemFlexGridSizer6b->Add(m_cColor, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
502
503 wxStaticText* staticTextStyle =
504 new wxStaticText(itemDialog1, wxID_ANY, _("Style") + _T(":"),
505 wxDefaultPosition, wxDefaultSize, 0);
506 itemFlexGridSizer6b->Add(staticTextStyle, 0, wxALIGN_CENTER_VERTICAL | wxALL,
507 5);
508
509 wxString m_chStyleChoices[] = {_("Default"), _("Solid"), _("Dot"),
510 _("Long dash"), _("Short dash")};
511 int m_chStyleNChoices = sizeof(m_chStyleChoices) / sizeof(wxString);
512 m_cStyle =
513 new wxChoice(itemDialog1, wxID_ANY, wxDefaultPosition, wxDefaultSize,
514 m_chStyleNChoices, m_chStyleChoices, 0);
515 m_cStyle->SetSelection(0);
516 itemFlexGridSizer6b->Add(m_cStyle, 0,
517 wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 5);
518
519#ifdef ocpnUSE_GLES // linestipple is emulated poorly
520 staticTextStyle->Hide();
521 m_cStyle->Hide();
522#endif
523
524 m_stWidth = new wxStaticText(itemDialog1, wxID_ANY, _("Width") + _T(":"),
525 wxDefaultPosition, wxDefaultSize, 0);
526 itemFlexGridSizer6b->Add(m_stWidth, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
527
528 wxString m_chWidthChoices[] = {_("Default"), _("1 pixel"), _("2 pixels"),
529 _("3 pixels"), _("4 pixels"), _("5 pixels"),
530 _("6 pixels"), _("7 pixels"), _("8 pixels"),
531 _("9 pixels"), _("10 pixels")};
532 int m_chWidthNChoices = sizeof(m_chWidthChoices) / sizeof(wxString);
533 m_cWidth =
534 new wxChoice(itemDialog1, wxID_ANY, wxDefaultPosition, wxSize(150, -1),
535 m_chWidthNChoices, m_chWidthChoices, 0);
536 m_cWidth->SetSelection(0);
537 itemFlexGridSizer6b->Add(m_cWidth, 0,
538 wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 5);
539
540 wxStaticBox* itemStaticBoxSizer14Static =
541 new wxStaticBox(itemDialog1, wxID_ANY, _("Waypoints"));
542 wxStaticBoxSizer* m_pListSizer =
543 new wxStaticBoxSizer(itemStaticBoxSizer14Static, wxVERTICAL);
544 itemBoxSizer2->Add(m_pListSizer, 1, wxEXPAND | wxALL, 1);
545
546 wxScrolledWindow* itemlistWin =
547 new wxScrolledWindow(itemDialog1, wxID_ANY, wxDefaultPosition,
548 wxDefaultSize, wxHSCROLL | wxVSCROLL);
549 itemlistWin->SetScrollRate(2, 2);
550
551 m_pListSizer->Add(itemlistWin, 0, wxEXPAND | wxALL, 6);
552
553 long flags = wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | wxLC_EDIT_LABELS;
554#ifndef __WXQT__ // Does not support Virtual list boxes....
555 flags |= wxLC_VIRTUAL;
556#endif
557
558 m_lcPoints = new OCPNTrackListCtrl(itemlistWin, wxID_ANY, wxDefaultPosition,
559 wxSize(100, 500), flags);
560 addColumns(m_lcPoints, GetCharWidth());
561
562 // sbSizerPoints->Add( m_lcPoints, 1, wxALL|wxEXPAND, 5 );
563
564#ifdef __ANDROID__
565 m_lcPoints->GetHandle()->setStyleSheet(getQtStyleSheet());
566#endif
567
568 // Buttons, etc...
569
570 wxBoxSizer* itemBoxSizerBottom = new wxBoxSizer(wxVERTICAL);
571 itemBoxSizer1->Add(itemBoxSizerBottom, 0, wxALIGN_LEFT | wxALL | wxEXPAND, 5);
572
573 int n_col = 3;
574
575 wxFlexGridSizer* itemBoxSizerAux = new wxFlexGridSizer(0, n_col, 0, 0);
576 itemBoxSizerAux->SetFlexibleDirection(wxBOTH);
577 itemBoxSizerAux->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
578
579 itemBoxSizerBottom->Add(itemBoxSizerAux, 1, wxALIGN_LEFT | wxALL, 5);
580
581#ifndef __ANDROID__
582
583 m_sdbBtmBtnsSizerPrint = new wxButton(this, wxID_ANY, _("Print"),
584 wxDefaultPosition, wxDefaultSize, 0);
585 itemBoxSizerAux->Add(m_sdbBtmBtnsSizerPrint, 0,
586 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5);
587 m_sdbBtmBtnsSizerPrint->Enable(true);
588#else
589 m_sdbBtmBtnsSizerPrint = NULL;
590#endif
591
592 m_sdbBtmBtnsSizerSplit = new wxButton(this, wxID_ANY, _("Split"),
593 wxDefaultPosition, wxDefaultSize, 0);
594 itemBoxSizerAux->Add(m_sdbBtmBtnsSizerSplit, 0,
595 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5);
596 m_sdbBtmBtnsSizerSplit->Enable(false);
597
598 m_sdbBtmBtnsSizerExtend = new wxButton(this, wxID_ANY, _("Extend"),
599 wxDefaultPosition, wxDefaultSize, 0);
600 itemBoxSizerAux->Add(m_sdbBtmBtnsSizerExtend, 0,
601 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5);
602
603 m_sdbBtmBtnsSizerToRoute = new wxButton(this, wxID_ANY, _("To route"),
604 wxDefaultPosition, wxDefaultSize, 0);
605 itemBoxSizerAux->Add(m_sdbBtmBtnsSizerToRoute, 0,
606 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5);
607
608 m_sdbBtmBtnsSizerExport = NULL;
609 // m_sdbBtmBtnsSizerExport = new wxButton( this, wxID_ANY, _("Export"),
610 // wxDefaultPosition, wxDefaultSize, 0 ); itemBoxSizerAux->Add(
611 // m_sdbBtmBtnsSizerExport, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
612 // wxALL, 5 );
613
614 wxBoxSizer* itemBoxSizer16 = new wxBoxSizer(wxHORIZONTAL);
615 itemBoxSizerBottom->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
616
617 m_sdbBtmBtnsSizerCancel = new wxButton(this, wxID_CANCEL, _("Cancel"),
618 wxDefaultPosition, wxDefaultSize, 0);
619 itemBoxSizer16->Add(m_sdbBtmBtnsSizerCancel, 0,
620 wxALIGN_RIGHT | wxALIGN_BOTTOM | wxALL, 5);
621
622 m_sdbBtmBtnsSizerOK =
623 new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0);
624 itemBoxSizer16->Add(m_sdbBtmBtnsSizerOK, 0,
625 wxALIGN_RIGHT | wxALIGN_BOTTOM | wxALL, 5);
626 m_sdbBtmBtnsSizerOK->SetDefault();
627
628 int char_size = GetCharWidth();
629 // Set the maximum size of the entire dialog
630 int width, height;
631 width = g_monitor_info[g_current_monitor].width;
632 height = g_monitor_info[g_current_monitor].height;
633 SetSizeHints(-1, -1, width - 100, height - 100);
634}
635
636void TrackPropDlg::CreateControls(void) {
637 wxBoxSizer* bSizerMain;
638 bSizerMain = new wxBoxSizer(wxVERTICAL);
639 SetSizer(bSizerMain);
640
641 m_notebook1 =
642 new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
643
644 bSizerMain->Add(m_notebook1, 1, wxEXPAND | wxALL, 5);
645
646 wxPanel* m_panel0 =
647 new wxPanel(m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize);
648 m_notebook1->AddPage(m_panel0, _("Basic"), true);
649
650 wxBoxSizer* bSizer0 = new wxBoxSizer(wxVERTICAL);
651 m_panel0->SetSizer(bSizer0);
652
653 wxBoxSizer* bSizer1 = new wxBoxSizer(wxVERTICAL);
654 bSizer0->Add(bSizer1, 1, wxEXPAND | wxALL, 5);
655
656 m_panelBasic = new wxScrolledWindow(m_panel0, wxID_ANY, wxDefaultPosition,
657 wxSize(-1, -1),
658 wxHSCROLL | wxVSCROLL | wxTAB_TRAVERSAL);
659
660#ifdef __ANDROID__
661 // Set Dialog Font by custom crafted Qt Stylesheet.
662 wxFont* qFont = GetOCPNScaledFont(_("Dialog"));
663
664 wxString wqs = getFontQtStylesheet(qFont);
665 wxCharBuffer sbuf = wqs.ToUTF8();
666 QString qsb = QString(sbuf.data());
667
668 QString qsbq = getQtStyleSheet(); // basic scrollbars, etc
669
670 m_panelBasic->GetHandle()->setStyleSheet(qsb +
671 qsbq); // Concatenated style sheets
672
673#endif
674
675 // #ifdef __ANDROID__
676 // m_panelBasic->GetHandle()->setStyleSheet( getQtStyleSheet());
677 // #endif
678
679 wxBoxSizer* bSizerBasic = new wxBoxSizer(wxVERTICAL);
680 m_panelBasic->SetSizer(bSizerBasic);
681
682 bSizer1->Add(m_panelBasic, 1, wxEXPAND | wxALL, 5);
683
684 wxBoxSizer* bSizerName;
685 bSizerName = new wxBoxSizer(wxHORIZONTAL);
686 bSizerBasic->Add(bSizerName, 0, wxALL | wxEXPAND, 5);
687
688 m_stName = new wxStaticText(m_panelBasic, wxID_ANY, _("Name"),
689 wxDefaultPosition, wxDefaultSize, 0);
690 // m_stName->Wrap( -1 );
691 bSizerName->Add(m_stName, 0, wxALL, 5);
692
693 m_tName = new wxTextCtrl(m_panelBasic, wxID_ANY, wxEmptyString,
694 wxDefaultPosition, wxDefaultSize, 0);
695 bSizerName->Add(m_tName, 1, 0, 5);
696
697 wxBoxSizer* bSizerFromTo;
698 bSizerFromTo = new wxBoxSizer(wxHORIZONTAL);
699 bSizerBasic->Add(bSizerFromTo, 0, wxALL | wxEXPAND, 5);
700
701 m_stFrom = new wxStaticText(m_panelBasic, wxID_ANY, _("From"),
702 wxDefaultPosition, wxDefaultSize, 0);
703 // m_stFrom->Wrap( -1 );
704 bSizerFromTo->Add(m_stFrom, 0, wxALL, 5);
705
706 m_tFrom = new wxTextCtrl(m_panelBasic, wxID_ANY, wxEmptyString,
707 wxDefaultPosition, wxDefaultSize, 0);
708 bSizerFromTo->Add(m_tFrom, 1, 0, 5);
709
710 m_stTo = new wxStaticText(m_panelBasic, wxID_ANY, _("To"), wxDefaultPosition,
711 wxDefaultSize, 0);
712 // m_stTo->Wrap( -1 );
713 bSizerFromTo->Add(m_stTo, 0, wxALL, 5);
714
715 m_tTo = new wxTextCtrl(m_panelBasic, wxID_ANY, wxEmptyString,
716 wxDefaultPosition, wxDefaultSize, 0);
717 bSizerFromTo->Add(m_tTo, 1, 0, 5);
718
719 wxStaticBoxSizer* sbSizerParams;
720 sbSizerParams = new wxStaticBoxSizer(
721 new wxStaticBox(m_panelBasic, wxID_ANY, _("Display parameters")),
722 wxHORIZONTAL);
723 bSizerBasic->Add(sbSizerParams, 0, wxALL | wxEXPAND, 5);
724
725 m_cbShow = new wxCheckBox(m_panelBasic, wxID_ANY, _("Show on chart"),
726 wxDefaultPosition, wxDefaultSize, 0);
727 sbSizerParams->Add(m_cbShow, 0, wxALL, 5);
728
729 m_stColor = new wxStaticText(m_panelBasic, wxID_ANY, _("Color"),
730 wxDefaultPosition, wxDefaultSize, 0);
731 // m_stColor->Wrap( -1 );
732 sbSizerParams->Add(m_stColor, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
733
734 wxString m_cColorChoices[] = {
735 _("Default color"), _("Black"), _("Dark Red"), _("Dark Green"),
736 _("Dark Yellow"), _("Dark Blue"), _("Dark Magenta"), _("Dark Cyan"),
737 _("Light Gray"), _("Dark Gray"), _("Red"), _("Green"),
738 _("Yellow"), _("Blue"), _("Magenta"), _("Cyan"),
739 _("White")};
740 int m_cColorNChoices = sizeof(m_cColorChoices) / sizeof(wxString);
741 m_cColor = new wxChoice(m_panelBasic, wxID_ANY, wxDefaultPosition,
742 wxDefaultSize, m_cColorNChoices, m_cColorChoices, 0);
743 m_cColor->SetSelection(0);
744 sbSizerParams->Add(m_cColor, 1, 0, 5);
745
746 m_stStyle = new wxStaticText(m_panelBasic, wxID_ANY, _("Style"),
747 wxDefaultPosition, wxDefaultSize, 0);
748 // m_stStyle->Wrap( -1 );
749 sbSizerParams->Add(m_stStyle, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
750
751 wxString m_cStyleChoices[] = {_("Default"), _("Solid"), _("Dot"),
752 _("Long dash"), _("Short dash")};
753 int m_cStyleNChoices = sizeof(m_cStyleChoices) / sizeof(wxString);
754 m_cStyle = new wxChoice(m_panelBasic, wxID_ANY, wxDefaultPosition,
755 wxDefaultSize, m_cStyleNChoices, m_cStyleChoices, 0);
756 m_cStyle->SetSelection(0);
757 sbSizerParams->Add(m_cStyle, 1, 0, 5);
758
759 m_stWidth = new wxStaticText(m_panelBasic, wxID_ANY, _("Width"),
760 wxDefaultPosition, wxDefaultSize, 0);
761 // m_stWidth->Wrap( -1 );
762 sbSizerParams->Add(m_stWidth, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
763
764 wxString m_cWidthChoices[] = {_("Default"), _("1 pixel"), _("2 pixels"),
765 _("3 pixels"), _("4 pixels"), _("5 pixels"),
766 _("6 pixels"), _("7 pixels"), _("8 pixels"),
767 _("9 pixels"), _("10 pixels")};
768 int m_cWidthNChoices = sizeof(m_cWidthChoices) / sizeof(wxString);
769 m_cWidth = new wxChoice(m_panelBasic, wxID_ANY, wxDefaultPosition,
770 wxDefaultSize, m_cWidthNChoices, m_cWidthChoices, 0);
771 m_cWidth->SetSelection(0);
772 sbSizerParams->Add(m_cWidth, 1, 0, 5);
773
774 wxStaticBoxSizer* sbSizerStats;
775 sbSizerStats = new wxStaticBoxSizer(
776 new wxStaticBox(m_panelBasic, wxID_ANY, _("Statistics")), wxVERTICAL);
777 bSizerBasic->Add(sbSizerStats, 0, wxALL | wxEXPAND, 5);
778
779 wxBoxSizer* bSizerStats;
780 bSizerStats = new wxBoxSizer(wxHORIZONTAL);
781
782 m_stTotDistance =
783 new wxStaticText(m_panelBasic, wxID_ANY, _("Total distance"),
784 wxDefaultPosition, wxDefaultSize, 0);
785 // m_stTotDistance->Wrap( -1 );
786 bSizerStats->Add(m_stTotDistance, 0, wxALL, 5);
787
788 m_tTotDistance =
789 new wxTextCtrl(m_panelBasic, wxID_ANY, wxEmptyString, wxDefaultPosition,
790 wxDefaultSize, wxTE_READONLY);
791 bSizerStats->Add(m_tTotDistance, 1, 0, 5);
792
793 m_stAvgSpeed = new wxStaticText(m_panelBasic, wxID_ANY, _("Avg. speed"),
794 wxDefaultPosition, wxDefaultSize, 0);
795 // m_stAvgSpeed->Wrap( -1 );
796 bSizerStats->Add(m_stAvgSpeed, 0, wxALL, 5);
797
798 m_tAvgSpeed = new wxTextCtrl(m_panelBasic, wxID_ANY, wxEmptyString,
799 wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
800 bSizerStats->Add(m_tAvgSpeed, 1, 0, 5);
801
802 m_stTimeEnroute = new wxStaticText(m_panelBasic, wxID_ANY, _("Time enroute"),
803 wxDefaultPosition, wxDefaultSize, 0);
804 // m_stTimeEnroute->Wrap( -1 );
805 bSizerStats->Add(m_stTimeEnroute, 0, wxALL, 5);
806
807 m_tTimeEnroute =
808 new wxTextCtrl(m_panelBasic, wxID_ANY, wxEmptyString, wxDefaultPosition,
809 wxDefaultSize, wxTE_READONLY);
810 bSizerStats->Add(m_tTimeEnroute, 2, 0, 5);
811
812 sbSizerStats->Add(bSizerStats, 0, wxEXPAND, 5);
813
814 wxStaticBoxSizer* sbSizerPoints;
815 sbSizerPoints = new wxStaticBoxSizer(
816 new wxStaticBox(m_panel0, wxID_ANY, _("Recorded points")), wxVERTICAL);
817 bSizer1->Add(sbSizerPoints, 1, wxALL | wxEXPAND, 5);
818
819 wxBoxSizer* bSizerShowTime;
820 bSizerShowTime = new wxBoxSizer(wxHORIZONTAL);
821
822 m_stShowTime = new wxStaticText(m_panel0, wxID_ANY, _("Time shown as"),
823 wxDefaultPosition, wxDefaultSize, 0);
824 // m_stShowTime->Wrap( -1 );
825 bSizerShowTime->Add(m_stShowTime, 0, wxALL, 5);
826
827 m_rbShowTimeUTC = new wxRadioButton(m_panel0, wxID_ANY, _("UTC"),
828 wxDefaultPosition, wxDefaultSize, 0);
829 bSizerShowTime->Add(m_rbShowTimeUTC, 0,
830 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT,
831 5);
832
833 m_rbShowTimePC = new wxRadioButton(m_panel0, wxID_ANY, _("Local Time"),
834 wxDefaultPosition, wxDefaultSize, 0);
835 bSizerShowTime->Add(m_rbShowTimePC, 0,
836 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT,
837 5);
838
840 new wxRadioButton(m_panel0, wxID_ANY, _("LMT@Track Start"),
841 wxDefaultPosition, wxDefaultSize, 0);
842 bSizerShowTime->Add(m_rbShowTimeLocal, 0,
843 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT,
844 5);
845
847 new wxRadioButton(m_panel0, wxID_ANY, _("Honor Global Settings"),
848 wxDefaultPosition, wxDefaultSize, 0);
849 bSizerShowTime->Add(m_rbShowTimeGlobalSettings, 0,
850 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT,
851 5);
852
853 m_rbShowTimeGlobalSettings->SetValue(true);
854
855 sbSizerPoints->Add(bSizerShowTime, 0, wxEXPAND, 5);
856
857 long flags = wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | wxLC_EDIT_LABELS;
858#ifndef __WXQT__ // Does not support Virtual list boxes....
859 flags |= wxLC_VIRTUAL;
860#endif
861
862 m_lcPoints = new OCPNTrackListCtrl(m_panel0, wxID_ANY, wxDefaultPosition,
863 wxDefaultSize, flags);
864 addColumns(m_lcPoints, GetCharWidth());
865
866 sbSizerPoints->Add(m_lcPoints, 1, wxALL | wxEXPAND, 5);
867
868#ifdef __ANDROID__
869 m_lcPoints->GetHandle()->setStyleSheet(getQtStyleSheet());
870#endif
871
872 // m_lcPoints = new OCPNTrackListCtrl( m_panel0, wxID_ANY,
873 // wxDefaultPosition, wxDefaultSize,
874 // wxLC_REPORT | wxLC_HRULES |
875 // wxLC_VRULES | wxLC_EDIT_LABELS |
876 // wxLC_VIRTUAL );
877 //
878 // m_lcPoints->Hide();
879 // m_rbShowTimeUTC = NULL;
880 // m_rbShowTimePC = NULL;
881 // m_rbShowTimeLocal = NULL;
882
883 m_panelAdvanced = new wxScrolledWindow(
884 m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
885
886 wxBoxSizer* bSizerAdvanced;
887 bSizerAdvanced = new wxBoxSizer(wxVERTICAL);
888
889 m_stDescription =
890 new wxStaticText(m_panelAdvanced, wxID_ANY, _("Description"),
891 wxDefaultPosition, wxDefaultSize, 0);
892 // m_stDescription->Wrap( -1 );
893 bSizerAdvanced->Add(m_stDescription, 0, wxALL, 5);
894
895 m_tDescription =
896 new wxTextCtrl(m_panelAdvanced, wxID_ANY, wxEmptyString,
897 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
898 bSizerAdvanced->Add(m_tDescription, 1, wxALL | wxEXPAND, 5);
899
900 sbSizerLinks = new wxStaticBoxSizer(
901 new wxStaticBox(m_panelAdvanced, wxID_ANY, _("Links")), wxVERTICAL);
902
903 m_scrolledWindowLinks =
904 new wxScrolledWindow(m_panelAdvanced, wxID_ANY, wxDefaultPosition,
905 wxDefaultSize, wxHSCROLL | wxVSCROLL);
906 m_scrolledWindowLinks->SetScrollRate(5, 5);
907 bSizerLinks = new wxBoxSizer(wxVERTICAL);
908
909 m_hyperlink1 =
910 new wxHyperlinkCtrl(m_scrolledWindowLinks, wxID_ANY, _("wxFB Website"),
911 wxT("http://www.wxformbuilder.org"),
912 wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
913 m_menuLink = new wxMenu();
914 m_menuItemEdit =
915 new wxMenuItem(m_menuLink, ID_TRK_MENU_EDIT, wxString(_("Edit")),
916 wxEmptyString, wxITEM_NORMAL);
917 m_menuLink->Append(m_menuItemEdit);
918
919 m_menuItemAdd =
920 new wxMenuItem(m_menuLink, ID_TRK_MENU_ADD, wxString(_("Add new")),
921 wxEmptyString, wxITEM_NORMAL);
922 m_menuLink->Append(m_menuItemAdd);
923
924 m_menuItemDelete =
925 new wxMenuItem(m_menuLink, ID_TRK_MENU_DELETE, wxString(_("Delete")),
926 wxEmptyString, wxITEM_NORMAL);
927 m_menuLink->Append(m_menuItemDelete);
928
929 m_hyperlink1->Connect(
930 wxEVT_RIGHT_DOWN,
931 wxMouseEventHandler(TrackPropDlg::m_hyperlink1OnContextMenu), NULL, this);
932
933 bSizerLinks->Add(m_hyperlink1, 0, wxALL, 5);
934
935 m_scrolledWindowLinks->SetSizer(bSizerLinks);
936 m_scrolledWindowLinks->Layout();
937 bSizerLinks->Fit(m_scrolledWindowLinks);
938 sbSizerLinks->Add(m_scrolledWindowLinks, 1, wxEXPAND | wxALL, 5);
939
940 wxBoxSizer* bSizerLinkBtns;
941 bSizerLinkBtns = new wxBoxSizer(wxHORIZONTAL);
942
943 m_buttonAddLink =
944 new wxButton(m_panelAdvanced, wxID_ANY, _("Add"), wxDefaultPosition,
945 wxDefaultSize, wxBU_EXACTFIT);
946 bSizerLinkBtns->Add(m_buttonAddLink, 0, wxALL, 5);
947
948 m_toggleBtnEdit = new wxToggleButton(m_panelAdvanced, wxID_ANY, _("Edit"),
949 wxDefaultPosition, wxDefaultSize, 0);
950 bSizerLinkBtns->Add(m_toggleBtnEdit, 0, wxALL, 5);
951
952 m_staticTextEditEnabled = new wxStaticText(
953 m_panelAdvanced, wxID_ANY, _("Links are opened in the default browser."),
954 wxDefaultPosition, wxDefaultSize, 0);
955 // m_staticTextEditEnabled->Wrap( -1 );
956 bSizerLinkBtns->Add(m_staticTextEditEnabled, 0,
957 wxALIGN_CENTER_VERTICAL | wxALL, 5);
958
959 sbSizerLinks->Add(bSizerLinkBtns, 0, wxEXPAND, 5);
960
961 bSizerAdvanced->Add(sbSizerLinks, 1, wxEXPAND, 5);
962
963 m_panelAdvanced->SetSizer(bSizerAdvanced);
964 m_notebook1->AddPage(m_panelAdvanced, _("Advanced"), false);
965
966 // Buttons, etc...
967
968 wxBoxSizer* itemBoxSizerBottom = new wxBoxSizer(wxVERTICAL);
969 bSizerMain->Add(itemBoxSizerBottom, 0, wxALIGN_LEFT | wxALL | wxEXPAND, 5);
970
971 // wxBoxSizer* itemBoxSizerAux = new wxBoxSizer( wxHORIZONTAL );
972
973 int n_col = 5;
974
975 wxFlexGridSizer* itemBoxSizerAux = new wxFlexGridSizer(0, n_col, 0, 0);
976 itemBoxSizerAux->SetFlexibleDirection(wxBOTH);
977 itemBoxSizerAux->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
978
979 itemBoxSizerBottom->Add(itemBoxSizerAux, 1, wxALIGN_LEFT | wxALL, 5);
980
981#ifndef __ANDROID__
982
983 m_sdbBtmBtnsSizerPrint = new wxButton(this, wxID_ANY, _("Print"),
984 wxDefaultPosition, wxDefaultSize, 0);
985 itemBoxSizerAux->Add(m_sdbBtmBtnsSizerPrint, 0,
986 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5);
987 m_sdbBtmBtnsSizerPrint->Enable(true);
988#else
989 m_sdbBtmBtnsSizerPrint = NULL;
990#endif
991
992 m_sdbBtmBtnsSizerSplit = new wxButton(this, wxID_ANY, _("Split"),
993 wxDefaultPosition, wxDefaultSize, 0);
994 itemBoxSizerAux->Add(m_sdbBtmBtnsSizerSplit, 0,
995 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5);
996 m_sdbBtmBtnsSizerSplit->Enable(false);
997
998 m_sdbBtmBtnsSizerExtend = new wxButton(this, wxID_ANY, _("Extend track"),
999 wxDefaultPosition, wxDefaultSize, 0);
1000 itemBoxSizerAux->Add(m_sdbBtmBtnsSizerExtend, 0,
1001 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5);
1002
1003 m_sdbBtmBtnsSizerToRoute = new wxButton(this, wxID_ANY, _("To route"),
1004 wxDefaultPosition, wxDefaultSize, 0);
1005 itemBoxSizerAux->Add(m_sdbBtmBtnsSizerToRoute, 0,
1006 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5);
1007
1008 m_sdbBtmBtnsSizerExport = new wxButton(this, wxID_ANY, _("Export"),
1009 wxDefaultPosition, wxDefaultSize, 0);
1010 itemBoxSizerAux->Add(m_sdbBtmBtnsSizerExport, 0,
1011 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5);
1012
1013 wxBoxSizer* itemBoxSizer16 = new wxBoxSizer(wxHORIZONTAL);
1014 itemBoxSizerBottom->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
1015
1016 m_sdbBtmBtnsSizerCancel = new wxButton(this, wxID_CANCEL, _("Cancel"),
1017 wxDefaultPosition, wxDefaultSize, 0);
1018 itemBoxSizer16->Add(m_sdbBtmBtnsSizerCancel, 0, wxALIGN_BOTTOM | wxALL, 5);
1019
1020 m_sdbBtmBtnsSizerOK =
1021 new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0);
1022 itemBoxSizer16->Add(m_sdbBtmBtnsSizerOK, 0, wxALIGN_BOTTOM | wxALL, 5);
1023 m_sdbBtmBtnsSizerOK->SetDefault();
1024
1025 // Make it look nice and add the needed non-standard buttons
1026 int w1, w2, h;
1027 ((wxWindowBase*)m_stName)->GetSize(&w1, &h);
1028 ((wxWindowBase*)m_stFrom)->GetSize(&w2, &h);
1029 ((wxWindowBase*)m_stName)->SetMinSize(wxSize(wxMax(w1, w2), h));
1030 ((wxWindowBase*)m_stFrom)->SetMinSize(wxSize(wxMax(w1, w2), h));
1031
1032 m_panelBasic->SetScrollRate(5, 5);
1033 m_panelAdvanced->SetScrollRate(5, 5);
1034}
1035
1036void TrackPropDlg::SetTrackAndUpdate(Track* pt) {
1037 m_pTrack = pt;
1038
1039 m_lcPoints->DeleteAllItems();
1040
1041 if (m_pMyLinkList) delete m_pMyLinkList;
1042 m_pMyLinkList = new HyperlinkList();
1043
1044 int NbrOfLinks = m_pTrack->m_HyperlinkList->GetCount();
1045 if (NbrOfLinks > 0) {
1046 wxHyperlinkListNode* linknode = m_pTrack->m_HyperlinkList->GetFirst();
1047 while (linknode) {
1048 Hyperlink* link = linknode->GetData();
1049
1050 Hyperlink* h = new Hyperlink();
1051 h->DescrText = link->DescrText;
1052 h->Link = link->Link;
1053 h->LType = link->LType;
1054
1055 m_pMyLinkList->Append(h);
1056
1057 linknode = linknode->GetNext();
1058 }
1059 }
1060
1061 InitializeList();
1063
1064 RecalculateSize();
1065}
1066
1067void TrackPropDlg::InitializeList() {
1068 if (NULL == m_pTrack) return;
1069
1070 m_lcPoints->m_pTrack = m_pTrack;
1071
1072 if (m_pTrack->GetnPoints()) {
1073 TrackPoint* prp = m_pTrack->GetPoint(0);
1074 if (prp)
1075 m_lcPoints->m_LMT_Offset = long((prp->m_lon) * 3600. / 15.); // estimated
1076 else
1077 m_lcPoints->m_LMT_Offset = 0;
1078 }
1079
1080 if (m_lcPoints->IsVirtual())
1081 m_lcPoints->SetItemCount(m_pTrack->GetnPoints());
1082
1083 else {
1084 for (int in = 0; in < m_pTrack->GetnPoints(); in++) {
1085 wxListItem item;
1086 item.SetId(in);
1087
1088 m_lcPoints->InsertItem(item);
1089 for (int j = 0; j < 7; j++) {
1090 item.SetColumn(j);
1091 item.SetText(m_lcPoints->OnGetItemText(in, j));
1092 m_lcPoints->SetItem(item);
1093 }
1094 }
1095 }
1096}
1097
1099 if (NULL == m_pTrack) return false;
1100
1101 ::wxBeginBusyCursor();
1102
1103 if (m_scrolledWindowLinks) {
1104 wxWindowList kids = m_scrolledWindowLinks->GetChildren();
1105 for (unsigned int i = 0; i < kids.GetCount(); i++) {
1106 wxWindowListNode* node = kids.Item(i);
1107 wxWindow* win = node->GetData();
1108
1109 auto link_win = dynamic_cast<wxHyperlinkCtrl*>(win);
1110 if (link_win) {
1111 link_win->Disconnect(
1112 wxEVT_COMMAND_HYPERLINK,
1113 wxHyperlinkEventHandler(TrackPropDlg::OnHyperLinkClick));
1114 link_win->Disconnect(
1115 wxEVT_RIGHT_DOWN,
1116 wxMouseEventHandler(TrackPropDlg::m_hyperlinkContextMenu));
1117 win->Destroy();
1118 }
1119 }
1121 int NbrOfLinks = m_pTrack->m_HyperlinkList->GetCount();
1122 HyperlinkList* hyperlinklist = m_pTrack->m_HyperlinkList;
1123 // int len = 0;
1124 if (NbrOfLinks > 0) {
1125 wxHyperlinkListNode* linknode = hyperlinklist->GetFirst();
1126 while (linknode) {
1127 Hyperlink* link = linknode->GetData();
1128 wxString Link = link->Link;
1129 wxString Descr = link->DescrText;
1130
1131 wxHyperlinkCtrl* ctrl = new wxHyperlinkCtrl(
1132 m_scrolledWindowLinks, wxID_ANY, Descr, Link, wxDefaultPosition,
1133 wxDefaultSize, wxHL_DEFAULT_STYLE);
1134 ctrl->Connect(wxEVT_COMMAND_HYPERLINK,
1135 wxHyperlinkEventHandler(TrackPropDlg::OnHyperLinkClick),
1136 NULL, this);
1137 if (!m_pTrack->m_bIsInLayer)
1138 ctrl->Connect(
1139 wxEVT_RIGHT_DOWN,
1140 wxMouseEventHandler(TrackPropDlg::m_hyperlinkContextMenu), NULL,
1141 this);
1142
1143 bSizerLinks->Add(ctrl, 0, wxALL, 5);
1144
1145 linknode = linknode->GetNext();
1146 }
1147 }
1148 bSizerLinks->Fit(m_scrolledWindowLinks);
1149 }
1150
1151 m_tName->SetValue(m_pTrack->GetName());
1152 m_tFrom->SetValue(m_pTrack->m_TrackStartString);
1153 m_tTo->SetValue(m_pTrack->m_TrackEndString);
1154 if (m_tDescription) m_tDescription->SetValue(m_pTrack->m_TrackDescription);
1155
1156 m_tTotDistance->SetValue(_T(""));
1157 m_tTimeEnroute->SetValue(_T(""));
1158
1159 m_sdbBtmBtnsSizerSplit->Enable(false);
1160 m_sdbBtmBtnsSizerExtend->Enable(false);
1161
1162 // Calculate AVG speed if we are showing a track and total time
1163 TrackPoint* last_point = m_pTrack->GetLastPoint();
1164 TrackPoint* first_point = m_pTrack->GetPoint(0);
1165 double trackLength = m_pTrack->Length();
1166 double total_seconds = 0.;
1167
1168 wxString speed(_T("--"));
1169
1170 if (last_point && first_point) {
1171 if (last_point->GetCreateTime().IsValid() &&
1172 first_point->GetCreateTime().IsValid()) {
1173 total_seconds = last_point->GetCreateTime()
1174 .Subtract(first_point->GetCreateTime())
1175 .GetSeconds()
1176 .ToDouble();
1177 if (total_seconds != 0.) {
1178 m_avgspeed = trackLength / total_seconds * 3600;
1179 } else {
1180 m_avgspeed = 0;
1181 }
1182 speed.Printf(_T("%5.2f"), toUsrSpeed(m_avgspeed));
1183 }
1184 }
1185
1186 m_tAvgSpeed->SetValue(speed);
1187
1188 // Total length
1189 wxString slen;
1190 slen.Printf(wxT("%5.2f ") + getUsrDistanceUnit(), toUsrDistance(trackLength));
1191
1192 m_tTotDistance->SetValue(slen);
1193
1194 // Time
1195 wxString time_form;
1196 wxTimeSpan time(0, 0, (int)total_seconds, 0);
1197 // TODO Construct a readable time string, e.g. "xx Days, 15:34"
1198 if (total_seconds > 3600. * 24.)
1199 time_form = time.Format("%H:%M");
1200 else if (total_seconds > 0.)
1201 time_form = time.Format("%H:%M");
1202 else
1203 time_form = _T("--");
1204 m_tTimeEnroute->SetValue(time_form);
1205
1206 m_cbShow->SetValue(m_pTrack->IsVisible());
1207
1208 if (m_pTrack->m_Colour == wxEmptyString)
1209 m_cColor->Select(0);
1210 else {
1211 for (unsigned int i = 0; i < sizeof(::GpxxColorNames) / sizeof(wxString);
1212 i++) {
1213 if (m_pTrack->m_Colour == ::GpxxColorNames[i]) {
1214 m_cColor->Select(i + 1);
1215 break;
1216 }
1217 }
1218 }
1219
1220 for (unsigned int i = 0; i < sizeof(::StyleValues) / sizeof(int); i++) {
1221 if (m_pTrack->m_style == ::StyleValues[i]) {
1222 m_cStyle->Select(i);
1223 break;
1224 }
1225 }
1226
1227 for (unsigned int i = 0; i < sizeof(::WidthValues) / sizeof(int); i++) {
1228 if (m_pTrack->m_width == ::WidthValues[i]) {
1229 m_cWidth->Select(i);
1230 break;
1231 }
1232 }
1233
1234 if (m_pTrack->m_bIsInLayer) {
1235 m_tName->SetEditable(false);
1236 m_tFrom->SetEditable(false);
1237 m_tTo->SetEditable(false);
1238 if (m_tDescription) m_tDescription->SetEditable(false);
1239 m_cbShow->Enable(false);
1240 m_cColor->Enable(false);
1241 m_cStyle->Enable(false);
1242 m_cWidth->Enable(false);
1243 m_sdbBtmBtnsSizerExtend->Enable(false);
1244 m_sdbBtmBtnsSizerSplit->Enable(false);
1245 SetTitle(wxString::Format(_T("%s, %s: %d"), _("Track properties"),
1246 _T("Layer"), m_pTrack->m_LayerID));
1247 } else {
1248 m_tName->SetEditable(true);
1249 m_tFrom->SetEditable(true);
1250 m_tTo->SetEditable(true);
1251 if (m_tDescription) m_tDescription->SetEditable(true);
1252 m_cbShow->Enable(true);
1253 m_cColor->Enable(true);
1254 m_cStyle->Enable(true);
1255 m_cWidth->Enable(true);
1256
1257 m_sdbBtmBtnsSizerExtend->Enable(IsThisTrackExtendable());
1258 // m_sdbBtmBtnsSizerSplit->Enable( false );
1259 SetTitle(_("Track properties"));
1260 }
1261
1262 ::wxEndBusyCursor();
1263
1264 return true;
1265}
1266
1267bool TrackPropDlg::IsThisTrackExtendable() {
1268 m_pExtendTrack = NULL;
1269 m_pExtendPoint = NULL;
1270 if (m_pTrack == g_pActiveTrack || m_pTrack->m_bIsInLayer) {
1271 return false;
1272 }
1273
1274 TrackPoint* pLastPoint = m_pTrack->GetPoint(0);
1275 if (!pLastPoint->GetCreateTime().IsValid()) {
1276 return false;
1277 }
1278
1279 for (Track* ptrack : g_TrackList) {
1280 if (ptrack->IsVisible() && (ptrack->m_GUID != m_pTrack->m_GUID)) {
1281 TrackPoint* track_node = ptrack->GetLastPoint();
1282 if (track_node) {
1283 if (track_node->GetCreateTime().IsValid()) {
1284 if (track_node->GetCreateTime() <= pLastPoint->GetCreateTime()) {
1285 if (!m_pExtendPoint ||
1286 track_node->GetCreateTime() > m_pExtendPoint->GetCreateTime()) {
1287 m_pExtendPoint = track_node;
1288 m_pExtendTrack = ptrack;
1289 }
1290 }
1291 }
1292 }
1293 }
1294 }
1295 if (m_pExtendTrack) {
1296 return (!m_pExtendTrack->m_bIsInLayer);
1297 } else {
1298 return false;
1299 }
1300}
1301
1302void TrackPropDlg::OnExtendBtnClick(wxCommandEvent& event) {
1303 TrackPoint* pFirstPoint = m_pTrack->GetPoint(0);
1304
1305 if (IsThisTrackExtendable()) {
1306 int begin = 0;
1307 if (pFirstPoint->GetCreateTime() == m_pExtendPoint->GetCreateTime()) {
1308 begin = 1;
1309 }
1310 pSelect->DeleteAllSelectableTrackSegments(m_pExtendTrack);
1311 m_pExtendTrack->Clone(m_pTrack, begin, m_pTrack->GetnPoints(), _("_plus"));
1312 pSelect->AddAllSelectableTrackSegments(m_pExtendTrack);
1313 pSelect->DeleteAllSelectableTrackSegments(m_pTrack);
1314 RoutemanGui(*g_pRouteMan).DeleteTrack(m_pTrack);
1315
1316 SetTrackAndUpdate(m_pExtendTrack);
1318
1319 if (pRouteManagerDialog && pRouteManagerDialog->IsShown()) {
1320 pRouteManagerDialog->UpdateTrkListCtrl();
1321 }
1322 }
1323}
1324
1325void TrackPropDlg::OnSplitBtnClick(wxCommandEvent& event) {
1326 m_sdbBtmBtnsSizerSplit->Enable(false);
1327
1328 if (m_pTrack->m_bIsInLayer) {
1329 return;
1330 }
1331
1332 if ((m_nSelected > 1) && (m_nSelected < m_pTrack->GetnPoints())) {
1333 Track* pHead = new Track();
1334 Track* pTail = new Track();
1335 pHead->Clone(m_pTrack, 0, m_nSelected - 1, _("_A"));
1336 pTail->Clone(m_pTrack, m_nSelected - 1, m_pTrack->GetnPoints(), _("_B"));
1337 g_TrackList.push_back(pHead);
1338 pConfig->AddNewTrack(pHead);
1339
1340 g_TrackList.push_back(pTail);
1341 pConfig->AddNewTrack(pTail);
1342
1343 pConfig->DeleteConfigTrack(m_pTrack);
1344
1345 pSelect->DeleteAllSelectableTrackSegments(m_pTrack);
1346 RoutemanGui(*g_pRouteMan).DeleteTrack(m_pTrack);
1347 pSelect->AddAllSelectableTrackSegments(pTail);
1348 pSelect->AddAllSelectableTrackSegments(pHead);
1349
1350 SetTrackAndUpdate(pTail);
1352
1353 if (pRouteManagerDialog && pRouteManagerDialog->IsShown()) {
1354 pRouteManagerDialog->UpdateTrkListCtrl();
1355 }
1356 }
1357}
1358
1359void TrackPropDlg::OnTrackPropCopyTxtClick(wxCommandEvent& event) {
1360 wxString tab("\t", wxConvUTF8);
1361 wxString eol("\n", wxConvUTF8);
1362 wxString csvString;
1363
1364 csvString << this->GetTitle() << eol << _("Name") << tab
1365 << m_pTrack->GetName() << eol << _("Depart From") << tab
1366 << m_pTrack->m_TrackStartString << eol << _("Destination") << tab
1367 << m_pTrack->m_TrackEndString << eol << _("Total distance") << tab
1368 << m_tTotDistance->GetValue() << eol << _("Speed") << tab
1369 << m_tAvgSpeed->GetValue() << eol
1370 << _("Departure Time") + _T(" ") + _("(m/d/y h:m)") << tab
1371 << m_pTrack->GetPoint(1)->GetCreateTime().Format() << eol
1372 << _("Time enroute") << tab << m_tTimeEnroute->GetValue() << eol
1373 << eol;
1374
1375 int noCols;
1376 int noRows;
1377 noCols = m_lcPoints->GetColumnCount();
1378 noRows = m_lcPoints->GetItemCount();
1379 wxListItem item;
1380 item.SetMask(wxLIST_MASK_TEXT);
1381
1382 for (int i = 0; i < noCols; i++) {
1383 m_lcPoints->GetColumn(i, item);
1384 csvString << item.GetText() << tab;
1385 }
1386 csvString << eol;
1387
1388 for (int j = 0; j < noRows; j++) {
1389 item.SetId(j);
1390 for (int i = 0; i < noCols; i++) {
1391 item.SetColumn(i);
1392 m_lcPoints->GetItem(item);
1393 csvString << item.GetText() << tab;
1394 }
1395 csvString << eol;
1396 }
1397
1398 if (wxTheClipboard->Open()) {
1399 wxTextDataObject* data = new wxTextDataObject;
1400 data->SetText(csvString);
1401 wxTheClipboard->SetData(data);
1402 wxTheClipboard->Close();
1403 }
1404}
1405
1406void TrackPropDlg::OnPrintBtnClick(wxCommandEvent& event) {
1407 TrackPrintSelection* dlg =
1408 new TrackPrintSelection(this, m_pTrack, m_lcPoints);
1409 DimeControl(dlg);
1410 dlg->ShowWindowModalThenDo([this, dlg](int retcode) {
1411 if (retcode == wxID_OK) {
1412 }
1413 });
1414}
1415
1416void TrackPropDlg::OnTrackPropRightClick(wxListEvent& event) {
1417 wxMenu menu;
1418
1419 wxMenuItem* copyItem =
1420 menu.Append(ID_RCLK_MENU_COPY_TEXT, _("&Copy all as text"));
1421
1422 PopupMenu(&menu);
1423}
1424
1425void TrackPropDlg::OnTrackPropListClick(wxListEvent& event) {
1426 long itemno = -1;
1427 m_nSelected = 0;
1428
1429 int selected_no;
1430 itemno =
1431 m_lcPoints->GetNextItem(itemno, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1432 if (itemno == -1)
1433 selected_no = 0;
1434 else
1435 selected_no = itemno;
1436
1437 m_pTrack->m_HighlightedTrackPoint = -1;
1438
1439 if (itemno >= 0) {
1440 TrackPoint* prp = m_pTrack->GetPoint(itemno);
1441 if (prp) {
1442 m_pTrack->m_HighlightedTrackPoint = itemno; // highlight the trackpoint
1443
1444 if (!(m_pTrack->m_bIsInLayer) && !(m_pTrack == g_pActiveTrack)) {
1445 m_nSelected = selected_no + 1;
1446 m_sdbBtmBtnsSizerSplit->Enable(true);
1447 }
1448 if (gFrame->GetFocusCanvas()) {
1449 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), prp->m_lat, prp->m_lon,
1450 gFrame->GetFocusCanvas()->GetVPScale());
1451 }
1452#ifdef __WXMSW__
1453 if (m_lcPoints) m_lcPoints->SetFocus();
1454#endif
1455 }
1456 }
1457 if (selected_no == 0 || selected_no == m_pTrack->GetnPoints() - 1)
1458 m_sdbBtmBtnsSizerSplit->Enable(false);
1459}
1460
1461void TrackPropDlg::OnTrackPropMenuSelected(wxCommandEvent& event) {
1462 switch (event.GetId()) {
1463 case ID_RCLK_MENU_COPY_TEXT:
1464 OnTrackPropCopyTxtClick(event);
1465 break;
1466 }
1467}
1468
1469void TrackPropDlg::OnToRouteBtnClick(wxCommandEvent& event) {
1470 pRouteManagerDialog->TrackToRoute(m_pTrack);
1471 if (NULL != pRouteManagerDialog && pRouteManagerDialog->IsVisible())
1472 pRouteManagerDialog->UpdateRouteListCtrl();
1473}
1474
1475void TrackPropDlg::OnExportBtnClick(wxCommandEvent& event) {
1476 wxString suggested_name = _("track");
1477 std::vector<Track*> list = {m_pTrack};
1478 if (m_pTrack->GetName() != wxEmptyString)
1479 suggested_name = m_pTrack->GetName();
1480 ExportGPXTracks(this, &list, suggested_name);
1481}
1482
1483void TrackPropDlg::m_hyperlinkContextMenu(wxMouseEvent& event) {
1484 m_pEditedLink = (wxHyperlinkCtrl*)event.GetEventObject();
1485 Connect(
1486 wxEVT_COMMAND_MENU_SELECTED,
1487 (wxObjectEventFunction)(wxEventFunction)&TrackPropDlg::PopupMenuHandler);
1488 m_scrolledWindowLinks->PopupMenu(
1489 m_menuLink, m_pEditedLink->GetPosition().x + event.GetPosition().x,
1490 m_pEditedLink->GetPosition().y + event.GetPosition().y);
1491}
1492
1493void TrackPropDlg::PopupMenuHandler(wxCommandEvent& event) {
1494 switch (event.GetId()) {
1495 case ID_TRK_MENU_ADD:
1496 OnAddLink(event);
1497 break;
1498 case ID_TRK_MENU_EDIT:
1499 OnEditLink(event);
1500 break;
1501 case ID_TRK_MENU_DELETE:
1502 OnDeleteLink(event);
1503 break;
1504 default:
1505 break;
1506 }
1507}
1508
1509void TrackPropDlg::OnDeleteLink(wxCommandEvent& event) {
1510 wxHyperlinkListNode* nodeToDelete = NULL;
1511 wxString findurl = m_pEditedLink->GetURL();
1512 wxString findlabel = m_pEditedLink->GetLabel();
1513
1514 wxWindowList kids = m_scrolledWindowLinks->GetChildren();
1515 for (unsigned int i = 0; i < kids.GetCount(); i++) {
1516 wxWindowListNode* node = kids.Item(i);
1517 wxWindow* win = node->GetData();
1518
1519 auto link_win = dynamic_cast<wxHyperlinkCtrl*>(win);
1520 if (link_win) {
1521 link_win->Disconnect(
1522 wxEVT_COMMAND_HYPERLINK,
1523 wxHyperlinkEventHandler(TrackPropDlg::OnHyperLinkClick));
1524 link_win->Disconnect(
1525 wxEVT_RIGHT_DOWN,
1526 wxMouseEventHandler(TrackPropDlg::m_hyperlinkContextMenu));
1527 win->Destroy();
1528 }
1529 }
1530
1532 int NbrOfLinks = m_pTrack->m_HyperlinkList->GetCount();
1533 HyperlinkList* hyperlinklist = m_pTrack->m_HyperlinkList;
1534 // int len = 0;
1535 if (NbrOfLinks > 0) {
1536 wxHyperlinkListNode* linknode = hyperlinklist->GetFirst();
1537 while (linknode) {
1538 Hyperlink* link = linknode->GetData();
1539 wxString Link = link->Link;
1540 wxString Descr = link->DescrText;
1541 if (Link == findurl &&
1542 (Descr == findlabel || (Link == findlabel && Descr == wxEmptyString)))
1543 nodeToDelete = linknode;
1544 else {
1545 wxHyperlinkCtrl* ctrl = new wxHyperlinkCtrl(
1546 m_scrolledWindowLinks, wxID_ANY, Descr, Link, wxDefaultPosition,
1547 wxDefaultSize, wxHL_DEFAULT_STYLE);
1548 ctrl->Connect(wxEVT_COMMAND_HYPERLINK,
1549 wxHyperlinkEventHandler(TrackPropDlg::OnHyperLinkClick),
1550 NULL, this);
1551 ctrl->Connect(wxEVT_RIGHT_DOWN,
1552 wxMouseEventHandler(TrackPropDlg::m_hyperlinkContextMenu),
1553 NULL, this);
1554
1555 bSizerLinks->Add(ctrl, 0, wxALL, 5);
1556 }
1557 linknode = linknode->GetNext();
1558 }
1559 }
1560 if (nodeToDelete) hyperlinklist->DeleteNode(nodeToDelete);
1561 m_scrolledWindowLinks->InvalidateBestSize();
1562 m_scrolledWindowLinks->Layout();
1563 sbSizerLinks->Layout();
1564 // event.Skip();
1565}
1566
1567void TrackPropDlg::OnEditLink(wxCommandEvent& event) {
1568 wxString findurl = m_pEditedLink->GetURL();
1569 wxString findlabel = m_pEditedLink->GetLabel();
1570
1571 LinkPropImpl* LinkPropDlg = new LinkPropImpl(this);
1572 LinkPropDlg->m_textCtrlLinkDescription->SetValue(findlabel);
1573 LinkPropDlg->m_textCtrlLinkUrl->SetValue(findurl);
1574 DimeControl(LinkPropDlg);
1575 LinkPropDlg->ShowWindowModalThenDo([this, LinkPropDlg, findurl,
1576 findlabel](int retcode) {
1577 if (retcode == wxID_OK) {
1578 int NbrOfLinks = m_pTrack->m_HyperlinkList->GetCount();
1579 HyperlinkList* hyperlinklist = m_pTrack->m_HyperlinkList;
1580 // int len = 0;
1581 if (NbrOfLinks > 0) {
1582 wxHyperlinkListNode* linknode = hyperlinklist->GetFirst();
1583 while (linknode) {
1584 Hyperlink* link = linknode->GetData();
1585 wxString Link = link->Link;
1586 wxString Descr = link->DescrText;
1587 if (Link == findurl &&
1588 (Descr == findlabel ||
1589 (Link == findlabel && Descr == wxEmptyString))) {
1590 link->Link = LinkPropDlg->m_textCtrlLinkUrl->GetValue();
1591 link->DescrText =
1592 LinkPropDlg->m_textCtrlLinkDescription->GetValue();
1593 wxHyperlinkCtrl* h =
1594 (wxHyperlinkCtrl*)m_scrolledWindowLinks->FindWindowByLabel(
1595 findlabel);
1596 if (h) {
1597 h->SetLabel(LinkPropDlg->m_textCtrlLinkDescription->GetValue());
1598 h->SetURL(LinkPropDlg->m_textCtrlLinkUrl->GetValue());
1599 }
1600 }
1601 linknode = linknode->GetNext();
1602 }
1603 }
1604
1605 m_scrolledWindowLinks->InvalidateBestSize();
1606 m_scrolledWindowLinks->Layout();
1607 sbSizerLinks->Layout();
1608 }
1609 });
1610 // event.Skip();
1611}
1612
1613void TrackPropDlg::OnAddLink(wxCommandEvent& event) {
1614 LinkPropImpl* LinkPropDlg = new LinkPropImpl(this);
1615 LinkPropDlg->m_textCtrlLinkDescription->SetValue(wxEmptyString);
1616 LinkPropDlg->m_textCtrlLinkUrl->SetValue(wxEmptyString);
1617 DimeControl(LinkPropDlg);
1618 LinkPropDlg->ShowWindowModalThenDo([this, LinkPropDlg](int retcode) {
1619 if (retcode == wxID_OK) {
1620 wxString desc = LinkPropDlg->m_textCtrlLinkDescription->GetValue();
1621 if (desc == wxEmptyString)
1622 desc = LinkPropDlg->m_textCtrlLinkUrl->GetValue();
1623 wxHyperlinkCtrl* ctrl = new wxHyperlinkCtrl(
1624 m_scrolledWindowLinks, wxID_ANY, desc,
1625 LinkPropDlg->m_textCtrlLinkUrl->GetValue(), wxDefaultPosition,
1626 wxDefaultSize, wxHL_DEFAULT_STYLE);
1627 ctrl->Connect(wxEVT_COMMAND_HYPERLINK,
1628 wxHyperlinkEventHandler(TrackPropDlg::OnHyperLinkClick),
1629 NULL, this);
1630 ctrl->Connect(wxEVT_RIGHT_DOWN,
1631 wxMouseEventHandler(TrackPropDlg::m_hyperlinkContextMenu),
1632 NULL, this);
1633
1634 bSizerLinks->Add(ctrl, 0, wxALL, 5);
1635 bSizerLinks->Fit(m_scrolledWindowLinks);
1636 // this->Fit();
1637
1638 Hyperlink* h = new Hyperlink();
1639 h->DescrText = LinkPropDlg->m_textCtrlLinkDescription->GetValue();
1640 h->Link = LinkPropDlg->m_textCtrlLinkUrl->GetValue();
1641 h->LType = wxEmptyString;
1642 m_pTrack->m_HyperlinkList->Append(h);
1643 }
1644 });
1645 // sbSizerLinks->Layout();
1646
1647 m_scrolledWindowLinks->InvalidateBestSize();
1648 m_scrolledWindowLinks->Layout();
1649 sbSizerLinks->Layout();
1650
1651 // event.Skip();
1652}
1653
1654void TrackPropDlg::OnEditLinkToggle(wxCommandEvent& event) {
1655 if (m_toggleBtnEdit->GetValue())
1656 m_staticTextEditEnabled->SetLabel(_("Links are opened for editing."));
1657 else
1658 m_staticTextEditEnabled->SetLabel(
1659 _("Links are opened in the default browser."));
1660 event.Skip();
1661}
1662
1663void TrackPropDlg::OnHyperLinkClick(wxHyperlinkEvent& event) {
1664 if (m_toggleBtnEdit->GetValue()) {
1665 m_pEditedLink = (wxHyperlinkCtrl*)event.GetEventObject();
1666 OnEditLink(event);
1667 event.Skip(false);
1668 return;
1669 }
1670 // Windows has trouble handling local file URLs with embedded anchor
1671 // points, e.g file://testfile.html#point1 The trouble is with the
1672 // wxLaunchDefaultBrowser with verb "open" Workaround is to probe the
1673 // registry to get the default browser, and open directly
1674 //
1675 // But, we will do this only if the URL contains the anchor point charater
1676 // '#' What a hack......
1677
1678#ifdef __WXMSW__
1679
1680 wxString cc = event.GetURL();
1681 if (cc.Find(_T("#")) != wxNOT_FOUND) {
1682 wxRegKey RegKey(
1683 wxString(_T("HKEY_CLASSES_ROOT\\HTTP\\shell\\open\\command")));
1684 if (RegKey.Exists()) {
1685 wxString command_line;
1686 RegKey.QueryValue(wxString(_T("")), command_line);
1687
1688 // Remove "
1689 command_line.Replace(wxString(_T("\"")), wxString(_T("")));
1690
1691 // Strip arguments
1692 int l = command_line.Find(_T(".exe"));
1693 if (wxNOT_FOUND == l) l = command_line.Find(_T(".EXE"));
1694
1695 if (wxNOT_FOUND != l) {
1696 wxString cl = command_line.Mid(0, l + 4);
1697 cl += _T(" ");
1698 cc.Prepend(_T("\""));
1699 cc.Append(_T("\""));
1700 cl += cc;
1701 wxExecute(cl); // Async, so Fire and Forget...
1702 }
1703 }
1704 } else
1705 event.Skip();
1706#else
1707 wxString url = event.GetURL();
1708 url.Replace(_T(" "), _T("%20"));
1709 ::wxLaunchDefaultBrowser(url);
1710// event.Skip();
1711#endif
1712}
1713
1714void TrackPropDlg::OnShowTimeTZ(wxCommandEvent& event) {
1715 if (m_rbShowTimeUTC && m_rbShowTimeUTC->GetValue())
1716 m_lcPoints->m_tz_selection = UTCINPUT;
1717 else if (m_rbShowTimePC && m_rbShowTimePC->GetValue())
1718 m_lcPoints->m_tz_selection = LTINPUT;
1719 else if (m_rbShowTimeLocal && m_rbShowTimeLocal->GetValue())
1720 m_lcPoints->m_tz_selection = LMTINPUT;
1722 m_lcPoints->m_tz_selection = GLOBAL_SETTINGS_INPUT;
1723 else
1724 throw std::logic_error("Unexpected time zone selection");
1725 m_lcPoints->DeleteAllItems();
1726 InitializeList();
1727}
1728
1729bool TrackPropDlg::SaveChanges(void) {
1730 if (m_pTrack && !m_pTrack->m_bIsInLayer) {
1731 // Get User input Text Fields
1732 m_pTrack->SetName(m_tName->GetValue());
1733 m_pTrack->m_TrackStartString = m_tFrom->GetValue();
1734 m_pTrack->m_TrackEndString = m_tTo->GetValue();
1735 if (m_tDescription)
1736 m_pTrack->m_TrackDescription = m_tDescription->GetValue();
1737 m_pTrack->SetVisible(m_cbShow->GetValue());
1738 if (m_cColor->GetSelection() == 0)
1739 m_pTrack->m_Colour = wxEmptyString;
1740 else
1741 m_pTrack->m_Colour = ::GpxxColorNames[m_cColor->GetSelection() - 1];
1742 m_pTrack->m_style = (wxPenStyle)::StyleValues[m_cStyle->GetSelection()];
1743 m_pTrack->m_width = ::WidthValues[m_cWidth->GetSelection()];
1744
1745 pConfig->UpdateTrack(m_pTrack);
1746 pConfig->UpdateSettings();
1747 }
1748
1749 if (m_pTrack && m_pTrack->IsRunning()) {
1750 wxJSONValue v;
1751 v[_T("Changed")] = true;
1752 v[_T("Name")] = m_pTrack->GetName();
1753 v[_T("GUID")] = m_pTrack->m_GUID;
1754 wxString msg_id(_T("OCPN_TRK_ACTIVATED"));
1755 SendJSONMessageToAllPlugins(msg_id, v);
1756 }
1757
1758 return true;
1759}
1760
1761void TrackPropDlg::OnOKBtnClick(wxCommandEvent& event) {
1762 // Look in the track list to be sure the track is still available
1763 // (May have been deleted by RouteManagerDialog...)
1764
1765 bool b_found_track = std::find(g_TrackList.begin(), g_TrackList.end(),
1766 m_pTrack) != g_TrackList.end();
1767
1768 if (b_found_track) {
1769 SaveChanges(); // write changes to globals and update config
1770 m_pTrack->ClearHighlights();
1771 }
1772
1773 m_bStartNow = false;
1774
1775 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
1776 pRouteManagerDialog->UpdateTrkListCtrl();
1777
1778 Hide();
1779 gFrame->InvalidateAllGL();
1780 gFrame->RefreshAllCanvas(false);
1781
1782 event.Skip();
1783}
1784
1785void TrackPropDlg::OnCancelBtnClick(wxCommandEvent& event) {
1786 bool b_found_track = std::find(g_TrackList.begin(), g_TrackList.end(),
1787 m_pTrack) != g_TrackList.end();
1788
1789 if (b_found_track) m_pTrack->ClearHighlights();
1790
1791 Hide();
1792 gFrame->InvalidateAllGL();
1793 gFrame->RefreshAllCanvas(false);
1794
1795 event.Skip();
1796}
1797
1798//--------------------------------------------------------------------------------------
1799// OCPNTrackListCtrl Implementation
1800//---------------------------------------------------------------------------------------
1801
1802OCPNTrackListCtrl::OCPNTrackListCtrl(wxWindow* parent, wxWindowID id,
1803 const wxPoint& pos, const wxSize& size,
1804 long style)
1805 : wxListCtrl(parent, id, pos, size, style) {
1806 m_parent = parent;
1807 m_tz_selection = GLOBAL_SETTINGS_INPUT;
1808 m_LMT_Offset = 0;
1809}
1810
1811OCPNTrackListCtrl::~OCPNTrackListCtrl() {}
1812
1814 if (m_pTrack->GetnPoints()) {
1815 TrackPoint* prp = m_pTrack->GetPoint(0);
1816 if (prp) return prp->m_lon;
1817 }
1818 return NAN;
1819}
1820
1821wxString OCPNTrackListCtrl::OnGetItemText(long item, long column) const {
1822 wxString ret;
1823
1824 if (item < 0 || item >= m_pTrack->GetnPoints()) return wxEmptyString;
1825
1826 TrackPoint* this_point = m_pTrack->GetPoint(item);
1827 TrackPoint* prev_point = item > 0 ? m_pTrack->GetPoint(item - 1) : NULL;
1828
1829 if (!this_point) return wxEmptyString;
1830
1831 double gt_brg, gt_leg_dist;
1832 double slat, slon;
1833 if (item == 0) {
1834 slat = gLat;
1835 slon = gLon;
1836 } else {
1837 slat = prev_point->m_lat;
1838 slon = prev_point->m_lon;
1839 }
1840
1841 switch (column) {
1842 case 0:
1843 if (item == 0)
1844 ret = _T("---");
1845 else
1846 ret.Printf(_T("%ld"), item);
1847 break;
1848
1849 case 1:
1850 DistanceBearingMercator(this_point->m_lat, this_point->m_lon, slat, slon,
1851 &gt_brg, &gt_leg_dist);
1852
1853 ret.Printf(_T("%6.2f ") + getUsrDistanceUnit(),
1854 toUsrDistance(gt_leg_dist));
1855 break;
1856
1857 case 2:
1858 DistanceBearingMercator(this_point->m_lat, this_point->m_lon, slat, slon,
1859 &gt_brg, &gt_leg_dist);
1860 ret.Printf("%03.0f %cT", gt_brg, 0x00B0);
1861 break;
1862
1863 case 3:
1864 ret = toSDMM(1, this_point->m_lat, 1);
1865 break;
1866
1867 case 4:
1868 ret = toSDMM(2, this_point->m_lon, 1);
1869 break;
1870
1871 case 5: {
1872 wxDateTime timestamp = this_point->GetCreateTime();
1873 if (timestamp.IsValid()) {
1876 .SetTimezone(getDatetimeTimezoneSelector(m_tz_selection))
1878 ret = ocpn::toUsrDateTimeFormat(timestamp, opts);
1879 } else
1880 ret = _T("----");
1881 } break;
1882
1883 case 6:
1884 if ((item > 0) && this_point->GetCreateTime().IsValid() &&
1885 prev_point->GetCreateTime().IsValid()) {
1886 DistanceBearingMercator(this_point->m_lat, this_point->m_lon, slat,
1887 slon, &gt_brg, &gt_leg_dist);
1888 double speed = 0.;
1889 double seconds = this_point->GetCreateTime()
1890 .Subtract(prev_point->GetCreateTime())
1891 .GetSeconds()
1892 .ToDouble();
1893
1894 if (seconds > 0.) speed = gt_leg_dist / seconds * 3600;
1895
1896 ret.Printf(_T("%5.2f"), toUsrSpeed(speed));
1897 } else
1898 ret = _("--");
1899 break;
1900
1901 default:
1902 break;
1903 }
1904
1905 return ret;
1906}
1907
1908int OCPNTrackListCtrl::OnGetItemColumnImage(long item, long column) const {
1909 return -1;
1910}
Represents an active track that is currently being recorded.
Definition track.h:194
Class LinkPropImpl.
Definition LinkPropDlg.h:89
Main application frame.
Definition ocpn_frame.h:135
int m_tz_selection
The timezone to use when formatting date/time.
double getStartPointLongitude() const
Return the longitude at the start point of the track.
Represents a single point in a track.
Definition track.h:53
Class TrackPropDlg.
bool UpdateProperties()
void OnDeleteLink(wxCommandEvent &event)
wxRadioButton * m_rbShowTimeLocal
Use Local Mean Time (LMT) at the location to format date/time.
wxRadioButton * m_rbShowTimePC
Use system timezone to format date/time, i.e.
wxRadioButton * m_rbShowTimeGlobalSettings
Honor OpenCPN global setting to format date/time.
Represents a track, which is a series of connected track points.
Definition track.h:79
The JSON value class implementation.
Definition jsonval.h:84
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
Definition gui_lib.cpp:54
General purpose GUI support.
Tools to send data to plugins.
Configuration options for date and time formatting.
DateTimeFormatOptions & SetTimezone(const wxString &tz)
Sets the timezone mode for date/time display.
DateTimeFormatOptions & SetLongitude(double lon)
Sets the reference longitude for Local Mean Time (LMT) calculations.