36#include <wx/jsonval.h>
37#include <wx/listimpl.cpp>
38#include <wx/tokenzr.h>
40#include "model/ais_decoder.h"
41#include "model/autopilot_output.h"
42#include "model/base_platform.h"
43#include "model/comm_n0183_output.h"
44#include "model/comm_vars.h"
45#include "model/config_vars.h"
46#include "model/cutil.h"
47#include "model/georef.h"
48#include "model/nav_object_database.h"
49#include "model/navutil_base.h"
50#include "model/nmea_ctx_factory.h"
51#include "model/own_ship.h"
52#include "model/route.h"
53#include "model/routeman.h"
54#include "model/track.h"
56#include "observable_globvar.h"
61#include "androidUTIL.h"
64bool g_bPluginHandleAutopilotRoute;
74float g_ChartScaleFactorExp;
77WX_DECLARE_LIST(wxBitmap, markicon_bitmap_list_type);
78WX_DECLARE_LIST(wxString, markicon_key_list_type);
79WX_DECLARE_LIST(wxString, markicon_description_list_type);
82#include <wx/listimpl.cpp>
83WX_DEFINE_LIST(markicon_bitmap_list_type);
84WX_DEFINE_LIST(markicon_key_list_type);
85WX_DEFINE_LIST(markicon_description_list_type);
88void appendOSDirSlash(wxString *pString);
90static void ActivatePersistedRoute(
Routeman *routeman) {
91 if (g_active_route ==
"") {
92 wxLogWarning(
"\"Persist route\" but no persisted route configured");
95 Route *route = routeman->FindRouteByGUID(g_active_route);
97 wxLogWarning(
"Persisted route GUID not available");
111 pRouteActivatePoint(0),
112 m_NMEA0183(NmeaCtxFactory()),
114 m_route_dlg_ctx(route_dlg_ctx) {
116 auto route_action = [&](wxCommandEvent) {
117 if (g_persist_active_route) ActivatePersistedRoute(
this);
119 active_route_listener.Init(active_route, route_action);
122Routeman::~Routeman() {
123 if (pRouteActivatePoint)
delete pRouteActivatePoint;
126bool Routeman::IsRouteValid(
Route *pRoute) {
127 wxRouteListNode *node = pRouteList->GetFirst();
129 if (pRoute == node->GetData())
return true;
130 node = node->GetNext();
137 wxRouteListNode *node = pRouteList->GetFirst();
139 Route *proute = node->GetData();
144 if (prp == pWP)
return proute;
145 pnode = pnode->GetNext();
148 node = node->GetNext();
156 wxRouteListNode *node = pRouteList->GetFirst();
158 Route *proute = node->GetData();
159 if (proute->IsVisible()) {
163 if (prp == pWP)
return proute;
164 pnode = pnode->GetNext();
168 node = node->GetNext();
175 wxArrayPtrVoid *pArray =
new wxArrayPtrVoid;
177 wxRouteListNode *route_node = pRouteList->GetFirst();
179 Route *proute = route_node->GetData();
181 wxRoutePointListNode *waypoint_node = (proute->
pRoutePointList)->GetFirst();
182 while (waypoint_node) {
185 pArray->Add((
void *)proute);
190 waypoint_node = waypoint_node->GetNext();
193 route_node = route_node->GetNext();
196 if (pArray->GetCount())
208 pSelect->DeleteAllSelectableRoutePoints(route);
209 pSelect->DeleteAllSelectableRouteSegments(route);
211 route->RemovePoint(point);
215 if (route->GetnPoints() <= 1 && route_state == 0) {
216 NavObjectChanges::getInstance()->DeleteConfigRoute(route);
217 g_pRouteMan->
DeleteRoute(route, NavObjectChanges::getInstance());
221 pSelect->AddSelectableRoutePoint(point->m_lat, point->m_lon, point);
226 m_prop_dlg_ctx.set_route_and_update(route);
229RoutePoint *Routeman::FindBestActivatePoint(
Route *pR,
double lat,
double lon,
230 double cog,
double sog) {
231 if (!pR)
return NULL;
235 double min_time_found = 1e6;
242 DistanceBearingMercator(pn->m_lat, pn->m_lon, lat, lon, &brg, &dist);
244 double angle = brg - cog;
245 double soa = cos(angle * PI / 180.);
247 double time_to_wp = dist / soa;
249 if (time_to_wp > 0) {
250 if (time_to_wp < min_time_found) {
251 min_time_found = time_to_wp;
255 node = node->GetNext();
261 g_bAllowShipToActive =
false;
264 v[_T(
"GUID")] = pRouteToActivate->
m_GUID;
265 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_RTE_ACTIVATED");
266 if (g_bPluginHandleAutopilotRoute)
return true;
270 m_have_n0183_out =
false;
271 m_have_n2000_out =
false;
273 m_output_drivers.clear();
276 if (attributes.find(
"protocol") == attributes.end())
continue;
277 if (attributes.at(
"protocol") ==
"nmea0183") {
278 if (attributes.find(
"ioDirection") != attributes.end()) {
279 if ((attributes.at(
"ioDirection") ==
"IN/OUT") ||
280 (attributes.at(
"ioDirection") ==
"OUT")) {
281 m_output_drivers.push_back(handle);
282 m_have_n0183_out =
true;
288 if (attributes.at(
"protocol") ==
"nmea2000") {
289 m_output_drivers.push_back(handle);
290 m_have_n2000_out =
true;
295 pActiveRoute = pRouteToActivate;
296 g_active_route = pActiveRoute->GetGUID();
299 pActivePoint = pStartPoint;
301 wxRoutePointListNode *node = (pActiveRoute->
pRoutePointList)->GetFirst();
302 pActivePoint = node->GetData();
313 m_bDataValid =
false;
315 m_route_dlg_ctx.show_with_fresh_fonts();
320 g_bAllowShipToActive =
false;
322 v[_T(
"GUID")] = pRP_target->m_GUID;
323 v[_T(
"WP_activated")] = pRP_target->GetName();
325 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_WPT_ACTIVATED");
327 if (g_bPluginHandleAutopilotRoute)
return true;
331 pActivePoint = pRP_target;
334 wxRoutePointListNode *node = (pActiveRoute->
pRoutePointList)->GetFirst();
337 pn->m_bBlink =
false;
338 pn->m_bIsActive =
false;
340 node = node->GetNext();
348 if (pRP_target == prp_first) {
349 if (pRouteActivatePoint)
delete pRouteActivatePoint;
351 pRouteActivatePoint =
352 new RoutePoint(gLat, gLon, wxString(_T(
"")), wxString(_T(
"Begin")),
353 wxEmptyString,
false);
354 pRouteActivatePoint->m_bShowName =
false;
356 pActiveRouteSegmentBeginPoint = pRouteActivatePoint;
360 prp_first->m_bBlink =
false;
361 node = node->GetNext();
365 if (pnext == pRP_target) {
366 pActiveRouteSegmentBeginPoint = np_prev;
371 node = node->GetNext();
375 pRP_target->m_bBlink =
true;
376 pRP_target->m_bIsActive =
true;
378 g_blink_rect = pRP_target->CurrentRect_in_DC;
390 m_prop_dlg_ctx.set_enroute_point(pA, pActivePoint);
395 g_bAllowShipToActive =
false;
399 pActivePoint->m_bBlink =
false;
400 pActivePoint->m_bIsActive =
false;
402 v[_T(
"isSkipped")] = skipped;
403 v[_T(
"GUID")] = pActivePoint->m_GUID;
404 v[_T(
"GUID_WP_arrived")] = pActivePoint->m_GUID;
405 v[_T(
"WP_arrived")] = pActivePoint->GetName();
407 int n_index_active = pActiveRoute->GetIndexOf(pActivePoint);
409 while (n_index_active == pActiveRoute->GetIndexOf(pActivePoint)) {
410 if ((n_index_active + step) <= pActiveRoute->GetnPoints()) {
411 pActiveRouteSegmentBeginPoint = pActivePoint;
413 pActiveRoute->GetPoint(n_index_active + step);
414 pActivePoint = pActiveRoute->GetPoint(n_index_active + step);
423 v[_T(
"Next_WP")] = pActivePoint->GetName();
424 v[_T(
"GUID_Next_WP")] = pActivePoint->m_GUID;
426 pActivePoint->m_bBlink =
true;
427 pActivePoint->m_bIsActive =
true;
428 g_blink_rect = pActivePoint->CurrentRect_in_DC;
439 m_prop_dlg_ctx.set_enroute_point(pr, pActivePoint);
441 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_WPT_ARRIVED");
446bool Routeman::DeactivateRoute(
bool b_arrival) {
448 pActivePoint->m_bBlink =
false;
449 pActivePoint->m_bIsActive =
false;
455 g_active_route.Clear();
460 v[_T(
"GUID")] = pActiveRoute->
m_GUID;
461 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_RTE_DEACTIVATED");
463 v[_T(
"GUID")] = pActiveRoute->
m_GUID;
465 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_RTE_ENDED");
471 if (pRouteActivatePoint)
delete pRouteActivatePoint;
472 pRouteActivatePoint = NULL;
476 m_route_dlg_ctx.clear_console_background();
477 m_bDataValid =
false;
482bool Routeman::UpdateAutopilot() {
483 if (!bGPSValid)
return false;
488 if ((g_maxWPNameLength >= 3) && (g_maxWPNameLength <= 32))
489 maxName = g_maxWPNameLength;
493 auto& registry = CommDriverRegistry::GetInstance();
494 const std::vector<DriverPtr>& drivers = registry.GetDrivers();
497 bool have_n0183 =
false;
498 bool have_n2000 =
false;
501 for (
auto key : m_output_drivers) {
502 for (
auto &d : drivers) {
503 if (d->Key() == key) {
504 std::unordered_map<std::string, std::string> attributes =
506 auto protocol_it = attributes.find(
"protocol");
507 if (protocol_it != attributes.end()) {
508 std::string protocol = protocol_it->second;
510 if (protocol ==
"nmea0183") {
512 }
else if (protocol ==
"nmea2000") {
521 if (m_have_n0183_out) rv |= UpdateAutopilotN0183(*
this);
523 if (m_have_n2000_out) rv |= UpdateAutopilotN2K(*
this);
528 leg_info.Btw = CurrentBrgToActivePoint;
529 leg_info.Dtw = CurrentRngToActivePoint;
530 leg_info.Xte = CurrentXTEToActivePoint;
532 leg_info.Xte = -leg_info.Xte;
534 leg_info.wp_name = pActivePoint->GetName().Truncate(maxName);
535 leg_info.arrival = m_bArrival;
546 if ((g_maxWPNameLength >= 3) && (g_maxWPNameLength <= 32))
547 maxName = g_maxWPNameLength;
551 double r_Sog(0.0), r_Cog(0.0);
552 if (!std::isnan(gSog)) r_Sog = gSog;
553 if (!std::isnan(gCog)) r_Cog = gCog;
558 leg_info.Btw = CurrentBrgToActivePoint;
559 leg_info.Dtw = CurrentRngToActivePoint;
560 leg_info.Xte = CurrentXTEToActivePoint;
562 leg_info.Xte = -leg_info.Xte;
564 leg_info.wp_name = pActivePoint->GetName().Truncate(maxName);
565 leg_info.arrival = m_bArrival;
571 m_NMEA0183.TalkerID =
"EC";
573 m_NMEA0183.Rmb.IsDataValid = bGPSValid ? NTrue : NFalse;
574 m_NMEA0183.Rmb.CrossTrackError = CurrentXTEToActivePoint;
575 m_NMEA0183.Rmb.DirectionToSteer = XTEDir < 0 ? Left : Right;
576 m_NMEA0183.Rmb.RangeToDestinationNauticalMiles = CurrentRngToActivePoint;
577 m_NMEA0183.Rmb.BearingToDestinationDegreesTrue = CurrentBrgToActivePoint;
579 if (pActivePoint->m_lat < 0.)
580 m_NMEA0183.Rmb.DestinationPosition.Latitude.Set(-pActivePoint->m_lat,
583 m_NMEA0183.Rmb.DestinationPosition.Latitude.Set(pActivePoint->m_lat,
"N");
585 if (pActivePoint->m_lon < 0.)
586 m_NMEA0183.Rmb.DestinationPosition.Longitude.Set(-pActivePoint->m_lon,
589 m_NMEA0183.Rmb.DestinationPosition.Longitude.Set(pActivePoint->m_lon,
592 m_NMEA0183.Rmb.DestinationClosingVelocityKnots =
593 r_Sog * cos((r_Cog - CurrentBrgToActivePoint) * PI / 180.0);
594 m_NMEA0183.Rmb.IsArrivalCircleEntered = m_bArrival ? NTrue : NFalse;
595 m_NMEA0183.Rmb.FAAModeIndicator = bGPSValid ?
"A" :
"N";
598 int wp_len = maxName;
600 m_NMEA0183.Rmb.To = pActivePoint->GetName().Truncate(wp_len);
601 m_NMEA0183.Rmb.From =
602 pActiveRouteSegmentBeginPoint->GetName().Truncate(wp_len);
603 m_NMEA0183.Rmb.Write(snt);
605 }
while (snt.Sentence.size() > 82 && wp_len > 0);
612 m_NMEA0183.TalkerID = _T(
"EC");
615 m_NMEA0183.Rmc.IsDataValid = NTrue;
616 if (!bGPSValid) m_NMEA0183.Rmc.IsDataValid = NFalse;
619 m_NMEA0183.Rmc.Position.Latitude.Set(-gLat, _T(
"S"));
621 m_NMEA0183.Rmc.Position.Latitude.Set(gLat, _T(
"N"));
624 m_NMEA0183.Rmc.Position.Longitude.Set(-gLon, _T(
"W"));
626 m_NMEA0183.Rmc.Position.Longitude.Set(gLon, _T(
"E"));
628 m_NMEA0183.Rmc.SpeedOverGroundKnots = r_Sog;
629 m_NMEA0183.Rmc.TrackMadeGoodDegreesTrue = r_Cog;
631 if (!std::isnan(gVar)) {
633 m_NMEA0183.Rmc.MagneticVariation = -gVar;
634 m_NMEA0183.Rmc.MagneticVariationDirection = West;
636 m_NMEA0183.Rmc.MagneticVariation = gVar;
637 m_NMEA0183.Rmc.MagneticVariationDirection = East;
640 m_NMEA0183.Rmc.MagneticVariation =
644 if (!gRmcTime.IsEmpty() && !gRmcDate.IsEmpty()) {
645 m_NMEA0183.Rmc.UTCTime = gRmcTime;
646 m_NMEA0183.Rmc.Date = gRmcDate;
648 wxDateTime now = wxDateTime::Now();
649 wxDateTime utc = now.ToUTC();
650 wxString time = utc.Format(_T(
"%H%M%S"));
651 m_NMEA0183.Rmc.UTCTime = time;
652 wxString date = utc.Format(_T(
"%d%m%y"));
653 m_NMEA0183.Rmc.Date = date;
656 m_NMEA0183.Rmc.FAAModeIndicator =
"A";
657 if (!bGPSValid) m_NMEA0183.Rmc.FAAModeIndicator =
"N";
659 m_NMEA0183.Rmc.Write(snt);
666 m_NMEA0183.TalkerID = _T(
"EC");
670 m_NMEA0183.Apb.IsLoranBlinkOK =
672 if (!bGPSValid) m_NMEA0183.Apb.IsLoranBlinkOK = NFalse;
674 m_NMEA0183.Apb.IsLoranCCycleLockOK = NTrue;
675 if (!bGPSValid) m_NMEA0183.Apb.IsLoranCCycleLockOK = NFalse;
677 m_NMEA0183.Apb.CrossTrackErrorMagnitude = CurrentXTEToActivePoint;
680 m_NMEA0183.Apb.DirectionToSteer = Left;
682 m_NMEA0183.Apb.DirectionToSteer = Right;
684 m_NMEA0183.Apb.CrossTrackUnits = _T(
"N");
687 m_NMEA0183.Apb.IsArrivalCircleEntered = NTrue;
689 m_NMEA0183.Apb.IsArrivalCircleEntered = NFalse;
693 m_NMEA0183.Apb.IsPerpendicular = NFalse;
695 m_NMEA0183.Apb.To = pActivePoint->GetName().Truncate(maxName);
698 DistanceBearingMercator(pActivePoint->m_lat, pActivePoint->m_lon,
699 pActiveRouteSegmentBeginPoint->m_lat,
700 pActiveRouteSegmentBeginPoint->m_lon, &brg1,
703 if (g_bMagneticAPB && !std::isnan(gVar)) {
705 ((brg1 - gVar) >= 0.) ? (brg1 - gVar) : (brg1 - gVar + 360.);
706 double bapm = ((CurrentBrgToActivePoint - gVar) >= 0.)
707 ? (CurrentBrgToActivePoint - gVar)
708 : (CurrentBrgToActivePoint - gVar + 360.);
710 m_NMEA0183.Apb.BearingOriginToDestination = brg1m;
711 m_NMEA0183.Apb.BearingOriginToDestinationUnits = _T(
"M");
713 m_NMEA0183.Apb.BearingPresentPositionToDestination = bapm;
714 m_NMEA0183.Apb.BearingPresentPositionToDestinationUnits = _T(
"M");
716 m_NMEA0183.Apb.HeadingToSteer = bapm;
717 m_NMEA0183.Apb.HeadingToSteerUnits = _T(
"M");
719 m_NMEA0183.Apb.BearingOriginToDestination = brg1;
720 m_NMEA0183.Apb.BearingOriginToDestinationUnits = _T(
"T");
722 m_NMEA0183.Apb.BearingPresentPositionToDestination =
723 CurrentBrgToActivePoint;
724 m_NMEA0183.Apb.BearingPresentPositionToDestinationUnits = _T(
"T");
726 m_NMEA0183.Apb.HeadingToSteer = CurrentBrgToActivePoint;
727 m_NMEA0183.Apb.HeadingToSteerUnits = _T(
"T");
730 m_NMEA0183.Apb.Write(snt);
736 m_NMEA0183.TalkerID = _T(
"EC");
740 m_NMEA0183.Xte.IsLoranBlinkOK =
742 if (!bGPSValid) m_NMEA0183.Xte.IsLoranBlinkOK = NFalse;
744 m_NMEA0183.Xte.IsLoranCCycleLockOK = NTrue;
745 if (!bGPSValid) m_NMEA0183.Xte.IsLoranCCycleLockOK = NFalse;
747 m_NMEA0183.Xte.CrossTrackErrorDistance = CurrentXTEToActivePoint;
750 m_NMEA0183.Xte.DirectionToSteer = Left;
752 m_NMEA0183.Xte.DirectionToSteer = Right;
754 m_NMEA0183.Xte.CrossTrackUnits = _T(
"N");
756 m_NMEA0183.Xte.Write(snt);
764bool Routeman::DoesRouteContainSharedPoints(
Route *pRoute) {
776 for (
unsigned int ir = 0; ir < pRA->GetCount(); ir++) {
786 if (pnode) pnode = pnode->GetNext();
793 if (prp->IsShared())
return true;
795 if (pnode) pnode = pnode->GetNext();
802bool Routeman::DeleteTrack(
Track *pTrack) {
803 if (pTrack && !pTrack->m_bIsInLayer) {
804 ::wxBeginBusyCursor();
820 pSelect->DeleteAllSelectableTrackSegments(pTrack);
821 auto it = std::find(g_TrackList.begin(), g_TrackList.end(), pTrack);
822 if (it != g_TrackList.end()) {
823 g_TrackList.erase(it);
837 if (pRoute == pAISMOBRoute) {
838 if (!m_route_dlg_ctx.confirm_delete_ais_mob()) {
843 ::wxBeginBusyCursor();
845 if (GetpActiveRoute() == pRoute) DeactivateRoute();
855 m_prop_dlg_ctx.hide(pRoute);
857 nav_obj_changes->DeleteConfigRoute(pRoute);
860 pSelect->DeleteAllSelectableRouteSegments(pRoute);
861 pRouteList->DeleteObject(pRoute);
863 m_route_dlg_ctx.route_mgr_dlg_update_list_ctrl();
872 Route *pcontainer_route = FindRouteContainingWaypoint(prp);
874 if (pcontainer_route == NULL && prp->m_bIsInRoute) {
877 if (!prp->IsShared()) {
882 pSelect->DeleteSelectablePoint(prp, SELTYPE_ROUTEPOINT);
885 wxRoutePointListNode *pdnode = pnode;
895 prp->SetShared(
false);
899 pnode = pnode->GetNext();
912 ::wxBeginBusyCursor();
915 wxRouteListNode *node = pRouteList->GetFirst();
917 Route *proute = node->GetData();
918 if (proute == pAISMOBRoute) {
919 if (!m_route_dlg_ctx.confirm_delete_ais_mob()) {
923 ::wxBeginBusyCursor();
926 node = node->GetNext();
929 nav_obj_changes->m_bSkipChangeSetUpdate =
true;
930 nav_obj_changes->DeleteConfigRoute(proute);
932 nav_obj_changes->m_bSkipChangeSetUpdate =
false;
938void Routeman::SetColorScheme(ColorScheme cs,
double displayDPmm) {
941 int scaled_line_width = g_route_line_width;
942 int track_scaled_line_width = g_track_line_width;
945 double nominal_line_width_pix = wxMax(1.5, floor(displayDPmm / 5.0));
947 double sline_width = wxMax(nominal_line_width_pix, g_route_line_width);
948 sline_width *= g_ChartScaleFactorExp;
949 scaled_line_width = wxMax(sline_width, 2);
951 double tsline_width = wxMax(nominal_line_width_pix, g_track_line_width);
952 tsline_width *= g_ChartScaleFactorExp;
953 track_scaled_line_width = wxMax(tsline_width, 2);
956 m_pActiveRoutePointPen = wxThePenList->FindOrCreatePen(
957 wxColour(0, 0, 255), scaled_line_width, wxPENSTYLE_SOLID);
958 m_pRoutePointPen = wxThePenList->FindOrCreatePen(
959 wxColour(0, 0, 255), scaled_line_width, wxPENSTYLE_SOLID);
964 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"UINFB"),
965 scaled_line_width, wxPENSTYLE_SOLID);
966 m_pSelectedRoutePen =
967 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"UINFO"),
968 scaled_line_width, wxPENSTYLE_SOLID);
970 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"UARTE"),
971 scaled_line_width, wxPENSTYLE_SOLID);
973 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"CHMGD"),
974 track_scaled_line_width, wxPENSTYLE_SOLID);
975 m_pRouteBrush = wxTheBrushList->FindOrCreateBrush(
976 m_route_dlg_ctx.get_global_colour(
"UINFB"), wxBRUSHSTYLE_SOLID);
977 m_pSelectedRouteBrush = wxTheBrushList->FindOrCreateBrush(
978 m_route_dlg_ctx.get_global_colour(
"UINFO"), wxBRUSHSTYLE_SOLID);
979 m_pActiveRouteBrush = wxTheBrushList->FindOrCreateBrush(
980 m_route_dlg_ctx.get_global_colour(
"PLRTE"), wxBRUSHSTYLE_SOLID);
983wxString Routeman::GetRouteReverseMessage(
void) {
985 _(
"Waypoints can be renamed to reflect the new order, the names will be "
986 "'001', '002' etc.\n\nDo you want to rename the waypoints?"));
989wxString Routeman::GetRouteResequenceMessage(
void) {
991 _(
"Waypoints will be renamed to reflect the natural order, the names "
992 "will be '001', '002' etc.\n\nDo you want to rename the waypoints?"));
995Route *Routeman::FindRouteByGUID(
const wxString &guid) {
996 wxRouteListNode *node1 = pRouteList->GetFirst();
998 Route *pRoute = node1->GetData();
1000 if (pRoute->
m_GUID == guid)
return pRoute;
1001 node1 = node1->GetNext();
1007Track *Routeman::FindTrackByGUID(
const wxString &guid) {
1008 for (
Track *pTrack : g_TrackList) {
1009 if (pTrack->m_GUID == guid)
return pTrack;
1015void Routeman::ZeroCurrentXTEToActivePoint() {
1017 if (pRouteActivatePoint)
delete pRouteActivatePoint;
1018 pRouteActivatePoint =
1019 new RoutePoint(gLat, gLon, wxString(_T(
"")), wxString(_T(
"")),
1020 wxEmptyString,
false);
1021 pRouteActivatePoint->m_bShowName =
false;
1023 pActiveRouteSegmentBeginPoint = pRouteActivatePoint;
1024 m_arrival_min = 1e6;
1031WayPointman::WayPointman(GlobalColourFunc color_func)
1032 : m_get_global_colour(color_func) {
1033 m_pWayPointList =
new RoutePointList;
1035 pmarkicon_image_list = NULL;
1038 m_pIconArray =
new ArrayOfMarkIcon;
1039 m_pLegacyIconArray = NULL;
1040 m_pExtendedIconArray = NULL;
1042 m_cs = (ColorScheme)-1;
1045 m_iconListScale = -999.0;
1046 m_iconListHeight = -1;
1049WayPointman::~WayPointman() {
1055 RoutePointList temp_list;
1057 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1061 temp_list.Append(pr);
1062 node = node->GetNext();
1065 temp_list.DeleteContents(
true);
1068 m_pWayPointList->Clear();
1069 delete m_pWayPointList;
1071 for (
unsigned int i = 0; i < m_pIconArray->GetCount(); i++) {
1073 delete pmi->piconBitmap;
1077 m_pIconArray->Clear();
1078 delete m_pIconArray;
1080 if (pmarkicon_image_list) pmarkicon_image_list->RemoveAll();
1081 delete pmarkicon_image_list;
1082 m_pLegacyIconArray->Clear();
1083 delete m_pLegacyIconArray;
1084 m_pExtendedIconArray->Clear();
1085 delete m_pExtendedIconArray;
1089 if (!prp)
return false;
1091 wxRoutePointListNode *prpnode = m_pWayPointList->Append(prp);
1092 prp->SetManagerListNode(prpnode);
1098 if (!prp)
return false;
1100 wxRoutePointListNode *prpnode =
1101 (wxRoutePointListNode *)prp->GetManagerListNode();
1106 m_pWayPointList->DeleteObject(prp);
1108 prp->SetManagerListNode(NULL);
1113wxImageList *WayPointman::Getpmarkicon_image_list(
int nominal_height) {
1115 if (pmarkicon_image_list && (nominal_height == m_iconListHeight)) {
1116 return pmarkicon_image_list;
1120 if (NULL != pmarkicon_image_list) {
1121 pmarkicon_image_list->RemoveAll();
1122 delete pmarkicon_image_list;
1124 pmarkicon_image_list =
new wxImageList(nominal_height, nominal_height);
1126 m_iconListHeight = nominal_height;
1127 m_bitmapSizeForList = nominal_height;
1129 return pmarkicon_image_list;
1132wxBitmap *WayPointman::CreateDimBitmap(wxBitmap *pBitmap,
double factor) {
1133 wxImage img = pBitmap->ConvertToImage();
1134 int sx = img.GetWidth();
1135 int sy = img.GetHeight();
1137 wxImage new_img(img);
1139 for (
int i = 0; i < sx; i++) {
1140 for (
int j = 0; j < sy; j++) {
1141 if (!img.IsTransparent(i, j)) {
1142 new_img.SetRGB(i, j, (
unsigned char)(img.GetRed(i, j) * factor),
1143 (
unsigned char)(img.GetGreen(i, j) * factor),
1144 (
unsigned char)(img.GetBlue(i, j) * factor));
1149 wxBitmap *pret =
new wxBitmap(new_img);
1154wxImage WayPointman::CreateDimImage(wxImage &image,
double factor) {
1155 int sx = image.GetWidth();
1156 int sy = image.GetHeight();
1158 wxImage new_img(image);
1160 for (
int i = 0; i < sx; i++) {
1161 for (
int j = 0; j < sy; j++) {
1162 if (!image.IsTransparent(i, j)) {
1163 new_img.SetRGB(i, j, (
unsigned char)(image.GetRed(i, j) * factor),
1164 (
unsigned char)(image.GetGreen(i, j) * factor),
1165 (
unsigned char)(image.GetBlue(i, j) * factor));
1170 return wxImage(new_img);
1173bool WayPointman::DoesIconExist(
const wxString &icon_key)
const {
1177 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1178 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1179 if (pmi->icon_name.IsSameAs(icon_key))
return true;
1185wxBitmap *WayPointman::GetIconBitmap(
const wxString &icon_key)
const {
1186 wxBitmap *pret = NULL;
1190 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1191 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1192 if (pmi->icon_name.IsSameAs(icon_key))
break;
1195 if (i == m_pIconArray->GetCount())
1198 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1199 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1205 if (i == m_pIconArray->GetCount())
1206 pmi = (
MarkIcon *)m_pIconArray->Item(0);
1209 if (pmi->piconBitmap)
1210 pret = pmi->piconBitmap;
1212 if (pmi->iconImage.IsOk()) {
1213 pmi->piconBitmap =
new wxBitmap(pmi->iconImage);
1214 pret = pmi->piconBitmap;
1221bool WayPointman::GetIconPrescaled(
const wxString &icon_key)
const {
1225 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1226 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1227 if (pmi->icon_name.IsSameAs(icon_key))
break;
1230 if (i == m_pIconArray->GetCount())
1233 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1234 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1240 if (i == m_pIconArray->GetCount())
1241 pmi = (
MarkIcon *)m_pIconArray->Item(0);
1244 return pmi->preScaled;
1249wxBitmap WayPointman::GetIconBitmapForList(
int index,
int height)
const {
1254 pmi = (
MarkIcon *)m_pIconArray->Item(index);
1256 if (pmi->iconImage.GetHeight() != height) {
1259 int w0 = pmi->iconImage.GetWidth();
1260 int h0 = pmi->iconImage.GetHeight();
1262 wxImage icon_resized = pmi->iconImage;
1263 if (h0 <= h && w0 <= w) {
1264 icon_resized = pmi->iconImage.Resize(
1265 wxSize(w, h), wxPoint(w / 2 - w0 / 2, h / 2 - h0 / 2));
1272 w1 = wxRound((
double)w0 * ((
double)h / (
double)h0));
1275 h1 = wxRound((
double)h0 * ((
double)w / (
double)w0));
1277 icon_resized = pmi->iconImage.Rescale(w1, h1);
1278 icon_resized = pmi->iconImage.Resize(
1279 wxSize(w, h), wxPoint(w / 2 - w1 / 2, h / 2 - h1 / 2));
1282 pret = wxBitmap(icon_resized);
1285 pret = wxBitmap(pmi->iconImage);
1291wxString *WayPointman::GetIconDescription(
int index)
const {
1292 wxString *pret = NULL;
1296 pret = &pmi->icon_description;
1301wxString WayPointman::GetIconDescription(wxString icon_key)
const {
1305 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1306 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1307 if (pmi->icon_name.IsSameAs(icon_key))
1308 return wxString(pmi->icon_description);
1311 return wxEmptyString;
1314wxString *WayPointman::GetIconKey(
int index)
const {
1315 wxString *pret = NULL;
1317 if ((index >= 0) && ((
unsigned int)index < m_pIconArray->GetCount())) {
1319 pret = &pmi->icon_name;
1324int WayPointman::GetIconIndex(
const wxBitmap *pbm)
const {
1325 unsigned int ret = 0;
1328 wxASSERT(m_pIconArray->GetCount() >= 1);
1329 for (
unsigned int i = 0; i < m_pIconArray->GetCount(); i++) {
1330 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1331 if (pmi->piconBitmap == pbm) {
1340int WayPointman::GetIconImageListIndex(
const wxBitmap *pbm)
const {
1344 if (pmarkicon_image_list && !pmi->m_blistImageOK) {
1345 int h0 = pmi->iconImage.GetHeight();
1346 int w0 = pmi->iconImage.GetWidth();
1347 int h = m_bitmapSizeForList;
1348 int w = m_bitmapSizeForList;
1350 wxImage icon_larger = pmi->iconImage;
1351 if (h0 <= h && w0 <= w) {
1352 icon_larger = pmi->iconImage.Resize(
1353 wxSize(w, h), wxPoint(w / 2 - w0 / 2, h / 2 - h0 / 2));
1362 w1 = wxRound((
double)w0 * ((
double)h / (
double)h0));
1365 h1 = wxRound((
double)h0 * ((
double)w / (
double)w0));
1367 icon_larger = pmi->iconImage.Rescale(w1, h1).Resize(
1368 wxSize(w, h), wxPoint(w / 2 - w1 / 2, h / 2 - h1 / 2));
1371 int index = pmarkicon_image_list->Add(wxBitmap(icon_larger));
1376 icon_larger.ConvertAlphaToMask(128);
1378 unsigned char r, g, b;
1379 icon_larger.GetOrFindMaskColour(&r, &g, &b);
1380 wxColour unused_color(r, g, b);
1383 wxBitmap xIcon(icon_larger);
1385 wxBitmap xbmp(w, h, -1);
1386 wxMemoryDC mdc(xbmp);
1387 mdc.SetBackground(wxBrush(unused_color));
1389 mdc.DrawBitmap(xIcon, 0, 0);
1390 int xm = xbmp.GetWidth() / 2;
1391 int ym = xbmp.GetHeight() / 2;
1393 int width = wxMax(xm / 10, 2);
1394 wxPen red(m_get_global_colour(
"URED"), width);
1396 mdc.DrawLine(xm - dp, ym - dp, xm + dp, ym + dp);
1397 mdc.DrawLine(xm - dp, ym + dp, xm + dp, ym - dp);
1398 mdc.SelectObject(wxNullBitmap);
1400 wxMask *pmask =
new wxMask(xbmp, unused_color);
1401 xbmp.SetMask(pmask);
1403 pmarkicon_image_list->Add(xbmp);
1406 wxBitmap fIcon(icon_larger);
1408 wxBitmap fbmp(w, h, -1);
1409 wxMemoryDC fmdc(fbmp);
1410 fmdc.SetBackground(wxBrush(unused_color));
1412 fmdc.DrawBitmap(xIcon, 0, 0);
1413 xm = fbmp.GetWidth() / 2;
1414 ym = fbmp.GetHeight() / 2;
1416 width = wxMax(xm / 10, 2);
1417 wxPen fred(m_get_global_colour(
"UGREN"), width);
1419 fmdc.DrawLine(xm - dp, ym + dp, xm + dp, ym + dp);
1420 fmdc.SelectObject(wxNullBitmap);
1422 wxMask *pfmask =
new wxMask(fbmp, unused_color);
1423 fbmp.SetMask(pfmask);
1425 pmarkicon_image_list->Add(fbmp);
1427 pmi->m_blistImageOK =
true;
1428 pmi->listIndex = index;
1431 return pmi->listIndex;
1435 return GetIconImageListIndex(pbm) + 1;
1439 return GetIconImageListIndex(pbm) + 2;
1443wxString WayPointman::CreateGUID(
RoutePoint *pRP) {
1447RoutePoint *WayPointman::FindRoutePointByGUID(
const wxString &guid) {
1448 wxRoutePointListNode *prpnode = m_pWayPointList->GetFirst();
1452 if (prp->m_GUID == guid)
return (prp);
1454 prpnode = prpnode->GetNext();
1460RoutePoint *WayPointman::GetNearbyWaypoint(
double lat,
double lon,
1461 double radius_meters) {
1464 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1468 double a = lat - pr->m_lat;
1469 double b = lon - pr->m_lon;
1470 double l = sqrt((a * a) + (b * b));
1472 if ((l * 60. * 1852.) < radius_meters)
return pr;
1474 node = node->GetNext();
1479RoutePoint *WayPointman::GetOtherNearbyWaypoint(
double lat,
double lon,
1480 double radius_meters,
1481 const wxString &guid) {
1484 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1488 double a = lat - pr->m_lat;
1489 double b = lon - pr->m_lon;
1490 double l = sqrt((a * a) + (b * b));
1492 if ((l * 60. * 1852.) < radius_meters)
1493 if (pr->m_GUID != guid)
return pr;
1495 node = node->GetNext();
1500bool WayPointman::IsReallyVisible(
RoutePoint *pWP) {
1502 return pWP->IsVisible();
1504 wxRouteListNode *node = pRouteList->GetFirst();
1506 Route *proute = node->GetData();
1509 if (proute->IsVisible())
return true;
1512 node = node->GetNext();
1515 if (pWP->IsShared())
1517 return pWP->IsVisible();
1522void WayPointman::ClearRoutePointFonts(
void) {
1526 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1530 pr->m_pMarkFont = NULL;
1531 node = node->GetNext();
1535bool WayPointman::SharedWptsExist() {
1536 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1539 if (prp->IsShared() && (prp->m_bIsInRoute || prp == pAnchorWatchPoint1 ||
1540 prp == pAnchorWatchPoint2))
1542 node = node->GetNext();
1547void WayPointman::DeleteAllWaypoints(
bool b_delete_used) {
1549 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1553 if (!prp->m_bIsInLayer && (prp->GetIconName() != _T(
"mob")) &&
1554 ((b_delete_used && prp->IsShared()) ||
1555 ((!prp->m_bIsInRoute) && !(prp == pAnchorWatchPoint1) &&
1556 !(prp == pAnchorWatchPoint2)))) {
1557 DestroyWaypoint(prp);
1559 node = m_pWayPointList->GetFirst();
1561 node = node->GetNext();
1566RoutePoint *WayPointman::FindWaypointByGuid(
const std::string &guid) {
1567 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1570 if (guid == rp->m_GUID)
return rp;
1571 node = node->GetNext();
1575void WayPointman::DestroyWaypoint(
RoutePoint *pRp,
bool b_update_changeset) {
1576 if (!b_update_changeset)
1577 NavObjectChanges::getInstance()->m_bSkipChangeSetUpdate =
true;
1585 for (
unsigned int ir = 0; ir < proute_array->GetCount(); ir++) {
1592 pr->RemovePoint(pRp);
1596 for (
unsigned int ir = 0; ir < proute_array->GetCount(); ir++) {
1598 if (pr->GetnPoints() < 2) {
1600 NavObjectChanges::getInstance()->m_bSkipChangeSetUpdate;
1601 NavObjectChanges::getInstance()->m_bSkipChangeSetUpdate =
true;
1602 NavObjectChanges::getInstance()->DeleteConfigRoute(pr);
1603 g_pRouteMan->
DeleteRoute(pr, NavObjectChanges::getInstance());
1604 NavObjectChanges::getInstance()->m_bSkipChangeSetUpdate = prev_bskip;
1608 delete proute_array;
1612 NavObjectChanges::getInstance()->DeleteWayPoint(pRp);
1613 NavObjectChanges::getInstance()->m_bSkipChangeSetUpdate =
false;
1615 pSelect->DeleteSelectableRoutePoint(pRp);
1618 if (pRp == pAnchorWatchPoint1) pAnchorWatchPoint1 = NULL;
1619 if (pRp == pAnchorWatchPoint2) pAnchorWatchPoint2 = NULL;
const void Notify()
Notify all listeners, no data supplied.
Wrapper for global variable, supports notification events when value changes.
static wxString GetUUID(void)
Return a unique RFC4122 version 4 compliant GUID string.
Represents a waypoint or mark within the navigation system.
bool m_bIsolatedMark
Flag indicating if the waypoint is a standalone mark.
Represents a navigational route in the navigation system.
RoutePointList * pRoutePointList
Ordered list of waypoints (RoutePoints) that make up this route.
bool m_bRtIsActive
Flag indicating whether this route is currently active for navigation.
RoutePoint * m_pRouteActivePoint
Pointer to the currently active waypoint within this route.
wxString m_RouteNameString
User-assigned name for the route.
wxString m_GUID
Globally unique identifier for this route.
bool m_bIsInLayer
Flag indicating whether this route belongs to a layer.
bool ActivateRoutePoint(Route *pA, RoutePoint *pRP)
Activates a specific waypoint within a route for navigation.
wxArrayPtrVoid * GetRouteArrayContaining(RoutePoint *pWP)
Find all routes that contain the given waypoint.
bool ActivateNextPoint(Route *pr, bool skipped)
Activates the next waypoint in a route when the current waypoint is reached.
bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes)
bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint=NULL)
Activates a route for navigation.
EventVar json_msg
Notified with message targeting all plugins.
EventVar json_leg_info
Notified with a shared_ptr<ActiveLegDat>, leg info to all plugins.
EventVar on_message_sent
Notified when a message available as GetString() is sent to garmin.
Represents a track, which is a series of connected track points.
int GetXIconImageListIndex(const wxBitmap *pbm) const
index of "X-ed out" icon in the image list
int GetFIconImageListIndex(const wxBitmap *pbm) const
index of "fixed viz" icon in the image list
bool AddRoutePoint(RoutePoint *prp)
Add a point to list which owns it.
bool RemoveRoutePoint(RoutePoint *prp)
Remove a routepoint from list if present, deallocate it all cases.
The JSON value class implementation.
Driver registration container, a singleton.
std::vector< DriverHandle > GetActiveDrivers()
Comm port plugin TX support methods
const std::unordered_map< std::string, std::string > GetAttributes(DriverHandle handle)
Query a specific driver for attributes.
Callbacks for RoutePropDlg.