1 /***************************************************************************
2  *
3  * Project:  OpenCPN
4  *
5  ***************************************************************************
6  *   Copyright (C) 2013 by David S. Register                               *
7  *                                                                         *
8  *   This program is free software; you can redistribute it and/or modify  *
9  *   it under the terms of the GNU General Public License as published by  *
10  *   the Free Software Foundation; either version 2 of the License, or     *
11  *   (at your option) any later version.                                   *
12  *                                                                         *
13  *   This program is distributed in the hope that it will be useful,       *
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16  *   GNU General Public License for more details.                          *
17  *                                                                         *
18  *   You should have received a copy of the GNU General Public License     *
19  *   along with this program; if not, write to the                         *
20  *   Free Software Foundation, Inc.,                                       *
21  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,  USA.         *
22  **************************************************************************/
23 
24 #ifndef __ROUTE_H__
25 #define __ROUTE_H__
26 
27 #include <wx/object.h>
28 #include <wx/list.h>
29 #include "wx28compat.h"
30 
31 #include "viewport.h"
32 #include "RoutePoint.h"
33 
34 #define WIDTH_UNDEFINED -1
35 
36 #define ROUTE_DEFAULT_SPEED 5.0
37 #define RTE_TIME_DISP_UTC _T("UTC")
38 #define RTE_TIME_DISP_PC _T("PC")
39 #define RTE_TIME_DISP_LOCAL _T("LOCAL")
40 #define RTE_UNDEF_DEPARTURE wxInvalidDateTime
41 
42 const wxString GpxxColorNames[] = { _T("Black"), _T("DarkRed"), _T("DarkGreen"), _T("DarkYellow"), _T("DarkBlue"), _T("DarkMagenta"), _T("DarkCyan"), _T("LightGray"), _T("DarkGray"), _T("Red"), _T("Green"), _T  ("Yellow"), _T("Blue"), _T("Magenta"), _T("Cyan"), _T("White") };//The last color defined by Garmin is transparent - we ignore it
43 const wxColour GpxxColors[] = { wxColour(0x00, 0x00, 0x00), wxColour(0x60, 0x00, 0x00), wxColour(0x00, 0x60, 0x00), wxColour(0x80, 0x80, 0x00), wxColour(0x00, 0x00, 0x60), wxColour(0x60, 0x00, 0x60), wxColour(  0x00, 0x80, 0x80), wxColour(0xC0, 0xC0, 0xC0), wxColour(0x60, 0x60, 0x60), wxColour(0xFF, 0x00, 0x00), wxColour(0x00, 0xFF, 0x00), wxColour(0xF0, 0xF0, 0x00), wxColour(0x00, 0x00, 0xFF), wxColour(0xFE, 0x00, 0xFE), wxColour(0x00, 0xFF, 0xFF), wxColour(0xFF, 0xFF, 0xFF) };
44 const int StyleValues[] = { -1, wxSOLID, wxDOT, wxLONG_DASH, wxSHORT_DASH, wxDOT_DASH };
45 const int WidthValues[] = { -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
46 
47 class ocpnDC;
48 class ChartCanvas;
49 class HyperlinkList;
50 
51 class Route : public wxObject
52 {
53 public:
54       Route();
55       ~Route();
56 
57       virtual void Draw(ocpnDC& dc, ChartCanvas *canvas, const LLBBox &box);
GetnPoints(void)58       virtual int GetnPoints(void) { return pRoutePointList->GetCount(); }
59 
60       void AddPoint(RoutePoint *pNewPoint,
61                     bool b_rename_in_sequence = true,
62                     bool b_deferBoxCalc = false);
63 
64       RoutePoint *GetPoint(int nPoint);
65       RoutePoint *GetPoint ( const wxString &guid );
66       int GetIndexOf(RoutePoint *prp);
67       RoutePoint *InsertPointBefore(RoutePoint *pRP, double rlat, double rlon, bool bRenamePoints = false);
68       RoutePoint *InsertPointAfter(RoutePoint *pRP, double rlat, double rlon, bool bRenamePoints = false);
69 
70       void DrawPointWhich(ocpnDC& dc, ChartCanvas *canvas, int iPoint, wxPoint *rpn);
71       void DrawSegment(ocpnDC& dc, ChartCanvas *canvas, wxPoint *rp1, wxPoint *rp2, ViewPort &vp, bool bdraw_arrow);
72 
73       void DrawGLLines( ViewPort &vp, ocpnDC *dc, ChartCanvas *canvas );
74       void DrawGL( ViewPort &vp, ChartCanvas *canvas );
75       void DrawGLRouteLines( ViewPort &vp, ChartCanvas *canvas );
76 
77       RoutePoint *GetLastPoint();
78       void DeletePoint(RoutePoint *rp, bool bRenamePoints = false);
79       void RemovePoint(RoutePoint *rp, bool bRenamePoints = false);
80       void DeSelectRoute();
81       void FinalizeForRendering();
82       void UpdateSegmentDistance( RoutePoint *prp0, RoutePoint *prp, double planspeed = -1.0 );
83       void UpdateSegmentDistances(double planspeed = -1.0);
84       void CalculateDCRect(wxDC& dc_route, ChartCanvas *canvas, wxRect *prect);
85       LLBBox &GetBBox();
SetHiLite(int width)86       void SetHiLite( int width ) {m_hiliteWidth = width; }
87       void Reverse(bool bRenamePoints = false);
88       void RebuildGUIDList(void);
89       void RenameRoutePoints();
90       void ReloadRoutePointIcons();
91       wxString GetNewMarkSequenced(void);
92       void AssembleRoute();
93       bool IsEqualTo(Route *ptargetroute);
94       void CloneRoute(Route *psourceroute, int start_nPoint, int end_nPoint, const wxString & suffix, const bool duplicate_first_point = false);
95       void ClearHighlights(void);
96       void RenderSegment(ocpnDC& dc, int xa, int ya, int xb, int yb, ViewPort &vp, bool bdraw_arrow, int hilite_width = 0);
97       void RenderSegmentArrowsGL( ocpnDC &dc, int xa, int ya, int xb, int yb, ViewPort &vp);
98 
99       void SetVisible(bool visible = true, bool includeWpts = true);
100       void SetListed(bool visible = true);
IsVisible()101       bool IsVisible() { return m_bVisible; }
IsListed()102       bool IsListed() { return m_bListed; }
IsActive()103       bool IsActive() { return m_bRtIsActive; }
IsSelected()104       bool IsSelected() { return m_bRtIsSelected; }
105 
106       bool ContainsSharedWP();
SetSharedWPViz(bool sharedWPVIZ)107       void SetSharedWPViz( bool sharedWPVIZ){ m_bsharedWPViz = sharedWPVIZ; }
GetSharedWPViz()108       bool GetSharedWPViz(){ return m_bsharedWPViz; }
109 
110       int SendToGPS(const wxString & com_name, bool bsend_waypoints, wxGauge *pProgress);
111 
GetRouteArrivalRadius(void)112       double GetRouteArrivalRadius(void){ return m_ArrivalRadius;}
SetRouteArrivalRadius(double radius)113       void SetRouteArrivalRadius(double radius){m_ArrivalRadius = radius;}
SetDepartureDate(const wxDateTime & dt)114       void SetDepartureDate(const wxDateTime &dt) { if( dt.IsValid() ) m_PlannedDeparture = dt; }
115 
GetName()116       wxString GetName() const { return m_RouteNameString; }
GetTo()117       wxString GetTo() const { return m_RouteEndString; }
GetGUID()118       wxString GetGUID() const { return m_GUID; }
119 
120       int         m_ConfigRouteNum;
121       bool        m_bRtIsSelected;
122       bool        m_bRtIsActive;
123       RoutePoint  *m_pRouteActivePoint;
124       bool        m_bIsBeingCreated;
125       bool        m_bIsBeingEdited;
126       double      m_route_length;
127       double      m_route_time;
128       wxString    m_RouteNameString;
129       wxString    m_RouteStartString;
130       wxString    m_RouteEndString;
131       wxString    m_RouteDescription;
132       bool        m_bDeleteOnArrival;
133       wxString    m_GUID;
134       bool        m_bIsInLayer;
135       int         m_LayerID;
136       int         m_width;
137       wxPenStyle  m_style;
138       int         m_lastMousePointIndex;
139       bool        m_NextLegGreatCircle;
140       double      m_PlannedSpeed;
141       wxDateTime  m_PlannedDeparture;
142       wxString    m_TimeDisplayFormat;
143 
144       RoutePointList     *pRoutePointList;
145 
146       wxRect      active_pt_rect;
147       wxString    m_Colour;
148       bool        m_btemp;
149       int         m_hiliteWidth;
150       HyperlinkList *m_HyperlinkList;
151 
152 private:
153       LLBBox     RBBox;
154 
155       int         m_nm_sequence;
156       bool        m_bVisible; // should this route be drawn?
157       bool        m_bListed;
158       double      m_ArrivalRadius;
159       bool        m_bsharedWPViz;
160 };
161 
162 WX_DECLARE_LIST(Route, RouteList); // establish class Route as list member
163 
164 #endif
165