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 
30 #include "chart1.h"                 // for ColorScheme definition
31 #include <wx/imaglist.h>
32 #include "styles.h"
33 #include "Select.h"
34 #include "nmea0183.h"
35 
36 //----------------------------------------------------------------------------
37 //   constants
38 //----------------------------------------------------------------------------
39 #ifndef PI
40 #define PI        3.1415926535897931160E0      /* pi */
41 #endif
42 
43 extern bool g_bPluginHandleAutopilotRoute;
44 
45 //----------------------------------------------------------------------------
46 //    forward class declarations
47 //----------------------------------------------------------------------------
48 
49 class Route;
50 class RoutePoint;
51 class RoutePointList;
52 
53 //    List definitions for Waypoint Manager Icons
54 
55 class markicon_bitmap_list_type;
56 class markicon_key_list_type;
57 class markicon_description_list_type;
58 class MarkIcon;
59 WX_DEFINE_SORTED_ARRAY(MarkIcon*, SortedArrayOfMarkIcon);
60 WX_DEFINE_ARRAY(MarkIcon*, ArrayOfMarkIcon);
61 
62 //----------------------------------------------------------------------------
63 //   Routeman
64 //----------------------------------------------------------------------------
65 
66 class Routeman
67 {
68 public:
69       Routeman(MyApp *parent);
70       ~Routeman();
71 
72       bool DeleteRoute(Route *pRoute);
73       void DeleteAllRoutes(void);
74       void DeleteAllTracks(void);
75 
76       void DeleteTrack(Track *pTrack);
77 
78       bool IsRouteValid(Route *pRoute);
79 
80       Route *FindRouteByGUID(const wxString &guid);
81       Track *FindTrackByGUID(const wxString &guid);
82       Route *FindRouteContainingWaypoint(RoutePoint *pWP);
83       wxArrayPtrVoid *GetRouteArrayContaining(RoutePoint *pWP);
84       bool DoesRouteContainSharedPoints( Route *pRoute );
85       void RemovePointFromRoute( RoutePoint* point, Route* route, ChartCanvas *cc );
86 
87       bool ActivateRoute(Route *pRouteToActivate, RoutePoint *pStartPoint = NULL);
88       bool ActivateRoutePoint(Route *pA, RoutePoint *pRP);
89       bool ActivateNextPoint(Route *pr, bool skipped);
90       RoutePoint *FindBestActivatePoint(Route *pR, double lat, double lon, double cog, double sog);
91 
92       bool UpdateProgress();
93       bool UpdateAutopilot();
94       bool DeactivateRoute( bool b_arrival = false );
IsAnyRouteActive(void)95       bool IsAnyRouteActive(void){ return (pActiveRoute != NULL); }
96       void SetColorScheme(ColorScheme cs);
97 
GetpActiveRoute()98       Route *GetpActiveRoute(){ return pActiveRoute;}
GetpActivePoint()99       RoutePoint *GetpActivePoint(){ return pActivePoint;}
GetCurrentRngToActivePoint()100       double GetCurrentRngToActivePoint(){ return CurrentRngToActivePoint;}
GetCurrentBrgToActivePoint()101       double GetCurrentBrgToActivePoint(){ return CurrentBrgToActivePoint;}
GetCurrentRngToActiveNormalArrival()102       double GetCurrentRngToActiveNormalArrival(){ return CurrentRangeToActiveNormalCrossing;}
GetCurrentXTEToActivePoint()103       double GetCurrentXTEToActivePoint(){ return CurrentXTEToActivePoint;}
104       void   ZeroCurrentXTEToActivePoint();
GetCurrentSegmentCourse()105       double GetCurrentSegmentCourse(){ return CurrentSegmentCourse;}
GetXTEDir()106       int   GetXTEDir(){ return XTEDir;}
107 
GetRoutePen(void)108       wxPen   * GetRoutePen(void){return m_pRoutePen;}
GetTrackPen(void)109       wxPen   * GetTrackPen(void){return m_pTrackPen;}
GetSelectedRoutePen(void)110       wxPen   * GetSelectedRoutePen(void){return m_pSelectedRoutePen;}
GetActiveRoutePen(void)111       wxPen   * GetActiveRoutePen(void){return m_pActiveRoutePen;}
GetActiveRoutePointPen(void)112       wxPen   * GetActiveRoutePointPen(void){return m_pActiveRoutePointPen;}
GetRoutePointPen(void)113       wxPen   * GetRoutePointPen(void){return m_pRoutePointPen;}
GetRouteBrush(void)114       wxBrush * GetRouteBrush(void){return m_pRouteBrush;}
GetSelectedRouteBrush(void)115       wxBrush * GetSelectedRouteBrush(void){return m_pSelectedRouteBrush;}
GetActiveRouteBrush(void)116       wxBrush * GetActiveRouteBrush(void){return m_pActiveRouteBrush;}
GetActiveRoutePointBrush(void)117       wxBrush * GetActiveRoutePointBrush(void){return m_pActiveRoutePointBrush;}
GetRoutePointBrush(void)118       wxBrush * GetRoutePointBrush(void){return m_pRoutePointBrush;}
119 
120       wxString GetRouteReverseMessage(void);
121 
122       bool        m_bDataValid;
123 
124 private:
125       void DoAdvance(void);
126 
127       MyApp       *m_pparent_app;
128       Route       *pActiveRoute;
129       RoutePoint  *pActivePoint;
130       double       RouteBrgToActivePoint;        //TODO all these need to be doubles
131       double       CurrentSegmentBeginLat;
132       double       CurrentSegmentBeginLon;
133       double       CurrentRngToActivePoint;
134       double       CurrentBrgToActivePoint;
135       double       CurrentXTEToActivePoint;
136       double       CourseToRouteSegment;
137       double       CurrentRangeToActiveNormalCrossing;
138       RoutePoint  *pActiveRouteSegmentBeginPoint;
139       RoutePoint  *pRouteActivatePoint;
140       double       CurrentSegmentCourse;
141       int         XTEDir;
142       bool        m_bArrival;
143       wxPen       *m_pRoutePen;
144       wxPen       *m_pTrackPen;
145       wxPen       *m_pSelectedRoutePen;
146       wxPen       *m_pActiveRoutePen;
147       wxPen       *m_pActiveRoutePointPen;
148       wxPen       *m_pRoutePointPen;
149       wxBrush     *m_pRouteBrush;
150       wxBrush     *m_pSelectedRouteBrush;
151       wxBrush     *m_pActiveRouteBrush;
152       wxBrush     *m_pActiveRoutePointBrush;
153       wxBrush     *m_pRoutePointBrush;
154 
155       NMEA0183    m_NMEA0183;                         // For autopilot output
156 
157       double      m_arrival_min;
158       int         m_arrival_test;
159 
160 
161 };
162 
163 
164 //----------------------------------------------------------------------------
165 //   WayPointman
166 //----------------------------------------------------------------------------
167 
168 class WayPointman
169 {
170 public:
171       WayPointman();
172       ~WayPointman();
173       wxBitmap *GetIconBitmap(const wxString& icon_key);
174       bool GetIconPrescaled( const wxString& icon_key );
175       unsigned int GetIconTexture( const wxBitmap *pmb, int &glw, int &glh );
176       int GetIconIndex(const wxBitmap *pbm);
177       int GetIconImageListIndex(const wxBitmap *pbm);
178       int GetXIconImageListIndex(const wxBitmap *pbm);
GetNumIcons(void)179       int GetNumIcons(void){ return m_pIconArray->Count(); }
180       wxString CreateGUID(RoutePoint *pRP);
181       RoutePoint *GetNearbyWaypoint(double lat, double lon, double radius_meters);
182       RoutePoint *GetOtherNearbyWaypoint(double lat, double lon, double radius_meters, const wxString &guid);
183       void SetColorScheme(ColorScheme cs);
184       bool SharedWptsExist();
185       void DeleteAllWaypoints(bool b_delete_used);
186       RoutePoint *FindRoutePointByGUID(const wxString &guid);
187       void DestroyWaypoint(RoutePoint *pRp, bool b_update_changeset = true);
188       void ClearRoutePointFonts(void);
189       void ProcessIcons( ocpnStyle::Style* style );
190       void ProcessDefaultIcons();
191       void ReloadAllIcons();
192       void ReloadRoutepointIcons();
193 
194       bool DoesIconExist(const wxString & icon_key) const;
195       wxBitmap GetIconBitmapForList(int index, int height);
196       wxString *GetIconDescription(int index);
197       wxString *GetIconKey(int index);
198 
199       wxImageList *Getpmarkicon_image_list( int nominal_height );
200 
201       bool AddRoutePoint(RoutePoint *prp);
202       bool RemoveRoutePoint(RoutePoint *prp);
GetWaypointList(void)203       RoutePointList *GetWaypointList(void) { return m_pWayPointList; }
204 
205       MarkIcon *ProcessIcon(wxBitmap pimage, const wxString & key, const wxString & description);
206 private:
207       MarkIcon *ProcessLegacyIcon( wxString fileName, const wxString & key, const wxString & description);
208       MarkIcon *ProcessExtendedIcon(wxImage &image, const wxString & key, const wxString & description);
209       wxRect CropImageOnAlpha(wxImage &image);
210       wxImage CreateDimImage( wxImage &image, double factor );
211 
212       void ProcessUserIcons( ocpnStyle::Style* style );
213       RoutePointList    *m_pWayPointList;
214       wxBitmap *CreateDimBitmap(wxBitmap *pBitmap, double factor);
215 
216       wxImageList       *pmarkicon_image_list;        // Current wxImageList, updated on colorscheme change
217       int               m_markicon_image_list_base_count;
218       ArrayOfMarkIcon    *m_pIconArray;
219 
220       int         m_nGUID;
221       double      m_iconListScale;
222 
223       SortedArrayOfMarkIcon    *m_pLegacyIconArray;
224       SortedArrayOfMarkIcon    *m_pExtendedIconArray;
225 
226       int         m_bitmapSizeForList;
227       int         m_iconListHeight;
228       ColorScheme m_cs;
229 };
230 
231 #endif
232