Common.cs
8.5 KB
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
299
using System;
using System.Collections.Generic;
using System.Drawing;
namespace CodeSplice
{
public static class Common
{
public static readonly string CONFIG_PATH = System.IO.Directory.GetCurrentDirectory() + "\\Config.xml";
public static readonly string LOG_DIR = System.IO.Directory.GetCurrentDirectory() + "\\Log\\";
public static readonly string LABEL_DIR = System.IO.Directory.GetCurrentDirectory() + "\\Label\\";
public static readonly string MATERIAL_DIR = System.IO.Directory.GetCurrentDirectory() + "\\Material\\";
public static readonly string LANGUAGE_DIR = System.IO.Directory.GetCurrentDirectory() + "\\Language\\";
public static readonly string HISTORY_DIR = System.IO.Directory.GetCurrentDirectory() + "\\History\\";
/// <summary>
/// 日志文件输出
/// </summary>
public static Asa.File.Log Log;
/// <summary>
/// 相机
/// </summary>
public static Asa.Camera.Camera Camera;
/// <summary>
/// 软件配置
/// </summary>
public static BLL.Config Config;
/// <summary>
/// 打印标签
/// </summary>
public static BLL.LabelEdit Label;
/// <summary>
/// 物料模板
/// </summary>
public static BLL.Material Mate;
/// <summary>
/// 追溯
/// </summary>
public static BLL.Traced Trace;
/// <summary>
/// 条形码
/// </summary>
public static BLL.BarCode BarCode;
/// <summary>
/// 康奈德寄存器
/// </summary>
public static Asa.IOModule.KND IO;
public static string[] LabelCode(List<LabelRect> rect)
{
List<string> item = new List<string>();
for (int i = 0; i < rect.Count; i++)
{
for (int j = 0; j < rect[i].Code.Count; j++)
item.Add(rect[i].Code[j].Text);
}
return item.ToArray();
}
public static string[] LabelCodeNumber(List<LabelRect> rect)
{
int n = 0;
string s;
List<string> item = new List<string>();
for (int i = 0; i < rect.Count; i++)
{
for (int j = 0; j < rect[i].Code.Count; j++)
{
s = ++n + " " + rect[i].Code[j].Text;
if (rect[i].Code[j].Mode.Length > 0)
s += string.Format(" ({0})", rect[i].Code[j].Mode);
if (rect[i].Code[j].Length < rect[i].Code[j].Text.Length)
s += string.Format(" ({0},{1})", rect[i].Code[j].Start, rect[i].Code[j].Length);
item.Add(s);
}
}
return item.ToArray();
}
public static PointF[] LabelCenter(List<LabelRect> rect)
{
List<PointF> item = new List<PointF>();
for (int i = 0; i < rect.Count; i++)
{
for (int j = 0; j < rect[i].Code.Count; j++)
item.Add(rect[i].Code[j].Center);
}
return item.ToArray();
}
}
/// <summary>
/// 完整的标签,用于打印
/// </summary>
public class PrintLabel
{
/// <summary>
/// 文件路径
/// </summary>
public string Path { set; get; } = "";
/// <summary>
/// 标签名称
/// </summary>
public string Name { set; get; } = "";
/// <summary>
/// 标签大小,毫米
/// </summary>
public SizeF Size_mm { get; set; } = new SizeF(0, 0);
/// <summary>
/// 标签大小,像素
/// </summary>
public SizeF Size_px { get; set; } = new SizeF(0, 0);
/// <summary>
/// 打印偏移量
/// </summary>
public Point PrintOffset { get; set; } = new Point(0, 0);
/// <summary>
/// 包含的字段
/// </summary>
public List<PrintLabelField> Field = new List<PrintLabelField>();
}
/// <summary>
/// 标签字段,用于打印
/// </summary>
public class PrintLabelField
{
/// <summary>
/// 位置大小,像素
/// </summary>
public RectangleF Rect_px = new RectangleF();
/// <summary>
/// 位置大小,毫米
/// </summary>
public RectangleF Rect_mm = new RectangleF();
/// <summary>
/// 字体
/// </summary>
public Font Font = new Font("宋体", 9f);
/// <summary>
/// 前缀
/// </summary>
public string Prefix { set; get; } = "";
/// <summary>
/// 打印的文本内容
/// </summary>
public string PrintText { set; get; } = "";
/// <summary>
/// 字段的类型
/// </summary>
public string Type { set; get; } = "";
}
/// <summary>
/// 条形码类
/// </summary>
public class BarCode
{
public int ID { get; set; }
/// <summary>
/// 文本
/// </summary>
public string Text { get; set; }
/// <summary>
/// 条码类型
/// </summary>
public string CodeType { get; set; }
/// <summary>
/// 中心点
/// </summary>
public PointF Center { get; set; }
/// <summary>
/// 角度,3点钟方向0°,逆时针为正,顺时针为负。
/// </summary>
public float Angle { get; set; }
/// <summary>
/// 宽度
/// </summary>
public float Width { get; set; }
/// <summary>
/// 高度
/// </summary>
public float Height { get; set; }
/// <summary>
/// 中心点到原点直线方程的距离
/// </summary>
public double Distance { get; set; }
/// <summary>
/// 模式,用于替换
/// </summary>
public string Mode { set; get; }
/// <summary>
/// 字符串截取起始
/// </summary>
public int Start { set; get; }
/// <summary>
/// 字符串截取长度
/// </summary>
public int Length { set; get; }
}
/// <summary>
/// 标签区域矩形
/// </summary>
public class LabelRect
{
/// <summary>
/// 条码的平均角度
/// </summary>
public float AvgAngle { set; get; } = 0;
/// <summary>
/// 条码数量
/// </summary>
public int CodeCount { set; get; } = 0;
/// <summary>
/// 是否检测
/// </summary>
public bool Check { set; get; } = false;
/// <summary>
/// 条码信息
/// </summary>
public List<BarCode> Code = new List<BarCode>();
/// <summary>
/// OCR识别
/// </summary>
public List<OcrRect> Ocr = new List<OcrRect>();
}
/// <summary>
/// OCR区域矩形
/// </summary>
public class OcrRect
{
/// <summary>
/// 条码ID
/// </summary>
public int CodeID { set; get; }
/// <summary>
/// 与指定条码的偏移
/// </summary>
public Point Offset { set; get; }
/// <summary>
/// 识别区域的大小
/// </summary>
public Size Size { set; get; }
/// <summary>
/// 模式,用于替换
/// </summary>
public string Mode { set; get; } = "";
}
public class OcrSpace
{
public int ID { set; get; }
public PointF CodeCenter { set; get; }
public float CodeAngle { set; get; }
public Point OcrOffset { set; get; }
public Size OcrSize { set; get; }
}
/// <summary>
/// 物料模板
/// </summary>
public class MaterialTemplate
{
public List<LabelRect> LabelRect = new List<LabelRect>();
public string FilePath { get; set; } = "";
public string ImagePath { get; set; } = "";
public Bitmap Image { get; set; } = null;
public string Name { get; set; } = "";
}
/// <summary>
/// 追溯模板
/// </summary>
public class TraceTemp
{
public string Name;
public string MateTemp;
public Bitmap MateImage;
public string MateImageName;
public string LabelTemp;
public Bitmap LabelImage;
public string LabelImageName;
public List<BarCode> Code = new List<BarCode>();
}
}