From eb4679bfe7f2c945f3e03f6927c8fde893f7d33c Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期三, 14 八月 2024 22:56:10 +0800
Subject: [PATCH] Revit解析bug修复

---
 Hydro/Yw.EPAnet.Calcu.Core/02-check/NetworkCheckExtensions.cs                              |    8 +-
 Service/HStation.Service.Revit.Core/04-service/01-json/model/RevitConnectListExtensions.cs |    4 
 Hydro/Yw.Hydro.Core/Yw.Hydro.Core.csproj                                                   |    2 
 Service/HStation.Service.Revit.Core/04-service/01-json/RevitJsonHelper.cs                  |   36 ++++++++++++
 Desktop/HStation.Desktop.Xhs.Core/Program.cs                                               |    4 
 WinFrmUI/Yw.WinFrmUI.Hydro.Core/Yw.WinFrmUI.Hydro.Core.csproj                              |    2 
 WinFrmUI/Yw.WinFrmUI.Hydro.Core/02-model/HydroModelMgrPage.cs                              |    1 
 Service/HStation.Service.Revit.Core/04-service/01-json/model/RevitPositionExtensions.cs    |   30 ++++++++++
 Service/HStation.Service.Revit.Core/04-service/02-correct/RevitCorrectHelper.cs            |   45 ++++++++++++--
 9 files changed, 113 insertions(+), 19 deletions(-)

diff --git a/Desktop/HStation.Desktop.Xhs.Core/Program.cs b/Desktop/HStation.Desktop.Xhs.Core/Program.cs
index fd646ba..a7eb645 100644
--- a/Desktop/HStation.Desktop.Xhs.Core/Program.cs
+++ b/Desktop/HStation.Desktop.Xhs.Core/Program.cs
@@ -62,8 +62,8 @@
                 //}
 
                 // Yw.FileFolderZipHelper.Zip(@"C:\Users\ZKC\Desktop\循环水用例", @"C:\Users\ZKC\Desktop\循环水用例.ywrvt");
-                Yw.FileFolderZipHelper.Zip(@"C:\Users\Eventech\Desktop\循环水用例", @"C:\Users\Eventech\Desktop\循环水用例.ywrvt");
-                //Yw.FileFolderZipHelper.Zip(@"C:\Users\admin\Desktop\居家办公工作\循环水用例", @"C:\Users\admin\Desktop\居家办公工作\循环水用例.ywrvt");
+                //Yw.FileFolderZipHelper.Zip(@"C:\Users\Eventech\Desktop\循环水用例", @"C:\Users\Eventech\Desktop\循环水用例.ywrvt");
+                Yw.FileFolderZipHelper.Zip(@"C:\Users\admin\Desktop\居家办公工作\循环水用例", @"C:\Users\admin\Desktop\居家办公工作\循环水用例.ywrvt");
 
                 //var json = RevitTestHelper.GenerateJson();
 
diff --git a/Hydro/Yw.EPAnet.Calcu.Core/02-check/NetworkCheckExtensions.cs b/Hydro/Yw.EPAnet.Calcu.Core/02-check/NetworkCheckExtensions.cs
index bff0317..9f44ef7 100644
--- a/Hydro/Yw.EPAnet.Calcu.Core/02-check/NetworkCheckExtensions.cs
+++ b/Hydro/Yw.EPAnet.Calcu.Core/02-check/NetworkCheckExtensions.cs
@@ -157,24 +157,24 @@
                             FailReason = "灞炴�ц缃敊璇紝绠¢亾闀垮害蹇呴』澶т簬0"
                         });
                     }
-                    if (pipe.Roughness <= 0.1 || pipe.Roughness > 10000)
+                    if (pipe.Roughness < 0.1 || pipe.Roughness > 10000)
                     {
                         result.Succeed = false;
                         result.FailedList.Add(new CheckFailed()
                         {
                             ParterId = pipe.Id,
                             FailType = eCheckFailType.PropSetError,
-                            FailReason = "灞炴�ц缃敊璇紝绮楃硻绯绘暟鍖洪棿(0.1,10000銆�"
+                            FailReason = "灞炴�ц缃敊璇紝绮楃硻绯绘暟鍖洪棿[0.1,10000銆�"
                         });
                     }
-                    if (pipe.Diameter <= 0.1 || pipe.Diameter > 10000)
+                    if (pipe.Diameter < 0.1 || pipe.Diameter > 10000)
                     {
                         result.Succeed = false;
                         result.FailedList.Add(new CheckFailed()
                         {
                             ParterId = pipe.Id,
                             FailType = eCheckFailType.PropSetError,
-                            FailReason = "灞炴�ц缃敊璇紝绠″緞鍖洪棿(0.1,10000銆�"
+                            FailReason = "灞炴�ц缃敊璇紝绠″緞鍖洪棿[0.1,10000]"
                         });
                     }
                 }
