using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; namespace DTS.Slice.PedestrianAndHeadReports { public class GraphChannel: INotifyPropertyChanged { public virtual void SetValue(Fields field, string value) { switch (field) { case Fields.Offset: double d; if (double.TryParse(value, out d)) { Offset = d; } break; case Fields.UseOffset: bool b; if (bool.TryParse(value, out b)) { UseOffset = b; } break; default: throw new NotImplementedException(field.ToString()); } } public virtual string GetValue(Fields field) { return GetValue(field, Properties.Settings.Default.PROTECTIONREPORT_NumberFormat); } public virtual string GetValueTrunc2Places(Fields field) { switch (field) { case Fields.DataMax: return (((int)(DataMax * 100)) / 100).ToString("N2"); case Fields.DataMin: return (((int)(DataMin * 100)) / 100).ToString("N2"); case Fields.TimeOfMax: return (((int)(TimeOfMax * 100)) / 100).ToString("N2"); case Fields.TimeOfMin: return (((int)(TimeOfMin * 100)) / 100).ToString("N2"); default: throw new NotImplementedException(); } } public virtual string GetValue(Fields field, string format) { switch (field) { case Fields.DataMax: return DataMax.ToString(format); case Fields.DataMin: return DataMin.ToString(format); case Fields.TimeOfMax: return TimeOfMax.ToString(format); case Fields.TimeOfMin: return TimeOfMin.ToString(format); case Fields.UseOffset: return UseOffset.ToString(); case Fields.Offset: return Offset.ToString(); default: throw new NotImplementedException(); } } private bool _useOffset = false; public bool UseOffset { get { return _useOffset; } set { SetProperty(ref _useOffset, value, "UseOffset"); if (null != Channel && null != Channel.Channel) { Channel.Channel.UserOffsetEU = value ? Offset : 0D; } } } private double _offset = 0D; public double Offset { get { return _offset; } set { SetProperty(ref _offset, value, "Offset"); if (UseOffset) { if (null != Channel && null != Channel.Channel) { Channel.Channel.UserOffsetEU = value; } } } } public enum Fields { DataMin, DataMax, TimeOfMin, TimeOfMax, HIC, T1, T2, UseOffset, Offset } /// /// these functions make us WPF/dependency property friendly, and also /// adds a convenient way for us to notify consumers when a property has changed /// public event PropertyChangedEventHandler PropertyChanged; protected bool SetProperty(ref T storage, T value, String propertyName) { if (object.Equals(storage, value)) return false; storage = value; this.OnPropertyChanged(propertyName); return true; } protected void OnPropertyChanged(string propertyName) { var eventHandler = this.PropertyChanged; if (eventHandler != null) { eventHandler(this, new PropertyChangedEventArgs(propertyName)); } } private string _id; public string Id { get { return _id; } } private string _displayName; public string DisplayName { get { return _displayName; } set { SetProperty(ref _displayName, value, "DisplayName"); } } private string _channelNameHint; public string ChannelNameHint { get { return _channelNameHint; } set { SetProperty(ref _channelNameHint, value, "ChannelNameHint"); } } private ReviewTestChannel _channel; public ReviewTestChannel Channel { get { return _channel; } set { SetProperty(ref _channel, value, "Channel"); } } public GraphChannel(string id, string displayName, string hint) { _id = id; DisplayName = displayName; ChannelNameHint = hint; } private double _dataMin; public double DataMin { get { return _dataMin; } set { SetProperty(ref _dataMin, value, "DataMin"); } } private double _dataMax; public double DataMax { get { return _dataMax; } set { SetProperty(ref _dataMax, value, "DataMax"); } } private double _timeOfMin; public double TimeOfMin { get { return _timeOfMin; } set { SetProperty(ref _timeOfMin, value, "TimeOfMin"); } } private double _timeOfMax; public double TimeOfMax { get { return _timeOfMax; } set { SetProperty(ref _timeOfMax, value, "TimeOfMax"); } } } public class HICChannel : GraphChannel { public double _HIC; public double HIC { get { return _HIC; } set { SetProperty(ref _HIC, value, "HIC"); } } public double _t1; public double T1 { get { return _t1; } set { SetProperty(ref _t1, value, "T1"); } } public double _t2; public double T2 { get { return _t2; } set { SetProperty(ref _t2, value, "T2"); } } public HICChannel(string id, string displayName, string hint) : base(id, displayName, hint) { } public override string GetValue(GraphChannel.Fields field) { switch (field) { case Fields.HIC: return (((int)(HIC * 1000)) / 1000D).ToString("N3"); case Fields.T1: return (((int)(T1 * 100 ))/ 100D).ToString("N2"); case Fields.T2: return (((int)(T2 * 100 ))/ 100D).ToString("N2"); default: return base.GetValue(field); } } } public class VectorAddition : GraphChannel { public VectorAddition(string id, string displayName, string hint) : base(id, displayName, hint) { } } public class BendingDisplacement : GraphChannel { public BendingDisplacement(string id, string displayname, string hint) : base(id, displayname, hint) { } } public class ShearingDisplacement : GraphChannel { public ShearingDisplacement(string id, string displayname, string hint) : base(id, displayname, hint) { } } }