ParsePipe.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:ParsePipe
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/13 16:54:19
  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.Plumbing;
  14. using JBIM;
  15. using JBIM.Definition;
  16. using RevitExport;
  17. using RevitExport.Export;
  18. using RevitToJBim.Common;
  19. using RevitToJBim.ParseData;
  20. using SAGA.RevitUtils.Extends;
  21. using SAGA.RevitUtils.MEP;
  22. using JPipe = JBIM.Component.Pipe;
  23. using XYZ = JBIM.Definition.XYZ;
  24. namespace RevitToJBim.ComponentParse
  25. {
  26. [UsableParseAttribute]
  27. public class ParsePipe : ParseBase
  28. {
  29. public override List<string> FastIndex()
  30. {
  31. return new List<string>() { typeof(Pipe).FullName, typeof(FlexPipe).FullName };
  32. }
  33. public override bool Match(ElementWrapper wrapper)
  34. {
  35. return wrapper.RefElement is Pipe || wrapper.RefElement is FlexPipe;
  36. }
  37. protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
  38. {
  39. /*
  40. * 解析思路:1、解析当前对象具体信息。
  41. * 2、维护一些构件的关联管理关系,可以放在这个方法中,也可以放在ArrangeRefElements中
  42. *
  43. */
  44. if (!(wrapper.RefElement is MEPCurve pipe))
  45. {
  46. return null;
  47. }
  48. JPipe jPipe = new JPipe();
  49. if (pipe is FlexPipe)
  50. jPipe = new JBIM.Component.FlexPipe();
  51. ParseCore.AttachObject(jPipe, wrapper);
  52. jPipe.Diameter = pipe.Diameter.FtToUse();
  53. try
  54. {
  55. var locations = new List<XYZ>();
  56. locations.Add(BimConvert.ConvertToXYZ(pipe.GetCurve().StartPoint()));
  57. locations.Add(BimConvert.ConvertToXYZ(pipe.GetCurve().EndPoint()));
  58. jPipe.Location = GeometryLocation.CreateLineLocation(locations);
  59. Polygon outLine = new Polygon(locations);
  60. jPipe.OutLine.Add(outLine);
  61. }
  62. catch (Exception e)
  63. {
  64. Console.WriteLine(e);
  65. }
  66. context.AddBimObject(jPipe);
  67. //Parameters
  68. jPipe.Parameters = RevitUtil.GetMEPCurveParameters(pipe);
  69. #region 关联数据处理相关
  70. #region 系统关系
  71. var pipeId = pipe.Id.ToString();
  72. try
  73. {
  74. if (pipe.MEPSystem != null)
  75. {
  76. var systemTypeName = pipe.Document.GetElement(pipe.MEPSystem.GetTypeId());
  77. jPipe.MepSystemTypeName = systemTypeName.Name;
  78. }
  79. }
  80. catch (Exception e)
  81. {
  82. Console.WriteLine(e.Message + e.StackTrace);
  83. }
  84. #endregion
  85. #region Connector连接关系
  86. var connectors = (pipe).GetConnectors(Domain.DomainPiping);
  87. ElementOneToManyRel relMany = new ElementOneToManyRel(pipeId) { RelatedObjects = new List<string>() };
  88. relMany.SetElementType(TypeDefinition.Property_ConnectedIds);
  89. foreach (var refConnector in connectors)
  90. {
  91. relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
  92. }
  93. if (relMany.RelatedObjects.Any())
  94. {
  95. context.RelationShips.Add(relMany);
  96. }
  97. #endregion
  98. #endregion
  99. return new List<BimId>() { jPipe.Id };
  100. }
  101. public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
  102. {
  103. if (!(wrapper.RefElement is MEPCurve pipe))
  104. {
  105. return null;
  106. }
  107. //创建MepSystem
  108. // var mepSystemElementWrapper = new ElementWrapper(pipe.MEPSystem);
  109. var wrappers = new List<ElementWrapper>() { };
  110. var connectors = pipe.GetConnectors(Domain.DomainPiping);
  111. foreach (var connector in connectors)
  112. {
  113. wrappers.Add(ParseCore.GetConnectorWrapper(connector));
  114. }
  115. return wrappers;
  116. }
  117. }
  118. }