Skip to content

Commit e3ddec2

Browse files
committed
add a new selector : SnoopElementsOnScreen
1 parent 5a0e9ee commit e3ddec2

File tree

9 files changed

+124
-32
lines changed

9 files changed

+124
-32
lines changed

sources/RevitDBExplorer/Application.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private void UIApplication_ViewActivated(object sender, Autodesk.Revit.UI.Events
107107
View = null;
108108
}
109109
}
110-
public static (string, double) GetMouseStatus()
110+
public static (string, XYZ, XYZ, bool) GetMouseStatus()
111111
{
112112
var uiView = Application.UIView;
113113
var view = Application.View;
@@ -124,49 +124,52 @@ public static (string, double) GetMouseStatus()
124124
double dy = (double)(p.Y - rect.Bottom) / (rect.Top - rect.Bottom);
125125

126126
var corners = uiView.GetZoomCorners();
127-
var a = corners[0];
128-
var b = corners[1];
129-
var v = b - a;
127+
var min = corners[0];
128+
var max = corners[1];
129+
var v = max - min;
130130
var l = v.GetLength();
131131

132132
var vr = dx * new XYZ(v.X * view.RightDirection.X, v.Y * view.RightDirection.Y, v.Z * view.RightDirection.Z);
133133
var vu = dy * new XYZ(v.X * view.UpDirection.X, v.Y * view.UpDirection.Y, v.Z * view.UpDirection.Z);
134-
var vv = 1.0 * new XYZ(a.X * view.ViewDirection.X, a.Y * view.ViewDirection.Y, a.Z * view.ViewDirection.Z);
134+
var vv = 1.0 * new XYZ(min.X * view.ViewDirection.X, min.Y * view.ViewDirection.Y, min.Z * view.ViewDirection.Z);
135135

136-
var q = a + vr + vu - vv;
136+
var q = min + vr + vu - vv;
137+
138+
min -= vv;
139+
max -= vv;
137140

138141
if ((Math.Abs(view.RightDirection.X) < 0.999) && (Math.Abs(view.RightDirection.Y) < 0.999) && (Math.Abs(view.RightDirection.Z) < 0.999))
139142
{
140-
return ("(?,,)", l);
143+
return ("(?,,)", min, max, false);
141144
}
142145
if ((Math.Abs(view.UpDirection.X) < 0.999) && (Math.Abs(view.UpDirection.Y) < 0.999) && (Math.Abs(view.UpDirection.Z) < 0.999))
143146
{
144-
return ("(,?,)", l);
147+
return ("(,?,)", min, max, false);
145148
}
146149
if ((Math.Abs(view.ViewDirection.X) < 0.999) && (Math.Abs(view.ViewDirection.Y) < 0.999) && (Math.Abs(view.ViewDirection.Z) < 0.999))
147150
{
148-
return ("(,,?)", l);
151+
return ("(,,?)", min, max, false);
149152
}
150153

151154
if (view.ViewDirection.IsParallelTo(XYZ.BasisX))
152155
{
153-
return ($"(-,--, {q.Y:f3}, {q.Z:f3})", l);
156+
return ($"(-,--, {q.Y:f3}, {q.Z:f3})", min, max, true);
154157
}
155158
if (view.ViewDirection.IsParallelTo(XYZ.BasisY))
156159
{
157-
return ($"({q.X:f3}, -,--, {q.Z:f3})", l);
160+
return ($"({q.X:f3}, -,--, {q.Z:f3})", min, max, true);
158161
}
159162
if (view.ViewDirection.IsParallelTo(XYZ.BasisZ))
160163
{
161-
return ($"({q.X:f3}, {q.Y:f3}, -,--)", l);
164+
return ($"({q.X:f3}, {q.Y:f3}, -,--)", min, max, true);
162165
}
163166
}
164167
catch
165168
{
166169

167170
}
168171
}
169-
return ("", 0);
172+
return ("", XYZ.Zero, XYZ.Zero, false);
170173
}
171174

172175

