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
76class markicon_bitmap_list_type;
77class markicon_key_list_type;
78class markicon_description_list_type;
79
80WX_DEFINE_SORTED_ARRAY(MarkIcon *, SortedArrayOfMarkIcon);
81WX_DEFINE_ARRAY(MarkIcon *, ArrayOfMarkIcon);
82
85 std::function<void(Route *)> set_route_and_update;
86 std::function<void(Route *, RoutePoint *)> set_enroute_point;
87 std::function<void(Route *)> hide;
89 : set_route_and_update([&](Route *r) {}),
90 set_enroute_point([&](Route *r, RoutePoint *rt) {}),
91 hide([&](Route *r) {}) {}
92};
93
97 std::function<bool()> confirm_delete_ais_mob;
98 std::function<wxColour(wxString)> get_global_colour;
99 std::function<void()> show_with_fresh_fonts;
100 std::function<void()> clear_console_background;
101 std::function<void()> route_mgr_dlg_update_list_ctrl;
102
104 : confirm_delete_ais_mob([]() { return true; }),
105 get_global_colour([](wxString c) { return *wxBLACK; }),
106 show_with_fresh_fonts([]() {}),
107 clear_console_background([]() {}),
108 route_mgr_dlg_update_list_ctrl([]() {}) {}
109};
110
111//----------------------------------------------------------------------------
112// Routeman
113//----------------------------------------------------------------------------
114//
115class Routeman {
116 friend class RoutemanGui;
117
118public:
119 Routeman(struct RoutePropDlgCtx prop_dlg_ctx,
120 struct RoutemanDlgCtx route_dlg_ctx);
121 ~Routeman();
122
123 bool DeleteTrack(Track *pTrack);
124 bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes);
125 void DeleteAllRoutes(NavObjectChanges *nav_obj_changes);
126
127 bool IsRouteValid(Route *pRoute);
128
129 Route *FindRouteByGUID(const wxString &guid);
130 Track *FindTrackByGUID(const wxString &guid);
131 Route *FindRouteContainingWaypoint(RoutePoint *pWP);
132 Route *FindVisibleRouteContainingWaypoint(RoutePoint *pWP);
145 wxArrayPtrVoid *GetRouteArrayContaining(RoutePoint *pWP);
146 bool DoesRouteContainSharedPoints(Route *pRoute);
147 void RemovePointFromRoute(RoutePoint *point, Route *route, int route_state);
148
169 bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint = NULL);
188 bool ActivateRoutePoint(Route *pA, RoutePoint *pRP);
209 bool ActivateNextPoint(Route *pr, bool skipped);
210 RoutePoint *FindBestActivatePoint(Route *pR, double lat, double lon,
211 double cog, double sog);
212
213 bool UpdateAutopilot();
214 bool DeactivateRoute(bool b_arrival = false);
215 bool IsAnyRouteActive(void) { return (pActiveRoute != NULL); }
216 bool GetArrival() { return m_bArrival; }
217
218 Route *GetpActiveRoute() { return pActiveRoute; }
219 RoutePoint *GetpActiveRouteSegmentBeginPoint() {
220 return pActiveRouteSegmentBeginPoint;
221 }
222
223 RoutePoint *GetpActivePoint() { return pActivePoint; }
224 double GetCurrentRngToActivePoint() { return CurrentRngToActivePoint; }
225 double GetCurrentBrgToActivePoint() { return CurrentBrgToActivePoint; }
226 double GetCurrentRngToActiveNormalArrival() {
227 return CurrentRangeToActiveNormalCrossing;
228 }
229 double GetCurrentXTEToActivePoint() { return CurrentXTEToActivePoint; }
230 void ZeroCurrentXTEToActivePoint();
231 double GetCurrentSegmentCourse() { return CurrentSegmentCourse; }
232 int GetXTEDir() { return XTEDir; }
233
234 void SetColorScheme(ColorScheme cs, double displayDPmm);
235 wxPen *GetRoutePen(void) { return m_pRoutePen; }
236 wxPen *GetTrackPen(void) { return m_pTrackPen; }
237 wxPen *GetSelectedRoutePen(void) { return m_pSelectedRoutePen; }
238 wxPen *GetActiveRoutePen(void) { return m_pActiveRoutePen; }
239 wxPen *GetActiveRoutePointPen(void) { return m_pActiveRoutePointPen; }
240 wxPen *GetRoutePointPen(void) { return m_pRoutePointPen; }
241 wxBrush *GetRouteBrush(void) { return m_pRouteBrush; }
242 wxBrush *GetSelectedRouteBrush(void) { return m_pSelectedRouteBrush; }
243 wxBrush *GetActiveRouteBrush(void) { return m_pActiveRouteBrush; }
244 wxBrush *GetActiveRoutePointBrush(void) { return m_pActiveRoutePointBrush; }
245 wxBrush *GetRoutePointBrush(void) { return m_pRoutePointBrush; }
246
247 wxString GetRouteReverseMessage(void);
248 wxString GetRouteResequenceMessage(void);
249 struct RoutemanDlgCtx &GetDlgContext() { return m_route_dlg_ctx; }
250 NMEA0183 GetNMEA0183() { return m_NMEA0183; }
251 EventVar &GetMessageSentEventVar() { return on_message_sent; }
252 std::vector<DriverHandle> GetOutpuDriverArray() { return m_output_drivers; }
253 bool m_bDataValid;
254
260
263
266
269
270private:
271 Route *pActiveRoute;
272 RoutePoint *pActivePoint;
273 double RouteBrgToActivePoint; // TODO all these need to be doubles
274 double CurrentSegmentBeginLat;
275 double CurrentSegmentBeginLon;
276 double CurrentRngToActivePoint;
277 double CurrentBrgToActivePoint;
278 double CurrentXTEToActivePoint;
279 double CourseToRouteSegment;
280 double CurrentRangeToActiveNormalCrossing;
281 RoutePoint *pActiveRouteSegmentBeginPoint;
282 RoutePoint *pRouteActivatePoint;
283 double CurrentSegmentCourse;
284 int XTEDir;
285 bool m_bArrival;
286 wxPen *m_pRoutePen;
287 wxPen *m_pTrackPen;
288 wxPen *m_pSelectedRoutePen;
289 wxPen *m_pActiveRoutePen;
290 wxPen *m_pActiveRoutePointPen;
291 wxPen *m_pRoutePointPen;
292 wxBrush *m_pRouteBrush;
293 wxBrush *m_pSelectedRouteBrush;
294 wxBrush *m_pActiveRouteBrush;
295 wxBrush *m_pActiveRoutePointBrush;
296 wxBrush *m_pRoutePointBrush;
297
298 NMEA0183 m_NMEA0183; // For autopilot output
299
300 double m_arrival_min;
301 int m_arrival_test;
302 struct RoutePropDlgCtx m_prop_dlg_ctx;
303 struct RoutemanDlgCtx m_route_dlg_ctx;
304
305 ObsListener msg_sent_listener;
306 ObsListener active_route_listener;
307 std::vector<DriverHandle> m_output_drivers;
308 bool m_have_n0183_out;
309 bool m_have_n2000_out;
310};
311
312//----------------------------------------------------------------------------
313// WayPointman
314//----------------------------------------------------------------------------
315
316typedef std::function<wxColour(wxString)> GlobalColourFunc;
317
319 friend class WayPointmanGui;
320
321public:
322 WayPointman(GlobalColourFunc colour_func);
323 ~WayPointman();
324 wxBitmap *GetIconBitmap(const wxString &icon_key) const;
325 bool GetIconPrescaled(const wxString &icon_key) const;
326 int GetIconIndex(const wxBitmap *pbm) const;
327 int GetIconImageListIndex(const wxBitmap *pbm) const;
328
330 int GetXIconImageListIndex(const wxBitmap *pbm) const;
331
333 int GetFIconImageListIndex(const wxBitmap *pbm) const;
334
335 int GetNumIcons(void) { return m_pIconArray->Count(); }
336 wxString CreateGUID(RoutePoint *pRP);
337 RoutePoint *FindWaypointByGuid(const std::string &guid);
338 RoutePoint *GetNearbyWaypoint(double lat, double lon, double radius_meters);
339 RoutePoint *GetOtherNearbyWaypoint(double lat, double lon,
340 double radius_meters,
341 const wxString &guid);
342 bool IsReallyVisible(RoutePoint *pWP);
343 bool SharedWptsExist();
344 void DeleteAllWaypoints(bool b_delete_used);
345 RoutePoint *FindRoutePointByGUID(const wxString &guid);
346 void DestroyWaypoint(RoutePoint *pRp, bool b_update_changeset = true);
347 void ClearRoutePointFonts(void);
348
349 bool DoesIconExist(const wxString &icon_key) const;
350 wxBitmap GetIconBitmapForList(int index, int height) const;
351 wxString *GetIconDescription(int index) const;
352 wxString *GetIconKey(int index) const;
353 wxString GetIconDescription(wxString icon_key) const;
354
355 wxImageList *Getpmarkicon_image_list(int nominal_height);
356
362 bool AddRoutePoint(RoutePoint *prp);
363
369 bool RemoveRoutePoint(RoutePoint *prp);
370
371 const RoutePointList *GetWaypointList(void) { return m_pWayPointList; }
372
373private:
374 wxImage CreateDimImage(wxImage &image, double factor);
375
376 RoutePointList *m_pWayPointList;
377 wxBitmap *CreateDimBitmap(wxBitmap *pBitmap, double factor);
378
379 wxImageList *pmarkicon_image_list; // Current wxImageList, updated on
380 // colorscheme change
381 int m_markicon_image_list_base_count;
382 ArrayOfMarkIcon *m_pIconArray;
383
384 int m_nGUID;
385 double m_iconListScale;
386
387 SortedArrayOfMarkIcon *m_pLegacyIconArray;
388 SortedArrayOfMarkIcon *m_pExtendedIconArray;
389
390 int m_bitmapSizeForList;
391 int m_iconListHeight;
392 ColorScheme m_cs;
393 GlobalColourFunc m_get_global_colour;
394};
395
396#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
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:319
wxArrayPtrVoid * GetRouteArrayContaining(RoutePoint *pWP)
Find all routes that contain the given waypoint.
Definition routeman.cpp:174
bool ActivateNextPoint(Route *pr, bool skipped)
Activates the next waypoint in a route when the current waypoint is reached.
Definition routeman.cpp:394
EventVar on_routes_update
Notified when list of routes is updated (no data in event)
Definition routeman.h:268
bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes)
Definition routeman.cpp:835
bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint=NULL)
Activates a route for navigation.
Definition routeman.cpp:260
EventVar json_msg
Notified with message targeting all plugins.
Definition routeman.h:259
EventVar json_leg_info
Notified with a shared_ptr<ActiveLegDat>, leg info to all plugins.
Definition routeman.h:262
EventVar on_message_sent
Notified when a message available as GetString() is sent to garmin.
Definition routeman.h:265
Represents a track, which is a series of connected track points.
Definition track.h:111
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:84
Routeman callbacks.
Definition routeman.h:96