diff --git a/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs b/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs index 63b5f1f2..bb2ea247 100644 --- a/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs +++ b/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs @@ -115,6 +115,7 @@ public static Descriptor FindDescriptor(object obj, Type type) View value when type == typeof(View) => new ViewDescriptor(value), ViewSchedule value when type == typeof(ViewSchedule) => new ViewScheduleDescriptor(value), ScheduleDefinition value when type == typeof(ScheduleDefinition) => new ScheduleDefinitionDescriptor(value), + TableData value when type == typeof(TableData) => new TableDataDescriptor(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/TableDataDescriptor.cs b/source/RevitLookup/Core/ComponentModel/Descriptors/TableDataDescriptor.cs new file mode 100644 index 00000000..093d2089 --- /dev/null +++ b/source/RevitLookup/Core/ComponentModel/Descriptors/TableDataDescriptor.cs @@ -0,0 +1,75 @@ +// 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; +using RevitLookup.Core.Contracts; +using RevitLookup.Core.Objects; + +namespace RevitLookup.Core.ComponentModel.Descriptors; + +public class TableDataDescriptor(TableData tableData) : Descriptor, IDescriptorResolver +{ + public ResolveSet Resolve(Document context, string target, ParameterInfo[] parameters) + { + return target switch + { + nameof(TableData.GetSectionData) => ResolveSectionData(), + nameof(TableData.IsValidZoomLevel) => ResolveZoomLevel(), + _ => null + }; + + ResolveSet ResolveSectionData() + { + var sectionTypes = Enum.GetValues(typeof(SectionType)); + var resolveSummary = new ResolveSet(sectionTypes.Length); + foreach (SectionType sectionType in sectionTypes) + { + resolveSummary.AppendVariant(tableData.GetSectionData(sectionType), sectionType.ToString()); + } + + return resolveSummary; + } + + ResolveSet ResolveZoomLevel() + { + var resolveSummary = new ResolveSet(512); + + var zoom = 0; + var emptyIterations = 0; + while (emptyIterations < 50) + { + var isValid = tableData.IsValidZoomLevel(zoom); + if (isValid) + { + resolveSummary.AppendVariant(true, $"{zoom}: valid"); + emptyIterations = 0; + } + else + { + emptyIterations++; + } + + zoom++; + } + + return resolveSummary; + } + } +} \ No newline at end of file