// -> UserSpan PropertyChanged External Reaction // --> main wrapper private void OnUserSpanPropertyChanged(object sender, EventArgs e) { PropertyChangedEventArgs pe = e as PropertyChangedEventArgs; UserSpan actualactualSpan = sender as UserSpan; if (pe.PropertyName == "TowerAbscissa" || pe.PropertyName == "SpanLength") { if (AlternativeInputMode && actualactualSpan.SpanLength != null) { OnSpanLengthPropertyChanged(sender); if (EvaluateNeedToPerformInternalIntegrityCheck()) { CheckInternalIntegrity(); } } else if (actualactualSpan.TowerAbscissa != null) { OnTowerAbscissaPropertyChanged(sender); if (EvaluateNeedToPerformInternalIntegrityCheck()) { CheckInternalIntegrity(); } } } else { if (EvaluateNeedToPerformInternalIntegrityCheck()) { CheckInternalIntegrity(); } } }
// --> 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); } } }
// METHODS // -> Basic section handling: public void JustAddSpan() { UserSpan newSpan = new UserSpan(); // add span at the end of current section newSpan.PropertyChanged += OnUserSpanPropertyChanged; Spans.Add(newSpan); OrderingSection(); SelectedUserSpan = Spans.Last(); }
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; } } }
// -> Section handling backstage: private void CreateBasicSection() { UserSpan span0 = new UserSpan(); UserSpan span1 = new UserSpan(); span0.PropertyChanged += OnUserSpanPropertyChanged; span1.PropertyChanged += OnUserSpanPropertyChanged; if (Spans.Count != 0) { LowLevelSectionErase(); } Spans.Add(span0); Spans.Add(span1); OrderingSection(); }
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); } } }