Skip to content

Commit a390bf9

Browse files
committed
add UIView and View3D handlers
1 parent fa5ccfd commit a390bf9

File tree

6 files changed

+101
-7
lines changed

6 files changed

+101
-7
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ internal static class ValueContainerFactory
6363
new FailureDefinitionIdHandler(),
6464
new SpatialElementBoundaryOptionsHandler(),
6565
new BoundarySegmentHandler(),
66-
66+
new UIViewHandler(),
67+
new View3DHandler(),
68+
6769
// generic
6870
new ElementHandler(),
6971

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Autodesk.Revit.DB;
4+
using Autodesk.Revit.UI;
5+
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
6+
using RevitExplorer.Visualizations.DrawingVisuals;
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 UIViewHandler : TypeHandler<UIView>
13+
{
14+
protected override bool CanBeSnoooped(SnoopableContext context, UIView value) => true;
15+
16+
protected override string ToLabel(SnoopableContext context, UIView value) => Labeler.GetLabelForObjectWithId("GeometryElement", value.ViewId.Value());
17+
18+
19+
protected override bool CanBeVisualized(SnoopableContext context, UIView value) => true;
20+
21+
22+
private readonly static Color CrossColor = new Color(255, 0, 225);
23+
24+
protected override IEnumerable<VisualizationItem> GetVisualization(SnoopableContext context, UIView uiView)
25+
{
26+
var view = context.Document.GetElement(uiView.ViewId) as View;
27+
IList<XYZ> corners = null;
28+
try
29+
{
30+
corners = uiView.GetZoomCorners();
31+
}
32+
catch
33+
{
34+
yield break;
35+
36+
}
37+
38+
yield return new VisualizationItem("UIView", "GetZoomCorners()[0]", new CrossDrawingVisual(corners[0], VisualizationItem.StartColor) { LineLength = 0.1 });
39+
yield return new VisualizationItem("UIView", "GetZoomCorners()[1]", new CrossDrawingVisual(corners[1], VisualizationItem.EndColor) { LineLength = 0.1 });
40+
41+
var diagVector = corners[0] - corners[1];
42+
43+
double height = Math.Abs(diagVector.DotProduct(view.UpDirection));
44+
double width = Math.Abs(diagVector.DotProduct(view.RightDirection));
45+
46+
var p0 = corners[0];
47+
var p1 = corners[0] + width * view.RightDirection;
48+
var p2 = corners[1];
49+
var p3 = corners[0] + height * view.UpDirection;
50+
51+
var l1 = Line.CreateBound(p0, p1);
52+
var l2 = Line.CreateBound(p1, p2);
53+
var l3 = Line.CreateBound(p2, p3);
54+
var l4 = Line.CreateBound(p3, p0);
55+
56+
yield return new VisualizationItem("UIView", "GetZoomCorners()", new CurvesDrawingVisual([l1, l2, l3 , l4], CrossColor));
57+
58+
}
59+
}
60+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
using Autodesk.Revit.DB;
3+
using RevitDBExplorer.Domain.DataModel.ValueContainers.Base;
4+
using RevitExplorer.Visualizations.DrawingVisuals;
5+
6+
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
7+
8+
namespace RevitDBExplorer.Domain.DataModel.ValueContainers
9+
{
10+
internal class View3DHandler : TypeHandler<View3D>
11+
{
12+
protected override bool CanBeSnoooped(SnoopableContext context, View3D view) => true;
13+
14+
protected override string ToLabel(SnoopableContext context, View3D view) => $"{view.Name} : ({view.Id})";
15+
16+
17+
protected override bool CanBeVisualized(SnoopableContext context, View3D view) => true;
18+
19+
20+
private readonly static Color CrossColor = new Color(255, 0, 225);
21+
22+
protected override IEnumerable<VisualizationItem> GetVisualization(SnoopableContext context, View3D view)
23+
{
24+
var orientation = view.GetOrientation();
25+
26+
yield return new VisualizationItem("View", "Origin", new CrossDrawingVisual(view.Origin, VisualizationItem.Accent1Color) { LineLength = 0.1 });
27+
yield return new VisualizationItem("View3D", "GetOrientation().EyePosition", new CrossDrawingVisual(orientation.EyePosition, VisualizationItem.Accent2Color) { LineLength = 0.1 });
28+
yield return new VisualizationItem("View3D", "GetOrientation().ForwardDirection", new VectorDrawingVisual(orientation.EyePosition, orientation.EyePosition+ orientation.ForwardDirection*100, VisualizationItem.NormalColor));
29+
30+
}
31+
}
32+
}

sources/RevitDBExplorer/Domain/Selectors/SnoopUIDocument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public IEnumerable<SnoopableObject> Snoop(UIApplication app)
1818

1919
if (document == null) yield break;
2020

21-
yield return new SnoopableObject(null, document);
21+
yield return new SnoopableObject(app.ActiveUIDocument.Document, document);
2222
}
2323
}
2424
}

sources/RevitDBExplorer/Domain/Selectors/SnoopUIView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public IEnumerable<SnoopableObject> Snoop(UIApplication app)
2020

2121
if (view == null) yield break;
2222

23-
yield return new SnoopableObject(null, view);
23+
yield return new SnoopableObject(app.ActiveUIDocument.Document, view);
2424
}
2525
}
2626
}

sources/RevitDBExplorer/MainWindow.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@
140140
</StackPanel>
141141
<Button.ContextMenu>
142142
<ContextMenu>
143+
<MenuItem Header="Snoop UI application" InputGestureText="commandData.Application" Click="SelectorButton_Click" Tag="UIApplication" />
144+
<MenuItem Header="Snoop UI document" InputGestureText="commandData.Application.ActiveUIDocument" Click="SelectorButton_Click" Tag="UIDocument" />
145+
<MenuItem Header="Snoop active UI view" InputGestureText="commandData.Application.ActiveUIDocument.GetOpenUIViews()" Click="SelectorButton_Click" Tag="UIView" />
146+
<Separator />
143147
<MenuItem Header="Snoop application" InputGestureText="commandData.Application.Application" Click="SelectorButton_Click" Tag="Application" />
144148
<MenuItem Header="Snoop document" InputGestureText="commandData.Application.ActiveUIDocument.Document" Click="SelectorButton_Click" Tag="ActiveDocument" />
145149
<MenuItem Header="Snoop active view" InputGestureText="commandData.Application.ActiveUIDocument.Document.ActiveView" Click="SelectorButton_Click" Tag="ActiveView" />
146-
<Separator />
147-
<MenuItem Header="Snoop ui application" InputGestureText="commandData.Application" Click="SelectorButton_Click" Tag="UIApplication" />
148-
<MenuItem Header="Snoop ui document" InputGestureText="commandData.Application.ActiveUIDocument" Click="SelectorButton_Click" Tag="UIDocument" />
149-
<MenuItem Header="Snoop active ui view" InputGestureText="commandData.Application.ActiveUIDocument.GetOpenUIViews()" Click="SelectorButton_Click" Tag="UIView" />
150150
</ContextMenu>
151151
</Button.ContextMenu>
152152
</Button>

0 commit comments

Comments
 (0)