VerticalPipeUtil.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* ==============================================================================
  2. * 功能描述:VerticalPipeUtil
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/11/5 15:35:20
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using Autodesk.Revit.DB;
  12. using FWindSoft.Revit;
  13. using FWindSoft.Wpf;
  14. using NPOI.SS.UserModel;
  15. using Saga.PlugIn.ModelCheck;
  16. using SAGA.DotNetUtils;
  17. using SAGA.DotNetUtils.Extend;
  18. using SAGA.DotNetUtils.Others;
  19. using SAGA.RevitUtils.MEP;
  20. namespace Saga.PlugIn.VerticalPipeCheck
  21. {
  22. /// <summary>
  23. /// VerticalPipeUtil
  24. /// </summary>
  25. class VerticalPipeUtil
  26. {
  27. /// <summary>
  28. /// 执行立管检查
  29. /// </summary>
  30. /// <param name="upPath"></param>
  31. /// <param name="downPath"></param>
  32. /// <param name="savePath"></param>
  33. /// <returns></returns>
  34. public static Tuple<int,int> Execute(string upPath,string downPath,string savePath)
  35. {
  36. try
  37. {
  38. var upPipes = GetVerticalMEPCurves(upPath,true);
  39. var downPipes = GetVerticalMEPCurves(downPath, false);
  40. Action<List<VerticalPipe>, List<VerticalPipe>, string, bool> check = (pipes1, pipes2, path, isup) =>
  41. {
  42. string fileName = path.GetFileName();
  43. foreach (VerticalPipe pipe in pipes1)
  44. {
  45. var pipes = pipes2.Where(t => t.OpenXyz.IsAlmostEqualTo(pipe.OpenXyz));
  46. if (pipes.Any())
  47. {
  48. pipe.TargetFileName = fileName;
  49. pipe.TargetPath = path;
  50. pipe.IsRight = true;
  51. string tip = isup ? "下" : "上";
  52. pipe.RMessage = $"在{tip}层相应位置到了对应的立管。Id:{pipes.FirstOrDefault().MepCurve.Id}";
  53. }
  54. else
  55. {
  56. pipe.TargetFileName = fileName;
  57. pipe.TargetPath = path;
  58. pipe.IsRight = false;
  59. string tip = isup ? "下" : "上";
  60. pipe.RMessage = $"在{tip}层相应位置找不到对应的立管,请检查模型";
  61. }
  62. }
  63. };
  64. check(upPipes, downPipes, downPath, true);
  65. check(downPipes, upPipes, upPath, false);
  66. List<VerticalPipe> results=new List<VerticalPipe>(upPipes);
  67. results.AddRange(downPipes);
  68. results.Sort(new CommonComparer<VerticalPipe>((x, y) => {return x.IsRight.CompareTo(y.IsRight); }));
  69. #region Save
  70. //重置workbook准备保存结果
  71. DCRExport.ClearWorkbook(DCRExport.VerticalPipePath);
  72. //保存
  73. ExportResult(results);
  74. DCRExport.Save(savePath, DCRExport.GetWorkbook());
  75. return new Tuple<int, int>(upPipes.Count,downPipes.Count);
  76. #endregion
  77. }
  78. catch (Exception e)
  79. {
  80. MessageShowBase.Show(e);
  81. }
  82. return null;
  83. }
  84. /// <summary>
  85. /// 获取所有的立管
  86. /// </summary>
  87. /// <param name="path"></param>
  88. /// <param n
  89. /// ame="isup"></param>
  90. /// <returns></returns>
  91. public static List<VerticalPipe> GetVerticalMEPCurves(string path,bool isup)
  92. {
  93. var doc=RevitCore.App.OpenDocumentFile(path);
  94. string fileName = path.GetFileName();
  95. var mepcurves = doc.GetElements<MEPCurve>();
  96. List<VerticalPipe> verticalPipes=new List<VerticalPipe>();
  97. foreach (MEPCurve mepCurve in mepcurves)
  98. {
  99. bool result = false;
  100. var curve = mepCurve.GetLocationCurve();
  101. if (curve is Line line)
  102. {
  103. if (line.Direction.IsParallel(XYZ.BasisZ))
  104. {
  105. var start = line.StartPoint();
  106. var end = line.EndPoint();
  107. XYZ point = null;
  108. if (isup)
  109. {
  110. point = start.Z.IsThan(end.Z) ? end : start;
  111. }
  112. else
  113. {
  114. point = start.Z.IsThan(end.Z) ? start : end;
  115. }
  116. Connector connector = mepCurve.GetNearConnector(point);
  117. if (connector!=null&&!connector.IsConnected)
  118. {
  119. VerticalPipe verticalPipe=new VerticalPipe();
  120. verticalPipe.MepCurve = mepCurve;
  121. verticalPipe.OpenXyz = point;
  122. verticalPipe.Path = path;
  123. verticalPipe.FileName = fileName;
  124. verticalPipes.Add(verticalPipe);
  125. }
  126. }
  127. }
  128. }
  129. return verticalPipes;
  130. }
  131. /// <summary>
  132. /// 检查结果汇总
  133. /// </summary>
  134. /// <param name="list"></param>
  135. /// <param name="context"></param>
  136. private static void ExportResult(List<VerticalPipe> list)
  137. {
  138. try
  139. {
  140. IWorkbook book = DCRExport.GetWorkbook();
  141. string sheetName = "立管对齐检查";
  142. ISheet sheet = book.GetSheet(sheetName);
  143. #region 添加数据
  144. int index = 3;
  145. //添加 共检查XXX条数据,未通过检查的如下 提示
  146. IRow rowTip = sheet.CreateRow(index - 1);
  147. //rowTip.AddCell(0, $"总检查{list.Count}条数据,未通过检查的如下", DataCheckNPOIStyle.Title);
  148. foreach (var result in list)
  149. {
  150. index++;
  151. IRow rowN = sheet.CreateRow(index);
  152. DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
  153. int j = -1;
  154. rowN.AddCell(++j, result.FileName, style);
  155. rowN.AddCell(++j, result.Path, style);
  156. rowN.AddCell(++j, result.MepCurve.Id.ToString(), style);
  157. rowN.AddCell(++j, result.MepCurve.GetSystemTypeName(), style);
  158. rowN.AddCell(++j, result.TargetFileName, style);
  159. rowN.AddCell(++j, result.TargetPath, style);
  160. string rowN4 = result.IsRight ? "通过" : "不通过";
  161. rowN.AddCell(++j, rowN4, style);
  162. rowN.AddCell(++j, result.RMessage, style);
  163. }
  164. #endregion
  165. }
  166. catch (Exception e)
  167. {
  168. MessageShowBase.Show(e);
  169. }
  170. }
  171. }
  172. class VerticalPipe
  173. {
  174. public MEPCurve MepCurve { get; set; }
  175. public XYZ OpenXyz { get; set; }
  176. public string Path { get; set; }
  177. public string FileName { get; set; }
  178. public string TargetPath { get; set; }
  179. public string TargetFileName { get; set; }
  180. /// <summary>
  181. /// 是否通过较验
  182. /// </summary>
  183. public bool IsRight { get; set; }
  184. /// <summary>
  185. /// 提示信息
  186. /// </summary>
  187. public string RMessage { get; set; }
  188. }
  189. }