领胜LDS 键盘AOI检测项目
wells.liu
2020-07-06 99587d3c26f5b952cb7dc87a56be91b08c5d277b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using Bro.Common.Helper;
using Bro.Common.Interface;
using Newtonsoft.Json;
using System;
using System.ComponentModel;
using System.Drawing.Design;
 
namespace Bro.Common.Model
{
 
    /// <summary>
    /// 标准配置
    /// </summary>
    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;
        }
    }
}