From 02c14c9c57dbde72d9c771bd8b0fab1cd023047d Mon Sep 17 00:00:00 2001
From: cloudflight <cloudflight@126.com>
Date: 星期一, 13 一月 2025 09:09:22 +0800
Subject: [PATCH] 上下游纵断面分析

---
 WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/02-panel/NetworkPanel.cs |  381 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 279 insertions(+), 102 deletions(-)

diff --git a/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/02-panel/NetworkPanel.cs b/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/02-panel/NetworkPanel.cs
index 7f33106..e0174ba 100644
--- a/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/02-panel/NetworkPanel.cs
+++ b/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/02-panel/NetworkPanel.cs
@@ -1,5 +1,4 @@
-锘�
-namespace Yw.WinFrmUI.HydroL2d
+锘縩amespace Yw.WinFrmUI.HydroL2d
 {
     /// <summary>
     /// 绠$綉闈㈡澘
@@ -22,22 +21,11 @@
             this.MinimumSize = new Size(10, 10);
         }
 
+        #region 鍒濆鍖�
 
         protected Network _network = null;//绠$綉
         protected RectangleF _networkBounds;//绠$綉杈圭晫
-        private Bitmap _cache = null;//缂撳瓨<渚濇嵁宸ヤ綔鍖哄煙鍒涘缓鐨勭┖鍥剧墖>
-        private object _cacheLocker = new();//缂撳瓨閿�
-        private Bitmap _disp = null;//鏄剧ず<鍦╟ache鍩虹涓婅繘琛岀粯鍒讹紝鏈�缁堢殑鏄剧ず鍥剧墖>
-        private object _dispLocker = new();//鏄剧ず閿�
-        private float _zoomMin = 0.01f;//鏈�灏忕缉鏀惧眰绾�
-        private float _zoomMax = 10000f;//鏈�澶х缉鏀惧眰绾�
-        private float _zoom = 1f;//褰撳墠缂╂斁灞傜骇
-        private float _dxo = 0f;//x鍋忕Щ閲�
-        private float _dyo = 0f;//y鍋忕Щ閲�
-        private RectangleF _clientRectf;//宸ヤ綔鍖哄煙鐭╁舰
-
-
-        #region 鍒濆鍖�
+        protected RectangleF _clientRectf;//宸ヤ綔鍖哄煙鐭╁舰
 
         /// <summary>
         /// 鏄惁鍒濆鍖�
@@ -60,6 +48,9 @@
 
         #region 缂撳瓨涓庢樉绀�
 
+        private Bitmap _cache = null;//缂撳瓨<渚濇嵁宸ヤ綔鍖哄煙鍒涘缓鐨勭┖鍥剧墖>
+        private object _cacheLocker = new();//缂撳瓨閿�
+
         /// <summary>
         /// 鍒涘缓缂撳瓨
         /// </summary>
@@ -70,7 +61,6 @@
                 return;
             }
             var img = new Bitmap((int)_clientRectf.Width, (int)_clientRectf.Height);
-            img.MakeTransparent(Color.White);
             lock (_cacheLocker)
             {
                 if (_cache != null)
@@ -94,14 +84,10 @@
             {
                 return;
             }
-            var disp = _cache.CloneC();
-            if (disp == null)
-            {
-                return;
-            }
             var dispRect = GetDispRectangleF();
-            using (var g = Graphics.FromImage(disp))
+            using (var g = Graphics.FromImage(_cache))
             {
+                g.Clear(Color.White);
                 g.PageUnit = GraphicsUnit.Pixel;
                 g.InterpolationMode = InterpolationMode.High;
                 g.SmoothingMode = SmoothingMode.AntiAlias;
@@ -110,16 +96,7 @@
                 g.TranslateTransform(_dxo, _dyo);
                 g.ScaleTransform(1, -1);
 
-                //_network.Draw(g, dispRect);
-                _network.Draw(g);
-            }
-            lock (_dispLocker)
-            {
-                if (_disp != null)
-                {
-                    _disp.Dispose();
-                }
-                _disp = disp;
+                _network.Draw(g, dispRect);
             }
         }
 
