ParseFacility.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:解析设备设施
  3. * 作者:Garrett
  4. * 创建时间:
  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;
  13. using Autodesk.Revit.DB.Mechanical;
  14. using Autodesk.Revit.DB.Plumbing;
  15. using JBIM;
  16. using JBIM.Component;
  17. using JBIM.Definition;
  18. using RevitExport;
  19. using RevitExport.Export;
  20. using RevitToJBim.Common;
  21. using RevitToJBim.Extension;
  22. using RevitToJBim.ParseData;
  23. using SAGA.RevitUtils.Extends;
  24. using SAGA.RevitUtils.MEP;
  25. using FamilyType = RevitToJBim.Common.FamilyType;
  26. using JEquip = JBIM.Component.Equipment;
  27. namespace RevitToJBim.ComponentParse
  28. {
  29. [UsableParse]
  30. public class ParseFacility : ParseBase
  31. {
  32. public override List<string> FastIndex()
  33. {
  34. return new List<string>() { CategoryGenerator.BuildingCategory(FamilyType.Facility) };
  35. }
  36. public override bool Match(ElementWrapper wrapper)
  37. {
  38. return wrapper.RefElement.IsEquipment()||wrapper.RefElement.IsEquipmentPart();
  39. }
  40. protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
  41. {
  42. if (!(wrapper.RefElement is FamilyInstance familyInstance))
  43. {
  44. return null;
  45. }
  46. //ElementType
  47. JEquip jObject = GetJEquip(familyInstance);
  48. //Name,SourceId
  49. ParseCore.AttachObject(jObject, wrapper);
  50. //Location
  51. jObject.Location = GeometryLocation.CreatePointLocation(BimConvert.ConvertToXYZ(familyInstance.GetLocationPoint()));
  52. //OutLine
  53. var polygonPath = RevitUtil.GetBottomPolygon(familyInstance);
  54. if (polygonPath != null && polygonPath.Any())
  55. {
  56. Polygon outLine = new Polygon(BimConvert.ConvertToXYZs(polygonPath));
  57. jObject.OutLine.Add(outLine);
  58. }
  59. //FamilyName
  60. jObject.FamilyName = familyInstance.GetFamilyName();
  61. //Tag
  62. jObject.Tag = "";
  63. //Parameters
  64. jObject.Parameters = RevitUtil.GetFacilityParameters(familyInstance);
  65. //Id
  66. context.AddBimObject(jObject);
  67. #region 关联数据处理相关
  68. //Owner
  69. var parentElement = RevitUtil.GetEquipPartParent(familyInstance);
  70. if (parentElement != null&&jObject is EquipPart jPart)
  71. {
  72. jPart.Owner = context.Parser.ParseElement(ElementWrapperFactory.CreateWrapper(parentElement)).FirstOrDefault()?.Id;
  73. }
  74. #region Connector连接关系
  75. var connectors = familyInstance.GetAllConnectors();
  76. ElementOneToManyRel relMany = ParseCore.GetConnectorRels(familyInstance,connectors);
  77. if (relMany!=null)
  78. {
  79. context.RelationShips.Add(relMany);
  80. }
  81. #endregion
  82. #endregion
  83. return new List<BimId>() { jObject.Id };
  84. }
  85. public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
  86. {
  87. var element = wrapper.RefElement;
  88. var wrappers = new List<ElementWrapper>() { };
  89. var connectors = element.GetAllConnectors();
  90. foreach (var connector in connectors)
  91. {
  92. wrappers.Add(ParseCore.GetConnectorWrapper(connector));
  93. }
  94. return wrappers;
  95. }
  96. private JEquip GetJEquip(FamilyInstance fi)
  97. {
  98. JEquip jObject = null;
  99. if(fi.IsEquipment())
  100. jObject=new JEquip();
  101. else if (fi.IsEquipmentPart())
  102. {
  103. jObject = new EquipPart();
  104. }
  105. return jObject;
  106. }
  107. }
  108. }