From 79fabf74a3fe97f1f2b8ae23e37cc33ba0d53ae2 Mon Sep 17 00:00:00 2001
From: cloudflight <cloudflight@126.com>
Date: 星期一, 10 六月 2024 22:25:49 +0800
Subject: [PATCH] [fix]修复器具ID对应异常的问题

---
 Hydraulic/Hydro.MapView/MapViewNetWork.cs |  157 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 156 insertions(+), 1 deletions(-)

diff --git a/Hydraulic/Hydro.MapView/MapViewNetWork.cs b/Hydraulic/Hydro.MapView/MapViewNetWork.cs
index 7ac683e..ec851d7 100644
--- a/Hydraulic/Hydro.MapView/MapViewNetWork.cs
+++ b/Hydraulic/Hydro.MapView/MapViewNetWork.cs
@@ -18,6 +18,7 @@
 using System.Runtime.InteropServices;
 using Hydro.HydraulicOptimizer;
 using Hydro.Core;
+using System.Xml.Linq;
 
 namespace Hydro.MapView
 {
@@ -35,6 +36,47 @@
         public NodeViewModel StartPoint { get; set; }
 
         public NodeViewModel EndPoint { get; set; }
+
+        public double[] getMinMax(ColourType colourType)
+        {
+            //鏍规嵁褰撳墠閫変腑鐨凜olourType,鍒ゆ柇鏄惁鏈夊搴旂殑缃戠粶鏁版嵁
+        
+            double max = 0;
+            double min = 0;
+
+            switch (colourType)
+            {
+                case ColourType.鑺傜偣鑷敱鍘嬪姏:
+                    max = Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Max(node => node.EN_PRESSURE);
+                    min = Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Min(node => node.EN_PRESSURE);
+                    break;
+                case ColourType.鑺傜偣缁濆鍘嬪姏:
+                    max = Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Max(node => node.EN_PRESSURE);
+                    min = Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Min(node => node.EN_PRESSURE);
+                    break;
+                case ColourType.鑺傜偣闇�姘撮噺:
+                    max = Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Max(node => node.EN_DEMAND);
+                    min = Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Min(node => node.EN_DEMAND);
+                    break;
+                case ColourType.绠$嚎娴侀噺:
+                    max = Links.Max(link => link.EN_FLOW);
+                    min = Links.Min(link => link.EN_FLOW);
+                    break;
+                case ColourType.绠$嚎娴侀��:
+                    max = Links.Max(link => link.EN_VELOCITY);
+                    min = Links.Min(link => link.EN_VELOCITY);
+                    break;
+                default:
+                    break;
+
+            }
+            return new double[] { min, max };
+        }
+
+        /// <summary>
+        /// 褰撻噺闆嗗悎锛屽綋閲忔ā鏉縄D锛�<鍣ㄥ叿ID锛屾暟閲�>
+        /// </summary>
+        //public Dictionary<long,Dictionary<long,int>> DlList { get; set; }
 
         /// <summary>
         /// 鏍稿績鎵胯浇瀛楁
@@ -387,6 +429,7 @@
             pipe.Status = StatusType.DEFAULT;
             pipe.StartNode = node1;
             pipe.EndNode = node2;
+            pipe.Length = -1;
 
 
 
@@ -566,7 +609,7 @@
                 EndPoint = network.EndPoint;
             }
         }
-        public List<IBaseViewModel> Add(MapViewNetWork net0, PointF3D offset = null, bool isCopy = false)
+        public List<IBaseViewModel> Add(MapViewNetWork net0, PointF3D offset = null, bool isCopy = false,NodeViewModel ConnectNode=null)
         {
             if (offset == null)
             {
@@ -610,6 +653,12 @@
                 Hash_ID.Add(l.ID);
                 list.Add(l);
             });
+            if (ConnectNode!=null)
+            {
+                var l = AddPipe(ConnectNode, net.StartPoint);
+                list.Add(l);
+                Hash_ID.Add(l.ID);
+            }
             //BuildRelation();
             return list;
         }
@@ -851,6 +900,61 @@
             return list;
             //return new List<TimePoint>();
         }
