From 82ac83d1daa1316bcbb4a4d7c64402fb5313aad1 Mon Sep 17 00:00:00 2001 From: SergeyNefyodov Date: Thu, 19 Dec 2024 19:01:01 +0100 Subject: [PATCH] Add compound structure support --- .../Core/ComponentModel/DescriptorMap.cs | 1 + .../CompoundStructureDescriptor.cs | 292 ++++++++++++++++++ 2 files changed, 293 insertions(+) create mode 100644 source/RevitLookup/Core/ComponentModel/Descriptors/CompoundStructureDescriptor.cs diff --git a/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs b/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs index fbddf8ef..64dc6bf9 100644 --- a/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs +++ b/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs @@ -155,6 +155,7 @@ public static Descriptor FindDescriptor(object obj, Type type) FamilySizeTableManager value when type is null || type == typeof(FamilySizeTableManager) => new FamilySizeTableManagerDescriptor(value), FamilySizeTable value when type is null || type == typeof(FamilySizeTable) => new FamilySizeTableDescriptor(value), FamilySizeTableColumn value when type is null || type == typeof(FamilySizeTableColumn) => new FamilySizeTableColumnDescriptor(value), + CompoundStructure value when type is null || type == typeof(CompoundStructure) => new CompoundStructureDescriptor(value), #if REVIT2024_OR_GREATER EvaluatedParameter value when type is null || type == typeof(EvaluatedParameter) => new EvaluatedParameterDescriptor(value), #endif diff --git a/source/RevitLookup/Core/ComponentModel/Descriptors/CompoundStructureDescriptor.cs b/source/RevitLookup/Core/ComponentModel/Descriptors/CompoundStructureDescriptor.cs new file mode 100644 index 00000000..8f419b72 --- /dev/null +++ b/source/RevitLookup/Core/ComponentModel/Descriptors/CompoundStructureDescriptor.cs @@ -0,0 +1,292 @@ +// Copyright 2003-2024 by Autodesk, Inc. +// +// Permission to use, copy, modify, and distribute this software in +// object code form for any purpose and without fee is hereby granted, +// provided that the above copyright notice appears in all copies and +// that both that copyright notice and the limited warranty and +// restricted rights notice below appear in all supporting +// documentation. +// +// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. +// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF +// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. +// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE +// UNINTERRUPTED OR ERROR FREE. +// +// Use, duplication, or disclosure by the U.S. Government is subject to +// restrictions set forth in FAR 52.227-19 (Commercial Computer +// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) +// (Rights in Technical Data and Computer Software), as applicable. + +using System.Reflection; + +namespace RevitLookup.Core.ComponentModel.Descriptors; + +public class CompoundStructureDescriptor(CompoundStructure compoundStructure) : Descriptor, IDescriptorResolver +{ + public Func Resolve(Document context, string target, ParameterInfo[] parameters) + { + return target switch + { + nameof(CompoundStructure.CanLayerBeStructuralMaterial) => ResolveCanLayerBeStructuralMaterial, + nameof(CompoundStructure.CanLayerBeVariable) => ResolveCanLayerBeVariable, + nameof(CompoundStructure.CanLayerWidthBeNonZero) => ResolveCanLayerWidthBeNonZero, + nameof(CompoundStructure.GetAdjacentRegions) => ResolveGetAdjacentRegions, + nameof(CompoundStructure.GetCoreBoundaryLayerIndex) => ResolveGetCoreBoundaryLayerIndex, + nameof(CompoundStructure.GetDeckEmbeddingType) => ResolveGetDeckEmbeddingType, + nameof(CompoundStructure.GetDeckProfileId) => ResolveGetDeckProfileId, + nameof(CompoundStructure.GetLayerAssociatedToRegion) => ResolveGetLayerAssociatedToRegion, + nameof(CompoundStructure.GetLayerFunction) => ResolveGetLayerFunction, + nameof(CompoundStructure.GetLayerWidth) => ResolveGetLayerWidth, + nameof(CompoundStructure.GetMaterialId) => ResolveGetMaterialId, + nameof(CompoundStructure.GetNumberOfShellLayers) => ResolveGetNumberOfShellLayers, + nameof(CompoundStructure.GetOffsetForLocationLine) => ResolveGetOffsetForLocationLine, + nameof(CompoundStructure.GetPreviousNonZeroLayerIndex) => ResolveGetPreviousNonZeroLayerIndex, + nameof(CompoundStructure.GetRegionEnvelope) => ResolveGetRegionEnvelope, + nameof(CompoundStructure.GetRegionsAssociatedToLayer) => ResolveGetRegionsAssociatedToLayer, + nameof(CompoundStructure.GetSegmentCoordinate) => ResolveGetSegmentCoordinate, + nameof(CompoundStructure.GetSegmentOrientation) => ResolveGetSegmentOrientation, + _ => null + }; + + IVariants ResolveCanLayerBeStructuralMaterial() + { + var layerCount = compoundStructure.LayerCount; + var variants = new Variants(layerCount); + for (var i = 0; i < layerCount; i++) + { + var result = compoundStructure.CanLayerBeStructuralMaterial(i); + variants.Add(result, $"Layer {i}: {result}"); + } + + return variants; + } + + IVariants ResolveCanLayerBeVariable() + { + var layerCount = compoundStructure.LayerCount; + var variants = new Variants(layerCount); + for (var i = 0; i < layerCount; i++) + { + var result = compoundStructure.CanLayerBeVariable(i); + variants.Add(result, $"Layer {i}: {result}"); + } + + return variants; + } + + IVariants ResolveCanLayerWidthBeNonZero() + { + var layerCount = compoundStructure.LayerCount; + var variants = new Variants(layerCount); + for (var i = 0; i < layerCount; i++) + { + var result = compoundStructure.CanLayerWidthBeNonZero(i); + variants.Add(result, $"Layer {i}: {result}"); + } + return variants; + } + + IVariants ResolveGetAdjacentRegions() + { + var regionsCount = compoundStructure.GetRegionIds().Count; + var variants = new Variants>(regionsCount); + + for (var i = 0; i < regionsCount; i++) + { + var result = compoundStructure.GetAdjacentRegions(i); + variants.Add(result, $"Region" + + $" {i}"); + } + + return variants; + } + + IVariants ResolveGetCoreBoundaryLayerIndex() + { + var values = Enum.GetValues(typeof(ShellLayerType)); + var variants = new Variants(values.Length); + + foreach (ShellLayerType value in values) + { + var result = compoundStructure.GetCoreBoundaryLayerIndex(value); + variants.Add(result, $"{value.ToString()}: {result}"); + } + + return variants; + } + + IVariants ResolveGetDeckEmbeddingType() + { + var layerCount = compoundStructure.LayerCount; + var variants = new Variants(layerCount); + for (var i = 0; i < layerCount; i++) + { + var result = compoundStructure.GetDeckEmbeddingType(i); + variants.Add(result, $"Layer {i}: {result}"); + } + + return variants; + } + + IVariants ResolveGetLayerAssociatedToRegion() + { + var regionsCount = compoundStructure.GetRegionIds().Count; + var variants = new Variants(regionsCount); + + for (var i = 0; i < regionsCount; i++) + { + var result = compoundStructure.GetLayerAssociatedToRegion(i); + variants.Add(result, $"Region {i}: {result}"); + } + + return variants; + } + + IVariants ResolveGetLayerFunction() + { + var layerCount = compoundStructure.LayerCount; + var variants = new Variants(layerCount); + for (var i = 0; i < layerCount; i++) + { + var result = compoundStructure.GetLayerFunction(i); + variants.Add(result, $"Layer {i}: {result}"); + } + + return variants; + } + + IVariants ResolveGetDeckProfileId() + { + var layerCount = compoundStructure.LayerCount; + var variants = new Variants(layerCount); + for (var i = 0; i < layerCount; i++) + { + var result = compoundStructure.GetDeckProfileId(i); + variants.Add(result, $"Layer {i}: {result}"); + } + + return variants; + } + + IVariants ResolveGetLayerWidth() + { + var layerCount = compoundStructure.LayerCount; + var variants = new Variants(layerCount); + for (var i = 0; i < layerCount; i++) + { + var result = compoundStructure.GetLayerWidth(i); + variants.Add(result, $"Layer {i}: {result}"); + } + + return variants; + } + + IVariants ResolveGetMaterialId() + { + var layerCount = compoundStructure.LayerCount; + var variants = new Variants(layerCount); + for (var i = 0; i < layerCount; i++) + { + var result = compoundStructure.GetMaterialId(i); + variants.Add(result, $"Layer {i}: {result}"); + } + + return variants; + } + + IVariants ResolveGetNumberOfShellLayers() + { + var values = Enum.GetValues(typeof(ShellLayerType)); + var variants = new Variants(values.Length); + + foreach (ShellLayerType value in values) + { + var result = compoundStructure.GetNumberOfShellLayers(value); + variants.Add(result, $"{value.ToString()}: {result}"); + } + + return variants; + } + + IVariants ResolveGetOffsetForLocationLine() + { + var values = Enum.GetValues(typeof(WallLocationLine)); + var variants = new Variants(values.Length); + + foreach (WallLocationLine value in values) + { + var result = compoundStructure.GetOffsetForLocationLine(value); + variants.Add(result, $"{value.ToString()}: {result}"); + } + + return variants; + } + + IVariants ResolveGetPreviousNonZeroLayerIndex() + { + var layerCount = compoundStructure.LayerCount; + var variants = new Variants(layerCount); + for (var i = 0; i < layerCount; i++) + { + var result = compoundStructure.GetPreviousNonZeroLayerIndex(i); + variants.Add(result, $"Layer {i}: {result}"); + } + + return variants; + } + + IVariants ResolveGetRegionEnvelope() + { + var regionsCount = compoundStructure.GetRegionIds().Count; + var variants = new Variants(regionsCount); + + for (var i = 0; i < regionsCount; i++) + { + var result = compoundStructure.GetRegionEnvelope(i); + variants.Add(result, $"Region {i}: {result}"); + } + + return variants; + } + + IVariants ResolveGetRegionsAssociatedToLayer() + { + var layerCount = compoundStructure.LayerCount; + var variants = new Variants>(layerCount); + for (var i = 0; i < layerCount; i++) + { + var result = compoundStructure.GetRegionsAssociatedToLayer(i); + variants.Add(result, $"Layer {i}"); + } + + return variants; + } + + IVariants ResolveGetSegmentCoordinate() + { + var segmentCount = compoundStructure.GetSegmentIds().Count; + var variants = new Variants(segmentCount); + for (var i = 0; i < segmentCount; i++) + { + var result = compoundStructure.GetSegmentCoordinate(i); + variants.Add(result, $"Segment {i}: {result}"); + } + + return variants; + } + + IVariants ResolveGetSegmentOrientation() + { + var segmentCount = compoundStructure.GetSegmentIds().Count; + var variants = new Variants(segmentCount); + for (var i = 0; i < segmentCount; i++) + { + var result = compoundStructure.GetSegmentOrientation(i); + variants.Add(result, $"Segment {i}: {result}"); + } + + return variants; + } + } +} \ No newline at end of file