From 57afe56c77abcde9a94c0c30ebf1af4325b837cf Mon Sep 17 00:00:00 2001 From: Zhuangkh Date: Wed, 4 Sep 2024 17:44:01 +0800 Subject: [PATCH] yyf update --- uBIMEarthTools/Commands/DWGDataExport.cs | 85 ++++++++++++++++++------ uBIMEarthTools/MethodTimeLogger.cs | 2 +- uBIMEarthTools/Utils/Common.cs | 31 +++++++-- 3 files changed, 90 insertions(+), 28 deletions(-) diff --git a/uBIMEarthTools/Commands/DWGDataExport.cs b/uBIMEarthTools/Commands/DWGDataExport.cs index 1aba829..71abdb6 100644 --- a/uBIMEarthTools/Commands/DWGDataExport.cs +++ b/uBIMEarthTools/Commands/DWGDataExport.cs @@ -86,9 +86,10 @@ namespace uBIMEarthTools.Commands if (transGroup.Start() == TransactionStatus.Started) { Transaction transaction = new Transaction(doc, "uBIM"); + transaction.Start(); int k = 0; - while (true) + while (k<1000) { #region 临时变量 XYZ origin_k = pointFirstTable_L + new XYZ(k * (pointSecTable.X - pointFirstTable_L.X), 0, 0);//当前图框左上角坐标 @@ -100,7 +101,7 @@ namespace uBIMEarthTools.Commands #region 获取当前图框里的textnote foreach (TextNote tntmp in textnoteList) - { + { if (tntmp.Coord.X > origin_k.X && tntmp.Coord.X < origin_k.X + (pointFirstTable_R.X - pointFirstTable_L.X) && tntmp.Coord.Y > origin_k.Y - (pointFirstTable_L.Y - pointFirstTable_R.Y) && tntmp.Coord.Y < origin_k.Y) { @@ -120,15 +121,24 @@ namespace uBIMEarthTools.Commands textnoteKList.Add(tntmp); } } + + foreach (TextNote tntmp in textnoteKList) + { + tntmp.Text = tntmp.Text.Replace("X=", "").Replace("Y=", "").Replace("m", "").Trim(); + } + + if (textnoteKList.Count == 0) //获取不到时,跳出 + { break; + } #endregion #region 获取当前图框编号,标高,X,Y - TextNote zkbhTn = Common.Textnote_At_Point(new XYZ(origin_k.X + pointNum.X - pointFirstTable_L.X, pointNum.Y, pointNum.Z), textnoteKList, 4); //钻孔编号 - TextNote kkbgTn = Common.Textnote_At_Point(new XYZ(origin_k.X + pointLevel.X - pointFirstTable_L.X, pointLevel.Y, pointLevel.Z), textnoteKList, 4); //孔口标高 - TextNote xTn = Common.Textnote_At_Point(new XYZ(origin_k.X + pointX.X - pointFirstTable_L.X, pointX.Y, pointX.Z), textnoteKList, 4); //孔口X - TextNote yTn = Common.Textnote_At_Point(new XYZ(origin_k.X + pointY.X - pointFirstTable_L.X, pointY.Y, pointY.Z), textnoteKList, 4); //孔口Y + TextNote zkbhTn = Common.Textnote_At_Point(new XYZ(origin_k.X + pointNum.X - pointFirstTable_L.X, pointNum.Y, pointNum.Z), textnoteKList, 100); //钻孔编号 + TextNote kkbgTn = Common.Textnote_At_Point(new XYZ(origin_k.X + pointLevel.X - pointFirstTable_L.X, pointLevel.Y, pointLevel.Z), textnoteKList, 100); //孔口标高 + TextNote xTn = Common.Textnote_At_Point(new XYZ(origin_k.X + pointX.X - pointFirstTable_L.X, pointX.Y, pointX.Z), textnoteKList, 100); //孔口X + TextNote yTn = Common.Textnote_At_Point(new XYZ(origin_k.X + pointY.X - pointFirstTable_L.X, pointY.Y, pointY.Z), textnoteKList, 100); //孔口Y //钻孔编号跟孔口标高不对应时,跳至下个图框 if (zkbhTn == null || kkbgTn == null) @@ -142,6 +152,8 @@ namespace uBIMEarthTools.Commands #region 归并地层编号中类似3-1的文字(当前条件:X公差:4mm;Y公差:2mm;字高公差:null) foreach (TextNote tntmp1 in textnoteKList) { + tntmp1.Text = Common.NameByRule(tntmp1.Text); + if (tntmp1.Coord.X > origin_k.X + pointLayer_R.X - pointFirstTable_L.X)//排除超出范围的 continue; if (delTextnoteList.Contains(tntmp1))//排除已剔除的 @@ -150,6 +162,8 @@ namespace uBIMEarthTools.Commands continue; foreach (TextNote tntmp2 in textnoteKList) { + tntmp2.Text = Common.NameByRule(tntmp2.Text); + if (delTextnoteList.Contains(tntmp2))//排除已剔除的 continue; if (tntmp2.Coord.X > origin_k.X + pointLayer_R.X - pointFirstTable_L.X)//排除超出范围的 @@ -163,18 +177,20 @@ namespace uBIMEarthTools.Commands if (Math.Abs(tntmp1.Coord.X - tntmp2.Coord.X) < 4 / 304.8 && Math.Abs(tntmp1.Coord.Y - tntmp2.Coord.Y) < 2 / 304.8)// &&Math.Abs(tntmp1.Height - tntmp2.Height) > 0.00001 / 304.8) { - transaction.Start(); + //transaction.Start(); if (tntmp1.Coord.X < tntmp2.Coord.X) { - tntmp1.Text = tntmp1.Text + "-" + tntmp2.Text; + string s = tntmp1.Text.Trim() + "-" + tntmp2.Text.Trim(); + tntmp1.Text = Common.NameByRule(s); delTextnoteList.Add(tntmp2); } else { - tntmp2.Text = tntmp2.Text + "-" + tntmp1.Text; + string s = tntmp2.Text.Trim() + "-" + tntmp1.Text.Trim(); + tntmp2.Text = Common.NameByRule(s); delTextnoteList.Add(tntmp1); } - transaction.Commit(); + //transaction.Commit(); } } } @@ -199,7 +215,7 @@ namespace uBIMEarthTools.Commands dcgcList = dcgcList.OrderByDescending(x => x.Coord.Y).ToList(); #endregion - #region 寻找已有钻孔列表中有没有相同编号,没有时新建钻孔 + #region 寻找已有钻孔列表中有没有相同编号,没有时新建钻孔 Borehole bh; if (boreholes.Count != 0 && boreholes.Select(x => x.Name).ToList().Contains(zkbhTn.Text)) { @@ -208,6 +224,22 @@ namespace uBIMEarthTools.Commands else { bh = new Borehole { Name = zkbhTn.Text }; + double xxx = 0; + double yyy = 0; + double zzz = 0; + try + { + xxx = Convert.ToDouble(xTn.Text); + yyy = Convert.ToDouble(yTn.Text); + zzz = Convert.ToDouble(kkbgTn.Text); + } + catch + { + k++; + MessageBox.Show(k+ "\n" +xTn.Text + "\n" + yTn.Text + "\n" + kkbgTn.Text, "向日葵", MessageBoxButtons.OK); + continue; + } + bh.ValueList.Add(new GeologyLayer(dcbhList.First().Text, new XYZ(Convert.ToDouble(xTn.Text), Convert.ToDouble(yTn.Text), Convert.ToDouble(kkbgTn.Text)))); boreholes.Add(bh); } @@ -216,18 +248,31 @@ namespace uBIMEarthTools.Commands #region 导出对应的钻孔地层数据 for (int i = 0; i < (dcbhList.Count < dcgcList.Count ? dcbhList.Count : dcgcList.Count); i++) { - string dcbh_i = dcbhList[i].Text.Replace("\r", "").Replace("\n", ""); - string dcmc_i = dcgcList[i].Text.Replace("\r", "").Replace("\n", ""); - double x = Convert.ToDouble(xTn.Text); - double y = Convert.ToDouble(yTn.Text); - double z = Convert.ToDouble(dcmc_i); - GeologyLayer geologyLayer = new GeologyLayer(dcbh_i, new XYZ(x, y, z)); - bh.ValueList.Add(geologyLayer); + string dcmc_i = "default"; + string dcbh_i = "default"; + //MessageBox.Show(xTn.Text + "\n" + yTn.Text + "\n" + dcbh_i + "\n" + dcmc_i, "向日葵", MessageBoxButtons.OK); + + try + { + dcbh_i = dcbhList[i].Text.Trim(); + dcmc_i = dcgcList[i].Text.Trim(); + double x = Convert.ToDouble(xTn.Text); + double y = Convert.ToDouble(yTn.Text); + double z = Convert.ToDouble(dcmc_i); + GeologyLayer geologyLayer = new GeologyLayer(dcbh_i, new XYZ(x, y, z)); + bh.ValueList.Add(geologyLayer); + } + catch (Exception ex) + { + //MessageBox.Show(ex.Message, "向日葵", MessageBoxButtons.OK); + } } #endregion k++; } + + transaction.Commit(); } status = transGroup.RollBack(); #endregion @@ -241,7 +286,7 @@ namespace uBIMEarthTools.Commands ExcelPackage.LicenseContext = LicenseContext.NonCommercial; FileInfo fileInfo = new FileInfo(localFilePath); - using (ExcelPackage excelPackage = new ExcelPackage(fileInfo)) + using (ExcelPackage excelPackage = new ExcelPackage()) { //using (FileStream fs = new FileStream(localFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) //{ @@ -281,7 +326,7 @@ namespace uBIMEarthTools.Commands } } - excelPackage.Save(); + excelPackage.SaveAs(fileInfo); //} //File.WriteAllBytes(localFilePath, excelPackage.GetAsByteArray()); } diff --git a/uBIMEarthTools/MethodTimeLogger.cs b/uBIMEarthTools/MethodTimeLogger.cs index bee7791..e6d428d 100644 --- a/uBIMEarthTools/MethodTimeLogger.cs +++ b/uBIMEarthTools/MethodTimeLogger.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.Reflection; -[assembly: MethodTimer.Time] +//[assembly: MethodTimer.Time] namespace uBIMEarthTools { public static class MethodTimeLogger diff --git a/uBIMEarthTools/Utils/Common.cs b/uBIMEarthTools/Utils/Common.cs index f74e59b..18a10ba 100644 --- a/uBIMEarthTools/Utils/Common.cs +++ b/uBIMEarthTools/Utils/Common.cs @@ -243,13 +243,23 @@ namespace uBIMEarthTools.Utils { TextNote tn = null; XYZ newXyz = new XYZ(p.X, p.Y, textnoteList[0].Coord.Z); - foreach (TextNote tntmp in textnoteList) - { - if (Math.Round(tntmp.Coord.DistanceTo(newXyz), 5) < (tolerance / 304.8)) - { - tn = tntmp; - } - } + List lines = new List(); + + textnoteList = textnoteList.FindAll(m => m.Text != "X =" && m.Text != "Y =").ToList(); + TextNote tntmp = textnoteList.OrderBy(m => m.Coord.DistanceTo(newXyz)).First(); + if (Math.Round(tntmp.Coord.DistanceTo(newXyz), 5) < (tolerance / 304.8)) + tn = tntmp; + + //foreach (TextNote tntmp in textnoteList) + //{ + // string text = tntmp.Text; + // if (text == "X=" || text == "Y=") + // continue; + // if (Math.Round(tntmp.Coord.DistanceTo(newXyz), 5) < (tolerance / 304.8)) + // { + // tn = tntmp; + // } + //} return tn; } public static void Swap(ref T x, ref T y) @@ -258,5 +268,12 @@ namespace uBIMEarthTools.Utils x = y; y = temp; } + + public static string NameByRule(string s) + { + //①②③④⑤⑥⑦⑧⑨ + string ss = s.Replace("--", "-").Replace("①","1").Replace("②", "2").Replace("③", "3").Replace("④", "4").Replace("⑤", "5").Replace("⑥", "6").Replace("⑦", "7").Replace("⑧", "8").Replace("⑨", "9"); + return ss; + } } }