Skip to content

Commit b5d9f67

Browse files
committed
make use of IHaveVisualization.CanBeVisualized in type handlers
1 parent 41f7b01 commit b5d9f67

17 files changed

+64
-27
lines changed

sources/RevitDBExplorer/Domain/DataModel/SnoopableMember.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Windows.Documents;
33
using RevitDBExplorer.Domain.DataModel.Streams.Base;
4+
using RevitDBExplorer.Domain.DataModel.ValueViewModels;
45

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

@@ -16,6 +17,7 @@ internal sealed class SnoopableMember : SnoopableItem
1617
public override string Name => memberDescriptor.Name;
1718
public DocXml Documentation => memberDescriptor.Documentation;
1819
public override bool CanGenerateCode => memberDescriptor.Kind != MemberKind.None;
20+
public bool CanBeVisualized => (ValueViewModel as DefaultPresenter)?.ValueContainer?.CanBeVisualized == true;
1921

2022

2123
public SnoopableMember(SnoopableObject parent, MemberDescriptor memberDescriptor) : base(parent, memberDescriptor.MemberAccessor)

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/BoundingBoxXYZHandler.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
using System;
22
using System.Collections.Generic;
33
using Autodesk.Revit.DB;
4-
using RevitExplorer.Visualizations.DrawingVisuals;
4+
using NSourceGenerators;
55
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
6+
using RevitExplorer.Visualizations.DrawingVisuals;
67

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

