SystemCheck.cs 4.9 KB

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