From 7c4fde84af5d666236c85b784bf13c9295bcb605 Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期二, 29 十月 2024 14:18:46 +0800
Subject: [PATCH] bimface 业务计算显示距离设定

---
 WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/06-simulation/XhsProjectSimulationCorePage.cs |  429 +++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 301 insertions(+), 128 deletions(-)

diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/06-simulation/XhsProjectSimulationCorePage.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/06-simulation/XhsProjectSimulationCorePage.cs
index 766069a..f3781c9 100644
--- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/06-simulation/XhsProjectSimulationCorePage.cs
+++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/06-simulation/XhsProjectSimulationCorePage.cs
@@ -1,7 +1,9 @@
 锘縢lobal using Yw.EPAnet;
 using DevExpress.Mvvm.Native;
 using DevExpress.XtraRichEdit.Layout;
+using DevExpress.XtraSpreadsheet.Commands;
 using HStation.WinFrmUI.PhartRelation;
+using Yw.Pump;
 using Yw.WinFrmUI.Bimface;
 using Yw.WinFrmUI.Hydro;
 
@@ -152,7 +154,7 @@
 
         #endregion
 
-        #region 灞炴�ч潰鏉�
+        #region 鏋勪欢灞炴��
 
         //灞炴�ф帶浠�
         private XhsProjectSimulationPropertyCtrl _propertyCtrl = null;
@@ -245,50 +247,22 @@
             {
                 ShowPropertyCtrl();
             }
-
             if (_parter == null)
             {
                 _propertyCtrl?.SelectParter(null);
                 return;
             }
-
             _propertyCtrl?.SelectParter(_parter.Code);
-            if (_calcuResult != null)
-            {
-                if (_calcuResult.Succeed)
-                {
-                    var allCalcuParterList = _calcuResult.GetParterList();
-                    var calcuParter = allCalcuParterList.Find(x => x.Id == _parter.Code);
-                    if (calcuParter != null)
-                    {
-                        IHydroCalcuResult calcuProperty = null;
-                        if (calcuParter is Yw.EPAnet.CalcuNode calcuNode)
-                        {
-                            var calcuNodeProperty = new Yw.WinFrmUI.HydroCalcuNodeResult();
-                            calcuNodeProperty.Code = _parter.Code;
-                            calcuNodeProperty.CalcuPress = calcuNode.Press;
-                            calcuNodeProperty.CalcuDemand = calcuNode.Demand;
-                            calcuNodeProperty.CalcuHead = calcuNode.Head;
-                            calcuProperty = calcuNodeProperty;
-                        }
-                        else if (calcuParter is Yw.EPAnet.CalcuLink calcuLink)
-                        {
-                            var calcuLinkProperty = new Yw.WinFrmUI.HydroCalcuLinkResult();
-                            calcuLinkProperty.Code = _parter.Code;
-                            calcuLinkProperty.CalcuHeadLoss = calcuLink.Headloss;
-                            calcuLinkProperty.CalcuFlow = calcuLink.Flow;
-                            calcuLinkProperty.CalcuVelocity = calcuLink.Velocity;
-                            calcuProperty = calcuLinkProperty;
-                        }
 
-                        if (calcuProperty != null)
-                        {
-                            _propertyCtrl?.UpdateCalcuProperty(calcuProperty);
-                        }
-                    }
+            var allCalcuResultList = GetAllCalcuResultList();
+            if (allCalcuResultList != null && allCalcuResultList.Count > 0)
+            {
+                var calcuResult = allCalcuResultList.Find(x => x.Code == _parter.Code);
+                if (calcuResult != null)
+                {
+                    _propertyCtrl?.UpdateCalcuProperty(calcuResult);
                 }
             }
-
         }
 
         #endregion
@@ -483,7 +457,7 @@
             return _checkCtrl;
         }
 
-        //鏄剧ず鏍¢獙鎺т欢
+        //鏄剧ず妫�鏌ユ帶浠�
         private void ShowCheckCtrl()
         {
             if (_checkResult == null)
@@ -495,12 +469,12 @@
             this.controlContainerBottom.Controls.Clear();
             this.controlContainerBottom.Controls.Add(checkCtrl);
             this.docPnlBottom.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
-            this.docPnlBottom.Text = "鏍¢獙缁撴灉";
+            this.docPnlBottom.Text = "妫�鏌ョ粨鏋�";
             this.docPnlBottom.Height = 350;
 
         }
 
