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 "hyperlink.h"
37#include "route.h"
38#include "vector2D.h"
39
40extern std::vector<Track *> g_TrackList;
41
42struct SubTrack {
43 SubTrack() {}
44
45 LLBBox m_box;
46 double m_scale;
47};
48
53public:
54 TrackPoint(double lat, double lon, wxString ts = "");
55 TrackPoint(double lat, double lon, wxDateTime dt);
58
59 wxDateTime GetCreateTime(void);
60 void SetCreateTime(wxDateTime dt);
61 const char *GetTimeString() { return m_stimestring.c_str(); }
62 bool HasValidTimestamp() {
63 if (m_stimestring.size() < strlen("YYYY-MM-DDTHH:MM:SSZ")) return false;
64 return true;
65 };
66
67 double m_lat, m_lon;
68 int m_GPXTrkSegNo;
69
70private:
71 void SetCreateTime(wxString ts);
72 std::string m_stimestring;
73};
74
78class Track {
79 friend class TrackGui;
80
81public:
82 Track();
83 virtual ~Track();
84
85 int GetnPoints(void) { return TrackPoints.size(); }
86
87 void SetVisible(bool visible = true) { m_bVisible = visible; }
88 TrackPoint *GetPoint(int nWhichPoint);
89 TrackPoint *GetLastPoint();
90 void AddPoint(TrackPoint *pNewPoint);
91 void AddPointFinalized(TrackPoint *pNewPoint);
92 TrackPoint *AddNewPoint(vector2D point, wxDateTime time);
93
94 void SetListed(bool listed = true) { m_bListed = listed; }
95 virtual bool IsRunning() { return false; }
96
97 bool IsVisible() { return m_bVisible; }
98 bool IsListed() { return m_bListed; }
99
100 int GetCurrentTrackSeg() { return m_CurrentTrackSeg; }
101 void SetCurrentTrackSeg(int seg) { m_CurrentTrackSeg = seg; }
102
103 double Length();
104 int Simplify(double maxDelta);
105 Route *RouteFromTrack(wxGenericProgressDialog *pprog);
106
107 void ClearHighlights();
108
109 wxString GetName(bool auto_if_empty = false) const {
110 if (!auto_if_empty || !m_TrackNameString.IsEmpty()) {
111 return m_TrackNameString;
112 } else {
113 wxString name;
114 TrackPoint *rp = NULL;
115 if ((int)TrackPoints.size() > 0) rp = TrackPoints[0];
116 if (rp && rp->GetCreateTime().IsValid())
117 name = rp->GetCreateTime().FormatISODate() + _T(" ") +
118 rp->GetCreateTime()
119 .FormatISOTime(); // name = rp->m_CreateTime.Format();
120 else
121 name = _("(Unnamed Track)");
122 return name;
123 }
124 }
125 void SetName(const wxString name) { m_TrackNameString = name; }
126
127 wxString GetDate(bool auto_if_empty = false) const {
128 wxString name;
129 TrackPoint *rp = NULL;
130 if ((int)TrackPoints.size() > 0) rp = TrackPoints[0];
131 if (rp && rp->GetCreateTime().IsValid())
132 name = rp->GetCreateTime().FormatISODate() + _T(" ") +
133 rp->GetCreateTime()
134 .FormatISOTime(); // name = rp->m_CreateTime.Format();
135 else
136 name = _("(Unknown Date)");
137 return name;
138 }
139
140 wxString m_GUID;
141 bool m_bIsInLayer;
142 int m_LayerID;
143
144 wxString m_TrackDescription;
145
146 wxString m_TrackStartString;
147 wxString m_TrackEndString;
148
149 int m_width;
150 wxPenStyle m_style;
151 wxString m_Colour;
152
153 bool m_bVisible;
154 bool m_bListed;
155 bool m_btemp;
156
157 int m_CurrentTrackSeg;
158
159 HyperlinkList *m_HyperlinkList;
160 int m_HighlightedTrackPoint;
161
162 void Clone(Track *psourcetrack, int start_nPoint, int end_nPoint,
163 const wxString &suffix);
164
165protected:
166 // void Segments(ChartCanvas *cc, std::list<std::list<wxPoint> > &pointlists,
167 // const LLBBox &box, double scale);
168 void DouglasPeuckerReducer(std::vector<TrackPoint *> &list,
169 std::vector<bool> &keeplist, int from, int to,
170 double delta);
171 double GetXTE(TrackPoint *fm1, TrackPoint *fm2, TrackPoint *to);
172 double GetXTE(double fm1Lat, double fm1Lon, double fm2Lat, double fm2Lon,
173 double toLat, double toLon);
174
175 std::vector<TrackPoint *> TrackPoints;
176 std::vector<std::vector<SubTrack> > SubTracks;
177
178private:
179 // void GetPointLists(ChartCanvas *cc,
180 // std::list<std::list<wxPoint> > &pointlists, ViewPort
181 // &VP, const LLBBox &box);
182 void Finalize();
183 double ComputeScale(int left, int right);
184 void InsertSubTracks(LLBBox &box, int level, int pos);
185 //
186 // void AddPointToList(ChartCanvas *cc,
187 // std::list<std::list<wxPoint> > &pointlists, int n);
188 // void AddPointToLists(ChartCanvas *cc,
189 // std::list<std::list<wxPoint> > &pointlists, int
190 // &last, int n);
191 //
192 // void Assemble(ChartCanvas *cc, std::list<std::list<wxPoint> > &pointlists,
193 // const LLBBox &box, double scale, int &last, int level, int
194 // pos);
195 //
196 wxString m_TrackNameString;
197};
198
199class Route;
203class ActiveTrack : public wxEvtHandler, public Track {
204public:
205 ActiveTrack();
206 ~ActiveTrack();
207
208 void SetPrecision(int precision);
209
210 void Start(void);
211 void Stop(bool do_add_point = false);
212 Track *DoExtendDaily();
213 bool IsRunning() { return m_bRunning; }
214
215 void AdjustCurrentTrackPoint(TrackPoint *prototype);
216
217private:
218 void OnTimerTrack(wxTimerEvent &event);
219 void AddPointNow(bool do_add_point = false);
220
221 bool m_bRunning;
222 wxTimer m_TimerTrack;
223
224 int m_nPrecision;
225 double m_TrackTimerSec;
226 double m_allowedMaxXTE;
227 double m_allowedMaxAngle;
228
229 vector2D m_lastAddedPoint;
230 double m_prev_dist;
231 wxDateTime m_prev_time;
232
233 TrackPoint *m_lastStoredTP;
234 TrackPoint *m_removeTP;
235 TrackPoint *m_prevFixedTP;
236 TrackPoint *m_fixedTP;
237 int m_track_run;
238 double m_minTrackpoint_delta;
239
240 enum eTrackPointState {
241 firstPoint,
242 secondPoint,
243 potentialPoint
244 } trackPointState;
245
246 std::deque<vector2D> skipPoints;
247 std::deque<wxDateTime> skipTimes;
248
249 DECLARE_EVENT_TABLE()
250};
251
252#endif
Represents an active track that is currently being recorded.
Definition track.h:203
Definition route.h:75
Represents a single point in a track.
Definition track.h:52
Represents a track, which is a series of connected track points.
Definition track.h:78