// --> auxilliaries for above mentioned: private double?CalculateSpanLengthFromPosition(UserSpan referenceSpan) { if (referenceSpan.IsLastSpan) { return(null); } else { double?towerAbscissa1 = referenceSpan.TowerAbscissa; double?towerAbscissa2 = Spans[Spans.IndexOf(referenceSpan) + 1].TowerAbscissa; double?spanLength; if (towerAbscissa1.HasValue && towerAbscissa2.HasValue) { spanLength = towerAbscissa2 - towerAbscissa1; if (spanLength <= 0) { return(null); } else { return(spanLength); } } else { return(null); } } }
public void RemoveSelectedSpan() // removes selected (doh) span { if (Spans.Count <= 2) { return; } int index = Spans.IndexOf(_selectedSpan); _selectedSpan.PropertyChanged -= OnUserSpanPropertyChanged; Spans.Remove(_selectedSpan); OrderingSection(); if (index >= Spans.Count()) { return; // last span was removed so nothing to do } else { OnTowerAbscissaPropertyChanged(Spans[index]); // altering span lengths as a consequence of the tower abscissas change (change of tower abscissa has higher priority than span length) } if (EvaluateNeedToPerformInternalIntegrityCheck()) { CheckInternalIntegrity(); } }
public void AddSpanAfterSelectedSpan() { int index = Spans.IndexOf(_selectedSpan); UserSpan newSpan = new UserSpan(); newSpan.PropertyChanged += OnUserSpanPropertyChanged; Spans.Insert(index + 1, newSpan); OrderingSection(); SelectedUserSpan = Spans[index + 1]; }
private void OnSpanLengthPropertyChanged(object sender) { UserSpan actualSpan = sender as UserSpan; int index = Spans.IndexOf(actualSpan); double? value; if (!actualSpan.TowerAbscissa.HasValue) { actualSpan.TowerAbscissa = 0; } for (int i = index; i < Spans.Count - 1; i++) { value = CalculatePositionFromSpanLength(Spans[i + 1]); //if (!value.HasValue) break; Spans[i + 1].TowerAbscissa = value; } }
// --> reaction on concrete property change private void OnTowerAbscissaPropertyChanged(object sender) { UserSpan actualSpan = sender as UserSpan; int index = Spans.IndexOf(actualSpan); double?value; for (int i = index - 1; i < Spans.Count - 1; i++) { if (i >= 0) { value = CalculateSpanLengthFromPosition(Spans[i]); //if (!value.HasValue) break; Spans[i].SpanLength = value; } } }
private double?CalculatePositionFromSpanLength(UserSpan referenceSpan) { double?spanLength; double?towerAbscissa0; int indexOfActualSpan; int indexOfPreviousSpan; indexOfActualSpan = Spans.IndexOf(referenceSpan); if (indexOfActualSpan == 0) { if (referenceSpan.TowerAbscissa.HasValue) { return(referenceSpan.TowerAbscissa); } else { return(0); } } else { indexOfPreviousSpan = indexOfActualSpan - 1; spanLength = Spans[indexOfPreviousSpan].SpanLength; towerAbscissa0 = Spans[indexOfPreviousSpan].TowerAbscissa; if (towerAbscissa0.HasValue && spanLength.HasValue) { return(towerAbscissa0 + spanLength); } else { return(null); } } }
public void ClearSelectedSpan() { Spans[Spans.IndexOf(_selectedSpan)].Clear(); SelectedUserSpan.Clear(); }