lixiaojun
2025-04-09 9aa8106d88fc3070498493e2819922f7ac31746e
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));
            }
        }