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 for (;;) {
1153 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1154 wxLIST_STATE_DONTCARE);
1155 if (item == -1) break;
1156
1157 Route *pR = (Route *)m_pRouteListCtrl->GetItemData(item);
1158
1159 pR->SetVisible(viz, viz);
1160 pR->SetSharedWPViz(viz);
1161
1162 m_pRouteListCtrl->SetItemImage(item, !viz); // visible
1163
1164 pConfig->UpdateRoute(pR);
1165 }
1166
1167 UpdateWptListCtrlViz();
1168
1169 gFrame->RefreshAllCanvas();
1170}
1171
1172void RouteManagerDialog::OnShowAllWpCBClicked(wxCommandEvent &event) {
1173 bool viz = m_cbShowAllWP->GetValue();
1174 long item = -1;
1175 for (;;) {
1176 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1177 wxLIST_STATE_DONTCARE);
1178 if (item == -1) break;
1179
1180 RoutePoint *pRP = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
1181
1182 if (!pRP->IsSharedInVisibleRoute()) {
1183 pRP->SetVisible(viz);
1184 } else
1185 pRP->SetVisible(true);
1186
1187 m_pWptListCtrl->SetItemImage(item, RoutePointGui(*pRP).GetIconImageIndex());
1188 pConfig->UpdateWayPoint(pRP);
1189 }
1190
1191 gFrame->RefreshAllCanvas();
1192}
1193
1194void RouteManagerDialog::OnShowAllTrkCBClicked(wxCommandEvent &event) {
1195 bool viz = m_cbShowAllTrk->GetValue();
1196 long item = -1;
1197 for (;;) {
1198 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1199 wxLIST_STATE_DONTCARE);
1200 if (item == -1) break;
1201
1202 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
1203
1204 track->SetVisible(viz);
1205 m_pTrkListCtrl->SetItemImage(item, track->IsVisible() ? 0 : 1);
1206 }
1207
1208 gFrame->RefreshAllCanvas();
1209}
1210
1211void RouteManagerDialog::OnShowAllLayCBClicked(wxCommandEvent &event) {
1212 bool viz = m_cbShowAllLay->GetValue();
1213 long item = -1;
1214 for (;;) {
1215 item = m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1216 wxLIST_STATE_DONTCARE);
1217 if (item == -1) break;
1218
1219 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(item);
1220
1221 layer->SetVisibleOnChart(viz);
1222 m_pLayListCtrl->SetItemImage(item, layer->IsVisibleOnChart() ? 0 : 1);
1223
1224 ToggleLayerContentsOnChart(layer);
1225 }
1226
1227 gFrame->RefreshAllCanvas();
1228}
1229
1230void RouteManagerDialog::UpdateRouteListCtrl() {
1231 // if an item was selected, make it selected again if it still exist
1232 long item = -1;
1233 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1234 wxLIST_STATE_SELECTED);
1235 wxUIntPtr selected_id = wxUIntPtr(0);
1236 if (item != -1) selected_id = m_pRouteListCtrl->GetItemData(item);
1237
1238 // Delete existing items
1239 m_pRouteListCtrl->DeleteAllItems();
1240
1241 // then add routes to the listctrl
1242 RouteList::iterator it;
1243 int index = 0;
1244 int list_index = 0;
1245 bool bpartialViz = false;
1246
1247 for (it = (*pRouteList).begin(); it != (*pRouteList).end(); ++it, ++index) {
1248 if (!(*it)->IsListed()) continue;
1249
1250 if (!(*it)->GetName().Upper().Contains(m_tFilterRte->GetValue().Upper())) {
1251 continue;
1252 }
1253
1254 wxListItem li;
1255 li.SetId(list_index);
1256 li.SetImage((*it)->IsVisible() ? 0 : 1);
1257 li.SetData(*it);
1258 li.SetText(_T(""));
1259 li.SetAlign(wxLIST_FORMAT_LEFT);
1260
1261 if ((*it)->m_bRtIsActive) {
1262 wxFont font = *wxNORMAL_FONT;
1263 font.SetWeight(wxFONTWEIGHT_BOLD);
1264 li.SetFont(font);
1265 }
1266
1267 long idx = m_pRouteListCtrl->InsertItem(li);
1268
1269 wxString name = (*it)->m_RouteNameString;
1270 if (name.IsEmpty()) name = _("(Unnamed Route)");
1271 m_pRouteListCtrl->SetItem(idx, rmROUTENAME, name);
1272
1273 wxString startend = (*it)->m_RouteStartString;
1274 if (!(*it)->m_RouteEndString.IsEmpty())
1275 startend.append(_(" - ") + (*it)->m_RouteEndString);
1276 m_pRouteListCtrl->SetItem(idx, rmROUTEDESC, startend);
1277
1278 wxListItem lic;
1279 lic.SetId(list_index);
1280 lic.SetColumn(1);
1281 lic.SetAlign(wxLIST_FORMAT_LEFT);
1282 m_pRouteListCtrl->SetItem(lic);
1283
1284 lic.SetColumn(2);
1285 lic.SetAlign(wxLIST_FORMAT_LEFT);
1286 m_pRouteListCtrl->SetItem(lic);
1287
1288 // Keep track if any are invisible
1289 if (!(*it)->IsVisible()) bpartialViz = true;
1290
1291 list_index++;
1292 }
1293
1294 m_pRouteListCtrl->SortItems(SortRoutesOnName, (wxIntPtr)NULL);
1295
1296 m_pRouteListCtrl->SetColumnWidth(0, 4 * m_charWidth);
1297
1298 // restore selection if possible
1299 // NOTE this will select a different item, if one is deleted
1300 // (the next route will get that index).
1301 if (selected_id != wxUIntPtr(0)) {
1302 item = m_pRouteListCtrl->FindItem(-1, selected_id);
1303 m_pRouteListCtrl->SetItemState(
1304 item, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
1305 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
1306 }
1307
1308 if ((m_lastRteItem >= 0) && (m_pRouteListCtrl->GetItemCount()))
1309 m_pRouteListCtrl->EnsureVisible(m_lastRteItem);
1310 UpdateRteButtons();
1311
1312 // If any route is invisible, then "show all" cb must be clear.
1313 m_cbShowAllRte->SetValue(!bpartialViz);
1314}
1315
1316void RouteManagerDialog::UpdateRteButtons() {
1317 // enable/disable buttons
1318 long selected_index_index =
1319 m_pRouteListCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1320 bool enable1 = m_pRouteListCtrl->GetSelectedItemCount() == 1;
1321 bool enablemultiple = m_pRouteListCtrl->GetSelectedItemCount() >= 1;
1322
1323 m_lastRteItem = selected_index_index;
1324
1325 btnRteDelete->Enable(m_pRouteListCtrl->GetSelectedItemCount() > 0);
1326 btnRteZoomto->Enable(enable1);
1327 btnRteProperties->Enable(enable1);
1328 btnRteReverse->Enable(enable1);
1329 btnRteExport->Enable(enablemultiple);
1330 btnRteResequence->Enable(enable1);
1331 btnRteSendToGPS->Enable(enable1);
1332 btnRteDeleteAll->Enable(m_pRouteListCtrl->GetItemCount() > 0);
1333 btnRteSendToPeer->Enable(enablemultiple);
1334
1335 // set activate button text
1336 Route *route = NULL;
1337 if (enable1)
1338 route = (Route *)m_pRouteListCtrl->GetItemData(selected_index_index);
1339
1340 if (!g_pRouteMan->IsAnyRouteActive()) {
1341 btnRteActivate->Enable(enable1);
1342 if (enable1) btnRteActivate->SetLabel(_("Activate"));
1343
1344 } else {
1345 if (enable1) {
1346 if (route && route->m_bRtIsActive) {
1347 btnRteActivate->Enable(enable1);
1348 btnRteActivate->SetLabel(_("Deactivate"));
1349 } else
1350 btnRteActivate->Enable(false);
1351 } else
1352 btnRteActivate->Enable(false);
1353 }
1354}
1355
1356void RouteManagerDialog::MakeAllRoutesInvisible() {
1357 RouteList::iterator it;
1358 long index = 0;
1359 for (it = (*pRouteList).begin(); it != (*pRouteList).end(); ++it, ++index) {
1360 if ((*it)->IsVisible()) { // avoid config updating as much as possible!
1361 (*it)->SetVisible(false);
1362 m_pRouteListCtrl->SetItemImage(m_pRouteListCtrl->FindItem(-1, index),
1363 1); // Likely not same order :0
1364 pConfig->UpdateRoute(*it); // auch, flushes config to disk. FIXME
1365 }
1366 }
1367}
1368
1369void RouteManagerDialog::ZoomtoRoute(Route *route) {
1370 // Calculate bbox center
1371 LLBBox RBBox = route->GetBBox();
1372 double clat = (RBBox.GetMinLat() + RBBox.GetMaxLat()) / 2;
1373 double clon = (RBBox.GetMinLon() + RBBox.GetMaxLon()) / 2;
1374
1375 // Calculate ppm
1376 double rw, rh, ppm; // route width, height, final ppm scale to use
1377 int ww, wh; // chart window width, height
1378 // route bbox width in nm
1379 DistanceBearingMercator(RBBox.GetMinLat(), RBBox.GetMinLon(),
1380 RBBox.GetMinLat(), RBBox.GetMaxLon(), NULL, &rw);
1381 // route bbox height in nm
1382 DistanceBearingMercator(RBBox.GetMinLat(), RBBox.GetMinLon(),
1383 RBBox.GetMaxLat(), RBBox.GetMinLon(), NULL, &rh);
1384
1385 if (gFrame->GetFocusCanvas()) {
1386 gFrame->GetFocusCanvas()->GetSize(&ww, &wh);
1387 ppm = wxMin(ww / (rw * 1852), wh / (rh * 1852)) * (100 - fabs(clat)) / 90;
1388 ppm = wxMin(ppm, 1.0);
1389
1390 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), clat, clon, ppm);
1391 }
1392
1393 m_bNeedConfigFlush = true;
1394}
1395
1396// BEGIN Event handlers
1397void RouteManagerDialog::OnRteDeleteClick(wxCommandEvent &event) {
1398 int count = m_pRouteListCtrl->GetSelectedItemCount();
1399 bool confirmed = RouteGui::OnDelete(this, count);
1400
1401 if (confirmed && count > 0) {
1402 ::wxBeginBusyCursor();
1403 RouteList list;
1404
1405 gFrame->CancelAllMouseRoute();
1406 m_bNeedConfigFlush = true;
1407
1408 long item = -1;
1409 for (;;) {
1410 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1411 wxLIST_STATE_SELECTED);
1412 if (item == -1) break;
1413
1414 Route *proute_to_delete = (Route *)m_pRouteListCtrl->GetItemData(item);
1415
1416 if (proute_to_delete) list.Append(proute_to_delete);
1417 }
1418
1419 for (unsigned int i = 0; i < list.GetCount(); i++) {
1420 Route *route = list.Item(i)->GetData();
1421 if (route) {
1422 pConfig->DeleteConfigRoute(route);
1423 g_pRouteMan->DeleteRoute(route, NavObjectChanges::getInstance());
1424 }
1425 }
1426
1427 m_lastRteItem = -1;
1428 UpdateRouteListCtrl();
1429 UpdateTrkListCtrl();
1430
1431 gFrame->InvalidateAllCanvasUndo();
1432 gFrame->RefreshAllCanvas();
1433 ::wxEndBusyCursor();
1434 }
1435}
1436
1437void RouteManagerDialog::OnRteDeleteAllClick(wxCommandEvent &event) {
1438 int dialog_ret =
1439 OCPNMessageBox(this, _("Are you sure you want to delete <ALL> routes?"),
1440 wxString(_("OpenCPN Alert")), wxYES_NO);
1441
1442 if (dialog_ret == wxID_YES) {
1443 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
1444
1445 gFrame->CancelAllMouseRoute();
1446
1447 g_pRouteMan->DeleteAllRoutes(NavObjectChanges::getInstance());
1448 // TODO Seth
1449 // m_pSelectedRoute = NULL;
1450 // m_pFoundRoutePoint = NULL;
1451 // m_pFoundRoutePointSecond = NULL;
1452
1453 m_lastRteItem = -1;
1454 UpdateRouteListCtrl();
1455
1456 // Also need to update the track list control, since routes and tracks
1457 // share a common global list (pRouteList)
1458 UpdateTrkListCtrl();
1459
1460 if (pRoutePropDialog) pRoutePropDialog->Hide();
1461 gFrame->InvalidateAllCanvasUndo();
1462 gFrame->RefreshAllCanvas();
1463
1464 m_bNeedConfigFlush = true;
1465 }
1466}
1467
1468void RouteManagerDialog::OnRtePropertiesClick(wxCommandEvent &event) {
1469 // Show routeproperties dialog for selected route
1470 long item = -1;
1471 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1472 wxLIST_STATE_SELECTED);
1473 if (item == -1) return;
1474
1475 Route *route = (Route *)m_pRouteListCtrl->GetItemData(item);
1476
1477 if (!route) return;
1478
1479 pRoutePropDialog = RoutePropDlgImpl::getInstance(GetParent());
1480
1481 pRoutePropDialog->SetRouteAndUpdate(route);
1482
1483 if (!pRoutePropDialog->IsShown()) pRoutePropDialog->Show();
1484
1485 pRoutePropDialog->Raise();
1486
1487 m_bNeedConfigFlush = true;
1488}
1489
1490void RouteManagerDialog::OnRteZoomtoClick(wxCommandEvent &event) {
1491 // Zoom into the bounding box of the selected route
1492 long item = -1;
1493 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1494 wxLIST_STATE_SELECTED);
1495 if (item == -1) return;
1496
1497 // optionally make this route exclusively visible
1498 if (m_bCtrlDown) MakeAllRoutesInvisible();
1499
1500 Route *route = (Route *)m_pRouteListCtrl->GetItemData(item);
1501
1502 if (!route) return;
1503
1504 // Ensure route is visible
1505 if (!route->IsVisible()) {
1506 route->SetVisible(true);
1507 m_pRouteListCtrl->SetItemImage(item, route->IsVisible() ? 0 : 1);
1508 pConfig->UpdateRoute(route);
1509 }
1510
1511 ZoomtoRoute(route);
1512}
1513
1514void RouteManagerDialog::OnRteReverseClick(wxCommandEvent &event) {
1515 // Reverse selected route
1516 long item = -1;
1517 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1518 wxLIST_STATE_SELECTED);
1519 if (item == -1) return;
1520
1521 Route *route = (Route *)m_pRouteListCtrl->GetItemData(item);
1522
1523 if (!route) return;
1524 if (route->m_bIsInLayer) return;
1525
1526 int ask_return = OCPNMessageBox(this, g_pRouteMan->GetRouteReverseMessage(),
1527 _("Rename Waypoints?"), wxYES_NO | wxCANCEL);
1528 if (ask_return != wxID_CANCEL) {
1529 bool rename = (ask_return == wxID_YES);
1530
1531 pSelect->DeleteAllSelectableRouteSegments(route);
1532 route->Reverse(rename);
1533 pSelect->AddAllSelectableRouteSegments(route);
1534
1535 // update column 2 - create a UpdateRouteItem(index) instead?
1536 wxString startend = route->m_RouteStartString;
1537 if (!route->m_RouteEndString.IsEmpty())
1538 startend.append(_(" - ") + route->m_RouteEndString);
1539 m_pRouteListCtrl->SetItem(item, 2, startend);
1540
1541 pConfig->UpdateRoute(route);
1542 gFrame->RefreshAllCanvas();
1543 }
1544
1545 m_bNeedConfigFlush = true;
1546}
1547
1548void RouteManagerDialog::OnRteExportClick(wxCommandEvent &event) {
1549 RouteList list;
1550
1551 wxString suggested_name = _T("routes");
1552
1553 long item = -1;
1554 for (;;) {
1555 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1556 wxLIST_STATE_SELECTED);
1557 if (item == -1) break;
1558
1559 Route *proute_to_export = (Route *)m_pRouteListCtrl->GetItemData(item);
1560
1561 if (proute_to_export) {
1562 list.Append(proute_to_export);
1563 if (proute_to_export->m_RouteNameString != wxEmptyString)
1564 suggested_name = proute_to_export->m_RouteNameString;
1565 }
1566 }
1567
1568 ExportGPXRoutes(this, &list, suggested_name);
1569}
1570
1571void RouteManagerDialog::OnRteResequenceClick(wxCommandEvent &event) {
1572 long item = -1;
1573 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1574 wxLIST_STATE_SELECTED);
1575 if (item == -1) return;
1576
1577 Route *route = (Route *)m_pRouteListCtrl->GetItemData(item);
1578
1579 if (!route) return;
1580 if (route->m_bIsInLayer) return;
1581 route->RenameRoutePoints();
1582}
1583
1584void RouteManagerDialog::OnRteSendToPeerClick(wxCommandEvent &event) {
1585 std::vector<Route *> list;
1586 long item = -1;
1587 for (;;) {
1588 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1589 wxLIST_STATE_SELECTED);
1590 if (item == -1) break;
1591
1592 Route *proute = (Route *)m_pRouteListCtrl->GetItemData(item);
1593
1594 if (proute) {
1595 list.push_back(proute);
1596 }
1597 }
1598 if (!list.empty()) {
1599 SendToPeerDlg dlg;
1600 for (auto r : list) {
1601 dlg.SetRoute(r);
1602 }
1603
1604 // Perform initial scan, if necessary
1605
1606 // Check for stale cache...
1607 MdnsCache::GetInstance().Validate();
1608 if (MdnsCache::GetInstance().GetCache().empty()) dlg.SetScanOnCreate(true);
1609
1610 dlg.SetScanTime(5); // seconds
1611 dlg.Create(NULL, -1, _("Send Route(s) to OpenCPN Peer") + _T( "..." ),
1612 _T(""));
1613 dlg.ShowModal();
1614 }
1615}
1616
1617void RouteManagerDialog::OnWptSendToPeerClick(wxCommandEvent &event) {
1618 std::vector<RoutePoint *> list;
1619 long item = -1;
1620 for (;;) {
1621 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1622 wxLIST_STATE_SELECTED);
1623 if (item == -1) break;
1624
1625 RoutePoint *proutep = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
1626
1627 if (proutep) {
1628 list.push_back(proutep);
1629 }
1630 }
1631 if (!list.empty()) {
1632 SendToPeerDlg dlg;
1633 for (auto r : list) {
1634 dlg.SetWaypoint(r);
1635 }
1636
1637 // Perform initial scan, if necessary
1638
1639 // Check for stale cache...
1640 MdnsCache::GetInstance().Validate();
1641 if (MdnsCache::GetInstance().GetCache().empty()) dlg.SetScanOnCreate(true);
1642
1643 dlg.SetScanTime(5); // seconds
1644 dlg.Create(NULL, -1, _("Send Waypoint(s) to OpenCPN Peer") + _T( "..." ),
1645 _T(""));
1646 dlg.ShowModal();
1647 }
1648}
1649
1650void RouteManagerDialog::OnTrkSendToPeerClick(wxCommandEvent &event) {
1651 std::vector<Track *> list;
1652 long item = -1;
1653 for (;;) {
1654 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1655 wxLIST_STATE_SELECTED);
1656 if (item == -1) break;
1657
1658 Track *ptrk = (Track *)m_pTrkListCtrl->GetItemData(item);
1659
1660 if (ptrk) {
1661 list.push_back(ptrk);
1662 }
1663 }
1664 if (!list.empty()) {
1665 SendToPeerDlg dlg;
1666 for (auto r : list) {
1667 dlg.SetTrack(r);
1668 }
1669
1670 // Perform initial scan, if necessary
1671
1672 // Check for stale cache...
1673 MdnsCache::GetInstance().Validate();
1674 if (MdnsCache::GetInstance().GetCache().empty()) dlg.SetScanOnCreate(true);
1675
1676 dlg.SetScanTime(5); // seconds
1677 dlg.Create(NULL, -1, _("Send Track(s) to OpenCPN Peer") + _T( "..." ),
1678 _T(""));
1679 dlg.ShowModal();
1680 }
1681}
1682
1683void RouteManagerDialog::OnRteActivateClick(wxCommandEvent &event) {
1684 // Activate the selected route, unless it already is
1685 long item = -1;
1686 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1687 wxLIST_STATE_SELECTED);
1688 if (item == -1) return;
1689
1690 if (m_bCtrlDown) MakeAllRoutesInvisible();
1691
1692 Route *route = (Route *)m_pRouteListCtrl->GetItemData(item);
1693
1694 if (!route) return;
1695
1696 if (!route->m_bRtIsActive) {
1697 if (!route->IsVisible()) {
1698 route->SetVisible(true);
1699 m_pRouteListCtrl->SetItemImage(item, 0, 0);
1700 }
1701
1702 ZoomtoRoute(route);
1703
1704 RoutePoint *best_point =
1705 g_pRouteMan->FindBestActivatePoint(route, gLat, gLon, gCog, gSog);
1706 g_pRouteMan->ActivateRoute(route, best_point);
1707 // g_pRouteMan->ActivateRoute(route);
1708 } else
1709 g_pRouteMan->DeactivateRoute();
1710
1711 UpdateRouteListCtrl();
1712
1713 pConfig->UpdateRoute(route);
1714
1715 gFrame->RefreshAllCanvas();
1716
1717 // btnRteActivate->SetLabel(route->m_bRtIsActive ? _("Deactivate") :
1718 // _("Activate"));
1719
1720 m_bNeedConfigFlush = true;
1721}
1722
1723void RouteManagerDialog::OnRteToggleVisibility(wxMouseEvent &event) {
1724 wxPoint pos = event.GetPosition();
1725 int flags = 0;
1726 long clicked_index = m_pRouteListCtrl->HitTest(pos, flags);
1727
1728 // Clicking Visibility column?
1729 if (clicked_index > -1 &&
1730 event.GetX() < m_pRouteListCtrl->GetColumnWidth(rmVISIBLE)) {
1731 // Process the clicked item
1732 Route *route = (Route *)m_pRouteListCtrl->GetItemData(clicked_index);
1733
1734 route->SetVisible(!route->IsVisible());
1735
1736 m_pRouteListCtrl->SetItemImage(clicked_index, route->IsVisible() ? 0 : 1);
1737
1738 ::wxBeginBusyCursor();
1739
1740 pConfig->UpdateRoute(route);
1741 gFrame->RefreshAllCanvas();
1742
1743 // We need to update the waypoint list control since the visibility of
1744 // shared waypoints might have changed.
1745 if (g_pRouteMan->DoesRouteContainSharedPoints(route))
1746 UpdateWptListCtrlViz();
1747
1748 // Manage "show all" checkbox
1749 bool viz = true;
1750 long item = -1;
1751 for (;;) {
1752 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1753 wxLIST_STATE_DONTCARE);
1754 if (item == -1) break;
1755
1756 Route *pR = (Route *)m_pRouteListCtrl->GetItemData(item);
1757
1758 if (!pR->IsVisible()) {
1759 viz = false;
1760 break;
1761 }
1762 }
1763 m_cbShowAllRte->SetValue(viz);
1764
1765 ::wxEndBusyCursor();
1766 }
1767
1768 // Allow wx to process...
1769 event.Skip();
1770}
1771
1772void RouteManagerDialog::OnRteBtnLeftDown(wxMouseEvent &event) {
1773 m_bCtrlDown = event.ControlDown();
1774 event.Skip();
1775}
1776
1777void RouteManagerDialog::OnRteSelected(wxListEvent &event) {
1778 long clicked_index = event.m_itemIndex;
1779 // Process the clicked item
1780 Route *route = (Route *)m_pRouteListCtrl->GetItemData(clicked_index);
1781 // route->SetVisible(!route->IsVisible());
1782 m_pRouteListCtrl->SetItemImage(clicked_index, route->IsVisible() ? 0 : 1);
1783 // pConfig->UpdateRoute(route);
1784
1785 gFrame->RefreshAllCanvas();
1786
1787 UpdateRteButtons();
1788}
1789
1790void RouteManagerDialog::OnRteColumnClicked(wxListEvent &event) {
1791 if (event.m_col == 1) {
1792 sort_route_name_dir++;
1793
1794 m_pRouteListCtrl->SortItems(SortRoutesOnName, (wxIntPtr)NULL);
1795 } else if (event.m_col == 2) {
1796 sort_route_to_dir++;
1797 m_pRouteListCtrl->SortItems(SortRoutesOnTo, (wxIntPtr)NULL);
1798 }
1799}
1800
1801void RouteManagerDialog::OnRteSendToGPSClick(wxCommandEvent &event) {
1802 long item = -1;
1803 item = m_pRouteListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1804 wxLIST_STATE_SELECTED);
1805 if (item == -1) return;
1806
1807 Route *route = (Route *)m_pRouteListCtrl->GetItemData(item);
1808
1809 if (!route) return;
1810
1811 SendToGpsDlg *pdlg = new SendToGpsDlg();
1812 pdlg->SetRoute(route);
1813
1814 wxFont fo = GetOCPNGUIScaledFont(_("Dialog"));
1815 pdlg->SetFont(fo);
1816
1817 wxString source;
1818 pdlg->Create(NULL, -1, _("Send to GPS") + _T( "..." ), source);
1819
1820#ifdef __WXOSX__
1821 HideWithEffect(wxSHOW_EFFECT_BLEND);
1822#endif
1823
1824 pdlg->ShowModal();
1825
1826#ifdef __WXOSX__
1827 ShowWithEffect(wxSHOW_EFFECT_BLEND);
1828#endif
1829
1830 pdlg->Destroy();
1831}
1832
1833void RouteManagerDialog::OnRteDefaultAction(wxListEvent &event) {
1834 wxCommandEvent evt;
1835 OnRtePropertiesClick(evt);
1836}
1837
1838void RouteManagerDialog::OnTrkDefaultAction(wxListEvent &event) {
1839 wxCommandEvent evt;
1840 OnTrkPropertiesClick(evt);
1841}
1842
1843void RouteManagerDialog::OnTrkRightClick(wxListEvent &event) {
1844 wxMenu menu;
1845 wxMenuItem *mergeItem = menu.Append(TRACK_MERGE, _("&Merge Selected Tracks"));
1846 mergeItem->Enable(m_pTrkListCtrl->GetSelectedItemCount() > 1);
1847 wxMenuItem *cleanItem = menu.Append(TRACK_CLEAN, _("Reduce Data..."));
1848 cleanItem->Enable(m_pTrkListCtrl->GetSelectedItemCount() == 1);
1849 wxMenuItem *copyItem = menu.Append(TRACK_COPY_TEXT, _("&Copy as text"));
1850 copyItem->Enable(m_pTrkListCtrl->GetSelectedItemCount() > 0);
1851 PopupMenu(&menu);
1852}
1853
1854static bool CompareTracks(Track *track1, Track *track2) {
1855 TrackPoint *start1 = track1->GetPoint(0);
1856 TrackPoint *start2 = track2->GetPoint(0);
1857 return start1->GetCreateTime() < start2->GetCreateTime();
1858}
1859
1860void RouteManagerDialog::OnTrkMenuSelected(wxCommandEvent &event) {
1861 int item = -1;
1862
1863 switch (event.GetId()) {
1864 case TRACK_CLEAN: {
1865 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1866 wxLIST_STATE_SELECTED);
1867 if (item == -1) break;
1868 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
1869 if (track->IsRunning()) {
1870 wxBell();
1871 break;
1872 }
1873
1874 const wxString choices[] = {_T("5.0"), _T("10.0"), _T("20.0"), _T("50.0"),
1875 _T("100.0")};
1876
1877 wxSingleChoiceDialog precisionDlg(this,
1878 _("Select the maximum error allowed "
1879 "(in meters)\nafter data reduction:"),
1880 _("Reduce Data Precision"), 5, choices);
1881#ifdef __WXOSX__
1882 precisionDlg.ShowWindowModal();
1883 while (precisionDlg.IsShown()) {
1884 wxMilliSleep(10);
1885 wxYield();
1886 }
1887 int result = precisionDlg.GetReturnCode();
1888#else
1889 int result = precisionDlg.ShowModal();
1890#endif
1891 if (result == wxID_CANCEL) break;
1892 double precision = 5.0;
1893 switch (precisionDlg.GetSelection()) {
1894 case 0:
1895 precision = 5.0;
1896 break;
1897 case 1:
1898 precision = 10.0;
1899 break;
1900 case 2:
1901 precision = 20.0;
1902 break;
1903 case 3:
1904 precision = 50.0;
1905 break;
1906 case 4:
1907 precision = 100.0;
1908 break;
1909 }
1910
1911 int pointsBefore = track->GetnPoints();
1912
1913 int reduction = track->Simplify(precision);
1914 gFrame->Refresh(false);
1915
1916 reduction = 100 * reduction / pointsBefore;
1917 wxString msg = wxString::Format(
1918 _("The amount of data used by the track\n was reduced by %d%%."),
1919 reduction);
1920 OCPNMessageBox(this, msg, _("OpenCPN info"), wxICON_INFORMATION | wxOK);
1921
1922 UpdateTrkListCtrl();
1923 UpdateRouteListCtrl();
1924
1925 break;
1926 }
1927
1928 case TRACK_COPY_TEXT: {
1929 wxString csvString;
1930 while (1) {
1931 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1932 wxLIST_STATE_SELECTED);
1933 if (item == -1) break;
1934 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
1935 csvString << track->GetName() << _T("\t")
1936 << wxString::Format(_T("%.1f"), track->Length()) << _T("\t")
1937 << _T("\n");
1938 }
1939
1940 if (wxTheClipboard->Open()) {
1941 wxTextDataObject *data = new wxTextDataObject;
1942 data->SetText(csvString);
1943 wxTheClipboard->SetData(data);
1944 wxTheClipboard->Close();
1945 }
1946
1947 break;
1948 }
1949
1950 case TRACK_MERGE: {
1951 Track *targetTrack = NULL;
1952 TrackPoint *tPoint;
1953 TrackPoint *newPoint;
1954 TrackPoint *lastPoint;
1955 std::vector<Track *> mergeList;
1956 std::vector<Track *> deleteList;
1957 bool runningSkipped = false;
1958
1959 ::wxBeginBusyCursor();
1960
1961 while (1) {
1962 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
1963 wxLIST_STATE_SELECTED);
1964 if (item == -1) break;
1965 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
1966 mergeList.push_back(track);
1967 }
1968
1969 if (!mergeList.size()) {
1970 ::wxEndBusyCursor();
1971 break;
1972 }
1973
1974 std::sort(mergeList.begin(), mergeList.end(), CompareTracks);
1975
1976 targetTrack = mergeList[0];
1977 lastPoint = targetTrack->GetLastPoint();
1978
1979 for (auto const &mergeTrack : mergeList) {
1980 if (mergeTrack == *mergeList.begin()) continue;
1981
1982 if (mergeTrack->IsRunning()) {
1983 runningSkipped = true;
1984 continue;
1985 }
1986
1987 for (int i = 0; i < mergeTrack->GetnPoints(); i++) {
1988 tPoint = mergeTrack->GetPoint(i);
1989 newPoint = new TrackPoint(tPoint->m_lat, tPoint->m_lon,
1990 tPoint->GetCreateTime());
1991
1992 targetTrack->AddPoint(newPoint);
1993 NavObj_dB::GetInstance().AddTrackPoint(targetTrack, newPoint);
1994
1995 pSelect->AddSelectableTrackSegment(lastPoint->m_lat, lastPoint->m_lon,
1996 newPoint->m_lat, newPoint->m_lon,
1997 lastPoint, newPoint, targetTrack);
1998 lastPoint = newPoint;
1999 }
2000 deleteList.push_back(mergeTrack);
2001 }
2002
2003 for (auto const &deleteTrack : deleteList) {
2004 g_pAIS->DeletePersistentTrack(deleteTrack);
2005 NavObj_dB::GetInstance().DeleteTrack(deleteTrack);
2006 RoutemanGui(*g_pRouteMan).DeleteTrack(deleteTrack);
2007 }
2008
2009 mergeList.clear();
2010 deleteList.clear();
2011
2012 ::wxEndBusyCursor();
2013
2014 UpdateTrkListCtrl();
2015 UpdateRouteListCtrl();
2016 gFrame->RefreshAllCanvas();
2017
2018 if (runningSkipped) {
2019 wxMessageDialog skipWarning(
2020 this,
2021 _("The currently running Track was not merged.\nYou can merge it "
2022 "later when it is completed."),
2023 _T("Warning"), wxCANCEL | wxICON_WARNING);
2024 skipWarning.ShowModal();
2025 }
2026
2027 break;
2028 }
2029 }
2030}
2031
2032void RouteManagerDialog::UpdateTrkListCtrl() {
2033 // if an item was selected, make it selected again if it still exist
2034 long item = -1;
2035 item =
2036 m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2037
2038 wxUIntPtr selected_id = wxUIntPtr(0);
2039 if (item != -1) selected_id = m_pTrkListCtrl->GetItemData(item);
2040
2041 // Delete existing items
2042 m_pTrkListCtrl->DeleteAllItems();
2043
2044 // then add tracks to the listctrl
2045 std::vector<Track *>::iterator it;
2046 int index = 0;
2047 int list_index = 0;
2048 bool bpartialViz = false;
2049
2050 for (Track *trk : g_TrackList) {
2051 if (!trk->IsVisible()) bpartialViz = true;
2052
2053 if (!trk->IsListed()) continue;
2054
2055 if (!trk->GetName(true).Upper().Contains(
2056 m_tFilterTrk->GetValue().Upper())) {
2057 continue;
2058 }
2059
2060 wxListItem li;
2061 li.SetId(list_index);
2062 li.SetImage(trk->IsVisible() ? 0 : 1);
2063 li.SetData(trk);
2064 li.SetText(_T(""));
2065
2066 if (g_pActiveTrack == trk) {
2067 wxFont font = *wxNORMAL_FONT;
2068 font.SetWeight(wxFONTWEIGHT_BOLD);
2069 li.SetFont(font);
2070 }
2071 long idx = m_pTrkListCtrl->InsertItem(li);
2072
2073 m_pTrkListCtrl->SetItem(idx, colTRKNAME, trk->GetName(true));
2074 // Populate the track start date/time, formatted using the global timezone
2075 // settings.
2076 m_pTrkListCtrl->SetItem(idx, colTRKDATE, trk->GetDateTime());
2077
2078 wxString len;
2079 len.Printf(wxT("%5.2f"), trk->Length());
2080 m_pTrkListCtrl->SetItem(idx, colTRKLENGTH, len);
2081
2082 wxListItem lic;
2083 lic.SetId(list_index);
2084 lic.SetColumn(1);
2085 lic.SetAlign(wxLIST_FORMAT_LEFT);
2086 m_pTrkListCtrl->SetItem(lic);
2087
2088 lic.SetColumn(2);
2089 lic.SetAlign(wxLIST_FORMAT_LEFT);
2090 m_pTrkListCtrl->SetItem(lic);
2091
2092 list_index++;
2093 }
2094
2095 switch (sort_track_key) {
2096 case SORT_ON_DISTANCE:
2097 m_pTrkListCtrl->SortItems(SortTracksOnDistance, (wxIntPtr)NULL);
2098 break;
2099 case SORT_ON_DATE:
2100 m_pTrkListCtrl->SortItems(SortTracksOnDate, (wxIntPtr)NULL);
2101 break;
2102 case SORT_ON_NAME:
2103 default:
2104 m_pTrkListCtrl->SortItems(SortTracksOnName, (wxIntPtr)NULL);
2105 break;
2106 }
2107
2108 m_pTrkListCtrl->SetColumnWidth(0, 4 * m_charWidth);
2109
2110 // restore selection if possible
2111 // NOTE this will select a different item, if one is deleted
2112 // (the next route will get that index).
2113 if (selected_id != wxUIntPtr(0)) {
2114 item = m_pTrkListCtrl->FindItem(-1, selected_id);
2115 m_pTrkListCtrl->SetItemState(item,
2116 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
2117 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
2118 }
2119
2120 if ((m_lastTrkItem >= 0) && (m_pTrkListCtrl->GetItemCount()))
2121 m_pTrkListCtrl->EnsureVisible(m_lastTrkItem);
2122
2123 m_cbShowAllTrk->SetValue(!bpartialViz);
2124 UpdateTrkButtons();
2125}
2126
2127void RouteManagerDialog::OnTrkSelected(wxListEvent &event) {
2128 UpdateTrkButtons();
2129}
2130
2131void RouteManagerDialog::OnTrkColumnClicked(wxListEvent &event) {
2132 if (event.m_col == 1) {
2133 sort_track_key = SORT_ON_NAME;
2134 sort_track_name_dir++;
2135 m_pTrkListCtrl->SortItems(SortTracksOnName, (wxIntPtr)NULL);
2136 } else if (event.m_col == 2) {
2137 sort_track_key = SORT_ON_DISTANCE;
2138 sort_track_len_dir++;
2139 m_pTrkListCtrl->SortItems(SortTracksOnDistance, (wxIntPtr)NULL);
2140 } else if (event.m_col == 3) {
2141 sort_track_key = SORT_ON_DATE;
2142 sort_track_date_dir++;
2143 m_pTrkListCtrl->SortItems(SortTracksOnDate, (wxIntPtr)NULL);
2144 }
2145}
2146
2147void RouteManagerDialog::UpdateTrkButtons() {
2148 long item = -1;
2149 item =
2150 m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2151 int items = m_pTrkListCtrl->GetSelectedItemCount();
2152
2153 m_lastTrkItem = item;
2154
2155 btnTrkProperties->Enable(items == 1);
2156 btnTrkDelete->Enable(items >= 1);
2157 btnTrkExport->Enable(items >= 1);
2158 btnTrkRouteFromTrack->Enable(items == 1);
2159 btnTrkDeleteAll->Enable(m_pTrkListCtrl->GetItemCount() > 0);
2160 btnTrkSendToPeer->Enable(items >= 1);
2161}
2162
2163void RouteManagerDialog::OnTrkToggleVisibility(wxMouseEvent &event) {
2164 wxPoint pos = event.GetPosition();
2165 int flags = 0;
2166 long clicked_index = m_pTrkListCtrl->HitTest(pos, flags);
2167
2168 // Clicking Visibility column?
2169 if (clicked_index > -1 &&
2170 event.GetX() < m_pTrkListCtrl->GetColumnWidth(colTRKVISIBLE)) {
2171 // Process the clicked item
2172 Track *track = (Track *)m_pTrkListCtrl->GetItemData(clicked_index);
2173 if (track) {
2174 track->SetVisible(!track->IsVisible());
2175 m_pTrkListCtrl->SetItemImage(clicked_index, track->IsVisible() ? 0 : 1);
2176 }
2177
2178 // Manage "show all" checkbox
2179 bool viz = true;
2180 long item = -1;
2181 for (;;) {
2182 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2183 wxLIST_STATE_DONTCARE);
2184 if (item == -1) break;
2185
2186 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
2187
2188 if (!track->IsVisible()) {
2189 viz = false;
2190 break;
2191 }
2192 }
2193 m_cbShowAllTrk->SetValue(viz);
2194
2195 gFrame->RefreshAllCanvas();
2196 }
2197
2198 // Allow wx to process...
2199 event.Skip();
2200}
2201
2202void RouteManagerDialog::OnTrkNewClick(wxCommandEvent &event) {
2203 gFrame->TrackOff();
2204 if (pConfig && pConfig->IsChangesFileDirty()) {
2205 pConfig->UpdateNavObj(true);
2206 }
2207
2208 gFrame->TrackOn();
2209
2210 UpdateTrkListCtrl();
2211}
2212
2213void RouteManagerDialog::OnTrkPropertiesClick(wxCommandEvent &event) {
2214 // Show trackproperties dialog for selected track
2215 long item = -1;
2216 item =
2217 m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2218 if (item == -1) return;
2219
2220 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
2221
2222 if (!track) return;
2223
2224 pTrackPropDialog = TrackPropDlg::getInstance(GetParent());
2225 pTrackPropDialog->SetTrackAndUpdate(track);
2226
2227 if (!pTrackPropDialog->IsShown()) pTrackPropDialog->Show();
2228 UpdateTrkListCtrl();
2229
2230 m_bNeedConfigFlush = true;
2231}
2232
2233void RouteManagerDialog::OnTrkDeleteClick(wxCommandEvent &event) {
2234 std::vector<Track *> list;
2235
2236 int answer = OCPNMessageBox(
2237 this, _("Are you sure you want to delete the selected object(s)"),
2238 wxString(_("OpenCPN Alert")), wxYES_NO);
2239 if (answer != wxID_YES) return;
2240
2241 bool busy = false;
2242 if (m_pTrkListCtrl->GetSelectedItemCount()) {
2243 ::wxBeginBusyCursor();
2244 // m_bNeedConfigFlush = true;
2245 busy = true;
2246 }
2247
2248 long item = -1;
2249 for (;;) {
2250 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2251 wxLIST_STATE_SELECTED);
2252 if (item == -1) break;
2253
2254 Track *ptrack_to_delete = (Track *)m_pTrkListCtrl->GetItemData(item);
2255
2256 if (ptrack_to_delete) list.push_back(ptrack_to_delete);
2257 }
2258
2259 if (busy) {
2260 for (unsigned int i = 0; i < list.size(); i++) {
2261 Track *track = list.at(i);
2262 if (track) {
2263 g_pAIS->DeletePersistentTrack(track);
2264 NavObj_dB::GetInstance().DeleteTrack(track);
2265 RoutemanGui(*g_pRouteMan).DeleteTrack(track);
2266 }
2267 }
2268
2269 m_lastTrkItem = -1;
2270 // UpdateRouteListCtrl();
2271 UpdateTrkListCtrl();
2272
2273 if (pConfig && pConfig->IsChangesFileDirty()) {
2274 pConfig->UpdateNavObj(true);
2275 }
2276
2277 gFrame->InvalidateAllCanvasUndo();
2278 gFrame->RefreshAllCanvas();
2279 ::wxEndBusyCursor();
2280 }
2281}
2282
2283void RouteManagerDialog::OnTrkExportClick(wxCommandEvent &event) {
2284 std::vector<Track *> list;
2285 wxString suggested_name = _T("tracks");
2286
2287 long item = -1;
2288 for (;;) {
2289 item = m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2290 wxLIST_STATE_SELECTED);
2291 if (item == -1) break;
2292
2293 Track *ptrack_to_export = (Track *)m_pTrkListCtrl->GetItemData(item);
2294
2295 if (ptrack_to_export) {
2296 list.push_back(ptrack_to_export);
2297 if (ptrack_to_export->GetName() != wxEmptyString)
2298 suggested_name = ptrack_to_export->GetName();
2299 }
2300 }
2301
2302 ExportGPXTracks(this, &list, suggested_name);
2303}
2304
2305void RouteManagerDialog::TrackToRoute(Track *track) {
2306 if (!track) return;
2307 if (track->m_bIsInLayer) return;
2308
2309 wxGenericProgressDialog pprog(_("OpenCPN Converting Track to Route...."),
2310 _("Processing Waypoints..."), 101, NULL,
2311 wxPD_AUTO_HIDE | wxPD_SMOOTH |
2312 wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME |
2313 wxPD_REMAINING_TIME);
2314
2315 ::wxBeginBusyCursor();
2316
2317 Route *route = track->RouteFromTrack(&pprog);
2318
2319 pRouteList->Append(route);
2320
2321 pprog.Update(101, _("Done."));
2322
2323 gFrame->RefreshAllCanvas();
2324
2325 ::wxEndBusyCursor();
2326}
2327
2328void RouteManagerDialog::OnTrkRouteFromTrackClick(wxCommandEvent &event) {
2329 long item = -1;
2330 item =
2331 m_pTrkListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2332 if (item == -1) return;
2333
2334 Track *track = (Track *)m_pTrkListCtrl->GetItemData(item);
2335
2336 TrackToRoute(track);
2337
2338 UpdateRouteListCtrl();
2339}
2340
2341void RouteManagerDialog::OnTrkDeleteAllClick(wxCommandEvent &event) {
2342 int dialog_ret =
2343 OCPNMessageBox(this, _("Are you sure you want to delete <ALL> tracks?"),
2344 wxString(_("OpenCPN Alert")), wxYES_NO);
2345
2346 if (dialog_ret == wxID_YES) {
2347 RoutemanGui(*g_pRouteMan).DeleteAllTracks();
2348 }
2349
2350 m_lastTrkItem = -1;
2351 m_lastRteItem = -1;
2352
2353 UpdateTrkListCtrl();
2354
2355 // Also need to update the route list control, since routes and tracks
2356 // share a common global list (pRouteList)
2357 UpdateRouteListCtrl();
2358
2359 if (pRoutePropDialog) pRoutePropDialog->Hide();
2360
2361 gFrame->RefreshAllCanvas();
2362
2363 m_bNeedConfigFlush = true;
2364}
2365
2366void RouteManagerDialog::UpdateWptListCtrl(RoutePoint *rp_select,
2367 bool b_retain_sort) {
2368 wxIntPtr selected_id = wxUIntPtr(0);
2369 long item = -1;
2370
2371 if (NULL == rp_select) {
2372 // if an item was selected, make it selected again if it still exists
2373 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2374 wxLIST_STATE_SELECTED);
2375
2376 if (item != -1) selected_id = m_pWptListCtrl->GetItemData(item);
2377 }
2378
2379 // Freshen the image list
2380 m_pWptListCtrl->SetImageList(
2381 pWayPointMan->Getpmarkicon_image_list(m_listIconSize),
2382 wxIMAGE_LIST_SMALL);
2383
2384 m_pWptListCtrl->DeleteAllItems();
2385
2386 wxRoutePointListNode *node = pWayPointMan->GetWaypointList()->GetFirst();
2387
2388 int index = 0;
2389 bool b_anyHidden = false;
2390 while (node) {
2391 RoutePoint *rp = node->GetData();
2392 if (rp && rp->IsListed()) {
2393 if (rp->m_bIsInRoute && !rp->IsShared()) {
2394 node = node->GetNext();
2395 continue;
2396 }
2397
2398 if (!rp->GetName().Upper().Contains(m_tFilterWpt->GetValue().Upper())) {
2399 node = node->GetNext();
2400 continue;
2401 }
2402
2403 wxListItem li;
2404 li.SetId(index);
2405 li.SetImage(RoutePointGui(*rp).GetIconImageIndex());
2406 li.SetData(rp);
2407 li.SetText(_T(""));
2408 long idx = m_pWptListCtrl->InsertItem(li);
2409
2410 wxString scamin = wxString::Format(_T("%i"), (int)rp->GetScaMin());
2411 if (!rp->GetUseSca()) scamin = _("Always");
2412 if (g_bOverruleScaMin) scamin = _("Overruled");
2413 m_pWptListCtrl->SetItem(idx, colWPTSCALE, scamin);
2414
2415 wxString name = rp->GetName();
2416 if (name.IsEmpty()) name = _("(Unnamed Waypoint)");
2417 m_pWptListCtrl->SetItem(idx, colWPTNAME, name);
2418
2419 double dst;
2420 DistanceBearingMercator(rp->m_lat, rp->m_lon, gLat, gLon, NULL, &dst);
2421 wxString dist;
2422 dist.Printf(_T("%5.2f ") + getUsrDistanceUnit(), toUsrDistance(dst));
2423 m_pWptListCtrl->SetItem(idx, colWPTDIST, dist);
2424
2425 if (rp == rp_select) selected_id = (wxIntPtr)rp_select;
2426
2427 wxListItem lic;
2428 lic.SetId(index);
2429 lic.SetColumn(1);
2430 lic.SetAlign(wxLIST_FORMAT_LEFT);
2431 m_pWptListCtrl->SetItem(lic);
2432
2433 lic.SetColumn(2);
2434 lic.SetAlign(wxLIST_FORMAT_LEFT);
2435 m_pWptListCtrl->SetItem(lic);
2436
2437 if (!rp->IsVisible()) b_anyHidden = true;
2438
2439 index++;
2440 }
2441
2442 node = node->GetNext();
2443 }
2444
2445 if (!b_retain_sort) {
2446 m_pWptListCtrl->SortItems(SortWaypointsOnName,
2447 reinterpret_cast<wxIntPtr>(m_pWptListCtrl));
2448 sort_wp_key = SORT_ON_NAME;
2449 } else {
2450 switch (sort_wp_key) {
2451 case SORT_ON_NAME:
2452 m_pWptListCtrl->SortItems(SortWaypointsOnName,
2453 reinterpret_cast<wxIntPtr>(m_pWptListCtrl));
2454 break;
2455 case SORT_ON_DISTANCE:
2456 m_pWptListCtrl->SortItems(SortWaypointsOnDistance,
2457 reinterpret_cast<wxIntPtr>(m_pWptListCtrl));
2458 break;
2459 }
2460 }
2461
2462 if (selected_id != wxUIntPtr(0)) {
2463 item = m_pWptListCtrl->FindItem(-1, selected_id);
2464 m_pWptListCtrl->SetItemState(item,
2465 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
2466 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
2467 }
2468
2469 if ((m_lastWptItem >= 0) && (m_pWptListCtrl->GetItemCount()))
2470 m_pWptListCtrl->EnsureVisible(m_lastWptItem);
2471
2472 if (pWayPointMan->Getpmarkicon_image_list(m_listIconSize)->GetImageCount()) {
2473 int iwidth, iheight;
2474 pWayPointMan->Getpmarkicon_image_list(m_listIconSize)
2475 ->GetSize(0, iwidth, iheight);
2476
2477 m_pWptListCtrl->SetColumnWidth(0, wxMax(iwidth + 4, 4 * m_charWidth));
2478 }
2479
2480 UpdateWptButtons();
2481
2482 m_cbShowAllWP->SetValue(!b_anyHidden);
2483}
2484
2485void RouteManagerDialog::UpdateWptListCtrlViz() {
2486 long item = -1;
2487 for (;;) {
2488 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2489 wxLIST_STATE_DONTCARE);
2490 if (item == -1) break;
2491
2492 RoutePoint *pRP = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2493 int imageIndex = RoutePointGui(*pRP).GetIconImageIndex();
2494
2495 m_pWptListCtrl->SetItemImage(item, imageIndex);
2496 }
2497}
2498
2499void RouteManagerDialog::OnWptDefaultAction(wxListEvent &event) {
2500 wxCommandEvent evt;
2501 OnWptPropertiesClick(evt);
2502}
2503
2504void RouteManagerDialog::OnWptSelected(wxListEvent &event) {
2505 UpdateWptButtons();
2506}
2507
2508void RouteManagerDialog::OnWptColumnClicked(wxListEvent &event) {
2509 if (event.m_col == NAME_COLUMN) {
2510 sort_wp_name_dir++;
2511 m_pWptListCtrl->SortItems(SortWaypointsOnName,
2512 reinterpret_cast<wxIntPtr>(m_pWptListCtrl));
2513 sort_wp_key = SORT_ON_NAME;
2514 } else {
2515 if (event.m_col == DISTANCE_COLUMN) {
2516 sort_wp_len_dir++;
2517 m_pWptListCtrl->SortItems(SortWaypointsOnDistance,
2518 reinterpret_cast<wxIntPtr>(m_pWptListCtrl));
2519 sort_wp_key = SORT_ON_DISTANCE;
2520 }
2521 }
2522 UpdateWptListCtrl();
2523}
2524
2525void RouteManagerDialog::UpdateWptButtons() {
2526 long item = -1;
2527 item =
2528 m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2529 bool enable1 = (m_pWptListCtrl->GetSelectedItemCount() == 1);
2530 bool enablemultiple = (m_pWptListCtrl->GetSelectedItemCount() >= 1);
2531
2532 if (enable1)
2533 m_lastWptItem = item;
2534 else
2535 m_lastWptItem = -1;
2536
2537 // Check selection to see if it is in a layer
2538 // If so, disable the "delete" button
2539 bool b_delete_enable = true;
2540 item = -1;
2541 for (;;) {
2542 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2543 wxLIST_STATE_SELECTED);
2544 if (item == -1) break;
2545
2546 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2547
2548 if (wp && wp->m_bIsInLayer) {
2549 b_delete_enable = false;
2550 break;
2551 }
2552 }
2553
2554 btnWptProperties->Enable(enablemultiple);
2555 btnWptZoomto->Enable(enable1);
2556 btnWptDeleteAll->Enable(m_pWptListCtrl->GetItemCount() > 0);
2557 btnWptDelete->Enable(b_delete_enable && enablemultiple);
2558 btnWptGoTo->Enable(enable1);
2559 btnWptExport->Enable(enablemultiple);
2560 btnWptSendToGPS->Enable(enable1);
2561 btnWptSendToPeer->Enable(enablemultiple);
2562}
2563
2564void RouteManagerDialog::OnWptToggleVisibility(wxMouseEvent &event) {
2565 wxPoint pos = event.GetPosition();
2566 int flags = 0;
2567 long clicked_index = m_pWptListCtrl->HitTest(pos, flags);
2568
2569 // Clicking Visibility column?
2570 if (clicked_index > -1 &&
2571 event.GetX() < m_pWptListCtrl->GetColumnWidth(colTRKVISIBLE)) {
2572 // Process the clicked item
2573 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(clicked_index);
2574
2575 if (!wp->IsSharedInVisibleRoute()) {
2576 wp->SetVisible(!wp->IsVisible());
2577 m_pWptListCtrl->SetItemImage(clicked_index,
2578 RoutePointGui(*wp).GetIconImageIndex());
2579
2580 pConfig->UpdateWayPoint(wp);
2581 }
2582
2583 // Manage "show all" checkbox
2584 bool viz = true;
2585 long item = -1;
2586 for (;;) {
2587 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2588 wxLIST_STATE_DONTCARE);
2589 if (item == -1) break;
2590
2591 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2592
2593 if (!wp->IsVisible()) {
2594 viz = false;
2595 break;
2596 }
2597 }
2598 m_cbShowAllWP->SetValue(viz);
2599
2600 gFrame->RefreshAllCanvas();
2601 } else // clicked on ScaMin column??
2602 if (clicked_index > -1 &&
2603 event.GetX() > m_pWptListCtrl->GetColumnWidth(colTRKVISIBLE) &&
2604 event.GetX() < (m_pWptListCtrl->GetColumnWidth(colTRKVISIBLE) +
2605 m_pWptListCtrl->GetColumnWidth(colWPTSCALE)) &&
2606 !g_bOverruleScaMin) {
2607 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(clicked_index);
2608 wp->SetUseSca(!wp->GetUseSca());
2609 pConfig->UpdateWayPoint(wp);
2610 gFrame->RefreshAllCanvas();
2611 wxString scamin = wxString::Format(_T("%i"), (int)wp->GetScaMin());
2612 if (!wp->GetUseSca()) scamin = _("Always");
2613 m_pWptListCtrl->SetItem(clicked_index, colWPTSCALE, scamin);
2614 }
2615
2616 // Allow wx to process...
2617 event.Skip();
2618}
2619
2620void RouteManagerDialog::OnWptNewClick(wxCommandEvent &event) {
2621 RoutePoint *pWP = new RoutePoint(gLat, gLon, g_default_wp_icon, wxEmptyString,
2622 wxEmptyString);
2623 pWP->m_bIsolatedMark = true; // This is an isolated mark
2624 pSelect->AddSelectableRoutePoint(gLat, gLon, pWP);
2625 pConfig->AddNewWayPoint(pWP, -1); // use auto next num
2626 gFrame->RefreshAllCanvas();
2627
2628 // g_pMarkInfoDialog = MarkInfoImpl::GetInstance( GetParent() );
2629 // There is on global instance of the MarkProp Dialog
2630 if (!g_pMarkInfoDialog) g_pMarkInfoDialog = new MarkInfoDlg(GetParent());
2631
2632 WptShowPropertiesDialog(pWP, GetParent());
2633}
2634
2635void RouteManagerDialog::OnWptPropertiesClick(wxCommandEvent &event) {
2636 long item = wxNOT_FOUND;
2637 item =
2638 m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2639 if (item == wxNOT_FOUND) return;
2640
2641 auto pWP = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2642 WptShowPropertiesDialog(pWP, GetParent());
2643
2644 UpdateWptListCtrl();
2645 m_bNeedConfigFlush = true;
2646}
2647
2648void RouteManagerDialog::WptShowPropertiesDialog(RoutePoint *pWP,
2649 wxWindow *parent) {
2650 if (!g_pMarkInfoDialog) // There is one global instance of the MarkProp
2651 // Dialog
2652 g_pMarkInfoDialog = new MarkInfoDlg(parent);
2653
2654 g_pMarkInfoDialog->SetRoutePoint(pWP);
2655 g_pMarkInfoDialog->UpdateProperties();
2656
2657 wxString base_title = _("Waypoint Properties");
2658
2659 if (pWP->m_bIsInLayer) {
2660 wxString caption(wxString::Format(_T("%s, %s: %s"), base_title, _("Layer"),
2661 GetLayerName(pWP->m_LayerID)));
2662 g_pMarkInfoDialog->SetDialogTitle(caption);
2663 } else {
2664 g_pMarkInfoDialog->SetDialogTitle(base_title);
2665 }
2666
2667 if (!g_pMarkInfoDialog->IsShown()) g_pMarkInfoDialog->Show();
2668 g_pMarkInfoDialog->Raise();
2669}
2670
2671void RouteManagerDialog::OnWptZoomtoClick(wxCommandEvent &event) {
2672 long item = -1;
2673 item =
2674 m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2675 if (item == -1) return;
2676
2677 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2678
2679 if (!wp) return;
2680
2681 if (gFrame->GetFocusCanvas()) {
2682 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), wp->m_lat, wp->m_lon,
2683 gFrame->GetFocusCanvas()->GetVPScale());
2684 }
2685}
2686
2687void RouteManagerDialog::OnWptDeleteClick(wxCommandEvent &event) {
2688 RoutePointList list;
2689
2690 int answer = OCPNMessageBox(
2691 this, _("Are you sure you want to delete the selected object(s)"),
2692 wxString(_("OpenCPN Alert")), wxYES_NO);
2693 if (answer != wxID_YES) return;
2694
2695 bool busy = false;
2696 if (m_pWptListCtrl->GetSelectedItemCount()) {
2697 ::wxBeginBusyCursor();
2698 m_bNeedConfigFlush = true;
2699 busy = true;
2700 }
2701
2702 long item = -1;
2703 long item_last_selected = -1;
2704 for (;;) {
2705 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2706 wxLIST_STATE_SELECTED);
2707 if (item == -1) break;
2708
2709 item_last_selected = item;
2710 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2711
2712 if (wp && !wp->m_bIsInLayer) list.Append(wp);
2713 }
2714
2715 if (busy) {
2716 for (unsigned int i = 0; i < list.GetCount(); i++) {
2717 RoutePoint *wp = list.Item(i)->GetData();
2718 if (wp) {
2719 if (wp->m_bIsInRoute) {
2720 if (wxID_YES ==
2721 OCPNMessageBox(this,
2722 _("The waypoint you want to delete is used in a "
2723 "route, do you really want to delete it?"),
2724 _("OpenCPN Alert"), wxYES_NO))
2725 pWayPointMan->DestroyWaypoint(wp);
2726 } else
2727 pWayPointMan->DestroyWaypoint(wp);
2728 }
2729 }
2730
2731 long item_next =
2732 m_pWptListCtrl->GetNextItem(item_last_selected); // next in list
2733 RoutePoint *wp_next = NULL;
2734 if (item_next > -1)
2735 wp_next = (RoutePoint *)m_pWptListCtrl->GetItemData(item_next);
2736
2737 m_lastWptItem = item_next;
2738
2739 UpdateRouteListCtrl();
2740 UpdateTrkListCtrl();
2741 UpdateWptListCtrl(wp_next, true);
2742
2743 if (g_pMarkInfoDialog) {
2744 g_pMarkInfoDialog->ClearData();
2745 }
2746
2747 gFrame->InvalidateAllCanvasUndo();
2748 gFrame->RefreshAllCanvas();
2749 ::wxEndBusyCursor();
2750 }
2751}
2752
2753void RouteManagerDialog::OnWptGoToClick(wxCommandEvent &event) {
2754 long item = -1;
2755 item =
2756 m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2757 if (item == -1) return;
2758
2759 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2760
2761 if (!wp) return;
2762
2763 RoutePoint *pWP_src = new RoutePoint(gLat, gLon, g_default_wp_icon,
2764 wxEmptyString, wxEmptyString);
2765 pSelect->AddSelectableRoutePoint(gLat, gLon, pWP_src);
2766
2767 Route *temp_route = new Route();
2768 pRouteList->Append(temp_route);
2769
2770 temp_route->AddPoint(pWP_src);
2771 temp_route->AddPoint(wp);
2772
2773 pSelect->AddSelectableRouteSegment(gLat, gLon, wp->m_lat, wp->m_lon, pWP_src,
2774 wp, temp_route);
2775
2776 wxString name = wp->GetName();
2777 if (name.IsEmpty()) name = _("(Unnamed Waypoint)");
2778 wxString rteName = _("Go to ");
2779 rteName.Append(name);
2780 temp_route->m_RouteNameString = rteName;
2781 temp_route->m_RouteStartString = _("Here");
2782
2783 temp_route->m_RouteEndString = name;
2784 temp_route->m_bDeleteOnArrival = true;
2785
2786 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
2787
2788 g_pRouteMan->ActivateRoute(temp_route, wp);
2789
2790 UpdateRouteListCtrl();
2791}
2792
2793void RouteManagerDialog::OnWptExportClick(wxCommandEvent &event) {
2794 RoutePointList list;
2795
2796 wxString suggested_name = _T("waypoints");
2797
2798 long item = -1;
2799 for (;;) {
2800 item = m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2801 wxLIST_STATE_SELECTED);
2802 if (item == -1) break;
2803
2804 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2805
2806 if (wp && !wp->m_bIsInLayer) {
2807 list.Append(wp);
2808 if (wp->GetName() != wxEmptyString) suggested_name = wp->GetName();
2809 }
2810 }
2811
2812 ExportGPXWaypoints(this, &list, suggested_name);
2813}
2814
2815void RouteManagerDialog::OnWptSendToGPSClick(wxCommandEvent &event) {
2816 long item = -1;
2817 item =
2818 m_pWptListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2819 if (item == -1) return;
2820
2821 RoutePoint *wp = (RoutePoint *)m_pWptListCtrl->GetItemData(item);
2822
2823 if (!wp) return;
2824
2825 SendToGpsDlg *pdlg = new SendToGpsDlg();
2826 pdlg->SetWaypoint(wp);
2827
2828 wxString source;
2829 pdlg->Create(NULL, -1, _("Send to GPS") + _T( "..." ), source);
2830
2831#ifdef __WXOSX__
2832 HideWithEffect(wxSHOW_EFFECT_BLEND);
2833#endif
2834 pdlg->ShowModal();
2835#ifdef __WXOSX__
2836 ShowWithEffect(wxSHOW_EFFECT_BLEND);
2837#endif
2838
2839 delete pdlg;
2840}
2841
2842void RouteManagerDialog::OnWptDeleteAllClick(wxCommandEvent &event) {
2843 wxString prompt;
2844 int buttons, type;
2845 if (!pWayPointMan->SharedWptsExist()) {
2846 prompt = _("Are you sure you want to delete <ALL> waypoints?");
2847 buttons = wxYES_NO;
2848 type = 1;
2849 } else {
2850 prompt =
2851 _("There are some waypoints used in routes or anchor alarms.\n Do you "
2852 "want to delete them as well?\n This will change the routes and "
2853 "disable the anchor alarms.\n Answering No keeps the waypoints used "
2854 "in routes or alarms.");
2855 buttons = wxYES_NO | wxCANCEL;
2856 type = 2;
2857 }
2858 int answer =
2859 OCPNMessageBox(this, prompt, wxString(_("OpenCPN Alert")), buttons);
2860 if (answer == wxID_YES) pWayPointMan->DeleteAllWaypoints(true);
2861 if (answer == wxID_NO && type == 2)
2862 pWayPointMan->DeleteAllWaypoints(false); // only delete unused waypoints
2863
2864 if (g_pMarkInfoDialog) {
2865 g_pMarkInfoDialog->ClearData();
2866 }
2867
2868 m_lastWptItem = -1;
2869 UpdateRouteListCtrl();
2870 UpdateWptListCtrl();
2871 gFrame->InvalidateAllCanvasUndo();
2872 gFrame->RefreshAllCanvas();
2873}
2874
2875void RouteManagerDialog::OnLaySelected(wxListEvent &event) {
2876 UpdateLayButtons();
2877}
2878
2879void RouteManagerDialog::OnLayColumnClicked(wxListEvent &event) {
2880 if (event.m_col == 1) {
2881 sort_layer_name_dir++;
2882 m_pLayListCtrl->SortItems(SortLayersOnName, (wxIntPtr)NULL);
2883 } else if (event.m_col == 2) {
2884 sort_layer_len_dir++;
2885 m_pLayListCtrl->SortItems(SortLayersOnSize, (wxIntPtr)NULL);
2886 }
2887}
2888
2889void RouteManagerDialog::UpdateLayButtons() {
2890 long item = -1;
2891 item =
2892 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2893 bool enable = (item != -1);
2894
2895 // btnLayProperties->Enable(false);
2896 btnLayDelete->Enable(enable);
2897 cbLayToggleChart->Enable(enable);
2898 cbLayToggleListing->Enable(enable);
2899 cbLayToggleNames->Enable(enable);
2900
2901 if (item >= 0) {
2902 cbLayToggleChart->SetValue(
2903 ((Layer *)m_pLayListCtrl->GetItemData(item))->IsVisibleOnChart());
2904
2905 cbLayToggleNames->Set3StateValue(
2906 ((Layer *)m_pLayListCtrl->GetItemData(item))->HasVisibleNames());
2907
2908 cbLayToggleListing->SetValue(
2909 ((Layer *)m_pLayListCtrl->GetItemData(item))->IsVisibleOnListing());
2910
2911 } else {
2912 cbLayToggleChart->SetValue(true);
2913 cbLayToggleNames->Set3StateValue(wxCHK_UNDETERMINED);
2914 cbLayToggleListing->SetValue(true);
2915 }
2916}
2917
2918void RouteManagerDialog::OnLayToggleVisibility(wxMouseEvent &event) {
2919 wxPoint pos = event.GetPosition();
2920 int flags = 0;
2921 long clicked_index = m_pLayListCtrl->HitTest(pos, flags);
2922
2923 // Clicking Visibility column?
2924 if (clicked_index > -1 &&
2925 event.GetX() < m_pLayListCtrl->GetColumnWidth(colLAYVISIBLE)) {
2926 // Process the clicked item
2927 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(clicked_index);
2928
2929 layer->SetVisibleOnChart(!layer->IsVisibleOnChart());
2930 m_pLayListCtrl->SetItemImage(clicked_index,
2931 layer->IsVisibleOnChart() ? 0 : 1);
2932
2933 // Manage "show all" checkbox
2934 bool viz = true;
2935 long item = -1;
2936 for (;;) {
2937 item = m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL,
2938 wxLIST_STATE_DONTCARE);
2939 if (item == -1) break;
2940
2941 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(item);
2942
2943 if (!layer->IsVisibleOnChart()) {
2944 viz = false;
2945 break;
2946 }
2947 }
2948 m_cbShowAllLay->SetValue(viz);
2949
2950 ToggleLayerContentsOnChart(layer);
2951 }
2952
2953 // Allow wx to process...
2954 event.Skip();
2955}
2956
2957void RouteManagerDialog::UpdateLists() {
2958 UpdateRouteListCtrl();
2959 UpdateTrkListCtrl();
2960 UpdateWptListCtrl();
2961 UpdateLayListCtrl();
2962}
2963
2964void RouteManagerDialog::OnLayNewClick(wxCommandEvent &event) {
2965 AddNewLayer(false); // Temporary layer
2966}
2967
2968void RouteManagerDialog::OnPerLayNewClick(wxCommandEvent &event) {
2969 AddNewLayer(true); // Persistent layer
2970}
2971
2972void RouteManagerDialog::AddNewLayer(bool isPersistent) {
2973 bool show_flag = g_bShowLayers;
2974 g_bShowLayers = true;
2975
2976 UI_ImportGPX(this, true, _T(""), true, isPersistent);
2977
2978 g_bShowLayers = show_flag;
2979 UpdateLists();
2980 gFrame->RefreshAllCanvas();
2981}
2982
2983void RouteManagerDialog::OnLayPropertiesClick(wxCommandEvent &event) {
2984 // Show layer properties dialog for selected layer - todo
2985 long item = -1;
2986 item =
2987 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2988 if (item == -1) return;
2989}
2990
2991void RouteManagerDialog::OnLayDeleteClick(wxCommandEvent &event) {
2992 long item = -1;
2993 item =
2994 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2995 if (item == -1) return;
2996
2997 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(item);
2998
2999 if (!layer) return;
3000 // Check if this file is a persistent layer.
3001 // If added in this session the listctrl file path is origin dir and not yet
3002 // /layers
3003 bool ispers = false;
3004 wxString destf, f, name, ext;
3005 f = layer->m_LayerFileName;
3006 wxFileName::SplitPath(f, NULL, NULL, &name, &ext);
3007 destf = g_Platform->GetPrivateDataDir();
3008 appendOSDirSlash(&destf);
3009 destf.Append(_T("layers"));
3010 appendOSDirSlash(&destf);
3011 destf << name << _T(".") << ext;
3012
3013 wxString prompt = _(
3014 "Are you sure you want to delete this layer and <ALL> of its contents?");
3015 if (wxFileExists(destf)) {
3016 prompt.Append(_T("\n"));
3017 prompt.Append(
3018 _("The file will also be deleted from OpenCPN's layer directory."));
3019 prompt.Append(_T("\n (") + destf + _T(")" ));
3020 ispers = true;
3021 }
3022 int answer =
3023 OCPNMessageBox(this, prompt, wxString(_("OpenCPN Alert")), wxYES_NO);
3024 if (answer == wxID_NO) return;
3025
3026 // Delete a persistent layer file if present
3027 if (ispers) {
3028 wxString remMSG;
3029 if (wxRemoveFile(destf))
3030 remMSG.sprintf(_T("Layer file: %s is deleted"), destf);
3031 else
3032 remMSG.sprintf(_T("Error deleting Layer file: %s"), destf);
3033
3034 wxLogMessage(remMSG);
3035 }
3036
3037 // Process Tracks and Routes in this layer
3038 wxRouteListNode *node1 = pRouteList->GetFirst();
3039 while (node1) {
3040 Route *pRoute = node1->GetData();
3041 wxRouteListNode *next_node = node1->GetNext();
3042 if (pRoute->m_bIsInLayer && (pRoute->m_LayerID == layer->m_LayerID)) {
3043 pRoute->m_bIsInLayer = false;
3044 pRoute->m_LayerID = 0;
3045 g_pRouteMan->DeleteRoute(pRoute, NavObjectChanges::getInstance());
3046 }
3047 node1 = next_node;
3048 }
3049
3050 for (Track *pTrack : g_TrackList) {
3051 if (pTrack->m_bIsInLayer && (pTrack->m_LayerID == layer->m_LayerID)) {
3052 pTrack->m_bIsInLayer = false;
3053 pTrack->m_LayerID = 0;
3054 NavObj_dB::GetInstance().DeleteTrack(pTrack);
3055 RoutemanGui(*g_pRouteMan).DeleteTrack(pTrack);
3056 }
3057 }
3058
3059 // Process waypoints in this layer
3060 wxRoutePointListNode *node = pWayPointMan->GetWaypointList()->GetFirst();
3061 wxRoutePointListNode *node3;
3062
3063 while (node) {
3064 node3 = node->GetNext();
3065 RoutePoint *rp = node->GetData();
3066 if (rp && (rp->m_LayerID == layer->m_LayerID)) {
3067 rp->m_bIsInLayer = false;
3068 rp->m_LayerID = 0;
3069 pWayPointMan->DestroyWaypoint(
3070 rp, false); // no need to update the change set on layer ops
3071 }
3072
3073 node = node3;
3074 node3 = NULL;
3075 }
3076
3077 if (g_pMarkInfoDialog) {
3078 g_pMarkInfoDialog->ClearData();
3079 }
3080
3081 pLayerList->DeleteObject(layer);
3082
3083 UpdateLists();
3084
3085 gFrame->RefreshAllCanvas();
3086
3087 m_bNeedConfigFlush = false;
3088}
3089
3090void RouteManagerDialog::OnLayToggleChartClick(wxCommandEvent &event) {
3091 // Toggle visibility on chart for selected layer
3092 long item = -1;
3093 item =
3094 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
3095 if (item == -1) return;
3096
3097 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(item);
3098
3099 if (!layer) return;
3100
3101 layer->SetVisibleOnChart(!layer->IsVisibleOnChart());
3102 m_pLayListCtrl->SetItemImage(item, layer->IsVisibleOnChart() ? 0 : 1);
3103
3104 ToggleLayerContentsOnChart(layer);
3105}
3106
3107void RouteManagerDialog::ToggleLayerContentsOnChart(Layer *layer) {
3108 // Process Tracks and Routes in this layer
3109 wxRouteListNode *node1 = pRouteList->GetFirst();
3110 while (node1) {
3111 Route *pRoute = node1->GetData();
3112 if (pRoute->m_bIsInLayer && (pRoute->m_LayerID == layer->m_LayerID)) {
3113 pRoute->SetVisible(layer->IsVisibleOnChart());
3114 }
3115 node1 = node1->GetNext();
3116 }
3117
3118 for (Track *pTrack : g_TrackList) {
3119 if (pTrack->m_bIsInLayer && (pTrack->m_LayerID == layer->m_LayerID))
3120 pTrack->SetVisible(layer->IsVisibleOnChart());
3121 }
3122
3123 // Process waypoints in this layer
3124 wxRoutePointListNode *node = pWayPointMan->GetWaypointList()->GetFirst();
3125
3126 while (node) {
3127 RoutePoint *rp = node->GetData();
3128 if (rp && (rp->m_LayerID == layer->m_LayerID)) {
3129 rp->SetVisible(layer->IsVisibleOnChart());
3130 }
3131
3132 node = node->GetNext();
3133 }
3134 UpdateLists();
3135
3136 UpdateLayButtons();
3137
3138 gFrame->RefreshAllCanvas();
3139}
3140
3141void RouteManagerDialog::OnLayToggleNamesClick(wxCommandEvent &event) {
3142 // Toggle WPT names visibility on chart for selected layer
3143 long item = -1;
3144 item =
3145 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
3146 if (item == -1) return;
3147
3148 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(item);
3149
3150 if (!layer) return;
3151
3152 layer->SetVisibleNames(cbLayToggleNames->Get3StateValue());
3153
3154 ToggleLayerContentsNames(layer);
3155}
3156
3157void RouteManagerDialog::ToggleLayerContentsNames(Layer *layer) {
3158 // Process Tracks and Routes in this layer
3159 wxRouteListNode *node1 = pRouteList->GetFirst();
3160 while (node1) {
3161 Route *pRoute = node1->GetData();
3162 if (pRoute->m_bIsInLayer && (pRoute->m_LayerID == layer->m_LayerID)) {
3163 wxRoutePointListNode *node = pRoute->pRoutePointList->GetFirst();
3164 RoutePoint *prp1 = node->GetData();
3165 while (node) {
3166 if (layer->HasVisibleNames() == wxCHK_UNDETERMINED) {
3167 prp1->m_bShowName = prp1->m_bShowNameData;
3168 } else {
3169 prp1->m_bShowName = (layer->HasVisibleNames() == wxCHK_CHECKED);
3170 }
3171 node = node->GetNext();
3172 }
3173 }
3174 node1 = node1->GetNext();
3175 }
3176
3177 // Process waypoints in this layer
3178 wxRoutePointListNode *node = pWayPointMan->GetWaypointList()->GetFirst();
3179
3180 while (node) {
3181 RoutePoint *rp = node->GetData();
3182 if (rp && (rp->m_LayerID == layer->m_LayerID)) {
3183 rp->SetNameShown(layer->HasVisibleNames() == wxCHK_CHECKED ||
3184 (rp->m_bShowNameData &&
3185 layer->HasVisibleNames() == wxCHK_UNDETERMINED));
3186 }
3187
3188 node = node->GetNext();
3189 }
3190
3191 UpdateLayButtons();
3192
3193 gFrame->RefreshAllCanvas();
3194}
3195
3196void RouteManagerDialog::OnLayToggleListingClick(wxCommandEvent &event) {
3197 // Toggle visibility on listing for selected layer
3198 long item = -1;
3199 item =
3200 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
3201 if (item == -1) return;
3202
3203 Layer *layer = (Layer *)m_pLayListCtrl->GetItemData(item);
3204
3205 if (!layer) return;
3206
3207 layer->SetVisibleOnListing(!layer->IsVisibleOnListing());
3208
3209 ToggleLayerContentsOnListing(layer);
3210}
3211
3212void RouteManagerDialog::ToggleLayerContentsOnListing(Layer *layer) {
3213 ::wxBeginBusyCursor();
3214
3215 // Process Tracks and Routes in this layer
3216 wxRouteListNode *node1 = pRouteList->GetFirst();
3217 while (node1) {
3218 Route *pRoute = node1->GetData();
3219 if (pRoute->m_bIsInLayer && (pRoute->m_LayerID == layer->m_LayerID)) {
3220 pRoute->SetListed(layer->IsVisibleOnListing());
3221 }
3222 node1 = node1->GetNext();
3223 }
3224
3225 for (Track *pTrack : g_TrackList) {
3226 if (pTrack->m_bIsInLayer && (pTrack->m_LayerID == layer->m_LayerID))
3227 pTrack->SetListed(layer->IsVisibleOnListing());
3228 }
3229
3230 // Process waypoints in this layer
3231 // n.b. If the waypoint belongs to a track, and is not shared, then do not
3232 // list it. This is a performance optimization, allowing large track support.
3233
3234 wxRoutePointListNode *node = pWayPointMan->GetWaypointList()->GetFirst();
3235
3236 while (node) {
3237 RoutePoint *rp = node->GetData();
3238 if (rp && rp->m_bIsolatedMark && (rp->m_LayerID == layer->m_LayerID)) {
3239 rp->SetListed(layer->IsVisibleOnListing());
3240 }
3241
3242 node = node->GetNext();
3243 }
3244
3245 UpdateLists();
3246
3247 ::wxEndBusyCursor();
3248
3249 gFrame->RefreshAllCanvas();
3250}
3251
3252void RouteManagerDialog::OnLayDefaultAction(wxListEvent &event) {
3253 wxCommandEvent evt;
3254 OnLayPropertiesClick(evt);
3255}
3256
3257void RouteManagerDialog::UpdateLayListCtrl() {
3258 // if an item was selected, make it selected again if it still exist
3259 long item = -1;
3260 item =
3261 m_pLayListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
3262
3263 wxUIntPtr selected_id = wxUIntPtr(0);
3264 if (item != -1) selected_id = m_pLayListCtrl->GetItemData(item);
3265
3266 // Delete existing items
3267 m_pLayListCtrl->DeleteAllItems();
3268
3269 // then add routes to the listctrl
3270 LayerList::iterator it;
3271 int index = 0;
3272 bool b_anyHidden = false;
3273 for (it = (*pLayerList).begin(); it != (*pLayerList).end(); ++it, ++index) {
3274 Layer *lay = (Layer *)(*it);
3275
3276 if (!lay->m_LayerName.Upper().Contains(m_tFilterLay->GetValue().Upper())) {
3277 continue;
3278 }
3279
3280 wxListItem li;
3281 li.SetId(index);
3282 li.SetImage(lay->IsVisibleOnChart() ? 0 : 1);
3283 li.SetData(lay);
3284 li.SetText(_T(""));
3285
3286 long idx = m_pLayListCtrl->InsertItem(li);
3287
3288 wxString name = lay->m_LayerName;
3289 if (name.IsEmpty()) {
3290 // RoutePoint *rp = trk->GetPoint(1);
3291 // if (rp)
3292 // name = rp->m_CreateTime.FormatISODate() + _T(" ") +
3293 // rp->m_CreateTime.FormatISOTime(); //name =
3294 // rp->m_CreateTime.Format();
3295 // else
3296 name = _("(Unnamed Layer)");
3297 }
3298 m_pLayListCtrl->SetItem(idx, colLAYNAME, name);
3299
3300 wxString len;
3301 len.Printf(wxT("%d"), (int)lay->m_NoOfItems);
3302 m_pLayListCtrl->SetItem(idx, colLAYITEMS, len);
3303 m_pLayListCtrl->SetItem(idx, colLAYPERSIST, lay->m_LayerType);
3304
3305 wxListItem lic;
3306 lic.SetId(index);
3307 lic.SetColumn(1);
3308 lic.SetAlign(wxLIST_FORMAT_LEFT);
3309 m_pLayListCtrl->SetItem(lic);
3310
3311 lic.SetColumn(2);
3312 lic.SetAlign(wxLIST_FORMAT_LEFT);
3313 m_pLayListCtrl->SetItem(lic);
3314
3315 if (!lay->IsVisibleOnChart()) b_anyHidden = true;
3316 }
3317
3318 m_pLayListCtrl->SortItems(SortLayersOnName,
3319 reinterpret_cast<wxIntPtr>(m_pLayListCtrl));
3320 m_pLayListCtrl->SetColumnWidth(0, 4 * m_charWidth);
3321
3322 // restore selection if possible
3323 // NOTE this will select a different item, if one is deleted
3324 // (the next route will get that index).
3325 if (selected_id != wxUIntPtr(0)) {
3326 item = m_pLayListCtrl->FindItem(-1, selected_id);
3327 m_pLayListCtrl->SetItemState(item,
3328 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
3329 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
3330 }
3331 UpdateLayButtons();
3332
3333 m_cbShowAllLay->SetValue(!b_anyHidden);
3334}
3335
3336void RouteManagerDialog::OnImportClick(wxCommandEvent &event) {
3337 // Import routes
3338 // FIXME there is no way to instruct this function about what to import.
3339 // Suggest to add that!
3340
3341 UI_ImportGPX(this);
3342
3343 UpdateLists();
3344
3345 gFrame->RefreshAllCanvas();
3346}
3347void RouteManagerDialog::OnExportClick(wxCommandEvent &event) {
3348 ExportGPX(this);
3349}
3350
3351void RouteManagerDialog::OnExportVizClick(wxCommandEvent &event) {
3352 ExportGPX(this, true, true); // only visible objects, layers included
3353}
3354
3355void RouteManagerDialog::OnFilterChanged(wxCommandEvent &event) {
3356 if (event.GetEventObject() == m_tFilterWpt) {
3357 UpdateWptListCtrl(NULL, true);
3358 } else if (event.GetEventObject() == m_tFilterRte) {
3359 UpdateRouteListCtrl();
3360 } else if (event.GetEventObject() == m_tFilterTrk) {
3361 UpdateTrkListCtrl();
3362 } else if (event.GetEventObject() == m_tFilterLay) {
3363 UpdateLayListCtrl();
3364 }
3365}
3366
3367// 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
EventVar on_routes_update
Notified when list of routes is updated (no data in event)
Definition routeman.h:268
bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes)
Definition routeman.cpp:837
bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint=NULL)
Activates a route for navigation.
Definition routeman.cpp:260
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.