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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
using Bro.Common.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
 
namespace Bro.Common.Helper
{
    /// <summary>
    /// 设备特性,指示该信息的设备类型,适用于设备信息和配置信息
    /// </summary>
    public class DeviceAttribute : Attribute
    {
        /// <summary>
        /// 设备类型
        /// </summary>
        public string TypeCode { get; set; }
 
        public string TypeDescription { get; set; }
 
        /// <summary>
        /// 特性修饰类别
        /// </summary>
        public EnumHelper.DeviceAttributeType AttrType { get; set; }
 
        public DeviceAttribute(string typeCode, string typeDesc, EnumHelper.DeviceAttributeType attrType)
        {
            TypeCode = typeCode;
            TypeDescription = typeDesc;
            AttrType = attrType;
        }
    }
 
    public class CompareDevice : IEqualityComparer<DeviceAttribute>
    {
        public bool Equals(DeviceAttribute x, DeviceAttribute y)
        {
            return x.TypeCode == y.TypeCode;
        }
 
        public int GetHashCode(DeviceAttribute obj)
        {
            return obj.GetHashCode();
        }
    }
 
    /// <summary>
    /// 预置状态特性  指定该修饰信息的前置状态允许范围
    /// </summary>
    public class PreStateAttribute : Attribute
    {
        public int PreState { get; set; }
        public PreStateAttribute(int _preState)
        {
            PreState = _preState;
        }
 
        /// <summary>
        /// 检查当前待执行操作的前置状态要求是否合法
        /// </summary>
        /// <param name="currentState"></param>
        /// <returns></returns>
        public bool CheckPreStateValid(int currentState)
        {
            return (currentState & PreState) == currentState;
        }
    }
 
    /// <summary>
    /// 跳过状态特性 指定该修饰状态执行时不需要执行具体操作的跳过状态
    /// 如当状态从打开切换至初始化时,可以跳过再次执行初始化操作
    /// </summary>
    public class SkipStateAttribute : Attribute
    {
 
    }
 
    /// <summary>
    /// 指定该特性修饰字段的数据源来自于哪一个枚举
    /// </summary>
    public class ConfigOutputResourceAttribute : Attribute
    {
        public string EnumName { get; set; }
 
        //public List<string> Results { get; set; }
 
        //public ConfigOutputAttribute(string _enumName = null, List<string> _results = null)
        //{
        //    EnumName = _enumName;
        //    Results = _results;
        //}
 
        public ConfigOutputResourceAttribute(string _enumName)
        {
            EnumName = _enumName;
        }
    }
 
    public class DeviceOutputMethodAttribute : Attribute
    {
        public string MethodName { get; set; }
        public string MethodDescription { get; set; }
 
        public DeviceOutputMethodAttribute(string methodName, string methodDescription)
        {
            MethodName = methodName;
            MethodDescription = methodDescription;
        }
    }
 
    /// <summary>
    /// 该特性用于修饰设备外部输入的判断方法
    /// 方法的输入参数为IOperationConfig,返回值为布尔类型
    /// </summary>
    public class DeviceInputMethodAttribute : Attribute
    {
        public string MethodName { get; set; }
        public string MethodDescription { get; set; }
 
        public DeviceInputMethodAttribute(string methodName, string methodDescription)
        {
            MethodName = methodName;
            MethodDescription = methodDescription;
        }
    }
 
    public class ColorSelectAttribute : Attribute
    {
        public string SelectedColor { get; set; }
        public ColorSelectAttribute(string selectedColor)
        {
            SelectedColor = selectedColor;
        }
    }
 
    public class CameraParaAttribute : Attribute
    {
        public string ParaName { get; set; }
        public string ParaNameCode { get; set; }
        public double MaxValue { get; set; }
        public double MinValue { get; set; }
        public int Ratio { get; set; } = 1;
 
