From 9aa8106d88fc3070498493e2819922f7ac31746e Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期三, 09 四月 2025 15:09:05 +0800
Subject: [PATCH] 增加BIMFACE水流动画效果

---
 WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/00-core/01-flow-effect/SimulationFlowEffectHelper.cs |  324 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 244 insertions(+), 80 deletions(-)

diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/00-core/01-flow-effect/SimulationFlowEffectHelper.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/00-core/01-flow-effect/SimulationFlowEffectHelper.cs
index 29bec79..41517e6 100644
--- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/00-core/01-flow-effect/SimulationFlowEffectHelper.cs
+++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/00-core/01-flow-effect/SimulationFlowEffectHelper.cs
@@ -11,15 +11,41 @@
         /// <summary>
         /// 
         /// </summary>
-        public SimulationFlowEffectHelper(SimulationVisualListHelper visualListHelper, ISimulationFlowEffectView view)
+        public SimulationFlowEffectHelper
+            (
+                SimulationVisualListHelper visualListHelper,
+                SimulationCalcuResultHelper calcuResultHelper,
+                ISimulationFlowEffectView view
+            )
         {
             _visualListHelper = visualListHelper;
+            _calcuResultHelper = calcuResultHelper;
+            _calcuResultHelper.InitialEvent += InitialData;
             _views = new List<ISimulationFlowEffectView>() { view };
+            InitialData();
         }
 
-        private SimulationVisualListHelper _visualListHelper = null;//鍙鍒楄〃杈呭姪绫�
-        private List<ISimulationFlowEffectView> _views = null;//瑙嗗浘鍒楄〃
-        private HydroCalcuResult _calcuResult = null;//璁$畻缁撴灉
+        /// <summary>
+        /// 
+        /// </summary>
+        public SimulationFlowEffectHelper
+            (
+                SimulationVisualListHelper visualListHelper,
+                SimulationCalcuResultHelper calcuResultHelper,
+                List<ISimulationFlowEffectView> views
+            )
+        {
+            _visualListHelper = visualListHelper;
+            _calcuResultHelper = calcuResultHelper;
+            _calcuResultHelper.InitialEvent += InitialData;
+            _views = views;
+            InitialData();
+        }
+
+        private readonly SimulationVisualListHelper _visualListHelper = null;//鍙鍒楄〃杈呭姪绫�
+        private readonly SimulationCalcuResultHelper _calcuResultHelper = null;//璁$畻缁撴灉杈呭姪绫�
+        private readonly List<ISimulationFlowEffectView> _views = null;//瑙嗗浘鍒楄〃
+        private readonly Dictionary<string, LogicFlowEffect> _cache = new();//缂撳瓨
 
         /// <summary>
         /// 鍙鎬�
@@ -31,42 +57,24 @@
         }
         private bool _visible = false;
 
-        /// <summary>
-        /// 椤瑰垪琛�
-        /// </summary>
-        public List<LogicFlowEffect> Items
-        {
-            get { return _items; }
-            private set { _items = value; }
-        }
-        private List<LogicFlowEffect> _items = null;
 
-        /// <summary>
-        /// 鍒濆鍖栨暟鎹�
-        /// </summary>
-        public void InitialData(HydroCalcuResult calcuResult)
+        //鍒濆鍖栨暟鎹�
+        private void InitialData()
         {
-            _calcuResult = calcuResult;
-            var allCalcuResultVisualDict = calcuResult?.GetVisualDict();
-            _visualListHelper.HydroInfo.Pipes?.ForEach(x => InitialItem(x, allCalcuResultVisualDict));
-        }
-
-        //鍒濆鍖栭」
-        private void InitialItem(HydroVisualInfo visual, Dictionary<string, HydroCalcuVisualResult> allCalcuResultVisualDict)
-        {
-            var item = CreateItem(visual, allCalcuResultVisualDict);
-            if (item != null)
+            var allCalcuVisualResultDict = _calcuResultHelper.GetVisualDict();
+            _cache.Clear();
+            _visualListHelper.GetVisualList()?.ForEach(x =>
             {
-                if (this.Items == null)
+                var item = CreateItem(x, allCalcuVisualResultDict);
+                if (item != null)
                 {
-                    this.Items = new List<LogicFlowEffect>();
+                    _cache[x.Code] = item;
                 }
-                this.Items.Add(item);
-            }
+            });
         }
 
         //鍒涘缓椤�
