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