OpenCPN Partial API docs
Loading...
Searching...
No Matches
canvas_menu.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2015 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
23
24#include "gl_headers.h" // Must come before anything using GL stuff
25
26// For compilers that support precompilation, includes "wx.h".
27#include <wx/wxprec.h>
28
29#include <wx/aui/aui.h>
30#include <wx/clipbrd.h>
31#include <wx/dynarray.h>
32#include <wx/event.h>
33#include <wx/font.h>
34#include <wx/gdicmn.h>
35#include <wx/graphics.h>
36#include <wx/image.h>
37#include <wx/listbook.h>
38#include <wx/menu.h>
39
40#include "ocpn-nlohmann/json.hpp"
41
42#include "model/ais_decoder.h"
45#include "model/config_vars.h"
46#include "model/georef.h"
47#include "model/gui_vars.h"
48#include "model/mdns_cache.h"
49#include "model/navobj_db.h"
50#include "model/own_ship.h"
51#include "model/plugin_comm.h"
52#include "model/route.h"
53#include "model/routeman.h"
54#include "model/select.h"
55#include "model/track.h"
56
57#include "ais.h"
58#include "canvas_menu.h"
59#include "chartdb.h"
60#include "chartdbs.h"
61#include "chcanv.h"
62#include "cm93.h" // for chart outline draw
63#include "go_to_position_dlg.h"
64#include "kml.h"
65#include "mark_info.h"
66#include "ocpn_frame.h"
67#include "ocpn_platform.h"
68#include "peer_client_dlg.h"
69#include "pluginmanager.h"
70#include "quilt.h"
71#include "route_gui.h"
72#include "routemanagerdialog.h"
73#include "routeman_gui.h"
74#include "route_point_gui.h"
75#include "route_prop_dlg_impl.h"
76#include "s52plib.h"
77#include "s57chart.h" // for ArrayOfS57Obj
78#include "send_to_gps_dlg.h"
79#include "send_to_peer_dlg.h"
80#include "styles.h"
81#include "tcmgr.h"
82#include "top_frame.h"
83#include "track_gui.h"
84#include "track_prop_dlg.h"
85#include "undo.h"
86#include "user_colors.h"
87
88#ifdef __ANDROID__
89#include "androidUTIL.h"
90#endif
91
92// Constants for right click menus
93enum {
94 ID_DEF_MENU_MAX_DETAIL = 1,
95 ID_DEF_MENU_SCALE_IN,
96 ID_DEF_MENU_SCALE_OUT,
97 ID_DEF_MENU_DROP_WP,
98 ID_DEF_MENU_NEW_RT,
99 ID_DEF_MENU_QUERY,
100 ID_DEF_MENU_MOVE_BOAT_HERE,
101 ID_DEF_MENU_GOTO_HERE,
102 ID_DEF_MENU_GOTOPOSITION,
103 ID_WP_MENU_GOTO,
104 ID_WP_MENU_DELPOINT,
105 ID_WP_MENU_PROPERTIES,
106 ID_RT_MENU_ACTIVATE,
107 ID_RT_MENU_DEACTIVATE,
108 ID_RT_MENU_INSERT,
109 ID_RT_MENU_APPEND,
110 ID_RT_MENU_COPY,
111 ID_RT_MENU_SPLIT_LEG,
112 ID_RT_MENU_SPLIT_WPT,
113 ID_TK_MENU_COPY,
114 ID_WPT_MENU_COPY,
115 ID_WPT_MENU_SENDTOGPS,
116 ID_WPT_MENU_SENDTONEWGPS,
117 ID_WPT_MENU_SENDTOPEER,
118 ID_PASTE_WAYPOINT,
119 ID_PASTE_ROUTE,
120 ID_PASTE_TRACK,
121 ID_RT_MENU_DELETE,
122 ID_RT_MENU_REVERSE,
123 ID_RT_MENU_DELPOINT,
124 ID_RT_MENU_ACTPOINT,
125 ID_RT_MENU_DEACTPOINT,
126 ID_RT_MENU_ACTNXTPOINT,
127 ID_RT_MENU_REMPOINT,
128 ID_RT_MENU_PROPERTIES,
129 ID_RT_MENU_SENDTOGPS,
130 ID_RT_MENU_SENDTONEWGPS,
131 ID_RT_MENU_SHOWNAMES,
132 ID_RT_MENU_RESEQUENCE,
133 ID_RT_MENU_SENDTOPEER,
134 ID_WP_MENU_SET_ANCHORWATCH,
135 ID_WP_MENU_CLEAR_ANCHORWATCH,
136 ID_DEF_MENU_AISTARGETLIST,
137 ID_DEF_MENU_AIS_CPAWARNING,
138
139 ID_RC_MENU_SCALE_IN,
140 ID_RC_MENU_SCALE_OUT,
141 ID_RC_MENU_ZOOM_IN,
142 ID_RC_MENU_ZOOM_OUT,
143 ID_RC_MENU_FINISH,
144 ID_DEF_MENU_AIS_QUERY,
145 ID_DEF_MENU_AIS_CPA,
146 ID_DEF_MENU_AISSHOWTRACK,
147 ID_DEF_MENU_ACTIVATE_MEASURE,
148 ID_DEF_MENU_DEACTIVATE_MEASURE,
149 ID_DEF_MENU_COPY_MMSI,
150
151 ID_UNDO,
152 ID_REDO,
153
154 ID_DEF_MENU_CM93OFFSET_DIALOG,
155
156 ID_TK_MENU_PROPERTIES,
157 ID_TK_MENU_DELETE,
158 ID_TK_MENU_SENDTOPEER,
159 ID_WP_MENU_ADDITIONAL_INFO,
160
161 ID_DEF_MENU_QUILTREMOVE,
162 ID_DEF_MENU_COGUP,
163 ID_DEF_MENU_NORTHUP,
164 ID_DEF_MENU_HEADUP,
165 ID_DEF_MENU_TOGGLE_FULL,
166 ID_DEF_MENU_TIDEINFO,
167 ID_DEF_MENU_CURRENTINFO,
168 ID_DEF_ZERO_XTE,
169
170 ID_DEF_MENU_DEBUG,
171 ID_DGB_MENU_NMEA_WINDOW,
172
173 ID_DEF_MENU_GROUPBASE, // Must be last entry, as chart group identifiers are
174 // created dynamically
175
176 ID_DEF_MENU_LAST
177};
178
179// Helper to create menu label + hotkey string when registering menus
180static wxString _menuText(wxString name, wxString shortcut) {
181 wxString menutext;
182 menutext << name;
183#ifndef __ANDROID__
184 menutext << "\t" << shortcut;
185#endif
186 return menutext;
187}
188
189//------------------------------------------------------------------------------
190// CanvasMenuHandler Implementation
191//------------------------------------------------------------------------------
192int CanvasMenuHandler::GetNextContextMenuId() {
193 return ID_DEF_MENU_LAST +
194 100; // Allowing for 100 dynamic menu item identifiers
195}
196
197wxFont CanvasMenuHandler::m_scaledFont;
198
199// Define a constructor for my canvas
200CanvasMenuHandler::CanvasMenuHandler(ChartCanvas *parentCanvas,
201 Route *selectedRoute, Track *selectedTrack,
202 RoutePoint *selectedPoint,
203 int selectedAIS_MMSI,
204 void *selectedTCIndex, wxWindow *nmea_log)
205 : m_nmea_log(nmea_log) {
206 parent = parentCanvas;
207 m_pSelectedRoute = selectedRoute;
208 m_pSelectedTrack = selectedTrack;
209 m_pFoundRoutePoint = selectedPoint;
210 m_FoundAIS_MMSI = selectedAIS_MMSI;
211 m_pIDXCandidate = selectedTCIndex;
212 if (!m_scaledFont.IsOk()) {
213 wxFont *qFont = GetOCPNScaledFont(_("Menu"));
214 m_scaledFont = *qFont;
215 }
216
217 m_DIPFactor = g_Platform->GetDisplayDIPMult(wxTheApp->GetTopWindow());
218}
219
220CanvasMenuHandler::~CanvasMenuHandler() {}
221
222//-------------------------------------------------------------------------------
223// Popup Menu Handling
224//-------------------------------------------------------------------------------
225
226void CanvasMenuHandler::PrepareMenuItem(wxMenuItem *item) {
227#if defined(__WXMSW__)
228 wxColour ctrl_back_color = GetGlobalColor("DILG1"); // Control Background
229 item->SetBackgroundColour(ctrl_back_color);
230 wxColour menu_text_color = GetGlobalColor("UITX1");
231 item->SetTextColour(menu_text_color);
232#endif
233}
234
235void CanvasMenuHandler::MenuPrepend1(wxMenu *menu, int id, wxString label) {
236 wxMenuItem *item = new wxMenuItem(menu, id, label);
237#if defined(__WXMSW__)
238 item->SetFont(m_scaledFont);
239#endif
240
241#ifdef __ANDROID__
242 wxFont sFont = GetOCPNGUIScaledFont(_("Menu"));
243 item->SetFont(sFont);
244#endif
245
246 PrepareMenuItem(item);
247
248 if (g_btouch) menu->InsertSeparator(0);
249 menu->Prepend(item);
250}
251
252void CanvasMenuHandler::MenuAppend1(wxMenu *menu, int id, wxString label) {
253 wxMenuItem *item = new wxMenuItem(menu, id, label);
254#if defined(__WXMSW__)
255 item->SetFont(m_scaledFont);
256#endif
257
258#ifdef __ANDROID__
259 wxFont sFont = GetOCPNGUIScaledFont(_("Menu"));
260 item->SetFont(sFont);
261#endif
262
263 PrepareMenuItem(item);
264
265 menu->Append(item);
266 if (g_btouch) menu->AppendSeparator();
267}
268
269void CanvasMenuHandler::SetMenuItemFont1(wxMenuItem *item) {
270#if defined(__WXMSW__)
271 item->SetFont(m_scaledFont);
272#endif
273
274#if defined(__ANDROID__)
275 wxFont *qFont = GetOCPNScaledFont(_("Menu"));
276 item->SetFont(*qFont);
277#endif
278
279 PrepareMenuItem(item);
280}
281
282void CanvasMenuHandler::CanvasPopupMenu(int x, int y, int seltype) {
283 wxMenu *contextMenu = new wxMenu;
284 wxMenu *menuWaypoint = NULL;
285 wxMenu *menuRoute = NULL;
286 wxMenu *menuTrack = NULL;
287 wxMenu *menuAIS = NULL;
288
289 wxMenu *subMenuChart = new wxMenu;
290 wxMenu *subMenuUndo = new wxMenu("Undo...Ctrl-Z");
291
292#ifdef __WXOSX__
293 wxMenu *subMenuRedo = new wxMenu("Redo...Shift-Ctrl-Z");
294#else
295 wxMenu *subMenuRedo = new wxMenu("Redo...Ctrl-Y");
296#endif
297 wxMenu *subMenuDebug = new wxMenu("");
298
299 // For small devices (e.g. Android phone)...
300 // Only add Data Monitor menu item if the device (gFrame) is
301 // large enough to contain it reasonably
302#ifdef __ANDROID__
303 wxFont *dFont = GetOCPNScaledFont_PlugIn(_("Dialog"));
304 int fwidth;
305 int fheight;
306 gFrame->GetTextExtent("W", &fwidth, &fheight, NULL, NULL, dFont);
307 auto frame_size = gFrame->GetSize();
308 if ((frame_size.x > fwidth * 60) && (frame_size.y > fheight * 18))
309#endif
310 MenuAppend1(subMenuDebug, ID_DGB_MENU_NMEA_WINDOW, _("Show Data Monitor"));
311
312 wxMenu *menuFocus = contextMenu; // This is the one that will be shown
313
314 popx = x;
315 popy = y;
316
317 if (!g_bBasicMenus || (seltype != SELTYPE_ROUTECREATE)) {
318 bool bsubMenus = false;
319
320 if (bsubMenus) {
321 if (parent->undo->AnythingToUndo()) {
322 // Undo SubMenu
323 wxMenuItem *subMenuItemundo =
324 contextMenu->AppendSubMenu(subMenuUndo, _("Undo"));
325
326 wxString undoItem;
327 undoItem << _("Undo") << " "
328 << parent->undo->GetNextUndoableAction()->Description();
329 MenuAppend1(subMenuUndo, ID_UNDO, undoItem);
330 }
331 if (parent->undo->AnythingToRedo()) {
332 // Redo SubMenu
333 wxMenuItem *subMenuItemRedo =
334 contextMenu->AppendSubMenu(subMenuRedo, _("Redo"));
335
336 wxString redoItem;
337 redoItem << _("Redo") << " "
338 << parent->undo->GetNextRedoableAction()->Description();
339 MenuAppend1(subMenuRedo, ID_REDO, redoItem);
340 }
341 } else {
342 if (parent->undo->AnythingToUndo()) {
343 wxString undoItem;
344 undoItem << _("Undo") << " "
345 << parent->undo->GetNextUndoableAction()->Description();
346 MenuAppend1(contextMenu, ID_UNDO, _menuText(undoItem, "Ctrl-Z"));
347 }
348
349 if (parent->undo->AnythingToRedo()) {
350 wxString redoItem;
351 redoItem << _("Redo") << " "
352 << parent->undo->GetNextRedoableAction()->Description();
353#ifdef __WXOSX__
354 MenuAppend1(contextMenu, ID_REDO, _menuText(redoItem, "Shift-Ctrl-Z"));
355#else
356 MenuAppend1(contextMenu, ID_REDO, _menuText(redoItem, "Ctrl-Y"));
357#endif
358 }
359 }
360 }
361
362 if (seltype == SELTYPE_ROUTECREATE) {
363 MenuAppend1(contextMenu, ID_RC_MENU_FINISH,
364 _menuText(_("End Route"), "Esc"));
365 }
366
367 if (!parent->m_pMouseRoute) {
368 if (parent->m_bMeasure_Active)
369 MenuAppend1(contextMenu, ID_DEF_MENU_DEACTIVATE_MEASURE,
370 _menuText(_("Measure Off"), "Esc"));
371 else
372 MenuAppend1(contextMenu, ID_DEF_MENU_ACTIVATE_MEASURE,
373 _menuText(_("Measure"), "M"));
374 }
375
376 bool ais_areanotice = false;
377 if (g_pAIS && parent->GetShowAIS() && g_bShowAreaNotices) {
378 float vp_scale = parent->GetVPScale();
379
380 for (const auto &target : g_pAIS->GetAreaNoticeSourcesList()) {
381 auto target_data = target.second;
382 if (!target_data->area_notices.empty()) {
383 for (auto &ani : target_data->area_notices) {
384 Ais8_001_22 &area_notice = ani.second;
385 BoundingBox bbox;
386
387 for (Ais8_001_22_SubAreaList::iterator sa =
388 area_notice.sub_areas.begin();
389 sa != area_notice.sub_areas.end(); ++sa) {
390 switch (sa->shape) {
391 case AIS8_001_22_SHAPE_CIRCLE: {
392 wxPoint target_point;
393 parent->GetCanvasPointPix(sa->latitude, sa->longitude,
394 &target_point);
395 bbox.Expand(target_point);
396 if (sa->radius_m > 0.0) bbox.EnLarge(sa->radius_m * vp_scale);
397 break;
398 }
399 case AIS8_001_22_SHAPE_RECT:
400 case AIS8_001_22_SHAPE_POLYGON:
401 case AIS8_001_22_SHAPE_POLYLINE: {
402 double lat = sa->latitude;
403 double lon = sa->longitude;
404 for (int i = 0; i < 4; ++i) {
405 ll_gc_ll(lat, lon, sa->angles[i], sa->dists_m[i] / 1852.0,
406 &lat, &lon);
407 wxPoint target_point;
408 parent->GetCanvasPointPix(lat, lon, &target_point);
409 bbox.Expand(target_point);
410 }
411 break;
412 }
413 case AIS8_001_22_SHAPE_SECTOR: {
414 double lat1 = sa->latitude;
415 double lon1 = sa->longitude;
416 double lat, lon;
417 wxPoint target_point;
418 parent->GetCanvasPointPix(lat1, lon1, &target_point);
419 bbox.Expand(target_point);
420 for (int i = 0; i < 18; ++i) {
421 ll_gc_ll(
422 lat1, lon1,
423 sa->left_bound_deg +
424 i * (sa->right_bound_deg - sa->left_bound_deg) / 18,
425 sa->radius_m / 1852.0, &lat, &lon);
426 parent->GetCanvasPointPix(lat, lon, &target_point);
427 bbox.Expand(target_point);
428 }
429 ll_gc_ll(lat1, lon1, sa->right_bound_deg, sa->radius_m / 1852.0,
430 &lat, &lon);
431 parent->GetCanvasPointPix(lat, lon, &target_point);
432 bbox.Expand(target_point);
433 break;
434 }
435 }
436 }
437
438 if (bbox.GetValid() && bbox.PointInBox(x, y)) {
439 ais_areanotice = true;
440 break;
441 }
442 }
443 }
444 }
445 }
446
447 int nChartStack = 0;
448 if (parent->GetpCurrentStack())
449 nChartStack = parent->GetpCurrentStack()->nEntry;
450
451 if (!parent->GetVP().b_quilt) {
452 if (nChartStack > 1) {
453 MenuAppend1(contextMenu, ID_DEF_MENU_MAX_DETAIL, _("Max Detail Here"));
454 MenuAppend1(contextMenu, ID_DEF_MENU_SCALE_IN,
455 _menuText(_("Scale In"), "Ctrl-Left"));
456 MenuAppend1(contextMenu, ID_DEF_MENU_SCALE_OUT,
457 _menuText(_("Scale Out"), "Ctrl-Right"));
458 }
459
460 if ((parent->m_singleChart &&
461 (parent->m_singleChart->GetChartFamily() == CHART_FAMILY_VECTOR)) ||
462 ais_areanotice) {
463 MenuAppend1(contextMenu, ID_DEF_MENU_QUERY, _("Object Query") + "...");
464 }
465
466 } else {
467 ChartBase *pChartTest =
468 parent->m_pQuilt->GetChartAtPix(parent->GetVP(), wxPoint(x, y));
469 if ((pChartTest && (pChartTest->GetChartFamily() == CHART_FAMILY_VECTOR)) ||
470 ais_areanotice) {
471 MenuAppend1(contextMenu, ID_DEF_MENU_QUERY, _("Object Query") + "...");
472 } else {
473#ifndef __ANDROID__
474 if (!g_bBasicMenus && (nChartStack > 1)) {
475 MenuAppend1(contextMenu, ID_DEF_MENU_SCALE_IN,
476 _menuText(_("Scale In"), "Ctrl-Left"));
477 MenuAppend1(contextMenu, ID_DEF_MENU_SCALE_OUT,
478 _menuText(_("Scale Out"), "Ctrl-Right"));
479 }
480#endif
481 }
482 }
483
484 if (!g_bBasicMenus || (seltype != SELTYPE_ROUTECREATE)) {
485 bool b_dm_add = true;
486 if (g_btouch && parent->IsMeasureActive()) b_dm_add = false;
487
488 if (b_dm_add) {
489 MenuAppend1(contextMenu, ID_DEF_MENU_DROP_WP,
490 _menuText(_("Drop Mark"), "Ctrl-M"));
491 MenuAppend1(contextMenu, ID_DEF_MENU_NEW_RT,
492 _menuText(_("New Route..."), "Ctrl-R"));
493 }
494
495 if (!bGPSValid)
496 MenuAppend1(contextMenu, ID_DEF_MENU_MOVE_BOAT_HERE, _("Move Boat Here"));
497 }
498
499 if (!g_bBasicMenus && !g_pRouteMan->GetpActiveRoute() &&
500 (!(seltype & SELTYPE_MARKPOINT) ||
501 (m_pFoundRoutePoint && m_pFoundRoutePoint->m_bIsInLayer)))
502 MenuAppend1(contextMenu, ID_DEF_MENU_GOTO_HERE, _("Navigate To Here"));
503
504 if (!g_bBasicMenus)
505 MenuAppend1(contextMenu, ID_DEF_MENU_GOTOPOSITION,
506 _("Center view") + "...");
507
508 if (!g_bBasicMenus) {
509 if (parent->GetVP().b_quilt) {
510 if (parent->GetUpMode() == NORTH_UP_MODE) {
511 MenuAppend1(contextMenu, ID_DEF_MENU_COGUP, _("Course Up Mode"));
512 if (!std::isnan(gHdt))
513 MenuAppend1(contextMenu, ID_DEF_MENU_HEADUP, _("Heading Up Mode"));
514 } else {
515 MenuAppend1(contextMenu, ID_DEF_MENU_NORTHUP, _("North Up Mode"));
516 }
517 } else {
518 if (parent->m_singleChart &&
519 (fabs(parent->m_singleChart->GetChartSkew()) > .01) && !g_bskew_comp)
520 MenuAppend1(contextMenu, ID_DEF_MENU_NORTHUP, _("Chart Up Mode"));
521 else
522 MenuAppend1(contextMenu, ID_DEF_MENU_NORTHUP, _("North Up Mode"));
523 }
524 }
525
526 if (!g_bBasicMenus) {
527 bool full_toggle_added = false;
528#ifndef __ANDROID__
529 if (g_btouch) {
530 MenuAppend1(contextMenu, ID_DEF_MENU_TOGGLE_FULL,
531 _("Toggle Full Screen"));
532 full_toggle_added = true;
533 }
534
535 if (!full_toggle_added) {
536 // if(gFrame->IsFullScreen())
537 MenuAppend1(contextMenu, ID_DEF_MENU_TOGGLE_FULL,
538 _("Toggle Full Screen"));
539 }
540#endif
541
542 if (g_pRouteMan->IsAnyRouteActive() &&
543 g_pRouteMan->GetCurrentXTEToActivePoint() > 0.)
544 MenuAppend1(contextMenu, ID_DEF_ZERO_XTE, _("Zero XTE"));
545
546 Kml *kml = new Kml;
547 int pasteBuffer = kml->ParsePasteBuffer();
548 if (pasteBuffer != KML_PASTE_INVALID) {
549 switch (pasteBuffer) {
550 case KML_PASTE_WAYPOINT: {
551 MenuAppend1(contextMenu, ID_PASTE_WAYPOINT, _("Paste Waypoint"));
552 break;
553 }
554 case KML_PASTE_ROUTE: {
555 MenuAppend1(contextMenu, ID_PASTE_ROUTE, _("Paste Route"));
556 break;
557 }
558 case KML_PASTE_TRACK: {
559 MenuAppend1(contextMenu, ID_PASTE_TRACK, _("Paste Track"));
560 break;
561 }
562 case KML_PASTE_ROUTE_TRACK: {
563 MenuAppend1(contextMenu, ID_PASTE_ROUTE, _("Paste Route"));
564 MenuAppend1(contextMenu, ID_PASTE_TRACK, _("Paste Track"));
565 break;
566 }
567 }
568 }
569 delete kml;
570
571 if (!parent->GetVP().b_quilt && parent->m_singleChart &&
572 (parent->m_singleChart->GetChartType() == CHART_TYPE_CM93COMP)) {
573 MenuAppend1(contextMenu, ID_DEF_MENU_CM93OFFSET_DIALOG,
574 _("CM93 Offset Dialog..."));
575 }
576
577 } // if( !g_bBasicMenus){
578
579#ifndef __ANDROID__
580// TODO stack
581// if( ( parent->GetVP().b_quilt ) && ( pCurrentStack &&
582// pCurrentStack->b_valid ) ) {
583// int dbIndex = parent->m_pQuilt->GetChartdbIndexAtPix(
584// parent->GetVP(), wxPoint( popx, popy ) ); if( dbIndex != -1 )
585// MenuAppend1( contextMenu, ID_DEF_MENU_QUILTREMOVE, _( "Hide This
586// Chart" ) );
587// }
588#endif
589
590#ifdef __WXMSW__
591 // If we dismiss the context menu without action, we need to discard some
592 // mouse events.... Eat the next 2 button events, which happen as down-up on
593 // MSW XP
594 g_click_stop = 2;
595#endif
596
597 // ChartGroup SubMenu
598 wxMenuItem *subItemChart =
599 contextMenu->AppendSubMenu(subMenuChart, _("Chart Groups"));
600 if (g_btouch) contextMenu->AppendSeparator();
601
602 SetMenuItemFont1(subItemChart);
603
604 if (g_pGroupArray->GetCount()) {
605#ifdef __WXMSW__
606 MenuAppend1(subMenuChart, wxID_CANCEL, _("temporary"));
607#endif
608 wxMenuItem *subItem0 = subMenuChart->AppendRadioItem(
609 ID_DEF_MENU_GROUPBASE, _("All Active Charts"));
610
611 SetMenuItemFont1(subItem0);
612
613 for (unsigned int i = 0; i < g_pGroupArray->GetCount(); i++) {
614 subItem0 = subMenuChart->AppendRadioItem(
615 ID_DEF_MENU_GROUPBASE + i + 1, g_pGroupArray->Item(i)->m_group_name);
616 SetMenuItemFont1(subItem0);
617 }
618
619#ifdef __WXMSW__
620 subMenuChart->Remove(wxID_CANCEL);
621#endif
622 subMenuChart->Check(ID_DEF_MENU_GROUPBASE + parent->m_groupIndex, true);
623 }
624
625 // This is the default context menu
626 menuFocus = contextMenu;
627
628 wxString name;
629 std::unique_ptr<HostApi> host_api = GetHostApi();
630 auto *api_121 = dynamic_cast<HostApi121 *>(host_api.get());
631 if (api_121) {
632 if (!g_bBasicMenus || (seltype != SELTYPE_ROUTECREATE)) {
633 if (g_pAIS) {
634 if (api_121 && parent->GetShowAIS() &&
635 (seltype & SELTYPE_AISTARGET &&
636 !(api_121->GetContextMenuMask() &
637 api_121->kContextMenuDisableAistarget))) {
638 auto myptarget = g_pAIS->Get_Target_Data_From_MMSI(m_FoundAIS_MMSI);
639 if (!g_bBasicMenus && myptarget) {
640 name = myptarget->GetFullName();
641 if (name.IsEmpty()) name.Printf("%d", m_FoundAIS_MMSI);
642 name.Prepend(" ( ").Append(" )");
643 } else
644 name = wxEmptyString;
645 menuAIS = new wxMenu(_("AIS") + name);
646 MenuAppend1(menuAIS, ID_DEF_MENU_AIS_QUERY, _("Target Query..."));
647 if (myptarget && myptarget->bCPA_Valid &&
648 (myptarget->n_alert_state != AIS_ALERT_SET)) {
649 if (myptarget->b_show_AIS_CPA)
650 MenuAppend1(menuAIS, ID_DEF_MENU_AIS_CPA, _("Hide Target CPA"));
651 else
652 MenuAppend1(menuAIS, ID_DEF_MENU_AIS_CPA, _("Show Target CPA"));
653 }
654 MenuAppend1(menuAIS, ID_DEF_MENU_AISTARGETLIST, _("Target List..."));
655 if (myptarget->Class != AIS_METEO /*g_bAISShowTracks*/) {
656 if (myptarget && !myptarget->b_PersistTrack) {
657 if (myptarget->b_show_track)
658 MenuAppend1(menuAIS, ID_DEF_MENU_AISSHOWTRACK,
659 _("Hide Target Track"));
660 else
661 MenuAppend1(menuAIS, ID_DEF_MENU_AISSHOWTRACK,
662 _("Show Target Track"));
663 }
664 }
665
666 MenuAppend1(menuAIS, ID_DEF_MENU_COPY_MMSI, _("Copy Target MMSI"));
667 menuAIS->AppendSeparator();
668
669 if (!parent->GetVP().b_quilt) {
670 if ((parent->m_singleChart &&
671 (parent->m_singleChart->GetChartFamily() ==
672 CHART_FAMILY_VECTOR))) {
673 MenuAppend1(menuAIS, ID_DEF_MENU_QUERY, _("Object Query..."));
674 }
675
676 } else {
677 ChartBase *pChartTest =
678 parent->m_pQuilt->GetChartAtPix(parent->GetVP(), wxPoint(x, y));
679 if ((pChartTest &&
680 (pChartTest->GetChartFamily() == CHART_FAMILY_VECTOR))) {
681 MenuAppend1(menuAIS, ID_DEF_MENU_QUERY, _("Object Query..."));
682 }
683 }
684
685 menuFocus = menuAIS;
686 } else {
687 bool enable_list = true;
688#ifdef __ANDROID__
689 double char_x = wxTheApp->GetTopWindow()->GetSize().x /
690 wxTheApp->GetTopWindow()->GetCharWidth();
691 double char_y = wxTheApp->GetTopWindow()->GetSize().y /
692 wxTheApp->GetTopWindow()->GetCharWidth();
693 double char_min = wxMin(char_x, char_y);
694 if (char_min < 100) enable_list = false;
695 // Another filter for phones, especially
696 double size_x = wxTheApp->GetTopWindow()->GetSize().x / g_androidDPmm;
697 double size_y = wxTheApp->GetTopWindow()->GetSize().y / g_androidDPmm;
698 if (wxMin(size_x, size_y) < 100) // it is a phone..
699 enable_list = false;
700#endif
701 if (enable_list)
702 MenuAppend1(contextMenu, ID_DEF_MENU_AISTARGETLIST,
703 _("AIS target list") + "...");
704
705 wxString nextCPAstatus = g_bCPAWarn ? _("Hide") : _("Show");
706 MenuAppend1(contextMenu, ID_DEF_MENU_AIS_CPAWARNING,
707 _menuText(nextCPAstatus + " " + _("CPA alarm "), "W"));
708 }
709 }
710 }
711 if (g_enable_root_menu_debug) {
712 wxMenuItem *subItemDebug =
713 contextMenu->AppendSubMenu(subMenuDebug, _("Debug"));
714 if (g_btouch) contextMenu->AppendSeparator();
715 SetMenuItemFont1(subItemDebug);
716 }
717
718 if (seltype & SELTYPE_ROUTESEGMENT &&
719 !(api_121->GetContextMenuMask() & api_121->kContextMenuDisableRoute)) {
720 if (!g_bBasicMenus && m_pSelectedRoute) {
721 name = m_pSelectedRoute->m_RouteNameString;
722 if (name.IsEmpty()) name = _("Unnamed Route");
723 name.Prepend(" ( ").Append(" )");
724 } else
725 name = wxEmptyString;
726 bool blay = false;
727 if (m_pSelectedRoute && m_pSelectedRoute->m_bIsInLayer) blay = true;
728
729 if (blay) {
730 menuRoute = new wxMenu(_("Layer Route") + name);
731 MenuAppend1(menuRoute, ID_RT_MENU_PROPERTIES, _("Properties") + "...");
732 if (m_pSelectedRoute) {
733 if (m_pSelectedRoute->IsActive()) {
734 int indexActive = m_pSelectedRoute->GetIndexOf(
735 m_pSelectedRoute->m_pRouteActivePoint);
736 if (indexActive + 1 < m_pSelectedRoute->GetnPoints() - 1) {
737 MenuAppend1(menuRoute, ID_RT_MENU_ACTNXTPOINT,
738 _("Activate Next Waypoint"));
739 }
740 MenuAppend1(menuRoute, ID_RT_MENU_DEACTIVATE, _("Deactivate"));
741 MenuAppend1(menuRoute, ID_DEF_ZERO_XTE, _("Zero XTE"));
742 } else {
743 MenuAppend1(menuRoute, ID_RT_MENU_ACTIVATE, _("Activate"));
744 }
745 }
746 } else {
747 menuRoute = new wxMenu(_("Route") + name);
748 MenuAppend1(menuRoute, ID_RT_MENU_PROPERTIES, _("Properties") + "...");
749 if (m_pSelectedRoute) {
750 if (m_pSelectedRoute->IsActive()) {
751 int indexActive = m_pSelectedRoute->GetIndexOf(
752 m_pSelectedRoute->m_pRouteActivePoint);
753 if (indexActive + 1 < m_pSelectedRoute->GetnPoints() - 1) {
754 MenuAppend1(menuRoute, ID_RT_MENU_ACTNXTPOINT,
755 _("Activate Next Waypoint"));
756 }
757 MenuAppend1(menuRoute, ID_RT_MENU_DEACTIVATE, _("Deactivate"));
758 MenuAppend1(menuRoute, ID_DEF_ZERO_XTE, _("Zero XTE"));
759 } else {
760 MenuAppend1(menuRoute, ID_RT_MENU_ACTIVATE, _("Activate"));
761 }
762 }
763 MenuAppend1(menuRoute, ID_RT_MENU_INSERT, _("Insert Waypoint"));
764 MenuAppend1(menuRoute, ID_RT_MENU_APPEND, _("Append Waypoint"));
765 if (!(seltype & SELTYPE_ROUTEPOINT) && m_pSelectedRoute) {
766 m_SelectedIdx = m_pSelectedRoute->GetIndexOf(m_pFoundRoutePoint);
767 if (m_SelectedIdx >= 1 &&
768 m_SelectedIdx < m_pSelectedRoute->GetnPoints() - 2)
769 MenuAppend1(menuRoute, ID_RT_MENU_SPLIT_LEG, _("Split around Leg"));
770 }
771 MenuAppend1(menuRoute, ID_RT_MENU_COPY, _("Copy as KML") + "...");
772 MenuAppend1(menuRoute, ID_RT_MENU_DELETE, _("Delete") + "...");
773 MenuAppend1(menuRoute, ID_RT_MENU_REVERSE, _("Reverse..."));
774 if (m_pSelectedRoute) {
775 if (m_pSelectedRoute->AreWaypointNamesVisible())
776 MenuAppend1(menuRoute, ID_RT_MENU_SHOWNAMES,
777 _("Hide Waypoint Names"));
778 else
779 MenuAppend1(menuRoute, ID_RT_MENU_SHOWNAMES,
780 _("Show Waypoint Names"));
781 }
782 MenuAppend1(menuRoute, ID_RT_MENU_RESEQUENCE,
783 _("Resequence Waypoints..."));
784
785 // #ifndef __ANDROID__
786 wxString port = parent->FindValidUploadPort();
787 parent->m_active_upload_port = port;
788 wxString item = _("Send to GPS");
789 if (!port.IsEmpty()) {
790 item.Append(" ( ");
791 item.Append(port);
792 item.Append(" )");
793 }
794 MenuAppend1(menuRoute, ID_RT_MENU_SENDTOGPS, item);
795
796 if (!port.IsEmpty()) {
797 wxString item = _("Send to new GPS");
798 MenuAppend1(menuRoute, ID_RT_MENU_SENDTONEWGPS, item);
799 }
800 // #endif
801 wxString itemstp = SYMBOL_STP_TITLE; // Send to Peer
802 MenuAppend1(menuRoute, ID_RT_MENU_SENDTOPEER, itemstp);
803 }
804 // Eventually set this menu as the "focused context menu"
805 if (menuFocus != menuAIS) menuFocus = menuRoute;
806 }
807
808 if (seltype & SELTYPE_TRACKSEGMENT &&
809 !(api_121->GetContextMenuMask() & api_121->kContextMenuDisableTrack)) {
810 name = wxEmptyString;
811 if (!g_bBasicMenus && m_pSelectedTrack)
812 name = " ( " + m_pSelectedTrack->GetName(true) + " )";
813 else
814 name = wxEmptyString;
815 bool blay = false;
816 if (m_pSelectedTrack && m_pSelectedTrack->m_bIsInLayer) blay = true;
817
818 if (blay) {
819 menuTrack = new wxMenu(_("Layer Track") + name);
820 MenuAppend1(menuTrack, ID_TK_MENU_PROPERTIES, _("Properties") + "...");
821 } else {
822 menuTrack = new wxMenu(_("Track") + name);
823 MenuAppend1(menuTrack, ID_TK_MENU_PROPERTIES, _("Properties") + "...");
824 MenuAppend1(menuTrack, ID_TK_MENU_COPY, _("Copy as KML"));
825 MenuAppend1(menuTrack, ID_TK_MENU_DELETE, _("Delete") + "...");
826 }
827
828 wxString itemstp = SYMBOL_STP_TITLE; // Send to Peer
829 MenuAppend1(menuTrack, ID_TK_MENU_SENDTOPEER, itemstp);
830
831 // Eventually set this menu as the "focused context menu"
832 if (menuFocus != menuAIS) menuFocus = menuTrack;
833 }
834
835 if (seltype & SELTYPE_ROUTEPOINT &&
836 !(api_121->GetContextMenuMask() &
837 api_121->kContextMenuDisableWaypoint)) {
838 if (!g_bBasicMenus && m_pFoundRoutePoint) {
839 name = m_pFoundRoutePoint->GetName();
840 if (name.IsEmpty()) name = _("Unnamed Waypoint");
841 name.Prepend(" ( ").Append(" )");
842 } else
843 name = wxEmptyString;
844 bool blay = false;
845 if (m_pFoundRoutePoint && m_pFoundRoutePoint->m_bIsInLayer) blay = true;
846
847 if (blay) {
848 menuWaypoint = new wxMenu(_("Layer Waypoint") + name);
849 MenuAppend1(menuWaypoint, ID_WP_MENU_PROPERTIES,
850 _("Properties") + "...");
851
852 if (m_pSelectedRoute && m_pSelectedRoute->IsActive())
853 MenuAppend1(menuWaypoint, ID_RT_MENU_ACTPOINT, _("Activate"));
854 } else {
855 menuWaypoint = new wxMenu(_("Waypoint") + name);
856 MenuAppend1(menuWaypoint, ID_WP_MENU_PROPERTIES,
857 _("Properties") + "...");
858 if (m_pSelectedRoute && m_pSelectedRoute->IsActive()) {
859 if (m_pSelectedRoute->m_pRouteActivePoint != m_pFoundRoutePoint)
860 MenuAppend1(menuWaypoint, ID_RT_MENU_ACTPOINT, _("Activate"));
861 }
862
863 if (m_pSelectedRoute && m_pSelectedRoute->IsActive()) {
864 if (m_pSelectedRoute->m_pRouteActivePoint == m_pFoundRoutePoint) {
865 int indexActive = m_pSelectedRoute->GetIndexOf(
866 m_pSelectedRoute->m_pRouteActivePoint);
867 if (indexActive < m_pSelectedRoute->GetnPoints() - 1)
868 MenuAppend1(menuWaypoint, ID_RT_MENU_ACTNXTPOINT,
869 _("Activate Next Waypoint"));
870 }
871 }
872 if (m_pSelectedRoute && m_pSelectedRoute->GetnPoints() > 2) {
873 MenuAppend1(menuWaypoint, ID_RT_MENU_REMPOINT,
874 _("Remove from Route"));
875
876 m_SelectedIdx = m_pSelectedRoute->GetIndexOf(m_pFoundRoutePoint);
877 if (m_SelectedIdx >= 1 &&
878 m_SelectedIdx < m_pSelectedRoute->GetnPoints() - 1)
879 MenuAppend1(menuWaypoint, ID_RT_MENU_SPLIT_WPT,
880 _("Split Route at Waypoint"));
881 }
882
883 MenuAppend1(menuWaypoint, ID_WPT_MENU_COPY, _("Copy as KML"));
884
885 if (m_pFoundRoutePoint && m_pFoundRoutePoint->GetIconName() != "mob")
886 MenuAppend1(menuWaypoint, ID_RT_MENU_DELPOINT, _("Delete"));
887
888 // #ifndef __ANDROID__
889 wxString port = parent->FindValidUploadPort();
890 parent->m_active_upload_port = port;
891 wxString item = _("Send to GPS");
892 if (!port.IsEmpty()) {
893 item.Append(" ( ");
894 item.Append(port);
895 item.Append(" )");
896 }
897 MenuAppend1(menuWaypoint, ID_WPT_MENU_SENDTOGPS, item);
898
899 if (!port.IsEmpty()) {
900 wxString item = _("Send to new GPS");
901 MenuAppend1(menuWaypoint, ID_WPT_MENU_SENDTONEWGPS, item);
902 }
903
904 MenuAppend1(menuWaypoint, ID_WPT_MENU_SENDTOPEER,
905 SYMBOL_STP_TITLE); // Send to Peer
906 }
907
908 // Eventually set this menu as the "focused context menu"
909 if (menuFocus != menuAIS) menuFocus = menuWaypoint;
910 }
911
912 if (seltype & SELTYPE_MARKPOINT &&
913 !(api_121->GetContextMenuMask() &
914 api_121->kContextMenuDisableWaypoint)) {
915 if (!g_bBasicMenus && m_pFoundRoutePoint) {
916 name = m_pFoundRoutePoint->GetName();
917 if (name.IsEmpty()) name = _("Unnamed Mark");
918 name.Prepend(" ( ").Append(" )");
919 } else
920 name = wxEmptyString;
921 bool blay = false;
922 if (m_pFoundRoutePoint && m_pFoundRoutePoint->m_bIsInLayer) blay = true;
923
924 if (blay) {
925 menuWaypoint = new wxMenu(_("Layer Waypoint") + name);
926 MenuAppend1(menuWaypoint, ID_WP_MENU_PROPERTIES,
927 _("Properties") + "...");
928 } else {
929 menuWaypoint = new wxMenu(_("Mark") + name);
930 MenuAppend1(menuWaypoint, ID_WP_MENU_PROPERTIES,
931 _("Properties") + "...");
932
933 if (!g_pRouteMan->GetpActiveRoute())
934 MenuAppend1(menuWaypoint, ID_WP_MENU_GOTO, _("Navigate To This"));
935
936 MenuAppend1(menuWaypoint, ID_WPT_MENU_COPY, _("Copy as KML"));
937
938 if (m_pFoundRoutePoint && m_pFoundRoutePoint->GetIconName() != "mob")
939 MenuAppend1(menuWaypoint, ID_WP_MENU_DELPOINT, _("Delete"));
940
941 // #ifndef __ANDROID__
942 wxString port = parent->FindValidUploadPort();
943 parent->m_active_upload_port = port;
944 wxString item = _("Send to GPS");
945 if (!port.IsEmpty()) {
946 item.Append(" ( ");
947 item.Append(port);
948 item.Append(" )");
949 }
950 MenuAppend1(menuWaypoint, ID_WPT_MENU_SENDTOGPS, item);
951
952 MenuAppend1(menuWaypoint, ID_WPT_MENU_SENDTOPEER,
953 SYMBOL_STP_TITLE); // Send to Peer
954 // #endif
955
956 if ((m_pFoundRoutePoint == pAnchorWatchPoint1) ||
957 (m_pFoundRoutePoint == pAnchorWatchPoint2))
958 MenuAppend1(menuWaypoint, ID_WP_MENU_CLEAR_ANCHORWATCH,
959 _("Clear Anchor Watch"));
960 else {
961 if (m_pFoundRoutePoint && !(m_pFoundRoutePoint->m_bIsInLayer) &&
962 ((NULL == pAnchorWatchPoint1) || (NULL == pAnchorWatchPoint2))) {
963 double dist;
964 double brg;
965 DistanceBearingMercator(m_pFoundRoutePoint->m_lat,
966 m_pFoundRoutePoint->m_lon, gLat, gLon, &brg,
967 &dist);
968 if (dist * 1852. <= g_nAWMax)
969 MenuAppend1(menuWaypoint, ID_WP_MENU_SET_ANCHORWATCH,
970 _("Set Anchor Watch"));
971 }
972 }
973 }
974 // Eventually set this menu as the "focused context menu"
975 if (menuFocus != menuAIS) menuFocus = menuWaypoint;
976 }
977
978 // Add plugin context items to the correct menu
979 AddPluginContextMenuItems(contextMenu, menuRoute, menuTrack, menuWaypoint,
980 menuAIS);
981
982 /*add the relevant submenus*/
983 enum { WPMENU = 1, TKMENU = 2, RTMENU = 4, MMMENU = 8 };
984 int sub_menu = 0;
985 if (!g_bBasicMenus && menuFocus != contextMenu) {
986 if (global_color_scheme != GLOBAL_COLOR_SCHEME_DUSK &&
987 global_color_scheme != GLOBAL_COLOR_SCHEME_NIGHT &&
988 global_color_scheme != GLOBAL_COLOR_SCHEME_NIGHT_HICON) {
989 menuFocus->AppendSeparator();
990 }
991
992 wxMenuItem *subMenu1;
993 if (menuWaypoint && menuFocus != menuWaypoint) {
994 subMenu1 =
995 menuFocus->AppendSubMenu(menuWaypoint, menuWaypoint->GetTitle());
996 SetMenuItemFont1(subMenu1);
997 sub_menu |= WPMENU;
998#ifdef __WXMSW__
999 menuWaypoint->SetTitle(wxEmptyString);
1000#endif
1001 }
1002 if (menuTrack && menuFocus != menuTrack) {
1003 subMenu1 = menuFocus->AppendSubMenu(menuTrack, menuTrack->GetTitle());
1004 SetMenuItemFont1(subMenu1);
1005 sub_menu |= TKMENU;
1006#ifdef __WXMSW__
1007 menuTrack->SetTitle(wxEmptyString);
1008#endif
1009 }
1010 if (menuRoute && menuFocus != menuRoute) {
1011 subMenu1 = menuFocus->AppendSubMenu(menuRoute, menuRoute->GetTitle());
1012 SetMenuItemFont1(subMenu1);
1013 sub_menu |= RTMENU;
1014#ifdef __WXMSW__
1015 menuRoute->SetTitle(wxEmptyString);
1016#endif
1017 }
1018 subMenu1 = menuFocus->AppendSubMenu(contextMenu, _("Main Menu"));
1019 SetMenuItemFont1(subMenu1);
1020 sub_menu |= MMMENU;
1021 }
1022
1023 if (!subMenuChart->GetMenuItemCount()) contextMenu->Destroy(subItemChart);
1024
1025 // Add the Tide/Current selections if the item was not activated by
1026 // shortcut in right-click handlers
1027 bool bsep = false;
1028 if (seltype & SELTYPE_TIDEPOINT) {
1029 menuFocus->AppendSeparator();
1030 bsep = true;
1031 MenuAppend1(menuFocus, ID_DEF_MENU_TIDEINFO, _("Show Tide Information"));
1032 }
1033
1034 if (seltype & SELTYPE_CURRENTPOINT) {
1035 if (!bsep) menuFocus->AppendSeparator();
1036 MenuAppend1(menuFocus, ID_DEF_MENU_CURRENTINFO,
1037 _("Show Current Information"));
1038 }
1039
1040 // Invoke the correct focused drop-down menu
1041
1042#ifdef __ANDROID__
1043 androidEnableBackButton(false);
1044 androidEnableOptionsMenu(false);
1045
1046 setMenuStyleSheet(menuRoute, GetOCPNGUIScaledFont(_("Menu")));
1047 setMenuStyleSheet(menuWaypoint, GetOCPNGUIScaledFont(_("Menu")));
1048 setMenuStyleSheet(menuTrack, GetOCPNGUIScaledFont(_("Menu")));
1049 setMenuStyleSheet(menuAIS, GetOCPNGUIScaledFont(_("Menu")));
1050#endif
1051
1052 parent->PopupMenu(menuFocus, x, y);
1053
1054#ifdef __ANDROID__
1055 androidEnableBackButton(true);
1056 androidEnableOptionsMenu(true);
1057#endif
1058
1059 /* Cleanup if necessary.
1060 Do not delete menus witch are submenu as they will be deleted by their
1061 parent menu. This could create a crash*/
1062 delete menuAIS;
1063 if (!(sub_menu & MMMENU)) delete contextMenu;
1064 if (!(sub_menu & RTMENU)) delete menuRoute;
1065 if (!(sub_menu & TKMENU)) delete menuTrack;
1066 if (!(sub_menu & WPMENU)) delete menuWaypoint;
1067 } // api_121
1068}
1069
1070void CanvasMenuHandler::AddPluginContextMenuItems(wxMenu *contextMenu,
1071 wxMenu *menuRoute,
1072 wxMenu *menuTrack,
1073 wxMenu *menuWaypoint,
1074 wxMenu *menuAIS) {
1075 // Give the plugins a chance to update their menu items
1076 g_pi_manager->PrepareAllPluginContextMenus();
1077
1078 // Add PlugIn Context Menu items
1079 ArrayOfPlugInMenuItems item_array =
1080 g_pi_manager->GetPluginContextMenuItemArray();
1081
1082 for (unsigned int i = 0; i < item_array.GetCount(); i++) {
1083 PlugInMenuItemContainer *pimis = item_array[i];
1084 if (!pimis->b_viz) continue;
1085
1086 wxMenu *submenu = NULL;
1087 if (pimis->pmenu_item->GetSubMenu()) {
1088 // Create a clone of the submenu referenced in the PlugInMenuItemContainer
1089 auto submenu_proto = pimis->pmenu_item->GetSubMenu();
1090 submenu = new wxMenu();
1091 const wxMenuItemList &items =
1092 pimis->pmenu_item->GetSubMenu()->GetMenuItems();
1093 for (wxMenuItemList::const_iterator it = items.begin(); it != items.end();
1094 ++it) {
1095 int id = (*it)->GetId();
1096 wxMenuItem *psmi =
1097 new wxMenuItem(submenu, id, (*it)->GetItemLabelText(),
1098 (*it)->GetHelp(), (*it)->GetKind());
1099
1100#ifdef __WXMSW__
1101 psmi->SetFont(m_scaledFont);
1102#endif
1103
1104#ifdef __ANDROID__
1105 wxFont sFont = GetOCPNGUIScaledFont(_("Menu"));
1106 psmi->SetFont(sFont);
1107#endif
1108
1109 PrepareMenuItem(psmi);
1110 submenu->Append(psmi);
1111 psmi->Check((*it)->IsChecked());
1112 }
1113 }
1114
1115 wxMenuItem *pmi = new wxMenuItem(
1116 contextMenu, pimis->id, pimis->pmenu_item->GetItemLabelText(),
1117 pimis->pmenu_item->GetHelp(), pimis->pmenu_item->GetKind(), submenu);
1118#ifdef __WXMSW__
1119 pmi->SetFont(m_scaledFont);
1120#endif
1121
1122#ifdef __ANDROID__
1123 wxFont sFont = GetOCPNGUIScaledFont(_("Menu"));
1124 pmi->SetFont(sFont);
1125#endif
1126
1127 PrepareMenuItem(pmi);
1128
1129 wxMenu *dst = contextMenu;
1130 if (pimis->m_in_menu == "Waypoint")
1131 dst = menuWaypoint;
1132 else if (pimis->m_in_menu == "Route")
1133 dst = menuRoute;
1134 else if (pimis->m_in_menu == "Track")
1135 dst = menuTrack;
1136 else if (pimis->m_in_menu == "AIS")
1137 dst = menuAIS;
1138
1139 if (dst != NULL) {
1140 dst->Append(pmi);
1141 dst->Enable(pimis->id, !pimis->b_grey);
1142 }
1143 }
1144}
1145
1146void CanvasMenuHandler::PopupMenuHandler(wxCommandEvent &event) {
1147 RoutePoint *pLast;
1148
1149 wxPoint r;
1150 double zlat, zlon;
1151
1152 int splitMode = 0; // variables for split
1153 bool dupFirstWpt = true, showRPD;
1154
1155 parent->GetCanvasPixPoint(popx * parent->GetDisplayScale(),
1156 popy * parent->GetDisplayScale(), zlat, zlon);
1157
1158 switch (event.GetId()) {
1159 case ID_DEF_MENU_MAX_DETAIL:
1160 vLat = zlat;
1161 vLon = zlon;
1162 parent->ClearbFollow();
1163
1164 top_frame::Get()->DoChartUpdate();
1165
1166 parent->SelectChartFromStack(0, false, CHART_TYPE_DONTCARE,
1167 CHART_FAMILY_RASTER);
1168 break;
1169
1170 case ID_DEF_MENU_SCALE_IN:
1171 parent->DoCanvasStackDelta(-1);
1172 break;
1173
1174 case ID_DEF_MENU_SCALE_OUT:
1175 parent->DoCanvasStackDelta(1);
1176 break;
1177
1178 case ID_UNDO:
1179 parent->undo->UndoLastAction();
1180 parent->InvalidateGL();
1181 parent->Refresh(false);
1182 break;
1183
1184 case ID_REDO:
1185 parent->undo->RedoNextAction();
1186 parent->InvalidateGL();
1187 parent->Refresh(false);
1188 break;
1189
1190 case ID_DEF_MENU_MOVE_BOAT_HERE:
1191 gLat = zlat;
1192 gLon = zlon;
1193 top_frame::Get()->UpdateStatusBar();
1194 break;
1195
1196 case ID_DEF_MENU_GOTO_HERE: {
1197 RoutePoint *pWP_dest = new RoutePoint(zlat, zlon, g_default_wp_icon,
1198 wxEmptyString, wxEmptyString);
1199 pSelect->AddSelectableRoutePoint(zlat, zlon, pWP_dest);
1200
1201 RoutePoint *pWP_src = new RoutePoint(gLat, gLon, g_default_wp_icon,
1202 wxEmptyString, wxEmptyString);
1203 pSelect->AddSelectableRoutePoint(gLat, gLon, pWP_src);
1204
1205 Route *temp_route = new Route();
1206 pRouteList->push_back(temp_route);
1207
1208 temp_route->AddPoint(pWP_src);
1209 temp_route->AddPoint(pWP_dest);
1210
1211 pSelect->AddSelectableRouteSegment(gLat, gLon, zlat, zlon, pWP_src,
1212 pWP_dest, temp_route);
1213
1214 temp_route->m_RouteNameString = _("Temporary GOTO Route");
1215 temp_route->m_RouteStartString = _("Here");
1216 ;
1217 temp_route->m_RouteEndString = _("There");
1218
1219 temp_route->m_bDeleteOnArrival = true;
1220
1221 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
1222
1223 g_pRouteMan->ActivateRoute(temp_route, pWP_dest);
1224
1225 break;
1226 }
1227
1228 case ID_DEF_MENU_DROP_WP: {
1229 RoutePoint *pWP = new RoutePoint(zlat, zlon, g_default_wp_icon,
1230 wxEmptyString, wxEmptyString);
1231 pWP->m_bIsolatedMark = true; // This is an isolated mark
1232 pSelect->AddSelectableRoutePoint(zlat, zlon, pWP);
1233 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
1234
1235 if (!RoutePointGui(*pWP).IsVisibleSelectable(this->parent))
1236 RoutePointGui(*pWP).ShowScaleWarningMessage(parent);
1237
1238 if (RouteManagerDialog::getInstanceFlag()) {
1239 if (pRouteManagerDialog && pRouteManagerDialog->IsShown()) {
1240 pRouteManagerDialog->UpdateWptListCtrl();
1241 }
1242 }
1243
1244 parent->undo->BeforeUndoableAction(Undo_CreateWaypoint, pWP,
1245 Undo_HasParent, NULL);
1246 parent->undo->AfterUndoableAction(NULL);
1247 top_frame::Get()->RefreshAllCanvas(false);
1248 top_frame::Get()->InvalidateAllGL();
1249 g_FlushNavobjChanges = true;
1250 break;
1251 }
1252
1253 case ID_DEF_MENU_NEW_RT: {
1254 parent->StartRoute();
1255 break;
1256 }
1257
1258 case ID_DEF_MENU_AISTARGETLIST:
1259 parent->ShowAISTargetList();
1260 break;
1261
1262 case ID_DEF_MENU_AIS_CPAWARNING:
1263 parent->ToggleCPAWarn();
1264 break;
1265
1266 case ID_WP_MENU_GOTO: {
1267 RoutePoint *pWP_src = new RoutePoint(gLat, gLon, g_default_wp_icon,
1268 wxEmptyString, wxEmptyString);
1269 pSelect->AddSelectableRoutePoint(gLat, gLon, pWP_src);
1270
1271 Route *temp_route = new Route();
1272 pRouteList->push_back(temp_route);
1273
1274 temp_route->AddPoint(pWP_src);
1275 temp_route->AddPoint(m_pFoundRoutePoint);
1276 m_pFoundRoutePoint->SetShared(true);
1277
1278 pSelect->AddSelectableRouteSegment(gLat, gLon, m_pFoundRoutePoint->m_lat,
1279 m_pFoundRoutePoint->m_lon, pWP_src,
1280 m_pFoundRoutePoint, temp_route);
1281
1282 wxString name = m_pFoundRoutePoint->GetName();
1283 if (name.IsEmpty()) name = _("(Unnamed Waypoint)");
1284 wxString rteName = _("Go to ");
1285 rteName.Append(name);
1286 temp_route->m_RouteNameString = rteName;
1287 temp_route->m_RouteStartString = _("Here");
1288 ;
1289 temp_route->m_RouteEndString = name;
1290 temp_route->m_bDeleteOnArrival = true;
1291
1292 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
1293
1294 g_pRouteMan->ActivateRoute(temp_route, m_pFoundRoutePoint);
1295
1296 break;
1297 }
1298
1299 case ID_DEF_MENU_COGUP:
1300 parent->SetUpMode(COURSE_UP_MODE);
1301 break;
1302
1303 case ID_DEF_MENU_HEADUP:
1304 parent->SetUpMode(HEAD_UP_MODE);
1305 break;
1306
1307 case ID_DEF_MENU_NORTHUP:
1308 parent->SetUpMode(NORTH_UP_MODE);
1309 break;
1310
1311 case ID_DEF_MENU_TOGGLE_FULL:
1312 top_frame::Get()->ToggleFullScreen();
1313 break;
1314
1315 case ID_DEF_MENU_GOTOPOSITION:
1316 if (NULL == pGoToPositionDialog) // There is one global instance of the
1317 // Go To Position Dialog
1318 pGoToPositionDialog = new GoToPositionDialog(parent);
1319 pGoToPositionDialog->SetCanvas(parent);
1320 pGoToPositionDialog->CheckPasteBufferForPosition();
1321 pGoToPositionDialog->Show();
1322 break;
1323
1324 case ID_WP_MENU_DELPOINT: {
1325 if (m_pFoundRoutePoint == pAnchorWatchPoint1) {
1326 pAnchorWatchPoint1 = NULL;
1327 g_AW1GUID.Clear();
1328 } else if (m_pFoundRoutePoint == pAnchorWatchPoint2) {
1329 pAnchorWatchPoint2 = NULL;
1330 g_AW2GUID.Clear();
1331 }
1332
1333 if (m_pFoundRoutePoint && !(m_pFoundRoutePoint->m_bIsInLayer) &&
1334 (m_pFoundRoutePoint->GetIconName() != "mob")) {
1335 // If the WP belongs to an invisible route, we come here instead of to
1336 // ID_RT_MENU_DELPOINT
1337 // Check it, and if so then remove the point from its routes
1338 wxArrayPtrVoid *proute_array =
1339 g_pRouteMan->GetRouteArrayContaining(m_pFoundRoutePoint);
1340 if (proute_array) {
1341 pWayPointMan->DestroyWaypoint(m_pFoundRoutePoint);
1342 delete proute_array;
1343 } else {
1344 parent->undo->BeforeUndoableAction(
1345 Undo_DeleteWaypoint, m_pFoundRoutePoint, Undo_IsOrphanded,
1346 NULL /*m_pFoundPoint*/);
1347 NavObj_dB::GetInstance().DeleteRoutePoint(m_pFoundRoutePoint);
1348 pSelect->DeleteSelectablePoint(m_pFoundRoutePoint,
1349 SELTYPE_ROUTEPOINT);
1350 if (NULL != pWayPointMan)
1351 pWayPointMan->RemoveRoutePoint(m_pFoundRoutePoint);
1352 parent->undo->AfterUndoableAction(NULL);
1353 }
1354
1355 if (g_pMarkInfoDialog) {
1356 g_pMarkInfoDialog->ClearData();
1357 }
1358
1359 if (RouteManagerDialog::getInstanceFlag()) {
1360 if (pRouteManagerDialog) {
1361 if (pRouteManagerDialog->IsShown())
1362 pRouteManagerDialog->UpdateWptListCtrl();
1363 }
1364 }
1365 top_frame::Get()->RefreshAllCanvas(false);
1366 top_frame::Get()->InvalidateAllGL();
1367 }
1368 break;
1369 }
1370 case ID_WP_MENU_PROPERTIES:
1371 parent->ShowMarkPropertiesDialog(m_pFoundRoutePoint);
1372 break;
1373
1374 case ID_WP_MENU_CLEAR_ANCHORWATCH: {
1375 wxString guid = wxEmptyString;
1376 if (pAnchorWatchPoint1 == m_pFoundRoutePoint) {
1377 pAnchorWatchPoint1 = NULL;
1378 guid = g_AW1GUID;
1379 g_AW1GUID.Clear();
1380 } else if (pAnchorWatchPoint2 == m_pFoundRoutePoint) {
1381 pAnchorWatchPoint2 = NULL;
1382 guid = g_AW2GUID;
1383 g_AW2GUID.Clear();
1384 }
1385 if (!guid.IsEmpty()) {
1386 nlohmann::json v;
1387 v["GUID"] = guid;
1388 SendJsonMessageToAllPlugins("OCPN_ANCHOR_WATCH_CLEARED", v);
1389 }
1390 break;
1391 }
1392
1393 case ID_WP_MENU_SET_ANCHORWATCH: {
1394 wxString guid = wxEmptyString;
1395 if (pAnchorWatchPoint1 == NULL) {
1396 pAnchorWatchPoint1 = m_pFoundRoutePoint;
1397 g_AW1GUID = pAnchorWatchPoint1->m_GUID;
1398 guid = g_AW1GUID;
1399 wxString nn;
1400 nn = m_pFoundRoutePoint->GetName();
1401 if (nn.IsNull()) {
1402 nn.Printf("%d m", g_nAWDefault);
1403 m_pFoundRoutePoint->SetName(nn);
1404 }
1405 } else if (pAnchorWatchPoint2 == NULL) {
1406 pAnchorWatchPoint2 = m_pFoundRoutePoint;
1407 g_AW2GUID = pAnchorWatchPoint2->m_GUID;
1408 guid = g_AW2GUID;
1409 wxString nn;
1410 nn = m_pFoundRoutePoint->GetName();
1411 if (nn.IsNull()) {
1412 nn.Printf("%d m", g_nAWDefault);
1413 m_pFoundRoutePoint->SetName(nn);
1414 }
1415 }
1416 if (!guid.IsEmpty()) {
1417 nlohmann::json v;
1418 v["GUID"] = guid;
1419 SendJsonMessageToAllPlugins("OCPN_ANCHOR_WATCH_SET", v);
1420 }
1421 break;
1422 }
1423
1424 case ID_DEF_MENU_ACTIVATE_MEASURE:
1425 parent->StartMeasureRoute();
1426 break;
1427
1428 case ID_DEF_MENU_DEACTIVATE_MEASURE:
1429 parent->CancelMeasureRoute();
1430 // gFrame->SurfaceAllCanvasToolbars();
1431 parent->InvalidateGL();
1432 parent->Refresh(false);
1433 break;
1434
1435 case ID_DEF_MENU_CM93OFFSET_DIALOG: {
1436 if (NULL == g_pCM93OffsetDialog) {
1437 g_pCM93OffsetDialog = new CM93OffsetDialog(wxTheApp->GetTopWindow());
1438 }
1439
1440 cm93compchart *pch = NULL;
1441 if (!parent->GetVP().b_quilt && parent->m_singleChart &&
1442 (parent->m_singleChart->GetChartType() == CHART_TYPE_CM93COMP)) {
1443 pch = (cm93compchart *)parent->m_singleChart;
1444 }
1445
1446 if (g_pCM93OffsetDialog) {
1447 g_pCM93OffsetDialog->SetCM93Chart(pch);
1448 g_pCM93OffsetDialog->Show();
1449 g_pCM93OffsetDialog->UpdateMCOVRList(parent->GetVP());
1450 }
1451
1452 break;
1453 }
1454 case ID_DEF_MENU_QUERY: {
1455 parent->ShowObjectQueryWindow(popx, popy, zlat, zlon);
1456 break;
1457 }
1458 case ID_DEF_MENU_AIS_QUERY: {
1459 ShowAISTargetQueryDialog(parent, m_FoundAIS_MMSI);
1460 break;
1461 }
1462
1463 case ID_DEF_MENU_AIS_CPA: {
1464 auto myptarget = g_pAIS->Get_Target_Data_From_MMSI(m_FoundAIS_MMSI);
1465 if (myptarget) myptarget->Toggle_AIS_CPA();
1466 break;
1467 }
1468
1469 case ID_DEF_MENU_AISSHOWTRACK: {
1470 auto myptarget = g_pAIS->Get_Target_Data_From_MMSI(m_FoundAIS_MMSI);
1471 if (myptarget) myptarget->ToggleShowTrack();
1472 break;
1473 }
1474
1475 case ID_DEF_MENU_COPY_MMSI: {
1476 // Write MMSI # as text to the clipboard
1477 if (wxTheClipboard->Open()) {
1478 wxTheClipboard->SetData(
1479 new wxTextDataObject(wxString::Format("%09d", m_FoundAIS_MMSI)));
1480 wxTheClipboard->Close();
1481 }
1482 break;
1483 }
1484
1485 case ID_DEF_MENU_QUILTREMOVE: {
1486 if (parent->GetVP().b_quilt) {
1487 int dbIndex = parent->m_pQuilt->GetChartdbIndexAtPix(
1488 parent->GetVP(), wxPoint(popx, popy));
1489 parent->RemoveChartFromQuilt(dbIndex);
1490
1491 parent->ReloadVP();
1492 }
1493
1494 break;
1495 }
1496
1497 case ID_DEF_MENU_CURRENTINFO: {
1498 parent->DrawTCWindow(popx, popy, (void *)m_pIDXCandidate);
1499 parent->Refresh(false);
1500
1501 break;
1502 }
1503
1504 case ID_DEF_MENU_TIDEINFO: {
1505 parent->DrawTCWindow(popx, popy, (void *)m_pIDXCandidate);
1506 parent->Refresh(false);
1507
1508 break;
1509 }
1510
1511 case ID_DGB_MENU_NMEA_WINDOW:
1512 m_nmea_log->Show();
1513 m_nmea_log->Raise();
1514 break;
1515
1516 case ID_RT_MENU_REVERSE: {
1517 if (m_pSelectedRoute->m_bIsInLayer) break;
1518
1519 int ask_return =
1520 OCPNMessageBox(parent, g_pRouteMan->GetRouteReverseMessage(),
1521 _("Rename Waypoints?"), wxYES_NO | wxCANCEL);
1522
1523 if (ask_return != wxID_CANCEL) {
1524 pSelect->DeleteAllSelectableRouteSegments(m_pSelectedRoute);
1525 m_pSelectedRoute->Reverse(ask_return == wxID_YES);
1526 pSelect->AddAllSelectableRouteSegments(m_pSelectedRoute);
1527
1528 NavObj_dB::GetInstance().UpdateRoute(m_pSelectedRoute);
1529
1530 if (pRoutePropDialog && (pRoutePropDialog->IsShown())) {
1531 pRoutePropDialog->SetRouteAndUpdate(m_pSelectedRoute);
1532 // pNew->UpdateProperties();
1533 }
1534 top_frame::Get()->InvalidateAllGL();
1535 top_frame::Get()->RefreshAllCanvas();
1536 }
1537 break;
1538 }
1539
1540 case ID_RT_MENU_SHOWNAMES: {
1541 if (m_pSelectedRoute) {
1542 m_pSelectedRoute->ShowWaypointNames(
1543 !m_pSelectedRoute->AreWaypointNamesVisible());
1544 }
1545
1546 break;
1547 }
1548
1549 case ID_RT_MENU_RESEQUENCE: {
1550 if (m_pSelectedRoute) {
1551 if (m_pSelectedRoute->m_bIsInLayer) break;
1552
1553 int ask_return =
1554 OCPNMessageBox(parent, g_pRouteMan->GetRouteResequenceMessage(),
1555 _("Rename Waypoints?"), wxYES_NO | wxCANCEL);
1556
1557 if (ask_return != wxID_CANCEL) {
1558 m_pSelectedRoute->RenameRoutePoints();
1559 }
1560
1561 top_frame::Get()->InvalidateAllGL();
1562 top_frame::Get()->RefreshAllCanvas();
1563 }
1564
1565 break;
1566 }
1567
1568 case ID_RT_MENU_DELETE: {
1569 bool confirmed = RouteGui::OnDelete(parent);
1570
1571 if (confirmed) {
1572 if (g_pRouteMan->GetpActiveRoute() == m_pSelectedRoute)
1573 g_pRouteMan->DeactivateRoute();
1574
1575 if (m_pSelectedRoute->m_bIsInLayer) break;
1576
1577 NavObj_dB::GetInstance().DeleteRoute(m_pSelectedRoute);
1578 if (!g_pRouteMan->DeleteRoute(m_pSelectedRoute)) break;
1579
1580 if (RouteManagerDialog::getInstanceFlag()) {
1581 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
1582 pRouteManagerDialog->UpdateRouteListCtrl();
1583 }
1584
1585 if (g_pMarkInfoDialog && g_pMarkInfoDialog->IsShown()) {
1586 g_pMarkInfoDialog->ValidateMark();
1587 g_pMarkInfoDialog->UpdateProperties();
1588 }
1589
1590 parent->undo->InvalidateUndo();
1591
1592 top_frame::Get()->InvalidateAllGL();
1593 top_frame::Get()->RefreshAllCanvas();
1594 }
1595 break;
1596 }
1597
1598 case ID_RT_MENU_ACTIVATE: {
1599 if (g_pRouteMan->GetpActiveRoute()) g_pRouteMan->DeactivateRoute();
1600
1601 // If this is an auto-created MOB route, always select the second point
1602 // (the MOB)
1603 // as the destination.
1604 RoutePoint *best_point;
1605 if (m_pSelectedRoute) {
1606 if (wxNOT_FOUND == m_pSelectedRoute->m_RouteNameString.Find("MOB")) {
1607 best_point = g_pRouteMan->FindBestActivatePoint(
1608 m_pSelectedRoute, gLat, gLon, gCog, gSog);
1609 } else
1610 best_point = m_pSelectedRoute->GetPoint(2);
1611
1612 g_pRouteMan->ActivateRoute(m_pSelectedRoute, best_point);
1613 m_pSelectedRoute->m_bRtIsSelected = false;
1614 }
1615
1616 break;
1617 }
1618
1619 case ID_RT_MENU_DEACTIVATE:
1620 g_pRouteMan->DeactivateRoute();
1621 m_pSelectedRoute->m_bRtIsSelected = false;
1622
1623 break;
1624
1625 case ID_RT_MENU_INSERT: {
1626 if (m_pSelectedRoute->m_bIsInLayer) break;
1627 bool rename = false;
1628 m_pSelectedRoute->InsertPointAfter(m_pFoundRoutePoint, zlat, zlon,
1629 rename);
1630
1631 pSelect->DeleteAllSelectableRoutePoints(m_pSelectedRoute);
1632 pSelect->DeleteAllSelectableRouteSegments(m_pSelectedRoute);
1633
1634 pSelect->AddAllSelectableRouteSegments(m_pSelectedRoute);
1635 pSelect->AddAllSelectableRoutePoints(m_pSelectedRoute);
1636
1637 // As a special case (which comes up often)...
1638 // If the inserted waypoint is on the active leg of an active route
1639 /* if(m_pSelectedRoute->m_bRtIsActive)
1640 {
1641 if(m_pSelectedRoute->m_nRouteActivePoint == np + 1)
1642 {
1643 pNew_Point = m_pSelectedRoute->GetPoint(np + 2);
1644 pRouteMan->ActivateRoutePoint(m_pSelectedRoute, pNew_Point);
1645 }
1646 }
1647 */
1648 NavObj_dB::GetInstance().UpdateRoute(m_pSelectedRoute);
1649
1650 if (pRoutePropDialog && (pRoutePropDialog->IsShown())) {
1651 pRoutePropDialog->SetRouteAndUpdate(m_pSelectedRoute, true);
1652 }
1653
1654 break;
1655 }
1656
1657 case ID_RT_MENU_APPEND:
1658
1659 if (m_pSelectedRoute->m_bIsInLayer) break;
1660
1661 parent->m_pMouseRoute = m_pSelectedRoute;
1662 parent->m_routeState = m_pSelectedRoute->GetnPoints() + 1;
1663 parent->m_pMouseRoute->m_lastMousePointIndex =
1664 m_pSelectedRoute->GetnPoints();
1665 parent->m_pMouseRoute->SetHiLite(50);
1666
1667 pLast = m_pSelectedRoute->GetLastPoint();
1668
1669 parent->m_prev_rlat = pLast->m_lat;
1670 parent->m_prev_rlon = pLast->m_lon;
1671 parent->m_prev_pMousePoint = pLast;
1672
1673 parent->m_bAppendingRoute = true;
1674
1675 parent->SetCursor(*parent->pCursorPencil);
1676#ifdef __ANDROID__
1677 androidSetRouteAnnunciator(true);
1678#endif
1679
1680 parent->HideGlobalToolbar();
1681
1682 break;
1683
1684 case ID_RT_MENU_SPLIT_LEG: // split route around a leg
1685 splitMode++;
1686 dupFirstWpt = false;
1687 case ID_RT_MENU_SPLIT_WPT: // split route at a wpt
1688
1689 showRPD = (pRoutePropDialog && pRoutePropDialog->IsShown());
1690
1691 if (g_pRouteMan->GetpActiveRoute() == m_pSelectedRoute)
1692 g_pRouteMan->DeactivateRoute();
1693
1694 m_pHead = new Route();
1695 m_pTail = new Route();
1696 m_pHead->CloneRoute(m_pSelectedRoute, 1, m_SelectedIdx + 1, _("_A"));
1697 m_pTail->CloneRoute(m_pSelectedRoute, m_SelectedIdx + 1 + splitMode,
1698 m_pSelectedRoute->GetnPoints(), _("_B"), dupFirstWpt);
1699 pRouteList->push_back(m_pHead);
1700 NavObj_dB::GetInstance().InsertRoute(m_pHead);
1701
1702 pRouteList->push_back(m_pTail);
1703 NavObj_dB::GetInstance().InsertRoute(m_pTail);
1704
1705 NavObj_dB::GetInstance().DeleteRoute(m_pSelectedRoute);
1706
1707 pSelect->DeleteAllSelectableRoutePoints(m_pSelectedRoute);
1708 pSelect->DeleteAllSelectableRouteSegments(m_pSelectedRoute);
1709 g_pRouteMan->DeleteRoute(m_pSelectedRoute);
1710 pSelect->AddAllSelectableRouteSegments(m_pTail);
1711 pSelect->AddAllSelectableRoutePoints(m_pTail);
1712 pSelect->AddAllSelectableRouteSegments(m_pHead);
1713 pSelect->AddAllSelectableRoutePoints(m_pHead);
1714
1715 if (showRPD) {
1716 pRoutePropDialog->SetRouteAndUpdate(m_pHead);
1717 pRoutePropDialog->Show();
1718 }
1719 if (RouteManagerDialog::getInstanceFlag() && pRouteManagerDialog &&
1720 (pRouteManagerDialog->IsShown()))
1721 pRouteManagerDialog->UpdateRouteListCtrl();
1722 break;
1723
1724 case ID_RT_MENU_COPY:
1725 if (m_pSelectedRoute) Kml::CopyRouteToClipboard(m_pSelectedRoute);
1726 break;
1727
1728 case ID_TK_MENU_COPY:
1729 if (m_pSelectedTrack) Kml::CopyTrackToClipboard(m_pSelectedTrack);
1730 break;
1731
1732 case ID_WPT_MENU_COPY:
1733 if (m_pFoundRoutePoint) Kml::CopyWaypointToClipboard(m_pFoundRoutePoint);
1734 break;
1735
1736 case ID_WPT_MENU_SENDTOGPS:
1737 if (m_pFoundRoutePoint) {
1738 if (parent->m_active_upload_port.Length())
1739 RoutePointGui(*m_pFoundRoutePoint)
1740 .SendToGPS(parent->m_active_upload_port.BeforeFirst(' '), NULL);
1741 else {
1742 SendToGpsDlg dlg;
1743 dlg.SetWaypoint(m_pFoundRoutePoint);
1744 wxFont fo = GetOCPNGUIScaledFont(_("Dialog"));
1745 dlg.SetFont(fo);
1746
1747 dlg.Create(NULL, -1, _("Send to GPS") + "...", "");
1748 dlg.ShowModal();
1749 }
1750 }
1751 break;
1752
1753 case ID_WPT_MENU_SENDTONEWGPS:
1754 if (m_pFoundRoutePoint) {
1755 SendToGpsDlg dlg;
1756 dlg.SetWaypoint(m_pFoundRoutePoint);
1757
1758 dlg.Create(NULL, -1, _("Send to GPS") + "...", "");
1759 dlg.ShowModal();
1760 }
1761 break;
1762
1763 case ID_WPT_MENU_SENDTOPEER:
1764 if (m_pFoundRoutePoint) {
1765 SendToPeerDlg dlg;
1766 dlg.SetWaypoint(m_pFoundRoutePoint);
1767
1768 // Perform initial scan, if necessary
1769
1770 // Check for stale cache...
1771 MdnsCache::GetInstance().Validate();
1772 if (MdnsCache::GetInstance().GetCache().empty())
1773 dlg.SetScanOnCreate(true);
1774
1775 dlg.SetScanTime(5); // seconds
1776 dlg.Create(NULL, -1, _("Send Waypoint to OpenCPN Peer") + "...", "");
1777 dlg.ShowModal();
1778 }
1779 break;
1780
1781 case ID_RT_MENU_SENDTOGPS:
1782 if (m_pSelectedRoute) {
1783 if (parent->m_active_upload_port.Length())
1784 RouteGui(*m_pSelectedRoute)
1785 .SendToGPS(parent->m_active_upload_port.BeforeFirst(' '), true,
1786 NULL);
1787 else {
1788 SendToGpsDlg dlg;
1789 dlg.SetRoute(m_pSelectedRoute);
1790
1791 dlg.Create(NULL, -1, _("Send to GPS") + "...", "");
1792 dlg.ShowModal();
1793 }
1794 }
1795 break;
1796
1797 case ID_RT_MENU_SENDTONEWGPS:
1798 if (m_pSelectedRoute) {
1799 SendToGpsDlg dlg;
1800 dlg.SetRoute(m_pSelectedRoute);
1801
1802 dlg.Create(NULL, -1, _("Send to GPS") + "...", "");
1803 dlg.ShowModal();
1804 }
1805 break;
1806
1807 case ID_RT_MENU_SENDTOPEER:
1808 if (m_pSelectedRoute) {
1809 SendToPeerDlg dlg;
1810 dlg.SetRoute(m_pSelectedRoute);
1811
1812 // Perform initial scan, if necessary
1813
1814 // Check for stale cache...
1815 MdnsCache::GetInstance().Validate();
1816 if (MdnsCache::GetInstance().GetCache().empty())
1817 dlg.SetScanOnCreate(true);
1818
1819 dlg.SetScanTime(5); // seconds
1820 dlg.Create(NULL, -1, _("Send Route to OpenCPN Peer") + "...", "");
1821 dlg.ShowModal();
1822 }
1823 break;
1824
1825 case ID_PASTE_WAYPOINT:
1826 pupHandler_PasteWaypoint();
1827 break;
1828
1829 case ID_PASTE_ROUTE:
1830 pupHandler_PasteRoute();
1831 break;
1832
1833 case ID_PASTE_TRACK:
1834 pupHandler_PasteTrack();
1835 break;
1836
1837 case ID_RT_MENU_DELPOINT:
1838 if (m_pSelectedRoute) {
1839 if (m_pSelectedRoute->m_bIsInLayer) break;
1840
1841 pWayPointMan->DestroyWaypoint(m_pFoundRoutePoint);
1842
1843 if (pRoutePropDialog && (pRoutePropDialog->IsShown())) {
1844 // Selected route may have been deleted as one-point route, so
1845 // check it
1846 if (g_pRouteMan->IsRouteValid(m_pSelectedRoute)) {
1847 pRoutePropDialog->SetRouteAndUpdate(m_pSelectedRoute, true);
1848 } else
1849 pRoutePropDialog->Hide();
1850 }
1851
1852 if (RouteManagerDialog::getInstanceFlag()) {
1853 if (pRouteManagerDialog && pRouteManagerDialog->IsShown()) {
1854 pRouteManagerDialog->UpdateWptListCtrl();
1855 pRouteManagerDialog->UpdateRouteListCtrl();
1856 }
1857 }
1858
1859 top_frame::Get()->InvalidateAllGL();
1860 top_frame::Get()->RefreshAllCanvas(true);
1861 }
1862
1863 break;
1864
1865 case ID_RT_MENU_REMPOINT:
1866 if (m_pSelectedRoute) {
1867 if (m_pSelectedRoute->m_bIsInLayer) break;
1868 g_pRouteMan->RemovePointFromRoute(m_pFoundRoutePoint, m_pSelectedRoute,
1869 parent->m_routeState);
1870 top_frame::Get()->InvalidateAllGL();
1871 top_frame::Get()->RefreshAllCanvas();
1872 }
1873 break;
1874
1875 case ID_RT_MENU_ACTPOINT:
1876 if (g_pRouteMan->GetpActiveRoute() == m_pSelectedRoute) {
1877 g_pRouteMan->ActivateRoutePoint(m_pSelectedRoute, m_pFoundRoutePoint);
1878 m_pSelectedRoute->m_bRtIsSelected = false;
1879 }
1880
1881 break;
1882
1883 case ID_RT_MENU_DEACTPOINT:
1884 break;
1885
1886 case ID_RT_MENU_ACTNXTPOINT:
1887 if (g_pRouteMan->GetpActiveRoute() == m_pSelectedRoute) {
1888 g_pRouteMan->ActivateNextPoint(m_pSelectedRoute, true);
1889 m_pSelectedRoute->m_bRtIsSelected = false;
1890 }
1891
1892 break;
1893
1894 case ID_RT_MENU_PROPERTIES: {
1895 parent->ShowRoutePropertiesDialog(_("Route Properties"),
1896 m_pSelectedRoute);
1897 break;
1898 }
1899
1900 case ID_TK_MENU_PROPERTIES: {
1901 parent->ShowTrackPropertiesDialog(m_pSelectedTrack);
1902 break;
1903 }
1904
1905 case ID_TK_MENU_DELETE: {
1906 int dlg_return = wxID_YES;
1907 if (g_bConfirmObjectDelete) {
1908 dlg_return = OCPNMessageBox(
1909 parent, _("Are you sure you want to delete this track?"),
1910 _("OpenCPN Track Delete"),
1911 (long)wxYES_NO | wxCANCEL | wxYES_DEFAULT);
1912 }
1913
1914 if (dlg_return == wxID_YES) {
1915 if (m_pSelectedTrack == g_pActiveTrack)
1916 m_pSelectedTrack = top_frame::Get()->TrackOff();
1917 g_pAIS->DeletePersistentTrack(m_pSelectedTrack);
1918 // pConfig->DeleteConfigTrack(m_pSelectedTrack);
1919 NavObj_dB::GetInstance().DeleteTrack(m_pSelectedTrack);
1920 RoutemanGui(*g_pRouteMan).DeleteTrack(m_pSelectedTrack);
1921
1922 if (TrackPropDlg::getInstanceFlag() && pTrackPropDialog &&
1923 (pTrackPropDialog->IsShown()) &&
1924 (m_pSelectedTrack == pTrackPropDialog->GetTrack())) {
1925 pTrackPropDialog->Hide();
1926 }
1927
1928 if (RoutePropDlgImpl::getInstanceFlag() && pRouteManagerDialog &&
1929 pRouteManagerDialog->IsShown()) {
1930 pRouteManagerDialog->UpdateTrkListCtrl();
1931 pRouteManagerDialog->UpdateRouteListCtrl();
1932 }
1933 top_frame::Get()->InvalidateAllGL();
1934 top_frame::Get()->RefreshAllCanvas();
1935 }
1936 break;
1937 }
1938
1939 case ID_TK_MENU_SENDTOPEER:
1940 if (m_pSelectedTrack) {
1941 SendToPeerDlg dlg;
1942 dlg.SetTrack(m_pSelectedTrack);
1943
1944 // Perform initial scan, if necessary
1945
1946 // Check for stale cache...
1947 MdnsCache::GetInstance().Validate();
1948 if (MdnsCache::GetInstance().GetCache().empty())
1949 dlg.SetScanOnCreate(true);
1950
1951 dlg.SetScanTime(5); // seconds
1952 dlg.Create(NULL, -1, _("Send Track to OpenCPN Peer") + "...", "");
1953 dlg.ShowModal();
1954 }
1955 break;
1956
1957 case ID_RC_MENU_SCALE_IN:
1958 top_frame::Get()->DoStackDown(parent);
1959 parent->GetCanvasPointPix(zlat, zlon, &r);
1960 parent->WarpPointer(r.x, r.y);
1961 break;
1962
1963 case ID_RC_MENU_SCALE_OUT:
1964 top_frame::Get()->DoStackUp(parent);
1965 parent->GetCanvasPointPix(zlat, zlon, &r);
1966 parent->WarpPointer(r.x, r.y);
1967 break;
1968
1969 case ID_RC_MENU_ZOOM_IN:
1970 parent->SetVPScale(parent->GetVPScale() * 2);
1971 parent->GetCanvasPointPix(zlat, zlon, &r);
1972 parent->WarpPointer(r.x, r.y);
1973 break;
1974
1975 case ID_RC_MENU_ZOOM_OUT:
1976 parent->SetVPScale(parent->GetVPScale() / 2);
1977 parent->GetCanvasPointPix(zlat, zlon, &r);
1978 parent->WarpPointer(r.x, r.y);
1979 break;
1980
1981 case ID_RC_MENU_FINISH:
1982 parent->FinishRoute();
1983 // gFrame->SurfaceAllCanvasToolbars();
1984 parent->Refresh(false);
1985 g_FlushNavobjChanges = true;
1986 break;
1987
1988 case ID_DEF_ZERO_XTE:
1989 g_pRouteMan->ZeroCurrentXTEToActivePoint();
1990 break;
1991
1992 default: {
1993 // Look for PlugIn Context Menu selections
1994 // If found, make the callback
1995 ArrayOfPlugInMenuItems item_array =
1996 g_pi_manager->GetPluginContextMenuItemArray();
1997
1998 for (unsigned int i = 0; i < item_array.GetCount(); i++) {
1999 PlugInMenuItemContainer *pimis = item_array[i];
2000 int target_id = pimis->id;
2001
2002 // Check submenus, if present.
2003 if (pimis->pmenu_item->GetSubMenu()) {
2004 const wxMenuItemList &items =
2005 pimis->pmenu_item->GetSubMenu()->GetMenuItems();
2006 for (wxMenuItemList::const_iterator it = items.begin();
2007 it != items.end(); ++it) {
2008 if ((*it)->GetId() == event.GetId()) {
2009 target_id = (*it)->GetId();
2010 break;
2011 }
2012 }
2013 }
2014
2015 if (pimis->m_pplugin && (target_id == event.GetId())) {
2016 if (pimis->extended) {
2017 std::string object_type;
2018 std::string object_ident;
2019
2020 if ((pimis->m_in_menu.IsSameAs("Waypoint")) && m_pFoundRoutePoint) {
2021 object_type = "Waypoint";
2022 object_ident = m_pFoundRoutePoint->m_GUID.ToStdString();
2023 } else if ((pimis->m_in_menu.IsSameAs("Route")) &&
2024 m_pSelectedRoute) {
2025 object_type = "Route";
2026 object_ident = m_pSelectedRoute->m_GUID.ToStdString();
2027 } else if ((pimis->m_in_menu.IsSameAs("Track")) &&
2028 m_pSelectedTrack) {
2029 object_type = "Track";
2030 object_ident = m_pSelectedTrack->m_GUID.ToStdString();
2031 } else if ((pimis->m_in_menu.IsSameAs("AIS")) && m_FoundAIS_MMSI) {
2032 object_type = "AIS";
2033 wxString sAIS = wxString::Format("%d", m_FoundAIS_MMSI);
2034 object_ident = sAIS.ToStdString();
2035 }
2036
2037 opencpn_plugin_120 *ppi =
2038 dynamic_cast<opencpn_plugin_120 *>(pimis->m_pplugin);
2039 if (ppi)
2040 ppi->OnContextMenuItemCallbackExt(target_id, object_ident,
2041 object_type, zlat, zlon);
2042 } else {
2043 pimis->m_pplugin->OnContextMenuItemCallback(pimis->id);
2044 }
2045 }
2046 }
2047 break;
2048 }
2049 } // switch
2050
2051 // Chart Groups....
2052 if ((event.GetId() >= ID_DEF_MENU_GROUPBASE) &&
2053 (event.GetId() <=
2054 ID_DEF_MENU_GROUPBASE + (int)g_pGroupArray->GetCount())) {
2055 parent->SetGroupIndex(event.GetId() - ID_DEF_MENU_GROUPBASE);
2056 }
2057
2058 parent->InvalidateGL();
2059
2060 g_click_stop = 0; // Context menu was processed, all is well
2061}
AisDecoder * g_pAIS
Global instance.
Class AisDecoder and helpers.
Global state for AIS decoder.
AIS target definitions.
std::unique_ptr< HostApi > GetHostApi()
HostApi factory,.
Definition api_122.cpp:36
Canvas context (right click) menu handler.
Charts database management
ChartGroupArray * g_pGroupArray
Global instance.
Definition chartdbs.cpp:61
Basic chart info storage.
Generic Chart canvas base.
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:174
void Validate()
Check that all entries are accessible, remove stale ones.
Represents a waypoint or mark within the navigation system.
Definition route_point.h:71
wxString m_GUID
Globally Unique Identifier for the waypoint.
bool m_bIsolatedMark
Flag indicating if the waypoint is a standalone mark.
Represents a navigational route in the navigation system.
Definition route.h:99
wxString m_RouteStartString
Name or description of the route's starting point.
Definition route.h:252
bool m_bDeleteOnArrival
Flag indicating whether the route should be deleted once navigation reaches the end.
Definition route.h:268
wxString m_RouteEndString
Name or description of the route's ending point.
Definition route.h:257
wxString m_RouteNameString
User-assigned name for the route.
Definition route.h:247
bool ActivateRoutePoint(Route *pA, RoutePoint *pRP)
Activates a specific waypoint within a route for navigation.
Definition routeman.cpp:287
wxArrayPtrVoid * GetRouteArrayContaining(RoutePoint *pWP)
Find all routes that contain the given waypoint.
Definition routeman.cpp:150
bool ActivateNextPoint(Route *pr, bool skipped)
Activates the next waypoint in a route when the current waypoint is reached.
Definition routeman.cpp:359
bool DeleteRoute(Route *pRoute)
Definition routeman.cpp:777
bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint=NULL)
Activates a route for navigation.
Definition routeman.cpp:222
Represents a track, which is a series of connected track points.
Definition track.h:117
bool RemoveRoutePoint(RoutePoint *prp)
Remove a routepoint from list if present, deallocate it all cases.
virtual void OnContextMenuItemCallback(int id)
Handles context menu item selection.
CM93OffsetDialog * g_pCM93OffsetDialog
Global instance.
Definition cm93.cpp:73
Class cm93chart and helpers – CM93 chart state.
Global variables stored in configuration file.
OpenCPN Georef utility.
Platform independent GL includes.
GoToPositionDialog * pGoToPositionDialog
Global instance.
Go to position dialog...
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
Definition gui_lib.cpp:61
wxFont GetOCPNGUIScaledFont(wxString item)
Retrieves a font optimized for touch and high-resolution interfaces.
Definition gui_lib.cpp:90
double vLat
Virtual lat from chcanv popup.
Definition gui_vars.cpp:72
double vLon
Virtual lon from chcanv popup.
Definition gui_vars.cpp:73
double g_androidDPmm
Only used used by ANDROID.
Definition gui_vars.cpp:66
Miscellaneous globals primarely used by gui layer, not persisted in configuration file.
Read and write KML Format.
MarkInfoDlg * g_pMarkInfoDialog
global instance
Definition mark_info.cpp:77
Waypoint properties maintenance dialog.
mDNS host lookups cache.
MySQL based storage for routes, tracks, etc.
OpenCPN top window.
MyFrame * gFrame
Global instance.
OpenCPN Platform specific support utilities.
bool bGPSValid
Indicate whether the Global Navigation Satellite System (GNSS) has a valid position.
Definition own_ship.cpp:34
double gHdt
True heading in degrees (0-359.99).
Definition own_ship.cpp:30
double gLat
Vessel's current latitude in decimal degrees.
Definition own_ship.cpp:26
double gCog
Course over ground in degrees (0-359.99).
Definition own_ship.cpp:28
double gSog
Speed over ground in knots.
Definition own_ship.cpp:29
double gLon
Vessel's current longitude in decimal degrees.
Definition own_ship.cpp:27
Position, course, speed, etc.
Confirm peer transfer PIN code dialog.
Tools to send data to plugins.
PlugInManager * g_pi_manager
Global instance.
PlugInManager and helper classes – Mostly gui parts (dialogs) and plugin API stuff.
Chart quilt support.
Route abstraction.
Route drawing stuff.
Purpose: Track and Trackpoint drawing stuff.
RoutePropDlgImpl * pRoutePropDialog
Global instance.
Route properties dialog.
RoutePoint * pAnchorWatchPoint2
Global instance.
Definition routeman.cpp:64
Routeman * g_pRouteMan
Global instance.
Definition routeman.cpp:60
RouteList * pRouteList
Global instance.
Definition routeman.cpp:66
RoutePoint * pAnchorWatchPoint1
Global instance.
Definition routeman.cpp:63
Route Manager.
Routeman drawing stuff.
RouteManagerDialog * pRouteManagerDialog
Global instance.
Manage routes dialog.
S57 Chart Object.
Select * pSelect
Global instance.
Definition select.cpp:36
Selected route, segment, waypoint, etc.
Send route/waypoint to GPS dialog.
Send Route/Waypoint/Track to peer dialog.
Chart Symbols.
Tide and Current Manager @TODO Add original author copyright.
Abstract gFrame/MyFrame interface.
ActiveTrack * g_pActiveTrack
global instance
Definition track.cpp:100
Recorded track abstraction.
Track and Trackpoint drawing stuff.
TrackPropDlg * pTrackPropDialog
Global instance.
Track Properties Dialog.
Framework for Undo features.