using Aurora.View; using CoreUnit.Control.UserControl.Canvas; using PropertyTools.DataAnnotations; using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using WeldingCommon.Settings; using WeldingCommon.Utils; namespace WeldingCommon.Data { public class PLCReportData : ReportData { public int Address { get => _Address; set => SetProperty(ref _Address, value); } private int _Address; public bool IsUpdate { get => _IsUpdate; set => SetProperty(ref _IsUpdate, value); } private bool _IsUpdate; public bool IsDoubleWord { get => _IsDoubleWord; set => SetProperty(ref _IsDoubleWord, value); } private bool _IsDoubleWord; public int PlacePoint { get => _PlacePoint; set => SetProperty(ref _PlacePoint, value); } private int _PlacePoint; public bool IsThrow { get => _IsThrowValue; set => SetProperty(ref _IsThrowValue, value); } private bool _IsThrowValue; public int ThrowAddress { get => _ThrowAddress; set => SetProperty(ref _ThrowAddress, value); } private int _ThrowAddress; public int getValue() => (int)(Value * Math.Pow(10, PlacePoint)); public T readValue(T fallback = default) where T : IConvertible { if (!IsUpdate) return fallback; var scaled = ConvertHelper.DownScaleDecimal(Value, PlacePoint); if (typeof(T) == typeof(int)) return (T)(object)Decimal.ToInt32(Math.Round(scaled, 0, MidpointRounding.AwayFromZero)); if (typeof(T) == typeof(long)) return (T)(object)Decimal.ToInt64(Math.Round(scaled, 0, MidpointRounding.AwayFromZero)); //Debug.WriteLine($"Scaled Value >> {scaled}"); return (T)Convert.ChangeType(scaled, typeof(T), CultureInfo.InvariantCulture); } public PLCReportData(string uploadName) : base(uploadName) { } public override object Clone() { var item = new PLCReportData(DataName); item.Address = Address; item.IsUpdate = IsUpdate; item.PlacePoint = PlacePoint; item.IsDoubleWord = IsDoubleWord; item.DataName = DataName; item.Value = Value; item.IsThrow = IsThrow; item.ThrowAddress = ThrowAddress; return item; } } //public class PLCReportDataList : List, ICloneable //{ // //public PLCReportData this[eUploadData index] { // // get => base[Convert.ToInt32(index)]; // //} // public PLCReportData this[string name] { // get => this.FirstOrDefault(t => t.DataName == name); // } // public object Clone() // { // var newItem = new PLCReportDataList(); // foreach (var item in this) { // newItem.Add(item.Clone() as PLCReportData); // } // return newItem; // } //} }