FrmBoardInfo.cs
54.3 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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
using log4net;
using MetroFramework.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Drawing2D;
using PUSICANLibrary;
using TSA_V;
using TSA_V.LoadCSVLibrary;
using AccAOI;
using System.Runtime.ExceptionServices;
namespace TSA_V
{
public partial class FrmBoardInfo : FrmBase
{
public static FrmBoardInfo instance = new FrmBoardInfo();
private bool isNew = false;
public BoardInfo updateBoardInfo = null;
PointDisplay display = new PointDisplay();
private bool isFinishLoad = false;
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private FrmBoardInfo()
{
InitializeComponent(); display.SetPic(picBoard, panBoard);
CheckForIllegalCrossThreadCalls = false;
}
public void SetBoard(BoardInfo board)
{
if (board != null)
{
updateBoardInfo = board;
this.isNew = false;
}
else
{
this.isNew = true;
}
if (isNew)
{
this.Text = ResourceCulture.GetString(this.ClassName + "_Text", "新增程序");
}
else
{
this.Text = "【" + board.boardName + "】";
}
}
public void LoadForm()
{
isFinishLoad = false;
chbNormal.Checked = true;
chbShowName.Checked = true;
if (isNew == false)
{
AOIManager.LoadAOIFile(cmbAOIFile, updateBoardInfo.AOIProName);
LoadBoardInfo();
}
else
{
AOIManager.LoadAOIFile(cmbAOIFile);
updateBoardInfo = new BoardInfo();
picBoard.Image = updateBoardInfo.GetImage();
// loadPictureBoxSize();
}
LOGGER.Info("load image " + picBoard.Name);
txtBoardName.Focus();
if (TSAVBean.Work.IsWorking)
{
LogUtil.error("进入程序界面,发现TSAVBean还在工作模式,停止工作");
TSAVBean.StopWork();
}
if (TSAVBean.Status <= TSAVStatus.Wait)
{
LogUtil.error("进入程序界面,还未启动组装信息机,开始启动组装信息机");
TSAVBean.StartRun();
}
TSAVBean.IsCanStepMove = true;
timer1.Start();
isFinishLoad = true;
if (dgvList.Rows.Count > 0)
{
// int index = dgvList.Rows.Count - 1;
// dgvList.Rows[0].Selected = true;
UpdateSelPoint(0);
}
}
private void LanguagePro()
{
this.下降ToolStripMenuItem.Text = ResourceCulture.GetString(ResourceCulture.ItemText_Down, "下降");
this.dataGridViewImageColumn1.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Up, "上升");
this.dataGridViewImageColumn2.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Down, "下降");
this.上升ToolStripMenuItem.Text = ResourceCulture.GetString(ResourceCulture.ItemText_Up, "上升");
this.删除ToolStripMenuItem.Text = ResourceCulture.GetString(ResourceCulture.ItemText_Delete, "删除");
this.详情ToolStripMenuItem.Text = ResourceCulture.GetString(ResourceCulture.ItemText_Detial, "详情");
this.测试位置ToolStripMenuItem.Text = ResourceCulture.GetString(ResourceCulture.ItemText_MoveTest, "移动测试");
this.更新为组装坐标ToolStripMenuItem.Text = ResourceCulture.GetString(ResourceCulture.ItemText_UpdateN, "更新为组装位置");
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_getPosition.Text = ResourceCulture.GetString(ResourceCulture.Col_UpdateP, "更新坐标");
this.Column_getPosition.ToolTipText = ResourceCulture.GetString(ResourceCulture.Col_UpdateP, "更新坐标");
this.Column_getPosition.HeaderText = ResourceCulture.GetString(ResourceCulture.Col_UpdateP, "更新坐标");
this.Column_MoveTest.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_MoveTest, "移动测试");
this.Column_MoveTest.Text = ResourceCulture.GetString(ResourceCulture.ItemText_MoveTest, "移动测试");
this.Column_MoveTest.ToolTipText = ResourceCulture.GetString(ResourceCulture.ItemText_MoveTest, "移动测试");
this.Column_btnDetail.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Detial, "详情");
this.Column_btnDetail.Text = ResourceCulture.GetString(ResourceCulture.ItemText_Detial, "详情");
this.Column_Del.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Delete, "删除");
this.Column_Del.Text = ResourceCulture.GetString(ResourceCulture.ItemText_Delete, "删除");
this.Column_Del.ToolTipText = ResourceCulture.GetString(ResourceCulture.ItemText_Delete, "删除");
//this.Column_Up.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Up, "上升");
//this.Column_Up.Text = ResourceCulture.GetString(ResourceCulture.ItemText_Up, "上升");
//this.Column_Up.ToolTipText = ResourceCulture.GetString(ResourceCulture.ItemText_Up, "上升");
//this.Column_Down.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Down, "下降");
//this.Column_Down.Text = ResourceCulture.GetString(ResourceCulture.ItemText_Down, "下降");
//this.Column_Down.ToolTipText = ResourceCulture.GetString(ResourceCulture.ItemText_Down, "下降");
this.Column_CheckOK.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Check, "校准点");
this.Column_disable.HeaderText = ResourceCulture.GetString(ResourceCulture.ItemText_Disable, "禁用");
this.Column_Notes.HeaderText = ResourceCulture.GetString("注意事项", "注意事项");
}
private void FrmBoardInfo_Load(object sender, EventArgs e)
{
picBoard.SizeMode = PictureBoxSizeMode.StretchImage;
chbNormal.Checked = true;
chbShowName.Checked = true;
lblAoi.Visible = TSAVBean.IsNeedAOI;
cmbAOIFile.Visible = TSAVBean.IsNeedAOI;
btnConfigAOI.Visible = TSAVBean.IsNeedAOI;
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;
}
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (!isShownOk)
{
return base.ProcessCmdKey(ref msg, keyData); // 其他键按默认处理
}
//// 按快捷键Ctrl+S执行按钮的点击事件方法
//if (btnUp.Enabled.Equals(true) && btnDown.Enabled.Equals(true) && btnLeft.Enabled.Equals(true) && btnRight.Enabled.Equals(true))
//{
//向上
if (keyData.Equals(Keys.Up) || keyData.Equals(Keys.MButton | Keys.Space))
{
DgvSelectRowUp();
}
//向下
else if (keyData.Equals(Keys.Down) || keyData.Equals(Keys.Back | Keys.Space))
{
DgvSelectRowDown();
}
//向左
else if (keyData.Equals(Keys.Left) || keyData.Equals(Keys.LButton | Keys.MButton | Keys.Space))
{
//PicBoardBlowUp();
}
//向右
else if (keyData.Equals(Keys.Right) || keyData.Equals(Keys.LButton | Keys.RButton | Keys.MButton | Keys.Space))
{
//PicBoardShrink();
}
//}
return base.ProcessCmdKey(ref msg, keyData); // 其他键按默认处理
}
/// <summary>
/// 选择的行上移
/// </summary>
private void DgvSelectRowUp()
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
int allCount = dgvList.SelectedRows.Count;
int rowIndex = dgvList.SelectedRows[0].Index;
rowIndex--;
if (rowIndex < 0)
{
rowIndex = allCount - 1;
}
dgvList.Rows[rowIndex].Selected = true;
}
}
/// <summary>
/// 选择的行下移
/// </summary>
private void DgvSelectRowDown()
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
int allCount = dgvList.SelectedRows.Count;
int rowIndex = dgvList.SelectedRows[0].Index;
rowIndex++;
if (rowIndex >= allCount)
{
rowIndex = 0;
}
dgvList.Rows[rowIndex].Selected = true;
}
}
private double CurrBeiLu = 1;
private void LoadBoardInfo()
{
txtBoardName.Text = updateBoardInfo.boardName;
txtBoardW.Text = updateBoardInfo.boardLength.ToString();
txtBoardL.Text = updateBoardInfo.boardWidth.ToString();
txtCode.Text = updateBoardInfo.boardCode.ToString();
picBoard.Image = updateBoardInfo.GetImage();
txtLineWidth.Text = updateBoardInfo.LineWidth.ToString();
//txtOriginX.Text = updateBoardInfo.originX.ToString();
//txtOriginY.Text = updateBoardInfo.originY.ToString();
picBoard.SizeMode = PictureBoxSizeMode.StretchImage;
loadPictureBoxSize();
picBoard.Tag = false;
this.dgvList.Rows.Clear();
foreach (SMTPointInfo point in updateBoardInfo.smtList)
{
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.Cells[0].Value = point.pointNum.ToString();
view.Cells[1].Value = point.PartNum.ToString();
view.Cells[2].Value = point.pointName;
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;
if (updateBoardInfo != null)
{
ComponetInfo com = CSVBomManager.GetCom(updateBoardInfo.bomName, point.PartNum);
if (com != null)
{
view.Cells[Column_Notes.Index].Value = com.Notes;
}
}
if (point.CheckOK)
{
view.DefaultCellStyle.ForeColor = Color.Red;
}
else
{
view.DefaultCellStyle.ForeColor = Color.Black;
}
return view;
}
private bool isRun = false;
private bool IsProcess = false;
private void timer_Elapsed(object sender, EventArgs e)
{
if (IsProcess) { return; }
IsProcess = true;
//if (TSAVBean.Status.Equals(TSAVStatus.Wait))
//{
// string msg = ResourceCulture.GetString(ResourceCulture.DeviceNotOkMsg, "设备未连接");
// if (!lblMsg.Text.Equals(msg))
// {
// lblMsg.Text = msg;
// btnGoHome.Enabled = false;
// }
//}
//else if (TSAVBean.Status.Equals(TSAVStatus.Reset))
//{
// string msg = ResourceCulture.GetString(ResourceCulture.DeviceInGohome, "设备正在原点返回中");
// if (!lblMsg.Text.Equals(msg))
// {
// lblMsg.Text = msg;
// btnGoHome.Enabled = true;
// }
//}
//else if (TSAVBean.Status.Equals(TSAVStatus.Runing))
//{
// string msg = ResourceCulture.GetString(ResourceCulture.DeviceInWork, "设备工作中");
// if (!lblMsg.Text.Equals(msg))
// {
// lblMsg.Text = msg;
// btnGoHome.Enabled = true;
// }
//}
IsProcess = false;
}
private void FrmBoardInfo_FormClosing(object sender, FormClosingEventArgs e)
{
FrmProjectorScreen.instance.ClearPoint();
timer1.Stop();
TSAVBean.IsCanStepMove = false;
this.Visible = false;
FrmBoardList.instance.Show();
FrmBoardList.instance.LoadCom();
e.Cancel = true;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1 && e.ColumnIndex >= 0)
{
string name = this.dgvList.Columns[e.ColumnIndex].Name;
if (name.Equals(this.Column_Del.Name))
{
DeleteRow(e.RowIndex);
}
else if (name.Equals(this.Column_getPosition.Name))
{
UpdateRow(e.RowIndex);
}
else if (name.Equals(this.Column_MoveTest.Name))
{
MoveTest(e.RowIndex);
}
else if (name.Equals(this.Column_btnDetail.Name))
{
showDetail(e.RowIndex);
}
else if (name.Equals(this.Column_Down.Name))
{
RowDown(e.RowIndex);
}
else if (name.Equals(this.Column_Up.Name))
{
RowUp(e.RowIndex);
}
}
}
private void RowDown(int rowIndex)
{
try
{
isFinishLoad = false;
if ( rowIndex >= dgvList.Rows.Count - 1)
{
return;
}
DataGridViewRow row = dgvList.Rows[rowIndex];
dgvList.Rows.Remove(dgvList.Rows[rowIndex]);
if (rowIndex >= dgvList.Rows.Count - 1)
{
dgvList.Rows.Add(row);
}
else
{
dgvList.Rows.Insert(rowIndex + 1, row);
};
dgvList.Rows[rowIndex + 1].Selected = true;
}
catch (Exception ex)
{
LogUtil.error("行下降出错:" + ex.ToString());
}
finally
{
isFinishLoad = true;
}
}
private void RowUp(int rowIndex)
{
try
{
isFinishLoad = false;
if (rowIndex <= 0)
{
return;
}
DataGridViewRow row = dgvList.Rows[rowIndex];
dgvList.Rows.Remove(dgvList.Rows[rowIndex]);
dgvList.Rows.Insert(rowIndex - 1, row);
dgvList.Rows[rowIndex - 1].Selected = true;
}
catch (Exception ex)
{
LogUtil.error("行上升出错:" + ex.ToString());
}
finally
{
isFinishLoad = true;
}
}
private void MoveTest(int rowIndex)
{
//移动测试
double x = Double.Parse(dgvList.Rows[rowIndex].Cells[this.Column_NodeX.Name].Value.ToString());
double y = Double.Parse(dgvList.Rows[rowIndex].Cells[this.Column_NodeY.Name].Value.ToString());
int type = Int32.Parse(dgvList.Rows[rowIndex].Cells[this.Column_PointType.Name].Value.ToString());
int sizeX = Int32.Parse(dgvList.Rows[rowIndex].Cells[this.Column_PointSizeX.Name].Value.ToString());
int sizeY = Int32.Parse(dgvList.Rows[rowIndex].Cells[this.Column_PointSizeY.Name].Value.ToString());
int penWidth = Int32.Parse(dgvList.Rows[rowIndex].Cells[this.Column_PenWidth.Name].Value.ToString());
string name = dgvList.Rows[rowIndex].Cells[this.Column_Name.Name].Value.ToString();
string showText = dgvList.Rows[rowIndex].Cells[this.Column_ShowText.Name].Value.ToString();
//判断位置是否超出范围
if (!TSAVBean.IsValidPosition(x, y))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PositionError, "位置:{0},{1}无效,请检查配置是否正确?", x, y),
ResourceCulture.GetString(ResourceCulture.MsgTitle, "提示?"), MessageBoxButtons.OK);
}
else
{
FrmProjectorScreen.instance.ClearPoint();
FrmProjectorScreen.instance.ShowPoint(new ProjectorPInfo((int)x, (int)y,type,sizeX,sizeY,penWidth,showText));
}
}
private void UpdateRow(int rowIndex)
{
int x_colIndex = dgvList.Columns[this.Column_NodeX.Name].Index;
int y_colIndex = dgvList.Columns[Column_NodeY.Name].Index;
dgvList.Rows[rowIndex].Cells[this.Column_NodeX.Name].Value = FrmProjectorScreen.instance.LastX;
dgvList.Rows[rowIndex].Cells[this.Column_NodeY.Name].Value =FrmProjectorScreen.instance.LastY;
dgvList.UpdateCellValue(x_colIndex, rowIndex);
dgvList.UpdateCellValue(y_colIndex, rowIndex);
}
private void DeleteRow(int rowIndex)
{
if (MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SureDelete, "确认要删除该行数据吗?"),
ResourceCulture.GetString(ResourceCulture.MsgTitle, "提示?"),
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) != DialogResult.OK)
{
return;
}
else
{
this.dgvList.Rows.RemoveAt(rowIndex);
if (isFinishLoad && this.txtBoardW.Text.Trim() != "" && this.txtBoardL.Text.Trim() != "")
{
loadPictureBoxSize();
}
}
}
private int orgType = 1;
private void btnSave_Click(object sender, EventArgs e)
{
BoardInfo board = new BoardInfo();
if (isNew)
{
board = new BoardInfo();
board.boardId = BoardManager.GetNextId();
}
else
{
board = this.updateBoardInfo;
}
board.boardName = FormUtil.getValue(txtBoardName);
board.boardLength = FormUtil.GetIntValue(txtBoardW);
board.boardWidth = FormUtil.GetIntValue(txtBoardL);
board.LineWidth = FormUtil.GetIntValue(txtLineWidth);
board.boardCode = FormUtil.getValue(txtCode);
board.orgType = orgType;
board.AOIProName = cmbAOIFile.Text;
if (board.boardName.Equals(""))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WritePName, "请输入程序名称"));
txtBoardName.Focus();
return;
}
//验证名字是否重复
foreach (BoardInfo obj in BoardManager.boardList)
{
if (obj.boardId.Equals(board.boardId))
{
continue;
}
else if (obj.boardName.Equals(board.boardName))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PNameExist, "程序名【{0}】已存在,请重新输入程序名称!", board.boardName));
txtBoardName.Focus();
return;
}
}
if (board.boardLength <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteLength, "请输入宽度"));
txtBoardW.Focus();
return;
}
if (board.boardWidth <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteWidth, "请输入长度"));
txtBoardL.Focus();
return;
}
if (board.LineWidth <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteLineWidth, "请输入线体宽度"));
txtLineWidth.Focus();
return;
}
if (picBoard.Image == null)
{
//MessageBox.Show("请添加程序图片");
//this.btnOpenFile.Focus();
//return;
}
else
{
if (openFileDialog1.FileName != "")
{
string imagePath = Path.GetFullPath(openFileDialog1.FileName);
ProcessPictures.copyImage(Application.StartupPath, board.boardName, imagePath);
board.imgName = board.boardName + Path.GetExtension(openFileDialog1.FileName);
}
}
board.smtList = new List<SMTPointInfo>();
List<SMTPointInfo> pointList = allPointInfo();
//board.planNeedTime = UpdateTime(pointList);
//判断名称是否重复
List<string> nameList = new List<string>();
int index = 0;
foreach (SMTPointInfo point in pointList)
{
if (point.NeedSoldering)
{
if (point.WeldTemp <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteRightTemp, "请输入正确的焊接温度!"));
dgvList.Rows[index].Selected = true;
return;
}
if (point.WeldTime <= 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteRightTime, "请输入正确的焊接时间!"));
dgvList.Rows[index].Selected = true;
return;
}
}
nameList.Add(point.pointName);
index++;
}
if (pointList != null)
{
board.smtList = pointList;
}
else
{
return;
}
if (isNew)
{
BoardManager.Add(board);
}
else
{
BoardManager.Update(board);
}
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SaveOk, "保存成功!"));
Close();
}
/// <summary>
/// 获取dataGridView里所有点信息
/// </summary>
/// <returns></returns>
private List<SMTPointInfo> allPointInfo()
{
List<SMTPointInfo> pointList = new List<SMTPointInfo>();
foreach (DataGridViewRow row in dgvList.Rows)
{
if (row != null)
{
SMTPointInfo point = getRowPointInfo(row);
if (point != null)
{
pointList.Add(point);
}
}
}
return pointList;
}
private SMTPointInfo getRowPointInfo(DataGridViewRow row)
{
SMTPointInfo point = new SMTPointInfo();
try
{
if (row.Cells[Column_Name.Name].Value == null)
{
return null;
}
point.pointName = row.Cells[Column_Name.Name].Value.ToString();
point.pointNum = Convert.ToInt32(row.Cells[this.Column_pointNum.Name].Value.ToString());
point.PartNum = row.Cells[this.Column_PartNum.Name].Value.ToString();
point.PositionX = Math.Round(Convert.ToDouble(row.Cells[this.Column_X.Name].Value.ToString()), 3);
point.PositionY = Math.Round(Convert.ToDouble(row.Cells[this.Column_Y.Name].Value.ToString()), 3);
point.NodePositionX = Convert.ToDouble(row.Cells[this.Column_NodeX.Name].Value.ToString());
point.NodePositionY = Convert.ToDouble(row.Cells[this.Column_NodeY.Name].Value.ToString());
point.PositionNum = row.Cells[this.Column_positionNum.Name].Value.ToString();
point.NeedCheck = Convert.ToBoolean(row.Cells[this.Column_NeedCheck.Name].Value.ToString());
point.NeedSoldering = Convert.ToBoolean(row.Cells[this.Column_NeedSoldering.Name].Value.ToString());
point.WeldTime = Convert.ToDouble(row.Cells[this.Column_WeldTime.Name].Value.ToString());
point.WeldTemp = Convert.ToInt32(row.Cells[this.Column_WeldTemp.Name].Value.ToString());
point.CheckOK = Convert.ToBoolean(row.Cells[this.Column_CheckOK.Name].Value.ToString());
point.PointSizeX = Convert.ToInt32(row.Cells[this.Column_PointSizeX.Name].Value.ToString());
point.PointSizeY = Convert.ToInt32(row.Cells[this.Column_PointSizeY.Name].Value.ToString());
point.PointType = Convert.ToInt32(row.Cells[this.Column_PointType.Name].Value.ToString());
point.PenWidth = Convert.ToInt32(row.Cells[this.Column_PenWidth.Name].Value.ToString());
point.ShowText = (row.Cells[this.Column_ShowText.Name].Value.ToString());
point.Disable = Convert.ToBoolean(row.Cells[this.Column_disable.Name].Value.ToString());
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "保存数据出错:" + ex.ToString());
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.CheckZZh, "请检查组装信息数据是否正确!"));
return null;
}
return point;
}
private void button1_Click(object sender, EventArgs e)
{
Close();
}
private void Close()
{
timer1.Stop();
TSAVBean.IsCanStepMove = false;
this.Visible = false;
FrmBoardList.instance.LoadCom();
FrmBoardList.instance.Visible = true;
}
protected override void OnVisibleChanged(EventArgs e)
{
base.OnVisibleChanged(e);
if (this.IsDisposed)
{
this.Close();
}
}
/// <summary>
/// 打开文件夹,选取图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnOpenFile_Click(object sender, EventArgs e)
{
openFileDialog1.DefaultExt = "gif|jpg|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;
picBoard.Image = Image.FromFile(openFileDialog1.FileName);
if (this.txtBoardL.Text.Trim() != "" && this.txtBoardW.Text.Trim() != "")
{
loadPictureBoxSize();
}
}
else
{
openFileDialog1.FileName = "";
}
}
private void UpdateSelPoint(int rowIndex, List<SMTPointInfo> pointList = null)
{
selectIndex = rowIndex;
loadPictureBoxSize(pointList);
}
private float imageXiShu = 1;
private int selectIndex = 0;
private void loadPictureBoxSize(List<SMTPointInfo> pointList = null)
{
CurrBeiLu = 1;
//picBoard.SizeMode = PictureBoxSizeMode.AutoSize;
if (pointList == null)
{
pointList = allPointInfo();
}
int width = 200;
int height = 200;
if (this.txtBoardL.Text.Trim() != "" && (this.txtBoardW.Text.Trim() != ""))
{
width = Convert.ToInt32(this.txtBoardL.Text.Trim());
height = Convert.ToInt32(this.txtBoardW.Text.Trim());
}
display.selectIndex = selectIndex;
display.SetImage(picBoard.Image);
display.ShowName = chbShowName.Checked;
display.ImageNormal = chbNormal.Checked;
display.LoadPoint(width, height, pointList);
imageXiShu = display.imageXiShu;
}
private void txtBoardLength_TextChanged(object sender, EventArgs e)
{
if (isFinishLoad && this.txtBoardW.Text.Trim() != "" && this.txtBoardL.Text.Trim() != "")
{
loadPictureBoxSize();
}
}
private void txtBoardWidth_TextChanged(object sender, EventArgs e)
{
if (isFinishLoad && this.txtBoardL.Text.Trim() != "" && this.txtBoardW.Text.Trim() != "")
{
loadPictureBoxSize();
}
}
private bool isShownOk = false;
private void FrmBoardInfo_Shown(object sender, EventArgs e)
{
//SetSkin(this);
loadPictureBoxSize();
LanguageProcess();
LanguagePro();
isShownOk = true;
}
private void NextProcess(int currIndex, SMTPointInfo smt = null)
{
try
{
if (dgvList.Rows.Count > currIndex)
{
if (smt != null)
{
setPointInfo(dgvList.Rows[currIndex - 1], smt);
}
dgvList.Rows[currIndex].Selected = true;
}
}catch(Exception ex)
{
LogUtil.error("NextProcess出错:"+ex.ToString());
}
}
private void showDetail(int rowIndex)
{
int index = dgvList.FirstDisplayedScrollingRowIndex;
DataGridViewRow row = dgvList.Rows[rowIndex];
SMTPointInfo smtInfo = getRowPointInfo(row);
if (smtInfo == null)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.NoZZh, "未找到组装信息信息!"));
return;
}
List<SMTPointInfo> allPoint = allPointInfo();
FrmPointInfo fwpi = new FrmPointInfo( updateBoardInfo, allPoint, rowIndex,NextProcess);
fwpi.AoiProgramName = cmbAOIFile.Text;
fwpi.PicImage = picBoard.Image;
DialogResult result = fwpi.ShowDialog();
//if (result.Equals(DialogResult.OK))
if (fwpi.IsUpdate)
{
dgvList.Rows.Clear();
allPoint = fwpi.PointList;
foreach (SMTPointInfo point in allPoint)
{
if (point != null)
{
dgvList.Rows.Add(setPointInfo(null, point));
}
}
rowIndex = fwpi.CurrIndex;
dgvList.Rows[rowIndex].Selected = true;
//smtInfo = fwpi.smpPointInfo;
//setPointInfo(dgvList.Rows[rowIndex], smtInfo);
if (isFinishLoad && this.txtBoardW.Text.Trim() != "" && this.txtBoardL.Text.Trim() != "")
{
loadPictureBoxSize();
}
SetListCurrCell(index);
}
}
private void 保存组装信息ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (m_MouseDownPointX.Equals(0) || m_MouseDownPointY.Equals(0))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SelectZZh, "请点击要保存的组装信息"));
return;
}
double x = m_MouseDownPointX / imageXiShu;
double y = m_MouseDownPointY / imageXiShu;
x = Math.Round(x, 0, MidpointRounding.AwayFromZero);
y = Math.Round(y, 0, MidpointRounding.AwayFromZero);
//double NodeX = TSAVBean.Axis_X.LastVoltage;
//double NodeY = TSAVBean.Axis_Y.LastVoltage;
double NodeX = FrmProjectorScreen.instance.LastX;
double NodeY = FrmProjectorScreen.instance.LastY;
LogUtil.info("新增组装信息:X【" + m_MouseDownPointX + "】Y【" + m_MouseDownPointY + "】,坐标X【" + x + "】坐标Y【" + y + "】");
AddNewPoint(x, y, NodeX, NodeY);
}
private void AddNewPoint(double x, double y, double nodeX, double nodeY)
{
SMTPointInfo smtInfo = new SMTPointInfo();
string name = "P" + (dgvList.Rows.Count + 1);
FrmPointInfo fwpi = new FrmPointInfo( name, x, y, nodeX, nodeY);
fwpi.AoiProgramName = cmbAOIFile.Text;
fwpi.PicImage = picBoard.Image;
DialogResult result = fwpi.ShowDialog();
if (result.Equals(DialogResult.OK))
{
smtInfo = fwpi.smtPointInfo;
DataGridViewRow view = new DataGridViewRow();
view.CreateCells(dgvList);
setPointInfo(view, smtInfo);
dgvList.Rows.Add(view);
if (isFinishLoad && this.txtBoardW.Text.Trim() != "" && this.txtBoardL.Text.Trim() != "")
{
loadPictureBoxSize();
}
}
}
private double m_MouseDownPointX = 0f;
private double m_MouseDownPointY = 0f;
private void picBoard_MouseDown(object sender, MouseEventArgs e)
{
base.OnMouseDown(e);
int x = e.Location.X;
int y = e.Location.Y;
m_MouseDownPointX = (double)x / CurrBeiLu;
m_MouseDownPointY = (double)y / CurrBeiLu;
if (isFinishLoad && this.picBoard.Image != null)
{
// loadPictureBoxSize();
//画十字
Graphics grfx = picBoard.CreateGraphics();
int width = 10;
grfx.DrawLine(new Pen(Color.White, 2), x, y - width, x, y + width);
grfx.DrawLine(new Pen(Color.White, 2), x - width, y, x + width, y);
grfx.Dispose();
}
if (e.Button == MouseButtons.Left)
{
this.contextMenuStrip1.Show((PictureBox)sender, new Point(e.X, e.Y)); //有的换位button1
}
}
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 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 { }
}
private void dgvList_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
try
{
if (selectionIdx > -1 && selectIndex <= (dgvList.Rows.Count - 1))
{
dgvList.Rows[selectionIdx].Selected = true;
dgvList.CurrentCell = dgvList.Rows[selectionIdx].Cells[0];
selectionIdx = -1;
}
}
catch (Exception ex)
{
}
}
private void dgvList_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (e.RowIndex >= 0)
{
this.dgvList.ClearSelection();
dgvList.Rows[e.RowIndex].Selected = true;
dgvList.CurrentCell = dgvList.Rows[e.RowIndex].Cells[e.ColumnIndex];
contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
}
}
}
private void 上升ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
RowUp(dgvList.SelectedRows[0].Index);
}
}
private void 下降ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
RowDown(dgvList.SelectedRows[0].Index);
}
}
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
DeleteRow(dgvList.SelectedRows[0].Index);
//liUpdateTime_LinkClicked(null, null);
}
}
private void 更新坐标ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
UpdateRow(dgvList.SelectedRows[0].Index);
}
}
private void 测试位置ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
MoveTest(dgvList.SelectedRows[0].Index);
}
}
private void 详情ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
showDetail(dgvList.SelectedRows[0].Index);
}
}
private void btnUpdateRow_Click(object sender, EventArgs e)
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
UpdateRow(dgvList.SelectedRows[0].Index);
//liUpdateTime_LinkClicked(null, null);
}
}
private void btnSetBasePoint_Click(object sender, EventArgs e)
{
//double x = TSAVBean.Axis_X.LastVoltage;
//double y = TSAVBean.Axis_Y.LastVoltage;
//double x = FrmProjectorScreen.instance.LastX;
//double y = FrmProjectorScreen.instance.LastY;
//DialogResult result = MessageBox.Show("确定保存 X:" + x + ",Y:" + y + " 为基准点?", "提示", MessageBoxButtons.YesNo);
////DialogResult result = MessageBox.Show("确定保存 X:" + txtRobotX.Text + ",Y:" + txtRobotY.Text + " 为基准点?", "确定重置基准点", MessageBoxButtons.YesNo);
//if (result.Equals(DialogResult.Yes))
//{
// this.txtOriginX.Text = x.ToString();
// this.txtOriginY.Text = y.ToString();
// ConfigAppSettings.SaveValue(Setting_Init.BOARD_ORIGIN_X, txtOriginX.Text);
// ConfigAppSettings.SaveValue(Setting_Init.BOARD_ORIGIN_Y, txtOriginY.Text);
//}
}
private void 重置基准点ToolStripMenuItem_Click(object sender, EventArgs e)
{
btnSetBasePoint_Click(null, null);
}
private DateTime preProTime = DateTime.Now;
private void picBoard_MouseMove(object sender, MouseEventArgs e)
{
TimeSpan span = DateTime.Now - preProTime;
if (span.TotalMilliseconds > 200)
{
preProTime = DateTime.Now;
int x = e.Location.X;
int y = e.Location.Y;
double positionX = Math.Round((double)x / CurrBeiLu, 2);
double positionY = Math.Round((double)y / CurrBeiLu, 2);
lblMousePosition.Text = " X: " + positionX + " ,Y: " + positionY;
}
}
private void 记录为组装坐标ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dgvList.SelectedRows != null && dgvList.SelectedRows.Count > 0)
{
int rowIndex = dgvList.SelectedRows[0].Index;
if (m_MouseDownPointX.Equals(0) || m_MouseDownPointY.Equals(0))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SelectImagePosition, "请先选择图片中的位置"));
return;
}
double x = m_MouseDownPointX / imageXiShu;
double y = m_MouseDownPointY / imageXiShu;
x = Math.Round(x, 0, MidpointRounding.AwayFromZero);
y = Math.Round(y, 0, MidpointRounding.AwayFromZero);
LogUtil.info("新增组装信息:X【" + m_MouseDownPointX + "】Y【" + m_MouseDownPointY + "】,坐标X【" + x + "】坐标Y【" + y + "】");
int x_colIndex = dgvList.Columns[this.Column_X.Name].Index;
int y_colIndex = dgvList.Columns[Column_Y.Name].Index;
dgvList.Rows[rowIndex].Cells[this.Column_X.Name].Value = x.ToString();
dgvList.Rows[rowIndex].Cells[this.Column_Y.Name].Value = y.ToString();
dgvList.UpdateCellValue(x_colIndex, rowIndex);
dgvList.UpdateCellValue(y_colIndex, rowIndex);
int newIndex = rowIndex + 1;
if (dgvList.Rows.Count > newIndex)
{
dgvList.Rows[newIndex].Selected = true;
}
// loadPictureBoxSize();
}
}
private void dgvList_SelectionChanged(object sender, EventArgs e)
{
if (isFinishLoad)
{
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();
记录为组装坐标ToolStripMenuItem.Text = ResourceCulture.GetString(ResourceCulture.ItemTextUpdateP, "更新为【{0}-{1}】的位置", partNum, name);
UpdateSelPoint(rowIndex);
}
}
}
private int preIndex = -1;
private void 更新为组装坐标ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (m_MouseDownPointX.Equals(0) || m_MouseDownPointY.Equals(0))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SelectImagePosition, "请先选择图片中的位置"));
return;
}
double x = m_MouseDownPointX / imageXiShu;
double y = m_MouseDownPointY / imageXiShu;
x = Math.Round(x, 0, MidpointRounding.AwayFromZero);
y = Math.Round(y, 0, MidpointRounding.AwayFromZero);
List<SMTPointInfo> pointList = allPointInfo();
int selIndex = -1;
if (preIndex >= 0)
{
selIndex = preIndex + 1;
}
FrmSelectPoint frm = new FrmSelectPoint(pointList, selIndex);
DialogResult result = frm.ShowDialog();
if (result.Equals(DialogResult.OK))
{
int x_colIndex = dgvList.Columns[this.Column_X.Name].Index;
int y_colIndex = dgvList.Columns[Column_Y.Name].Index;
int index = frm.SelectIndex;
preIndex = index;
dgvList.Rows[index].Cells[this.Column_X.Name].Value = x.ToString();
dgvList.Rows[index].Cells[this.Column_Y.Name].Value = y.ToString();
dgvList.UpdateCellValue(x_colIndex, index);
dgvList.UpdateCellValue(y_colIndex, index);
dgvList.Rows[index].Selected = true;
}
}
private void btnSort_Click(object sender, EventArgs e)
{
//根据XY排序
List<SMTPointInfo> allSmt = allPointInfo();
dgvList.Rows.Clear();
//List<SMTPointInfo> newList = (from m in allSmt orderby m.PositionX ascending, m.PositionY ascending select m).ToList<SMTPointInfo>();
List<LoadCSVLibrary.ComponetInfo> list = CSVBomManager.GetComList(updateBoardInfo.bomName);
if (list == null && list.Count <= 0)
{
LogUtil.info("未找到元器件库列表【" + updateBoardInfo.bomName + "】");
return;
}
List<SMTPointInfo> newList = new List<SMTPointInfo>();
List<string> names = new List<string>();
foreach (ComponetInfo com in list)
{
List<SMTPointInfo> smts = (from m in allSmt where m.PartNum.Equals(com.PartNum) select m).ToList<SMTPointInfo>();
if (smts.Count > 0)
{
newList.Add(smts[0]);
}
names.Add(com.PartNum);
}
foreach (SMTPointInfo s in allSmt)
{
if (!names.Contains(s.PartNum))
{
newList.Add(s);
}
}
//List<SMTPointInfo> newList = (from m in allSmt orderby m.PartNum ascending select m).ToList<SMTPointInfo>();
foreach (SMTPointInfo point in newList)
{
if (point != null)
{
dgvList.Rows.Add(setPointInfo(null, point));
}
}
}
private void FrmBoardInfo_VisibleChanged(object sender, EventArgs e)
{
if (this.Visible)
{
LanguagePro();
}
}
private void btnUpdate_Click(object sender, EventArgs e)
{
if (updateBoardInfo != null)
{
double xUpdate = FormUtil.getDoubleValue(txtXUpdate);
double yUpdate = FormUtil.getDoubleValue(txtYUpdate);
if (xUpdate.Equals(0) && yUpdate.Equals(0))
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PWUpdateValue, "请输入修正值!"));
txtXUpdate.Focus();
return;
}
DialogResult result = MessageBox.Show(ResourceCulture.GetString(ResourceCulture.PWSureUPdateXY, "程序【{0}】的组装位置将修正,偏移量X[{1}],Y[{2}],是否确定修正", updateBoardInfo.boardName, xUpdate, yUpdate), ResourceCulture.GetString(ResourceCulture.Sure, "确认"), MessageBoxButtons.YesNo);
if (result.Equals(DialogResult.Yes))
{
List<SMTPointInfo> pointList = allPointInfo();
for (int i = 0; i < pointList.Count; i++)
{
pointList[i].PositionX += xUpdate;
pointList[i].PositionY += yUpdate;
dgvList.Rows[i].Cells[this.Column_X.Name].Value = pointList[i].PositionX;
dgvList.Rows[i].Cells[this.Column_Y.Name].Value = pointList[i].PositionY;
}
updateBoardInfo.smtList = pointList;
LogUtil.info("程序【{0}】的组装位置将修正完成,偏移量X[{1}],Y[{2}] ");
loadPictureBoxSize(pointList);
//重新加载
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.UpdateOk, "图片坐标修正完成!"));
txtXUpdate.Text = 0.ToString();
txtYUpdate.Text = 0.ToString();
}
}
}
private void btnCheck_Click(object sender, EventArgs e)
{
btnCheck.Enabled = false;
LogUtil.info("=======根据校准点进行校准,至少需要两个校准点----------------------------------------------------");
NCalibrationProcess();
btnCheck.Enabled = true;
}
private void SetListCurrCell(int index)
{
try
{
dgvList.FirstDisplayedScrollingRowIndex = index;
}
catch (Exception ex)
{
}
}
private void chbShowName_CheckedChanged(object sender, EventArgs e)
{
loadPictureBoxSize();
}
private void chbNormal_CheckedChanged(object sender, EventArgs e)
{
loadPictureBoxSize();
}
[HandleProcessCorruptedStateExceptions]
private void btnConfigAOI_Click(object sender, EventArgs e)
{
FrmProjectorScreen.instance.ClearPoint();
LogUtil.info("点击 AOI配置,清理投影内容,进入AOI配置界面");
GC.Collect();
try
{
string aoiName = cmbAOIFile.Text;
string path = Application.StartupPath + ConfigAppSettings.GetValue(Setting_Init.AOIFileConfig);
string fileName = "";
if (!aoiName.Equals(""))
{
fileName = path + aoiName;
}
AccAOI.AOIResourceCulture.SetCurrentCulture(ResourceCulture.CurrLanguage);
FrmAoiSetting frm = new FrmAoiSetting(fileName, null, path);
frm.ShowDialog();
AOIManager.LoadAOIFile(cmbAOIFile,cmbAOIFile.Text);
}
catch (Exception ex)
{
LogUtil.error("加载AOI配置界面出错:" + ex.ToString());
}
}
private void btnOpenFile_Click(object sender, LinkLabelLinkClickedEventArgs e)
{
btnOpenFile_Click(null, null);
}
private void llblAllSel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
int cout = dgvList.Rows.Count;
for (int i = 0; i < cout; i++)
{
dgvList.Rows[i].Cells[this.Column_disable.Name].Value = false;
}
}
private void llblAllUSel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
int cout = dgvList.Rows.Count;
for (int i = 0; i < cout; i++)
{
dgvList.Rows[i].Cells[this.Column_disable.Name].Value = true ;
}
}
}
}