private void tsbScreenshot_Click(object sender, EventArgs e) { /*SaveFileDialog ofd = new SaveFileDialog(); * // ofd.Title = * // ofd.InitialDirectory = * ofd.Filter = ConstructImageFilter(); * ofd.FilterIndex = 1; * ofd.AddExtension = true; * ofd.RestoreDirectory = true; * * if (ofd.ShowDialog() == DialogResult.OK) * { * using (Bitmap bmp = mapView.RenderToBitmap()) * { * bmp.Save(ofd.FileName); * } * }*/ distancia = distancia + 100; TrackActivity track = GetSelectedTrack(); secuencia = GetIndexDistance(track, distancia, secuencia); UpdateInfoBox(secuencia, 0); mapChart.SetIndexes(secuencia, 0); mapView.SetIndices(secuencia, 0); }
private static void PostProcessActivityData(TrackActivity activity) { int lapIndex = 0; int pointIndex = 0; TimeSpan totalTime = TimeSpan.Zero; double totalDist = 0; TrackPoint firstPoint = FindFirstPoint(activity); if (firstPoint == null) { return; } foreach (TrackLap lap in activity.Laps) { lap.Index = lapIndex++; lap.FirstPointIndex = pointIndex; lap.LastPointIndex = pointIndex + lap.Points.Count - 1; PostProcessPointIndex(lap, ref pointIndex); PostProcessPointTimeDelta(lap, firstPoint.Time); PostProcessLapData(lap); totalTime += lap.TotalTime; totalDist += lap.TotalDistance; } activity.StartTime = firstPoint.Time; activity.TotalTime = totalTime; activity.TotalDistance = totalDist; }
private static TrackActivity ConvertTrack(GpxTrack gpxTrack) { TrackActivity track = new TrackActivity(); track.Laps = new List <TrackLap>(); track.Waypoints = new List <TrackWaypoint>(); track.Name = gpxTrack.Name; track.Description = gpxTrack.Description; foreach (GpxTrackSegment segment in gpxTrack.TrackSegments) { TrackLap lap = new TrackLap(); lap.Points = new List <TrackPoint>(); foreach (GpxTrackPoint gpxPt in segment.TrackPoints) { TrackPoint pt = new TrackPoint(); pt.Latitude = (float)gpxPt.Lat; pt.Longitude = (float)gpxPt.Lon; pt.Altitude = (float)gpxPt.Elevation; pt.Time = gpxPt.Time; lap.Points.Add(pt); } track.Laps.Add(lap); } return(track); }
private void UpdateMapChart() { TrackActivity track = GetSelectedTrack(); if (track == null) { return; } mapChart.ClearMarkers(); List <PointF> chartPts = new List <PointF>(); foreach (TrackLap lap in track.Laps) { foreach (TrackPoint pt in lap.Points) { chartPts.Add(ChartPointFromTrackPoint(pt)); } if (lap.Points.Count > 0) { string text = String.Format(CultureInfo.CurrentCulture, "Lap {0}", lap.Index); mapChart.AddMarker(ChartPointFromTrackPoint(lap.Points[0]).X, text); } } mapChart.SetPoints(chartPts.ToArray()); }
private void UpdateInfoBox(int selIndex, int ctrlIndex) { TrackActivity track = GetSelectedTrack(); if (track != null) { TrackPoint selPoint = GetPointFromIndex(track, selIndex); TrackPoint ctrlPoint = GetPointFromIndex(track, ctrlIndex); if (selPoint != null && ctrlPoint != null) { float dist = Math.Abs(selPoint.Distance - ctrlPoint.Distance); float acc_asc = Math.Abs(selPoint.AccAsc - ctrlPoint.AccAsc); float acc_desc = Math.Abs(selPoint.AccDesc - ctrlPoint.AccDesc); TimeSpan time = (selPoint.Time - ctrlPoint.Time).Duration(); labelTime.Text = time.ToString(); labelDist.Text = Units.Provider.DistanceString(dist); labelAlti.Text = Units.Provider.HeightString(selPoint.Altitude); labelAccAsc.Text = Units.Provider.HeightString(acc_asc); labelAccDesc.Text = Units.Provider.HeightString(acc_desc); labelSpeedAvg.Text = Units.Provider.SpeedString(time, dist); labelSpeedCurr.Text = Units.Provider.SpeedString(selPoint.Speed); } else { ClearInfoBox(); } } }
private static TrackActivity ConvertCourse(TcxCourse tcxCourse) { TrackActivity track = new TrackActivity(); track.Laps = new List <TrackLap>(); track.Waypoints = new List <TrackWaypoint>(); track.Name = tcxCourse.Name; TrackLap lap = new TrackLap(); lap.Points = new List <TrackPoint>(); if (tcxCourse.CoursePoints != null) { foreach (TcxCoursePoint tcxCoursePoint in tcxCourse.CoursePoints) { track.Waypoints.Add(ConvertWaypoint(tcxCoursePoint)); } } if (tcxCourse.TrackpointList != null && tcxCourse.TrackpointList.Trackpoints != null) { foreach (TcxTrackPoint tcxPt in tcxCourse.TrackpointList.Trackpoints) { TrackPoint pt = ConvertTrackPoint(tcxPt); lap.Points.Add(pt); } } track.Laps.Add(lap); return(track); }
private static TrackPoint FindFirstPoint(TrackActivity activity) { foreach (TrackLap lap in activity.Laps) { foreach (TrackPoint point in lap.Points) { return(point); } } return(null); }
private static TrackPoint GetPointFromIndex(TrackActivity track, int index) { foreach (TrackLap lap in track.Laps) { if (index >= lap.FirstPointIndex && index <= lap.LastPointIndex) { return(lap.Points[index - lap.FirstPointIndex]); } } return(null); }
private void SetMapViewMarkers(TrackActivity track) { mapView.ClearMarkers(); foreach (TrackLap lap in track.Laps) { if (lap.Points.Count > 0) { string text = String.Format(CultureInfo.CurrentCulture, "Lap {0}", lap.Index); mapView.AddMarker(lap.Points[0].Index, text); } } }
private void SetMapViewTrackPoints(TrackActivity track) { List <PointF> points = new List <PointF>(); foreach (TrackLap lap in track.Laps) { foreach (TrackPoint pt in lap.Points) { points.Add(new PointF(pt.Longitude, pt.Latitude)); } } mapView.SetPoints(points.ToArray()); }
private void UpdateMapView() { TrackActivity track = GetSelectedTrack(); if (track == null) { return; } SetMapViewTrackPoints(track); SetMapViewWaypoints(track); SetMapViewMarkers(track); mapView.ResetView(); }
private static int GetIndexDistance(TrackActivity track, double meter, int index) { foreach (TrackLap lap in track.Laps) { if (index >= lap.FirstPointIndex && index <= lap.LastPointIndex) { for (int i = index; i < lap.LastPointIndex; i++) { if (lap.Points[i].Distance >= meter) { return(i); } } } } return(0); }
/// <summary> /// Reads the file and return the contained activities. /// </summary> /// <param name="fileName">Name of the file.</param> /// <returns></returns> public ICollection <TrackActivity> ReadFile(string fileName) { List <TrackActivity> activities = new List <TrackActivity>(); GpxTree tree = ParseFile(fileName); if (tree == null) { return(activities); } if (tree.Tracks != null) { foreach (GpxTrack gpxTrack in tree.Tracks) { TrackActivity track = ConvertTrack(gpxTrack); track.FileName = fileName; activities.Add(track); } } if (tree.Waypoints != null) { TrackActivity activity = new TrackActivity(); activity.FileName = fileName; activity.Laps = new List <TrackLap>(); activity.Waypoints = new List <TrackWaypoint>(); foreach (GpxWaypoint gpxWaypoint in tree.Waypoints) { activity.Waypoints.Add(ConvertWaypoint(gpxWaypoint)); } activities.Add(activity); } return(activities); }
/// <summary> /// Reads the file and return the contained activities. /// </summary> /// <param name="fileName">Name of the file.</param> /// <returns></returns> public ICollection <TrackActivity> ReadFile(string fileName) { List <TrackActivity> activities = new List <TrackActivity>(); TcxTree tree = ParseFile(fileName); if (tree == null) { return(activities); } if (tree.CourseList != null && tree.CourseList.Courses != null) { foreach (TcxCourse tcxCourse in tree.CourseList.Courses) { TrackActivity track = ConvertCourse(tcxCourse); track.FileName = fileName; activities.Add(track); } } if (tree.ActivityList != null && tree.ActivityList.Activities != null) { foreach (TcxActivity tcxActivity in tree.ActivityList.Activities) { TrackActivity track = ConvertActivity(tcxActivity); track.FileName = fileName; activities.Add(track); } } return(activities); }
private void SetMapViewWaypoints(TrackActivity track) { mapView.ClearWaypoints(); foreach (TrackWaypoint pt in track.Waypoints) { string text = pt.Name; if (!String.IsNullOrEmpty(pt.Name)) { if (!String.IsNullOrEmpty(pt.Description)) { text += " - " + pt.Description; } } else { text = pt.Description; } PointF wpt = new PointF(pt.Longitude, pt.Latitude); mapView.AddWaypoint(wpt, text); } }
private static TrackActivity ConvertActivity(TcxActivity tcxActivity) { TrackActivity track = new TrackActivity(); track.Laps = new List <TrackLap>(); track.Waypoints = new List <TrackWaypoint>(); foreach (TcxActivityLap tcxLap in tcxActivity.Laps) { TrackLap lap = new TrackLap(); lap.Points = new List <TrackPoint>(); if (tcxLap.Tracks != null) { foreach (TcxTrackPointList tcxTrack in tcxLap.Tracks) { if (tcxTrack.Trackpoints != null) { foreach (TcxTrackPoint tcxPoint in tcxTrack.Trackpoints) { TrackPoint pt = ConvertTrackPoint(tcxPoint); if (pt != null) { lap.Points.Add(pt); } } } } } track.Laps.Add(lap); } return(track); }