ConnectorCheck.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* ==============================================================================
  2. * 功能描述:SagaCheck
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/6/11 16:09:09
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using Autodesk.Revit.DB;
  10. using SAGA.DotNetUtils.Extend;
  11. using SAGA.RevitUtils.MEP;
  12. using ServiceRevitLib.Extend;
  13. using ServiceRevitLib.Mode;
  14. using ServiceRevitLib.Utils;
  15. namespace ServiceRevitLib.DataCheck.Mode
  16. {
  17. /// <summary>
  18. /// SagaCheck
  19. /// </summary>
  20. class ConnectorCheck : CheckBase
  21. {
  22. public ConnectorCheck()
  23. {
  24. ReferenceSheet = "参考-连接件对照表";
  25. }
  26. public override void Check()
  27. {
  28. try
  29. {
  30. base.Check();
  31. #region
  32. bool unitResult = true;
  33. m_ProDefineConnectors = GetPreDefineConnectors();
  34. var elements = m_Doc.GetEqEcElements();
  35. foreach (var element in elements)
  36. {
  37. //检查设备或者部件
  38. var result = GetCheckResult(element);
  39. if (result == null) continue;
  40. Content.Add(result);
  41. }
  42. #endregion
  43. }
  44. catch (Exception e)
  45. {
  46. Result = ResultState.Failure;
  47. ResultMsg = $"{e.Message}\r\n{e.StackTrace}";
  48. }
  49. }
  50. private string m_HaveConnectorSing = "√";
  51. private List<DCR_Connector> m_ProDefineConnectors;
  52. public List<DCR_Connector> GetPreDefineConnectors()
  53. {
  54. var list = new List<DCR_Connector>();
  55. var alllist = DataCheckRule.GetPreDefineConnectors();
  56. foreach (DCR_Connector connector in alllist)
  57. {
  58. var pipeType = connector.PipeConnector;
  59. var hvacType = connector.HvacConnector;
  60. if (pipeType == m_HaveConnectorSing || hvacType == m_HaveConnectorSing)
  61. {
  62. list.Add(connector);
  63. if (connector.PName.IsNotNullEmpty() && connector.PCode.IsNotNullEmpty())
  64. {
  65. //部件单独提出来当做一项
  66. var pconnector = new DCR_Connector()
  67. {
  68. Code = connector.PCode,
  69. Name = connector.Name,
  70. PipeConnector = connector.PipeConnector,
  71. HvacConnector = connector.HvacConnector
  72. };
  73. list.Add(pconnector);
  74. }
  75. }
  76. }
  77. return list;
  78. }
  79. /// <summary>
  80. /// 获取检测结果
  81. /// </summary>
  82. /// <param name="fi"></param>
  83. /// <returns></returns>
  84. private ConnectorCheckResult GetCheckResult(Element element)
  85. {
  86. if (element == null) return null;
  87. var result = new ConnectorCheckResult();
  88. var code = element.GetFamilyCode();
  89. var defineConType = GetDefineConType(code);
  90. if (defineConType == null) return null;
  91. var type= code.Length == 4 ? ElementRangeCheck.DCElementType.Equipment : ElementRangeCheck.DCElementType.EuipmentPart;
  92. result.Type = type.GetDescription();
  93. result.FamilyName = element.GetFamilyName();
  94. result.Id = element.Id.ToString();
  95. result.Result = ResultState.Success;
  96. CheckConType(result, element, defineConType.Item1);
  97. CheckConType(result, element, defineConType.Item2);
  98. return result;
  99. }
  100. /// <summary>
  101. /// 获取定义的风和水连接件类型
  102. /// </summary>
  103. /// <param name="code"></param>
  104. /// <returns></returns>
  105. private Tuple<Domain, Domain> GetDefineConType(string code)
  106. {
  107. var item = m_ProDefineConnectors.FirstOrDefault(t => t.Code == code);
  108. if (item == null) return null;
  109. var pipeType = item.PipeConnector;
  110. var hvacType = item.HvacConnector;
  111. var pipeConType = pipeType == m_HaveConnectorSing ? Domain.DomainPiping : Domain.DomainUndefined;
  112. var hvacConType = hvacType == m_HaveConnectorSing ? Domain.DomainHvac : Domain.DomainUndefined;
  113. return new Tuple<Domain, Domain>(pipeConType, hvacConType);
  114. }
  115. /// <summary>
  116. /// 检查连接件类型是否存在
  117. /// </summary>
  118. /// <param name="result"></param>
  119. /// <param name="domain"></param>
  120. private void CheckConType(ConnectorCheckResult result, Element fi, Domain domain)
  121. {
  122. if (domain != Domain.DomainUndefined)
  123. {
  124. var connectors = fi.GetConnectors(domain);
  125. var domainStr = DomainToString(domain);
  126. if (connectors.Any())
  127. {
  128. if (connectors.All(t => t.IsConnected)) return;
  129. result.Result = ResultState.Failure;
  130. result.ResultMsg += $"发现 {domainStr}连接件未连接;";
  131. }
  132. else
  133. {
  134. result.Result = ResultState.Failure;
  135. result.ResultMsg += $"缺少 {domainStr} 连接件;";
  136. }
  137. }
  138. }
  139. private string DomainToString(Domain domain)
  140. {
  141. string str = "";
  142. switch (domain)
  143. {
  144. case Domain.DomainPiping:
  145. str = "水管";
  146. break;
  147. case Domain.DomainHvac:
  148. str = "风管";
  149. break;
  150. default:
  151. str = "未知";
  152. break;
  153. }
  154. return str;
  155. }
  156. }
  157. }