PointDisplay.cs
8.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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
namespace TSA_V
{
public class PointDisplay
{
private System.Windows.Forms.Panel panBoard;
private System.Windows.Forms.PictureBox picBoard;
public int selectIndex = 0;
public bool ImageNormal = true;
public bool ShowName = true;
public float imageXiShu = 1;
public double CurrBeiLu = 1;
private Image PicImage = null;
private List<SMTPointInfo> PointList = new List<SMTPointInfo>();
private int Width = 0;
private int Height = 0;
public bool IsWorkForm = false;
public void SetImage(Image image)
{
picBoard.Image = image;
this.PicImage = image;
}
public void SetPic(PictureBox p, Panel pan)
{
this.picBoard = p;
this.panBoard = pan;
picBoard.Tag = false;
picBoard.SizeMode = PictureBoxSizeMode.StretchImage;
// picBoard.MouseWheel += picBoard_MouseWheel;
}
private void SetPicSize()
{
int xishu = 100;
picBoard.Width = Width * xishu;
picBoard.Height = Height * xishu;
if (picBoard.Width > panBoard.Width)
{
picBoard.Height = Height * xishu * panBoard.Width / (Width * xishu);
picBoard.Width = panBoard.Width;
}
if (picBoard.Height > panBoard.Height)
{
picBoard.Width = Width * xishu * panBoard.Height / (Height * xishu);
picBoard.Height = panBoard.Height;
}
}
public void LoadPoint(int width, int height, List<SMTPointInfo> pointList = null)
{
this.PointList = pointList;
Width = width;
Height = height;
CurrBeiLu = 1;
//picBoard.SizeMode = PictureBoxSizeMode.AutoSize;
if (pointList == null)
{
return;
}
if (!ImageNormal)
{
picBoard.Width = picBoard.Image.Width;
picBoard.Height = picBoard.Image.Height;
}
else
{
//int xishu = 100;
//picBoard.Width = width * xishu;
//picBoard.Height = height * xishu;
//if (picBoard.Width > panBoard.Width)
//{
// picBoard.Height = height * xishu * panBoard.Width / (width * xishu);
// picBoard.Width = panBoard.Width;
//}
//if (picBoard.Height > (panBoard.Height - 10))
//{
// picBoard.Width = width * xishu * (panBoard.Height - 10) / (height * xishu);
// picBoard.Height = (panBoard.Height - 10);
//}
//picBoard.Width = (int)(picBoard.Width * CurrBeiLu);
//picBoard.Height = (int)(picBoard.Height * CurrBeiLu);
SetPicSize();
}
//显示点
picBoard.Refresh();
//panBoard.Refresh();
imageXiShu = (float)picBoard.Width / (float)width;
Graphics grfx = picBoard.CreateGraphics();
//float preX = 0;
//float preY = 0;
int index = 0;
foreach (SMTPointInfo weld in pointList)
{
float x = (float)Math.Abs(weld.PositionX) * imageXiShu;
float y = (float)Math.Abs(weld.PositionY) * imageXiShu;
int lineLength = 8;
Color color = Color.HotPink;
Brush brushes = Brushes.HotPink;
if (weld.CheckOK)
{
color = Color.Red;
brushes = Brushes.Red;
}
if (index.Equals(selectIndex))
{
color = Color.Orange;
brushes = Brushes.Orange;
}
grfx.DrawLine(new Pen(color, 2), x, y - lineLength, x, y + lineLength);
grfx.DrawLine(new Pen(color, 2), x - lineLength, y, x + lineLength, y);
//写字
if (index.Equals(selectIndex) || ShowName)
{
grfx.DrawString(weld.GetDisplayStr(), new Font("Arial ", 9, FontStyle.Bold), brushes, x - lineLength / 2 + 2, y + lineLength / 2 + 2);
}
index++;
}
grfx.SmoothingMode = SmoothingMode.HighQuality;
grfx.Dispose();
}
public Dictionary<int, double> pointXMap = new Dictionary<int, double>();
public Dictionary<int, double> pointYMap = new Dictionary<int, double>();
public void LoadWorkFromPoint(BoardInfo board, SMTPointInfo smtPoint,bool isOnlyWork=true )
{
if (picBoard == null)
{
return;
}
try
{
picBoard.SizeMode = PictureBoxSizeMode.StretchImage;
this.Width = board.boardWidth;
this.Height = board.boardLength;
this.PointList = board.smtList;
SetPicSize();
// updatePicPointSize(pWidth, pHeight);
bool isFindCurrPoint = false;
//显示点
Graphics g = (picBoard).CreateGraphics();
picBoard.Image = board.GetImage();
picBoard.Refresh();
int orgType = board.orgType;
//double orgX = board.getImageOrgX();
//double orgY = board.getImageOrgY();
Graphics grfx = picBoard.CreateGraphics();
float preX = 0;
float preY = 0;
int index = 0;
pointXMap = new Dictionary<int, double>();
pointYMap = new Dictionary<int, double>();
List<SMTPointInfo> list = board.smtList;
if (isOnlyWork)
{
list = board.GetSmtList();
}
foreach (SMTPointInfo weld in list)
{
float x = (float)Math.Abs(weld.PositionX) * picBoard.Width / Width;
float y = (float)Math.Abs(weld.PositionY) * picBoard.Width / Width;
pointXMap.Add(weld.pointNum, x);
pointYMap.Add(weld.pointNum, y);
if (weld.PartNum.Equals(smtPoint.PartNum))
//if (prepareWeld && weld.pointName.Equals(smtPoint.pointName))
{
int lineLength = 12;
grfx.DrawLine(new Pen(Color.Red, 4), x, y - lineLength, x, y + lineLength);
grfx.DrawLine(new Pen(Color.Red, 4), x - lineLength, y, x + lineLength, y);
isFindCurrPoint = true; ;
g.DrawString(weld.GetDisplayStr(), new Font("Arial ", 8, FontStyle.Bold), Brushes.Red, x - lineLength / 2 + 5, y + lineLength / 2 + 2);
}
else
{
if (isFindCurrPoint)
{
//未开始
int lineLength = 8;
grfx.DrawLine(new Pen(Color.Orange, 2), x, y - lineLength, x, y + lineLength);
grfx.DrawLine(new Pen(Color.Orange, 2), x - lineLength, y, x + lineLength, y);
}
else
{
//已完成
int lineLength = 6;
grfx.DrawLine(new Pen(Color.HotPink, 2), x, y - lineLength, x, y + lineLength);
grfx.DrawLine(new Pen(Color.HotPink, 2), x - lineLength, y, x + lineLength, y);
//g.FillEllipse(Brushes.Red, x - pointHight / 2, y - pointHight / 2, pointHight + pointWidth, pointHight + pointWidth);
}
}
preX = x;
preY = y;
index++;
}
this.PicImage = (Bitmap)picBoard.Image;
grfx.Dispose();
g.Dispose();
}
catch (Exception ex)
{
LogUtil.error("画图出错:" + ex.ToString());
}
}
}
}