24#include <wx/clipbrd.h>
26#include "RoutePropDlgImpl.h"
32#include "routemanagerdialog.h"
33#include "routeprintout.h"
35#include "navutil_base.h"
37#include "ocpn_plugin.h"
40#define ID_RCLK_MENU_COPY_TEXT 7013
41#define ID_RCLK_MENU_EDIT_WP 7014
42#define ID_RCLK_MENU_DELETE 7015
43#define ID_RCLK_MENU_MOVEUP_WP 7026
44#define ID_RCLK_MENU_MOVEDOWN_WP 7027
46#define COLUMN_PLANNED_SPEED 9
49extern wxString GetLayerName(
int id);
54extern ColorScheme global_color_scheme;
55extern RouteList* pRouteList;
62int g_route_prop_x, g_route_prop_y, g_route_prop_sx, g_route_prop_sy;
71#define PI (4. * atan(1.0))
74#define DEGS (180. / PI)
75#define RADS (PI / 180.)
85static wxString GetDaylightString(
int index) {
90 return _(
"MoTwilight");
98 return _(
"EvTwilight");
100 return _(
"Nighttime");
107static double sign(
double x) {
114static double FNipart(
double x) {
return (sign(x) * (
int)(fabs(x))); }
116static double FNday(
int y,
int m,
int d,
int h) {
117 long fd = (367 * y - 7 * (y + (m + 9) / 12) / 4 + 275 * m / 9 + d);
118 return ((
double)fd - 730531.5 + h / 24.);
121static double FNrange(
double x) {
123 double a = TPI * (b - FNipart(b));
124 if (a < 0.) a = TPI + a;
128static double getDaylightEvent(
double glat,
double glong,
int riset,
129 double altitude,
int y,
int m,
int d) {
130 double day = FNday(y, m, d, 0);
131 double days, correction;
135 sin(altitude * RADS);
136 double sinphi = sin(glat * RADS);
137 double cosphi = cos(glat * RADS);
138 double g = glong * RADS;
139 double t, L, G, ec, lambda, E, obl, delta, GHA, cosc;
141 while ((fabs(utold - utnew) > .001)) {
142 if (limit-- <= 0)
return (-1.);
143 days = day + utnew / TPI;
146 L = FNrange(4.8949504201433 + 628.331969753199 * t);
147 G = FNrange(6.2400408 + 628.3019501 * t);
148 ec = .033423 * sin(G) + .00034907 * sin(2 * G);
150 E = -1. * ec + .0430398 * sin(2 * lambda) - .00092502 * sin(4. * lambda);
151 obl = .409093 - .0002269 * t;
152 delta = asin(sin(obl) * sin(lambda));
153 GHA = utold - PI + E;
154 cosc = (sinalt - sinphi * sin(delta)) / (cosphi * cos(delta));
160 correction = acos(cosc);
162 utnew = FNrange(utold - (GHA + g + riset * correction));
165 return (utnew * DEGS / 15.);
168static double getLMT(
double ut,
double lon) {
169 double t = ut + lon / 15.;
179static int getDaylightStatus(
double lat,
double lon, wxDateTime utcDateTime) {
180 if (fabs(lat) > 60.)
return (0);
181 int y = utcDateTime.GetYear();
182 int m = utcDateTime.GetMonth() + 1;
183 int d = utcDateTime.GetDay();
184 int h = utcDateTime.GetHour();
185 int n = utcDateTime.GetMinute();
186 int s = utcDateTime.GetSecond();
187 if (y < 2000 || y > 2100)
return (0);
189 double ut = (double)h + (
double)n / 60. + (double)s / 3600.;
190 double lt = getLMT(ut, lon);
191 double rsalt = -0.833;
195 double sunrise = getDaylightEvent(lat, lon, +1, rsalt, y, m, d);
199 sunrise = getLMT(sunrise, lon);
201 if (fabs(lt - sunrise) < 0.15)
return (SUNRISE);
202 if (lt > sunrise)
return (DAY);
203 double twilight = getDaylightEvent(lat, lon, +1, twalt, y, m, d);
207 twilight = getLMT(twilight, lon);
213 double sunset = getDaylightEvent(lat, lon, -1, rsalt, y, m, d);
217 sunset = getLMT(sunset, lon);
218 if (fabs(lt - sunset) < 0.15)
return (SUNSET);
219 if (lt < sunset)
return (DAY);
220 double twilight = getDaylightEvent(lat, lon, -1, twalt, y, m, d);
224 twilight = getLMT(twilight, lon);
232RoutePropDlgImpl::RoutePropDlgImpl(wxWindow* parent, wxWindowID
id,
233 const wxString& title,
const wxPoint& pos,
234 const wxSize& size,
long style)
238 SetColorScheme(global_color_scheme);
240 if (g_route_prop_sx > 0 && g_route_prop_sy > 0 &&
241 g_route_prop_sx < wxGetDisplaySize().x &&
242 g_route_prop_sy < wxGetDisplaySize().y) {
243 SetSize(g_route_prop_sx, g_route_prop_sy);
246 if (g_route_prop_x > 0 && g_route_prop_y > 0 &&
247 g_route_prop_x < wxGetDisplaySize().x &&
248 g_route_prop_y < wxGetDisplaySize().y) {
249 SetPosition(wxPoint(10, 10));
253 Connect(wxEVT_COMMAND_MENU_SELECTED,
254 wxCommandEventHandler(RoutePropDlgImpl::OnRoutePropMenuSelected),
258 Connect(wxEVT_ACTIVATE,
259 wxActivateEventHandler(RoutePropDlgImpl::OnActivate),
264RoutePropDlgImpl::~RoutePropDlgImpl() {
265 Disconnect(wxEVT_COMMAND_MENU_SELECTED,
266 wxCommandEventHandler(RoutePropDlgImpl::OnRoutePropMenuSelected),
268 instanceFlag =
false;
271bool RoutePropDlgImpl::instanceFlag =
false;
272bool RoutePropDlgImpl::getInstanceFlag() {
273 return RoutePropDlgImpl::instanceFlag;
285void RoutePropDlgImpl::OnActivate(wxActivateEvent& event){
286 wxFrame* pWin = wxDynamicCast(event.GetEventObject(), wxFrame);
287 long int style = pWin->GetWindowStyle();
288 if (event.GetActive())
289 pWin->SetWindowStyle(style | wxSTAY_ON_TOP);
291 pWin->SetWindowStyle(style ^ wxSTAY_ON_TOP);
294void RoutePropDlgImpl::RecalculateSize(
void) {
296 esize.x = GetCharWidth() * 110;
297 esize.y = GetCharHeight() * 40;
299 wxSize dsize = GetParent()->GetSize();
300 esize.y = wxMin(esize.y, dsize.y - 0 );
301 esize.x = wxMin(esize.x, dsize.x - 0 );
304 wxSize fsize = GetSize();
305 wxSize canvas_size = GetParent()->GetSize();
306 wxPoint screen_pos = GetParent()->GetScreenPosition();
307 int xp = (canvas_size.x - fsize.x) / 2;
308 int yp = (canvas_size.y - fsize.y) / 2;
309 Move(screen_pos.x + xp, screen_pos.y + yp);
312void RoutePropDlgImpl::UpdatePoints() {
313 if (!m_pRoute)
return;
314 wxDataViewItem selection = m_dvlcWaypoints->GetSelection();
315 int selected_row = m_dvlcWaypoints->GetSelectedRow();
316 m_dvlcWaypoints->DeleteAllItems();
318 wxVector<wxVariant> data;
320 m_pRoute->UpdateSegmentDistances(
321 m_pRoute->m_PlannedSpeed);
322 m_tcDistance->SetValue(
323 wxString::Format(wxT(
"%5.1f ") + getUsrDistanceUnit(),
324 toUsrDistance(m_pRoute->m_route_length)));
325 m_tcEnroute->SetValue(formatTimeDelta(wxLongLong(m_pRoute->m_route_time)));
327 wxRoutePointListNode* pnode = m_pRoute->pRoutePointList->GetFirst();
329 wxString slen, eta, ete;
330 double bearing, distance, speed;
331 double totalDistance = 0;
332 wxDateTime eta_dt = wxInvalidDateTime;
334 speed = pnode->GetData()->GetPlannedSpeed();
336 speed = m_pRoute->m_PlannedSpeed;
339 DistanceBearingMercator(pnode->GetData()->GetLatitude(),
340 pnode->GetData()->GetLongitude(), gLat, gLon,
341 &bearing, &distance);
342 if (m_pRoute->m_PlannedDeparture.IsValid()) {
343 eta = wxString::Format(
344 "Start: %s", toUsrDateTime(m_pRoute->m_PlannedDeparture,
345 m_tz_selection, pnode->GetData()->m_lon)
346 .Format(ETA_FORMAT_STR)
348 eta.Append(wxString::Format(
350 GetDaylightString(getDaylightStatus(pnode->GetData()->m_lat,
351 pnode->GetData()->m_lon,
352 m_pRoute->m_PlannedDeparture))
354 eta_dt = m_pRoute->m_PlannedDeparture;
359 ete = formatTimeDelta(wxLongLong(3600. * distance / speed));
364 distance = pnode->GetData()->GetDistance();
365 bearing = pnode->GetData()->GetCourse();
366 if (pnode->GetData()->GetETA().IsValid()) {
367 eta = toUsrDateTime(pnode->GetData()->GetETA(), m_tz_selection,
368 pnode->GetData()->m_lon)
369 .Format(ETA_FORMAT_STR);
370 eta.Append(wxString::Format(
372 GetDaylightString(getDaylightStatus(pnode->GetData()->m_lat,
373 pnode->GetData()->m_lon,
374 pnode->GetData()->GetETA()))
376 eta_dt = pnode->GetData()->GetETA();
380 ete = pnode->GetData()->GetETE();
381 totalDistance += distance;
383 wxString name = pnode->GetData()->GetName();
384 double lat = pnode->GetData()->GetLatitude();
385 double lon = pnode->GetData()->GetLongitude();
386 wxString tide_station = pnode->GetData()->m_TideStation;
387 wxString desc = pnode->GetData()->GetDescription();
389 if (pnode->GetData()->GetManualETD().IsValid()) {
391 etd = toUsrDateTime(pnode->GetData()->GetManualETD(),
392 0 , pnode->GetData()->m_lon)
393 .Format(ETA_FORMAT_STR);
394 if (pnode->GetData()->GetManualETD().IsValid() &&
395 pnode->GetData()->GetETA().IsValid() &&
396 pnode->GetData()->GetManualETD() < pnode->GetData()->GetETA()) {
403 pnode = pnode->GetNext();
406 crs = formatAngle(pnode->GetData()->GetCourse());
412 data.push_back(wxVariant(
"---"));
414 std::ostringstream stm;
416 data.push_back(wxVariant(stm.str()));
419 wxString schar = wxEmptyString;
420#ifdef __OCPN__ANDROID__
421 schar = wxString(
" ");
423 data.push_back(wxVariant(name + schar));
424 slen.Printf(wxT(
"%5.1f ") + getUsrDistanceUnit(), toUsrDistance(distance));
425 data.push_back(wxVariant(schar + slen + schar));
426 data.push_back(wxVariant(schar + formatAngle(bearing)));
427 slen.Printf(wxT(
"%5.1f ") + getUsrDistanceUnit(),
428 toUsrDistance(totalDistance));
429 data.push_back(wxVariant(schar + slen + schar));
430 data.push_back(wxVariant(schar + ::toSDMM(1, lat, FALSE) + schar));
431 data.push_back(wxVariant(schar + ::toSDMM(2, lon, FALSE) + schar));
432 data.push_back(wxVariant(schar + ete + schar));
433 data.push_back(schar + eta + schar);
435 wxVariant(wxString::FromDouble(toUsrSpeed(speed))));
436 data.push_back(wxVariant(
437 MakeTideInfo(tide_station, lat, lon, eta_dt)));
438 data.push_back(wxVariant(desc));
439 data.push_back(wxVariant(crs));
440 data.push_back(wxVariant(etd));
441 data.push_back(wxVariant(
444 m_dvlcWaypoints->AppendItem(data);
448 if (selected_row > 0) {
449 m_dvlcWaypoints->SelectRow(selected_row);
450 m_dvlcWaypoints->EnsureVisible(selection);
454wxDateTime RoutePropDlgImpl::toUsrDateTime(
const wxDateTime ts,
455 const int format,
const double lon) {
460 switch (m_tz_selection) {
462 if (std::isnan(lon)) {
463 dt = wxInvalidDateTime;
466 ts.Add(wxTimeSpan(wxTimeSpan(0, 0, wxLongLong(lon * 3600. / 15.))));
479wxDateTime RoutePropDlgImpl::fromUsrDateTime(
const wxDateTime ts,
486 switch (m_tz_selection) {
488 if (std::isnan(lon)) {
489 dt = wxInvalidDateTime;
491 dt = ts.Subtract(wxTimeSpan(0, 0, wxLongLong(lon * 3600. / 15.)));
504void RoutePropDlgImpl::SetRouteAndUpdate(
Route* pR,
bool only_points) {
505 if (NULL == pR)
return;
511 m_OrigRoute.m_PlannedDeparture = pR->m_PlannedDeparture;
512 m_OrigRoute.m_PlannedSpeed = pR->m_PlannedSpeed;
515 pR->GetName() == wxEmptyString ? _(
"Route Properties") : pR->GetName();
516 if (!pR->m_bIsInLayer)
519 wxString caption(wxString::Format(_T(
"%s, %s: %s"), title, _(
"Layer"),
520 GetLayerName(pR->m_LayerID)));
526 if (!pR->m_PlannedDeparture.IsValid())
527 pR->m_PlannedDeparture = wxDateTime::Now().ToUTC();
530 if (pR != m_pRoute) {
531 if (pR->m_TimeDisplayFormat == RTE_TIME_DISP_UTC)
533 else if (pR->m_TimeDisplayFormat == RTE_TIME_DISP_LOCAL)
535 m_pEnroutePoint = NULL;
541 m_tcPlanSpeed->SetValue(
542 wxString::FromDouble(toUsrSpeed(m_pRoute->m_PlannedSpeed)));
544 if (m_scrolledWindowLinks) {
545 wxWindowList kids = m_scrolledWindowLinks->GetChildren();
546 for (
unsigned int i = 0; i < kids.GetCount(); i++) {
547 wxWindowListNode* node = kids.Item(i);
548 wxWindow* win = node->GetData();
549 if (win->IsKindOf(CLASSINFO(wxHyperlinkCtrl))) {
550 ((wxHyperlinkCtrl*)win)
552 wxEVT_COMMAND_HYPERLINK,
553 wxHyperlinkEventHandler(RoutePropDlgImpl::OnHyperlinkClick));
554 ((wxHyperlinkCtrl*)win)
557 wxMouseEventHandler(RoutePropDlgImpl::HyperlinkContextMenu));
561 int NbrOfLinks = m_pRoute->m_HyperlinkList->GetCount();
562 HyperlinkList* hyperlinklist = m_pRoute->m_HyperlinkList;
563 if (NbrOfLinks > 0) {
564 wxHyperlinkListNode* linknode = hyperlinklist->GetFirst();
567 wxString Link = link->Link;
568 wxString Descr = link->DescrText;
570 wxHyperlinkCtrl* ctrl =
new wxHyperlinkCtrl(
571 m_scrolledWindowLinks, wxID_ANY, Descr, Link, wxDefaultPosition,
572 wxDefaultSize, wxHL_DEFAULT_STYLE);
574 wxEVT_COMMAND_HYPERLINK,
575 wxHyperlinkEventHandler(RoutePropDlgImpl::OnHyperlinkClick), NULL,
577 if (!m_pRoute->m_bIsInLayer) {
580 wxMouseEventHandler(RoutePropDlgImpl::HyperlinkContextMenu),
583 bSizerLinks->Add(ctrl, 0, wxALL, 5);
585 linknode = linknode->GetNext();
588 m_scrolledWindowLinks->InvalidateBestSize();
589 m_scrolledWindowLinks->Layout();
590 bSizerLinks->Layout();
593 m_choiceTimezone->SetSelection(m_tz_selection);
596 m_tcName->SetValue(m_pRoute->m_RouteNameString);
597 m_tcFrom->SetValue(m_pRoute->m_RouteStartString);
598 m_tcTo->SetValue(m_pRoute->m_RouteEndString);
599 m_tcDescription->SetValue(m_pRoute->m_RouteDescription);
601 m_tcName->SetFocus();
602 if (m_pRoute->m_PlannedDeparture.IsValid() &&
603 m_pRoute->m_PlannedDeparture.GetValue() > 0) {
604 m_dpDepartureDate->SetValue(
605 toUsrDateTime(m_pRoute->m_PlannedDeparture, m_tz_selection,
606 m_pRoute->pRoutePointList->GetFirst()->GetData()->m_lon)
608 m_tpDepartureTime->SetValue(toUsrDateTime(
609 m_pRoute->m_PlannedDeparture, m_tz_selection,
610 m_pRoute->pRoutePointList->GetFirst()->GetData()->m_lon));
612 m_dpDepartureDate->SetValue(
613 toUsrDateTime(wxDateTime::Now(), m_tz_selection,
614 m_pRoute->pRoutePointList->GetFirst()->GetData()->m_lon)
616 m_tpDepartureTime->SetValue(toUsrDateTime(
617 wxDateTime::Now(), m_tz_selection,
618 m_pRoute->pRoutePointList->GetFirst()->GetData()->m_lon));
622 m_btnSplit->Enable(
false);
623 if (!m_pRoute)
return;
625 if (m_pRoute->m_Colour == wxEmptyString) {
626 m_choiceColor->Select(0);
628 for (
unsigned int i = 0; i <
sizeof(::GpxxColorNames) /
sizeof(wxString);
630 if (m_pRoute->m_Colour == ::GpxxColorNames[i]) {
631 m_choiceColor->Select(i + 1);
637 for (
unsigned int i = 0; i <
sizeof(::StyleValues) /
sizeof(
int); i++) {
638 if (m_pRoute->m_style == ::StyleValues[i]) {
639 m_choiceStyle->Select(i);
644 for (
unsigned int i = 0; i <
sizeof(::WidthValues) /
sizeof(
int); i++) {
645 if (m_pRoute->m_width == ::WidthValues[i]) {
646 m_choiceWidth->Select(i);
653 m_btnExtend->Enable(IsThisRouteExtendable());
656void RoutePropDlgImpl::DepartureDateOnDateChanged(wxDateEvent& event) {
657 if (!m_pRoute)
return;
658 m_pRoute->SetDepartureDate(GetDepartureTS());
663void RoutePropDlgImpl::DepartureTimeOnTimeChanged(wxDateEvent& event) {
664 if (!m_pRoute)
return;
665 m_pRoute->SetDepartureDate(GetDepartureTS());
670void RoutePropDlgImpl::TimezoneOnChoice(wxCommandEvent& event) {
671 m_tz_selection = m_choiceTimezone->GetSelection();
672 m_dpDepartureDate->SetValue(
673 toUsrDateTime(m_pRoute->m_PlannedDeparture, m_tz_selection,
674 m_pRoute->pRoutePointList->GetFirst()->GetData()->m_lon)
676 m_tpDepartureTime->SetValue(
677 toUsrDateTime(m_pRoute->m_PlannedDeparture, m_tz_selection,
678 m_pRoute->pRoutePointList->GetFirst()->GetData()->m_lon));
683void RoutePropDlgImpl::PlanSpeedOnTextEnter(wxCommandEvent& event) {
684 if (!m_pRoute)
return;
686 if (m_tcPlanSpeed->GetValue().ToDouble(&spd)) {
687 if (m_pRoute->m_PlannedSpeed != fromUsrSpeed(spd)) {
688 m_pRoute->m_PlannedSpeed = fromUsrSpeed(spd);
692 m_tcPlanSpeed->SetValue(
693 wxString::FromDouble(toUsrSpeed(m_pRoute->m_PlannedSpeed)));
697void RoutePropDlgImpl::PlanSpeedOnKillFocus(wxFocusEvent& event) {
698 if (!m_pRoute)
return;
700 if (m_tcPlanSpeed->GetValue().ToDouble(&spd)) {
701 if (m_pRoute->m_PlannedSpeed != fromUsrSpeed(spd)) {
702 m_pRoute->m_PlannedSpeed = fromUsrSpeed(spd);
706 m_tcPlanSpeed->SetValue(
707 wxString::FromDouble(toUsrSpeed(m_pRoute->m_PlannedSpeed)));
713void RoutePropDlgImpl::WaypointsOnDataViewListCtrlItemEditingDone(
714 wxDataViewEvent& event) {
718 ev_col =
event.GetColumn();
721void RoutePropDlgImpl::WaypointsOnDataViewListCtrlItemValueChanged(
722 wxDataViewEvent& event) {
723#if wxCHECK_VERSION(3, 1, 2)
725 if (!m_pRoute)
return;
726 wxDataViewModel*
const model =
event.GetModel();
728 model->GetValue(value, event.GetItem(), ev_col);
730 static_cast<int>(
reinterpret_cast<long long>(event.GetItem().GetID())));
731 if (ev_col == COLUMN_PLANNED_SPEED) {
733 if (!value.GetString().ToDouble(&spd)) {
736 p->SetPlannedSpeed(fromUsrSpeed(spd));
737 }
else if (ev_col == COLUMN_ETD) {
738 wxString::const_iterator end;
741 wxString ts = value.GetString();
742 if (ts.StartsWith(
"!")) {
743 ts.Replace(
"!", wxEmptyString,
true);
749 if (!etd.ParseDateTime(ts, &end)) {
750 p->SetETD(wxInvalidDateTime);
753 fromUsrDateTime(etd, m_tz_selection, p->m_lon).FormatISOCombined());
756 p->SetETD(wxInvalidDateTime);
763void RoutePropDlgImpl::WaypointsOnDataViewListCtrlSelectionChanged(
764 wxDataViewEvent& event) {
765 long selected_row = m_dvlcWaypoints->GetSelectedRow();
766 if (selected_row > 0 && selected_row < m_dvlcWaypoints->GetItemCount() - 1) {
767 m_btnSplit->Enable(
true);
769 m_btnSplit->Enable(
false);
771 if (IsThisRouteExtendable()) {
772 m_btnExtend->Enable(
true);
774 m_btnExtend->Enable(
false);
776 if (selected_row >= 0 && selected_row < m_dvlcWaypoints->GetItemCount()) {
777 RoutePoint* prp = m_pRoute->GetPoint(selected_row + 1);
779 gFrame->JumpToPosition(gFrame->GetPrimaryCanvas(), prp->m_lat, prp->m_lon,
780 gFrame->GetPrimaryCanvas()->GetVPScale());
782 if (m_dvlcWaypoints) m_dvlcWaypoints->SetFocus();
788wxDateTime RoutePropDlgImpl::GetDepartureTS() {
789 wxDateTime dt = m_dpDepartureDate->GetValue();
790 dt.SetHour(m_tpDepartureTime->GetValue().GetHour());
791 dt.SetMinute(m_tpDepartureTime->GetValue().GetMinute());
792 dt.SetSecond(m_tpDepartureTime->GetValue().GetSecond());
793 return fromUsrDateTime(
795 m_pRoute->pRoutePointList->GetFirst()->GetData()->m_lon);
799void RoutePropDlgImpl::OnRoutepropCopyTxtClick(wxCommandEvent& event) {
800 wxString tab(
"\t", wxConvUTF8);
801 wxString eol(
"\n", wxConvUTF8);
804 csvString << this->GetTitle() << eol << _(
"Name") << tab
805 << m_pRoute->m_RouteNameString << eol << _(
"Depart From") << tab
806 << m_pRoute->m_RouteStartString << eol << _(
"Destination") << tab
807 << m_pRoute->m_RouteEndString << eol << _(
"Total distance") << tab
808 << m_tcDistance->GetValue() << eol << _(
"Speed (Kts)") << tab
809 << m_tcPlanSpeed->GetValue() << eol
810 << _(
"Departure Time") + _T(
" (") + _T(ETA_FORMAT_STR) + _T(
")")
811 << tab << GetDepartureTS().Format(ETA_FORMAT_STR) << eol
812 << _(
"Time enroute") << tab << m_tcEnroute->GetValue() << eol
817 noCols = m_dvlcWaypoints->GetColumnCount();
818 noRows = m_dvlcWaypoints->GetItemCount();
820 item.SetMask(wxLIST_MASK_TEXT);
822 for (
int i = 0; i < noCols; i++) {
823 wxDataViewColumn* col = m_dvlcWaypoints->GetColumn(i);
824 csvString << col->GetTitle() << tab;
829 for (
int j = 0; j < noRows; j++) {
830 for (
int i = 0; i < noCols; i++) {
831 m_dvlcWaypoints->GetValue(value, j, i);
832 csvString << value.MakeString() << tab;
837 if (wxTheClipboard->Open()) {
838 wxTextDataObject* data =
new wxTextDataObject;
839 data->SetText(csvString);
840 wxTheClipboard->SetData(data);
841 wxTheClipboard->Close();
845void RoutePropDlgImpl::OnRoutePropMenuSelected(wxCommandEvent& event) {
847 switch (event.GetId()) {
848 case ID_RCLK_MENU_COPY_TEXT: {
849 OnRoutepropCopyTxtClick(event);
852 case ID_RCLK_MENU_MOVEUP_WP: {
855 case ID_RCLK_MENU_MOVEDOWN_WP: {
857 moveup ? _(
"Are you sure you want to move Up this waypoint?")
858 : _(
"Are you sure you want to move Down this waypoint?");
860 OCPNMessageBox(
this, mess, _(
"OpenCPN Move Waypoint"),
861 (
long)wxYES_NO | wxCANCEL | wxYES_DEFAULT);
863 if (dlg_return == wxID_YES) {
864 wxDataViewItem selection = m_dvlcWaypoints->GetSelection();
866 static_cast<int>(
reinterpret_cast<long long>(selection.GetID())));
867 int nRP = m_pRoute->pRoutePointList->IndexOf(pRP) + (moveup ? -1 : 1);
869 pSelect->DeleteAllSelectableRoutePoints(m_pRoute);
870 pSelect->DeleteAllSelectableRouteSegments(m_pRoute);
872 m_pRoute->pRoutePointList->DeleteObject(pRP);
873 m_pRoute->pRoutePointList->Insert(nRP, pRP);
875 pSelect->AddAllSelectableRouteSegments(m_pRoute);
876 pSelect->AddAllSelectableRoutePoints(m_pRoute);
878 pConfig->UpdateRoute(m_pRoute);
880 m_pRoute->FinalizeForRendering();
881 m_pRoute->UpdateSegmentDistances();
884 gFrame->InvalidateAllGL();
886 m_dvlcWaypoints->SelectRow(nRP);
888 SetRouteAndUpdate(m_pRoute,
true);
892 case ID_RCLK_MENU_DELETE: {
893 int dlg_return = OCPNMessageBox(
894 this, _(
"Are you sure you want to remove this waypoint?"),
895 _(
"OpenCPN Remove Waypoint"),
896 (
long)wxYES_NO | wxCANCEL | wxYES_DEFAULT);
898 if (dlg_return == wxID_YES) {
899 int sel = m_dvlcWaypoints->GetSelectedRow();
900 m_dvlcWaypoints->SelectRow(sel);
902 wxDataViewItem selection = m_dvlcWaypoints->GetSelection();
904 static_cast<int>(
reinterpret_cast<long long>(selection.GetID())));
906 g_pRouteMan->RemovePointFromRoute(pRP, m_pRoute, 0);
907 gFrame->InvalidateAllGL();
912 case ID_RCLK_MENU_EDIT_WP: {
913 wxDataViewItem selection = m_dvlcWaypoints->GetSelection();
915 static_cast<int>(
reinterpret_cast<long long>(selection.GetID())));
917 RouteManagerDialog::WptShowPropertiesDialog(pRP,
this);
923void RoutePropDlgImpl::WaypointsOnDataViewListCtrlItemContextMenu(
924 wxDataViewEvent& event) {
926 if (!m_pRoute->m_bIsInLayer) {
927 wxMenuItem* editItem =
new wxMenuItem(&menu, ID_RCLK_MENU_EDIT_WP,
928 _(
"Waypoint Properties") + _T(
"..."));
929 wxMenuItem* moveUpItem =
930 new wxMenuItem(&menu, ID_RCLK_MENU_MOVEUP_WP, _(
"Move Up"));
931 wxMenuItem* moveDownItem =
932 new wxMenuItem(&menu, ID_RCLK_MENU_MOVEDOWN_WP, _(
"Move Down"));
933 wxMenuItem* delItem =
934 new wxMenuItem(&menu, ID_RCLK_MENU_DELETE, _(
"Remove Selected"));
935#ifdef __OCPN__ANDROID__
936 wxFont* pf = OCPNGetFont(_T(
"Menu"), 0);
937 editItem->SetFont(*pf);
938 moveUpItem->SetFont(*pf);
939 moveDownItem->SetFont(*pf);
940 delItem->SetFont(*pf);
942#if defined(__WXMSW__)
943 wxFont* pf = GetOCPNScaledFont(_T(
"Menu"));
944 editItem->SetFont(*pf);
945 moveUpItem->SetFont(*pf);
946 moveDownItem->SetFont(*pf);
947 delItem->SetFont(*pf);
950 menu.Append(editItem);
951 if (g_btouch) menu.AppendSeparator();
952 menu.Append(moveUpItem);
953 if (g_btouch) menu.AppendSeparator();
954 menu.Append(moveDownItem);
955 if (g_btouch) menu.AppendSeparator();
956 menu.Append(delItem);
958 editItem->Enable(m_dvlcWaypoints->GetSelectedRow() >= 0);
959 moveUpItem->Enable(m_dvlcWaypoints->GetSelectedRow() >= 1 &&
960 m_dvlcWaypoints->GetItemCount() > 2);
961 moveDownItem->Enable(m_dvlcWaypoints->GetSelectedRow() >= 0 &&
962 m_dvlcWaypoints->GetSelectedRow() <
963 m_dvlcWaypoints->GetItemCount() - 1 &&
964 m_dvlcWaypoints->GetItemCount() > 2);
965 delItem->Enable(m_dvlcWaypoints->GetSelectedRow() >= 0 &&
966 m_dvlcWaypoints->GetItemCount() > 2);
969 wxMenuItem* copyItem =
970 new wxMenuItem(&menu, ID_RCLK_MENU_COPY_TEXT, _(
"&Copy all as text"));
972#if defined(__WXMSW__)
973 wxFont* qFont = GetOCPNScaledFont(_T(
"Menu"));
974 copyItem->SetFont(*qFont);
977 if (g_btouch) menu.AppendSeparator();
978 menu.Append(copyItem);
984void RoutePropDlgImpl::ResetChanges() {
985 if (!m_pRoute)
return;
986 m_pRoute->m_PlannedSpeed = m_OrigRoute.m_PlannedSpeed;
987 m_pRoute->m_PlannedDeparture = m_OrigRoute.m_PlannedDeparture;
991void RoutePropDlgImpl::SaveChanges() {
992 if (m_pRoute && !m_pRoute->m_bIsInLayer) {
994 m_pRoute->m_RouteNameString = m_tcName->GetValue();
995 m_pRoute->m_RouteStartString = m_tcFrom->GetValue();
996 m_pRoute->m_RouteEndString = m_tcTo->GetValue();
997 m_pRoute->m_RouteDescription = m_tcDescription->GetValue();
998 if (m_choiceColor->GetSelection() == 0) {
999 m_pRoute->m_Colour = wxEmptyString;
1001 m_pRoute->m_Colour = ::GpxxColorNames[m_choiceColor->GetSelection() - 1];
1004 (wxPenStyle)::StyleValues[m_choiceStyle->GetSelection()];
1005 m_pRoute->m_width = ::WidthValues[m_choiceWidth->GetSelection()];
1006 switch (m_tz_selection) {
1008 m_pRoute->m_TimeDisplayFormat = RTE_TIME_DISP_PC;
1011 m_pRoute->m_TimeDisplayFormat = RTE_TIME_DISP_LOCAL;
1014 m_pRoute->m_TimeDisplayFormat = RTE_TIME_DISP_UTC;
1017 pConfig->UpdateRoute(m_pRoute);
1018 pConfig->UpdateSettings();
1023void RoutePropDlgImpl::SetColorScheme(ColorScheme cs) { DimeControl(
this); }
1025void RoutePropDlgImpl::SaveGeometry() {
1026 GetSize(&g_route_prop_sx, &g_route_prop_sy);
1027 GetPosition(&g_route_prop_x, &g_route_prop_y);
1030void RoutePropDlgImpl::BtnsOnOKButtonClick(wxCommandEvent& event) {
1032 if (pRouteManagerDialog && pRouteManagerDialog->IsShown()) {
1033 pRouteManagerDialog->UpdateRouteListCtrl();
1039void RoutePropDlgImpl::SplitOnButtonClick(wxCommandEvent& event) {
1040 m_btnSplit->Enable(
false);
1042 if (m_pRoute->m_bIsInLayer)
return;
1044 int nSelected = m_dvlcWaypoints->GetSelectedRow() + 1;
1045 if ((nSelected > 1) && (nSelected < m_pRoute->GetnPoints())) {
1046 m_pHead =
new Route();
1047 m_pTail =
new Route();
1048 m_pHead->CloneRoute(m_pRoute, 1, nSelected, _(
"_A"));
1049 m_pTail->CloneRoute(m_pRoute, nSelected, m_pRoute->GetnPoints(), _(
"_B"),
1051 pRouteList->Append(m_pHead);
1052 pConfig->AddNewRoute(m_pHead);
1054 pRouteList->Append(m_pTail);
1055 pConfig->AddNewRoute(m_pTail);
1057 pConfig->DeleteConfigRoute(m_pRoute);
1059 pSelect->DeleteAllSelectableRoutePoints(m_pRoute);
1060 pSelect->DeleteAllSelectableRouteSegments(m_pRoute);
1061 g_pRouteMan->
DeleteRoute(m_pRoute, NavObjectChanges::getInstance());
1062 pSelect->AddAllSelectableRouteSegments(m_pTail);
1063 pSelect->AddAllSelectableRoutePoints(m_pTail);
1064 pSelect->AddAllSelectableRouteSegments(m_pHead);
1065 pSelect->AddAllSelectableRoutePoints(m_pHead);
1067 SetRouteAndUpdate(m_pTail);
1070 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
1071 pRouteManagerDialog->UpdateRouteListCtrl();
1075void RoutePropDlgImpl::PrintOnButtonClick(wxCommandEvent& event) {
1078 dlg->ShowWindowModalThenDo([
this, dlg](
int retcode) {
1079 if (retcode == wxID_OK) {
1084void RoutePropDlgImpl::ExtendOnButtonClick(wxCommandEvent& event) {
1085 m_btnExtend->Enable(
false);
1087 if (IsThisRouteExtendable()) {
1088 int fm = m_pExtendRoute->GetIndexOf(m_pExtendPoint) + 1;
1089 int to = m_pExtendRoute->GetnPoints();
1091 pSelect->DeleteAllSelectableRouteSegments(m_pRoute);
1092 m_pRoute->CloneRoute(m_pExtendRoute, fm, to, _(
"_plus"));
1093 pSelect->AddAllSelectableRouteSegments(m_pRoute);
1094 SetRouteAndUpdate(m_pRoute);
1098 m_btnExtend->Enable(
true);
1101bool RoutePropDlgImpl::IsThisRouteExtendable() {
1102 m_pExtendRoute = NULL;
1103 m_pExtendPoint = NULL;
1104 if (m_pRoute->m_bRtIsActive || m_pRoute->m_bIsInLayer)
return false;
1106 RoutePoint* pLastPoint = m_pRoute->GetLastPoint();
1107 wxArrayPtrVoid* pEditRouteArray;
1109 pEditRouteArray = g_pRouteMan->GetRouteArrayContaining(pLastPoint);
1112 for (i = pEditRouteArray->GetCount(); i > 0; i--) {
1113 Route* p = (
Route*)pEditRouteArray->Item(i - 1);
1114 if (!p->IsVisible() || (p->m_GUID == m_pRoute->m_GUID))
1115 pEditRouteArray->RemoveAt(i - 1);
1117 if (pEditRouteArray->GetCount() == 1) {
1118 m_pExtendPoint = pLastPoint;
1120 if (pEditRouteArray->GetCount() == 0) {
1121 int nearby_radius_meters =
1122 (int)(8. / gFrame->GetPrimaryCanvas()->GetCanvasTrueScale());
1123 double rlat = pLastPoint->m_lat;
1124 double rlon = pLastPoint->m_lon;
1126 m_pExtendPoint = pWayPointMan->GetOtherNearbyWaypoint(
1127 rlat, rlon, nearby_radius_meters, pLastPoint->m_GUID);
1128 if (m_pExtendPoint) {
1129 wxArrayPtrVoid* pCloseWPRouteArray =
1130 g_pRouteMan->GetRouteArrayContaining(m_pExtendPoint);
1131 if (pCloseWPRouteArray) {
1132 pEditRouteArray = pCloseWPRouteArray;
1135 for (i = pEditRouteArray->GetCount(); i > 0; i--) {
1136 Route* p = (
Route*)pEditRouteArray->Item(i - 1);
1137 if (!p->IsVisible() || (p->m_GUID == m_pRoute->m_GUID))
1138 pEditRouteArray->RemoveAt(i - 1);
1144 if (pEditRouteArray->GetCount() == 1) {
1146 int fm = p->GetIndexOf(m_pExtendPoint) + 1;
1147 int to = p->GetnPoints();
1150 delete pEditRouteArray;
1154 delete pEditRouteArray;
1159wxString RoutePropDlgImpl::MakeTideInfo(wxString stationName,
double lat,
1160 double lon, wxDateTime utcTime) {
1161 if (stationName.Find(
"lind") != wxNOT_FOUND)
int yyp = 4;
1163 if (stationName.IsEmpty()) {
1164 return wxEmptyString;
1166 if (!utcTime.IsValid()) {
1167 return _(
"Invalid date/time!");
1169 int stationID = ptcmgr->GetStationIDXbyName(stationName, lat, lon);
1170 if (stationID == 0) {
1171 return _(
"Unknown station!");
1173 time_t dtmtt = utcTime.FromUTC().GetTicks();
1174 int ev = ptcmgr->GetNextBigEvent(&dtmtt, stationID);
1177 dtm.Set(dtmtt).MakeUTC();
1179 wxString tide_form = wxEmptyString;
1182 tide_form.Append(_T(
"LW: "));
1183 }
else if (ev == 2) {
1184 tide_form.Append(_T(
"HW: "));
1185 }
else if (ev == 0) {
1186 tide_form.Append(_(
"Unavailable: "));
1190 ptcmgr->GetStationTimeOffset((
IDX_entry*)ptcmgr->GetIDX_entry(stationID));
1193 toUsrDateTime(dtm, m_tz_selection, lon).Format(ETA_FORMAT_STR));
1194 dtm.Add(wxTimeSpan(0, offset, 0));
1195 tide_form.Append(wxString::Format(_T(
" (") + _(
"Local") + _T(
": %s) @ %s"),
1196 dtm.Format(ETA_FORMAT_STR),
1197 stationName.c_str()));
1202void RoutePropDlgImpl::ItemEditOnMenuSelection(wxCommandEvent& event) {
1203 wxString findurl = m_pEditedLink->GetURL();
1204 wxString findlabel = m_pEditedLink->GetLabel();
1207 LinkPropDlg->m_textCtrlLinkDescription->SetValue(findlabel);
1208 LinkPropDlg->m_textCtrlLinkUrl->SetValue(findurl);
1209 DimeControl(LinkPropDlg);
1210 LinkPropDlg->ShowWindowModalThenDo([
this, LinkPropDlg, findurl,
1211 findlabel](
int retcode) {
1212 if (retcode == wxID_OK) {
1213 int NbrOfLinks = m_pRoute->m_HyperlinkList->GetCount();
1214 HyperlinkList* hyperlinklist = m_pRoute->m_HyperlinkList;
1216 if (NbrOfLinks > 0) {
1217 wxHyperlinkListNode* linknode = hyperlinklist->GetFirst();
1220 wxString Link = link->Link;
1221 wxString Descr = link->DescrText;
1222 if (Link == findurl &&
1223 (Descr == findlabel ||
1224 (Link == findlabel && Descr == wxEmptyString))) {
1225 link->Link = LinkPropDlg->m_textCtrlLinkUrl->GetValue();
1227 LinkPropDlg->m_textCtrlLinkDescription->GetValue();
1228 wxHyperlinkCtrl* h =
1229 (wxHyperlinkCtrl*)m_scrolledWindowLinks->FindWindowByLabel(
1232 h->SetLabel(LinkPropDlg->m_textCtrlLinkDescription->GetValue());
1233 h->SetURL(LinkPropDlg->m_textCtrlLinkUrl->GetValue());
1236 linknode = linknode->GetNext();
1240 m_scrolledWindowLinks->InvalidateBestSize();
1241 m_scrolledWindowLinks->Layout();
1242 bSizerLinks->Layout();
1248void RoutePropDlgImpl::ItemAddOnMenuSelection(wxCommandEvent& event) {
1249 AddLinkOnButtonClick(event);
1253 wxHyperlinkListNode* nodeToDelete = NULL;
1254 wxString findurl = m_pEditedLink->GetURL();
1255 wxString findlabel = m_pEditedLink->GetLabel();
1257 wxWindowList kids = m_scrolledWindowLinks->GetChildren();
1258 for (
unsigned int i = 0; i < kids.GetCount(); i++) {
1259 wxWindowListNode* node = kids.Item(i);
1260 wxWindow* win = node->GetData();
1262 if (win->IsKindOf(CLASSINFO(wxHyperlinkCtrl))) {
1263 ((wxHyperlinkCtrl*)win)
1265 wxEVT_COMMAND_HYPERLINK,
1266 wxHyperlinkEventHandler(RoutePropDlgImpl::OnHyperlinkClick));
1267 ((wxHyperlinkCtrl*)win)
1270 wxMouseEventHandler(RoutePropDlgImpl::HyperlinkContextMenu));
1276 int NbrOfLinks = m_pRoute->m_HyperlinkList->GetCount();
1277 HyperlinkList* hyperlinklist = m_pRoute->m_HyperlinkList;
1279 if (NbrOfLinks > 0) {
1280 wxHyperlinkListNode* linknode = hyperlinklist->GetFirst();
1283 wxString Link = link->Link;
1284 wxString Descr = link->DescrText;
1285 if (Link == findurl &&
1286 (Descr == findlabel || (Link == findlabel && Descr == wxEmptyString)))
1287 nodeToDelete = linknode;
1289 wxHyperlinkCtrl* ctrl =
new wxHyperlinkCtrl(
1290 m_scrolledWindowLinks, wxID_ANY, Descr, Link, wxDefaultPosition,
1291 wxDefaultSize, wxHL_DEFAULT_STYLE);
1293 wxEVT_COMMAND_HYPERLINK,
1294 wxHyperlinkEventHandler(RoutePropDlgImpl::OnHyperlinkClick), NULL,
1298 wxMouseEventHandler(RoutePropDlgImpl::HyperlinkContextMenu), NULL,
1301 bSizerLinks->Add(ctrl, 0, wxALL, 5);
1303 linknode = linknode->GetNext();
1307 hyperlinklist->DeleteNode(nodeToDelete);
1309 m_scrolledWindowLinks->InvalidateBestSize();
1310 m_scrolledWindowLinks->Layout();
1311 bSizerLinks->Layout();
1315void RoutePropDlgImpl::AddLinkOnButtonClick(wxCommandEvent& event) {
1317 LinkPropDlg->m_textCtrlLinkDescription->SetValue(wxEmptyString);
1318 LinkPropDlg->m_textCtrlLinkUrl->SetValue(wxEmptyString);
1319 DimeControl(LinkPropDlg);
1320 LinkPropDlg->ShowWindowModalThenDo([
this, LinkPropDlg](
int retcode) {
1321 if (retcode == wxID_OK) {
1322 wxString desc = LinkPropDlg->m_textCtrlLinkDescription->GetValue();
1323 if (desc == wxEmptyString)
1324 desc = LinkPropDlg->m_textCtrlLinkUrl->GetValue();
1325 wxHyperlinkCtrl* ctrl =
new wxHyperlinkCtrl(
1326 m_scrolledWindowLinks, wxID_ANY, desc,
1327 LinkPropDlg->m_textCtrlLinkUrl->GetValue(), wxDefaultPosition,
1328 wxDefaultSize, wxHL_DEFAULT_STYLE);
1329 ctrl->Connect(wxEVT_COMMAND_HYPERLINK,
1330 wxHyperlinkEventHandler(RoutePropDlgImpl::OnHyperlinkClick),
1332 ctrl->Connect(wxEVT_RIGHT_DOWN,
1333 wxMouseEventHandler(RoutePropDlgImpl::HyperlinkContextMenu),
1336 bSizerLinks->Add(ctrl, 0, wxALL, 5);
1337 m_scrolledWindowLinks->InvalidateBestSize();
1338 m_scrolledWindowLinks->Layout();
1339 bSizerLinks->Layout();
1342 h->DescrText = LinkPropDlg->m_textCtrlLinkDescription->GetValue();
1343 h->Link = LinkPropDlg->m_textCtrlLinkUrl->GetValue();
1344 h->LType = wxEmptyString;
1345 m_pRoute->m_HyperlinkList->Append(h);
1350void RoutePropDlgImpl::BtnEditOnToggleButton(wxCommandEvent& event) {
1351 if (m_toggleBtnEdit->GetValue()) {
1352 m_stEditEnabled->SetLabel(_(
"Links are opened for editing."));
1354 m_stEditEnabled->SetLabel(_(
"Links are opened in the default browser."));
1359void RoutePropDlgImpl::OnHyperlinkClick(wxHyperlinkEvent& event) {
1360 if (m_toggleBtnEdit->GetValue()) {
1361 m_pEditedLink = (wxHyperlinkCtrl*)event.GetEventObject();
1362 ItemEditOnMenuSelection(event);
1375 wxString cc =
event.GetURL();
1376 if (cc.Find(_T(
"#")) != wxNOT_FOUND) {
1378 wxString(_T(
"HKEY_CLASSES_ROOT\\HTTP\\shell\\open\\command")));
1379 if (RegKey.Exists()) {
1380 wxString command_line;
1381 RegKey.QueryValue(wxString(_T(
"")), command_line);
1384 command_line.Replace(wxString(_T(
"\"")), wxString(_T(
"")));
1387 int l = command_line.Find(_T(
".exe"));
1388 if (wxNOT_FOUND == l) l = command_line.Find(_T(
".EXE"));
1390 if (wxNOT_FOUND != l) {
1391 wxString cl = command_line.Mid(0, l + 4);
1393 cc.Prepend(_T(
"\""));
1394 cc.Append(_T(
"\""));
1402 wxString url =
event.GetURL();
1403 url.Replace(_T(
" "), _T(
"%20"));
1404 ::wxLaunchDefaultBrowser(url);
1408void RoutePropDlgImpl::HyperlinkContextMenu(wxMouseEvent& event) {
1409 m_pEditedLink = (wxHyperlinkCtrl*)event.GetEventObject();
1410 m_scrolledWindowLinks->PopupMenu(
1411 m_menuLink, m_pEditedLink->GetPosition().x +
event.GetPosition().x,
1412 m_pEditedLink->GetPosition().y +
event.GetPosition().y);
void ItemDeleteOnMenuSelection(wxCommandEvent &event)
bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes)