ParsePipe.cs 3.6 KB

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