using HStation.Model;
|
|
namespace HStation.Service
|
{
|
/// <summary>
|
/// 修正辅助类
|
/// </summary>
|
public static class RevitCorrectHelper
|
{
|
/// <summary>
|
/// 修正
|
/// </summary>
|
public static bool Correct(this Model.RevitModel rhs, ref List<string> msgList)
|
{
|
if (rhs == null)
|
{
|
return false;
|
}
|
if (msgList == null)
|
{
|
msgList = new List<string>();
|
}
|
var result = true;
|
if (!CorrectCollection(rhs, ref msgList))
|
{//修正集合
|
result = false;
|
}
|
if (!CorrectName(rhs, ref msgList))
|
{//修正名称
|
result = false;
|
}
|
if (!CorrectExchanger(rhs, ref msgList))
|
{//修正换热器
|
result = false;
|
}
|
if (!CorrectCompressor(rhs, ref msgList))
|
{//修正空压机
|
result = false;
|
}
|
if (!CorrectCode(rhs, ref msgList))
|
{//修正编码
|
result = false;
|
}
|
if (!CorrectLink(rhs, ref msgList))
|
{//修正连接
|
result = false;
|
}
|
|
return result;
|
}
|
|
//修正集合
|
private static bool CorrectCollection(Model.RevitModel rhs, ref List<string> msgList)
|
{
|
if (rhs == null)
|
{
|
return false;
|
}
|
if (msgList == null)
|
{
|
msgList = new List<string>();
|
}
|
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.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.Nozzles == null)
|
{//喷头
|
rhs.Nozzles = new List<Model.RevitNozzle>();
|
}
|
if (rhs.Hydrants == null)
|
{//消火栓
|
rhs.Hydrants = new List<Model.RevitHydrant>();
|
}
|
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.Pipes == null)
|
{//管道
|
rhs.Pipes = new List<Model.RevitPipe>();
|
}
|
if (rhs.Translations == null)
|
{//过渡件
|
rhs.Translations = new List<Model.RevitTranslation>();
|
}
|
if (rhs.Pumps == null)
|
{//水泵
|
rhs.Pumps = new List<Model.RevitPump>();
|
}
|
if (rhs.Valves == null)
|
{//阀门
|
rhs.Valves = new List<Model.RevitValve>();
|
}
|
if (rhs.Exchangers == null)
|
{//换热器
|
rhs.Exchangers = new List<RevitExchanger>();
|
}
|
if (rhs.Compressors == null)
|
{//空压机
|
rhs.Compressors = new List<RevitCompressor>();
|
}
|
return true;
|
}
|
|
//修正名称
|
private static bool CorrectName(Model.RevitModel rhs, ref List<string> msgList)
|
{
|
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.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);
|
}
|
}
|
}
|
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.Compressors != null && rhs.Compressors.Count > 0)
|
{//空压机
|
var compressorNameList = rhs.Compressors.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).Distinct().ToList();
|
foreach (var compressor in rhs.Compressors)
|
{
|
if (string.IsNullOrEmpty(compressor.Name))
|
{
|
var compressorName = Yw.Untity.UniqueHelper.CreateFromFirst("空压机", compressorNameList);
|
compressor.Name = compressorName;
|
compressorNameList.Add(compressorName);
|
}
|
}
|
}
|
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();
|
foreach (var exchanger in rhs.Exchangers)
|
{
|
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);
|
}
|
else
|
{
|
if (connectParter is RevitBlunthead blunthead)
|
{
|
var decorator = new Model.RevitDecorator();
|
decorator.Id = blunthead.Id;
|
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.Count < 1)
|
{
|
var startConnect = exchanger.ConnectList.GetStartConnect();
|
if (startConnect != null)
|
{
|
startConnectList.Add(startConnect);
|
}
|
}
|
if (startConnectList.Count < 1)
|
{
|
msgList.Add($"换热器[{exchanger.Id}]上游连接组件不存在");
|
result = false;
|
continue;
|
}
|
var startJunction = new Model.RevitJunction();
|
startJunction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Id).ToList());
|
startJunction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList());
|
startJunction.Flags = null;
|
startJunction.ModelType = null;
|
startJunction.Description = "换热器修正时,自动添加";
|
startJunction.Position = startConnectList.GetCenterPosition();
|
startJunction.Elev = exchanger.Elev;
|
startJunction.Demand = null;
|
startJunction.DemandPattern = null;
|
rhs.Junctions.Add(startJunction);
|
exchanger.StartCode = startJunction.Id;
|
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);
|
|
#endregion
|
|
#region 结束连接
|
|
var endConnectList = exchanger.ConnectList.GetEndConnects();
|
if (endConnectList.Count < 1)
|
{
|
var endConnect = exchanger.ConnectList.GetEndConnect();
|
if (endConnect != null)
|
{
|
endConnectList.Add(endConnect);
|
}
|
}
|
if (endConnectList.Count < 1)
|
{
|
msgList.Add($"换热器[{exchanger.Id}]下游连接组件不存在");
|
result = false;
|
continue;
|
}
|
var endJunction = new Model.RevitJunction();
|
endJunction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Id).ToList());
|
endJunction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList());
|
endJunction.Flags = null;
|
endJunction.ModelType = null;
|
endJunction.Description = "换热器修正时,自动添加";
|
endJunction.Position = endConnectList.GetCenterPosition();
|
endJunction.Elev = exchanger.Elev;
|
endJunction.Demand = null;
|
endJunction.DemandPattern = null;
|
rhs.Junctions.Add(endJunction);
|
exchanger.EndCode = endJunction.Id;
|
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);
|
|
#endregion
|
}
|
else
|
{
|
msgList.Add($"换热器[{exchanger.Id}]连接列表为空");
|
result = false;
|
}
|
}
|
}
|
return result;
|
}
|
|
//修复空压机
|
private static bool CorrectCompressor(Model.RevitModel rhs, ref List<string> msgList)
|
{
|
if (rhs == null)
|
{
|
return false;
|
}
|
if (msgList == null)
|
{
|
msgList = new List<string>();
|
}
|
var result = true;
|
if (rhs.Compressors != null && rhs.Compressors.Count > 0)
|
{
|
var allParterList = rhs.GetAllParters();
|
foreach (var compressor in rhs.Compressors)
|
{
|
if (compressor.ConnectList != null && compressor.ConnectList.Count > 0)
|
{
|
#region 去除无效连接和闷头
|
|
foreach (var connect in compressor.ConnectList.ToList())
|
{
|
var connectParter = allParterList.Find(x => x.Id == connect.Id);
|
if (connectParter == null)
|
{
|
compressor.ConnectList.Remove(connect);
|
}
|
else
|
{
|
if (connectParter is RevitBlunthead blunthead)
|
{
|
var decorator = new Model.RevitDecorator();
|
decorator.Id = blunthead.Id;
|
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 = compressor.ConnectList.GetStartConnects();
|
if (startConnectList.Count < 1)
|
{
|
var startConnect = compressor.ConnectList.GetStartConnect();
|
if (startConnect != null)
|
{
|
startConnectList.Add(startConnect);
|
}
|
}
|
if (startConnectList.Count < 1)
|
{
|
msgList.Add($"空压机[{compressor.Id}]上游连接组件不存在");
|
result = false;
|
continue;
|
}
|
var startJunction = new Model.RevitJunction();
|
startJunction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Id).ToList());
|
startJunction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList());
|
startJunction.Flags = null;
|
startJunction.ModelType = null;
|
startJunction.Description = "空压机修正时,自动添加";
|
startJunction.Position = startConnectList.GetCenterPosition();
|
startJunction.Elev = compressor.Elev;
|
startJunction.Demand = null;
|
startJunction.DemandPattern = null;
|
rhs.Junctions.Add(startJunction);
|
compressor.StartCode = startJunction.Id;
|
foreach (var startConnect in startConnectList)
|
{
|
var startConnectParter = allParterList.Find(x => x.Id == startConnect.Id);
|
if (startConnectParter is RevitLink revitLink)
|
{
|
if (revitLink.StartCode == compressor.Id)
|
{
|
revitLink.StartCode = startJunction.Id;
|
}
|
else if (revitLink.EndCode == compressor.Id)
|
{
|
revitLink.EndCode = startJunction.Id;
|
}
|
}
|
}
|
allParterList.Add(startJunction);
|
|
#endregion
|
|
#region 结束连接
|
|
var endConnectList = compressor.ConnectList.GetEndConnects();
|
if (endConnectList.Count < 1)
|
{
|
var endConnect = compressor.ConnectList.GetEndConnect();
|
if (endConnect != null)
|
{
|
endConnectList.Add(endConnect);
|
}
|
}
|
if (endConnectList.Count < 1)
|
{
|
msgList.Add($"空压机[{compressor.Id}]下游连接组件不存在");
|
result = false;
|
continue;
|
}
|
var endJunction = new Model.RevitJunction();
|
endJunction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Id).ToList());
|
endJunction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList());
|
endJunction.Flags = null;
|
endJunction.ModelType = null;
|
endJunction.Description = "空压机修正时,自动添加";
|
endJunction.Position = endConnectList.GetCenterPosition();
|
endJunction.Elev = compressor.Elev;
|
endJunction.Demand = null;
|
endJunction.DemandPattern = null;
|
rhs.Junctions.Add(endJunction);
|
compressor.EndCode = endJunction.Id;
|
foreach (var endConnect in endConnectList)
|
{
|
var endConnectParter = allParterList.Find(x => x.Id == endConnect.Id);
|
if (endConnectParter is RevitLink revitLink)
|
{
|
if (revitLink.StartCode == compressor.Id)
|
{
|
revitLink.StartCode = endJunction.Id;
|
}
|
else if (revitLink.EndCode == compressor.Id)
|
{
|
revitLink.EndCode = endJunction.Id;
|
}
|
}
|
}
|
allParterList.Add(endJunction);
|
|
#endregion
|
}
|
else
|
{
|
msgList.Add($"空压机[{compressor.Id}]连接列表为空");
|
result = false;
|
}
|
}
|
}
|
return result;
|
}
|
|
//修正编码
|
private static bool CorrectCode(Model.RevitModel rhs, ref List<string> msgList)
|
{
|
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)
|
{
|
var startLinkParter = allParterList.Find(x => x.Id == link.StartCode);
|
if (startLinkParter == null)
|
{
|
msgList.Add($"管段:[{link.Id}]上游节点[{link.StartCode}]错误");
|
result = false;
|
}
|
else
|
{
|
link.StartCode = startLinkParter.Id;
|
}
|
|
var endLinkParter = allParterList.Find(x => x.Id == link.EndCode);
|
if (endLinkParter == null)
|
{
|
msgList.Add($"管段:[{link.Id}]下游节点[{link.EndCode}]错误");
|
result = false;
|
}
|
else
|
{
|
link.EndCode = endLinkParter.Id;
|
}
|
|
}
|
return result;
|
}
|
|
//修正连接
|
private static bool CorrectLink(Model.RevitModel rhs, ref List<string> msgList)
|
{
|
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)
|
{
|
var startLinkParter = allParterList.Find(x => x.Id == link.StartCode);
|
if (startLinkParter is RevitLink startLink)
|
{
|
var junction = new Model.RevitJunction();
|
junction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Id).ToList());
|
junction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList());
|
junction.Flags = null;
|
junction.ModelType = null;
|
junction.Description = "水力修正时,自动添加";
|
junction.Position = link.StartPosition;
|
junction.Elev = link.StartPosition.Z;
|
junction.Demand = null;
|
junction.DemandPattern = null;
|
rhs.Junctions.Add(junction);
|
link.StartCode = junction.Id;
|
|
if (startLink.StartCode == link.Id)
|
{
|
startLink.StartCode = junction.Id;
|
}
|
else if (startLink.EndCode == link.Id)
|
{
|
startLink.EndCode = junction.Id;
|
}
|
allParterList.Add(junction);
|
}
|
|
var endLinkParter = allParterList.Find(x => x.Id == link.EndCode);
|
if (endLinkParter is RevitLink endLink)
|
{
|
var junction = new Model.RevitJunction();
|
junction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Id).ToList());
|
junction.Name = UniqueHelper.CreateFromFirst("连接节点", allParterList.Select(x => x.Name).Distinct().ToList());
|
junction.Flags = null;
|
junction.ModelType = null;
|
junction.Description = "水力修正时,自动添加";
|
junction.Position = link.EndPosition;
|
junction.Elev = link.EndPosition.Z;
|
junction.Demand = null;
|
junction.DemandPattern = null;
|
rhs.Junctions.Add(junction);
|
link.EndCode = junction.Id;
|
if (endLink.StartCode == link.Id)
|
{
|
endLink.StartCode = junction.Id;
|
}
|
else if (endLink.EndCode == link.Id)
|
{
|
endLink.EndCode = junction.Id;
|
}
|
allParterList.Add(junction);
|
}
|
}
|
return true;
|
}
|
|
|
|
}
|
}
|