-        //姘村姏楠岃瘉
+        //姘村姏妫�鏌�
         private void barBtnHydroCheck_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
         {
             if (_hydroInfo == null)
@@ -644,25 +618,111 @@
             //闂峰ご
             this.barBtnSetBluntheadList.ItemClick += delegate
             {
+                if (_hydroInfo == null)
+                {
+                    return;
+                }
                 var dlg = new HydroBluntheadBulkSetListDlg();
                 dlg.ShowDialog();
             };
             //寮ご
             this.barBtnSetElbowsList.ItemClick += delegate
             {
+                if (_hydroInfo == null)
+                {
+                    return;
+                }
                 var dlg = new HydroElbowBulkSetListDlg();
+                dlg.SetBindingData(_hydroInfo);
                 dlg.ShowDialog();
             };
             //涓夐��
             this.barBtnSetThreelinkList.ItemClick += delegate
             {
+                if (_hydroInfo == null)
+                {
+                    return;
+                }
                 var dlg = new HydroThreelinkBulkSetListDlg();
+                dlg.SetBindingData(_hydroInfo);
                 dlg.ShowDialog();
             };
             //鍥涢��
             this.barBtnSetFourlinkList.ItemClick += delegate
             {
-
+                if (_hydroInfo == null)
+                {
+                    return;
+                }
+                var dlg = new HydroFourlinkBulkSetListDlg();
+                dlg.SetBindingData(_hydroInfo);
+                dlg.ShowDialog();
+            };
+            //姘磋〃
+            this.barBtnSetMeterList.ItemClick += delegate
+            {
+                if (_hydroInfo == null)
+                {
+                    return;
+                }
+                var dlg = new HydroMeterBulkSetListDlg();
+                dlg.SetBindingData(_hydroInfo);
+                dlg.ShowDialog();
+            };
+            //娴侀噺璁�
+            this.barBtnSetFlowmeterList.ItemClick += delegate
+            {
+                if (_hydroInfo == null)
+                {
+                    return;
+                }
+                var dlg = new HydroFlowmeterBulkSetListDlg();
+                dlg.SetBindingData(_hydroInfo);
+                dlg.ShowDialog();
+            };
+            //鍘嬪姏琛�
+            this.barBtnSetPressmeterList.ItemClick += delegate
+            {
+                if (_hydroInfo == null)
+                {
+                    return;
+                }
+                var dlg = new HydroPressmeterBulkSetListDlg();
+                dlg.SetBindingData(_hydroInfo);
+                dlg.ShowDialog();
+            };
+            //绠¢亾
+            this.barBtnSetPipeList.ItemClick += delegate
+            {
+                if (_hydroInfo == null)
+                {
+                    return;
+                }
+                var dlg = new HydroPipeBulkSetListDlg();
+                dlg.SetBindingData(_hydroInfo);
+                dlg.ShowDialog();
+            };
+            //姘存车
+            this.barBtnSetPumpList.ItemClick += delegate
+            {
+                if (_hydroInfo == null)
+                {
+                    return;
+                }
+                var dlg = new HydroPumpBulkSetListDlg();
+                dlg.SetBindingData(_hydroInfo);
+                dlg.ShowDialog();
+            };
+            //闃�闂�
+            this.barBtnSetValveList.ItemClick += delegate
+            {
+                if (_hydroInfo == null)
+                {
+                    return;
+                }
+                var dlg = new HydroValveBulkSetListDlg();
+                dlg.SetBindingData(_hydroInfo);
+                dlg.ShowDialog();
             };
         }
 
@@ -947,7 +1007,7 @@
 
             }
 
