ElementWrapperFactory.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.Threading.Tasks;
  12. using Autodesk.Revit.DB;
  13. using RevitExport;
  14. using RevitExport.Export;
  15. using SAGA.RevitUtils.Extends;
  16. using SAGA.RevitUtils.MEP;
  17. namespace RevitToJBim.Common
  18. {
  19. /// <summary>
  20. /// 解析对象创建工厂
  21. /// </summary>
  22. public class ElementWrapperFactory
  23. {
  24. /// <summary>
  25. /// 根据element创建带分类对象的解析信息。便于快速过滤.
  26. /// 注:生成wrapper时,为了保证统一性,最好统一调用该方法
  27. /// </summary>
  28. /// <param name="element"></param>
  29. /// <returns></returns>
  30. public static ElementWrapper CreateWrapper(Element element)
  31. {
  32. if (element is FamilyInstance fi)
  33. {
  34. CreateWrapper(fi);
  35. }
  36. return new ElementWrapper(element);
  37. }
  38. /// <summary>
  39. /// 创建FamilyInstance的wrapper
  40. /// </summary>
  41. /// <param name="familyInstance"></param>
  42. /// <returns></returns>
  43. public static ElementWrapper CreateWrapper(FamilyInstance familyInstance)
  44. {
  45. var useFamilyType = FamilyType.Undefine;
  46. var category = familyInstance.Category;
  47. if (category != null)
  48. {
  49. var enumValue = (BuiltInCategory)category.Id.IntegerValue;
  50. #region category转换
  51. switch (enumValue)
  52. {
  53. case BuiltInCategory.OST_Doors:
  54. {
  55. useFamilyType = FamilyType.Door;
  56. break;
  57. }
  58. case BuiltInCategory.OST_Windows:
  59. {
  60. useFamilyType = FamilyType.Window;
  61. break;
  62. }
  63. case BuiltInCategory.OST_Columns:
  64. {
  65. useFamilyType = FamilyType.Column;
  66. break;
  67. }
  68. }
  69. #endregion
  70. }
  71. if (useFamilyType == FamilyType.Undefine)
  72. {
  73. //判断部件和设备
  74. var family = familyInstance.GetFamily();
  75. ///todo
  76. }
  77. if (useFamilyType == FamilyType.Undefine)
  78. {
  79. var connectors = familyInstance.GetAllConnectors();
  80. if (connectors.Any(c => c.Domain == Domain.DomainHvac || c.Domain == Domain.DomainPiping))
  81. {
  82. useFamilyType = FamilyType.Other;
  83. }
  84. }
  85. if (useFamilyType == FamilyType.Undefine)
  86. {
  87. return null;
  88. }
  89. ElementWrapper wrapper = new ElementWrapper(familyInstance);
  90. wrapper.Category = CategoryGenerator.BuildingCategory(useFamilyType);
  91. return wrapper;
  92. }
  93. }
  94. }