From 00f80abcfbf890ab3718d960550380389c64cea3 Mon Sep 17 00:00:00 2001 From: lixiaojun <1287241240@qq.com> Date: 星期三, 16 十月 2024 10:30:39 +0800 Subject: [PATCH] Revit解析修改 --- Service/HStation.Service.Revit.Core/04-service/02-correct/RevitCorrectHelper.cs | 486 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 405 insertions(+), 81 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 d4b9954..74e5e54 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 @@ -10,138 +10,388 @@ /// <summary> /// 淇 /// </summary> - public static bool Correct(this Model.RevitModel rhs, out string msg) + public static bool Correct(this Model.RevitModel rhs, ref List<string> msgList) { if (rhs == null) { - msg = "鏁版嵁涓虹┖"; return false; } - if (!Zero(rhs, out msg)) + if (msgList == null) { - return false; + msgList = new List<string>(); } - if (!First(rhs, out msg)) - { - return false; + var result = true; + if (!CorrectCollection(rhs, ref msgList)) + {//淇闆嗗悎 + result = false; } - if (!Exchanger(rhs, out msg)) - { - return false; + if (!CorrectName(rhs, ref msgList)) + {//淇鍚嶇О + result = false; } - if (!Second(rhs, out msg)) - { - return false; + if (!CorrectExchanger(rhs, ref msgList)) + {//淇鎹㈢儹鍣� + result = false; } - if (!Three(rhs, out msg)) - { - return false; + if (!CorrectCode(rhs, ref msgList)) + {//淇缂栫爜 + result = false; } - return true; + if (!CorrectLink(rhs, ref msgList)) + {//淇杩炴帴 + result = false; + } + + return result; } - //鍓嶆彁锛氶獙璇佸悎娉曟�� - private static bool Zero(Model.RevitModel rhs, out string msg) + //淇闆嗗悎 + private static bool CorrectCollection(Model.RevitModel rhs, ref List<string> msgList) { - msg = string.Empty; - var allWaterSourceList = rhs.GetAllWaterSources(); - if (allWaterSourceList == null || allWaterSourceList.Count < 1) + if (rhs == null) { - msg = "鏃犳按婧�"; return false; } - var allJunctionList = rhs.GetAllJunctions(); - if (allJunctionList == null || allJunctionList.Count < 1) + if (msgList == null) { - msg = "鏃犺繛鎺ヨ妭鐐�"; - return false; + msgList = new List<string>(); } - return true; - } - - //绗竴姝ワ細妫�鏌ラ泦鍚堝垵濮嬪寲 - private static bool First(Model.RevitModel rhs, out string msg) - { - msg = string.Empty; if (rhs.Reservoirs == null) - { + {//姘村簱 rhs.Reservoirs = new List<Model.RevitReservoir>(); } if (rhs.Tanks == null) - { + {//姘存睜 rhs.Tanks = new List<Model.RevitTank>(); } if (rhs.Waterboxs == null) - { + {//姘寸 rhs.Waterboxs = new List<Model.RevitWaterbox>(); } if (rhs.Junctions == null) - { - rhs.Waterboxs = new List<Model.RevitWaterbox>(); + {//杩炴帴鑺傜偣 + rhs.Junctions = new List<Model.RevitJunction>(); + } + if (rhs.Bluntheads == null) + {//闂峰ご + rhs.Bluntheads = new List<Model.RevitBlunthead>(); } if (rhs.Elbows == null) - { + {//寮ご rhs.Elbows = new List<Model.RevitElbow>(); } if (rhs.Threelinks == null) - { + {//涓夐�� rhs.Threelinks = new List<Model.RevitThreelink>(); } if (rhs.Fourlinks == null) - { + {//鍥涢�� 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>(); } if (rhs.Pressmeters == null) - { + {//鍘嬪姏琛� rhs.Pressmeters = new List<Model.RevitPressmeter>(); } if (rhs.Nozzles == null) - { + {//鍠峰ご rhs.Nozzles = new List<Model.RevitNozzle>(); } if (rhs.Hydrants == null) - { + {//娑堢伀鏍� rhs.Hydrants = new List<Model.RevitHydrant>(); } - if (rhs.Bluntheads == null) - { - rhs.Bluntheads = new List<Model.RevitBlunthead>(); - } + if (rhs.Pipes == null) - { + {//绠¢亾 rhs.Pipes = new List<Model.RevitPipe>(); } if (rhs.Translations == null) - { + {//杩囨浮浠� 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) + //淇鍚嶇О + private static bool CorrectName(Model.RevitModel rhs, ref List<string> msgList) { - msg = string.Empty; + if (rhs == null) + { + return false; + } + if (msgList == null) + { + msgList = new List<string>(); + } + if (rhs.Reservoirs != null && rhs.Reservoirs.Count > 0) + {//姘村簱 + var reservoirNameList = rhs.Reservoirs.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var reservoir in rhs.Reservoirs) + { + if (string.IsNullOrEmpty(reservoir.Name)) + { + var reservoirName = Yw.Untity.UniqueHelper.CreateFromFirst("姘村簱", reservoirNameList); + reservoir.Name = reservoirName; + reservoirNameList.Add(reservoirName); + } + } + } + if (rhs.Tanks != null && rhs.Tanks.Count > 0) + {//姘存睜 + var tankNameList = rhs.Tanks.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var tank in rhs.Tanks) + { + if (string.IsNullOrEmpty(tank.Name)) + { + var tankName = Yw.Untity.UniqueHelper.CreateFromFirst("姘存睜", tankNameList); + tank.Name = tankName; + tankNameList.Add(tankName); + } + } + } + if (rhs.Waterboxs != null && rhs.Waterboxs.Count > 0) + {//姘寸 + var waterboxNameList = rhs.Waterboxs.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var waterbox in rhs.Waterboxs) + { + if (string.IsNullOrEmpty(waterbox.Name)) + { + var waterboxName = Yw.Untity.UniqueHelper.CreateFromFirst("姘存睜", waterboxNameList); + waterbox.Name = waterboxName; + waterboxNameList.Add(waterboxName); + } + } + } + if (rhs.Junctions != null && rhs.Junctions.Count > 0) + {//杩炴帴鑺傜偣 + var junctionNameList = rhs.Junctions.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var junction in rhs.Junctions) + { + if (string.IsNullOrEmpty(junction.Name)) + { + var junctionName = Yw.Untity.UniqueHelper.CreateFromFirst("杩炴帴鑺傜偣", junctionNameList); + junction.Name = junctionName; + junctionNameList.Add(junctionName); + } + } + } + if (rhs.Bluntheads != null && rhs.Bluntheads.Count > 0) + {//闂峰ご + var bluntheadNameList = rhs.Bluntheads.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var blunthead in rhs.Bluntheads) + { + if (string.IsNullOrEmpty(blunthead.Name)) + { + var bluntheadName = Yw.Untity.UniqueHelper.CreateFromFirst("闂峰ご", bluntheadNameList); + blunthead.Name = bluntheadName; + bluntheadNameList.Add(bluntheadName); + } + } + } + if (rhs.Elbows != null && rhs.Elbows.Count > 0) + {//寮ご + var elbowNameList = rhs.Elbows.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var elbow in rhs.Elbows) + { + if (string.IsNullOrEmpty(elbow.Name)) + { + var elbowName = Yw.Untity.UniqueHelper.CreateFromFirst("寮ご", elbowNameList); + elbow.Name = elbowName; + elbowNameList.Add(elbowName); + } + } + } + if (rhs.Threelinks != null && rhs.Threelinks.Count > 0) + {//涓夐�� + var threelinkNameList = rhs.Threelinks.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var threelink in rhs.Threelinks) + { + if (string.IsNullOrEmpty(threelink.Name)) + { + var threelinkName = Yw.Untity.UniqueHelper.CreateFromFirst("涓夐��", threelinkNameList); + threelink.Name = threelinkName; + threelinkNameList.Add(threelinkName); + } + } + } + if (rhs.Fourlinks != null && rhs.Fourlinks.Count > 0) + {//鍥涢�� + var fourlinkNameList = rhs.Fourlinks.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var fourlink in rhs.Fourlinks) + { + if (string.IsNullOrEmpty(fourlink.Name)) + { + var fourlinkName = Yw.Untity.UniqueHelper.CreateFromFirst("鍥涢��", fourlinkNameList); + fourlink.Name = fourlinkName; + fourlinkNameList.Add(fourlinkName); + } + } + } + if (rhs.Nozzles != null && rhs.Nozzles.Count > 0) + {//鍠峰ご + var nozzleNameList = rhs.Nozzles.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var nozzle in rhs.Nozzles) + { + if (string.IsNullOrEmpty(nozzle.Name)) + { + var nozzleName = Yw.Untity.UniqueHelper.CreateFromFirst("鍠峰ご", nozzleNameList); + nozzle.Name = nozzleName; + nozzleNameList.Add(nozzleName); + } + } + } + if (rhs.Hydrants != null && rhs.Hydrants.Count > 0) + {//娑堢伀鏍� + var hydrantNameList = rhs.Hydrants.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var hydrant in rhs.Hydrants) + { + if (string.IsNullOrEmpty(hydrant.Name)) + { + var hydrantName = Yw.Untity.UniqueHelper.CreateFromFirst("娑堢伀鏍�", hydrantNameList); + hydrant.Name = hydrantName; + hydrantNameList.Add(hydrantName); + } + } + } + if (rhs.Meters != null && rhs.Meters.Count > 0) + {//姘磋〃 + var meterNameList = rhs.Meters.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var meter in rhs.Meters) + { + if (string.IsNullOrEmpty(meter.Name)) + { + var meterName = Yw.Untity.UniqueHelper.CreateFromFirst("姘磋〃", meterNameList); + meter.Name = meterName; + meterNameList.Add(meterName); + } + } + } + if (rhs.Flowmeters != null && rhs.Flowmeters.Count > 0) + {//娴侀噺璁� + var flowmeterNameList = rhs.Flowmeters.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var flowmeter in rhs.Flowmeters) + { + if (string.IsNullOrEmpty(flowmeter.Name)) + { + var flowmeterName = Yw.Untity.UniqueHelper.CreateFromFirst("娴侀噺璁�", flowmeterNameList); + flowmeter.Name = flowmeterName; + flowmeterNameList.Add(flowmeterName); + } + } + } + if (rhs.Pressmeters != null && rhs.Pressmeters.Count > 0) + {//鍘嬪姏琛� + var pressmeterNameList = rhs.Pressmeters.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var pressmeter in rhs.Pressmeters) + { + if (string.IsNullOrEmpty(pressmeter.Name)) + { + var pressmeterName = Yw.Untity.UniqueHelper.CreateFromFirst("鍘嬪姏琛�", pressmeterNameList); + pressmeter.Name = pressmeterName; + pressmeterNameList.Add(pressmeterName); + } + } + } + if (rhs.Pipes != null && rhs.Pipes.Count > 0) + {//绠¢亾 + var pipeNameList = rhs.Pipes.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var pipe in rhs.Pipes) + { + if (string.IsNullOrEmpty(pipe.Name)) + { + var pipeName = Yw.Untity.UniqueHelper.CreateFromFirst("绠¢亾", pipeNameList); + pipe.Name = pipeName; + pipeNameList.Add(pipeName); + } + } + } + if (rhs.Translations != null && rhs.Translations.Count > 0) + {//杩囨浮浠� + var translationNameList = rhs.Translations.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var translation in rhs.Translations) + { + if (string.IsNullOrEmpty(translation.Name)) + { + var translationName = Yw.Untity.UniqueHelper.CreateFromFirst("杩囨浮浠�", translationNameList); + translation.Name = translationName; + translationNameList.Add(translationName); + } + } + } + if (rhs.Exchangers != null && rhs.Exchangers.Count > 0) + {//鎹㈢儹鍣� + var exchangerNameList = rhs.Exchangers.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var exchanger in rhs.Exchangers) + { + if (string.IsNullOrEmpty(exchanger.Name)) + { + var exchangerName = Yw.Untity.UniqueHelper.CreateFromFirst("鎹㈢儹鍣�", exchangerNameList); + exchanger.Name = exchangerName; + exchangerNameList.Add(exchangerName); + } + } + } + if (rhs.Pumps != null && rhs.Pumps.Count > 0) + {//姘存车 + var pumpNameList = rhs.Pumps.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var pump in rhs.Pumps) + { + if (string.IsNullOrEmpty(pump.Name)) + { + var pumpName = Yw.Untity.UniqueHelper.CreateFromFirst("姘存车", pumpNameList); + pump.Name = pumpName; + pumpNameList.Add(pumpName); + } + } + } + if (rhs.Valves != null && rhs.Valves.Count > 0) + {//闃�闂� + var valveNameList = rhs.Valves.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList(); + foreach (var valve in rhs.Valves) + { + if (string.IsNullOrEmpty(valve.Name)) + { + var valveName = Yw.Untity.UniqueHelper.CreateFromFirst("闃�闂�", valveNameList); + valve.Name = valveName; + valveNameList.Add(valveName); + } + } + } + return true; + } + + //淇鎹㈢儹鍣� + private static bool CorrectExchanger(Model.RevitModel rhs, ref List<string> msgList) + { + if (rhs == null) + { + return false; + } + if (msgList == null) + { + msgList = new List<string>(); + } + var result = true; if (rhs.Exchangers != null && rhs.Exchangers.Count > 0) { var allParterList = rhs.GetAllParters(); @@ -149,22 +399,51 @@ { if (exchanger.ConnectList != null && exchanger.ConnectList.Count > 0) { + #region 鍘婚櫎鏃犳晥杩炴帴鍜岄椃澶� + 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; + } + 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); + } } } + #endregion + + #region 寮�濮嬭繛鎺� + var startConnectList = exchanger.ConnectList.GetStartConnects(); - if (startConnectList == null || startConnectList.Count < 1) + if (startConnectList.Count < 1) { - msg = $"鎹㈢儹鍣細{exchanger.Id} 涓婃父杩炴帴缁勪欢涓嶅瓨鍦�"; - return false; + var startConnect = exchanger.ConnectList.GetStartConnect(); + if (startConnect != null) + { + startConnectList.Add(startConnect); + } + } + if (startConnectList.Count < 1) + { + msgList.Add($"鎹㈢儹鍣╗{exchanger.Code}]涓婃父杩炴帴缁勪欢涓嶅瓨鍦�"); + result = false; + continue; } var startJunction = new Model.RevitJunction(); startJunction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Code).ToList()); @@ -197,11 +476,24 @@ } allParterList.Add(startJunction); + #endregion + + #region 缁撴潫杩炴帴 + var endConnectList = exchanger.ConnectList.GetEndConnects(); - if (endConnectList == null || endConnectList.Count < 1) + if (endConnectList.Count < 1) { - msg = $"鎹㈢儹鍣細{exchanger.Id} 涓嬫父杩炴帴缁勪欢涓嶅瓨鍦�"; - return false; + var endConnect = exchanger.ConnectList.GetEndConnect(); + if (endConnect != null) + { + endConnectList.Add(endConnect); + } + } + if (endConnectList.Count < 1) + { + msgList.Add($"鎹㈢儹鍣╗{exchanger.Code}]涓嬫父杩炴帴缁勪欢涓嶅瓨鍦�"); + result = false; + continue; } var endJunction = new Model.RevitJunction(); endJunction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Code).ToList()); @@ -233,16 +525,31 @@ } } allParterList.Add(endJunction); + + #endregion + } + else + { + msgList.Add($"鎹㈢儹鍣╗{exchanger.Code}]杩炴帴鍒楄〃涓虹┖"); + result = false; } } } - return true; + return result; } - //绗簩姝ワ細妫�鏌ヤ笂涓嬫父缂栫爜 - private static bool Second(Model.RevitModel rhs, out string msg) + //淇缂栫爜 + private static bool CorrectCode(Model.RevitModel rhs, ref List<string> msgList) { - msg = string.Empty; + if (rhs == null) + { + return false; + } + if (msgList == null) + { + msgList = new List<string>(); + } + var result = true; var allParterList = rhs.GetAllParters(); var allLinks = rhs.GetAllLinks(); foreach (var link in allLinks) @@ -250,25 +557,40 @@ var startLinkParter = allParterList.Find(x => x.Id == link.StartCode); if (startLinkParter == null) { - msg = $"绠℃: {link.Id} 涓婃父鑺傜偣閿欒"; - return false; + msgList.Add($"绠℃:[{link.Code}]涓婃父鑺傜偣閿欒"); + result = false; } - link.StartCode = startLinkParter.Code; + else + { + link.StartCode = startLinkParter.Code; + } + var endLinkParter = allParterList.Find(x => x.Id == link.EndCode); if (endLinkParter == null) { - msg = $"绠℃: {link.Id} 涓嬫父鑺傜偣閿欒"; - return false; + msgList.Add($"绠℃:[{link.Code}]涓嬫父鑺傜偣閿欒"); + result = false; } - link.EndCode = endLinkParter.Code; + else + { + link.EndCode = endLinkParter.Code; + } + } - return true; + return result; } - //绗笁姝ワ細鎸夌収姘村姏缁撴瀯杩涜淇 - private static bool Three(Model.RevitModel rhs, out string msg) + //淇杩炴帴 + private static bool CorrectLink(Model.RevitModel rhs, ref List<string> msgList) { - msg = string.Empty; + if (rhs == null) + { + return false; + } + if (msgList == null) + { + msgList = new List<string>(); + } var allParterList = rhs.GetAllParters(); var allLinks = rhs.GetAllLinks(); foreach (var link in allLinks) @@ -333,5 +655,7 @@ return true; } + + } } -- Gitblit v1.9.3