-            var dlg = new PumpParallelChartDlg();
+            var dlg = new PumpParallelAnalyDlg();
             dlg.SetBindingData(vmList);
             dlg.ReloadDataEvent += (list) =>
             {
@@ -969,6 +1029,65 @@
         #endregion
 
         #region 姘村姏璁$畻
+
+
+        #region 鍓嶆彁鏉′欢
+
+        //鏄剧ず璁$畻鍓嶆彁鏉′欢绐椾綋
+        private async void ShowCalcuPrefixDlg()
+        {
+            if (_hydroInfo == null)
+            {
+                return;
+            }
+            var dlg = new SetHydroCalcuPrefixDlg();
+            dlg.SetBindingData(_hydroInfo);
+            dlg.HydroViewEvent += async (parter) =>
+            {
+                _parter = parter;
+                if (_parter != null)
+                {
+                    await _bimfaceCtrl?.ZoomAndSelectComponents(new List<string>() { _parter.Code });
+                }
+                ShowProperty();
+            };
+            dlg.HydroCalcuEvent += async () =>
+            {
+                if (_hydroInfo == null)
+                {
+                    return;
+                }
+
+                //鏍¢獙
+                _checkResult = _hydroInfo.Check();
+                if (!_checkResult.Succeed)
+                {
+                    ShowCheckCtrl();
+                    TipFormHelper.ShowWarn("鏍¢獙澶辫触锛岃妫�鏌ュ悗閲嶈瘯");
+                    return;
+                }
+
+                var netWork = Yw.Hydro.ParseHelper.ToNetwork(_hydroInfo);
+                _calcuResult = netWork.Calcu();
+                if (_calcuResult.Succeed)
+                {
+                    GetAllCalcuResultList(false);
+                    await _bimfaceCtrl?.SetLogicCalcuCustomLabels(_calcuResult);
+                    TipFormHelper.ShowSucceed("璁$畻鎴愬姛锛�");
+                }
+                else
+                {
+                    ShowCalcuFailedCtrl();
+                    TipFormHelper.ShowError("璁$畻澶辫触锛�");
+                }
+
+            };
+            dlg.ShowDialog();
+        }
+
+        #endregion
+
+        #region 璁$畻澶辫触
 
         //璁$畻澶辫触鎺т欢
         private HydroCalcuFailedCtrl _calcuFailedCtrl = null;
@@ -1008,8 +1127,16 @@
             this.docPnlBottom.Height = 350;
         }
 
+        #endregion
+
+        #region 璁$畻缁撴灉
+
+        //鎵�鏈夎绠楃粨鏋滃垪琛�
+        private List<HydroCalcuResult> _allCalcuResultList = null;
+
         //鑾峰彇璁$畻缁撴灉
-        private List<IHydroCalcuResult> GetAllCalcuResultList()
+        //true 浣跨敤缂撳瓨锛宖alse 涓嶄娇鐢ㄧ紦瀛�
+        private List<HydroCalcuResult> GetAllCalcuResultList(bool isCache = true)
         {
             if (_hydroInfo == null)
             {
@@ -1023,110 +1150,156 @@
             {
                 return default;
             }
-            var list = new List<IHydroCalcuResult>();
+            if (isCache)
+            {
+                return _allCalcuResultList;
+            }
+
+            _allCalcuResultList = new List<HydroCalcuResult>();
+
+            //鑺傜偣
             var allNodeList = _hydroInfo.GetAllNodes();
             if (allNodeList != null && allNodeList.Count > 0)
             {
-                var allCalcuNodeList = _calcuResult.NodeList;
-                if (allCalcuNodeList != null && allCalcuNodeList.Count > 0)
+                foreach (var node in allNodeList)
                 {
-                    foreach (var node in allNodeList)
+                    var calcuNode = _calcuResult.NodeList?.Find(x => x.Id == node.Code);
+                    if (calcuNode != null)
                     {
-                        var calcuNode = allCalcuNodeList.Find(x => x.Id == node.Code);
-                        if (calcuNode != null)
+                        var calcuResult = new HydroCalcuNodeResult()
                         {
-                            var calcuResult = new HydroCalcuNodeResult()
-                            {
-                                Code = node.Code,
-                                CalcuPress = calcuNode.Press,
-                                CalcuHead = calcuNode.Head,
-                                CalcuDemand = calcuNode.Demand
-                            };
-                            list.Add(calcuResult);
-                        }
+                            Code = node.Code,
+                            CalcuPress = calcuNode.Press,
+                            CalcuHead = calcuNode.Head,
+                            CalcuDemand = calcuNode.Demand
+                        };
+                        _allCalcuResultList.Add(calcuResult);
                     }
                 }
             }
 
-            var allListList = _hydroInfo.GetAllLinks();
-            if (allListList != null && allListList.Count > 0)
+            //绠℃
+            var allLinkList = _hydroInfo.GetAllLinks();
+            if (allLinkList != null && allLinkList.Count > 0)
             {
-                var allCalcuLinkList = _calcuResult.LinkList;
-                if (allCalcuLinkList != null && allCalcuLinkList.Count > 0)
+                foreach (var link in allLinkList)
                 {
-                    foreach (var link in allListList)
+                    var calcuLink = _calcuResult.LinkList?.Find(x => x.Id == link.Code);
+                    if (calcuLink != null)
                     {
-                        var calcuLink = allCalcuLinkList.Find(x => x.Id == link.Code);
-                        if (calcuLink != null)
+                        var calcuResult = new HydroCalcuLinkResult()
                         {
-                            var calcuResult = new HydroCalcuLinkResult()
-                            {
-                                Code = link.Code,
-                                CalcuFlow = calcuLink.Flow,
-                                CalcuVelocity = calcuLink.Velocity,
-                                CalcuHeadLoss = calcuLink.Headloss
-                            };
-                            list.Add(calcuResult);
-                        }
+                            Code = link.Code,
+                            CalcuFlow = calcuLink.Flow,
+                            CalcuVelocity = calcuLink.Velocity,
+                            CalcuHeadLoss = calcuLink.Headloss
+                        };
+                        _allCalcuResultList.Add(calcuResult);
                     }
                 }
             }
 
