ConnectorCheck.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 System.Text.RegularExpressions;
  10. using Autodesk.Revit.DB;
  11. using SAGA.DotNetUtils.Extend;
  12. using ServiceRevitLib.Common;
  13. using SAGA.RevitUtils.Extends;
  14. using SAGA.RevitUtils.MEP;
  15. using ServiceRevitLib.Extend;
  16. using ServiceRevitLib.Utils;
  17. namespace ServiceRevitLib.Mode
  18. {
  19. /// <summary>
  20. /// SagaCheck
  21. /// </summary>
  22. class ConnectorCheck : CheckBase
  23. {
  24. public ConnectorCheck()
  25. {
  26. ReferenceSheet = "参考-连接件对照表";
  27. }
  28. public override void Check()
  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. private string m_HaveConnectorSing = "√";
  45. private List<DCR_Connector> m_ProDefineConnectors;
  46. public List<DCR_Connector> GetPreDefineConnectors()
  47. {
  48. var list = new List<DCR_Connector>();
  49. var alllist = DataCheckRule.GetPreDefineConnectors();
  50. foreach (DCR_Connector connector in alllist)
  51. {
  52. var pipeType = connector.PipeConnector;
  53. var hvacType = connector.HvacConnector;
  54. if (pipeType == m_HaveConnectorSing || hvacType == m_HaveConnectorSing)
  55. {
  56. list.Add(connector);
  57. if (connector.PName.IsNotNullEmpty() && connector.PCode.IsNotNullEmpty())
  58. {
  59. //部件单独提出来当做一项
  60. var pconnector = new DCR_Connector()
  61. {
  62. Code = connector.PCode,
  63. Name = connector.Name,
  64. PipeConnector = connector.PipeConnector,
  65. HvacConnector = connector.HvacConnector
  66. };
  67. list.Add(pconnector);
  68. }
  69. }
  70. }
  71. return list;
  72. }
  73. /// <summary>
  74. /// 获取检测结果
  75. /// </summary>
  76. /// <param name="fi"></param>
  77. /// <returns></returns>
  78. private ConnectorCheckResult GetCheckResult(Element element)
  79. {
  80. if (element == null) return null;
  81. var result = new ConnectorCheckResult();
  82. var code = element.GetFamilyCode();
  83. var defineConType = GetDefineConType(code);
  84. if (defineConType == null) return null;
  85. result.FamilyName = element.GetFamilyName();
  86. result.Id = element.Id.ToString();
  87. result.Result = ResultState.Success;
  88. CheckConType(result, element, defineConType.Item1);
  89. CheckConType(result, element, defineConType.Item2);
  90. return result;
  91. }
  92. /// <summary>
  93. /// 获取定义的风和水连接件类型
  94. /// </summary>
  95. /// <param name="code"></param>
  96. /// <returns></returns>
  97. private Tuple<Domain, Domain> GetDefineConType(string code)
  98. {
  99. var item = m_ProDefineConnectors.FirstOrDefault(t => t.Code == code);
  100. if (item == null) return null;
  101. var pipeType = item.PipeConnector;
  102. var hvacType = item.HvacConnector;
  103. var pipeConType = pipeType == m_HaveConnectorSing ? Domain.DomainPiping : Domain.DomainUndefined;
  104. var hvacConType = hvacType == m_HaveConnectorSing ? Domain.DomainHvac : Domain.DomainUndefined;
  105. return new Tuple<Domain, Domain>(pipeConType, hvacConType);
  106. }
  107. /// <summary>
  108. /// 检查连接件类型是否存在
  109. /// </summary>
  110. /// <param name="result"></param>
  111. /// <param name="domain"></param>
  112. private void CheckConType(ConnectorCheckResult result, Element fi, Domain domain)
  113. {
  114. if (domain != Domain.DomainUndefined)
  115. {
  116. var connectors = fi.GetConnectors(domain);
  117. var domainStr = DomainToString(domain);
  118. if (connectors.Any())
  119. {
  120. if (connectors.All(t => t.IsConnected)) return;
  121. result.Result = ResultState.Failure;
  122. result.ResultMsg += $"发现 {domainStr}连接件未连接;";
  123. }
  124. else
  125. {
  126. result.Result = ResultState.Failure;
  127. result.ResultMsg += $"缺少 {domainStr} 连接件;";
  128. }
  129. }
  130. }
  131. private string DomainToString(Domain domain)
  132. {
  133. string str = "";
  134. switch (domain)
  135. {
  136. case Domain.DomainPiping:
  137. str = "水管";
  138. break;
  139. case Domain.DomainHvac:
  140. str = "风管";
  141. break;
  142. default:
  143. str = "未知";
  144. break;
  145. }
  146. return str;
  147. }
  148. }
  149. }