LimitAreaInfo.cs 4.9 KB
using log4net.Util;
using Mushiny;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;

namespace CtuDeviceLib
{
    public class LimitAreaInfo
    {
        /// <summary>
        /// 限制区域名
        /// </summary>
        public string Name { get; set; } = "";
        /// <summary>
        /// 占用的AGV名
        /// </summary>
        public string OccupiedAgvName { get; set; } = string.Empty;
        public List<uint> CtuPointCodes { get; set; } = new List<uint>();
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool Enabled { get; set; }
        /// <summary>
        /// 是否是共享区域
        /// </summary>
        public bool IsSharedArea { get; set; }
        /// <summary>
        /// 机器人类型
        /// </summary>
        public int RobotType { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Desc { get; set; } = "";
        /// <summary>
        /// 是否被占用
        /// </summary>
        /// <param name="agvName"></param>
        /// <param name="pointCode"></param>
        /// <returns></returns>
        public bool IsOccupied(string agvName, int robotType)
        {
            if (!Enabled) return false;//未启用,认为未占用
            if (CtuPointCodes == null || CtuPointCodes.Count == 0) return false;//没有地标,认为未占用
            //if (IsSharedArea)
            //{

            //}
            //else
            {
                if (!string.IsNullOrEmpty(OccupiedAgvName))
                {
                    if (robotType == 1)
                    {
                        return true;
                    }
                    else
                    {
                        if (OccupiedAgvName.Equals(agvName))//被自己占用的认为未占用
                        {
                            return false;
                        }
                        else
                        {
                            return true;
                        }
                    }

                }
            }

            return false;
        }

        public bool SetOccupied(RequestLimitInfo info)
        {
            if (info == null) return false;
            OccupiedAgvName = info.AGVName;
            RobotType = info.RobotType;
            Desc = info.Desc;
            LogUtil.info($"【{info.AGVName}】占用限制区【{info.AreaName}】【{info.Desc}】【{JsonHelper.SerializeObject(this)}】");
            return true;
        }

        public bool ClearOccupied(ReleaseLimitInfo info)
        {
            if (info == null) return false;
            if (info.RobotType == 1)//塔斯克
            {
                OccupiedAgvName = string.Empty;
                RobotType = 0;
                Desc = "";
                LogUtil.info($"【{info.AGVName}】塔斯克 清除限制区完成 【{info.AreaName}】【{JsonHelper.SerializeObject(this)}】");
                return true;
            }
            else
            {
                if (OccupiedAgvName.Equals(info.AGVName))
                {
                    OccupiedAgvName = string.Empty;
                    RobotType = 0;
                    Desc = "";
                    LogUtil.info($"【{info.AGVName}】清除限制区完成【{info.AreaName}】【{JsonHelper.SerializeObject(this)}】");
                    return true;
                }
            }

            return false;
        }
        public void Reset()
        {
            OccupiedAgvName = string.Empty;
            RobotType = 0;
            Desc = "";
            LogUtil.info($"重置限制区【{Name}】状态");
        }
        public string[] ToDataGridData()
        {
            List<string> list = new List<string>()
            {
                Name,
                Enabled?"启用":"关闭",
              $"{OccupiedAgvName}",
              $"{(IsSharedArea?"共享":"本地")}",
              $"{string.Join(",",CtuPointCodes)}",
            };
            string type = "";
            if (RobotType == 1)
            {
                type = "栈板AGV";
            }
            else if (RobotType == 2)
            {
                type = "半成品CTU";
            }
            else if (RobotType == 3)
            {
                type = "原材料CTU";
            }
            list.Add(type);
            list.Add(Desc);
            return list.ToArray();
        }
    }
    public class RequestLimitInfo
    {
        public string AreaName { get; set; }
        public int RobotType { get; set; }
        public string AGVName { get; set; }
        public string Desc { get; set; }
    }
    public class ReleaseLimitInfo
    {
        public int RobotType { get; set; }
        public string AreaName { get; set; }
        public string AGVName { get; set; }
    }

}