Skip to content

Commit 321edaf

Browse files
committed
introduce Revit Database Visualization
1 parent afc02ff commit 321edaf

File tree

15 files changed

+157
-25
lines changed

15 files changed

+157
-25
lines changed

sources/RevitDBExplorer/Domain/DataModel/SnoopableObject.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
using Autodesk.Revit.DB;
66
using Autodesk.Revit.DB.Structure.StructuralSections;
77
using Autodesk.Revit.UI;
8+
using RevitDBExplorer.Augmentations.RevitDatabaseVisualization.DrawingVisuals;
89
using RevitDBExplorer.Domain.DataModel.Streams;
10+
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
911
using RevitDBExplorer.WPF;
1012

1113
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
@@ -132,6 +134,17 @@ public IEnumerable<SnoopableParameter> GetParameters(UIApplication app)
132134
}
133135

134136

137+
public IEnumerable<DrawingVisual> GetVisualization()
138+
{
139+
if (Object is not null)
140+
{
141+
var typeHandler = ValueContainerFactory.SelectTypeHandler(Object.GetType());
142+
return typeHandler.GetVisualization(this.Context, Object);
143+
}
144+
return Enumerable.Empty<DrawingVisual>();
145+
}
146+
147+
135148
private bool isFrozen = false;
136149
IList<SnoopableMember> frozenMembers;
137150
private static readonly Type[] doNotFreeze = new Type[] { typeof(Document) , typeof(View), typeof(Element), typeof(Transform) };

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/Base/ITypeHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace RevitDBExplorer.Domain.DataModel.ValueContainers.Base
66
{
7-
internal interface ITypeHandler : IToLabel, ICanBeSnooped, ISnoop
7+
internal interface ITypeHandler : IToLabel, ICanBeSnooped, ISnoop, IHaveVisualization
88
{
99
Type Type { get; }
1010
}
11-
internal interface ITypeHandler<in T> : IToLabel<T>, ICanBeSnooped<T>, ISnoop<T>
11+
internal interface ITypeHandler<in T> : IToLabel<T>, ICanBeSnooped<T>, ISnoop<T>, IHaveVisualization<T>
1212
{
1313
Type Type { get; }
1414
string GetTypeHandlerName(T value);

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/Base/IValueContainer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using RevitDBExplorer.Augmentations.RevitDatabaseVisualization.DrawingVisuals;
34

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

@@ -17,5 +18,6 @@ internal interface IValueContainer
1718
bool CanBeSnooped { get; }
1819
string ToolTip { get; }
1920
IEnumerable<SnoopableObject> Snoop();
21+
IEnumerable<DrawingVisual> GetVisualization();
2022
}
2123
}

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/Base/Traits.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using RevitDBExplorer.Augmentations.RevitDatabaseVisualization.DrawingVisuals;
23

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

@@ -36,4 +37,13 @@ internal interface IHaveToolTip<in T>
3637
{
3738
string GetToolTip(SnoopableContext context, T value);
3839
}
40+
41+
internal interface IHaveVisualization
42+
{
43+
IEnumerable<DrawingVisual> GetVisualization(SnoopableContext context, object value);
44+
}
45+
internal interface IHaveVisualization<in T>
46+
{
47+
IEnumerable<DrawingVisual> GetVisualization(SnoopableContext context, T value);
48+
}
3949
}

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/Base/TypeHandler.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using Autodesk.Revit.DB;
5+
using RevitDBExplorer.Augmentations.RevitDatabaseVisualization.DrawingVisuals;
56

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

@@ -13,6 +14,7 @@ internal abstract class TypeHandler<T> : ITypeHandler<T>, ITypeHandler
1314

1415
public Type Type => type;
1516

17+
Type ITypeHandler<T>.Type { get; }
1618

1719
public string GetTypeHandlerName(T value)
1820
{
@@ -64,5 +66,27 @@ string IToLabel<T>.ToLabel(SnoopableContext context, T value)
6466
return label;
6567
}
6668
protected abstract string ToLabel(SnoopableContext context, T value);
69+
70+
71+
72+
IEnumerable<DrawingVisual> IHaveVisualization.GetVisualization(SnoopableContext context, object value)
73+
{
74+
T typedValue = value.CastValue<T>(type);
75+
return (this as IHaveVisualization<T>).GetVisualization(context, typedValue);
76+
}
77+
IEnumerable<DrawingVisual> IHaveVisualization<T>.GetVisualization(SnoopableContext context, T value)
78+
{
79+
if (value is not null)
80+
{
81+
if ((value is Element element) && (!element.IsValidObject))
82+
{
83+
return Enumerable.Empty<DrawingVisual>();
84+
}
85+
86+
return GetVisualization(context, value) ?? Enumerable.Empty<DrawingVisual>();
87+
}
88+
return Enumerable.Empty<DrawingVisual>();
89+
}
90+
protected virtual IEnumerable<DrawingVisual> GetVisualization(SnoopableContext context, T value) => null;
6791
}
6892
}

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/Base/ValueContainer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using RevitDBExplorer.Augmentations.RevitDatabaseVisualization.DrawingVisuals;
34

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

@@ -67,6 +68,7 @@ public string ToolTip
6768
}
6869
}
6970

