EquipmentPartRefEqCheck.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* ==============================================================================
  2. * 功能描述:部件关联设备检查
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/10/23 15:08:55
  5. * ==============================================================================*/
  6. using System;
  7. using System.Linq;
  8. using Autodesk.Revit.DB;
  9. using NPOI.SS.UserModel;
  10. using SAGA.DotNetUtils.Others;
  11. using SAGA.RevitUtils.Extends;
  12. namespace Saga.PlugIn.ModelCheck
  13. {
  14. /// <summary>
  15. /// UnitCheck
  16. /// </summary>
  17. class EquipmentPartRefEqCheck : ModeCheckBase
  18. {
  19. public EquipmentPartRefEqCheck()
  20. {
  21. Name = "部件所在位置检查";
  22. }
  23. public override bool Check()
  24. {
  25. if (!RBase.IsRight)
  26. {
  27. IsRight = RBase.IsRight;
  28. return IsRight;
  29. }
  30. IsRight = GetCheckResult();
  31. return IsRight;
  32. }
  33. private bool GetCheckResult()
  34. {
  35. bool unitResult = true;
  36. foreach (SagaSignCheckResult signResult in RBase.Results)
  37. {
  38. var document = signResult.RDocument;
  39. var parts = document.GetFamilyInstances().Where(t => t.IsEquipmentPart());
  40. foreach (var fi in parts)
  41. {
  42. var result = GetCheckResult(fi);
  43. result.RBase = signResult;
  44. Results.Add(result);
  45. }
  46. }
  47. return Results.All(t => t.IsRight);
  48. }
  49. /// <summary>
  50. /// 获取检测结果
  51. /// </summary>
  52. /// <param name="fi"></param>
  53. /// <returns></returns>
  54. private ModeCheckResultBase GetCheckResult(Element fi)
  55. {
  56. var result = new EquipmentPartRefEqCheckResult();
  57. result.FamilyName = fi.GetFamilyName();
  58. result.Id = fi.Id.ToString();
  59. var partParent = fi.GetEquipPartParent();
  60. if (partParent == null)
  61. {
  62. result.IsRight = false;
  63. result.RMessage = "未与设备相交,请检查";
  64. }
  65. else
  66. {
  67. result.IsRight = true;
  68. result.RMessage = $"关联设备的id为{partParent.Id}";
  69. }
  70. return result;
  71. }
  72. public override void Export()
  73. {
  74. try
  75. {
  76. IWorkbook book = DCRExport.GetWorkbook();
  77. //ISheet sheet = book.CreateSheet(Name);
  78. ISheet sheet = book.GetSheet(Name);
  79. #region 添加数据
  80. int index = 3;
  81. foreach (EquipmentPartRefEqCheckResult result in Results)
  82. {
  83. SagaSignCheckResult rbase = result.RBase as SagaSignCheckResult;
  84. if (rbase == null)
  85. continue;
  86. index++;
  87. IRow rowN = sheet.CreateRow(index);
  88. DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
  89. int j = -1;
  90. rowN.AddCell(++j, result.FamilyName, style);
  91. rowN.AddCell(++j, result.Id, style);
  92. string rowN4 = result.IsRight ? "通过" : "不通过";
  93. rowN.AddCell(++j, rowN4, style);
  94. rowN.AddCell(++j, result.RMessage, style);
  95. }
  96. #endregion
  97. }
  98. catch (Exception e)
  99. {
  100. MessageShowBase.Show(e);
  101. }
  102. }
  103. }
  104. class EquipmentPartRefEqCheckResult : ModeCheckResultBase
  105. {
  106. public string Id { get; set; }
  107. public string FamilyName { get; set; }
  108. }
  109. }