ParseSpace.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. bimObject.Name = space.GetSpaceDefaultName();
  50. var location = space.Location.GetPoint();
  51. if (location != null)
  52. {
  53. bimObject.Location =
  54. GeometryLocation.CreatePointLocation(BimConvert.ConvertToXYZ(location));
  55. }
  56. bimObject.Height = (space.GetTopStaticHeight() - space.GetBaseStaticHeight()).FtToUse();
  57. //Parameters
  58. bimObject.Parameters = RevitUtil.GetSpaceParameters(space);
  59. var options = new SpatialElementBoundaryOptions();
  60. //options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;
  61. var segments = space.GetBoundarySegments(options);
  62. if (segments != null)
  63. {
  64. foreach (IList<BoundarySegment> segmentList in segments)
  65. {
  66. Polygon outLine = new Polygon();
  67. List<BimId> segmentBimids = new List<BimId>();
  68. foreach (BoundarySegment segment in segmentList)
  69. {
  70. var points = segment.GetCurve().GetPoints();
  71. var usePoints = points.Select(xyz => BimConvert.ConvertToXYZ(xyz)).ToList();
  72. outLine.AddRange(usePoints.GetRange(0, usePoints.Count - 1));
  73. #region 解析线段类
  74. JBoundarySegment jSegment = new JBoundarySegment();
  75. jSegment.Curve.AddRange(usePoints);
  76. var jSegmentId=context.AddBimObject(jSegment);
  77. segmentBimids.Add(jSegmentId);
  78. var referenceElementId = segment.ElementId;
  79. if (referenceElementId != null)
  80. {
  81. ElementOneToOneRel rel = new ElementOneToOneRel(jSegmentId.ToString(), referenceElementId.ToString());
  82. rel.SetElementType(TypeDefinition.Property_Reference);
  83. rel.RelatingObjectIsBimId = true;
  84. context.RelationShips.Add(rel);
  85. }
  86. #endregion
  87. }
  88. if (outLine.Any())
  89. {
  90. StandardUtil.ArrangeLoop(outLine);
  91. bimObject.OutLine.Add(outLine);
  92. }
  93. if (segmentBimids.Any())
  94. {
  95. bimObject.BoundarySegments.Add(segmentBimids);
  96. }
  97. }
  98. //外轮廓
  99. bimObject.OutLine2 = null; //space.GetSpaceOutline();
  100. }
  101. context.AddBimObject(bimObject);
  102. return new List<BimId>();
  103. }
  104. }
  105. }