ParseDuct.cs 3.9 KB

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