using HStation.Model; using Microsoft.VisualBasic; namespace HStation.Service { /// /// 修正辅助类 /// public static class RevitCorrectHelper { /// /// 修正(无法修正会抛出异常) /// /// RevitModel public static bool Correct(this Model.RevitModel rhs, out string msg) { if (rhs == null) { msg = "数据为空"; return false; } if (!Zero(rhs, out msg)) { return false; } if (!First(rhs, out msg)) { return false; } if (!Second(rhs, out msg)) { return false; } if (!Three(rhs, out msg)) { return false; } return true; } //前提:验证合法性 private static bool Zero(Model.RevitModel rhs, out string msg) { msg = string.Empty; var allWaterSourceList = rhs.GetAllWaterSources(); if (allWaterSourceList == null || allWaterSourceList.Count < 1) { msg = "无水源"; return false; } var allJunctionList = rhs.GetAllJunctions(); if (allJunctionList == null || allJunctionList.Count < 1) { msg = "无连接节点"; return false; } return true; } //第一步:检查集合初始化 private static bool First(Model.RevitModel rhs, out string msg) { msg = string.Empty; if (rhs.Reservoirs == null) { rhs.Reservoirs = new List(); } if (rhs.Tanks == null) { rhs.Tanks = new List(); } if (rhs.Waterboxs == null) { rhs.Waterboxs = new List(); } if (rhs.Junctions == null) { rhs.Waterboxs = new List(); } if (rhs.Elbows == null) { rhs.Elbows = new List(); } if (rhs.Threelinks == null) { rhs.Threelinks = new List(); } if (rhs.Fourlinks == null) { rhs.Fourlinks = new List(); } if (rhs.Flowmeters == null) { rhs.Flowmeters = new List(); } if (rhs.Pressmeters == null) { rhs.Pressmeters = new List(); } if (rhs.Nozzles == null) { rhs.Nozzles = new List(); } if (rhs.Hydrants == null) { rhs.Hydrants = new List(); } if (rhs.Bluntheads == null) { rhs.Bluntheads = new List(); } if (rhs.Pipes == null) { rhs.Pipes = new List(); } if (rhs.Translations == null) { rhs.Translations = new List(); } if (rhs.Pumps == null) { rhs.Pumps = new List(); } if (rhs.Valves == null) { rhs.Valves = new List(); } return true; } //第二步:检查上下游编码 private static bool Second(Model.RevitModel rhs, out string msg) { msg = string.Empty; var allParterList = rhs.GetAllParters(); var allLinks = rhs.GetAllLinks(); foreach (var link in allLinks) { var startLinkParter = allParterList.Find(x => x.Id == link.StartCode); if (startLinkParter == null) { msg = $"管段: {link.Id} 上游节点错误"; return false; } link.StartCode = startLinkParter.Code; var endLinkParter = allParterList.Find(x => x.Id == link.EndCode); if (endLinkParter == null) { msg = $"管段: {link.Id} 下游节点错误"; return false; } link.EndCode = endLinkParter.Code; } return true; } //第三步:按照水力结构进行修正 private static bool Three(Model.RevitModel rhs, out string msg) { msg = string.Empty; 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) { var junction = new Model.RevitJunction(); junction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Code).ToList()); junction.Code = junction.Id; junction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList()); junction.Flags = null; junction.ModelType = null; junction.Description = "水力修正时,自动添加"; junction.Quality = link.StartQuality; junction.Position = link.StartPosition; junction.Elev = link.StartElev; junction.Demand = null; junction.DemandPattern = null; rhs.Junctions.Add(junction); link.StartCode = junction.Code; (startLinkParter as IRevitLink).EndCode = junction.Code; } allParterList = rhs.GetAllParters(); var endLinkParter = allParterList.Find(x => x.Code == link.EndCode); if (endLinkParter is IRevitLink) { var junction = new Model.RevitJunction(); junction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Code).ToList()); junction.Code = junction.Id; junction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList()); junction.Flags = null; junction.ModelType = null; junction.Description = "水力修正时,自动添加"; junction.Quality = link.EndQuality; junction.Position = link.EndPosition; junction.Elev = link.EndElev; junction.Demand = null; junction.DemandPattern = null; rhs.Junctions.Add(junction); link.EndCode = junction.Code; (endLinkParter as IRevitLink).StartCode = junction.Code; } } return true; } } }