From 4a9ff14dde985aedc8a57264fc7e3deeeaea3829 Mon Sep 17 00:00:00 2001 From: NeVeSpl Date: Tue, 28 Nov 2023 18:13:52 +0100 Subject: [PATCH] cherry pick jeremytammik/RevitLookup#187 - GetBoundarySegments method of spatial elements support added --- .../SpatialElement_GetBoundarySegments.cs | 41 +++++++++++++++++++ .../Base/ValueContainerFactory.cs | 2 + .../ValueContainers/BoundarySegmentHandler.cs | 17 ++++++++ .../SpatialElementBoundaryOptionsHandler.cs | 21 ++++++++++ 4 files changed, 81 insertions(+) create mode 100644 sources/RevitDBExplorer/Domain/DataModel/MemberAccessors/SpatialElement/SpatialElement_GetBoundarySegments.cs create mode 100644 sources/RevitDBExplorer/Domain/DataModel/ValueContainers/BoundarySegmentHandler.cs create mode 100644 sources/RevitDBExplorer/Domain/DataModel/ValueContainers/SpatialElementBoundaryOptionsHandler.cs diff --git a/sources/RevitDBExplorer/Domain/DataModel/MemberAccessors/SpatialElement/SpatialElement_GetBoundarySegments.cs b/sources/RevitDBExplorer/Domain/DataModel/MemberAccessors/SpatialElement/SpatialElement_GetBoundarySegments.cs new file mode 100644 index 0000000..da8e1ab --- /dev/null +++ b/sources/RevitDBExplorer/Domain/DataModel/MemberAccessors/SpatialElement/SpatialElement_GetBoundarySegments.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using System.Linq.Expressions; +using Autodesk.Revit.DB; + +// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md + +namespace RevitDBExplorer.Domain.DataModel.MemberAccessors +{ + internal class SpatialElement_GetBoundarySegments : MemberAccessorByType, ICanCreateMemberAccessor + { + public IEnumerable GetHandledMembers() { yield return (SpatialElement x) => x.GetBoundarySegments(null); } + + + protected override bool CanBeSnoooped(Document document, SpatialElement value) => true; + + protected override string GetLabel(Document document, SpatialElement value) + { + return "[[BoundarySegment]]"; + } + + protected override IEnumerable Snooop(Document document, SpatialElement element) + { + var options = new[] + { + new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center, StoreFreeBoundaryFaces = true }, + new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.CoreBoundary, StoreFreeBoundaryFaces = true }, + new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish, StoreFreeBoundaryFaces = true }, + new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.CoreCenter, StoreFreeBoundaryFaces = true }, + new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center, StoreFreeBoundaryFaces = false }, + new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.CoreBoundary, StoreFreeBoundaryFaces = false }, + new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish, StoreFreeBoundaryFaces = false }, + new SpatialElementBoundaryOptions() { SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.CoreCenter, StoreFreeBoundaryFaces = false }, + }; + + foreach (var option in options) + { + yield return SnoopableObject.CreateKeyValuePair(document, option, element.GetBoundarySegments(option), "options"); + } + } + } +} diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/Base/ValueContainerFactory.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/Base/ValueContainerFactory.cs index 7bae391..0454fc2 100644 --- a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/Base/ValueContainerFactory.cs +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/Base/ValueContainerFactory.cs @@ -62,6 +62,8 @@ internal static class ValueContainerFactory new RevitApiEventArgsHandler(), new WorksetIdHandler(), new FailureDefinitionIdHandler(), + new SpatialElementBoundaryOptionsHandler(), + new BoundarySegmentHandler(), // generic new ElementHandler(), diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/BoundarySegmentHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/BoundarySegmentHandler.cs new file mode 100644 index 0000000..0946a59 --- /dev/null +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/BoundarySegmentHandler.cs @@ -0,0 +1,17 @@ +using Autodesk.Revit.DB; +using RevitDBExplorer.Domain.DataModel.ValueContainers.Base; + +// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md + +namespace RevitDBExplorer.Domain.DataModel.ValueContainers +{ + internal class BoundarySegmentHandler : TypeHandler + { + protected override bool CanBeSnoooped(SnoopableContext context, BoundarySegment boundarySegment) => boundarySegment is not null; + + protected override string ToLabel(SnoopableContext context, BoundarySegment boundarySegment) + { + return $"ID: {boundarySegment.ElementId}, {boundarySegment.GetCurve()?.Length} ft"; ; + } + } +} \ No newline at end of file diff --git a/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/SpatialElementBoundaryOptionsHandler.cs b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/SpatialElementBoundaryOptionsHandler.cs new file mode 100644 index 0000000..9ccecc4 --- /dev/null +++ b/sources/RevitDBExplorer/Domain/DataModel/ValueContainers/SpatialElementBoundaryOptionsHandler.cs @@ -0,0 +1,21 @@ +using Autodesk.Revit.DB; +using RevitDBExplorer.Domain.DataModel.ValueContainers.Base; + +// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md + +namespace RevitDBExplorer.Domain.DataModel.ValueContainers +{ + internal class SpatialElementBoundaryOptionsHandler : TypeHandler + { + protected override bool CanBeSnoooped(SnoopableContext context, SpatialElementBoundaryOptions value) => true; + protected override string ToLabel(SnoopableContext context, SpatialElementBoundaryOptions value) + { + if (value.StoreFreeBoundaryFaces == true) + { + return $"{value.SpatialElementBoundaryLocation}, store free boundary faces"; + } + + return $"{value.SpatialElementBoundaryLocation}"; + } + } +} \ No newline at end of file