ElementWrapperFactory.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:ElementWrapperFactory
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/24 8:44:46
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Threading.Tasks;
  13. using Autodesk.Revit.DB;
  14. using RevitExport;
  15. using RevitExport.Export;
  16. using RevitToJBim.Extension;
  17. using RevitToJBim.MBI;
  18. using SAGA.RevitUtils.Extends;
  19. using SAGA.RevitUtils.MEP;
  20. namespace RevitToJBim.Common
  21. {
  22. /// <summary>
  23. /// 解析对象创建工厂
  24. /// </summary>
  25. public class ElementWrapperFactory
  26. {
  27. /// <summary>
  28. /// 根据element创建带分类对象的解析信息。便于快速过滤.
  29. /// 注:生成wrapper时,为了保证统一性,最好统一调用该方法
  30. /// </summary>
  31. /// <param name="element"></param>
  32. /// <returns></returns>
  33. public static ElementWrapper CreateWrapper(Element element)
  34. {
  35. if (element is FamilyInstance fi)
  36. {
  37. CreateWrapper(fi);
  38. }
  39. return new ElementWrapper(element);
  40. }
  41. /// <summary>
  42. /// 创建FamilyInstance的wrapper
  43. /// </summary>
  44. /// <param name="familyInstance"></param>
  45. /// <returns></returns>
  46. public static ElementWrapper CreateWrapper(FamilyInstance familyInstance)
  47. {
  48. var useFamilyType = FamilyType.Undefine;
  49. var category = familyInstance.Category;
  50. if (category != null)
  51. {
  52. var enumValue = (BuiltInCategory)category.Id.IntegerValue;
  53. #region category转换
  54. switch (enumValue)
  55. {
  56. case BuiltInCategory.OST_Doors:
  57. {
  58. useFamilyType = FamilyType.Door;
  59. break;
  60. }
  61. case BuiltInCategory.OST_Windows:
  62. {
  63. useFamilyType = FamilyType.Window;
  64. break;
  65. }
  66. case BuiltInCategory.OST_Columns:
  67. {
  68. useFamilyType = FamilyType.Column;
  69. break;
  70. }
  71. }
  72. #endregion
  73. }
  74. if (useFamilyType == FamilyType.Undefine)
  75. {
  76. //判断部件和设备
  77. var familyName = familyInstance.GetFamilyName();
  78. if (Regex.IsMatch(familyName, MBIRegexPattern.IsEquip)|| Regex.IsMatch(familyName, MBIRegexPattern.IsEquipPart))
  79. useFamilyType = FamilyType.Facility;
  80. else if (Regex.IsMatch(familyName, MBIRegexPattern.IsBeacon))
  81. {
  82. useFamilyType = FamilyType.Beacon;
  83. }
  84. }
  85. if (useFamilyType == FamilyType.Undefine)
  86. {
  87. var connectors = familyInstance.GetAllConnectors();
  88. if (connectors.Any(c => c.Domain == Domain.DomainHvac || c.Domain == Domain.DomainPiping))
  89. {
  90. useFamilyType = FamilyType.Other;
  91. }
  92. }
  93. if (useFamilyType == FamilyType.Undefine)
  94. {
  95. return null;
  96. }
  97. ElementWrapper wrapper = new ElementWrapper(familyInstance);
  98. wrapper.Category = CategoryGenerator.BuildingCategory(useFamilyType);
  99. return wrapper;
  100. }
  101. }
  102. }