Sharp.cs 13.1 KB
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);
                }
            }));
        }
    }
}