lixiaojun
2024-09-30 91c87afb0418628d23962014dc7cdca4778642c5
Service/HStation.Service.Revit.Core/04-service/02-correct/RevitCorrectHelper.cs
@@ -1,6 +1,4 @@
using HStation.Model;
using Microsoft.VisualBasic;
using System;
namespace HStation.Service
{
@@ -10,9 +8,8 @@
    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)
@@ -152,13 +149,29 @@
                {
                    if (exchanger.ConnectList != null && exchanger.ConnectList.Count > 0)
                    {
                        foreach (var connect in exchanger.ConnectList)
                        foreach (var connect in exchanger.ConnectList.ToList())
                        {
                            var connectParter = allParterList.Find(x => x.Id == connect.Id);
                            if (connectParter == null)
                            {
                                msg = $"换热器:{exchanger.Id} 连接组件 {connect.Id} 不存在";
                                return false;
                                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);
                                }
                            }
                        }
@@ -176,7 +189,7 @@
                        startJunction.ModelType = null;
                        startJunction.Description = "换热器修正时,自动添加";
                        startJunction.Quality = exchanger.StartQuality;
                        startJunction.Position = exchanger.StartPosition;
                        startJunction.Position = startConnectList.GetCenterPosition();
                        startJunction.Elev = exchanger.StartElev;
                        startJunction.Demand = null;
                        startJunction.DemandPattern = null;
@@ -185,9 +198,16 @@
                        foreach (var startConnect in startConnectList)
                        {
                            var startConnectParter = allParterList.Find(x => x.Id == startConnect.Id);
                            if (startConnectParter is IRevitLink revitLink)
                            if (startConnectParter is RevitLink revitLink)
                            {
                                revitLink.EndCode = startJunction.Id;
                                if (revitLink.StartCode == exchanger.Id)
                                {
                                    revitLink.StartCode = startJunction.Id;
                                }
                                else if (revitLink.EndCode == exchanger.Id)
                                {
                                    revitLink.EndCode = startJunction.Id;
                                }
                            }
                        }
                        allParterList.Add(startJunction);
@@ -206,7 +226,7 @@
                        endJunction.ModelType = null;
                        endJunction.Description = "换热器修正时,自动添加";
                        endJunction.Quality = exchanger.EndQuality;
                        endJunction.Position = exchanger.EndPosition;
                        endJunction.Position = endConnectList.GetCenterPosition();
                        endJunction.Elev = exchanger.EndElev;
                        endJunction.Demand = null;
                        endJunction.DemandPattern = null;
@@ -215,9 +235,16 @@
                        foreach (var endConnect in endConnectList)
                        {
                            var endConnectParter = allParterList.Find(x => x.Id == endConnect.Id);
                            if (endConnectParter is IRevitLink revitLink)
                            if (endConnectParter is RevitLink revitLink)
                            {
                                revitLink.StartCode = endJunction.Id;
                                if (revitLink.StartCode == exchanger.Id)
                                {
                                    revitLink.StartCode = endJunction.Id;
                                }
                                else if (revitLink.EndCode == exchanger.Id)
                                {
                                    revitLink.EndCode = endJunction.Id;
                                }
                            }
                        }
                        allParterList.Add(endJunction);
@@ -262,7 +289,7 @@
            foreach (var link in allLinks)
            {
                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());
@@ -278,12 +305,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);
                }
                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());
@@ -299,7 +334,14 @@
                    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);
                }
            }