OpenCPN Partial API docs
Loading...
Searching...
No Matches
routeman.h
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: Route Manager
5 * Author: David Register
6 *
7 ***************************************************************************
8 * Copyright (C) 2010 by David S. Register *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 **************************************************************************/
25
26#ifndef _ROUTEMAN_H__
27#define _ROUTEMAN_H__
28
29#include <functional>
30
31#include <wx/bitmap.h>
32#include <wx/brush.h>
33#include <wx/dynarray.h>
34#include <wx/imaglist.h>
35#include <wx/pen.h>
36#include <wx/string.h>
37
38#include "model/MarkIcon.h"
39#include "model/nav_object_database.h"
40#include "model/nmea_log.h"
41#include "model/ocpn_types.h"
42#include "model/route.h"
43#include "model/route_point.h"
44#include "model/select.h"
45
46#include "color_types.h"
47#include "nmea0183.h"
48#include "observable_evtvar.h"
49
50//----------------------------------------------------------------------------
51// constants
52//----------------------------------------------------------------------------
53#ifndef PI
54#define PI 3.1415926535897931160E0 /* pi */
55#endif
56
57class Routeman; // forward
58class WayPointman; // forward
59
60extern bool g_bPluginHandleAutopilotRoute;
61
62extern Route *pAISMOBRoute;
63
64extern RouteList *pRouteList;
65
66extern RoutePoint *pAnchorWatchPoint1;
67extern RoutePoint *pAnchorWatchPoint2;
68
69extern float g_ChartScaleFactorExp;
70
71extern Routeman *g_pRouteMan;
72
73// List definitions for Waypoint Manager Icons
74
75class markicon_bitmap_list_type;
76class markicon_key_list_type;
77class markicon_description_list_type;
78
79WX_DEFINE_SORTED_ARRAY(MarkIcon *, SortedArrayOfMarkIcon);
80WX_DEFINE_ARRAY(MarkIcon *, ArrayOfMarkIcon);
81
84 std::function<void(Route *)> set_route_and_update;
85 std::function<void(Route *, RoutePoint *)> set_enroute_point;
86 std::function<void(Route *)> hide;
88 : set_route_and_update([&](Route *r) {}),
89 set_enroute_point([&](Route *r, RoutePoint *rt) {}),
90 hide([&](Route *r) {}) {}
91};
92
96 std::function<bool()> confirm_delete_ais_mob;
97 std::function<wxColour(wxString)> get_global_colour;
98 std::function<void()> show_with_fresh_fonts;
99 std::function<void()> clear_console_background;
100 std::function<void()> route_mgr_dlg_update_list_ctrl;
101
103 : confirm_delete_ais_mob([]() { return true; }),
104 get_global_colour([](wxString c) { return *wxBLACK; }),
105 show_with_fresh_fonts([]() {}),
106 clear_console_background([]() {}),
107 route_mgr_dlg_update_list_ctrl([]() {}) {}
108};
109
110//----------------------------------------------------------------------------
111// Routeman
112//----------------------------------------------------------------------------
113//
114class Routeman {
115 friend class RoutemanGui;
116
117public:
118 Routeman(struct RoutePropDlgCtx prop_dlg_ctx,
119 struct RoutemanDlgCtx route_dlg_ctx, NmeaLog &nmea_log);
120 ~Routeman();
121
122 bool DeleteTrack(Track *pTrack);
123 bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes);
124 void DeleteAllRoutes(NavObjectChanges *nav_obj_changes);
125
126 bool IsRouteValid(Route *pRoute);
127
128 Route *FindRouteByGUID(const wxString &guid);
129 Track *FindTrackByGUID(const wxString &guid);
130 Route *FindRouteContainingWaypoint(RoutePoint *pWP);
131 Route *FindVisibleRouteContainingWaypoint(RoutePoint *pWP);
132 wxArrayPtrVoid *GetRouteArrayContaining(RoutePoint *pWP);
133 bool DoesRouteContainSharedPoints(Route *pRoute);
134 void RemovePointFromRoute(RoutePoint *point, Route *route, int route_state);
135
136 bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint = NULL);
137 bool ActivateRoutePoint(Route *pA, RoutePoint *pRP);
138 bool ActivateNextPoint(Route *pr, bool skipped);
139 RoutePoint *FindBestActivatePoint(Route *pR, double lat, double lon,
140 double cog, double sog);
141
142 bool UpdateAutopilot();
143 bool DeactivateRoute(bool b_arrival = false);
144 bool IsAnyRouteActive(void) { return (pActiveRoute != NULL); }
145
146 Route *GetpActiveRoute() { return pActiveRoute; }
147 RoutePoint *GetpActivePoint() { return pActivePoint; }
148 double GetCurrentRngToActivePoint() { return CurrentRngToActivePoint; }
149 double GetCurrentBrgToActivePoint() { return CurrentBrgToActivePoint; }
150 double GetCurrentRngToActiveNormalArrival() {
151 return CurrentRangeToActiveNormalCrossing;
152 }
153 double GetCurrentXTEToActivePoint() { return CurrentXTEToActivePoint; }
154 void ZeroCurrentXTEToActivePoint();
155 double GetCurrentSegmentCourse() { return CurrentSegmentCourse; }
156 int GetXTEDir() { return XTEDir; }
157
158 void SetColorScheme(ColorScheme cs, double displayDPmm);
159 wxPen *GetRoutePen(void) { return m_pRoutePen; }
160 wxPen *GetTrackPen(void) { return m_pTrackPen; }
161 wxPen *GetSelectedRoutePen(void) { return m_pSelectedRoutePen; }
162 wxPen *GetActiveRoutePen(void) { return m_pActiveRoutePen; }
163 wxPen *GetActiveRoutePointPen(void) { return m_pActiveRoutePointPen; }
164 wxPen *GetRoutePointPen(void) { return m_pRoutePointPen; }
165 wxBrush *GetRouteBrush(void) { return m_pRouteBrush; }
166 wxBrush *GetSelectedRouteBrush(void) { return m_pSelectedRouteBrush; }
167 wxBrush *GetActiveRouteBrush(void) { return m_pActiveRouteBrush; }
168 wxBrush *GetActiveRoutePointBrush(void) { return m_pActiveRoutePointBrush; }
169 wxBrush *GetRoutePointBrush(void) { return m_pRoutePointBrush; }
170
171 wxString GetRouteReverseMessage(void);
172 wxString GetRouteResequenceMessage(void);
173 struct RoutemanDlgCtx &GetDlgContext() { return m_route_dlg_ctx; }
174
175 bool m_bDataValid;
176
182
185
188
191
192private:
193 Route *pActiveRoute;
194 RoutePoint *pActivePoint;
195 double RouteBrgToActivePoint; // TODO all these need to be doubles
196 double CurrentSegmentBeginLat;
197 double CurrentSegmentBeginLon;
198 double CurrentRngToActivePoint;
199 double CurrentBrgToActivePoint;
200 double CurrentXTEToActivePoint;
201 double CourseToRouteSegment;
202 double CurrentRangeToActiveNormalCrossing;
203 RoutePoint *pActiveRouteSegmentBeginPoint;
204 RoutePoint *pRouteActivatePoint;
205 double CurrentSegmentCourse;
206 int XTEDir;
207 bool m_bArrival;
208 wxPen *m_pRoutePen;
209 wxPen *m_pTrackPen;
210 wxPen *m_pSelectedRoutePen;
211 wxPen *m_pActiveRoutePen;
212 wxPen *m_pActiveRoutePointPen;
213 wxPen *m_pRoutePointPen;
214 wxBrush *m_pRouteBrush;
215 wxBrush *m_pSelectedRouteBrush;
216 wxBrush *m_pActiveRouteBrush;
217 wxBrush *m_pActiveRoutePointBrush;
218 wxBrush *m_pRoutePointBrush;
219
220 NMEA0183 m_NMEA0183; // For autopilot output
221
222 double m_arrival_min;
223 int m_arrival_test;
224 struct RoutePropDlgCtx m_prop_dlg_ctx;
225 struct RoutemanDlgCtx m_route_dlg_ctx;
226 NmeaLog &m_nmea_log;
227
228 ObsListener msg_sent_listener;
229 ObsListener active_route_listener;
230};
231
232//----------------------------------------------------------------------------
233// WayPointman
234//----------------------------------------------------------------------------
235
236typedef std::function<wxColour(wxString)> GlobalColourFunc;
237
239 friend class WayPointmanGui;
240
241public:
242 WayPointman(GlobalColourFunc colour_func);
243 ~WayPointman();
244 wxBitmap *GetIconBitmap(const wxString &icon_key) const;
245 bool GetIconPrescaled(const wxString &icon_key) const;
246 int GetIconIndex(const wxBitmap *pbm) const;
247 int GetIconImageListIndex(const wxBitmap *pbm) const;
248
250 int GetXIconImageListIndex(const wxBitmap *pbm) const;
251
253 int GetFIconImageListIndex(const wxBitmap *pbm) const;
254
255 int GetNumIcons(void) { return m_pIconArray->Count(); }
256 wxString CreateGUID(RoutePoint *pRP);
257 RoutePoint *FindWaypointByGuid(const std::string &guid);
258 RoutePoint *GetNearbyWaypoint(double lat, double lon, double radius_meters);
259 RoutePoint *GetOtherNearbyWaypoint(double lat, double lon,
260 double radius_meters,
261 const wxString &guid);
262 bool IsReallyVisible(RoutePoint *pWP);
263 bool SharedWptsExist();
264 void DeleteAllWaypoints(bool b_delete_used);
265 RoutePoint *FindRoutePointByGUID(const wxString &guid);
266 void DestroyWaypoint(RoutePoint *pRp, bool b_update_changeset = true);
267 void ClearRoutePointFonts(void);
268
269 bool DoesIconExist(const wxString &icon_key) const;
270 wxBitmap GetIconBitmapForList(int index, int height) const;
271 wxString *GetIconDescription(int index) const;
272 wxString *GetIconKey(int index) const;
273 wxString GetIconDescription(wxString icon_key) const;
274
275 wxImageList *Getpmarkicon_image_list(int nominal_height);
276
282 bool AddRoutePoint(RoutePoint *prp);
283
289 bool RemoveRoutePoint(RoutePoint *prp);
290
291 const RoutePointList *GetWaypointList(void) { return m_pWayPointList; }
292
293private:
294 wxImage CreateDimImage(wxImage &image, double factor);
295
296 RoutePointList *m_pWayPointList;
297 wxBitmap *CreateDimBitmap(wxBitmap *pBitmap, double factor);
298
299 wxImageList *pmarkicon_image_list; // Current wxImageList, updated on
300 // colorscheme change
301 int m_markicon_image_list_base_count;
302 ArrayOfMarkIcon *m_pIconArray;
303
304 int m_nGUID;
305 double m_iconListScale;
306
307 SortedArrayOfMarkIcon *m_pLegacyIconArray;
308 SortedArrayOfMarkIcon *m_pExtendedIconArray;
309
310 int m_bitmapSizeForList;
311 int m_iconListHeight;
312 ColorScheme m_cs;
313 GlobalColourFunc m_get_global_colour;
314};
315
316#endif // _ROUTEMAN_H__
Generic event handling between MVC Model and Controller based on a shared EventVar variable.
Define an action to be performed when a KeyProvider is notified.
Definition observable.h:228
Definition route.h:75
bool ActivateRoutePoint(Route *pA, RoutePoint *pRP)
Definition routeman.cpp:290
bool ActivateNextPoint(Route *pr, bool skipped)
Definition routeman.cpp:365
EventVar on_routes_update
Notified when list of routes is updated (no data in event)
Definition routeman.h:190
bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes)
Definition routeman.cpp:747
EventVar json_msg
Notified with message targeting all plugins.
Definition routeman.h:181
EventVar json_leg_info
Notified with a shared_ptr<ActiveLegDat>, leg info to all plugins.
Definition routeman.h:184
EventVar on_message_sent
Notified when a message available as GetString() is sent to garmin.
Definition routeman.h:187
Represents a track, which is a series of connected track points.
Definition track.h:78
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.
Callbacks for RoutePropDlg.
Definition routeman.h:83
Routeman callbacks.
Definition routeman.h:95