PipeCheck.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. var tempSystem = mepCurve.GetSystemTypeName();
  95. if (tempSystem.IsNullOrEmpty()) continue;
  96. if (systemName != tempSystem)
  97. {
  98. errorCode = PipeCheckErrorCode.Code_002;
  99. break;
  100. }
  101. }
  102. } while (false);
  103. return errorCode;
  104. }
  105. /// <summary>
  106. /// 获取错误描述
  107. /// </summary>
  108. /// <param name="errorCode"></param>
  109. /// <returns></returns>
  110. private string GetErrorDescription(PipeCheckErrorCode errorCode)
  111. {
  112. string description = errorCode.GetDescription()+",请检查";
  113. return description;
  114. }
  115. /// <summary>
  116. /// 是否需要导出
  117. /// </summary>
  118. /// <param name="errorCode"></param>
  119. /// <returns></returns>
  120. private bool IsNeedExport(PipeCheckErrorCode errorCode)
  121. {
  122. return errorCode == PipeCheckErrorCode.Code_001 || errorCode == PipeCheckErrorCode.Code_002;
  123. }
  124. enum PipeCheckErrorCode
  125. {
  126. [Description("管段连接正确")]
  127. Code_000,
  128. [Description("末端未连接任何设备")]
  129. Code_001,
  130. [Description("管道两端连接了不同类型的管道")]
  131. Code_002,
  132. Code_003,
  133. [Description("误报")]
  134. Code_004
  135. }
  136. }
  137. }