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 "MarkIcon.h"
39#include "nav_object_database.h"
40#include "nmea0183.h"
41#include "ocpn_types.h"
42#include "observable_evtvar.h"
43#include "route.h"
44#include "route_point.h"
45#include "select.h"
46
47//----------------------------------------------------------------------------
48// constants
49//----------------------------------------------------------------------------
50#ifndef PI
51#define PI 3.1415926535897931160E0 /* pi */
52#endif
53
54extern bool g_bPluginHandleAutopilotRoute;
55
56// List definitions for Waypoint Manager Icons
57
58class markicon_bitmap_list_type;
59class markicon_key_list_type;
60class markicon_description_list_type;
61
62WX_DEFINE_SORTED_ARRAY(MarkIcon *, SortedArrayOfMarkIcon);
63WX_DEFINE_ARRAY(MarkIcon *, ArrayOfMarkIcon);
64
65// Callbacks for RoutePropDlg
67 std::function<void(Route*)> SetRouteAndUpdate;
68 std::function<void(Route*, RoutePoint*)> SetEnroutePoint;
69 std::function<void(Route*)> Hide;
71 SetRouteAndUpdate([&](Route* r) {}),
72 SetEnroutePoint([&](Route* r, RoutePoint* rt) {}),
73 Hide([&](Route* r) {})
74 { }
75};
76
77//----------------------------------------------------------------------------
78// Routeman
79//----------------------------------------------------------------------------
80//
81class Routeman {
82
83friend class RoutemanGui;
84
85public:
86 Routeman(struct RoutePropDlgCtx ctx,
87 std::function<void()> RouteMgrDlgUpdateListCtrl);
88 ~Routeman();
89
90 bool DeleteRoute(Route *pRoute, NavObjectChanges* nav_obj_changes);
91 void DeleteAllRoutes(NavObjectChanges* nav_obj_changes);
92
93
94 bool IsRouteValid(Route *pRoute);
95
96 Route *FindRouteByGUID(const wxString &guid);
97 Track *FindTrackByGUID(const wxString &guid);
98 Route *FindRouteContainingWaypoint(RoutePoint *pWP);
99 Route *FindVisibleRouteContainingWaypoint(RoutePoint *pWP);
100 wxArrayPtrVoid *GetRouteArrayContaining(RoutePoint *pWP);
101 bool DoesRouteContainSharedPoints(Route *pRoute);
102 void RemovePointFromRoute(RoutePoint *point, Route *route, int route_state);
103
104 bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint = NULL);
105 bool ActivateRoutePoint(Route *pA, RoutePoint *pRP);
106 bool ActivateNextPoint(Route *pr, bool skipped);
107 RoutePoint *FindBestActivatePoint(Route *pR, double lat, double lon,
108 double cog, double sog);
109
110 bool UpdateAutopilot();
111 bool DeactivateRoute(bool b_arrival = false);
112 bool IsAnyRouteActive(void) { return (pActiveRoute != NULL); }
113
114 Route *GetpActiveRoute() { return pActiveRoute; }
115 RoutePoint *GetpActivePoint() { return pActivePoint; }
116 double GetCurrentRngToActivePoint() { return CurrentRngToActivePoint; }
117 double GetCurrentBrgToActivePoint() { return CurrentBrgToActivePoint; }
118 double GetCurrentRngToActiveNormalArrival() {
119 return CurrentRangeToActiveNormalCrossing;
120 }
121 double GetCurrentXTEToActivePoint() { return CurrentXTEToActivePoint; }
122 void ZeroCurrentXTEToActivePoint();
123 double GetCurrentSegmentCourse() { return CurrentSegmentCourse; }
124 int GetXTEDir() { return XTEDir; }
125
126 void SetColorScheme(ColorScheme cs, double displayDPmm);
127 wxPen *GetRoutePen(void) { return m_pRoutePen; }
128 wxPen *GetTrackPen(void) { return m_pTrackPen; }
129 wxPen *GetSelectedRoutePen(void) { return m_pSelectedRoutePen; }
130 wxPen *GetActiveRoutePen(void) { return m_pActiveRoutePen; }
131 wxPen *GetActiveRoutePointPen(void) { return m_pActiveRoutePointPen; }
132 wxPen *GetRoutePointPen(void) { return m_pRoutePointPen; }
133 wxBrush *GetRouteBrush(void) { return m_pRouteBrush; }
134 wxBrush *GetSelectedRouteBrush(void) { return m_pSelectedRouteBrush; }
135 wxBrush *GetActiveRouteBrush(void) { return m_pActiveRouteBrush; }
136 wxBrush *GetActiveRoutePointBrush(void) { return m_pActiveRoutePointBrush; }
137 wxBrush *GetRoutePointBrush(void) { return m_pRoutePointBrush; }
138
139 wxString GetRouteReverseMessage(void);
140 wxString GetRouteResequenceMessage(void);
141
142 bool m_bDataValid;
143
149
152
153private:
154
155 Route *pActiveRoute;
156 RoutePoint *pActivePoint;
157 double RouteBrgToActivePoint; // TODO all these need to be doubles
158 double CurrentSegmentBeginLat;
159 double CurrentSegmentBeginLon;
160 double CurrentRngToActivePoint;
161 double CurrentBrgToActivePoint;
162 double CurrentXTEToActivePoint;
163 double CourseToRouteSegment;
164 double CurrentRangeToActiveNormalCrossing;
165 RoutePoint *pActiveRouteSegmentBeginPoint;
166 RoutePoint *pRouteActivatePoint;
167 double CurrentSegmentCourse;
168 int XTEDir;
169 bool m_bArrival;
170 wxPen *m_pRoutePen;
171 wxPen *m_pTrackPen;
172 wxPen *m_pSelectedRoutePen;
173 wxPen *m_pActiveRoutePen;
174 wxPen *m_pActiveRoutePointPen;
175 wxPen *m_pRoutePointPen;
176 wxBrush *m_pRouteBrush;
177 wxBrush *m_pSelectedRouteBrush;
178 wxBrush *m_pActiveRouteBrush;
179 wxBrush *m_pActiveRoutePointBrush;
180 wxBrush *m_pRoutePointBrush;
181
182 NMEA0183 m_NMEA0183; // For autopilot output
183
184 double m_arrival_min;
185 int m_arrival_test;
186 struct RoutePropDlgCtx m_prop_dlg_ctx;
187 std::function<void()> m_route_mgr_dlg_update_list_ctrl;
188};
189
190//----------------------------------------------------------------------------
191// WayPointman
192//----------------------------------------------------------------------------
193
195
196friend class WayPointmanGui;
197
198public:
199 WayPointman();
200 ~WayPointman();
201 wxBitmap *GetIconBitmap(const wxString &icon_key);
202 bool GetIconPrescaled(const wxString &icon_key);
203 unsigned int GetIconTexture(const wxBitmap *pmb, int &glw, int &glh);
204 int GetIconIndex(const wxBitmap *pbm);
205 int GetIconImageListIndex(const wxBitmap *pbm);
206 int GetXIconImageListIndex(const wxBitmap *pbm);
207 int GetFIconImageListIndex(const wxBitmap *pbm);
208 int GetNumIcons(void) { return m_pIconArray->Count(); }
209 wxString CreateGUID(RoutePoint *pRP);
210 RoutePoint *GetNearbyWaypoint(double lat, double lon, double radius_meters);
211 RoutePoint *GetOtherNearbyWaypoint(double lat, double lon,
212 double radius_meters,
213 const wxString &guid);
214 bool IsReallyVisible(RoutePoint *pWP);
215 bool SharedWptsExist();
216 void DeleteAllWaypoints(bool b_delete_used);
217 RoutePoint *FindRoutePointByGUID(const wxString &guid);
218 void DestroyWaypoint(RoutePoint *pRp, bool b_update_changeset = true);
219 void ClearRoutePointFonts(void);
220
221 bool DoesIconExist(const wxString &icon_key) const;
222 wxBitmap GetIconBitmapForList(int index, int height);
223 wxString *GetIconDescription(int index);
224 wxString *GetIconKey(int index);
225 wxString GetIconDescription(wxString icon_key);
226
227 wxImageList *Getpmarkicon_image_list(int nominal_height);
228
229 bool AddRoutePoint(RoutePoint *prp);
230 bool RemoveRoutePoint(RoutePoint *prp);
231 RoutePointList *GetWaypointList(void) { return m_pWayPointList; }
232
233
234private:
235 wxImage CreateDimImage(wxImage &image, double factor);
236
237 RoutePointList *m_pWayPointList;
238 wxBitmap *CreateDimBitmap(wxBitmap *pBitmap, double factor);
239
240 wxImageList *pmarkicon_image_list; // Current wxImageList, updated on
241 // colorscheme change
242 int m_markicon_image_list_base_count;
243 ArrayOfMarkIcon *m_pIconArray;
244
245 int m_nGUID;
246 double m_iconListScale;
247
248 SortedArrayOfMarkIcon *m_pLegacyIconArray;
249 SortedArrayOfMarkIcon *m_pExtendedIconArray;
250
251 int m_bitmapSizeForList;
252 int m_iconListHeight;
253 ColorScheme m_cs;
254};
255
256#endif // _ROUTEMAN_H__
Generic event handling between between two parties like MVC Model and Controller using a shared Event...
Definition: route.h:70
bool ActivateRoutePoint(Route *pA, RoutePoint *pRP)
Definition: routeman.cpp:312
bool ActivateNextPoint(Route *pr, bool skipped)
Definition: routeman.cpp:387
bool DeleteRoute(Route *pRoute, NavObjectChanges *nav_obj_changes)
Definition: routeman.cpp:726
EventVar json_msg
Notified with message targeting all plugins.
Definition: routeman.h:148
EventVar json_leg_info
Notified with a shared_ptr<ActiveLegDat>, leg info to all plugins.
Definition: routeman.h:151
Definition: track.h:79