Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DatumPlane support #232

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/RevitLookup/Core/ComponentModel/DescriptorMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public static Descriptor FindDescriptor(object obj, Type type)
Document value when type is null || type == typeof(Document) => new DocumentDescriptor(value),
PlanViewRange value when type is null || type == typeof(PlanViewRange) => new PlanViewRangeDescriptor(value),
ElevationMarker value when type == typeof(ElevationMarker) => new ElevationMarkerDescriptor(value),
DatumPlane value when type == typeof(DatumPlane) => new DatumPlaneDescriptor(value),
ForgeTypeId value when type is null || type == typeof(ForgeTypeId) => new ForgeTypeIdDescriptor(value),
Entity value when type is null || type == typeof(Entity) => new EntityDescriptor(value),
Field value when type is null || type == typeof(Field) => new FieldDescriptor(value),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// 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 DatumPlaneDescriptor(DatumPlane datumPlane) : Descriptor, IDescriptorResolver
{
public ResolveSet Resolve(Document context, string target, ParameterInfo[] parameters)
{
return target switch
{
nameof(DatumPlane.CanBeVisibleInView) => ResolveCanBeVisibleInView(),
nameof(DatumPlane.GetCurvesInView) => ResolveCurvesInView(),
nameof(DatumPlane.GetDatumExtentTypeInView) => ResolveDatumExtentTypeInView(),
nameof(DatumPlane.GetLeader) => ResolveLeader(),
nameof(DatumPlane.GetPropagationViews) => ResolvePropagationViews(),
nameof(DatumPlane.HasBubbleInView) => ResolveHasBubbleInView(),
nameof(DatumPlane.IsBubbleVisibleInView) => ResolveBubbleVisibleInView(),
_ => null
};

ResolveSet ResolveCanBeVisibleInView()
{
var views = context.EnumerateInstances<View>().ToArray();
var resolveSummary = new ResolveSet(views.Length);

foreach (var view in views)
{
var result = datumPlane.CanBeVisibleInView(view);
resolveSummary.AppendVariant(result, $"{view.Name}: {result}");
}

return resolveSummary;
}

ResolveSet ResolveDatumExtentTypeInView()
{
var resolveSummary = new ResolveSet(2);
Nice3point marked this conversation as resolved.
Show resolved Hide resolved

var resultEnd0 = datumPlane.GetDatumExtentTypeInView(DatumEnds.End0, context.ActiveView);
var resultEnd1 = datumPlane.GetDatumExtentTypeInView(DatumEnds.End1, context.ActiveView);
resolveSummary.AppendVariant(resultEnd0, $"End 0, Active view: {resultEnd0}");
resolveSummary.AppendVariant(resultEnd1, $"End 1, Active view: {resultEnd1}");

return resolveSummary;
}

ResolveSet ResolveCurvesInView()
{
var resolveSummary = new ResolveSet(2);

resolveSummary.AppendVariant(datumPlane.GetCurvesInView(DatumExtentType.Model, context.ActiveView), $"Model, Active view");
resolveSummary.AppendVariant(datumPlane.GetCurvesInView(DatumExtentType.ViewSpecific, context.ActiveView), $"ViewSpecific, Active view");

return resolveSummary;
}

ResolveSet ResolveLeader()
{
var resolveSummary = new ResolveSet(2);

Check notice on line 82 in source/RevitLookup/Core/ComponentModel/Descriptors/DatumPlaneDescriptor.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant string interpolation

Redundant string interpolation
resolveSummary.AppendVariant(datumPlane.GetLeader(DatumEnds.End0, context.ActiveView), $"End 0, Active view");

Check notice on line 83 in source/RevitLookup/Core/ComponentModel/Descriptors/DatumPlaneDescriptor.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant string interpolation

Redundant string interpolation
resolveSummary.AppendVariant(datumPlane.GetLeader(DatumEnds.End1, context.ActiveView), $"End 1, Active view");

return resolveSummary;
}

ResolveSet ResolvePropagationViews()
{
var views = context.EnumerateInstances<View>().ToArray();
var resolveSummary = new ResolveSet(views.Length);

foreach (var view in views)
{
if (!datumPlane.CanBeVisibleInView(view)) continue;

var result = datumPlane.GetPropagationViews(view);
resolveSummary.AppendVariant(result, view.Name);
}

return resolveSummary;

Check notice on line 102 in source/RevitLookup/Core/ComponentModel/Descriptors/DatumPlaneDescriptor.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant string interpolation

Redundant string interpolation
}

Check notice on line 103 in source/RevitLookup/Core/ComponentModel/Descriptors/DatumPlaneDescriptor.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant string interpolation

Redundant string interpolation

ResolveSet ResolveHasBubbleInView()
{
var resolveSummary = new ResolveSet(2);

var resultEnd0 = datumPlane.HasBubbleInView(DatumEnds.End0, context.ActiveView);
var resultEnd1 = datumPlane.HasBubbleInView(DatumEnds.End1, context.ActiveView);
resolveSummary.AppendVariant(resultEnd0, $"End 0, Active view: {resultEnd0}");
resolveSummary.AppendVariant(resultEnd1, $"End 1, Active view: {resultEnd1}");

return resolveSummary;
}

ResolveSet ResolveBubbleVisibleInView()
{
var resolveSummary = new ResolveSet(2);

Check notice on line 120 in source/RevitLookup/Core/ComponentModel/Descriptors/DatumPlaneDescriptor.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Invert 'if' statement to reduce nesting

Invert 'if' statement to reduce nesting
var resultEnd0 = datumPlane.IsBubbleVisibleInView(DatumEnds.End0, context.ActiveView);
var resultEnd1 = datumPlane.IsBubbleVisibleInView(DatumEnds.End1, context.ActiveView);
resolveSummary.AppendVariant(resultEnd0, $"End 0, Active view: {resultEnd0}");
resolveSummary.AppendVariant(resultEnd1, $"End 1, Active view: {resultEnd1}");

return resolveSummary;
}
}
}
Loading