Form7.cs 27.2 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
using AGVMapDemo.DemoModel;
using CtuDeviceLib;
using log4net;
using Mushiny;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
using zhouchen.chart;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar;

namespace TheMachine.Model
{
    public partial class Form7 : Form
    {
        private CTUPointCode _agvPosition;
        private List<CTUPointCode> _pathPoints = new List<CTUPointCode>();
        float ratio = 0.019f;//比例
        float addreX = 50;//整体偏移X
        float addreY = 50;//整体偏移Y
        //新的缩放方法参数
        float maxPointX = float.MinValue;
        float maxPointY = float.MinValue;
        float minPointX = float.MaxValue;
        float minPointY = float.MaxValue;
        float RangX = float.MaxValue;
        float RangY = float.MaxValue;
        int screenWidth = 1920;
        int screenHeight = 1080;
        int screenRatio = 2;
        List<CTURobot> cTUs = new List<CTURobot>();
        List<TweenAnimationModel> cTUs_Animation = new List<TweenAnimationModel>();
        object Lock_Update_CTU = new object();
        object Lock_Update_CTUUI = new object();
        float CTU_Width = 50f;
        System.Timers.Timer CTU_timer = new System.Timers.Timer();
        System.Timers.Timer CTU_test_timer = new System.Timers.Timer();
        List<PointCode> PointCodes = new List<PointCode>();
        Bitmap MapBmp;

        float distanceRatio = 0.04f;
        float markRatio = 5.0f;
        int markFontRatio = 6;
        float LineRatio = 2.0f;
        float CTULineRatio = 2.0f;
        int CTUFontRatio = 12;
        event EventHandler<Bitmap> setimage;
        Graphics mapDraw = null;
        Graphics CTUDraw = null;
        //箭头
        // 角度A(以度为单位)  
        float angleA = 135;
        // 长度B  
        float lengthB = 5;
        Dictionary<uint, CTUPointCode> CTUMap = new Dictionary<uint, CTUPointCode>();

        #region 测试
        List<uint> planway = new List<uint>() { 427, 525, 3001, 3002, 3003, 3004,
                3005, 3006, 3007, 3008, 3009, 3010, 3011, 3012,
                3013, 3014, 3015, 3016, 3017, 3018, 3019, 3020, 539, 487 };
        List<uint> currentway = new List<uint>() { 427, 525, 3001, 3002, 3003, 3004 };
        List<uint> occupyway = new List<uint>() { 427, 525, 3001 };
        Color ctuclor = Color.Red;
        Color planclor = Color.Orange;
        Color currentclor = Color.Yellow;
        Color occupyclor = Color.Green;
        int inedx = 0;
        private void CTU_test_timer_Tick(object sender, EventArgs e)
        {
            if (inedx > planway.Count - 2)
            {
                inedx = 0;
            }
            else
            {
                inedx++;
                occupyway.RemoveAt(0);
                occupyway.Add(planway[inedx]);
                Update_CTU(3037, planway, currentway, occupyway, ctuclor, planclor, currentclor, occupyclor, "正常");
            }
        }
        #endregion

