ParseConnector.cs 3.7 KB

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