Manager.cs
4.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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AGV_UI
{
class Manager
{
static ImageList connImageList;
static ImageList batteryImageList;
static ImageList stateImageList;
static string OnLine = "OnLine";
static string OffLine = "OffLine";
static string LowBattery = "LowBattery";
static string CommonBattery = "CommonBattery";
static string FullBattery = "FullBattery";
static string ChargeBattery = "ChargeBattery";
static string Ready = "Ready";
static string Pause = "Pause";
static string Executing = "Executing";
static string Aborted = "Aborted";
static string EmergencyStop = "EmergencyStop";
static string ManualControl = "ManualControl";
static string Error = "Error";
static string UNKNOWN = "UNKNOWN";
static void InitconnImageList()
{
connImageList = new ImageList();
connImageList.ImageSize = new System.Drawing.Size(32, 32);
connImageList.Images.Add(OnLine, Properties.Resources.online);
connImageList.Images.Add(OffLine, Properties.Resources.offline);
}
static void InitbatteryImageList()
{
batteryImageList = new ImageList();
batteryImageList.ImageSize = new System.Drawing.Size(48, 48);
batteryImageList.Images.Add(LowBattery, Properties.Resources.low);
batteryImageList.Images.Add(CommonBattery, Properties.Resources.common);
batteryImageList.Images.Add(FullBattery, Properties.Resources.full);
batteryImageList.Images.Add(ChargeBattery, Properties.Resources.charge);
}
static void InitStateImageList()
{
stateImageList = new ImageList();
stateImageList.ImageSize = new System.Drawing.Size(48, 48);
stateImageList.Images.Add(UNKNOWN, Properties.Resources.Unknown);
stateImageList.Images.Add(Ready, Properties.Resources.ready);
stateImageList.Images.Add(Pause, Properties.Resources.pause);
stateImageList.Images.Add(ManualControl, Properties.Resources.manual);
stateImageList.Images.Add(Executing, Properties.Resources.Executing);
stateImageList.Images.Add(Error, Properties.Resources.Error);
stateImageList.Images.Add(EmergencyStop, Properties.Resources.emergency);
stateImageList.Images.Add(Aborted, Properties.Resources.Aborted);
}
/// <summary>
/// 设置连接状态
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static Image SetConnState(bool state = false)
{
string tmp = state ? OnLine : OffLine;
if (connImageList == null)
InitconnImageList();
return connImageList.Images[tmp];
}
/// <summary>
/// 设置电量
/// </summary>
/// <param name="min"></param>
/// <param name="max"></param>
public static object[] SetBattery(int curBattery, bool isCharge = false, int min = 20, int max = 90)
{
if (curBattery < 0) curBattery = 0;
Image image;
if (batteryImageList == null)
InitbatteryImageList();
if (isCharge)
{
image = batteryImageList.Images[ChargeBattery];
}
else
{
if (curBattery < min)
image = batteryImageList.Images[LowBattery];
else if (curBattery < max)
image = batteryImageList.Images[CommonBattery];
else
image = batteryImageList.Images[FullBattery];
}
return new object[] { string.Format("{0}%",curBattery), image };
}
/// <summary>
/// 设置小车状态
/// </summary>
/// <param name="curState"></param>
public static object[] SetAGVState(string curState)
{
Image image;
if (stateImageList == null)
InitStateImageList();
if(stateImageList.Images.ContainsKey(curState))
image = stateImageList.Images[curState];
else
image = stateImageList.Images[UNKNOWN];
return new object[] { curState, image };
}
}
}