PipeCheck.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. // 如果为软管,则不导出。软管的系统名称为空
  45. var tempSystem = element.GetSystemTypeName();
  46. if (tempSystem.IsNullOrEmpty()) continue;
  47. item.SystemName = tempSystem;
  48. item.Id = element.Id.ToString();
  49. var code = GetErrorCode(element, item.SystemName);
  50. if (IsNeedExport(code))
  51. {
  52. item.Result = ResultState.Failure;
  53. item.ResultMsg = GetErrorDescription(code);
  54. Content.Add(item);
  55. }
  56. }
  57. #endregion
  58. }
  59. catch (Exception e)
  60. {
  61. Result = ResultState.Failure;
  62. ResultMsg = $"{e.Message}\r\n{e.StackTrace}";
  63. }
  64. }
  65. /// <summary>
  66. /// 获取错误码
  67. /// </summary>
  68. /// <param name="element"></param>
  69. /// <param name="systemName"></param>
  70. /// <returns></returns>
  71. private PipeCheckErrorCode GetErrorCode(Element element,string systemName)
  72. {
  73. PipeCheckErrorCode errorCode = PipeCheckErrorCode.Code_000;
  74. Domain[] domains = new Domain[] { Domain.DomainPiping, Domain.DomainHvac };
  75. do
  76. {
  77. foreach (Domain domain in domains)
  78. {
  79. var connectors = element.GetConnectors(domain);
  80. if (connectors.Any(c => !c.IsConnected))
  81. {
  82. errorCode = PipeCheckErrorCode.Code_001;
  83. }
  84. }
  85. if (errorCode == PipeCheckErrorCode.Code_001 && element.GetLocationCurve() is Line line)
  86. {
  87. //一端不连接的立管不导出
  88. if (line.Direction.IsParallel(XYZ.BasisZ))
  89. {
  90. errorCode = PipeCheckErrorCode.Code_003;
  91. }
  92. }
  93. var endElements = element.GetFirstElements(null, e => e is MEPCurve || e.IsEquipment());
  94. List<MEPCurve> curves = endElements.OfType<MEPCurve>().ToList();
  95. foreach (var mepCurve in curves)
  96. {
  97. var tempSystem = mepCurve.GetSystemTypeName();
  98. if (tempSystem.IsNullOrEmpty()) continue;
  99. if (systemName != tempSystem)
  100. {
  101. errorCode = PipeCheckErrorCode.Code_002;
  102. break;
  103. }
  104. }
  105. } while (false);
  106. return errorCode;
  107. }
  108. /// <summary>
  109. /// 获取错误描述
  110. /// </summary>
  111. /// <param name="errorCode"></param>
  112. /// <returns></returns>
  113. private string GetErrorDescription(PipeCheckErrorCode errorCode)
  114. {
  115. string description = errorCode.GetDescription()+",请检查";
  116. return description;
  117. }
  118. /// <summary>
  119. /// 是否需要导出
  120. /// </summary>
  121. /// <param name="errorCode"></param>
  122. /// <returns></returns>
  123. private bool IsNeedExport(PipeCheckErrorCode errorCode)
  124. {
  125. return errorCode == PipeCheckErrorCode.Code_001 || errorCode == PipeCheckErrorCode.Code_002;
  126. }
  127. enum PipeCheckErrorCode
  128. {
  129. [Description("管段连接正确")]
  130. Code_000,
  131. [Description("末端未连接任何设备")]
  132. Code_001,
  133. [Description("管道两端连接了不同类型的管道")]
  134. Code_002,
  135. Code_003,
  136. [Description("误报")]
  137. Code_004
  138. }
  139. }
  140. }