/// <summary> /// Adds a new section to this route. A section is a list of geolocations representing a subpart of a route. /// </summary> /// <param name="section">Thew list of geolocations representing a section.</param> public void AddSection(List <GeoLocation> section) { if (section != null) { RouteLocations.Add(section); } }
void UpdateMapElements(GeoCoordinate currentLoc) { Center = currentLoc; Pushpins.Clear(); Pushpins.Add(new Pushpin { Location = currentLoc }); Speed = (currentLoc.Speed * 3.6).ToString(); Altitude = currentLoc.Altitude.ToString(); if (IsRecording == false) { return; } RouteLocations.Add(currentLoc); if (RouteLocations.Count - 2 >= 0) { Distance = Distance + RouteLocations[RouteLocations.Count - 2].GetDistanceTo(currentLoc); } if (Routes.Count == 0) { var routeModel = new RouteModel(RouteLocations); Routes.Add(routeModel); Route = routeModel; } NotifyPropertyChanged(() => Route); NotifyPropertyChanged(() => Routes); }
public RouteProperty Get(Type routePropertyType, RouteLocations locations) { if (!cache.ContainsKey(routePropertyType)) return null; var cacheSection = cache[routePropertyType]; if (!cacheSection.ContainsKey(locations)) return null; var item = cacheSection[locations]; return item; }
/// <summary> /// Updates an existing section of the route. /// </summary> /// <param name="section">The geolocations representing the new section.</param> /// <param name="position">The index of the sction to be updated.</param> public void UpdateSection(List <GeoLocation> section, int position) { if (section != null && position > 0 && position < RouteLocations.Count) { RouteLocations.RemoveAt(position); RouteLocations.Insert(position, section); } }
public void Export() { var writerSettings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true, IndentChars = " " }; var writer = XmlWriter.Create(OutputStream, writerSettings); var formatter = new Formatter(); var cacheManager = new RoutePropertyCacheManager(); if (writer != null) { writer.WriteStartDocument(); writer.WriteStartElement("Route"); int segmentCount = 0; foreach (var segment in Session.Route.Segments) { writer.WriteStartElement("Segment"); var waypoints = Session.Route.GetEquallySpacedWaypoints(segment.FirstWaypoint.Time, segment.LastWaypoint.Time, Settings.SamplingInterval, Settings.ZeroTime); var lastPl = new ParameterizedLocation(segmentCount, 0); foreach (var waypoint in waypoints) { writer.WriteStartElement("Sample"); var pl = Session.Route.GetParameterizedLocationFromTime(waypoint.Time, lastPl, ParameterizedLocation.Direction.Forward); var locations = new RouteLocations(pl); foreach (var lpType in Settings.RoutePropertyTypes) { if (lpType.Selected) { RetrieveExternalPropertyDelegate dlg = new ExternalRoutePropertyRetriever(Session.Settings).RetrieveExternalProperty; var lp = Activator.CreateInstance(lpType.RoutePropertyType, Session, locations, dlg) as RouteProperty; if (lp != null) { lp.CacheManager = cacheManager; if (lp.ContainsValue) { var attributeName = GetCamelCaseString(lpType.RoutePropertyType.Name); var attributeValue = lp.ToString(formatter); writer.WriteAttributeString(attributeName, attributeValue); } } } } writer.WriteEndElement(); lastPl = pl; } writer.WriteEndElement(); segmentCount++; } writer.WriteEndElement(); writer.Close(); } }
public RouteProperty GetLastAdded(Type routePropertyType, RouteLocations desiredLocations) { if (!lastAddedCache.ContainsKey(routePropertyType)) return null; var items = lastAddedCache[routePropertyType]; if (desiredLocations.IsSpan) { for(int i=items.Count-1; i>=0; i--) { if (items[i].Locations.Start == desiredLocations.Start) return items[i]; } return null; } else { return items[items.Count-1]; } }
public RouteProperty GetClosest(Type routePropertyType, RouteLocations locations, ParameterizedLocation.Direction direction) { if (!cache.ContainsKey(routePropertyType)) return null; var cacheSection = cache[routePropertyType]; RouteProperty closestRouteProperty = null; ParameterizedLocation closestPL = null; if (locations.IsSpan) { foreach (var item in cacheSection) { if (item.Key.Start == locations.Start // need to have same start && (closestPL == null || (direction == ParameterizedLocation.Direction.Forward && item.Key.End >= locations.End && item.Key.End < closestPL) || (direction == ParameterizedLocation.Direction.Backward && item.Key.End <= locations.End && item.Key.End > closestPL) )) { closestPL = item.Key.End; closestRouteProperty = item.Value; } } } else { foreach (var item in cacheSection) { if (closestPL == null || (direction == ParameterizedLocation.Direction.Forward && item.Key.Location >= locations.Location && item.Key.Location < closestPL) || (direction == ParameterizedLocation.Direction.Backward && item.Key.Location <= locations.Location && item.Key.Location > closestPL) ) { closestPL = item.Key.End; closestRouteProperty = item.Value; } } } return closestRouteProperty; }
private void CalculateLapInfo() { Session s = canvas.CurrentSession; if (s == null) return; Route r = s.Route; ParameterizedLocation previousLapPL = ParameterizedLocation.Start; lapInfoList = new List<LapInfo>(); for (int i = 0; i < s.Laps.Count; i++) { Lap lap = s.Laps[i]; ParameterizedLocation lapPL = r.GetParameterizedLocationFromTime(lap.Time, previousLapPL, ParameterizedLocation.Direction.Forward); if (lap.LapType != LapType.Start && i > 0) { var li = new LapInfo { LapType = lap.LapType, Index = i }; var locations = new RouteLocations(previousLapPL, lapPL); foreach (var lpType in ApplicationSettings.LapPropertyTypes) { if (lpType.Selected) { RetrieveExternalPropertyDelegate dlg = new ExternalRoutePropertyRetriever(s.Settings).RetrieveExternalProperty; var lp = Activator.CreateInstance(lpType.RoutePropertyType, s, locations, dlg) as RouteProperty; li.AddProperty(lp); } } if (s.Laps.Count > 2) { lapInfoList.Add(li); } } previousLapPL = lapPL; } // total row var totalInfo = new LapInfo() { LapType = LapType.Stop, Index = -1 }; foreach (var lpType in ApplicationSettings.LapPropertyTypes) { if (lpType.Selected) { // create route span property object var routeSpanProperty = Activator.CreateInstance(lpType.RoutePropertyType, s, new RouteLocations(ParameterizedLocation.Start), null) as RouteSpanProperty; if (routeSpanProperty != null) { // get the route from start property type for this object Type routeFromStartPropertyType = routeSpanProperty.GetRouteFromStartPropertyType(); // create an instance of that type RetrieveExternalPropertyDelegate dlg = new ExternalRoutePropertyRetriever(s.Settings).RetrieveExternalProperty; var routeFromStartProperty = Activator.CreateInstance(routeFromStartPropertyType, s, new RouteLocations(r.LastPL), dlg) as RouteFromStartProperty; if (routeFromStartProperty == null) { // no matching route from start property, add blank column totalInfo.AddProperty(new BlankRouteProperty()); } else { totalInfo.AddProperty(routeFromStartProperty); } } else { RetrieveExternalPropertyDelegate dlg = new ExternalRoutePropertyRetriever(s.Settings).RetrieveExternalProperty; var routeFromStartProperty = Activator.CreateInstance(lpType.RoutePropertyType, s, new RouteLocations(r.LastPL), dlg) as RouteFromStartProperty; if (routeFromStartProperty == null) { // no matching route from start property, add blank column totalInfo.AddProperty(new BlankRouteProperty()); } else { totalInfo.AddProperty(routeFromStartProperty); } } } } lapInfoList.Add(totalInfo); // set number of rows and columns in grid updatingUINowCounter++; laps.RowCount = 0; laps.ColumnCount = 0; laps.RowCount = lapInfoList.Count; laps.ColumnCount = (lapInfoList.Count == 0 ? 0 : lapInfoList[0].GetProperties().Count); updatingUINowCounter--; SetLapGridHeaders(); SortLapGrid(); laps.Invalidate(); updatingUINowCounter -= 100; // ugly! laps.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); updatingUINowCounter += 100; // ugly! if (laps.Rows.Count > 0) { updatingUINowCounter++; laps.Rows[laps.Rows.Count - 1].Selected = true; updatingUINowCounter--; } int width = 0; foreach (DataGridViewColumn c in laps.Columns) { width += c.Width; } updatingUINowCounter++; rightPanel.Width = width + laps.Margin.Horizontal; updatingUINowCounter--; }
public AverageStraightLinePaceFromStart(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
protected RouteMomentaneousProperty(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public AverageHeartRate(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public RouteToStraightLine(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public CircleTimeAtStartOfSpan(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public AveragePaceWhenNotReadingMap(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
protected RouteFromStartProperty(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public AscentFromStart(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public CircleTimeBackward(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public ElapsedTime(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public NumberOfMapReadingsFromStart(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public PreviousMapReadingEnd(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public Inclination(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public MapReadingPercentageFromStart(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public AverageTimeBetweenMapReadings(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public AverageMapReadingTimeFromStart(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public MapReadingState(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
protected RouteProperty(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) { Session = session; Locations = locations; RetrieveExternalProperty = retrieveExternalProperty; }
public AltitudeDifferenceFromStart(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public MaxPower(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public AverageInclinationFromStart(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public AverageDirectionDeviationToNextLapFromStart(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }
public Altitude(Session session, RouteLocations locations, RetrieveExternalPropertyDelegate retrieveExternalProperty) : base(session, locations, retrieveExternalProperty) { }