ParseSpace.cs 3.7 KB

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