ParseCore.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. //获取可用的解析类
  30. public static List<ParseBase> GetUseParsers()
  31. {
  32. List<ParseBase> result = new List<ParseBase>();
  33. Assembly assembly = Assembly.GetCallingAssembly();
  34. Type[] types = assembly.GetTypes();
  35. foreach (var type in types)
  36. {
  37. if (typeof(ParseBase).IsAssignableFrom (type))
  38. {
  39. if (type.IsAbstract || type.IsGenericTypeDefinition)
  40. continue;
  41. var attribute = type.GetCustomAttribute<UsableParseAttribute>();
  42. if (attribute == null)
  43. continue;
  44. var construstor = type.GetConstructor(Type.EmptyTypes);
  45. if (construstor == null)
  46. continue;
  47. if (construstor.Invoke(null) is ParseBase parse)
  48. result.Add(parse);
  49. }
  50. }
  51. return result;
  52. }
  53. public static void AttachObject(ComponentObject bimObj, ElementWrapper wrapper)
  54. {
  55. bimObj.SourceId = wrapper.SourceId;
  56. bimObj.Name = wrapper.RefElement?.Name;
  57. }
  58. public static Connector CreateConnector(Autodesk.Revit.DB.Connector connector)
  59. {
  60. var result= new Connector();
  61. result.SourceId = RevitIdGenerator.GetConnectorId(connector);
  62. switch (connector.Domain)
  63. {
  64. case Domain.DomainHvac:
  65. {
  66. result.Domain = ConnectorDomain.DomainHvac.ToString();
  67. break;
  68. }
  69. case Domain.DomainPiping:
  70. {
  71. result.Domain = ConnectorDomain.DomainPiping.ToString();
  72. break;
  73. }
  74. }
  75. result.IsConnected = connector.IsConnected;
  76. result.Description = connector.Description;
  77. result.Origin = BimConvert.ConvertToXYZ(connector.Origin);
  78. return result;
  79. }
  80. /// <summary>
  81. /// 获取Connector包装类
  82. /// </summary>
  83. /// <param name="connector"></param>
  84. /// <returns></returns>
  85. public static ElementWrapper GetConnectorWrapper(Autodesk.Revit.DB.Connector connector)
  86. {
  87. ElementWrapper wrapper = new ElementWrapper(connector, RevitIdGenerator.GetConnectorId(connector));
  88. return wrapper;
  89. }
  90. }
  91. }