From 63f84ab1ad9224ceb5b8c4ef5b2066e31e811104 Mon Sep 17 00:00:00 2001 From: SergeyNefyodov Date: Mon, 15 Apr 2024 17:53:14 +0200 Subject: [PATCH 1/7] Add support to View class methods --- .../Core/ComponentModel/DescriptorMap.cs | 1 + .../Descriptors/ViewDescriptor.cs | 152 ++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs diff --git a/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs b/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs index 3142762e..505349cd 100644 --- a/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs +++ b/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs @@ -112,6 +112,7 @@ 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), #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/ViewDescriptor.cs b/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs new file mode 100644 index 00000000..d2888b20 --- /dev/null +++ b/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs @@ -0,0 +1,152 @@ +// 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.GetCategoryHidden) => ResolveCategoryHidden(), + nameof(View.GetCategoryOverrides) => ResolveCategoryOverrides(), + nameof(View.GetIsFilterEnabled) => ResolveFilterEnabled(), + nameof(View.GetFilterOverrides) => ResolveFilterOverrides(), + nameof(View.GetFilterVisibility) => ResolveFilterVisibility(), + nameof(View.GetWorksetVisibility) => ResolveWorksetVisibility(), +#if REVIT2022_OR_GREATER + nameof(View.GetColorFillSchemeId) => ResolveColorFillSchemeId(), +#endif + _ => null + }; + + ResolveSet ResolveCategoryHidden() + { + var values = context.Settings.Categories; + var resolveSummary = new ResolveSet(values.Size); + foreach (Category value in values) + { + if (value is null || !value.IsVisibleInUI) continue; + var id = value.Id; + var name = value.Name; + var result = view.GetCategoryHidden(id); + resolveSummary.AppendVariant(result, $"{name}, {result}"); + } + + return resolveSummary; + } + + ResolveSet ResolveCategoryOverrides() + { + var values = context.Settings.Categories; + var resolveSummary = new ResolveSet(values.Size); + foreach (Category value in values) + { + if (value is null || !value.IsVisibleInUI) continue; + var id = value.Id; + var name = value.Name; + var result = view.GetCategoryOverrides(id); + resolveSummary.AppendVariant(result, $"Settings: {name}"); + } + + return resolveSummary; + } + + ResolveSet ResolveFilterOverrides() + { + var values = view.GetFilters(); + var resolveSummary = new ResolveSet(values.Count); + foreach (var id in values) + { + var name = id.ToElement(context)!.Name; + var result = view.GetFilterOverrides(id); + resolveSummary.AppendVariant(result, $"Filter: {name}"); + } + + return resolveSummary; + } + + ResolveSet ResolveFilterVisibility() + { + var values = view.GetFilters(); + var resolveSummary = new ResolveSet(values.Count); + foreach (var id in values) + { + var name = id.ToElement(context)!.Name; + var result = view.GetFilterVisibility(id); + resolveSummary.AppendVariant(result, $"Filter: {name}"); + } + + return resolveSummary; + } + + ResolveSet ResolveFilterEnabled() + { + var values = view.GetFilters(); + var resolveSummary = new ResolveSet(values.Count); + foreach (var id in values) + { + var name = id.ToElement(context)!.Name; + var result = view.GetIsFilterEnabled(id); + resolveSummary.AppendVariant(result, $"Filter: {name}"); + } + + return resolveSummary; + } + + ResolveSet ResolveWorksetVisibility() + { + if (!context.IsWorkshared) + return new ResolveSet().AppendVariant("The document is not workshared"); + var workSets = new FilteredWorksetCollector(Context.Document).OfKind(WorksetKind.UserWorkset).ToWorksets(); + var resolveSummary = new ResolveSet(workSets.Count); + foreach (var workSet in workSets) + { + var name = workSet.Name; + var result = view.GetWorksetVisibility(workSet.Id); + resolveSummary.AppendVariant(result, $"Workset: {name}"); + } + + return resolveSummary; + } +#if REVIT2022_OR_GREATER + ResolveSet ResolveColorFillSchemeId() + { + var values = context.Settings.Categories; + var resolveSummary = new ResolveSet(values.Size); + foreach (Category value in values) + { + if (value is null || !value.IsVisibleInUI) continue; + var id = value.Id; + var name = value.Name; + var result = view.GetColorFillSchemeId(id); + resolveSummary.AppendVariant(result, $"{name}, ColorFillScheme: {result}"); + } + + return resolveSummary; + } +#endif + } +} \ No newline at end of file From b401b75df26bfd5a49cb5d9e1343510021218bec Mon Sep 17 00:00:00 2001 From: Nice3point Date: Thu, 18 Apr 2024 14:03:30 +0300 Subject: [PATCH 2/7] Cleanup --- .../Descriptors/ViewDescriptor.cs | 91 +++++++++---------- 1 file changed, 43 insertions(+), 48 deletions(-) diff --git a/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs b/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs index d2888b20..1901175c 100644 --- a/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs +++ b/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs @@ -44,31 +44,29 @@ public ResolveSet Resolve(Document context, string target, ParameterInfo[] param ResolveSet ResolveCategoryHidden() { - var values = context.Settings.Categories; - var resolveSummary = new ResolveSet(values.Size); - foreach (Category value in values) + var categories = context.Settings.Categories; + var resolveSummary = new ResolveSet(categories.Size); + foreach (Category category in categories) { - if (value is null || !value.IsVisibleInUI) continue; - var id = value.Id; - var name = value.Name; - var result = view.GetCategoryHidden(id); - resolveSummary.AppendVariant(result, $"{name}, {result}"); + if (!category.IsVisibleInUI) continue; + + var result = view.GetCategoryHidden(category.Id); + resolveSummary.AppendVariant(result, $"{category.Name}: {result}"); } - + return resolveSummary; } ResolveSet ResolveCategoryOverrides() { - var values = context.Settings.Categories; - var resolveSummary = new ResolveSet(values.Size); - foreach (Category value in values) + var categories = context.Settings.Categories; + var resolveSummary = new ResolveSet(categories.Size); + foreach (Category category in categories) { - if (value is null || !value.IsVisibleInUI) continue; - var id = value.Id; - var name = value.Name; - var result = view.GetCategoryOverrides(id); - resolveSummary.AppendVariant(result, $"Settings: {name}"); + if (!category.IsVisibleInUI) continue; + + var result = view.GetCategoryOverrides(category.Id); + resolveSummary.AppendVariant(result, category.Name); } return resolveSummary; @@ -76,13 +74,13 @@ ResolveSet ResolveCategoryOverrides() ResolveSet ResolveFilterOverrides() { - var values = view.GetFilters(); - var resolveSummary = new ResolveSet(values.Count); - foreach (var id in values) + var filters = view.GetFilters(); + var resolveSummary = new ResolveSet(filters.Count); + foreach (var filterId in filters) { - var name = id.ToElement(context)!.Name; - var result = view.GetFilterOverrides(id); - resolveSummary.AppendVariant(result, $"Filter: {name}"); + var filter = filterId.ToElement(context)!; + var result = view.GetFilterOverrides(filterId); + resolveSummary.AppendVariant(result, filter.Name); } return resolveSummary; @@ -90,13 +88,13 @@ ResolveSet ResolveFilterOverrides() ResolveSet ResolveFilterVisibility() { - var values = view.GetFilters(); - var resolveSummary = new ResolveSet(values.Count); - foreach (var id in values) + var filters = view.GetFilters(); + var resolveSummary = new ResolveSet(filters.Count); + foreach (var filterId in filters) { - var name = id.ToElement(context)!.Name; - var result = view.GetFilterVisibility(id); - resolveSummary.AppendVariant(result, $"Filter: {name}"); + var filter = filterId.ToElement(context)!; + var result = view.GetFilterVisibility(filterId); + resolveSummary.AppendVariant(result, $"{filter.Name}: {result}"); } return resolveSummary; @@ -104,13 +102,13 @@ ResolveSet ResolveFilterVisibility() ResolveSet ResolveFilterEnabled() { - var values = view.GetFilters(); - var resolveSummary = new ResolveSet(values.Count); - foreach (var id in values) + var filters = view.GetFilters(); + var resolveSummary = new ResolveSet(filters.Count); + foreach (var filterId in filters) { - var name = id.ToElement(context)!.Name; - var result = view.GetIsFilterEnabled(id); - resolveSummary.AppendVariant(result, $"Filter: {name}"); + var filter = filterId.ToElement(context)!; + var result = view.GetIsFilterEnabled(filterId); + resolveSummary.AppendVariant(result, $"{filter.Name}: {result}"); } return resolveSummary; @@ -118,31 +116,28 @@ ResolveSet ResolveFilterEnabled() ResolveSet ResolveWorksetVisibility() { - if (!context.IsWorkshared) - return new ResolveSet().AppendVariant("The document is not workshared"); var workSets = new FilteredWorksetCollector(Context.Document).OfKind(WorksetKind.UserWorkset).ToWorksets(); var resolveSummary = new ResolveSet(workSets.Count); foreach (var workSet in workSets) { - var name = workSet.Name; var result = view.GetWorksetVisibility(workSet.Id); - resolveSummary.AppendVariant(result, $"Workset: {name}"); + resolveSummary.AppendVariant(result, $"{workSet.Name}: {result}"); } return resolveSummary; } -#if REVIT2022_OR_GREATER +#if REVIT2022_OR_GREATER + ResolveSet ResolveColorFillSchemeId() { - var values = context.Settings.Categories; - var resolveSummary = new ResolveSet(values.Size); - foreach (Category value in values) + var categories = context.Settings.Categories; + var resolveSummary = new ResolveSet(categories.Size); + foreach (Category category in categories) { - if (value is null || !value.IsVisibleInUI) continue; - var id = value.Id; - var name = value.Name; - var result = view.GetColorFillSchemeId(id); - resolveSummary.AppendVariant(result, $"{name}, ColorFillScheme: {result}"); + if (!category.IsVisibleInUI) continue; + + var result = view.GetColorFillSchemeId(category.Id); + resolveSummary.AppendVariant(result, category.Name); } return resolveSummary; From 7aec1289ccc2f5044dfda62d48a62dec50db5577 Mon Sep 17 00:00:00 2001 From: SergeyNefyodov Date: Thu, 18 Apr 2024 17:25:30 +0200 Subject: [PATCH 3/7] Add support to View class methods --- .../Descriptors/ViewDescriptor.cs | 76 ++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs b/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs index 1901175c..dc51d9db 100644 --- a/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs +++ b/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs @@ -36,6 +36,11 @@ public ResolveSet Resolve(Document context, string target, ParameterInfo[] param 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(), #if REVIT2022_OR_GREATER nameof(View.GetColorFillSchemeId) => ResolveColorFillSchemeId(), #endif @@ -72,6 +77,21 @@ ResolveSet ResolveCategoryOverrides() return resolveSummary; } + ResolveSet ResolveIsCategoryOverridable() + { + var categories = context.Settings.Categories; + var resolveSummary = new ResolveSet(categories.Size); + foreach (Category category in categories) + { + if (!category.IsVisibleInUI) continue; + + var result = view.IsCategoryOverridable(category.Id); + resolveSummary.AppendVariant(result, category.Name); + } + + return resolveSummary; + } + ResolveSet ResolveFilterOverrides() { var filters = view.GetFilters(); @@ -114,9 +134,63 @@ ResolveSet ResolveFilterEnabled() 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.Document).OfKind(WorksetKind.UserWorkset).ToWorksets(); + var workSets = new FilteredWorksetCollector(context).OfKind(WorksetKind.UserWorkset).ToWorksets(); var resolveSummary = new ResolveSet(workSets.Count); foreach (var workSet in workSets) { From f26a18a464dcfe2ddc04de208ba72b1a7cf6cf31 Mon Sep 17 00:00:00 2001 From: SergeyNefyodov Date: Fri, 19 Apr 2024 20:17:45 +0200 Subject: [PATCH 4/7] Cleanup excessive checks in ViewDescriptor class --- .../Core/ComponentModel/Descriptors/ViewDescriptor.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs b/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs index dc51d9db..99d49519 100644 --- a/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs +++ b/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs @@ -53,8 +53,6 @@ ResolveSet ResolveCategoryHidden() var resolveSummary = new ResolveSet(categories.Size); foreach (Category category in categories) { - if (!category.IsVisibleInUI) continue; - var result = view.GetCategoryHidden(category.Id); resolveSummary.AppendVariant(result, $"{category.Name}: {result}"); } @@ -68,8 +66,6 @@ ResolveSet ResolveCategoryOverrides() var resolveSummary = new ResolveSet(categories.Size); foreach (Category category in categories) { - if (!category.IsVisibleInUI) continue; - var result = view.GetCategoryOverrides(category.Id); resolveSummary.AppendVariant(result, category.Name); } @@ -83,8 +79,6 @@ ResolveSet ResolveIsCategoryOverridable() var resolveSummary = new ResolveSet(categories.Size); foreach (Category category in categories) { - if (!category.IsVisibleInUI) continue; - var result = view.IsCategoryOverridable(category.Id); resolveSummary.AppendVariant(result, category.Name); } @@ -208,8 +202,6 @@ ResolveSet ResolveColorFillSchemeId() var resolveSummary = new ResolveSet(categories.Size); foreach (Category category in categories) { - if (!category.IsVisibleInUI) continue; - var result = view.GetColorFillSchemeId(category.Id); resolveSummary.AppendVariant(result, category.Name); } From 7ae570c2289e131554189951514916f7498570ff Mon Sep 17 00:00:00 2001 From: SergeyNefyodov Date: Sat, 20 Apr 2024 12:05:12 +0200 Subject: [PATCH 5/7] Add support to View class methods --- .../Descriptors/ViewDescriptor.cs | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs b/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs index 99d49519..f6f1bf77 100644 --- a/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs +++ b/source/RevitLookup/Core/ComponentModel/Descriptors/ViewDescriptor.cs @@ -30,6 +30,9 @@ public ResolveSet Resolve(Document context, string target, ParameterInfo[] param { 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(), @@ -41,12 +44,52 @@ public ResolveSet Resolve(Document context, string target, ParameterInfo[] param 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; @@ -142,7 +185,6 @@ ResolveSet ResolveIsFilterApplied() return resolveSummary; } - ResolveSet ResolveIsInTemporaryViewMode() { var values = Enum.GetValues(typeof(TemporaryViewMode)); @@ -194,6 +236,19 @@ ResolveSet ResolveWorksetVisibility() 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() From b86555aa24c612c5ceb4e013b99dada7459e2ed8 Mon Sep 17 00:00:00 2001 From: SergeyNefyodov Date: Mon, 22 Apr 2024 17:35:10 +0200 Subject: [PATCH 6/7] Add ScheduleDefinition methods support --- .../Core/ComponentModel/DescriptorMap.cs | 1 + .../ScheduleDefinitionDescriptor.cs | 210 ++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 source/RevitLookup/Core/ComponentModel/Descriptors/ScheduleDefinitionDescriptor.cs diff --git a/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs b/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs index 505349cd..b7817f08 100644 --- a/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs +++ b/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs @@ -113,6 +113,7 @@ public static Descriptor FindDescriptor(object obj, Type type) 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 From 5b7b28ae053267dabb6d62ce3387c3001dd17d35 Mon Sep 17 00:00:00 2001 From: SergeyNefyodov Date: Thu, 25 Apr 2024 17:07:28 +0200 Subject: [PATCH 7/7] Fix typo in filename --- .../Descriptors/{ScemaDescriptor.cs => SchemaDescriptor.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename source/RevitLookup/Core/ComponentModel/Descriptors/{ScemaDescriptor.cs => SchemaDescriptor.cs} (100%) 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