@@ -132,11 +109,11 @@
             {
                 return;
             }
-            lock (_dispLocker)
+            lock (_cacheLocker)
             {
-                if (_disp != null)
+                if (_cache != null)
                 {
-                    g.DrawImage(_disp, _clientRectf);
+                    g.DrawImage(_cache, _clientRectf);
                 }
             }
 
@@ -144,7 +121,13 @@
 
         #endregion
 
-        #region 缂╂斁
+        #region 缂╂斁涓庡亸绉�
+
+        private float _zoomMin = 0.001f;//鏈�灏忕缉鏀惧眰绾�
+        private float _zoomMax = 30000f;//鏈�澶х缉鏀惧眰绾�
+        private float _zoom = 1f;//褰撳墠缂╂斁灞傜骇
+        private float _dxo = 0f;//x鍋忕Щ閲�
+        private float _dyo = 0f;//y鍋忕Щ閲�
 
         /// <summary>
         /// 缂╂斁绛夌骇
@@ -288,7 +271,7 @@
 
         #endregion
 
-        #region 鑾峰彇鐭╁舰
+        #region 鑾峰彇鐭╁舰鍖哄煙
 
         /// <summary>
         /// 鑾峰彇宸ヤ綔鍖哄煙
@@ -312,7 +295,7 @@
             {
                 return default;
             }
-            var pt = ClientToDispPoint(_clientRectf.Location);
+            var pt = ClientToDispPoint(new PointF(_clientRectf.X, _clientRectf.Height));
             var width = _clientRectf.Width / _zoom;
             var height = _clientRectf.Height / _zoom;
             return new RectangleF(pt, new SizeF(width, height));
@@ -345,17 +328,11 @@
         {
             if (e.Button == MouseButtons.Left)
             {
-                if (Initialized)
-                {
-                    if (this.AllowMoveWhenMouseLeftDown)
-                    {
-                        _hasMouseLeftDown = true;
-                        _mouseLeftDownMovePoint = e.Location;
-                        return true;
-                    }
-                }
+                _hasMouseLeftDown = true;
+                _mouseLeftDownMovePoint = e.Location;
+                return true;
             }
-            return true;
+            return false;
         }
 
         /// <summary>
