using Yw.WinFrmUI.Q3d;
|
namespace Yw.WinFrmUI
|
{
|
/// <summary>
|
/// Q3d转换辅助类
|
/// </summary>
|
public static class HydroQ3dTransferHelper
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public static NetworkViewModel ToNetworkViewModel(this Yw.Model.HydroModelInfo rhs)
|
{
|
if (rhs == null)
|
{
|
return default;
|
}
|
var vm = new NetworkViewModel();
|
|
if (rhs.Reservoirs != null && rhs.Reservoirs.Count > 0)
|
{
|
foreach (var reservoir in rhs.Reservoirs)
|
{
|
var reservoirViewModel = new ReservoirViewModel();
|
reservoirViewModel.ID = reservoir.Code;
|
reservoirViewModel.Name = reservoir.Name;
|
reservoirViewModel.Position3D = new PointF3D((float)reservoir.Position3d.X, (float)reservoir.Position3d.Y, (float)reservoir.Position3d.Z);
|
vm.Nodes.Add(reservoirViewModel);
|
}
|
}
|
if (rhs.Tanks != null && rhs.Tanks.Count > 0)
|
{
|
foreach (var tank in rhs.Tanks)
|
{
|
var tankViewModel = new TankViewModel();
|
tankViewModel.ID = tank.Code;
|
tankViewModel.Name = tank.Name;
|
tankViewModel.Position3D = new PointF3D((float)tank.Position3d.X, (float)tank.Position3d.Y, (float)tank.Position3d.Z);
|
vm.Nodes.Add(tankViewModel);
|
}
|
}
|
if (rhs.Waterboxs != null && rhs.Waterboxs.Count > 0)
|
{
|
foreach (var waterbox in rhs.Waterboxs)
|
{
|
var waterboxViewModel = new TankViewModel();
|
waterboxViewModel.ID = waterbox.Code;
|
waterboxViewModel.Name = waterbox.Name;
|
waterboxViewModel.Position3D = new PointF3D((float)waterbox.Position3d.X, (float)waterbox.Position3d.Y, (float)waterbox.Position3d.Z);
|
vm.Nodes.Add(waterboxViewModel);
|
}
|
}
|
if (rhs.Junctions != null && rhs.Junctions.Count > 0)
|
{
|
foreach (var junction in rhs.Junctions)
|
{
|
var junctionViewModel = new JunctionViewModel();
|
junctionViewModel.ID = junction.Code;
|
junctionViewModel.Name = junction.Name;
|
junctionViewModel.Position3D = new PointF3D((float)junction.Position3d.X, (float)junction.Position3d.Y, (float)junction.Position3d.Z);
|
vm.Nodes.Add(junctionViewModel);
|
}
|
}
|
if (rhs.Nozzles != null && rhs.Nozzles.Count > 0)
|
{
|
foreach (var nozzle in rhs.Nozzles)
|
{
|
var nozzleViewModel = new NozzleViewModel();
|
nozzleViewModel.ID = nozzle.Code;
|
nozzleViewModel.Name = nozzle.Name;
|
nozzleViewModel.Position3D = new PointF3D((float)nozzle.Position3d.X, (float)nozzle.Position3d.Y, (float)nozzle.Position3d.Z);
|
vm.Nodes.Add(nozzleViewModel);
|
}
|
}
|
if (rhs.Hydrants != null && rhs.Hydrants.Count > 0)
|
{
|
foreach (var hydrant in rhs.Hydrants)
|
{
|
var hydrantViewModel = new JunctionViewModel();
|
hydrantViewModel.ID = hydrant.Code;
|
hydrantViewModel.Name = hydrant.Name;
|
hydrantViewModel.Position3D = new PointF3D((float)hydrant.Position3d.X, (float)hydrant.Position3d.Y, (float)hydrant.Position3d.Z);
|
vm.Nodes.Add(hydrantViewModel);
|
}
|
}
|
if (rhs.Coolings != null && rhs.Coolings.Count > 0)
|
{
|
foreach (var cooling in rhs.Coolings)
|
{
|
var coolingViewModel = new JunctionViewModel();
|
coolingViewModel.ID = cooling.Code;
|
coolingViewModel.Name = cooling.Name;
|
coolingViewModel.Position3D = new PointF3D((float)cooling.Position3d.X, (float)cooling.Position3d.Y, (float)cooling.Position3d.Z);
|
vm.Nodes.Add(coolingViewModel);
|
}
|
}
|
if (rhs.Bluntheads != null && rhs.Bluntheads.Count > 0)
|
{
|
foreach (var blunthead in rhs.Bluntheads)
|
{
|
var bluntheadViewModel = new JunctionViewModel();
|
bluntheadViewModel.ID = blunthead.Code;
|
bluntheadViewModel.Name = blunthead.Name;
|
bluntheadViewModel.Position3D = new PointF3D((float)blunthead.Position3d.X, (float)blunthead.Position3d.Y, (float)blunthead.Position3d.Z);
|
vm.Nodes.Add(bluntheadViewModel);
|
}
|
}
|
if (rhs.Elbows != null && rhs.Elbows.Count > 0)
|
{
|
foreach (var elbow in rhs.Elbows)
|
{
|
var elbowViewModel = new JunctionViewModel();
|
elbowViewModel.ID = elbow.Code;
|
elbowViewModel.Name = elbow.Name;
|
elbowViewModel.Position3D = new PointF3D((float)elbow.Position3d.X, (float)elbow.Position3d.Y, (float)elbow.Position3d.Z);
|
vm.Nodes.Add(elbowViewModel);
|
}
|
}
|
if (rhs.Threelinks != null && rhs.Threelinks.Count > 0)
|
{
|
foreach (var threelink in rhs.Threelinks)
|
{
|
var threelinkViewModel = new JunctionViewModel();
|
threelinkViewModel.ID = threelink.Code;
|
threelinkViewModel.Name = threelink.Name;
|
threelinkViewModel.Position3D = new PointF3D((float)threelink.Position3d.X, (float)threelink.Position3d.Y, (float)threelink.Position3d.Z);
|
vm.Nodes.Add(threelinkViewModel);
|
}
|
}
|
if (rhs.Fourlinks != null && rhs.Fourlinks.Count > 0)
|
{
|
foreach (var fourlink in rhs.Fourlinks)
|
{
|
var fourlinkViewModel = new JunctionViewModel();
|
fourlinkViewModel.ID = fourlink.Code;
|
fourlinkViewModel.Name = fourlink.Name;
|
fourlinkViewModel.Position3D = new PointF3D((float)fourlink.Position3d.X, (float)fourlink.Position3d.Y, (float)fourlink.Position3d.Z);
|
vm.Nodes.Add(fourlinkViewModel);
|
}
|
}
|
if (rhs.Meters != null && rhs.Meters.Count > 0)
|
{
|
foreach (var meter in rhs.Meters)
|
{
|
var meterViewModel = new MeterViewModel();
|
meterViewModel.ID = meter.Code;
|
meterViewModel.Name = meter.Name;
|
meterViewModel.Position3D = new PointF3D((float)meter.Position3d.X, (float)meter.Position3d.Y, (float)meter.Position3d.Z);
|
vm.Nodes.Add(meterViewModel);
|
}
|
}
|
if (rhs.Flowmeters != null && rhs.Flowmeters.Count > 0)
|
{
|
foreach (var flowmeter in rhs.Flowmeters)
|
{
|
var flowmeterViewModel = new JunctionViewModel();
|
flowmeterViewModel.ID = flowmeter.Code;
|
flowmeterViewModel.Name = flowmeter.Name;
|
flowmeterViewModel.Position3D = new PointF3D((float)flowmeter.Position3d.X, (float)flowmeter.Position3d.Y, (float)flowmeter.Position3d.Z);
|
vm.Nodes.Add(flowmeterViewModel);
|
}
|
}
|
if (rhs.Pressmeters != null && rhs.Pressmeters.Count > 0)
|
{
|
foreach (var pressmeter in rhs.Pressmeters)
|
{
|
var pressmeterViewModel = new JunctionViewModel();
|
pressmeterViewModel.ID = pressmeter.Code;
|
pressmeterViewModel.Name = pressmeter.Name;
|
pressmeterViewModel.Position3D = new PointF3D((float)pressmeter.Position3d.X, (float)pressmeter.Position3d.Y, (float)pressmeter.Position3d.Z);
|
vm.Nodes.Add(pressmeterViewModel);
|
}
|
}
|
|
if (rhs.Pipes != null && rhs.Pipes.Count > 0)
|
{
|
foreach (var pipe in rhs.Pipes)
|
{
|
var pipeViewModel = new PipeViewModel();
|
pipeViewModel.ID = pipe.Code;
|
pipeViewModel.Name = pipe.Name;
|
pipeViewModel.StartNode = vm.Nodes.Find(x => x.ID == pipe.StartCode);
|
pipeViewModel.EndNode = vm.Nodes.Find(x => x.ID == pipe.EndCode);
|
vm.Links.Add(pipeViewModel);
|
}
|
}
|
if (rhs.Translations != null && rhs.Translations.Count > 0)
|
{
|
foreach (var translation in rhs.Translations)
|
{
|
var translationViewModel = new PipeViewModel();
|
translationViewModel.ID = translation.Code;
|
translationViewModel.Name = translation.Name;
|
translationViewModel.StartNode = vm.Nodes.Find(x => x.ID == translation.StartCode);
|
translationViewModel.EndNode = vm.Nodes.Find(x => x.ID == translation.EndCode);
|
vm.Links.Add(translationViewModel);
|
}
|
}
|
|
if (rhs.Pumps != null && rhs.Pumps.Count > 0)
|
{
|
foreach (var pump in rhs.Pumps)
|
{
|
var pumpViewModel = new PumpViewModel();
|
pumpViewModel.ID = pump.Code;
|
pumpViewModel.Name = pump.Name;
|
pumpViewModel.StartNode = vm.Nodes.Find(x => x.ID == pump.StartCode);
|
pumpViewModel.EndNode = vm.Nodes.Find(x => x.ID == pump.EndCode);
|
vm.Links.Add(pumpViewModel);
|
}
|
}
|
if (rhs.Valves != null && rhs.Valves.Count > 0)
|
{
|
foreach (var valve in rhs.Valves)
|
{
|
var valveViewModel = new ValveViewModel();
|
valveViewModel.ID = valve.Code;
|
valveViewModel.Name = valve.Name;
|
valveViewModel.StartNode = vm.Nodes.Find(x => x.ID == valve.StartCode);
|
valveViewModel.EndNode = vm.Nodes.Find(x => x.ID == valve.EndCode);
|
vm.Links.Add(valveViewModel);
|
}
|
}
|
|
if (rhs.Exchangers != null && rhs.Exchangers.Count > 0)
|
{
|
foreach (var exchanger in rhs.Exchangers)
|
{
|
var exchangerViewModel = new PipeViewModel();
|
exchangerViewModel.ID = exchanger.Code;
|
exchangerViewModel.Name = exchanger.Name;
|
exchangerViewModel.StartNode = vm.Nodes.Find(x => x.ID == exchanger.StartCode);
|
exchangerViewModel.EndNode = vm.Nodes.Find(x => x.ID == exchanger.EndCode);
|
vm.Links.Add(exchangerViewModel);
|
}
|
}
|
if (rhs.Compressors != null && rhs.Compressors.Count > 0)
|
{
|
foreach (var compressor in rhs.Compressors)
|
{
|
var compresorViewModel = new PipeViewModel();
|
compresorViewModel.ID = compressor.Code;
|
compresorViewModel.Name = compressor.Name;
|
compresorViewModel.StartNode = vm.Nodes.Find(x => x.ID == compressor.StartCode);
|
compresorViewModel.EndNode = vm.Nodes.Find(x => x.ID == compressor.EndCode);
|
vm.Links.Add(compresorViewModel);
|
}
|
}
|
|
|
return vm;
|
}
|
|
|
|
}
|
}
|