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"
62#include "androidUTIL.h"
65bool g_bPluginHandleAutopilotRoute;
75float g_ChartScaleFactorExp;
78WX_DECLARE_LIST(wxBitmap, markicon_bitmap_list_type);
79WX_DECLARE_LIST(wxString, markicon_key_list_type);
80WX_DECLARE_LIST(wxString, markicon_description_list_type);
83#include <wx/listimpl.cpp>
84WX_DEFINE_LIST(markicon_bitmap_list_type);
85WX_DEFINE_LIST(markicon_key_list_type);
86WX_DEFINE_LIST(markicon_description_list_type);
89void appendOSDirSlash(wxString *pString);
91static void ActivatePersistedRoute(
Routeman *routeman) {
92 if (g_active_route ==
"") {
93 wxLogWarning(
"\"Persist route\" but no persisted route configured");
96 Route *route = routeman->FindRouteByGUID(g_active_route);
98 wxLogWarning(
"Persisted route GUID not available");
112 pRouteActivatePoint(0),
113 m_NMEA0183(NmeaCtxFactory()),
115 m_route_dlg_ctx(route_dlg_ctx) {
117 auto route_action = [&](wxCommandEvent) {
118 if (g_persist_active_route) ActivatePersistedRoute(
this);
120 active_route_listener.Init(active_route, route_action);
123Routeman::~Routeman() {
124 if (pRouteActivatePoint)
delete pRouteActivatePoint;
127bool Routeman::IsRouteValid(
Route *pRoute) {
128 wxRouteListNode *node = pRouteList->GetFirst();
130 if (pRoute == node->GetData())
return true;
131 node = node->GetNext();
138 wxRouteListNode *node = pRouteList->GetFirst();
140 Route *proute = node->GetData();
145 if (prp == pWP)
return proute;
146 pnode = pnode->GetNext();
149 node = node->GetNext();
156Route *Routeman::FindRouteContainingWaypoint(
const std::string &guid) {
157 wxRouteListNode *node = pRouteList->GetFirst();
159 Route *proute = node->GetData();
164 if (prp->
m_GUID == guid)
return proute;
165 pnode = pnode->GetNext();
168 node = node->GetNext();
176 wxRouteListNode *node = pRouteList->GetFirst();
178 Route *proute = node->GetData();
179 if (proute->IsVisible()) {
183 if (prp == pWP)
return proute;
184 pnode = pnode->GetNext();
188 node = node->GetNext();
195 wxArrayPtrVoid *pArray =
new wxArrayPtrVoid;
197 wxRouteListNode *route_node = pRouteList->GetFirst();
199 Route *proute = route_node->GetData();
201 wxRoutePointListNode *waypoint_node = (proute->
pRoutePointList)->GetFirst();
202 while (waypoint_node) {
205 pArray->Add((
void *)proute);
210 waypoint_node = waypoint_node->GetNext();
213 route_node = route_node->GetNext();
216 if (pArray->GetCount())
228 pSelect->DeleteAllSelectableRoutePoints(route);
229 pSelect->DeleteAllSelectableRouteSegments(route);
231 route->RemovePoint(point);
235 if (route->GetnPoints() <= 1 && route_state == 0) {
240 pSelect->AddSelectableRoutePoint(point->m_lat, point->m_lon, point);
245 m_prop_dlg_ctx.set_route_and_update(route);
248RoutePoint *Routeman::FindBestActivatePoint(
Route *pR,
double lat,
double lon,
249 double cog,
double sog) {
250 if (!pR)
return NULL;
254 double min_time_found = 1e6;
261 DistanceBearingMercator(pn->m_lat, pn->m_lon, lat, lon, &brg, &dist);
263 double angle = brg - cog;
264 double soa = cos(angle * PI / 180.);
266 double time_to_wp = dist / soa;
268 if (time_to_wp > 0) {
269 if (time_to_wp < min_time_found) {
270 min_time_found = time_to_wp;
274 node = node->GetNext();
280 g_bAllowShipToActive =
false;
283 v[_T(
"GUID")] = pRouteToActivate->
m_GUID;
284 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_RTE_ACTIVATED");
285 if (g_bPluginHandleAutopilotRoute)
return true;
289 m_have_n0183_out =
false;
290 m_have_n2000_out =
false;
292 m_output_drivers.clear();
295 if (attributes.find(
"protocol") == attributes.end())
continue;
296 if (attributes.at(
"protocol") ==
"nmea0183") {
297 if (attributes.find(
"ioDirection") != attributes.end()) {
298 if ((attributes.at(
"ioDirection") ==
"IN/OUT") ||
299 (attributes.at(
"ioDirection") ==
"OUT")) {
300 m_output_drivers.push_back(handle);
301 m_have_n0183_out =
true;
307 if (attributes.at(
"protocol") ==
"nmea2000") {
308 m_output_drivers.push_back(handle);
309 m_have_n2000_out =
true;
314 pActiveRoute = pRouteToActivate;
315 g_active_route = pActiveRoute->GetGUID();
318 pActivePoint = pStartPoint;
320 wxRoutePointListNode *node = (pActiveRoute->
pRoutePointList)->GetFirst();
321 pActivePoint = node->GetData();
332 m_bDataValid =
false;
334 m_route_dlg_ctx.show_with_fresh_fonts();
339 g_bAllowShipToActive =
false;
341 v[_T(
"GUID")] = pRP_target->
m_GUID;
342 v[_T(
"WP_activated")] = pRP_target->GetName();
344 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_WPT_ACTIVATED");
346 if (g_bPluginHandleAutopilotRoute)
return true;
350 pActivePoint = pRP_target;
353 wxRoutePointListNode *node = (pActiveRoute->
pRoutePointList)->GetFirst();
359 node = node->GetNext();
367 if (pRP_target == prp_first) {
368 if (pRouteActivatePoint)
delete pRouteActivatePoint;
370 pRouteActivatePoint =
371 new RoutePoint(gLat, gLon, wxString(_T(
"")), wxString(_T(
"Begin")),
372 wxEmptyString,
false);
375 pActiveRouteSegmentBeginPoint = pRouteActivatePoint;
380 node = node->GetNext();
384 if (pnext == pRP_target) {
385 pActiveRouteSegmentBeginPoint = np_prev;
390 node = node->GetNext();
409 m_prop_dlg_ctx.set_enroute_point(pA, pActivePoint);
414 g_bAllowShipToActive =
false;
421 v[_T(
"isSkipped")] = skipped;
422 v[_T(
"GUID")] = pActivePoint->
m_GUID;
423 v[_T(
"GUID_WP_arrived")] = pActivePoint->
m_GUID;
424 v[_T(
"WP_arrived")] = pActivePoint->GetName();
426 int n_index_active = pActiveRoute->GetIndexOf(pActivePoint);
428 while (n_index_active == pActiveRoute->GetIndexOf(pActivePoint)) {
429 if ((n_index_active + step) <= pActiveRoute->GetnPoints()) {
430 pActiveRouteSegmentBeginPoint = pActivePoint;
432 pActiveRoute->GetPoint(n_index_active + step);
433 pActivePoint = pActiveRoute->GetPoint(n_index_active + step);
442 v[_T(
"Next_WP")] = pActivePoint->GetName();
443 v[_T(
"GUID_Next_WP")] = pActivePoint->
m_GUID;
458 m_prop_dlg_ctx.set_enroute_point(pr, pActivePoint);
460 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_WPT_ARRIVED");
465bool Routeman::DeactivateRoute(
bool b_arrival) {
474 g_active_route.Clear();
479 v[_T(
"GUID")] = pActiveRoute->
m_GUID;
480 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_RTE_DEACTIVATED");
482 v[_T(
"GUID")] = pActiveRoute->
m_GUID;
484 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_RTE_ENDED");
490 if (pRouteActivatePoint)
delete pRouteActivatePoint;
491 pRouteActivatePoint = NULL;
495 m_route_dlg_ctx.clear_console_background();
496 m_bDataValid =
false;
501bool Routeman::UpdateAutopilot() {
502 if (!pActiveRoute)
return false;
504 if (!bGPSValid)
return false;
509 if ((g_maxWPNameLength >= 3) && (g_maxWPNameLength <= 32))
510 maxName = g_maxWPNameLength;
514 auto& registry = CommDriverRegistry::GetInstance();
515 const std::vector<DriverPtr>& drivers = registry.GetDrivers();
518 bool have_n0183 =
false;
519 bool have_n2000 =
false;
522 for (
auto key : m_output_drivers) {
523 for (
auto &d : drivers) {
524 if (d->Key() == key) {
525 std::unordered_map<std::string, std::string> attributes =
527 auto protocol_it = attributes.find(
"protocol");
528 if (protocol_it != attributes.end()) {
529 std::string protocol = protocol_it->second;
531 if (protocol ==
"nmea0183") {
533 }
else if (protocol ==
"nmea2000") {
542 if (m_have_n0183_out) rv |= UpdateAutopilotN0183(*
this);
544 if (m_have_n2000_out) rv |= UpdateAutopilotN2K(*
this);
549 leg_info.Btw = CurrentBrgToActivePoint;
550 leg_info.Dtw = CurrentRngToActivePoint;
551 leg_info.Xte = CurrentXTEToActivePoint;
553 leg_info.Xte = -leg_info.Xte;
555 leg_info.wp_name = pActivePoint->GetName().Truncate(maxName);
556 leg_info.arrival = m_bArrival;
567 if ((g_maxWPNameLength >= 3) && (g_maxWPNameLength <= 32))
568 maxName = g_maxWPNameLength;
572 double r_Sog(0.0), r_Cog(0.0);
573 if (!std::isnan(gSog)) r_Sog = gSog;
574 if (!std::isnan(gCog)) r_Cog = gCog;
579 leg_info.Btw = CurrentBrgToActivePoint;
580 leg_info.Dtw = CurrentRngToActivePoint;
581 leg_info.Xte = CurrentXTEToActivePoint;
583 leg_info.Xte = -leg_info.Xte;
585 leg_info.wp_name = pActivePoint->GetName().Truncate(maxName);
586 leg_info.arrival = m_bArrival;
592 m_NMEA0183.TalkerID =
"EC";
594 m_NMEA0183.Rmb.IsDataValid = bGPSValid ? NTrue : NFalse;
595 m_NMEA0183.Rmb.CrossTrackError = CurrentXTEToActivePoint;
596 m_NMEA0183.Rmb.DirectionToSteer = XTEDir < 0 ? Left : Right;
597 m_NMEA0183.Rmb.RangeToDestinationNauticalMiles = CurrentRngToActivePoint;
598 m_NMEA0183.Rmb.BearingToDestinationDegreesTrue = CurrentBrgToActivePoint;
600 if (pActivePoint->m_lat < 0.)
601 m_NMEA0183.Rmb.DestinationPosition.Latitude.Set(-pActivePoint->m_lat,
604 m_NMEA0183.Rmb.DestinationPosition.Latitude.Set(pActivePoint->m_lat,
"N");
606 if (pActivePoint->m_lon < 0.)
607 m_NMEA0183.Rmb.DestinationPosition.Longitude.Set(-pActivePoint->m_lon,
610 m_NMEA0183.Rmb.DestinationPosition.Longitude.Set(pActivePoint->m_lon,
613 m_NMEA0183.Rmb.DestinationClosingVelocityKnots =
614 r_Sog * cos((r_Cog - CurrentBrgToActivePoint) * PI / 180.0);
615 m_NMEA0183.Rmb.IsArrivalCircleEntered = m_bArrival ? NTrue : NFalse;
616 m_NMEA0183.Rmb.FAAModeIndicator = bGPSValid ?
"A" :
"N";
619 int wp_len = maxName;
621 m_NMEA0183.Rmb.To = pActivePoint->GetName().Truncate(wp_len);
622 m_NMEA0183.Rmb.From =
623 pActiveRouteSegmentBeginPoint->GetName().Truncate(wp_len);
624 m_NMEA0183.Rmb.Write(snt);
626 }
while (snt.Sentence.size() > 82 && wp_len > 0);
633 m_NMEA0183.TalkerID = _T(
"EC");
636 m_NMEA0183.Rmc.IsDataValid = NTrue;
637 if (!bGPSValid) m_NMEA0183.Rmc.IsDataValid = NFalse;
640 m_NMEA0183.Rmc.Position.Latitude.Set(-gLat, _T(
"S"));
642 m_NMEA0183.Rmc.Position.Latitude.Set(gLat, _T(
"N"));
645 m_NMEA0183.Rmc.Position.Longitude.Set(-gLon, _T(
"W"));
647 m_NMEA0183.Rmc.Position.Longitude.Set(gLon, _T(
"E"));
649 m_NMEA0183.Rmc.SpeedOverGroundKnots = r_Sog;
650 m_NMEA0183.Rmc.TrackMadeGoodDegreesTrue = r_Cog;
652 if (!std::isnan(gVar)) {
654 m_NMEA0183.Rmc.MagneticVariation = -gVar;
655 m_NMEA0183.Rmc.MagneticVariationDirection = West;
657 m_NMEA0183.Rmc.MagneticVariation = gVar;
658 m_NMEA0183.Rmc.MagneticVariationDirection = East;
661 m_NMEA0183.Rmc.MagneticVariation =
665 if (!gRmcTime.IsEmpty() && !gRmcDate.IsEmpty()) {
666 m_NMEA0183.Rmc.UTCTime = gRmcTime;
667 m_NMEA0183.Rmc.Date = gRmcDate;
669 wxDateTime now = wxDateTime::Now();
670 wxDateTime utc = now.ToUTC();
671 wxString time = utc.Format(_T(
"%H%M%S"));
672 m_NMEA0183.Rmc.UTCTime = time;
673 wxString date = utc.Format(_T(
"%d%m%y"));
674 m_NMEA0183.Rmc.Date = date;
677 m_NMEA0183.Rmc.FAAModeIndicator =
"A";
678 if (!bGPSValid) m_NMEA0183.Rmc.FAAModeIndicator =
"N";
680 m_NMEA0183.Rmc.Write(snt);
687 m_NMEA0183.TalkerID = _T(
"EC");
691 m_NMEA0183.Apb.IsLoranBlinkOK =
693 if (!bGPSValid) m_NMEA0183.Apb.IsLoranBlinkOK = NFalse;
695 m_NMEA0183.Apb.IsLoranCCycleLockOK = NTrue;
696 if (!bGPSValid) m_NMEA0183.Apb.IsLoranCCycleLockOK = NFalse;
698 m_NMEA0183.Apb.CrossTrackErrorMagnitude = CurrentXTEToActivePoint;
701 m_NMEA0183.Apb.DirectionToSteer = Left;
703 m_NMEA0183.Apb.DirectionToSteer = Right;
705 m_NMEA0183.Apb.CrossTrackUnits = _T(
"N");
708 m_NMEA0183.Apb.IsArrivalCircleEntered = NTrue;
710 m_NMEA0183.Apb.IsArrivalCircleEntered = NFalse;
714 m_NMEA0183.Apb.IsPerpendicular = NFalse;
716 m_NMEA0183.Apb.To = pActivePoint->GetName().Truncate(maxName);
719 DistanceBearingMercator(pActivePoint->m_lat, pActivePoint->m_lon,
720 pActiveRouteSegmentBeginPoint->m_lat,
721 pActiveRouteSegmentBeginPoint->m_lon, &brg1,
724 if (g_bMagneticAPB && !std::isnan(gVar)) {
726 ((brg1 - gVar) >= 0.) ? (brg1 - gVar) : (brg1 - gVar + 360.);
727 double bapm = ((CurrentBrgToActivePoint - gVar) >= 0.)
728 ? (CurrentBrgToActivePoint - gVar)
729 : (CurrentBrgToActivePoint - gVar + 360.);
731 m_NMEA0183.Apb.BearingOriginToDestination = brg1m;
732 m_NMEA0183.Apb.BearingOriginToDestinationUnits = _T(
"M");
734 m_NMEA0183.Apb.BearingPresentPositionToDestination = bapm;
735 m_NMEA0183.Apb.BearingPresentPositionToDestinationUnits = _T(
"M");
737 m_NMEA0183.Apb.HeadingToSteer = bapm;
738 m_NMEA0183.Apb.HeadingToSteerUnits = _T(
"M");
740 m_NMEA0183.Apb.BearingOriginToDestination = brg1;
741 m_NMEA0183.Apb.BearingOriginToDestinationUnits = _T(
"T");
743 m_NMEA0183.Apb.BearingPresentPositionToDestination =
744 CurrentBrgToActivePoint;
745 m_NMEA0183.Apb.BearingPresentPositionToDestinationUnits = _T(
"T");
747 m_NMEA0183.Apb.HeadingToSteer = CurrentBrgToActivePoint;
748 m_NMEA0183.Apb.HeadingToSteerUnits = _T(
"T");
751 m_NMEA0183.Apb.Write(snt);
757 m_NMEA0183.TalkerID = _T(
"EC");
761 m_NMEA0183.Xte.IsLoranBlinkOK =
763 if (!bGPSValid) m_NMEA0183.Xte.IsLoranBlinkOK = NFalse;
765 m_NMEA0183.Xte.IsLoranCCycleLockOK = NTrue;
766 if (!bGPSValid) m_NMEA0183.Xte.IsLoranCCycleLockOK = NFalse;
768 m_NMEA0183.Xte.CrossTrackErrorDistance = CurrentXTEToActivePoint;
771 m_NMEA0183.Xte.DirectionToSteer = Left;
773 m_NMEA0183.Xte.DirectionToSteer = Right;
775 m_NMEA0183.Xte.CrossTrackUnits = _T(
"N");
777 m_NMEA0183.Xte.Write(snt);
785bool Routeman::DoesRouteContainSharedPoints(
Route *pRoute) {
797 for (
unsigned int ir = 0; ir < pRA->GetCount(); ir++) {
807 if (pnode) pnode = pnode->GetNext();
814 if (prp->IsShared())
return true;
816 if (pnode) pnode = pnode->GetNext();
823bool Routeman::DeleteTrack(
Track *pTrack) {
824 if (pTrack && !pTrack->m_bIsInLayer) {
825 ::wxBeginBusyCursor();
841 pSelect->DeleteAllSelectableTrackSegments(pTrack);
842 auto it = std::find(g_TrackList.begin(), g_TrackList.end(), pTrack);
843 if (it != g_TrackList.end()) {
844 g_TrackList.erase(it);
858 if (pRoute == pAISMOBRoute) {
859 if (!m_route_dlg_ctx.confirm_delete_ais_mob()) {
864 ::wxBeginBusyCursor();
866 if (GetpActiveRoute() == pRoute) DeactivateRoute();
876 m_prop_dlg_ctx.hide(pRoute);
881 pSelect->DeleteAllSelectableRouteSegments(pRoute);
882 pRouteList->DeleteObject(pRoute);
884 m_route_dlg_ctx.route_mgr_dlg_update_list_ctrl();
893 Route *pcontainer_route = FindRouteContainingWaypoint(prp);
898 if (!prp->IsShared()) {
899 pSelect->DeleteSelectablePoint(prp, SELTYPE_ROUTEPOINT);
902 wxRoutePointListNode *pdnode = pnode;
909 NavObj_dB::GetInstance().DeleteRoutePoint(prp);
913 prp->SetShared(
false);
914 NavObj_dB::GetInstance().UpdateRoutePoint(prp);
918 pnode = pnode->GetNext();
923 NavObj_dB::GetInstance().DeleteRoute(pRoute);
931void Routeman::DeleteAllRoutes() {
932 ::wxBeginBusyCursor();
935 wxRouteListNode *node = pRouteList->GetFirst();
937 Route *proute = node->GetData();
938 if (proute == pAISMOBRoute) {
939 if (!m_route_dlg_ctx.confirm_delete_ais_mob()) {
943 ::wxBeginBusyCursor();
946 node = node->GetNext();
955void Routeman::SetColorScheme(ColorScheme cs,
double displayDPmm) {
958 int scaled_line_width = g_route_line_width;
959 int track_scaled_line_width = g_track_line_width;
962 double nominal_line_width_pix = wxMax(1.5, floor(displayDPmm / 5.0));
964 double sline_width = wxMax(nominal_line_width_pix, g_route_line_width);
965 sline_width *= g_ChartScaleFactorExp;
966 scaled_line_width = wxMax(sline_width, 2);
968 double tsline_width = wxMax(nominal_line_width_pix, g_track_line_width);
969 tsline_width *= g_ChartScaleFactorExp;
970 track_scaled_line_width = wxMax(tsline_width, 2);
973 m_pActiveRoutePointPen = wxThePenList->FindOrCreatePen(
974 wxColour(0, 0, 255), scaled_line_width, wxPENSTYLE_SOLID);
975 m_pRoutePointPen = wxThePenList->FindOrCreatePen(
976 wxColour(0, 0, 255), scaled_line_width, wxPENSTYLE_SOLID);
981 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"UINFB"),
982 scaled_line_width, wxPENSTYLE_SOLID);
983 m_pSelectedRoutePen =
984 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"UINFO"),
985 scaled_line_width, wxPENSTYLE_SOLID);
987 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"UARTE"),
988 scaled_line_width, wxPENSTYLE_SOLID);
990 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"CHMGD"),
991 track_scaled_line_width, wxPENSTYLE_SOLID);
992 m_pRouteBrush = wxTheBrushList->FindOrCreateBrush(
993 m_route_dlg_ctx.get_global_colour(
"UINFB"), wxBRUSHSTYLE_SOLID);
994 m_pSelectedRouteBrush = wxTheBrushList->FindOrCreateBrush(
995 m_route_dlg_ctx.get_global_colour(
"UINFO"), wxBRUSHSTYLE_SOLID);
996 m_pActiveRouteBrush = wxTheBrushList->FindOrCreateBrush(
997 m_route_dlg_ctx.get_global_colour(
"PLRTE"), wxBRUSHSTYLE_SOLID);
1000wxString Routeman::GetRouteReverseMessage(
void) {
1002 _(
"Waypoints can be renamed to reflect the new order, the names will be "
1003 "'001', '002' etc.\n\nDo you want to rename the waypoints?"));
1006wxString Routeman::GetRouteResequenceMessage(
void) {
1008 _(
"Waypoints will be renamed to reflect the natural order, the names "
1009 "will be '001', '002' etc.\n\nDo you want to rename the waypoints?"));
1012Route *Routeman::FindRouteByGUID(
const wxString &guid) {
1013 wxRouteListNode *node1 = pRouteList->GetFirst();
1015 Route *pRoute = node1->GetData();
1017 if (pRoute->
m_GUID == guid)
return pRoute;
1018 node1 = node1->GetNext();
1024Track *Routeman::FindTrackByGUID(
const wxString &guid) {
1025 for (
Track *pTrack : g_TrackList) {
1026 if (pTrack->m_GUID == guid)
return pTrack;
1032void Routeman::ZeroCurrentXTEToActivePoint() {
1034 if (pRouteActivatePoint)
delete pRouteActivatePoint;
1035 pRouteActivatePoint =
1036 new RoutePoint(gLat, gLon, wxString(_T(
"")), wxString(_T(
"")),
1037 wxEmptyString,
false);
1040 pActiveRouteSegmentBeginPoint = pRouteActivatePoint;
1041 m_arrival_min = 1e6;
1048WayPointman::WayPointman(GlobalColourFunc color_func)
1049 : m_get_global_colour(color_func) {
1050 m_pWayPointList =
new RoutePointList;
1052 pmarkicon_image_list = NULL;
1055 m_pIconArray =
new ArrayOfMarkIcon;
1056 m_pLegacyIconArray = NULL;
1057 m_pExtendedIconArray = NULL;
1059 m_cs = (ColorScheme)-1;
1062 m_iconListScale = -999.0;
1063 m_iconListHeight = -1;
1066WayPointman::~WayPointman() {
1072 RoutePointList temp_list;
1074 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1078 temp_list.Append(pr);
1079 node = node->GetNext();
1082 int a = temp_list.GetCount();
1084 temp_list.DeleteContents(
true);
1087 m_pWayPointList->Clear();
1088 delete m_pWayPointList;
1090 for (
unsigned int i = 0; i < m_pIconArray->GetCount(); i++) {
1092 delete pmi->piconBitmap;
1096 m_pIconArray->Clear();
1097 delete m_pIconArray;
1099 if (pmarkicon_image_list) pmarkicon_image_list->RemoveAll();
1100 delete pmarkicon_image_list;
1101 m_pLegacyIconArray->Clear();
1102 delete m_pLegacyIconArray;
1103 m_pExtendedIconArray->Clear();
1104 delete m_pExtendedIconArray;
1108 if (!prp)
return false;
1110 wxRoutePointListNode *prpnode = m_pWayPointList->Append(prp);
1111 prp->SetManagerListNode(prpnode);
1117 if (!prp)
return false;
1119 wxRoutePointListNode *prpnode =
1120 (wxRoutePointListNode *)prp->GetManagerListNode();
1125 m_pWayPointList->DeleteObject(prp);
1127 prp->SetManagerListNode(NULL);
1132wxImageList *WayPointman::Getpmarkicon_image_list(
int nominal_height) {
1134 if (pmarkicon_image_list && (nominal_height == m_iconListHeight)) {
1135 return pmarkicon_image_list;
1139 if (NULL != pmarkicon_image_list) {
1140 pmarkicon_image_list->RemoveAll();
1141 delete pmarkicon_image_list;
1143 pmarkicon_image_list =
new wxImageList(nominal_height, nominal_height);
1145 m_iconListHeight = nominal_height;
1146 m_bitmapSizeForList = nominal_height;
1148 return pmarkicon_image_list;
1151wxBitmap *WayPointman::CreateDimBitmap(wxBitmap *pBitmap,
double factor) {
1152 wxImage img = pBitmap->ConvertToImage();
1153 int sx = img.GetWidth();
1154 int sy = img.GetHeight();
1156 wxImage new_img(img);
1158 for (
int i = 0; i < sx; i++) {
1159 for (
int j = 0; j < sy; j++) {
1160 if (!img.IsTransparent(i, j)) {
1161 new_img.SetRGB(i, j, (
unsigned char)(img.GetRed(i, j) * factor),
1162 (
unsigned char)(img.GetGreen(i, j) * factor),
1163 (
unsigned char)(img.GetBlue(i, j) * factor));
1168 wxBitmap *pret =
new wxBitmap(new_img);
1173wxImage WayPointman::CreateDimImage(wxImage &image,
double factor) {
1174 int sx = image.GetWidth();
1175 int sy = image.GetHeight();
1177 wxImage new_img(image);
1179 for (
int i = 0; i < sx; i++) {
1180 for (
int j = 0; j < sy; j++) {
1181 if (!image.IsTransparent(i, j)) {
1182 new_img.SetRGB(i, j, (
unsigned char)(image.GetRed(i, j) * factor),
1183 (
unsigned char)(image.GetGreen(i, j) * factor),
1184 (
unsigned char)(image.GetBlue(i, j) * factor));
1189 return wxImage(new_img);
1192bool WayPointman::DoesIconExist(
const wxString &icon_key)
const {
1196 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1197 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1198 if (pmi->icon_name.IsSameAs(icon_key))
return true;
1204wxBitmap *WayPointman::GetIconBitmap(
const wxString &icon_key)
const {
1205 wxBitmap *pret = NULL;
1209 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1210 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1211 if (pmi->icon_name.IsSameAs(icon_key))
break;
1214 if (i == m_pIconArray->GetCount())
1217 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1218 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1224 if (i == m_pIconArray->GetCount())
1225 pmi = (
MarkIcon *)m_pIconArray->Item(0);
1228 if (pmi->piconBitmap)
1229 pret = pmi->piconBitmap;
1231 if (pmi->iconImage.IsOk()) {
1232 pmi->piconBitmap =
new wxBitmap(pmi->iconImage);
1233 pret = pmi->piconBitmap;
1240bool WayPointman::GetIconPrescaled(
const wxString &icon_key)
const {
1244 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1245 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1246 if (pmi->icon_name.IsSameAs(icon_key))
break;
1249 if (i == m_pIconArray->GetCount())
1252 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1253 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1259 if (i == m_pIconArray->GetCount())
1260 pmi = (
MarkIcon *)m_pIconArray->Item(0);
1263 return pmi->preScaled;
1268wxBitmap WayPointman::GetIconBitmapForList(
int index,
int height)
const {
1273 pmi = (
MarkIcon *)m_pIconArray->Item(index);
1275 if (pmi->iconImage.GetHeight() != height) {
1278 int w0 = pmi->iconImage.GetWidth();
1279 int h0 = pmi->iconImage.GetHeight();
1281 wxImage icon_resized = pmi->iconImage;
1282 if (h0 <= h && w0 <= w) {
1283 icon_resized = pmi->iconImage.Resize(
1284 wxSize(w, h), wxPoint(w / 2 - w0 / 2, h / 2 - h0 / 2));
1291 w1 = wxRound((
double)w0 * ((
double)h / (
double)h0));
1294 h1 = wxRound((
double)h0 * ((
double)w / (
double)w0));
1296 icon_resized = pmi->iconImage.Rescale(w1, h1);
1297 icon_resized = pmi->iconImage.Resize(
1298 wxSize(w, h), wxPoint(w / 2 - w1 / 2, h / 2 - h1 / 2));
1301 pret = wxBitmap(icon_resized);
1304 pret = wxBitmap(pmi->iconImage);
1310wxString *WayPointman::GetIconDescription(
int index)
const {
1311 wxString *pret = NULL;
1315 pret = &pmi->icon_description;
1320wxString WayPointman::GetIconDescription(wxString icon_key)
const {
1324 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1325 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1326 if (pmi->icon_name.IsSameAs(icon_key))
1327 return wxString(pmi->icon_description);
1330 return wxEmptyString;
1333wxString *WayPointman::GetIconKey(
int index)
const {
1334 wxString *pret = NULL;
1336 if ((index >= 0) && ((
unsigned int)index < m_pIconArray->GetCount())) {
1338 pret = &pmi->icon_name;
1343int WayPointman::GetIconIndex(
const wxBitmap *pbm)
const {
1344 unsigned int ret = 0;
1347 wxASSERT(m_pIconArray->GetCount() >= 1);
1348 for (
unsigned int i = 0; i < m_pIconArray->GetCount(); i++) {
1349 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1350 if (pmi->piconBitmap == pbm) {
1359int WayPointman::GetIconImageListIndex(
const wxBitmap *pbm)
const {
1363 if (pmarkicon_image_list && !pmi->m_blistImageOK) {
1364 int h0 = pmi->iconImage.GetHeight();
1365 int w0 = pmi->iconImage.GetWidth();
1366 int h = m_bitmapSizeForList;
1367 int w = m_bitmapSizeForList;
1369 wxImage icon_larger = pmi->iconImage;
1370 if (h0 <= h && w0 <= w) {
1371 icon_larger = pmi->iconImage.Resize(
1372 wxSize(w, h), wxPoint(w / 2 - w0 / 2, h / 2 - h0 / 2));
1381 w1 = wxRound((
double)w0 * ((
double)h / (
double)h0));
1384 h1 = wxRound((
double)h0 * ((
double)w / (
double)w0));
1386 icon_larger = pmi->iconImage.Rescale(w1, h1).Resize(
1387 wxSize(w, h), wxPoint(w / 2 - w1 / 2, h / 2 - h1 / 2));
1390 int index = pmarkicon_image_list->Add(wxBitmap(icon_larger));
1395 icon_larger.ConvertAlphaToMask(128);
1397 unsigned char r, g, b;
1398 icon_larger.GetOrFindMaskColour(&r, &g, &b);
1399 wxColour unused_color(r, g, b);
1402 wxBitmap xIcon(icon_larger);
1404 wxBitmap xbmp(w, h, -1);
1405 wxMemoryDC mdc(xbmp);
1406 mdc.SetBackground(wxBrush(unused_color));
1408 mdc.DrawBitmap(xIcon, 0, 0);
1409 int xm = xbmp.GetWidth() / 2;
1410 int ym = xbmp.GetHeight() / 2;
1412 int width = wxMax(xm / 10, 2);
1413 wxPen red(m_get_global_colour(
"URED"), width);
1415 mdc.DrawLine(xm - dp, ym - dp, xm + dp, ym + dp);
1416 mdc.DrawLine(xm - dp, ym + dp, xm + dp, ym - dp);
1417 mdc.SelectObject(wxNullBitmap);
1419 wxMask *pmask =
new wxMask(xbmp, unused_color);
1420 xbmp.SetMask(pmask);
1422 pmarkicon_image_list->Add(xbmp);
1425 wxBitmap fIcon(icon_larger);
1427 wxBitmap fbmp(w, h, -1);
1428 wxMemoryDC fmdc(fbmp);
1429 fmdc.SetBackground(wxBrush(unused_color));
1431 fmdc.DrawBitmap(xIcon, 0, 0);
1432 xm = fbmp.GetWidth() / 2;
1433 ym = fbmp.GetHeight() / 2;
1435 width = wxMax(xm / 10, 2);
1436 wxPen fred(m_get_global_colour(
"UGREN"), width);
1438 fmdc.DrawLine(xm - dp, ym + dp, xm + dp, ym + dp);
1439 fmdc.SelectObject(wxNullBitmap);
1441 wxMask *pfmask =
new wxMask(fbmp, unused_color);
1442 fbmp.SetMask(pfmask);
1444 pmarkicon_image_list->Add(fbmp);
1446 pmi->m_blistImageOK =
true;
1447 pmi->listIndex = index;
1450 return pmi->listIndex;
1454 return GetIconImageListIndex(pbm) + 1;
1458 return GetIconImageListIndex(pbm) + 2;
1462wxString WayPointman::CreateGUID(
RoutePoint *pRP) {
1466RoutePoint *WayPointman::FindRoutePointByGUID(
const wxString &guid) {
1467 wxRoutePointListNode *prpnode = m_pWayPointList->GetFirst();
1471 if (prp->
m_GUID == guid)
return (prp);
1473 prpnode = prpnode->GetNext();
1479RoutePoint *WayPointman::GetNearbyWaypoint(
double lat,
double lon,
1480 double radius_meters) {
1483 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1487 double a = lat - pr->m_lat;
1488 double b = lon - pr->m_lon;
1489 double l = sqrt((a * a) + (b * b));
1491 if ((l * 60. * 1852.) < radius_meters)
return pr;
1493 node = node->GetNext();
1498RoutePoint *WayPointman::GetOtherNearbyWaypoint(
double lat,
double lon,
1499 double radius_meters,
1500 const wxString &guid) {
1503 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1507 double a = lat - pr->m_lat;
1508 double b = lon - pr->m_lon;
1509 double l = sqrt((a * a) + (b * b));
1511 if ((l * 60. * 1852.) < radius_meters)
1512 if (pr->
m_GUID != guid)
return pr;
1514 node = node->GetNext();
1519bool WayPointman::IsReallyVisible(
RoutePoint *pWP) {
1521 return pWP->IsVisible();
1523 wxRouteListNode *node = pRouteList->GetFirst();
1525 Route *proute = node->GetData();
1528 if (proute->IsVisible())
return true;
1531 node = node->GetNext();
1534 if (pWP->IsShared())
1536 return pWP->IsVisible();
1541void WayPointman::ClearRoutePointFonts(
void) {
1545 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1550 node = node->GetNext();
1554bool WayPointman::SharedWptsExist() {
1555 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1558 if (prp->IsShared() && (prp->
m_bIsInRoute || prp == pAnchorWatchPoint1 ||
1559 prp == pAnchorWatchPoint2))
1561 node = node->GetNext();
1566void WayPointman::DeleteAllWaypoints(
bool b_delete_used) {
1568 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1572 if (!prp->
m_bIsInLayer && (prp->GetIconName() != _T(
"mob")) &&
1573 ((b_delete_used && prp->IsShared()) ||
1574 ((!prp->
m_bIsInRoute) && !(prp == pAnchorWatchPoint1) &&
1575 !(prp == pAnchorWatchPoint2)))) {
1576 DestroyWaypoint(prp);
1578 node = m_pWayPointList->GetFirst();
1580 node = node->GetNext();
1585RoutePoint *WayPointman::FindWaypointByGuid(
const std::string &guid) {
1586 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1589 if (guid == rp->
m_GUID)
return rp;
1590 node = node->GetNext();
1594void WayPointman::DestroyWaypoint(
RoutePoint *pRp,
bool b_update_changeset) {
1600 for (
unsigned int ir = 0; ir < proute_array->GetCount(); ir++) {
1607 pr->RemovePoint(pRp);
1611 for (
unsigned int ir = 0; ir < proute_array->GetCount(); ir++) {
1613 if (pr->GetnPoints() < 2) {
1618 delete proute_array;
1622 NavObj_dB::GetInstance().DeleteRoutePoint(pRp);
1624 pSelect->DeleteSelectableRoutePoint(pRp);
1627 if (pRp == pAnchorWatchPoint1) pAnchorWatchPoint1 = NULL;
1628 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.
wxRect CurrentRect_in_DC
Current rectangle occupied by the waypoint in the display.
wxString m_GUID
Globally Unique Identifier for the waypoint.
bool m_bIsolatedMark
Flag indicating if the waypoint is a standalone mark.
bool m_bIsActive
Flag indicating if this waypoint is active for navigation.
bool m_bIsInRoute
Flag indicating if this waypoint is part of a route.
wxFont * m_pMarkFont
Font used for rendering the waypoint name.
bool m_bShowName
Flag indicating if the waypoint name should be shown.
bool m_bBlink
Flag indicating if the waypoint should blink when displayed.
bool m_bIsInLayer
Flag indicating if the waypoint belongs to a layer.
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)
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.