Skip to content

Commit

Permalink
Merge pull request #233 from SergeyNefyodov/dev-family-size-tables-su…
Browse files Browse the repository at this point in the history
…pport

Add FamilySizeTable support
  • Loading branch information
Nice3point authored May 10, 2024
2 parents 043105b + 17805c7 commit e923218
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/Qodana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
jobs:
qodana:
runs-on: windows-latest
permissions:
contents: write
pull-requests: write
checks: write
steps:
- uses: actions/checkout@v4
with:
Expand Down
16 changes: 7 additions & 9 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,23 @@ public sealed class UiElementDescriptor : Descriptor, IDescriptorResolver
In another situation you have nothing to return by the condition, use the `Variants.Empty()` as well:

```c#
public sealed class IndependentTagDescriptor : Descriptor, IDescriptorResolver
public sealed class DocumentDescriptor : Descriptor, IDescriptorResolver
{
public IVariants Resolve(Document context, string target, ParameterInfo[] parameters)
{
return target switch
{
nameof(IndependentTag.GetLeaderEnd) => ResolveLeaderEnd(),
nameof(Document.PlanTopologies) when parameters.Length == 0 => ResolvePlanTopologies(),
_ => null
};

IVariants ResolveLeaderEnd()
IVariants ResolvePlanTopologies()
{
if (_tag.LeaderEndCondition == LeaderEndCondition.Attached)
{
return Variants.Empty<XYZ>();
}

// User code
if (_document.IsReadOnly) return Variants.Empty<PlanTopologySet>();

return Variants.Single(_document.PlanTopologies);
}
}
}
```

Expand Down
3 changes: 3 additions & 0 deletions source/RevitLookup/Core/ComponentModel/DescriptorMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ public static Descriptor FindDescriptor(object obj, Type type)
TableView value when type == typeof(TableView) => new TableViewDescriptor(value),
TableData value when type == typeof(TableData) => new TableDataDescriptor(value),
TableSectionData value when type == typeof(TableSectionData) => new TableSectionDataDescriptor(value),
FamilySizeTableManager value when type == typeof(FamilySizeTableManager) => new FamilySizeTableManagerDescriptor(value),
FamilySizeTable value when type == typeof(FamilySizeTable) => new FamilySizeTableDescriptor(value),
FamilySizeTableColumn value when type == typeof(FamilySizeTableColumn) => new FamilySizeTableColumnDescriptor(value),
#if REVIT2024_OR_GREATER
EvaluatedParameter value when type is null || type == typeof(EvaluatedParameter) => new EvaluatedParameterDescriptor(value),
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// (Rights in Technical Data and Computer Software), as applicable.

using System.Reflection;
using System.Runtime.InteropServices.JavaScript;
using Autodesk.Revit.DB.Visual;
using RevitLookup.Core.Contracts;
using RevitLookup.Core.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@

namespace RevitLookup.Core.ComponentModel.Descriptors;

public sealed class DocumentDescriptor : Descriptor, IDescriptorResolver
public sealed class DocumentDescriptor : Descriptor, IDescriptorResolver, IDescriptorExtension
{
private readonly Document _document;

public DocumentDescriptor(Document document)
{
_document = document;
Name = document.Title;
}

public IVariants Resolve(Document context, string target, ParameterInfo[] parameters)
{
return target switch
Expand All @@ -46,15 +46,39 @@ public IVariants Resolve(Document context, string target, ParameterInfo[] parame
#endif
_ => null
};

IVariants ResolvePlanTopologies()
{
if (_document.IsReadOnly) return Variants.Empty<PlanTopologySet>();

var transaction = new Transaction(_document);
transaction.Start("Calculating plan topologies");
var topologies = _document.PlanTopologies;
transaction.Commit();

return Variants.Single(topologies);
}
}

public void RegisterExtensions(IExtensionManager manager)
{
if (!_document.IsFamilyDocument)
{
manager.Register(nameof(FamilySizeTableManager.GetFamilySizeTableManager), _ =>
{
var families = _document.EnumerateInstances<Family>().ToArray();
var variants = new Variants<FamilySizeTableManager>(families.Length);
foreach (var family in families)
{
var result = FamilySizeTableManager.GetFamilySizeTableManager(_document, family.Id);
if (result is not null && result.NumberOfSizeTables > 0)
{
variants.Add(result, $"{ElementDescriptor.CreateName(family)}");
}
}
return variants;
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 RevitLookup.Core.Objects;

namespace RevitLookup.Core.ComponentModel.Descriptors;

public sealed class FamilySizeTableColumnDescriptor : Descriptor
{
public FamilySizeTableColumnDescriptor(FamilySizeTableColumn column)
{
Name = column.Name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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 sealed class FamilySizeTableDescriptor(FamilySizeTable table) : Descriptor, IDescriptorResolver
{
public IVariants Resolve(Document context, string target, ParameterInfo[] parameters)
{
return target switch
{
nameof(FamilySizeTable.GetColumnHeader) => ResolveColumnHeader(),
nameof(FamilySizeTable.IsValidColumnIndex) => ResolveIsValidColumnIndex(),
_ => null
};

IVariants ResolveColumnHeader()
{
var count = table.NumberOfColumns;
var variants = new Variants<FamilySizeTableColumn>(count);

for (var i = 0; i < count; i++)
{
variants.Add(table.GetColumnHeader(i));
}

return variants;
}

IVariants ResolveIsValidColumnIndex()
{
var count = table.NumberOfColumns;
var variants = new Variants<bool>(count);

for (var i = 0; i <= count; i++)
{
var result = table.IsValidColumnIndex(i);
variants.Add(result, $"{i}: {result}");
}

return variants;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 sealed class FamilySizeTableManagerDescriptor(FamilySizeTableManager manager) : Descriptor, IDescriptorResolver
{
public IVariants Resolve(Document context, string target, ParameterInfo[] parameters)
{
return target switch
{
nameof(FamilySizeTableManager.GetSizeTable) => ResolveSizeTable(),
nameof(FamilySizeTableManager.HasSizeTable) => ResolveHasSizeTable(),
nameof(FamilySizeTableManager.GetFamilySizeTableManager) => Variants.Single(manager),
_ => null
};

IVariants ResolveSizeTable()
{
var names = manager.GetAllSizeTableNames();
var variants = new Variants<FamilySizeTable>(names.Count);

foreach (var name in names)
{
variants.Add(manager.GetSizeTable(name), name);
}

return variants;
}

IVariants ResolveHasSizeTable()
{
var names = manager.GetAllSizeTableNames();
var variants = new Variants<bool>(names.Count);

foreach (var name in names)
{
var result = manager.HasSizeTable(name);
variants.Add(result, $"{name}: {result}");
}

return variants;
}
}
}

0 comments on commit e923218

Please sign in to comment.