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
40#include "model/nav_object_database.h"
41#include "model/nmea_log.h"
42#include "model/ocpn_types.h"
43#include "model/route.h"
44#include "model/route_point.h"
45#include "model/select.h"
46
47#include "color_types.h"
48#include "nmea0183.h"
49#include "observable_evtvar.h"
50
51//----------------------------------------------------------------------------
52// constants
53//----------------------------------------------------------------------------
54#ifndef PI
55#define PI 3.1415926535897931160E0 /* pi */
56#endif
57
58class Routeman; // forward
59class WayPointman; // forward
60
61extern bool g_bPluginHandleAutopilotRoute;
62
63extern Route *pAISMOBRoute;
64
65extern RouteList *pRouteList;
66
67extern RoutePoint *pAnchorWatchPoint1;
68extern RoutePoint *pAnchorWatchPoint2;
69
70extern float g_ChartScaleFactorExp;
71
72extern Routeman *g_pRouteMan;
73
74// List definitions for Waypoint Manager Icons
75
76WX_DEFINE_SORTED_ARRAY(MarkIcon *, SortedArrayOfMarkIcon);
77WX_DEFINE_ARRAY(MarkIcon *, ArrayOfMarkIcon);
78
81 std::function<void(Route *)> set_route_and_update;
82 std::function<void(Route *, RoutePoint *)> set_enroute_point;
83 std::function<void(Route *)> hide;
85 : set_route_and_update([&](Route *r) {}),
86 set_enroute_point([&](Route *r, RoutePoint *rt) {}),
87 hide([&](Route *r) {}) {}
88};
89
93 std::function<bool()> confirm_delete_ais_mob;
94 std::function<wxColour(wxString)> get_global_colour;
95 std::function<void()> show_with_fresh_fonts;
96 std::function<void()> clear_console_background;
97 std::function<void()> route_mgr_dlg_update_list_ctrl;
98
100 : confirm_delete_ais_mob([]() { return true; }),
101 get_global_colour([](wxString c) { return *wxBLACK; }),
102 show_with_fresh_fonts([]() {}),
103 clear_console_background([]() {}),
104 route_mgr_dlg_update_list_ctrl([]() {}) {}
105};
106
107//----------------------------------------------------------------------------
108// Routeman
109//----------------------------------------------------------------------------
110//
111class Routeman {
112 friend class RoutemanGui;
113
114public:
115 Routeman(struct RoutePropDlgCtx prop_dlg_ctx,
116 struct RoutemanDlgCtx route_dlg_ctx);
117 ~Routeman();
118
119 bool DeleteTrack(Track *pTrack);
120 bool DeleteRoute(Route *pRoute);
121 void DeleteAllRoutes();
122
123 bool IsRouteValid(Route *pRoute);
124
125 Route *FindRouteByGUID(const wxString &guid);
126 Track *FindTrackByGUID(const wxString &guid);
127 Route *FindRouteContainingWaypoint(RoutePoint *pWP);
128 Route *FindRouteContainingWaypoint(const std::string &guid);
129 Route *FindVisibleRouteContainingWaypoint(RoutePoint *pWP);
142 wxArrayPtrVoid *GetRouteArrayContaining(RoutePoint *pWP);
143 bool DoesRouteContainSharedPoints(Route *pRoute);
144 void RemovePointFromRoute(RoutePoint *point, Route *route, int route_state);
145
166 bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint = NULL);
185 bool ActivateRoutePoint(Route *pA, RoutePoint *pRP);
206 bool ActivateNextPoint(Route *pr, bool skipped);
207 RoutePoint *FindBestActivatePoint(Route *pR, double lat, double lon,
208 double cog, double sog);
209
210 bool UpdateAutopilot();
211 bool DeactivateRoute(bool b_arrival = false);
212 bool IsAnyRouteActive(void) { return (pActiveRoute != NULL); }
213 bool GetArrival() { return m_bArrival; }
214
215 Route *GetpActiveRoute() { return pActiveRoute; }
216 RoutePoint *GetpActiveRouteSegmentBeginPoint() {
217 return pActiveRouteSegmentBeginPoint;
218 }
219
220 RoutePoint *GetpActivePoint() { return pActivePoint; }
221 double GetCurrentRngToActivePoint() { return CurrentRngToActivePoint; }
222 double GetCurrentBrgToActivePoint() { return CurrentBrgToActivePoint; }
223 double GetCurrentRngToActiveNormalArrival() {
224 return CurrentRangeToActiveNormalCrossing;
225 }
226 double GetCurrentXTEToActivePoint() { return CurrentXTEToActivePoint; }
227 void ZeroCurrentXTEToActivePoint();
228 double GetCurrentSegmentCourse() { return CurrentSegmentCourse; }
229 int GetXTEDir() { return XTEDir; }
230
231 void SetColorScheme(ColorScheme cs, double displayDPmm);
232 wxPen *GetRoutePen(void) { return m_pRoutePen; }
233 wxPen *GetTrackPen(void) { return m_pTrackPen; }
234 wxPen *GetSelectedRoutePen(void) { return m_pSelectedRoutePen; }
235 wxPen *GetActiveRoutePen(void) { return m_pActiveRoutePen; }
236 wxPen *GetActiveRoutePointPen(void) { return m_pActiveRoutePointPen; }
237 wxPen *GetRoutePointPen(void) { return m_pRoutePointPen; }
238 wxBrush *GetRouteBrush(void) { return m_pRouteBrush; }
239 wxBrush *GetSelectedRouteBrush(void) { return m_pSelectedRouteBrush; }
240 wxBrush *GetActiveRouteBrush(void) { return m_pActiveRouteBrush; }
241 wxBrush *GetActiveRoutePointBrush(void) { return m_pActiveRoutePointBrush; }
242 wxBrush *GetRoutePointBrush(void) { return m_pRoutePointBrush; }
243
244 wxString GetRouteReverseMessage(void);
245 wxString GetRouteResequenceMessage(void);
246 struct RoutemanDlgCtx &GetDlgContext() { return m_route_dlg_ctx; }
247 NMEA0183 GetNMEA0183() { return m_NMEA0183; }
248 EventVar &GetMessageSentEventVar() { return on_message_sent; }
249 std::vector<DriverHandle> GetOutpuDriverArray() { return m_output_drivers; }
250 bool m_bDataValid;
251
257
260
263
266
267private:
268 Route *pActiveRoute;
269 RoutePoint *pActivePoint;
270 double RouteBrgToActivePoint; // TODO all these need to be doubles
271 double CurrentSegmentBeginLat;
272 double CurrentSegmentBeginLon;
273 double CurrentRngToActivePoint;
274 double CurrentBrgToActivePoint;
275 double CurrentXTEToActivePoint;
276 double CourseToRouteSegment;
277 double CurrentRangeToActiveNormalCrossing;
278 RoutePoint *pActiveRouteSegmentBeginPoint;
279 RoutePoint *pRouteActivatePoint;
280 double CurrentSegmentCourse;
281 int XTEDir;
282 bool m_bArrival;
283 wxPen *m_pRoutePen;
284 wxPen *m_pTrackPen;
285 wxPen *m_pSelectedRoutePen;
286 wxPen *m_pActiveRoutePen;
287 wxPen *m_pActiveRoutePointPen;
288 wxPen *m_pRoutePointPen;
289 wxBrush *m_pRouteBrush;
290 wxBrush *m_pSelectedRouteBrush;
291 wxBrush *m_pActiveRouteBrush;
292 wxBrush *m_pActiveRoutePointBrush;
293 wxBrush *m_pRoutePointBrush;
294
295 NMEA0183 m_NMEA0183; // For autopilot output
296
297 double m_arrival_min;
298 int m_arrival_test;
299 struct RoutePropDlgCtx m_prop_dlg_ctx;
300 struct RoutemanDlgCtx m_route_dlg_ctx;
301
302 ObsListener msg_sent_listener;
303 ObsListener active_route_listener;
304 std::vector<DriverHandle> m_output_drivers;
305 bool m_have_n0183_out;
306 bool m_have_n2000_out;
307};
308
309//----------------------------------------------------------------------------
310// WayPointman
311//----------------------------------------------------------------------------
312
313typedef std::function<wxColour(wxString)> GlobalColourFunc;
314
316 friend class WayPointmanGui;
317
318public:
319 WayPointman(GlobalColourFunc colour_func);
320 ~WayPointman();
321 wxBitmap *GetIconBitmap(const wxString &icon_key) const;
322 bool GetIconPrescaled(const wxString &icon_key) const;
323 int GetIconIndex(const wxBitmap *pbm) const;
324 int GetIconImageListIndex(const wxBitmap *pbm) const;
325
327 int GetXIconImageListIndex(const wxBitmap *pbm) const;
328
330 int GetFIconImageListIndex(const wxBitmap *pbm) const;
331
332 int GetNumIcons(void) { return m_pIconArray->Count(); }
333 wxString CreateGUID(RoutePoint *pRP);
334 RoutePoint *FindWaypointByGuid(const std::string &guid);
335 RoutePoint *GetNearbyWaypoint(double lat, double lon, double radius_meters);
336 RoutePoint *GetOtherNearbyWaypoint(double lat, double lon,
337 double radius_meters,
338 const wxString &guid);
339 bool IsReallyVisible(RoutePoint *pWP);
340 bool SharedWptsExist();
341 void DeleteAllWaypoints(bool b_delete_used);
342 RoutePoint *FindRoutePointByGUID(const wxString &guid);
343 void DestroyWaypoint(RoutePoint *pRp, bool b_update_changeset = true);
344 void ClearRoutePointFonts(void);
345
346 bool DoesIconExist(const wxString &icon_key) const;
347 wxBitmap GetIconBitmapForList(int index, int height) const;
348 wxString *GetIconDescription(int index) const;
349 wxString *GetIconKey(int index) const;
350 wxString GetIconDescription(wxString icon_key) const;
351
352 wxImageList *Getpmarkicon_image_list(int nominal_height);
353
359 bool AddRoutePoint(RoutePoint *prp);
360
366 bool RemoveRoutePoint(RoutePoint *prp);
367
368 const RoutePointList *GetWaypointList(void) { return m_pWayPointList; }
369
370private:
371 wxImage CreateDimImage(wxImage &image, double factor);
372
373 RoutePointList *m_pWayPointList;
374 wxBitmap *CreateDimBitmap(wxBitmap *pBitmap, double factor);
375
376 wxImageList *pmarkicon_image_list; // Current wxImageList, updated on
377 // colorscheme change
378 int m_markicon_image_list_base_count;
379 ArrayOfMarkIcon *m_pIconArray;
380
381 int m_nGUID;
382 double m_iconListScale;
383
384 SortedArrayOfMarkIcon *m_pLegacyIconArray;
385 SortedArrayOfMarkIcon *m_pExtendedIconArray;
386
387 int m_bitmapSizeForList;
388 int m_iconListHeight;
389 ColorScheme m_cs;
390 GlobalColourFunc m_get_global_colour;
391};
392
393#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:257
Represents a waypoint or mark within the navigation system.
Definition route_point.h:70
Represents a navigational route in the navigation system.
Definition route.h:98
bool ActivateRoutePoint(Route *pA, RoutePoint *pRP)
Activates a specific waypoint within a route for navigation.
Definition routeman.cpp:328
wxArrayPtrVoid * GetRouteArrayContaining(RoutePoint *pWP)
Find all routes that contain the given waypoint.
Definition routeman.cpp:178
bool ActivateNextPoint(Route *pr, bool skipped)
Activates the next waypoint in a route when the current waypoint is reached.
Definition routeman.cpp:403
bool DeleteRoute(Route *pRoute)
Definition routeman.cpp:818
EventVar on_routes_update
Notified when list of routes is updated (no data in event)
Definition routeman.h:265
bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint=NULL)
Activates a route for navigation.
Definition routeman.cpp:263
EventVar json_msg
Notified with message targeting all plugins.
Definition routeman.h:256
EventVar json_leg_info
Notified with a shared_ptr<ActiveLegDat>, leg info to all plugins.
Definition routeman.h:259
EventVar on_message_sent
Notified when a message available as GetString() is sent to garmin.
Definition routeman.h:262
Represents a track, which is a series of connected track points.
Definition track.h:114
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.
Basic DataMonitor logging interface: LogLine (reflects a line in the log) and NmeaLog,...
A common variable shared between producer and consumer which supports Listen() and Notify().
Callbacks for RoutePropDlg.
Definition routeman.h:80
Routeman callbacks.
Definition routeman.h:92