| | |
| | | using Yw.WinFrmUI.Q3d; |
| | | using Yw.EPAnet; |
| | | using System.IO; |
| | | |
| | | using Newtonsoft.Json; |
| | | |
| | | namespace Hydro.ClientTool |
| | | { |
| | | public partial class Form3 : Form |
| | | { |
| | | public NetworkViewModel _net { get; set; } |
| | | public NetworkViewModel _viewnet { get; set; } |
| | | |
| | | public Network _network { get; set; } |
| | | |
| | | public Dictionary<string, Node> dictNodes { get; set; } |
| | | public Dictionary<string, Link> dictLinks { get; set; } |
| | | public Form3() |
| | | { |
| | | InitializeComponent(); |
| | |
| | | { |
| | | //打开文件对话框,选择inp类型的文件 |
| | | var ofd = new OpenFileDialog(); |
| | | ofd.Filter = "inp文件|*.inp"; |
| | | ofd.Filter = "json文件|*.json|inp文件|*.inp"; |
| | | if (ofd.ShowDialog() == DialogResult.OK) |
| | | { |
| | | |
| | | //string inptxt = File.ReadAllText(ofd.FileName); |
| | | _network = InpInteropHelper.FromInpString(ofd.FileName); |
| | | //如果是inp文件,调用InpInteropHelper.FromInpString方法,将inp文件转换为Network对象 |
| | | //如果是json文件,直接调用JsonConvert.DeserializeObject方法,将json文件转换为Network对象 |
| | | if (ofd.FileName.EndsWith(".inp")) |
| | | //_network = InpInteropHelper.FromInpString(ofd.FileName); |
| | | _network = InpInteropHelper.FromInpString(ofd.FileName); |
| | | else |
| | | { |
| | | string inptxt = File.ReadAllText(ofd.FileName); |
| | | _network = JsonConvert.DeserializeObject<Network>(inptxt); |
| | | //_network.GetAllNodes().ForEach(n => |
| | | //{ |
| | | // n.Links = new List<Link>(); |
| | | //}); |
| | | dictNodes = _network.GetAllNodes().ToDictionary(n => n.Id); |
| | | _network.GetAllLinks().ForEach(l => |
| | | { |
| | | l.StartNode = dictNodes[l.StartNode.Id]; |
| | | l.EndNode = dictNodes[l.EndNode.Id]; |
| | | |
| | | _net = ConvertNetworkToNetworkViewModel(_network); |
| | | map.SetData(_net); |
| | | }); |
| | | dictLinks = _network.GetAllLinks().ToDictionary(l => l.Id); |
| | | |
| | | _network.GetAllLinks().ForEach(l => |
| | | { |
| | | if (l.StartNode.Links == null) l.StartNode.Links = new List<Link>(); |
| | | if (l.EndNode.Links == null) l.EndNode.Links = new List<Link>(); |
| | | l.StartNode.Links.Add(l); |
| | | l.EndNode.Links.Add(l); |
| | | }); |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | _viewnet = ConvertNetworkToNetworkViewModel(_network); |
| | | map.SetData(_viewnet); |
| | | map.SelectedObjectsChanged += (oo, ee) => |
| | | { |
| | | if (map.selectedObjs.Count > 1) |
| | | { |
| | | propertyGrid1.SelectedObjects = map.selectedObjs.ToArray(); |
| | | } |
| | | else if (map.selectedObjs.Count == 1) |
| | | { |
| | | propertyGrid1.SelectedObject = map.selectedObjs[0]; |
| | | } |
| | | else |
| | | { |
| | | propertyGrid1.SelectedObject = null; |
| | | } |
| | | }; |
| | | } |
| | | |
| | | |
| | |
| | | Length = (float)pipe.Length, |
| | | Diameter = (float)pipe.Diameter, |
| | | Roughness = (float)pipe.Roughness, |
| | | Status = (ObjectEnum.StatusType)Enum.Parse(typeof(ObjectEnum.StatusType), pipe.LinkStatus.ToUpper()), |
| | | Status = pipe.LinkStatus == null ? ObjectEnum.StatusType.DEFAULT : (ObjectEnum.StatusType)Enum.Parse(typeof(ObjectEnum.StatusType), pipe.LinkStatus.ToUpper()), |
| | | }); |
| | | } |
| | | else if (l is Pump) |
| | |
| | | Node1 = pump.StartNode.Id, |
| | | Node2 = pump.EndNode.Id, |
| | | HeadCurve = pump.CurveQH, |
| | | Status = (ObjectEnum.StatusType)Enum.Parse(typeof(ObjectEnum.StatusType), pump.LinkStatus.ToUpper()), |
| | | Status = pump.LinkStatus == null ? ObjectEnum.StatusType.DEFAULT : (ObjectEnum.StatusType)Enum.Parse(typeof(ObjectEnum.StatusType), pump.LinkStatus.ToUpper()), |
| | | }); |
| | | } |
| | | else if (l is Valve) |
| | |
| | | Node2 = valve.EndNode.Id, |
| | | Diameter = (float)valve.Diameter, |
| | | Setting = valve.ValveSetting, |
| | | Status = (ObjectEnum.StatusType)Enum.Parse(typeof(ObjectEnum.StatusType), valve.LinkStatus.ToUpper()), |
| | | Status = valve.LinkStatus == null ? ObjectEnum.StatusType.DEFAULT : (ObjectEnum.StatusType)Enum.Parse(typeof(ObjectEnum.StatusType), valve.LinkStatus.ToUpper()), |
| | | }); |
| | | } |
| | | else if (l is Exchanger) |
| | |
| | | |
| | | private void Form3_Load(object sender, EventArgs e) |
| | | { |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | this.Close(); |
| | | } |
| | | |
| | | |
| | | |
| | | private void 简单计算ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | CalcuResult result = _network.Calcu(CalcuMode.Simple); |
| | | //将计算结果建立node字典和link字典 |
| | | Dictionary<string, CalcuNode> dictNodes = result.NodeList.ToDictionary(n => n.Id); |
| | | Dictionary<string, CalcuLink> dictLinks = result.LinkList.ToDictionary(l => l.Id); |
| | | //将计算结果显示在_net中 |
| | | _viewnet.Links.ForEach(l => |
| | | { |
| | | if (dictLinks.ContainsKey(l.ID)) |
| | | { |
| | | l.EN_FLOW = (float)dictLinks[l.ID].Flow; |
| | | l.EN_VELOCITY = (float)dictLinks[l.ID].Velocity; |
| | | l.EN_HEADLOSS = (float)dictLinks[l.ID].Headloss; |
| | | |
| | | } |
| | | }); |
| | | _viewnet.Nodes.ForEach(n => |
| | | { |
| | | if (dictNodes.ContainsKey(n.ID)) |
| | | { |
| | | n.EN_HEAD = (float)dictNodes[n.ID].Head; |
| | | n.EN_PRESSURE = (float)dictNodes[n.ID].Press; |
| | | n.EN_DEMAND = (float)dictNodes[n.ID].Demand; |
| | | |
| | | } |
| | | }); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | private void 局部损失计算ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | var result = _network.Calcu(CalcuMode.MinorLoss); |
| | | } |
| | | |
| | | private void 下游路径分析ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | if (_network == null) |
| | |
| | | MessageBox.Show("请先打开文件"); |
| | | return; |
| | | } |
| | | if (map.selectedObjs.Count>0 && map.selectedObjs[0] is NodeViewModel node) |
| | | if (map.selectedObjs.Count > 0 && map.selectedObjs[0] is NodeViewModel node) |
| | | { |
| | | var calcResult= _network.Calcu(CalcuMode.MinorLoss); |
| | | var Snode=_network.GetAllNodes().FirstOrDefault(n=>n.Id== node.ID); |
| | | var calcResult = _network.Calcu(CalcuMode.MinorLoss); |
| | | var Snode = _network.GetAllNodes().FirstOrDefault(n => n.Id == node.ID); |
| | | var links = _network.AnalyzeDownstreamPath(Snode, calcResult); |
| | | map.SetSelectObj(links.Select(l=>l.Id).ToList()); |
| | | if (links == null || links.Count <= 0) return; |
| | | map.SetSelectObj(links.Select(l => l.Id).ToList()); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | private void 沿程纵断面分析ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | if (_network == null) |
| | | { |
| | | MessageBox.Show("请先打开文件"); |
| | | return; |
| | | } |
| | | if (map.selectedObjs.Count > 0 && map.selectedObjs[0] is NodeViewModel node) |
| | | { |
| | | var calcResult = _network.Calcu(CalcuMode.MinorLoss); |
| | | var Snode = _network.GetAllNodes().FirstOrDefault(n => n.Id == node.ID); |
| | | var links = _network.AnalyzeDownstreamPath(Snode, calcResult); |
| | | if (links == null || links.Count <= 0) return; |
| | | |
| | | map.SetSelectObj(links.Select(l => l.Id).ToList()); |
| | | var result = _network.GetChartNodeByPathLinks(links, calcResult); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | private void iNPToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | //打开文件对话框,将 _network.ToInpString();导出 |
| | | var sfd = new SaveFileDialog(); |
| | | sfd.Filter = "inp文件|*.inp"; |
| | | if (sfd.ShowDialog() == DialogResult.OK) |
| | | { |
| | | File.WriteAllText(sfd.FileName, _network.ToInpString()); |
| | | } |
| | | } |
| | | } |
| | | } |