From 9460b5d627a67b3a8ce41b3e0ea7e27dc8054183 Mon Sep 17 00:00:00 2001 From: SergeyNefyodov Date: Sun, 5 May 2024 22:15:07 +0200 Subject: [PATCH 1/2] Add CurveElement support --- .../Core/ComponentModel/DescriptorMap.cs | 1 + .../Descriptors/CurveElementDescriptor.cs | 111 ++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 source/RevitLookup/Core/ComponentModel/Descriptors/CurveElementDescriptor.cs diff --git a/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs b/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs index f2894e4b..3610c3be 100644 --- a/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs +++ b/source/RevitLookup/Core/ComponentModel/DescriptorMap.cs @@ -119,6 +119,7 @@ public static Descriptor FindDescriptor(object obj, Type type) InternalOrigin value when type == typeof(InternalOrigin) => new InternalOriginDescriptor(value), ConnectorManager value when type == typeof(ConnectorManager) => new ConnectorManagerDescriptor(value), Wire value when type == typeof(Wire) => new WireDescriptor(value), + CurveElement value when type == typeof(CurveElement) => new CurveElementDescriptor(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), diff --git a/source/RevitLookup/Core/ComponentModel/Descriptors/CurveElementDescriptor.cs b/source/RevitLookup/Core/ComponentModel/Descriptors/CurveElementDescriptor.cs new file mode 100644 index 00000000..fadb614f --- /dev/null +++ b/source/RevitLookup/Core/ComponentModel/Descriptors/CurveElementDescriptor.cs @@ -0,0 +1,111 @@ +// 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 CurveElementDescriptor(CurveElement curveElement) : Descriptor, IDescriptorResolver +{ + public ResolveSet Resolve(Document context, string target, ParameterInfo[] parameters) + { + return target switch + { + nameof(CurveElement.GetAdjoinedCurveElements) => ResolveSet + .Append(curveElement.GetAdjoinedCurveElements(0), "Point 0") + .AppendVariant(curveElement.GetAdjoinedCurveElements(1), "Point 1"), + nameof(CurveElement.HasTangentLocks) => ResolveSet + .Append(curveElement.HasTangentLocks(0), "Point 0") + .AppendVariant(curveElement.HasTangentLocks(1), "Point 1"), + nameof(CurveElement.GetTangentLock) => ResolveTangentLock(), + nameof(CurveElement.HasTangentJoin) => ResolveTangentJoin(), + nameof(CurveElement.IsAdjoinedCurveElement) => ResolveIsAdjoinedCurveElement(), + _ => null + }; + + ResolveSet ResolveTangentLock() + { + var set0 = curveElement.GetAdjoinedCurveElements(0); + var set1 = curveElement.GetAdjoinedCurveElements(1); + var resolveSummary = new ResolveSet(set0.Count + set1.Count); + + foreach (var id in set0) + { + if (!curveElement.HasTangentJoin(0, id)) continue; + + var result = curveElement.GetTangentLock(0, id); + var element = id.ToElement(context); + resolveSummary.AppendVariant(result, $"Point 0, {element!.Name}: {result}"); + } + + foreach (var id in set1) + { + if (!curveElement.HasTangentJoin(1, id)) continue; + + var result = curveElement.GetTangentLock(1, id); + var element = id.ToElement(context); + resolveSummary.AppendVariant(result, $"Point 1, {element!.Name}: {result}"); + } + return resolveSummary; + } + + ResolveSet ResolveTangentJoin() + { + var set0 = curveElement.GetAdjoinedCurveElements(0); + var set1 = curveElement.GetAdjoinedCurveElements(1); + var resolveSummary = new ResolveSet(set0.Count + set1.Count); + + foreach (var id in set0) + { + var result = curveElement.HasTangentJoin(0, id); + resolveSummary.AppendVariant(result, $"Point 0, {id}: {result}"); + } + + foreach (var id in set1) + { + var result = curveElement.HasTangentJoin(1, id); + resolveSummary.AppendVariant(result, $"Point 1, {id}: {result}"); + } + return resolveSummary; + } + + ResolveSet ResolveIsAdjoinedCurveElement() + { + var set0 = curveElement.GetAdjoinedCurveElements(0); + var set1 = curveElement.GetAdjoinedCurveElements(1); + var resolveSummary = new ResolveSet(set0.Count + set1.Count); + + foreach (var id in set0) + { + var result = curveElement.IsAdjoinedCurveElement(0, id); + resolveSummary.AppendVariant(result, $"Point 0, {id}: {result}"); + } + + foreach (var id in set1) + { + var result = curveElement.IsAdjoinedCurveElement(1, id); + resolveSummary.AppendVariant(result, $"Point 1, {id}: {result}"); + } + return resolveSummary; + } + } +} \ No newline at end of file From f6234bcd58c1c496b04beb6da3d30ffe1f991e6b Mon Sep 17 00:00:00 2001 From: Nice3point Date: Tue, 7 May 2024 19:29:07 +0300 Subject: [PATCH 2/2] Cleanup --- .../Descriptors/CurveElementDescriptor.cs | 69 ++++++++++++------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/source/RevitLookup/Core/ComponentModel/Descriptors/CurveElementDescriptor.cs b/source/RevitLookup/Core/ComponentModel/Descriptors/CurveElementDescriptor.cs index fadb614f..67e82340 100644 --- a/source/RevitLookup/Core/ComponentModel/Descriptors/CurveElementDescriptor.cs +++ b/source/RevitLookup/Core/ComponentModel/Descriptors/CurveElementDescriptor.cs @@ -30,81 +30,100 @@ public ResolveSet Resolve(Document context, string target, ParameterInfo[] param { return target switch { - nameof(CurveElement.GetAdjoinedCurveElements) => ResolveSet - .Append(curveElement.GetAdjoinedCurveElements(0), "Point 0") - .AppendVariant(curveElement.GetAdjoinedCurveElements(1), "Point 1"), - nameof(CurveElement.HasTangentLocks) => ResolveSet - .Append(curveElement.HasTangentLocks(0), "Point 0") - .AppendVariant(curveElement.HasTangentLocks(1), "Point 1"), + nameof(CurveElement.GetAdjoinedCurveElements) => ResolveAdjoinedCurveElements(), + nameof(CurveElement.HasTangentLocks) => ResolveHasTangentLocks(), nameof(CurveElement.GetTangentLock) => ResolveTangentLock(), nameof(CurveElement.HasTangentJoin) => ResolveTangentJoin(), nameof(CurveElement.IsAdjoinedCurveElement) => ResolveIsAdjoinedCurveElement(), _ => null }; + ResolveSet ResolveAdjoinedCurveElements() + { + var resolveSet = new ResolveSet(2); + var startCurveElements = curveElement.GetAdjoinedCurveElements(0); + var endCurveElements = curveElement.GetAdjoinedCurveElements(1); + + return resolveSet + .AppendVariant(startCurveElements, "Point 0") + .AppendVariant(endCurveElements, "Point 1"); + } + + ResolveSet ResolveHasTangentLocks() + { + var resolveSet = new ResolveSet(2); + var startHasTangentLocks = curveElement.HasTangentLocks(0); + var endHasTangentLocks = curveElement.HasTangentLocks(1); + + return resolveSet + .AppendVariant(startHasTangentLocks, $"Point 0: {startHasTangentLocks}") + .AppendVariant(endHasTangentLocks, $"Point 1: {endHasTangentLocks}"); + } + ResolveSet ResolveTangentLock() { - var set0 = curveElement.GetAdjoinedCurveElements(0); - var set1 = curveElement.GetAdjoinedCurveElements(1); - var resolveSummary = new ResolveSet(set0.Count + set1.Count); + var startCurveElements = curveElement.GetAdjoinedCurveElements(0); + var endCurveElements = curveElement.GetAdjoinedCurveElements(1); + var resolveSummary = new ResolveSet(startCurveElements.Count + endCurveElements.Count); - foreach (var id in set0) + foreach (var id in startCurveElements) { if (!curveElement.HasTangentJoin(0, id)) continue; var result = curveElement.GetTangentLock(0, id); - var element = id.ToElement(context); - resolveSummary.AppendVariant(result, $"Point 0, {element!.Name}: {result}"); + resolveSummary.AppendVariant(result, $"Point 0, {id}: {result}"); } - foreach (var id in set1) + foreach (var id in endCurveElements) { if (!curveElement.HasTangentJoin(1, id)) continue; var result = curveElement.GetTangentLock(1, id); - var element = id.ToElement(context); - resolveSummary.AppendVariant(result, $"Point 1, {element!.Name}: {result}"); + resolveSummary.AppendVariant(result, $"Point 1, {id}: {result}"); } + return resolveSummary; } ResolveSet ResolveTangentJoin() { - var set0 = curveElement.GetAdjoinedCurveElements(0); - var set1 = curveElement.GetAdjoinedCurveElements(1); - var resolveSummary = new ResolveSet(set0.Count + set1.Count); + var startCurveElements = curveElement.GetAdjoinedCurveElements(0); + var endCurveElements = curveElement.GetAdjoinedCurveElements(1); + var resolveSummary = new ResolveSet(startCurveElements.Count + endCurveElements.Count); - foreach (var id in set0) + foreach (var id in startCurveElements) { var result = curveElement.HasTangentJoin(0, id); resolveSummary.AppendVariant(result, $"Point 0, {id}: {result}"); } - foreach (var id in set1) + foreach (var id in endCurveElements) { var result = curveElement.HasTangentJoin(1, id); resolveSummary.AppendVariant(result, $"Point 1, {id}: {result}"); } + return resolveSummary; } ResolveSet ResolveIsAdjoinedCurveElement() { - var set0 = curveElement.GetAdjoinedCurveElements(0); - var set1 = curveElement.GetAdjoinedCurveElements(1); - var resolveSummary = new ResolveSet(set0.Count + set1.Count); + var startCurveElements = curveElement.GetAdjoinedCurveElements(0); + var endCurveElements = curveElement.GetAdjoinedCurveElements(1); + var resolveSummary = new ResolveSet(startCurveElements.Count + endCurveElements.Count); - foreach (var id in set0) + foreach (var id in startCurveElements) { var result = curveElement.IsAdjoinedCurveElement(0, id); resolveSummary.AppendVariant(result, $"Point 0, {id}: {result}"); } - foreach (var id in set1) + foreach (var id in endCurveElements) { var result = curveElement.IsAdjoinedCurveElement(1, id); resolveSummary.AppendVariant(result, $"Point 1, {id}: {result}"); } + return resolveSummary; } }