using Yw.WinFrmUI.HydroW3d; namespace Yw.WinFrmUI { /// /// W3d转换辅助类 /// public static class HydroW3dTransferHelper { /// /// /// public static NetworkViewModel ToW3dNetworkViewModel(this Yw.Model.HydroModelInfo model) { if (model == null) { return default; } var netWork = new NetworkViewModel(); #region 节点 //水库 if (model.Reservoirs != null && model.Reservoirs.Count > 0) { foreach (var reservoir in model.Reservoirs) { var reservoirModel = new ReservoirViewModel(); reservoirModel.Id = reservoir.Code; reservoirModel.Catalog = Catalog.Reservoir; reservoirModel.Name = reservoir.Name; reservoirModel.Position = new Point3d(reservoir.Position3d.X, reservoir.Position3d.Y, reservoir.Position3d.Z); netWork.Reservoirs.Add(reservoirModel); } } //水池 if (model.Tanks != null && model.Tanks.Count > 0) { foreach (var tank in model.Tanks) { var tankModel = new TankViewModel(); tankModel.Id = tank.Code; tankModel.Catalog = Catalog.Tank; tankModel.Name = tank.Name; tankModel.Position = new Point3d(tank.Position3d.X, tank.Position3d.Y, tank.Position3d.Z); netWork.Tanks.Add(tankModel); } } //水箱 if (model.Waterboxs != null && model.Waterboxs.Count > 0) { foreach (var waterbox in model.Waterboxs) { var waterboxModel = new WaterboxViewModel(); waterboxModel.Id = waterbox.Code; waterboxModel.Catalog = Catalog.Waterbox; waterboxModel.Name = waterbox.Name; waterboxModel.Position = new Point3d(waterbox.Position3d.X, waterbox.Position3d.Y, waterbox.Position3d.Z); netWork.Waterboxs.Add(waterboxModel); } } //连接节点 if (model.Junctions != null && model.Junctions.Count > 0) { foreach (var junction in model.Junctions) { var junctionModel = new JunctionViewModel(); junctionModel.Id = junction.Code; junctionModel.Catalog = Catalog.Junction; junctionModel.Name = junction.Name; junctionModel.Position = new Point3d(junction.Position3d.X, junction.Position3d.Y, junction.Position3d.Z); netWork.Junctions.Add(junctionModel); } } //喷嘴 if (model.Nozzles != null && model.Nozzles.Count > 0) { foreach (var nozzle in model.Nozzles) { var nozzleModel = new NozzleViewModel(); nozzleModel.Id = nozzle.Code; nozzleModel.Catalog = Catalog.Nozzle; nozzleModel.Name = nozzle.Name; nozzleModel.Position = new Point3d(nozzle.Position3d.X, nozzle.Position3d.Y, nozzle.Position3d.Z); netWork.Nozzles.Add(nozzleModel); } } //消火栓 if (model.Hydrants != null && model.Hydrants.Count > 0) { foreach (var hydrant in model.Hydrants) { var hydrantModel = new HydrantViewModel(); hydrantModel.Id = hydrant.Code; hydrantModel.Catalog = Catalog.Hydrant; hydrantModel.Name = hydrant.Name; hydrantModel.Position = new Point3d(hydrant.Position3d.X, hydrant.Position3d.Y, hydrant.Position3d.Z); netWork.Hydrants.Add(hydrantModel); } } //闷头 if (model.Bluntheads != null && model.Bluntheads.Count > 0) { foreach (var blunthead in model.Bluntheads) { var bluntheadModel = new BluntheadViewModel(); bluntheadModel.Id = blunthead.Code; bluntheadModel.Catalog = Catalog.Blunthead; bluntheadModel.Name = blunthead.Name; bluntheadModel.Position = new Point3d(blunthead.Position3d.X, blunthead.Position3d.Y, blunthead.Position3d.Z); netWork.Bluntheads.Add(bluntheadModel); } } //弯头 if (model.Elbows != null && model.Elbows.Count > 0) { foreach (var elbow in model.Elbows) { var elbowModel = new ElbowViewModel(); elbowModel.Id = elbow.Code; elbowModel.Catalog = Catalog.Elbow; elbowModel.Name = elbow.Name; elbowModel.Position = new Point3d(elbow.Position3d.X, elbow.Position3d.Y, elbow.Position3d.Z); netWork.Elbows.Add(elbowModel); } } //三通 if (model.Threelinks != null && model.Threelinks.Count > 0) { foreach (var threelink in model.Threelinks) { var threelinkModel = new ThreelinkViewModel(); threelinkModel.Id = threelink.Code; threelinkModel.Catalog = Catalog.Threelink; threelinkModel.Name = threelink.Name; threelinkModel.Position = new Point3d(threelink.Position3d.X, threelink.Position3d.Y, threelink.Position3d.Z); netWork.Threelinks.Add(threelinkModel); } } //四通 if (model.Fourlinks != null && model.Fourlinks.Count > 0) { foreach (var fourlink in model.Fourlinks) { var fourlinkModel = new FourlinkViewModel(); fourlinkModel.Id = fourlink.Code; fourlinkModel.Catalog = Catalog.Fourlink; fourlinkModel.Name = fourlink.Name; fourlinkModel.Position = new Point3d(fourlink.Position3d.X, fourlink.Position3d.Y, fourlink.Position3d.Z); netWork.Fourlinks.Add(fourlinkModel); } } //水表 if (model.Meters != null && model.Meters.Count > 0) { foreach (var meter in model.Meters) { var meterModel = new MeterViewModel(); meterModel.Id = meter.Code; meterModel.Catalog = Catalog.Meter; meterModel.Name = meter.Name; meterModel.Position = new Point3d(meter.Position3d.X, meter.Position3d.Y, meter.Position3d.Z); netWork.Meters.Add(meterModel); } } //流量计 if (model.Flowmeters != null && model.Flowmeters.Count > 0) { foreach (var flowmeter in model.Flowmeters) { var flowmeterModel = new FlowmeterViewModel(); flowmeterModel.Id = flowmeter.Code; flowmeterModel.Catalog = Catalog.Flowmeter; flowmeterModel.Name = flowmeter.Name; flowmeterModel.Position = new Point3d(flowmeter.Position3d.X, flowmeter.Position3d.Y, flowmeter.Position3d.Z); netWork.Flowmeters.Add(flowmeterModel); } } //压力表 if (model.Pressmeters != null && model.Pressmeters.Count > 0) { foreach (var pressmeter in model.Pressmeters) { var pressmeterModel = new PressmeterViewModel(); pressmeterModel.Id = pressmeter.Code; pressmeterModel.Catalog = Catalog.Pressmeter; pressmeterModel.Name = pressmeter.Name; pressmeterModel.Position = new Point3d(pressmeter.Position3d.X, pressmeter.Position3d.Y, pressmeter.Position3d.Z); netWork.Pressmeters.Add(pressmeterModel); } } #endregion #region 管段 var allNodes = netWork.GetAllNodes(); var allNodeDict = new Dictionary(); allNodes.ForEach(x => allNodeDict.Add(x.Id, x)); //管道 if (model.Pipes != null && model.Pipes.Count > 0) { foreach (var pipe in model.Pipes) { var pipeModel = new PipeViewModel(); pipeModel.Id = pipe.Code; pipeModel.Catalog = Catalog.Pipe; pipeModel.Name = pipe.Name; pipeModel.StartId = pipe.StartCode; pipeModel.EndId = pipe.EndCode; pipeModel.Diameter = pipe.Diameter; netWork.Pipes.Add(pipeModel); } } //过渡件 if (model.Translations != null && model.Translations.Count > 0) { foreach (var translation in model.Translations) { var translationModel = new TranslationViewModel(); translationModel.Id = translation.Code; translationModel.Catalog = Catalog.Translation; translationModel.Name = translation.Name; translationModel.StartId = translation.StartCode; translationModel.EndId = translation.EndCode; translationModel.Diameter = translation.Diameter; translationModel.StartDiameter = translation.StartDiameter; translationModel.EndDiameter = translation.EndDiameter; netWork.Translations.Add(translationModel); } } //水泵 if (model.Pumps != null && model.Pumps.Count > 0) { foreach (var pump in model.Pumps) { var pumpModel = new HydroW3d.PumpViewModel(); pumpModel.Id = pump.Code; pumpModel.Catalog = Catalog.Pump; pumpModel.Name = pump.Name; pumpModel.StartId = pump.StartCode; pumpModel.EndId = pump.EndCode; netWork.Pumps.Add(pumpModel); } } //阀门 if (model.Valves != null && model.Valves.Count > 0) { foreach (var valve in model.Valves) { var valveModel = new ValveViewModel(); valveModel.Id = valve.Code; valveModel.Catalog = Catalog.Valve; valveModel.Name = valve.Name; valveModel.StartId = valve.StartCode; valveModel.EndId = valve.EndCode; valveModel.Diameter = valve.Diameter; netWork.Valves.Add(valveModel); } } //换热器 if (model.Exchangers != null && model.Exchangers.Count > 0) { foreach (var exchanger in model.Exchangers) { var exchangerModel = new ExchangerViewModel(); exchangerModel.Id = exchanger.Code; exchangerModel.Catalog = Catalog.Exchanger; exchangerModel.Name = exchanger.Name; exchangerModel.StartId = exchanger.StartCode; exchangerModel.EndId = exchanger.EndCode; exchangerModel.Diameter = exchanger.Diameter; netWork.Exchangers.Add(exchangerModel); } } //压缩机 if (model.Compressors != null && model.Compressors.Count > 0) { foreach (var compressor in model.Compressors) { var compressorModel = new CompressorViewModel(); compressorModel.Id = compressor.Code; compressorModel.Catalog = Catalog.Compressor; compressorModel.Name = compressor.Name; compressorModel.StartId = compressor.StartCode; compressorModel.EndId = compressor.EndCode; compressorModel.Diameter = compressor.Diameter; netWork.Compressors.Add(compressorModel); } } #endregion #region 节点连接 var allLinks = netWork.GetAllLinks(); foreach (var node in allNodes) { var links = allLinks.Where(x => x.StartId == node.Id || x.EndId == node.Id).ToList(); node.LinkIds = links.Select(x => x.Id).Distinct().ToList(); } #endregion return netWork; } } }