| | |
| | | using HStation.Model; |
| | | using Microsoft.VisualBasic; |
| | | |
| | | namespace HStation.Service |
| | | { |
| | |
| | | public static class RevitCorrectHelper |
| | | { |
| | | /// <summary> |
| | | /// 修正(无法修正会抛出异常) |
| | | /// 修正 |
| | | /// </summary> |
| | | /// <param name="rhs">RevitModel</param> |
| | | public static bool Correct(this Model.RevitModel rhs, out string msg) |
| | | { |
| | | if (rhs == null) |
| | |
| | | return false; |
| | | } |
| | | if (!First(rhs, out msg)) |
| | | { |
| | | return false; |
| | | } |
| | | if (!Exchanger(rhs, out msg)) |
| | | { |
| | | return false; |
| | | } |
| | |
| | | { |
| | | rhs.Fourlinks = new List<Model.RevitFourlink>(); |
| | | } |
| | | if (rhs.Meters == null) |
| | | { |
| | | rhs.Meters = new List<RevitMeter>(); |
| | | } |
| | | if (rhs.Flowmeters == null) |
| | | { |
| | | rhs.Flowmeters = new List<Model.RevitFlowmeter>(); |
| | |
| | | { |
| | | rhs.Translations = new List<Model.RevitTranslation>(); |
| | | } |
| | | if (rhs.Exchangers == null) |
| | | { |
| | | rhs.Exchangers = new List<RevitExchanger>(); |
| | | } |
| | | if (rhs.Pumps == null) |
| | | { |
| | | rhs.Pumps = new List<Model.RevitPump>(); |
| | |
| | | if (rhs.Valves == null) |
| | | { |
| | | rhs.Valves = new List<Model.RevitValve>(); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | //单独修复换热器 |
| | | private static bool Exchanger(Model.RevitModel rhs, out string msg) |
| | | { |
| | | msg = string.Empty; |
| | | if (rhs.Exchangers != null && rhs.Exchangers.Count > 0) |
| | | { |
| | | var allParterList = rhs.GetAllParters(); |
| | | foreach (var exchanger in rhs.Exchangers) |
| | | { |
| | | if (exchanger.ConnectList != null && exchanger.ConnectList.Count > 0) |
| | | { |
| | | foreach (var connect in exchanger.ConnectList.ToList()) |
| | | { |
| | | var connectParter = allParterList.Find(x => x.Id == connect.Id); |
| | | if (connectParter == null) |
| | | { |
| | | exchanger.ConnectList.Remove(connect); |
| | | } |
| | | else |
| | | { |
| | | if (connectParter is RevitBlunthead blunthead) |
| | | { |
| | | var decorator = new Model.RevitDecorator(); |
| | | decorator.Id = blunthead.Id; |
| | | decorator.Code = blunthead.Code; |
| | | decorator.Name = blunthead.Name; |
| | | decorator.Category = RevitJsonCatalog.Blunthead; |
| | | decorator.Decoration = null; |
| | | decorator.Description = blunthead.Description; |
| | | rhs.Decorators.Add(decorator); |
| | | |
| | | rhs.Bluntheads.Remove(blunthead); |
| | | allParterList.Remove(connectParter); |
| | | } |
| | | } |
| | | } |
| | | |
| | | var startConnectList = exchanger.ConnectList.GetStartConnects(); |
| | | if (startConnectList == null || startConnectList.Count < 1) |
| | | { |
| | | msg = $"换热器:{exchanger.Id} 上游连接组件不存在"; |
| | | return false; |
| | | } |
| | | var startJunction = new Model.RevitJunction(); |
| | | startJunction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Code).ToList()); |
| | | startJunction.Code = startJunction.Id; |
| | | startJunction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList()); |
| | | startJunction.Flags = null; |
| | | startJunction.ModelType = null; |
| | | startJunction.Description = "换热器修正时,自动添加"; |
| | | startJunction.Quality = exchanger.StartQuality; |
| | | startJunction.Position = startConnectList.GetCenterPosition(); |
| | | startJunction.Elev = exchanger.StartElev; |
| | | startJunction.Demand = null; |
| | | startJunction.DemandPattern = null; |
| | | rhs.Junctions.Add(startJunction); |
| | | exchanger.StartCode = startJunction.Code; |
| | | foreach (var startConnect in startConnectList) |
| | | { |
| | | var startConnectParter = allParterList.Find(x => x.Id == startConnect.Id); |
| | | if (startConnectParter is RevitLink revitLink) |
| | | { |
| | | if (revitLink.StartCode == exchanger.Id) |
| | | { |
| | | revitLink.StartCode = startJunction.Id; |
| | | } |
| | | else if (revitLink.EndCode == exchanger.Id) |
| | | { |
| | | revitLink.EndCode = startJunction.Id; |
| | | } |
| | | } |
| | | } |
| | | allParterList.Add(startJunction); |
| | | |
| | | var endConnectList = exchanger.ConnectList.GetEndConnects(); |
| | | if (endConnectList == null || endConnectList.Count < 1) |
| | | { |
| | | msg = $"换热器:{exchanger.Id} 下游连接组件不存在"; |
| | | return false; |
| | | } |
| | | var endJunction = new Model.RevitJunction(); |
| | | endJunction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Code).ToList()); |
| | | endJunction.Code = endJunction.Id; |
| | | endJunction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList()); |
| | | endJunction.Flags = null; |
| | | endJunction.ModelType = null; |
| | | endJunction.Description = "换热器修正时,自动添加"; |
| | | endJunction.Quality = exchanger.EndQuality; |
| | | endJunction.Position = endConnectList.GetCenterPosition(); |
| | | endJunction.Elev = exchanger.EndElev; |
| | | endJunction.Demand = null; |
| | | endJunction.DemandPattern = null; |
| | | rhs.Junctions.Add(endJunction); |
| | | exchanger.EndCode = endJunction.Code; |
| | | foreach (var endConnect in endConnectList) |
| | | { |
| | | var endConnectParter = allParterList.Find(x => x.Id == endConnect.Id); |
| | | if (endConnectParter is RevitLink revitLink) |
| | | { |
| | | if (revitLink.StartCode == exchanger.Id) |
| | | { |
| | | revitLink.StartCode = endJunction.Id; |
| | | } |
| | | else if (revitLink.EndCode == exchanger.Id) |
| | | { |
| | | revitLink.EndCode = endJunction.Id; |
| | | } |
| | | } |
| | | } |
| | | allParterList.Add(endJunction); |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | |
| | | private static bool Three(Model.RevitModel rhs, out string msg) |
| | | { |
| | | msg = string.Empty; |
| | | var allParterList = rhs.GetAllParters(); |
| | | var allLinks = rhs.GetAllLinks(); |
| | | foreach (var link in allLinks) |
| | | { |
| | | var allParterList = rhs.GetAllParters(); |
| | | var startLinkParter = allParterList.Find(x => x.Code == link.StartCode); |
| | | if (startLinkParter is IRevitLink) |
| | | if (startLinkParter is RevitLink startLink) |
| | | { |
| | | var junction = new Model.RevitJunction(); |
| | | junction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Code).ToList()); |
| | |
| | | junction.DemandPattern = null; |
| | | rhs.Junctions.Add(junction); |
| | | link.StartCode = junction.Code; |
| | | (startLinkParter as IRevitLink).EndCode = junction.Code; |
| | | |
| | | if (startLink.StartCode == link.Code) |
| | | { |
| | | startLink.StartCode = junction.Code; |
| | | } |
| | | else if (startLink.EndCode == link.Code) |
| | | { |
| | | startLink.EndCode = junction.Code; |
| | | } |
| | | allParterList.Add(junction); |
| | | } |
| | | |
| | | allParterList = rhs.GetAllParters(); |
| | | var endLinkParter = allParterList.Find(x => x.Code == link.EndCode); |
| | | if (endLinkParter is IRevitLink) |
| | | if (endLinkParter is RevitLink endLink) |
| | | { |
| | | var junction = new Model.RevitJunction(); |
| | | junction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Code).ToList()); |
| | |
| | | junction.DemandPattern = null; |
| | | rhs.Junctions.Add(junction); |
| | | link.EndCode = junction.Code; |
| | | (endLinkParter as IRevitLink).StartCode = junction.Code; |
| | | if (endLink.StartCode == link.Code) |
| | | { |
| | | endLink.StartCode = junction.Code; |
| | | } |
| | | else if (endLink.EndCode == link.Code) |
| | | { |
| | | endLink.EndCode = junction.Code; |
| | | } |
| | | allParterList.Add(junction); |
| | | } |
| | | } |
| | | return true; |