-        private LogicFlowEffect CreateItem(HydroVisualInfo visual, Dictionary<string, HydroCalcuVisualResult> allCalcuResultVisualDict = null)
+        private LogicFlowEffect CreateItem(HydroVisualInfo visual, Dictionary<string, HydroCalcuVisualResult> allCalcuVisualResultDict = null)
         {
             if (visual == null)
             {
@@ -82,39 +90,213 @@
                         item.Id = pipe.Code;
                         item.Rotation = 90;
                         item.SpeedX = 0.1;
-                        //if (pipe.FlowDirectionX == Yw.Hydro.FlowDirection.None)
-                        //{
-                        //    item.SpeedX = 0;
-                        //}
-                        //else if (pipe.FlowDirectionX == Yw.Hydro.FlowDirection.Positive)
-                        //{
-                        //    item.SpeedX = 0.1;
-                        //}
-                        //else
-                        //{
-                        //    item.SpeedX = -0.1;
-                        //}
+                        if (pipe.FlowDirectionX == Yw.Hydro.FlowDirection.None)
+                        {
+                            item.SpeedX = 0;
+                        }
+                        else if (pipe.FlowDirectionX == Yw.Hydro.FlowDirection.Positive)
+                        {
+                            item.SpeedX = 0.1;
+                        }
+                        else
+                        {
+                            item.SpeedX = -0.1;
+                        }
 
-                        //if (pipe.FlowDirectionY == Yw.Hydro.FlowDirection.None)
-                        //{
-                        //    item.SpeedY = 0;
-                        //}
-                        //else if (pipe.FlowDirectionY == Yw.Hydro.FlowDirection.Positive)
-                        //{
-                        //    item.SpeedY = 0.1;
-                        //}
-                        //else
-                        //{
-                        //    item.SpeedY = -0.1;
-                        //}
+                        if (pipe.FlowDirectionY == Yw.Hydro.FlowDirection.None)
+                        {
+                            item.SpeedY = 0;
+                        }
+                        else if (pipe.FlowDirectionY == Yw.Hydro.FlowDirection.Positive)
+                        {
+                            item.SpeedY = 0.1;
+                        }
+                        else
+                        {
+                            item.SpeedY = -0.1;
+                        }
 
-                        var calcuLinkResult = allCalcuResultVisualDict?.GetValue(pipe.Code) as HydroCalcuLinkResult;
+                        var calcuLinkResult = allCalcuVisualResultDict?.GetValue(pipe.Code) as HydroCalcuLinkResult;
                         if (calcuLinkResult != null)
                         {
                             if (calcuLinkResult.CalcuVelocity < 0)
                             {
                                 item.SpeedX = -item.SpeedX;
                             }
+                        }
+                    }
+                    break;
+                case Yw.Hydro.ParterCatalog.Translation:
+                    {
+                        HydroTranslationInfo translation = visual as HydroTranslationInfo;
+                        item = new LogicFlowEffect();
+                        item.Id = translation.Code;
+                        item.Rotation = 90;
+                        item.SpeedX = 0.1;
+                        if (translation.FlowDirectionX == Yw.Hydro.FlowDirection.None)
+                        {
+                            item.SpeedX = 0;
+                        }
+                        else if (translation.FlowDirectionX == Yw.Hydro.FlowDirection.Positive)
+                        {
+                            item.SpeedX = 0.1;
+                        }
+                        else
+                        {
+                            item.SpeedX = -0.1;
+                        }
+                        if (translation.FlowDirectionY == Yw.Hydro.FlowDirection.None)
+                        {
+                            item.SpeedY = 0;
+                        }
+                        else if (translation.FlowDirectionY == Yw.Hydro.FlowDirection.Positive)
+                        {
+                            item.SpeedY = 0.1;
+                        }
+                        else
+                        {
+                            item.SpeedY = -0.1;
+                        }
+
+                        var calcuLinkResult = allCalcuVisualResultDict?.GetValue(translation.Code) as HydroCalcuLinkResult;
+                        if (calcuLinkResult != null)
+                        {
+                            if (calcuLinkResult.CalcuVelocity < 0)
+                            {
+                                item.SpeedX = -item.SpeedX;
+                            }
+                        }
+                    }
+                    break;
+                case Yw.Hydro.ParterCatalog.Blunthead:
+                    {
+                        HydroBluntheadInfo blunthead = visual as HydroBluntheadInfo;
+                        item = new LogicFlowEffect();
+                        item.Id = blunthead.Code;
+                        item.Rotation = 90;
+                        item.SpeedX = 0.1;
+                        if (blunthead.FlowDirectionX == Yw.Hydro.FlowDirection.None)
+                        {
+                            item.SpeedX = 0;
+                        }
+                        else if (blunthead.FlowDirectionX == Yw.Hydro.FlowDirection.Positive)
+                        {
+                            item.SpeedX = 0.1;
+                        }
+                        else
+                        {
+                            item.SpeedX = -0.1;
+                        }
+                        if (blunthead.FlowDirectionY == Yw.Hydro.FlowDirection.None)
+                        {
+                            item.SpeedY = 0;
+                        }
+                        else if (blunthead.FlowDirectionY == Yw.Hydro.FlowDirection.Positive)
+                        {
+                            item.SpeedY = 0.1;
+                        }
+                        else
+                        {
+                            item.SpeedY = -0.1;
+                        }
+                    }
+                    break;
+                case Yw.Hydro.ParterCatalog.Elbow:
+                    {
+                        HydroElbowInfo elbow = visual as HydroElbowInfo;
+                        item = new LogicFlowEffect();
+                        item.Id = elbow.Code;
+                        item.Rotation = 90;
+                        item.SpeedX = 0.1;
+                        if (elbow.FlowDirectionX == Yw.Hydro.FlowDirection.None)
+                        {
+                            item.SpeedX = 0;
+                        }
+                        else if (elbow.FlowDirectionX == Yw.Hydro.FlowDirection.Positive)
+                        {
+                            item.SpeedX = 0.1;
+                        }
+                        else
+                        {
+                            item.SpeedX = -0.1;
+                        }
+                        if (elbow.FlowDirectionY == Yw.Hydro.FlowDirection.None)
+                        {
+                            item.SpeedY = 0;
+                        }
+                        else if (elbow.FlowDirectionY == Yw.Hydro.FlowDirection.Positive)
+                        {
+                            item.SpeedY = 0.1;
+                        }
+                        else
+                        {
+                            item.SpeedY = -0.1;
+                        }
+                    }
+                    break;
+                case Yw.Hydro.ParterCatalog.Threelink:
+                    {
+                        HydroThreelinkInfo threelink = visual as HydroThreelinkInfo;
+                        item = new LogicFlowEffect();
+                        item.Id = threelink.Code;
+                        item.Rotation = 90;
+                        item.SpeedX = 0.1;
+                        if (threelink.FlowDirectionX == Yw.Hydro.FlowDirection.None)
+                        {
+                            item.SpeedX = 0;
+                        }
+                        else if (threelink.FlowDirectionX == Yw.Hydro.FlowDirection.Positive)
+                        {
+                            item.SpeedX = 0.1;
+                        }
+                        else
+                        {
+                            item.SpeedX = -0.1;
+                        }
+                        if (threelink.FlowDirectionY == Yw.Hydro.FlowDirection.None)
+                        {
+                            item.SpeedY = 0;
+                        }
+                        else if (threelink.FlowDirectionY == Yw.Hydro.FlowDirection.Positive)
+                        {
+                            item.SpeedY = 0.1;
+                        }
+                        else
+                        {
+                            item.SpeedY = -0.1;
+                        }
+                    }
+                    break;
+                case Yw.Hydro.ParterCatalog.Fourlink:
+                    {
+                        HydroFourlinkInfo fourlink = visual as HydroFourlinkInfo;
+                        item = new LogicFlowEffect();
+                        item.Id = fourlink.Code;
+                        item.Rotation = 90;
+                        item.SpeedX = 0.1;
+                        if (fourlink.FlowDirectionX == Yw.Hydro.FlowDirection.None)
+                        {
+                            item.SpeedX = 0;
+                        }
+                        else if (fourlink.FlowDirectionX == Yw.Hydro.FlowDirection.Positive)
+                        {
+                            item.SpeedX = 0.1;
+                        }
+                        else
+                        {
+                            item.SpeedX = -0.1;
+                        }
+                        if (fourlink.FlowDirectionY == Yw.Hydro.FlowDirection.None)
+                        {
+                            item.SpeedY = 0;
+                        }
+                        else if (fourlink.FlowDirectionY == Yw.Hydro.FlowDirection.Positive)
+                        {
+                            item.SpeedY = 0.1;
+                        }
+                        else
+                        {
+                            item.SpeedY = -0.1;
                         }
                     }
                     break;
@@ -130,7 +312,7 @@
         {
             if (this.Visible)
             {
-                _views?.ForEach(async x => await x.LoadFlowEffect(this.Items));
+                _views?.ForEach(async x => await x.LoadFlowEffect(_cache.Values.ToList()));
             }
             else
             {
@@ -147,30 +329,12 @@
             {
                 return;
             }
-            var oldItem = this.Items?.Find(x => x.Id == visual.Code);
-            if (oldItem != null)
-            {
-                if (this.Items != null)
-                {
-                    this.Items.Remove(oldItem);
-                }
-                this.Items?.Remove(oldItem);
-            }
-            var allCalcuResultVisualDict = _calcuResult?.GetVisualDict();
-            var newItem = CreateItem(visual, allCalcuResultVisualDict);
-            if (newItem != null)
-            {
-                if (this.Items != null)
-                {
-                    this.Items.Add(newItem);
-                }
-            }
+            var allCalcuVisualResultDict = _calcuResultHelper?.GetVisualDict();
+            var item = CreateItem(visual, allCalcuVisualResultDict);
+            _cache[visual.Code] = item;
             if (this.Visible)
             {
-                if (newItem != null)
-                {
-                    _views?.ForEach(async x => await x.UpdateFlowEffect(newItem));
-                }
+                _views?.ForEach(async x => await x.UpdateFlowEffect(item));
             }
 
         }

--
Gitblit v1.9.3