lixiaojun
2024-07-30 a6f889d45e29cbba4648bd7c4705d1de7aab36d2
Hydro/HStation.Hydro.Core/ParseHelper.cs
@@ -1,4 +1,6 @@
namespace HStation.Hydro
using HStation.Model;
namespace HStation.Hydro
{
    /// <summary>
    /// 解析辅助类
@@ -8,9 +10,54 @@
        /// <summary>
        /// 从Revit解析
        /// </summary>
        public static Yw.Model.HydroModelInfo FromRevit(HStation.Model.RevitModel revitModel)
        public static Yw.Model.HydroModelInfo FromRevit(HStation.Model.RevitModel revitModel, out string msg)
        {
            msg = string.Empty;
            #region Revit组件整合
            var allRevitParterList = new List<HStation.Model.RevitParter>();
            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;
@@ -20,6 +67,300 @@
            hydro.Flags = null;
            hydro.TagName = null;
            hydro.Description = revitModel.Description;
            //水泵
            if (revitModel.Pumps != null && revitModel.Pumps.Count > 0)
            {
                hydro.Pumps = new List<Yw.Model.HydroPumpInfo>();
                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<RevitJunction>();
                        }
                        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<RevitJunction>();
                        }
                        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<Yw.Model.HydroValveInfo>();
                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<RevitJunction>();
                        }
                        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<RevitJunction>();
                        }
                        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<Yw.Model.HydroPipeInfo>();
                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<RevitJunction>();
                        }
                        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<RevitJunction>();
                        }
                        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)
@@ -33,15 +374,16 @@
                    reservoir.Code = revitReservoir.Code;
                    reservoir.Flags = revitReservoir.Flags;
                    reservoir.Description = revitReservoir.Description;
                    reservoir.Quality = revitReservoir.Quality;
                    reservoir.Head = revitReservoir.Head;
                    reservoir.Pattern = revitReservoir.Pattern;
                    var center = revitReservoir.BoundingBox.GetCenter();
                    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.PropName,
                        PropValue = x.PropValue
                        PropName = x.Key,
                        PropValue = x.Value?.ToString()
                    }).ToList();
                    hydro.Reservoirs.Add(reservoir);
                }
@@ -59,48 +401,23 @@
                    tank.Code = revitTank.Code;
                    tank.Flags = revitTank.Flags;
                    tank.Description = revitTank.Description;
                    tank.Elev = revitTank.Elev;
                    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.GetCenter();
                    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.PropName,
                        PropValue = x.PropValue
                        PropName = x.Key,
                        PropValue = x.Value?.ToString()
                    }).ToList();
                    hydro.Tanks.Add(tank);
                }
            }
            //扩散器
            if (revitModel.Emitters != null && revitModel.Emitters.Count > 0)
            {
                hydro.Emitters = new List<Yw.Model.HydroEmitterInfo>();
                foreach (var revitEmitter in revitModel.Emitters)
                {
                    var emitter = new Yw.Model.HydroEmitterInfo();
                    emitter.Catalog = Yw.Hydro.Catalog.Emitter;
                    emitter.Name = revitEmitter.Name;
                    emitter.Code = revitEmitter.Code;
                    emitter.Flags = revitEmitter.Flags;
                    emitter.Description = revitEmitter.Description;
                    emitter.EmitterType = revitEmitter.EmitterType;
                    emitter.FlowCoefficient = revitEmitter.FlowCoefficient;
                    var center = revitEmitter.BoundingBox.GetCenter();
                    emitter.Position2d = new Yw.Model.Hydro.Position2d(center.X, center.Y);
                    emitter.Position3d = new Yw.Model.Hydro.Position3d(center.X, center.Y, center.Z);
                    emitter.ScenePropValueList = revitEmitter.PropValueList?.Select(x => new Yw.Model.HydroScenePropValuePureInfo()
                    {
                        PropName = x.PropName,
                        PropValue = x.PropValue
                    }).ToList();
                    hydro.Emitters.Add(emitter);
                }
            }
@@ -116,100 +433,20 @@
                    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.Pattern = revitJunction.Pattern;
                    var center = revitJunction.BoundingBox.GetCenter();
                    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.PropName,
                        PropValue = x.PropValue
                        PropName = x.Key,
                        PropValue = x.Value?.ToString()
                    }).ToList();
                    hydro.Junctions.Add(junction);
                }
            }
            //管道
            if (revitModel.Pipes != null && revitModel.Pipes.Count > 0)
            {
                hydro.Pipes = new List<Yw.Model.HydroPipeInfo>();
                foreach (var revitPipe in revitModel.Pipes)
                {
                    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.Diameter = revitPipe.Diameter;
                    pipe.Length = revitPipe.Length;
                    pipe.Roughness = revitPipe.Roughness;
                    pipe.MinorLoss = revitPipe.MinorLoss;
                    pipe.PipeStatus = revitPipe.PipeStatus;
                    pipe.ScenePropValueList = revitPipe.PropValueList?.Select(x => new Yw.Model.HydroScenePropValuePureInfo()
                    {
                        PropName = x.PropName,
                        PropValue = x.PropValue
                    }).ToList();
                    hydro.Pipes.Add(pipe);
                }
            }
            //水泵
            if (revitModel.Pumps != null && revitModel.Pumps.Count > 0)
            {
                hydro.Pumps = new List<Yw.Model.HydroPumpInfo>();
                foreach (var revitPump in revitModel.Pumps)
                {
                    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.Power = revitPump.Power;
                    pump.Head = revitPump.Head;
                    pump.Speed = revitPump.Speed;
                    pump.Pattern = revitPump.Pattern;
                    pump.ScenePropValueList = revitPump.PropValueList?.Select(x => new Yw.Model.HydroScenePropValuePureInfo()
                    {
                        PropName = x.PropName,
                        PropValue = x.PropValue
                    }).ToList();
                    hydro.Pumps.Add(pump);
                }
            }
            //阀门
            if (revitModel.Valves != null && revitModel.Valves.Count > 0)
            {
                hydro.Valves = new List<Yw.Model.HydroValveInfo>();
                foreach (var revitValve in revitModel.Valves)
                {
                    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.PropName,
                        PropValue = x.PropValue
                    }).ToList();
                    hydro.Valves.Add(valve);
                }
            }