diff --git a/Hydro/Yw.Hydro.Core/Yw.Hydro.Core.csproj b/Hydro/Yw.Hydro.Core/Yw.Hydro.Core.csproj
index 412470e..6dbfda3 100644
--- a/Hydro/Yw.Hydro.Core/Yw.Hydro.Core.csproj
+++ b/Hydro/Yw.Hydro.Core/Yw.Hydro.Core.csproj
@@ -7,7 +7,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Yw.Service.Hydro.Core" Version="3.2.8" />
+    <PackageReference Include="Yw.Service.Hydro.Core" Version="3.2.9" />
   </ItemGroup>
 
   <ItemGroup>
diff --git a/Service/HStation.Service.Revit.Core/04-service/01-json/RevitJsonHelper.cs b/Service/HStation.Service.Revit.Core/04-service/01-json/RevitJsonHelper.cs
index 5d7d7d5..f1b1b73 100644
--- a/Service/HStation.Service.Revit.Core/04-service/01-json/RevitJsonHelper.cs
+++ b/Service/HStation.Service.Revit.Core/04-service/01-json/RevitJsonHelper.cs
@@ -687,6 +687,18 @@
                                 {
                                     exchanger.Roughness = roughness;
                                 }
+                                if (exchanger.Length <= 0)
+                                {
+                                    exchanger.Length = exchanger.StartPosition.Distance(exchanger.EndPosition);
+                                }
+                                if (exchanger.Diameter < 0.1)
+                                {
+                                    exchanger.Diameter = 0.1;
+                                }
+                                if (exchanger.Roughness < 0.1)
+                                {
+                                    exchanger.Roughness = 0.1;
+                                }
                                 model.Exchangers.Add(exchanger);
                             }
                             break;
@@ -759,6 +771,18 @@
                                 {
                                     pipe.Roughness = roughness;
                                 }
+                                if (pipe.Length <= 0)
+                                {
+                                    pipe.Length = pipe.StartPosition.Distance(pipe.EndPosition);
+                                }
+                                if (pipe.Diameter < 0.1)
+                                {
+                                    pipe.Diameter = 0.1;
+                                }
+                                if (pipe.Roughness < 0.1)
+                                {
+                                    pipe.Roughness = 0.1;
+                                }
                                 model.Pipes.Add(pipe);
                             }
                             break;
@@ -831,6 +855,18 @@
                                 {
                                     translation.Roughness = roughness;
                                 }
+                                if (translation.Length <= 0)
+                                {
+                                    translation.Length = translation.StartPosition.Distance(translation.EndPosition);
+                                }
+                                if (translation.Diameter < 0.1)
+                                {
+                                    translation.Diameter = 0.1;
+                                }
+                                if (translation.Roughness < 0.1)
+                                {
+                                    translation.Roughness = 0.1;
+                                }
                                 model.Translations.Add(translation);
                             }
                             break;
diff --git a/Service/HStation.Service.Revit.Core/04-service/01-json/model/RevitConnectListExtensions.cs b/Service/HStation.Service.Revit.Core/04-service/01-json/model/RevitConnectListExtensions.cs
index e877a9c..d8e6ddb 100644
--- a/Service/HStation.Service.Revit.Core/04-service/01-json/model/RevitConnectListExtensions.cs
+++ b/Service/HStation.Service.Revit.Core/04-service/01-json/model/RevitConnectListExtensions.cs
@@ -36,7 +36,7 @@
             var start = list.Find(x => x.Direction == Direction.Inlet);
             if (start == null)
             {
-                start = list.First();
+                start = list.Where(x => x.Direction == Direction.None).FirstOrDefault();
             }
             return start;
         }
@@ -70,7 +70,7 @@
             var end = list.Find(x => x.Direction == Direction.Outlet);
             if (end == null)
             {
-                end = list.Last();
+                end = list.Where(x => x.Direction == Direction.None).LastOrDefault();
             }
             return end;
         }
diff --git a/Service/HStation.Service.Revit.Core/04-service/01-json/model/RevitPositionExtensions.cs b/Service/HStation.Service.Revit.Core/04-service/01-json/model/RevitPositionExtensions.cs
new file mode 100644
index 0000000..8e0f4e0
--- /dev/null
+++ b/Service/HStation.Service.Revit.Core/04-service/01-json/model/RevitPositionExtensions.cs
@@ -0,0 +1,30 @@
+锘縰sing HStation.Model;
+
+namespace HStation.Service
+{
+    /// <summary>
+    /// Revit浣嶇疆鎷撳睍
+    /// </summary>
+    internal static class RevitPositionExtensions
+    {
+        /// <summary>
+        /// 璺濈
+        /// </summary>
+        /// <param name="rhs">鑷韩浣嶇疆</param>
+        /// <param name="other">鍏朵粬浣嶇疆</param>
+        /// <returns></returns>
+        public static double Distance(this RevitPosition rhs, RevitPosition other)
+        {
+            if (rhs == null)
+            {
+                return default;
+            }
+            if (other == null)
+            {
+                return default;
+            }
+            return Math.Sqrt(Math.Pow(rhs.X - other.X, 2) + Math.Pow(rhs.Y - other.Y, 2) + Math.Pow(rhs.Z - other.Z, 2));
+        }
+
+    }
+}
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 61eb6f5..dab1a35 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
@@ -176,7 +176,7 @@
                         startJunction.ModelType = null;
                         startJunction.Description = "鎹㈢儹鍣ㄤ慨姝f椂锛岃嚜鍔ㄦ坊鍔�";
                         startJunction.Quality = exchanger.StartQuality;
