ParseRoom.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //wangwei 2020.11.23
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Autodesk.Revit.DB.Mechanical;
  8. using JBIM;
  9. using RevitExport;
  10. using RevitToJBim.Common;
  11. using SAGA.RevitUtils.Extends;
  12. using JRoom = JBIM.Component.Room;
  13. using JBoundarySegment = JBIM.Component.BoundarySegment;
  14. using Autodesk.Revit.DB;
  15. using JBIM.Definition;
  16. using RevitExport.Export;
  17. using RevitToJBim.Extension;
  18. using RevitToJBim.ParseData;
  19. using Autodesk.Revit.DB.Architecture;
  20. using SAGA.DotNetUtils.Extend;
  21. namespace RevitToJBim.ComponentParse
  22. {
  23. [UsableParse]
  24. //仿照ParseSpace
  25. public class ParseRoom : ParseBase
  26. {
  27. public override List<string> FastIndex()
  28. {
  29. return new List<string>() { typeof(Room).FullName };
  30. }
  31. public override bool Match(ElementWrapper wrapper)
  32. {
  33. return wrapper.RefElement is Room;
  34. }
  35. protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
  36. {
  37. if (!(wrapper.RefElement is Room room))
  38. {
  39. return null;
  40. }
  41. JRoom bimObject = new JRoom();
  42. ParseCore.AttachObject(bimObject, wrapper);
  43. bimObject.Name = GetSpaceDefaultName(room);
  44. var location = room.Location.GetPoint();
  45. if (location != null)
  46. {
  47. bimObject.Location =
  48. GeometryLocation.CreatePointLocation(BimConvert.ConvertToXYZ(location));
  49. }
  50. bimObject.Height = room.GetParameterDouble(BuiltInParameter.ROOM_HEIGHT);
  51. //Parameters
  52. bimObject.Parameters = RevitUtil.GetRoomParameters(room);
  53. var options = new SpatialElementBoundaryOptions();
  54. //options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;
  55. var segments = room.GetBoundarySegments(options);
  56. if (segments != null)
  57. {
  58. foreach (IList<BoundarySegment> segmentList in segments)
  59. {
  60. Polygon outLine = new Polygon();
  61. List<BimId> segmentBimids = new List<BimId>();
  62. foreach (BoundarySegment segment in segmentList)
  63. {
  64. var points = segment.GetCurve().GetPoints();
  65. var usePoints = points.Select(xyz => BimConvert.ConvertToXYZ(xyz)).ToList();
  66. outLine.AddRange(usePoints.GetRange(0, usePoints.Count - 1));
  67. #region 解析线段类
  68. JBoundarySegment jSegment = new JBoundarySegment();
  69. jSegment.Curve.AddRange(usePoints);
  70. var jSegmentId = context.AddBimObject(jSegment);
  71. segmentBimids.Add(jSegmentId);
  72. var referenceElementId = segment.ElementId;
  73. if (referenceElementId != null)
  74. {
  75. ElementOneToOneRel rel = new ElementOneToOneRel(jSegmentId.ToString(), referenceElementId.ToString());
  76. rel.SetElementType(TypeDefinition.Property_Reference);
  77. rel.RelatingObjectIsBimId = true;
  78. context.RelationShips.Add(rel);
  79. }
  80. #endregion
  81. }
  82. if (outLine.Any())
  83. {
  84. StandardUtil.ArrangeLoop(outLine);
  85. bimObject.OutLine.Add(outLine);
  86. }
  87. if (segmentBimids.Any())
  88. {
  89. bimObject.BoundarySegments.Add(segmentBimids);
  90. }
  91. }
  92. //外轮廓
  93. bimObject.OutLine2 = null; //space.GetSpaceOutline();
  94. }
  95. context.AddBimObject(bimObject);
  96. return new List<BimId>();
  97. }
  98. //从SAGA.RevitUtils拷贝而来
  99. public static string GetSpaceDefaultName(Room room)
  100. {
  101. string defaultName = room.Name;
  102. var roomname = room.GetParameterString(BuiltInParameter.ROOM_NAME);
  103. if (roomname == "房间" || roomname.IsNullOrEmptyExt()) return defaultName;
  104. defaultName = roomname;
  105. return defaultName;
  106. }
  107. }
  108. }