ParseSpace.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:ParseSpace
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/17 14:28:03
  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.Mechanical;
  13. using JBIM;
  14. using RevitExport;
  15. using RevitToJBim.Common;
  16. using SAGA.RevitUtils.Extends;
  17. using JSpace = JBIM.Component.Space;
  18. using JBoundarySegment = JBIM.Component.BoundarySegment;
  19. using Autodesk.Revit.DB;
  20. using JBIM.Definition;
  21. using RevitExport.Export;
  22. using RevitToJBim.ParseData;
  23. namespace RevitToJBim.ComponentParse
  24. {
  25. [UsableParse]
  26. public class ParseSpace : ParseBase
  27. {
  28. public override List<string> FastIndex()
  29. {
  30. return new List<string>() {typeof(Space).FullName};
  31. }
  32. public override bool Match(ElementWrapper wrapper)
  33. {
  34. return wrapper.RefElement is Space;
  35. }
  36. protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
  37. {
  38. if (!(wrapper.RefElement is Space space))
  39. {
  40. return null;
  41. }
  42. //if (!space.IsSpace())
  43. //{
  44. // return null;
  45. //}
  46. JSpace bimObject = new JSpace();
  47. ParseCore.AttachObject(bimObject, wrapper);
  48. var location = space.Location.GetPoint();
  49. if (location != null)
  50. {
  51. bimObject.Location =
  52. GeometryLocation.CreatePointLocation(BimConvert.ConvertToXYZ(location));
  53. }
  54. bimObject.Height = (space.GetTopStaticHeight() - space.GetBaseStaticHeight()).FtToUse();
  55. //Parameters
  56. bimObject.Parameters = RevitUtil.GetSpaceParameters(space);
  57. var options = new SpatialElementBoundaryOptions();
  58. options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;
  59. var segments = space.GetBoundarySegments(options);
  60. if (segments != null)
  61. {
  62. foreach (IList<BoundarySegment> segmentList in segments)
  63. {
  64. Polygon outLine = new Polygon();
  65. List<BimId> segmentBimids = new List<BimId>();
  66. foreach (BoundarySegment segment in segmentList)
  67. {
  68. var points = segment.GetCurve().GetPoints();
  69. var usePoints = points.Select(xyz => BimConvert.ConvertToXYZ(xyz)).ToList();
  70. outLine.AddRange(usePoints.GetRange(0, usePoints.Count - 1));
  71. #region 解析线段类
  72. JBoundarySegment jSegment = new JBoundarySegment();
  73. jSegment.Curve.AddRange(usePoints);
  74. var jSegmentId=context.AddBimObject(jSegment);
  75. segmentBimids.Add(jSegmentId);
  76. var referenceElementId = segment.ElementId;
  77. if (referenceElementId != null)
  78. {
  79. ElementOneToOneRel rel = new ElementOneToOneRel(jSegmentId.ToString(), referenceElementId.ToString());
  80. rel.SetElementType(TypeDefinition.Property_Reference);
  81. rel.RelatingObjectIsBimId = true;
  82. context.RelationShips.Add(rel);
  83. }
  84. #endregion
  85. }
  86. if (outLine.Any())
  87. {
  88. StandardUtil.ArrangeLoop(outLine);
  89. bimObject.OutLine.Add(outLine);
  90. }
  91. if (segmentBimids.Any())
  92. {
  93. bimObject.BoundarySegments.Add(segmentBimids);
  94. }
  95. }
  96. }
  97. context.AddBimObject(bimObject);
  98. return new List<BimId>();
  99. }
  100. }
  101. }