        /// <summary>
        /// 更新单个小车位置信息
        /// </summary>
        /// <param name="Id">小车ID</param>
        /// <param name="PlanWay">小车完整路径</param>
        /// <param name="CurrentWay">小车当前阶段运行路径</param>
        /// <param name="OccupyPoint">小车占用地标</param>
        /// <param name="CTUColor">小车颜色</param>
        /// <param name="PlanWayColor">小车计划路径颜色</param>
        /// <param name="CurrentWayColor">小车当前路径颜色</param>
        /// <param name="OccupyPointColor">小车占用地标颜色</param>
        /// <param name="state">小车状态</param>
        public void Update_CTU(uint Id, List<uint> PlanWay, List<uint> CurrentWay, List<uint> OccupyPoint,
            Color CTUColor, Color PlanWayColor, Color CurrentWayColor, Color OccupyPointColor, string state)
        {
            lock (Lock_Update_CTU)
            {
                if (cTUs.Count > 0)
                {
                    var ctu = cTUs.Find(m => m.Id == Id);
                    if (ctu != null)
                    {
                        ctu.PlanWay.Clear();
                        ctu.CurrentWay.Clear();
                        ctu.OccupyPoint.Clear();

                        ctu.PlanWay = ConvertToCTUPointCode(PlanWay);
                        ctu.CurrentWay = ConvertToCTUPointCode(CurrentWay);
                        ctu.OccupyPoint = ConvertToCTUPointCode(OccupyPoint);
                        ctu.CTUColor = CTUColor;
                        ctu.CTUPlanWayColor = PlanWayColor;
                        ctu.CTUCurrentWayColor = CurrentWayColor;
                        ctu.CTUOccupyPointColor = OccupyPointColor;
                    }
                    var ctu_Animation = cTUs_Animation.Find(m => m.CTUID == Id);
                    if (ctu_Animation != null)
                    {
                        ctu_Animation.PrePoint = ctu_Animation.CurrPoint;
                        ctu_Animation.PreTime = ctu_Animation.CurrTime;
                        ctu_Animation.CurrPoint = ctu.OccupyPoint[OccupyPoint.Count / 2 - 1];
                        ctu_Animation.CurrTime = DateTime.Now;
                    }
                }
                else
                {
                    CTURobot cTU = new CTURobot();
                    cTU.Id = Id;
                    cTU.PlanWay = ConvertToCTUPointCode(PlanWay);
                    cTU.CurrentWay = ConvertToCTUPointCode(CurrentWay);
                    cTU.OccupyPoint = ConvertToCTUPointCode(OccupyPoint);
                    cTU.CTUColor = CTUColor;
                    cTU.CTUPlanWayColor = PlanWayColor;
                    cTU.CTUCurrentWayColor = CurrentWayColor;
                    cTU.CTUOccupyPointColor = OccupyPointColor;
                    cTUs.Add(cTU);

                    TweenAnimationModel tween = new TweenAnimationModel();
                    tween.CTUID = Id;
                    tween.CurrTime = DateTime.Now;
                    tween.CurrPoint = cTU.OccupyPoint[OccupyPoint.Count / 2 - 1];
                    cTUs_Animation.Add(tween);
                }
            }
        }
        List<CTUPointCode> ConvertToCTUPointCode(List<uint> pointCodes)
        {
            CTUPointCode cTU;
            List<CTUPointCode> cTUs = new List<CTUPointCode>();
            foreach (var pathPoint in pointCodes)
            {
                if (CTUMap.TryGetValue(pathPoint, out cTU))
                {
                    cTUs.Add(cTU);
                }
            }
            return cTUs;
        }

        private PointF RotateVector(PointF vector, float angleDegrees)
        {
            float angleRadians = (float)(angleDegrees * Math.PI / 180.0);
            float cosTheta = (float)Math.Cos(angleRadians);
            float sinTheta = (float)Math.Sin(angleRadians);

            float newX = vector.X * cosTheta - vector.Y * sinTheta;
            float newY = vector.X * sinTheta + vector.Y * cosTheta;

            return new PointF(newX, newY);
        }

