Manager.cs 4.5 KB
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 };
        }

    }
}