+        public List<TimePoint> WaterDistribution(string inpPath, string configPath = null,List<WaterEquivalentSettings> settings=null,double TotalDemand=-1,double InitPress=100)
+        {
+            if (TotalDemand < 0)
+            {
+                throw new Exception("TotalDemand must be set");
+            }
+            WdnmoParam wdnmoParam = new WdnmoParam();
+            wdnmoParam.UpdateWParamByWaterEquivalentSettings(settings, TotalDemand);
+            wdnmoParam.ScadaPoints.Add(new TimePoint { Key = "initPress", Value= InitPress });
+            Nodes.ForEach(n =>
+            {
+                //if (n is JunctionViewModel || n is MeterViewModel || n is NozzleViewModel)
+                {
+                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Press_{n.ID}" });
+                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Head_{n.ID}" });
+                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Demand_{n.ID}" });
+                }
+            });
+            Links.ForEach(n =>
+            {
+                //if (n is PipeViewModel || n is PumpViewModel || n is ValveViewModel)
+                {
+                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Flow_{n.ID}" });
+                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Velocity_{n.ID}" });
+                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Headloss_{n.ID}" });
+
+                }
+            });
+
+            calc c = new calc();
+            var list = c.GetCalcResult(inpPath, wdnmoParam, configPath);
+            if (list == null) return list;
+            list.Sort((a, b) => string.Compare(a.Key, b.Key));
+            Nodes.Sort((a, b) => string.Compare(a.ID, b.ID));
+            Links.Sort((a, b) => string.Compare(a.ID, b.ID));
+            SetNodeFromWparam(this, list, "Press");
+            SetNodeFromWparam(this, list, "Head");
+            SetNodeFromWparam(this, list, "Demand");
+
+            SetLinkFromWparam(this, list, "Flow");
+            SetLinkFromWparam(this, list, "Velocity");
+            SetLinkFromWparam(this, list, "Headloss");
+
+            Links.ForEach(l =>
+            {
+                l.EN_HEADLOSS_MINOR = (float)Math.Round(l.MinorLoss * Math.Pow(l.EN_VELOCITY, 2) / 2 / 9.8, 4);
+                l.EN_HEADLOSS_LINE = l.EN_HEADLOSS - l.EN_HEADLOSS_MINOR;
+            });
+            Nodes.ForEach(n => n.Demand = n.EN_DEMAND);
+            this._isCalculated = true;
+            return list;
+            //return new List<TimePoint>();
+        }
+
+        
 
         public List<TimePoint> CalcByVal(WDNModelOptimizer wdo, Result val)
         {
@@ -903,6 +1007,57 @@
             //return new List<TimePoint>();
         }
 
+        public List<TimePoint> CalcByValAndHead(WDNModelOptimizer wdo, Result val,double Head)
+        {
+
+            WdnmoParam wdnmoParam = new WdnmoParam();
+
+
+            Nodes.ForEach(n =>
+            {
+                //if (n is JunctionViewModel || n is MeterViewModel || n is NozzleViewModel)
+                {
+                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Press_{n.ID}" });
+                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Head_{n.ID}" });
+                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Demand_{n.ID}" });
+                }
+            });
+            Links.ForEach(n =>
+            {
+                //if (n is PipeViewModel || n is PumpViewModel || n is ValveViewModel)
+                {
+                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Flow_{n.ID}" });
+                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Velocity_{n.ID}" });
+                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Headloss_{n.ID}" });
+
+                }
+            });
+            calcParam calcParam = new calcParam();
+            calcParam.vars = val.arrayTryValue;
+            calcParam.setVars = new List<SetVar>();
+            reservoirs.ForEach(r =>
+            {
+                calcParam.setVars.Add(new SetVar(r.ID, true, (int)EpanetEnum.NodeValueType.姘存睜姘翠綅, (float)Head));
+            });
+
+            wdnmoParam = wdo.CalcbyResult(calcParam, wdnmoParam);
+            var list = wdnmoParam.ResultPoints;
+            if (list == null) return list;
+            list.Sort((a, b) => string.Compare(a.Key, b.Key));
+            Nodes.Sort((a, b) => string.Compare(a.ID, b.ID));
+            Links.Sort((a, b) => string.Compare(a.ID, b.ID));
+            SetNodeFromWparam(this, list, "Press");
+            SetNodeFromWparam(this, list, "Head");
+            SetNodeFromWparam(this, list, "Demand");
+
+            SetLinkFromWparam(this, list, "Flow");
+            SetLinkFromWparam(this, list, "Velocity");
+            SetLinkFromWparam(this, list, "Headloss");
+            this._isCalculated = true;
+            return list;
+            //return new List<TimePoint>();
+        }
+
         private void SetNodeFromWparam(MapViewNetWork net, List<TimePoint> list, string valueType)
         {
             int k1 = 0;

--
Gitblit v1.9.3