JobParam.cs 4.9 KB
using System;
using System.Collections.Generic;
using System.Text;

namespace DeviceLib.Model.AGV
{
    /// <summary>
    /// Job运行参数
    /// </summary>
    public class JobParam
    {
        /// <summary>
        /// 订单编号
        /// </summary>
        public string OrderId { get; set; } = "";
        public string RobotIp { get; set; }
        /// <summary>
        /// Job的运行类型
        /// </summary>
        public JobGoal JobGoal { get; set; }
        /// <summary>
        /// 满料箱编号
        /// </summary>
        public string FullBoxId { get; set; } = "";
        /// <summary>
        /// 回调Job
        /// </summary>
        public JobCallBack CallbackJob;
        /// <summary>
        /// 取料动作
        /// </summary>
        public JobAction GetAction = new JobAction();
        /// <summary>
        /// 送料动作
        /// </summary>
        public JobAction SendAction  = new JobAction();
        /// <summary>
        /// 返还动作
        /// </summary>
        public JobAction ReturnAction = new JobAction();
        public void SetAction(string action="000000")
        {
            char[] actions = action.ToCharArray();
            GetAction.SetAction(int.Parse(action[0].ToString()), int.Parse(action[1].ToString()));
            SendAction.SetAction(int.Parse(action[2].ToString()), int.Parse(action[3].ToString()));
            ReturnAction.SetAction(int.Parse(action[4].ToString()), int.Parse(action[5].ToString()));
        }
        /// <summary>
        /// 当前动作
        /// </summary>
        public JobAction CurAction
        {
            get
            {
                if (JobGoal == JobGoal.Send)
                {
                    return SendAction;
                }
                else if (JobGoal == JobGoal.Get)
                {
                    return GetAction;
                }
                else if (JobGoal == JobGoal.Return)
                {
                    return ReturnAction;
                }
                else
                    return new JobAction();
            }
        }
        /// <summary>
        ///线体点位
        /// </summary>
        public ClientNode LineNode { get; set; }
        /// <summary>
        /// 所有起始点
        /// </summary>
        public List<NodeJobState> SrcNodes { get; set; }
        /// <summary>
        /// 上一目标点
        /// </summary>
        public NodeJobState PreDstNode { get; set; }
        public MissionState MissionState { get; set; } = new MissionState();
        /// <summary>
        /// 料架返还点
        /// 默认为null,不使用
        ///
        /// </summary>
        public NodeJobState ReturnDstNode { get; set; } = null;
        /// <summary>
        /// 当前目标地点
        /// </summary>
        public NodeJobState CurDstNode
        {
            get
            {
                if (JobGoal == JobGoal.Send)
                {
                    return TargetNodes.Find(s => s.Finished.Equals(false));
                }
                else if (JobGoal == JobGoal.Get)
                {
                    return SrcNodes.Find(s => s.Finished.Equals(false));
                }
                else if (JobGoal == JobGoal.Return)
                {
                    return ReturnDstNode;
                }
                else
                    return TargetNodes[0];
            }
        }
        /// <summary>
        /// 是否有下一目的地
        /// </summary>
        /// <returns></returns>
        public bool HasNextDst()
        {
            if (JobGoal == JobGoal.Send)
            {
                return TargetNodes.Find(s => s.Finished.Equals(false)) != null;
            }
            else if (JobGoal == JobGoal.Get)
            {
                return SrcNodes.Find(s => s.Finished.Equals(false)) != null;
            }
            else if (JobGoal == JobGoal.Return)
            {
                return false;
            }
            return false;
        }
        /// <summary>
        /// 所有任务点
        /// </summary>
        public List<NodeJobState> TargetNodes { get; set; }
        /// <summary>
        /// 料车信息
        /// </summary>
        public Shelf Shelf { get; set; }
        public JobParam(List<NodeJobState> sourceNodes, List<NodeJobState> targetNodes, string orderId = null, Shelf shelf = null)
        {
            SrcNodes = sourceNodes;
            TargetNodes = targetNodes;
            Shelf = shelf;
            this.OrderId = orderId;
        }

        public void SetCurNodeFinished()
        {
            PreDstNode = CurDstNode;
            CurDstNode.Finished = true;
        }

    }

    public class JobCallBack
    {
        public Type Type { get; set; }
        public Job Job { get; set; }
        public RunStep RunStep { get; set; }
        public JobCallBack(Type type, RunStep step)
        {
            this.Type = type;
            this.RunStep = step;
        }
    }
}