From 473f0b15ec693b18ecf7b1174360088df0e8e86c Mon Sep 17 00:00:00 2001 From: lixiaojun <1287241240@qq.com> Date: 星期四, 19 九月 2024 14:07:14 +0800 Subject: [PATCH] Revit导入修改 --- Service/HStation.Service.Revit.Core/04-service/02-correct/RevitCorrectHelper.cs | 202 +++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 182 insertions(+), 20 deletions(-) diff --git a/Service/HStation.Service.Revit.Core/04-service/02-correct/RevitCorrectHelper.cs b/Service/HStation.Service.Revit.Core/04-service/02-correct/RevitCorrectHelper.cs index 7835963..d4b9954 100644 --- a/Service/HStation.Service.Revit.Core/04-service/02-correct/RevitCorrectHelper.cs +++ b/Service/HStation.Service.Revit.Core/04-service/02-correct/RevitCorrectHelper.cs @@ -8,39 +8,61 @@ public static class RevitCorrectHelper { /// <summary> - /// 淇(鏃犳硶淇浼氭姏鍑哄紓甯�) + /// 淇 /// </summary> - /// <param name="rhs">RevitModel</param> - public static void Correct(this Model.RevitModel rhs) + public static bool Correct(this Model.RevitModel rhs, out string msg) { if (rhs == null) { - throw new Exception("鏁版嵁涓虹┖"); + msg = "鏁版嵁涓虹┖"; + return false; } - Zero(rhs); - First(rhs); - Second(rhs); - Three(rhs); + if (!Zero(rhs, out msg)) + { + return false; + } + if (!First(rhs, out msg)) + { + return false; + } + if (!Exchanger(rhs, out msg)) + { + return false; + } + if (!Second(rhs, out msg)) + { + return false; + } + if (!Three(rhs, out msg)) + { + return false; + } + return true; } //鍓嶆彁锛氶獙璇佸悎娉曟�� - private static void Zero(Model.RevitModel rhs) + private static bool Zero(Model.RevitModel rhs, out string msg) { + msg = string.Empty; var allWaterSourceList = rhs.GetAllWaterSources(); if (allWaterSourceList == null || allWaterSourceList.Count < 1) { - throw new Exception("鏃犳按婧�"); + msg = "鏃犳按婧�"; + return false; } var allJunctionList = rhs.GetAllJunctions(); if (allJunctionList == null || allJunctionList.Count < 1) { - throw new Exception("鏃犺繛鎺ヨ妭鐐�"); + msg = "鏃犺繛鎺ヨ妭鐐�"; + return false; } + return true; } //绗竴姝ワ細妫�鏌ラ泦鍚堝垵濮嬪寲 - private static void First(Model.RevitModel rhs) + private static bool First(Model.RevitModel rhs, out string msg) { + msg = string.Empty; if (rhs.Reservoirs == null) { rhs.Reservoirs = new List<Model.RevitReservoir>(); @@ -68,6 +90,10 @@ if (rhs.Fourlinks == null) { rhs.Fourlinks = new List<Model.RevitFourlink>(); + } + if (rhs.Meters == null) + { + rhs.Meters = new List<RevitMeter>(); } if (rhs.Flowmeters == null) { @@ -97,6 +123,10 @@ { 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>(); @@ -105,31 +135,146 @@ { 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); + //msg = $"鎹㈢儹鍣細{exchanger.Id} 杩炴帴缁勪欢 {connect.Id} 涓嶅瓨鍦�"; + // return false; + } + } + + 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 = "鎹㈢儹鍣ㄤ慨姝f椂锛岃嚜鍔ㄦ坊鍔�"; + 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 = "鎹㈢儹鍣ㄤ慨姝f椂锛岃嚜鍔ㄦ坊鍔�"; + 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 void Second(Model.RevitModel rhs) + 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 void Three(Model.RevitModel rhs) + 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()); @@ -145,12 +290,20 @@ 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()); @@ -166,9 +319,18 @@ 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; } } -- Gitblit v1.9.3