ParseCore.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:ParseCore
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/13 18:03:03
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using Autodesk.Revit.DB;
  14. using JBIM;
  15. using JBIM.Component;
  16. using JBIM.Definition;
  17. using RevitExport;
  18. using RevitExport.Export;
  19. using RevitToJBim.Common;
  20. using Connector = JBIM.Component.Connector;
  21. namespace RevitToJBim.ComponentParse
  22. {
  23. /*
  24. * 核心解析类不解析关系
  25. */
  26. /// <summary>
  27. /// 核心解析类
  28. /// </summary>
  29. public class ParseCore
  30. {
  31. //获取可用的解析类
  32. public static List<ParseBase> GetUseParsers()
  33. {
  34. List<ParseBase> result = new List<ParseBase>();
  35. Assembly assembly = Assembly.GetCallingAssembly();
  36. Type[] types = assembly.GetTypes();
  37. foreach (var type in types)
  38. {
  39. if (typeof(ParseBase).IsAssignableFrom (type))
  40. {
  41. if (type.IsAbstract || type.IsGenericTypeDefinition)
  42. continue;
  43. var attribute = type.GetCustomAttribute<UsableParseAttribute>();
  44. if (attribute == null)
  45. continue;
  46. var construstor = type.GetConstructor(Type.EmptyTypes);
  47. if (construstor == null)
  48. continue;
  49. if (construstor.Invoke(null) is ParseBase parse)
  50. result.Add(parse);
  51. }
  52. }
  53. return result;
  54. }
  55. public static void AttachObject(ComponentObject bimObj, ElementWrapper wrapper)
  56. {
  57. bimObj.SourceId = wrapper.SourceId;
  58. bimObj.Name = wrapper.RefElement?.Name;
  59. }
  60. public static Connector CreateConnector(Autodesk.Revit.DB.Connector connector)
  61. {
  62. var result= new Connector();
  63. result.SourceId = RevitIdGenerator.GetConnectorId(connector);
  64. switch (connector.Domain)
  65. {
  66. case Domain.DomainHvac:
  67. {
  68. result.Domain = ConnectorDomain.DomainHvac.ToString();
  69. break;
  70. }
  71. case Domain.DomainPiping:
  72. {
  73. result.Domain = ConnectorDomain.DomainPiping.ToString();
  74. break;
  75. }
  76. }
  77. result.IsConnected = connector.IsConnected;
  78. result.Description = connector.Description;
  79. result.Origin = BimConvert.ConvertToXYZ(connector.Origin);
  80. return result;
  81. }
  82. /// <summary>
  83. /// 获取Connector包装类
  84. /// </summary>
  85. /// <param name="connector"></param>
  86. /// <returns></returns>
  87. public static ElementWrapper GetConnectorWrapper(Autodesk.Revit.DB.Connector connector)
  88. {
  89. ElementWrapper wrapper = new ElementWrapper(connector, RevitIdGenerator.GetConnectorId(connector));
  90. return wrapper;
  91. }
  92. }
  93. }