SystemNameCheck.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 Autodesk.Revit.DB.Mechanical;
  12. using SAGA.DotNetUtils.Extend;
  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 SystemNameCheck : CheckBase
  24. {
  25. public SystemNameCheck()
  26. {
  27. ReferenceSheet = "参考-可识别的系统名称";
  28. }
  29. public override void Check()
  30. {
  31. try
  32. {
  33. base.Check();
  34. #region
  35. m_MEPSystems = DataCheckRule.GetMepSystems();
  36. var mepsystemTypes = new List<MEPSystemType>();
  37. mepsystemTypes.AddRange(m_Doc.GetMechanicalSystemTypes());
  38. mepsystemTypes.AddRange(m_Doc.GetPipingSystemTypes());
  39. foreach (var t in mepsystemTypes)
  40. {
  41. var result = GetCheckResult(t);
  42. Content.Add(result);
  43. }
  44. #endregion
  45. }
  46. catch (Exception e)
  47. {
  48. Result = ResultState.Failure;
  49. ResultMsg = $"{e.Message}\r\n{e.StackTrace}";
  50. }
  51. }
  52. private List<DCR_MEPSystem> m_MEPSystems;
  53. /// <summary>
  54. /// 获取检测结果
  55. /// </summary>
  56. /// <param name="fi"></param>
  57. /// <returns></returns>
  58. private SystemNameCheckResult GetCheckResult(MEPSystemType system)
  59. {
  60. var result = new SystemNameCheckResult();
  61. string systemName = system.Name;
  62. result.SystemName = systemName;
  63. result.SystemType = system is MechanicalSystemType ? "风管系统" : "管道系统";
  64. var item = m_MEPSystems.Where(t => SystemNameIsEqual(systemName, t.Name));
  65. if (item.Any())
  66. {
  67. result.Result = ResultState.Success;
  68. }
  69. else
  70. {
  71. result.Result = ResultState.Failure;
  72. result.ResultMsg = $"未知的系统名称,请按照系统类型命名规范修改";
  73. }
  74. return result;
  75. }
  76. /// <summary>
  77. /// 系统名称相等,模型中的系统名称包含就定义名称即可
  78. /// </summary>
  79. /// <param name="originName"></param>
  80. /// <param name="targetName"></param>
  81. /// <returns></returns>
  82. private bool SystemNameIsEqual(string originName, string targetName)
  83. {
  84. bool result = false;
  85. string n1 = originName.ToLower();
  86. string n2 = targetName.ToLower();
  87. return n1.Equals(n2);
  88. }
  89. }
  90. }