VerticalPipeUtil.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. //刷新界面
  46. WpfSysCmd.DoEvent();
  47. var pipes = pipes2.Where(t => t.OpenXyz.IsAlmostEqualTo(pipe.OpenXyz));
  48. if (pipes.Any())
  49. {
  50. pipe.TargetFileName = fileName;
  51. pipe.TargetPath = path;
  52. pipe.IsRight = true;
  53. string tip = isup ? "下" : "上";
  54. pipe.RMessage = $"在{tip}层相应位置到了对应的立管。Id:{pipes.FirstOrDefault().MepCurve.Id}";
  55. }
  56. else
  57. {
  58. pipe.TargetFileName = fileName;
  59. pipe.TargetPath = path;
  60. pipe.IsRight = false;
  61. string tip = isup ? "下" : "上";
  62. pipe.RMessage = $"在{tip}层相应位置找不到对应的立管,请检查模型";
  63. }
  64. }
  65. };
  66. check(upPipes, downPipes, downPath, true);
  67. check(downPipes, upPipes, upPath, false);
  68. List<VerticalPipe> results=new List<VerticalPipe>(upPipes);
  69. results.AddRange(downPipes);
  70. results.Sort(new CommonComparer<VerticalPipe>((x, y) => {return x.IsRight.CompareTo(y.IsRight); }));
  71. #region Save
  72. //重置workbook准备保存结果
  73. DCRExport.ClearWorkbook(DCRExport.VerticalPipePath);
  74. //保存
  75. ExportResult(results);
  76. DCRExport.Save(savePath, DCRExport.GetWorkbook());
  77. return new Tuple<int, int>(upPipes.Count,downPipes.Count);
  78. #endregion
  79. }
  80. catch (Exception e)
  81. {
  82. MessageShowBase.Show(e);
  83. }
  84. return null;
  85. }
  86. /// <summary>
  87. /// 获取所有的立管
  88. /// </summary>
  89. /// <param name="path"></param>
  90. /// <param n
  91. /// ame="isup"></param>
  92. /// <returns></returns>
  93. public static List<VerticalPipe> GetVerticalMEPCurves(string path,bool isup)
  94. {
  95. //刷新界面
  96. WpfSysCmd.DoEvent();
  97. var doc=RevitCore.App.OpenDocumentFile(path);
  98. //刷新界面
  99. WpfSysCmd.DoEvent();
  100. string fileName = path.GetFileName();
  101. var mepcurves = doc.GetElements<MEPCurve>();
  102. List<VerticalPipe> verticalPipes=new List<VerticalPipe>();
  103. foreach (MEPCurve mepCurve in mepcurves)
  104. {
  105. bool result = false;
  106. var curve = mepCurve.GetLocationCurve();
  107. if (curve is Line line)
  108. {
  109. if (line.Direction.IsParallel(XYZ.BasisZ))
  110. {
  111. var start = line.StartPoint();
  112. var end = line.EndPoint();
  113. XYZ point = null;
  114. if (isup)
  115. {
  116. point = start.Z.IsThan(end.Z) ? end : start;
  117. }
  118. else
  119. {
  120. point = start.Z.IsThan(end.Z) ? start : end;
  121. }
  122. Connector connector = mepCurve.GetNearConnector(point);
  123. if (!connector.IsConnected)
  124. {
  125. VerticalPipe verticalPipe=new VerticalPipe();
  126. verticalPipe.MepCurve = mepCurve;
  127. verticalPipe.OpenXyz = point;
  128. verticalPipe.Path = path;
  129. verticalPipe.FileName = fileName;
  130. verticalPipes.Add(verticalPipe);
  131. }
  132. //刷新界面
  133. WpfSysCmd.DoEvent();
  134. }
  135. }
  136. }
  137. return verticalPipes;
  138. }
  139. /// <summary>
  140. /// 检查结果汇总
  141. /// </summary>
  142. /// <param name="list"></param>
  143. /// <param name="context"></param>
  144. private static void ExportResult(List<VerticalPipe> list)
  145. {
  146. try
  147. {
  148. IWorkbook book = DCRExport.GetWorkbook();
  149. string sheetName = "立管对齐检查";
  150. ISheet sheet = book.GetSheet(sheetName);
  151. #region 添加数据
  152. int index = 3;
  153. //添加 共检查XXX条数据,未通过检查的如下 提示
  154. IRow rowTip = sheet.CreateRow(index - 1);
  155. //rowTip.AddCell(0, $"总检查{list.Count}条数据,未通过检查的如下", DataCheckNPOIStyle.Title);
  156. foreach (var result in list)
  157. {
  158. index++;
  159. IRow rowN = sheet.CreateRow(index);
  160. DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
  161. int j = -1;
  162. rowN.AddCell(++j, result.FileName, style);
  163. rowN.AddCell(++j, result.Path, style);
  164. rowN.AddCell(++j, result.MepCurve.Id.ToString(), style);
  165. rowN.AddCell(++j, result.MepCurve.GetSystemTypeName(), style);
  166. rowN.AddCell(++j, result.TargetFileName, style);
  167. rowN.AddCell(++j, result.TargetPath, style);
  168. string rowN4 = result.IsRight ? "通过" : "不通过";
  169. rowN.AddCell(++j, rowN4, style);
  170. rowN.AddCell(++j, result.RMessage, style);
  171. }
  172. #endregion
  173. }
  174. catch (Exception e)
  175. {
  176. MessageShowBase.Show(e);
  177. }
  178. }
  179. }
  180. class VerticalPipe
  181. {
  182. public MEPCurve MepCurve { get; set; }
  183. public XYZ OpenXyz { get; set; }
  184. public string Path { get; set; }
  185. public string FileName { get; set; }
  186. public string TargetPath { get; set; }
  187. public string TargetFileName { get; set; }
  188. /// <summary>
  189. /// 是否通过较验
  190. /// </summary>
  191. public bool IsRight { get; set; }
  192. /// <summary>
  193. /// 提示信息
  194. /// </summary>
  195. public string RMessage { get; set; }
  196. }
  197. }