/* Copyright 2017 Diversified Technical Systems */ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using DTS.Common.Classes.TestSetups; using DTS.Common.Interface.Channels; using DTS.Common.Interface.TestSetups; namespace DTS.Common.ISO { /// /// this class will probably become an abstract base class in the future but for now since we only have /// summed realtime channels, we can be a little less formal /// public class CalculatedValueClass : CalculatedChannelRecord { public CalculatedValueClass() { } public CalculatedValueClass(CalculatedValueClass copy) { Id = copy.Id; Operation = copy.Operation; TestSetupName = copy.TestSetupName; Name = copy.Name; foreach (var a in copy.Attributes) { _attributes.Add(a.Copy()); } CalculatedValueCode = copy.CalculatedValueCode; CFCForInputChannels = copy.CFCForInputChannels; ChannelFilterClassForOutput = copy.ChannelFilterClassForOutput; var ids = new List(copy.InputChannelIds); _inputChannelIds = ids.ToArray(); ViewInRealtime = copy.ViewInRealtime; ClipLength = copy.ClipLength; } public CalculatedValueClass(ICalculatedChannelRecord record) : base(record) { } /// /// returns true if the calculation channel supports realtime /// public bool SupportsRealtime { get { if (!ViewInRealtime) { return false; } return true; } } public bool IsValid(Dictionary channelIdLookup) { if (string.IsNullOrWhiteSpace(Name)) { return false; } if (InputChannelIds.Length < 1) { return false; } foreach (var id in _inputChannelIds) { if (!channelIdLookup.ContainsKey(id)) { return false; } } return true; } public new Operations Operation { get => base.Operation; set { base.Operation = value; OnPropertyChanged("ViewInRealtime"); OnPropertyChanged("CanChangeViewInRealtime"); } } public new bool ViewInRealtime { get { switch (Operation) { case Operations.IRTRACC3D: case Operations.IRTRACC3D_ABDOMEN: case Operations.IRTRACC3D_LOWERTHORAX: case Operations.HIC: return false; } return base.ViewInRealtime; } set => base.ViewInRealtime = value; } public bool CanChangeViewInRealtime { get { switch (Operation) { case Operations.IRTRACC3D: case Operations.IRTRACC3D_ABDOMEN: case Operations.IRTRACC3D_LOWERTHORAX: case Operations.HIC: return false; } return true; } } public new string[] InputChannelIds { get { if (_channels.Any()) { var ids = new List(); foreach (var ch in _channels) { if (null == ch) { ids.Add("-1"); } else { ids.Add(ch.Id.ToString()); } } _inputChannelIds = ids.ToArray(); } return base.InputChannelIds; } set => base.InputChannelIds = value; } private List _channels = new List(); public List TestObjectChannels { get; set; } = new List(); public void SetChannels(IGroupChannel[] groupChannels) { _channels = new List(groupChannels); } public void SetTestObjectChannels(TestObjectChannel[] testObjectChannels) { TestObjectChannels = new List(testObjectChannels); } public byte[] InputChannelIdsBlob { get { var text = string.Join(CultureInfo.InvariantCulture.TextInfo.ListSeparator, InputChannelIds); return Encoding.UTF8.GetBytes(text); } set { var text = Encoding.UTF8.GetString(value); var ids = new List(text.Split( new[] { CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None)); _inputChannelIds = ids.ToArray(); } } private readonly List _attributes = new List(); public CCAttributeBase[] Attributes { get => _attributes.ToArray(); set { _attributes.Clear(); _attributes.AddRange(value); } } public void ReplaceInputChannelIdAtIndex(int index, string newId) { _inputChannelIds[index] = newId; } } /// /// the design here is so that we can attach attributes to calculated channels that need them (HIC, Head Contact Duration), but let them be a bit variable and dynamic /// public abstract class CCAttributeBase { protected int _attributeId; public int AttributeId => _attributeId; protected object _attributeValue; public abstract string GetSerializedValue(); public abstract string GetDefaultValue(); public abstract string GetNameResourceId { get; } public abstract CCAttributeBase Copy(); } }