FrmAddBoard.cs
35.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
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
using PUSICANLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.IO.Compression;
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.frmBoard;
using TSA_V.LoadCSVLibrary;
using UserFromControl;
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(ResourceCulture.GetPTypes(), ResourceCulture.GetDirTypes(), ResourceCulture.GetXYControlMap());
}
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 ;
}
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 && !IOBase.NoLine)
{
board.LineWidth = board.boardWidth;
txtLineWidth.Text = board.LineWidth.ToString();
//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)
{
if (cmbBomList.SelectedIndex < 0)
{
MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ChoiceLibrary, "请选择元器件库!"));
txtBoardName.Focus();
return false;
}
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(imagePath);
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;
//int PolaritiesType = xyMoveControl1.PolaritiesType;
int pointSizeX =(int) numSizeX.Value;
int pointSizeY = (int)numSizeY.Value;
int pointType = cmbType.SelectedIndex+1;
int penWidth =(int) numPenWidth.Value;
int PolaritiesType = 0;
bool hasTest = chbShowText.Checked;
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;
}
string showText = com.Text;
if (hasTest && showText == "")
{
showText = com.TagNo;
}
SMTPointInfo point = new SMTPointInfo(i, com.TagNo, com.PN, x, y, com.PositionNum, showText, pointType,pointSizeX,pointSizeY,penWidth, PolaritiesType);
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;
if (com.Id!=-1)
{
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 List<PictureBox> pictureBoxes = new List<PictureBox>();
private List<Image> picDefImages = new List<Image>();
private List<Image> picSelImages = new List<Image>();
private void FrmAddBoard_Load(object sender, EventArgs e)
{
labelH.Text = ResourceCulture.GetString("FrmPointInfo_lblSizeWidth_Text", "高↓: ");
label10.Text = ResourceCulture.GetString("FrmPointInfo_lblSizeLength_Text", "宽→:");
lbltype.Text = ResourceCulture.GetString("FrmPointInfo_lbltype_Text", "形状:");
lblLineWidth.Text = ResourceCulture.GetString("FrmPointInfo_lblLineWidth_Text", "画笔宽度:");
this.timer1.Enabled = true;
LoadComList();
LanguageProcess();
xyMoveControl1.Visible = false;
//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 = 1;
SetScreen();
xyMoveControl1.ShowPointEvent += XyMoveControl1_ShowPointEvent;
xyMoveControl1.XValue = TSAVBean.X_Max/2;
xyMoveControl1.YValue = TSAVBean.Y_Max/2;
xyMoveControl1.MaxX =(int) TSAVBean.X_Max;
xyMoveControl1.MaxY = (int)TSAVBean.Y_Max;
xyMoveControl1.ShowText = "";
cmbType.SelectedIndex= 0;
rdbData.Checked = true;
ComChange( );
List<string> list = new List<string>(ResourceCulture.GetPTypes());
cmbType.Items.Clear();
foreach (string str in list)
{
cmbType.Items.Add(str);
}
cmbType.SelectedIndex = 0;
if (IOBase.NoLine)
{
lblWidth.Visible = false;
txtLineWidth.Visible = false;
label9.Visible = false;
}
pictureBoxes.Add(pictureBox1);
pictureBoxes.Add(pictureBox2);
pictureBoxes.Add(pictureBox3);
pictureBoxes.Add(pictureBox4);
pictureBoxes.Add(pictureBox5);
pictureBoxes.Add(pictureBox6);
picDefImages.Add(UserFromControl.ImageManager.imgType1);
picDefImages.Add(UserFromControl.ImageManager.imgType2);
picDefImages.Add(UserFromControl.ImageManager.imgType3);
picDefImages.Add(UserFromControl.ImageManager.imgType4);
picDefImages.Add(UserFromControl.ImageManager.imgType5);
picDefImages.Add(UserFromControl.ImageManager.imgType6);
picSelImages.Add(UserFromControl.ImageManager.imgType1s);
picSelImages.Add(UserFromControl.ImageManager.imgType2s);
picSelImages.Add(UserFromControl.ImageManager.imgType3s);
picSelImages.Add(UserFromControl.ImageManager.imgType4s);
picSelImages.Add(UserFromControl.ImageManager.imgType5s);
picSelImages.Add(UserFromControl.ImageManager.imgType6s);
TypeUpdate(cmbType.SelectedIndex);
}
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( )
{
txtCsvFileName.Visible = false ;
likDownFile.Visible = rdbUpload.Checked;
likSelCsvFile.Visible = rdbUpload.Checked;
cmbBomList.Visible = rdbSelCom.Checked;
linkBomUpload.Visible = rdbData.Checked;
linkDataViewer.Visible = uploadPointList.Count > 0;
}
private void rdbUpload_CheckedChanged(object sender, EventArgs e)
{
ComChange( );
}
private void rdbSelCom_CheckedChanged(object sender, EventArgs e)
{
ComChange( );
}
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";
openFileDialogImg.Filter = "Image Files|*.bmp;*.jpg;*.gif;*.png;*jpeg|gerber Files|*.*";
openFileDialogImg.Multiselect = true;
string directory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//桌面路径
openFileDialogImg.InitialDirectory = directory;
if (openFileDialogImg.ShowDialog() == DialogResult.OK)
{
string[] files = openFileDialogImg.FileNames;
string defPath = Path.GetPathRoot(Application.StartupPath) + @"image\";
FrmImageViewer imageViewer;
//List<string> newFiles = FileUtil.FileProcess(openFileDialog.FileNames);
GerberVS.BoundingBox boxBound = GerberVS.AGerberController.OpenLayers(files, defPath, out string filename);
if (boxBound != null && File.Exists(filename))
{
double x = boxBound.Right - boxBound.Left;
double y = boxBound.Top - boxBound.Bottom;
string msg = $"位置左下角({Math.Round(boxBound.Left, 2)},{Math.Round(boxBound.Bottom, 2)})," +
$"右上角({Math.Round(boxBound.Right, 2)},{Math.Round(boxBound.Top, 2)}):尺寸:{Math.Round(x, 2)}X{Math.Round(y, 2)}";
LogUtil.info($"gerber文件【{string.Join(",", files)}】成功导入到文件:{filename},{msg}");
imageViewer = new FrmImageViewer(filename);
if (!imageViewer.ShowDialog().Equals(DialogResult.Cancel))
{
int l = (int)Math.Round(x);
int w = (int)Math.Round(y);
if (x <= 10 || w <= 10)
{
l = (int)(x * 25.4);
w = (int)(y * 25.4);
}
this.txtImagePath.Text = filename;
int currl = FormUtil.GetIntValue(txtBoardL);
int currw = FormUtil.GetIntValue(txtBoardW);
if (currl <= 0)
{
txtBoardL.Text = l.ToString();
}
if (currw <= 0)
{
txtBoardW.Text = w.ToString();
}
}
}
else
{
List<string> fileTypes = new List<string>() { ".bmp", ".jpg", ".gif", ".png", ".jpeg" };
foreach (string file in files)
{
string ext = Path.GetExtension(file);
if (fileTypes.Contains(ext.ToLower()))
{
imageViewer = new FrmImageViewer(openFileDialogImg.FileName);
if (!imageViewer.ShowDialog().Equals(DialogResult.Cancel))
{
openFileDialogImg.Tag = true;
this.txtImagePath.Text = openFileDialogImg.FileName;
return;
}
}
}
MessageBox.Show(ResourceCulture.GetString("FileError", "文件格式错误 "));
}
}
}
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);
bool proResult= ProcessComData(uploadPointList);
if (proResult)
{
FrmBomViewer frmViewer = new FrmBomViewer(uploadPointList);
DialogResult sureresult = frmViewer.ShowDialog();
if (sureresult.Equals(DialogResult.Cancel))
{
uploadPointList = new List<ComponetInfo>();
txtCsvFileName.Text = "";
linkDataViewer.Visible = false;
}
else
{
this.uploadPointList = frmViewer.dataList;
this.txtCsvFileName.Text = fileName;
linkDataViewer.Visible = true;
}
}
}
private bool ProcessComData(List<ComponetInfo> uploadPointList)
{
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)
{
DialogResult result = MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SureImportPosition,
"元器件【{0}】配置多个位置【{1}】,是否确定导入?", pnKey, getListMsg(positions), "",
MessageBoxButtons.OKCancel)); ;
if (!result.Equals(DialogResult.OK))
{
uploadPointList = new List<ComponetInfo>();
return false ;
}
}
}
foreach (string key in positionPNMap.Keys)
{
List<string> pnList = new List<string>(positionPNMap[key]);
if (pnList.Count > 1)
{
DialogResult result = MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SureImportPn,
"位置【{0}】配置多个元器件【{1}】,是否确定导入?", key, getListMsg(pnList), "",
MessageBoxButtons.OKCancel)); ;
if (!result.Equals(DialogResult.OK))
{
uploadPointList = new List<ComponetInfo>();
return false ;
}
}
}
return true;
}
private bool GerberFileProcess(string[] files)
{
string defPath = Path.GetPathRoot(Application.StartupPath) + @"image\";
//List<string> newFiles = FileUtil.FileProcess(openFileDialog.FileNames);
GerberVS.BoundingBox boxBound = GerberVS.AGerberController.OpenLayers(files, defPath, out string filename);
if (boxBound != null && File.Exists(filename))
{
double x = boxBound.Right - boxBound.Left;
double y = boxBound.Top - boxBound.Bottom;
string msg = $"位置左下角({Math.Round(boxBound.Left, 2)},{Math.Round(boxBound.Bottom, 2)})," +
$"右上角({Math.Round(boxBound.Right, 2)},{Math.Round(boxBound.Top, 2)}):尺寸:{Math.Round(x, 2)}X{Math.Round(y, 2)}";
LogUtil.info($"gerber文件【{string.Join(",", files)}】成功导入到文件:{filename},{msg}");
FrmImageViewer imageViewer = new FrmImageViewer(filename);
DialogResult sureresult = imageViewer.ShowDialog();
if (!sureresult.Equals(DialogResult.Cancel))
{
int l = (int)Math.Round(x);
int w = (int)Math.Round(y);
if (x <= 10 || w <= 10)
{
l = (int)(x * 25.4);
w = (int)(y * 25.4);
}
this.txtImagePath.Text = filename;
int currl = FormUtil.GetIntValue(txtBoardL);
int currw = FormUtil.GetIntValue(txtBoardW);
if (currl <= 0)
{
txtBoardL.Text = l.ToString();
}
if (currw <= 0)
{
txtBoardW.Text = w.ToString();
}
}
return true;
}
else
{
MessageBox.Show(ResourceCulture.GetString("FileError", "文件格式错误 "));
}
return false;
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Title = "Open Gerber File(s)";
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
GerberFileProcess(openFileDialog.FileNames);
//string defPath = Path.GetPathRoot(Application.StartupPath) + @"image\";
////List<string> newFiles = FileUtil.FileProcess(openFileDialog.FileNames);
//GerberVS.BoundingBox boxBound = GerberVS.AGerberController.OpenLayers(openFileDialog.FileNames,defPath, out string filename);
//if (boxBound!=null && File.Exists(filename))
//{
// double x = boxBound.Right - boxBound.Left;
// double y = boxBound.Top - boxBound.Bottom;
// string msg = $"位置左下角({Math.Round(boxBound.Left, 2)},{Math.Round(boxBound.Bottom, 2)})," +
// $"右上角({Math.Round(boxBound.Right, 2)},{Math.Round(boxBound.Top, 2)}):尺寸:{Math.Round(x, 2)}X{Math.Round(y, 2)}";
// LogUtil.info($"gerber文件【{string.Join(",", openFileDialog.FileNames) }】成功导入到文件:{filename},{msg}");
// FrmImageViewer imageViewer = new FrmImageViewer(filename);
// DialogResult sureresult = imageViewer.ShowDialog();
// if (!sureresult.Equals(DialogResult.Cancel))
// {
// int l =(int) Math.Round(x);
// int w = (int)Math.Round(y);
// if (x <= 10 || w <= 10)
// {
// l = (int)(x * 25.4);
// w = (int)(y * 25.4);
// }
// this.txtImagePath.Text = filename;
// int currl = FormUtil.GetIntValue(txtBoardL);
// int currw = FormUtil.GetIntValue(txtBoardW);
// if (currl <= 0)
// {
// txtBoardL.Text = l.ToString();
// }
// if (currw <= 0)
// {
// txtBoardW.Text = w.ToString();
// }
// }
//}
//else
//{
// MessageBox.Show(ResourceCulture.GetString("FileError", "文件格式错误 "));
//}
}
}
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string fileName = this.txtImagePath.Text;
if ( File.Exists(fileName))
{
FrmImageViewer imageViewer = new FrmImageViewer(fileName);
DialogResult sureresult = imageViewer.ShowDialog();
if (sureresult.Equals(DialogResult.Cancel))
{
this.txtImagePath.Text = "";
}
}
}
private void groupBox_new_Enter(object sender, EventArgs e)
{
}
private void rbBom_CheckedChanged(object sender, EventArgs e)
{
ComChange();
}
private void linkBomUpload_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
FrmBomUpload frm = new FrmBomUpload();
DialogResult resut = frm.ShowDialog();
if (resut.Equals(DialogResult.OK))
{
List<ComponetInfo> dataList = frm.componetInfos;
if (ProcessComData(dataList))
{
string bomName = "bomUpdate_" + DateTime.Now.ToString("yyyyMMddHHmm");
string path= Path.GetPathRoot(Application.StartupPath)+@"bomFile\"+bomName+".csv";
//保存元器件到文件
if (CSVBomManager.SaveBomToFile(bomName, dataList, path))
{
uploadPointList = dataList;
txtCsvFileName.Text = path;
linkDataViewer.Visible = true;
}
}
}
}
private void linkDataViewer_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (uploadPointList.Count>0)
{
FrmBomViewer frmViewer = new FrmBomViewer(uploadPointList);
DialogResult sureresult = frmViewer.ShowDialog();
if (sureresult.Equals(DialogResult.Cancel))
{
uploadPointList = new List<ComponetInfo>();
txtCsvFileName.Text = "";
linkDataViewer.Visible = false;
}
else
{
this.uploadPointList = frmViewer.dataList;
}
}
}
private void rdbData_CheckedChanged(object sender, EventArgs e)
{
ComChange();
}
private void TypeUpdate(int index)
{
for (int i = 0; i < pictureBoxes.Count; i++)
{
if (i.Equals(index))
{
pictureBoxes[i].Image = picSelImages[i];
}
else
{
pictureBoxes[i].Image = picDefImages[i];
}
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
cmbType.SelectedIndex = 0;
}
private void pictureBox2_Click(object sender, EventArgs e)
{
cmbType.SelectedIndex = 1;
}
private void pictureBox3_Click(object sender, EventArgs e)
{
cmbType.SelectedIndex = 2;
}
private void pictureBox4_Click(object sender, EventArgs e)
{
cmbType.SelectedIndex = 3;
}
private void pictureBox5_Click(object sender, EventArgs e)
{
cmbType.SelectedIndex = 4;
}
private void pictureBox6_Click(object sender, EventArgs e)
{
cmbType.SelectedIndex = 5;
}
private void cmbType_SelectedIndexChanged(object sender, EventArgs e)
{
TypeUpdate(cmbType.SelectedIndex);
}
}
}