PipeCheck.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* ==============================================================================
  2. * 功能描述:管网检查
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/6/11 16:09:09
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Linq;
  10. using Autodesk.Revit.DB;
  11. using SAGA.DotNetUtils.Extend;
  12. using SAGA.RevitUtils.Extends;
  13. using SAGA.RevitUtils.MEP;
  14. using ServiceRevitLib.Extend;
  15. using ServiceRevitLib.Mode;
  16. namespace ServiceRevitLib.DataCheck.Mode
  17. {
  18. /// <summary>
  19. /// SagaCheck
  20. /// </summary>
  21. class PipeCheck : CheckBase
  22. {
  23. public override void Check()
  24. {
  25. try
  26. {
  27. base.Check();
  28. #region
  29. var document = m_Doc;
  30. var elements = document.FilterElements<MEPCurve>().ToList();
  31. foreach (var element in elements)
  32. {
  33. if (element.IsStart())
  34. {
  35. //标记立管,所有连接点都未记录则删除
  36. //if (!connectors.Any(c => c.IsConnected))
  37. //{
  38. // item.ErrorCode = "001";
  39. // reportItem.ResultItems.Add(item);
  40. //}
  41. continue;
  42. }
  43. var item = new PipeCheckResult();
  44. item.SystemName = element.GetSystemTypeName();
  45. item.Id = element.Id.ToString();
  46. var code = GetErrorCode(element, item.SystemName);
  47. if (IsNeedExport(code))
  48. {
  49. item.Result = ResultState.Failure;
  50. item.ResultMsg = GetErrorDescription(code);
  51. Content.Add(item);
  52. }
  53. }
  54. #endregion
  55. }
  56. catch (Exception e)
  57. {
  58. Result = ResultState.Failure;
  59. ResultMsg = $"{e.Message}\r\n{e.StackTrace}";
  60. }
  61. }
  62. /// <summary>
  63. /// 获取错误码
  64. /// </summary>
  65. /// <param name="element"></param>
  66. /// <param name="systemName"></param>
  67. /// <returns></returns>
  68. private PipeCheckErrorCode GetErrorCode(Element element,string systemName)
  69. {
  70. PipeCheckErrorCode errorCode = PipeCheckErrorCode.Code_000;
  71. Domain[] domains = new Domain[] { Domain.DomainPiping, Domain.DomainHvac };
  72. do
  73. {
  74. foreach (Domain domain in domains)
  75. {
  76. var connectors = element.GetConnectors(domain);
  77. if (connectors.Any(c => !c.IsConnected))
  78. {
  79. errorCode = PipeCheckErrorCode.Code_001;
  80. }
  81. }
  82. if (errorCode == PipeCheckErrorCode.Code_001 && element.GetLocationCurve() is Line line)
  83. {
  84. //一端不连接的立管不导出
  85. if (line.Direction.IsParallel(XYZ.BasisZ))
  86. {
  87. errorCode = PipeCheckErrorCode.Code_003;
  88. }
  89. }
  90. var endElements = element.GetFirstElements(null, e => e is MEPCurve || e.IsEquipment());
  91. List<MEPCurve> curves = endElements.OfType<MEPCurve>().ToList();
  92. foreach (var mepCurve in curves)
  93. {
  94. if (systemName != mepCurve.GetSystemTypeName())
  95. {
  96. errorCode = PipeCheckErrorCode.Code_002;
  97. break;
  98. }
  99. }
  100. } while (false);
  101. return errorCode;
  102. }
  103. /// <summary>
  104. /// 获取错误描述
  105. /// </summary>
  106. /// <param name="errorCode"></param>
  107. /// <returns></returns>
  108. private string GetErrorDescription(PipeCheckErrorCode errorCode)
  109. {
  110. string description = errorCode.GetDescription()+",请检查";
  111. return description;
  112. }
  113. /// <summary>
  114. /// 是否需要导出
  115. /// </summary>
  116. /// <param name="errorCode"></param>
  117. /// <returns></returns>
  118. private bool IsNeedExport(PipeCheckErrorCode errorCode)
  119. {
  120. return errorCode == PipeCheckErrorCode.Code_001 || errorCode == PipeCheckErrorCode.Code_002;
  121. }
  122. enum PipeCheckErrorCode
  123. {
  124. [Description("管段连接正确")]
  125. Code_000,
  126. [Description("末端未连接任何设备")]
  127. Code_001,
  128. [Description("管道两端连接了不同类型的管道")]
  129. Code_002,
  130. Code_003,
  131. [Description("误报")]
  132. Code_004
  133. }
  134. }
  135. }