70-
public IEnumerable<SnoopableObject> Snoop() => typeHandler.Snoop(context, value);
71+
public IEnumerable<SnoopableObject> Snoop() => typeHandler.Snoop(context, value);
72+
public IEnumerable<DrawingVisual> GetVisualization() => typeHandler.GetVisualization(context, value);
7173
}
7274
}

sources/RevitDBExplorer/Domain/DataModel/ValueContainers/Base/ValueContainerFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ internal static class ValueContainerFactory
3535
new LocationHandler(),
3636

3737
//
38+
new RebarHandler(),
3839
new GeometryElementHandler(),
3940
new TransformHandler(),
4041
new ParameterHandler(),

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

Lines changed: 13 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 RevitDBExplorer.Augmentations.RevitDatabaseVisualization.DrawingVisuals;
45
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
56

67
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
@@ -27,10 +28,22 @@ protected override string ToLabel(SnoopableContext context, Element element)
2728
}
2829
return $"{elementName} ({element.Id})";
2930
}
31+
3032
protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context, Element element)
3133
{
3234
var freshElement = context.Document?.GetElement(element.Id) ?? element;
3335
yield return new SnoopableObject(context.Document, freshElement);
3436
}
37+
38+
39+
protected override IEnumerable<DrawingVisual> GetVisualization(SnoopableContext context, Element element)
40+
{
41+
var bb = element.get_BoundingBox(null);
42+
43+
if ((bb != null) && (bb.IsSet))
44+
{
45+
yield return new BoundingBox(bb.Min, bb.Max);
46+
}
47+
}
3548
}
3649
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Autodesk.Revit.DB;
4+
using Autodesk.Revit.DB.Structure;
5+
using RevitDBExplorer.Augmentations.RevitDatabaseVisualization.DrawingVisuals;
6+
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
7+
8+
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
9+
10+
namespace RevitDBExplorer.Domain.DataModel.ValueContainers
11+
{
12+
internal class RebarHandler : TypeHandler<Rebar>
13+
{
14+
protected override bool CanBeSnoooped(SnoopableContext context, Rebar rebar) => rebar is not null;
15+
16+
protected override string ToLabel(SnoopableContext context, Rebar rebar)
17+
{
18+
return Labeler.GetLabelForObjectWithId(rebar.Name, rebar.Id.Value());
19+
}
20+
21+
protected override IEnumerable<SnoopableObject> Snooop(SnoopableContext context, Rebar rebar)
22+
{
23+
var freshElement = context.Document?.GetElement(rebar.Id) ?? rebar;
24+
yield return new SnoopableObject(context.Document, freshElement);
25+
}
26+
27+
28+
private readonly static Color ArrowColor = new Color(112, 48, 161);
29+
private readonly static Color StartColor = new Color(0, 255, 0);
30+
private readonly static Color EndColor = new Color(255, 0, 0);
31+
32+
protected override IEnumerable<DrawingVisual> GetVisualization(SnoopableContext context, Rebar rebar)
33+
{
34+
if (rebar.IsRebarShapeDriven())
35+
{
36+
var bb = rebar.get_BoundingBox(null);
37+
var center = (bb.Min + bb.Max) / 2;
38+
39+
var rebarShapeDrivenAccessor = rebar.GetShapeDrivenAccessor();
40+
var normal = rebarShapeDrivenAccessor.Normal;
41+
42+
yield return new Arrow(center, normal, ArrowColor);
43+
44+
var curves = rebar.GetCenterlineCurves(false, true, true, MultiplanarOption.IncludeOnlyPlanarCurves, 0);
45+
var startPoint = curves.First().GetEndPoint(0);
46+
var endPoint = curves.Last().GetEndPoint(1);
47+
48+
yield return new Cube(startPoint, StartColor);
49+
yield return new Cube(endPoint, EndColor);
50+
}
51+
}
52+
}
53+
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Collections.Generic;
23
using Autodesk.Revit.DB;
4+
using RevitDBExplorer.Augmentations.RevitDatabaseVisualization.DrawingVisuals;
35
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
46

57
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
@@ -14,12 +16,17 @@ protected override string ToLabel(SnoopableContext context, XYZ xyz)
1416
return $"({xyz.X}, {xyz.Y}, {xyz.Z})";
1517
}
1618

17-
public string GetToolTip(SnoopableContext context, XYZ value)
19+
public string GetToolTip(SnoopableContext context, XYZ xyz)
1820
{
1921
var units = context.Document?.GetUnits();
2022
if (units == null) return null;
2123

22-
return $"{ToLabel(context, value)}\n({value.X.ToLengthDisplayString(units)}, {value.Y.ToLengthDisplayString(units)},{value.Z.ToLengthDisplayString(units)})"; ;
24+
return $"{ToLabel(context, xyz)}\n({xyz.X.ToLengthDisplayString(units)}, {xyz.Y.ToLengthDisplayString(units)},{xyz.Z.ToLengthDisplayString(units)})"; ;
25+
}
26+
27+
protected override IEnumerable<DrawingVisual> GetVisualization(SnoopableContext context, XYZ xyz)
28+
{
29+
yield return new CoordinateSystem(xyz);
2330
}
2431
}
2532
}

0 commit comments

Comments
 (0)