Skip to content

Commit

Permalink
Add support for Panels and Curtain Grids
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyNefyodov committed Apr 9, 2024
1 parent 0f79279 commit 7326061
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 7 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,74 @@
// 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)
{
var uLinesIds = curtainGrid.GetUGridLineIds().ToList();
var vLinesIds = curtainGrid.GetVGridLineIds().ToList();
uLinesIds.Add(ElementId.InvalidElementId);
vLinesIds.Add(ElementId.InvalidElementId);
var capacity = uLinesIds.Count * vLinesIds.Count;

return target switch
{
nameof(CurtainGrid.GetCell) => ResolveCells(),
nameof(CurtainGrid.GetPanel) => ResolvePanels(),
_ => null
};

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

return resolveSummary;
}

ResolveSet ResolvePanels()
{
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: {panel.Name}, ID{panel.Id}");
}
}

return resolveSummary;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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()
{
var resolveSummary = new ResolveSet(2);
ElementId uId = null;
ElementId vId = null;
panel.GetRefGridLines(ref uId, ref vId);
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

0 comments on commit 7326061

Please sign in to comment.