37#include "ais_decoder.h"
39#include "routemanagerdialog.h"
40#include "routeman_gui.h"
41#include "route_point.h"
47#include "ocpn_frame.h"
49#include "nav_object_database.h"
51#include "TrackPropDlg.h"
54extern bool g_bShowShipToActive;
55extern bool g_bAllowShipToActive;
56extern bool g_bAdvanceRouteWaypointOnArrivalOnly;
63extern std::vector<Track*> g_TrackList;
69bool RoutemanGui::UpdateProgress() {
70 bool bret_val =
false;
72 if (m_routeman.pActiveRoute) {
78 toSM(m_routeman.pActivePoint->m_lat, m_routeman.pActivePoint->m_lon,
79 gLat, gLon, &east, &north);
80 double a = atan(north / east);
81 if (fabs(m_routeman.pActivePoint->m_lon - gLon) < 180.) {
82 if (m_routeman.pActivePoint->m_lon > gLon)
83 m_routeman.CurrentBrgToActivePoint = 90. - (a * 180 / PI);
85 m_routeman.CurrentBrgToActivePoint = 270. - (a * 180 / PI);
87 if (m_routeman.pActivePoint->m_lon > gLon)
88 m_routeman.CurrentBrgToActivePoint = 270. - (a * 180 / PI);
90 m_routeman.CurrentBrgToActivePoint = 90. - (a * 180 / PI);
96 DistGreatCircle(gLat, gLon, m_routeman.pActivePoint->m_lat, m_routeman.pActivePoint->m_lon);
97 m_routeman.CurrentRngToActivePoint = d5;
102 double brg1, dist1, brg2, dist2;
103 DistanceBearingMercator(m_routeman.pActivePoint->m_lat, m_routeman.pActivePoint->m_lon,
104 m_routeman.pActiveRouteSegmentBeginPoint->m_lat,
105 m_routeman.pActiveRouteSegmentBeginPoint->m_lon, &brg1,
107 vb.x = dist1 * sin(brg1 * PI / 180.);
108 vb.y = dist1 * cos(brg1 * PI / 180.);
110 DistanceBearingMercator(m_routeman.pActivePoint->m_lat, m_routeman.pActivePoint->m_lon, gLat,
111 gLon, &brg2, &dist2);
112 va.x = dist2 * sin(brg2 * PI / 180.);
113 va.y = dist2 * cos(brg2 * PI / 180.);
115 double sdelta = vGetLengthOfNormal(&va, &vb, &vn);
116 m_routeman.CurrentXTEToActivePoint = sdelta;
121 vector2D vToArriveNormal;
122 vSubtractVectors(&va, &vn, &vToArriveNormal);
124 m_routeman.CurrentRangeToActiveNormalCrossing =
125 vVectorMagnitude(&vToArriveNormal);
129 double x1, y1, x2, y2;
130 toSM(m_routeman.pActiveRouteSegmentBeginPoint->m_lat,
131 m_routeman.pActiveRouteSegmentBeginPoint->m_lon,
132 m_routeman.pActiveRouteSegmentBeginPoint->m_lat,
133 m_routeman.pActiveRouteSegmentBeginPoint->m_lon, &x1, &y1);
135 toSM(m_routeman.pActivePoint->m_lat, m_routeman.pActivePoint->m_lon,
136 m_routeman.pActiveRouteSegmentBeginPoint->m_lat,
137 m_routeman.pActiveRouteSegmentBeginPoint->m_lon, &x2, &y2);
139 double e1 = atan2((x2 - x1), (y2 - y1));
140 m_routeman.CurrentSegmentCourse = e1 * 180 / PI;
141 if (m_routeman.CurrentSegmentCourse < 0)
142 m_routeman.CurrentSegmentCourse += 360;
145 double h = atan(vn.y / vn.x);
147 m_routeman.CourseToRouteSegment = 90. - (h * 180 / PI);
149 m_routeman.CourseToRouteSegment = 270. - (h * 180 / PI);
151 h = m_routeman.CurrentBrgToActivePoint - m_routeman.CourseToRouteSegment;
152 if (h < 0) h = h + 360;
155 m_routeman.XTEDir = 1;
157 m_routeman.XTEDir = -1;
161 if (g_bShowShipToActive) {
162 if (m_routeman.pActiveRoute->GetIndexOf(m_routeman.pActivePoint) == 1)
163 g_bAllowShipToActive =
true;
168 ll_gc_ll(gLat, gLon, m_routeman.CourseToRouteSegment,
169 (m_routeman.CurrentXTEToActivePoint / 1.852), &tlat, &tlon);
170 gFrame->GetFocusCanvas()->GetCanvasPointPix(gLat, gLon, &r1);
171 gFrame->GetFocusCanvas()->GetCanvasPointPix(tlat, tlon, &r);
173 sqrt(pow((
double)(r1.x - r.x), 2) + pow((
double)(r1.y - r.y), 2));
175 double xtemm = xtepix / gFrame->GetFocusCanvas()->GetPixPerMM();
177 g_bAllowShipToActive = (xtemm > 3.0) ?
true :
false;
183 bool bDidArrival =
false;
187 if (m_routeman.pActivePoint->GetWaypointArrivalRadius() > 0) {
188 if (m_routeman.CurrentRangeToActiveNormalCrossing <=
189 m_routeman.pActivePoint->GetWaypointArrivalRadius()) {
190 m_routeman.m_bArrival =
true;
191 m_routeman.UpdateAutopilot();
200 if ((m_routeman.CurrentRangeToActiveNormalCrossing - m_routeman.m_arrival_min) >
201 m_routeman.pActivePoint->GetWaypointArrivalRadius()) {
202 if (++m_routeman.m_arrival_test > 2 &&
203 !g_bAdvanceRouteWaypointOnArrivalOnly)
205 m_routeman.m_bArrival =
true;
206 m_routeman.UpdateAutopilot();
212 m_routeman.m_arrival_test = 0;
216 m_routeman.m_arrival_min = wxMin(m_routeman.m_arrival_min,
217 m_routeman.CurrentRangeToActiveNormalCrossing);
219 if (!bDidArrival) m_routeman.UpdateAutopilot();
222 m_routeman.m_bDataValid =
true;
226void RoutemanGui::DeleteTrack(
Track *pTrack) {
228 if (pTrack->m_bIsInLayer)
return;
230 ::wxBeginBusyCursor();
232 wxGenericProgressDialog *pprog =
nullptr;
234 int count = pTrack->GetnPoints();
236 pprog =
new wxGenericProgressDialog(
237 _(
"OpenCPN Track Delete"), _T(
"0/0"), count, NULL,
238 wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_ELAPSED_TIME |
239 wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME);
240 pprog->SetSize(400, wxDefaultCoord);
243 if (TrackPropDlg::getInstanceFlag() && pTrackPropDialog &&
244 (pTrackPropDialog->IsShown()) &&
245 (pTrack == pTrackPropDialog->GetTrack())) {
246 pTrackPropDialog->Hide();
249 if ((pTrack == g_pActiveTrack) && pTrack->IsRunning()){
250 pTrack = gFrame->TrackOff();
253 pSelect->DeleteAllSelectableTrackSegments(pTrack);
254 auto it = std::find(g_TrackList.begin(), g_TrackList.end(), pTrack);
255 if (it != g_TrackList.end()) {
256 g_TrackList.erase(it);
266void RoutemanGui::DeleteAllTracks() {
269 ::wxBeginBusyCursor();
274 std::vector<Track*> to_del = g_TrackList;
275 for (
Track *ptrack : to_del) {
276 if (ptrack->m_bIsInLayer)
continue;
278 g_pAIS->DeletePersistentTrack(ptrack);
279 NavObjectChanges::getInstance()->m_bSkipChangeSetUpdate =
true;
280 NavObjectChanges::getInstance()->DeleteConfigTrack(ptrack);
282 NavObjectChanges::getInstance()->m_bSkipChangeSetUpdate =
false;
285 if (pConfig && pConfig->IsChangesFileDirty()) {
286 pConfig->UpdateNavObj(
true);
292void RoutemanGui::DoAdvance(
void) {
295 Route *pthis_route = m_routeman.pActiveRoute;
296 m_routeman.DeactivateRoute(
true);
298 if (pthis_route->m_bDeleteOnArrival && !pthis_route->m_bIsBeingEdited) {
299 NavObjectChanges::getInstance()->DeleteConfigRoute(pthis_route);
300 m_routeman.
DeleteRoute(pthis_route, NavObjectChanges::getInstance());
303 if (pRouteManagerDialog) pRouteManagerDialog->UpdateRouteListCtrl();
bool ActivateNextPoint(Route *pr, bool skipped)
bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes)