diff --git a/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs b/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs index 3142762e..b7817f08 100644 --- a/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs +++ b/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs @@ -112,6 +112,8 @@ public static Descriptor FindDescriptor(object obj, Type type) AssetProperty value when type is null || type == typeof(AssetProperty) => new AssetPropertyDescriptor(value), BasePoint value when type == typeof(BasePoint) => new BasePointDescriptor(value), InternalOrigin value when type == typeof(InternalOrigin) => new InternalOriginDescriptor(value), + View value when type == typeof(View) => new ViewDescriptor(value), + ScheduleDefinition value when type == typeof(ScheduleDefinition) => new ScheduleDefinitionDescriptor(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/ScheduleDefinitionDescriptor.cs b/source/RevitLookup/Core/ComponentModel/Descriptors/ScheduleDefinitionDescriptor.cs new file mode 100644 index 00000000..c763ef64 --- /dev/null +++ b/source/RevitLookup/Core/ComponentModel/Descriptors/ScheduleDefinitionDescriptor.cs @@ -0,0 +1,210 @@ +// 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 ScheduleDefinitionDescriptor(ScheduleDefinition scheduleDefinition) : Descriptor, IDescriptorResolver +{ + public ResolveSet Resolve(Document context, string target, ParameterInfo[] parameters) + { + return target switch + { + nameof(ScheduleDefinition.CanFilterByGlobalParameters) => ResolveFilterByGlobalParameters(), + nameof(ScheduleDefinition.CanFilterByParameterExistence) => ResolveFilterByParameterExistence(), + nameof(ScheduleDefinition.CanFilterBySubstring) => ResolveFilterBySubstring(), + nameof(ScheduleDefinition.CanFilterByValue) => ResolveFilterByValue(), + nameof(ScheduleDefinition.CanFilterByValuePresence) => ResolveFilterByValuePresence(), + nameof(ScheduleDefinition.CanSortByField) => ResolveSortByField(), + nameof(ScheduleDefinition.GetField) => ResolveGetField(), + nameof(ScheduleDefinition.GetFieldId) => ResolveGetFieldId(), + nameof(ScheduleDefinition.GetFieldIndex) => ResolveGetFieldIndex(), + nameof(ScheduleDefinition.GetFilter) => ResolveGetFilter(), + nameof(ScheduleDefinition.GetSortGroupField) => ResolveGetSortGroupField(), + nameof(ScheduleDefinition.IsValidCategoryForEmbeddedSchedule) => ResolveValidCategoryForEmbeddedSchedule(), + _ => null + }; + + ResolveSet ResolveFilterByGlobalParameters() + { + var fields = scheduleDefinition.GetFieldOrder(); + var resolveSummary = new ResolveSet(fields.Count); + foreach (var field in fields) + { + var result = scheduleDefinition.CanFilterByGlobalParameters(field); + var name = scheduleDefinition.GetField(field).GetName(); + resolveSummary.AppendVariant(result, $"{name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveFilterByParameterExistence() + { + var fields = scheduleDefinition.GetFieldOrder(); + var resolveSummary = new ResolveSet(fields.Count); + foreach (var field in fields) + { + var result = scheduleDefinition.CanFilterByParameterExistence(field); + var name = scheduleDefinition.GetField(field).GetName(); + resolveSummary.AppendVariant(result, $"{name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveFilterBySubstring() + { + var fields = scheduleDefinition.GetFieldOrder(); + var resolveSummary = new ResolveSet(fields.Count); + foreach (var field in fields) + { + var result = scheduleDefinition.CanFilterBySubstring(field); + var name = scheduleDefinition.GetField(field).GetName(); + resolveSummary.AppendVariant(result, $"{name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveFilterByValue() + { + var fields = scheduleDefinition.GetFieldOrder(); + var resolveSummary = new ResolveSet(fields.Count); + foreach (var field in fields) + { + var result = scheduleDefinition.CanFilterByValue(field); + var name = scheduleDefinition.GetField(field).GetName(); + resolveSummary.AppendVariant(result, $"{name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveFilterByValuePresence() + { + var fields = scheduleDefinition.GetFieldOrder(); + var resolveSummary = new ResolveSet(fields.Count); + foreach (var field in fields) + { + var result = scheduleDefinition.CanFilterByValuePresence(field); + var name = scheduleDefinition.GetField(field).GetName(); + resolveSummary.AppendVariant(result, $"{name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveSortByField() + { + var fields = scheduleDefinition.GetFieldOrder(); + var resolveSummary = new ResolveSet(fields.Count); + foreach (var field in fields) + { + var result = scheduleDefinition.CanSortByField(field); + var name = scheduleDefinition.GetField(field).GetName(); + resolveSummary.AppendVariant(result, $"{name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveGetField() + { + var fields = scheduleDefinition.GetFieldOrder(); + var resolveSummary = new ResolveSet(fields.Count); + foreach (var field in fields) + { + var result = scheduleDefinition.GetField(field); + resolveSummary.AppendVariant(result, $"{result.GetName()}"); + } + + return resolveSummary; + } + + ResolveSet ResolveGetFieldId() + { + var fields = scheduleDefinition.GetFieldOrder(); + var resolveSummary = new ResolveSet(fields.Count); + foreach (var field in fields) + { + var result = scheduleDefinition.GetFieldId(field.IntegerValue); + var name = scheduleDefinition.GetField(field).GetName(); + resolveSummary.AppendVariant(result, $"{name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveGetFieldIndex() + { + var fields = scheduleDefinition.GetFieldOrder(); + var resolveSummary = new ResolveSet(fields.Count); + foreach (var field in fields) + { + var result = scheduleDefinition.GetFieldIndex(field); + var name = scheduleDefinition.GetField(field).GetName(); + resolveSummary.AppendVariant(result, $"{name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveGetFilter() + { + var count = scheduleDefinition.GetFilterCount(); + var resolveSummary = new ResolveSet(count); + for (var i = 0; i < count; i++) + { + resolveSummary.AppendVariant(scheduleDefinition.GetFilter(i)); + } + + return resolveSummary; + } + + ResolveSet ResolveGetSortGroupField() + { + var count = scheduleDefinition.GetSortGroupFieldCount(); + var resolveSummary = new ResolveSet(count); + for (var i = 0; i < count; i++) + { + resolveSummary.AppendVariant(scheduleDefinition.GetSortGroupField(i)); + } + + return resolveSummary; + } + + ResolveSet ResolveValidCategoryForEmbeddedSchedule() + { + var categories = context.Settings.Categories; + var resolveSummary = new ResolveSet(categories.Size); + foreach (Category category in categories) + { + if (scheduleDefinition.IsValidCategoryForEmbeddedSchedule(category.Id)) + resolveSummary.AppendVariant(true, category.Name); + } + + return resolveSummary; + } + } +} \ No newline at end of file diff --git a/source/RevitLookup/Core/ComponentModel/Descriptors/ScemaDescriptor.cs b/source/RevitLookup/Core/ComponentModel/Descriptors/SchemaDescriptor.cs similarity index 100% rename from source/RevitLookup/Core/ComponentModel/Descriptors/ScemaDescriptor.cs rename to source/RevitLookup/Core/ComponentModel/Descriptors/SchemaDescriptor.cs diff --git a/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs b/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs new file mode 100644 index 00000000..f6f1bf77 --- /dev/null +++ b/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs @@ -0,0 +1,268 @@ +// 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 ViewDescriptor(View view) : Descriptor, IDescriptorResolver +{ + public ResolveSet Resolve(Document context, string target, ParameterInfo[] parameters) + { + return target switch + { + nameof(View.CanCategoryBeHidden) => ResolveCanCategoryBeHidden(), + nameof(View.CanCategoryBeHiddenTemporary) => ResolveCanCategoryBeHiddenTemporary(), + nameof(View.CanViewBeDuplicated) => ResolveCanViewBeDuplicated(), + nameof(View.GetCategoryHidden) => ResolveCategoryHidden(), + nameof(View.GetCategoryOverrides) => ResolveCategoryOverrides(), + nameof(View.GetIsFilterEnabled) => ResolveFilterEnabled(), + nameof(View.GetFilterOverrides) => ResolveFilterOverrides(), + nameof(View.GetFilterVisibility) => ResolveFilterVisibility(), + nameof(View.GetWorksetVisibility) => ResolveWorksetVisibility(), + nameof(View.IsCategoryOverridable) => ResolveIsCategoryOverridable(), + nameof(View.IsFilterApplied) => ResolveIsFilterApplied(), + nameof(View.IsInTemporaryViewMode) => ResolveIsInTemporaryViewMode(), + nameof(View.IsValidViewTemplate) => ResolveIsValidViewTemplate(), + nameof(View.IsWorksetVisible) => ResolveIsWorksetVisible(), + nameof(View.SupportsWorksharingDisplayMode) => ResolveSupportsWorksharingDisplayMode(), +#if REVIT2022_OR_GREATER + nameof(View.GetColorFillSchemeId) => ResolveColorFillSchemeId(), +#endif + _ => null + }; + + ResolveSet ResolveCanCategoryBeHidden() + { + var categories = context.Settings.Categories; + var resolveSummary = new ResolveSet(categories.Size); + foreach (Category category in categories) + { + var result = view.CanCategoryBeHidden(category.Id); + resolveSummary.AppendVariant(result, $"{category.Name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveCanCategoryBeHiddenTemporary() + { + var categories = context.Settings.Categories; + var resolveSummary = new ResolveSet(categories.Size); + foreach (Category category in categories) + { + var result = view.CanCategoryBeHiddenTemporary(category.Id); + resolveSummary.AppendVariant(result, $"{category.Name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveCanViewBeDuplicated() + { + var values = Enum.GetValues(typeof(ViewDuplicateOption)); + var resolveSummary = new ResolveSet(values.Length); + + foreach (ViewDuplicateOption option in values) + { + resolveSummary.AppendVariant(view.CanViewBeDuplicated(option), option.ToString()); + } + + return resolveSummary; + } + + ResolveSet ResolveCategoryHidden() + { + var categories = context.Settings.Categories; + var resolveSummary = new ResolveSet(categories.Size); + foreach (Category category in categories) + { + var result = view.GetCategoryHidden(category.Id); + resolveSummary.AppendVariant(result, $"{category.Name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveCategoryOverrides() + { + var categories = context.Settings.Categories; + var resolveSummary = new ResolveSet(categories.Size); + foreach (Category category in categories) + { + var result = view.GetCategoryOverrides(category.Id); + resolveSummary.AppendVariant(result, category.Name); + } + + return resolveSummary; + } + + ResolveSet ResolveIsCategoryOverridable() + { + var categories = context.Settings.Categories; + var resolveSummary = new ResolveSet(categories.Size); + foreach (Category category in categories) + { + var result = view.IsCategoryOverridable(category.Id); + resolveSummary.AppendVariant(result, category.Name); + } + + return resolveSummary; + } + + ResolveSet ResolveFilterOverrides() + { + var filters = view.GetFilters(); + var resolveSummary = new ResolveSet(filters.Count); + foreach (var filterId in filters) + { + var filter = filterId.ToElement(context)!; + var result = view.GetFilterOverrides(filterId); + resolveSummary.AppendVariant(result, filter.Name); + } + + return resolveSummary; + } + + ResolveSet ResolveFilterVisibility() + { + var filters = view.GetFilters(); + var resolveSummary = new ResolveSet(filters.Count); + foreach (var filterId in filters) + { + var filter = filterId.ToElement(context)!; + var result = view.GetFilterVisibility(filterId); + resolveSummary.AppendVariant(result, $"{filter.Name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveFilterEnabled() + { + var filters = view.GetFilters(); + var resolveSummary = new ResolveSet(filters.Count); + foreach (var filterId in filters) + { + var filter = filterId.ToElement(context)!; + var result = view.GetIsFilterEnabled(filterId); + resolveSummary.AppendVariant(result, $"{filter.Name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveIsFilterApplied() + { + var filters = view.GetFilters(); + var resolveSummary = new ResolveSet(filters.Count); + foreach (var filterId in filters) + { + var filter = filterId.ToElement(context)!; + var result = view.IsFilterApplied(filterId); + resolveSummary.AppendVariant(result, $"{filter.Name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveIsInTemporaryViewMode() + { + var values = Enum.GetValues(typeof(TemporaryViewMode)); + var resolveSummary = new ResolveSet(values.Length); + + foreach (TemporaryViewMode mode in values) + { + resolveSummary.AppendVariant(view.IsInTemporaryViewMode(mode), mode.ToString()); + } + + return resolveSummary; + } + + ResolveSet ResolveIsValidViewTemplate() + { + var templates = context.EnumerateInstances().Where(x => x.IsTemplate).ToArray(); + var resolveSummary = new ResolveSet(templates.Length); + foreach (var template in templates) + { + var result = view.IsValidViewTemplate(template.Id); + resolveSummary.AppendVariant(result, $"{template.Name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveIsWorksetVisible() + { + var workSets = new FilteredWorksetCollector(context).OfKind(WorksetKind.UserWorkset).ToWorksets(); + var resolveSummary = new ResolveSet(workSets.Count); + foreach (var workSet in workSets) + { + var result = view.IsWorksetVisible(workSet.Id); + resolveSummary.AppendVariant(result, $"{workSet.Name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveWorksetVisibility() + { + var workSets = new FilteredWorksetCollector(context).OfKind(WorksetKind.UserWorkset).ToWorksets(); + var resolveSummary = new ResolveSet(workSets.Count); + foreach (var workSet in workSets) + { + var result = view.GetWorksetVisibility(workSet.Id); + resolveSummary.AppendVariant(result, $"{workSet.Name}: {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveSupportsWorksharingDisplayMode() + { + var values = Enum.GetValues(typeof(WorksharingDisplayMode)); + var resolveSummary = new ResolveSet(values.Length); + + foreach (WorksharingDisplayMode mode in values) + { + resolveSummary.AppendVariant(view.SupportsWorksharingDisplayMode(mode), mode.ToString()); + } + + return resolveSummary; + } +#if REVIT2022_OR_GREATER + + ResolveSet ResolveColorFillSchemeId() + { + var categories = context.Settings.Categories; + var resolveSummary = new ResolveSet(categories.Size); + foreach (Category category in categories) + { + var result = view.GetColorFillSchemeId(category.Id); + resolveSummary.AppendVariant(result, category.Name); + } + + return resolveSummary; + } +#endif + } +} \ No newline at end of file