OpenCPN Partial API docs
Loading...
Searching...
No Matches
track.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2016 Sean D'Epagnier *
3 * Copyright (C) 2016 by David S. Register *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
25#ifndef TRACK_H_
26#define TRACK_H_
27
28#include <wx/progdlg.h>
29
30#include <deque>
31#include <list>
32#include <vector>
33
34#include "model/datetime.h"
35#include "model/route.h"
36#include "bbox.h"
37#include "hyperlink.h"
38#include "route.h"
39#include "vector2D.h"
40
41class Track; // forward
42extern std::vector<Track *> g_TrackList;
44class ActiveTrack; // forward
47class Route; // circular
48
49struct SubTrack {
50 SubTrack() {}
51
52 LLBBox m_box;
53 double m_scale;
54};
55
60public:
61 TrackPoint(double lat, double lon, wxString ts = "");
62 TrackPoint(double lat, double lon, wxDateTime dt);
65
73 wxDateTime GetCreateTime(void);
86 void SetCreateTime(wxDateTime dt);
87 const char *GetTimeString() { return m_stimestring.c_str(); }
88 bool HasValidTimestamp() {
89 if (m_stimestring.size() < strlen("YYYY-MM-DDTHH:MM:SSZ")) return false;
90 return true;
91 };
92
93 double m_lat, m_lon;
94 int m_GPXTrkSegNo;
95
96private:
110 void SetCreateTime(wxString ts);
111 std::string m_stimestring;
112};
113
117class Track {
118 friend class TrackGui;
119
120public:
121 Track();
122 virtual ~Track();
123
124 int GetnPoints(void) { return TrackPoints.size(); }
125
126 void SetVisible(bool visible = true) { m_bVisible = visible; }
127 TrackPoint *GetPoint(int nWhichPoint);
128 TrackPoint *GetLastPoint();
129 void AddPoint(TrackPoint *pNewPoint);
130 void AddPointFinalized(TrackPoint *pNewPoint);
131 TrackPoint *AddNewPoint(vector2D point, wxDateTime time);
132
133 void SetListed(bool listed = true) { m_bListed = listed; }
134 virtual bool IsRunning() { return false; }
135
136 bool IsVisible() { return m_bVisible; }
137 bool IsListed() { return m_bListed; }
138
139 int GetCurrentTrackSeg() { return m_CurrentTrackSeg; }
140 void SetCurrentTrackSeg(int seg) { m_CurrentTrackSeg = seg; }
141
142 double Length();
143 int Simplify(double maxDelta);
144 Route *RouteFromTrack(wxGenericProgressDialog *pprog);
145
146 void ClearHighlights();
147
148 /* Return the name of the track, or the start date/time of the track if no
149 * name has been set. */
150 wxString GetName(bool auto_if_empty = false) const {
151 if (!auto_if_empty || !m_TrackNameString.IsEmpty()) {
152 return m_TrackNameString;
153 } else {
154 return GetDateTime(_("(Unnamed Track)"));
155 }
156 }
157 void SetName(const wxString name) { m_TrackNameString = name; }
158
159 /* Return the start date/time of the track, formatted as ISO 8601 timestamp.
160 * The separator between date and time is a space character. */
161 wxString GetIsoDateTime(
162 const wxString label_for_invalid_date = _("(Unknown Date)")) const;
163
164 /* Return the start date/time of the track, formatted using the global
165 * timezone settings. */
166 wxString GetDateTime(
167 const wxString label_for_invalid_date = _("(Unknown Date)")) const;
168
169 wxString m_GUID;
170 bool m_bIsInLayer;
171 int m_LayerID;
172
173 wxString m_TrackDescription;
174
175 wxString m_TrackStartString;
176 wxString m_TrackEndString;
177
178 int m_width;
179 wxPenStyle m_style;
180 wxString m_Colour;
181
182 bool m_bVisible;
183 bool m_bListed;
184 bool m_btemp;
185
186 int m_CurrentTrackSeg;
187
188 HyperlinkList *m_TrackHyperlinkList;
189 int m_HighlightedTrackPoint;
190
191 void Clone(Track *psourcetrack, int start_nPoint, int end_nPoint,
192 const wxString &suffix);
193
194protected:
195 void DouglasPeuckerReducer(std::vector<TrackPoint *> &list,
196 std::vector<bool> &keeplist, int from, int to,
197 double delta);
198 double GetXTE(TrackPoint *fm1, TrackPoint *fm2, TrackPoint *to);
199 double GetXTE(double fm1Lat, double fm1Lon, double fm2Lat, double fm2Lon,
200 double toLat, double toLon);
201
202 std::vector<TrackPoint *> TrackPoints;
203 std::vector<std::vector<SubTrack> > SubTracks;
204
205private:
206 void Finalize();
207 double ComputeScale(int left, int right);
208 void InsertSubTracks(LLBBox &box, int level, int pos);
209 //
210 // void AddPointToList(ChartCanvas *cc,
211 // std::list<std::list<wxPoint> > &pointlists, int n);
212 // void AddPointToLists(ChartCanvas *cc,
213 // std::list<std::list<wxPoint> > &pointlists, int
214 // &last, int n);
215 //
216 // void Assemble(ChartCanvas *cc, std::list<std::list<wxPoint> > &pointlists,
217 // const LLBBox &box, double scale, int &last, int level, int
218 // pos);
219 //
220 wxString m_TrackNameString;
221};
222
223class Route;
227class ActiveTrack : public wxEvtHandler, public Track {
228public:
229 ActiveTrack();
230 ~ActiveTrack();
231
232 void SetPrecision(int precision);
233
234 void Start(void);
235 void Stop(bool do_add_point = false);
236 Track *DoExtendDaily();
237 bool IsRunning() { return m_bRunning; }
238
239 void AdjustCurrentTrackPoint(TrackPoint *prototype);
240
241private:
242 void OnTimerTrack(wxTimerEvent &event);
243 void AddPointNow(bool do_add_point = false);
244
245 bool m_bRunning;
246 wxTimer m_TimerTrack;
247
248 int m_nPrecision;
249 double m_TrackTimerSec;
250 double m_allowedMaxXTE;
251 double m_allowedMaxAngle;
252
253 vector2D m_lastAddedPoint;
254 double m_prev_dist;
255 wxDateTime m_prev_time;
256
257 TrackPoint *m_lastStoredTP;
258 TrackPoint *m_removeTP;
259 TrackPoint *m_prevFixedTP;
260 TrackPoint *m_fixedTP;
261 int m_track_run;
262 double m_minTrackpoint_delta;
263
264 enum eTrackPointState {
265 firstPoint,
266 secondPoint,
267 potentialPoint
268 } trackPointState;
269
270 std::deque<vector2D> skipPoints;
271 std::deque<wxDateTime> skipTimes;
272
273 DECLARE_EVENT_TABLE()
274};
275
276#endif
Represents an active track that is currently being recorded.
Definition track.h:227
Represents a navigational route in the navigation system.
Definition route.h:99
Represents a single point in a track.
Definition track.h:59
wxDateTime GetCreateTime(void)
Retrieves the creation timestamp of a track point as a wxDateTime object.
Definition track.cpp:138
void SetCreateTime(wxDateTime dt)
Sets the creation timestamp for a track point.
Definition track.cpp:144
Represents a track, which is a series of connected track points.
Definition track.h:117
Date and time utilities.
Route abstraction.
ActiveTrack * g_pActiveTrack
global instance
Definition track.cpp:99
std::vector< Track * > g_TrackList
Global instance.
Definition track.cpp:96