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_HyperlinkList;
183 int m_HighlightedTrackPoint;
184
185 void Clone(Track *psourcetrack, int start_nPoint, int end_nPoint,
186 const wxString &suffix);
187
188protected:
189 // void Segments(ChartCanvas *cc, std::list<std::list<wxPoint> > &pointlists,
190 // const LLBBox &box, double scale);
191 void DouglasPeuckerReducer(std::vector<TrackPoint *> &list,
192 std::vector<bool> &keeplist, int from, int to,
193 double delta);
194 double GetXTE(TrackPoint *fm1, TrackPoint *fm2, TrackPoint *to);
195 double GetXTE(double fm1Lat, double fm1Lon, double fm2Lat, double fm2Lon,
196 double toLat, double toLon);
197
198 std::vector<TrackPoint *> TrackPoints;
199 std::vector<std::vector<SubTrack> > SubTracks;
200
201private:
202 // void GetPointLists(ChartCanvas *cc,
203 // std::list<std::list<wxPoint> > &pointlists, ViewPort
204 // &VP, const LLBBox &box);
205 void Finalize();
206 double ComputeScale(int left, int right);
207 void InsertSubTracks(LLBBox &box, int level, int pos);
208 //
209 // void AddPointToList(ChartCanvas *cc,
210 // std::list<std::list<wxPoint> > &pointlists, int n);
211 // void AddPointToLists(ChartCanvas *cc,
212 // std::list<std::list<wxPoint> > &pointlists, int
213 // &last, int n);
214 //
215 // void Assemble(ChartCanvas *cc, std::list<std::list<wxPoint> > &pointlists,
216 // const LLBBox &box, double scale, int &last, int level, int
217 // pos);
218 //
219 wxString m_TrackNameString;
220};
221
222class Route;
226class ActiveTrack : public wxEvtHandler, public Track {
227public:
228 ActiveTrack();
229 ~ActiveTrack();
230
231 void SetPrecision(int precision);
232
233 void Start(void);
234 void Stop(bool do_add_point = false);
235 Track *DoExtendDaily();
236 bool IsRunning() { return m_bRunning; }
237
238 void AdjustCurrentTrackPoint(TrackPoint *prototype);
239
240private:
241 void OnTimerTrack(wxTimerEvent &event);
242 void AddPointNow(bool do_add_point = false);
243
244 bool m_bRunning;
245 wxTimer m_TimerTrack;
246
247 int m_nPrecision;
248 double m_TrackTimerSec;
249 double m_allowedMaxXTE;
250 double m_allowedMaxAngle;
251
252 vector2D m_lastAddedPoint;
253 double m_prev_dist;
254 wxDateTime m_prev_time;
255
256 TrackPoint *m_lastStoredTP;
257 TrackPoint *m_removeTP;
258 TrackPoint *m_prevFixedTP;
259 TrackPoint *m_fixedTP;
260 int m_track_run;
261 double m_minTrackpoint_delta;
262
263 enum eTrackPointState {
264 firstPoint,
265 secondPoint,
266 potentialPoint
267 } trackPointState;
268
269 std::deque<vector2D> skipPoints;
270 std::deque<wxDateTime> skipTimes;
271
272 DECLARE_EVENT_TABLE()
273};
274
275#endif
Represents an active track that is currently being recorded.
Definition track.h:226
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:139
void SetCreateTime(wxDateTime dt)
Sets the creation timestamp for a track point.
Definition track.cpp:145
Represents a track, which is a series of connected track points.
Definition track.h:111