ParsePipe.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. var systemTypeName=pipe.Document.GetElement(pipe.MEPSystem.GetTypeId());
  62. jPipe.MepSystemTypeName = systemTypeName.Name;
  63. #endregion
  64. #region Connector连接关系
  65. var connectors = pipe.GetConnectors();
  66. ElementOneToManyRel relMany = new ElementOneToManyRel(pipeId) { RelatedObjects = new List<string>() };
  67. relMany.SetElementType(TypeDefinition.Property_ConnectedIds);
  68. foreach (var refConnector in connectors)
  69. {
  70. relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
  71. }
  72. if (relMany.RelatedObjects.Any())
  73. {
  74. context.RelationShips.Add(relMany);
  75. }
  76. #endregion
  77. #endregion
  78. return new List<BimId>(){ jPipe.Id };
  79. }
  80. public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
  81. {
  82. if (!(wrapper.RefElement is Pipe pipe))
  83. {
  84. return null;
  85. }
  86. //创建MepSystem
  87. // var mepSystemElementWrapper = new ElementWrapper(pipe.MEPSystem);
  88. var wrappers=new List<ElementWrapper>() { };
  89. var connectors = pipe.GetConnectors();
  90. foreach (var connector in connectors)
  91. {
  92. wrappers.Add(ParseCore.GetConnectorWrapper(connector));
  93. }
  94. return wrappers;
  95. }
  96. }
  97. }