42#include "model/nav_object_database.h"
58static bool ConfirmDeleteAisMob() {
59 int r = OCPNMessageBox(NULL,
60 _(
"You are trying to delete an active AIS MOB "
61 "route, are you REALLY sure?"),
62 _(
"OpenCPN Warning"), wxYES_NO);
69 ctx.confirm_delete_ais_mob = []() {
return ConfirmDeleteAisMob(); };
70 ctx.get_global_colour = [](wxString c) {
return GetGlobalColor(c); };
71 ctx.show_with_fresh_fonts = [] {
72 if (
console && !g_bhide_route_console)
console->ShowWithFreshFonts();
74 ctx.clear_console_background = []() {
75 console->GetCDI()->ClearBackground();
78 ctx.route_mgr_dlg_update_list_ctrl = []() {
79 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
80 pRouteManagerDialog->UpdateRouteListCtrl();
85bool RoutemanGui::UpdateProgress() {
86 bool bret_val =
false;
88 if (m_routeman.pActiveRoute) {
94 toSM(m_routeman.pActivePoint->m_lat, m_routeman.pActivePoint->m_lon,
gLat,
96 double a = atan(north / east);
97 if (fabs(m_routeman.pActivePoint->m_lon -
gLon) < 180.) {
98 if (m_routeman.pActivePoint->m_lon >=
gLon)
99 m_routeman.CurrentBrgToActivePoint = 90. - (a * 180 / PI);
101 m_routeman.CurrentBrgToActivePoint = 270. - (a * 180 / PI);
103 if (m_routeman.pActivePoint->m_lon >=
gLon)
104 m_routeman.CurrentBrgToActivePoint = 270. - (a * 180 / PI);
106 m_routeman.CurrentBrgToActivePoint = 90. - (a * 180 / PI);
111 double d5 = DistGreatCircle(
gLat,
gLon, m_routeman.pActivePoint->m_lat,
112 m_routeman.pActivePoint->m_lon);
113 m_routeman.CurrentRngToActivePoint = d5;
118 double brg1, dist1, brg2, dist2;
119 DistanceBearingMercator(
120 m_routeman.pActivePoint->m_lat, m_routeman.pActivePoint->m_lon,
121 m_routeman.pActiveRouteSegmentBeginPoint->m_lat,
122 m_routeman.pActiveRouteSegmentBeginPoint->m_lon, &brg1, &dist1);
123 vb.x = dist1 * sin(brg1 * PI / 180.);
124 vb.y = dist1 * cos(brg1 * PI / 180.);
126 DistanceBearingMercator(m_routeman.pActivePoint->m_lat,
127 m_routeman.pActivePoint->m_lon,
gLat,
gLon, &brg2,
129 va.x = dist2 * sin(brg2 * PI / 180.);
130 va.y = dist2 * cos(brg2 * PI / 180.);
132 double sdelta = vGetLengthOfNormal(&va, &vb, &vn);
133 m_routeman.CurrentXTEToActivePoint = sdelta;
138 vector2D vToArriveNormal;
139 vSubtractVectors(&va, &vn, &vToArriveNormal);
141 m_routeman.CurrentRangeToActiveNormalCrossing =
142 vVectorMagnitude(&vToArriveNormal);
146 double x1, y1, x2, y2;
147 toSM(m_routeman.pActiveRouteSegmentBeginPoint->m_lat,
148 m_routeman.pActiveRouteSegmentBeginPoint->m_lon,
149 m_routeman.pActiveRouteSegmentBeginPoint->m_lat,
150 m_routeman.pActiveRouteSegmentBeginPoint->m_lon, &x1, &y1);
152 toSM(m_routeman.pActivePoint->m_lat, m_routeman.pActivePoint->m_lon,
153 m_routeman.pActiveRouteSegmentBeginPoint->m_lat,
154 m_routeman.pActiveRouteSegmentBeginPoint->m_lon, &x2, &y2);
156 double e1 = atan2((x2 - x1), (y2 - y1));
157 m_routeman.CurrentSegmentCourse = e1 * 180 / PI;
158 if (m_routeman.CurrentSegmentCourse < 0)
159 m_routeman.CurrentSegmentCourse += 360;
162 double h = atan(vn.y / vn.x);
164 m_routeman.CourseToRouteSegment = 90. - (h * 180 / PI);
166 m_routeman.CourseToRouteSegment = 270. - (h * 180 / PI);
168 h = m_routeman.CurrentBrgToActivePoint - m_routeman.CourseToRouteSegment;
169 if (h < 0) h = h + 360;
172 m_routeman.XTEDir = 1;
174 m_routeman.XTEDir = -1;
178 if (g_bShowShipToActive) {
179 if (m_routeman.pActiveRoute->GetIndexOf(m_routeman.pActivePoint) == 1)
180 g_bAllowShipToActive =
true;
185 ll_gc_ll(
gLat,
gLon, m_routeman.CourseToRouteSegment,
186 (m_routeman.CurrentXTEToActivePoint / 1.852), &tlat, &tlon);
190 sqrt(pow((
double)(r1.x - r.x), 2) + pow((
double)(r1.y - r.y), 2));
192 double xtemm = xtepix / gFrame->GetFocusCanvas()->
GetPixPerMM();
194 g_bAllowShipToActive = (xtemm > 3.0) ?
true : false;
200 bool bDidArrival =
false;
203 if (isnan(m_routeman.CurrentRangeToActiveNormalCrossing)) {
204 m_routeman.CurrentRangeToActiveNormalCrossing =
205 m_routeman.CurrentRngToActivePoint;
210 if (m_routeman.pActivePoint->GetWaypointArrivalRadius() > 0) {
211 if (m_routeman.CurrentRangeToActiveNormalCrossing <=
212 m_routeman.pActivePoint->GetWaypointArrivalRadius()) {
213 m_routeman.m_bArrival =
true;
214 m_routeman.UpdateAutopilot();
223 if ((m_routeman.CurrentRangeToActiveNormalCrossing -
224 m_routeman.m_arrival_min) >
225 m_routeman.pActivePoint->GetWaypointArrivalRadius()) {
226 if (++m_routeman.m_arrival_test > 2 &&
227 !g_bAdvanceRouteWaypointOnArrivalOnly) {
228 m_routeman.m_bArrival =
true;
229 m_routeman.UpdateAutopilot();
235 m_routeman.m_arrival_test = 0;
239 m_routeman.m_arrival_min =
240 wxMin(m_routeman.m_arrival_min,
241 m_routeman.CurrentRangeToActiveNormalCrossing);
243 if (!bDidArrival) m_routeman.UpdateAutopilot();
246 m_routeman.m_bDataValid =
true;
250void RoutemanGui::DeleteTrack(
Track *pTrack) {
252 if (pTrack->m_bIsInLayer)
return;
254 ::wxBeginBusyCursor();
256 wxGenericProgressDialog *pprog =
nullptr;
258 int count = pTrack->GetnPoints();
260 pprog =
new wxGenericProgressDialog(
261 _(
"OpenCPN Track Delete"),
"0/0", count, NULL,
262 wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_ELAPSED_TIME |
263 wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME);
264 pprog->SetSize(400, wxDefaultCoord);
274 pTrack = gFrame->TrackOff();
277 pSelect->DeleteAllSelectableTrackSegments(pTrack);
290void RoutemanGui::DeleteAllTracks() {
293 ::wxBeginBusyCursor();
299 for (
Track *ptrack : to_del) {
300 if (ptrack->m_bIsInLayer)
continue;
302 g_pAIS->DeletePersistentTrack(ptrack);
303 NavObj_dB::GetInstance().DeleteTrack(ptrack);
309void RoutemanGui::DoAdvance() {
313 Route *pthis_route = m_routeman.pActiveRoute;
314 m_routeman.DeactivateRoute(
true);
320 if (pRouteManagerDialog) pRouteManagerDialog->UpdateRouteListCtrl();
AisDecoder * g_pAIS
Global instance.
Class AisDecoder and helpers.
Generic Chart canvas base.
bool GetCanvasPointPix(double rlat, double rlon, wxPoint *r)
Convert latitude/longitude to canvas pixel coordinates (physical pixels) rounded to nearest integer.
double GetPixPerMM()
Get the number of logical pixels per millimeter on the screen.
Represents a navigational route in the navigation system.
bool m_bDeleteOnArrival
Flag indicating whether the route should be deleted once navigation reaches the end.
bool m_bIsBeingEdited
Flag indicating that the route is currently being edited by the user.
bool ActivateNextPoint(Route *pr, bool skipped)
Activates the next waypoint in a route when the current waypoint is reached.
bool DeleteRoute(Route *pRoute)
Represents a track, which is a series of connected track points.
APConsole * console
Global instance.
Primary navigation console display for route and vessel tracking.
Global variables stored in configuration file.
Miscellaneous globals primarely used by gui layer, not persisted in configuration file.
MySQL based storage for routes, tracks, etc.
double gLat
Vessel's current latitude in decimal degrees.
double gLon
Vessel's current longitude in decimal degrees.
Position, course, speed, etc.
Waypoint or mark abstraction.
Select * pSelect
Global instance.
Selected route, segment, waypoint, etc.
ActiveTrack * g_pActiveTrack
global instance
std::vector< Track * > g_TrackList
Global instance.
Recorded track abstraction.
TrackPropDlg * pTrackPropDialog
Global instance.