From f5cdfeae3594e3e6e1461300e93c266ce79c1a8a Mon Sep 17 00:00:00 2001 From: lixiaojun <1287241240@qq.com> Date: 星期四, 05 十二月 2024 16:35:35 +0800 Subject: [PATCH] 属性代码恢复 --- WinFrmUI/Yw.WinFrmUI.Hydro.Core/00-core/05-extensions/HydroModelInfoExtensions.cs | 240 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 234 insertions(+), 6 deletions(-) diff --git a/WinFrmUI/Yw.WinFrmUI.Hydro.Core/00-core/05-extensions/HydroModelInfoExtensions.cs b/WinFrmUI/Yw.WinFrmUI.Hydro.Core/00-core/05-extensions/HydroModelInfoExtensions.cs index 9dc99eb..35bc429 100644 --- a/WinFrmUI/Yw.WinFrmUI.Hydro.Core/00-core/05-extensions/HydroModelInfoExtensions.cs +++ b/WinFrmUI/Yw.WinFrmUI.Hydro.Core/00-core/05-extensions/HydroModelInfoExtensions.cs @@ -1,17 +1,16 @@ -锘縰sing System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +锘縰sing Yw.EPAnet; +using Yw.Hydro; using Yw.Model; namespace Yw.WinFrmUI { /// <summary> - /// + /// 姘村姏淇℃伅鎷撳睍 /// </summary> public static class HydroModelInfoExtensions { + #region 鍙瀛楀吀 + /// <summary> /// 鑾峰彇鍙瀛楀吀 /// </summary> @@ -25,6 +24,235 @@ return allVisualList?.ToDictionary(x => x.Code); } + #endregion + + #region 淇绠$綉鏂瑰悜 + + /// <summary> + /// 淇绠$綉鏂瑰悜 + /// </summary> + public static bool RepairLinksDirection(this Yw.Model.HydroModelInfo hydroInfo, out string msg) + { + msg = string.Empty; + if (hydroInfo == null) + { + return false; + } + + var checkResult = hydroInfo.Check(); + if (!checkResult.Succeed) + { + msg = "妫�鏌ュけ璐ュ鑷存棤娉曡繘琛岃瘯绠楋紝鍋滄绠$綉淇锛�"; + return false; + } + + var calcuResult = hydroInfo.Calcu(Yw.EPAnet.CalcuMode.Simple); + if (!calcuResult.Succeed) + { + msg = "璇曠畻澶辫触锛屽仠姝㈢缃戜慨澶嶏紒"; + return false; + } + + var allLinkList = hydroInfo.GetAllLinks(); + if (allLinkList != null && allLinkList.Count < 1) + { + msg = "妯″瀷涓湭鍖呭惈绠℃淇℃伅锛屽仠姝㈢缃戜慨澶嶏紒"; + return false; + } + + int count = 0; + foreach (var link in allLinkList) + { + var calcuLink = calcuResult.LinkList?.Find(x => x.Code == link.Code); + if (calcuLink == null) + { + continue; + } + if (!calcuLink.CalcuFlow.HasValue) + { + continue; + } + if (calcuLink.CalcuFlow.Value < 0) + { + var tempCode = link.StartCode; + link.StartCode = link.EndCode; + link.EndCode = tempCode; + count++; + } + } + + msg = $"淇瀹屾垚锛屽叡淇绠℃({count})涓紒"; + return true; + } + + #endregion + + #region 淇鍙傛暟 + + private const double _pipe_diameter_default = 500;//绠¢亾榛樿鐩村緞 + private const double _pipe_roughness_default = 110;//绠¢亾榛樿绮楃硻绯绘暟 + private const double _pipe_minorloss_default = 0.1;//绠¢亾榛樿绮楃硻绯绘暟 + //闃�闂ㄩ粯璁ゅ眬闃荤郴鏁� + private const double _valve_minorloss_default = 0.3d; + + + /// <summary> + /// 淇鍙傛暟 + /// </summary> + public static void RepairParas(this Yw.Model.HydroModelInfo hydroInfo, out string msg) + { + msg = string.Empty; + if (hydroInfo == null) + { + return; + } + + var allNodes = hydroInfo.GetAllNodes(); + var allLinks = hydroInfo.GetAllLinks(); + + //绠¢亾 + if (hydroInfo.Pipes != null && hydroInfo.Pumps.Count > 0) + { + foreach (var pipe in hydroInfo.Pipes) + { + if (pipe.Diameter <= 0) + { + pipe.Diameter = _pipe_diameter_default; + pipe.UpdatePropStatus(nameof(pipe.Diameter), ePropStatus.Lack, $"鐩村緞缂虹渷锛屼娇鐢ㄩ粯璁ゅ�笺�恵_pipe_diameter_default}mm銆戜慨澶�"); + } + if (pipe.Roughness <= 0) + { + pipe.Roughness = _pipe_roughness_default; + pipe.UpdatePropStatus(nameof(pipe.Roughness), ePropStatus.Lack, $"绮楃硻绯绘暟缂虹渷锛屼娇鐢ㄩ粯璁ゅ�笺�恵_pipe_roughness_default}銆戜慨澶�"); + } + if (pipe.MinorLoss <= 0) + { + pipe.MinorLoss = _pipe_minorloss_default; + pipe.UpdatePropStatus(nameof(pipe.MinorLoss), ePropStatus.Lack, $"绮楃硻绯绘暟缂虹渷锛屼娇鐢ㄩ粯璁ゅ�笺�恵_pipe_minorloss_default}銆戜慨澶�"); + } + } + } + + //杩囨浮浠� + if (hydroInfo.Translations != null && hydroInfo.Translations.Count > 0) + { + foreach (var translation in hydroInfo.Translations) + { + if (translation.Diameter <= 0) + { + translation.Diameter = _pipe_diameter_default; + translation.UpdatePropStatus(nameof(translation.Diameter), ePropStatus.Lack, $"鐩村緞缂虹渷锛屼娇鐢ㄩ粯璁ゅ�笺�恵_pipe_diameter_default}mm銆戜慨澶�"); + } + if (translation.Roughness <= 0) + { + translation.Roughness = _pipe_roughness_default; + translation.UpdatePropStatus(nameof(translation.Roughness), ePropStatus.Lack, $"绮楃硻绯绘暟缂虹渷锛屼娇鐢ㄩ粯璁ゅ�笺�恵_pipe_roughness_default}銆戜慨澶�"); + } + if (translation.MinorLoss <= 0) + { + translation.MinorLoss = _pipe_minorloss_default; + translation.UpdatePropStatus(nameof(translation.MinorLoss), ePropStatus.Lack, $"绮楃硻绯绘暟缂虹渷锛屼娇鐢ㄩ粯璁ゅ�笺�恵_pipe_minorloss_default}銆戜慨澶�"); + } + } + foreach (var translation in hydroInfo.Translations) + { + double? tempDiameter = null; + var startNode = allNodes.Find(x => x.Code == translation.StartCode); + if (startNode != null) + { + var startLink = allLinks.Find(x => x.EndCode == startNode.Code); + if (startLink != null) + { + var startPipe = startLink as Yw.Model.HydroPipeInfo; + if (startPipe != null) + { + tempDiameter = startPipe.Diameter; + if (translation.StartDiameter != startPipe.Diameter) + { + translation.StartDiameter = startPipe.Diameter; + translation.UpdatePropStatus(nameof(translation.StartDiameter), ePropStatus.Lack, $"涓婃父鐩村緞缂虹渷锛屼娇鐢ㄤ笂娓哥閬撱�恵startPipe.Code}銆戜慨澶�"); + } + } + } + } + var endNode = allNodes.Find(x => x.Code == translation.EndCode); + if (endNode != null) + { + var endLink = allLinks.Find(x => x.StartCode == endNode.Code); + if (endLink != null) + { + var endPipe = endLink as Yw.Model.HydroPipeInfo; + if (endPipe != null) + { + if (translation.EndDiameter != endPipe.Diameter) + { + tempDiameter = endPipe.Diameter; + translation.EndDiameter = endPipe.Diameter; + translation.UpdatePropStatus(nameof(translation.EndDiameter), ePropStatus.Lack, $"涓嬫父鐩村緞缂虹渷锛屼娇鐢ㄤ笅娓哥閬撱�恵endPipe.Code}銆戜慨澶�"); + } + } + } + } + if (translation.StartDiameter <= 0) + { + if (tempDiameter.HasValue) + { + translation.StartDiameter = tempDiameter.Value; + } + } + if (translation.EndDiameter <= 0) + { + if (tempDiameter.HasValue) + { + translation.EndDiameter = tempDiameter.Value; + } + } + } + } + + //闃�闂� + if (hydroInfo.Valves != null && hydroInfo.Valves.Count > 0) + { + foreach (var valve in hydroInfo.Valves) + { + if (valve.MinorLoss <= 0) + { + valve.MinorLoss = _valve_minorloss_default; + valve.UpdatePropStatus(nameof(valve.MinorLoss), ePropStatus.Lack, $"灞�闃荤郴鏁扮己鐪侊紝浣跨敤榛樿鍊笺�恵_valve_minorloss_default}銆戜慨澶�"); + } + if (valve.Diameter <= 0) + { + var startNode = allNodes.Find(x => x.Code == valve.StartCode); + if (startNode != null) + { + var startPipe = allLinks.Find(x => x.EndCode == startNode.Code) as Yw.Model.HydroPipeInfo; + if (startPipe != null) + { + valve.Diameter = startPipe.Diameter; + valve.UpdatePropStatus(nameof(valve.Diameter), ePropStatus.Lack, $"鐩村緞缂虹渷锛屼娇鐢ㄤ笂娓哥閬撱�恵startPipe.Code}銆戜慨澶�"); + } + else + { + var endNode = allNodes.Find(x => x.Code == valve.EndCode); + if (endNode != null) + { + var endPipe = allLinks.Find(x => x.StartCode == endNode.Code) as Yw.Model.HydroPipeInfo; + if (endPipe != null) + { + valve.Diameter = endPipe.Diameter; + valve.UpdatePropStatus(nameof(valve.Diameter), ePropStatus.Lack, $"鐩村緞缂虹渷锛屼娇鐢ㄤ笅娓哥閬撱�恵endPipe.Code}銆戜慨澶�"); + } + } + } + } + } + } + } + + } + + + #endregion } } -- Gitblit v1.9.3