@@ -364,20 +341,17 @@
         /// <param name="e"></param>
         protected virtual bool MouseLeftDownMove(MouseEventArgs e)
         {
-            if (e.Button == MouseButtons.Left)
+            if (_hasMouseLeftDown)
             {
                 if (this.AllowMoveWhenMouseLeftDown)
                 {
-                    if (_hasMouseLeftDown)
+                    if (this.Initialized)
                     {
-                        if (Initialized)
-                        {
-                            var pt = new PointF(e.X - _mouseLeftDownMovePoint.X, e.Y - _mouseLeftDownMovePoint.Y);
-                            _dxo += pt.X / _zoom;
-                            _dyo += pt.Y / _zoom;
-                            _mouseLeftDownMovePoint = e.Location;
-                            return true;
-                        }
+                        var pt = new PointF(e.X - _mouseLeftDownMovePoint.X, e.Y - _mouseLeftDownMovePoint.Y);
+                        _dxo += pt.X / _zoom;
+                        _dyo += pt.Y / _zoom;
+                        _mouseLeftDownMovePoint = e.Location;
+                        return true;
                     }
                 }
             }
@@ -389,13 +363,86 @@
         /// </summary>
         protected virtual bool HasMouseLeftUp(MouseEventArgs e)
         {
-            _hasMouseLeftDown = false;
-            return true;
+            if (_hasMouseLeftDown)
+            {
+                _hasMouseLeftDown = false;
+                return true;
+            }
+            return false;
         }
 
         #endregion
 
-        #region 榧犳爣鍙屽嚮鎭㈠鑷�傚簲
+        #region 榧犳爣鍙抽敭鎸変笅鎷栧姩
+
+        /// <summary>
+        /// 褰撻紶鏍囧彸閿寜涓嬫椂鍏佽鎷栧姩
+        /// </summary>
+        [Browsable(true)]
+        [Description("褰撻紶鏍囧彸閿寜涓嬫椂鍏佽鎷栧姩")]
+        [DefaultValue(true)]
+        public bool AllowMoveWhenMouseRightDown
+        {
+            get => _allowMoveWhenMouseRightDown;
+            set => _allowMoveWhenMouseRightDown = value;
+        }
+        private bool _allowMoveWhenMouseRightDown = true;
+
+        protected bool _hasMouseRightDown = false;//榧犳爣鍙抽敭鏄惁鎸変笅
+        protected Point _mouseRightDownMovePoint;//榧犳爣鍙抽敭鎸変笅绉诲姩鐐�
+
+        /// <summary>
+        /// 鍒ゆ柇榧犳爣鍙抽敭鏄惁鎸変笅
+        /// </summary>
+        protected virtual bool HasMouseRightDown(MouseEventArgs e)
+        {
+            if (e.Button == MouseButtons.Right)
+            {
+                _hasMouseRightDown = true;
+                _mouseRightDownMovePoint = e.Location;
+                return true;
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 榧犳爣鍙抽敭鎸変笅绉诲姩
+        /// </summary>
+        protected virtual bool MouseRightDownMove(MouseEventArgs e)
+        {
+            if (_hasMouseRightDown)
+            {
+                if (this.AllowMoveWhenMouseRightDown)
+                {
+                    if (this.Initialized)
+                    {
+                        var pt = new PointF(e.X - _mouseRightDownMovePoint.X, e.Y - _mouseRightDownMovePoint.Y);
+                        _dxo += pt.X / _zoom;
+                        _dyo += pt.Y / _zoom;
+                        _mouseRightDownMovePoint = e.Location;
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 鍒ゆ柇榧犳爣宸﹂敭鏄惁寮硅捣
+        /// </summary>
+        protected virtual bool HasMouseRightUp(MouseEventArgs e)
+        {
+            if (_hasMouseRightDown)
+            {
+                _hasMouseRightDown = false;
+                return true;
+            }
+            return false;
+        }
+
+        #endregion
+
+        #region 榧犳爣宸﹂敭鍙屽嚮鎭㈠鑷�傚簲
 
         /// <summary>
         /// 褰撻紶鏍囧弻鍑绘椂鍏佽鑷�傚簲
@@ -403,27 +450,168 @@
         [Browsable(true)]
         [Description("褰撻紶鏍囧弻鍑绘椂鍏佽鑷�傚簲")]
         [DefaultValue(true)]
-        public bool AllowZoomAllWhenMouseDoubleClick
+        public bool AllowZoomAllWhenMouseLeftDoubleClick
         {
-            get => _allowZoomAllWhenMouseDoubleClick;
-            set => _allowZoomAllWhenMouseDoubleClick = value;
+            get => _allowZoomAllWhenMouseLeftDoubleClick;
+            set => _allowZoomAllWhenMouseLeftDoubleClick = value;
         }
-        private bool _allowZoomAllWhenMouseDoubleClick = true;
+        private bool _allowZoomAllWhenMouseLeftDoubleClick = true;
 
         /// <summary>
         /// 榧犳爣鍙屽嚮鏃惰嚜閫傚簲
         /// </summary>
-        protected virtual bool ZoomAllWhenMouseDoubleClick(MouseEventArgs e)
+        protected virtual bool ZoomAllWhenMouseLeftDoubleClick(MouseEventArgs e)
         {
-            if (e.Clicks > 1)
+            if (e.Button == MouseButtons.Left)
             {
-                if (AllowZoomAllWhenMouseDoubleClick)
+                if (e.Clicks > 1)
                 {
-                    ZoomAll();
+                    if (this.AllowZoomAllWhenMouseLeftDoubleClick)
+                    {
+                        if (this.Initialized)
+                        {
+                            ZoomAll();
+                            return true;
+                        }
+                    }
+                }
+            }
+            return false;
+        }
+
+        #endregion
+
+        #region 榧犳爣鎮仠
+
+        /// <summary>
+        /// 鍏佽榧犳爣鎮仠
+        /// </summary>
+        [Browsable(true)]
+        [Description("鍏佽榧犳爣鎮仠")]
+        [DefaultValue(true)]
+        public bool AllowMouseHover
+        {
+            get => _allowMouseHover;
+            set => _allowMouseHover = value;
+        }
+        private bool _allowMouseHover = true;
+        private List<Parter> _lastHoverList = null;//鏈�鍚庝竴娆℃偓鍋滃垪琛�
+
+        /// <summary>
+        /// 鎮仠
+        /// 濡傛灉鍙戠敓鏀瑰彉灏辫繑鍥瀟rue
+        /// </summary>
+        protected virtual bool Hover(MouseEventArgs e)
+        {
+            if (this.AllowMouseHover)
+            {
+                if (this.Initialized)
+                {
+                    var pt = ClientToDispPoint(e.Location);
+                    var hoverList = _network.Hover(pt);
+                    if (hoverList == null || hoverList.Count < 1)
+                    {
+                        if (_lastHoverList == null || _lastHoverList.Count < 1)
+                        {
+                            return false;
+                        }
+                    }
+                    _lastHoverList = hoverList;
                     return true;
                 }
             }
+            if (_lastHoverList == null || _lastHoverList.Count < 1)
+            {
+                return false;
+            }
             return true;
+        }
+
+        #endregion
+
+        #region 榧犳爣宸﹂敭鐐瑰嚮閫夋嫨
+
+        /// <summary>
+        /// 鍏佽榧犳爣宸﹂敭鍗曞嚮閫夋嫨
+        /// </summary>
+        [Browsable(true)]
+        [Description("鍏佽榧犳爣宸﹂敭鍗曞嚮閫夋嫨")]
+        [DefaultValue(true)]
+        public bool AllowMouseLeftSingleClickSelect
+        {
+            get => _allowMouseLeftSingleClickSelect;
+            set => _allowMouseLeftSingleClickSelect = value;
+        }
+        private bool _allowMouseLeftSingleClickSelect = true;
+        private List<Parter> _lastMouseLeftClickSelectList = null;//鏈�鍚庝竴娆¢紶鏍囧乏閿崟鍑婚�夋嫨鍒楄〃
+
+
+        /// <summary>
+        /// 褰撻紶鏍囧乏閿崟鍑绘椂閫夋嫨
+        /// </summary>
+        protected virtual bool SelectWhenMouseLeftSingleClick(MouseEventArgs e)
+        {
+            if (e.Button == MouseButtons.Left)
+            {
+                if (e.Clicks == 1)
+                {
+                    if (this.Initialized)
+                    {
+                        var pt = ClientToDispPoint(e.Location);
+                        var selectList = _network.Select(pt);
+                        if (selectList == null || selectList.Count < 1)
+                        {
+                            if (_lastMouseLeftClickSelectList == null || _lastMouseLeftClickSelectList.Count < 1)
+                            {
+                                return false;
+                            }
+                        }
+                        _lastMouseLeftClickSelectList = selectList;
+                        return true;
+                    }
+                }
+            }
+            if (_lastMouseLeftClickSelectList == null || _lastMouseLeftClickSelectList.Count < 1)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        #endregion
+
+        #region 榧犳爣婊氳疆婊氬姩缂╂斁
+
+        /// <summary>
+        /// 褰撻紶鏍囨粴杞粴鍔ㄦ椂鍏佽缂╂斁
+        /// </summary>
+        [Browsable(true)]
+        [Description("褰撻紶鏍囨粴杞粴鍔ㄦ椂鍏佽缂╂斁")]
+        [DefaultValue(true)]
+        public bool AllowZoomWhenMouseWheelRoll
+        {
+            get => _allowZoomWhenMouseWheelRoll;
+            set => _allowZoomWhenMouseWheelRoll = value;
+        }
+        private bool _allowZoomWhenMouseWheelRoll = true;
+
+        /// <summary>
+        /// 褰撻紶鏍囨粴杞粴鍔ㄦ椂缂╂斁
+        /// </summary>
+        protected virtual bool ZoomWhenMouseWheelRoll(MouseEventArgs e)
+        {
+            if (e.Delta != 0)
+            {
+                if (this.AllowZoomWhenMouseWheelRoll)
+                {
+                    if (this.Initialized)
+                    {
+                        ZoomToPoint(e);
+                        return true;
+                    }
+                }
+            }
+            return false;
         }
 
         #endregion
@@ -444,29 +632,7 @@
 
         #endregion
 
-        #region 閫夋嫨
 
-        /// <summary>
-        /// 閫夋嫨锛堥�氳繃鐐归�夋嫨锛�
-        /// </summary>
-        protected virtual List<Parter> Select(MouseEventArgs e)
-        {
-            var pt = ClientToDispPoint(e.Location);
-            var list = _network.Select(pt);
-            return list;
-        }
-
-        /// <summary>
-        /// 鎮仠
-        /// </summary>
-        protected virtual List<Parter> Hover(MouseEventArgs e)
-        {
-            var pt = ClientToDispPoint(e.Location);
-            var list = _network.Hover(pt);
-            return list;
-        }
-
-        #endregion
 
         /// <summary>
         /// 閲嶇粯
@@ -500,7 +666,7 @@
         {
             base.OnMouseDown(e);
             HasMouseLeftDown(e);
-
+            HasMouseRightDown(e);
         }
 
         /// <summary>
@@ -509,9 +675,13 @@
         protected override void OnMouseMove(MouseEventArgs e)
         {
             base.OnMouseMove(e);
-            Hover(e);
-            MouseLeftDownMove(e);
-            this.Invalidate();
+            var hoverResult = Hover(e);
+            var hasMouseLeftDownMove = MouseLeftDownMove(e);
+            var hasMouseRightDownMove = MouseRightDownMove(e);
+            if (hoverResult || hasMouseLeftDownMove || hasMouseRightDownMove)
+            {
+                this.Invalidate();
+            }
         }
 
         /// <summary>
@@ -520,17 +690,24 @@
         protected override void OnMouseUp(MouseEventArgs e)
         {
             base.OnMouseUp(e);
-            HasMouseLeftUp(e);
-            Select(e);
-            this.Invalidate();
+            var hasMouseLeftUp = HasMouseLeftUp(e);
+            var hasMouseRightUp = HasMouseRightUp(e);
+            var mouseLeftSingleClickSelectResult = SelectWhenMouseLeftSingleClick(e);
+            if (hasMouseLeftUp || hasMouseRightUp || mouseLeftSingleClickSelectResult)
+            {
+                this.Invalidate();
+            }
         }
 
         //榧犳爣婊氳疆婊氬姩
         protected override void OnMouseWheel(MouseEventArgs e)
         {
             base.OnMouseWheel(e);
-            ZoomToPoint(e);
-            this.Refresh();
+            var zoomWhenMouseWheelRollResult = ZoomWhenMouseWheelRoll(e);
+            if (zoomWhenMouseWheelRollResult)
+            {
+                this.Refresh();
+            }
         }
 
         /// <summary>
@@ -539,11 +716,11 @@
         protected override void OnMouseDoubleClick(MouseEventArgs e)
         {
             base.OnMouseDoubleClick(e);
-            if (ZoomAllWhenMouseDoubleClick(e))
+            var zoomAllWhenMouseLeftDoubleClickResult = ZoomAllWhenMouseLeftDoubleClick(e);
+            if (zoomAllWhenMouseLeftDoubleClickResult)
             {
                 this.Invalidate();
             }
-
         }
 
     }

--
Gitblit v1.9.3