ParseFacility.cs 4.1 KB

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