        private void DrwaMap(Graphics g)
        {
            #region 绘制地图
            //this.Invoke(new Action(UpdateUI));

            // 重新绘制路径和AGV位置  
            //Graphics g = panel1.CreateGraphics();
            Pen pen = new Pen(Color.Blue, LineRatio);
            Brush brushpoint = new SolidBrush(Color.Blue);
            Brush brushTurningpoint = new SolidBrush(Color.Green);
            Brush brush = new SolidBrush(Color.Red);

            // 绘制地标点  
            for (int i = 1; i < _pathPoints.Count; i++)
            {
                if (_pathPoints[i].Type == LandmarkType.Turning)
                {
                    g.FillRectangle(brushTurningpoint, _pathPoints[i].X, _pathPoints[i].Y, markRatio, markRatio);
                    //文字
                    // 设置字体和笔刷  
                    Font font = new Font("Arial", markFontRatio);
                    Brush CTUNameBrush = Brushes.Black;
                    // 要显示的文字
                    string CTUNameText = _pathPoints[i].Id.ToString();
                    PointF location = new PointF(_pathPoints[i].X + 10, _pathPoints[i].Y);
                    // 绘制文字  
                    g.DrawString(CTUNameText, font, CTUNameBrush, location);
                    // 释放字体资源(可选,如果使用IDisposable的对象,最好进行释放)  
                    font.Dispose();
                }
                else
                {
                    g.FillEllipse(brushpoint, _pathPoints[i].X, _pathPoints[i].Y, markRatio, markRatio);

                    //文字
                    // 设置字体和笔刷  
                    Font font = new Font("Arial", markFontRatio);
                    Brush CTUNameBrush = Brushes.Black;
                    // 要显示的文字
                    string CTUNameText = _pathPoints[i].Id.ToString();
                    PointF location = new PointF(_pathPoints[i].X + 10, _pathPoints[i].Y);
                    // 绘制文字  
                    g.DrawString(CTUNameText, font, CTUNameBrush, location);
                    // 释放字体资源(可选,如果使用IDisposable的对象,最好进行释放)  
                    font.Dispose();
                }

            }
            //绘制路径
            //将原有坐标点转换为图论的坐标点
            List<Point> points = new List<Point>();
            foreach (CTUPointCode ctuPoint in _pathPoints)
            {
                Point point = new Point(ctuPoint.X, ctuPoint.Y, ctuPoint.Id);

                //左
                {
                    if (ctuPoint.Left != null)
                    {
                        uint id = ctuPoint.Left.Id;
                        point.LeftID = id;
                    }
                }
                //右
                {
                    if (ctuPoint.Right != null)
                    {
                        uint id = ctuPoint.Right.Id;
                        point.RightID = id;
                    }
                }
                //上
                {
                    if (ctuPoint.Above != null)
                    {
                        uint id = ctuPoint.Above.Id;
                        point.UpID = id;
                    }
                }
                //下
                {
                    if (ctuPoint.Below != null)
                    {
                        uint id = ctuPoint.Below.Id;
                        point.DownID = id;
                    }
                }

                points.Add(point);
            }
            //为图的坐标点确定上下左右的点
            foreach (var point in points)
            {
                point.Up = points.Find(m => m.Id == point.UpID);
                point.Down = points.Find(m => m.Id == point.DownID);
                point.Left = points.Find(m => m.Id == point.LeftID);
                point.Right = points.Find(m => m.Id == point.RightID);
            }
            // 创建GraphTraversal实例并执行遍历  
            GraphTraversal traversal = new GraphTraversal();

            traversal.Traverse(points[0]); // 从点(0, 0)开始遍历  

            // 输出所有的边  
            // 用于存储单向联通的边  
            List<(Point, Point)> oneWayEdges = new List<(Point, Point)>();
            // 用于存储双向联通的边  
            List<(Point, Point)> twoWayEdges = new List<(Point, Point)>();
            oneWayEdges = traversal.oneWayEdges;
            twoWayEdges = traversal.twoWayEdges;
            //绘制单向边
            Pen penOneWay = new Pen(Color.Red, LineRatio);
            foreach (var point in oneWayEdges)
            {
                g.DrawLine(penOneWay, point.Item1.X, point.Item1.Y, point.Item2.X, point.Item2.Y);

                // 计算P1P2的方向向量  
                PointF direction = new PointF(point.Item2.X - point.Item1.X, point.Item2.Y - point.Item1.Y);
                // 计算旋转后的向量(角度A需要转换为弧度)  
                PointF rotatedDirectionA = RotateVector(direction, angleA);
                PointF rotatedDirectionB = RotateVector(direction, -angleA);
                // 规范化旋转后的向量,并乘以长度B得到终点坐标  
                float magnitudeA = (float)Math.Sqrt(rotatedDirectionA.X * rotatedDirectionA.X + rotatedDirectionA.Y * rotatedDirectionA.Y);
                float magnitudeB = (float)Math.Sqrt(rotatedDirectionB.X * rotatedDirectionB.X + rotatedDirectionB.Y * rotatedDirectionB.Y);
                PointF normalizedRotatedDirectionA = new PointF(rotatedDirectionA.X / magnitudeA, rotatedDirectionA.Y / magnitudeA);
                PointF normalizedRotatedDirectionB = new PointF(rotatedDirectionB.X / magnitudeB, rotatedDirectionB.Y / magnitudeB);
                PointF endPointA = new PointF(point.Item2.X + normalizedRotatedDirectionA.X * lengthB, point.Item2.Y + normalizedRotatedDirectionA.Y * lengthB);
                PointF endPointB = new PointF(point.Item2.X + normalizedRotatedDirectionB.X * lengthB, point.Item2.Y + normalizedRotatedDirectionB.Y * lengthB);
                // 绘制线段  
                g.DrawLine(penOneWay, point.Item2.X, point.Item2.Y, endPointA.X, endPointA.Y);
                g.DrawLine(penOneWay, point.Item2.X, point.Item2.Y, endPointB.X, endPointB.Y);


                //g.DrawLine(penOneWay, point.Item2.X, point.Item2.Y, (point.Item2.X + point.Item1.X) / 2, point.Item2.Y + Math.Abs(point.Item2.X - point.Item1.X) / 2);
                //g.DrawLine(penOneWay, point.Item2.X, point.Item2.Y, (point.Item2.X + point.Item1.X) / 2, point.Item2.Y - Math.Abs(point.Item2.X - point.Item1.X) / 2);
            }
            //绘制双向边
            Pen penTwoWay = new Pen(Color.Green, LineRatio);
            foreach (var point in twoWayEdges)
            {
                g.DrawLine(penTwoWay, point.Item1.X, point.Item1.Y, point.Item2.X, point.Item2.Y);

            }
            #endregion
            g.Save();
        }
        private void UpdateCTU(Graphics g)
        {
            lock (Lock_Update_CTU)
            {

                #region 绘制AGV小车,路线
                foreach (var ctu in cTUs)
                {
                    if (ctu.PlanWay.Count == 0 || ctu.CurrentWay.Count == 0 || ctu.OccupyPoint.Count == 0 || ctu.CTUPlanWayColor == null || ctu.CTUCurrentWayColor == null || ctu.CTUOccupyPointColor == null)
                    {
                        return;
                    }
                    //小车(以固定半透明框代表)
                    Color semiTransparentColor = Color.FromArgb(128, ctu.CTUColor); // 128是透明度(0-255),后面是RGB颜色值  
                    Brush semiTransparentBrush = new SolidBrush(semiTransparentColor);
                    #region 补间动画
                    TweenAnimationModel ctu_Animation = cTUs_Animation.Find(m => m.CTUID == ctu.Id);
                    if (ctu_Animation != null && ctu_Animation.PreTime != DateTime.MinValue && ctu_Animation.CurrTime != DateTime.MinValue)
                    {
                        ctu_Animation.UILaterTime = DateTime.Now;
                        float pointx = ctu_Animation.AddX;
                        float pointy = ctu_Animation.AddY;
                        g.FillRectangle(semiTransparentBrush, pointx - CTU_Width / 2, pointy - CTU_Width / 2, CTU_Width, CTU_Width);
                        //文字
                        // 设置字体和笔刷  
                        Font font = new Font("Arial", CTUFontRatio);
                        Brush CTUNameBrush = Brushes.Black;
                        // 要显示的文字
                        string CTUNameText = ctu.Id.ToString();
                        PointF location = new PointF(pointx, pointy);
                        // 绘制文字  
                        g.DrawString(CTUNameText, font, CTUNameBrush, location);
                        // 释放字体资源(可选,如果使用IDisposable的对象,最好进行释放)  
                        font.Dispose();
                     
                    }
                    #endregion
                    //计划路径
                    Pen PlanWay = new Pen(ctu.CTUPlanWayColor, CTULineRatio);
                    for (int i = 1; i < ctu.PlanWay.Count; i++)
                    {
                        g.DrawLine(PlanWay, ctu.PlanWay[i - 1].X, ctu.PlanWay[i - 1].Y, ctu.PlanWay[i].X, ctu.PlanWay[i].Y);
                    }
                    //当前路径
                    Pen CurrentWay = new Pen(ctu.CTUCurrentWayColor, CTULineRatio);
                    for (int i = 1; i < ctu.CurrentWay.Count; i++)
                    {
                        g.DrawLine(CurrentWay, ctu.CurrentWay[i - 1].X, ctu.CurrentWay[i - 1].Y, ctu.CurrentWay[i].X, ctu.CurrentWay[i].Y);
                    }


                    //占用路径
                    Pen OccupyWay = new Pen(ctu.CTUOccupyPointColor, CTULineRatio);
                    for (int i = 1; i < ctu.OccupyPoint.Count; i++)
                    {
                        g.DrawLine(OccupyWay, ctu.OccupyPoint[i - 1].X, ctu.OccupyPoint[i - 1].Y, ctu.OccupyPoint[i].X, ctu.OccupyPoint[i].Y);
                    }
                  

                }
                #endregion
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            lock (Lock_Update_CTUUI)
            {
                if (cTUs != null && mapDraw != null && MapBmp != null)
                {
                    Bitmap DrawMapBmp = MapBmp.Clone() as Bitmap;
                    CTUDraw = Graphics.FromImage(DrawMapBmp);
                    // 设置绘图品质  
                    CTUDraw.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    CTUDraw.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    // 绘制背景,填充为白色  
                    UpdateCTU(CTUDraw);
                    setimage?.Invoke(this, DrawMapBmp);

                }
            }

        }

        public static void Init()
        {
            MushinyManager.Init();
        }
        /// <summary>
        /// 加工坐标点
        /// </summary>
        /// <param name="point">输入点</param>
        /// <param name="ratio">缩放比例</param>
        /// <param name="overturn">是否翻转</param>
        /// <param name="addreX">X轴偏移量</param>
        /// <param name="addreY">Y轴偏移量</param>
        /// <returns></returns>
        CTUPointCode PointProcess(CTUPointCode point, float ratio = 1, bool overturn = true, float addreX = 0, float addreY = 0)
        {
            float x = point.X;
            float y = point.Y;
            if (overturn)
            {
                point.X = y * ratio + addreY;
                point.Y = x * ratio + addreX;
            }
            else
            {
                point.X = x * ratio + addreX;
                point.Y = y * ratio + addreY;
            }

            return point;
        }


        private void AlgoMatch_setimage(object sender, Bitmap e)
        {
            Bitmap temp = e.Clone() as Bitmap;
            this.pictureBox1.Invoke(new Action(() =>
            {
                pictureBox1.Image = temp;
            }));
        }

        public Form7()
        {
            InitializeComponent();
            Init();
            CTU_test_timer.Enabled = true;
            CTU_test_timer.Elapsed += CTU_test_timer_Tick;
            CTU_test_timer.Interval = 50;
            CTU_test_timer.Start();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            #region 对于加载的地码重新计算坐标
            PointCode tempPoint;
            foreach (var pathPoint in LandMarks.GetPointCodes())
            {
                tempPoint = new PointCode()
                {
                    Above = pathPoint.Above,
                    Below = pathPoint.Below,
                    Id = pathPoint.Id,
                    Name = pathPoint.Name,
                    Type = pathPoint.Type,
                    CanTurning = pathPoint.CanTurning,
                    Left = pathPoint.Left,
                    Right = pathPoint.Right,
                    X = pathPoint.X,
                    Y = pathPoint.Y,
                    Reserved = pathPoint.Reserved
                };
                // 更新路径点  
                PointCodes.Add(tempPoint);
            }
            List<Point_CTU> points = new List<Point_CTU>();
            foreach (PointCode ctuPoint in PointCodes)
            {
                Point_CTU point = new Point_CTU(ctuPoint.X, ctuPoint.Y, ctuPoint.Id);
                #region
                //左
                {
                    if (ctuPoint.Left != null)
                    {
                        uint id = ctuPoint.Left.Id;
                        point.LeftID = id;
                        point.LeftDistance = ctuPoint.Left.Distance;
                    }
                }
                //右
                {
                    if (ctuPoint.Right != null)
                    {
                        uint id = ctuPoint.Right.Id;
                        point.RightID = id;
                        point.RightDistance = ctuPoint.Right.Distance;
                    }
                }
                //上
                {
                    if (ctuPoint.Above != null)
                    {
                        uint id = ctuPoint.Above.Id;
                        point.UpID = id;
                        point.UpDistance = ctuPoint.Above.Distance;
                    }
                }
                //下
                {
                    if (ctuPoint.Below != null)
                    {
                        uint id = ctuPoint.Below.Id;
                        point.DownID = id;
                        point.DownDistance = ctuPoint.Below.Distance;
                    }
                }
                #endregion
                points.Add(point);
            }
            //为图的坐标点确定上下左右的点
            foreach (var point in points)
            {
                point.Up = points.Find(m => m.Id == point.UpID);
                point.Down = points.Find(m => m.Id == point.DownID);
                point.Left = points.Find(m => m.Id == point.LeftID);
                point.Right = points.Find(m => m.Id == point.RightID);
            }
            // 创建GraphTraversal实例并执行遍历  
            GraphTraversal_CTU traversal = new GraphTraversal_CTU();

            traversal.Traverse(points.First(m => m.Id == 617)); // 从点(0, 0)开始遍历  
            //更新原始地码的坐标
            foreach (var point in traversal.PointCodes)
            {
                PointCodes.Find(m => m.Id == point.Id).X = point.X;
                PointCodes.Find(m => m.Id == point.Id).Y = point.Y;
            }
            #endregion
            foreach (var pathPoint in PointCodes)
            {
                _agvPosition = new CTUPointCode()
                {
                    Above = pathPoint.Above,
                    Below = pathPoint.Below,
                    Id = pathPoint.Id,
                    Name = pathPoint.Name,
                    Type = pathPoint.Type,
                    CanTurning = pathPoint.CanTurning,
                    Left = pathPoint.Left,
                    Right = pathPoint.Right,
                    X = pathPoint.X,
                    Y = pathPoint.Y,
                    Reserved = pathPoint.Reserved
                };
                // 更新路径点  
                _pathPoints.Add(PointProcess(_agvPosition, distanceRatio, false, addreX, addreY));
            }
            foreach (var point in _pathPoints)
            {
                if (maxPointX < point.X)
                {
                    maxPointX = point.X;
                }
                if (maxPointY < point.Y)
                {
                    maxPointY = point.Y;
                }
                if (minPointX > point.X)
                {
                    minPointX = point.X;
                }
                if (minPointY > point.Y)
                {
                    minPointY = point.Y;
                }
            }
            RangX = maxPointX - minPointX;
            RangY = maxPointY - minPointY;
            //修正坐标为正数
            #region 修正坐标为正数
            List<CTUPointCode> tempPathPoints = new List<CTUPointCode>();
            foreach (var point in _pathPoints)
            {
                tempPathPoints.Add(PointProcess(point, 1, false, -minPointX + addreX, -minPointY + addreY));
            }
            _pathPoints.Clear();
            _pathPoints = tempPathPoints;

            #endregion
            maxPointX = float.MinValue;
            maxPointY = float.MinValue;
            minPointX = float.MaxValue;
            minPointY = float.MaxValue;
            RangX = float.MaxValue;
            RangY = float.MaxValue;
            foreach (var point in _pathPoints)
            {
                if (maxPointX < point.X)
                {
                    maxPointX = point.X;
                }
                if (maxPointY < point.Y)
                {
                    maxPointY = point.Y;
                }
                if (minPointX > point.X)
                {
                    minPointX = point.X;
                }
                if (minPointY > point.Y)
                {
                    minPointY = point.Y;
                }
            }
            #region Y轴镜像   
            List<CTUPointCode> tempPathPointsY = new List<CTUPointCode>();
            foreach (var point in _pathPoints)
            {
                point.Y = (maxPointY) - point.Y + addreY;
                tempPathPointsY.Add(point);
            }
            _pathPoints.Clear();
            _pathPoints = tempPathPointsY;

            #endregion
            #region 处理好的点加载进地图字典
            foreach (var point in _pathPoints)
            {
                CTUMap.Add(point.Id, point);
            }
            #endregion

            MapBmp = new Bitmap(Convert.ToInt32(maxPointX + addreX), Convert.ToInt32(maxPointY + addreY), PixelFormat.Format32bppRgb);
            mapDraw = Graphics.FromImage(MapBmp);
            // 设置绘图品质  
            mapDraw.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            mapDraw.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            // 绘制背景,填充为白色  
            mapDraw.Clear(Color.White);
            DrwaMap(mapDraw);
            setimage += AlgoMatch_setimage;
            // 保存图像到文件  
            MapBmp.Save("output.png", System.Drawing.Imaging.ImageFormat.Png);
            pictureBox1.Size = new Size(MapBmp.Width, MapBmp.Height);

            setimage?.Invoke(this, MapBmp);

            CTU_timer.Enabled = true;
            CTU_timer.Elapsed += timer1_Tick;
            CTU_timer.Interval = 50;
            CTU_timer.Start();
        }
        private void Form3_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
            System.Environment.Exit(0);
        }
    }
}