FrmEditMPoint.cs
17.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
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
using log4net;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
using TSA_V.frmBoard;
using TSA_V.LoadCSVLibrary;
using static TSA_V.Common.LogUtil;
namespace TSA_V
{
public partial class FrmEditMPoint : FrmBase
{
public BoardInfo updateBoardInfo = null;
public List<SMTPointInfo> selectPoints = new List<SMTPointInfo>();
public List<SMTPointInfo> resultPointList=new List<SMTPointInfo> ();
/// <summary>
/// 1=点位偏移旋转。2=复制,3=删除。
/// </summary>
public int EditType = 0;
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public FrmEditMPoint()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
LanguagePro();
}
public void SetBoard(BoardInfo board, List<SMTPointInfo> selectPoints)
{
updateBoardInfo = board;
this.selectPoints = selectPoints;
LoadBoardInfo();
}
public void LoadForm()
{
}
private void LanguagePro()
{
this.dataGridViewImageColumn1.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Up, "上升");
this.dataGridViewImageColumn2.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Down, "下降");
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
int rowIndex = dgvList.SelectedRows[0].Index;
string partNum = dgvList.Rows[rowIndex].Cells[this.Column_PartNum.Name].Value.ToString();
string name = dgvList.Rows[rowIndex].Cells[this.Column_Name.Name].Value.ToString();
}
else
{
}
this.Column_PartNum.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Num, "位号");
this.Column_Name.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Name, "物料编号");
this.Column_positionNum.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_Position, "料盘位置");
this.Column_NeedSoldering.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_NWeld, "需焊接");
this.Column_WeldTemp.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_WeldTemp, "焊接温度");
this.Column_WeldTime.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_WeldTime, "焊接时间");
this.Column_NeedCheck.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_NCheck, "需检测");
this.Column_CheckOK.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Check, "校准点");
this.Column_CheckOK.Visible = false;
this.Column_disable.Visible = false;
this.Column_disable.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Disable, "禁用");
this.Column_Notes.HeaderText = ResourceCulture.GetString("注意事项", "注意事项");
this.Column_Notes.Width = 140;
}
private void FrmBoardInfo_Load(object sender, EventArgs e)
{
int count = dgvList.Columns.Count;
for (int i = 0; i < count; i++)
{
if (i.Equals(Column_disable.Index))
{
dgvList.Columns[i].ReadOnly = false;
}
else
{
dgvList.Columns[i].ReadOnly = true;
}
dgvList.Columns[i].Selected = false;
}
rdbChange();
}
private void LoadBoardInfo()
{
this.dgvList.Rows.Clear();
foreach (SMTPointInfo point in selectPoints)
{
if (point != null)
{
dgvList.Rows.Add(setPointInfo(null, point));
}
}
}
private DataGridViewRow setPointInfo(DataGridViewRow view, SMTPointInfo point)
{
if (view == null)
{
view = new DataGridViewRow();
view.CreateCells(dgvList);
}
view.Tag = point;
view.Cells[0].Value = point.pointNum.ToString();
view.Cells[1].Value = point.TagNo.ToString();
view.Cells[2].Value = point.PN;
view.Cells[3].Value = point.PositionX.ToString();
view.Cells[4].Value = point.PositionY.ToString();
view.Cells[5].Value = point.NodePositionX.ToString();
view.Cells[6].Value = point.NodePositionY.ToString();
view.Cells[7].Value = point.PositionNum.ToString();
view.Cells[8].Value = point.NeedSoldering;
view.Cells[9].Value = point.WeldTemp;
view.Cells[10].Value = point.WeldTime;
view.Cells[11].Value = point.NeedCheck;
view.Cells[12].Value = point.CheckOK;
view.Cells[Column_PointType.Index].Value = point.PointType;
view.Cells[Column_PointSizeX.Index].Value = point.PointSizeX;
view.Cells[Column_PointSizeY.Index].Value = point.PointSizeY;
view.Cells[Column_PenWidth.Index].Value = point.PenWidth;
view.Cells[Column_ShowText.Index].Value = point.ShowText;
view.Cells[Column_disable.Index].Value = point.Disable;
view.Cells[col_IsEdit.Index].Value=point.IsEdit;
view.Cells[col_Polarities.Index].Value = point.PolaritiesType;
if (updateBoardInfo != null)
{
ComponetInfo com = CSVBomManager.GetCom(updateBoardInfo.bomName, point);
if (com != null)
{
view.Cells[Column_Notes.Index].Value = com.Notes;
view.Cells[7].Value = com.PositionNum.ToString();
}
}
view.DefaultCellStyle.ForeColor = Color.Black;
view.DefaultCellStyle.BackColor = Color.White;
if (point.Disable)
{
view.DefaultCellStyle.ForeColor = Color.Gray;
view.DefaultCellStyle.BackColor = Color.LightGray;
}
if (point.CheckOK)
{
view.DefaultCellStyle.ForeColor = Color.Red;
}
return view;
}
private bool isRun = false;
private bool IsProcess = false;
private void timer_Elapsed(object sender, EventArgs e)
{
if (IsProcess) { return; }
IsProcess = true;
IsProcess = false;
}
private void FrmBoardInfo_FormClosing(object sender, FormClosingEventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1 && e.ColumnIndex >= 0)
{
}
}
private void btnSave_Click(object sender, EventArgs e)
{
resultPointList = new List<SMTPointInfo>();
EditType = 0;
string msg = "";
string showMsg = "";
if (rdbPianyi.Checked)
{
EditType = 1;
double xUpdate = FormUtil.getDoubleValue(txtXUpdate);
double yUpdate = FormUtil.getDoubleValue(txtYUpdate);
int angle = FormUtil.GetIntValue(txtAngle);
if (xUpdate.Equals(0) && yUpdate.Equals(0) && angle.Equals(0))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PWUpdateValue, "请输入修正值或角度!"));
txtXUpdate.Focus();
return;
}
if (xUpdate != 0 || yUpdate != 0)
{
showMsg = ResourceCulture.GetString(ResourceCulture.PWSureUPdateXY, "程序【{0}】的组装位置将修正,偏移量X[{1}],Y[{2}],是否确定修正", updateBoardInfo.boardName, xUpdate, yUpdate);
}
if (angle != 0)
{
showMsg += "\r\n" + ResourceCulture.GetString(ResourceCulture.PWSureXuanzhuan, "以左下角为基准顺时针旋转{0}度?", angle);
}
DialogResult result = MessageBox.Show(showMsg, ResourceCulture.GetString(ResourceCulture.Sure, "确认"), MessageBoxButtons.YesNo);
if (!result.Equals(DialogResult.Yes))
{
return;
}
msg = $"坐标偏移/旋转: X={xUpdate},Y={yUpdate},angle={angle},列表: ";
foreach (SMTPointInfo point in selectPoints)
{
double oldX = point.PositionX;
double oldY = point.PositionY;
if (xUpdate != 0 || yUpdate != 0)
{
point.PositionX += xUpdate;
point.PositionY += yUpdate;
}
if (angle != 0)
{
DPoint pointR =XYConvertManager.RotatePoint(point.PositionX, point.PositionY, 0, 0, angle);
point.PositionX = pointR.X;
point.PositionY = pointR.Y;
}
resultPointList.Add(point);
msg += "\r\n" + point.TagNo + "_" + point.PN + $",原坐标:{oldX},{oldY}, 新坐标:{point.PositionX},{point.PositionY}";
}
selectPoints = new List<SMTPointInfo>(resultPointList);
LogUtil.info(msg);
this.DialogResult = DialogResult.OK;
this.Close();
}
else if (rdbCopy.Checked)
{
EditType = 2;
int row = FormUtil.GetIntValue(txtRow);
int col = FormUtil.GetIntValue(txtCol);
int rowValue = FormUtil.GetIntValue(txtRowS);
int colValue = FormUtil.GetIntValue(txtColS);
showMsg = ResourceCulture.GetString(ResourceCulture.PWSureCopyPoint, "确定复制?目标为{0}行,{1}列,X间距={2}, Y间距={3}", row,col, colValue, rowValue);
DialogResult result = MessageBox.Show(showMsg, ResourceCulture.GetString(ResourceCulture.Sure, "确认"), MessageBoxButtons.YesNo);
if (!result.Equals(DialogResult.Yes))
{
return;
}
//复制
List<SMTPointInfo> oldPoints = new List<SMTPointInfo>();
resultPointList = new List<SMTPointInfo>();
msg = $"点位复制: 目标为{row}行,{col}列,X间距={colValue}, Y间距={rowValue},列表: ";
foreach (SMTPointInfo point in selectPoints)
{
msg += "\r\n" + point.TagNo + "_" + point.PN + $",更改组={1}";
point.Group = 1;
oldPoints.Add(point);
}
List<SMTPointInfo> checkOKList = updateBoardInfo.getCalPoint();//如果已经校准过点位,直接校准新点位
int nextNum = updateBoardInfo.GetNextPNum();
selectPoints = new List<SMTPointInfo>(oldPoints);
for (int currRow = 1; currRow <= row; currRow++)
{
for (int currCol = 1; currCol <= col; currCol++)
{
int index = (currRow - 1) * col + currCol;
if (index == 1)
{
continue;
}
foreach (SMTPointInfo point in oldPoints)
{
SMTPointInfo newPoint = new SMTPointInfo(point);
newPoint.pointNum = nextNum;
newPoint.PositionX = newPoint.PositionX + (currCol - 1) * colValue;
newPoint.PositionY = newPoint.PositionY + rowValue * (currRow - 1);
newPoint.Group = index;
newPoint.TagNo = point.TagNo + "-" + index;
newPoint.PointSizeX = point.PointSizeX;
newPoint.CheckOK = false;
newPoint = XYConvertManager.CalPointNodePosition(newPoint, checkOKList);
msg += "\r\n" + point.pointName + "_" + point.PN + $",更改组={index} , X={newPoint.PositionX},Y={newPoint.PositionY},投影X={newPoint.NodePositionX},投影Y={newPoint.NodePositionY}";
resultPointList.Add(newPoint);
nextNum++;
}
}
}
LogUtil.info(msg);
this.DialogResult = DialogResult.OK;
this.Close();
}
else if (rdbDelete.Checked)
{
EditType = 3;
DialogResult result = MessageBox.Show($"确定删除?", ResourceCulture.GetString(ResourceCulture.Sure, "确认"), MessageBoxButtons.YesNo);
if (!result.Equals(DialogResult.Yes))
{
msg = $"点位删除: 列表: ";
foreach (SMTPointInfo point in selectPoints)
{
msg += "\r\n" + point.TagNo + "_" + point.PN + $" ";
resultPointList.Add(point);
}
LogUtil.info(msg);
this.DialogResult = DialogResult.OK;
this.Close();
}
}
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SaveOk, "保存成功!"));
Close();
}
private void button1_Click(object sender, EventArgs e)
{
Close();
}
private void dgvList_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void dgvList_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
{
if ((e.Clicks < 2) && (e.Button == MouseButtons.Left))
{
if ((e.ColumnIndex == -1) && (e.RowIndex > -1))
this.dgvList.DoDragDrop(dgvList.Rows[e.RowIndex], DragDropEffects.Move);
}
}
int selectionIdx = -1;
private void dgvList_DragDrop(object sender, DragEventArgs e)
{
try
{
int idx = GetRowFromPoint(e.X, e.Y);
if (idx < 0)
{
return;
}
if (e.Data.GetDataPresent(typeof(DataGridViewRow)))
{
DataGridViewRow row = (DataGridViewRow)e.Data.GetData(typeof(DataGridViewRow));
dgvList.Rows.Remove(row);
selectionIdx = idx;
if (idx >= dgvList.Rows.Count - 1)
{
dgvList.Rows.Add(row);
}
else
{
dgvList.Rows.Insert(idx, row);
}
}
}
catch (Exception ex)
{
LogUtil.error("拖拽出错:" + ex.ToString());
}
}
private int GetRowFromPoint(int x, int y)
{
y = y + VerticalScrollIndex;
for (int i = 0; i < dgvList.RowCount; i++)
{
Rectangle rec = dgvList.GetRowDisplayRectangle(i, false);
if (dgvList.RectangleToScreen(rec).Contains(x, y))
return i;
}
return -1;
}
int VerticalScrollIndex = 0, HorizontalOffset = 0;
private void rdbPianyi_CheckedChanged(object sender, EventArgs e)
{
rdbChange();
}
private void rdbXuanzhuan_CheckedChanged(object sender, EventArgs e)
{
rdbChange();
}
private void rdbCopy_CheckedChanged(object sender, EventArgs e)
{
rdbChange();
}
private void rdbChange()
{
groupCopy.Enabled = true;
//groupXuanzhuan.Enabled = rdbXuanzhuan.Checked;
groupPianYi.Enabled = true;
groupDelete.Enabled = true;
txtXUpdate.Enabled= rdbPianyi.Checked;
txtYUpdate.Enabled = rdbPianyi.Checked;
txtAngle.Enabled = rdbPianyi.Checked;
txtCol.Enabled = rdbCopy.Checked;
txtRow.Enabled = rdbCopy.Checked;
txtColS.Enabled = rdbCopy.Checked;
txtRowS.Enabled = rdbCopy.Checked;
}
private void button1_Click_1(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
rdbChange();
}
private void dgvList_Scroll(object sender, ScrollEventArgs e)
{
try
{
if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
{
VerticalScrollIndex = e.NewValue;
}
else if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
{
HorizontalOffset = e.NewValue;
}
}
catch { }
}
}
}