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.find(
"protocol") == attributes.end())
continue;
308 if (attributes.at(
"protocol") ==
"nmea2000") {
309 if (attributes.find(
"ioDirection") != attributes.end()) {
310 if ((attributes.at(
"ioDirection") ==
"IN/OUT") ||
311 (attributes.at(
"ioDirection") ==
"OUT")) {
312 m_output_drivers.push_back(handle);
313 m_have_n2000_out =
true;
320 pActiveRoute = pRouteToActivate;
321 g_active_route = pActiveRoute->GetGUID();
324 pActivePoint = pStartPoint;
326 wxRoutePointListNode *node = (pActiveRoute->
pRoutePointList)->GetFirst();
327 pActivePoint = node->GetData();
338 m_bDataValid =
false;
340 m_route_dlg_ctx.show_with_fresh_fonts();
345 g_bAllowShipToActive =
false;
347 v[_T(
"GUID")] = pRP_target->
m_GUID;
348 v[_T(
"WP_activated")] = pRP_target->GetName();
350 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_WPT_ACTIVATED");
352 if (g_bPluginHandleAutopilotRoute)
return true;
356 pActivePoint = pRP_target;
359 wxRoutePointListNode *node = (pActiveRoute->
pRoutePointList)->GetFirst();
365 node = node->GetNext();
373 if (pRP_target == prp_first) {
374 if (pRouteActivatePoint)
delete pRouteActivatePoint;
376 pRouteActivatePoint =
377 new RoutePoint(gLat, gLon, wxString(_T(
"")), wxString(_T(
"Begin")),
378 wxEmptyString,
false);
381 pActiveRouteSegmentBeginPoint = pRouteActivatePoint;
386 node = node->GetNext();
390 if (pnext == pRP_target) {
391 pActiveRouteSegmentBeginPoint = np_prev;
396 node = node->GetNext();
415 m_prop_dlg_ctx.set_enroute_point(pA, pActivePoint);
420 g_bAllowShipToActive =
false;
427 v[_T(
"isSkipped")] = skipped;
428 v[_T(
"GUID")] = pActivePoint->
m_GUID;
429 v[_T(
"GUID_WP_arrived")] = pActivePoint->
m_GUID;
430 v[_T(
"WP_arrived")] = pActivePoint->GetName();
432 int n_index_active = pActiveRoute->GetIndexOf(pActivePoint);
434 while (n_index_active == pActiveRoute->GetIndexOf(pActivePoint)) {
435 if ((n_index_active + step) <= pActiveRoute->GetnPoints()) {
436 pActiveRouteSegmentBeginPoint = pActivePoint;
438 pActiveRoute->GetPoint(n_index_active + step);
439 pActivePoint = pActiveRoute->GetPoint(n_index_active + step);
448 v[_T(
"Next_WP")] = pActivePoint->GetName();
449 v[_T(
"GUID_Next_WP")] = pActivePoint->
m_GUID;
464 m_prop_dlg_ctx.set_enroute_point(pr, pActivePoint);
466 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_WPT_ARRIVED");
471bool Routeman::DeactivateRoute(
bool b_arrival) {
480 g_active_route.Clear();
485 v[_T(
"GUID")] = pActiveRoute->
m_GUID;
486 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_RTE_DEACTIVATED");
488 v[_T(
"GUID")] = pActiveRoute->
m_GUID;
490 json_msg.
Notify(std::make_shared<wxJSONValue>(v),
"OCPN_RTE_ENDED");
496 if (pRouteActivatePoint)
delete pRouteActivatePoint;
497 pRouteActivatePoint = NULL;
501 m_route_dlg_ctx.clear_console_background();
502 m_bDataValid =
false;
507bool Routeman::UpdateAutopilot() {
508 if (!pActiveRoute)
return false;
510 if (!bGPSValid)
return false;
515 if ((g_maxWPNameLength >= 3) && (g_maxWPNameLength <= 32))
516 maxName = g_maxWPNameLength;
520 auto& registry = CommDriverRegistry::GetInstance();
521 const std::vector<DriverPtr>& drivers = registry.GetDrivers();
524 bool have_n0183 =
false;
525 bool have_n2000 =
false;
528 for (
auto key : m_output_drivers) {
529 for (
auto &d : drivers) {
530 if (d->Key() == key) {
531 std::unordered_map<std::string, std::string> attributes =
533 auto protocol_it = attributes.find(
"protocol");
534 if (protocol_it != attributes.end()) {
535 std::string protocol = protocol_it->second;
537 if (protocol ==
"nmea0183") {
539 }
else if (protocol ==
"nmea2000") {
548 if (m_have_n0183_out) rv |= UpdateAutopilotN0183(*
this);
550 if (m_have_n2000_out) rv |= UpdateAutopilotN2K(*
this);
555 leg_info.Btw = CurrentBrgToActivePoint;
556 leg_info.Dtw = CurrentRngToActivePoint;
557 leg_info.Xte = CurrentXTEToActivePoint;
559 leg_info.Xte = -leg_info.Xte;
561 leg_info.wp_name = pActivePoint->GetName().Truncate(maxName);
562 leg_info.arrival = m_bArrival;
573 if ((g_maxWPNameLength >= 3) && (g_maxWPNameLength <= 32))
574 maxName = g_maxWPNameLength;
578 double r_Sog(0.0), r_Cog(0.0);
579 if (!std::isnan(gSog)) r_Sog = gSog;
580 if (!std::isnan(gCog)) r_Cog = gCog;
585 leg_info.Btw = CurrentBrgToActivePoint;
586 leg_info.Dtw = CurrentRngToActivePoint;
587 leg_info.Xte = CurrentXTEToActivePoint;
589 leg_info.Xte = -leg_info.Xte;
591 leg_info.wp_name = pActivePoint->GetName().Truncate(maxName);
592 leg_info.arrival = m_bArrival;
598 m_NMEA0183.TalkerID =
"EC";
600 m_NMEA0183.Rmb.IsDataValid = bGPSValid ? NTrue : NFalse;
601 m_NMEA0183.Rmb.CrossTrackError = CurrentXTEToActivePoint;
602 m_NMEA0183.Rmb.DirectionToSteer = XTEDir < 0 ? Left : Right;
603 m_NMEA0183.Rmb.RangeToDestinationNauticalMiles = CurrentRngToActivePoint;
604 m_NMEA0183.Rmb.BearingToDestinationDegreesTrue = CurrentBrgToActivePoint;
606 if (pActivePoint->m_lat < 0.)
607 m_NMEA0183.Rmb.DestinationPosition.Latitude.Set(-pActivePoint->m_lat,
610 m_NMEA0183.Rmb.DestinationPosition.Latitude.Set(pActivePoint->m_lat,
"N");
612 if (pActivePoint->m_lon < 0.)
613 m_NMEA0183.Rmb.DestinationPosition.Longitude.Set(-pActivePoint->m_lon,
616 m_NMEA0183.Rmb.DestinationPosition.Longitude.Set(pActivePoint->m_lon,
619 m_NMEA0183.Rmb.DestinationClosingVelocityKnots =
620 r_Sog * cos((r_Cog - CurrentBrgToActivePoint) * PI / 180.0);
621 m_NMEA0183.Rmb.IsArrivalCircleEntered = m_bArrival ? NTrue : NFalse;
622 m_NMEA0183.Rmb.FAAModeIndicator = bGPSValid ?
"A" :
"N";
625 int wp_len = maxName;
627 m_NMEA0183.Rmb.To = pActivePoint->GetName().Truncate(wp_len);
628 m_NMEA0183.Rmb.From =
629 pActiveRouteSegmentBeginPoint->GetName().Truncate(wp_len);
630 m_NMEA0183.Rmb.Write(snt);
632 }
while (snt.Sentence.size() > 82 && wp_len > 0);
639 m_NMEA0183.TalkerID = _T(
"EC");
642 m_NMEA0183.Rmc.IsDataValid = NTrue;
643 if (!bGPSValid) m_NMEA0183.Rmc.IsDataValid = NFalse;
646 m_NMEA0183.Rmc.Position.Latitude.Set(-gLat, _T(
"S"));
648 m_NMEA0183.Rmc.Position.Latitude.Set(gLat, _T(
"N"));
651 m_NMEA0183.Rmc.Position.Longitude.Set(-gLon, _T(
"W"));
653 m_NMEA0183.Rmc.Position.Longitude.Set(gLon, _T(
"E"));
655 m_NMEA0183.Rmc.SpeedOverGroundKnots = r_Sog;
656 m_NMEA0183.Rmc.TrackMadeGoodDegreesTrue = r_Cog;
658 if (!std::isnan(gVar)) {
660 m_NMEA0183.Rmc.MagneticVariation = -gVar;
661 m_NMEA0183.Rmc.MagneticVariationDirection = West;
663 m_NMEA0183.Rmc.MagneticVariation = gVar;
664 m_NMEA0183.Rmc.MagneticVariationDirection = East;
667 m_NMEA0183.Rmc.MagneticVariation =
671 if (!gRmcTime.IsEmpty() && !gRmcDate.IsEmpty()) {
672 m_NMEA0183.Rmc.UTCTime = gRmcTime;
673 m_NMEA0183.Rmc.Date = gRmcDate;
675 wxDateTime now = wxDateTime::Now();
676 wxDateTime utc = now.ToUTC();
677 wxString time = utc.Format(_T(
"%H%M%S"));
678 m_NMEA0183.Rmc.UTCTime = time;
679 wxString date = utc.Format(_T(
"%d%m%y"));
680 m_NMEA0183.Rmc.Date = date;
683 m_NMEA0183.Rmc.FAAModeIndicator =
"A";
684 if (!bGPSValid) m_NMEA0183.Rmc.FAAModeIndicator =
"N";
686 m_NMEA0183.Rmc.Write(snt);
693 m_NMEA0183.TalkerID = _T(
"EC");
697 m_NMEA0183.Apb.IsLoranBlinkOK =
699 if (!bGPSValid) m_NMEA0183.Apb.IsLoranBlinkOK = NFalse;
701 m_NMEA0183.Apb.IsLoranCCycleLockOK = NTrue;
702 if (!bGPSValid) m_NMEA0183.Apb.IsLoranCCycleLockOK = NFalse;
704 m_NMEA0183.Apb.CrossTrackErrorMagnitude = CurrentXTEToActivePoint;
707 m_NMEA0183.Apb.DirectionToSteer = Left;
709 m_NMEA0183.Apb.DirectionToSteer = Right;
711 m_NMEA0183.Apb.CrossTrackUnits = _T(
"N");
714 m_NMEA0183.Apb.IsArrivalCircleEntered = NTrue;
716 m_NMEA0183.Apb.IsArrivalCircleEntered = NFalse;
720 m_NMEA0183.Apb.IsPerpendicular = NFalse;
722 m_NMEA0183.Apb.To = pActivePoint->GetName().Truncate(maxName);
725 DistanceBearingMercator(pActivePoint->m_lat, pActivePoint->m_lon,
726 pActiveRouteSegmentBeginPoint->m_lat,
727 pActiveRouteSegmentBeginPoint->m_lon, &brg1,
730 if (g_bMagneticAPB && !std::isnan(gVar)) {
732 ((brg1 - gVar) >= 0.) ? (brg1 - gVar) : (brg1 - gVar + 360.);
733 double bapm = ((CurrentBrgToActivePoint - gVar) >= 0.)
734 ? (CurrentBrgToActivePoint - gVar)
735 : (CurrentBrgToActivePoint - gVar + 360.);
737 m_NMEA0183.Apb.BearingOriginToDestination = brg1m;
738 m_NMEA0183.Apb.BearingOriginToDestinationUnits = _T(
"M");
740 m_NMEA0183.Apb.BearingPresentPositionToDestination = bapm;
741 m_NMEA0183.Apb.BearingPresentPositionToDestinationUnits = _T(
"M");
743 m_NMEA0183.Apb.HeadingToSteer = bapm;
744 m_NMEA0183.Apb.HeadingToSteerUnits = _T(
"M");
746 m_NMEA0183.Apb.BearingOriginToDestination = brg1;
747 m_NMEA0183.Apb.BearingOriginToDestinationUnits = _T(
"T");
749 m_NMEA0183.Apb.BearingPresentPositionToDestination =
750 CurrentBrgToActivePoint;
751 m_NMEA0183.Apb.BearingPresentPositionToDestinationUnits = _T(
"T");
753 m_NMEA0183.Apb.HeadingToSteer = CurrentBrgToActivePoint;
754 m_NMEA0183.Apb.HeadingToSteerUnits = _T(
"T");
757 m_NMEA0183.Apb.Write(snt);
763 m_NMEA0183.TalkerID = _T(
"EC");
767 m_NMEA0183.Xte.IsLoranBlinkOK =
769 if (!bGPSValid) m_NMEA0183.Xte.IsLoranBlinkOK = NFalse;
771 m_NMEA0183.Xte.IsLoranCCycleLockOK = NTrue;
772 if (!bGPSValid) m_NMEA0183.Xte.IsLoranCCycleLockOK = NFalse;
774 m_NMEA0183.Xte.CrossTrackErrorDistance = CurrentXTEToActivePoint;
777 m_NMEA0183.Xte.DirectionToSteer = Left;
779 m_NMEA0183.Xte.DirectionToSteer = Right;
781 m_NMEA0183.Xte.CrossTrackUnits = _T(
"N");
783 m_NMEA0183.Xte.Write(snt);
791bool Routeman::DoesRouteContainSharedPoints(
Route *pRoute) {
803 for (
unsigned int ir = 0; ir < pRA->GetCount(); ir++) {
813 if (pnode) pnode = pnode->GetNext();
820 if (prp->IsShared())
return true;
822 if (pnode) pnode = pnode->GetNext();
829bool Routeman::DeleteTrack(
Track *pTrack) {
830 if (pTrack && !pTrack->m_bIsInLayer) {
831 ::wxBeginBusyCursor();
847 pSelect->DeleteAllSelectableTrackSegments(pTrack);
848 auto it = std::find(g_TrackList.begin(), g_TrackList.end(), pTrack);
849 if (it != g_TrackList.end()) {
850 g_TrackList.erase(it);
864 if (pRoute == pAISMOBRoute) {
865 if (!m_route_dlg_ctx.confirm_delete_ais_mob()) {
870 ::wxBeginBusyCursor();
872 if (GetpActiveRoute() == pRoute) DeactivateRoute();
882 m_prop_dlg_ctx.hide(pRoute);
887 pSelect->DeleteAllSelectableRouteSegments(pRoute);
888 pRouteList->DeleteObject(pRoute);
890 m_route_dlg_ctx.route_mgr_dlg_update_list_ctrl();
899 Route *pcontainer_route = FindRouteContainingWaypoint(prp);
904 if (!prp->IsShared()) {
905 pSelect->DeleteSelectablePoint(prp, SELTYPE_ROUTEPOINT);
908 wxRoutePointListNode *pdnode = pnode;
915 NavObj_dB::GetInstance().DeleteRoutePoint(prp);
919 prp->SetShared(
false);
920 NavObj_dB::GetInstance().UpdateRoutePoint(prp);
924 pnode = pnode->GetNext();
929 NavObj_dB::GetInstance().DeleteRoute(pRoute);
937void Routeman::DeleteAllRoutes() {
938 ::wxBeginBusyCursor();
941 wxRouteListNode *node = pRouteList->GetFirst();
943 Route *proute = node->GetData();
944 if (proute == pAISMOBRoute) {
945 if (!m_route_dlg_ctx.confirm_delete_ais_mob()) {
949 ::wxBeginBusyCursor();
952 node = node->GetNext();
961void Routeman::SetColorScheme(ColorScheme cs,
double displayDPmm) {
964 int scaled_line_width = g_route_line_width;
965 int track_scaled_line_width = g_track_line_width;
968 double nominal_line_width_pix = wxMax(2.0, floor(displayDPmm * 0.4));
970 double sline_width = wxMax(nominal_line_width_pix, g_route_line_width);
971 sline_width *= g_ChartScaleFactorExp;
972 scaled_line_width = wxMax(sline_width, 2);
974 double tsline_width = wxMax(nominal_line_width_pix, g_track_line_width);
975 tsline_width *= g_ChartScaleFactorExp;
976 track_scaled_line_width = wxMax(tsline_width, 2);
979 m_pActiveRoutePointPen = wxThePenList->FindOrCreatePen(
980 wxColour(0, 0, 255), scaled_line_width, wxPENSTYLE_SOLID);
981 m_pRoutePointPen = wxThePenList->FindOrCreatePen(
982 wxColour(0, 0, 255), scaled_line_width, wxPENSTYLE_SOLID);
987 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"UINFB"),
988 scaled_line_width, wxPENSTYLE_SOLID);
989 m_pSelectedRoutePen =
990 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"UINFO"),
991 scaled_line_width, wxPENSTYLE_SOLID);
993 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"UARTE"),
994 scaled_line_width, wxPENSTYLE_SOLID);
996 wxThePenList->FindOrCreatePen(m_route_dlg_ctx.get_global_colour(
"CHMGD"),
997 track_scaled_line_width, wxPENSTYLE_SOLID);
998 m_pRouteBrush = wxTheBrushList->FindOrCreateBrush(
999 m_route_dlg_ctx.get_global_colour(
"UINFB"), wxBRUSHSTYLE_SOLID);
1000 m_pSelectedRouteBrush = wxTheBrushList->FindOrCreateBrush(
1001 m_route_dlg_ctx.get_global_colour(
"UINFO"), wxBRUSHSTYLE_SOLID);
1002 m_pActiveRouteBrush = wxTheBrushList->FindOrCreateBrush(
1003 m_route_dlg_ctx.get_global_colour(
"PLRTE"), wxBRUSHSTYLE_SOLID);
1006wxString Routeman::GetRouteReverseMessage(
void) {
1008 _(
"Waypoints can be renamed to reflect the new order, the names will be "
1009 "'001', '002' etc.\n\nDo you want to rename the waypoints?"));
1012wxString Routeman::GetRouteResequenceMessage(
void) {
1014 _(
"Waypoints will be renamed to reflect the natural order, the names "
1015 "will be '001', '002' etc.\n\nDo you want to rename the waypoints?"));
1018Route *Routeman::FindRouteByGUID(
const wxString &guid) {
1019 wxRouteListNode *node1 = pRouteList->GetFirst();
1021 Route *pRoute = node1->GetData();
1023 if (pRoute->
m_GUID == guid)
return pRoute;
1024 node1 = node1->GetNext();
1030Track *Routeman::FindTrackByGUID(
const wxString &guid) {
1031 for (
Track *pTrack : g_TrackList) {
1032 if (pTrack->m_GUID == guid)
return pTrack;
1038void Routeman::ZeroCurrentXTEToActivePoint() {
1040 if (pRouteActivatePoint)
delete pRouteActivatePoint;
1041 pRouteActivatePoint =
1042 new RoutePoint(gLat, gLon, wxString(_T(
"")), wxString(_T(
"")),
1043 wxEmptyString,
false);
1046 pActiveRouteSegmentBeginPoint = pRouteActivatePoint;
1047 m_arrival_min = 1e6;
1054WayPointman::WayPointman(GlobalColourFunc color_func)
1055 : m_get_global_colour(color_func) {
1056 m_pWayPointList =
new RoutePointList;
1058 pmarkicon_image_list = NULL;
1061 m_pIconArray =
new ArrayOfMarkIcon;
1062 m_pLegacyIconArray = NULL;
1063 m_pExtendedIconArray = NULL;
1065 m_cs = (ColorScheme)-1;
1068 m_iconListScale = -999.0;
1069 m_iconListHeight = -1;
1072WayPointman::~WayPointman() {
1078 RoutePointList temp_list;
1080 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1084 temp_list.Append(pr);
1085 node = node->GetNext();
1088 int a = temp_list.GetCount();
1090 temp_list.DeleteContents(
true);
1093 m_pWayPointList->Clear();
1094 delete m_pWayPointList;
1096 for (
unsigned int i = 0; i < m_pIconArray->GetCount(); i++) {
1098 delete pmi->piconBitmap;
1102 m_pIconArray->Clear();
1103 delete m_pIconArray;
1105 if (pmarkicon_image_list) pmarkicon_image_list->RemoveAll();
1106 delete pmarkicon_image_list;
1107 m_pLegacyIconArray->Clear();
1108 delete m_pLegacyIconArray;
1109 m_pExtendedIconArray->Clear();
1110 delete m_pExtendedIconArray;
1114 if (!prp)
return false;
1116 wxRoutePointListNode *prpnode = m_pWayPointList->Append(prp);
1117 prp->SetManagerListNode(prpnode);
1123 if (!prp)
return false;
1125 wxRoutePointListNode *prpnode =
1126 (wxRoutePointListNode *)prp->GetManagerListNode();
1131 m_pWayPointList->DeleteObject(prp);
1133 prp->SetManagerListNode(NULL);
1138wxImageList *WayPointman::Getpmarkicon_image_list(
int nominal_height) {
1140 if (pmarkicon_image_list && (nominal_height == m_iconListHeight)) {
1141 return pmarkicon_image_list;
1145 if (NULL != pmarkicon_image_list) {
1146 pmarkicon_image_list->RemoveAll();
1147 delete pmarkicon_image_list;
1149 pmarkicon_image_list =
new wxImageList(nominal_height, nominal_height);
1151 m_iconListHeight = nominal_height;
1152 m_bitmapSizeForList = nominal_height;
1154 return pmarkicon_image_list;
1157wxBitmap *WayPointman::CreateDimBitmap(wxBitmap *pBitmap,
double factor) {
1158 wxImage img = pBitmap->ConvertToImage();
1159 int sx = img.GetWidth();
1160 int sy = img.GetHeight();
1162 wxImage new_img(img);
1164 for (
int i = 0; i < sx; i++) {
1165 for (
int j = 0; j < sy; j++) {
1166 if (!img.IsTransparent(i, j)) {
1167 new_img.SetRGB(i, j, (
unsigned char)(img.GetRed(i, j) * factor),
1168 (
unsigned char)(img.GetGreen(i, j) * factor),
1169 (
unsigned char)(img.GetBlue(i, j) * factor));
1174 wxBitmap *pret =
new wxBitmap(new_img);
1179wxImage WayPointman::CreateDimImage(wxImage &image,
double factor) {
1180 int sx = image.GetWidth();
1181 int sy = image.GetHeight();
1183 wxImage new_img(image);
1185 for (
int i = 0; i < sx; i++) {
1186 for (
int j = 0; j < sy; j++) {
1187 if (!image.IsTransparent(i, j)) {
1188 new_img.SetRGB(i, j, (
unsigned char)(image.GetRed(i, j) * factor),
1189 (
unsigned char)(image.GetGreen(i, j) * factor),
1190 (
unsigned char)(image.GetBlue(i, j) * factor));
1195 return wxImage(new_img);
1198bool WayPointman::DoesIconExist(
const wxString &icon_key)
const {
1202 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1203 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1204 if (pmi->icon_name.IsSameAs(icon_key))
return true;
1210wxBitmap *WayPointman::GetIconBitmap(
const wxString &icon_key)
const {
1211 wxBitmap *pret = NULL;
1215 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1216 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1217 if (pmi->icon_name.IsSameAs(icon_key))
break;
1220 if (i == m_pIconArray->GetCount())
1223 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1224 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1230 if (i == m_pIconArray->GetCount())
1231 pmi = (
MarkIcon *)m_pIconArray->Item(0);
1234 if (pmi->piconBitmap)
1235 pret = pmi->piconBitmap;
1237 if (pmi->iconImage.IsOk()) {
1238 pmi->piconBitmap =
new wxBitmap(pmi->iconImage);
1239 pret = pmi->piconBitmap;
1246bool WayPointman::GetIconPrescaled(
const wxString &icon_key)
const {
1250 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1251 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1252 if (pmi->icon_name.IsSameAs(icon_key))
break;
1255 if (i == m_pIconArray->GetCount())
1258 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1259 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1265 if (i == m_pIconArray->GetCount())
1266 pmi = (
MarkIcon *)m_pIconArray->Item(0);
1269 return pmi->preScaled;
1274wxBitmap WayPointman::GetIconBitmapForList(
int index,
int height)
const {
1279 pmi = (
MarkIcon *)m_pIconArray->Item(index);
1281 if (pmi->iconImage.GetHeight() != height) {
1284 int w0 = pmi->iconImage.GetWidth();
1285 int h0 = pmi->iconImage.GetHeight();
1287 wxImage icon_resized = pmi->iconImage;
1288 if (h0 <= h && w0 <= w) {
1289 icon_resized = pmi->iconImage.Resize(
1290 wxSize(w, h), wxPoint(w / 2 - w0 / 2, h / 2 - h0 / 2));
1297 w1 = wxRound((
double)w0 * ((
double)h / (
double)h0));
1300 h1 = wxRound((
double)h0 * ((
double)w / (
double)w0));
1302 icon_resized = pmi->iconImage.Rescale(w1, h1);
1303 icon_resized = pmi->iconImage.Resize(
1304 wxSize(w, h), wxPoint(w / 2 - w1 / 2, h / 2 - h1 / 2));
1307 pret = wxBitmap(icon_resized);
1310 pret = wxBitmap(pmi->iconImage);
1316wxString *WayPointman::GetIconDescription(
int index)
const {
1317 wxString *pret = NULL;
1321 pret = &pmi->icon_description;
1326wxString WayPointman::GetIconDescription(wxString icon_key)
const {
1330 for (i = 0; i < m_pIconArray->GetCount(); i++) {
1331 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1332 if (pmi->icon_name.IsSameAs(icon_key))
1333 return wxString(pmi->icon_description);
1336 return wxEmptyString;
1339wxString *WayPointman::GetIconKey(
int index)
const {
1340 wxString *pret = NULL;
1342 if ((index >= 0) && ((
unsigned int)index < m_pIconArray->GetCount())) {
1344 pret = &pmi->icon_name;
1349int WayPointman::GetIconIndex(
const wxBitmap *pbm)
const {
1350 unsigned int ret = 0;
1353 wxASSERT(m_pIconArray->GetCount() >= 1);
1354 for (
unsigned int i = 0; i < m_pIconArray->GetCount(); i++) {
1355 pmi = (
MarkIcon *)m_pIconArray->Item(i);
1356 if (pmi->piconBitmap == pbm) {
1365int WayPointman::GetIconImageListIndex(
const wxBitmap *pbm)
const {
1369 if (pmarkicon_image_list && !pmi->m_blistImageOK) {
1370 int h0 = pmi->iconImage.GetHeight();
1371 int w0 = pmi->iconImage.GetWidth();
1372 int h = m_bitmapSizeForList;
1373 int w = m_bitmapSizeForList;
1375 wxImage icon_larger = pmi->iconImage;
1376 if (h0 <= h && w0 <= w) {
1377 icon_larger = pmi->iconImage.Resize(
1378 wxSize(w, h), wxPoint(w / 2 - w0 / 2, h / 2 - h0 / 2));
1387 w1 = wxRound((
double)w0 * ((
double)h / (
double)h0));
1390 h1 = wxRound((
double)h0 * ((
double)w / (
double)w0));
1392 icon_larger = pmi->iconImage.Rescale(w1, h1).Resize(
1393 wxSize(w, h), wxPoint(w / 2 - w1 / 2, h / 2 - h1 / 2));
1396 int index = pmarkicon_image_list->Add(wxBitmap(icon_larger));
1401 icon_larger.ConvertAlphaToMask(128);
1403 unsigned char r, g, b;
1404 icon_larger.GetOrFindMaskColour(&r, &g, &b);
1405 wxColour unused_color(r, g, b);
1408 wxBitmap xIcon(icon_larger);
1410 wxBitmap xbmp(w, h, -1);
1411 wxMemoryDC mdc(xbmp);
1412 mdc.SetBackground(wxBrush(unused_color));
1414 mdc.DrawBitmap(xIcon, 0, 0);
1415 int xm = xbmp.GetWidth() / 2;
1416 int ym = xbmp.GetHeight() / 2;
1418 int width = wxMax(xm / 10, 2);
1419 wxPen red(m_get_global_colour(
"URED"), width);
1421 mdc.DrawLine(xm - dp, ym - dp, xm + dp, ym + dp);
1422 mdc.DrawLine(xm - dp, ym + dp, xm + dp, ym - dp);
1423 mdc.SelectObject(wxNullBitmap);
1425 wxMask *pmask =
new wxMask(xbmp, unused_color);
1426 xbmp.SetMask(pmask);
1428 pmarkicon_image_list->Add(xbmp);
1431 wxBitmap fIcon(icon_larger);
1433 wxBitmap fbmp(w, h, -1);
1434 wxMemoryDC fmdc(fbmp);
1435 fmdc.SetBackground(wxBrush(unused_color));
1437 fmdc.DrawBitmap(xIcon, 0, 0);
1438 xm = fbmp.GetWidth() / 2;
1439 ym = fbmp.GetHeight() / 2;
1441 width = wxMax(xm / 10, 2);
1442 wxPen fred(m_get_global_colour(
"UGREN"), width);
1444 fmdc.DrawLine(xm - dp, ym + dp, xm + dp, ym + dp);
1445 fmdc.SelectObject(wxNullBitmap);
1447 wxMask *pfmask =
new wxMask(fbmp, unused_color);
1448 fbmp.SetMask(pfmask);
1450 pmarkicon_image_list->Add(fbmp);
1452 pmi->m_blistImageOK =
true;
1453 pmi->listIndex = index;
1456 return pmi->listIndex;
1460 return GetIconImageListIndex(pbm) + 1;
1464 return GetIconImageListIndex(pbm) + 2;
1468wxString WayPointman::CreateGUID(
RoutePoint *pRP) {
1472RoutePoint *WayPointman::FindRoutePointByGUID(
const wxString &guid) {
1473 wxRoutePointListNode *prpnode = m_pWayPointList->GetFirst();
1477 if (prp->
m_GUID == guid)
return (prp);
1479 prpnode = prpnode->GetNext();
1485RoutePoint *WayPointman::GetNearbyWaypoint(
double lat,
double lon,
1486 double radius_meters) {
1489 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1493 double a = lat - pr->m_lat;
1494 double b = lon - pr->m_lon;
1495 double l = sqrt((a * a) + (b * b));
1497 if ((l * 60. * 1852.) < radius_meters)
return pr;
1499 node = node->GetNext();
1504RoutePoint *WayPointman::GetOtherNearbyWaypoint(
double lat,
double lon,
1505 double radius_meters,
1506 const wxString &guid) {
1509 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1513 double a = lat - pr->m_lat;
1514 double b = lon - pr->m_lon;
1515 double l = sqrt((a * a) + (b * b));
1517 if ((l * 60. * 1852.) < radius_meters)
1518 if (pr->
m_GUID != guid)
return pr;
1520 node = node->GetNext();
1525bool WayPointman::IsReallyVisible(
RoutePoint *pWP) {
1527 return pWP->IsVisible();
1529 wxRouteListNode *node = pRouteList->GetFirst();
1531 Route *proute = node->GetData();
1534 if (proute->IsVisible())
return true;
1537 node = node->GetNext();
1540 if (pWP->IsShared())
1542 return pWP->IsVisible();
1547void WayPointman::ClearRoutePointFonts(
void) {
1551 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1556 node = node->GetNext();
1560bool WayPointman::SharedWptsExist() {
1561 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1564 if (prp->IsShared() && (prp->
m_bIsInRoute || prp == pAnchorWatchPoint1 ||
1565 prp == pAnchorWatchPoint2))
1567 node = node->GetNext();
1572void WayPointman::DeleteAllWaypoints(
bool b_delete_used) {
1574 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1578 if (!prp->
m_bIsInLayer && (prp->GetIconName() != _T(
"mob")) &&
1579 ((b_delete_used && prp->IsShared()) ||
1580 ((!prp->
m_bIsInRoute) && !(prp == pAnchorWatchPoint1) &&
1581 !(prp == pAnchorWatchPoint2)))) {
1582 DestroyWaypoint(prp);
1584 node = m_pWayPointList->GetFirst();
1586 node = node->GetNext();
1591RoutePoint *WayPointman::FindWaypointByGuid(
const std::string &guid) {
1592 wxRoutePointListNode *node = m_pWayPointList->GetFirst();
1595 if (guid == rp->
m_GUID)
return rp;
1596 node = node->GetNext();
1600void WayPointman::DestroyWaypoint(
RoutePoint *pRp,
bool b_update_changeset) {
1606 for (
unsigned int ir = 0; ir < proute_array->GetCount(); ir++) {
1613 pr->RemovePoint(pRp);
1617 for (
unsigned int ir = 0; ir < proute_array->GetCount(); ir++) {
1619 if (pr->GetnPoints() < 2) {
1624 delete proute_array;
1628 NavObj_dB::GetInstance().DeleteRoutePoint(pRp);
1630 pSelect->DeleteSelectableRoutePoint(pRp);
1633 if (pRp == pAnchorWatchPoint1) pAnchorWatchPoint1 = NULL;
1634 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.