ParseSpace.cs 3.6 KB

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