OpenCPN Partial API docs
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 #include "model/nav_object_database.h"
40 #include "model/nmea_log.h"
41 #include "model/ocpn_types.h"
42 #include "model/route.h"
43 #include "model/route_point.h"
44 #include "model/select.h"
45 
46 #include "color_types.h"
47 #include "nmea0183.h"
48 #include "observable_evtvar.h"
49 
50 //----------------------------------------------------------------------------
51 // constants
52 //----------------------------------------------------------------------------
53 #ifndef PI
54 #define PI 3.1415926535897931160E0 /* pi */
55 #endif
56 
57 class Routeman; // forward
58 class WayPointman; // forward
59 
60 extern bool g_bPluginHandleAutopilotRoute;
61 
62 extern Route *pAISMOBRoute;
63 
64 extern RouteList *pRouteList;
65 
66 extern RoutePoint *pAnchorWatchPoint1;
67 extern RoutePoint *pAnchorWatchPoint2;
68 
69 extern float g_ChartScaleFactorExp;
70 
71 extern Routeman* g_pRouteMan;
72 
73 // List definitions for Waypoint Manager Icons
74 
75 class markicon_bitmap_list_type;
76 class markicon_key_list_type;
77 class markicon_description_list_type;
78 
79 WX_DEFINE_SORTED_ARRAY(MarkIcon *, SortedArrayOfMarkIcon);
80 WX_DEFINE_ARRAY(MarkIcon *, ArrayOfMarkIcon);
81 
84  std::function<void(Route*)> set_route_and_update;
85  std::function<void(Route*, RoutePoint*)> set_enroute_point;
86  std::function<void(Route*)> hide;
87  RoutePropDlgCtx() :
88  set_route_and_update([&](Route* r) {}),
89  set_enroute_point([&](Route* r, RoutePoint* rt) {}),
90  hide([&](Route* r) {})
91  { }
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 
113 //----------------------------------------------------------------------------
114 // Routeman
115 //----------------------------------------------------------------------------
116 //
117 class Routeman {
118 
119 friend class RoutemanGui;
120 
121 public:
122  Routeman(struct RoutePropDlgCtx prop_dlg_ctx,
123  struct RoutemanDlgCtx route_dlg_ctx,
124  NmeaLog& nmea_log);
125  ~Routeman();
126 
127  bool DeleteTrack(Track *pTrack);
128  bool DeleteRoute(Route *pRoute, NavObjectChanges* nav_obj_changes);
129  void DeleteAllRoutes(NavObjectChanges* nav_obj_changes);
130 
131 
132  bool IsRouteValid(Route *pRoute);
133 
134  Route *FindRouteByGUID(const wxString &guid);
135  Track *FindTrackByGUID(const wxString &guid);
136  Route *FindRouteContainingWaypoint(RoutePoint *pWP);
137  Route *FindVisibleRouteContainingWaypoint(RoutePoint *pWP);
138  wxArrayPtrVoid *GetRouteArrayContaining(RoutePoint *pWP);
139  bool DoesRouteContainSharedPoints(Route *pRoute);
140  void RemovePointFromRoute(RoutePoint *point, Route *route, int route_state);
141 
142  bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint = NULL);
143  bool ActivateRoutePoint(Route *pA, RoutePoint *pRP);
144  bool ActivateNextPoint(Route *pr, bool skipped);
145  RoutePoint *FindBestActivatePoint(Route *pR, double lat, double lon,
146  double cog, double sog);
147 
148  bool UpdateAutopilot();
149  bool DeactivateRoute(bool b_arrival = false);
150  bool IsAnyRouteActive(void) { return (pActiveRoute != NULL); }
151 
152  Route *GetpActiveRoute() { return pActiveRoute; }
153  RoutePoint *GetpActivePoint() { return pActivePoint; }
154  double GetCurrentRngToActivePoint() { return CurrentRngToActivePoint; }
155  double GetCurrentBrgToActivePoint() { return CurrentBrgToActivePoint; }
156  double GetCurrentRngToActiveNormalArrival() {
157  return CurrentRangeToActiveNormalCrossing;
158  }
159  double GetCurrentXTEToActivePoint() { return CurrentXTEToActivePoint; }
160  void ZeroCurrentXTEToActivePoint();
161  double GetCurrentSegmentCourse() { return CurrentSegmentCourse; }
162  int GetXTEDir() { return XTEDir; }
163 
164  void SetColorScheme(ColorScheme cs, double displayDPmm);
165  wxPen *GetRoutePen(void) { return m_pRoutePen; }
166  wxPen *GetTrackPen(void) { return m_pTrackPen; }
167  wxPen *GetSelectedRoutePen(void) { return m_pSelectedRoutePen; }
168  wxPen *GetActiveRoutePen(void) { return m_pActiveRoutePen; }
169  wxPen *GetActiveRoutePointPen(void) { return m_pActiveRoutePointPen; }
170  wxPen *GetRoutePointPen(void) { return m_pRoutePointPen; }
171  wxBrush *GetRouteBrush(void) { return m_pRouteBrush; }
172  wxBrush *GetSelectedRouteBrush(void) { return m_pSelectedRouteBrush; }
173  wxBrush *GetActiveRouteBrush(void) { return m_pActiveRouteBrush; }
174  wxBrush *GetActiveRoutePointBrush(void) { return m_pActiveRoutePointBrush; }
175  wxBrush *GetRoutePointBrush(void) { return m_pRoutePointBrush; }
176 
177  wxString GetRouteReverseMessage(void);
178  wxString GetRouteResequenceMessage(void);
179  struct RoutemanDlgCtx &GetDlgContext(){ return m_route_dlg_ctx;}
180 
181  bool m_bDataValid;
182 
188 
191 
194 
197 
198 private:
199  Route *pActiveRoute;
200  RoutePoint *pActivePoint;
201  double RouteBrgToActivePoint; // TODO all these need to be doubles
202  double CurrentSegmentBeginLat;
203  double CurrentSegmentBeginLon;
204  double CurrentRngToActivePoint;
205  double CurrentBrgToActivePoint;
206  double CurrentXTEToActivePoint;
207  double CourseToRouteSegment;
208  double CurrentRangeToActiveNormalCrossing;
209  RoutePoint *pActiveRouteSegmentBeginPoint;
210  RoutePoint *pRouteActivatePoint;
211  double CurrentSegmentCourse;
212  int XTEDir;
213  bool m_bArrival;
214  wxPen *m_pRoutePen;
215  wxPen *m_pTrackPen;
216  wxPen *m_pSelectedRoutePen;
217  wxPen *m_pActiveRoutePen;
218  wxPen *m_pActiveRoutePointPen;
219  wxPen *m_pRoutePointPen;
220  wxBrush *m_pRouteBrush;
221  wxBrush *m_pSelectedRouteBrush;
222  wxBrush *m_pActiveRouteBrush;
223  wxBrush *m_pActiveRoutePointBrush;
224  wxBrush *m_pRoutePointBrush;
225 
226  NMEA0183 m_NMEA0183; // For autopilot output
227 
228  double m_arrival_min;
229  int m_arrival_test;
230  struct RoutePropDlgCtx m_prop_dlg_ctx;
231  struct RoutemanDlgCtx m_route_dlg_ctx;
232  NmeaLog& m_nmea_log;
233 
234  ObsListener msg_sent_listener;
235  ObsListener active_route_listener;
236 };
237 
238 //----------------------------------------------------------------------------
239 // WayPointman
240 //----------------------------------------------------------------------------
241 
242 typedef std::function<wxColour(wxString)> GlobalColourFunc;
243 
244 class WayPointman {
245 
246 friend class WayPointmanGui;
247 
248 public:
249  WayPointman(GlobalColourFunc colour_func);
250  ~WayPointman();
251  wxBitmap *GetIconBitmap(const wxString &icon_key);
252  bool GetIconPrescaled(const wxString &icon_key);
253  int GetIconIndex(const wxBitmap *pbm);
254  int GetIconImageListIndex(const wxBitmap *pbm);
255  int GetXIconImageListIndex(const wxBitmap *pbm);
256  int GetFIconImageListIndex(const wxBitmap *pbm);
257  int GetNumIcons(void) { return m_pIconArray->Count(); }
258  wxString CreateGUID(RoutePoint *pRP);
259  RoutePoint* FindWaypointByGuid(const std::string& guid);
260  RoutePoint *GetNearbyWaypoint(double lat, double lon, double radius_meters);
261  RoutePoint *GetOtherNearbyWaypoint(double lat, double lon,
262  double radius_meters,
263  const wxString &guid);
264  bool IsReallyVisible(RoutePoint *pWP);
265  bool SharedWptsExist();
266  void DeleteAllWaypoints(bool b_delete_used);
267  RoutePoint *FindRoutePointByGUID(const wxString &guid);
268  void DestroyWaypoint(RoutePoint *pRp, bool b_update_changeset = true);
269  void ClearRoutePointFonts(void);
270 
271  bool DoesIconExist(const wxString &icon_key) const;
272  wxBitmap GetIconBitmapForList(int index, int height);
273  wxString *GetIconDescription(int index);
274  wxString *GetIconKey(int index);
275  wxString GetIconDescription(wxString icon_key);
276 
277  wxImageList *Getpmarkicon_image_list(int nominal_height);
278 
279  bool AddRoutePoint(RoutePoint *prp);
280  bool RemoveRoutePoint(RoutePoint *prp);
281  RoutePointList *GetWaypointList(void) { return m_pWayPointList; }
282 
283 
284 private:
285  wxImage CreateDimImage(wxImage &image, double factor);
286 
287  RoutePointList *m_pWayPointList;
288  wxBitmap *CreateDimBitmap(wxBitmap *pBitmap, double factor);
289 
290  wxImageList *pmarkicon_image_list; // Current wxImageList, updated on
291  // colorscheme change
292  int m_markicon_image_list_base_count;
293  ArrayOfMarkIcon *m_pIconArray;
294 
295  int m_nGUID;
296  double m_iconListScale;
297 
298  SortedArrayOfMarkIcon *m_pLegacyIconArray;
299  SortedArrayOfMarkIcon *m_pExtendedIconArray;
300 
301  int m_bitmapSizeForList;
302  int m_iconListHeight;
303  ColorScheme m_cs;
304  GlobalColourFunc m_get_global_colour;
305 };
306 
307 #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:210
Definition: route.h:75
bool ActivateRoutePoint(Route *pA, RoutePoint *pRP)
Definition: routeman.cpp:294
bool ActivateNextPoint(Route *pr, bool skipped)
Definition: routeman.cpp:369
EventVar on_routes_update
Notified when list of routes is updated (no data in event)
Definition: routeman.h:196
bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes)
Definition: routeman.cpp:751
EventVar json_msg
Notified with message targeting all plugins.
Definition: routeman.h:187
EventVar json_leg_info
Notified with a shared_ptr<ActiveLegDat>, leg info to all plugins.
Definition: routeman.h:190
EventVar on_message_sent
Notified when a message available as GetString() is sent to garmin.
Definition: routeman.h:193
Definition: track.h:78
Callbacks for RoutePropDlg.
Definition: routeman.h:83
Routeman callbacks.
Definition: routeman.h:96