ParseSpace.cs 4.2 KB

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