36#include <wx/jsonval.h>
39#include "model/autopilot_output.h"
40#include "model/base_platform.h"
42#include "model/comm_n0183_output.h"
44#include "model/georef.h"
45#include "model/nav_object_database.h"
46#include "model/navutil_base.h"
48#include "model/nmea_ctx_factory.h"
49#include "model/own_ship.h"
50#include "model/route.h"
51#include "model/routeman.h"
52#include "model/track.h"
57#include "androidUTIL.h"
60bool g_bPluginHandleAutopilotRoute;
70float g_ChartScaleFactorExp;
73void appendOSDirSlash(wxString *pString);
75static void ActivatePersistedRoute(
Routeman *routeman) {
76 if (g_active_route ==
"") {
77 wxLogWarning(
"\"Persist route\" but no persisted route configured");
80 Route *route = routeman->FindRouteByGUID(g_active_route);
82 wxLogWarning(
"Persisted route GUID not available");
96 pRouteActivatePoint(0),
97 m_NMEA0183(NmeaCtxFactory()),
99 m_route_dlg_ctx(route_dlg_ctx) {
101 auto route_action = [&](wxCommandEvent) {
102 if (g_persist_active_route) ActivatePersistedRoute(
this);
104 active_route_listener.Init(active_route, route_action);
107Routeman::~Routeman() {
108 if (pRouteActivatePoint)
delete pRouteActivatePoint;
111bool Routeman::IsRouteValid(
Route *pRoute) {
112 wxRouteListNode *node = pRouteList->GetFirst();
114 if (pRoute == node->GetData())
return true;
115 node = node->GetNext();
122 wxRouteListNode *node = pRouteList->GetFirst();
124 Route *proute = node->GetData();
129 if (prp == pWP)
return proute;
130 pnode = pnode->GetNext();
133 node = node->GetNext();
140Route *Routeman::FindRouteContainingWaypoint(
const std::string &guid) {
141 wxRouteListNode *node = pRouteList->GetFirst();
143 Route *proute = node->GetData();
148 if (prp->
m_GUID == guid)
return proute;
149 pnode = pnode->GetNext();
152 node = node->GetNext();
160 wxRouteListNode *node = pRouteList->GetFirst();
162 Route *proute = node->GetData();
163 if (proute->IsVisible()) {
167 if (prp == pWP)
return proute;
168 pnode = pnode->GetNext();
172 node = node->GetNext();
179 wxArrayPtrVoid *pArray =
new wxArrayPtrVoid;
181 wxRouteListNode *route_node = pRouteList->GetFirst();
183 Route *proute = route_node->GetData();
185 wxRoutePointListNode *waypoint_node = (proute->
pRoutePointList)->GetFirst();
186 while (waypoint_node) {
189 pArray->Add((
void *)proute);
194 waypoint_node = waypoint_node->GetNext();
197 route_node = route_node->GetNext();
200 if (pArray->GetCount())
212 pSelect->DeleteAllSelectableRoutePoints(route);
213 pSelect->DeleteAllSelectableRouteSegments(route);
215 route->RemovePoint(point);
219 if (route->GetnPoints() <= 1 && route_state == 0) {
224 pSelect->AddSelectableRoutePoint(point->m_lat, point->m_lon, point);
229 m_prop_dlg_ctx.set_route_and_update(route);
232RoutePoint *Routeman::FindBestActivatePoint(
Route *pR,
double lat,
double lon,
233 double cog,
double sog) {
234 if (!pR)
return NULL;
238 double min_time_found = 1e6;
245 DistanceBearingMercator(pn->m_lat, pn->m_lon, lat, lon, &brg, &dist);
247 double angle = brg - cog;
248 double soa = cos(angle * PI / 180.);
250 double time_to_wp = dist / soa;
252 if (time_to_wp > 0) {
253 if (time_to_wp < min_time_found) {
254 min_time_found = time_to_wp;
258 node = node->GetNext();
264 g_bAllowShipToActive =
false;
267 v[_T(
"GUID")] = pRouteToActivate->
m_GUID;
268 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_RTE_ACTIVATED");
269 if (g_bPluginHandleAutopilotRoute)
return true;
273 m_have_n0183_out =
false;
274 m_have_n2000_out =
false;
276 m_output_drivers.clear();
279 if (attributes.find(
"protocol") == attributes.end())
continue;
280 if (attributes.at(
"protocol") ==
"nmea0183") {
281 if (attributes.find(
"ioDirection") != attributes.end()) {
282 if ((attributes.at(
"ioDirection") ==
"IN/OUT") ||
283 (attributes.at(
"ioDirection") ==
"OUT")) {
284 m_output_drivers.push_back(handle);
285 m_have_n0183_out =
true;
291 if (attributes.find(
"protocol") == attributes.end())
continue;
292 if (attributes.at(
"protocol") ==
"nmea2000") {
293 if (attributes.find(
"ioDirection") != attributes.end()) {
294 if ((attributes.at(
"ioDirection") ==
"IN/OUT") ||
295 (attributes.at(
"ioDirection") ==
"OUT")) {
296 m_output_drivers.push_back(handle);
297 m_have_n2000_out =
true;
304 pActiveRoute = pRouteToActivate;
305 g_active_route = pActiveRoute->GetGUID();
308 pActivePoint = pStartPoint;
310 wxRoutePointListNode *node = (pActiveRoute->
pRoutePointList)->GetFirst();
311 pActivePoint = node->GetData();
322 m_bDataValid =
false;
324 m_route_dlg_ctx.show_with_fresh_fonts();
329 g_bAllowShipToActive =
false;
331 v[_T(
"GUID")] = pRP_target->
m_GUID;
332 v[_T(
"WP_activated")] = pRP_target->GetName();
334 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_WPT_ACTIVATED");
336 if (g_bPluginHandleAutopilotRoute)
return true;
340 pActivePoint = pRP_target;
343 wxRoutePointListNode *node = (pActiveRoute->
pRoutePointList)->GetFirst();
349 node = node->GetNext();
357 if (pRP_target == prp_first) {
358 if (pRouteActivatePoint)
delete pRouteActivatePoint;
360 pRouteActivatePoint =
361 new RoutePoint(gLat, gLon, wxString(_T(
"")), wxString(_T(
"Begin")),
362 wxEmptyString,
false);
365 pActiveRouteSegmentBeginPoint = pRouteActivatePoint;
370 node = node->GetNext();
374 if (pnext == pRP_target) {
375 pActiveRouteSegmentBeginPoint = np_prev;
380 node = node->GetNext();
399 m_prop_dlg_ctx.set_enroute_point(pA, pActivePoint);
404 g_bAllowShipToActive =
false;
411 v[_T(
"isSkipped")] = skipped;
412 v[_T(
"GUID")] = pActivePoint->
m_GUID;
413 v[_T(
"GUID_WP_arrived")] = pActivePoint->
m_GUID;
414 v[_T(
"WP_arrived")] = pActivePoint->GetName();
416 int n_index_active = pActiveRoute->GetIndexOf(pActivePoint);
418 while (n_index_active == pActiveRoute->GetIndexOf(pActivePoint)) {
419 if ((n_index_active + step) <= pActiveRoute->GetnPoints()) {
420 pActiveRouteSegmentBeginPoint = pActivePoint;
422 pActiveRoute->GetPoint(n_index_active + step);
423 pActivePoint = pActiveRoute->GetPoint(n_index_active + step);
432 v[_T(
"Next_WP")] = pActivePoint->GetName();
433 v[_T(
"GUID_Next_WP")] = pActivePoint->
m_GUID;
448 m_prop_dlg_ctx.set_enroute_point(pr, pActivePoint);
450 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_WPT_ARRIVED");
455bool Routeman::DeactivateRoute(
bool b_arrival) {
464 g_active_route.Clear();
469 v[_T(
"GUID")] = pActiveRoute->
m_GUID;
470 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_RTE_DEACTIVATED");
472 v[_T(
"GUID")] = pActiveRoute->
m_GUID;
474 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_RTE_ENDED");
480 if (pRouteActivatePoint)
delete pRouteActivatePoint;
481 pRouteActivatePoint = NULL;
485 m_route_dlg_ctx.clear_console_background();
486 m_bDataValid =
false;
491bool Routeman::UpdateAutopilot() {
492 if (!pActiveRoute)
return false;
494 if (!bGPSValid)
return false;
499 if ((g_maxWPNameLength >= 3) && (g_maxWPNameLength <= 32))
500 maxName = g_maxWPNameLength;
502 if (m_have_n0183_out) rv |= UpdateAutopilotN0183(*
this);
503 if (m_have_n2000_out) rv |= UpdateAutopilotN2K(*
this);
507 if (!pActiveRoute)
return false;
511 leg_info.Btw = CurrentBrgToActivePoint;
512 leg_info.Dtw = CurrentRngToActivePoint;
513 leg_info.Xte = CurrentXTEToActivePoint;
515 leg_info.Xte = -leg_info.Xte;
517 leg_info.wp_name = pActivePoint->GetName().Truncate(maxName);
518 leg_info.arrival = m_bArrival;
529 if ((g_maxWPNameLength >= 3) && (g_maxWPNameLength <= 32))
530 maxName = g_maxWPNameLength;
534 double r_Sog(0.0), r_Cog(0.0);
535 if (!std::isnan(gSog)) r_Sog = gSog;
536 if (!std::isnan(gCog)) r_Cog = gCog;
541 leg_info.Btw = CurrentBrgToActivePoint;
542 leg_info.Dtw = CurrentRngToActivePoint;
543 leg_info.Xte = CurrentXTEToActivePoint;
545 leg_info.Xte = -leg_info.Xte;
547 leg_info.wp_name = pActivePoint->GetName().Truncate(maxName);
548 leg_info.arrival = m_bArrival;
554 m_NMEA0183.TalkerID =
"EC";
556 m_NMEA0183.Rmb.IsDataValid = bGPSValid ? NTrue : NFalse;
557 m_NMEA0183.Rmb.CrossTrackError = CurrentXTEToActivePoint;
558 m_NMEA0183.Rmb.DirectionToSteer = XTEDir < 0 ? Left : Right;
559 m_NMEA0183.Rmb.RangeToDestinationNauticalMiles = CurrentRngToActivePoint;
560 m_NMEA0183.Rmb.BearingToDestinationDegreesTrue = CurrentBrgToActivePoint;
562 if (pActivePoint->m_lat < 0.)
563 m_NMEA0183.Rmb.DestinationPosition.Latitude.Set(-pActivePoint->m_lat,
566 m_NMEA0183.Rmb.DestinationPosition.Latitude.Set(pActivePoint->m_lat,
"N");
568 if (pActivePoint->m_lon < 0.)
569 m_NMEA0183.Rmb.DestinationPosition.Longitude.Set(-pActivePoint->m_lon,
572 m_NMEA0183.Rmb.DestinationPosition.Longitude.Set(pActivePoint->m_lon,
575 m_NMEA0183.Rmb.DestinationClosingVelocityKnots =
576 r_Sog * cos((r_Cog - CurrentBrgToActivePoint) * PI / 180.0);
577 m_NMEA0183.Rmb.IsArrivalCircleEntered = m_bArrival ? NTrue : NFalse;
578 m_NMEA0183.Rmb.FAAModeIndicator = bGPSValid ?
"A" :
"N";
581 int wp_len = maxName;
583 m_NMEA0183.Rmb.To = pActivePoint->GetName().Truncate(wp_len);
584 m_NMEA0183.Rmb.From =
585 pActiveRouteSegmentBeginPoint->GetName().Truncate(wp_len);
586 m_NMEA0183.Rmb.Write(snt);
588 }
while (snt.Sentence.size() > 82 && wp_len > 0);
595 m_NMEA0183.TalkerID = _T(
"EC");
598 m_NMEA0183.Rmc.IsDataValid = NTrue;
599 if (!bGPSValid) m_NMEA0183.Rmc.IsDataValid = NFalse;
602 m_NMEA0183.Rmc.Position.Latitude.Set(-gLat, _T(
"S"));
604 m_NMEA0183.Rmc.Position.Latitude.Set(gLat, _T(
"N"));
607 m_NMEA0183.Rmc.Position.Longitude.Set(-gLon, _T(
"W"));
609 m_NMEA0183.Rmc.Position.Longitude.Set(gLon, _T(
"E"));
611 m_NMEA0183.Rmc.SpeedOverGroundKnots = r_Sog;
612 m_NMEA0183.Rmc.TrackMadeGoodDegreesTrue = r_Cog;
614 if (!std::isnan(gVar)) {
616 m_NMEA0183.Rmc.MagneticVariation = -gVar;
617 m_NMEA0183.Rmc.MagneticVariationDirection = West;
619 m_NMEA0183.Rmc.MagneticVariation = gVar;
620 m_NMEA0183.Rmc.MagneticVariationDirection = East;
623 m_NMEA0183.Rmc.MagneticVariation =
627 if (!gRmcTime.IsEmpty() && !gRmcDate.IsEmpty()) {
628 m_NMEA0183.Rmc.UTCTime = gRmcTime;
629 m_NMEA0183.Rmc.Date = gRmcDate;
631 wxDateTime now = wxDateTime::Now();
632 wxDateTime utc = now.ToUTC();
633 wxString time = utc.Format(_T(
"%H%M%S"));
634 m_NMEA0183.Rmc.UTCTime = time;
635 wxString date = utc.Format(_T(
"%d%m%y"));
636 m_NMEA0183.Rmc.Date = date;
639 m_NMEA0183.Rmc.FAAModeIndicator =
"A";
640 if (!bGPSValid) m_NMEA0183.Rmc.FAAModeIndicator =
"N";
642 m_NMEA0183.Rmc.Write(snt);
649 m_NMEA0183.TalkerID = _T(
"EC");
653 m_NMEA0183.Apb.IsLoranBlinkOK =
655 if (!bGPSValid) m_NMEA0183.Apb.IsLoranBlinkOK = NFalse;
657 m_NMEA0183.Apb.IsLoranCCycleLockOK = NTrue;
658 if (!bGPSValid) m_NMEA0183.Apb.IsLoranCCycleLockOK = NFalse;
660 m_NMEA0183.Apb.CrossTrackErrorMagnitude = CurrentXTEToActivePoint;
663 m_NMEA0183.Apb.DirectionToSteer = Left;
665 m_NMEA0183.Apb.DirectionToSteer = Right;
667 m_NMEA0183.Apb.CrossTrackUnits = _T(
"N");
670 m_NMEA0183.Apb.IsArrivalCircleEntered = NTrue;
672 m_NMEA0183.Apb.IsArrivalCircleEntered = NFalse;
676 m_NMEA0183.Apb.IsPerpendicular = NFalse;
678 m_NMEA0183.Apb.To = pActivePoint->GetName().Truncate(maxName);
681 DistanceBearingMercator(pActivePoint->m_lat, pActivePoint->m_lon,
682 pActiveRouteSegmentBeginPoint->m_lat,
683 pActiveRouteSegmentBeginPoint->m_lon, &brg1,
686 if (g_bMagneticAPB && !std::isnan(gVar)) {
688 ((brg1 - gVar) >= 0.) ? (brg1 - gVar) : (brg1 - gVar + 360.);
689 double bapm = ((CurrentBrgToActivePoint - gVar) >= 0.)
690 ? (CurrentBrgToActivePoint - gVar)
691 : (CurrentBrgToActivePoint - gVar + 360.);
693 m_NMEA0183.Apb.BearingOriginToDestination = brg1m;
694 m_NMEA0183.Apb.BearingOriginToDestinationUnits = _T(
"M");
696 m_NMEA0183.Apb.BearingPresentPositionToDestination = bapm;
697 m_NMEA0183.Apb.BearingPresentPositionToDestinationUnits = _T(
"M");
699 m_NMEA0183.Apb.HeadingToSteer = bapm;
700 m_NMEA0183.Apb.HeadingToSteerUnits = _T(
"M");
702 m_NMEA0183.Apb.BearingOriginToDestination = brg1;
703 m_NMEA0183.Apb.BearingOriginToDestinationUnits = _T(
"T");
705 m_NMEA0183.Apb.BearingPresentPositionToDestination =
706 CurrentBrgToActivePoint;
707 m_NMEA0183.Apb.BearingPresentPositionToDestinationUnits = _T(
"T");
709 m_NMEA0183.Apb.HeadingToSteer = CurrentBrgToActivePoint;
710 m_NMEA0183.Apb.HeadingToSteerUnits = _T(
"T");
713 m_NMEA0183.Apb.Write(snt);
719 m_NMEA0183.TalkerID = _T(
"EC");
723 m_NMEA0183.Xte.IsLoranBlinkOK =
725 if (!bGPSValid) m_NMEA0183.Xte.IsLoranBlinkOK = NFalse;
727 m_NMEA0183.Xte.IsLoranCCycleLockOK = NTrue;
728 if (!bGPSValid) m_NMEA0183.Xte.IsLoranCCycleLockOK = NFalse;
730 m_NMEA0183.Xte.CrossTrackErrorDistance = CurrentXTEToActivePoint;
733 m_NMEA0183.Xte.DirectionToSteer = Left;
735 m_NMEA0183.Xte.DirectionToSteer = Right;
737 m_NMEA0183.Xte.CrossTrackUnits = _T(
"N");
739 m_NMEA0183.Xte.Write(snt);
747bool Routeman::DoesRouteContainSharedPoints(
Route *pRoute) {
759 for (
unsigned int ir = 0; ir < pRA->GetCount(); ir++) {
769 if (pnode) pnode = pnode->GetNext();
776 if (prp->IsShared())
return true;
778 if (pnode) pnode = pnode->GetNext();
785bool Routeman::DeleteTrack(
Track *pTrack) {
786 if (pTrack && !pTrack->m_bIsInLayer) {
787 ::wxBeginBusyCursor();
803 pSelect->DeleteAllSelectableTrackSegments(pTrack);
804 auto it = std::find(g_TrackList.begin(), g_TrackList.end(), pTrack);
805 if (it != g_TrackList.end()) {
806 g_TrackList.erase(it);
820 if (pRoute == pAISMOBRoute) {
821 if (!m_route_dlg_ctx.confirm_delete_ais_mob()) {
826 ::wxBeginBusyCursor();
828 if (GetpActiveRoute() == pRoute) DeactivateRoute();
838 m_prop_dlg_ctx.hide(pRoute);
843 pSelect->DeleteAllSelectableRouteSegments(pRoute);
844 pRouteList->DeleteObject(pRoute);
846 m_route_dlg_ctx.route_mgr_dlg_update_list_ctrl();
855 Route *pcontainer_route = FindRouteContainingWaypoint(prp);
860 if (!prp->IsShared()) {
861 pSelect->DeleteSelectablePoint(prp, SELTYPE_ROUTEPOINT);
864 wxRoutePointListNode *pdnode = pnode;
871 NavObj_dB::GetInstance().DeleteRoutePoint(prp);
875 prp->SetShared(
false);
876 NavObj_dB::GetInstance().UpdateRoutePoint(prp);
880 pnode = pnode->GetNext();
885 NavObj_dB::GetInstance().DeleteRoute(pRoute);
893void Routeman::DeleteAllRoutes() {
894 ::wxBeginBusyCursor();
897 wxRouteListNode *node = pRouteList->GetFirst();
899 Route *proute = node->GetData();
900 if (proute == pAISMOBRoute) {
901 if (!m_route_dlg_ctx.confirm_delete_ais_mob()) {
905 ::wxBeginBusyCursor();
908 node = node->GetNext();
917void Routeman::SetColorScheme(ColorScheme cs,
double displayDPmm) {
920 int scaled_line_width = g_route_line_width;
921 int track_scaled_line_width = g_track_line_width;
924 double nominal_line_width_pix = wxMax(2.0, floor(displayDPmm * 0.4));
926 double sline_width = wxMax(nominal_line_width_pix, g_route_line_width);
927 sline_width *= g_ChartScaleFactorExp;
928 scaled_line_width = wxMax(sline_width, 2);
930 double tsline_width = wxMax(nominal_line_width_pix, g_track_line_width);
931 tsline_width *= g_ChartScaleFactorExp;
932 track_scaled_line_width = wxMax(tsline_width, 2);
935 m_pActiveRoutePointPen = wxThePenList->FindOrCreatePen(
936 wxColour(0, 0, 255), scaled_line_width, wxPENSTYLE_SOLID);
937 m_pRoutePointPen = wxThePenList->FindOrCreatePen(
938 wxColour(0, 0, 255), scaled_line_width, wxPENSTYLE_SOLID);
943 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"UINFB"),
944 scaled_line_width, wxPENSTYLE_SOLID);
945 m_pSelectedRoutePen =
946 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"UINFO"),
947 scaled_line_width, wxPENSTYLE_SOLID);
949 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"UARTE"),
950 scaled_line_width, wxPENSTYLE_SOLID);
952 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"CHMGD"),
953 track_scaled_line_width, wxPENSTYLE_SOLID);
954 m_pRouteBrush = wxTheBrushList->FindOrCreateBrush(
955 m_route_dlg_ctx.get_global_colour(
"UINFB"), wxBRUSHSTYLE_SOLID);
956 m_pSelectedRouteBrush = wxTheBrushList->FindOrCreateBrush(
957 m_route_dlg_ctx.get_global_colour(
"UINFO"), wxBRUSHSTYLE_SOLID);
958 m_pActiveRouteBrush = wxTheBrushList->FindOrCreateBrush(
959 m_route_dlg_ctx.get_global_colour(
"PLRTE"), wxBRUSHSTYLE_SOLID);
962wxString Routeman::GetRouteReverseMessage(
void) {
964 _(
"Waypoints can be renamed to reflect the new order, the names will be "
965 "'001', '002' etc.\n\nDo you want to rename the waypoints?"));
968wxString Routeman::GetRouteResequenceMessage(
void) {
970 _(
"Waypoints will be renamed to reflect the natural order, the names "
971 "will be '001', '002' etc.\n\nDo you want to rename the waypoints?"));
974Route *Routeman::FindRouteByGUID(
const wxString &guid) {
975 wxRouteListNode *node1 = pRouteList->GetFirst();
977 Route *pRoute = node1->GetData();
979 if (pRoute->
m_GUID == guid)
return pRoute;
980 node1 = node1->GetNext();
986Track *Routeman::FindTrackByGUID(
const wxString &guid) {
987 for (
Track *pTrack : g_TrackList) {
988 if (pTrack->m_GUID == guid)
return pTrack;
994void Routeman::ZeroCurrentXTEToActivePoint() {
996 if (pRouteActivatePoint)
delete pRouteActivatePoint;
997 pRouteActivatePoint =
998 new RoutePoint(gLat, gLon, wxString(_T(
"")), wxString(_T(
"")),
999 wxEmptyString,
false);
1002 pActiveRouteSegmentBeginPoint = pRouteActivatePoint;
1003 m_arrival_min = 1e6;
1010WayPointman::WayPointman(GlobalColourFunc color_func)
1011 : m_get_global_colour(color_func) {
1012 m_pWayPointList =
new RoutePointList;
1014 pmarkicon_image_list = NULL;
1017 m_pIconArray =
new ArrayOfMarkIcon;
1018 m_pLegacyIconArray = NULL;
1019 m_pExtendedIconArray = NULL;
1021 m_cs = (ColorScheme)-1;
1024 m_iconListScale = -999.0;
1025 m_iconListHeight = -1;
1028WayPointman::~WayPointman() {
1034 RoutePointList temp_list;
1036 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1040 temp_list.Append(pr);
1041 node = node->GetNext();
1044 int a = temp_list.GetCount();
1046 temp_list.DeleteContents(
true);
1049 m_pWayPointList->Clear();
1050 delete m_pWayPointList;
1052 for (
unsigned int i = 0; i < m_pIconArray->GetCount(); i++) {
1054 delete pmi->piconBitmap;
1058 m_pIconArray->Clear();
1059 delete m_pIconArray;
1061 if (pmarkicon_image_list) pmarkicon_image_list->RemoveAll();
1062 delete pmarkicon_image_list;
1063 m_pLegacyIconArray->Clear();
1064 delete m_pLegacyIconArray;
1065 m_pExtendedIconArray->Clear();
1066 delete m_pExtendedIconArray;
1070 if (!prp)
return false;
1072 wxRoutePointListNode *prpnode = m_pWayPointList->Append(prp);
1073 prp->SetManagerListNode(prpnode);
1079 if (!prp)
return false;
1081 wxRoutePointListNode *prpnode =
1082 (wxRoutePointListNode *)prp->GetManagerListNode();
1087 m_pWayPointList->DeleteObject(prp);
1089 prp->SetManagerListNode(NULL);
1094wxImageList *WayPointman::Getpmarkicon_image_list(
int nominal_height) {
1096 if (pmarkicon_image_list && (nominal_height == m_iconListHeight)) {
1097 return pmarkicon_image_list;
1101 if (NULL != pmarkicon_image_list) {
1102 pmarkicon_image_list->RemoveAll();
1103 delete pmarkicon_image_list;
1105 pmarkicon_image_list =
new wxImageList(nominal_height, nominal_height);
1107 m_iconListHeight = nominal_height;
1108 m_bitmapSizeForList = nominal_height;
1110 return pmarkicon_image_list;
1113wxBitmap *WayPointman::CreateDimBitmap(wxBitmap *pBitmap,
double factor) {
1114 wxImage img = pBitmap->ConvertToImage();
1115 int sx = img.GetWidth();
1116 int sy = img.GetHeight();
1118 wxImage new_img(img);
1120 for (
int i = 0; i < sx; i++) {
1121 for (
int j = 0; j < sy; j++) {
1122 if (!img.IsTransparent(i, j)) {
1123 new_img.SetRGB(i, j, (
unsigned char)(img.GetRed(i, j) * factor),
1124 (
unsigned char)(img.GetGreen(i, j) * factor),
1125 (
unsigned char)(img.GetBlue(i, j) * factor));
1130 wxBitmap *pret =
new wxBitmap(new_img);
1135wxImage WayPointman::CreateDimImage(wxImage &image,
double factor) {
1136 int sx = image.GetWidth();
1137 int sy = image.GetHeight();
1139 wxImage new_img(image);
1141 for (
int i = 0; i < sx; i++) {
1142 for (
int j = 0; j < sy; j++) {
1143 if (!image.IsTransparent(i, j)) {
1144 new_img.SetRGB(i, j, (
unsigned char)(image.GetRed(i, j) * factor),
1145 (
unsigned char)(image.GetGreen(i, j) * factor),
1146 (
unsigned char)(image.GetBlue(i, j) * factor));
1151 return wxImage(new_img);
1154bool WayPointman::DoesIconExist(
const wxString &icon_key)
const {
1158 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1159 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1160 if (pmi->icon_name.IsSameAs(icon_key))
return true;
1166wxBitmap *WayPointman::GetIconBitmap(
const wxString &icon_key)
const {
1167 wxBitmap *pret = NULL;
1171 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1172 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1173 if (pmi->icon_name.IsSameAs(icon_key))
break;
1176 if (i == m_pIconArray->GetCount())
1179 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1180 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1186 if (i == m_pIconArray->GetCount())
1187 pmi = (
MarkIcon *)m_pIconArray->Item(0);
1190 if (pmi->piconBitmap)
1191 pret = pmi->piconBitmap;
1193 if (pmi->iconImage.IsOk()) {
1194 pmi->piconBitmap =
new wxBitmap(pmi->iconImage);
1195 pret = pmi->piconBitmap;
1202bool WayPointman::GetIconPrescaled(
const wxString &icon_key)
const {
1206 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1207 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1208 if (pmi->icon_name.IsSameAs(icon_key))
break;
1211 if (i == m_pIconArray->GetCount())
1214 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1215 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1221 if (i == m_pIconArray->GetCount())
1222 pmi = (
MarkIcon *)m_pIconArray->Item(0);
1225 return pmi->preScaled;
1230wxBitmap WayPointman::GetIconBitmapForList(
int index,
int height)
const {
1235 pmi = (
MarkIcon *)m_pIconArray->Item(index);
1237 if (pmi->iconImage.GetHeight() != height) {
1240 int w0 = pmi->iconImage.GetWidth();
1241 int h0 = pmi->iconImage.GetHeight();
1243 wxImage icon_resized = pmi->iconImage;
1244 if (h0 <= h && w0 <= w) {
1245 icon_resized = pmi->iconImage.Resize(
1246 wxSize(w, h), wxPoint(w / 2 - w0 / 2, h / 2 - h0 / 2));
1253 w1 = wxRound((
double)w0 * ((
double)h / (
double)h0));
1256 h1 = wxRound((
double)h0 * ((
double)w / (
double)w0));
1258 icon_resized = pmi->iconImage.Rescale(w1, h1);
1259 icon_resized = pmi->iconImage.Resize(
1260 wxSize(w, h), wxPoint(w / 2 - w1 / 2, h / 2 - h1 / 2));
1263 pret = wxBitmap(icon_resized);
1266 pret = wxBitmap(pmi->iconImage);
1272wxString *WayPointman::GetIconDescription(
int index)
const {
1273 wxString *pret = NULL;
1277 pret = &pmi->icon_description;
1282wxString WayPointman::GetIconDescription(wxString icon_key)
const {
1286 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1287 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1288 if (pmi->icon_name.IsSameAs(icon_key))
1289 return wxString(pmi->icon_description);
1292 return wxEmptyString;
1295wxString *WayPointman::GetIconKey(
int index)
const {
1296 wxString *pret = NULL;
1298 if ((index >= 0) && ((
unsigned int)index < m_pIconArray->GetCount())) {
1300 pret = &pmi->icon_name;
1305int WayPointman::GetIconIndex(
const wxBitmap *pbm)
const {
1306 unsigned int ret = 0;
1309 wxASSERT(m_pIconArray->GetCount() >= 1);
1310 for (
unsigned int i = 0; i < m_pIconArray->GetCount(); i++) {
1311 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1312 if (pmi->piconBitmap == pbm) {
1321int WayPointman::GetIconImageListIndex(
const wxBitmap *pbm)
const {
1325 if (pmarkicon_image_list && !pmi->m_blistImageOK) {
1326 int h0 = pmi->iconImage.GetHeight();
1327 int w0 = pmi->iconImage.GetWidth();
1328 int h = m_bitmapSizeForList;
1329 int w = m_bitmapSizeForList;
1331 wxImage icon_larger = pmi->iconImage;
1332 if (h0 <= h && w0 <= w) {
1333 icon_larger = pmi->iconImage.Resize(
1334 wxSize(w, h), wxPoint(w / 2 - w0 / 2, h / 2 - h0 / 2));
1343 w1 = wxRound((
double)w0 * ((
double)h / (
double)h0));
1346 h1 = wxRound((
double)h0 * ((
double)w / (
double)w0));
1348 icon_larger = pmi->iconImage.Rescale(w1, h1).Resize(
1349 wxSize(w, h), wxPoint(w / 2 - w1 / 2, h / 2 - h1 / 2));
1352 int index = pmarkicon_image_list->Add(wxBitmap(icon_larger));
1357 icon_larger.ConvertAlphaToMask(128);
1359 unsigned char r, g, b;
1360 icon_larger.GetOrFindMaskColour(&r, &g, &b);
1361 wxColour unused_color(r, g, b);
1364 wxBitmap xIcon(icon_larger);
1366 wxBitmap xbmp(w, h, -1);
1367 wxMemoryDC mdc(xbmp);
1368 mdc.SetBackground(wxBrush(unused_color));
1370 mdc.DrawBitmap(xIcon, 0, 0);
1371 int xm = xbmp.GetWidth() / 2;
1372 int ym = xbmp.GetHeight() / 2;
1374 int width = wxMax(xm / 10, 2);
1375 wxPen red(m_get_global_colour(
"URED"), width);
1377 mdc.DrawLine(xm - dp, ym - dp, xm + dp, ym + dp);
1378 mdc.DrawLine(xm - dp, ym + dp, xm + dp, ym - dp);
1379 mdc.SelectObject(wxNullBitmap);
1381 wxMask *pmask =
new wxMask(xbmp, unused_color);
1382 xbmp.SetMask(pmask);
1384 pmarkicon_image_list->Add(xbmp);
1387 wxBitmap fIcon(icon_larger);
1389 wxBitmap fbmp(w, h, -1);
1390 wxMemoryDC fmdc(fbmp);
1391 fmdc.SetBackground(wxBrush(unused_color));
1393 fmdc.DrawBitmap(xIcon, 0, 0);
1394 xm = fbmp.GetWidth() / 2;
1395 ym = fbmp.GetHeight() / 2;
1397 width = wxMax(xm / 10, 2);
1398 wxPen fred(m_get_global_colour(
"UGREN"), width);
1400 fmdc.DrawLine(xm - dp, ym + dp, xm + dp, ym + dp);
1401 fmdc.SelectObject(wxNullBitmap);
1403 wxMask *pfmask =
new wxMask(fbmp, unused_color);
1404 fbmp.SetMask(pfmask);
1406 pmarkicon_image_list->Add(fbmp);
1408 pmi->m_blistImageOK =
true;
1409 pmi->listIndex = index;
1412 return pmi->listIndex;
1416 return GetIconImageListIndex(pbm) + 1;
1420 return GetIconImageListIndex(pbm) + 2;
1424wxString WayPointman::CreateGUID(
RoutePoint *pRP) {
1428RoutePoint *WayPointman::FindRoutePointByGUID(
const wxString &guid) {
1429 wxRoutePointListNode *prpnode = m_pWayPointList->GetFirst();
1433 if (prp->
m_GUID == guid)
return (prp);
1435 prpnode = prpnode->GetNext();
1441RoutePoint *WayPointman::GetNearbyWaypoint(
double lat,
double lon,
1442 double radius_meters) {
1445 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1449 double a = lat - pr->m_lat;
1450 double b = lon - pr->m_lon;
1451 double l = sqrt((a * a) + (b * b));
1453 if ((l * 60. * 1852.) < radius_meters)
return pr;
1455 node = node->GetNext();
1460RoutePoint *WayPointman::GetOtherNearbyWaypoint(
double lat,
double lon,
1461 double radius_meters,
1462 const wxString &guid) {
1465 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1469 double a = lat - pr->m_lat;
1470 double b = lon - pr->m_lon;
1471 double l = sqrt((a * a) + (b * b));
1473 if ((l * 60. * 1852.) < radius_meters)
1474 if (pr->
m_GUID != guid)
return pr;
1476 node = node->GetNext();
1481bool WayPointman::IsReallyVisible(
RoutePoint *pWP) {
1483 return pWP->IsVisible();
1485 wxRouteListNode *node = pRouteList->GetFirst();
1487 Route *proute = node->GetData();
1490 if (proute->IsVisible())
return true;
1493 node = node->GetNext();
1496 if (pWP->IsShared())
1498 return pWP->IsVisible();
1503void WayPointman::ClearRoutePointFonts(
void) {
1507 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1512 node = node->GetNext();
1516bool WayPointman::SharedWptsExist() {
1517 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1520 if (prp->IsShared() && (prp->
m_bIsInRoute || prp == pAnchorWatchPoint1 ||
1521 prp == pAnchorWatchPoint2))
1523 node = node->GetNext();
1528void WayPointman::DeleteAllWaypoints(
bool b_delete_used) {
1530 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1534 if (!prp->
m_bIsInLayer && (prp->GetIconName() != _T(
"mob")) &&
1535 ((b_delete_used && prp->IsShared()) ||
1536 ((!prp->
m_bIsInRoute) && !(prp == pAnchorWatchPoint1) &&
1537 !(prp == pAnchorWatchPoint2)))) {
1538 DestroyWaypoint(prp);
1540 node = m_pWayPointList->GetFirst();
1542 node = node->GetNext();
1547RoutePoint *WayPointman::FindWaypointByGuid(
const std::string &guid) {
1548 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1551 if (guid == rp->
m_GUID)
return rp;
1552 node = node->GetNext();
1556void WayPointman::DestroyWaypoint(
RoutePoint *pRp,
bool b_update_changeset) {
1562 for (
unsigned int ir = 0; ir < proute_array->GetCount(); ir++) {
1569 pr->RemovePoint(pRp);
1573 for (
unsigned int ir = 0; ir < proute_array->GetCount(); ir++) {
1575 if (pr->GetnPoints() < 2) {
1580 delete proute_array;
1584 NavObj_dB::GetInstance().DeleteRoutePoint(pRp);
1586 pSelect->DeleteSelectableRoutePoint(pRp);
1589 if (pRp == pAnchorWatchPoint1) pAnchorWatchPoint1 = NULL;
1590 if (pRp == pAnchorWatchPoint2) pAnchorWatchPoint2 = NULL;
Class AisDecoder and helpers.
void Notify() override
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.
Global variables stored in configuration file.
Global variables Listen()/Notify() wrapper.
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.