ParsePipe.cs 3.5 KB

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