OpenCPN Partial API docs
Loading...
Searching...
No Matches
MarkInfo.cpp
1/**************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: MarkProperties Support
5 * Author: David Register
6 *
7 ***************************************************************************
8 * Copyright (C) 2010 by David S. Register *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 **************************************************************************/
25#include "config.h"
26
27// 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/datetime.h>
35#include <wx/clipbrd.h>
36#include <wx/print.h>
37#include <wx/printdlg.h>
38#include <wx/stattext.h>
39#include <wx/clrpicker.h>
40#include <wx/bmpbuttn.h>
41
42#include "chcanv.h"
43#include "gui_lib.h"
44#include "MarkInfo.h"
45#include "model/georef.h"
46#include "model/navutil_base.h"
47#include "model/own_ship.h"
48#include "model/position_parser.h"
49#include "model/route.h"
50#include "model/routeman.h"
51#include "model/select.h"
52#include "navutil.h" // for Route
53#include "ocpn_frame.h"
54#include "OCPNPlatform.h"
55#include "pluginmanager.h"
56#include "routemanagerdialog.h"
57#include "RoutePropDlgImpl.h"
58#include "styles.h"
59#include "model/svg_utils.h"
60#include "TCWin.h"
61#include "ui_utils.h"
62#include "model/navobj_db.h"
63
64#ifdef __ANDROID__
65#include "androidUTIL.h"
66#include <QtWidgets/QScroller>
67#endif
68
69MarkInfoDlg* g_pMarkInfoDialog;
70
71extern TCMgr* ptcmgr;
72extern MyConfig* pConfig;
73extern Routeman* g_pRouteMan;
74extern RouteManagerDialog* pRouteManagerDialog;
75extern RoutePropDlgImpl* pRoutePropDialog;
76extern ocpnStyle::StyleManager* g_StyleManager;
77
78extern MyFrame* gFrame;
79extern OCPNPlatform* g_Platform;
80extern wxString g_default_wp_icon;
81
82// Global print data, to remember settings during the session
83
84// Global page setup data
85
86extern float g_MarkScaleFactorExp;
87
88extern MarkInfoDlg* g_pMarkInfoDialog;
89
90#include <wx/arrimpl.cpp>
91WX_DEFINE_OBJARRAY(ArrayOfBitmaps);
92
93#define EXTENDED_PROP_PAGE 2 // Index of the extended properties page
94
95OCPNIconCombo::OCPNIconCombo(wxWindow* parent, wxWindowID id,
96 const wxString& value, const wxPoint& pos,
97 const wxSize& size, int n,
98 const wxString choices[], long style,
99 const wxValidator& validator, const wxString& name)
100 : wxOwnerDrawnComboBox(parent, id, value, pos, size, n, choices, style,
101 validator, name) {
102 double fontHeight =
103 GetFont().GetPointSize() / g_Platform->getFontPointsperPixel();
104 itemHeight = (int)wxRound(fontHeight);
105}
106
107OCPNIconCombo::~OCPNIconCombo() {}
108
109void OCPNIconCombo::OnDrawItem(wxDC& dc, const wxRect& rect, int item,
110 int flags) const {
111 int offset_x = bmpArray[item].GetWidth();
112 int bmpHeight = bmpArray[item].GetHeight();
113 dc.DrawBitmap(bmpArray[item], rect.x, rect.y + (rect.height - bmpHeight) / 2,
114 true);
115
116 if (flags & wxODCB_PAINTING_CONTROL) {
117 wxString text = GetValue();
118 int margin_x = 2;
119
120#if wxCHECK_VERSION(2, 9, 0)
121 if (ShouldUseHintText()) {
122 text = GetHint();
123 wxColour col = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
124 dc.SetTextForeground(col);
125 }
126
127 margin_x = GetMargins().x;
128#endif
129
130 dc.DrawText(text, rect.x + margin_x + offset_x,
131 (rect.height - dc.GetCharHeight()) / 2 + rect.y);
132 } else {
133 dc.DrawText(GetVListBoxComboPopup()->GetString(item), rect.x + 2 + offset_x,
134 (rect.height - dc.GetCharHeight()) / 2 + rect.y);
135 }
136}
137
138wxCoord OCPNIconCombo::OnMeasureItem(size_t item) const {
139 int bmpHeight = bmpArray[item].GetHeight();
140
141 return wxMax(itemHeight, bmpHeight);
142}
143
144wxCoord OCPNIconCombo::OnMeasureItemWidth(size_t item) const { return -1; }
145
146int OCPNIconCombo::Append(const wxString& item, wxBitmap bmp) {
147 bmpArray.Add(bmp);
148 int idx = wxOwnerDrawnComboBox::Append(item);
149
150 return idx;
151}
152
153void OCPNIconCombo::Clear(void) {
154 wxOwnerDrawnComboBox::Clear();
155 bmpArray.Clear();
156}
157
158//-------------------------------------------------------------------------------
159//
160// Mark Properties Dialog Implementation
161//
162//-------------------------------------------------------------------------------
167// DEFINE_EVENT_TYPE(EVT_LLCHANGE) // events from LatLonTextCtrl
168const wxEventType EVT_LLCHANGE = wxNewEventType();
169//------------------------------------------------------------------------------
170// LatLonTextCtrl Window Implementation
171//------------------------------------------------------------------------------
172BEGIN_EVENT_TABLE(LatLonTextCtrl, wxWindow)
173END_EVENT_TABLE()
174
175// constructor
176LatLonTextCtrl::LatLonTextCtrl(wxWindow* parent, wxWindowID id,
177 const wxString& value, const wxPoint& pos,
178 const wxSize& size, long style,
179 const wxValidator& validator,
180 const wxString& name)
181 : wxTextCtrl(parent, id, value, pos, size, style, validator, name) {
182 m_pParentEventHandler = parent->GetEventHandler();
183}
184
185void LatLonTextCtrl::OnKillFocus(wxFocusEvent& event) {
186 // Send an event to the Parent Dialog
187 wxCommandEvent up_event(EVT_LLCHANGE, GetId());
188 up_event.SetEventObject((wxObject*)this);
189 m_pParentEventHandler->AddPendingEvent(up_event);
190}
191
192//-------------------------------------------------------------------------------
193//
194// Mark Information Dialog Implementation
195//
196//-------------------------------------------------------------------------------
197BEGIN_EVENT_TABLE(MarkInfoDlg, DIALOG_PARENT)
198EVT_BUTTON(wxID_OK, MarkInfoDlg::OnMarkInfoOKClick)
199EVT_BUTTON(wxID_CANCEL, MarkInfoDlg::OnMarkInfoCancelClick)
200EVT_BUTTON(ID_BTN_DESC_BASIC, MarkInfoDlg::OnExtDescriptionClick)
201EVT_BUTTON(ID_DEFAULT, MarkInfoDlg::DefautlBtnClicked)
202EVT_BUTTON(ID_BTN_SHOW_TIDES, MarkInfoDlg::ShowTidesBtnClicked)
203EVT_COMBOBOX(ID_BITMAPCOMBOCTRL, MarkInfoDlg::OnBitmapCombClick)
204EVT_CHECKBOX(ID_CHECKBOX_SCAMIN_VIS, MarkInfoDlg::OnSelectScaMinExt)
205EVT_TEXT(ID_DESCR_CTR_DESC, MarkInfoDlg::OnDescChangedExt)
206EVT_TEXT(ID_DESCR_CTR_BASIC, MarkInfoDlg::OnDescChangedBasic)
207EVT_TEXT(ID_LATCTRL, MarkInfoDlg::OnPositionCtlUpdated)
208EVT_TEXT(ID_LONCTRL, MarkInfoDlg::OnPositionCtlUpdated)
209EVT_CHOICE(ID_WPT_RANGERINGS_NO, MarkInfoDlg::OnWptRangeRingsNoChange)
210// the HTML listbox's events
211EVT_HTML_LINK_CLICKED(wxID_ANY, MarkInfoDlg::OnHtmlLinkClicked)
212EVT_COMMAND(wxID_ANY, EVT_LAYOUT_RESIZE, MarkInfoDlg::OnLayoutResize)
213EVT_CLOSE(MarkInfoDlg::OnClose)
214
215// EVT_CHOICE( ID_WAYPOINTRANGERINGS, MarkInfoDef::OnWaypointRangeRingSelect )
216END_EVENT_TABLE()
217
218MarkInfoDlg::MarkInfoDlg(wxWindow* parent, wxWindowID id, const wxString& title,
219 const wxPoint& pos, const wxSize& size, long style) {
220 DIALOG_PARENT::Create(parent, id, title, pos, size, style);
221
222 wxFont* qFont = GetOCPNScaledFont(_("Dialog"));
223 SetFont(*qFont);
224 int metric = GetCharHeight();
225
226#ifdef __ANDROID__
227 // Set Dialog Font by custom crafted Qt Stylesheet.
228 wxString wqs = getFontQtStylesheet(qFont);
229 wxCharBuffer sbuf = wqs.ToUTF8();
230 QString qsb = QString(sbuf.data());
231 QString qsbq = getQtStyleSheet(); // basic scrollbars, etc
232 this->GetHandle()->setStyleSheet(qsb + qsbq); // Concatenated style sheets
233 wxScreenDC sdc;
234 if (sdc.IsOk()) sdc.GetTextExtent("W", NULL, &metric, NULL, NULL, qFont);
235#endif
236 Create();
237 m_pMyLinkList = NULL;
238 SetColorScheme((ColorScheme)0);
239 m_pRoutePoint = NULL;
240 m_SaveDefaultDlg = NULL;
241 CenterOnScreen();
242
243#ifdef __WXOSX__
244 Connect(wxEVT_ACTIVATE, wxActivateEventHandler(MarkInfoDlg::OnActivate), NULL,
245 this);
246#endif
247}
248
249void MarkInfoDlg::OnActivate(wxActivateEvent& event) {
250 auto pWin = dynamic_cast<DIALOG_PARENT*>(event.GetEventObject());
251 long int style = pWin->GetWindowStyle();
252 if (event.GetActive())
253 pWin->SetWindowStyle(style | wxSTAY_ON_TOP);
254 else
255 pWin->SetWindowStyle(style ^ wxSTAY_ON_TOP);
256}
257
258void MarkInfoDlg::initialize_images(void) {
259 wxString iconDir = g_Platform->GetSharedDataDir() + "uidata/MUI_flat/";
260 _img_MUI_settings_svg = LoadSVG(iconDir + "MUI_settings.svg",
261 2 * GetCharHeight(), 2 * GetCharHeight());
262
263 ocpnStyle::Style* style = g_StyleManager->GetCurrentStyle();
264 wxBitmap tide = style->GetIcon("tidesml");
265 wxImage tide1 = tide.ConvertToImage();
266 wxImage tide1s = tide1.Scale(m_sizeMetric * 3 / 2, m_sizeMetric * 3 / 2,
267 wxIMAGE_QUALITY_HIGH);
268 m_bmTide = wxBitmap(tide1s);
269
270 return;
271}
272
273void MarkInfoDlg::Create() {
274 wxFont* qFont = GetOCPNScaledFont(_("Dialog"));
275 SetFont(*qFont);
276 m_sizeMetric = GetCharHeight();
277
278#ifdef __ANDROID__
279 // Set Dialog Font by custom crafted Qt Stylesheet.
280
281 wxString wqs = getFontQtStylesheet(qFont);
282 wxCharBuffer sbuf = wqs.ToUTF8();
283 QString qsb = QString(sbuf.data());
284
285 QString qsbq = getAdjustedDialogStyleSheet(); // basic scrollbars, etc
286
287 this->GetHandle()->setStyleSheet(qsb + qsbq); // Concatenated style sheets
288
289 wxScreenDC sdc;
290 if (sdc.IsOk())
291 sdc.GetTextExtent("W", NULL, &m_sizeMetric, NULL, NULL, qFont);
292
293#endif
294
295 initialize_images();
296
297 wxBoxSizer* bSizer1;
298 bSizer1 = new wxBoxSizer(wxVERTICAL);
299 SetSizer(bSizer1);
300 bSizer1->SetSizeHints(this); // set size hints to honour minimum size
301
302 // Notebook with fixed width tabs
303 m_notebookProperties = new wxNotebook(this, wxID_ANY, wxDefaultPosition,
304 wxDefaultSize, wxNB_FIXEDWIDTH);
305
306 m_panelBasicProperties = new wxScrolledWindow(
307 m_notebookProperties, wxID_ANY, wxDefaultPosition, wxDefaultSize,
308 wxHSCROLL | wxVSCROLL | wxTAB_TRAVERSAL);
309#ifdef __ANDROID__
310 m_panelBasicProperties->GetHandle()->setStyleSheet(
311 getAdjustedDialogStyleSheet());
312#endif
313
314 // Basic panel
315 m_panelBasicProperties->SetScrollRate(0, 2);
316 m_notebookProperties->AddPage(m_panelBasicProperties, _("Basic"), true);
317 bSizerBasicProperties = new wxBoxSizer(wxVERTICAL);
318 m_panelBasicProperties->SetSizer(bSizerBasicProperties);
319
320 // Layer notification
321 m_staticTextLayer = new wxStaticText(
322 m_panelBasicProperties, wxID_ANY,
323 _("This waypoint is part of a layer and can't be edited"),
324 wxDefaultPosition, wxDefaultSize, 0);
325 m_staticTextLayer->Enable(false);
326 bSizerBasicProperties->Add(m_staticTextLayer, 0, wxALL, 5);
327
328 // Basic properties grid layout
329 wxPanel* props_panel = new wxPanel(m_panelBasicProperties);
330 FormGrid* props_sizer = new FormGrid(this);
331 props_panel->SetSizer(props_sizer);
332 bSizerBasicProperties->Add(props_panel, 0, wxALL | wxEXPAND, 16);
333 int label_size = m_sizeMetric * 4;
334
335 // Name property
336 m_textName = new TextField(props_panel, _("Name"));
337
338 // Show name checkbox
339 wxStaticText* name_cb_label =
340 new wxStaticText(props_panel, wxID_ANY, _("Show waypoint name"));
341 m_checkBoxShowName =
342 new wxCheckBox(props_panel, wxID_ANY, wxEmptyString, wxDefaultPosition,
343 wxDefaultSize, wxALIGN_CENTER_VERTICAL);
344 m_checkBoxShowName->Bind(wxEVT_CHECKBOX,
345 &MarkInfoDlg::OnShowWaypointNameSelectBasic, this);
346 props_sizer->Add(name_cb_label, 0, wxALIGN_TOP);
347 props_sizer->Add(m_checkBoxShowName, 0, wxEXPAND);
348
349 // Icon property (with icon scaling)
350 int icon_size = m_sizeMetric * 2;
351 icon_size = wxMax(icon_size, (32 * g_MarkScaleFactorExp) + 4);
352 m_bcomboBoxIcon =
353 new OCPNIconCombo(props_panel, wxID_ANY, _("Combo!"), wxDefaultPosition,
354 wxDefaultSize, 0, NULL, wxCB_READONLY);
355 m_bcomboBoxIcon->SetPopupMaxHeight(::wxGetDisplaySize().y / 2);
356 m_bcomboBoxIcon->SetMinSize(wxSize(-1, icon_size));
357
358 wxStaticText* icon_label = new wxStaticText(props_panel, wxID_ANY, _("Icon"));
359 icon_label->SetMinSize(wxSize(label_size, -1));
360 props_sizer->Add(icon_label, 0, wxALIGN_CENTER_VERTICAL);
361 props_sizer->Add(m_bcomboBoxIcon, 0, wxEXPAND);
362
363 // Lat/lon properties
364 m_textLatitude = new TextField(props_panel, _("Latitude"));
365 m_textLongitude = new TextField(props_panel, _("Longitude"));
366 props_sizer->Fit(props_panel);
367
368 // Description box
369 wxStaticBox* desc_box =
370 new wxStaticBox(m_panelBasicProperties, wxID_ANY, _("Description"));
371 wxStaticBoxSizer* desc_sizer = new wxStaticBoxSizer(desc_box, wxHORIZONTAL);
372 bSizerBasicProperties->Add(desc_sizer, 1, wxALL | wxEXPAND, 8);
373 m_textDescription = new wxTextCtrl(
374 m_panelBasicProperties, ID_DESCR_CTR_BASIC, wxEmptyString,
375 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
376 m_textDescription->SetMinSize(wxSize(-1, 80));
377 desc_sizer->Add(m_textDescription, 1, wxEXPAND);
378
379 // Description expand button
380 m_buttonExtDescription =
381 new wxButton(m_panelBasicProperties, ID_BTN_DESC_BASIC, "...",
382 wxDefaultPosition, wxSize(GetCharHeight() * 15 / 10, -1), 0);
383 desc_sizer->Add(m_buttonExtDescription, 0, wxEXPAND);
384
385 // Links box
386 wxStaticBox* links_box =
387 new wxStaticBox(m_panelBasicProperties, wxID_ANY, _("Links"));
388 wxStaticBoxSizer* links_sizer = new wxStaticBoxSizer(links_box, wxHORIZONTAL);
389 bSizerBasicProperties->Add(links_sizer, 1, wxALL | wxEXPAND, 8);
390
391#ifndef __ANDROID__ // wxSimpleHtmlListBox is broken on Android....
392 m_htmlList = new wxSimpleHtmlListBox(m_panelBasicProperties, wxID_ANY,
393 wxDefaultPosition, wxDefaultSize, 0);
394 links_sizer->Add(m_htmlList, 1, wxEXPAND);
395#else
396
397 m_scrolledWindowLinks =
398 new wxScrolledWindow(m_panelBasicProperties, wxID_ANY, wxDefaultPosition,
399 wxSize(-1, 100), wxHSCROLL | wxVSCROLL);
400 m_scrolledWindowLinks->SetMinSize(wxSize(-1, 80));
401 m_scrolledWindowLinks->SetScrollRate(2, 2);
402 links_sizer->Add(m_scrolledWindowLinks, 1, wxEXPAND);
403
404 bSizerLinks = new wxBoxSizer(wxVERTICAL);
405 m_scrolledWindowLinks->SetSizer(bSizerLinks);
406
407 m_menuLink = new wxMenu();
408 wxMenuItem* m_menuItemDelete;
409 m_menuItemDelete = new wxMenuItem(m_menuLink, wxID_ANY, wxString(_("Delete")),
410 wxEmptyString, wxITEM_NORMAL);
411 m_menuLink->Append(m_menuItemDelete);
412
413 wxMenuItem* m_menuItemEdit;
414 m_menuItemEdit = new wxMenuItem(m_menuLink, wxID_ANY, wxString(_("Edit")),
415 wxEmptyString, wxITEM_NORMAL);
416 m_menuLink->Append(m_menuItemEdit);
417
418 wxMenuItem* m_menuItemAdd;
419 m_menuItemAdd = new wxMenuItem(m_menuLink, wxID_ANY, wxString(_("Add new")),
420 wxEmptyString, wxITEM_NORMAL);
421 m_menuLink->Append(m_menuItemAdd);
422
423 wxBoxSizer* bSizer9 = new wxBoxSizer(wxHORIZONTAL);
424
425 m_buttonAddLink =
426 new wxButton(m_panelBasicProperties, wxID_ANY, _("Add new"),
427 wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
428 bSizer9->Add(m_buttonAddLink, 0, wxALL, 5);
429
430 m_buttonAddLink->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
431 wxCommandEventHandler(MarkInfoDlg::OnAddLink), NULL,
432 this);
433
434 links_sizer->Add(bSizer9, 0, wxEXPAND, 5);
435
436#endif
437
438 m_panelDescription =
439 new wxPanel(m_notebookProperties, wxID_ANY, wxDefaultPosition,
440 wxDefaultSize, wxTAB_TRAVERSAL);
441 wxBoxSizer* bSizer15;
442 bSizer15 = new wxBoxSizer(wxVERTICAL);
443
444 m_textCtrlExtDescription =
445 new wxTextCtrl(m_panelDescription, ID_DESCR_CTR_DESC, wxEmptyString,
446 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
447 bSizer15->Add(m_textCtrlExtDescription, 1, wxALL | wxEXPAND, 5);
448
449 m_panelDescription->SetSizer(bSizer15);
450 m_notebookProperties->AddPage(m_panelDescription, _("Description"), false);
451
454
455 m_panelExtendedProperties = new wxScrolledWindow(
456 m_notebookProperties, wxID_ANY, wxDefaultPosition, wxDefaultSize,
457 wxHSCROLL | wxVSCROLL | wxTAB_TRAVERSAL);
458#ifdef __ANDROID__
459 m_panelExtendedProperties->GetHandle()->setStyleSheet(
460 getAdjustedDialogStyleSheet());
461#endif
462
463 m_panelExtendedProperties->SetScrollRate(0, 2);
464
465 wxBoxSizer* fSizerExtProperties = new wxBoxSizer(wxVERTICAL);
466 m_panelExtendedProperties->SetSizer(fSizerExtProperties);
467 m_notebookProperties->AddPage(m_panelExtendedProperties, _("Extended"),
468 false);
469
470 sbSizerExtProperties = new wxStaticBoxSizer(
471 wxVERTICAL, m_panelExtendedProperties, _("Extended Properties"));
472 wxFlexGridSizer* gbSizerInnerExtProperties = new wxFlexGridSizer(3, 0, 0);
473 gbSizerInnerExtProperties->AddGrowableCol(2);
474 gbSizerInnerExtProperties->SetFlexibleDirection(wxBOTH);
475 gbSizerInnerExtProperties->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
476
477 m_checkBoxVisible = new wxCheckBox(sbSizerExtProperties->GetStaticBox(),
478 ID_CHECKBOX_VIS_EXT, wxEmptyString);
479 gbSizerInnerExtProperties->Add(m_checkBoxVisible);
480 wxStaticText* m_staticTextVisible = new wxStaticText(
481 sbSizerExtProperties->GetStaticBox(), wxID_ANY, _("Show on chart"));
482 gbSizerInnerExtProperties->Add(m_staticTextVisible);
483 gbSizerInnerExtProperties->Add(0, 0, 1, wxEXPAND, 0);
484
485 m_checkBoxScaMin = new wxCheckBox(sbSizerExtProperties->GetStaticBox(),
486 ID_CHECKBOX_SCAMIN_VIS, wxEmptyString);
487 gbSizerInnerExtProperties->Add(m_checkBoxScaMin, 0, wxALIGN_CENTRE_VERTICAL,
488 0);
489 m_staticTextScaMin = new wxStaticText(sbSizerExtProperties->GetStaticBox(),
490 wxID_ANY, _("Show at scale > 1 :"));
491 gbSizerInnerExtProperties->Add(m_staticTextScaMin, 0, wxALIGN_CENTRE_VERTICAL,
492 0);
493 m_textScaMin = new wxTextCtrl(sbSizerExtProperties->GetStaticBox(), wxID_ANY);
494 gbSizerInnerExtProperties->Add(m_textScaMin, 0, wxALL | wxEXPAND, 5);
495
496 m_checkBoxShowNameExt = new wxCheckBox(sbSizerExtProperties->GetStaticBox(),
497 wxID_ANY, wxEmptyString);
498 m_checkBoxShowNameExt->Bind(wxEVT_CHECKBOX,
499 &MarkInfoDlg::OnShowWaypointNameSelectExt, this);
500 gbSizerInnerExtProperties->Add(m_checkBoxShowNameExt);
501 m_staticTextShowNameExt = new wxStaticText(
502 sbSizerExtProperties->GetStaticBox(), wxID_ANY, _("Show waypoint name"));
503
504 gbSizerInnerExtProperties->Add(m_staticTextShowNameExt);
505 gbSizerInnerExtProperties->Add(0, 0, 1, wxEXPAND, 0);
506
507 sbRangeRingsExtProperties = new wxStaticBoxSizer(
508 wxVERTICAL, sbSizerExtProperties->GetStaticBox(), _("Range rings"));
509 wxFlexGridSizer* gbRRExtProperties = new wxFlexGridSizer(4, 0, 0);
510 gbRRExtProperties->AddGrowableCol(0);
511 gbRRExtProperties->AddGrowableCol(1);
512 gbRRExtProperties->AddGrowableCol(3);
513 m_staticTextRR1 = new wxStaticText(sbSizerExtProperties->GetStaticBox(),
514 wxID_ANY, _("Number"));
515 gbRRExtProperties->Add(m_staticTextRR1, 0, wxLEFT, 5);
516 m_staticTextRR2 = new wxStaticText(sbSizerExtProperties->GetStaticBox(),
517 wxID_ANY, _("Distance"));
518 gbRRExtProperties->Add(m_staticTextRR2, 0, wxLEFT, 5);
519 gbRRExtProperties->Add(0, 0, 1, wxEXPAND, 5); // a spacer
520 m_staticTextRR4 = new wxStaticText(sbSizerExtProperties->GetStaticBox(),
521 wxID_ANY, _("Color"));
522 gbRRExtProperties->Add(m_staticTextRR4, 0, wxLEFT, 5);
523
524 wxString rrAlt[] = {_("None"), _T( "1" ), _T( "2" ), _T( "3" ),
525 _T( "4" ), _T( "5" ), _T( "6" ), _T( "7" ),
526 _T( "8" ), _T( "9" ), _T( "10" )};
527 m_ChoiceWaypointRangeRingsNumber =
528 new wxChoice(sbSizerExtProperties->GetStaticBox(), ID_WPT_RANGERINGS_NO,
529 wxDefaultPosition, wxDefaultSize, 11, rrAlt);
530
531 gbRRExtProperties->Add(m_ChoiceWaypointRangeRingsNumber, 0, wxALL | wxEXPAND,
532 5);
533 m_textWaypointRangeRingsStep =
534 new wxTextCtrl(sbSizerExtProperties->GetStaticBox(), wxID_ANY, _("0.05"),
535 wxDefaultPosition, wxDefaultSize, 0);
536 gbRRExtProperties->Add(m_textWaypointRangeRingsStep, 0, wxALL | wxEXPAND, 5);
537
538 wxString pDistUnitsStrings[] = {_("NMi"), _("km")};
539 m_RangeRingUnits =
540 new wxChoice(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
541 wxDefaultPosition, wxDefaultSize, 2, pDistUnitsStrings);
542 gbRRExtProperties->Add(m_RangeRingUnits, 0, wxALIGN_CENTRE_VERTICAL, 0);
543
544 m_PickColor = new wxColourPickerCtrl(sbSizerExtProperties->GetStaticBox(),
545 wxID_ANY, wxColour(0, 0, 0),
546 wxDefaultPosition, wxDefaultSize, 0);
547 gbRRExtProperties->Add(m_PickColor, 0, wxALL | wxEXPAND, 5);
548 sbRangeRingsExtProperties->Add(
549 gbRRExtProperties, 1,
550 wxLEFT | wxTOP | wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP, 5);
551
552 sbSizerExtProperties->GetStaticBox()->Layout();
553
554 wxFlexGridSizer* gbSizerInnerExtProperties2 = new wxFlexGridSizer(2, 0, 0);
555 gbSizerInnerExtProperties2->AddGrowableCol(1);
556
557 m_staticTextGuid =
558 new wxStaticText(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
559 _("GUID"), wxDefaultPosition, wxDefaultSize, 0);
560 gbSizerInnerExtProperties2->Add(m_staticTextGuid, 0, wxALIGN_CENTRE_VERTICAL,
561 0);
562 m_textCtrlGuid = new wxTextCtrl(sbSizerExtProperties->GetStaticBox(),
563 wxID_ANY, wxEmptyString, wxDefaultPosition,
564 wxDefaultSize, wxTE_READONLY);
565 m_textCtrlGuid->SetEditable(false);
566 gbSizerInnerExtProperties2->Add(m_textCtrlGuid, 0, wxALL | wxEXPAND, 5);
567
568 wxFlexGridSizer* gbSizerInnerExtProperties1 = new wxFlexGridSizer(3, 0, 0);
569 gbSizerInnerExtProperties1->AddGrowableCol(1);
570
571 m_staticTextTideStation =
572 new wxStaticText(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
573 _("Tide Station"), wxDefaultPosition, wxDefaultSize, 0);
574 gbSizerInnerExtProperties1->Add(m_staticTextTideStation, 0,
575 wxALIGN_CENTRE_VERTICAL, 5);
576
577#ifdef __ANDROID__
578 m_choiceTideChoices.Add(" ");
579 m_comboBoxTideStation =
580 new wxChoice(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
581 wxDefaultPosition, wxDefaultSize, m_choiceTideChoices);
582
583 gbSizerInnerExtProperties1->Add(
584 m_comboBoxTideStation, 0, wxALL | wxEXPAND | wxALIGN_CENTRE_VERTICAL, 5);
585
586#else
587 m_comboBoxTideStation = new wxComboBox(
588 sbSizerExtProperties->GetStaticBox(), wxID_ANY, wxEmptyString,
589 wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY);
590 gbSizerInnerExtProperties1->Add(
591 m_comboBoxTideStation, 0, wxALL | wxEXPAND | wxALIGN_CENTRE_VERTICAL, 5);
592#endif
593 m_comboBoxTideStation->SetToolTip(
594 _("Associate this waypoint with a tide station to quickly access tide "
595 "predictions. Select from nearby stations or leave empty for no "
596 "association."));
597
598 m_buttonShowTides = new wxBitmapButton(
599 sbSizerExtProperties->GetStaticBox(), ID_BTN_SHOW_TIDES, m_bmTide,
600 wxDefaultPosition, m_bmTide.GetSize(), 0);
601 gbSizerInnerExtProperties1->Add(m_buttonShowTides, 0,
602 wxALL | wxALIGN_CENTRE_VERTICAL, 5);
603
604 m_staticTextArrivalRadius = new wxStaticText(
605 sbSizerExtProperties->GetStaticBox(), wxID_ANY, _("Arrival Radius"));
606 gbSizerInnerExtProperties1->Add(m_staticTextArrivalRadius, 0,
607 wxALIGN_CENTRE_VERTICAL, 0);
608 m_textArrivalRadius =
609 new wxTextCtrl(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
610 wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
611 m_textArrivalRadius->SetToolTip(
612 _("Distance from the waypoint at which OpenCPN will consider the "
613 "waypoint reached. Used for automatic waypoint advancement during "
614 "active navigation."));
615 gbSizerInnerExtProperties1->Add(m_textArrivalRadius, 0, wxALL | wxEXPAND, 5);
616 m_staticTextArrivalUnits =
617 new wxStaticText(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
618 wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
619 gbSizerInnerExtProperties1->Add(m_staticTextArrivalUnits, 0,
620 wxALIGN_CENTRE_VERTICAL, 0);
621
622 m_staticTextPlSpeed =
623 new wxStaticText(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
624 _("Planned Speed"), wxDefaultPosition, wxDefaultSize, 0);
625 gbSizerInnerExtProperties1->Add(m_staticTextPlSpeed, 0,
626 wxALIGN_CENTRE_VERTICAL, 0);
628 new wxTextCtrl(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
629 wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
630 m_textCtrlPlSpeed->SetToolTip(_(
631 "Enter the planned vessel speed for the leg FOLLOWING this waypoint. "
632 "This speed is used when traveling FROM this waypoint TO the next "
633 "waypoint in the route. The value is used to calculate estimated time "
634 "of arrival at the next waypoint based on the ETD from this waypoint.\n\n"
635 "If left blank, the route's default speed will be used for this leg. "
636 "Individual waypoint speeds override the route-level speed setting."));
637 gbSizerInnerExtProperties1->Add(m_textCtrlPlSpeed, 0, wxALL | wxEXPAND, 5);
638 m_staticTextPlSpeedUnits =
639 new wxStaticText(sbSizerExtProperties->GetStaticBox(), wxID_ANY,
640 getUsrSpeedUnit(), wxDefaultPosition, wxDefaultSize, 0);
641 gbSizerInnerExtProperties1->Add(m_staticTextPlSpeedUnits, 0,
642 wxALIGN_CENTRE_VERTICAL, 0);
643
644 // The value of m_staticTextEtd is updated in UpdateProperties() based on
645 // the date/time format specified in the "Options" dialog.
646 m_staticTextEtd = new wxStaticText(sbSizerExtProperties->GetStaticBox(),
647 wxID_ANY, _("ETD"));
648 gbSizerInnerExtProperties1->Add(m_staticTextEtd, 0, wxALIGN_CENTRE_VERTICAL,
649 0);
650 wxBoxSizer* bsTimestamp = new wxBoxSizer(wxHORIZONTAL);
651 m_cbEtdPresent = new wxCheckBox(sbSizerExtProperties->GetStaticBox(),
652 wxID_ANY, wxEmptyString);
653 m_cbEtdPresent->SetToolTip(
654 _("Enable to manually set a planned departure time (ETD) for this "
655 "waypoint.\n"
656 "When checked, the specified date and time will be used instead of the "
657 "automatically calculated ETD. This affects ETA calculations for "
658 "subsequent waypoints in the route."));
659 bsTimestamp->Add(m_cbEtdPresent, 0, wxALL | wxEXPAND, 5);
660 m_EtdDatePickerCtrl = new wxDatePickerCtrl(
661 sbSizerExtProperties->GetStaticBox(), ID_ETA_DATEPICKERCTRL,
662 wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DEFAULT,
663 wxDefaultValidator);
664 m_EtdDatePickerCtrl->SetToolTip(_(
665 "Select the planned departure date (ETD) for this waypoint.\nUsed "
666 "together with the time control to calculate arrival times at subsequent "
667 "waypoints.\nETD information is only used for route planning "
668 "and does not affect navigation."));
669 bsTimestamp->Add(m_EtdDatePickerCtrl, 0, wxALL | wxEXPAND, 5);
670
671#ifdef __WXGTK__
673 new TimeCtrl(sbSizerExtProperties->GetStaticBox(), ID_ETA_TIMEPICKERCTRL,
674 wxDefaultDateTime, wxDefaultPosition, wxDefaultSize);
675#else
676 m_EtdTimePickerCtrl = new wxTimePickerCtrl(
677 sbSizerExtProperties->GetStaticBox(), ID_ETA_TIMEPICKERCTRL,
678 wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DEFAULT,
679 wxDefaultValidator);
680#endif
681
682 bsTimestamp->Add(m_EtdTimePickerCtrl, 0, wxALL | wxEXPAND, 5);
683 gbSizerInnerExtProperties1->Add(bsTimestamp, 0, wxEXPAND, 0);
684 sbSizerExtProperties->Add(gbSizerInnerExtProperties, 0, wxALL | wxEXPAND, 5);
685 sbSizerExtProperties->Add(sbRangeRingsExtProperties, 0, wxALL | wxEXPAND, 5);
686 sbSizerExtProperties->Add(gbSizerInnerExtProperties2, 0, wxALL | wxEXPAND, 5);
687 sbSizerExtProperties->Add(gbSizerInnerExtProperties1, 0, wxALL | wxEXPAND, 5);
688
689 fSizerExtProperties->Add(sbSizerExtProperties, 1, wxALL | wxEXPAND);
690
691 //-----------------
692 bSizer1->Add(m_notebookProperties, 1, wxEXPAND);
693
694 wxBoxSizer* btnSizer = new wxBoxSizer(wxHORIZONTAL);
695 bSizer1->Add(btnSizer, 0, wxEXPAND, 0);
696
697 DefaultsBtn =
698 new wxBitmapButton(this, ID_DEFAULT, _img_MUI_settings_svg,
699 wxDefaultPosition, _img_MUI_settings_svg.GetSize(), 0);
700 btnSizer->Add(DefaultsBtn, 0, wxALL | wxALIGN_LEFT | wxALIGN_BOTTOM, 5);
701 btnSizer->Add(0, 0, 1, wxEXPAND); // spacer
702
703 m_sdbSizerButtons = new wxStdDialogButtonSizer();
704 m_buttonOkay = new wxButton(this, wxID_OK);
705 m_sdbSizerButtons->AddButton(m_buttonOkay);
706 m_sdbSizerButtons->AddButton(new wxButton(this, wxID_CANCEL, _("Cancel")));
707 m_sdbSizerButtons->Realize();
708 btnSizer->Add(m_sdbSizerButtons, 0, wxALL, 5);
709
710 // SetMinSize(wxSize(-1, 600));
711
712 // Connect Events
713 m_textLatitude->Connect(
714 wxEVT_CONTEXT_MENU,
715 wxCommandEventHandler(MarkInfoDlg::OnRightClickLatLon), NULL, this);
716 m_textLongitude->Connect(
717 wxEVT_CONTEXT_MENU,
718 wxCommandEventHandler(MarkInfoDlg::OnRightClickLatLon), NULL, this);
719#ifndef __ANDROID__ // wxSimpleHtmlListBox is broken on Android....
720 m_htmlList->Connect(wxEVT_RIGHT_DOWN,
721 wxMouseEventHandler(MarkInfoDlg::m_htmlListContextMenu),
722 NULL, this);
723#else
724#endif
725 m_notebookProperties->Connect(
726 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
727 wxNotebookEventHandler(MarkInfoDlg::OnNotebookPageChanged), NULL, this);
728 // m_EtdTimePickerCtrl->Connect( wxEVT_TIME_CHANGED, wxDateEventHandler(
729 // MarkInfoDlg::OnTimeChanged ), NULL, this ); m_EtdDatePickerCtrl->Connect(
730 // wxEVT_DATE_CHANGED, wxDateEventHandler( MarkInfoDlg::OnTimeChanged ), NULL,
731 // this );
732 m_comboBoxTideStation->Connect(
733 wxEVT_COMMAND_COMBOBOX_SELECTED,
734 wxCommandEventHandler(MarkInfoDlg::OnTideStationCombobox), NULL, this);
735}
736
737void MarkInfoDlg::OnClose(wxCloseEvent& event) {
738 Hide();
739 event.Veto();
740 if (m_pRoutePoint) m_pRoutePoint->m_bRPIsBeingEdited = false;
741}
742
743#define TIDESTATION_BATCH_SIZE 10
744
745void MarkInfoDlg::OnTideStationCombobox(wxCommandEvent& event) {
746 int count = m_comboBoxTideStation->GetCount();
747 int sel = m_comboBoxTideStation->GetSelection();
748 if (sel == count - 1) {
749 wxString n;
750 int i = 0;
751 for (auto ts : m_tss) {
752 if (i == count + TIDESTATION_BATCH_SIZE) {
753 break;
754 }
755 if (i > count) {
756 n = wxString::FromUTF8(ts.second->IDX_station_name);
757 m_comboBoxTideStation->Append(n);
758 }
759 i++;
760 }
761 }
762}
763
764void MarkInfoDlg::OnNotebookPageChanged(wxNotebookEvent& event) {
765 if (event.GetSelection() == EXTENDED_PROP_PAGE) {
766 if (m_lasttspos.IsSameAs(m_textLatitude->GetValue() +
767 m_textLongitude->GetValue())) {
768 return;
769 }
770 m_lasttspos = m_textLatitude->GetValue() + m_textLongitude->GetValue();
771 double lat = fromDMM(m_textLatitude->GetValue());
772 double lon = fromDMM(m_textLongitude->GetValue());
773 m_tss = ptcmgr->GetStationsForLL(lat, lon);
774 wxString s = m_comboBoxTideStation->GetStringSelection();
775 wxString n;
776 int i = 0;
777 m_comboBoxTideStation->Clear();
778 m_comboBoxTideStation->Append(wxEmptyString);
779 for (auto ts : m_tss) {
780 if (i == TIDESTATION_BATCH_SIZE) {
781 break;
782 }
783 i++;
784 n = wxString::FromUTF8(ts.second->IDX_station_name);
785 m_comboBoxTideStation->Append(n);
786 if (s == n) {
787 m_comboBoxTideStation->SetSelection(i);
788 }
789 }
790 if (m_comboBoxTideStation->GetStringSelection() != s) {
791 m_comboBoxTideStation->Insert(s, 1);
792 m_comboBoxTideStation->SetSelection(1);
793 }
794 }
795}
796
797void MarkInfoDlg::RecalculateSize(void) {
798#ifdef __ANDROID__
799
800 Layout();
801
802 wxSize dsize = GetParent()->GetClientSize();
803
804 wxSize esize;
805
806 esize.x = GetCharHeight() * 20;
807 esize.y = GetCharHeight() * 40;
808 // qDebug() << "esizeA" << esize.x << esize.y;
809
810 esize.y = wxMin(esize.y, dsize.y - (2 * GetCharHeight()));
811 esize.x = wxMin(esize.x, dsize.x - (1 * GetCharHeight()));
812 SetSize(wxSize(esize.x, esize.y));
813 // qDebug() << "esize" << esize.x << esize.y;
814
815 wxSize fsize = GetSize();
816 fsize.y = wxMin(fsize.y, dsize.y - (2 * GetCharHeight()));
817 fsize.x = wxMin(fsize.x, dsize.x - (1 * GetCharHeight()));
818 // qDebug() << "fsize" << fsize.x << fsize.y;
819
820 // And finally, not too tall...
821 fsize.y = wxMin(fsize.y, (25 * GetCharHeight()));
822
823 SetSize(wxSize(-1, fsize.y));
824
825 m_defaultClientSize = GetClientSize();
826 Center();
827#else
828 wxSize dsize = GetParent()->GetClientSize();
829 SetSize(-1, wxMax(GetSize().y, dsize.y / 1.5));
830#endif
831}
832
833MarkInfoDlg::~MarkInfoDlg() {
834 // Disconnect Events
835 m_textLatitude->Disconnect(
836 wxEVT_CONTEXT_MENU,
837 wxCommandEventHandler(MarkInfoDlg::OnRightClickLatLon), NULL, this);
838 m_textLongitude->Disconnect(
839 wxEVT_CONTEXT_MENU,
840 wxCommandEventHandler(MarkInfoDlg::OnRightClickLatLon), NULL, this);
841#ifndef __ANDROID__ // wxSimpleHtmlListBox is broken on Android....
842 m_htmlList->Disconnect(
843 wxEVT_RIGHT_DOWN, wxMouseEventHandler(MarkInfoDlg::m_htmlListContextMenu),
844 NULL, this);
845#else
846#endif
847
848 m_notebookProperties->Disconnect(
849 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
850 wxNotebookEventHandler(MarkInfoDlg::OnNotebookPageChanged), NULL, this);
851 m_EtdTimePickerCtrl->Disconnect(
852 wxEVT_TIME_CHANGED, wxDateEventHandler(MarkInfoDlg::OnTimeChanged), NULL,
853 this);
854 m_EtdDatePickerCtrl->Disconnect(
855 wxEVT_DATE_CHANGED, wxDateEventHandler(MarkInfoDlg::OnTimeChanged), NULL,
856 this);
857
858#ifdef __ANDROID__
859 androidEnableBackButton(true);
860#endif
861}
862
863void MarkInfoDlg::InitialFocus(void) {
864 m_textName->SetFocus();
865 m_textName->SetInsertionPointEnd();
866}
867
868void MarkInfoDlg::SetColorScheme(ColorScheme cs) { DimeControl(this); }
869
870void MarkInfoDlg::ClearData() {
871 m_pRoutePoint = NULL;
872 UpdateProperties();
873}
874
875void MarkInfoDlg::SetRoutePoint(RoutePoint* pRP) {
876 m_pRoutePoint = pRP;
877 if (m_pRoutePoint) {
878 m_lat_save = m_pRoutePoint->m_lat;
879 m_lon_save = m_pRoutePoint->m_lon;
880 m_IconName_save = m_pRoutePoint->GetIconName();
881 m_bShowName_save = m_pRoutePoint->m_bShowName;
882 m_bIsVisible_save = m_pRoutePoint->m_bIsVisible;
883 m_Name_save = m_pRoutePoint->GetName();
884 m_Description_save = m_pRoutePoint->m_MarkDescription;
885 m_bUseScaMin_save = m_pRoutePoint->GetUseSca();
886 m_iScaminVal_save = m_pRoutePoint->GetScaMin();
887
888 if (m_pMyLinkList) delete m_pMyLinkList;
889 m_pMyLinkList = new HyperlinkList();
890 for (Hyperlink* link : *m_pRoutePoint->m_HyperlinkList) {
891 Hyperlink* h = new Hyperlink();
892 h->DescrText = link->DescrText;
893 h->Link = link->Link;
894 h->LType = link->LType;
895
896 m_pMyLinkList->push_back(h);
897 }
898 }
899}
900
901void MarkInfoDlg::UpdateHtmlList() {
902#ifndef __ANDROID__ // wxSimpleHtmlListBox is broken on Android....
903 GetSimpleBox()->Clear();
904 int NbrOfLinks = m_pRoutePoint->m_HyperlinkList->size();
905
906 if (NbrOfLinks > 0) {
907 auto& list = m_pRoutePoint->m_HyperlinkList;
908 for (auto it = list->begin(); it != list->end(); ++it) {
909 Hyperlink* link = *it;
910 wxString s =
911 wxString::Format("<a href='%s'>%s</a>", link->Link, link->DescrText);
912 GetSimpleBox()->AppendString(s);
913 }
914 }
915#else
916 // Clear the list
917 wxWindowList kids = m_scrolledWindowLinks->GetChildren();
918 for (unsigned int i = 0; i < kids.GetCount(); i++) {
919 wxWindowListNode* node = kids.Item(i);
920 wxWindow* win = node->GetData();
921
922 auto link_win = dynamic_cast<wxHyperlinkCtrl*>(win);
923 if (link_win) {
924 link_win->Disconnect(
925 wxEVT_COMMAND_HYPERLINK,
926 wxHyperlinkEventHandler(MarkInfoDlg::OnHyperLinkClick));
927 link_win->Disconnect(
928 wxEVT_RIGHT_DOWN,
929 wxMouseEventHandler(MarkInfoDlg::m_htmlListContextMenu));
930 win->Destroy();
931 }
932 }
933
934 for (Hyperlink* link : *m_pRoutePoint->m_HyperlinkList) {
935 wxString Link = link->Link;
936 wxString Descr = link->DescrText;
937
938 wxHyperlinkCtrl* ctrl = new wxHyperlinkCtrl(
939 m_scrolledWindowLinks, wxID_ANY, Descr, Link, wxDefaultPosition,
940 wxDefaultSize, wxNO_BORDER | wxHL_CONTEXTMENU | wxHL_ALIGN_LEFT);
941 ctrl->Connect(wxEVT_COMMAND_HYPERLINK,
942 wxHyperlinkEventHandler(MarkInfoDlg::OnHyperLinkClick), NULL,
943 this);
944 if (!m_pRoutePoint->m_bIsInLayer)
945 ctrl->Connect(wxEVT_RIGHT_DOWN,
946 wxMouseEventHandler(MarkInfoDlg::m_htmlListContextMenu),
947 NULL, this);
948
949 bSizerLinks->Add(ctrl, 1, wxALL | wxEXPAND, 5);
950 }
951
952 // Integrate all of the rebuilt hyperlink controls
953 m_scrolledWindowLinks->Layout();
954#endif
955}
956
957void MarkInfoDlg::OnHyperLinkClick(wxHyperlinkEvent& event) {
958 wxString url = event.GetURL();
959 url.Replace(" ", "%20");
960 if (g_Platform) g_Platform->platformLaunchDefaultBrowser(url);
961}
962
963void MarkInfoDlg::OnHtmlLinkClicked(wxHtmlLinkEvent& event) {
964 // Windows has trouble handling local file URLs with embedded anchor
965 // points, e.g file://testfile.html#point1 The trouble is with the
966 // wxLaunchDefaultBrowser with verb "open" Workaround is to probe the
967 // registry to get the default browser, and open directly
968 //
969 // But, we will do this only if the URL contains the anchor point
970 // character '#' What a hack......
971
972#ifdef __WXMSW__
973 wxString cc = event.GetLinkInfo().GetHref().c_str();
974 if (cc.Find("#") != wxNOT_FOUND) {
975 wxRegKey RegKey(wxString("HKEY_CLASSES_ROOT\\HTTP\\shell\\open\\command"));
976 if (RegKey.Exists()) {
977 wxString command_line;
978 RegKey.QueryValue(wxString(""), command_line);
979
980 // Remove "
981 command_line.Replace(wxString("\""), wxString(""));
982
983 // Strip arguments
984 int l = command_line.Find(".exe");
985 if (wxNOT_FOUND == l) l = command_line.Find(".EXE");
986
987 if (wxNOT_FOUND != l) {
988 wxString cl = command_line.Mid(0, l + 4);
989 cl += " ";
990 cc.Prepend("\"");
991 cc.Append("\"");
992 cl += cc;
993 wxExecute(cl); // Async, so Fire and Forget...
994 }
995 }
996 } else {
997 wxString url = event.GetLinkInfo().GetHref().c_str();
998 url.Replace(" ", "%20");
999 ::wxLaunchDefaultBrowser(url);
1000 event.Skip();
1001 }
1002#else
1003 wxString url = event.GetLinkInfo().GetHref().c_str();
1004 url.Replace(" ", "%20");
1005 if (g_Platform) g_Platform->platformLaunchDefaultBrowser(url);
1006
1007 event.Skip();
1008#endif
1009}
1010
1011void MarkInfoDlg::OnLayoutResize(wxCommandEvent& event) {
1012 m_panelBasicProperties->Layout();
1013 this->Layout();
1014}
1015
1016void MarkInfoDlg::OnDescChangedExt(wxCommandEvent& event) {
1017 if (m_panelDescription->IsShownOnScreen()) {
1018 m_textDescription->ChangeValue(m_textCtrlExtDescription->GetValue());
1019 }
1020 event.Skip();
1021}
1022void MarkInfoDlg::OnDescChangedBasic(wxCommandEvent& event) {
1023 if (m_panelBasicProperties->IsShownOnScreen()) {
1024 m_textCtrlExtDescription->ChangeValue(m_textDescription->GetValue());
1025 }
1026 event.Skip();
1027}
1028
1029void MarkInfoDlg::OnExtDescriptionClick(wxCommandEvent& event) {
1030 long pos = m_textDescription->GetInsertionPoint();
1031 m_notebookProperties->SetSelection(1);
1032 m_textCtrlExtDescription->SetInsertionPoint(pos);
1033 event.Skip();
1034}
1035
1036void MarkInfoDlg::OnShowWaypointNameSelectBasic(wxCommandEvent& event) {
1037 m_checkBoxShowNameExt->SetValue(m_checkBoxShowName->GetValue());
1038 event.Skip();
1039}
1040void MarkInfoDlg::OnShowWaypointNameSelectExt(wxCommandEvent& event) {
1041 m_checkBoxShowName->SetValue(m_checkBoxShowNameExt->GetValue());
1042 event.Skip();
1043}
1044
1045void MarkInfoDlg::OnWptRangeRingsNoChange(wxCommandEvent& event) {
1046 if (!m_pRoutePoint->m_bIsInLayer) {
1047 m_textWaypointRangeRingsStep->Enable(
1048 (bool)(m_ChoiceWaypointRangeRingsNumber->GetSelection() != 0));
1049 m_PickColor->Enable(
1050 (bool)(m_ChoiceWaypointRangeRingsNumber->GetSelection() != 0));
1051 }
1052}
1053
1054void MarkInfoDlg::OnSelectScaMinExt(wxCommandEvent& event) {
1055 if (!m_pRoutePoint->m_bIsInLayer) {
1056 m_textScaMin->Enable(m_checkBoxScaMin->GetValue());
1057 }
1058}
1059
1060void MarkInfoDlg::OnPositionCtlUpdated(wxCommandEvent& event) {
1061 // Fetch the control values, convert to degrees
1062 double lat = fromDMM(m_textLatitude->GetValue());
1063 double lon = fromDMM(m_textLongitude->GetValue());
1064 if (!m_pRoutePoint->m_bIsInLayer) {
1065 m_pRoutePoint->SetPosition(lat, lon);
1066 pSelect->ModifySelectablePoint(lat, lon, (void*)m_pRoutePoint,
1067 SELTYPE_ROUTEPOINT);
1068 }
1069 // Update the mark position dynamically
1070 gFrame->RefreshAllCanvas();
1071}
1072
1073void MarkInfoDlg::m_htmlListContextMenu(wxMouseEvent& event) {
1074#ifndef __ANDROID__
1075 // SimpleHtmlList->HitTest doesn't seem to work under msWin, so we use a
1076 // custom made version
1077 wxPoint pos = event.GetPosition();
1078 i_htmlList_item = -1;
1079 for (int i = 0; i < (int)GetSimpleBox()->GetCount(); i++) {
1080 wxRect rect = GetSimpleBox()->GetItemRect(i);
1081 if (rect.Contains(pos)) {
1082 i_htmlList_item = i;
1083 break;
1084 }
1085 }
1086
1087 wxMenu* popup = new wxMenu();
1088 if ((GetSimpleBox()->GetCount()) > 0 && (i_htmlList_item > -1) &&
1089 (i_htmlList_item < (int)GetSimpleBox()->GetCount())) {
1090 popup->Append(ID_RCLK_MENU_DELETE_LINK, _("Delete"));
1091 popup->Append(ID_RCLK_MENU_EDIT_LINK, _("Edit"));
1092 }
1093 popup->Append(ID_RCLK_MENU_ADD_LINK, _("Add New"));
1094
1095 m_contextObject = event.GetEventObject();
1096 popup->Connect(
1097 wxEVT_COMMAND_MENU_SELECTED,
1098 wxCommandEventHandler(MarkInfoDlg::On_html_link_popupmenu_Click), NULL,
1099 this);
1100 PopupMenu(popup);
1101 delete popup;
1102#else
1103
1104 m_pEditedLink = dynamic_cast<wxHyperlinkCtrl*>(event.GetEventObject());
1105
1106 if (m_pEditedLink) {
1107 wxString url = m_pEditedLink->GetURL();
1108 wxString label = m_pEditedLink->GetLabel();
1109 i_htmlList_item = -1;
1110 HyperlinkList* hyperlinklist = m_pRoutePoint->m_HyperlinkList;
1111 int i = 0;
1112 for (Hyperlink* link : *hyperlinklist) {
1113 if (link->DescrText == label) {
1114 i_htmlList_item = i;
1115 break;
1116 }
1117 i++;
1118 }
1119
1120 wxFont sFont = GetOCPNGUIScaledFont(_("Menu"));
1121
1122 wxMenu* popup = new wxMenu();
1123 {
1124 wxMenuItem* menuItemDelete =
1125 new wxMenuItem(popup, ID_RCLK_MENU_DELETE_LINK, wxString(_("Delete")),
1126 wxEmptyString, wxITEM_NORMAL);
1127#ifdef __WXQT__
1128 menuItemDelete->SetFont(sFont);
1129#endif
1130 popup->Append(menuItemDelete);
1131
1132 wxMenuItem* menuItemEdit =
1133 new wxMenuItem(popup, ID_RCLK_MENU_EDIT_LINK, wxString(_("Edit")),
1134 wxEmptyString, wxITEM_NORMAL);
1135#ifdef __WXQT__
1136 menuItemEdit->SetFont(sFont);
1137#endif
1138 popup->Append(menuItemEdit);
1139 }
1140
1141 wxMenuItem* menuItemAdd =
1142 new wxMenuItem(popup, ID_RCLK_MENU_ADD_LINK, wxString(_("Add New")),
1143 wxEmptyString, wxITEM_NORMAL);
1144#ifdef __WXQT__
1145 menuItemAdd->SetFont(sFont);
1146#endif
1147 popup->Append(menuItemAdd);
1148
1149 m_contextObject = event.GetEventObject();
1150 popup->Connect(
1151 wxEVT_COMMAND_MENU_SELECTED,
1152 wxCommandEventHandler(MarkInfoDlg::On_html_link_popupmenu_Click), NULL,
1153 this);
1154 wxPoint p = m_scrolledWindowLinks->GetPosition();
1155 p.x += m_scrolledWindowLinks->GetSize().x / 2;
1156 PopupMenu(popup, p);
1157 delete popup;
1158
1159 // m_scrolledWindowLinks->PopupMenu( m_menuLink,
1160 // m_pEditedLink->GetPosition().x /*+ event.GetPosition().x*/,
1161 // m_pEditedLink->GetPosition().y /*+ event.GetPosition().y*/ );
1162 }
1163/*
1164 wxPoint pos = event.GetPosition();
1165 i_htmlList_item = -1;
1166 for( int i=0; i < (int)GetSimpleBox()->GetCount(); i++ )
1167 {
1168 wxRect rect = GetSimpleBox()->GetItemRect( i );
1169 if( rect.Contains( pos) ){
1170 i_htmlList_item = i;
1171 break;
1172 }
1173 }
1174
1175 */
1176#endif
1177}
1178
1179void MarkInfoDlg::OnAddLink(wxCommandEvent& event) {
1180 wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED);
1181 evt.SetId(ID_RCLK_MENU_ADD_LINK);
1182
1183 On_html_link_popupmenu_Click(evt);
1184}
1185
1186void MarkInfoDlg::On_html_link_popupmenu_Click(wxCommandEvent& event) {
1187 switch (event.GetId()) {
1188 case ID_RCLK_MENU_DELETE_LINK: {
1189 auto it = m_pRoutePoint->m_HyperlinkList->begin() + i_htmlList_item;
1190 m_pRoutePoint->m_HyperlinkList->erase(it);
1191 UpdateHtmlList();
1192 break;
1193 }
1194 case ID_RCLK_MENU_EDIT_LINK: {
1195 auto it = m_pRoutePoint->m_HyperlinkList->begin() + i_htmlList_item;
1196 Hyperlink* link = *it;
1197 LinkPropImpl* LinkPropDlg = new LinkPropImpl(this);
1198 LinkPropDlg->m_textCtrlLinkDescription->SetValue(link->DescrText);
1199 LinkPropDlg->m_textCtrlLinkUrl->SetValue(link->Link);
1200 DimeControl(LinkPropDlg);
1201 LinkPropDlg->ShowWindowModalThenDo([this, LinkPropDlg,
1202 link](int retcode) {
1203 if (retcode == wxID_OK) {
1204 link->DescrText = LinkPropDlg->m_textCtrlLinkDescription->GetValue();
1205 auto it = m_pRoutePoint->m_HyperlinkList->begin() + i_htmlList_item;
1206 link->Link = LinkPropDlg->m_textCtrlLinkUrl->GetValue();
1207 *it = link;
1208 UpdateHtmlList();
1209 }
1210 });
1211 break;
1212 }
1213 case ID_RCLK_MENU_ADD_LINK: {
1214 LinkPropImpl* LinkPropDlg = new LinkPropImpl(this);
1215 LinkPropDlg->m_textCtrlLinkDescription->SetValue(wxEmptyString);
1216 LinkPropDlg->m_textCtrlLinkUrl->SetValue(wxEmptyString);
1217 DimeControl(LinkPropDlg);
1218 LinkPropDlg->ShowWindowModalThenDo([this, LinkPropDlg](int retcode) {
1219 if (retcode == wxID_OK) {
1220 Hyperlink* link = new Hyperlink;
1221 link->DescrText = LinkPropDlg->m_textCtrlLinkDescription->GetValue();
1222 link->Link = LinkPropDlg->m_textCtrlLinkUrl->GetValue();
1223 // Check if decent
1224 if (link->DescrText == wxEmptyString) {
1225 link->DescrText = link->Link;
1226 }
1227 if (link->Link == wxEmptyString) {
1228 delete link;
1229 } else {
1230 m_pRoutePoint->m_HyperlinkList->push_back(link);
1231 }
1232 UpdateHtmlList();
1233 }
1234 });
1235 break;
1236 }
1237 }
1238 event.Skip();
1239}
1240
1241void MarkInfoDlg::OnRightClickLatLon(wxCommandEvent& event) {
1242 wxMenu* popup = new wxMenu();
1243 popup->Append(ID_RCLK_MENU_COPY, _("Copy"));
1244 popup->Append(ID_RCLK_MENU_COPY_LL, _("Copy lat/long"));
1245 popup->Append(ID_RCLK_MENU_PASTE, _("Paste"));
1246 popup->Append(ID_RCLK_MENU_PASTE_LL, _("Paste lat/long"));
1247 m_contextObject = event.GetEventObject();
1248 popup->Connect(wxEVT_COMMAND_MENU_SELECTED,
1249 wxCommandEventHandler(MarkInfoDlg::OnCopyPasteLatLon), NULL,
1250 this);
1251
1252 PopupMenu(popup);
1253 delete popup;
1254}
1255
1256void MarkInfoDlg::OnCopyPasteLatLon(wxCommandEvent& event) {
1257 // Fetch the control values, convert to degrees
1258 double lat = fromDMM(m_textLatitude->GetValue());
1259 double lon = fromDMM(m_textLongitude->GetValue());
1260
1261 wxString result;
1262
1263 switch (event.GetId()) {
1264 case ID_RCLK_MENU_PASTE: {
1265 if (wxTheClipboard->Open()) {
1266 wxTextDataObject data;
1267 wxTheClipboard->GetData(data);
1268 result = data.GetText();
1269 ((wxTextCtrl*)m_contextObject)->SetValue(result);
1270 wxTheClipboard->Close();
1271 }
1272 return;
1273 }
1274 case ID_RCLK_MENU_PASTE_LL: {
1275 if (wxTheClipboard->Open()) {
1276 wxTextDataObject data;
1277 wxTheClipboard->GetData(data);
1278 result = data.GetText();
1279
1280 PositionParser pparse(result);
1281
1282 if (pparse.IsOk()) {
1283 m_textLatitude->SetValue(pparse.GetLatitudeString());
1284 m_textLongitude->SetValue(pparse.GetLongitudeString());
1285 }
1286 wxTheClipboard->Close();
1287 }
1288 return;
1289 }
1290 case ID_RCLK_MENU_COPY: {
1291 result = ((wxTextCtrl*)m_contextObject)->GetValue();
1292 break;
1293 }
1294 case ID_RCLK_MENU_COPY_LL: {
1295 result << toSDMM(1, lat, true) << _T('\t');
1296 result << toSDMM(2, lon, true);
1297 break;
1298 }
1299 }
1300
1301 if (wxTheClipboard->Open()) {
1302 wxTextDataObject* data = new wxTextDataObject;
1303 data->SetText(result);
1304 wxTheClipboard->SetData(data);
1305 wxTheClipboard->Close();
1306 }
1307}
1308
1309void MarkInfoDlg::DefautlBtnClicked(wxCommandEvent& event) {
1310 m_SaveDefaultDlg = new SaveDefaultsDialog(this);
1311 m_SaveDefaultDlg->Center();
1312 DimeControl(m_SaveDefaultDlg);
1313 int retcode = m_SaveDefaultDlg->ShowModal();
1314
1315 {
1316 if (retcode == wxID_OK) {
1317 double value;
1318 if (m_SaveDefaultDlg->IconCB->GetValue()) {
1319 g_default_wp_icon =
1320 *pWayPointMan->GetIconKey(m_bcomboBoxIcon->GetSelection());
1321 }
1322 if (m_SaveDefaultDlg->RangRingsCB->GetValue()) {
1323 g_iWaypointRangeRingsNumber =
1324 m_ChoiceWaypointRangeRingsNumber->GetSelection();
1325 if (m_textWaypointRangeRingsStep->GetValue().ToDouble(&value))
1326 g_fWaypointRangeRingsStep = fromUsrDistance(value, -1);
1327 g_colourWaypointRangeRingsColour = m_PickColor->GetColour();
1328 }
1329 if (m_SaveDefaultDlg->ArrivalRCB->GetValue())
1330 if (m_textArrivalRadius->GetValue().ToDouble(&value))
1331 g_n_arrival_circle_radius = fromUsrDistance(value, -1);
1332 if (m_SaveDefaultDlg->ScaleCB->GetValue()) {
1333 g_iWpt_ScaMin = wxAtoi(m_textScaMin->GetValue());
1334 g_bUseWptScaMin = m_checkBoxScaMin->GetValue();
1335 }
1336 if (m_SaveDefaultDlg->NameCB->GetValue()) {
1337 g_bShowWptName = m_checkBoxShowName->GetValue();
1338 }
1339 }
1340 m_SaveDefaultDlg = NULL;
1341 }
1342}
1343
1344void MarkInfoDlg::OnMarkInfoCancelClick(wxCommandEvent& event) {
1345 if (m_pRoutePoint) {
1346 m_pRoutePoint->SetVisible(m_bIsVisible_save);
1347 m_pRoutePoint->SetNameShown(m_bShowName_save);
1348 m_pRoutePoint->SetPosition(m_lat_save, m_lon_save);
1349 m_pRoutePoint->SetIconName(m_IconName_save);
1350 m_pRoutePoint->ReLoadIcon();
1351 m_pRoutePoint->SetName(m_Name_save);
1352 m_pRoutePoint->m_MarkDescription = m_Description_save;
1353 m_pRoutePoint->SetUseSca(m_bUseScaMin_save);
1354 m_pRoutePoint->SetScaMin(m_iScaminVal_save);
1355
1356 m_pRoutePoint->m_HyperlinkList->clear();
1357
1358 int NbrOfLinks = m_pMyLinkList->size();
1359 if (NbrOfLinks > 0) {
1360 for (Hyperlink* link : *m_pMyLinkList) {
1361 Hyperlink* h = new Hyperlink();
1362 h->DescrText = link->DescrText;
1363 h->Link = link->Link;
1364 h->LType = link->LType;
1365
1366 m_pRoutePoint->m_HyperlinkList->push_back(h);
1367 }
1368 }
1369 }
1370
1371 m_lasttspos.Clear();
1372
1373#ifdef __WXGTK__
1374 gFrame->Raise();
1375#endif
1376
1377 Show(false);
1378 delete m_pMyLinkList;
1379 m_pMyLinkList = NULL;
1380 SetClientSize(m_defaultClientSize);
1381
1382#ifdef __ANDROID__
1383 androidEnableBackButton(true);
1384#endif
1385
1386 event.Skip();
1387}
1388
1389void MarkInfoDlg::OnMarkInfoOKClick(wxCommandEvent& event) {
1390 if (m_pRoutePoint) {
1391 m_pRoutePoint->m_wxcWaypointRangeRingsColour = m_PickColor->GetColour();
1392
1393 OnPositionCtlUpdated(event);
1394 SaveChanges(); // write changes to globals and update config
1395 }
1396
1397#ifdef __WXGTK__
1398 gFrame->Raise();
1399#endif
1400
1401 Show(false);
1402
1403 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
1404 pRouteManagerDialog->UpdateWptListCtrl();
1405
1406 if (pRoutePropDialog && pRoutePropDialog->IsShown())
1407 pRoutePropDialog->UpdatePoints();
1408
1409 SetClientSize(m_defaultClientSize);
1410
1411#ifdef __ANDROID__
1412 androidEnableBackButton(true);
1413#endif
1414
1415 event.Skip();
1416}
1417
1418bool MarkInfoDlg::UpdateProperties(bool positionOnly) {
1419 if (m_pRoutePoint) {
1420 m_textLatitude->SetValue(::toSDMM(1, m_pRoutePoint->m_lat));
1421 m_textLongitude->SetValue(::toSDMM(2, m_pRoutePoint->m_lon));
1422 m_lat_save = m_pRoutePoint->m_lat;
1423 m_lon_save = m_pRoutePoint->m_lon;
1424 m_textName->SetValue(m_pRoutePoint->GetName());
1425 m_textDescription->ChangeValue(m_pRoutePoint->m_MarkDescription);
1426 m_textCtrlExtDescription->ChangeValue(m_pRoutePoint->m_MarkDescription);
1427 m_checkBoxShowName->SetValue(m_pRoutePoint->m_bShowName);
1428 m_checkBoxShowNameExt->SetValue(m_pRoutePoint->m_bShowName);
1429 m_checkBoxVisible->SetValue(m_pRoutePoint->m_bIsVisible);
1430 m_checkBoxScaMin->SetValue(m_pRoutePoint->GetUseSca());
1431 m_textScaMin->SetValue(
1432 wxString::Format("%i", (int)m_pRoutePoint->GetScaMin()));
1433 m_textCtrlGuid->SetValue(m_pRoutePoint->m_GUID);
1434 m_ChoiceWaypointRangeRingsNumber->SetSelection(
1435 m_pRoutePoint->GetWaypointRangeRingsNumber());
1436 wxString buf;
1437 buf.Printf("%.3f",
1438 toUsrDistance(m_pRoutePoint->GetWaypointRangeRingsStep(), -1));
1439 m_textWaypointRangeRingsStep->SetValue(buf);
1440 m_staticTextArrivalUnits->SetLabel(getUsrDistanceUnit());
1441 buf.Printf("%.3f",
1442 toUsrDistance(m_pRoutePoint->GetWaypointArrivalRadius(), -1));
1443 m_textArrivalRadius->SetValue(buf);
1444
1445 int nUnits = m_pRoutePoint->GetWaypointRangeRingsStepUnits();
1446 m_RangeRingUnits->SetSelection(nUnits);
1447
1448 wxColour col = m_pRoutePoint->m_wxcWaypointRangeRingsColour;
1449 m_PickColor->SetColour(col);
1450
1451 if (m_pRoutePoint->m_bIsInRoute) {
1452 if (m_name_validator) m_name_validator.reset();
1453 m_name_validator =
1454 std::make_unique<RoutePointNameValidator>(m_pRoutePoint);
1455 m_textName->SetValidator(*m_name_validator);
1456 m_textName->Bind(wxEVT_TEXT, &TextField::OnTextChanged, m_textName);
1457 m_textName->Bind(wxEVT_KILL_FOCUS, &MarkInfoDlg::OnFocusEvent, this);
1458 } else {
1459 m_textName->SetValidator();
1460 m_textName->Unbind(wxEVT_TEXT, &TextField::OnTextChanged, m_textName);
1461 m_textName->Unbind(wxEVT_KILL_FOCUS, &MarkInfoDlg::OnFocusEvent, this);
1462 }
1463
1464 if (m_comboBoxTideStation->GetStringSelection() !=
1465 m_pRoutePoint->m_TideStation) {
1466 m_comboBoxTideStation->Clear();
1467 m_comboBoxTideStation->Append(wxEmptyString);
1468 if (!m_pRoutePoint->m_TideStation.IsEmpty()) {
1469 m_comboBoxTideStation->Append(m_pRoutePoint->m_TideStation);
1470 m_comboBoxTideStation->SetSelection(1);
1471 }
1472 }
1473
1474 m_staticTextPlSpeedUnits->SetLabel(getUsrSpeedUnit());
1475 if (m_pRoutePoint->GetPlannedSpeed() > .01) {
1476 m_textCtrlPlSpeed->SetValue(wxString::Format(
1477 "%.1f", toUsrSpeed(m_pRoutePoint->GetPlannedSpeed())));
1478 } else {
1479 m_textCtrlPlSpeed->SetValue(wxEmptyString);
1480 }
1481
1482 bool isLastWaypoint = false;
1483 if (m_pRoutePoint && m_pRoutePoint->m_bIsInRoute) {
1484 // Get routes containing this waypoint
1485 wxArrayPtrVoid* pRouteArray =
1486 g_pRouteMan->GetRouteArrayContaining(m_pRoutePoint);
1487 if (pRouteArray) {
1488 isLastWaypoint = true;
1489 // Check if this waypoint is the last across all routes.
1490 for (unsigned int i = 0; i < pRouteArray->GetCount(); i++) {
1491 Route* route = (Route*)pRouteArray->Item(i);
1492 if (route->GetLastPoint()->m_GUID != m_pRoutePoint->m_GUID) {
1493 isLastWaypoint = false;
1494 break;
1495 }
1496 }
1497 delete pRouteArray;
1498 }
1499 }
1500 wxDateTime etd;
1501 etd = m_pRoutePoint->GetManualETD();
1502 if (isLastWaypoint) {
1503 // If this is the last waypoint in a route, uncheck the checkbox and set
1504 // the date/time to empty, as the ETD is meaningless.
1505 etd = wxDateTime();
1506 }
1507 if (etd.IsValid()) {
1508 m_cbEtdPresent->SetValue(true);
1509 wxString dtFormat = ocpn::getUsrDateTimeFormat();
1510 if (dtFormat == "Local Time") {
1511 // The ETD is in UTC and needs to be converted to local time for display
1512 // purpose.
1513 etd.MakeFromUTC();
1514 } else if (dtFormat == "UTC") {
1515 // The date/time is already in UTC.
1516 } else {
1517 // This code path is not expected to be reached, unless
1518 // the global date/time format is enhanced in the future
1519 // to include new format options.
1520 wxLogError(
1521 "MarkInfoDlg::UpdateProperties. Unexpected date/time format: %s",
1522 dtFormat);
1523 etd = wxInvalidDateTime;
1524 }
1525 m_EtdDatePickerCtrl->SetValue(etd.GetDateOnly());
1526 m_EtdTimePickerCtrl->SetValue(etd);
1527 } else {
1528 m_cbEtdPresent->SetValue(false);
1529 }
1530 // Inherit the date/time format from the user settings.
1531 m_staticTextEtd->SetLabel(
1532 wxString::Format("%s (%s)", _("ETD"), ocpn::getUsrDateTimeFormat()));
1533
1534 m_staticTextPlSpeed->Show(m_pRoutePoint->m_bIsInRoute);
1535 m_textCtrlPlSpeed->Show(m_pRoutePoint->m_bIsInRoute);
1536 m_staticTextEtd->Show(m_pRoutePoint->m_bIsInRoute);
1537 m_EtdDatePickerCtrl->Show(m_pRoutePoint->m_bIsInRoute);
1538 m_EtdTimePickerCtrl->Show(m_pRoutePoint->m_bIsInRoute);
1539 m_cbEtdPresent->Show(m_pRoutePoint->m_bIsInRoute);
1540 m_staticTextPlSpeedUnits->Show(m_pRoutePoint->m_bIsInRoute);
1541 m_staticTextArrivalRadius->Show(m_pRoutePoint->m_bIsInRoute);
1542 m_staticTextArrivalUnits->Show(m_pRoutePoint->m_bIsInRoute);
1543 m_textArrivalRadius->Show(m_pRoutePoint->m_bIsInRoute);
1544
1545 if (positionOnly) return true;
1546
1547 // Layer or not?
1548 if (m_pRoutePoint->m_bIsInLayer) {
1549 m_staticTextLayer->Enable();
1550 m_staticTextLayer->Show(true);
1551 m_textName->SetEditable(false);
1552 m_textDescription->SetEditable(false);
1553 m_textCtrlExtDescription->SetEditable(false);
1554 m_textLatitude->SetEditable(false);
1555 m_textLongitude->SetEditable(false);
1556 m_bcomboBoxIcon->Enable(false);
1557 m_checkBoxShowName->Enable(false);
1558 m_checkBoxVisible->Enable(false);
1559 m_textArrivalRadius->SetEditable(false);
1560 m_checkBoxScaMin->Enable(false);
1561 m_textScaMin->SetEditable(false);
1562 m_checkBoxShowNameExt->Enable(false);
1563 m_ChoiceWaypointRangeRingsNumber->Enable(false);
1564 m_textWaypointRangeRingsStep->SetEditable(false);
1565 m_PickColor->Enable(false);
1566 DefaultsBtn->Enable(false);
1567 m_EtdDatePickerCtrl->Enable(false);
1568 m_EtdTimePickerCtrl->Enable(false);
1569 m_cbEtdPresent->Enable(false);
1570 m_notebookProperties->SetSelection(0); // Show Basic page
1571 m_comboBoxTideStation->Enable(false);
1572 } else {
1573 m_staticTextLayer->Enable(false);
1574 m_staticTextLayer->Show(false);
1575 m_textName->SetEditable(true);
1576 m_textDescription->SetEditable(true);
1577 m_textCtrlExtDescription->SetEditable(true);
1578 m_textLatitude->SetEditable(true);
1579 m_textLongitude->SetEditable(true);
1580 m_bcomboBoxIcon->Enable(true);
1581 m_checkBoxShowName->Enable(true);
1582 m_checkBoxVisible->Enable(true);
1583 m_textArrivalRadius->SetEditable(true);
1584 m_checkBoxScaMin->Enable(true);
1585 m_textScaMin->SetEditable(true);
1586 m_checkBoxShowNameExt->Enable(true);
1587 m_ChoiceWaypointRangeRingsNumber->Enable(true);
1588 m_textWaypointRangeRingsStep->SetEditable(true);
1589 m_PickColor->Enable(true);
1590 DefaultsBtn->Enable(true);
1591 m_notebookProperties->SetSelection(0);
1592 m_comboBoxTideStation->Enable(true);
1593
1594 // If this is the last waypoint in a route, disable the ETD as it does not
1595 // make sense to have an ETD for the last waypoint in a route.
1596 m_EtdDatePickerCtrl->Enable(!isLastWaypoint);
1597 m_EtdTimePickerCtrl->Enable(!isLastWaypoint);
1598 m_cbEtdPresent->Enable(!isLastWaypoint);
1599 }
1600
1601 // Fill the icon selector combo box
1602 m_bcomboBoxIcon->Clear();
1603 // Iterate on the Icon Descriptions, filling in the combo control
1604 bool fillCombo = m_bcomboBoxIcon->GetCount() == 0;
1605
1606 if (fillCombo) {
1607 for (int i = 0; i < pWayPointMan->GetNumIcons(); i++) {
1608 wxString* ps = pWayPointMan->GetIconDescription(i);
1609 wxBitmap bmp =
1610 pWayPointMan->GetIconBitmapForList(i, 2 * GetCharHeight());
1611
1612 m_bcomboBoxIcon->Append(*ps, bmp);
1613 }
1614 }
1615 // find the correct item in the combo box
1616 int iconToSelect = -1;
1617 for (int i = 0; i < pWayPointMan->GetNumIcons(); i++) {
1618 if (*pWayPointMan->GetIconKey(i) == m_pRoutePoint->GetIconName()) {
1619 iconToSelect = i;
1620 m_bcomboBoxIcon->Select(iconToSelect);
1621 break;
1622 }
1623 }
1624 wxCommandEvent ev;
1625 OnShowWaypointNameSelectBasic(ev);
1626 OnWptRangeRingsNoChange(ev);
1627 OnSelectScaMinExt(ev);
1628 UpdateHtmlList();
1629 }
1630
1631#ifdef __ANDROID__
1632 androidEnableBackButton(false);
1633#endif
1634
1635 Fit();
1636 // SetMinSize(wxSize(-1, 600));
1637 RecalculateSize();
1638
1639 return true;
1640}
1641
1642// Focus event handler to validate the dialog.
1643void MarkInfoDlg::OnFocusEvent(wxFocusEvent& event) {
1644 bool is_valid = Validate();
1645 m_buttonOkay->Enable(is_valid);
1646 event.Skip();
1647}
1648
1649void MarkInfoDlg::OnBitmapCombClick(wxCommandEvent& event) {
1650 wxString* icon_name =
1651 pWayPointMan->GetIconKey(m_bcomboBoxIcon->GetSelection());
1652 if (icon_name && icon_name->Length()) m_pRoutePoint->SetIconName(*icon_name);
1653 m_pRoutePoint->ReLoadIcon();
1654 SaveChanges();
1655 // pConfig->UpdateWayPoint( m_pRoutePoint );
1656}
1657
1658void MarkInfoDlg::ValidateMark(void) {
1659 // Look in the master list of Waypoints to see if the currently selected
1660 // waypoint is still valid It may have been deleted as part of a route
1661 wxRoutePointListNode* node = pWayPointMan->GetWaypointList()->GetFirst();
1662
1663 bool b_found = false;
1664 while (node) {
1665 RoutePoint* rp = node->GetData();
1666 if (m_pRoutePoint == rp) {
1667 b_found = true;
1668 break;
1669 }
1670 node = node->GetNext();
1671 }
1672 if (!b_found) m_pRoutePoint = NULL;
1673}
1674
1675bool MarkInfoDlg::SaveChanges() {
1676 if (m_pRoutePoint) {
1677 if (m_pRoutePoint->m_bIsInLayer) return true;
1678 if (!this->Validate()) return false; // prevent invalid save
1679
1680 // Get User input Text Fields
1681 m_pRoutePoint->SetName(m_textName->GetValue());
1682 m_pRoutePoint->SetWaypointArrivalRadius(m_textArrivalRadius->GetValue());
1683 m_pRoutePoint->SetScaMin(m_textScaMin->GetValue());
1684 m_pRoutePoint->SetUseSca(m_checkBoxScaMin->GetValue());
1685 m_pRoutePoint->m_MarkDescription = m_textDescription->GetValue();
1686 m_pRoutePoint->SetVisible(m_checkBoxVisible->GetValue());
1687 m_pRoutePoint->m_bShowName = m_checkBoxShowName->GetValue();
1688 m_pRoutePoint->SetPosition(fromDMM(m_textLatitude->GetValue()),
1689 fromDMM(m_textLongitude->GetValue()));
1690 wxString* icon_name =
1691 pWayPointMan->GetIconKey(m_bcomboBoxIcon->GetSelection());
1692 if (icon_name && icon_name->Length())
1693 m_pRoutePoint->SetIconName(*icon_name);
1694 m_pRoutePoint->ReLoadIcon();
1695 m_pRoutePoint->SetShowWaypointRangeRings(
1696 (bool)(m_ChoiceWaypointRangeRingsNumber->GetSelection() != 0));
1697 m_pRoutePoint->SetWaypointRangeRingsNumber(
1698 m_ChoiceWaypointRangeRingsNumber->GetSelection());
1699 double value;
1700 if (m_textWaypointRangeRingsStep->GetValue().ToDouble(&value))
1701 m_pRoutePoint->SetWaypointRangeRingsStep(fromUsrDistance(value, -1));
1702 if (m_textArrivalRadius->GetValue().ToDouble(&value))
1703 m_pRoutePoint->SetWaypointArrivalRadius(fromUsrDistance(value, -1));
1704
1705 if (m_RangeRingUnits->GetSelection() != wxNOT_FOUND)
1706 m_pRoutePoint->SetWaypointRangeRingsStepUnits(
1707 m_RangeRingUnits->GetSelection());
1708
1709 m_pRoutePoint->m_TideStation = m_comboBoxTideStation->GetStringSelection();
1710 if (m_textCtrlPlSpeed->GetValue() == wxEmptyString) {
1711 m_pRoutePoint->SetPlannedSpeed(0.0);
1712 } else {
1713 double spd;
1714 if (m_textCtrlPlSpeed->GetValue().ToDouble(&spd)) {
1715 m_pRoutePoint->SetPlannedSpeed(fromUsrSpeed(spd));
1716 }
1717 }
1718
1719 if (m_cbEtdPresent->GetValue()) {
1720 wxDateTime dt = m_EtdDatePickerCtrl->GetValue();
1721 wxDateTime t = m_EtdTimePickerCtrl->GetValue();
1722 int hour = t.GetHour();
1723 dt.SetHour(hour);
1724 dt.SetMinute(m_EtdTimePickerCtrl->GetValue().GetMinute());
1725 dt.SetSecond(m_EtdTimePickerCtrl->GetValue().GetSecond());
1726 if (dt.IsValid()) {
1727 // The date/time in the UI is specified according to the global settings
1728 // in Options -> Date/Time format. The date/time format is either "Local
1729 // Time" or "UTC". If the date/time format is "Local Time", convert to
1730 // UTC. Otherwise, it is already in UTC.
1731 wxString dtFormat = ocpn::getUsrDateTimeFormat();
1732 if (dtFormat == "Local Time") {
1733 m_pRoutePoint->SetETD(dt.MakeUTC());
1734 } else if (dtFormat == "UTC") {
1735 m_pRoutePoint->SetETD(dt);
1736 } else {
1737 // This code path should never be reached, as the date/time format is
1738 // either "Local Time" or "UTC".
1739 // In the future, other date/time formats may be supported in
1740 // global settings (Options -> Display -> Date/Time Format).
1741 // When/if this happens, this code will need to be updated to
1742 // handle the new formats.
1743 wxLogError(
1744 "Failed to configured ETD. Unsupported date/time format: %s",
1745 dtFormat);
1746 m_pRoutePoint->SetETD(wxInvalidDateTime);
1747 }
1748 }
1749 } else {
1750 m_pRoutePoint->SetETD(wxInvalidDateTime);
1751 }
1752
1753 if (m_pRoutePoint->m_bIsInRoute) {
1754 // Update the route segment selectables
1755 pSelect->UpdateSelectableRouteSegments(m_pRoutePoint);
1756
1757 // Get an array of all routes using this point
1758 wxArrayPtrVoid* pEditRouteArray =
1759 g_pRouteMan->GetRouteArrayContaining(m_pRoutePoint);
1760
1761 if (pEditRouteArray) {
1762 for (unsigned int ir = 0; ir < pEditRouteArray->GetCount(); ir++) {
1763 Route* pr = (Route*)pEditRouteArray->Item(ir);
1764 pr->FinalizeForRendering();
1765 pr->UpdateSegmentDistances();
1766
1767 // pConfig->UpdateRoute(pr);
1768 NavObj_dB::GetInstance().UpdateRoute(pr);
1769 }
1770 delete pEditRouteArray;
1771 }
1772 } else {
1773 // pConfig->UpdateWayPoint(m_pRoutePoint);
1774 NavObj_dB::GetInstance().UpdateRoutePoint(m_pRoutePoint);
1775 }
1776 }
1777 return true;
1778}
1779
1780SaveDefaultsDialog::SaveDefaultsDialog(MarkInfoDlg* parent)
1781 : wxDialog(parent, wxID_ANY, _("Save some defaults")) {
1782 //(*Initialize(SaveDefaultsDialog)
1783 this->SetSizeHints(wxDefaultSize, wxDefaultSize);
1784
1785 wxBoxSizer* bSizer1 = new wxBoxSizer(wxVERTICAL);
1786 wxStdDialogButtonSizer* StdDialogButtonSizer1;
1787
1788 StaticText1 =
1789 new wxStaticText(this, wxID_ANY,
1790 _("Check which properties of current waypoint\n should "
1791 "be set as default for NEW waypoints."));
1792 bSizer1->Add(StaticText1, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 5);
1793
1794 wxFlexGridSizer* fgSizer1 = new wxFlexGridSizer(2);
1795
1796 wxString s =
1797 (g_pMarkInfoDialog->m_checkBoxShowName->GetValue() ? _("Do use")
1798 : _("Don't use"));
1799 NameCB =
1800 new wxCheckBox(this, wxID_ANY, _("Show Waypoint Name"), wxDefaultPosition,
1801 wxDefaultSize, 0, wxDefaultValidator);
1802 fgSizer1->Add(NameCB, 0, wxALL, 5);
1803 stName = new wxStaticText(this, wxID_ANY, "[" + s + "]", wxDefaultPosition,
1804 wxDefaultSize, 0);
1805 stName->Wrap(-1);
1806 fgSizer1->Add(stName, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
1807
1808 s = g_pMarkInfoDialog->m_pRoutePoint->GetIconName();
1809 IconCB = new wxCheckBox(this, wxID_ANY, _("Icon"));
1810 fgSizer1->Add(IconCB, 0, wxALL, 5);
1811 stIcon = new wxStaticText(this, wxID_ANY, "[" + s + "]", wxDefaultPosition,
1812 wxDefaultSize, 0);
1813 stIcon->Wrap(-1);
1814 fgSizer1->Add(stIcon, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
1815
1816 s = (g_pMarkInfoDialog->m_ChoiceWaypointRangeRingsNumber->GetSelection()
1817 ? _("Do use") +
1818 wxString::Format(
1819 " (%i) ",
1820 g_pMarkInfoDialog->m_ChoiceWaypointRangeRingsNumber
1821 ->GetSelection())
1822 : _("Don't use"));
1823 RangRingsCB = new wxCheckBox(this, wxID_ANY, _("Range rings"));
1824 fgSizer1->Add(RangRingsCB, 0, wxALL, 5);
1825 stRR = new wxStaticText(this, wxID_ANY, "[" + s + "]", wxDefaultPosition,
1826 wxDefaultSize, 0);
1827 stRR->Wrap(-1);
1828 fgSizer1->Add(stRR, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
1829
1830 s = (g_pMarkInfoDialog->m_textArrivalRadius->GetValue());
1831 ArrivalRCB = new wxCheckBox(this, wxID_ANY, _("Arrival radius"));
1832 fgSizer1->Add(ArrivalRCB, 0, wxALL, 5);
1833 stArrivalR = new wxStaticText(
1834 this, wxID_ANY,
1835 wxString::Format("[%s %s]", s.c_str(), getUsrDistanceUnit().c_str()),
1836 wxDefaultPosition, wxDefaultSize, 0);
1837 stArrivalR->Wrap(-1);
1838 fgSizer1->Add(stArrivalR, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL,
1839 5);
1840
1841 s = (g_pMarkInfoDialog->m_checkBoxScaMin->GetValue()
1842 ? _("Show only if") + " < " +
1843 g_pMarkInfoDialog->m_textScaMin->GetValue()
1844 : _("Show always"));
1845 ScaleCB = new wxCheckBox(this, wxID_ANY, _("Show only at scale"));
1846 fgSizer1->Add(ScaleCB, 0, wxALL, 5);
1847 stScale = new wxStaticText(this, wxID_ANY, "[" + s + "]", wxDefaultPosition,
1848 wxDefaultSize, 0);
1849 stScale->Wrap(-1);
1850 fgSizer1->Add(stScale, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
1851
1852 bSizer1->Add(fgSizer1, 0, wxALL | wxEXPAND, 5);
1853
1854 StdDialogButtonSizer1 = new wxStdDialogButtonSizer();
1855 StdDialogButtonSizer1->AddButton(new wxButton(this, wxID_OK));
1856 StdDialogButtonSizer1->AddButton(
1857 new wxButton(this, wxID_CANCEL, _("Cancel")));
1858 StdDialogButtonSizer1->Realize();
1859 bSizer1->Add(StdDialogButtonSizer1, 0, wxALL | wxEXPAND, 5);
1860
1861 SetSizer(bSizer1);
1862 Fit();
1863 Layout();
1864
1865#ifdef __ANDROID__
1866 SetSize(parent->GetSize());
1867#endif
1868
1869 Center();
1870}
1871
1872void MarkInfoDlg::ShowTidesBtnClicked(wxCommandEvent& event) {
1873 if (m_comboBoxTideStation->GetSelection() < 1) {
1874 return;
1875 }
1876 IDX_entry* pIDX = (IDX_entry*)ptcmgr->GetIDX_entry(
1877 ptcmgr->GetStationIDXbyName(m_comboBoxTideStation->GetStringSelection(),
1878 fromDMM(m_textLatitude->GetValue()),
1879 fromDMM(m_textLongitude->GetValue())));
1880 if (pIDX) {
1881 TCWin* pCwin = new TCWin(gFrame->GetPrimaryCanvas(), 0, 0, pIDX);
1882 pCwin->Show();
1883 } else {
1884 wxString msg(_("Tide Station not found"));
1885 msg += ":\n";
1886 msg += m_comboBoxTideStation->GetStringSelection();
1887 OCPNMessageBox(NULL, msg, _("OpenCPN Info"), wxOK | wxCENTER, 10);
1888 }
1889}
Generic Chart canvas base.
Grid layout with 2 columns for form labels and fields.
Definition form_grid.h:28
Represents an index entry for tidal and current data.
Definition idx_entry.h:48
Class LinkPropImpl.
Definition LinkPropDlg.h:89
Dialog for displaying and editing waypoint properties.
Definition MarkInfo.h:215
wxDatePickerCtrl * m_EtdDatePickerCtrl
Date picker control for setting the Estimated Time of Departure (ETD).
Definition MarkInfo.h:384
wxStaticText * m_staticTextEtd
Label for the Estimated Time of Departure field.
Definition MarkInfo.h:339
wxCheckBox * m_cbEtdPresent
Checkbox control that enables/disables manual ETD setting for a waypoint.
Definition MarkInfo.h:297
wxTextCtrl * m_textCtrlPlSpeed
Text control for waypoint planned speed.
Definition MarkInfo.h:372
wxTimePickerCtrl * m_EtdTimePickerCtrl
Time picker control for setting the Estimated Time of Departure (ETD).
Definition MarkInfo.h:395
Main application frame.
Definition ocpn_frame.h:138
Custom combobox for selecting waypoint icons.
Definition MarkInfo.h:162
Provides platform-specific support utilities for OpenCPN.
Represents a waypoint or mark within the navigation system.
Definition route_point.h:70
HyperlinkList * m_HyperlinkList
List of hyperlinks associated with this waypoint.
wxColour m_wxcWaypointRangeRingsColour
Color for the range rings display.
wxString m_MarkDescription
Description text for the waypoint.
bool m_bRPIsBeingEdited
Flag indicating if this waypoint is currently being edited.
wxString m_GUID
Globally Unique Identifier for the waypoint.
wxDateTime GetManualETD()
Retrieves the manually set Estimated Time of Departure for this waypoint, in UTC.
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.
double GetPlannedSpeed()
Return the planned speed associated with this waypoint.
bool m_bIsVisible
Flag indicating if the waypoint should be drawn on the chart.
bool m_bIsInLayer
Flag indicating if the waypoint belongs to a layer.
wxString m_TideStation
Associated tide station identifier.
void SetETD(const wxDateTime &etd)
Sets the Estimated Time of Departure for this waypoint, in UTC.
Represents a navigational route in the navigation system.
Definition route.h:98
wxArrayPtrVoid * GetRouteArrayContaining(RoutePoint *pWP)
Find all routes that contain the given waypoint.
Definition routeman.cpp:178
Dialog for saving default waypoint properties.
Definition MarkInfo.h:468
Definition tcmgr.h:91
Definition TCWin.h:45
Text field with validator and error handler.
Definition field_text.h:38
void OnTextChanged(wxCommandEvent &event)
Text changed event handler.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
Definition gui_lib.cpp:59
wxFont GetOCPNGUIScaledFont(wxString item)
Retrieves a font optimized for touch and high-resolution interfaces.
Definition gui_lib.cpp:88
General purpose GUI support.
wxString getUsrDateTimeFormat()
Return the date/time format to use when formatting date/time strings.
Definition datetime.cpp:37
Class NavObj_dB.
PlugInManager and helper classes – Mostly gui parts (dialogs) and plugin API stuff.
SVG utilities.
GUI library utils and events.