-            return list;
+            //娴侀噺璁�
+            var allFlowmeterList = _hydroInfo.Flowmeters;
+            if (allFlowmeterList != null && allFlowmeterList.Count > 0)
+            {
+                foreach (var flowmeter in allFlowmeterList)
+                {
+                    var calcuFlowmeterResult = _allCalcuResultList.Find(x => x.Code == flowmeter.Code) as HydroCalcuNodeResult;
+                    if (calcuFlowmeterResult != null)
+                    {
+                        var calcuFlowmeterNewResult = new HydroCalcuFlowmeterResult(calcuFlowmeterResult);
+                        var calcuFlowmeterLinkResultList = new List<HydroCalcuLinkResult>();
+                        var flowmeterLinkList = allLinkList?.Where(x => x.StartCode == flowmeter.Code || x.EndCode == flowmeter.Code).ToList();
+                        if (flowmeterLinkList != null && flowmeterLinkList.Count > 0)
+                        {
+                            foreach (var flowmeterLink in flowmeterLinkList)
+                            {
+                                var calcuFlowmeterLinkResult = _allCalcuResultList.Find(x => x.Code == flowmeterLink.Code) as HydroCalcuLinkResult;
+                                if (calcuFlowmeterLinkResult != null)
+                                {
+                                    calcuFlowmeterLinkResultList.Add(calcuFlowmeterLinkResult);
+                                }
+                            }
+                        }
+                        if (calcuFlowmeterLinkResultList.Exists(x => x.CalcuFlow.HasValue))
+                        {
+                            calcuFlowmeterNewResult.CalcuQ = calcuFlowmeterLinkResultList.Where(x => x.CalcuFlow.HasValue).Average(x => x.CalcuFlow.Value);
+                        }
+                        _allCalcuResultList.Remove(calcuFlowmeterResult);
+                        _allCalcuResultList.Add(calcuFlowmeterNewResult);
+                    }
+                }
+            }
+
+            //鍘嬪姏琛�
+            var allPressmeterList = _hydroInfo.Pressmeters;
+            if (allPressmeterList != null && allPressmeterList.Count > 0)
+            {
+                foreach (var pressmeter in allPressmeterList)
+                {
+                    var calcuPressmeterResult = _allCalcuResultList.Find(x => x.Code == pressmeter.Code) as HydroCalcuNodeResult;
+                    if (calcuPressmeterResult != null)
+                    {
+                        var calcuPressmeterNewResult = new HydroCalcuPressmeterResult(calcuPressmeterResult);
+                        calcuPressmeterNewResult.CalcuPr = calcuPressmeterResult.CalcuPress;
+                        _allCalcuResultList.Remove(calcuPressmeterResult);
+                        _allCalcuResultList.Add(calcuPressmeterNewResult);
+                    }
+                }
+            }
+
+            //姘存车
+            var allPumpList = _hydroInfo.Pumps;
+            if (allPumpList != null && allPumpList.Count > 0)
+            {
+                foreach (var pump in allPumpList)
+                {
+                    var calcuPumpResult = _allCalcuResultList.Find(x => x.Code == pump.Code) as HydroCalcuLinkResult;
+                    if (calcuPumpResult != null)
+                    {
+                        var calcuPumpNewResult = new HydroCalcuPumpResult(calcuPumpResult);
+                        calcuPumpNewResult.CalcuQ = calcuPumpResult.CalcuFlow;
+                        if (calcuPumpNewResult.CalcuQ.HasValue)
+                        {
+                            var calcuNodeStartResult = _allCalcuResultList.Find(x => x.Code == pump.StartCode) as HydroCalcuNodeResult;
+                            var calcuNodeEndResult = _allCalcuResultList.Find(x => x.Code == pump.EndCode) as HydroCalcuNodeResult;
+                            if (calcuNodeStartResult != null && calcuNodeEndResult != null)
+                            {
+                                if (calcuNodeStartResult.CalcuPress.HasValue && calcuNodeEndResult.CalcuPress.HasValue)
+                                {
+                                    calcuPumpNewResult.CalcuH = Math.Abs(calcuNodeStartResult.CalcuPress.Value - calcuNodeEndResult.CalcuPress.Value);
+                                }
+                                if (pump.LinkStatus == Yw.Hydro.PumpStatus.Open && pump.RatedN.HasValue)
+                                {
+                                    var curveqp = _hydroInfo.Curves?.Find(x => x.Code == pump.CurveQP);
+                                    if (curveqp != null)
+                                    {
+                                        if (curveqp.CurveData != null && curveqp.CurveData.Count > 3)
+                                        {
+                                            var point2dList = curveqp.CurveData.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
+                                            var point2dSimularList = point2dList.GetQPPointListByN(pump.RatedN.Value, pump.RatedN.Value * pump.SpeedRatio);
+                                            var pumpCurveQp = new Yw.Pump.CurveQP(eFeatType.Cubic, point2dSimularList);
+                                            calcuPumpNewResult.CalcuP = pumpCurveQp.FeatCurve.GetPointY(calcuPumpNewResult.CalcuQ.Value);
+                                        }
+                                    }
+                                }
+                                if (calcuPumpNewResult.CalcuH.HasValue && calcuPumpNewResult.CalcuP.HasValue)
+                                {
+                                    calcuPumpNewResult.CalcuE = Yw.Pump.CalculationHelper.CalcuE(calcuPumpNewResult.CalcuQ.Value, calcuPumpNewResult.CalcuH.Value, calcuPumpNewResult.CalcuP.Value);
+                                }
+                            }
+                        }
+                        _allCalcuResultList.Remove(calcuPumpResult);
+                        _allCalcuResultList.Add(calcuPumpNewResult);
+                    }
+                }
+            }
+
+            return _allCalcuResultList;
         }
 
