ParsePipe.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.Relationship;
  15. using RevitExport;
  16. using RevitToJBim.Common;
  17. using SAGA.RevitUtils.Extends;
  18. using SAGA.RevitUtils.MEP;
  19. using JPipe=JBIM.Component.Pipe;
  20. namespace RevitToJBim.ComponentParse
  21. {
  22. [UsableParseAttribute]
  23. public class ParsePipe : ParseBase
  24. {
  25. public override List<string> FastIndex()
  26. {
  27. return new List<string>() { typeof(Pipe).FullName };
  28. }
  29. public override bool Match(ElementWrapper wrapper)
  30. {
  31. return wrapper.RefElement is Pipe;
  32. }
  33. protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
  34. {
  35. /*
  36. * 解析思路:1、解析当前对象具体信息。
  37. * 2、维护一些构件的关联管理关系,可以放在这个方法中,也可以放在ArrangeRefElements中
  38. *
  39. */
  40. if (!(wrapper.RefElement is Pipe pipe))
  41. {
  42. return null;
  43. }
  44. JPipe jPipe = new JPipe();
  45. ParseCore.AttachObject(jPipe, wrapper);
  46. jPipe.Diameter = BimConvert.Round(pipe.Diameter.FromApi());
  47. jPipe.Location.Add(BimConvert.ConvertToXYZ(pipe.GetCurve().StartPoint()));
  48. jPipe.Location.Add(BimConvert.ConvertToXYZ(pipe.GetCurve().EndPoint()));
  49. Polygon outLine = new Polygon(jPipe.Location);
  50. jPipe.OutLine.Add(outLine);
  51. context.AddBimObject(jPipe);
  52. #region 关联数据处理相关
  53. #region 系统关系
  54. var pipeId = pipe.Id.ToString();
  55. var systemId = pipe.MEPSystem.Id.ToString();
  56. ElementOneToOneRel rel = new ElementOneToOneRel(pipeId, systemId);
  57. rel.SetElementType(TypeDefinition.Property_MepSystem);
  58. context.RelationShips.Add(rel);
  59. #endregion
  60. #region Connector连接关系
  61. var connectors = pipe.GetConnectors();
  62. ElementOneToManyRel relMany = new ElementOneToManyRel(pipeId) { RelatedObjects = new List<string>() };
  63. relMany.SetElementType(TypeDefinition.Property_ConnectedIds);
  64. foreach (var refConnector in connectors)
  65. {
  66. relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
  67. }
  68. if (relMany.RelatedObjects.Any())
  69. {
  70. context.RelationShips.Add(relMany);
  71. }
  72. #endregion
  73. #endregion
  74. return new List<BimId>(){ jPipe.Id };
  75. }
  76. public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
  77. {
  78. if (!(wrapper.RefElement is Pipe pipe))
  79. {
  80. return null;
  81. }
  82. //创建MepSystem
  83. var mepSystemElementWrapper = new ElementWrapper(pipe.MEPSystem);
  84. return new List<ElementWrapper>() {mepSystemElementWrapper};
  85. }
  86. }
  87. }