OpenCPN Partial API docs
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 
40 extern std::vector<Track*> g_TrackList;
41 
42 struct SubTrack {
43  SubTrack() {}
44 
45  LLBBox m_box;
46  double m_scale;
47 };
48 
49 class TrackPoint {
50 public:
51  TrackPoint(double lat, double lon, wxString ts = "");
52  TrackPoint(double lat, double lon, wxDateTime dt);
53  TrackPoint(TrackPoint *orig);
54  ~TrackPoint();
55 
56  wxDateTime GetCreateTime(void);
57  void SetCreateTime(wxDateTime dt);
58  const char *GetTimeString() { return m_stimestring.c_str(); }
59  bool HasValidTimestamp() {
60  if (m_stimestring.size() != strlen("YYYY-MM-DDTHH:MM:SSZ"))
61  return false;
62  return true;
63  };
64 
65  double m_lat, m_lon;
66  int m_GPXTrkSegNo;
67 
68 
69 private:
70  void SetCreateTime(wxString ts);
71  std::string m_stimestring;
72 };
73 
74 //----------------------------------------------------------------------------
75 // Track
76 //----------------------------------------------------------------------------
77 
78 class Track {
79 friend class TrackGui;
80 
81 public:
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 
165 protected:
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 
178 private:
179 // void GetPointLists(ChartCanvas *cc,
180 // std::list<std::list<wxPoint> > &pointlists, ViewPort &VP,
181 // 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 &last,
190 // 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 pos);
194 //
195  wxString m_TrackNameString;
196 };
197 
198 class Route;
199 class ActiveTrack : public wxEvtHandler, public Track {
200 public:
201  ActiveTrack();
202  ~ActiveTrack();
203 
204  void SetPrecision(int precision);
205 
206  void Start(void);
207  void Stop(bool do_add_point = false);
208  Track *DoExtendDaily();
209  bool IsRunning() { return m_bRunning; }
210 
211  void AdjustCurrentTrackPoint(TrackPoint *prototype);
212 
213 private:
214  void OnTimerTrack(wxTimerEvent &event);
215  void AddPointNow(bool do_add_point = false);
216 
217  bool m_bRunning;
218  wxTimer m_TimerTrack;
219 
220  int m_nPrecision;
221  double m_TrackTimerSec;
222  double m_allowedMaxXTE;
223  double m_allowedMaxAngle;
224 
225  vector2D m_lastAddedPoint;
226  double m_prev_dist;
227  wxDateTime m_prev_time;
228 
229  TrackPoint *m_lastStoredTP;
230  TrackPoint *m_removeTP;
231  TrackPoint *m_prevFixedTP;
232  TrackPoint *m_fixedTP;
233  int m_track_run;
234  double m_minTrackpoint_delta;
235 
236  enum eTrackPointState {
237  firstPoint,
238  secondPoint,
239  potentialPoint
240  } trackPointState;
241 
242  std::deque<vector2D> skipPoints;
243  std::deque<wxDateTime> skipTimes;
244 
245  DECLARE_EVENT_TABLE()
246 };
247 
248 #endif
Definition: route.h:75
Definition: track.h:78
Definition: track.h:42