OpenCPN Partial API docs
Loading...
Searching...
No Matches
track.h
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: Navigation Utility Functions
5 * Authors: David Register
6 * Sean D'Epagnier
7 *
8 ***************************************************************************
9 * Copyright (C) 2016 by David S. Register *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25 **************************************************************************/
26#ifndef _TRACK_H__
27#define _TRACK_H__
28
29#include <wx/progdlg.h>
30
31#include <deque>
32#include <list>
33#include <vector>
34
35#include "bbox.h"
36#include "route.h"
37#include "vector2D.h"
38
39class HyperlinkList;
40class ChartCanvas;
41class ViewPort;
42
43struct SubTrack {
44 SubTrack() {}
45
46 LLBBox m_box;
47 double m_scale;
48};
49
51public:
52 TrackPoint(double lat, double lon, wxString ts = "");
53 TrackPoint(double lat, double lon, wxDateTime dt);
56
57 wxDateTime GetCreateTime(void);
58 void SetCreateTime(wxDateTime dt);
59 const char *GetTimeString() { return m_stimestring.c_str(); }
60 bool HasValidTimestamp() {
61 if (m_stimestring.size() != strlen("YYYY-MM-DDTHH:MM:SSZ"))
62 return false;
63 return true;
64 };
65
66 double m_lat, m_lon;
67 int m_GPXTrkSegNo;
68
69
70private:
71 void SetCreateTime(wxString ts);
72 std::string m_stimestring;
73};
74
75//----------------------------------------------------------------------------
76// Track
77//----------------------------------------------------------------------------
78
79class Track {
80friend class TrackGui;
81
82public:
83 Track();
84 virtual ~Track();
85
86 int GetnPoints(void) { return TrackPoints.size(); }
87
88 void SetVisible(bool visible = true) { m_bVisible = visible; }
89 TrackPoint *GetPoint(int nWhichPoint);
90 TrackPoint *GetLastPoint();
91 void AddPoint(TrackPoint *pNewPoint);
92 void AddPointFinalized(TrackPoint *pNewPoint);
93 TrackPoint *AddNewPoint(vector2D point, wxDateTime time);
94
95 void SetListed(bool listed = true) { m_bListed = listed; }
96 virtual bool IsRunning() { return false; }
97
98 bool IsVisible() { return m_bVisible; }
99 bool IsListed() { return m_bListed; }
100
101 int GetCurrentTrackSeg() { return m_CurrentTrackSeg; }
102 void SetCurrentTrackSeg(int seg) { m_CurrentTrackSeg = seg; }
103
104 double Length();
105 int Simplify(double maxDelta);
106 Route *RouteFromTrack(wxGenericProgressDialog *pprog);
107
108 void ClearHighlights();
109
110 wxString GetName(bool auto_if_empty = false) const {
111 if (!auto_if_empty || !m_TrackNameString.IsEmpty()) {
112 return m_TrackNameString;
113 } else {
114 wxString name;
115 TrackPoint *rp = NULL;
116 if ((int)TrackPoints.size() > 0) rp = TrackPoints[0];
117 if (rp && rp->GetCreateTime().IsValid())
118 name = rp->GetCreateTime().FormatISODate() + _T(" ") +
119 rp->GetCreateTime()
120 .FormatISOTime(); // name = rp->m_CreateTime.Format();
121 else
122 name = _("(Unnamed Track)");
123 return name;
124 }
125 }
126 void SetName(const wxString name) { m_TrackNameString = name; }
127
128 wxString m_GUID;
129 bool m_bIsInLayer;
130 int m_LayerID;
131
132 wxString m_TrackDescription;
133
134 wxString m_TrackStartString;
135 wxString m_TrackEndString;
136
137 int m_width;
138 wxPenStyle m_style;
139 wxString m_Colour;
140
141 bool m_bVisible;
142 bool m_bListed;
143 bool m_btemp;
144
145 int m_CurrentTrackSeg;
146
147 HyperlinkList *m_HyperlinkList;
148 int m_HighlightedTrackPoint;
149
150 void Clone(Track *psourcetrack, int start_nPoint, int end_nPoint,
151 const wxString &suffix);
152
153protected:
154// void Segments(ChartCanvas *cc, std::list<std::list<wxPoint> > &pointlists,
155// const LLBBox &box, double scale);
156 void DouglasPeuckerReducer(std::vector<TrackPoint *> &list,
157 std::vector<bool> &keeplist, int from, int to,
158 double delta);
159 double GetXTE(TrackPoint *fm1, TrackPoint *fm2, TrackPoint *to);
160 double GetXTE(double fm1Lat, double fm1Lon, double fm2Lat, double fm2Lon,
161 double toLat, double toLon);
162
163 std::vector<TrackPoint *> TrackPoints;
164 std::vector<std::vector<SubTrack> > SubTracks;
165
166private:
167// void GetPointLists(ChartCanvas *cc,
168// std::list<std::list<wxPoint> > &pointlists, ViewPort &VP,
169// const LLBBox &box);
170 void Finalize();
171 double ComputeScale(int left, int right);
172 void InsertSubTracks(LLBBox &box, int level, int pos);
173//
174// void AddPointToList(ChartCanvas *cc,
175// std::list<std::list<wxPoint> > &pointlists, int n);
176// void AddPointToLists(ChartCanvas *cc,
177// std::list<std::list<wxPoint> > &pointlists, int &last,
178// int n);
179//
180// void Assemble(ChartCanvas *cc, std::list<std::list<wxPoint> > &pointlists,
181// const LLBBox &box, double scale, int &last, int level, int pos);
182//
183 wxString m_TrackNameString;
184};
185
186class Route;
187class ActiveTrack : public wxEvtHandler, public Track {
188public:
189 ActiveTrack();
190 ~ActiveTrack();
191
192 void SetPrecision(int precision);
193
194 void Start(void);
195 void Stop(bool do_add_point = false);
196 Track *DoExtendDaily();
197 bool IsRunning() { return m_bRunning; }
198
199 void AdjustCurrentTrackPoint(TrackPoint *prototype);
200
201private:
202 void OnTimerTrack(wxTimerEvent &event);
203 void AddPointNow(bool do_add_point = false);
204
205 bool m_bRunning;
206 wxTimer m_TimerTrack;
207
208 int m_nPrecision;
209 double m_TrackTimerSec;
210 double m_allowedMaxXTE;
211 double m_allowedMaxAngle;
212
213 vector2D m_lastAddedPoint;
214 double m_prev_dist;
215 wxDateTime m_prev_time;
216
217 TrackPoint *m_lastStoredTP;
218 TrackPoint *m_removeTP;
219 TrackPoint *m_prevFixedTP;
220 TrackPoint *m_fixedTP;
221 int m_track_run;
222 double m_minTrackpoint_delta;
223
224 enum eTrackPointState {
225 firstPoint,
226 secondPoint,
227 potentialPoint
228 } trackPointState;
229
230 std::deque<vector2D> skipPoints;
231 std::deque<wxDateTime> skipTimes;
232
233 DECLARE_EVENT_TABLE()
234};
235
236#endif
Definition: route.h:70
Definition: track.h:79
Definition: track.h:43