ParseConnector.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:ParseConnector
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/18 11:26:05
  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 Autodesk.Revit.DB.Mechanical;
  14. using JBIM;
  15. using JBIM.Relationship;
  16. using RevitExport;
  17. using RevitToJBim.Common;
  18. using SAGA.RevitUtils.MEP;
  19. using JConnector = JBIM.Component.Connector;
  20. namespace RevitToJBim.ComponentParse
  21. {
  22. [UsableParse]
  23. public class ParseConnector : ParseBase
  24. {
  25. public override List<string> FastIndex()
  26. {
  27. return new List<string>() { typeof(Connector).FullName, typeof(MechanicalSystemType).FullName };
  28. }
  29. public override bool Match(ElementWrapper wrapper)
  30. {
  31. return wrapper.GetObject<Connector>() != null;
  32. }
  33. protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
  34. {
  35. var connector = wrapper.GetObject<Connector>();
  36. if (connector == null)
  37. {
  38. return null;
  39. }
  40. JConnector jConnector = ParseCore.CreateConnector(connector);
  41. jConnector.SourceId = wrapper.SourceId;
  42. context.AddBimObject(jConnector);
  43. #region 所属类别解析
  44. //直接递归方式获取
  45. var owner = connector.Owner;
  46. if (owner != null)
  47. {
  48. ElementWrapper systemTypeWrapper = new ElementWrapper(owner);
  49. jConnector.Owner = context.Parser.ParseElement(systemTypeWrapper)?.FirstOrDefault();
  50. }
  51. #endregion
  52. #region 所属系统解析
  53. //维护关联并递归
  54. var connectorId = jConnector.SourceId;
  55. var systemId = connector.MEPSystem?.Id?.ToString();
  56. if (!string.IsNullOrWhiteSpace(systemId))
  57. {
  58. ElementOneToOneRel rel = new ElementOneToOneRel(connectorId, systemId);
  59. rel.SetElementType(TypeDefinition.Property_MepSystem);
  60. context.RelationShips.Add(rel);
  61. }
  62. #endregion
  63. #region 关联Connector
  64. //这里只维护关联,不进行递归
  65. var refConnectors = connector.GetReferenceConnectors();
  66. ElementOneToManyRel relMany = new ElementOneToManyRel(connectorId){RelatedObjects=new List<string>()};
  67. relMany.SetElementType(TypeDefinition.Property_MepSystem);
  68. foreach (var refConnector in refConnectors)
  69. {
  70. relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
  71. }
  72. if (relMany.RelatedObjects.Any())
  73. {
  74. context.RelationShips.Add(relMany);
  75. }
  76. #endregion
  77. return new List<BimId>() { jConnector.Id };
  78. }
  79. public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
  80. {
  81. if (!(wrapper.RefObject is Connector connector))
  82. {
  83. return null;
  84. }
  85. if (connector.MEPSystem == null)
  86. {
  87. return null;
  88. }
  89. //创建MepSystem
  90. var mepSystemElementWrapper = new ElementWrapper(connector.MEPSystem);
  91. return new List<ElementWrapper>() { mepSystemElementWrapper };
  92. }
  93. }
  94. }