sources/RevitDBExplorer/Domain/Selectors/SelectorFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public enum Selector
1010
{
1111
Db,
1212
CurrentSelection,
13+
ElementsOnScreen,
1314
PickFace,
1415
PickEdge,
1516
PickPoint,
@@ -48,6 +49,7 @@ private static ISelector CreateSelector(Selector selector)
4849
{
4950
Selector.Db => new SnoopDatabase(),
5051
Selector.CurrentSelection => new SnoopCurrentSelection(),
52+
Selector.ElementsOnScreen => new SnoopElementsOnScreen(),
5153
Selector.PickFace => new SnoopPick(ObjectType.Face),
5254
Selector.PickEdge => new SnoopPick(ObjectType.Edge),
5355
Selector.PickPoint => new SnoopPick(ObjectType.PointOnElement),
@@ -68,7 +70,7 @@ private static ISelector CreateSelector(Selector selector)
6870
Selector.Updaters => new SnoopUpdaters(),
6971
Selector.LoadedApplications => new SnoopLoadedApplications(),
7072
Selector.ExternalServices => new SnoopExternalServices(),
71-
Selector.VisibleInView => new VisibleInView(),
73+
Selector.VisibleInView => new SnoopVisibleInView(),
7274
_ => throw new NotImplementedException()
7375
}; ;
7476
return result;

sources/RevitDBExplorer/Domain/Selectors/SnoopCurrentSelection.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,7 @@ public IEnumerable<SnoopableObject> Snoop(UIApplication app)
3232
else
3333
{
3434
collector = new FilteredElementCollector(document, document.ActiveView.Id);
35-
Info.ShortTitle = "visible elements in a view";
36-
//var uiViews = app.ActiveUIDocument.GetOpenUIViews();
37-
//var uiView = uiViews.FirstOrDefault(x => x.ViewId == document.ActiveView.Id);
38-
//var zoomCorners= uiView.GetZoomCorners();
39-
//var outline = new Outline(zoomCorners[0], zoomCorners[1]);
40-
//collector = new FilteredElementCollector(document).WherePasses(new BoundingBoxIsInsideFilter(outline));
41-
//Info.ShortTitle = "visible elements on the screen";
35+
Info.ShortTitle = "visible elements in a view";
4236
}
4337

4438
if (collector.GetElementCount() == 0 && selectedIds.Count > 0)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Autodesk.Revit.DB;
4+
using Autodesk.Revit.UI;
5+
using RevitDBExplorer.Domain.DataModel;
6+
using RevitDBExplorer.Domain.Selectors.Base;
7+
8+
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
9+
10+
namespace RevitDBExplorer.Domain.Selectors
11+
{
12+
internal class SnoopElementsOnScreen : ISelector
13+
{
14+
public InfoAboutSource Info { get; private set; } = new("elements on the screen ");
15+
16+
public IEnumerable<SnoopableObject> Snoop(UIApplication app)
17+
{
18+
var document = app?.ActiveUIDocument?.Document;
19+
20+
if (document == null) return null;
21+
22+
if (document.ActiveView is ViewPlan viewPlan)
23+
{
24+
//var currentElevation = viewPlan.GenLevel.Elevation;
25+
//var bottomElevation = -1000.0;
26+
27+
//var viewRange = viewPlan.GetViewRange();
28+
//var depthPlaneLevelId = viewRange.GetLevelId(PlanViewPlane.ViewDepthPlane);
29+
//if (depthPlaneLevelId != ElementId.InvalidElementId)
30+
//{
31+
// var depthOffset = viewRange.GetOffset(PlanViewPlane.ViewDepthPlane);
32+
// var depthLevel = document.GetElement(depthPlaneLevelId) as Level;
33+
// bottomElevation = depthLevel.Elevation + depthOffset;
34+
//}
35+
36+
//var deltaBottom = currentElevation - bottomElevation;
37+
}
38+
39+
var view = app.ActiveUIDocument.ActiveView;
40+
41+
if (view.ViewDirection.IsParallelTo(XYZ.BasisX) == false && view.ViewDirection.IsParallelTo(XYZ.BasisY) == false && view.ViewDirection.IsParallelTo(XYZ.BasisZ) == false)
42+
return null;
43+
if (view.RightDirection.IsParallelTo(XYZ.BasisX) == false && view.RightDirection.IsParallelTo(XYZ.BasisY) == false && view.RightDirection.IsParallelTo(XYZ.BasisZ) == false)
44+
return null;
45+
46+
var uiViews = app.ActiveUIDocument.GetOpenUIViews();
47+
var uiView = uiViews.FirstOrDefault(x => x.ViewId == document.ActiveView.Id);
48+
var zoomCorners = uiView.GetZoomCorners();
49+
var min = zoomCorners[0];
50+
var max = zoomCorners[1];
51+
52+
var margin1 = document.ActiveView.ViewDirection * 54321;
53+
var margin2 = margin1.Negate();
54+
55+
min = min + margin1.Min(margin2);
56+
max = max + margin1.Max(margin2);
57+
58+
var outline = new Outline(min, max);
59+
var collector = new FilteredElementCollector(document, document.ActiveView.Id).WherePasses(new BoundingBoxIntersectsFilter(outline));
60+
61+
return collector.ToElements().Select(x => new SnoopableObject(document, x));
62+
}
63+
}
64+
}

sources/RevitDBExplorer/Domain/Selectors/VisibleInView.cs renamed to sources/RevitDBExplorer/Domain/Selectors/SnoopVisibleInView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
namespace RevitDBExplorer.Domain.Selectors
1111
{
12-
class VisibleInView : ISelector
12+
internal class SnoopVisibleInView : ISelector
1313
{
14-
public InfoAboutSource Info { get; private set; } = new("visible elements in View");
14+
public InfoAboutSource Info { get; private set; } = new("visible elements in a view");
1515

1616
public IEnumerable<SnoopableObject> Snoop(UIApplication app)
1717
{

sources/RevitDBExplorer/Extensions/Autodesk.Revit.DB/XYZExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,15 @@ public static bool IsCodirectionalTo(this XYZ first, XYZ second)
2222

2323
return Math.Abs(dotProduct - 1.0) < 1e-6;
2424
}
25+
26+
public static XYZ Min(this XYZ first, XYZ second)
27+
{
28+
return new XYZ(Math.Min(first.X, second.X), Math.Min(first.Y, second.Y), Math.Min(first.Z, second.Z));
29+
}
30+
31+
public static XYZ Max(this XYZ first, XYZ second)
32+
{
33+
return new XYZ(Math.Max(first.X, second.X), Math.Max(first.Y, second.Y), Math.Max(first.Z, second.Z));
34+
}
2535
}
2636
}

sources/RevitDBExplorer/MainWindow.xaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<RowDefinition Height="21"/>
5858
</Grid.RowDefinitions>
5959

60-
<UniformGrid Columns="10" Margin="0 0 0 2" >
60+
<UniformGrid Columns="11" Margin="0 0 0 2" >
6161
<UniformGrid.Resources>
6262
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
6363
<Setter Property="Background" Value="Transparent"/>
@@ -93,12 +93,15 @@
9393
<TextBlock >Selection/Visible</TextBlock>
9494
</StackPanel>
9595
</Button>
96-
<!--<Button Click="SelectorButton_Click" Tag="VisibleInView" ToolTip="Snoop all visible elements from an active view">
96+
<Button Click="SelectorButton_Click" Tag="ElementsOnScreen" x:Name="cSelectorButtonScreen" ToolTip="Snoop all visible elements on the computer screen">
9797
<StackPanel>
98-
<Path Height="20" Style="{StaticResource IconActiveView}" />
99-
<TextBlock >View</TextBlock>
98+
<Grid Height="20">
99+
<Path Height="20" Style="{StaticResource IconScreen}" />
100+
<Path Height="10" Style="{StaticResource IconMethod}" Margin="0 -4 0 0" />
101+
</Grid>
102+
<TextBlock>Screen</TextBlock>
100103
</StackPanel>
101-
</Button>-->
104+
</Button>
102105
<Button Click="SelectorButton_Click" Tag="Db" ToolTip="Snoop Database - all elements returned from FilteredElementCollector" >
103106
<StackPanel>
104107
<Path Height="20" Style="{StaticResource IconDb}" />

sources/RevitDBExplorer/MainWindow.xaml.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ internal partial class MainWindow : Window, IAmWindowOpener, INotifyPropertyChan
4444
private bool isWiderThan800px;
4545
private string mouseStatus;
4646
private string rdqGeneratedCSharpSyntax = "";
47-
47+
private Autodesk.Revit.DB.XYZ min;
48+
private Autodesk.Revit.DB.XYZ max;
4849

4950
public QueryEditorViewModel QueryEditor => queryEditorVM;
5051
public QueryVisualizationVM QueryVisualization => queryVisualizationVM;
@@ -168,7 +169,10 @@ private async Task InitializeAsync()
168169
private void IsRevitBusyDispatcher_Tick(object sender, EventArgs e)
169170
{
170171
IsRevitBusy = Application.IsRevitBussy();
171-
(MouseStatus, rdvController.ScaleFactor) = Application.GetMouseStatus();
172+
(MouseStatus, min, max, var isValid) = Application.GetMouseStatus();
173+
cSelectorButtonScreen.IsEnabled = isValid;
174+
var v = max - min;
175+
rdvController.ScaleFactor = v.GetLength();
172176
}
173177
private void Dispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
174178
{
@@ -269,7 +273,12 @@ private void UpdateRDV()
269273
drawingVisuals.AddRange(presenter.ValueContainer.GetVisualization());
270274
}
271275
}
272-
}
276+
}
277+
278+
//var line = Autodesk.Revit.DB.Line.CreateBound(min, max);
279+
//var cd = new CurveDrawingVisual(line, new Autodesk.Revit.DB.Color(255, 0, 0));
280+
//drawingVisuals.AddRange(new DrawingVisual[] { cd, new CoordinateSystemDrawingVisual(min), new CoordinateSystemDrawingVisual(max) });
281+
273282
rdvController.AddDrawingVisuals(drawingVisuals);
274283
}
275284
}

