ParseDuct.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:ParseDuct
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/20 9:40:13
  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 Autodesk.Revit.DB.Plumbing;
  15. using JBIM;
  16. using RevitExport;
  17. using RevitToJBim.Common;
  18. using SAGA.RevitUtils.Extends;
  19. using SAGA.RevitUtils.MEP;
  20. using JDuctShape = JBIM.DuctShape;
  21. using JDuct = JBIM.Component.Duct;
  22. using XYZ = JBIM.XYZ;
  23. namespace RevitToJBim.ComponentParse
  24. {
  25. [UsableParse]
  26. public class ParseDuct : ParseBase
  27. {
  28. public override List<string> FastIndex()
  29. {
  30. return new List<string>() { typeof(Duct).FullName };
  31. }
  32. public override bool Match(ElementWrapper wrapper)
  33. {
  34. return wrapper.RefElement is Duct;
  35. }
  36. protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
  37. {
  38. if (!(wrapper.RefElement is Duct duct))
  39. {
  40. return null;
  41. }
  42. JDuct jDuct = new JDuct();
  43. ParseCore.AttachObject(jDuct, wrapper);
  44. var locations = new List<XYZ>();
  45. locations.Add(BimConvert.ConvertToXYZ(duct.GetCurve().StartPoint()));
  46. locations.Add(BimConvert.ConvertToXYZ(duct.GetCurve().EndPoint()));
  47. jDuct.Location = GeometryLocation.CreateLineLocation(locations);
  48. Polygon outLine = new Polygon(locations);
  49. jDuct.OutLine.Add(outLine);
  50. context.AddBimObject(jDuct);
  51. #region 关联数据处理相关
  52. #region 系统关系
  53. var pipeId = duct.Id.ToString();
  54. var systemTypeName = duct.Document.GetElement(duct.MEPSystem.GetTypeId());
  55. jDuct.MepSystemTypeName = systemTypeName.Name;
  56. #endregion
  57. ConnectorProfileType shape = ConnectorProfileType.Invalid;
  58. #region Connector连接关系
  59. var connectors = duct.GetConnectors(Autodesk.Revit.DB.Domain.DomainHvac);
  60. ElementOneToManyRel relMany = new ElementOneToManyRel(pipeId) { RelatedObjects = new List<string>() };
  61. relMany.SetElementType(TypeDefinition.Property_ConnectedIds);
  62. foreach (var refConnector in connectors)
  63. {
  64. relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
  65. shape = refConnector.Shape;
  66. }
  67. if (relMany.RelatedObjects.Any())
  68. {
  69. context.RelationShips.Add(relMany);
  70. }
  71. #endregion
  72. if (shape== ConnectorProfileType.Round)
  73. {//duct.
  74. jDuct.Diameter = duct.Diameter.FtToUse();
  75. }
  76. else
  77. {
  78. jDuct.Width = duct.Width.FtToUse();
  79. jDuct.Height = duct.Height.FtToUse();
  80. }
  81. jDuct.Shape = (JDuctShape) (int) shape;
  82. #endregion
  83. return new List<BimId>() { jDuct.Id };
  84. }
  85. public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
  86. {
  87. if (!(wrapper.RefElement is Duct duct))
  88. {
  89. return null;
  90. }
  91. var wrappers = new List<ElementWrapper>() { };
  92. var connectors = duct.GetConnectors(Autodesk.Revit.DB.Domain.DomainHvac);
  93. foreach (var connector in connectors)
  94. {
  95. wrappers.Add(ParseCore.GetConnectorWrapper(connector));
  96. }
  97. return wrappers;
  98. }
  99. }
  100. }