-                        startJunction.Position = exchanger.StartPosition;
+                        startJunction.Position = startConnectList.GetCenterPosition();
                         startJunction.Elev = exchanger.StartElev;
                         startJunction.Demand = null;
                         startJunction.DemandPattern = null;
@@ -187,7 +187,14 @@
                             var startConnectParter = allParterList.Find(x => x.Id == startConnect.Id);
                             if (startConnectParter is IRevitLink 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 +213,7 @@
                         endJunction.ModelType = null;
                         endJunction.Description = "鎹㈢儹鍣ㄤ慨姝f椂锛岃嚜鍔ㄦ坊鍔�";
                         endJunction.Quality = exchanger.EndQuality;
-                        endJunction.Position = exchanger.EndPosition;
+                        endJunction.Position = endConnectList.GetCenterPosition();
                         endJunction.Elev = exchanger.EndElev;
                         endJunction.Demand = null;
                         endJunction.DemandPattern = null;
@@ -217,7 +224,14 @@
                             var endConnectParter = allParterList.Find(x => x.Id == endConnect.Id);
                             if (endConnectParter is IRevitLink 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 +276,7 @@
             foreach (var link in allLinks)
             {
                 var startLinkParter = allParterList.Find(x => x.Code == link.StartCode);
-                if (startLinkParter is IRevitLink)
+                if (startLinkParter is IRevitLink startLink)
                 {
                     var junction = new Model.RevitJunction();
                     junction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Code).ToList());
@@ -278,12 +292,20 @@
                     junction.DemandPattern = null;
                     rhs.Junctions.Add(junction);
                     link.StartCode = junction.Code;
-                    (startLinkParter as IRevitLink).EndCode = junction.Code;
+
+                    if (startLink.StartCode == link.StartCode)
+                    {
+                        startLink.StartCode = junction.Code;
+                    }
+                    else if (startLink.EndCode == link.StartCode)
+                    {
+                        startLink.EndCode = junction.Code;
+                    }
                     allParterList.Add(junction);
                 }
 
                 var endLinkParter = allParterList.Find(x => x.Code == link.EndCode);
-                if (endLinkParter is IRevitLink)
+                if (endLinkParter is IRevitLink endLink)
                 {
                     var junction = new Model.RevitJunction();
                     junction.Id = Yw.Untity.UniqueHelper.CreateFromFirst("junction", allParterList.Select(x => x.Code).ToList());
@@ -299,7 +321,14 @@
                     junction.DemandPattern = null;
                     rhs.Junctions.Add(junction);
                     link.EndCode = junction.Code;
-                    (endLinkParter as IRevitLink).StartCode = junction.Code;
+                    if (endLink.StartCode == link.EndCode)
+                    {
+                        endLink.StartCode = junction.Code;
+                    }
+                    else if (endLink.EndCode == link.EndCode)
+                    {
+                        endLink.EndCode = junction.Code;
+                    }
                     allParterList.Add(junction);
                 }
             }
diff --git a/WinFrmUI/Yw.WinFrmUI.Hydro.Core/02-model/HydroModelMgrPage.cs b/WinFrmUI/Yw.WinFrmUI.Hydro.Core/02-model/HydroModelMgrPage.cs
index ffb31af..6766d1b 100644
--- a/WinFrmUI/Yw.WinFrmUI.Hydro.Core/02-model/HydroModelMgrPage.cs
+++ b/WinFrmUI/Yw.WinFrmUI.Hydro.Core/02-model/HydroModelMgrPage.cs
@@ -2,7 +2,6 @@
 using DevExpress.Utils.About;
 using DevExpress.XtraEditors;
 using Yw.EPAnet;
-using Yw.EPAnet.Calcu;
 using Yw.WinFrmUI.Page;
 
 namespace Yw.WinFrmUI
diff --git a/WinFrmUI/Yw.WinFrmUI.Hydro.Core/Yw.WinFrmUI.Hydro.Core.csproj b/WinFrmUI/Yw.WinFrmUI.Hydro.Core/Yw.WinFrmUI.Hydro.Core.csproj
index d29ef2e..8fc2818 100644
--- a/WinFrmUI/Yw.WinFrmUI.Hydro.Core/Yw.WinFrmUI.Hydro.Core.csproj
+++ b/WinFrmUI/Yw.WinFrmUI.Hydro.Core/Yw.WinFrmUI.Hydro.Core.csproj
@@ -10,7 +10,7 @@
   <ItemGroup>
     <PackageReference Include="DevExpress.Win.Design" Version="23.2.4" />
     <PackageReference Include="Yw.BLL.Basic.Core" Version="3.2.5" />
-    <PackageReference Include="Yw.BLL.Hydro.Core" Version="3.1.6" />
+    <PackageReference Include="Yw.BLL.Hydro.Core" Version="3.1.7" />
   </ItemGroup>
 
   <ItemGroup>

--
Gitblit v1.9.3