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