ParseConnector.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 mepSystemTypeId = connector.MEPSystem?.GetTypeId();
  56. if (mepSystemTypeId != null)
  57. {
  58. var systemTypeName = owner.Document.GetElement(mepSystemTypeId);
  59. jConnector.MepSystemTypeName = systemTypeName.Name;
  60. }
  61. #endregion
  62. #region 关联Connector
  63. //这里只维护关联,不进行递归
  64. var refConnectors = connector.GetReferenceConnectors();
  65. ElementOneToManyRel relMany = new ElementOneToManyRel(connectorId){RelatedObjects=new List<string>()};
  66. relMany.SetElementType(TypeDefinition.Property_MepSystem);
  67. foreach (var refConnector in refConnectors)
  68. {
  69. relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
  70. }
  71. if (relMany.RelatedObjects.Any())
  72. {
  73. context.RelationShips.Add(relMany);
  74. }
  75. #endregion
  76. return new List<BimId>() { jConnector.Id };
  77. }
  78. public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
  79. {
  80. #region MyRegion
  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. #endregion
  93. return null;
  94. }
  95. }
  96. }