/// <summary> /// Compares a property of this object with a property of another LapInfo object. If they are equal, use the LapInfo index as a comparison. /// </summary> /// <param name="other">The LapInfo object to compare with.</param> /// <param name="propertyIndex">The zero-based index of the property to compare.</param> /// <returns></returns> public int CompareProperty(LapInfo other, int propertyIndex) { if(propertyIndex > properties.Count-1 || propertyIndex > other.GetProperties().Count-1) return 0; var value = this[propertyIndex].CompareTo(other[propertyIndex]); if (value == 0) value = Index == -1 ? 1 : (other.Index == -1 ? -1 : Index.CompareTo(other.Index)); return value; }
/// <summary> /// Compares a property of this object with a property of another LapInfo object. If they are equal, use the LapInfo index as a comparison. /// </summary> /// <param name="other">The LapInfo object to compare with.</param> /// <param name="propertyIndex">The zero-based index of the property to compare.</param> /// <returns></returns> public int CompareProperty(LapInfo other, int propertyIndex) { if (propertyIndex > properties.Count - 1 || propertyIndex > other.GetProperties().Count - 1) { return(0); } var value = this[propertyIndex].CompareTo(other[propertyIndex]); if (value == 0) { value = Index == -1 ? 1 : (other.Index == -1 ? -1 : Index.CompareTo(other.Index)); } return(value); }
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--; }