Sharp.cs
13.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
298
299
using XingYe_ACS.BaseStruct;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace XingYe_ACS.Common
{
public class Sharp
{
/// <summary>
/// 初始化监控界面
/// </summary>
public int[] MoniterAreaInit()
{
//获取xy方向的最大值
App.WidthMax = App.PointList.Max(a => a.intX);
App.WidthMin = App.PointList.Min(a => a.intX);
App.HeightMax = App.PointList.Max(a => a.intY);
App.HeightMin = App.PointList.Min(a => a.intY);
//设置画布大小
long pointXCount = App.WidthMax - App.WidthMin + 1;
int AreaWidth = (int)(pointXCount * (App.GsWidth + 2) + pointXCount);
long pointYCount = App.HeightMax - App.HeightMin + 1;
int AreaHeight = (int)(pointYCount * (App.GsHeight + 2) + pointYCount);
return new int[] { AreaWidth, AreaHeight };
}
/// <summary>
/// 货架绘制
/// </summary>
public void ShelfSet()
{
foreach (Point point in App.PointList.FindAll(a => a.pointType.GetIndexInt() == 4 || a.pointType.GetIndexInt() == 20
|| a.pointType.GetIndexInt() == 24 || a.pointType.GetIndexInt() == 3|| a.pointType.GetIndexInt() == 7))
{
Rectangle rectangle = new Rectangle();
rectangle.ToolTip = point.strBarcode;
rectangle.Width = App.GsWidth;
rectangle.Height = App.GsHeight;
rectangle.Fill = new SolidColorBrush(Colors.Transparent);
rectangle.Stroke = new SolidColorBrush(Colors.DarkGray);
double[] xy = DrawSharp(point.intX, point.intY);
rectangle.SetValue(Canvas.TopProperty, xy[1]);
rectangle.SetValue(Canvas.LeftProperty, xy[0]);
App.Canvas_Monit.Children.Add(rectangle);
App.ShelfSharp.Add(rectangle);
}
}
/// <summary>
/// 小车绘制
/// </summary>
public void AgvPointSet()
{
foreach (Agv agv in App.AgvList)
{
Ellipse ellipse = App.AgvSharp.FirstOrDefault(new Func<Ellipse, bool>(a => a.Name == agv.strAgvNo));
if (ellipse != null) throw new Exception(agv.strAgvNo + "小车已存在地图中");
ellipse = new Ellipse();
ellipse.Name = agv.strAgvNo;
ellipse.ToolTip = ellipse.Name;
ellipse.Width = App.GsWidth;
ellipse.Height = App.GsHeight;
ellipse.Fill = new SolidColorBrush(Colors.Transparent);
ellipse.Stroke = new SolidColorBrush(Colors.Tan);
ellipse.StrokeThickness = 12;
Point point = App.PointList.FirstOrDefault(a => a.strBarcode == agv.strBarcode);
if (point != null)
{
double[] xy = DrawSharp(point.intX, point.intY);
ellipse.SetValue(Canvas.TopProperty, xy[1]);
ellipse.SetValue(Canvas.LeftProperty, xy[0]);
}
App.Canvas_Monit.Children.Add(ellipse);
App.AgvSharp.Add(ellipse);
if (!agv.isEnable)
ellipse.Visibility = System.Windows.Visibility.Hidden;
else
ellipse.Visibility = System.Windows.Visibility.Visible;
}
}
/// <summary>
/// 地图坐标点绘制
/// </summary>
public void PointSet()
{
foreach (Point point in App.PointList.FindAll(a=>a.pointType != EnumMsg.PointType.死点))
{
Ellipse ellipse = new Ellipse();
Station station = App.StationList.Find(a => a.strBarcode == point.strBarcode);
//码值
ellipse.ToolTip = point.strBarcode;
//坐标及类型
if (station != null)
{
ellipse.ToolTip += "\n" + string.Format("({0},{1}),{2}", point.intX, point.intY, station.strStationNo);
}
else
{
ellipse.ToolTip += "\n" + string.Format("({0},{1}),{2}", point.intX, point.intY, point.pointType.ToString());
}
//区域类型
//ellipse.ToolTip += "\n" + string.Format("AreaType:{0}", point.pointAreaType.ToString());
//点方向锁
ellipse.ToolTip += "\n" + string.Format("X+:{0}", point.isXPos);
ellipse.ToolTip += "\n" + string.Format("X-:{0}", point.isXNeg);
ellipse.ToolTip += "\n" + string.Format("Y+:{0}", point.isYPos);
ellipse.ToolTip += "\n" + string.Format("Y-:{0}", point.isYNeg);
ellipse.ToolTip += "\n" + string.Format("X间距:{0}", point.intXLength);
ellipse.ToolTip += "\n" + string.Format("Y间距:{0}", point.intYLength);
if (point.strRegionName != "")
{
ellipse.ToolTip += "\n" + string.Format("限制区域:{0}", point.strRegionName);
}
//大小
ellipse.Width = 8;
ellipse.Height = 8;
switch (point.pointType)
{
case EnumMsg.PointType.普通行走点:
ellipse.Fill = new SolidColorBrush(Colors.Maroon);
break;
case EnumMsg.PointType.充电点:
ellipse.Fill = new SolidColorBrush(Colors.Green);
ellipse.Width = 8;
ellipse.Height = 8;
break;
case EnumMsg.PointType.站台点:
ellipse.Fill = new SolidColorBrush(Colors.Blue);
ellipse.Width = 8;
ellipse.Height = 8;
break;
case EnumMsg.PointType.站台附属点:
case EnumMsg.PointType.暂停点:
ellipse.Fill = new SolidColorBrush(Colors.LightBlue);
ellipse.Width = 10;
ellipse.Height = 10;
break;
case EnumMsg.PointType.避让点:
case EnumMsg.PointType.走弧点:
case EnumMsg.PointType.虚拟点:
case EnumMsg.PointType.电梯点:
case EnumMsg.PointType.电梯等待点:
case EnumMsg.PointType.电梯关门点:
case EnumMsg.PointType.对接点:
case EnumMsg.PointType.对接等待点:
case EnumMsg.PointType.托盘旋转点:
ellipse.Fill = new SolidColorBrush(Colors.Orange);
ellipse.Width = 10;
ellipse.Height = 10;
break;
case EnumMsg.PointType.回家点:
ellipse.Fill = new SolidColorBrush(Colors.Orange);
ellipse.Width = 8;
ellipse.Height = 8;
break;
case EnumMsg.PointType.旋转点:
case EnumMsg.PointType.整体旋转点:
ellipse.Fill = new SolidColorBrush(Colors.Blue);
ellipse.Width = 10;
ellipse.Height = 10;
break;
case EnumMsg.PointType.旋转附属点:
ellipse.Fill = new SolidColorBrush(Colors.LightYellow);
ellipse.Width = 8;
ellipse.Height = 8;
break;
case EnumMsg.PointType.死点:
ellipse.Fill = new SolidColorBrush(Colors.Black);
ellipse.Width = 16;
ellipse.Height = 16;
break;
default:
//throw new Exception(point.strBarcode + "未配色点属性" + point.pointType);
break;
}
int[] xy = DrawPoint(point.intX, point.intY,(int)ellipse.Width);
ellipse.SetValue(Canvas.TopProperty, (double)xy[1]);
ellipse.SetValue(Canvas.LeftProperty, (double)xy[0]);
App.Canvas_Monit.Children.Add(ellipse);
App.PointSharp.Add(ellipse);
}
}
/// <summary>
/// 绘制地图点
/// </summary>
/// <param name="intX"></param>
/// <param name="intY"></param>
/// <returns></returns>
public int[] DrawPoint(int intX, int intY, int flag)
{
int y = ((int)App.HeightMax - intY) * App.GsHeight + App.GsHeight / 2 - flag / 2 + 1;
//int y = (intY-(int)App.HeightMin) * App.GsHeight + App.GsHeight / 2 - flag / 2 + 1;
int x = (intX - (int)App.WidthMin) * App.GsWidth + App.GsWidth / 2 - flag / 2 + 1;
return new int[] { x, y };
}
/// <summary>
/// 绘制小车货架
/// </summary>
/// <param name="intX"></param>
/// <param name="intY"></param>
/// <returns></returns>
public double[] DrawSharp(int intX, int intY)
{
int y = ((int)App.HeightMax - intY) * App.GsHeight + 1;
//int y = (intY - (int)App.HeightMin) * App.GsHeight + 1;
int x = (intX - (int)App.WidthMin) * App.GsWidth + 1;
return new double[] { x, y };
}
/// <summary>
/// 小车移动绘制
/// </summary>
/// <param name="agv"></param>
public void AgvChange(Agv agv)
{
App.AppDispatcher.Invoke(new Action(() =>
{
Point point = App.PointList.FirstOrDefault(a => a.strBarcode == agv.strBarcode);
Ellipse ellipse = App.AgvSharp.FirstOrDefault(new Func<Ellipse, bool>(a => a.Name == agv.strAgvNo));
if (ellipse == null) throw new Exception(agv.strAgvNo + "在地图中未添加");
if (ellipse.Visibility != System.Windows.Visibility.Visible)
ellipse.Visibility = System.Windows.Visibility.Visible;
if (!agv.isEnable)
ellipse.Visibility = System.Windows.Visibility.Hidden;
double[] xy = { 0, 0 };
if (point != null)
{
xy = DrawSharp(point.intX, point.intY);
}
ellipse.SetValue(Canvas.LeftProperty, xy[0]);
ellipse.SetValue(Canvas.TopProperty, xy[1]);
}));
}
/// <summary>
/// 小车状态绘制
/// </summary>
/// <param name="Agv"></param>
public void AgvStateChange(Agv agv)
{
App.AppDispatcher.Invoke(new Action(() =>
{
Ellipse ellipse = App.AgvSharp.FirstOrDefault(new Func<Ellipse, bool>(a => a.Name == agv.strAgvNo));
//if (ellipse == null) throw new Exception(agv.strAgvNo + "在地图中未添加");
if (agv.strAgvError != "")
{
ellipse.Stroke = new SolidColorBrush(Colors.Red);
}
else if (!agv.isOnline)
{
ellipse.Stroke = new SolidColorBrush(Colors.Tan);
}
else if (agv.heightState == EnumMsg.HeightState.高位)
{
if (agv.agvState == EnumMsg.State.自动空闲)
ellipse.Stroke = new SolidColorBrush(Colors.DarkSalmon);
else if (agv.agvState == EnumMsg.State.忙碌)
ellipse.Stroke = new SolidColorBrush(Colors.DarkBlue);
else if (agv.agvState == EnumMsg.State.充电中)
ellipse.Stroke = new SolidColorBrush(Colors.DarkGreen);
else
ellipse.Stroke = new SolidColorBrush(Colors.Yellow);
}
else if (agv.heightState == EnumMsg.HeightState.中位)
{
ellipse.Stroke = new SolidColorBrush(Colors.DarkOrange);
}
else if (agv.heightState == EnumMsg.HeightState.低位)
{
if (agv.agvState == EnumMsg.State.自动空闲)
ellipse.Stroke = new SolidColorBrush(Colors.Cyan);
else if (agv.agvState == EnumMsg.State.忙碌)
ellipse.Stroke = new SolidColorBrush(Colors.Blue);
else if (agv.agvState == EnumMsg.State.充电中)
ellipse.Stroke = new SolidColorBrush(Colors.Green);
else
ellipse.Stroke = new SolidColorBrush(Colors.Yellow);
}
}));
}
}
}