SystemReferEquipCheck.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.Logger;
  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 SystemReferEquipCheck : CheckBase
  21. {
  22. public SystemReferEquipCheck()
  23. {
  24. ReferenceSheet = "参考-管网及相关设备";
  25. }
  26. public override void Check()
  27. {
  28. try
  29. {
  30. base.Check();
  31. #region
  32. m_EquipReferSystems = DataCheckRule.GetEquipReferSystems();
  33. var elements = m_Doc.GetEqEcElements();
  34. foreach (Element element in elements)
  35. {
  36. var result = GetCheckResult(element);
  37. if (result == null) continue;
  38. Content.Add(result);
  39. }
  40. #endregion
  41. }
  42. catch (Exception e)
  43. {
  44. Result = ResultState.Failure;
  45. ResultMsg = $"{e.Message}\r\n{e.StackTrace}";
  46. }
  47. }
  48. private List<DCR_EquipReferSystem> m_EquipReferSystems;
  49. /// <summary>
  50. /// 获取检测结果
  51. /// </summary>
  52. /// <param name="fi"></param>
  53. /// <returns></returns>
  54. private SystemReferEquipCheckResult GetCheckResult(Element element)
  55. {
  56. var result = new SystemReferEquipCheckResult();
  57. var code = element.GetFamilyCode();
  58. // 可以与设备连接的系统
  59. var referSystems = m_EquipReferSystems.FirstOrDefault(t => t.EquipName == code)?.Systems ?? new List<string>();
  60. if (referSystems.Count == 0) return null;
  61. result.FamilyName = element.GetFamilyName();
  62. result.Id = element.Id.ToString();
  63. var tuple = CheckConType(element, referSystems);
  64. if (tuple.Item2.Any())
  65. {
  66. result.ResultMsg = $"连接件所连接的管道系统与规范不一致,请检查";
  67. result.UnPassSystems += string.Join("、", tuple.Item2.ToArray());
  68. result.Result = ResultState.Failure;
  69. }
  70. else
  71. {
  72. result.Result = ResultState.Success;
  73. }
  74. result.PassSystems += string.Join("、", tuple.Item1.ToArray());
  75. return result;
  76. }
  77. /// <summary>
  78. /// 检查连接件连接的管道系统是否符合规范
  79. /// </summary>
  80. /// <param name="result">符合要求的系统名称</param>
  81. /// <param name="domain">不符合要求的系统名称</param>
  82. private Tuple<List<string>, List<string>> CheckConType(Element element, List<string> referSystems)
  83. {
  84. List<string> passList = new List<string>();
  85. List<string> unpassList = new List<string>();
  86. var connectors = element.GetAllConnectors();
  87. foreach (Connector connector in connectors)
  88. {
  89. try
  90. {
  91. var mepSystem = connector.MEPSystem;
  92. if (mepSystem == null) continue;
  93. var elementId = mepSystem.GetTypeId();
  94. var type = element.Document.GetElement(elementId);
  95. if (!referSystems.Contains(type.Name))
  96. {
  97. unpassList.Add(type.Name);
  98. }
  99. else
  100. {
  101. passList.Add(type.Name);
  102. }
  103. }
  104. catch (Exception e)
  105. {
  106. Log4Net.Info($"读取连接件系统错误。Id:{element.Id},Path:{element.Document.PathName}");
  107. }
  108. }
  109. return new Tuple<List<string>, List<string>>(passList, unpassList);
  110. }
  111. }
  112. }