        public CameraParaAttribute(string name, string nameCode, double maxValue, double minValue, int ratio)
        {
            ParaName = name;
            ParaNameCode = nameCode;
            MaxValue = maxValue;
            MinValue = minValue;
            Ratio = ratio;
        }
    }
 
    public class ProcessMethodAttribute : Attribute
    {
        public string MethodCode { get; set; }
        public string MethodDesc { get; set; }
 
        /// <summary>
        /// 是否提供人工调用测试
        /// </summary>
        public bool IsAllowManualInvoke { get; set; }
 
        public string DeviceType { get; set; }
 
        public ProcessMethodAttribute(string deviceType, string code, string description, bool isAllowManualInvoke = false)
        {
            DeviceType = deviceType;
            MethodCode = code;
            MethodDesc = description;
            IsAllowManualInvoke = isAllowManualInvoke;
        }
    }
 
    public class CameraInvokeAttribute : Attribute
    {
        public string CameraName { get; set; }
 
        public CameraInvokeAttribute(string cameraName)
        {
            CameraName = cameraName;
        }
    }
 
    public class StationAttribute : Attribute
    {
        public string StationCode { get; set; }
 
        public StationAttribute(string stationCode)
        {
            StationCode = stationCode;
        }
    }
 
    public class CSVOutputAttribute : Attribute
    {
        public string HeadName { get; set; }
 
        public int OrderIndex { get; set; }
 
        public int PositionIndex { get; set; }
 
        public bool IsCSVInterface { get; set; }
 
        public bool IsConfig { get; set; }
 
        public bool IsCSVOutput { get; set; } = true;
 
        public CSVOutputAttribute(bool isOutput)
        {
            IsCSVOutput = isOutput;
        }
 
        /// <summary>
        /// CSV输出修饰特性
        /// </summary>
        /// <param name="headName">列名</param>
        /// <param name="orderIndex">序号</param>
        /// <param name="positionIndex">工位索引 从0开始</param>
        /// <param name="isCSVInterface">是否CSV输出接口</param>
        /// <param name="isConfig">是否配置信息中的CSV字段</param>
        public CSVOutputAttribute(string headName, int orderIndex, int positionIndex, bool isCSVInterface, bool isConfig)
        {
            HeadName = headName;
            OrderIndex = orderIndex;
            PositionIndex = positionIndex;
            IsCSVInterface = isCSVInterface;
            IsConfig = isConfig;
        }
    }
 
    public class DeviceOperationAttribute : Attribute
    {
        public DeviceOpCmmd DeviceCmmd { get; set; }
 
        /// <summary>
        /// 该方法是否需要IOperationconfig参数 true:需要 false:不需要
        /// </summary>
        public bool IsOpConfigNeed { get; set; }
 
        public DeviceOperationAttribute(DeviceOpCmmd deviceCmmd, bool isOpConfigNeed)
        {
            DeviceCmmd = deviceCmmd;
            IsOpConfigNeed = isOpConfigNeed;
        }
    }
 
    public class SFCNameAttribute : Attribute
    {
        public string SFCAlias { get; set; }
 
        public SFCNameAttribute(string alias)
        {
            SFCAlias = alias;
        }
    }
 
    public class PCWarningAttribute : Attribute
    {
 
    }
 
    public class SwitchDisplayAttribute : Attribute
    {
        public string SwitchName { get; set; }
 
        public bool SwithOnStatus { get; set; } = true;
 
        public SwitchDisplayAttribute(string name, bool status)
        {
            SwitchName = name;
            SwithOnStatus = status;
        }
    }
 
    public class ElementAttribute : Attribute
    {
        public string Name { get; set; }
 
        public string Desc { get; set; }
 
        public string IconPath { get; set; }
 
        public bool IsShowInToolBar { get; set; }
 
        public ElementAttribute(string desc, string iconPath, bool isShowInToolBar = true, [CallerMemberName] string name = "")
        {
            Name = name;
            Desc = desc;
            IconPath = iconPath;
            IsShowInToolBar = isShowInToolBar;
        }
    }
}