From d9b8c4b8639e5239cea8fbb88fa2ae6fa1ac706b Mon Sep 17 00:00:00 2001
From: duheng <2784771470@qq.com>
Date: 星期一, 23 九月 2024 09:48:29 +0800
Subject: [PATCH] 提交修改

---
 WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/04-link/Pipe.cs |  123 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 115 insertions(+), 8 deletions(-)

diff --git a/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/04-link/Pipe.cs b/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/04-link/Pipe.cs
index 1188cf0..8b1162a 100644
--- a/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/04-link/Pipe.cs
+++ b/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/04-link/Pipe.cs
@@ -16,22 +16,129 @@
         public float? LineWidth { get; set; }
 
         /// <summary>
+        /// 鎮仠绾胯壊
+        /// </summary>
+        public Color? HoveredLineColor { get; set; }
+
+        /// <summary>
+        /// 鎮仠绾垮
+        /// </summary>
+        public float? HoveredLineWidth { get; set; }
+
+        /// <summary>
+        /// 閫夋嫨绾胯壊
+        /// </summary>
+        public Color? SelectedLineColor { get; set; }
+
+        /// <summary>
+        /// 閫夋嫨绾垮
+        /// </summary>
+        public float? SelectedLineWidth { get; set; }
+
+        private Coordinate _coordinate { get; set; }//鍧愭爣淇℃伅
+
+        //鑾峰彇鍧愭爣浣嶇疆
+        private Coordinate GetCoordinate(Graphics g)
+        {
+            var ws = this.LineWidth.HasValue ? this.LineWidth.Value : CacheHelper.HydroL2d.Pipe.Line.Width;
+            var wz = ws / g.PageScale;
+            var angle = (float)this.StartPosition.AngleClockWise(this.EndPosition);
+            var xp = this.StartPosition.GetXPoint(this.EndPosition);
+            var size = new SizeF(xp.X - this.StartPosition.X, 2 * wz);
+            return Coordinate.GetCoordinate(this.StartPosition, angle, size, StringAlignment.Near, StringAlignment.Center);
+        }
+
+        /// <summary>
         /// 缁樺埗
         /// </summary>
         public override void Draw(Graphics g)
         {
-            var fromCachePen = true;
-            var pen = CacheHelper.PipeLinePen;
-            if (this.LineColor.HasValue && this.LineWidth.HasValue)
+            _coordinate = GetCoordinate(g);
+
+            if (this.Hovered)
             {
-                pen = new Pen(this.LineColor.Value, this.LineWidth.Value);
-                fromCachePen = false;
+                var fromCachePen = true;
+                var pen = CacheHelper.PipeHoveredLinePen;
+                if (this.HoveredLineColor.HasValue && this.HoveredLineWidth.HasValue)
+                {
+                    pen = new Pen(this.HoveredLineColor.Value, this.HoveredLineWidth.Value);
+                    fromCachePen = false;
+                }
+                var penWidth = pen.Width;
+                pen.Width = penWidth / g.PageScale;
+                g.DrawLines(pen, this.Positions.ToArray());
+                pen.Width = penWidth;
+                if (!fromCachePen)
+                {
+                    pen.Dispose();
+                }
             }
-            g.DrawLines(pen, this.Positions.ToArray());
-            if (!fromCachePen)
+            else if (this.Selected)
             {
-                pen.Dispose();
+                var fromCachePen = true;
+                var pen = CacheHelper.PipeSelectedLinePen;
+                if (this.SelectedLineColor.HasValue && this.SelectedLineWidth.HasValue)
+                {
+                    pen = new Pen(this.SelectedLineColor.Value, this.SelectedLineWidth.Value);
+                    fromCachePen = false;
+                }
+                var penWidth = pen.Width;
+                pen.Width = penWidth / g.PageScale;
+                g.DrawLines(pen, this.Positions.ToArray());
+                pen.Width = penWidth;
+                if (!fromCachePen)
+                {
+                    pen.Dispose();
+                }
             }
+            else
+            {
+                var fromCachePen = true;
+                var pen = CacheHelper.PipeLinePen;
+                if (this.LineColor.HasValue && this.LineWidth.HasValue)
+                {
+                    pen = new Pen(this.LineColor.Value, this.LineWidth.Value);
+                    fromCachePen = false;
+                }
+                var penWidth = pen.Width;
+                pen.Width = penWidth / g.PageScale;
+                g.DrawLines(pen, this.Positions.ToArray());
+                pen.Width = penWidth;
+                if (!fromCachePen)
+                {
+                    pen.Dispose();
+                }
+            }
+        }
+
+        /// <summary>
+        /// 鍖呭惈
+        /// </summary>
+        public override bool Contains(PointF pt)
+        {
+            if (_coordinate == null)
+            {
+                return false;
+            }
+            var pa = _coordinate.Origin.RotatePointF(pt, _coordinate.Angle, false);
+            return _coordinate.BeforeRectf.Contains(pa);
+        }
+
+        /// <summary>
+        /// 鐩镐氦
+        /// </summary>
+        public override bool Intersect(RectangleF rectf)
+        {
+            var positions = this.Positions;
+            foreach (var position in positions)
+            {
+                if (rectf.Contains(position))
+                {
+                    return true;
+                }
+            }
+            return false;
+
         }
 
 

--
Gitblit v1.9.3