OpenCPN Partial API docs
Loading...
Searching...
No Matches
routeman.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2010 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifndef _ROUTEMAN_H__
25#define _ROUTEMAN_H__
26
27#include <functional>
28
29#include <wx/bitmap.h>
30#include <wx/brush.h>
31#include <wx/dynarray.h>
32#include <wx/imaglist.h>
33#include <wx/pen.h>
34#include <wx/string.h>
35
36#include "model/MarkIcon.h"
37
38#include "model/nav_object_database.h"
39#include "model/nmea_log.h"
40#include "model/ocpn_types.h"
41#include "model/route.h"
42#include "model/route_point.h"
43#include "model/select.h"
44
45#include "color_types.h"
46#include "nmea0183.h"
47#include "observable_evtvar.h"
48
49//----------------------------------------------------------------------------
50// constants
51//----------------------------------------------------------------------------
52#ifndef PI
53#define PI 3.1415926535897931160E0 /* pi */
54#endif
55
56using RouteList = std::vector<Route *>;
57
58class Routeman; // forward
59class WayPointman; // forward
60
63extern Route *pAISMOBRoute;
65extern RouteList *pRouteList;
70extern float g_ChartScaleFactorExp;
72extern Routeman *g_pRouteMan;
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 bool IsRouteInList(Route *pRoute);
125
126 Route *FindRouteByGUID(const wxString &guid);
127 Track *FindTrackByGUID(const wxString &guid);
128 Route *FindRouteContainingWaypoint(RoutePoint *pWP);
129 Route *FindRouteContainingWaypoint(const std::string &guid);
130 Route *FindVisibleRouteContainingWaypoint(RoutePoint *pWP);
143 wxArrayPtrVoid *GetRouteArrayContaining(RoutePoint *pWP);
144 bool DoesRouteContainSharedPoints(Route *pRoute);
145 void RemovePointFromRoute(RoutePoint *point, Route *route, int route_state);
146
167 bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint = NULL);
186 bool ActivateRoutePoint(Route *pA, RoutePoint *pRP);
207 bool ActivateNextPoint(Route *pr, bool skipped);
208 RoutePoint *FindBestActivatePoint(Route *pR, double lat, double lon,
209 double cog, double sog);
210
211 bool UpdateAutopilot();
212 bool DeactivateRoute(bool b_arrival = false);
213 bool IsAnyRouteActive(void) { return (pActiveRoute != NULL); }
214 bool GetArrival() { return m_bArrival; }
215
216 Route *GetpActiveRoute() { return pActiveRoute; }
217 RoutePoint *GetpActiveRouteSegmentBeginPoint() {
218 return pActiveRouteSegmentBeginPoint;
219 }
220
221 RoutePoint *GetpActivePoint() { return pActivePoint; }
222 double GetCurrentRngToActivePoint() { return CurrentRngToActivePoint; }
223 double GetCurrentBrgToActivePoint() { return CurrentBrgToActivePoint; }
224 double GetCurrentRngToActiveNormalArrival() {
225 return CurrentRangeToActiveNormalCrossing;
226 }
227 double GetCurrentXTEToActivePoint() { return CurrentXTEToActivePoint; }
228 void ZeroCurrentXTEToActivePoint();
229 double GetCurrentSegmentCourse() { return CurrentSegmentCourse; }
230 int GetXTEDir() { return XTEDir; }
231
232 void SetColorScheme(ColorScheme cs, double displayDPmm);
233 wxPen *GetRoutePen(void) { return m_pRoutePen; }
234 wxPen *GetTrackPen(void) { return m_pTrackPen; }
235 wxPen *GetSelectedRoutePen(void) { return m_pSelectedRoutePen; }
236 wxPen *GetActiveRoutePen(void) { return m_pActiveRoutePen; }
237 wxPen *GetActiveRoutePointPen(void) { return m_pActiveRoutePointPen; }
238 wxPen *GetRoutePointPen(void) { return m_pRoutePointPen; }
239 wxBrush *GetRouteBrush(void) { return m_pRouteBrush; }
240 wxBrush *GetSelectedRouteBrush(void) { return m_pSelectedRouteBrush; }
241 wxBrush *GetActiveRouteBrush(void) { return m_pActiveRouteBrush; }
242 wxBrush *GetActiveRoutePointBrush(void) { return m_pActiveRoutePointBrush; }
243 wxBrush *GetRoutePointBrush(void) { return m_pRoutePointBrush; }
244
245 wxString GetRouteReverseMessage(void);
246 wxString GetRouteResequenceMessage(void);
247 struct RoutemanDlgCtx &GetDlgContext() { return m_route_dlg_ctx; }
248 NMEA0183 GetNMEA0183() { return m_NMEA0183; }
249 EventVar &GetMessageSentEventVar() { return on_message_sent; }
250 std::vector<DriverHandle> GetOutpuDriverArray() { return m_output_drivers; }
251 bool m_bDataValid;
252
258
261
264
265private:
266 Route *pActiveRoute;
267 RoutePoint *pActivePoint;
268 double RouteBrgToActivePoint; // TODO all these need to be doubles
269 double CurrentSegmentBeginLat;
270 double CurrentSegmentBeginLon;
271 double CurrentRngToActivePoint;
272 double CurrentBrgToActivePoint;
273 double CurrentXTEToActivePoint;
274 double CourseToRouteSegment;
275 double CurrentRangeToActiveNormalCrossing;
276 RoutePoint *pActiveRouteSegmentBeginPoint;
277 RoutePoint *pRouteActivatePoint;
278 double CurrentSegmentCourse;
279 int XTEDir;
280 bool m_bArrival;
281 wxPen *m_pRoutePen;
282 wxPen *m_pTrackPen;
283 wxPen *m_pSelectedRoutePen;
284 wxPen *m_pActiveRoutePen;
285 wxPen *m_pActiveRoutePointPen;
286 wxPen *m_pRoutePointPen;
287 wxBrush *m_pRouteBrush;
288 wxBrush *m_pSelectedRouteBrush;
289 wxBrush *m_pActiveRouteBrush;
290 wxBrush *m_pActiveRoutePointBrush;
291 wxBrush *m_pRoutePointBrush;
292
293 NMEA0183 m_NMEA0183; // For autopilot output
294
295 double m_arrival_min;
296 int m_arrival_test;
297 struct RoutePropDlgCtx m_prop_dlg_ctx;
298 struct RoutemanDlgCtx m_route_dlg_ctx;
299
300 ObsListener msg_sent_listener;
301 ObsListener active_route_listener;
302 std::vector<DriverHandle> m_output_drivers;
303 bool m_have_n0183_out;
304 bool m_have_n2000_out;
305};
306
307//----------------------------------------------------------------------------
308// WayPointman
309//----------------------------------------------------------------------------
310
311typedef std::function<wxColour(wxString)> GlobalColourFunc;
312
314 friend class WayPointmanGui;
315
316public:
317 WayPointman(GlobalColourFunc colour_func);
318 ~WayPointman();
319 wxBitmap *GetIconBitmap(const wxString &icon_key) const;
320 bool GetIconPrescaled(const wxString &icon_key) const;
321 int GetIconIndex(const wxBitmap *pbm) const;
322 int GetIconImageListIndex(const wxBitmap *pbm) const;
323
325 int GetXIconImageListIndex(const wxBitmap *pbm) const;
326
328 int GetFIconImageListIndex(const wxBitmap *pbm) const;
329
330 int GetNumIcons(void) { return m_pIconArray->Count(); }
331 wxString CreateGUID(RoutePoint *pRP);
332 RoutePoint *FindWaypointByGuid(const std::string &guid);
333 RoutePoint *GetNearbyWaypoint(double lat, double lon, double radius_meters);
334 RoutePoint *GetOtherNearbyWaypoint(double lat, double lon,
335 double radius_meters,
336 const wxString &guid);
337 bool IsReallyVisible(RoutePoint *pWP);
338 bool SharedWptsExist();
339 void DeleteAllWaypoints(bool b_delete_used);
340 RoutePoint *FindRoutePointByGUID(const wxString &guid);
341 void DestroyWaypoint(RoutePoint *pRp, bool b_update_changeset = true);
342 void ClearRoutePointFonts(void);
343
344 bool DoesIconExist(const wxString &icon_key) const;
345 wxBitmap GetIconBitmapForList(int index, int height) const;
346 wxString *GetIconDescription(int index) const;
347 wxString *GetIconKey(int index) const;
348 wxString GetIconDescription(wxString icon_key) const;
349
350 wxImageList *Getpmarkicon_image_list(int nominal_height);
351
357 bool AddRoutePoint(RoutePoint *prp);
358
364 bool RemoveRoutePoint(RoutePoint *prp);
365
366 const RoutePointList *GetWaypointList(void) { return m_pWayPointList; }
367
368private:
369 wxImage CreateDimImage(wxImage &image, double factor);
370
371 RoutePointList *m_pWayPointList;
372 wxBitmap *CreateDimBitmap(wxBitmap *pBitmap, double factor);
373
374 wxImageList *pmarkicon_image_list; // Current wxImageList, updated on
375 // colorscheme change
376 int m_markicon_image_list_base_count;
377 ArrayOfMarkIcon *m_pIconArray;
378
379 int m_nGUID;
380 double m_iconListScale;
381
382 SortedArrayOfMarkIcon *m_pLegacyIconArray;
383 SortedArrayOfMarkIcon *m_pExtendedIconArray;
384
385 int m_bitmapSizeForList;
386 int m_iconListHeight;
387 ColorScheme m_cs;
388 GlobalColourFunc m_get_global_colour;
389};
390
391#endif // _ROUTEMAN_H__
Extended icon definition.
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:71
Represents a navigational route in the navigation system.
Definition route.h:99
bool ActivateRoutePoint(Route *pA, RoutePoint *pRP)
Activates a specific waypoint within a route for navigation.
Definition routeman.cpp:286
wxArrayPtrVoid * GetRouteArrayContaining(RoutePoint *pWP)
Find all routes that contain the given waypoint.
Definition routeman.cpp:150
bool ActivateNextPoint(Route *pr, bool skipped)
Activates the next waypoint in a route when the current waypoint is reached.
Definition routeman.cpp:357
bool DeleteRoute(Route *pRoute)
Definition routeman.cpp:772
bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint=NULL)
Activates a route for navigation.
Definition routeman.cpp:222
EventVar json_msg
Notified with message targeting all plugins.
Definition routeman.h:257
EventVar json_leg_info
Notified with a shared_ptr<ActiveLegDat>, leg info to all plugins.
Definition routeman.h:260
EventVar on_message_sent
Notified when a message available as GetString() is sent to garmin.
Definition routeman.h:263
Represents a track, which is a series of connected track points.
Definition track.h:117
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().
Navigation data types.
Route abstraction.
Waypoint or mark abstraction.
RoutePoint * pAnchorWatchPoint2
Global instance.
Definition routeman.cpp:64
Routeman * g_pRouteMan
Global instance.
Definition routeman.cpp:60
RouteList * pRouteList
Global instance.
Definition routeman.cpp:66
bool g_bPluginHandleAutopilotRoute
Global instance.
Definition routeman.cpp:58
RoutePoint * pAnchorWatchPoint1
Global instance.
Definition routeman.cpp:63
Route * pAISMOBRoute
Global instance.
Definition routeman.cpp:61
float g_ChartScaleFactorExp
Global instance.
Definition routeman.cpp:68
Selected route, segment, waypoint, etc.
Callbacks for RoutePropDlg.
Definition routeman.h:80
Routeman callbacks.
Definition routeman.h:92