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);
125 void DeleteAllRoutes();
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 *FindRouteContainingWaypoint(const std::string &guid);
133 Route *FindVisibleRouteContainingWaypoint(RoutePoint *pWP);
146 wxArrayPtrVoid *GetRouteArrayContaining(RoutePoint *pWP);
147 bool DoesRouteContainSharedPoints(Route *pRoute);
148 void RemovePointFromRoute(RoutePoint *point, Route *route, int route_state);
149
170 bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint = NULL);
189 bool ActivateRoutePoint(Route *pA, RoutePoint *pRP);
210 bool ActivateNextPoint(Route *pr, bool skipped);
211 RoutePoint *FindBestActivatePoint(Route *pR, double lat, double lon,
212 double cog, double sog);
213
214 bool UpdateAutopilot();
215 bool DeactivateRoute(bool b_arrival = false);
216 bool IsAnyRouteActive(void) { return (pActiveRoute != NULL); }
217 bool GetArrival() { return m_bArrival; }
218
219 Route *GetpActiveRoute() { return pActiveRoute; }
220 RoutePoint *GetpActiveRouteSegmentBeginPoint() {
221 return pActiveRouteSegmentBeginPoint;
222 }
223
224 RoutePoint *GetpActivePoint() { return pActivePoint; }
225 double GetCurrentRngToActivePoint() { return CurrentRngToActivePoint; }
226 double GetCurrentBrgToActivePoint() { return CurrentBrgToActivePoint; }
227 double GetCurrentRngToActiveNormalArrival() {
228 return CurrentRangeToActiveNormalCrossing;
229 }
230 double GetCurrentXTEToActivePoint() { return CurrentXTEToActivePoint; }
231 void ZeroCurrentXTEToActivePoint();
232 double GetCurrentSegmentCourse() { return CurrentSegmentCourse; }
233 int GetXTEDir() { return XTEDir; }
234
235 void SetColorScheme(ColorScheme cs, double displayDPmm);
236 wxPen *GetRoutePen(void) { return m_pRoutePen; }
237 wxPen *GetTrackPen(void) { return m_pTrackPen; }
238 wxPen *GetSelectedRoutePen(void) { return m_pSelectedRoutePen; }
239 wxPen *GetActiveRoutePen(void) { return m_pActiveRoutePen; }
240 wxPen *GetActiveRoutePointPen(void) { return m_pActiveRoutePointPen; }
241 wxPen *GetRoutePointPen(void) { return m_pRoutePointPen; }
242 wxBrush *GetRouteBrush(void) { return m_pRouteBrush; }
243 wxBrush *GetSelectedRouteBrush(void) { return m_pSelectedRouteBrush; }
244 wxBrush *GetActiveRouteBrush(void) { return m_pActiveRouteBrush; }
245 wxBrush *GetActiveRoutePointBrush(void) { return m_pActiveRoutePointBrush; }
246 wxBrush *GetRoutePointBrush(void) { return m_pRoutePointBrush; }
247
248 wxString GetRouteReverseMessage(void);
249 wxString GetRouteResequenceMessage(void);
250 struct RoutemanDlgCtx &GetDlgContext() { return m_route_dlg_ctx; }
251 NMEA0183 GetNMEA0183() { return m_NMEA0183; }
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
306 ObsListener msg_sent_listener;
307 ObsListener active_route_listener;
308 std::vector<DriverHandle> m_output_drivers;
309 bool m_have_n0183_out;
310 bool m_have_n2000_out;
311};
312
313//----------------------------------------------------------------------------
314// WayPointman
315//----------------------------------------------------------------------------
316
317typedef std::function<wxColour(wxString)> GlobalColourFunc;
318
320 friend class WayPointmanGui;
321
322public:
323 WayPointman(GlobalColourFunc colour_func);
324 ~WayPointman();
325 wxBitmap *GetIconBitmap(const wxString &icon_key) const;
326 bool GetIconPrescaled(const wxString &icon_key) const;
327 int GetIconIndex(const wxBitmap *pbm) const;
328 int GetIconImageListIndex(const wxBitmap *pbm) const;
329
331 int GetXIconImageListIndex(const wxBitmap *pbm) const;
332
334 int GetFIconImageListIndex(const wxBitmap *pbm) const;
335
336 int GetNumIcons(void) { return m_pIconArray->Count(); }
337 wxString CreateGUID(RoutePoint *pRP);
338 RoutePoint *FindWaypointByGuid(const std::string &guid);
339 RoutePoint *GetNearbyWaypoint(double lat, double lon, double radius_meters);
340 RoutePoint *GetOtherNearbyWaypoint(double lat, double lon,
341 double radius_meters,
342 const wxString &guid);
343 bool IsReallyVisible(RoutePoint *pWP);
344 bool SharedWptsExist();
345 void DeleteAllWaypoints(bool b_delete_used);
346 RoutePoint *FindRoutePointByGUID(const wxString &guid);
347 void DestroyWaypoint(RoutePoint *pRp, bool b_update_changeset = true);
348 void ClearRoutePointFonts(void);
349
350 bool DoesIconExist(const wxString &icon_key) const;
351 wxBitmap GetIconBitmapForList(int index, int height) const;
352 wxString *GetIconDescription(int index) const;
353 wxString *GetIconKey(int index) const;
354 wxString GetIconDescription(wxString icon_key) const;
355
356 wxImageList *Getpmarkicon_image_list(int nominal_height);
357
363 bool AddRoutePoint(RoutePoint *prp);
364
370 bool RemoveRoutePoint(RoutePoint *prp);
371
372 const RoutePointList *GetWaypointList(void) { return m_pWayPointList; }
373
374private:
375 wxImage CreateDimImage(wxImage &image, double factor);
376
377 RoutePointList *m_pWayPointList;
378 wxBitmap *CreateDimBitmap(wxBitmap *pBitmap, double factor);
379
380 wxImageList *pmarkicon_image_list; // Current wxImageList, updated on
381 // colorscheme change
382 int m_markicon_image_list_base_count;
383 ArrayOfMarkIcon *m_pIconArray;
384
385 int m_nGUID;
386 double m_iconListScale;
387
388 SortedArrayOfMarkIcon *m_pLegacyIconArray;
389 SortedArrayOfMarkIcon *m_pExtendedIconArray;
390
391 int m_bitmapSizeForList;
392 int m_iconListHeight;
393 ColorScheme m_cs;
394 GlobalColourFunc m_get_global_colour;
395};
396
397#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:338
wxArrayPtrVoid * GetRouteArrayContaining(RoutePoint *pWP)
Find all routes that contain the given waypoint.
Definition routeman.cpp:194
bool ActivateNextPoint(Route *pr, bool skipped)
Activates the next waypoint in a route when the current waypoint is reached.
Definition routeman.cpp:413
bool DeleteRoute(Route *pRoute)
Definition routeman.cpp:856
EventVar on_routes_update
Notified when list of routes is updated (no data in event)
Definition routeman.h:269
bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint=NULL)
Activates a route for navigation.
Definition routeman.cpp:279
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