sources/RevitDBExplorer/Resources/VectorGraphic.xaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
<StreamGeometry x:Key="vBroom">M19.36,2.72L20.78,4.14L15.06,9.85C16.13,11.39 16.28,13.24 15.38,14.44L9.06,8.12C10.26,7.22 12.11,7.37 13.65,8.44L19.36,2.72M5.93,17.57C3.92,15.56 2.69,13.16 2.35,10.92L7.23,8.83L14.67,16.27L12.58,21.15C10.34,20.81 7.94,19.58 5.93,17.57Z</StreamGeometry>
5151
<StreamGeometry x:Key="vLambda">M6,20L10.16,7.91L9.34,6H8V4H10C10.42,4 10.78,4.26 10.93,4.63L16.66,18H18V20H16C15.57,20 15.21,19.73 15.07,19.36L11.33,10.65L8.12,20H6Z</StreamGeometry>
5252
<StreamGeometry x:Key="vCodeBracesBox">M19 3H5C3.9 3 3 3.9 3 5V19C3 20.1 3.9 21 5 21H19C20.1 21 21 20.1 21 19V5C21 3.9 20.1 3 19 3M11 8H9V10C9 11.1 8.1 12 7 12C8.1 12 9 12.9 9 14V16H11V18H9C7.9 18 7 17.1 7 16V15C7 13.9 6.1 13 5 13V11C6.1 11 7 10.1 7 9V8C7 6.9 7.9 6 9 6H11V8M19 13C17.9 13 17 13.9 17 15V16C17 17.1 16.1 18 15 18H13V16H15V14C15 12.9 15.9 12 17 12C15.9 12 15 11.1 15 10V8H13V6H15C16.1 6 17 6.9 17 8V9C17 10.1 17.9 11 19 11V13Z</StreamGeometry>
53-
53+
<StreamGeometry x:Key="vMonitor">M21,16H3V4H21M21,2H3C1.89,2 1,2.89 1,4V16A2,2 0 0,0 3,18H10V20H8V22H16V20H14V18H21A2,2 0 0,0 23,16V4C23,2.89 22.1,2 21,2Z</StreamGeometry>
54+
5455

5556

5657
<Style x:Key="IconMemberKind" TargetType="Path" >
@@ -138,6 +139,12 @@
138139
<Style x:Key="IconDb" TargetType="Path" BasedOn="{StaticResource IconSelector}">
139140
<Setter Property="Data" Value="{StaticResource vDatabase}"/>
140141
</Style>
142+
<Style x:Key="IconScreen" TargetType="Path" BasedOn="{StaticResource IconSelector}">
143+
<Setter Property="Data" Value="{StaticResource vMonitor}"/>
144+
</Style>
145+
<Style x:Key="IconView" TargetType="Path" BasedOn="{StaticResource IconSelector}">
146+
<Setter Property="Data" Value="{StaticResource vCubeScan}"/>
147+
</Style>
141148
<Style x:Key="IconPickFace" TargetType="Path" BasedOn="{StaticResource IconSelector}">
142149
<Setter Property="Data" Value="{StaticResource vBorderAllVariant}"/>
143150
</Style>

0 commit comments

Comments
 (0)