910
namespace RevitDBExplorer.Domain.DataModel.ValueContainers
1011
{
1112
internal sealed class BoundingBoxXYZHandler : TypeHandler<BoundingBoxXYZ>, IHaveToolTip<BoundingBoxXYZ>
1213
{
13-
protected override bool CanBeSnoooped(SnoopableContext context, BoundingBoxXYZ box) => box is not null;
14+
protected override bool CanBeSnoooped(SnoopableContext context, BoundingBoxXYZ box) => true;
1415
protected override string ToLabel(SnoopableContext context, BoundingBoxXYZ box)
1516
{
1617
return $"Min({box.Min.X:0.##}, {box.Min.Y:0.##}, {box.Min.Z:0.##}), Max({box.Max.X:0.##}, {box.Max.Y:0.##}, {box.Max.Z:0.##})";
1718
}
19+
20+
[CodeToString]
1821
protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context, BoundingBoxXYZ box)
1922
{
2023
yield return new SnoopableObject(context.Document, box);
@@ -31,15 +34,14 @@ public string GetToolTip(SnoopableContext context, BoundingBoxXYZ value)
3134
WDH({(value.Max.X - value.Min.X).ToLengthDisplayString(units)}, {(value.Max.Y - value.Min.Y).ToLengthDisplayString(units)}, {(value.Max.Z - value.Min.Z).ToLengthDisplayString(units)})";
3235
}
3336

34-
37+
protected override bool CanBeVisualized(SnoopableContext context, BoundingBoxXYZ value) => true;
38+
[CodeToString]
3539
protected override IEnumerable<DrawingVisual> GetVisualization(SnoopableContext context, BoundingBoxXYZ box)
3640
{
37-
var bb = box;
38-
39-
if (bb != null && (bb.Max != null) && (bb.Min != null))
41+
if ((box.Max != null) && (box.Min != null))
4042
{
41-
var min = box.Transform.OfPoint(bb.Min);
42-
var max = box.Transform.OfPoint(bb.Max);
43+
var min = box.Transform.OfPoint(box.Min);
44+
var max = box.Transform.OfPoint(box.Max);
4345

4446
yield return new BoundingBoxDrawingVisual(min, max);
4547
}

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CategoryHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using Autodesk.Revit.DB;
3+
using NSourceGenerators;
34
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
45

56
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
@@ -11,8 +12,10 @@ internal sealed class CategoryHandler : TypeHandler<Category>
1112
protected override bool CanBeSnoooped(SnoopableContext context, Category category) => category is not null;
1213
protected override string ToLabel(SnoopableContext context, Category category)
1314
{
14-
return $"{category.Name} ({category.Id})";
15+
return Labeler.GetLabelForObjectWithId(category.Name, category.Id.Value());
1516
}
17+
18+
[CodeToString]
1619
protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context, Category category)
1720
{
1821
yield return new SnoopableObject(context.Document, category);

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CategoryNameMapHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using Autodesk.Revit.DB;
3+
using NSourceGenerators;
34
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
45

56
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
@@ -11,8 +12,10 @@ internal class CategoryNameMapHandler : TypeHandler<CategoryNameMap>
1112
protected override bool CanBeSnoooped(SnoopableContext context, CategoryNameMap categoryNameMap) => categoryNameMap?.IsEmpty == false;
1213
protected override string ToLabel(SnoopableContext context, CategoryNameMap categoryNameMap)
1314
{
14-
return $"Categories : {categoryNameMap.Size}";
15+
return Labeler.GetLabelForCollection("Category", categoryNameMap.Size);
1516
}
17+
18+
[CodeToString]
1619
protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context, CategoryNameMap categoryNameMap)
1720
{
1821
foreach (Category cat in categoryNameMap)

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/CurveHandler.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
using System;
22
using System.Collections.Generic;
33
using Autodesk.Revit.DB;
4-
using RevitExplorer.Visualizations.DrawingVisuals;
4+
using NSourceGenerators;
55
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
6+
using RevitExplorer.Visualizations.DrawingVisuals;
67

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

910
namespace RevitDBExplorer.Domain.DataModel.ValueContainers
1011
{
1112
internal sealed class CurveHandler : TypeHandler<Curve>
1213
{
13-
protected override bool CanBeSnoooped(SnoopableContext context, Curve curve) => curve is not null;
14+
protected override bool CanBeSnoooped(SnoopableContext context, Curve curve) => true;
1415
protected override string ToLabel(SnoopableContext context, Curve curve) => curve.GetType()?.GetCSharpName();
16+
17+
[CodeToString]
1518
protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context, Curve curve)
1619
{
1720
yield return new SnoopableObject(context.Document, curve);
1821
}
1922

20-
2123
private readonly static Color StartColor = new Color(0, 255, 0);
2224
private readonly static Color EndColor = new Color(255, 0, 0);
2325
private readonly static Color CurveColor = new Color(80, 175, 228);
24-
26+
protected override bool CanBeVisualized(SnoopableContext context, Curve curve) => true;
27+
[CodeToString]
2528
protected override IEnumerable<DrawingVisual> GetVisualization(SnoopableContext context, Curve curve)
2629
{
2730
if (curve.IsBound)

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/EdgeHandler.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
using System;
22
using System.Collections.Generic;
33
using Autodesk.Revit.DB;
4-
using RevitExplorer.Visualizations.DrawingVisuals;
4+
using NSourceGenerators;
55
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
6+
using RevitExplorer.Visualizations.DrawingVisuals;
67

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

910
namespace RevitDBExplorer.Domain.DataModel.ValueContainers
1011
{
1112
internal sealed class EdgeHandler : TypeHandler<Edge>
1213
{
13-
protected override bool CanBeSnoooped(SnoopableContext context, Edge edge) => edge is not null;
14+
protected override bool CanBeSnoooped(SnoopableContext context, Edge edge) => true;
1415
protected override string ToLabel(SnoopableContext context, Edge edge) => edge.GetType()?.GetCSharpName();
16+
17+
[CodeToString]
1518
protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context, Edge edge)
1619
{
1720
yield return new SnoopableObject(context.Document, edge);
@@ -22,6 +25,8 @@ protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context,
2225
private readonly static Color EndColor = new Color(255, 0, 0);
2326
private readonly static Color CurveColor = new Color(80, 175, 228);
2427

28+
protected override bool CanBeVisualized(SnoopableContext context, Edge edge) => true;
29+
[CodeToString]
2530
protected override IEnumerable<DrawingVisual> GetVisualization(SnoopableContext context, Edge edge)
2631
{
2732
var curve = edge.AsCurve();

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/ElementHandler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using Autodesk.Revit.DB;
4-
using RevitExplorer.Visualizations.DrawingVisuals;
4+
using NSourceGenerators;
55
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
6+
using RevitExplorer.Visualizations.DrawingVisuals;
67

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

@@ -29,13 +30,15 @@ protected override string ToLabel(SnoopableContext context, Element element)
2930
return $"{elementName} ({element.Id})";
3031
}
3132

33+
[CodeToString]
3234
protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context, Element element)
3335
{
3436
var freshElement = context.Document?.GetElement(element.Id) ?? element;
3537
yield return new SnoopableObject(context.Document, freshElement);
3638
}
3739

38-
40+
protected override bool CanBeVisualized(SnoopableContext context, Element element) => element is not ElementType;
41+
[CodeToString]
3942
protected override IEnumerable<DrawingVisual> GetVisualization(SnoopableContext context, Element element)
4043
{
4144
var bb = element.get_BoundingBox(null);

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/ElementIdHandler.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using Autodesk.Revit.DB;
4+
using NSourceGenerators;
45
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
56

67
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
@@ -37,6 +38,8 @@ protected override string ToLabel(SnoopableContext context, ElementId id)
3738
}
3839
return $"{id}";
3940
}
41+
42+
[CodeToString]
4043
protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context, ElementId id)
4144
{
4245
yield return new SnoopableObject(context.Document, id);

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/FaceHandler.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
using System;
22
using System.Collections.Generic;
33
using Autodesk.Revit.DB;
4-
using RevitExplorer.Visualizations.DrawingVisuals;
4+
using NSourceGenerators;
55
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
6+
using RevitExplorer.Visualizations.DrawingVisuals;
67

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

910
namespace RevitDBExplorer.Domain.DataModel.ValueContainers
1011
{
1112
internal sealed class FaceHandler : TypeHandler<Face>
1213
{
13-
protected override bool CanBeSnoooped(SnoopableContext context, Face face) => face is not null;
14+
protected override bool CanBeSnoooped(SnoopableContext context, Face face) => true;
1415
protected override string ToLabel(SnoopableContext context, Face face) => face.GetType()?.GetCSharpName();
16+
1517
protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context, Face face)
1618
{
1719
yield return new SnoopableObject(context.Document, face);
@@ -20,6 +22,8 @@ protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context,
2022

2123
private readonly static Color FaceColor = new Color(80, 175, 228);
2224

25+
protected override bool CanBeVisualized(SnoopableContext context, Face face) => true;
26+
[CodeToString]
2327
protected override IEnumerable<DrawingVisual> GetVisualization(SnoopableContext context, Face face)
2428
{
2529
yield return new FaceDrawingVisual(face, FaceColor);

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/FailureDefinitionIdHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ protected override bool CanBeSnoooped(SnoopableContext context, FailureDefinitio
1313
{
1414
return true;
1515
}
16-
1716
protected override string ToLabel(SnoopableContext context, FailureDefinitionId value)
1817
{
1918
return $"FailureDefinitionId ({value.Guid})";
2019
}
20+
2121
protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context, FailureDefinitionId value)
2222
{
2323
var failure = ControlledApplication.GetFailureDefinitionRegistry().FindFailureDefinition(value);

0 commit comments

Comments
 (0)