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, NmeaLog *nmea_log);
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 NmeaLog *GetNmeaLog() { return m_nmea_log; }
252 EventVar &GetMessageSentEventVar() { return on_message_sent; }
253 std::vector<DriverHandle> GetOutpuDriverArray() { return m_output_drivers; }
254 bool m_bDataValid;
255
261
264
267
270
271private:
272 Route *pActiveRoute;
273 RoutePoint *pActivePoint;
274 double RouteBrgToActivePoint; // TODO all these need to be doubles
275 double CurrentSegmentBeginLat;
276 double CurrentSegmentBeginLon;
277 double CurrentRngToActivePoint;
278 double CurrentBrgToActivePoint;
279 double CurrentXTEToActivePoint;
280 double CourseToRouteSegment;
281 double CurrentRangeToActiveNormalCrossing;
282 RoutePoint *pActiveRouteSegmentBeginPoint;
283 RoutePoint *pRouteActivatePoint;
284 double CurrentSegmentCourse;
285 int XTEDir;
286 bool m_bArrival;
287 wxPen *m_pRoutePen;
288 wxPen *m_pTrackPen;
289 wxPen *m_pSelectedRoutePen;
290 wxPen *m_pActiveRoutePen;
291 wxPen *m_pActiveRoutePointPen;
292 wxPen *m_pRoutePointPen;
293 wxBrush *m_pRouteBrush;
294 wxBrush *m_pSelectedRouteBrush;
295 wxBrush *m_pActiveRouteBrush;
296 wxBrush *m_pActiveRoutePointBrush;
297 wxBrush *m_pRoutePointBrush;
298
299 NMEA0183 m_NMEA0183; // For autopilot output
300
301 double m_arrival_min;
302 int m_arrival_test;
303 struct RoutePropDlgCtx m_prop_dlg_ctx;
304 struct RoutemanDlgCtx m_route_dlg_ctx;
305 NmeaLog *m_nmea_log;
306
307 ObsListener msg_sent_listener;
308 ObsListener active_route_listener;
309 std::vector<DriverHandle> m_output_drivers;
310 bool m_have_n0183_out;
311 bool m_have_n2000_out;
312};
313
314//----------------------------------------------------------------------------
315// WayPointman
316//----------------------------------------------------------------------------
317
318typedef std::function<wxColour(wxString)> GlobalColourFunc;
319
321 friend class WayPointmanGui;
322
323public:
324 WayPointman(GlobalColourFunc colour_func);
325 ~WayPointman();
326 wxBitmap *GetIconBitmap(const wxString &icon_key) const;
327 bool GetIconPrescaled(const wxString &icon_key) const;
328 int GetIconIndex(const wxBitmap *pbm) const;
329 int GetIconImageListIndex(const wxBitmap *pbm) const;
330
332 int GetXIconImageListIndex(const wxBitmap *pbm) const;
333
335 int GetFIconImageListIndex(const wxBitmap *pbm) const;
336
337 int GetNumIcons(void) { return m_pIconArray->Count(); }
338 wxString CreateGUID(RoutePoint *pRP);
339 RoutePoint *FindWaypointByGuid(const std::string &guid);
340 RoutePoint *GetNearbyWaypoint(double lat, double lon, double radius_meters);
341 RoutePoint *GetOtherNearbyWaypoint(double lat, double lon,
342 double radius_meters,
343 const wxString &guid);
344 bool IsReallyVisible(RoutePoint *pWP);
345 bool SharedWptsExist();
346 void DeleteAllWaypoints(bool b_delete_used);
347 RoutePoint *FindRoutePointByGUID(const wxString &guid);
348 void DestroyWaypoint(RoutePoint *pRp, bool b_update_changeset = true);
349 void ClearRoutePointFonts(void);
350
351 bool DoesIconExist(const wxString &icon_key) const;
352 wxBitmap GetIconBitmapForList(int index, int height) const;
353 wxString *GetIconDescription(int index) const;
354 wxString *GetIconKey(int index) const;
355 wxString GetIconDescription(wxString icon_key) const;
356
357 wxImageList *Getpmarkicon_image_list(int nominal_height);
358
364 bool AddRoutePoint(RoutePoint *prp);
365
371 bool RemoveRoutePoint(RoutePoint *prp);
372
373 const RoutePointList *GetWaypointList(void) { return m_pWayPointList; }
374
375private:
376 wxImage CreateDimImage(wxImage &image, double factor);
377
378 RoutePointList *m_pWayPointList;
379 wxBitmap *CreateDimBitmap(wxBitmap *pBitmap, double factor);
380
381 wxImageList *pmarkicon_image_list; // Current wxImageList, updated on
382 // colorscheme change
383 int m_markicon_image_list_base_count;
384 ArrayOfMarkIcon *m_pIconArray;
385
386 int m_nGUID;
387 double m_iconListScale;
388
389 SortedArrayOfMarkIcon *m_pLegacyIconArray;
390 SortedArrayOfMarkIcon *m_pExtendedIconArray;
391
392 int m_bitmapSizeForList;
393 int m_iconListHeight;
394 ColorScheme m_cs;
395 GlobalColourFunc m_get_global_colour;
396};
397
398#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:68
Represents a navigational route in the navigation system.
Definition route.h:96
bool ActivateRoutePoint(Route *pA, RoutePoint *pRP)
Activates a specific waypoint within a route for navigation.
Definition routeman.cpp:320
wxArrayPtrVoid * GetRouteArrayContaining(RoutePoint *pWP)
Find all routes that contain the given waypoint.
Definition routeman.cpp:175
bool ActivateNextPoint(Route *pr, bool skipped)
Activates the next waypoint in a route when the current waypoint is reached.
Definition routeman.cpp:395
EventVar on_routes_update
Notified when list of routes is updated (no data in event)
Definition routeman.h:269
bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes)
Definition routeman.cpp:836
bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint=NULL)
Activates a route for navigation.
Definition routeman.cpp:261
EventVar json_msg
Notified with message targeting all plugins.
Definition routeman.h:260
EventVar json_leg_info
Notified with a shared_ptr<ActiveLegDat>, leg info to all plugins.
Definition routeman.h:263
EventVar on_message_sent
Notified when a message available as GetString() is sent to garmin.
Definition routeman.h:266
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