/*------------------------------------------------------------------------- * 功能描述:ParseSpace * 作者:xulisong * 创建时间: 2019/6/17 14:28:03 * 版本号:v1.0 * -------------------------------------------------------------------------*/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.Revit.DB.Mechanical; using JBIM; using RevitExport; using RevitToJBim.Common; using SAGA.RevitUtils.Extends; using JSpace = JBIM.Component.Space; using JBoundarySegment = JBIM.Component.BoundarySegment; using Autodesk.Revit.DB; using JBIM.Definition; using RevitExport.Export; using RevitToJBim.ParseData; namespace RevitToJBim.ComponentParse { [UsableParse] public class ParseSpace : ParseBase { public override List FastIndex() { return new List() {typeof(Space).FullName}; } public override bool Match(ElementWrapper wrapper) { return wrapper.RefElement is Space; } protected override List ParseInner(ElementWrapper wrapper, JBimParseContext context) { if (!(wrapper.RefElement is Space space)) { return null; } //if (!space.IsSpace()) //{ // return null; //} JSpace bimObject = new JSpace(); ParseCore.AttachObject(bimObject, wrapper); var location = space.Location.GetPoint(); if (location != null) { bimObject.Location = GeometryLocation.CreatePointLocation(BimConvert.ConvertToXYZ(location)); } //Parameters bimObject.Parameters = RevitUtil.GetSpaceParameters(space); var segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions()); if (segments != null) { foreach (IList segmentList in segments) { Polygon outLine = new Polygon(); List segmentBimids = new List(); foreach (BoundarySegment segment in segmentList) { var points = segment.GetCurve().GetPoints(); var usePoints = points.Select(xyz => BimConvert.ConvertToXYZ(xyz)).ToList(); outLine.AddRange(usePoints.GetRange(0, usePoints.Count - 1)); #region 解析线段类 JBoundarySegment jSegment = new JBoundarySegment(); jSegment.Curve.AddRange(usePoints); var jSegmentId=context.AddBimObject(jSegment); segmentBimids.Add(jSegmentId); var referenceElementId = segment.ElementId; if (referenceElementId != null) { ElementOneToOneRel rel = new ElementOneToOneRel(jSegmentId.ToString(), referenceElementId.ToString()); rel.SetElementType(TypeDefinition.Property_Reference); rel.RelatingObjectIsBimId = true; context.RelationShips.Add(rel); } #endregion } if (outLine.Any()) { StandardUtil.ArrangeLoop(outLine); bimObject.OutLine.Add(outLine); } if (segmentBimids.Any()) { bimObject.BoundarySegments.Add(segmentBimids); } } } context.AddBimObject(bimObject); return new List(); } } }