Skip to content

Commit

Permalink
Merge pull request jeremytammik#215 from SergeyNefyodov/dev-curtain-w…
Browse files Browse the repository at this point in the history
…alls-support

Add support for Panels and Curtain Grids
  • Loading branch information
Nice3point authored Apr 10, 2024
2 parents 0f79279 + 280d5d7 commit 8e90465
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 25 deletions.
2 changes: 2 additions & 0 deletions source/RevitLookup/Core/ComponentModel/DescriptorMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ public static Descriptor FindDescriptor(object obj, Type type)
FamilyManager value when type is null || type == typeof(FamilyManager) => new FamilyManagerDescriptor(value),
MEPSection value when type is null || type == typeof(MEPSection) => new MepSectionDescriptor(value),
LocationCurve value when type is null || type == typeof(LocationCurve) => new LocationCurveDescriptor(value),
CurtainGrid value when type is null || type == typeof(CurtainGrid) => new CurtainGridDescriptor(value),
APIObject when type is null || type == typeof(APIObject) => new ApiObjectDescriptor(),

//IDisposables
HostObject value when type is null || type == typeof(HostObject) => new HostObjectDescriptor(value),
RevitLinkType value when type is null || type == typeof(RevitLinkType) => new RevitLinkTypeDescriptor(value),
FamilyInstance value when type is null || type == typeof(FamilyInstance) => new FamilyInstanceDescriptor(value),
Panel value when type == typeof(Panel) => new PanelDescriptor(value),
SpatialElement value when type is null || type == typeof(SpatialElement) => new SpatialElementDescriptor(value),
MEPSystem value when type is null || type == typeof(MEPSystem) => new MepSystemDescriptor(value),
Element value when type is null || type == typeof(Element) => new ElementDescriptor(value),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 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 CurtainGridDescriptor(CurtainGrid curtainGrid) : Descriptor, IDescriptorResolver
{
public ResolveSet Resolve(Document context, string target, ParameterInfo[] parameters)
{
return target switch
{
nameof(CurtainGrid.GetCell) => ResolveCells(),
nameof(CurtainGrid.GetPanel) => ResolvePanels(),
_ => null
};

ResolveSet ResolveCells()
{
var uLinesIds = (List<ElementId>) curtainGrid.GetUGridLineIds();
var vLinesIds = (List<ElementId>) curtainGrid.GetVGridLineIds();
uLinesIds.Add(ElementId.InvalidElementId);
vLinesIds.Add(ElementId.InvalidElementId);
var capacity = uLinesIds.Count * vLinesIds.Count;

var resolveSummary = new ResolveSet(capacity);
foreach (var uLineId in uLinesIds)
{
foreach (var vLineId in vLinesIds)
{
var cell = curtainGrid.GetCell(uLineId, vLineId);
resolveSummary.AppendVariant(cell, $"U: {uLineId}, V: {vLineId}");
}
}

return resolveSummary;
}

ResolveSet ResolvePanels()
{
var uLinesIds = (List<ElementId>) curtainGrid.GetUGridLineIds();
var vLinesIds = (List<ElementId>) curtainGrid.GetVGridLineIds();
uLinesIds.Add(ElementId.InvalidElementId);
vLinesIds.Add(ElementId.InvalidElementId);
var capacity = uLinesIds.Count * vLinesIds.Count;

var resolveSummary = new ResolveSet(capacity);
foreach (var uLineId in uLinesIds)
{
foreach (var vLineId in vLinesIds)
{
var panel = curtainGrid.GetPanel(uLineId, vLineId);
resolveSummary.AppendVariant(panel, $"U: {uLineId}, V: {vLineId} - {panel.Name}, ID{panel.Id}");
}
}

return resolveSummary;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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 PanelDescriptor(Panel panel) : Descriptor, IDescriptorResolver
{
public ResolveSet Resolve(Document context, string target, ParameterInfo[] parameters)
{
return target switch
{
nameof(Panel.GetRefGridLines) => ResolveGridLines(),
_ => null
};

ResolveSet ResolveGridLines()
{
ElementId uId = null;
ElementId vId = null;
panel.GetRefGridLines(ref uId, ref vId);

var resolveSummary = new ResolveSet(2);
resolveSummary.AppendVariant(uId);
resolveSummary.AppendVariant(vId);
return resolveSummary;
}
}
}
15 changes: 8 additions & 7 deletions source/RevitLookup/Core/Metadata/DescriptorBuilder.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@ private bool TryEvaluate(MethodInfo member, out object value, out ParameterInfo[
{
value = null;
parameters = member.GetParameters();
if (member.ReturnType.Name == "Void")
{
if (!_settings.IncludeUnsupported) return false;

value = new NotSupportedException("Method doesn't return a value");
return true;
}

if (_currentDescriptor is IDescriptorResolver resolver)
{
value = resolver.Resolve(Context, member.Name, parameters);
if (value is not null) return true;
}

if (member.ReturnType.Name == "Void")
{
if (!_settings.IncludeUnsupported) return false;

value = new NotSupportedException("Method doesn't return a value");
return true;
}

if (parameters.Length > 0)
{
Expand Down
44 changes: 26 additions & 18 deletions source/RevitLookup/Core/Metadata/DescriptorBuilder.Write.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ private void WriteDescriptor(object value)
MemberAttributes = MemberAttributes.Property,
Type = DescriptorUtils.MakeGenericTypeName(_type)
};

descriptor.Name = descriptor.Value.Descriptor.Type;
_descriptors.Add(descriptor);
}

private void WriteDescriptor(string name, object value)
{
var descriptor = new ObjectDescriptor
Expand All @@ -55,11 +55,11 @@ private void WriteDescriptor(string name, object value)
Type = DescriptorUtils.MakeGenericTypeName(_type),
ComputationTime = _tracker.Elapsed.TotalMilliseconds
};

_descriptors.Add(descriptor);
_tracker.Reset();
}

private void WriteDescriptor(MemberInfo member, object value, ParameterInfo[] parameters)
{
var descriptor = new ObjectDescriptor
Expand All @@ -72,37 +72,45 @@ private void WriteDescriptor(MemberInfo member, object value, ParameterInfo[] pa
Type = DescriptorUtils.MakeGenericTypeName(_type),
ComputationTime = _tracker.Elapsed.TotalMilliseconds
};

_descriptors.Add(descriptor);
_tracker.Reset();
}

private SnoopableObject EvaluateValue(MemberInfo member, object value)
{
var snoopableObject = new SnoopableObject(value, Context);
SnoopUtils.Redirect(member.Name, snoopableObject);
RestoreSetDescription(member, value, snoopableObject);
return snoopableObject;
}

private SnoopableObject EvaluateValue(object value)
{
var snoopableObject = new SnoopableObject(value, Context);
SnoopUtils.Redirect(snoopableObject);
RestoreSetDescription(value, snoopableObject);
return snoopableObject;
}

private static string EvaluateName(MemberInfo member, [CanBeNull] ParameterInfo[] types)
{
if (types is null) return member.Name;
if (types.Length == 0) return member.Name;

var parameterNames = types.Select(info => DescriptorUtils.MakeGenericTypeName(info.ParameterType));

var parameterNames = types.Select(info =>
{
return info.ParameterType.IsByRef switch
{
true => $"ref {DescriptorUtils.MakeGenericTypeName(info.ParameterType).Replace("&", string.Empty)}",
_ => DescriptorUtils.MakeGenericTypeName(info.ParameterType)
};
});

var parameters = string.Join(", ", parameterNames);
return $"{member.Name} ({parameters})";
}

private static MemberAttributes EvaluateAttributes(MemberInfo member)
{
return member switch
Expand All @@ -114,44 +122,44 @@ private static MemberAttributes EvaluateAttributes(MemberInfo member)
_ => throw new ArgumentOutOfRangeException(nameof(member))
};
}

private static MemberAttributes GetModifiers(MemberAttributes attributes, MethodAttributes methodAttributes)
{
if ((methodAttributes & MethodAttributes.Static) != 0) attributes |= MemberAttributes.Static;
if ((methodAttributes & MethodAttributes.Private) != 0) attributes |= MemberAttributes.Private;
return attributes;
}

private static MemberAttributes GetModifiers(MemberAttributes attributes, FieldAttributes fieldAttributes)
{
if ((fieldAttributes & FieldAttributes.Static) != 0) attributes |= MemberAttributes.Static;
if ((fieldAttributes & FieldAttributes.Private) != 0) attributes |= MemberAttributes.Private;
return attributes;
}

private static void RestoreSetDescription(object value, SnoopableObject snoopableObject)
{
if (value is not ResolveSet set) return;
if (set.Variants.Count == 1) return;

var type = set.Variants.Peek().Result.GetType();
var name = DescriptorUtils.MakeGenericTypeName(type);
snoopableObject.Descriptor.Name = name;
snoopableObject.Descriptor.Type = name;
}

private static void RestoreSetDescription(MemberInfo member, object value, SnoopableObject snoopableObject)
{
if (value is not ResolveSet set) return;
if (set.Variants.Count == 1) return;

var name = member switch
{
PropertyInfo property => DescriptorUtils.MakeGenericTypeName(property.GetMethod.ReturnType),
MethodInfo method => DescriptorUtils.MakeGenericTypeName(method.ReturnType),
_ => snoopableObject.Descriptor.Name
};

snoopableObject.Descriptor.Name = name;
snoopableObject.Descriptor.Type = name;
}
Expand Down

0 comments on commit 8e90465

Please sign in to comment.