using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using Yw.WinFrmUI.Q3d;
|
using Yw.EPAnet;
|
using System.IO;
|
|
|
namespace Hydro.ClientTool
|
{
|
public partial class Form3 : Form
|
{
|
public NetworkViewModel _net { get; set; }
|
|
public Network _network { get; set; }
|
|
public Form3()
|
{
|
InitializeComponent();
|
}
|
|
private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
|
{
|
//打开文件对话框,选择inp类型的文件
|
var ofd = new OpenFileDialog();
|
ofd.Filter = "inp文件|*.inp";
|
if (ofd.ShowDialog() == DialogResult.OK)
|
{
|
|
//string inptxt = File.ReadAllText(ofd.FileName);
|
_network = InpInteropHelper.FromInpString(ofd.FileName);
|
|
_net = ConvertNetworkToNetworkViewModel(_network);
|
map.SetData(_net);
|
}
|
|
|
|
}
|
public NetworkViewModel ConvertNetworkToNetworkViewModel(Network network)
|
{
|
NetworkViewModel net = new NetworkViewModel();
|
network.GetAllLinks().ForEach(l =>
|
{
|
if (l is Pipe)
|
{
|
Pipe pipe = l as Pipe;
|
net.Links.Add(new PipeViewModel()
|
{
|
ID = pipe.Id,
|
Node1 = pipe.StartNode.Id,
|
Node2 = pipe.EndNode.Id,
|
Length = (float)pipe.Length,
|
Diameter = (float)pipe.Diameter,
|
Roughness = (float)pipe.Roughness,
|
Status = (ObjectEnum.StatusType)Enum.Parse(typeof(ObjectEnum.StatusType), pipe.LinkStatus.ToUpper()),
|
});
|
}
|
else if (l is Pump)
|
{
|
Pump pump = l as Pump;
|
net.Links.Add(new PumpViewModel()
|
{
|
ID = pump.Id,
|
Node1 = pump.StartNode.Id,
|
Node2 = pump.EndNode.Id,
|
HeadCurve = pump.CurveQH,
|
Status = (ObjectEnum.StatusType)Enum.Parse(typeof(ObjectEnum.StatusType), pump.LinkStatus.ToUpper()),
|
});
|
}
|
else if (l is Valve)
|
{
|
Valve valve = l as Valve;
|
net.Links.Add(new ValveViewModel()
|
{
|
ID = valve.Id,
|
Node1 = valve.StartNode.Id,
|
Node2 = valve.EndNode.Id,
|
Diameter = (float)valve.Diameter,
|
Setting = valve.ValveSetting,
|
Status = (ObjectEnum.StatusType)Enum.Parse(typeof(ObjectEnum.StatusType), valve.LinkStatus.ToUpper()),
|
});
|
}
|
else if (l is Exchanger)
|
{
|
Exchanger valve = l as Exchanger;
|
net.Links.Add(new HeatExchanger()
|
{
|
ID = valve.Id,
|
Node1 = valve.StartNode.Id,
|
Node2 = valve.EndNode.Id,
|
Diameter = (float)valve.Diameter,
|
Setting = valve.CurveQL,
|
Status = (ObjectEnum.StatusType)Enum.Parse(typeof(ObjectEnum.StatusType), valve.LinkStatus.ToUpper()),
|
});
|
}
|
else if (l is Compressor)
|
{
|
Compressor valve = l as Compressor;
|
net.Links.Add(new AirCompressor()
|
{
|
ID = valve.Id,
|
Node1 = valve.StartNode.Id,
|
Node2 = valve.EndNode.Id,
|
Diameter = (float)valve.Diameter,
|
Setting = valve.CurveQL,
|
Status = (ObjectEnum.StatusType)Enum.Parse(typeof(ObjectEnum.StatusType), valve.LinkStatus.ToUpper()),
|
});
|
}
|
|
});
|
|
network.GetAllNodes().ForEach(n =>
|
{
|
if (n is Junction)
|
{
|
var junction = (Junction)n;
|
net.Nodes.Add(new JunctionViewModel()
|
{
|
ID = junction.Id,
|
X = (float)junction.Position.X,
|
Y = (float)junction.Position.Y,
|
Z = (float)junction.Elev,
|
Demand = (float)junction.Demand,
|
PatternID = junction.DemandPattern,
|
});
|
}
|
else if (n is Tank)
|
{
|
var tank = (Tank)n;
|
net.Nodes.Add(new TankViewModel()
|
{
|
ID = tank.Id,
|
X = (float)tank.Position.X,
|
Y = (float)tank.Position.Y,
|
Z = (float)tank.PoolElev,
|
InitLevel = (float)tank.InitLevel,
|
MinLevel = (float)tank.MinLevel,
|
MaxLevel = (float)tank.MaxLevel,
|
Diameter = (float)tank.Diameter,
|
});
|
}
|
else if (n is Reservoir)
|
{
|
var reservoir = (Reservoir)n;
|
net.Nodes.Add(new ReservoirViewModel()
|
{
|
ID = reservoir.Id,
|
X = (float)reservoir.Position.X,
|
Y = (float)reservoir.Position.Y,
|
Z = (float)(reservoir.PoolElev ?? 0),
|
Head = (float)reservoir.Head,
|
});
|
}
|
else if (n is Emitter)
|
{
|
var emitter = (Emitter)n;
|
net.Nodes.Add(new NozzleViewModel()
|
{
|
ID = emitter.Id,
|
X = (float)emitter.Position.X,
|
Y = (float)emitter.Position.Y,
|
Z = (float)emitter.Elev,
|
FlowCoefficient = (float)emitter.Coefficient,
|
});
|
}
|
else if (n is Meter)
|
{
|
var meter = (Meter)n;
|
net.Nodes.Add(new MeterViewModel()
|
{
|
ID = meter.Id,
|
X = (float)meter.Position.X,
|
Y = (float)meter.Position.Y,
|
Z = (float)meter.Elev,
|
Demand = (float)meter.Demand,
|
PatternID = meter.DemandPattern,
|
});
|
}
|
});
|
net.BuildRelation();
|
return net;
|
}
|
|
private void Form3_Load(object sender, EventArgs e)
|
{
|
|
}
|
|
|
|
private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)
|
{
|
this.Close();
|
}
|
|
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);
|
map.SetSelectObj(links.Select(l=>l.Id).ToList());
|
|
}
|
|
|
}
|
}
|
}
|