SystemNameCheck.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 Autodesk.Revit.DB.Mechanical;
  11. using SAGA.RevitUtils.MEP;
  12. using ServiceRevitLib.Mode;
  13. using ServiceRevitLib.Utils;
  14. namespace ServiceRevitLib.DataCheck.Mode
  15. {
  16. /// <summary>
  17. /// SagaCheck
  18. /// </summary>
  19. class SystemNameCheck : CheckBase
  20. {
  21. public SystemNameCheck()
  22. {
  23. ReferenceSheet = "参考-可识别的系统名称";
  24. }
  25. public override void Check()
  26. {
  27. try
  28. {
  29. base.Check();
  30. #region
  31. m_MEPSystems = DataCheckRule.GetMepSystems();
  32. var mepsystemTypes = new List<MEPSystemType>();
  33. mepsystemTypes.AddRange(m_Doc.GetMechanicalSystemTypes());
  34. mepsystemTypes.AddRange(m_Doc.GetPipingSystemTypes());
  35. foreach (var t in mepsystemTypes)
  36. {
  37. var result = GetCheckResult(t);
  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_MEPSystem> m_MEPSystems;
  49. /// <summary>
  50. /// 获取检测结果
  51. /// </summary>
  52. /// <param name="fi"></param>
  53. /// <returns></returns>
  54. private SystemNameCheckResult GetCheckResult(MEPSystemType system)
  55. {
  56. var result = new SystemNameCheckResult();
  57. string systemName = system.Name;
  58. result.SystemName = systemName;
  59. result.SystemType = system is MechanicalSystemType ? "风管系统" : "管道系统";
  60. var item = m_MEPSystems.Where(t => SystemNameIsEqual(systemName, t.Name));
  61. if (item.Any())
  62. {
  63. result.Result = ResultState.Success;
  64. }
  65. else
  66. {
  67. result.Result = ResultState.Failure;
  68. result.ResultMsg = $"未知的系统名称,请按照系统类型命名规范修改";
  69. }
  70. return result;
  71. }
  72. /// <summary>
  73. /// 系统名称相等,模型中的系统名称包含就定义名称即可
  74. /// </summary>
  75. /// <param name="originName"></param>
  76. /// <param name="targetName"></param>
  77. /// <returns></returns>
  78. private bool SystemNameIsEqual(string originName, string targetName)
  79. {
  80. bool result = false;
  81. string n1 = originName.ToLower();
  82. string n2 = targetName.ToLower();
  83. return n1.Equals(n2);
  84. }
  85. }
  86. }