using Bro.Common.Helper; using Bro.Common.Interface; using Newtonsoft.Json; using System; using System.ComponentModel; using System.Drawing.Design; namespace Bro.Common.Model { /// /// 标准配置 /// public class Spec : ICSVOutput, IComplexDisplay { [Category("通用配置")] [Description("标准代码")] public virtual string Code { get; set; } [Category("通用配置")] [Description("启用状态,true:启用;false:禁用")] [DisplayName("启用状态")] public bool IsEnabled { get; set; } [Category("标准配置")] [Description("标准值")] [DisplayName("标准值")] public double StandardValue { get; set; } [Category("标准配置")] [Description("正公差")] [DisplayName("正公差")] public double Tolrenance_Positive { get; set; } [Category("标准配置")] [Description("负公差")] [DisplayName("负公差")] public double Tolrenance_Negative { get; set; } protected double? actualValue = null; [Browsable(false)] [JsonIgnore] public virtual double? ActualValue { get { return actualValue; } set { //if (actualValue != value && value != null) if (value != null) { if (value.Value >= (StandardValue - Tolrenance_Negative) && value.Value <= (StandardValue + Tolrenance_Positive)) { MeasureResult = true; } else { MeasureResult = false; } } actualValue = value; } } [Browsable(false)] [JsonIgnore] public bool? MeasureResult { get; set; } = null; public virtual string GetCSVHead() { return Code + ":" + StandardValue.ToString("f3") + "/+" + Tolrenance_Positive.ToString("f3") + "/-" + Tolrenance_Negative.ToString("f3"); } public virtual string GetCSVData() { return ActualValue == null ? "NA" : ActualValue.Value.ToString("f3"); } public virtual string GetDisplayText() { return (IsEnabled ? "" : "禁用 ") + Code + ":" + StandardValue.ToString("f3") + "/+" + Tolrenance_Positive.ToString("f3") + "/-" + Tolrenance_Negative.ToString("f3"); } } public class PointSpec : IComplexDisplay { [Category("点位标准设置")] [Description("标准点位")] [DisplayName("标准点位")] [TypeConverter(typeof(ComplexObjectConvert))] [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))] public CustomizedPoint StandardPoint { get; set; } = new CustomizedPoint(); [Category("点位标准设置")] [Description("允许偏移距离")] [DisplayName("允许偏移")] public float MaxOffset { get; set; } [Category("点位标准设置")] [Description("是否启用偏移限制设置")] [DisplayName("启用状态")] public bool IsEnableOffsetLimit { get; set; } = false; private CustomizedPoint actualPoint = null; [Browsable(false)] [JsonIgnore] public CustomizedPoint ActualPoint { get { return actualPoint; } set { if (value != null) { double distance = Math.Sqrt(Math.Pow(value.X - StandardPoint.X, 2) + Math.Pow(value.Y - StandardPoint.Y, 2)); MeasureResult = distance <= MaxOffset; } actualPoint = value; } } [Browsable(false)] [JsonIgnore] public bool MeasureResult { get; set; } = false; public string GetDisplayText() { return "(" + StandardPoint.X + ";" + StandardPoint.Y + ") Offset:" + MaxOffset; } } }