From fca1e7620976d1e4544518f656022a2218d8569c Mon Sep 17 00:00:00 2001 From: Nice3point Date: Thu, 23 Nov 2023 22:19:57 +0300 Subject: [PATCH] MEPSection IsMain support --- .../Descriptors/MepSectionDescriptor.cs | 58 ++++++++++++------- .../Descriptors/MepSystemDescriptor.cs | 2 +- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/RevitLookup/Core/ComponentModel/Descriptors/MepSectionDescriptor.cs b/RevitLookup/Core/ComponentModel/Descriptors/MepSectionDescriptor.cs index 2db3d5cf9..3c2b3a9d9 100644 --- a/RevitLookup/Core/ComponentModel/Descriptors/MepSectionDescriptor.cs +++ b/RevitLookup/Core/ComponentModel/Descriptors/MepSectionDescriptor.cs @@ -27,13 +27,8 @@ namespace RevitLookup.Core.ComponentModel.Descriptors; -public class MepSectionDescriptor : Descriptor, IDescriptorResolver +public sealed class MepSectionDescriptor(MEPSection mepSection) : Descriptor, IDescriptorResolver { - private MEPSection _mepSection; - public MepSectionDescriptor(MEPSection mepSection) - { - _mepSection = mepSection; - } public ResolveSet Resolve(Document context, string target, ParameterInfo[] parameters) { return target switch @@ -42,61 +37,84 @@ public ResolveSet Resolve(Document context, string target, ParameterInfo[] param nameof(MEPSection.GetCoefficient) => ResolveCoefficient(), nameof(MEPSection.GetPressureDrop) => ResolvePressureDrop(), nameof(MEPSection.GetSegmentLength) => ResolveSegmentLength(), + nameof(MEPSection.IsMain) => ResolveIsMain(), _ => null }; - + ResolveSet ResolveSectionIds() { - var elementIds = _mepSection.GetElementIds(); + var elementIds = mepSection.GetElementIds(); var resolveSummary = new ResolveSet(elementIds.Count); foreach (var id in elementIds) { resolveSummary.AppendVariant(id); } + return resolveSummary; } + ResolveSet ResolveCoefficient() { - var elementIds = _mepSection.GetElementIds(); + var elementIds = mepSection.GetElementIds(); var resolveSummary = new ResolveSet(elementIds.Count); foreach (var id in elementIds) { - resolveSummary.AppendVariant(_mepSection.GetCoefficient(id), $"{id}"); + resolveSummary.AppendVariant(mepSection.GetCoefficient(id), $"ID{id}"); } + return resolveSummary; } - + ResolveSet ResolvePressureDrop() { - var elementIds = _mepSection.GetElementIds(); + var elementIds = mepSection.GetElementIds(); var resolveSummary = new ResolveSet(elementIds.Count); foreach (var id in elementIds) { - resolveSummary.AppendVariant(_mepSection.GetPressureDrop(id), $"{id}"); + resolveSummary.AppendVariant(mepSection.GetPressureDrop(id), $"ID{id}"); } + return resolveSummary; } - + ResolveSet ResolveSegmentLength() { - var elementIds = _mepSection.GetElementIds(); + var elementIds = mepSection.GetElementIds(); var resolveSummary = new ResolveSet(elementIds.Count); foreach (var id in elementIds) { - var length = 0.0d; try { - length = _mepSection.GetSegmentLength(id); + var length = mepSection.GetSegmentLength(id); + resolveSummary.AppendVariant(length, $"ID{id}"); } catch (ArgumentException) { // ignored } - if (length != 0.0d) resolveSummary.AppendVariant(length, $"{id}"); } + return resolveSummary; } - } - + ResolveSet ResolveIsMain() + { + var elementIds = mepSection.GetElementIds(); + var resolveSummary = new ResolveSet(elementIds.Count); + foreach (var id in elementIds) + { + try + { + var isMain = mepSection.IsMain(id); + resolveSummary.AppendVariant(isMain, $"ID{id}"); + } + catch (ArgumentException) + { + // ignored + } + } + + return resolveSummary; + } + } } \ No newline at end of file diff --git a/RevitLookup/Core/ComponentModel/Descriptors/MepSystemDescriptor.cs b/RevitLookup/Core/ComponentModel/Descriptors/MepSystemDescriptor.cs index 77ddccbcc..7e9ba4fda 100644 --- a/RevitLookup/Core/ComponentModel/Descriptors/MepSystemDescriptor.cs +++ b/RevitLookup/Core/ComponentModel/Descriptors/MepSystemDescriptor.cs @@ -25,7 +25,7 @@ namespace RevitLookup.Core.ComponentModel.Descriptors; -public class MepSystemDescriptor(MEPSystem mepSystem) : ElementDescriptor(mepSystem), IDescriptorResolver +public sealed class MepSystemDescriptor(MEPSystem mepSystem) : ElementDescriptor(mepSystem), IDescriptorResolver { public new ResolveSet Resolve(Document context, string target, ParameterInfo[] parameters) {