ElementWrapperFactory.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. return 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. case BuiltInCategory.OST_StructuralColumns:
  68. {
  69. useFamilyType = FamilyType.Column;
  70. break;
  71. }
  72. }
  73. #endregion
  74. }
  75. if (useFamilyType == FamilyType.Undefine)
  76. {
  77. //判断部件和设备
  78. var familyName = familyInstance.GetFamilyName();
  79. if (Regex.IsMatch(familyName, MBIRegexPattern.IsEquip)|| Regex.IsMatch(familyName, MBIRegexPattern.IsEquipPart))
  80. useFamilyType = FamilyType.Facility;
  81. else if (Regex.IsMatch(familyName, MBIRegexPattern.IsBeacon))
  82. {
  83. useFamilyType = FamilyType.Beacon;
  84. }
  85. }
  86. if (useFamilyType == FamilyType.Undefine)
  87. {
  88. var connectors = familyInstance.GetAllConnectors();
  89. if (connectors.Any(c => c.Domain == Domain.DomainHvac || c.Domain == Domain.DomainPiping))
  90. {
  91. useFamilyType = FamilyType.JoinObject;
  92. }
  93. }
  94. if (useFamilyType == FamilyType.Undefine)
  95. {
  96. useFamilyType = FamilyType.Other;
  97. }
  98. ElementWrapper wrapper = new ElementWrapper(familyInstance);
  99. wrapper.Category = CategoryGenerator.BuildingCategory(useFamilyType);
  100. return wrapper;
  101. }
  102. }
  103. }