ParseCore.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 RevitExport;
  17. using RevitToJBim.Common;
  18. using Connector = JBIM.Component.Connector;
  19. namespace RevitToJBim.ComponentParse
  20. {
  21. /*
  22. * 核心解析类不解析关系
  23. */
  24. /// <summary>
  25. /// 核心解析类
  26. /// </summary>
  27. public class ParseCore
  28. {
  29. public class ParseElementManager
  30. {
  31. //获取可用的解析类
  32. public static List<ParseBase> GetUseParses()
  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. }
  56. public static void AttachObject(ComponentObject bimObj, ElementWrapper wrapper)
  57. {
  58. bimObj.SourceId = wrapper.SourceId;
  59. bimObj.Name = wrapper.RefElement?.Name;
  60. }
  61. public static BimObject GetObject(object obj)
  62. {
  63. return null;
  64. }
  65. public static Connector CreateConnector(Autodesk.Revit.DB.Connector connector)
  66. {
  67. var result= new Connector();
  68. result.SourceId = RevitIdGenerator.GetConnectorId(connector);
  69. switch (connector.Domain)
  70. {
  71. case Domain.DomainHvac:
  72. {
  73. result.Domain = ConnectorDomain.DomainHvac.ToString();
  74. break;
  75. }
  76. case Domain.DomainPiping:
  77. {
  78. result.Domain = ConnectorDomain.DomainPiping.ToString();
  79. break;
  80. }
  81. }
  82. result.IsConnected = connector.IsConnected;
  83. result.Description = connector.Description;
  84. result.Origin = BimConvert.ConvertToXYZ(connector.Origin);
  85. return result;
  86. }
  87. public static MepSystem CreateConnector(Autodesk.Revit.DB.MEPSystem mepSystem)
  88. {
  89. var result= new MepSystem();
  90. result.Name = mepSystem.Name;
  91. result.SourceId = mepSystem.Id.ToString();
  92. return result;
  93. }
  94. public static MepSystemType CreateConnector(Autodesk.Revit.DB.MEPSystemType mepSystemType)
  95. {
  96. var result = new MepSystemType();
  97. result.Name = mepSystemType.Name;
  98. result.SourceId = mepSystemType.Id.ToString();
  99. return result;
  100. }
  101. }
  102. }