ParsePipe.cs 4.0 KB

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