Skip to content

Commit

Permalink
use a new c# syntax for MemberAccessors
Browse files Browse the repository at this point in the history
  • Loading branch information
NeVeSpl committed May 12, 2024
1 parent c624aa7 commit ed20ffd
Show file tree
Hide file tree
Showing 47 changed files with 434 additions and 316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ public ReadResult(string label, string accessorName, bool canBeSnooped = false,
CanBeVisualized = canBeVisualized;
State = state;
}

public static ReadResult Forbidden => new ReadResult("<access denied / forbidden>", null, false, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
using System.Linq.Expressions;
using Autodesk.Revit.DB.Visual;
using RevitDBExplorer.Domain.DataModel.Accessors;
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
{
internal class AssetProperties_Item : MemberAccessorTypedWithDefaultPresenter<AssetProperties>, ICanCreateMemberAccessor
{
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() { yield return (AssetProperties x) => x[0]; }
internal class AssetProperties_Item : MemberAccessorByType<AssetProperties>, ICanCreateMemberAccessor
{
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() => [ (AssetProperties x) => x[0] ];


public override ReadResult Read(SnoopableContext context, AssetProperties assetProperties) => new()
Expand All @@ -19,7 +18,7 @@ internal class AssetProperties_Item : MemberAccessorTypedWithDefaultPresenter<As
CanBeSnooped = assetProperties.Size > 0
};

public override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, AssetProperties assetProperties, IValueContainer state)
protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, AssetProperties assetProperties)
{
for (int i = 0; i < assetProperties.Size; i++)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain.DataModel.Accessors;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
{
internal class CurtainGrid_GetCell : MemberAccessorByType<CurtainGrid>, ICanCreateMemberAccessor
{
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() { yield return (CurtainGrid x) => x.GetCell(ElementId.InvalidElementId, ElementId.InvalidElementId); }
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() => [ (CurtainGrid x) => x.GetCell(ElementId.InvalidElementId, ElementId.InvalidElementId) ];


protected override bool CanBeSnoooped(Document document, CurtainGrid grid) => true;
protected override string GetLabel(Document document, CurtainGrid grid)
{
string value = $"[CurtainCell]";
return value;
}
protected override IEnumerable<SnoopableObject> Snooop(Document document, CurtainGrid grid)
public override ReadResult Read(SnoopableContext context, CurtainGrid grid) => new()
{
Label = Labeler.GetLabelForCollection(nameof(CurtainCell), null),
CanBeSnooped = true
};


protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, CurtainGrid grid)
{
var uLineIds = grid.GetUGridLineIds();
var vLineIds = grid.GetVGridLineIds();
Expand All @@ -30,7 +32,7 @@ protected override IEnumerable<SnoopableObject> Snooop(Document document, Curtai
{
var cell = grid.GetCell(uLineId, vLineId);

yield return new SnoopableObject(document, cell) { Name = $"uGridLineId: {uLineId}, vGridLineId: {vLineId}" };
yield return new SnoopableObject(context.Document, cell) { Name = $"uGridLineId: {uLineId}, vGridLineId: {vLineId}" };
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain.DataModel.Accessors;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
{
internal class CurtainGrid_GetPanel : MemberAccessorByType<CurtainGrid>, ICanCreateMemberAccessor
{
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() { yield return (CurtainGrid x) => x.GetPanel(ElementId.InvalidElementId, ElementId.InvalidElementId); }
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() => [ (CurtainGrid x) => x.GetPanel(ElementId.InvalidElementId, ElementId.InvalidElementId) ];


protected override bool CanBeSnoooped(Document document, CurtainGrid grid) => true;
protected override string GetLabel(Document document, CurtainGrid grid)
{
string value = $"[Panel]";
return value;
}
protected override IEnumerable<SnoopableObject> Snooop(Document document, CurtainGrid grid)
public override ReadResult Read(SnoopableContext context, CurtainGrid grid) => new()
{
Label = Labeler.GetLabelForCollection(nameof(Panel), null),
CanBeSnooped = true
};


protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, CurtainGrid grid)
{
var uLineIds = grid.GetUGridLineIds();
var vLineIds = grid.GetVGridLineIds();
Expand All @@ -30,7 +32,7 @@ protected override IEnumerable<SnoopableObject> Snooop(Document document, Curtai
{
var cell = grid.GetPanel(uLineId, vLineId);

yield return new SnoopableObject(document, cell) { Name = $"uGridLineId: {uLineId}, vGridLineId: {vLineId}" };
yield return new SnoopableObject(context.Document, cell) { Name = $"uGridLineId: {uLineId}, vGridLineId: {vLineId}" };
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain.DataModel.Accessors;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
{
internal class Curve_GetEndPoint : MemberAccessorByType<Curve>, ICanCreateMemberAccessor
{
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() { yield return (Curve x) => x.GetEndPoint(0); }
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() => [ (Curve x) => x.GetEndPoint(0) ];


protected override bool CanBeSnoooped(Document document, Curve curve) => curve.IsBound;
protected override string GetLabel(Document document, Curve curve)
public override ReadResult Read(SnoopableContext context, Curve curve) => new()
{
Label = GetLabel(curve),
CanBeSnooped = curve.IsBound
};
private string GetLabel(Curve curve)
{
var p0 = curve.GetEndPoint(0);
var p1 = curve.GetEndPoint(1);

string value = $"({p0.X:0.##}, {p0.Y:0.##}, {p0.Z:0.##}) - ({p1.X:0.##}, {p1.Y:0.##}, {p1.Z:0.##})";
return value;
}
protected override IEnumerable<SnoopableObject> Snooop(Document document, Curve curve)


protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, Curve curve)
{
var p0 = curve.GetEndPoint(0);
var p1 = curve.GetEndPoint(1);

yield return new SnoopableObject(document, p0) { Index = 0, Name = "Start"};
yield return new SnoopableObject(document, p1) { Index = 1, Name = "End" };
yield return new SnoopableObject(context.Document, p0) { Index = 0, Name = "Start"};
yield return new SnoopableObject(context.Document, p1) { Index = 1, Name = "End" };
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Events;
using RevitDBExplorer.Domain.DataModel.Accessors;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
{
internal class DialogBoxShowingEventArgs_OverrideResult : MemberAccessorByType<DialogBoxShowingEventArgs>, ICanCreateMemberAccessor
{
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() { yield return (DialogBoxShowingEventArgs x) => x.OverrideResult(0); }
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() => [ (DialogBoxShowingEventArgs x) => x.OverrideResult(0) ];


public override ReadResult Read(SnoopableContext context, DialogBoxShowingEventArgs value) => ReadResult.Forbidden;


protected override bool CanBeSnoooped(Document document, DialogBoxShowingEventArgs value) => false;
protected override string GetLabel(Document document, DialogBoxShowingEventArgs value) => QuoteGenerator.Deny();
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain.DataModel.Accessors;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
{
internal class Document_Close : MemberAccessorByType<Document>, ICanCreateMemberAccessor
{
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() { yield return (Document x) => x.Close(); yield return (Document x) => x.Close(true); }
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() => [ (Document x) => x.Close(), (Document x) => x.Close(true) ];


protected override bool CanBeSnoooped(Document document, Document value) => false;
protected override string GetLabel(Document document, Document value) => QuoteGenerator.Deny();

public override ReadResult Read(SnoopableContext context, Document value) => ReadResult.Forbidden;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@
using System.Linq;
using System.Linq.Expressions;
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain.DataModel.Accessors;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
{
internal class Document_PlanTopology : MemberAccessorByType<Document>, ICanCreateMemberAccessor
{
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() { yield return (Document x, Phase phase) => x.get_PlanTopologies(phase); }
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() => [ (Document x, Phase phase) => x.get_PlanTopologies(phase) ];


protected override bool CanBeSnoooped(Document document, Document value) => false;// document.Phases.Size > 0;
protected override string GetLabel(Document document, Document value) => $"[{nameof(PlanTopology)}]";
public override ReadResult Read(SnoopableContext context, Document value) => new()
{
Label = Labeler.GetLabelForCollection(nameof(PlanTopology), null),
CanBeSnooped = false
};


protected override IEnumerable<SnoopableObject> Snooop(Document document, Document value)
protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, Document value)
{
var document = context.Document;
var transaction = document.IsModifiable == false ? new Transaction(document, GetType().Name) : null;
transaction?.Start();
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
{
internal class Element_BoundingBox : MemberAccessorByFunc<Element, BoundingBoxXYZ>, ICanCreateMemberAccessor
{
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() { yield return (Element x, View v) => x.get_BoundingBox(v); }
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() => [ (Element x, View v) => x.get_BoundingBox(v) ];


public Element_BoundingBox() : base((document, element) => element.get_BoundingBox(document.ActiveView), Snoop)
Expand All @@ -19,6 +19,7 @@ public Element_BoundingBox() : base((document, element) => element.get_BoundingB

private static IEnumerable<SnoopableObject> Snoop(Document document, Element element)
{
//var document = context.Document;
yield return new SnoopableObject(document, null, new[] { new SnoopableObject(document, element.get_BoundingBox(null)) }) { NamePrefix = "view:" };
if (document.ActiveView != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,35 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain.DataModel.Accessors;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
{
internal sealed class Element_Geometry : MemberAccessorByType<Element>, ICanCreateMemberAccessor
{
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() { yield return (Element x, Options o) => x.get_Geometry(o); }

IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() => [ (Element x, Options o) => x.get_Geometry(o) ];

protected override bool CanBeSnoooped(Document document, Element element)

public override ReadResult Read(SnoopableContext context, Element element) => new()
{
Label = Labeler.GetLabelForCollection(nameof(GeometryElement), null),
CanBeSnooped = CanBeSnoooped(context.Document, element),
};
private bool CanBeSnoooped(Document document, Element element)
{
var options = element.ViewSpecific ? new Options() { View = document.ActiveView } : new Options();
var geometry = element.get_Geometry(options);
var canBeSnooped = geometry != null;

return canBeSnooped;
}
protected override string GetLabel(Document document, Element element) => $"[{nameof(GeometryElement)}]";
protected override IEnumerable<SnoopableObject> Snooop(Document document, Element element)


protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, Element element)
{
var document = context.Document;
var optionsForActiveView = new List<Options>();
if (document.ActiveView != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
{
internal class Element_GetDependentElements : MemberAccessorByFunc<Element, IList<ElementId>>, ICanCreateMemberAccessor
{
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() { yield return (Element x, ElementFilter ef) => x.GetDependentElements(ef); }
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() => [ (Element x, ElementFilter ef) => x.GetDependentElements(ef) ];


public Element_GetDependentElements() : base( (document, element) => element.GetDependentElements(null) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
using System.Linq.Expressions;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.ExtensibleStorage;
using RevitDBExplorer.Domain.DataModel.Accessors;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer.Domain.DataModel.MemberAccessors
{
internal class Element_GetEntity : MemberAccessorByType<Element>, ICanCreateMemberAccessor
{
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() { yield return (Element x, Schema s) => x.GetEntity(s); }
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() => [ (Element x, Schema s) => x.GetEntity(s) ];


protected override bool CanBeSnoooped(Document document, Element element)
public override ReadResult Read(SnoopableContext context, Element element) => new()
{
Label = Labeler.GetLabelForCollection(nameof(Entity), null),
CanBeSnooped = CanBeSnoooped(element)
};
private bool CanBeSnoooped(Element element)
{
foreach (var id in element.GetEntitySchemaGuids())
{
Expand All @@ -21,11 +27,9 @@ protected override bool CanBeSnoooped(Document document, Element element)
}
return false;
}
protected override string GetLabel(Document document, Element element)
{
return $"[{nameof(Entity)}]";
}
protected override IEnumerable<SnoopableObject> Snooop(Document document, Element element)


protected override IEnumerable<SnoopableObject> Snoop(SnoopableContext context, Element element)
{
var schemas = Schema.ListSchemas();

Expand All @@ -35,7 +39,7 @@ protected override IEnumerable<SnoopableObject> Snooop(Document document, Elemen
var entity = element.GetEntity(schema);
if (!entity.IsValid()) continue;

yield return SnoopableObject.CreateInOutPair(document, schema, entity);
yield return SnoopableObject.CreateInOutPair(context.Document, schema, entity);
}
}
}
Expand Down
Loading

0 comments on commit ed20ffd

Please sign in to comment.