ParseSpace.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. //Parameters
  55. bimObject.Parameters = RevitUtil.GetSpaceParameters(space);
  56. var segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
  57. if (segments != null)
  58. {
  59. foreach (IList<BoundarySegment> segmentList in segments)
  60. {
  61. Polygon outLine = new Polygon();
  62. List<BimId> segmentBimids = new List<BimId>();
  63. foreach (BoundarySegment segment in segmentList)
  64. {
  65. var points = segment.GetCurve().GetPoints();
  66. var usePoints = points.Select(xyz => BimConvert.ConvertToXYZ(xyz)).ToList();
  67. outLine.AddRange(usePoints.GetRange(0, usePoints.Count - 1));
  68. #region 解析线段类
  69. JBoundarySegment jSegment = new JBoundarySegment();
  70. jSegment.Curve.AddRange(usePoints);
  71. var jSegmentId=context.AddBimObject(jSegment);
  72. segmentBimids.Add(jSegmentId);
  73. var referenceElementId = segment.ElementId;
  74. if (referenceElementId != null)
  75. {
  76. ElementOneToOneRel rel = new ElementOneToOneRel(jSegmentId.ToString(), referenceElementId.ToString());
  77. rel.SetElementType(TypeDefinition.Property_Reference);
  78. rel.RelatingObjectIsBimId = true;
  79. context.RelationShips.Add(rel);
  80. }
  81. #endregion
  82. }
  83. if (outLine.Any())
  84. {
  85. StandardUtil.ArrangeLoop(outLine);
  86. bimObject.OutLine.Add(outLine);
  87. }
  88. if (segmentBimids.Any())
  89. {
  90. bimObject.BoundarySegments.Add(segmentBimids);
  91. }
  92. }
  93. }
  94. context.AddBimObject(bimObject);
  95. return new List<BimId>();
  96. }
  97. }
  98. }