FrmAddBoard.cs
12.1 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
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();
}
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, "程序名【" + 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.bomName = cmbBomList.Text;
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 ;
}
string imagePath = Path.GetFullPath(txtImagePath.Text);
ProcessPictures.copyImage(Application.StartupPath, board.boardName, imagePath);
board.imgName = board.boardName + Path.GetExtension(openFileDialog1.FileName);
return true;
}
private BoardInfo SaveBoard()
{
try
{
BoardInfo board = new BoardInfo();
bool result = GetFormBoard(board);
if (!result)
{
return null;
}
List<ComponetInfo> 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.PartNum, com.ComponentName, 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.pointName + "】导入【" + com.PositionX + "," + com.PositionY + "】红点【" + nodeXValue + "," + nodeYValue + "】超出移动范围,默认为右下角坐标!");
}
point.WeldTemp = 360;
point.WeldTime = 3;
point.NeedCheck = true;
point.NeedSoldering = true;
LogUtil.info("新增【" + board.boardName + "】元器件【" + point.pointName + "】导入【" + com.PositionX + "," + com.PositionY + "】图片【" + point.PositionX+","+point.PositionY+ "】红点【" + nodeXValue + "," + nodeYValue + "】");
smtList.Add(point);
i++;
}
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)
{
openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
openFileDialog1.DefaultExt = "jpg|gif|bmp|png|jpeg";
openFileDialog1.Filter = "jpg|*.jpg|gif|*.gif|bmp|*.bmp|png|*.png|jpeg|*.jpeg";
string directory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//桌面路径
openFileDialog1.InitialDirectory = directory;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
openFileDialog1.Tag = true;
this.txtImagePath.Text= openFileDialog1.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 = "";
}
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();
}
}
}