-        //鏄剧ず璁$畻鍓嶆彁绐椾綋
-        private async void ShowCalcuPrefixDlg()
-        {
-            if (_hydroInfo == null)
-            {
-                return;
-            }
-            var dlg = new SetHydroCalcuPrefixDlg();
-            dlg.SetBindingData(_hydroInfo);
-            dlg.HydroViewEvent += async (parter) =>
-            {
-                _parter = parter;
-                if (_parter != null)
-                {
-                    await _bimfaceCtrl?.ZoomAndSelectComponents(new List<string>() { _parter.Code });
-                }
-                ShowProperty();
-            };
-            dlg.HydroCalcuEvent += async () =>
-            {
-                if (_hydroInfo == null)
-                {
-                    return;
-                }
-
-                //鏍¢獙
-                _checkResult = _hydroInfo.Check();
-                if (!_checkResult.Succeed)
-                {
-                    ShowCheckCtrl();
-                    TipFormHelper.ShowWarn("鏍¢獙澶辫触锛岃妫�鏌ュ悗閲嶈瘯");
-                    return;
-                }
-
-                var netWork = Yw.Hydro.ParseHelper.ToNetwork(_hydroInfo);
-                _calcuResult = netWork.Calcu();
-                if (_calcuResult.Succeed)
-                {
-                    await _bimfaceCtrl?.SetLogicCalcuCustomLabels(_calcuResult);
-                    TipFormHelper.ShowSucceed("璁$畻鎴愬姛锛�");
-                }
-                else
-                {
-                    ShowCalcuFailedCtrl();
-                    TipFormHelper.ShowError("璁$畻澶辫触锛�");
-                }
-            };
-            if (dlg.ShowDialog() == DialogResult.Cancel)
-            {
-                await _bimfaceCtrl?.ClearLogicCalcuCustomLabels();
-            }
-        }
+        #endregion
 
         //姘村姏璁$畻
         private void barBtnHydroCalcu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
@@ -1344,12 +1517,12 @@
             {
                 _allGradingCodeList = obj?.Select(x => x.Code).Distinct().ToList();
                 var objGroupList = obj?.GroupBy(x => x.Color).ToList();
-                objGroupList.ForEach(async x =>
+                objGroupList?.ForEach(async x =>
                 {
                     await _bimfaceCtrl?.OverrideComponentsColor(x.Select(t => t.Code).Distinct().ToList(), x.Key, 1);
                 });
             };
-            if (dlg.ShowDialog() != DialogResult.OK)
+            if (dlg.ShowDialog() == DialogResult.Cancel)
             {
                 await _bimfaceCtrl?.RestoreComponentsColor(_allGradingCodeList);
             }

--
Gitblit v1.9.3