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 "model/datetime.h"
36#include "bbox.h"
37#include "hyperlink.h"
38#include "route.h"
39#include "vector2D.h"
40
41extern std::vector<Track *> g_TrackList;
42
43struct SubTrack {
44 SubTrack() {}
45
46 LLBBox m_box;
47 double m_scale;
48};
49
54public:
55 TrackPoint(double lat, double lon, wxString ts = "");
56 TrackPoint(double lat, double lon, wxDateTime dt);
59
67 wxDateTime GetCreateTime(void);
80 void SetCreateTime(wxDateTime dt);
81 const char *GetTimeString() { return m_stimestring.c_str(); }
82 bool HasValidTimestamp() {
83 if (m_stimestring.size() < strlen("YYYY-MM-DDTHH:MM:SSZ")) return false;
84 return true;
85 };
86
87 double m_lat, m_lon;
88 int m_GPXTrkSegNo;
89
90private:
104 void SetCreateTime(wxString ts);
105 std::string m_stimestring;
106};
107
111class Track {
112 friend class TrackGui;
113
114public:
115 Track();
116 virtual ~Track();
117
118 int GetnPoints(void) { return TrackPoints.size(); }
119
120 void SetVisible(bool visible = true) { m_bVisible = visible; }
121 TrackPoint *GetPoint(int nWhichPoint);
122 TrackPoint *GetLastPoint();
123 void AddPoint(TrackPoint *pNewPoint);
124 void AddPointFinalized(TrackPoint *pNewPoint);
125 TrackPoint *AddNewPoint(vector2D point, wxDateTime time);
126
127 void SetListed(bool listed = true) { m_bListed = listed; }
128 virtual bool IsRunning() { return false; }
129
130 bool IsVisible() { return m_bVisible; }
131 bool IsListed() { return m_bListed; }
132
133 int GetCurrentTrackSeg() { return m_CurrentTrackSeg; }
134 void SetCurrentTrackSeg(int seg) { m_CurrentTrackSeg = seg; }
135
136 double Length();
137 int Simplify(double maxDelta);
138 Route *RouteFromTrack(wxGenericProgressDialog *pprog);
139
140 void ClearHighlights();
141
142 /* Return the name of the track, or the start date/time of the track if no
143 * name has been set. */
144 wxString GetName(bool auto_if_empty = false) const {
145 if (!auto_if_empty || !m_TrackNameString.IsEmpty()) {
146 return m_TrackNameString;
147 } else {
148 return GetDateTime(_("(Unnamed Track)"));
149 }
150 }
151 void SetName(const wxString name) { m_TrackNameString = name; }
152
153 /* Return the start date/time of the track, formatted as ISO 8601 timestamp.
154 * The separator between date and time is a space character. */
155 wxString GetIsoDateTime(
156 const wxString label_for_invalid_date = _("(Unknown Date)")) const;
157
158 /* Return the start date/time of the track, formatted using the global
159 * timezone settings. */
160 wxString GetDateTime(
161 const wxString label_for_invalid_date = _("(Unknown Date)")) const;
162
163 wxString m_GUID;
164 bool m_bIsInLayer;
165 int m_LayerID;
166
167 wxString m_TrackDescription;
168
169 wxString m_TrackStartString;
170 wxString m_TrackEndString;
171
172 int m_width;
173 wxPenStyle m_style;
174 wxString m_Colour;
175
176 bool m_bVisible;
177 bool m_bListed;
178 bool m_btemp;
179
180 int m_CurrentTrackSeg;
181
182 HyperlinkList *m_TrackHyperlinkList;
183 int m_HighlightedTrackPoint;
184
185 void Clone(Track *psourcetrack, int start_nPoint, int end_nPoint,
186 const wxString &suffix);
187
188protected:
189 void DouglasPeuckerReducer(std::vector<TrackPoint *> &list,
190 std::vector<bool> &keeplist, int from, int to,
191 double delta);
192 double GetXTE(TrackPoint *fm1, TrackPoint *fm2, TrackPoint *to);
193 double GetXTE(double fm1Lat, double fm1Lon, double fm2Lat, double fm2Lon,
194 double toLat, double toLon);
195
196 std::vector<TrackPoint *> TrackPoints;
197 std::vector<std::vector<SubTrack> > SubTracks;
198
199private:
200 void Finalize();
201 double ComputeScale(int left, int right);
202 void InsertSubTracks(LLBBox &box, int level, int pos);
203 //
204 // void AddPointToList(ChartCanvas *cc,
205 // std::list<std::list<wxPoint> > &pointlists, int n);
206 // void AddPointToLists(ChartCanvas *cc,
207 // std::list<std::list<wxPoint> > &pointlists, int
208 // &last, int n);
209 //
210 // void Assemble(ChartCanvas *cc, std::list<std::list<wxPoint> > &pointlists,
211 // const LLBBox &box, double scale, int &last, int level, int
212 // pos);
213 //
214 wxString m_TrackNameString;
215};
216
217class Route;
221class ActiveTrack : public wxEvtHandler, public Track {
222public:
223 ActiveTrack();
224 ~ActiveTrack();
225
226 void SetPrecision(int precision);
227
228 void Start(void);
229 void Stop(bool do_add_point = false);
230 Track *DoExtendDaily();
231 bool IsRunning() { return m_bRunning; }
232
233 void AdjustCurrentTrackPoint(TrackPoint *prototype);
234
235private:
236 void OnTimerTrack(wxTimerEvent &event);
237 void AddPointNow(bool do_add_point = false);
238
239 bool m_bRunning;
240 wxTimer m_TimerTrack;
241
242 int m_nPrecision;
243 double m_TrackTimerSec;
244 double m_allowedMaxXTE;
245 double m_allowedMaxAngle;
246
247 vector2D m_lastAddedPoint;
248 double m_prev_dist;
249 wxDateTime m_prev_time;
250
251 TrackPoint *m_lastStoredTP;
252 TrackPoint *m_removeTP;
253 TrackPoint *m_prevFixedTP;
254 TrackPoint *m_fixedTP;
255 int m_track_run;
256 double m_minTrackpoint_delta;
257
258 enum eTrackPointState {
259 firstPoint,
260 secondPoint,
261 potentialPoint
262 } trackPointState;
263
264 std::deque<vector2D> skipPoints;
265 std::deque<wxDateTime> skipTimes;
266
267 DECLARE_EVENT_TABLE()
268};
269
270#endif
Represents an active track that is currently being recorded.
Definition track.h:221
Represents a navigational route in the navigation system.
Definition route.h:98
Represents a single point in a track.
Definition track.h:53
wxDateTime GetCreateTime(void)
Retrieves the creation timestamp of a track point as a wxDateTime object.
Definition track.cpp:140
void SetCreateTime(wxDateTime dt)
Sets the creation timestamp for a track point.
Definition track.cpp:146
Represents a track, which is a series of connected track points.
Definition track.h:111