SystemReferEquipCheck.cs 4.0 KB

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