OpenCPN Partial API docs
Loading...
Searching...
No Matches
routemanagerdialog.cpp
1/*
2 This program is free software; you can redistribute it and/or
3 modify it under the terms of the GNU General Public License
4 as published by the Free Software Foundation; either version 2
5 of the License, or (at your option) any later version.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor,
15 Boston, MA 02110-1301, USA.
16
17 ---
18 Copyright (C) 2010, Anders Lund <anders@alweb.dk>
19 Copyright (c) 2025 NoCodeHummel
20 */
21
22#include "config.h"
23
24#include "routemanagerdialog.h"
25#include "route_gui.h"
26
27// For compilers that support precompilation, includes "wx/wx.h".
28#include <wx/wxprec.h>
29
30#ifndef WX_PRECOMP
31#include <wx/wx.h>
32#endif
33
34#include <wx/filename.h>
35#include <wx/stdpaths.h>
36#include <wx/progdlg.h>
37#include <wx/clipbrd.h>
38#include <wx/statline.h>
39
40#include <iostream>
41#include <vector>
42#include <algorithm>
43
44#include "model/ais_decoder.h"
45#include "model/config_vars.h"
46#include "model/georef.h"
47#include "model/mdns_cache.h"
48#include "model/mdns_query.h"
49#include "model/navobj_db.h"
50#include "model/navutil_base.h"
51#include "model/own_ship.h"
52#include "model/route.h"
53#include "model/routeman.h"
54#include "model/select.h"
55#include "model/track.h"
56
57#include "chartbase.h"
58#include "chcanv.h"
59#include "dychart.h"
60#include "Layer.h"
61#include "MarkInfo.h"
62#include "navutil.h"
63#include "ocpn_frame.h"
64#include "OCPNPlatform.h"
65#include "routeman_gui.h"
66#include "route_point_gui.h"
67#include "RoutePropDlgImpl.h"
68#include "SendToGpsDlg.h"
69#include "SendToPeerDlg.h"
70#include "styles.h"
71#include "svg_utils.h"
72#include "TrackPropDlg.h"
73
74#ifdef __ANDROID__
75#include "androidUTIL.h"
76#endif
77
78#define DIALOG_MARGIN 10
79
80enum { rmVISIBLE = 0, rmROUTENAME, rmROUTEDESC }; // RMColumns;
81enum { colTRKVISIBLE = 0, colTRKNAME, colTRKLENGTH, colTRKDATE };
82enum { colLAYVISIBLE = 0, colLAYNAME, colLAYITEMS, colLAYPERSIST };
83enum { colWPTICON = 0, colWPTSCALE, colWPTNAME, colWPTDIST };
84
85// GLOBALS :0
86extern RouteList *pRouteList;
87extern std::vector<Track *> g_TrackList;
88extern LayerList *pLayerList;
89extern wxString GetLayerName(int id);
90extern RoutePropDlgImpl *pRoutePropDialog;
91extern TrackPropDlg *pTrackPropDialog;
92extern Routeman *g_pRouteMan;
93extern MyConfig *pConfig;
94extern ActiveTrack *g_pActiveTrack;
95extern MarkInfoDlg *g_pMarkInfoDialog;
96extern MyFrame *gFrame;
97extern bool g_bShowLayers;
98extern wxString g_default_wp_icon;
99extern OCPNPlatform *g_Platform;
100
101// Helper for conditional file name separator
102void appendOSDirSlash(wxString *pString);
103
104static int SortRouteTrack(const int order, const wxString &it1,
105 const wxString &it2) {
106 if (order & 1) return it2.CmpNoCase(it1);
107
108 return it1.CmpNoCase(it2);
109}
110
111// sort callback. Sort by route name.
112static int sort_route_name_dir;
113#if wxCHECK_VERSION(2, 9, 0)
114static int wxCALLBACK SortRoutesOnName(wxIntPtr item1, wxIntPtr item2,
115 wxIntPtr list)
116#else
117int wxCALLBACK SortRoutesOnName(long item1, long item2, long list)
118#endif
119{
120 return SortRouteTrack(sort_route_name_dir, ((Route *)item1)->GetName(),
121 ((Route *)item2)->GetName());
122}
123
124// sort callback. Sort by route Destination.
125static int sort_route_to_dir;
126#if wxCHECK_VERSION(2, 9, 0)
127static int wxCALLBACK SortRoutesOnTo(wxIntPtr item1, wxIntPtr item2,
128 wxIntPtr list)
129#else
130int wxCALLBACK SortRoutesOnTo(long item1, long item2, long list)
131#endif
132{
133 return SortRouteTrack(sort_route_to_dir, ((Route *)item1)->GetTo(),
134 ((Route *)item2)->GetTo());
135}
136
137// sort callback. Sort by track name.
138static int sort_track_name_dir;
139#if wxCHECK_VERSION(2, 9, 0)
140static int wxCALLBACK SortTracksOnName(wxIntPtr item1, wxIntPtr item2,
141 wxIntPtr list)
142#else
143int wxCALLBACK SortTracksOnName(long item1, long item2, long list)
144#endif
145{
146 return SortRouteTrack(sort_track_name_dir, ((Track *)item1)->GetName(),
147 ((Track *)item2)->GetName());
148}
149
150static int SortDouble(const int order, const double &it1, const double &it2) {
151 double l1;
152 double l2;
153
154 if (order & 1) {
155 l1 = it2;
156 l2 = it1;
157 } else {
158 l1 = it1;
159 l2 = it2;
160 }
161
162 if (l1 == l2) return 0;
163 if (l2 < l1) return 1;
164 return -1;
165}
166
167// sort callback. Sort by track length.
168static int sort_track_len_dir;
169#if wxCHECK_VERSION(2, 9, 0)
170static int wxCALLBACK SortTracksOnDistance(wxIntPtr item1, wxIntPtr item2,
171 wxIntPtr list)
172#else
173int wxCALLBACK SortTracksOnDistance(long item1, long item2, long list)
174#endif
175{
176 return SortDouble(sort_track_len_dir, ((Track *)item1)->Length(),
177 ((Track *)item2)->Length());
178}
179
180// sort callback. Sort by track start date.
181static int sort_track_date_dir;
182#if wxCHECK_VERSION(2, 9, 0)
183static int wxCALLBACK SortTracksOnDate(wxIntPtr item1, wxIntPtr item2,
184 wxIntPtr list)
185#else
186int wxCALLBACK SortTracksOnDate(long item1, long item2, long list)
187#endif
188{
189 // Sort date/time using ISO format, which is sortable as a string.
190 return SortRouteTrack(sort_track_date_dir, ((Track *)item1)->GetIsoDateTime(),
191 ((Track *)item2)->GetIsoDateTime());
192}
193
194static int sort_wp_key;
195static int sort_track_key;
196
197// sort callback. Sort by wpt name.
198static int sort_wp_name_dir;
199#if wxCHECK_VERSION(2, 9, 0)
200static int wxCALLBACK SortWaypointsOnName(wxIntPtr item1, wxIntPtr item2,
201 wxIntPtr list)
202#else
203int wxCALLBACK SortWaypointsOnName(long item1, long item2, long list)
204#endif
205
206{
207 RoutePoint *pRP1 = (RoutePoint *)item1;
208 RoutePoint *pRP2 = (RoutePoint *)item2;
209
210 if (pRP1 && pRP2) {
211 if (sort_wp_name_dir & 1)
212 return pRP2->GetName().CmpNoCase(pRP1->GetName());
213 else
214 return pRP1->GetName().CmpNoCase(pRP2->GetName());
215 } else
216 return 0;
217}
218
219// sort callback. Sort by wpt distance.
220static int sort_wp_len_dir;
221#if wxCHECK_VERSION(2, 9, 0)
222static int wxCALLBACK SortWaypointsOnDistance(wxIntPtr item1, wxIntPtr item2,
223 wxIntPtr list)
224#else
225int wxCALLBACK SortWaypointsOnDistance(long item1, long item2, long list)
226#endif
227{
228 double dst1, dst2;
229 DistanceBearingMercator(((RoutePoint *)item1)->m_lat,
230 ((RoutePoint *)item1)->m_lon, gLat, gLon, NULL,
231 &dst1);
232 DistanceBearingMercator(((RoutePoint *)item2)->m_lat,
233 ((RoutePoint *)item2)->m_lon, gLat, gLon, NULL,
234 &dst2);
235 return SortDouble(sort_wp_len_dir, dst1, dst2);
236}
237
238// sort callback. Sort by layer name.
239static int sort_layer_name_dir;
240#if wxCHECK_VERSION(2, 9, 0)
241static int wxCALLBACK SortLayersOnName(wxIntPtr item1, wxIntPtr item2,
242 wxIntPtr list)
243#else
244int wxCALLBACK SortLayersOnName(long item1, long item2, long list)
245#endif
246{
247 return SortRouteTrack(sort_layer_name_dir, ((Layer *)item1)->m_LayerName,
248 ((Layer *)item2)->m_LayerName);
249}
250
251// sort callback. Sort by layer size.
252static int sort_layer_len_dir;
253#if wxCHECK_VERSION(2, 9, 0)
254static int wxCALLBACK SortLayersOnSize(wxIntPtr item1, wxIntPtr item2,
255 wxIntPtr list)
256#else
257int wxCALLBACK SortLayersOnSize(long item1, long item2, long list)
258#endif
259{
260 return SortDouble(sort_layer_len_dir, ((Layer *)item1)->m_NoOfItems,
261 ((Layer *)item2)->m_NoOfItems);
262}
263
264// event table. Mostly empty, because I find it much easier to see what is
265// connected to what using Connect() where possible, so that it is visible in
266// the code.
267BEGIN_EVENT_TABLE(RouteManagerDialog, wxFrame)
268EVT_NOTEBOOK_PAGE_CHANGED(
269 wxID_ANY,
270 RouteManagerDialog::OnTabSwitch) // This should work under Windows :-(
271EVT_CLOSE(RouteManagerDialog::OnClose)
272EVT_COMMAND(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, RouteManagerDialog::OnOK)
273EVT_CHAR_HOOK(RouteManagerDialog::OnKey)
274END_EVENT_TABLE()
275
276void RouteManagerDialog::OnKey(wxKeyEvent &ke) {
277 if (ke.GetKeyCode() == WXK_ESCAPE)
278 Close(true);
279 else
280 ke.Skip();
281}
282
283void RouteManagerDialog::OnTabSwitch(wxNotebookEvent &event) {
284 if (!m_pNotebook) return;
285 int current_page = m_pNotebook->GetSelection();
286 if (current_page == 3) {
287 if (btnImport) btnImport->Enable(false);
288 if (btnExport) btnExport->Enable(false);
289 if (btnExportViz) btnExportViz->Enable(false);
290 } else {
291 if (btnImport) btnImport->Enable(true);
292 if (btnExport) btnExport->Enable(true);
293 if (btnExportViz) btnExportViz->Enable(true);
294 }
295 event.Skip(); // remove if using event table... why?
296}
297
298// implementation
299
300bool RouteManagerDialog::instanceFlag = false;
301RouteManagerDialog *RouteManagerDialog::single = NULL;
302
303RouteManagerDialog *RouteManagerDialog::getInstance(wxWindow *parent) {
304 if (!instanceFlag) {
305 single = new RouteManagerDialog(parent);
306 instanceFlag = true;
307 return single;
308 } else {
309 return single;
310 }
311}
312
313RouteManagerDialog::RouteManagerDialog(wxWindow *parent) {
314 long style =
315 wxDEFAULT_FRAME_STYLE | wxRESIZE_BORDER | wxFRAME_FLOAT_ON_PARENT;
316
317 wxFrame::Create(parent, -1, wxString(_("Route & Mark Manager")),
318 wxDefaultPosition, wxDefaultSize, style);
319
320 wxFont *qFont = GetOCPNScaledFont(_("Dialog"));
321 SetFont(*qFont);
322
323 m_lastWptItem = -1;
324 m_lastTrkItem = -1;
325 m_lastRteItem = -1;
326 sort_wp_key = SORT_ON_NAME;
327 sort_track_key = SORT_ON_NAME;
328
329 btnImport = NULL;
330 btnExport = NULL;
331 btnExportViz = NULL;
332
333 Create();
334 routes_update_listener.Init(g_pRouteMan->on_routes_update,
335 [&](wxCommandEvent) { UpdateRouteListCtrl(); });
336}
337
338void RouteManagerDialog::Create() {
339 // Get a text height metric for reference
340 int char_width, char_height;
341 GetTextExtent(_T("W"), &char_width, &char_height);
342 m_charWidth = char_width;
343
344 wxBoxSizer *itemBoxSizer1 = new wxBoxSizer(wxVERTICAL);
345 SetSizer(itemBoxSizer1);
346
347 m_pNotebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition,
348 wxSize(-1, -1), wxNB_TOP);
349 itemBoxSizer1->Add(m_pNotebook, 1, wxALL | wxEXPAND, 5);
350
351 // Create "Routes" panel
352 m_pPanelRte = new wxPanel(m_pNotebook, wxID_ANY, wxDefaultPosition,
353 wxDefaultSize, wxNO_BORDER | wxTAB_TRAVERSAL);
354
355 wxBoxSizer *sbsRoutes = new wxBoxSizer(wxHORIZONTAL);
356 m_pPanelRte->SetSizer(sbsRoutes);
357 m_pNotebook->AddPage(m_pPanelRte, _("Routes"));
358
359 sort_wp_len_dir = 1;
360 sort_wp_name_dir = 0;
361 sort_track_len_dir = 1;
362 sort_route_to_dir = 0;
363 sort_track_name_dir = 0;
364 sort_route_name_dir = 0;
365 sort_layer_name_dir = 0;
366 sort_layer_len_dir = 1;
367
368 m_listIconSize = 2 * GetCharHeight();
369
370 // Setup GUI
371 wxBoxSizer *bSizerRteContents;
372 bSizerRteContents = new wxBoxSizer(wxVERTICAL);
373
374 wxFlexGridSizer *fgSizerFilterRte;
375 fgSizerFilterRte = new wxFlexGridSizer(0, 2, 0, 0);
376 fgSizerFilterRte->AddGrowableCol(1);
377 fgSizerFilterRte->SetFlexibleDirection(wxBOTH);
378 fgSizerFilterRte->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
379
380 m_stFilterRte = new wxStaticText(m_pPanelRte, wxID_ANY, _("Filter"),
381 wxDefaultPosition, wxDefaultSize, 0);
382 m_stFilterRte->Wrap(-1);
383 fgSizerFilterRte->Add(m_stFilterRte, 0, wxALL, 5);
384
385 m_tFilterRte = new wxTextCtrl(m_pPanelRte, wxID_ANY, wxEmptyString,
386 wxDefaultPosition, wxDefaultSize, 0);
387 fgSizerFilterRte->Add(m_tFilterRte, 1, wxALL | wxEXPAND, 5);
388
389 bSizerRteContents->Add(fgSizerFilterRte, 0, wxEXPAND, 5);
390 m_tFilterRte->Connect(
391 wxEVT_COMMAND_TEXT_UPDATED,
392 wxCommandEventHandler(RouteManagerDialog::OnFilterChanged), NULL, this);
393
394 m_cbShowAllRte = new wxCheckBox(m_pPanelRte, wxID_ANY, _("Show all routes"));
395 bSizerRteContents->Add(m_cbShowAllRte, 0, wxEXPAND | wxLEFT, 5);
396 m_cbShowAllRte->Connect(
397 wxEVT_COMMAND_CHECKBOX_CLICKED,
398 wxCommandEventHandler(RouteManagerDialog::OnShowAllRteCBClicked), NULL,
399 this);
400
401 m_pRouteListCtrl =
402 new wxListCtrl(m_pPanelRte, -1, wxDefaultPosition, wxSize(-1, -1),
403 wxLC_REPORT | wxLC_SORT_ASCENDING | wxLC_HRULES |
404 wxBORDER_SUNKEN /*|wxLC_VRULES*/);
405#ifdef __ANDROID__
406 m_pRouteListCtrl->GetHandle()->setStyleSheet(getAdjustedDialogStyleSheet());
407#endif
408
409 m_pRouteListCtrl->Connect(
410 wxEVT_COMMAND_LIST_ITEM_SELECTED,
411 wxListEventHandler(RouteManagerDialog::OnRteSelected), NULL, this);
412 m_pRouteListCtrl->Connect(
413 wxEVT_COMMAND_LIST_ITEM_DESELECTED,
414 wxListEventHandler(RouteManagerDialog::OnRteSelected), NULL, this);
415 m_pRouteListCtrl->Connect(
416 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
417 wxListEventHandler(RouteManagerDialog::OnRteDefaultAction), NULL, this);
418 m_pRouteListCtrl->Connect(
419 wxEVT_LEFT_DOWN,
420 wxMouseEventHandler(RouteManagerDialog::OnRteToggleVisibility), NULL,
421 this);
422 m_pRouteListCtrl->Connect(
423 wxEVT_COMMAND_LIST_COL_CLICK,
424 wxListEventHandler(RouteManagerDialog::OnRteColumnClicked), NULL, this);
425 bSizerRteContents->Add(m_pRouteListCtrl, 1, wxEXPAND | wxALL, DIALOG_MARGIN);
426 sbsRoutes->Add(bSizerRteContents, 1, wxEXPAND, 5);
427
428 // Columns: visibility ctrl, name
429 // note that under MSW for SetColumnWidth() to work we need to create the
430 // items with images initially even if we specify dummy image id
431 m_pRouteListCtrl->InsertColumn(rmVISIBLE, _("Show"), wxLIST_FORMAT_LEFT,
432 10 /*4 * char_width*/);
433 m_pRouteListCtrl->InsertColumn(rmROUTENAME, _("Route Name"),
434 wxLIST_FORMAT_LEFT, 15 * char_width);
435 m_pRouteListCtrl->InsertColumn(rmROUTEDESC, _("From <-> To"),
436 wxLIST_FORMAT_LEFT, 10 * char_width);
437
438 // Buttons: Delete, Properties...
439 wxBoxSizer *bsRouteButtons = new wxBoxSizer(wxVERTICAL);
440 sbsRoutes->Add(bsRouteButtons, 0, wxEXPAND);
441
442 wxScrolledWindow *winr = new wxScrolledWindow(
443 m_pPanelRte, wxID_ANY, wxDefaultPosition, wxDefaultSize,
444 wxNO_BORDER | wxTAB_TRAVERSAL | wxVSCROLL);
445 winr->SetScrollRate(0, 5);
446
447 bsRouteButtons->Add(winr, 1, wxALL | wxEXPAND, DIALOG_MARGIN);
448
449 wxBoxSizer *bsRouteButtonsInner = new wxBoxSizer(wxVERTICAL);
450 winr->SetSizer(bsRouteButtonsInner);
451
452 btnRteProperties = new wxButton(winr, -1, _("&Properties") + _T("..."));
453 bsRouteButtonsInner->Add(btnRteProperties, 0, wxALL | wxEXPAND,
454 DIALOG_MARGIN);
455 btnRteProperties->Connect(
456 wxEVT_COMMAND_BUTTON_CLICKED,
457 wxCommandEventHandler(RouteManagerDialog::OnRtePropertiesClick), NULL,
458 this);
459
460 btnRteActivate = new wxButton(winr, -1, _("&Activate"));
461 bsRouteButtonsInner->Add(btnRteActivate, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
462 btnRteActivate->Connect(
463 wxEVT_COMMAND_BUTTON_CLICKED,
464 wxCommandEventHandler(RouteManagerDialog::OnRteActivateClick), NULL,
465 this);
466 btnRteActivate->Connect(
467 wxEVT_LEFT_DOWN,
468 wxMouseEventHandler(RouteManagerDialog::OnRteBtnLeftDown), NULL, this);
469
470 btnRteZoomto = new wxButton(winr, -1, _("&Center View"));
471 bsRouteButtonsInner->Add(btnRteZoomto, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
472 btnRteZoomto->Connect(
473 wxEVT_COMMAND_BUTTON_CLICKED,
474 wxCommandEventHandler(RouteManagerDialog::OnRteZoomtoClick), NULL, this);
475 btnRteZoomto->Connect(
476 wxEVT_LEFT_DOWN,
477 wxMouseEventHandler(RouteManagerDialog::OnRteBtnLeftDown), NULL, this);
478
479 btnRteReverse = new wxButton(winr, -1, _("&Reverse"));
480 bsRouteButtonsInner->Add(btnRteReverse, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
481 btnRteReverse->Connect(
482 wxEVT_COMMAND_BUTTON_CLICKED,
483 wxCommandEventHandler(RouteManagerDialog::OnRteReverseClick), NULL, this);
484
485 btnRteDelete = new wxButton(winr, -1, _("&Delete"));
486 bsRouteButtonsInner->Add(btnRteDelete, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
487 btnRteDelete->Connect(
488 wxEVT_COMMAND_BUTTON_CLICKED,
489 wxCommandEventHandler(RouteManagerDialog::OnRteDeleteClick), NULL, this);
490
491 wxString reseq_label(_("&Resequence Waypoints"));
492 wxString export_label(_("&Export selected..."));
493 wxString send_to_gps_label(_("&Send to GPS..."));
494 wxString send_to_peer_label(_("Send to &Peer..."));
495
496#ifdef __ANDROID__
497 reseq_label = wxString(_("Resequence"));
498 export_label = wxString(_("Export"));
499 send_to_gps_label = wxString(_("Send to GPS"));
500 send_to_peer_label = wxString(_("Send to Peer"));
501#endif
502
503 btnRteExport = new wxButton(winr, -1, export_label);
504 bsRouteButtonsInner->Add(btnRteExport, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
505 btnRteExport->Connect(
506 wxEVT_COMMAND_BUTTON_CLICKED,
507 wxCommandEventHandler(RouteManagerDialog::OnRteExportClick), NULL, this);
508
509 btnRteResequence = new wxButton(winr, -1, reseq_label);
510 bsRouteButtonsInner->Add(btnRteResequence, 0, wxALL | wxEXPAND,
511 DIALOG_MARGIN);
512 btnRteResequence->Connect(
513 wxEVT_COMMAND_BUTTON_CLICKED,
514 wxCommandEventHandler(RouteManagerDialog::OnRteResequenceClick), NULL,
515 this);
516
517 btnRteSendToPeer = new wxButton(winr, -1, send_to_peer_label);
518 bsRouteButtonsInner->Add(btnRteSendToPeer, 0, wxALL | wxEXPAND,
519 DIALOG_MARGIN);
520 btnRteSendToPeer->Connect(
521 wxEVT_COMMAND_BUTTON_CLICKED,
522 wxCommandEventHandler(RouteManagerDialog::OnRteSendToPeerClick), NULL,
523 this);
524
525 btnRteSendToGPS = new wxButton(winr, -1, send_to_gps_label);
526 bsRouteButtonsInner->Add(btnRteSendToGPS, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
527 btnRteSendToGPS->Connect(
528 wxEVT_COMMAND_BUTTON_CLICKED,
529 wxCommandEventHandler(RouteManagerDialog::OnRteSendToGPSClick), NULL,
530 this);
531
532 bsRouteButtonsInner->AddSpacer(10);
533
534 btnRteDeleteAll = new wxButton(winr, -1, _("&Delete All"));
535 bsRouteButtonsInner->Add(btnRteDeleteAll, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
536 btnRteDeleteAll->Connect(
537 wxEVT_COMMAND_BUTTON_CLICKED,
538 wxCommandEventHandler(RouteManagerDialog::OnRteDeleteAllClick), NULL,
539 this);
540
541 // Create "Tracks" panel
542 m_pPanelTrk = new wxPanel(m_pNotebook, wxID_ANY, wxDefaultPosition,
543 wxDefaultSize, wxNO_BORDER | wxTAB_TRAVERSAL);
544 wxBoxSizer *sbsTracks = new wxBoxSizer(wxHORIZONTAL);
545 m_pPanelTrk->SetSizer(sbsTracks);
546 m_pNotebook->AddPage(m_pPanelTrk, _("Tracks"));
547
548 wxBoxSizer *bSizerTrkContents;
549 bSizerTrkContents = new wxBoxSizer(wxVERTICAL);
550
551 wxFlexGridSizer *fgSizerFilterTrk;
552 fgSizerFilterTrk = new wxFlexGridSizer(0, 2, 0, 0);
553 fgSizerFilterTrk->AddGrowableCol(1);
554 fgSizerFilterTrk->SetFlexibleDirection(wxBOTH);
555 fgSizerFilterTrk->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
556
557 m_stFilterTrk = new wxStaticText(m_pPanelTrk, wxID_ANY, _("Filter"),
558 wxDefaultPosition, wxDefaultSize, 0);
559 m_stFilterTrk->Wrap(-1);
560 fgSizerFilterTrk->Add(m_stFilterTrk, 0, wxALL, 5);
561
562 m_tFilterTrk = new wxTextCtrl(m_pPanelTrk, wxID_ANY, wxEmptyString,
563 wxDefaultPosition, wxDefaultSize, 0);
564 fgSizerFilterTrk->Add(m_tFilterTrk, 1, wxALL | wxEXPAND, 5);
565
566 bSizerTrkContents->Add(fgSizerFilterTrk, 0, wxEXPAND, 5);
567 m_tFilterTrk->Connect(
568 wxEVT_COMMAND_TEXT_UPDATED,
569 wxCommandEventHandler(RouteManagerDialog::OnFilterChanged), NULL, this);
570
571 m_cbShowAllTrk = new wxCheckBox(m_pPanelTrk, wxID_ANY, _("Show all tracks"));
572 bSizerTrkContents->Add(m_cbShowAllTrk, 0, wxEXPAND | wxLEFT, 5);
573 m_cbShowAllTrk->Connect(
574 wxEVT_COMMAND_CHECKBOX_CLICKED,
575 wxCommandEventHandler(RouteManagerDialog::OnShowAllTrkCBClicked), NULL,
576 this);
577
578 m_pTrkListCtrl =
579 new wxListCtrl(m_pPanelTrk, -1, wxDefaultPosition, wxDefaultSize,
580 wxLC_REPORT | wxLC_SORT_ASCENDING | wxLC_HRULES |
581 wxBORDER_SUNKEN /*|wxLC_VRULES*/);
582
583#ifdef __ANDROID__
584 m_pTrkListCtrl->GetHandle()->setStyleSheet(getAdjustedDialogStyleSheet());
585#endif
586
587 m_pTrkListCtrl->Connect(wxEVT_COMMAND_LIST_ITEM_SELECTED,
588 wxListEventHandler(RouteManagerDialog::OnTrkSelected),
589 NULL, this);
590 m_pTrkListCtrl->Connect(wxEVT_COMMAND_LIST_ITEM_DESELECTED,
591 wxListEventHandler(RouteManagerDialog::OnTrkSelected),
592 NULL, this);
593 m_pTrkListCtrl->Connect(
594 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
595 wxListEventHandler(RouteManagerDialog::OnTrkDefaultAction), NULL, this);
596 m_pTrkListCtrl->Connect(
597 wxEVT_LEFT_DOWN,
598 wxMouseEventHandler(RouteManagerDialog::OnTrkToggleVisibility), NULL,
599 this);
600 m_pTrkListCtrl->Connect(
601 wxEVT_COMMAND_LIST_COL_CLICK,
602 wxListEventHandler(RouteManagerDialog::OnTrkColumnClicked), NULL, this);
603 m_pTrkListCtrl->Connect(
604 wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
605 wxListEventHandler(RouteManagerDialog::OnTrkRightClick), NULL, this);
606 this->Connect(wxEVT_COMMAND_MENU_SELECTED,
607 wxCommandEventHandler(RouteManagerDialog::OnTrkMenuSelected),
608 NULL, this);
609
610 bSizerTrkContents->Add(m_pTrkListCtrl, 1, wxEXPAND | wxALL, DIALOG_MARGIN);
611 sbsTracks->Add(bSizerTrkContents, 1, wxEXPAND, 5);
612
613 m_pTrkListCtrl->InsertColumn(colTRKVISIBLE, _("Show"), wxLIST_FORMAT_LEFT,
614 4 * char_width);
615 m_pTrkListCtrl->InsertColumn(colTRKNAME, _("Track Name"), wxLIST_FORMAT_LEFT,
616 20 * char_width);
617 m_pTrkListCtrl->InsertColumn(colTRKDATE, _("Start Date"), wxLIST_FORMAT_LEFT,
618 20 * char_width);
619 m_pTrkListCtrl->InsertColumn(colTRKLENGTH, _("Length"), wxLIST_FORMAT_LEFT,
620 5 * char_width);
621
622 wxBoxSizer *bsTrkButtons = new wxBoxSizer(wxVERTICAL);
623 sbsTracks->Add(bsTrkButtons, 0, wxEXPAND);
624
625 wxScrolledWindow *wint = new wxScrolledWindow(
626 m_pPanelTrk, wxID_ANY, wxDefaultPosition, wxDefaultSize,
627 wxNO_BORDER | wxTAB_TRAVERSAL | wxVSCROLL);
628 wint->SetScrollRate(0, 5);
629
630 bsTrkButtons->Add(wint, 1, wxALL | wxEXPAND, DIALOG_MARGIN);
631
632 wxBoxSizer *bsTrkButtonsInner = new wxBoxSizer(wxVERTICAL);
633 wint->SetSizer(bsTrkButtonsInner);
634
635 btnTrkNew = new wxButton(wint, -1, _("&Start Track"));
636 bsTrkButtonsInner->Add(btnTrkNew, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
637 btnTrkNew->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
638 wxCommandEventHandler(RouteManagerDialog::OnTrkNewClick),
639 NULL, this);
640
641 btnTrkProperties = new wxButton(wint, -1, _("&Properties"));
642 bsTrkButtonsInner->Add(btnTrkProperties, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
643 btnTrkProperties->Connect(
644 wxEVT_COMMAND_BUTTON_CLICKED,
645 wxCommandEventHandler(RouteManagerDialog::OnTrkPropertiesClick), NULL,
646 this);
647
648 btnTrkDelete = new wxButton(wint, -1, _("&Delete"));
649 bsTrkButtonsInner->Add(btnTrkDelete, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
650 btnTrkDelete->Connect(
651 wxEVT_COMMAND_BUTTON_CLICKED,
652 wxCommandEventHandler(RouteManagerDialog::OnTrkDeleteClick), NULL, this);
653
654 btnTrkExport = new wxButton(wint, -1, _("&Export selected..."));
655 bsTrkButtonsInner->Add(btnTrkExport, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
656 btnTrkExport->Connect(
657 wxEVT_COMMAND_BUTTON_CLICKED,
658 wxCommandEventHandler(RouteManagerDialog::OnTrkExportClick), NULL, this);
659
660 btnTrkRouteFromTrack = new wxButton(wint, -1, _("Route from Track"));
661 bsTrkButtonsInner->Add(btnTrkRouteFromTrack, 0, wxALL | wxEXPAND,
662 DIALOG_MARGIN);
663 btnTrkRouteFromTrack->Connect(
664 wxEVT_COMMAND_BUTTON_CLICKED,
665 wxCommandEventHandler(RouteManagerDialog::OnTrkRouteFromTrackClick), NULL,
666 this);
667
668 btnTrkSendToPeer = new wxButton(wint, -1, _("Send to &Peer"));
669 bsTrkButtonsInner->Add(btnTrkSendToPeer, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
670 btnTrkSendToPeer->Connect(
671 wxEVT_COMMAND_BUTTON_CLICKED,
672 wxCommandEventHandler(RouteManagerDialog::OnTrkSendToPeerClick), NULL,
673 this);
674
675 bsTrkButtonsInner->AddSpacer(10);
676
677 btnTrkDeleteAll = new wxButton(wint, -1, _("&Delete All"));
678 bsTrkButtonsInner->Add(btnTrkDeleteAll, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
679 btnTrkDeleteAll->Connect(
680 wxEVT_COMMAND_BUTTON_CLICKED,
681 wxCommandEventHandler(RouteManagerDialog::OnTrkDeleteAllClick), NULL,
682 this);
683
684 // Create "Marks" panel
685 m_pPanelWpt = new wxPanel(m_pNotebook, wxID_ANY, wxDefaultPosition,
686 wxDefaultSize, wxNO_BORDER | wxTAB_TRAVERSAL);
687 wxBoxSizer *sbsWpts = new wxBoxSizer(wxHORIZONTAL);
688 m_pPanelWpt->SetSizer(sbsWpts);
689 m_pNotebook->AddPage(m_pPanelWpt, _("Marks"));
690
691 wxBoxSizer *bSizerWptContents;
692 bSizerWptContents = new wxBoxSizer(wxVERTICAL);
693
694 wxFlexGridSizer *fgSizerFilterWpt;
695 fgSizerFilterWpt = new wxFlexGridSizer(0, 2, 0, 0);
696 fgSizerFilterWpt->AddGrowableCol(1);
697 fgSizerFilterWpt->SetFlexibleDirection(wxBOTH);
698 fgSizerFilterWpt->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
699
700 m_stFilterWpt = new wxStaticText(m_pPanelWpt, wxID_ANY, _("Filter"),
701 wxDefaultPosition, wxDefaultSize, 0);
702 m_stFilterWpt->Wrap(-1);
703 fgSizerFilterWpt->Add(m_stFilterWpt, 0, wxALL, 5);
704
705 m_tFilterWpt = new wxTextCtrl(m_pPanelWpt, wxID_ANY, wxEmptyString,
706 wxDefaultPosition, wxDefaultSize, 0);
707 fgSizerFilterWpt->Add(m_tFilterWpt, 1, wxALL | wxEXPAND, 5);
708
709 bSizerWptContents->Add(fgSizerFilterWpt, 0, wxEXPAND, 5);
710 m_tFilterWpt->Connect(
711 wxEVT_COMMAND_TEXT_UPDATED,
712 wxCommandEventHandler(RouteManagerDialog::OnFilterChanged), NULL, this);
713
714 m_cbShowAllWP = new wxCheckBox(m_pPanelWpt, wxID_ANY, _("Show all marks"));
715 bSizerWptContents->Add(m_cbShowAllWP, 0, wxEXPAND | wxLEFT, 5);
716 m_cbShowAllWP->Connect(
717 wxEVT_COMMAND_CHECKBOX_CLICKED,
718 wxCommandEventHandler(RouteManagerDialog::OnShowAllWpCBClicked), NULL,
719 this);
720
721 m_pWptListCtrl =
722 new wxListCtrl(m_pPanelWpt, -1, wxDefaultPosition, wxDefaultSize,
723 wxLC_REPORT | wxLC_SORT_ASCENDING | wxLC_HRULES |
724 wxBORDER_SUNKEN /*|wxLC_VRULES*/);
725#ifdef __ANDROID__
726 m_pWptListCtrl->GetHandle()->setStyleSheet(getAdjustedDialogStyleSheet());
727#endif
728
729 m_pWptListCtrl->Connect(wxEVT_COMMAND_LIST_ITEM_SELECTED,
730 wxListEventHandler(RouteManagerDialog::OnWptSelected),
731 NULL, this);
732 m_pWptListCtrl->Connect(wxEVT_COMMAND_LIST_ITEM_DESELECTED,
733 wxListEventHandler(RouteManagerDialog::OnWptSelected),
734 NULL, this);
735 m_pWptListCtrl->Connect(
736 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
737 wxListEventHandler(RouteManagerDialog::OnWptDefaultAction), NULL, this);
738 m_pWptListCtrl->Connect(
739 wxEVT_LEFT_DOWN,
740 wxMouseEventHandler(RouteManagerDialog::OnWptToggleVisibility), NULL,
741 this);
742 m_pWptListCtrl->Connect(
743 wxEVT_COMMAND_LIST_COL_CLICK,
744 wxListEventHandler(RouteManagerDialog::OnWptColumnClicked), NULL, this);
745 bSizerWptContents->Add(m_pWptListCtrl, 1, wxEXPAND | wxALL, DIALOG_MARGIN);
746 sbsWpts->Add(bSizerWptContents, 1, wxEXPAND, 5);
747
748 m_pWptListCtrl->InsertColumn(colWPTICON, _("Icon"), wxLIST_FORMAT_LEFT,
749 4 * char_width);
750 m_pWptListCtrl->InsertColumn(colWPTSCALE, _("Scale"), wxLIST_FORMAT_LEFT,
751 8 * char_width);
752 m_pWptListCtrl->InsertColumn(colWPTNAME, _("Mark Name"), wxLIST_FORMAT_LEFT,
753 15 * char_width);
754 m_pWptListCtrl->InsertColumn(colWPTDIST, _("Distance from own ship"),
755 wxLIST_FORMAT_LEFT, 14 * char_width);
756
757 wxBoxSizer *bsWptButtons = new wxBoxSizer(wxVERTICAL);
758 sbsWpts->Add(bsWptButtons, 0, wxEXPAND);
759
760 wxScrolledWindow *winw = new wxScrolledWindow(
761 m_pPanelWpt, wxID_ANY, wxDefaultPosition, wxDefaultSize,
762 wxNO_BORDER | wxTAB_TRAVERSAL | wxVSCROLL);
763 winw->SetScrollRate(0, 5);
764
765 bsWptButtons->Add(winw, 1, wxALL | wxEXPAND, DIALOG_MARGIN);
766
767 wxBoxSizer *bsWptButtonsInner = new wxBoxSizer(wxVERTICAL);
768 winw->SetSizer(bsWptButtonsInner);
769
770 btnWptNew = new wxButton(winw, -1, _("&New"));
771 bsWptButtonsInner->Add(btnWptNew, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
772 btnWptNew->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
773 wxCommandEventHandler(RouteManagerDialog::OnWptNewClick),
774 NULL, this);
775
776 btnWptProperties = new wxButton(winw, -1, _("&Properties"));
777 bsWptButtonsInner->Add(btnWptProperties, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
778 btnWptProperties->Connect(
779 wxEVT_COMMAND_BUTTON_CLICKED,
780 wxCommandEventHandler(RouteManagerDialog::OnWptPropertiesClick), NULL,
781 this);
782
783 btnWptZoomto = new wxButton(winw, -1, _("&Center View"));
784 bsWptButtonsInner->Add(btnWptZoomto, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
785 btnWptZoomto->Connect(
786 wxEVT_COMMAND_BUTTON_CLICKED,
787 wxCommandEventHandler(RouteManagerDialog::OnWptZoomtoClick), NULL, this);
788
789 btnWptDelete = new wxButton(winw, -1, _("&Delete"));
790 bsWptButtonsInner->Add(btnWptDelete, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
791 btnWptDelete->Connect(
792 wxEVT_COMMAND_BUTTON_CLICKED,
793 wxCommandEventHandler(RouteManagerDialog::OnWptDeleteClick), NULL, this);
794
795 btnWptGoTo = new wxButton(winw, -1, _("&Go To"));
796 bsWptButtonsInner->Add(btnWptGoTo, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
797 btnWptGoTo->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
798 wxCommandEventHandler(RouteManagerDialog::OnWptGoToClick),
799 NULL, this);
800
801 btnWptExport = new wxButton(winw, -1, _("&Export selected..."));
802 bsWptButtonsInner->Add(btnWptExport, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
803 btnWptExport->Connect(
804 wxEVT_COMMAND_BUTTON_CLICKED,
805 wxCommandEventHandler(RouteManagerDialog::OnWptExportClick), NULL, this);
806
807 btnWptSendToGPS = new wxButton(winw, -1, _("&Send to GPS"));
808 bsWptButtonsInner->Add(btnWptSendToGPS, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
809 btnWptSendToGPS->Connect(
810 wxEVT_COMMAND_BUTTON_CLICKED,
811 wxCommandEventHandler(RouteManagerDialog::OnWptSendToGPSClick), NULL,
812 this);
813
814 btnWptSendToPeer = new wxButton(winw, -1, _("Send to &Peer"));
815 bsWptButtonsInner->Add(btnWptSendToPeer, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
816 btnWptSendToPeer->Connect(
817 wxEVT_COMMAND_BUTTON_CLICKED,
818 wxCommandEventHandler(RouteManagerDialog::OnWptSendToPeerClick), NULL,
819 this);
820
821 bsWptButtonsInner->AddSpacer(10);
822
823 btnWptDeleteAll = new wxButton(winw, -1, _("Delete All"));
824 bsWptButtonsInner->Add(btnWptDeleteAll, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
825 btnWptDeleteAll->Connect(
826 wxEVT_COMMAND_BUTTON_CLICKED,
827 wxCommandEventHandler(RouteManagerDialog::OnWptDeleteAllClick), NULL,
828 this);
829
830 wxBoxSizer *itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
831 itemBoxSizer1->Add(itemBoxSizer5, 0, wxALL | wxEXPAND);
832
833 wxBoxSizer *itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
834 itemBoxSizer5->Add(itemBoxSizer6, 1, wxALL | wxEXPAND);
835
836 btnImport = new wxButton(this, -1, _("I&mport GPX..."));
837 itemBoxSizer6->Add(btnImport, 0, wxALL | wxALIGN_LEFT, DIALOG_MARGIN);
838 btnImport->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
839 wxCommandEventHandler(RouteManagerDialog::OnImportClick),
840 NULL, this);
841 /*
842 * btnExport = new wxButton( this, -1, _("E&xport All...") );
843 * itemBoxSizer6->Add( btnExport, 0, wxALL | wxALIGN_LEFT, DIALOG_MARGIN );
844 * btnExport->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
845 * wxCommandEventHandler(RouteManagerDialog::OnExportClick), NULL,
846 * this );
847 */
848 btnExportViz = new wxButton(this, -1, _("Export All Visible..."));
849 itemBoxSizer6->Add(btnExportViz, 0, wxALL | wxALIGN_LEFT, DIALOG_MARGIN);
850 btnExportViz->Connect(
851 wxEVT_COMMAND_BUTTON_CLICKED,
852 wxCommandEventHandler(RouteManagerDialog::OnExportVizClick), NULL, this);
853
854 // Dialog OK button
855 wxSize sz = ::wxGetDisplaySize();
856 if (sz.y < sz.x) { // landscape
857 itemBoxSizer6->Add(0, 0, 1, wxEXPAND, 5); // Spacer
858 itemBoxSizer6->Add(new wxButton(this, wxID_OK), 0, wxALL, DIALOG_MARGIN);
859 } else {
860 wxStaticLine *staticLine121 = new wxStaticLine(
861 this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL);
862 itemBoxSizer1->Add(staticLine121, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
863
864 wxBoxSizer *itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
865 itemBoxSizer1->Add(itemBoxSizer7, 0, wxEXPAND);
866
867 wxBoxSizer *itemBoxSizer7a = new wxBoxSizer(wxHORIZONTAL);
868 itemBoxSizer7->Add(itemBoxSizer7a, 1, wxEXPAND);
869
870 itemBoxSizer7a->AddStretchSpacer();
871 itemBoxSizer7a->Add(new wxButton(this, wxID_OK), 0, wxRIGHT | wxALIGN_RIGHT,
872 DIALOG_MARGIN * 4);
873 }
874
875 // Create "Layers" panel
876 m_pPanelLay = new wxPanel(m_pNotebook, wxID_ANY, wxDefaultPosition,
877 wxDefaultSize, wxNO_BORDER | wxTAB_TRAVERSAL);
878 wxBoxSizer *sbsLayers = new wxBoxSizer(wxHORIZONTAL);
879 m_pPanelLay->SetSizer(sbsLayers);
880 m_pNotebook->AddPage(m_pPanelLay, _("Layers"));
881
882 wxBoxSizer *bSizerLayContents;
883 bSizerLayContents = new wxBoxSizer(wxVERTICAL);
884
885 wxFlexGridSizer *fgSizerFilterLay;
886 fgSizerFilterLay = new wxFlexGridSizer(0, 2, 0, 0);
887 fgSizerFilterLay->AddGrowableCol(1);
888 fgSizerFilterLay->SetFlexibleDirection(wxBOTH);
889 fgSizerFilterLay->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
890
891 m_stFilterLay = new wxStaticText(m_pPanelLay, wxID_ANY, _("Filter"),
892 wxDefaultPosition, wxDefaultSize, 0);
893 m_stFilterLay->Wrap(-1);
894 fgSizerFilterLay->Add(m_stFilterLay, 0, wxALL, 5);
895
896 m_tFilterLay = new wxTextCtrl(m_pPanelLay, wxID_ANY, wxEmptyString,
897 wxDefaultPosition, wxDefaultSize, 0);
898 fgSizerFilterLay->Add(m_tFilterLay, 1, wxALL | wxEXPAND, 5);
899
900 bSizerLayContents->Add(fgSizerFilterLay, 0, wxEXPAND, 5);
901 m_tFilterLay->Connect(
902 wxEVT_COMMAND_TEXT_UPDATED,
903 wxCommandEventHandler(RouteManagerDialog::OnFilterChanged), NULL, this);
904
905 m_cbShowAllLay = new wxCheckBox(m_pPanelLay, wxID_ANY, _("Show all layers"));
906 bSizerLayContents->Add(m_cbShowAllLay, 0, wxEXPAND | wxLEFT, 5);
907 m_cbShowAllLay->Connect(
908 wxEVT_COMMAND_CHECKBOX_CLICKED,
909 wxCommandEventHandler(RouteManagerDialog::OnShowAllLayCBClicked), NULL,
910 this);
911
912 m_pLayListCtrl =
913 new wxListCtrl(m_pPanelLay, -1, wxDefaultPosition, wxDefaultSize,
914 wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_SORT_ASCENDING |
915 wxLC_HRULES | wxBORDER_SUNKEN /*|wxLC_VRULES*/);
916#ifdef __ANDROID__
917 m_pLayListCtrl->GetHandle()->setStyleSheet(getAdjustedDialogStyleSheet());
918#endif
919
920 m_pLayListCtrl->Connect(wxEVT_COMMAND_LIST_ITEM_SELECTED,
921 wxListEventHandler(RouteManagerDialog::OnLaySelected),
922 NULL, this);
923 m_pLayListCtrl->Connect(wxEVT_COMMAND_LIST_ITEM_DESELECTED,
924 wxListEventHandler(RouteManagerDialog::OnLaySelected),
925 NULL, this);
926 m_pLayListCtrl->Connect(
927 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
928 wxListEventHandler(RouteManagerDialog::OnLayDefaultAction), NULL, this);
929 m_pLayListCtrl->Connect(
930 wxEVT_LEFT_DOWN,
931 wxMouseEventHandler(RouteManagerDialog::OnLayToggleVisibility), NULL,
932 this);
933 m_pLayListCtrl->Connect(
934 wxEVT_COMMAND_LIST_COL_CLICK,
935 wxListEventHandler(RouteManagerDialog::OnLayColumnClicked), NULL, this);
936 bSizerLayContents->Add(m_pLayListCtrl, 1, wxEXPAND | wxALL, DIALOG_MARGIN);
937 sbsLayers->Add(bSizerLayContents, 1, wxEXPAND, 5);
938
939 m_pLayListCtrl->InsertColumn(colLAYVISIBLE, _T(""), wxLIST_FORMAT_LEFT,
940 4 * char_width);
941 m_pLayListCtrl->InsertColumn(colLAYNAME, _("Layer Name"), wxLIST_FORMAT_LEFT,
942 14 * char_width);
943 m_pLayListCtrl->InsertColumn(colLAYITEMS, _("No. of items"),
944 wxLIST_FORMAT_LEFT, 10 * char_width);
945 m_pLayListCtrl->InsertColumn(colLAYPERSIST, _("Layer type"),
946 wxLIST_FORMAT_LEFT, 10 * char_width);
947
948 wxBoxSizer *bsLayButtons = new wxBoxSizer(wxVERTICAL);
949 sbsLayers->Add(bsLayButtons, 0, wxEXPAND);
950
951 wxScrolledWindow *winl = new wxScrolledWindow(
952 m_pPanelLay, wxID_ANY, wxDefaultPosition, wxDefaultSize,
953 wxNO_BORDER | wxTAB_TRAVERSAL | wxVSCROLL);
954 winl->SetScrollRate(0, 5);
955
956 bsLayButtons->Add(winl, 1, wxALL | wxEXPAND, DIALOG_MARGIN);
957
958 wxBoxSizer *bsLayButtonsInner = new wxBoxSizer(wxVERTICAL);
959 winl->SetSizer(bsLayButtonsInner);
960
961 btnLayNew = new wxButton(winl, -1, _("Create Temporary layer"));
962 bsLayButtonsInner->Add(btnLayNew, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
963 btnLayNew->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
964 wxCommandEventHandler(RouteManagerDialog::OnLayNewClick),
965 NULL, this);
966
967 btnPerLayNew = new wxButton(winl, -1, _("Create Persistent layer"));
968 bsLayButtonsInner->Add(btnPerLayNew, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
969 btnPerLayNew->Connect(
970 wxEVT_COMMAND_BUTTON_CLICKED,
971 wxCommandEventHandler(RouteManagerDialog::OnPerLayNewClick), NULL, this);
972
973 btnLayDelete = new wxButton(winl, -1, _("&Delete"));
974 bsLayButtonsInner->Add(btnLayDelete, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
975 btnLayDelete->Connect(
976 wxEVT_COMMAND_BUTTON_CLICKED,
977 wxCommandEventHandler(RouteManagerDialog::OnLayDeleteClick), NULL, this);
978
979 cbLayToggleChart = new wxCheckBox(winl, -1, _("Show on chart"));
980 bsLayButtonsInner->Add(cbLayToggleChart, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
981 cbLayToggleChart->Connect(
982 wxEVT_COMMAND_CHECKBOX_CLICKED,
983 wxCommandEventHandler(RouteManagerDialog::OnLayToggleChartClick), NULL,
984 this);
985
986 cbLayToggleNames =
987 new wxCheckBox(winl, -1, _("Show WPT names"), wxDefaultPosition,
988 wxDefaultSize, wxCHK_3STATE);
989
990 bsLayButtonsInner->Add(cbLayToggleNames, 0, wxALL | wxEXPAND, DIALOG_MARGIN);
991 cbLayToggleNames->Connect(
992 wxEVT_COMMAND_CHECKBOX_CLICKED,
993 wxCommandEventHandler(RouteManagerDialog::OnLayToggleNamesClick), NULL,
994 this);
995
996 cbLayToggleListing = new wxCheckBox(winl, -1, _("List contents"));
997 bsLayButtonsInner->Add(cbLayToggleListing, 0, wxALL | wxEXPAND,
998 DIALOG_MARGIN);
999 cbLayToggleListing->Connect(
1000 wxEVT_COMMAND_CHECKBOX_CLICKED,
1001 wxCommandEventHandler(RouteManagerDialog::OnLayToggleListingClick), NULL,
1002 this);
1003
1004 RecalculateSize();
1005
1006 int imageRefSize = m_charWidth * 2; // g_Platform->GetDisplayDPmm() * 4;
1007 wxImageList *imglist = new wxImageList(imageRefSize, imageRefSize, true, 1);
1008
1009 // Load eye icons
1010 wxString UserIconPath = g_Platform->GetSharedDataDir() + _T("uidata") +
1011 wxFileName::GetPathSeparator();
1012 wxImage iconSVG =
1013 LoadSVG(UserIconPath + _T("eye.svg"), imageRefSize, imageRefSize)
1014 .ConvertToImage();
1015 if (iconSVG.IsOk()) {
1016 iconSVG.Resize(wxSize(imageRefSize, imageRefSize),
1017 wxPoint(0, 0)); // Avoid wxImageList size asserts
1018 imglist->Add(wxBitmap(iconSVG));
1019 }
1020
1021 iconSVG = LoadSVG(UserIconPath + _T("eyex.svg"), imageRefSize, imageRefSize)
1022 .ConvertToImage();
1023 if (iconSVG.IsOk()) {
1024 iconSVG.Resize(wxSize(imageRefSize, imageRefSize), wxPoint(0, 0));
1025 imglist->Add(wxBitmap(iconSVG));
1026 }
1027
1028 iconSVG =
1029 LoadSVG(UserIconPath + _T("eyeGray.svg"), imageRefSize, imageRefSize)
1030 .ConvertToImage();
1031 if (iconSVG.IsOk()) {
1032 iconSVG.Resize(wxSize(imageRefSize, imageRefSize), wxPoint(0, 0));
1033 imglist->Add(wxBitmap(iconSVG));
1034 }
1035
1036 m_pRouteListCtrl->AssignImageList(imglist, wxIMAGE_LIST_SMALL);
1037
1038#ifdef __ANDROID__
1039 m_pRouteListCtrl->GetHandle()->setIconSize(QSize(imageRefSize, imageRefSize));
1040#endif
1041
1042 // Assign will handle destroy, Set will not. It's OK, that's what we want
1043 m_pTrkListCtrl->SetImageList(imglist, wxIMAGE_LIST_SMALL);
1044 m_pWptListCtrl->SetImageList(
1045 pWayPointMan->Getpmarkicon_image_list(m_listIconSize),
1046 wxIMAGE_LIST_SMALL);
1047 m_pLayListCtrl->SetImageList(imglist, wxIMAGE_LIST_SMALL);
1048
1049 SetColorScheme();
1050
1051 UpdateLists();
1052
1053 // This should work under Linux :-(
1054 // m_pNotebook->Connect(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
1055 // wxNotebookEventHandler(RouteManagerDialog::OnTabSwitch), NULL, this);
1056
1057 m_bNeedConfigFlush = false;
1058}
1059
1060RouteManagerDialog::~RouteManagerDialog() {
1061 delete m_pRouteListCtrl;
1062 delete m_pTrkListCtrl;
1063 delete m_pWptListCtrl;
1064 delete m_pLayListCtrl;
1065
1066 delete btnRteDelete;
1067 delete btnRteResequence;
1068 delete btnRteExport;
1069 delete btnRteZoomto;
1070 delete btnRteProperties;
1071 delete btnRteActivate;
1072 delete btnRteReverse;
1073 delete btnRteSendToGPS;
1074 delete btnRteDeleteAll;
1075 delete btnTrkNew;
1076 delete btnTrkProperties;
1077 delete btnTrkDelete;
1078 delete btnTrkExport;
1079 delete btnTrkRouteFromTrack;
1080 delete btnTrkDeleteAll;
1081 delete btnWptNew;
1082 delete btnWptProperties;
1083 delete btnWptZoomto;
1084 delete btnWptDelete;
1085 delete btnWptGoTo;
1086 delete btnWptExport;
1087 delete btnWptSendToGPS;
1088 delete btnWptDeleteAll;
1089 delete btnLayNew;
1090 // delete btnLayProperties;
1091 delete cbLayToggleChart;
1092 delete cbLayToggleListing;
1093 delete cbLayToggleNames;
1094 delete btnLayDelete;
1095 delete btnImport;
1096 delete btnExport;
1097 delete btnExportViz;
1098 btnImport = NULL;
1099 btnExport = NULL;
1100 btnExportViz = NULL;
1101
1102 delete m_pNotebook;
1103 instanceFlag = false;
1104}
1105
1106void RouteManagerDialog::RecalculateSize() {
1107 // All of this dialog layout is expandable, so we need to set a specific size
1108 // target for the onscreen display. The size will then be adjusted so that it
1109 // fits within the parent's client area, with some padding
1110
1111 // Get a text height metric for reference
1112 int char_width, char_height;
1113 GetTextExtent(_T("W"), &char_width, &char_height);
1114
1115 wxSize sz;
1116 sz.x = 60 * char_width;
1117 sz.y = 30 * char_height;
1118
1119 wxSize dsize = GetParent()->GetClientSize();
1120 sz.y = wxMin(sz.y, dsize.y);
1121 sz.x = wxMin(sz.x, dsize.x);
1122 SetClientSize(sz);
1123
1124 wxSize fsize = GetSize();
1125 fsize.y = wxMin(fsize.y, dsize.y);
1126 fsize.x = wxMin(fsize.x, dsize.x);
1127 SetSize(fsize);
1128
1129 CentreOnParent();
1130}
1131
1132void RouteManagerDialog::OnClose(wxCloseEvent &event) {
1133#ifdef __WXGTK__
1134 gFrame->Raise();
1135#endif
1136 Hide();
1137 // pRouteManagerDialog = NULL;
1138}
1139
1140void RouteManagerDialog::OnOK(wxCommandEvent &event) {
1141#ifdef __WXGTK__
1142 gFrame->Raise();
1143#endif
1144 Hide();
1145}
1146
1147void RouteManagerDialog::SetColorScheme() { DimeControl(this); }
1148
1149void RouteManagerDialog::OnShowAllRteCBClicked(wxCommandEvent &event) {
1150 bool viz = m_cbShowAllRte->GetValue();
1151 long item = -1;
1152 int item_count = m_pRouteListCtrl->GetItemCount();
1153 bool busy = false;
1154 if (item_count > 50) {
1155 busy = true;
1156 ::wxBeginBusyCursor();
1157 }
1158 for (;;) {
1159 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1160 wxLIST_STATE_DONTCARE);
1161 if (item == -1) break;
1162
1163 Route *pR = (Route *)m_pRouteListCtrl->GetItemData(item);
1164
1165 pR->SetVisible(viz, viz);
1166 pR->SetSharedWPViz(viz);
1167
1168 m_pRouteListCtrl->SetItemImage(item, !viz); // visible
1169
1170 NavObj_dB::GetInstance().UpdateRouteViz(pR);
1171 }
1172
1173 if (busy) ::wxEndBusyCursor();
1174
1175 UpdateWptListCtrlViz();
1176 gFrame->RefreshAllCanvas();
1177}
1178
1179void RouteManagerDialog::OnShowAllWpCBClicked(wxCommandEvent &event) {
1180 bool viz = m_cbShowAllWP->GetValue();
1181 long item = -1;
1182 int item_count = m_pWptListCtrl->GetItemCount();
1183 bool busy = false;
1184 if (item_count > 100) {
1185 busy = true;
1186 ::wxBeginBusyCursor();
1187 }
1188
1189 for (;;) {
1190 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1191 wxLIST_STATE_DONTCARE);
1192 if (item == -1) break;
1193
1194 RoutePoint *pRP = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
1195
1196 if (!pRP->IsSharedInVisibleRoute()) {
1197 pRP->SetVisible(viz);
1198 } else
1199 pRP->SetVisible(true);
1200
1201 m_pWptListCtrl->SetItemImage(item, RoutePointGui(*pRP).GetIconImageIndex());
1202 NavObj_dB::GetInstance().UpdateDBRoutePointViz(pRP);
1203 }
1204
1205 if (busy) ::wxEndBusyCursor();
1206
1207 gFrame->RefreshAllCanvas();
1208}
1209
1210void RouteManagerDialog::OnShowAllTrkCBClicked(wxCommandEvent &event) {
1211 bool viz = m_cbShowAllTrk->GetValue();
1212 long item = -1;
1213 for (;;) {
1214 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1215 wxLIST_STATE_DONTCARE);
1216 if (item == -1) break;
1217
1218 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
1219
1220 track->SetVisible(viz);
1221 m_pTrkListCtrl->SetItemImage(item, track->IsVisible() ? 0 : 1);
1222 }
1223
1224 gFrame->RefreshAllCanvas();
1225}
1226
1227void RouteManagerDialog::OnShowAllLayCBClicked(wxCommandEvent &event) {
1228 bool viz = m_cbShowAllLay->GetValue();
1229 long item = -1;
1230 for (;;) {
1231 item = m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1232 wxLIST_STATE_DONTCARE);
1233 if (item == -1) break;
1234
1235 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(item);
1236
1237 layer->SetVisibleOnChart(viz);
1238 m_pLayListCtrl->SetItemImage(item, layer->IsVisibleOnChart() ? 0 : 1);
1239
1240 ToggleLayerContentsOnChart(layer);
1241 }
1242
1243 gFrame->RefreshAllCanvas();
1244}
1245
1246void RouteManagerDialog::UpdateRouteListCtrl() {
1247 // if an item was selected, make it selected again if it still exist
1248 long item = -1;
1249 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1250 wxLIST_STATE_SELECTED);
1251 wxUIntPtr selected_id = wxUIntPtr(0);
1252 if (item != -1) selected_id = m_pRouteListCtrl->GetItemData(item);
1253
1254 // Delete existing items
1255 m_pRouteListCtrl->DeleteAllItems();
1256
1257 // then add routes to the listctrl
1258 RouteList::iterator it;
1259 int index = 0;
1260 int list_index = 0;
1261 bool bpartialViz = false;
1262
1263 for (it = (*pRouteList).begin(); it != (*pRouteList).end(); ++it, ++index) {
1264 if (!(*it)->IsListed()) continue;
1265
1266 if (!(*it)->GetName().Upper().Contains(m_tFilterRte->GetValue().Upper())) {
1267 continue;
1268 }
1269
1270 wxListItem li;
1271 li.SetId(list_index);
1272 li.SetImage((*it)->IsVisible() ? 0 : 1);
1273 li.SetData(*it);
1274 li.SetText(_T(""));
1275 li.SetAlign(wxLIST_FORMAT_LEFT);
1276
1277 if ((*it)->m_bRtIsActive) {
1278 wxFont font = *wxNORMAL_FONT;
1279 font.SetWeight(wxFONTWEIGHT_BOLD);
1280 li.SetFont(font);
1281 }
1282
1283 long idx = m_pRouteListCtrl->InsertItem(li);
1284
1285 wxString name = (*it)->m_RouteNameString;
1286 if (name.IsEmpty()) name = _("(Unnamed Route)");
1287 m_pRouteListCtrl->SetItem(idx, rmROUTENAME, name);
1288
1289 wxString startend = (*it)->m_RouteStartString;
1290 if (!(*it)->m_RouteEndString.IsEmpty())
1291 startend.append(_(" - ") + (*it)->m_RouteEndString);
1292 m_pRouteListCtrl->SetItem(idx, rmROUTEDESC, startend);
1293
1294 wxListItem lic;
1295 lic.SetId(list_index);
1296 lic.SetColumn(1);
1297 lic.SetAlign(wxLIST_FORMAT_LEFT);
1298 m_pRouteListCtrl->SetItem(lic);
1299
1300 lic.SetColumn(2);
1301 lic.SetAlign(wxLIST_FORMAT_LEFT);
1302 m_pRouteListCtrl->SetItem(lic);
1303
1304 // Keep track if any are invisible
1305 if (!(*it)->IsVisible()) bpartialViz = true;
1306
1307 list_index++;
1308 }
1309
1310 m_pRouteListCtrl->SortItems(SortRoutesOnName, (wxIntPtr)NULL);
1311
1312 m_pRouteListCtrl->SetColumnWidth(0, 4 * m_charWidth);
1313
1314 // restore selection if possible
1315 // NOTE this will select a different item, if one is deleted
1316 // (the next route will get that index).
1317 if (selected_id != wxUIntPtr(0)) {
1318 item = m_pRouteListCtrl->FindItem(-1, selected_id);
1319 m_pRouteListCtrl->SetItemState(
1320 item, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
1321 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
1322 }
1323
1324 if ((m_lastRteItem >= 0) && (m_pRouteListCtrl->GetItemCount()))
1325 m_pRouteListCtrl->EnsureVisible(m_lastRteItem);
1326 UpdateRteButtons();
1327
1328 // If any route is invisible, then "show all" cb must be clear.
1329 m_cbShowAllRte->SetValue(!bpartialViz);
1330}
1331
1332void RouteManagerDialog::UpdateRteButtons() {
1333 // enable/disable buttons
1334 long selected_index_index =
1335 m_pRouteListCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1336 bool enable1 = m_pRouteListCtrl->GetSelectedItemCount() == 1;
1337 bool enablemultiple = m_pRouteListCtrl->GetSelectedItemCount() >= 1;
1338
1339 m_lastRteItem = selected_index_index;
1340
1341 btnRteDelete->Enable(m_pRouteListCtrl->GetSelectedItemCount() > 0);
1342 btnRteZoomto->Enable(enable1);
1343 btnRteProperties->Enable(enable1);
1344 btnRteReverse->Enable(enable1);
1345 btnRteExport->Enable(enablemultiple);
1346 btnRteResequence->Enable(enable1);
1347 btnRteSendToGPS->Enable(enable1);
1348 btnRteDeleteAll->Enable(m_pRouteListCtrl->GetItemCount() > 0);
1349 btnRteSendToPeer->Enable(enablemultiple);
1350
1351 // set activate button text
1352 Route *route = NULL;
1353 if (enable1)
1354 route = (Route *)m_pRouteListCtrl->GetItemData(selected_index_index);
1355
1356 if (!g_pRouteMan->IsAnyRouteActive()) {
1357 btnRteActivate->Enable(enable1);
1358 if (enable1) btnRteActivate->SetLabel(_("Activate"));
1359
1360 } else {
1361 if (enable1) {
1362 if (route && route->m_bRtIsActive) {
1363 btnRteActivate->Enable(enable1);
1364 btnRteActivate->SetLabel(_("Deactivate"));
1365 } else
1366 btnRteActivate->Enable(false);
1367 } else
1368 btnRteActivate->Enable(false);
1369 }
1370}
1371
1372void RouteManagerDialog::MakeAllRoutesInvisible() {
1373 RouteList::iterator it;
1374 long index = 0;
1375 for (it = (*pRouteList).begin(); it != (*pRouteList).end(); ++it, ++index) {
1376 if ((*it)->IsVisible()) { // avoid config updating as much as possible!
1377 (*it)->SetVisible(false);
1378 m_pRouteListCtrl->SetItemImage(m_pRouteListCtrl->FindItem(-1, index),
1379 1); // Likely not same order :0
1380 NavObj_dB::GetInstance().UpdateRoute(*it);
1381 }
1382 }
1383}
1384
1385void RouteManagerDialog::ZoomtoRoute(Route *route) {
1386 // Calculate bbox center
1387 LLBBox RBBox = route->GetBBox();
1388 double clat = (RBBox.GetMinLat() + RBBox.GetMaxLat()) / 2;
1389 double clon = (RBBox.GetMinLon() + RBBox.GetMaxLon()) / 2;
1390
1391 // Calculate ppm
1392 double rw, rh, ppm; // route width, height, final ppm scale to use
1393 int ww, wh; // chart window width, height
1394 // route bbox width in nm
1395 DistanceBearingMercator(RBBox.GetMinLat(), RBBox.GetMinLon(),
1396 RBBox.GetMinLat(), RBBox.GetMaxLon(), NULL, &rw);
1397 // route bbox height in nm
1398 DistanceBearingMercator(RBBox.GetMinLat(), RBBox.GetMinLon(),
1399 RBBox.GetMaxLat(), RBBox.GetMinLon(), NULL, &rh);
1400
1401 if (gFrame->GetFocusCanvas()) {
1402 gFrame->GetFocusCanvas()->GetSize(&ww, &wh);
1403 ppm = wxMin(ww / (rw * 1852), wh / (rh * 1852)) * (100 - fabs(clat)) / 90;
1404 ppm = wxMin(ppm, 1.0);
1405
1406 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), clat, clon, ppm);
1407 }
1408
1409 m_bNeedConfigFlush = true;
1410}
1411
1412// BEGIN Event handlers
1413void RouteManagerDialog::OnRteDeleteClick(wxCommandEvent &event) {
1414 int count = m_pRouteListCtrl->GetSelectedItemCount();
1415 bool confirmed = RouteGui::OnDelete(this, count);
1416
1417 if (confirmed && count > 0) {
1418 ::wxBeginBusyCursor();
1419 RouteList list;
1420
1421 gFrame->CancelAllMouseRoute();
1422 m_bNeedConfigFlush = true;
1423
1424 long item = -1;
1425 for (;;) {
1426 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1427 wxLIST_STATE_SELECTED);
1428 if (item == -1) break;
1429
1430 Route *proute_to_delete = (Route *)m_pRouteListCtrl->GetItemData(item);
1431
1432 if (proute_to_delete) list.Append(proute_to_delete);
1433 }
1434
1435 for (unsigned int i = 0; i < list.GetCount(); i++) {
1436 Route *route = list.Item(i)->GetData();
1437 if (route) {
1438 NavObj_dB::GetInstance().DeleteRoute(route);
1439 g_pRouteMan->DeleteRoute(route);
1440 }
1441 }
1442
1443 m_lastRteItem = -1;
1444 UpdateRouteListCtrl();
1445 UpdateTrkListCtrl();
1446
1447 gFrame->InvalidateAllCanvasUndo();
1448 gFrame->RefreshAllCanvas();
1449 ::wxEndBusyCursor();
1450 }
1451}
1452
1453void RouteManagerDialog::OnRteDeleteAllClick(wxCommandEvent &event) {
1454 int dialog_ret =
1455 OCPNMessageBox(this, _("Are you sure you want to delete <ALL> routes?"),
1456 wxString(_("OpenCPN Alert")), wxYES_NO);
1457
1458 if (dialog_ret == wxID_YES) {
1459 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
1460
1461 gFrame->CancelAllMouseRoute();
1462
1463 g_pRouteMan->DeleteAllRoutes();
1464
1465 m_lastRteItem = -1;
1466 UpdateRouteListCtrl();
1467
1468 // Also need to update the track list control, since routes and tracks
1469 // share a common global list (pRouteList)
1470 UpdateTrkListCtrl();
1471
1472 if (pRoutePropDialog) pRoutePropDialog->Hide();
1473 gFrame->InvalidateAllCanvasUndo();
1474 gFrame->RefreshAllCanvas();
1475
1476 m_bNeedConfigFlush = true;
1477 }
1478}
1479
1480void RouteManagerDialog::OnRtePropertiesClick(wxCommandEvent &event) {
1481 // Show routeproperties dialog for selected route
1482 long item = -1;
1483 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1484 wxLIST_STATE_SELECTED);
1485 if (item == -1) return;
1486
1487 Route *route = (Route *)m_pRouteListCtrl->GetItemData(item);
1488
1489 if (!route) return;
1490
1491 pRoutePropDialog = RoutePropDlgImpl::getInstance(GetParent());
1492
1493 pRoutePropDialog->SetRouteAndUpdate(route);
1494
1495 if (!pRoutePropDialog->IsShown()) pRoutePropDialog->Show();
1496
1497 pRoutePropDialog->Raise();
1498
1499 m_bNeedConfigFlush = true;
1500}
1501
1502void RouteManagerDialog::OnRteZoomtoClick(wxCommandEvent &event) {
1503 // Zoom into the bounding box of the selected route
1504 long item = -1;
1505 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1506 wxLIST_STATE_SELECTED);
1507 if (item == -1) return;
1508
1509 // optionally make this route exclusively visible
1510 if (m_bCtrlDown) MakeAllRoutesInvisible();
1511
1512 Route *route = (Route *)m_pRouteListCtrl->GetItemData(item);
1513
1514 if (!route) return;
1515
1516 // Ensure route is visible
1517 if (!route->IsVisible()) {
1518 route->SetVisible(true);
1519 m_pRouteListCtrl->SetItemImage(item, route->IsVisible() ? 0 : 1);
1520 NavObj_dB::GetInstance().UpdateRoute(route);
1521 }
1522
1523 ZoomtoRoute(route);
1524}
1525
1526void RouteManagerDialog::OnRteReverseClick(wxCommandEvent &event) {
1527 // Reverse selected route
1528 long item = -1;
1529 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1530 wxLIST_STATE_SELECTED);
1531 if (item == -1) return;
1532
1533 Route *route = (Route *)m_pRouteListCtrl->GetItemData(item);
1534
1535 if (!route) return;
1536 if (route->m_bIsInLayer) return;
1537
1538 int ask_return = OCPNMessageBox(this, g_pRouteMan->GetRouteReverseMessage(),
1539 _("Rename Waypoints?"), wxYES_NO | wxCANCEL);
1540 if (ask_return != wxID_CANCEL) {
1541 bool rename = (ask_return == wxID_YES);
1542
1543 pSelect->DeleteAllSelectableRouteSegments(route);
1544 route->Reverse(rename);
1545 pSelect->AddAllSelectableRouteSegments(route);
1546
1547 // update column 2 - create a UpdateRouteItem(index) instead?
1548 wxString startend = route->m_RouteStartString;
1549 if (!route->m_RouteEndString.IsEmpty())
1550 startend.append(_(" - ") + route->m_RouteEndString);
1551 m_pRouteListCtrl->SetItem(item, 2, startend);
1552
1553 NavObj_dB::GetInstance().UpdateRoute(route);
1554
1555 gFrame->RefreshAllCanvas();
1556 }
1557
1558 m_bNeedConfigFlush = true;
1559}
1560
1561void RouteManagerDialog::OnRteExportClick(wxCommandEvent &event) {
1562 RouteList list;
1563
1564 wxString suggested_name = _T("routes");
1565
1566 long item = -1;
1567 for (;;) {
1568 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1569 wxLIST_STATE_SELECTED);
1570 if (item == -1) break;
1571
1572 Route *proute_to_export = (Route *)m_pRouteListCtrl->GetItemData(item);
1573
1574 if (proute_to_export) {
1575 list.Append(proute_to_export);
1576 if (proute_to_export->m_RouteNameString != wxEmptyString)
1577 suggested_name = proute_to_export->m_RouteNameString;
1578 }
1579 }
1580
1581 ExportGPXRoutes(this, &list, suggested_name);
1582}
1583
1584void RouteManagerDialog::OnRteResequenceClick(wxCommandEvent &event) {
1585 long item = -1;
1586 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1587 wxLIST_STATE_SELECTED);
1588 if (item == -1) return;
1589
1590 Route *route = (Route *)m_pRouteListCtrl->GetItemData(item);
1591
1592 if (!route) return;
1593 if (route->m_bIsInLayer) return;
1594 route->RenameRoutePoints();
1595}
1596
1597void RouteManagerDialog::OnRteSendToPeerClick(wxCommandEvent &event) {
1598 std::vector<Route *> list;
1599 long item = -1;
1600 for (;;) {
1601 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1602 wxLIST_STATE_SELECTED);
1603 if (item == -1) break;
1604
1605 Route *proute = (Route *)m_pRouteListCtrl->GetItemData(item);
1606
1607 if (proute) {
1608 list.push_back(proute);
1609 }
1610 }
1611 if (!list.empty()) {
1612 SendToPeerDlg dlg;
1613 for (auto r : list) {
1614 dlg.SetRoute(r);
1615 }
1616
1617 // Perform initial scan, if necessary
1618
1619 // Check for stale cache...
1620 MdnsCache::GetInstance().Validate();
1621 if (MdnsCache::GetInstance().GetCache().empty()) dlg.SetScanOnCreate(true);
1622
1623 dlg.SetScanTime(5); // seconds
1624 dlg.Create(NULL, -1, _("Send Route(s) to OpenCPN Peer") + _T( "..." ),
1625 _T(""));
1626 dlg.ShowModal();
1627 }
1628}
1629
1630void RouteManagerDialog::OnWptSendToPeerClick(wxCommandEvent &event) {
1631 std::vector<RoutePoint *> list;
1632 long item = -1;
1633 for (;;) {
1634 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1635 wxLIST_STATE_SELECTED);
1636 if (item == -1) break;
1637
1638 RoutePoint *proutep = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
1639
1640 if (proutep) {
1641 list.push_back(proutep);
1642 }
1643 }
1644 if (!list.empty()) {
1645 SendToPeerDlg dlg;
1646 for (auto r : list) {
1647 dlg.SetWaypoint(r);
1648 }
1649
1650 // Perform initial scan, if necessary
1651
1652 // Check for stale cache...
1653 MdnsCache::GetInstance().Validate();
1654 if (MdnsCache::GetInstance().GetCache().empty()) dlg.SetScanOnCreate(true);
1655
1656 dlg.SetScanTime(5); // seconds
1657 dlg.Create(NULL, -1, _("Send Waypoint(s) to OpenCPN Peer") + _T( "..." ),
1658 _T(""));
1659 dlg.ShowModal();
1660 }
1661}
1662
1663void RouteManagerDialog::OnTrkSendToPeerClick(wxCommandEvent &event) {
1664 std::vector<Track *> list;
1665 long item = -1;
1666 for (;;) {
1667 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1668 wxLIST_STATE_SELECTED);
1669 if (item == -1) break;
1670
1671 Track *ptrk = (Track *)m_pTrkListCtrl->GetItemData(item);
1672
1673 if (ptrk) {
1674 list.push_back(ptrk);
1675 }
1676 }
1677 if (!list.empty()) {
1678 SendToPeerDlg dlg;
1679 for (auto r : list) {
1680 dlg.SetTrack(r);
1681 }
1682
1683 // Perform initial scan, if necessary
1684
1685 // Check for stale cache...
1686 MdnsCache::GetInstance().Validate();
1687 if (MdnsCache::GetInstance().GetCache().empty()) dlg.SetScanOnCreate(true);
1688
1689 dlg.SetScanTime(5); // seconds
1690 dlg.Create(NULL, -1, _("Send Track(s) to OpenCPN Peer") + _T( "..." ),
1691 _T(""));
1692 dlg.ShowModal();
1693 }
1694}
1695
1696void RouteManagerDialog::OnRteActivateClick(wxCommandEvent &event) {
1697 // Activate the selected route, unless it already is
1698 long item = -1;
1699 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1700 wxLIST_STATE_SELECTED);
1701 if (item == -1) return;
1702
1703 if (m_bCtrlDown) MakeAllRoutesInvisible();
1704
1705 Route *route = (Route *)m_pRouteListCtrl->GetItemData(item);
1706
1707 if (!route) return;
1708
1709 if (!route->m_bRtIsActive) {
1710 if (!route->IsVisible()) {
1711 route->SetVisible(true);
1712 m_pRouteListCtrl->SetItemImage(item, 0, 0);
1713 }
1714
1715 ZoomtoRoute(route);
1716
1717 RoutePoint *best_point =
1718 g_pRouteMan->FindBestActivatePoint(route, gLat, gLon, gCog, gSog);
1719 g_pRouteMan->ActivateRoute(route, best_point);
1720 // g_pRouteMan->ActivateRoute(route);
1721 } else
1722 g_pRouteMan->DeactivateRoute();
1723
1724 UpdateRouteListCtrl();
1725
1726 NavObj_dB::GetInstance().UpdateRoute(route);
1727
1728 gFrame->RefreshAllCanvas();
1729
1730 // btnRteActivate->SetLabel(route->m_bRtIsActive ? _("Deactivate") :
1731 // _("Activate"));
1732
1733 m_bNeedConfigFlush = true;
1734}
1735
1736void RouteManagerDialog::OnRteToggleVisibility(wxMouseEvent &event) {
1737 wxPoint pos = event.GetPosition();
1738 int flags = 0;
1739 long clicked_index = m_pRouteListCtrl->HitTest(pos, flags);
1740
1741 // Clicking Visibility column?
1742 if (clicked_index > -1 &&
1743 event.GetX() < m_pRouteListCtrl->GetColumnWidth(rmVISIBLE)) {
1744 // Process the clicked item
1745 Route *route = (Route *)m_pRouteListCtrl->GetItemData(clicked_index);
1746
1747 route->SetVisible(!route->IsVisible());
1748
1749 m_pRouteListCtrl->SetItemImage(clicked_index, route->IsVisible() ? 0 : 1);
1750
1751 ::wxBeginBusyCursor();
1752
1753 NavObj_dB::GetInstance().UpdateRoute(route);
1754
1755 gFrame->RefreshAllCanvas();
1756
1757 // We need to update the waypoint list control since the visibility of
1758 // shared waypoints might have changed.
1759 if (g_pRouteMan->DoesRouteContainSharedPoints(route))
1760 UpdateWptListCtrlViz();
1761
1762 // Manage "show all" checkbox
1763 bool viz = true;
1764 long item = -1;
1765 for (;;) {
1766 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1767 wxLIST_STATE_DONTCARE);
1768 if (item == -1) break;
1769
1770 Route *pR = (Route *)m_pRouteListCtrl->GetItemData(item);
1771
1772 if (!pR->IsVisible()) {
1773 viz = false;
1774 break;
1775 }
1776 }
1777 m_cbShowAllRte->SetValue(viz);
1778
1779 ::wxEndBusyCursor();
1780 }
1781
1782 // Allow wx to process...
1783 event.Skip();
1784}
1785
1786void RouteManagerDialog::OnRteBtnLeftDown(wxMouseEvent &event) {
1787 m_bCtrlDown = event.ControlDown();
1788 event.Skip();
1789}
1790
1791void RouteManagerDialog::OnRteSelected(wxListEvent &event) {
1792 long clicked_index = event.m_itemIndex;
1793 // Process the clicked item
1794 Route *route = (Route *)m_pRouteListCtrl->GetItemData(clicked_index);
1795 // route->SetVisible(!route->IsVisible());
1796 m_pRouteListCtrl->SetItemImage(clicked_index, route->IsVisible() ? 0 : 1);
1797
1798 gFrame->RefreshAllCanvas();
1799
1800 UpdateRteButtons();
1801}
1802
1803void RouteManagerDialog::OnRteColumnClicked(wxListEvent &event) {
1804 if (event.m_col == 1) {
1805 sort_route_name_dir++;
1806
1807 m_pRouteListCtrl->SortItems(SortRoutesOnName, (wxIntPtr)NULL);
1808 } else if (event.m_col == 2) {
1809 sort_route_to_dir++;
1810 m_pRouteListCtrl->SortItems(SortRoutesOnTo, (wxIntPtr)NULL);
1811 }
1812}
1813
1814void RouteManagerDialog::OnRteSendToGPSClick(wxCommandEvent &event) {
1815 long item = -1;
1816 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1817 wxLIST_STATE_SELECTED);
1818 if (item == -1) return;
1819
1820 Route *route = (Route *)m_pRouteListCtrl->GetItemData(item);
1821
1822 if (!route) return;
1823
1824 SendToGpsDlg *pdlg = new SendToGpsDlg();
1825 pdlg->SetRoute(route);
1826
1827 wxFont fo = GetOCPNGUIScaledFont(_("Dialog"));
1828 pdlg->SetFont(fo);
1829
1830 wxString source;
1831 pdlg->Create(NULL, -1, _("Send to GPS") + _T( "..." ), source);
1832
1833#ifdef __WXOSX__
1834 HideWithEffect(wxSHOW_EFFECT_BLEND);
1835#endif
1836
1837 pdlg->ShowModal();
1838
1839#ifdef __WXOSX__
1840 ShowWithEffect(wxSHOW_EFFECT_BLEND);
1841#endif
1842
1843 pdlg->Destroy();
1844}
1845
1846void RouteManagerDialog::OnRteDefaultAction(wxListEvent &event) {
1847 wxCommandEvent evt;
1848 OnRtePropertiesClick(evt);
1849}
1850
1851void RouteManagerDialog::OnTrkDefaultAction(wxListEvent &event) {
1852 wxCommandEvent evt;
1853 OnTrkPropertiesClick(evt);
1854}
1855
1856void RouteManagerDialog::OnTrkRightClick(wxListEvent &event) {
1857 wxMenu menu;
1858 wxMenuItem *mergeItem = menu.Append(TRACK_MERGE, _("&Merge Selected Tracks"));
1859 mergeItem->Enable(m_pTrkListCtrl->GetSelectedItemCount() > 1);
1860 wxMenuItem *cleanItem = menu.Append(TRACK_CLEAN, _("Reduce Data..."));
1861 cleanItem->Enable(m_pTrkListCtrl->GetSelectedItemCount() == 1);
1862 wxMenuItem *copyItem = menu.Append(TRACK_COPY_TEXT, _("&Copy as text"));
1863 copyItem->Enable(m_pTrkListCtrl->GetSelectedItemCount() > 0);
1864 PopupMenu(&menu);
1865}
1866
1867static bool CompareTracks(Track *track1, Track *track2) {
1868 TrackPoint *start1 = track1->GetPoint(0);
1869 TrackPoint *start2 = track2->GetPoint(0);
1870 return start1->GetCreateTime() < start2->GetCreateTime();
1871}
1872
1873void RouteManagerDialog::OnTrkMenuSelected(wxCommandEvent &event) {
1874 int item = -1;
1875
1876 switch (event.GetId()) {
1877 case TRACK_CLEAN: {
1878 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1879 wxLIST_STATE_SELECTED);
1880 if (item == -1) break;
1881 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
1882 if (track->IsRunning()) {
1883 wxBell();
1884 break;
1885 }
1886
1887 const wxString choices[] = {_T("5.0"), _T("10.0"), _T("20.0"), _T("50.0"),
1888 _T("100.0")};
1889
1890 wxSingleChoiceDialog precisionDlg(this,
1891 _("Select the maximum error allowed "
1892 "(in meters)\nafter data reduction:"),
1893 _("Reduce Data Precision"), 5, choices);
1894#ifdef __WXOSX__
1895 precisionDlg.ShowWindowModal();
1896 while (precisionDlg.IsShown()) {
1897 wxMilliSleep(10);
1898 wxYield();
1899 }
1900 int result = precisionDlg.GetReturnCode();
1901#else
1902 int result = precisionDlg.ShowModal();
1903#endif
1904 if (result == wxID_CANCEL) break;
1905 double precision = 5.0;
1906 switch (precisionDlg.GetSelection()) {
1907 case 0:
1908 precision = 5.0;
1909 break;
1910 case 1:
1911 precision = 10.0;
1912 break;
1913 case 2:
1914 precision = 20.0;
1915 break;
1916 case 3:
1917 precision = 50.0;
1918 break;
1919 case 4:
1920 precision = 100.0;
1921 break;
1922 }
1923
1924 int pointsBefore = track->GetnPoints();
1925
1926 int reduction = track->Simplify(precision);
1927 gFrame->Refresh(false);
1928
1929 reduction = 100 * reduction / pointsBefore;
1930 wxString msg = wxString::Format(
1931 _("The amount of data used by the track\n was reduced by %d%%."),
1932 reduction);
1933 OCPNMessageBox(this, msg, _("OpenCPN info"), wxICON_INFORMATION | wxOK);
1934
1935 UpdateTrkListCtrl();
1936 UpdateRouteListCtrl();
1937
1938 break;
1939 }
1940
1941 case TRACK_COPY_TEXT: {
1942 wxString csvString;
1943 while (1) {
1944 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1945 wxLIST_STATE_SELECTED);
1946 if (item == -1) break;
1947 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
1948 csvString << track->GetName() << _T("\t")
1949 << wxString::Format(_T("%.1f"), track->Length()) << _T("\t")
1950 << _T("\n");
1951 }
1952
1953 if (wxTheClipboard->Open()) {
1954 wxTextDataObject *data = new wxTextDataObject;
1955 data->SetText(csvString);
1956 wxTheClipboard->SetData(data);
1957 wxTheClipboard->Close();
1958 }
1959
1960 break;
1961 }
1962
1963 case TRACK_MERGE: {
1964 Track *targetTrack = NULL;
1965 TrackPoint *tPoint;
1966 TrackPoint *newPoint;
1967 TrackPoint *lastPoint;
1968 std::vector<Track *> mergeList;
1969 std::vector<Track *> deleteList;
1970 bool runningSkipped = false;
1971
1972 ::wxBeginBusyCursor();
1973
1974 while (1) {
1975 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1976 wxLIST_STATE_SELECTED);
1977 if (item == -1) break;
1978 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
1979 mergeList.push_back(track);
1980 }
1981
1982 if (!mergeList.size()) {
1983 ::wxEndBusyCursor();
1984 break;
1985 }
1986
1987 std::sort(mergeList.begin(), mergeList.end(), CompareTracks);
1988
1989 targetTrack = mergeList[0];
1990 lastPoint = targetTrack->GetLastPoint();
1991
1992 for (auto const &mergeTrack : mergeList) {
1993 if (mergeTrack == *mergeList.begin()) continue;
1994
1995 if (mergeTrack->IsRunning()) {
1996 runningSkipped = true;
1997 continue;
1998 }
1999
2000 for (int i = 0; i < mergeTrack->GetnPoints(); i++) {
2001 tPoint = mergeTrack->GetPoint(i);
2002 newPoint = new TrackPoint(tPoint->m_lat, tPoint->m_lon,
2003 tPoint->GetCreateTime());
2004
2005 targetTrack->AddPoint(newPoint);
2006 NavObj_dB::GetInstance().AddTrackPoint(targetTrack, newPoint);
2007
2008 pSelect->AddSelectableTrackSegment(lastPoint->m_lat, lastPoint->m_lon,
2009 newPoint->m_lat, newPoint->m_lon,
2010 lastPoint, newPoint, targetTrack);
2011 lastPoint = newPoint;
2012 }
2013 deleteList.push_back(mergeTrack);
2014 }
2015
2016 for (auto const &deleteTrack : deleteList) {
2017 g_pAIS->DeletePersistentTrack(deleteTrack);
2018 NavObj_dB::GetInstance().DeleteTrack(deleteTrack);
2019 RoutemanGui(*g_pRouteMan).DeleteTrack(deleteTrack);
2020 }
2021
2022 mergeList.clear();
2023 deleteList.clear();
2024
2025 ::wxEndBusyCursor();
2026
2027 UpdateTrkListCtrl();
2028 UpdateRouteListCtrl();
2029 gFrame->RefreshAllCanvas();
2030
2031 if (runningSkipped) {
2032 wxMessageDialog skipWarning(
2033 this,
2034 _("The currently running Track was not merged.\nYou can merge it "
2035 "later when it is completed."),
2036 _T("Warning"), wxCANCEL | wxICON_WARNING);
2037 skipWarning.ShowModal();
2038 }
2039
2040 break;
2041 }
2042 }
2043}
2044
2045void RouteManagerDialog::UpdateTrkListCtrl() {
2046 // if an item was selected, make it selected again if it still exist
2047 long item = -1;
2048 item =
2049 m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2050
2051 wxUIntPtr selected_id = wxUIntPtr(0);
2052 if (item != -1) selected_id = m_pTrkListCtrl->GetItemData(item);
2053
2054 // Delete existing items
2055 m_pTrkListCtrl->DeleteAllItems();
2056
2057 // then add tracks to the listctrl
2058 std::vector<Track *>::iterator it;
2059 int index = 0;
2060 int list_index = 0;
2061 bool bpartialViz = false;
2062
2063 for (Track *trk : g_TrackList) {
2064 if (!trk->IsVisible()) bpartialViz = true;
2065
2066 if (!trk->IsListed()) continue;
2067
2068 if (!trk->GetName(true).Upper().Contains(
2069 m_tFilterTrk->GetValue().Upper())) {
2070 continue;
2071 }
2072
2073 wxListItem li;
2074 li.SetId(list_index);
2075 li.SetImage(trk->IsVisible() ? 0 : 1);
2076 li.SetData(trk);
2077 li.SetText(_T(""));
2078
2079 if (g_pActiveTrack == trk) {
2080 wxFont font = *wxNORMAL_FONT;
2081 font.SetWeight(wxFONTWEIGHT_BOLD);
2082 li.SetFont(font);
2083 }
2084 long idx = m_pTrkListCtrl->InsertItem(li);
2085
2086 m_pTrkListCtrl->SetItem(idx, colTRKNAME, trk->GetName(true));
2087 // Populate the track start date/time, formatted using the global timezone
2088 // settings.
2089 m_pTrkListCtrl->SetItem(idx, colTRKDATE, trk->GetDateTime());
2090
2091 wxString len;
2092 len.Printf(wxT("%5.2f"), trk->Length());
2093 m_pTrkListCtrl->SetItem(idx, colTRKLENGTH, len);
2094
2095 wxListItem lic;
2096 lic.SetId(list_index);
2097 lic.SetColumn(1);
2098 lic.SetAlign(wxLIST_FORMAT_LEFT);
2099 m_pTrkListCtrl->SetItem(lic);
2100
2101 lic.SetColumn(2);
2102 lic.SetAlign(wxLIST_FORMAT_LEFT);
2103 m_pTrkListCtrl->SetItem(lic);
2104
2105 list_index++;
2106 }
2107
2108 switch (sort_track_key) {
2109 case SORT_ON_DISTANCE:
2110 m_pTrkListCtrl->SortItems(SortTracksOnDistance, (wxIntPtr)NULL);
2111 break;
2112 case SORT_ON_DATE:
2113 m_pTrkListCtrl->SortItems(SortTracksOnDate, (wxIntPtr)NULL);
2114 break;
2115 case SORT_ON_NAME:
2116 default:
2117 m_pTrkListCtrl->SortItems(SortTracksOnName, (wxIntPtr)NULL);
2118 break;
2119 }
2120
2121 m_pTrkListCtrl->SetColumnWidth(0, 4 * m_charWidth);
2122
2123 // restore selection if possible
2124 // NOTE this will select a different item, if one is deleted
2125 // (the next route will get that index).
2126 if (selected_id != wxUIntPtr(0)) {
2127 item = m_pTrkListCtrl->FindItem(-1, selected_id);
2128 m_pTrkListCtrl->SetItemState(item,
2129 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
2130 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
2131 }
2132
2133 if ((m_lastTrkItem >= 0) && (m_pTrkListCtrl->GetItemCount()))
2134 m_pTrkListCtrl->EnsureVisible(m_lastTrkItem);
2135
2136 m_cbShowAllTrk->SetValue(!bpartialViz);
2137 UpdateTrkButtons();
2138}
2139
2140void RouteManagerDialog::OnTrkSelected(wxListEvent &event) {
2141 UpdateTrkButtons();
2142}
2143
2144void RouteManagerDialog::OnTrkColumnClicked(wxListEvent &event) {
2145 if (event.m_col == 1) {
2146 sort_track_key = SORT_ON_NAME;
2147 sort_track_name_dir++;
2148 m_pTrkListCtrl->SortItems(SortTracksOnName, (wxIntPtr)NULL);
2149 } else if (event.m_col == 2) {
2150 sort_track_key = SORT_ON_DISTANCE;
2151 sort_track_len_dir++;
2152 m_pTrkListCtrl->SortItems(SortTracksOnDistance, (wxIntPtr)NULL);
2153 } else if (event.m_col == 3) {
2154 sort_track_key = SORT_ON_DATE;
2155 sort_track_date_dir++;
2156 m_pTrkListCtrl->SortItems(SortTracksOnDate, (wxIntPtr)NULL);
2157 }
2158}
2159
2160void RouteManagerDialog::UpdateTrkButtons() {
2161 long item = -1;
2162 item =
2163 m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2164 int items = m_pTrkListCtrl->GetSelectedItemCount();
2165
2166 m_lastTrkItem = item;
2167
2168 btnTrkProperties->Enable(items == 1);
2169 btnTrkDelete->Enable(items >= 1);
2170 btnTrkExport->Enable(items >= 1);
2171 btnTrkRouteFromTrack->Enable(items == 1);
2172 btnTrkDeleteAll->Enable(m_pTrkListCtrl->GetItemCount() > 0);
2173 btnTrkSendToPeer->Enable(items >= 1);
2174}
2175
2176void RouteManagerDialog::OnTrkToggleVisibility(wxMouseEvent &event) {
2177 wxPoint pos = event.GetPosition();
2178 int flags = 0;
2179 long clicked_index = m_pTrkListCtrl->HitTest(pos, flags);
2180
2181 // Clicking Visibility column?
2182 if (clicked_index > -1 &&
2183 event.GetX() < m_pTrkListCtrl->GetColumnWidth(colTRKVISIBLE)) {
2184 // Process the clicked item
2185 Track *track = (Track *)m_pTrkListCtrl->GetItemData(clicked_index);
2186 if (track) {
2187 track->SetVisible(!track->IsVisible());
2188 m_pTrkListCtrl->SetItemImage(clicked_index, track->IsVisible() ? 0 : 1);
2189 }
2190
2191 // Manage "show all" checkbox
2192 bool viz = true;
2193 long item = -1;
2194 for (;;) {
2195 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2196 wxLIST_STATE_DONTCARE);
2197 if (item == -1) break;
2198
2199 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
2200
2201 if (!track->IsVisible()) {
2202 viz = false;
2203 break;
2204 }
2205 }
2206 m_cbShowAllTrk->SetValue(viz);
2207
2208 gFrame->RefreshAllCanvas();
2209 }
2210
2211 // Allow wx to process...
2212 event.Skip();
2213}
2214
2215void RouteManagerDialog::OnTrkNewClick(wxCommandEvent &event) {
2216 gFrame->TrackOff();
2217 gFrame->TrackOn();
2218
2219 UpdateTrkListCtrl();
2220}
2221
2222void RouteManagerDialog::OnTrkPropertiesClick(wxCommandEvent &event) {
2223 // Show trackproperties dialog for selected track
2224 long item = -1;
2225 item =
2226 m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2227 if (item == -1) return;
2228
2229 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
2230
2231 if (!track) return;
2232
2233 pTrackPropDialog = TrackPropDlg::getInstance(GetParent());
2234 pTrackPropDialog->SetTrackAndUpdate(track);
2235
2236 if (!pTrackPropDialog->IsShown()) pTrackPropDialog->Show();
2237 UpdateTrkListCtrl();
2238
2239 m_bNeedConfigFlush = true;
2240}
2241
2242void RouteManagerDialog::OnTrkDeleteClick(wxCommandEvent &event) {
2243 std::vector<Track *> list;
2244
2245 int answer = OCPNMessageBox(
2246 this, _("Are you sure you want to delete the selected object(s)"),
2247 wxString(_("OpenCPN Alert")), wxYES_NO);
2248 if (answer != wxID_YES) return;
2249
2250 bool busy = false;
2251 if (m_pTrkListCtrl->GetSelectedItemCount()) {
2252 ::wxBeginBusyCursor();
2253 // m_bNeedConfigFlush = true;
2254 busy = true;
2255 }
2256
2257 long item = -1;
2258 for (;;) {
2259 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2260 wxLIST_STATE_SELECTED);
2261 if (item == -1) break;
2262
2263 Track *ptrack_to_delete = (Track *)m_pTrkListCtrl->GetItemData(item);
2264
2265 if (ptrack_to_delete) list.push_back(ptrack_to_delete);
2266 }
2267
2268 if (busy) {
2269 for (unsigned int i = 0; i < list.size(); i++) {
2270 Track *track = list.at(i);
2271 if (track) {
2272 g_pAIS->DeletePersistentTrack(track);
2273 NavObj_dB::GetInstance().DeleteTrack(track);
2274 RoutemanGui(*g_pRouteMan).DeleteTrack(track);
2275 }
2276 }
2277
2278 m_lastTrkItem = -1;
2279 // UpdateRouteListCtrl();
2280 UpdateTrkListCtrl();
2281
2282 gFrame->InvalidateAllCanvasUndo();
2283 gFrame->RefreshAllCanvas();
2284 ::wxEndBusyCursor();
2285 }
2286}
2287
2288void RouteManagerDialog::OnTrkExportClick(wxCommandEvent &event) {
2289 std::vector<Track *> list;
2290 wxString suggested_name = _T("tracks");
2291
2292 long item = -1;
2293 for (;;) {
2294 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2295 wxLIST_STATE_SELECTED);
2296 if (item == -1) break;
2297
2298 Track *ptrack_to_export = (Track *)m_pTrkListCtrl->GetItemData(item);
2299
2300 if (ptrack_to_export) {
2301 list.push_back(ptrack_to_export);
2302 if (ptrack_to_export->GetName() != wxEmptyString)
2303 suggested_name = ptrack_to_export->GetName();
2304 }
2305 }
2306
2307 ExportGPXTracks(this, &list, suggested_name);
2308}
2309
2310void RouteManagerDialog::TrackToRoute(Track *track) {
2311 if (!track) return;
2312 if (track->m_bIsInLayer) return;
2313
2314 wxGenericProgressDialog pprog(_("OpenCPN Converting Track to Route...."),
2315 _("Processing Waypoints..."), 101, NULL,
2316 wxPD_AUTO_HIDE | wxPD_SMOOTH |
2317 wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME |
2318 wxPD_REMAINING_TIME);
2319
2320 ::wxBeginBusyCursor();
2321
2322 Route *route = track->RouteFromTrack(&pprog);
2323
2324 pRouteList->Append(route);
2325
2326 pprog.Update(101, _("Done."));
2327
2328 gFrame->RefreshAllCanvas();
2329
2330 ::wxEndBusyCursor();
2331}
2332
2333void RouteManagerDialog::OnTrkRouteFromTrackClick(wxCommandEvent &event) {
2334 long item = -1;
2335 item =
2336 m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2337 if (item == -1) return;
2338
2339 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
2340
2341 TrackToRoute(track);
2342
2343 UpdateRouteListCtrl();
2344}
2345
2346void RouteManagerDialog::OnTrkDeleteAllClick(wxCommandEvent &event) {
2347 int dialog_ret =
2348 OCPNMessageBox(this, _("Are you sure you want to delete <ALL> tracks?"),
2349 wxString(_("OpenCPN Alert")), wxYES_NO);
2350
2351 if (dialog_ret == wxID_YES) {
2352 RoutemanGui(*g_pRouteMan).DeleteAllTracks();
2353 }
2354
2355 m_lastTrkItem = -1;
2356 m_lastRteItem = -1;
2357
2358 UpdateTrkListCtrl();
2359
2360 // Also need to update the route list control, since routes and tracks
2361 // share a common global list (pRouteList)
2362 UpdateRouteListCtrl();
2363
2364 if (pRoutePropDialog) pRoutePropDialog->Hide();
2365
2366 gFrame->RefreshAllCanvas();
2367
2368 m_bNeedConfigFlush = true;
2369}
2370
2371void RouteManagerDialog::UpdateWptListCtrl(RoutePoint *rp_select,
2372 bool b_retain_sort) {
2373 wxIntPtr selected_id = wxUIntPtr(0);
2374 long item = -1;
2375
2376 if (NULL == rp_select) {
2377 // if an item was selected, make it selected again if it still exists
2378 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2379 wxLIST_STATE_SELECTED);
2380
2381 if (item != -1) selected_id = m_pWptListCtrl->GetItemData(item);
2382 }
2383
2384 // Freshen the image list
2385 m_pWptListCtrl->SetImageList(
2386 pWayPointMan->Getpmarkicon_image_list(m_listIconSize),
2387 wxIMAGE_LIST_SMALL);
2388
2389 m_pWptListCtrl->DeleteAllItems();
2390
2391 wxRoutePointListNode *node = pWayPointMan->GetWaypointList()->GetFirst();
2392
2393 int index = 0;
2394 bool b_anyHidden = false;
2395 while (node) {
2396 RoutePoint *rp = node->GetData();
2397 if (rp && rp->IsListed()) {
2398 if (rp->m_bIsInRoute && !rp->IsShared()) {
2399 node = node->GetNext();
2400 continue;
2401 }
2402
2403 if (!rp->GetName().Upper().Contains(m_tFilterWpt->GetValue().Upper())) {
2404 node = node->GetNext();
2405 continue;
2406 }
2407
2408 wxListItem li;
2409 li.SetId(index);
2410 li.SetImage(RoutePointGui(*rp).GetIconImageIndex());
2411 li.SetData(rp);
2412 li.SetText(_T(""));
2413 long idx = m_pWptListCtrl->InsertItem(li);
2414
2415 wxString scamin = wxString::Format(_T("%i"), (int)rp->GetScaMin());
2416 if (!rp->GetUseSca()) scamin = _("Always");
2417 if (g_bOverruleScaMin) scamin = _("Overruled");
2418 m_pWptListCtrl->SetItem(idx, colWPTSCALE, scamin);
2419
2420 wxString name = rp->GetName();
2421 if (name.IsEmpty()) name = _("(Unnamed Waypoint)");
2422 m_pWptListCtrl->SetItem(idx, colWPTNAME, name);
2423
2424 double dst;
2425 DistanceBearingMercator(rp->m_lat, rp->m_lon, gLat, gLon, NULL, &dst);
2426 wxString dist;
2427 dist.Printf(_T("%5.2f ") + getUsrDistanceUnit(), toUsrDistance(dst));
2428 m_pWptListCtrl->SetItem(idx, colWPTDIST, dist);
2429
2430 if (rp == rp_select) selected_id = (wxIntPtr)rp_select;
2431
2432 wxListItem lic;
2433 lic.SetId(index);
2434 lic.SetColumn(1);
2435 lic.SetAlign(wxLIST_FORMAT_LEFT);
2436 m_pWptListCtrl->SetItem(lic);
2437
2438 lic.SetColumn(2);
2439 lic.SetAlign(wxLIST_FORMAT_LEFT);
2440 m_pWptListCtrl->SetItem(lic);
2441
2442 if (!rp->IsVisible()) b_anyHidden = true;
2443
2444 index++;
2445 }
2446
2447 node = node->GetNext();
2448 }
2449
2450 if (!b_retain_sort) {
2451 m_pWptListCtrl->SortItems(SortWaypointsOnName,
2452 reinterpret_cast<wxIntPtr>(m_pWptListCtrl));
2453 sort_wp_key = SORT_ON_NAME;
2454 } else {
2455 switch (sort_wp_key) {
2456 case SORT_ON_NAME:
2457 m_pWptListCtrl->SortItems(SortWaypointsOnName,
2458 reinterpret_cast<wxIntPtr>(m_pWptListCtrl));
2459 break;
2460 case SORT_ON_DISTANCE:
2461 m_pWptListCtrl->SortItems(SortWaypointsOnDistance,
2462 reinterpret_cast<wxIntPtr>(m_pWptListCtrl));
2463 break;
2464 }
2465 }
2466
2467 if (selected_id != wxUIntPtr(0)) {
2468 item = m_pWptListCtrl->FindItem(-1, selected_id);
2469 m_pWptListCtrl->SetItemState(item,
2470 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
2471 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
2472 }
2473
2474 if ((m_lastWptItem >= 0) && (m_pWptListCtrl->GetItemCount()))
2475 m_pWptListCtrl->EnsureVisible(m_lastWptItem);
2476
2477 if (pWayPointMan->Getpmarkicon_image_list(m_listIconSize)->GetImageCount()) {
2478 int iwidth, iheight;
2479 pWayPointMan->Getpmarkicon_image_list(m_listIconSize)
2480 ->GetSize(0, iwidth, iheight);
2481
2482 m_pWptListCtrl->SetColumnWidth(0, wxMax(iwidth + 4, 4 * m_charWidth));
2483 }
2484
2485 UpdateWptButtons();
2486
2487 m_cbShowAllWP->SetValue(!b_anyHidden);
2488}
2489
2490void RouteManagerDialog::UpdateWptListCtrlViz() {
2491 long item = -1;
2492 for (;;) {
2493 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2494 wxLIST_STATE_DONTCARE);
2495 if (item == -1) break;
2496
2497 RoutePoint *pRP = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2498 int imageIndex = RoutePointGui(*pRP).GetIconImageIndex();
2499
2500 m_pWptListCtrl->SetItemImage(item, imageIndex);
2501 }
2502}
2503
2504void RouteManagerDialog::OnWptDefaultAction(wxListEvent &event) {
2505 wxCommandEvent evt;
2506 OnWptPropertiesClick(evt);
2507}
2508
2509void RouteManagerDialog::OnWptSelected(wxListEvent &event) {
2510 UpdateWptButtons();
2511}
2512
2513void RouteManagerDialog::OnWptColumnClicked(wxListEvent &event) {
2514 if (event.m_col == NAME_COLUMN) {
2515 sort_wp_name_dir++;
2516 m_pWptListCtrl->SortItems(SortWaypointsOnName,
2517 reinterpret_cast<wxIntPtr>(m_pWptListCtrl));
2518 sort_wp_key = SORT_ON_NAME;
2519 } else {
2520 if (event.m_col == DISTANCE_COLUMN) {
2521 sort_wp_len_dir++;
2522 m_pWptListCtrl->SortItems(SortWaypointsOnDistance,
2523 reinterpret_cast<wxIntPtr>(m_pWptListCtrl));
2524 sort_wp_key = SORT_ON_DISTANCE;
2525 }
2526 }
2527 UpdateWptListCtrl();
2528}
2529
2530void RouteManagerDialog::UpdateWptButtons() {
2531 long item = -1;
2532 item =
2533 m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2534 bool enable1 = (m_pWptListCtrl->GetSelectedItemCount() == 1);
2535 bool enablemultiple = (m_pWptListCtrl->GetSelectedItemCount() >= 1);
2536
2537 if (enable1)
2538 m_lastWptItem = item;
2539 else
2540 m_lastWptItem = -1;
2541
2542 // Check selection to see if it is in a layer
2543 // If so, disable the "delete" button
2544 bool b_delete_enable = true;
2545 item = -1;
2546 for (;;) {
2547 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2548 wxLIST_STATE_SELECTED);
2549 if (item == -1) break;
2550
2551 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2552
2553 if (wp && wp->m_bIsInLayer) {
2554 b_delete_enable = false;
2555 break;
2556 }
2557 }
2558
2559 btnWptProperties->Enable(enablemultiple);
2560 btnWptZoomto->Enable(enable1);
2561 btnWptDeleteAll->Enable(m_pWptListCtrl->GetItemCount() > 0);
2562 btnWptDelete->Enable(b_delete_enable && enablemultiple);
2563 btnWptGoTo->Enable(enable1);
2564 btnWptExport->Enable(enablemultiple);
2565 btnWptSendToGPS->Enable(enable1);
2566 btnWptSendToPeer->Enable(enablemultiple);
2567}
2568
2569void RouteManagerDialog::OnWptToggleVisibility(wxMouseEvent &event) {
2570 wxPoint pos = event.GetPosition();
2571 int flags = 0;
2572 long clicked_index = m_pWptListCtrl->HitTest(pos, flags);
2573
2574 // Clicking Visibility column?
2575 if (clicked_index > -1 &&
2576 event.GetX() < m_pWptListCtrl->GetColumnWidth(colTRKVISIBLE)) {
2577 // Process the clicked item
2578 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(clicked_index);
2579
2580 if (!wp->IsSharedInVisibleRoute()) {
2581 wp->SetVisible(!wp->IsVisible());
2582 m_pWptListCtrl->SetItemImage(clicked_index,
2583 RoutePointGui(*wp).GetIconImageIndex());
2584
2585 NavObj_dB::GetInstance().UpdateRoutePoint(wp);
2586 }
2587
2588 // Manage "show all" checkbox
2589 bool viz = true;
2590 long item = -1;
2591 for (;;) {
2592 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2593 wxLIST_STATE_DONTCARE);
2594 if (item == -1) break;
2595
2596 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2597
2598 if (!wp->IsVisible()) {
2599 viz = false;
2600 break;
2601 }
2602 }
2603 m_cbShowAllWP->SetValue(viz);
2604
2605 gFrame->RefreshAllCanvas();
2606 } else // clicked on ScaMin column??
2607 if (clicked_index > -1 &&
2608 event.GetX() > m_pWptListCtrl->GetColumnWidth(colTRKVISIBLE) &&
2609 event.GetX() < (m_pWptListCtrl->GetColumnWidth(colTRKVISIBLE) +
2610 m_pWptListCtrl->GetColumnWidth(colWPTSCALE)) &&
2611 !g_bOverruleScaMin) {
2612 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(clicked_index);
2613 wp->SetUseSca(!wp->GetUseSca());
2614 NavObj_dB::GetInstance().UpdateRoutePoint(wp);
2615 gFrame->RefreshAllCanvas();
2616 wxString scamin = wxString::Format(_T("%i"), (int)wp->GetScaMin());
2617 if (!wp->GetUseSca()) scamin = _("Always");
2618 m_pWptListCtrl->SetItem(clicked_index, colWPTSCALE, scamin);
2619 }
2620
2621 // Allow wx to process...
2622 event.Skip();
2623}
2624
2625void RouteManagerDialog::OnWptNewClick(wxCommandEvent &event) {
2626 RoutePoint *pWP = new RoutePoint(gLat, gLon, g_default_wp_icon, wxEmptyString,
2627 wxEmptyString);
2628 pWP->m_bIsolatedMark = true; // This is an isolated mark
2629 pSelect->AddSelectableRoutePoint(gLat, gLon, pWP);
2630 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
2631
2632 gFrame->RefreshAllCanvas();
2633
2634 // g_pMarkInfoDialog = MarkInfoImpl::GetInstance( GetParent() );
2635 // There is on global instance of the MarkProp Dialog
2636 if (!g_pMarkInfoDialog) g_pMarkInfoDialog = new MarkInfoDlg(GetParent());
2637
2638 WptShowPropertiesDialog(pWP, GetParent());
2639}
2640
2641void RouteManagerDialog::OnWptPropertiesClick(wxCommandEvent &event) {
2642 long item = wxNOT_FOUND;
2643 item =
2644 m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2645 if (item == wxNOT_FOUND) return;
2646
2647 auto pWP = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2648 WptShowPropertiesDialog(pWP, GetParent());
2649
2650 UpdateWptListCtrl();
2651 m_bNeedConfigFlush = true;
2652}
2653
2654void RouteManagerDialog::WptShowPropertiesDialog(RoutePoint *pWP,
2655 wxWindow *parent) {
2656 if (!g_pMarkInfoDialog) // There is one global instance of the MarkProp
2657 // Dialog
2658 g_pMarkInfoDialog = new MarkInfoDlg(parent);
2659
2660 g_pMarkInfoDialog->SetRoutePoint(pWP);
2661 g_pMarkInfoDialog->UpdateProperties();
2662
2663 wxString base_title = _("Waypoint Properties");
2664
2665 if (pWP->m_bIsInLayer) {
2666 wxString caption(wxString::Format(_T("%s, %s: %s"), base_title, _("Layer"),
2667 GetLayerName(pWP->m_LayerID)));
2668 g_pMarkInfoDialog->SetDialogTitle(caption);
2669 } else {
2670 g_pMarkInfoDialog->SetDialogTitle(base_title);
2671 }
2672
2673 if (!g_pMarkInfoDialog->IsShown()) g_pMarkInfoDialog->Show();
2674 g_pMarkInfoDialog->Raise();
2675}
2676
2677void RouteManagerDialog::OnWptZoomtoClick(wxCommandEvent &event) {
2678 long item = -1;
2679 item =
2680 m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2681 if (item == -1) return;
2682
2683 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2684
2685 if (!wp) return;
2686
2687 if (gFrame->GetFocusCanvas()) {
2688 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), wp->m_lat, wp->m_lon,
2689 gFrame->GetFocusCanvas()->GetVPScale());
2690 }
2691}
2692
2693void RouteManagerDialog::OnWptDeleteClick(wxCommandEvent &event) {
2694 RoutePointList list;
2695
2696 int answer = OCPNMessageBox(
2697 this, _("Are you sure you want to delete the selected object(s)"),
2698 wxString(_("OpenCPN Alert")), wxYES_NO);
2699 if (answer != wxID_YES) return;
2700
2701 bool busy = false;
2702 if (m_pWptListCtrl->GetSelectedItemCount()) {
2703 ::wxBeginBusyCursor();
2704 m_bNeedConfigFlush = true;
2705 busy = true;
2706 }
2707
2708 long item = -1;
2709 long item_last_selected = -1;
2710 for (;;) {
2711 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2712 wxLIST_STATE_SELECTED);
2713 if (item == -1) break;
2714
2715 item_last_selected = item;
2716 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2717
2718 if (wp && !wp->m_bIsInLayer) list.Append(wp);
2719 }
2720
2721 if (busy) {
2722 for (unsigned int i = 0; i < list.GetCount(); i++) {
2723 RoutePoint *wp = list.Item(i)->GetData();
2724 if (wp) {
2725 if (wp->m_bIsInRoute) {
2726 if (wxID_YES ==
2727 OCPNMessageBox(this,
2728 _("The waypoint you want to delete is used in a "
2729 "route, do you really want to delete it?"),
2730 _("OpenCPN Alert"), wxYES_NO)) {
2731 NavObj_dB::GetInstance().DeleteRoutePoint(wp);
2732 pWayPointMan->DestroyWaypoint(wp);
2733 }
2734 } else {
2735 NavObj_dB::GetInstance().DeleteRoutePoint(wp);
2736 pWayPointMan->DestroyWaypoint(wp);
2737 }
2738 }
2739 }
2740
2741 long item_next =
2742 m_pWptListCtrl->GetNextItem(item_last_selected); // next in list
2743 RoutePoint *wp_next = NULL;
2744 if (item_next > -1)
2745 wp_next = (RoutePoint *)m_pWptListCtrl->GetItemData(item_next);
2746
2747 m_lastWptItem = item_next;
2748
2749 UpdateRouteListCtrl();
2750 UpdateTrkListCtrl();
2751 UpdateWptListCtrl(wp_next, true);
2752
2753 if (g_pMarkInfoDialog) {
2754 g_pMarkInfoDialog->ClearData();
2755 }
2756
2757 gFrame->InvalidateAllCanvasUndo();
2758 gFrame->RefreshAllCanvas();
2759 ::wxEndBusyCursor();
2760 }
2761}
2762
2763void RouteManagerDialog::OnWptGoToClick(wxCommandEvent &event) {
2764 long item = -1;
2765 item =
2766 m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2767 if (item == -1) return;
2768
2769 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2770
2771 if (!wp) return;
2772
2773 RoutePoint *pWP_src = new RoutePoint(gLat, gLon, g_default_wp_icon,
2774 wxEmptyString, wxEmptyString);
2775 pSelect->AddSelectableRoutePoint(gLat, gLon, pWP_src);
2776
2777 Route *temp_route = new Route();
2778 pRouteList->Append(temp_route);
2779
2780 temp_route->AddPoint(pWP_src);
2781 temp_route->AddPoint(wp);
2782
2783 pSelect->AddSelectableRouteSegment(gLat, gLon, wp->m_lat, wp->m_lon, pWP_src,
2784 wp, temp_route);
2785
2786 wxString name = wp->GetName();
2787 if (name.IsEmpty()) name = _("(Unnamed Waypoint)");
2788 wxString rteName = _("Go to ");
2789 rteName.Append(name);
2790 temp_route->m_RouteNameString = rteName;
2791 temp_route->m_RouteStartString = _("Here");
2792
2793 temp_route->m_RouteEndString = name;
2794 temp_route->m_bDeleteOnArrival = true;
2795
2796 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
2797
2798 g_pRouteMan->ActivateRoute(temp_route, wp);
2799
2800 UpdateRouteListCtrl();
2801}
2802
2803void RouteManagerDialog::OnWptExportClick(wxCommandEvent &event) {
2804 RoutePointList list;
2805
2806 wxString suggested_name = _T("waypoints");
2807
2808 long item = -1;
2809 for (;;) {
2810 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2811 wxLIST_STATE_SELECTED);
2812 if (item == -1) break;
2813
2814 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2815
2816 if (wp && !wp->m_bIsInLayer) {
2817 list.Append(wp);
2818 if (wp->GetName() != wxEmptyString) suggested_name = wp->GetName();
2819 }
2820 }
2821
2822 ExportGPXWaypoints(this, &list, suggested_name);
2823}
2824
2825void RouteManagerDialog::OnWptSendToGPSClick(wxCommandEvent &event) {
2826 long item = -1;
2827 item =
2828 m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2829 if (item == -1) return;
2830
2831 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2832
2833 if (!wp) return;
2834
2835 SendToGpsDlg *pdlg = new SendToGpsDlg();
2836 pdlg->SetWaypoint(wp);
2837
2838 wxString source;
2839 pdlg->Create(NULL, -1, _("Send to GPS") + _T( "..." ), source);
2840
2841#ifdef __WXOSX__
2842 HideWithEffect(wxSHOW_EFFECT_BLEND);
2843#endif
2844 pdlg->ShowModal();
2845#ifdef __WXOSX__
2846 ShowWithEffect(wxSHOW_EFFECT_BLEND);
2847#endif
2848
2849 delete pdlg;
2850}
2851
2852void RouteManagerDialog::OnWptDeleteAllClick(wxCommandEvent &event) {
2853 wxString prompt;
2854 int buttons, type;
2855 if (!pWayPointMan->SharedWptsExist()) {
2856 prompt = _("Are you sure you want to delete <ALL> waypoints?");
2857 buttons = wxYES_NO;
2858 type = 1;
2859 } else {
2860 prompt =
2861 _("There are some waypoints used in routes or anchor alarms.\n Do you "
2862 "want to delete them as well?\n This will change the routes and "
2863 "disable the anchor alarms.\n Answering No keeps the waypoints used "
2864 "in routes or alarms.");
2865 buttons = wxYES_NO | wxCANCEL;
2866 type = 2;
2867 }
2868 int answer =
2869 OCPNMessageBox(this, prompt, wxString(_("OpenCPN Alert")), buttons);
2870 if (answer == wxID_YES) pWayPointMan->DeleteAllWaypoints(true);
2871 if (answer == wxID_NO && type == 2)
2872 pWayPointMan->DeleteAllWaypoints(false); // only delete unused waypoints
2873
2874 if (g_pMarkInfoDialog) {
2875 g_pMarkInfoDialog->ClearData();
2876 }
2877
2878 m_lastWptItem = -1;
2879 UpdateRouteListCtrl();
2880 UpdateWptListCtrl();
2881 gFrame->InvalidateAllCanvasUndo();
2882 gFrame->RefreshAllCanvas();
2883}
2884
2885void RouteManagerDialog::OnLaySelected(wxListEvent &event) {
2886 UpdateLayButtons();
2887}
2888
2889void RouteManagerDialog::OnLayColumnClicked(wxListEvent &event) {
2890 if (event.m_col == 1) {
2891 sort_layer_name_dir++;
2892 m_pLayListCtrl->SortItems(SortLayersOnName, (wxIntPtr)NULL);
2893 } else if (event.m_col == 2) {
2894 sort_layer_len_dir++;
2895 m_pLayListCtrl->SortItems(SortLayersOnSize, (wxIntPtr)NULL);
2896 }
2897}
2898
2899void RouteManagerDialog::UpdateLayButtons() {
2900 long item = -1;
2901 item =
2902 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2903 bool enable = (item != -1);
2904
2905 // btnLayProperties->Enable(false);
2906 btnLayDelete->Enable(enable);
2907 cbLayToggleChart->Enable(enable);
2908 cbLayToggleListing->Enable(enable);
2909 cbLayToggleNames->Enable(enable);
2910
2911 if (item >= 0) {
2912 cbLayToggleChart->SetValue(
2913 ((Layer *)m_pLayListCtrl->GetItemData(item))->IsVisibleOnChart());
2914
2915 cbLayToggleNames->Set3StateValue(
2916 ((Layer *)m_pLayListCtrl->GetItemData(item))->HasVisibleNames());
2917
2918 cbLayToggleListing->SetValue(
2919 ((Layer *)m_pLayListCtrl->GetItemData(item))->IsVisibleOnListing());
2920
2921 } else {
2922 cbLayToggleChart->SetValue(true);
2923 cbLayToggleNames->Set3StateValue(wxCHK_UNDETERMINED);
2924 cbLayToggleListing->SetValue(true);
2925 }
2926}
2927
2928void RouteManagerDialog::OnLayToggleVisibility(wxMouseEvent &event) {
2929 wxPoint pos = event.GetPosition();
2930 int flags = 0;
2931 long clicked_index = m_pLayListCtrl->HitTest(pos, flags);
2932
2933 // Clicking Visibility column?
2934 if (clicked_index > -1 &&
2935 event.GetX() < m_pLayListCtrl->GetColumnWidth(colLAYVISIBLE)) {
2936 // Process the clicked item
2937 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(clicked_index);
2938
2939 layer->SetVisibleOnChart(!layer->IsVisibleOnChart());
2940 m_pLayListCtrl->SetItemImage(clicked_index,
2941 layer->IsVisibleOnChart() ? 0 : 1);
2942
2943 // Manage "show all" checkbox
2944 bool viz = true;
2945 long item = -1;
2946 for (;;) {
2947 item = m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2948 wxLIST_STATE_DONTCARE);
2949 if (item == -1) break;
2950
2951 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(item);
2952
2953 if (!layer->IsVisibleOnChart()) {
2954 viz = false;
2955 break;
2956 }
2957 }
2958 m_cbShowAllLay->SetValue(viz);
2959
2960 ToggleLayerContentsOnChart(layer);
2961 }
2962
2963 // Allow wx to process...
2964 event.Skip();
2965}
2966
2967void RouteManagerDialog::UpdateLists() {
2968 UpdateRouteListCtrl();
2969 UpdateTrkListCtrl();
2970 UpdateWptListCtrl();
2971 UpdateLayListCtrl();
2972}
2973
2974void RouteManagerDialog::OnLayNewClick(wxCommandEvent &event) {
2975 AddNewLayer(false); // Temporary layer
2976}
2977
2978void RouteManagerDialog::OnPerLayNewClick(wxCommandEvent &event) {
2979 AddNewLayer(true); // Persistent layer
2980}
2981
2982void RouteManagerDialog::AddNewLayer(bool isPersistent) {
2983 bool show_flag = g_bShowLayers;
2984 g_bShowLayers = true;
2985
2986 UI_ImportGPX(this, true, _T(""), true, isPersistent);
2987
2988 g_bShowLayers = show_flag;
2989 UpdateLists();
2990 gFrame->RefreshAllCanvas();
2991}
2992
2993void RouteManagerDialog::OnLayPropertiesClick(wxCommandEvent &event) {
2994 // Show layer properties dialog for selected layer - todo
2995 long item = -1;
2996 item =
2997 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2998 if (item == -1) return;
2999}
3000
3001void RouteManagerDialog::OnLayDeleteClick(wxCommandEvent &event) {
3002 long item = -1;
3003 item =
3004 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
3005 if (item == -1) return;
3006
3007 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(item);
3008
3009 if (!layer) return;
3010 // Check if this file is a persistent layer.
3011 // If added in this session the listctrl file path is origin dir and not yet
3012 // /layers
3013 bool ispers = false;
3014 wxString destf, f, name, ext;
3015 f = layer->m_LayerFileName;
3016 wxFileName::SplitPath(f, NULL, NULL, &name, &ext);
3017 destf = g_Platform->GetPrivateDataDir();
3018 appendOSDirSlash(&destf);
3019 destf.Append(_T("layers"));
3020 appendOSDirSlash(&destf);
3021 destf << name << _T(".") << ext;
3022
3023 wxString prompt = _(
3024 "Are you sure you want to delete this layer and <ALL> of its contents?");
3025 if (wxFileExists(destf)) {
3026 prompt.Append(_T("\n"));
3027 prompt.Append(
3028 _("The file will also be deleted from OpenCPN's layer directory."));
3029 prompt.Append(_T("\n (") + destf + _T(")" ));
3030 ispers = true;
3031 }
3032 int answer =
3033 OCPNMessageBox(this, prompt, wxString(_("OpenCPN Alert")), wxYES_NO);
3034 if (answer == wxID_NO) return;
3035
3036 // Delete a persistent layer file if present
3037 if (ispers) {
3038 wxString remMSG;
3039 if (wxRemoveFile(destf))
3040 remMSG.sprintf(_T("Layer file: %s is deleted"), destf);
3041 else
3042 remMSG.sprintf(_T("Error deleting Layer file: %s"), destf);
3043
3044 wxLogMessage(remMSG);
3045 }
3046
3047 // Process Tracks and Routes in this layer
3048 wxRouteListNode *node1 = pRouteList->GetFirst();
3049 while (node1) {
3050 Route *pRoute = node1->GetData();
3051 wxRouteListNode *next_node = node1->GetNext();
3052 if (pRoute->m_bIsInLayer && (pRoute->m_LayerID == layer->m_LayerID)) {
3053 pRoute->m_bIsInLayer = false;
3054 pRoute->m_LayerID = 0;
3055 g_pRouteMan->DeleteRoute(pRoute);
3056 }
3057 node1 = next_node;
3058 }
3059
3060 for (Track *pTrack : g_TrackList) {
3061 if (pTrack->m_bIsInLayer && (pTrack->m_LayerID == layer->m_LayerID)) {
3062 pTrack->m_bIsInLayer = false;
3063 pTrack->m_LayerID = 0;
3064 NavObj_dB::GetInstance().DeleteTrack(pTrack);
3065 RoutemanGui(*g_pRouteMan).DeleteTrack(pTrack);
3066 }
3067 }
3068
3069 // Process waypoints in this layer
3070 wxRoutePointListNode *node = pWayPointMan->GetWaypointList()->GetFirst();
3071 wxRoutePointListNode *node3;
3072
3073 while (node) {
3074 node3 = node->GetNext();
3075 RoutePoint *rp = node->GetData();
3076 if (rp && (rp->m_LayerID == layer->m_LayerID)) {
3077 rp->m_bIsInLayer = false;
3078 rp->m_LayerID = 0;
3079 pWayPointMan->DestroyWaypoint(
3080 rp, false); // no need to update the change set on layer ops
3081 }
3082
3083 node = node3;
3084 node3 = NULL;
3085 }
3086
3087 if (g_pMarkInfoDialog) {
3088 g_pMarkInfoDialog->ClearData();
3089 }
3090
3091 pLayerList->DeleteObject(layer);
3092
3093 UpdateLists();
3094
3095 gFrame->RefreshAllCanvas();
3096
3097 m_bNeedConfigFlush = false;
3098}
3099
3100void RouteManagerDialog::OnLayToggleChartClick(wxCommandEvent &event) {
3101 // Toggle visibility on chart for selected layer
3102 long item = -1;
3103 item =
3104 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
3105 if (item == -1) return;
3106
3107 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(item);
3108
3109 if (!layer) return;
3110
3111 layer->SetVisibleOnChart(!layer->IsVisibleOnChart());
3112 m_pLayListCtrl->SetItemImage(item, layer->IsVisibleOnChart() ? 0 : 1);
3113
3114 ToggleLayerContentsOnChart(layer);
3115}
3116
3117void RouteManagerDialog::ToggleLayerContentsOnChart(Layer *layer) {
3118 // Process Tracks and Routes in this layer
3119 wxRouteListNode *node1 = pRouteList->GetFirst();
3120 while (node1) {
3121 Route *pRoute = node1->GetData();
3122 if (pRoute->m_bIsInLayer && (pRoute->m_LayerID == layer->m_LayerID)) {
3123 pRoute->SetVisible(layer->IsVisibleOnChart());
3124 }
3125 node1 = node1->GetNext();
3126 }
3127
3128 for (Track *pTrack : g_TrackList) {
3129 if (pTrack->m_bIsInLayer && (pTrack->m_LayerID == layer->m_LayerID))
3130 pTrack->SetVisible(layer->IsVisibleOnChart());
3131 }
3132
3133 // Process waypoints in this layer
3134 wxRoutePointListNode *node = pWayPointMan->GetWaypointList()->GetFirst();
3135
3136 while (node) {
3137 RoutePoint *rp = node->GetData();
3138 if (rp && (rp->m_LayerID == layer->m_LayerID)) {
3139 rp->SetVisible(layer->IsVisibleOnChart());
3140 }
3141
3142 node = node->GetNext();
3143 }
3144 UpdateLists();
3145
3146 UpdateLayButtons();
3147
3148 gFrame->RefreshAllCanvas();
3149}
3150
3151void RouteManagerDialog::OnLayToggleNamesClick(wxCommandEvent &event) {
3152 // Toggle WPT names visibility on chart for selected layer
3153 long item = -1;
3154 item =
3155 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
3156 if (item == -1) return;
3157
3158 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(item);
3159
3160 if (!layer) return;
3161
3162 layer->SetVisibleNames(cbLayToggleNames->Get3StateValue());
3163
3164 ToggleLayerContentsNames(layer);
3165}
3166
3167void RouteManagerDialog::ToggleLayerContentsNames(Layer *layer) {
3168 // Process Tracks and Routes in this layer
3169 wxRouteListNode *node1 = pRouteList->GetFirst();
3170 while (node1) {
3171 Route *pRoute = node1->GetData();
3172 if (pRoute->m_bIsInLayer && (pRoute->m_LayerID == layer->m_LayerID)) {
3173 wxRoutePointListNode *node = pRoute->pRoutePointList->GetFirst();
3174 RoutePoint *prp1 = node->GetData();
3175 while (node) {
3176 if (layer->HasVisibleNames() == wxCHK_UNDETERMINED) {
3177 prp1->m_bShowName = prp1->m_bShowNameData;
3178 } else {
3179 prp1->m_bShowName = (layer->HasVisibleNames() == wxCHK_CHECKED);
3180 }
3181 node = node->GetNext();
3182 }
3183 }
3184 node1 = node1->GetNext();
3185 }
3186
3187 // Process waypoints in this layer
3188 wxRoutePointListNode *node = pWayPointMan->GetWaypointList()->GetFirst();
3189
3190 while (node) {
3191 RoutePoint *rp = node->GetData();
3192 if (rp && (rp->m_LayerID == layer->m_LayerID)) {
3193 rp->SetNameShown(layer->HasVisibleNames() == wxCHK_CHECKED ||
3194 (rp->m_bShowNameData &&
3195 layer->HasVisibleNames() == wxCHK_UNDETERMINED));
3196 }
3197
3198 node = node->GetNext();
3199 }
3200
3201 UpdateLayButtons();
3202
3203 gFrame->RefreshAllCanvas();
3204}
3205
3206void RouteManagerDialog::OnLayToggleListingClick(wxCommandEvent &event) {
3207 // Toggle visibility on listing for selected layer
3208 long item = -1;
3209 item =
3210 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
3211 if (item == -1) return;
3212
3213 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(item);
3214
3215 if (!layer) return;
3216
3217 layer->SetVisibleOnListing(!layer->IsVisibleOnListing());
3218
3219 ToggleLayerContentsOnListing(layer);
3220}
3221
3222void RouteManagerDialog::ToggleLayerContentsOnListing(Layer *layer) {
3223 ::wxBeginBusyCursor();
3224
3225 // Process Tracks and Routes in this layer
3226 wxRouteListNode *node1 = pRouteList->GetFirst();
3227 while (node1) {
3228 Route *pRoute = node1->GetData();
3229 if (pRoute->m_bIsInLayer && (pRoute->m_LayerID == layer->m_LayerID)) {
3230 pRoute->SetListed(layer->IsVisibleOnListing());
3231 }
3232 node1 = node1->GetNext();
3233 }
3234
3235 for (Track *pTrack : g_TrackList) {
3236 if (pTrack->m_bIsInLayer && (pTrack->m_LayerID == layer->m_LayerID))
3237 pTrack->SetListed(layer->IsVisibleOnListing());
3238 }
3239
3240 // Process waypoints in this layer
3241 // n.b. If the waypoint belongs to a track, and is not shared, then do not
3242 // list it. This is a performance optimization, allowing large track support.
3243
3244 wxRoutePointListNode *node = pWayPointMan->GetWaypointList()->GetFirst();
3245
3246 while (node) {
3247 RoutePoint *rp = node->GetData();
3248 if (rp && rp->m_bIsolatedMark && (rp->m_LayerID == layer->m_LayerID)) {
3249 rp->SetListed(layer->IsVisibleOnListing());
3250 }
3251
3252 node = node->GetNext();
3253 }
3254
3255 UpdateLists();
3256
3257 ::wxEndBusyCursor();
3258
3259 gFrame->RefreshAllCanvas();
3260}
3261
3262void RouteManagerDialog::OnLayDefaultAction(wxListEvent &event) {
3263 wxCommandEvent evt;
3264 OnLayPropertiesClick(evt);
3265}
3266
3267void RouteManagerDialog::UpdateLayListCtrl() {
3268 // if an item was selected, make it selected again if it still exist
3269 long item = -1;
3270 item =
3271 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
3272
3273 wxUIntPtr selected_id = wxUIntPtr(0);
3274 if (item != -1) selected_id = m_pLayListCtrl->GetItemData(item);
3275
3276 // Delete existing items
3277 m_pLayListCtrl->DeleteAllItems();
3278
3279 // then add routes to the listctrl
3280 LayerList::iterator it;
3281 int index = 0;
3282 bool b_anyHidden = false;
3283 for (it = (*pLayerList).begin(); it != (*pLayerList).end(); ++it, ++index) {
3284 Layer *lay = (Layer *)(*it);
3285
3286 if (!lay->m_LayerName.Upper().Contains(m_tFilterLay->GetValue().Upper())) {
3287 continue;
3288 }
3289
3290 wxListItem li;
3291 li.SetId(index);
3292 li.SetImage(lay->IsVisibleOnChart() ? 0 : 1);
3293 li.SetData(lay);
3294 li.SetText(_T(""));
3295
3296 long idx = m_pLayListCtrl->InsertItem(li);
3297
3298 wxString name = lay->m_LayerName;
3299 if (name.IsEmpty()) {
3300 // RoutePoint *rp = trk->GetPoint(1);
3301 // if (rp)
3302 // name = rp->m_CreateTime.FormatISODate() + _T(" ") +
3303 // rp->m_CreateTime.FormatISOTime(); //name =
3304 // rp->m_CreateTime.Format();
3305 // else
3306 name = _("(Unnamed Layer)");
3307 }
3308 m_pLayListCtrl->SetItem(idx, colLAYNAME, name);
3309
3310 wxString len;
3311 len.Printf(wxT("%d"), (int)lay->m_NoOfItems);
3312 m_pLayListCtrl->SetItem(idx, colLAYITEMS, len);
3313 m_pLayListCtrl->SetItem(idx, colLAYPERSIST, lay->m_LayerType);
3314
3315 wxListItem lic;
3316 lic.SetId(index);
3317 lic.SetColumn(1);
3318 lic.SetAlign(wxLIST_FORMAT_LEFT);
3319 m_pLayListCtrl->SetItem(lic);
3320
3321 lic.SetColumn(2);
3322 lic.SetAlign(wxLIST_FORMAT_LEFT);
3323 m_pLayListCtrl->SetItem(lic);
3324
3325 if (!lay->IsVisibleOnChart()) b_anyHidden = true;
3326 }
3327
3328 m_pLayListCtrl->SortItems(SortLayersOnName,
3329 reinterpret_cast<wxIntPtr>(m_pLayListCtrl));
3330 m_pLayListCtrl->SetColumnWidth(0, 4 * m_charWidth);
3331
3332 // restore selection if possible
3333 // NOTE this will select a different item, if one is deleted
3334 // (the next route will get that index).
3335 if (selected_id != wxUIntPtr(0)) {
3336 item = m_pLayListCtrl->FindItem(-1, selected_id);
3337 m_pLayListCtrl->SetItemState(item,
3338 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
3339 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
3340 }
3341 UpdateLayButtons();
3342
3343 m_cbShowAllLay->SetValue(!b_anyHidden);
3344}
3345
3346void RouteManagerDialog::OnImportClick(wxCommandEvent &event) {
3347 // Import routes
3348 // FIXME there is no way to instruct this function about what to import.
3349 // Suggest to add that!
3350
3351 UI_ImportGPX(this);
3352
3353 UpdateLists();
3354
3355 gFrame->RefreshAllCanvas();
3356}
3357void RouteManagerDialog::OnExportClick(wxCommandEvent &event) {
3358 ExportGPX(this);
3359}
3360
3361void RouteManagerDialog::OnExportVizClick(wxCommandEvent &event) {
3362 ExportGPX(this, true, true); // only visible objects, layers included
3363}
3364
3365void RouteManagerDialog::OnFilterChanged(wxCommandEvent &event) {
3366 if (event.GetEventObject() == m_tFilterWpt) {
3367 UpdateWptListCtrl(NULL, true);
3368 } else if (event.GetEventObject() == m_tFilterRte) {
3369 UpdateRouteListCtrl();
3370 } else if (event.GetEventObject() == m_tFilterTrk) {
3371 UpdateTrkListCtrl();
3372 } else if (event.GetEventObject() == m_tFilterLay) {
3373 UpdateLayListCtrl();
3374 }
3375}
3376
3377// END Event handlers
wxString & GetPrivateDataDir()
Return dir path for opencpn.log, etc., respecting -c cli option.
Represents an active track that is currently being recorded.
Definition track.h:221
Represents a layer of chart objects in OpenCPN.
Definition Layer.h:38
Dialog for displaying and editing waypoint properties.
Definition MarkInfo.h:212
void Validate()
Check that all entries are accessible, remove stale ones.
Main application frame.
Definition ocpn_frame.h:136
Provides platform-specific support utilities for OpenCPN.
void Init(const KeyProvider &kp, std::function< void(ObservedEvt &ev)> action)
Initiate an object yet not listening.
Definition observable.h:255
Represents a waypoint or mark within the navigation system.
Definition route_point.h:70
bool m_bIsolatedMark
Flag indicating if the waypoint is a standalone mark.
bool m_bShowNameData
Flag indicating if waypoint data should be shown with the name.
bool m_bIsInRoute
Flag indicating if this waypoint is part of a route.
bool m_bShowName
Flag indicating if the waypoint name should be shown.
bool m_bIsInLayer
Flag indicating if the waypoint belongs to a layer.
int m_LayerID
Layer identifier if the waypoint belongs to a layer.
Represents a navigational route in the navigation system.
Definition route.h:98
wxString m_RouteStartString
Name or description of the route's starting point.
Definition route.h:251
RoutePointList * pRoutePointList
Ordered list of waypoints (RoutePoints) that make up this route.
Definition route.h:335
bool m_bRtIsActive
Flag indicating whether this route is currently active for navigation.
Definition route.h:207
bool m_bDeleteOnArrival
Flag indicating whether the route should be deleted once navigation reaches the end.
Definition route.h:267
wxString m_RouteEndString
Name or description of the route's ending point.
Definition route.h:256
wxString m_RouteNameString
User-assigned name for the route.
Definition route.h:246
bool m_bIsInLayer
Flag indicating whether this route belongs to a layer.
Definition route.h:277
int m_LayerID
Identifier of the layer containing this route.
Definition route.h:282
bool DeleteRoute(Route *pRoute)
Definition routeman.cpp:856
EventVar on_routes_update
Notified when list of routes is updated (no data in event)
Definition routeman.h:269
bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint=NULL)
Activates a route for navigation.
Definition routeman.cpp:279
Dialog for sending routes/waypoints to a GPS device.
Dialog for sending navigation objects to peer devices.
Represents a single point in a track.
Definition track.h:53
wxDateTime GetCreateTime(void)
Retrieves the creation timestamp of a track point as a wxDateTime object.
Definition track.cpp:140
Class TrackPropDlg.
Represents a track, which is a series of connected track points.
Definition track.h:111
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
Definition gui_lib.cpp:54
wxFont GetOCPNGUIScaledFont(wxString item)
Retrieves a font optimized for touch and high-resolution interfaces.
Definition gui_lib.cpp:83
MdnsCache mDNS host lookups cache.
mDNS lookup wrappers.
Class NavObj_dB.