FrmBoardList.cs
14.6 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
using log4net;
using URSoldering.DeviceLibrary;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using URSoldering.Common;
using System.Drawing.Drawing2D;
using System.IO;
using System.Text;
namespace URSoldering.Client
{
public partial class FrmBoardList : FrmBase
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public FrmBoardList()
{
InitializeComponent();
}
private void FrmBoard_Load(object sender, EventArgs e)
{
LoadCom();
}
private void AddColumn(string text, int width)
{
ColumnHeader chName = new ColumnHeader();
chName.Text = text; //设置列标题
chName.Width = width; //设置列宽度
chName.TextAlign = HorizontalAlignment.Left; //设置列的对齐方式
this.listPoint.Columns.Add(chName); //将列头添加到ListView控件。
}
private void LoadCom()
{
List<BoardInfo> newList = (from m in BoardManager.boardList orderby m.PartNumber ascending, m.boardName ascending select m).ToList<BoardInfo>();
cmbBoardList.DataSource = null;
cmbBoardList.DataSource = newList;
cmbBoardList.DisplayMember = "boardName";
cmbBoardList.ValueMember = "boardId";
if (newList.Count > 0)
{
cmbBoardList.SelectedIndex = 0;
}
this.listPoint.Columns.Clear();
AddColumn("焊点名称", 120);
AddColumn("类型", 90);
AddColumn("预热温度", 90);
AddColumn("焊接温度", 90);
AddColumn("初始送丝", 90);
AddColumn("送丝量", 80);
}
private void btnSave_Click(object sender, EventArgs e)
{
int updateIndex = cmbBoardList.SelectedIndex;
if (cmbBoardList.Text != "" && updateIndex >= 0)
{
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
FrmBoardInfo frm = new FrmBoardInfo(board);
this.Visible = false;
frm.ShowDialog();
this.Visible = true;
LoadCom();
if (updateIndex.Equals(cmbBoardList.SelectedIndex))
{
LoadBoard();
}
preId = -1;
}
else
{
MessageBox.Show("请选择程序!");
}
}
private int pointHight = 14;
private void btnLook_Click(object sender, EventArgs e)
{
LoadBoard();
this.panel1.Refresh();
}
private void LoadBoard()
{
if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
{
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
txtBoardName.Text = board.boardName;
txtLength.Text = board.boardLength.ToString();
txtWidth.Text = board.boardWidth.ToString();
txtPointCount.Text = board.pointList.Count.ToString();
txtMianji.Text = (board.boardLength * board.boardWidth).ToString();
txtAOIName.Text = board.AoiFileName;
loadPictureBoxSize(board);
LoadPoint(board);
}
}
int preId = -1;
public object ResourceCulture { get; private set; }
private void LoadPoint(BoardInfo board)
{
if (preId >= 0 && preId.Equals(board.boardId))
{
return;
}
preId = board.boardId;
this.listPoint.Items.Clear();
int i = 0;
foreach (WeldPointInfo point in board.pointList)
{
ListViewItem lvi = new ListViewItem();
lvi.ImageIndex = i;
lvi.Text = point.pointName;
lvi.SubItems.Add(point.TypeValue);
lvi.SubItems.Add(point.preheatTemperature.ToString() + "°C");
lvi.SubItems.Add(point.weldTemperature.ToString() + "°C");
lvi.SubItems.Add((point.startSendWireSpeed * point.startSendWireTime).ToString() + "mm");
lvi.SubItems.Add((point.sendWireTime * point.sendWireSpeed).ToString() + "mm");
this.listPoint.Items.Add(lvi);
i++;
}
}
private void btnNew_Click(object sender, EventArgs e)
{
FrmBoardInfo info = new FrmBoardInfo(null);
this.Visible = false;
info.ShowDialog();
this.Visible = true;
LoadCom();
preId = -1;
}
private void cmbBoardList_SelectedIndexChanged(object sender, EventArgs e)
{
LoadBoard();
}
private void btnDel_Click(object sender, EventArgs e)
{
if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
{
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
if (MessageBox.Show("确认要删除程序【" + board.boardName + "】吗?", "删除确认",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question).Equals(DialogResult.OK))
{
BoardManager.Delete(board);
MessageBox.Show("删除程序【" + board.boardName + "】成功!");
LoadCom();
preId = -1;
}
}
else
{
MessageBox.Show("请选择程序!");
}
}
private void GetPicPointByUrPoint(BoardInfo boardInfo, URPointValue point, out float x, out float y)
{
int width = picBoard.Width;
int height = picBoard.Height;
URPointValue APointValue = boardInfo.APointValue;
URPointValue BPointValue = boardInfo.BPointValue;
URPointValue CPointValue = boardInfo.CPointValue;
URPointValue DPointValue = boardInfo.DPointValue;
//判断AD点是否有效
if (APointValue.IsValid() && DPointValue.IsValid())
{
x = (float)((point.X - APointValue.X) * width / (DPointValue.X - APointValue.X));
y = (float)((point.Y - APointValue.Y) * height / (DPointValue.Y - APointValue.Y));
}
else if (BPointValue.IsValid() && CPointValue.IsValid())
{
x = (float)((point.X - BPointValue.X) * width / (CPointValue.X - BPointValue.X));
y = (float)((point.Y - CPointValue.Y) * height / (BPointValue.Y - CPointValue.Y));
}
else
{
x = -1;
y = -1;
}
}
private void loadPictureBoxSize(BoardInfo board)
{
picBoard.SizeMode = PictureBoxSizeMode.StretchImage;
List<WeldPointInfo> pointList = board.pointList;
int width = board.boardWidth;
int height = board.boardLength;
int xishu = 10;
picBoard.Width = width * xishu;
picBoard.Height = height * xishu;
if (picBoard.Width > panBoard.Width)
{
picBoard.Height = height * xishu * panBoard.Width / (width * xishu);
picBoard.Width = panBoard.Width;
}
if (picBoard.Height > panBoard.Height)
{
picBoard.Width = width * xishu * panBoard.Height / (height * xishu);
picBoard.Height = panBoard.Height;
}
int locationX = picBoard.Location.X;
int locationY = picBoard.Location.Y;
locationX = (panBoard.Size.Width - picBoard.Width) / 2;
picBoard.Location = new Point(locationX, locationY);
//显示点
Graphics g = (picBoard).CreateGraphics();
picBoard.Image = board.GetImage();
picBoard.Refresh();
Graphics grfx = picBoard.CreateGraphics();
float preX = 0;
float preY = 0;
int index = 0;
foreach (WeldPointInfo weld in pointList)
{
int pointHight = 16;
float x, y;
GetPicPointByUrPoint(board, weld.GetURPoint(), out x, out y);
LogUtil.debug("显示焊点:X【" + x + "】Y【" + y + "】,坐标X【" + weld.RobotX + "】坐标Y【" + weld.RobotY + "】");
g.FillEllipse(Brushes.Red, x - pointHight / 2, y - pointHight / 2, pointHight, pointHight);
if (index > 0)
{
Pen p = new Pen(Color.Red, 1);
//中间点
float xCenter = (preX + x) / 2;
float yCenter = (preY + y) / 2;
System.Drawing.Drawing2D.AdjustableArrowCap lineCap = new System.Drawing.Drawing2D.AdjustableArrowCap(6, 8, true);
Pen RedPen = new Pen(Color.Red, 1);
RedPen.CustomEndCap = lineCap;
grfx.DrawLine(RedPen, preX, preY, xCenter, yCenter);
grfx.DrawLine(p, preX, preY, x, y);
}
//写字
g.DrawString(weld.pointName, new Font("Arial ", 10, FontStyle.Bold), Brushes.Red, x - pointHight / 2, y + pointHight / 2 + 2);
preX = x;
preY = y;
index++;
}
grfx.SmoothingMode = SmoothingMode.HighQuality;
g.DrawString("A ", new Font("Arial ", 10, FontStyle.Bold), Brushes.White, 3, 3);
g.DrawString("B ", new Font("Arial ", 10, FontStyle.Bold), Brushes.White, 3, picBoard.Height - 20);
g.DrawString("C ", new Font("Arial ", 10, FontStyle.Bold), Brushes.White, picBoard.Width - 18, 0);
g.DrawString("D ", new Font("Arial ", 10, FontStyle.Bold), Brushes.White, picBoard.Width - 18, picBoard.Height - 20);
g.Dispose();
}
private void FrmBoardList_Shown(object sender, EventArgs e)
{
LoadBoard();
}
private void btnBack_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnCopy_Click(object sender, EventArgs e)
{
if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
{
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
DialogResult result = MessageBox.Show("复制后的程序料号不变,是否确定复制?", "确定", MessageBoxButtons.YesNo);
if (result.Equals(DialogResult.Yes))
{
FrmBoardCopy copy = new FrmBoardCopy(board);
DialogResult saveResult = copy.ShowDialog();
if (saveResult.Equals(DialogResult.OK))
{
LoadCom();
}
}
}
else
{
MessageBox.Show("请选择程序!");
}
}
private void btnExport_Click(object sender, EventArgs e)
{
if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
{
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
SaveFileDialog sfd = new SaveFileDialog();
sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
sfd.FileName = "程序-" + board.boardName + "-"+DateTime.Now.ToString("yyyy:MM:dd:HH:mm").Replace(":","");
sfd.Filter = @"data|*.data";
DialogResult result = sfd.ShowDialog();
if (result.Equals(DialogResult.OK))
{
string filePath = sfd.FileName;
{
if (File.Exists(filePath))
{
File.Delete(filePath);
}
File.WriteAllText(filePath, JsonHelper.SerializeObject(board), Encoding.GetEncoding("gbk"));
MessageBox.Show("成功导出程序【" + board.boardName + "】到文件:\r\n" + filePath, "提示");
}
}
}
}
private void btnImport_Click(object sender, EventArgs e)
{
openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
openFileDialog1.Filter = @"data|*.data";
DialogResult result = this.openFileDialog1.ShowDialog();
if (result.Equals(DialogResult.OK))
{
string fileName = this.openFileDialog1.FileName;
string[] lines = File.ReadAllLines(fileName, Encoding.GetEncoding("gbk"));
if (lines.Length <= 0)
{
MessageBox.Show("解析程序失败,请选择正确文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
bool isNeedUpdate = false;
BoardInfo board = BoardManager.StringToBoard(lines[0],out isNeedUpdate);
if (board == null)
{
MessageBox.Show("解析程序失败,请选择正确文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (BoardManager.getBoardByName(board.boardName) != null)
{
MessageBox.Show("导入失败:程序名【" + board.boardName+"】已存在","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
string oldName = ConfigAppSettings.GetValue(Setting_Init.BOARD_IMAGE_DEFAULT);
string newName = board.boardName + Path.GetExtension(oldName);
string configPath = ConfigAppSettings.GetValue(Setting_Init.BOARD_IMAGE_PATH);
string oldPath = Application.StartupPath + "/" + configPath + "/" + oldName;
string newPath = Application.StartupPath + "/" + configPath + "/" + newName;
if (File.Exists(oldPath))
{
File.Copy(oldPath, newPath, true);
}
board.imgName = newName;
board.boardId = BoardManager.GetNextId();
BoardManager.Add(board);
MessageBox.Show("程序【" + board.boardName + "】导入成功","提示");
LoadCom();
preId = -1;
}
}
}
}