FrmAddBoard.cs
19.7 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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
using PUSICANLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
using TSA_V.LoadCSVLibrary;
namespace TSA_V
{
public partial class FrmAddBoard : FrmBase
{
public FrmAddBoard()
{
InitializeComponent();
string str7 = ResourceCulture.GetString(ResourceCulture.Type7, "极性_上方");
string str8 = ResourceCulture.GetString(ResourceCulture.Type8, "极性_下方");
string str9 = ResourceCulture.GetString(ResourceCulture.Type9, "极性_左方");
string str10 = ResourceCulture.GetString(ResourceCulture.Type10, "极性_右方");
string[] typeList=new string[] {
"1=●",
"2=✚",
"3=┃",
"4=━━",
"5=□",
"6=○",
"7="+str7,
"8="+str8,
"9="+str9,
"10="+str10
};
xyMoveControl1.loadTypeList(typeList);
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnSave_Click(object sender, EventArgs e)
{
BoardInfo board = SaveBoard();
if (board != null)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SaveOk,"保存成功!"));
this.Close();
}
}
private bool GetFormBoard(BoardInfo board)
{
board.originX = xyMoveControl1.XValue;
board.originY = xyMoveControl1.YValue;
board.boardName = FormUtil.getValue(txtBoardName);
board.orgType = 4;
board.orgType = cmbOrgType.SelectedIndex + 1;
if (board.boardName.Equals(""))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WritePName, "请输入程序名称!"));
cmbBomList.Focus();
return false ;
}
if (!(BoardManager.getBoardByName(board.boardName) == null))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PNameExist, "程序名【{0}】已存在,请重新输入!", board.boardName));
txtBoardName.Focus();
return false ;
}
if (cmbBomList.SelectedIndex < 0)
{
//MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ChoiceLibrary, "请选择元器件库!"));
txtBoardName.Focus();
return false ;
}
board.boardCode = FormUtil.getValue(txtCode);
board.imgName = FormUtil.getValue(txtImagePath);
if (board.imgName.Equals(""))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ImportPImage, "请导入程序图片!"));
this.btnOpenFile.Focus();
return false ;
}
board.boardLength = FormUtil.GetIntValue(txtBoardW);
board.boardWidth = FormUtil.GetIntValue(txtBoardL);
if (board.boardLength <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteLength, "请输入宽度!"));
this.txtBoardW.Focus();
return false ;
}
if (board.boardWidth <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteWidth, "请输入长度!"));
this.txtBoardL.Focus();
return false ;
}
board.LineWidth = FormUtil.GetIntValue(txtLineWidth);
if (board.LineWidth <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteLineWidth, "请输入线体宽度!"));
this.txtLineWidth.Focus();
return false;
}
if (!TSAVBean.IsValidPosition(board.originX, board.originY))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WPointP, "请输入有效的右下角坐标!"));
//this.txtRobotX.Focus();
return false ;
}
if (rdbSelCom.Checked)
{
board.bomName = cmbBomList.Text;
}
else
{
board.bomName = board.boardName;
if (txtCsvFileName.Text.Equals("") || uploadPointList.Count <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.UploadFile, "请上传程序文件!"));
this.likSelCsvFile.Focus();
return false;
}
}
string imagePath = Path.GetFullPath(txtImagePath.Text);
ProcessPictures.copyImage(Application.StartupPath, board.boardName, imagePath);
board.imgName = board.boardName + Path.GetExtension(openFileDialogImg.FileName);
return true;
}
private BoardInfo SaveBoard()
{
try
{
BoardInfo board = new BoardInfo();
bool result = GetFormBoard(board);
if (!result)
{
return null;
}
List<ComponetInfo> comList = this.uploadPointList;
if (rdbSelCom.Checked)
{
comList = CSVBomManager.GetComList(board.bomName);
}
if (chbSort.Checked)
{
comList = (from m in comList orderby m.PositionX ascending, m.PositionY ascending select m).ToList<ComponetInfo>();
}
List<SMTPointInfo> smtList = new List<SMTPointInfo>();
int i = 1;
double xNodeChange = TSAVBean.X_ChangeValue;
double yNodeChange = TSAVBean.Y_ChangeValue;
LogUtil.info("新增【"+board.boardName+"】,根据换算参数计算红外坐标(转换系数:x["+xNodeChange + "]y["+yNodeChange+"])");
double pianYiX = 0, pianYiY = 0;
int xFangxiang = 1;
int yFangxiang = -1;
int pointSizeX = xyMoveControl1.PointSizeX;
int pointSizeY = xyMoveControl1.PointSizeY;
int pointType = xyMoveControl1.PointType;
int penWidth = xyMoveControl1.PenWidth;
foreach (ComponetInfo com in comList)
{
double x =com.PositionX+ pianYiX;
double y = com.PositionY+pianYiY;
if (board.orgType.Equals(2))
{
x = com.PositionX;
y = board.boardLength - y;
}
else if (board.orgType.Equals(3))
{
x = board.boardWidth - com.PositionX;
y = com.PositionY;
}
else if (board.orgType.Equals(4))
{
y = board.boardLength - y;
x = board.boardWidth - x;
}
SMTPointInfo point = new SMTPointInfo(i, com.TagNo, com.PN, x, y, com.PositionNum,pointType,pointSizeX,pointSizeY,penWidth);
y = board.boardLength - y;
x = board.boardWidth - x;
double nodeXValue = (board.originX + (double)(x * xNodeChange*xFangxiang));
double nodeYValue = (board.originY - (double)(y * yNodeChange*yFangxiang));
if (board.orgType.Equals(2))
{
nodeXValue = (board.originX + (double)(x * xNodeChange * xFangxiang));
nodeYValue = (board.originY + (double)(y * yNodeChange * yFangxiang));
}else if (board.orgType.Equals(3))
{
nodeXValue = (board.originX - (double)(x * xNodeChange * xFangxiang));
nodeYValue = (board.originY - (double)(y * yNodeChange * yFangxiang));
}
else if (board.orgType.Equals(4))
{
nodeXValue = (board.originX - (double)(x * xNodeChange * xFangxiang));
nodeYValue = (board.originY + (double)(y * yNodeChange * yFangxiang));
}
if (TSAVBean.IsValidPosition(nodeXValue, nodeYValue))
{
point.NodePositionX = nodeXValue;
point.NodePositionY = nodeYValue;
}
else
{
point.NodePositionX = board.originX;
point.NodePositionY = board.originY;
LogUtil.error("新增【" + board.boardName + "】元器件【" + point.PN + "】导入【" + com.PositionX + "," + com.PositionY + "】红点【" + nodeXValue + "," + nodeYValue + "】超出移动范围,默认为右下角坐标!");
}
point.WeldTemp = 360;
point.WeldTime = 3;
point.NeedCheck = true;
point.NeedSoldering = true;
LogUtil.info("新增【" + board.boardName + "】元器件【" + point.PN + "】导入【" + com.PositionX + "," + com.PositionY + "】图片【" + point.PositionX+","+point.PositionY+ "】红点【" + nodeXValue + "," + nodeYValue + "】");
smtList.Add(point);
i++;
}
if (!rdbSelCom.Checked)
{
board.bomName =CSVBomManager. AutoAddBomList(board.bomName, new List<ComponetInfo>(comList));
LogUtil.info("新增【" + board.boardName + "】自动创建bom【" + board.bomName + "】");
}
board.smtList = smtList;
board.boardId = BoardManager.GetNextId();
BoardManager.Add(board);
return board;
}
catch (Exception ex)
{
MessageBox.Show( ResourceCulture.GetString(ResourceCulture.SaveError, "保存失败!"));
LogUtil.error("添加程序出错:" + ex.ToString());
return null;
}
}
private void btnStart_Click(object sender, EventArgs e)
{
BoardInfo board = SaveBoard();
if (board!=null)
{
this.Visible = false;
FrmBoardInfo.instance.Show();
FrmBoardInfo.instance.SetBoard(board);
FrmBoardInfo.instance.LoadForm();
this.Close();
}
}
private void btnOpenFile_Click(object sender, EventArgs e)
{
openFileDialogImg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
openFileDialogImg.DefaultExt = "jpg|gif|bmp|png|jpeg";
openFileDialogImg.Filter = "jpg|*.jpg|gif|*.gif|bmp|*.bmp|png|*.png|jpeg|*.jpeg";
string directory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//桌面路径
openFileDialogImg.InitialDirectory = directory;
if (openFileDialogImg.ShowDialog() == DialogResult.OK)
{
openFileDialogImg.Tag = true;
this.txtImagePath.Text= openFileDialogImg.FileName;
}
}
private void FrmAddBoard_Load(object sender, EventArgs e)
{
cmbOrgType.SelectedIndex = 2;
this.timer1.Enabled = true;
LoadComList();
LanguageProcess();
//xyMoveControl1.XValue = ConfigAppSettings.GetDoubleValue(Setting_Init.BOARD_ORIGIN_X);
//xyMoveControl1.YValue = ConfigAppSettings.GetDoubleValue(Setting_Init.BOARD_ORIGIN_Y);
this.cmbOrgType.Items.Clear();
if (ResourceCulture.CurrLanguage.Equals(ResourceCulture.English))
{
this.cmbOrgType.Items.AddRange(new object[] {
"TOP LEFT CORNER",
"LEFT BOTTOM",
"TOP RIGHT CORNER",
"BOTTOM RIGHT CORNER"});
}
else if (ResourceCulture.CurrLanguage.Equals(ResourceCulture.China))
{
this.cmbOrgType.Items.AddRange(new object[] {
"左上角",
"左下角",
"右上角",
"右下角"});
}
cmbOrgType.SelectedIndex = 2;
SetScreen();
xyMoveControl1.ShowPointEvent += XyMoveControl1_ShowPointEvent;
xyMoveControl1.XValue = TSAVBean.X_Max/2;
xyMoveControl1.YValue = TSAVBean.Y_Max/2;
xyMoveControl1.ShowText = "";
rdbUpload.Checked = true;
ComChange(true);
}
private bool XyMoveControl1_ShowPointEvent(ProjectorPInfo p)
{
FrmProjectorScreen.instance.ClearPoint();
FrmProjectorScreen.instance.ShowPoint(p);
return true;
}
private void LoadComList()
{
List<string> keyList = new List<string>(LoadCSVLibrary.CSVBomManager.allComMap.Keys);
this.cmbBomList.Items.Clear();
foreach (string key in keyList)
{
this.cmbBomList.Items.Add(key);
}
if (keyList.Count > 0)
{
this.cmbBomList.SelectedIndex = 0;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
xyMoveControl1.UpdateStatus();
}
private void ComChange(bool isUploadSel)
{
txtCsvFileName.Visible = isUploadSel;
likDownFile.Visible = isUploadSel;
likSelCsvFile.Visible = isUploadSel;
cmbBomList.Visible = !isUploadSel;
}
private void rdbUpload_CheckedChanged(object sender, EventArgs e)
{
ComChange(rdbUpload.Checked);
}
private void rdbSelCom_CheckedChanged(object sender, EventArgs e)
{
ComChange(!rdbSelCom.Checked);
}
private void btnOpenFile_Click(object sender, LinkLabelLinkClickedEventArgs e)
{
openFileDialogImg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
openFileDialogImg.DefaultExt = "jpg|gif|bmp|png|jpeg";
openFileDialogImg.Filter = "jpg|*.jpg|gif|*.gif|bmp|*.bmp|png|*.png|jpeg|*.jpeg";
string directory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//桌面路径
openFileDialogImg.InitialDirectory = directory;
if (openFileDialogImg.ShowDialog() == DialogResult.OK)
{
openFileDialogImg.Tag = true;
this.txtImagePath.Text = openFileDialogImg.FileName;
}
}
private void likDownFile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
sfd.FileName = ResourceCulture.GetString("元器件库模板");
sfd.Filter = @"csv|*.csv";
DialogResult result = sfd.ShowDialog();
if (result.Equals(DialogResult.OK))
{
string filePath = sfd.FileName;
string sourcePath = Application.StartupPath + ConfigAppSettings.GetValue(Setting_Init.Componet_Template, "_"+CurrLanguage);
//string sourcePath = Application.StartupPath + ConfigAppSettings.GetValue(Setting_Init.Componet_Template);
if (File.Exists(filePath))
{
File.Delete(filePath);
}
//复制文件
File.Copy(sourcePath, filePath);
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.DemoSave, "模板已保存在:") + filePath);
}
}
private string getListMsg(List<string> list)
{
string msg = "";
foreach(string str in list)
{
msg += str + ",";
}
return msg.Substring(0, msg.Length - 1);
}
private List<ComponetInfo> uploadPointList = new List<ComponetInfo>();
private void likSelCsvFile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
openFileDialogCsv.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
this.openFileDialogCsv.Filter = "csv|*.csv";
DialogResult result = this.openFileDialogCsv.ShowDialog();
if (!result.Equals(DialogResult.OK))
{
return;
}
string fileName = this.openFileDialogCsv.FileName;
uploadPointList = CSVBomManager.ReadFile(fileName);
if (uploadPointList.Count <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SelectRightFile, "请选择正确的文件(文件格式可以通过下载模板获得)"));
}
Dictionary<string, List<string>> PnPositonMap = new Dictionary<string, List<string>>();
Dictionary<string, List<string>> positionPNMap = new Dictionary<string, List<string>>();
foreach (ComponetInfo com in uploadPointList)
{
if (!PnPositonMap.ContainsKey(com.PN))
{
PnPositonMap.Add(com.PN, new List<string>());
}
if (!PnPositonMap[com.PN].Contains(com.PositionNum))
{
PnPositonMap[com.PN].Add(com.PositionNum);
}
if (!positionPNMap.ContainsKey(com.PositionNum))
{
positionPNMap.Add(com.PositionNum, new List<string>());
}
if (!positionPNMap[com.PositionNum].Contains(com.PN))
{
positionPNMap[com.PositionNum].Add(com.PN);
}
}
foreach (string pnKey in PnPositonMap.Keys)
{
List<string> positions = new List<string>(PnPositonMap[pnKey]);
if (positions.Count > 1)
{
result = MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SureImportPosition,
"元器件【{0}】配置多个位置【{1}】,是否确定导入?", pnKey, getListMsg(positions), "",
MessageBoxButtons.OKCancel)); ;
if (!result.Equals(DialogResult.OK))
{
uploadPointList = new List<ComponetInfo>();
return;
}
}
}
foreach (string key in positionPNMap.Keys)
{
List<string> pnList = new List<string>(positionPNMap[key]);
if (pnList.Count > 1)
{
result = MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SureImportPn,
"位置【{0}】配置多个元器件【{1}】,是否确定导入?", key, getListMsg(pnList), "",
MessageBoxButtons.OKCancel)); ;
if (!result.Equals(DialogResult.OK))
{
uploadPointList = new List<ComponetInfo>();
return;
}
}
}
this.txtCsvFileName.Text = fileName;
}
}
}