SystemCheck.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* ==============================================================================
  2. * 功能描述:拓扑计算系统名称检查
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/10/23 15:08:55
  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 NPOI.SS.UserModel;
  12. using SAGA.DotNetUtils.Others;
  13. using SAGA.RevitUtils.MEP;
  14. namespace Saga.PlugIn.ModelCheck
  15. {
  16. /// <summary>
  17. /// UnitCheck
  18. /// </summary>
  19. class SystemCheck : ModeCheckBase
  20. {
  21. public SystemCheck()
  22. {
  23. Name = "系统类型名称检查";
  24. RSPecificationSheet.Add("参考-可识别的系统名称");
  25. }
  26. public override bool Check()
  27. {
  28. if (!RBase.IsRight)
  29. {
  30. IsRight = RBase.IsRight;
  31. return IsRight;
  32. }
  33. IsRight = GetCheckResult();
  34. return IsRight;
  35. }
  36. private bool GetCheckResult()
  37. {
  38. bool unitResult = true;
  39. m_MEPSystems = DataCheckRule.GetMepSystems();
  40. foreach (SagaSignCheckResult signResult in RBase.Results)
  41. {
  42. var list = Check(signResult);
  43. Results.AddRange(list);
  44. }
  45. return Results.All(t => t.IsRight);
  46. }
  47. private List<DCR_MEPSystem> m_MEPSystems;
  48. /// <summary>
  49. /// 获取本楼层的检查结果
  50. /// </summary>
  51. /// <param name="document"></param>
  52. /// <returns></returns>
  53. private List<ModeCheckResultBase> Check(SagaSignCheckResult signResult)
  54. {
  55. List<ModeCheckResultBase> list = new List<ModeCheckResultBase>();
  56. var mepsystemTypes = new List<MEPSystemType>();
  57. mepsystemTypes.AddRange(signResult.RDocument.GetMechanicalSystemTypes());
  58. mepsystemTypes.AddRange(signResult.RDocument.GetPipingSystemTypes());
  59. mepsystemTypes.ForEach(t=>
  60. {
  61. var result = GetCheckResult(t);
  62. result.RBase = signResult;
  63. list.Add(result);
  64. });
  65. return list;
  66. }
  67. /// <summary>
  68. /// 获取检测结果
  69. /// </summary>
  70. /// <param name="fi"></param>
  71. /// <returns></returns>
  72. private ModeCheckResultBase GetCheckResult(MEPSystemType system)
  73. {
  74. var result = new SystemCheckResult();
  75. string systemName = system.Name;
  76. result.RSystemName = systemName;
  77. result.Type = system is MechanicalSystemType ? "风管系统" : "管道系统";
  78. result.IsRight = true;
  79. var item = m_MEPSystems.Where(t => SystemNameIsEqual(systemName,t.Name));
  80. if (!item.Any())
  81. {
  82. result.IsRight = false;
  83. result.RMessage = $"未知的系统名称,请按照系统类型命名规范修改";
  84. }
  85. return result;
  86. }
  87. /// <summary>
  88. /// 系统名称相等
  89. /// </summary>
  90. /// <param name="originName"></param>
  91. /// <param name="targetName"></param>
  92. /// <returns></returns>
  93. private bool SystemNameIsEqual(string originName,string targetName)
  94. {
  95. bool result = false;
  96. string n1 = originName.ToLower();
  97. string n2 = targetName.ToLower();
  98. return n1.Equals(n2);
  99. }
  100. public override void Export()
  101. {
  102. try
  103. {
  104. IWorkbook book = DCRExport.GetWorkbook();
  105. //ISheet sheet = book.CreateSheet(Name);
  106. ISheet sheet = book.GetSheet(Name);
  107. #region 添加数据
  108. int index = 3;
  109. foreach (SystemCheckResult result in Results)
  110. {
  111. SagaSignCheckResult rbase = result.RBase as SagaSignCheckResult;
  112. if (rbase == null)
  113. continue;
  114. index++;
  115. IRow rowN = sheet.CreateRow(index);
  116. DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
  117. int j = -1;
  118. rowN.AddCell(++j, result.RSystemName, style);
  119. rowN.AddCell(++j, result.Type, style);
  120. string rowN4 = result.IsRight ? "通过" : "不通过";
  121. rowN.AddCell(++j, rowN4, style);
  122. rowN.AddCell(++j, result.RMessage, style);
  123. }
  124. #endregion
  125. }
  126. catch (Exception e)
  127. {
  128. MessageShowBase.Show(e);
  129. }
  130. }
  131. }
  132. class SystemCheckResult : ModeCheckResultBase
  133. {
  134. public string RSystemName { get; set; }
  135. public string Type { get; set; }
  136. }
  137. }