EquipmentPartRefEqCheck.cs 3.7 KB

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