using HStation.Model;
namespace HStation.Hydro
{
///
/// 解析辅助类
///
public class ParseHelper
{
///
/// 从Revit解析
///
public static Yw.Model.HydroModelInfo FromRevit(HStation.Model.RevitModel revitModel, out string msg)
{
msg = string.Empty;
#region Revit组件整合
var allRevitParterList = new List();
if (revitModel.Reservoirs != null)
{
allRevitParterList.AddRange(revitModel.Reservoirs);
}
if (revitModel.Tanks != null)
{
allRevitParterList.AddRange(revitModel.Tanks);
}
if (revitModel.Junctions != null)
{
allRevitParterList.AddRange(revitModel.Junctions);
}
if (revitModel.Pumps != null)
{
allRevitParterList.AddRange(revitModel.Pumps);
}
if (revitModel.Valves != null)
{
allRevitParterList.AddRange(revitModel.Valves);
}
if (revitModel.Pipes != null)
{
allRevitParterList.AddRange(revitModel.Pipes);
}
if (revitModel.Curves != null)
{
allRevitParterList.AddRange(revitModel.Curves);
}
if (revitModel.Patterns != null)
{
allRevitParterList.AddRange(revitModel.Patterns);
}
if (revitModel.Rules != null)
{
allRevitParterList.AddRange(revitModel.Rules);
}
var allRevitNodeList = allRevitParterList.Where(x => x is IRevitNode).ToList();
var allRevitLinkList = allRevitParterList.Where(x => x is IRevitLink).ToList();
#endregion
var hydro = new Yw.Model.HydroModelInfo();
hydro.Name = revitModel.Name;
hydro.Code = null;
hydro.Scene = HStation.Revit.ConstParas.Scene;
hydro.Paras = null;
hydro.Flags = null;
hydro.TagName = null;
hydro.Description = revitModel.Description;
//水泵
if (revitModel.Pumps != null && revitModel.Pumps.Count > 0)
{
hydro.Pumps = new List();
foreach (var revitPump in revitModel.Pumps)
{
var revitStartParter = allRevitParterList.Find(x => x.Code == revitPump.StartCode);
if (revitStartParter == null)
{
msg = $"Pump:{revitPump.Code},StartCode:{revitPump.StartCode} Error";
return default;
}
//上游连接组件是Link
if (revitStartParter is IRevitLink)
{
var revitStartJunction = new RevitJunction();
revitStartJunction.Id = RevitHelper.CreateUniqueCode(Yw.Hydro.Catalog.Junction, allRevitParterList);
revitStartJunction.Name = revitStartJunction.Id;
revitStartJunction.Code = revitStartJunction.Id;
revitStartJunction.Flags = null;
revitStartJunction.Description = "自动生成";
revitStartJunction.ModelType = null;
revitStartJunction.Quality = 0;
revitStartJunction.Coefficient = 0;
revitStartJunction.Elev = revitPump.StartElev;
revitStartJunction.Demand = null;
revitStartJunction.DemandPattern = null;
revitStartJunction.PropValueList = null;
revitStartJunction.BoundingBox = revitPump.BoundingBox;
if (revitModel.Junctions == null)
{
revitModel.Junctions = new List();
}
revitModel.Junctions.Add(revitStartJunction);
allRevitParterList.Add(revitStartJunction);
allRevitNodeList.Add(revitStartJunction);
(revitStartParter as IRevitLink).EndCode = revitStartJunction.Id;
}
var revitEndParter = allRevitParterList.Find(x => x.Code == revitPump.EndCode);
if (revitEndParter == null)
{
msg = $"Pump:{revitPump.Code},EndCode:{revitPump.EndCode} Error";
return default;
}
//下游连接组件是Link
if (revitEndParter is IRevitLink)
{
var revitEndJunction = new RevitJunction();
revitEndJunction.Id = RevitHelper.CreateUniqueCode(Yw.Hydro.Catalog.Junction, allRevitParterList);
revitEndJunction.Name = revitEndJunction.Id;
revitEndJunction.Code = revitEndJunction.Id;
revitEndJunction.Flags = null;
revitEndJunction.Description = "自动生成";
revitEndJunction.ModelType = null;
revitEndJunction.Quality = 0;
revitEndJunction.Coefficient = 0;
revitEndJunction.Elev = revitPump.EndElev;
revitEndJunction.Demand = null;
revitEndJunction.DemandPattern = null;
revitEndJunction.PropValueList = null;
revitEndJunction.BoundingBox = revitPump.BoundingBox;
if (revitModel.Junctions == null)
{
revitModel.Junctions = new List();
}
revitModel.Junctions.Add(revitEndJunction);
allRevitParterList.Add(revitEndJunction);
allRevitNodeList.Add(revitEndJunction);
(revitEndParter as IRevitLink).StartCode = revitEndJunction.Id;
}
var pump = new Yw.Model.HydroPumpInfo();
pump.Catalog = Yw.Hydro.Catalog.Pump;
pump.Name = revitPump.Name;
pump.Code = revitPump.Code;
pump.Flags = revitPump.Flags;
pump.Description = revitPump.Description;
pump.StartCode = revitPump.StartCode;
pump.EndCode = revitPump.EndCode;
pump.LinkStatus = revitPump.LinkStatus;
pump.RatedPower = revitPump.RatedPower;
pump.CurveQH = revitPump.CurveQH;
pump.Price = revitPump.Price;
pump.PricePattern = revitPump.PricePattern;
pump.CurveQE = revitPump.CurveQE;
pump.ScenePropValueList = revitPump.PropValueList?.Select(x => new Yw.Model.HydroScenePropValuePureInfo()
{
PropName = x.Key,
PropValue = x.Value?.ToString()
}).ToList();
hydro.Pumps.Add(pump);
}
}
//阀门
if (revitModel.Valves != null && revitModel.Valves.Count > 0)
{
hydro.Valves = new List();
foreach (var revitValve in revitModel.Valves)
{
var revitStartParter = allRevitParterList.Find(x => x.Code == revitValve.StartCode);
if (revitStartParter == null)
{
msg = $"Valve:{revitValve.Code},StartCode:{revitValve.StartCode} Error";
return default;
}
//上游连接组件是Link
if (revitStartParter is IRevitLink)
{
var revitStartJunction = new RevitJunction();
revitStartJunction.Id = RevitHelper.CreateUniqueCode(Yw.Hydro.Catalog.Junction, allRevitParterList);
revitStartJunction.Name = revitStartJunction.Id;
revitStartJunction.Code = revitStartJunction.Id;
revitStartJunction.Flags = null;
revitStartJunction.Description = "自动生成";
revitStartJunction.ModelType = null;
revitStartJunction.Quality = 0;
revitStartJunction.Coefficient = 0;
revitStartJunction.Elev = revitValve.StartElev;
revitStartJunction.Demand = null;
revitStartJunction.DemandPattern = null;
revitStartJunction.PropValueList = null;
revitStartJunction.BoundingBox = revitValve.BoundingBox;
if (revitModel.Junctions == null)
{
revitModel.Junctions = new List();
}
revitModel.Junctions.Add(revitStartJunction);
allRevitParterList.Add(revitStartJunction);
allRevitNodeList.Add(revitStartJunction);
(revitStartParter as IRevitLink).EndCode = revitStartJunction.Id;
}
var revitEndParter = allRevitParterList.Find(x => x.Code == revitValve.EndCode);
if (revitEndParter == null)
{
msg = $"Valve:{revitValve.Code},EndCode:{revitValve.EndCode} Error";
return default;
}
//下游连接组件是Link
if (revitEndParter is IRevitLink)
{
var revitEndJunction = new RevitJunction();
revitEndJunction.Id = RevitHelper.CreateUniqueCode(Yw.Hydro.Catalog.Junction, allRevitParterList);
revitEndJunction.Name = revitEndJunction.Id;
revitEndJunction.Code = revitEndJunction.Id;
revitEndJunction.Flags = null;
revitEndJunction.Description = "自动生成";
revitEndJunction.ModelType = null;
revitEndJunction.Quality = 0;
revitEndJunction.Coefficient = 0;
revitEndJunction.Elev = revitValve.EndElev;
revitEndJunction.Demand = null;
revitEndJunction.DemandPattern = null;
revitEndJunction.PropValueList = null;
revitEndJunction.BoundingBox = revitValve.BoundingBox;
if (revitModel.Junctions == null)
{
revitModel.Junctions = new List();
}
revitModel.Junctions.Add(revitEndJunction);
allRevitParterList.Add(revitEndJunction);
allRevitNodeList.Add(revitEndJunction);
(revitEndParter as IRevitLink).StartCode = revitEndJunction.Id;
}
var valve = new Yw.Model.HydroValveInfo();
valve.Catalog = Yw.Hydro.Catalog.Valve;
valve.Name = revitValve.Name;
valve.Code = revitValve.Code;
valve.Flags = revitValve.Flags;
valve.Description = revitValve.Description;
valve.StartCode = revitValve.StartCode;
valve.EndCode = revitValve.EndCode;
valve.Diameter = revitValve.Diameter;
valve.MinorLoss = revitValve.MinorLoss;
valve.ValveType = revitValve.ValveType;
valve.ValveSetting = revitValve.ValveSetting;
valve.ScenePropValueList = revitValve.PropValueList?.Select(x => new Yw.Model.HydroScenePropValuePureInfo()
{
PropName = x.Key,
PropValue = x.Value?.ToString()
}).ToList();
hydro.Valves.Add(valve);
}
}
//管道
if (revitModel.Pipes != null && revitModel.Pipes.Count > 0)
{
hydro.Pipes = new List();
foreach (var revitPipe in revitModel.Pipes)
{
var revitStartParter = allRevitParterList.Find(x => x.Code == revitPipe.StartCode);
if (revitStartParter == null)
{
msg = $"Pipe:{revitPipe.Code},StartCode:{revitPipe.StartCode} Error";
return default;
}
//上游连接组件是Link
if (revitStartParter is IRevitLink)
{
var revitStartJunction = new RevitJunction();
revitStartJunction.Id = RevitHelper.CreateUniqueCode(Yw.Hydro.Catalog.Junction, allRevitParterList);
revitStartJunction.Name = revitStartJunction.Id;
revitStartJunction.Code = revitStartJunction.Id;
revitStartJunction.Flags = null;
revitStartJunction.Description = "自动生成";
revitStartJunction.ModelType = null;
revitStartJunction.Quality = 0;
revitStartJunction.Coefficient = 0;
revitStartJunction.Elev = revitPipe.StartElev;
revitStartJunction.Demand = null;
revitStartJunction.DemandPattern = null;
revitStartJunction.PropValueList = null;
revitStartJunction.BoundingBox = revitPipe.BoundingBox;
if (revitModel.Junctions == null)
{
revitModel.Junctions = new List();
}
revitModel.Junctions.Add(revitStartJunction);
allRevitParterList.Add(revitStartJunction);
allRevitNodeList.Add(revitStartJunction);
(revitStartParter as IRevitLink).EndCode = revitStartJunction.Id;
}
var revitEndParter = allRevitParterList.Find(x => x.Code == revitPipe.EndCode);
if (revitEndParter == null)
{
msg = $"Pipe:{revitPipe.Code},EndCode:{revitPipe.EndCode} Error";
return default;
}
//下游连接组件是Link
if (revitEndParter is IRevitLink)
{
var revitEndJunction = new RevitJunction();
revitEndJunction.Id = RevitHelper.CreateUniqueCode(Yw.Hydro.Catalog.Junction, allRevitParterList);
revitEndJunction.Name = revitEndJunction.Id;
revitEndJunction.Code = revitEndJunction.Id;
revitEndJunction.Flags = null;
revitEndJunction.Description = "自动生成";
revitEndJunction.ModelType = null;
revitEndJunction.Quality = 0;
revitEndJunction.Coefficient = 0;
revitEndJunction.Elev = revitPipe.EndElev;
revitEndJunction.Demand = null;
revitEndJunction.DemandPattern = null;
revitEndJunction.PropValueList = null;
revitEndJunction.BoundingBox = revitPipe.BoundingBox;
if (revitModel.Junctions == null)
{
revitModel.Junctions = new List();
}
revitModel.Junctions.Add(revitEndJunction);
allRevitParterList.Add(revitEndJunction);
allRevitNodeList.Add(revitEndJunction);
(revitEndParter as IRevitLink).StartCode = revitEndJunction.Id;
}
var pipe = new Yw.Model.HydroPipeInfo();
pipe.Catalog = Yw.Hydro.Catalog.Pipe;
pipe.Name = revitPipe.Name;
pipe.Code = revitPipe.Code;
pipe.Flags = revitPipe.Flags;
pipe.Description = revitPipe.Description;
pipe.StartCode = revitPipe.StartCode;
pipe.EndCode = revitPipe.EndCode;
pipe.LinkStatus = revitPipe.LinkStatus;
pipe.Diameter = revitPipe.Diameter;
pipe.Length = revitPipe.Length;
pipe.Roughness = revitPipe.Roughness;
pipe.MinorLoss = revitPipe.MinorLoss;
pipe.ScenePropValueList = revitPipe.PropValueList?.Select(x => new Yw.Model.HydroScenePropValuePureInfo()
{
PropName = x.Key,
PropValue = x.Value?.ToString()
}).ToList();
hydro.Pipes.Add(pipe);
}
}
//水库
if (revitModel.Reservoirs != null && revitModel.Reservoirs.Count > 0)
{
hydro.Reservoirs = new List();
foreach (var revitReservoir in revitModel.Reservoirs)
{
var reservoir = new Yw.Model.HydroReservoirInfo();
reservoir.Catalog = Yw.Hydro.Catalog.Reservoir;
reservoir.Name = revitReservoir.Name;
reservoir.Code = revitReservoir.Code;
reservoir.Flags = revitReservoir.Flags;
reservoir.Description = revitReservoir.Description;
reservoir.Quality = revitReservoir.Quality;
reservoir.Head = revitReservoir.Head;
reservoir.HeadPattern = revitReservoir.HeadPattern;
var center = revitReservoir.BoundingBox.Center;
reservoir.Position2d = new Yw.Model.Hydro.Position2d(center.X, center.Y);
reservoir.Position3d = new Yw.Model.Hydro.Position3d(center.X, center.Y, center.Z);
reservoir.ScenePropValueList = revitReservoir.PropValueList?.Select(x => new Yw.Model.HydroScenePropValuePureInfo()
{
PropName = x.Key,
PropValue = x.Value?.ToString()
}).ToList();
hydro.Reservoirs.Add(reservoir);
}
}
//水池
if (revitModel.Tanks != null && revitModel.Tanks.Count > 0)
{
hydro.Tanks = new List();
foreach (var revitTank in revitModel.Tanks)
{
var tank = new Yw.Model.HydroTankInfo();
tank.Catalog = Yw.Hydro.Catalog.Tank;
tank.Name = revitTank.Name;
tank.Code = revitTank.Code;
tank.Flags = revitTank.Flags;
tank.Description = revitTank.Description;
tank.Quality = revitTank.Quality;
tank.PoolElev = revitTank.PoolElev;
tank.InitLevel = revitTank.InitLevel;
tank.MinLevel = revitTank.MinLevel;
tank.MaxLevel = revitTank.MaxLevel;
tank.Diameter = revitTank.Diameter;
tank.MinVol = revitTank.MinVol;
tank.VolCurve = revitTank.VolCurve;
var center = revitTank.BoundingBox.Center;
tank.Position2d = new Yw.Model.Hydro.Position2d(center.X, center.Y);
tank.Position3d = new Yw.Model.Hydro.Position3d(center.X, center.Y, center.Z);
tank.ScenePropValueList = revitTank.PropValueList?.Select(x => new Yw.Model.HydroScenePropValuePureInfo()
{
PropName = x.Key,
PropValue = x.Value?.ToString()
}).ToList();
hydro.Tanks.Add(tank);
}
}
//节点
if (revitModel.Junctions != null && revitModel.Junctions.Count > 0)
{
hydro.Junctions = new List();
foreach (var revitJunction in revitModel.Junctions)
{
var junction = new Yw.Model.HydroJunctionInfo();
junction.Catalog = Yw.Hydro.Catalog.Junction;
junction.Name = revitJunction.Name;
junction.Code = revitJunction.Code;
junction.Flags = revitJunction.Flags;
junction.Description = revitJunction.Description;
junction.Quality = revitJunction.Quality;
junction.Coefficient = revitJunction.Coefficient;
junction.Elev = revitJunction.Elev;
junction.Demand = revitJunction.Demand;
junction.DemandPattern = revitJunction.DemandPattern;
var center = revitJunction.BoundingBox.Center;
junction.Position2d = new Yw.Model.Hydro.Position2d(center.X, center.Y);
junction.Position3d = new Yw.Model.Hydro.Position3d(center.X, center.Y, center.Z);
junction.ScenePropValueList = revitJunction.PropValueList?.Select(x => new Yw.Model.HydroScenePropValuePureInfo()
{
PropName = x.Key,
PropValue = x.Value?.ToString()
}).ToList();
hydro.Junctions.Add(junction);
}
}
//装饰件
if (revitModel.Decorators != null && revitModel.Decorators.Count > 0)
{
hydro.Decorators = new List();
foreach (var revitDecorator in revitModel.Decorators)
{
var decorator = new Yw.Model.HydroDecoratorInfo();
decorator.Name = revitDecorator.Name;
decorator.Category = revitDecorator.Category;
decorator.Decoration = revitDecorator.Decoration;
decorator.Description = revitDecorator.Description;
hydro.Decorators.Add(decorator);
}
}
return hydro;
}
}
}