Skip to content

Commit 50b3648

Browse files
committed
add tracking revit selection
1 parent 0ac43e1 commit 50b3648

File tree

13 files changed

+216
-10
lines changed

13 files changed

+216
-10
lines changed

sources/RevitDBExplorer/Application.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public Result OnStartup(UIControlledApplication application)
6565
RevitDatabaseQueryService.Init();
6666
RevitVisualizationFactory.Init(UIApplication, new ServerIdentity("Revit Explorer Visualizations", "RevitDBExplorer", ""));
6767
EventMonitor.Register(application);
68+
EventListener.Register(application);
6869

6970
ApplicationModifyTab.Init(panel.GetRibbonPanel(), AppSettings.Default.AddRDBECmdToModifyTab);
7071

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Collections.Generic;
2+
using System.Linq.Expressions;
3+
using Autodesk.Revit.UI;
4+
using RevitDBExplorer.Domain.DataModel.Accessors;
5+
using RevitDBExplorer.Domain.DataModel.Members;
6+
using RevitDBExplorer.Domain.DataModel.Members.Accessors;
7+
8+
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
9+
10+
namespace RevitDBExplorer.Domain.DataModel.MembersOverrides
11+
{
12+
internal class UIDocument_Close : MemberAccessorByType<UIDocument>, ICanCreateMemberAccessor
13+
{
14+
IEnumerable<LambdaExpression> ICanCreateMemberAccessor.GetHandledMembers() => [ (UIDocument x) => x.SaveAndClose() ];
15+
16+
17+
protected override ReadResult Read(SnoopableContext context, UIDocument value) => ReadResult.Forbidden;
18+
}
19+
}

sources/RevitDBExplorer/Domain/DataModel/MembersTemplates/Element_Templates.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public IEnumerable<ISnoopableMemberTemplate> GetTemplates() =>
3838
MemberTemplate<Element>.Create((document, target) => AnnotationMultipleAlignmentUtils.ElementSupportsMultiAlign(target)),
3939
MemberTemplate<Element>.Create((document, target) => AnnotationMultipleAlignmentUtils.GetAnnotationOutlineWithoutLeaders(target)),
4040
#endif
41+
42+
MemberTemplate<Element>.CreateWithParam((doc, target, viewMode) => doc.ActiveView.IsElementVisibleInTemporaryViewMode(viewMode, target.Id), (doc, target) => new TemporaryViewMode[] { TemporaryViewMode.TemporaryHideIsolate }),
4143
];
4244
}
4345
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using Autodesk.Revit.UI;
3+
using Autodesk.Revit.UI.Events;
4+
5+
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
6+
7+
namespace RevitDBExplorer.Domain
8+
{
9+
internal class EventListener
10+
{
11+
public static event EventHandler<SelectionChangedEventArgs> SelectionChanged;
12+
13+
14+
15+
public static void Register(UIControlledApplication application)
16+
{
17+
application.SelectionChanged += Application_SelectionChanged;
18+
}
19+
20+
21+
22+
23+
24+
private static void Application_SelectionChanged(object sender, SelectionChangedEventArgs e)
25+
{
26+
SelectionChanged?.Invoke(sender, e);
27+
}
28+
}
29+
}

sources/RevitDBExplorer/Domain/SourceOfObjects.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using System.Windows.Documents;
4+
using Autodesk.Revit.DB;
45
using Autodesk.Revit.UI;
56
using RevitDBExplorer.Domain.DataModel;
67

@@ -24,6 +25,7 @@ internal sealed class SourceOfObjects
2425

2526
public InfoAboutSource Info { get => info; init => info = value; }
2627
public IList<SnoopableObject> Objects { get; private set; } = new SnoopableObject[0];
28+
public Document RevitDocument { get; private set; }
2729

2830

2931
public SourceOfObjects()
@@ -51,14 +53,17 @@ public void ReadFromTheSource(UIApplication uiApplication)
5153
{
5254
info = sourceWithInfo.Info;
5355
}
56+
57+
RevitDocument = uiApplication.ActiveUIDocument?.Document;
5458
}
5559
}
5660

5761
internal sealed class InfoAboutSource
5862
{
5963
public string ShortTitle { get; set; } = "";
6064
public string FullTitle { get; set; } = "";
61-
public IEnumerable<Inline> FullTitleColored { get;set; }
65+
public IEnumerable<Inline> FullTitleColored { get; set; }
66+
public bool EnrichWithVisibilityData { get; set; }
6267

6368

6469
public InfoAboutSource()

sources/RevitDBExplorer/MainWindow.xaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<RowDefinition Height="auto" MaxHeight="21"/>
6161
</Grid.RowDefinitions>
6262

63-
<UniformGrid Columns="11" Margin="0 0 0 2" >
63+
<UniformGrid Columns="10" Margin="0 0 0 2" >
6464
<UniformGrid.Resources>
6565
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
6666
<Setter Property="Background" Value="Transparent"/>
@@ -108,7 +108,7 @@
108108
<Button Click="SelectorButton_Click" Tag="Db" ToolTip="Snoop Database - all elements returned from FilteredElementCollector" >
109109
<StackPanel>
110110
<Path Height="20" Style="{StaticResource IconDb}" />
111-
<TextBlock >Database</TextBlock>
111+
<TextBlock>Database</TextBlock>
112112
</StackPanel>
113113
</Button>
114114
<!--<Button Click="SelectorButton_Click" Tag="ActiveView" ToolTip="Snoop active view, &#x0a;&#x0a;source: commandData.Application.ActiveUIDocument.Document.ActiveView">
@@ -165,17 +165,23 @@
165165
<ContextMenu>
166166
<MenuItem Header="Snoop face" Click="SelectorButton_Click" Tag="PickFace" ToolTip="Snoop by selecting face in Revit"/>
167167
<MenuItem Header="Snoop edge" Icon="" Click="SelectorButton_Click" Tag="PickEdge" ToolTip="Snoop by selecting edge in Revit"/>
168+
<Separator />
169+
<MenuItem Header="Snoop an element from a linked file" Click="SelectorButton_Click" Tag="LinkedElement" ToolTip="Snoop by selecting linked element in Revit">
170+
<MenuItem.Icon>
171+
<Path Height="14" Style="{StaticResource IconLinkedElement}" />
172+
</MenuItem.Icon>
173+
</MenuItem>
168174
<!--<MenuItem Header="Snoop point on element" Icon="" Click="SelectorButton_Click" Tag="PickPoint" ToolTip="Snoop by selecting point in Revit"/>
169175
<MenuItem Header="Snoop subelement" Icon="" Click="SelectorButton_Click" Tag="PickSubelement" ToolTip="Snoop by selecting subelement in Revit"/>-->
170176
</ContextMenu>
171177
</Button.ContextMenu>
172178
</Button>
173-
<Button Click="SelectorButton_Click" Tag="LinkedElement" ToolTip="Snoop by selecting linked element in Revit">
179+
<!--<Button Click="SelectorButton_Click" Tag="LinkedElement" ToolTip="Snoop by selecting linked element in Revit">
174180
<StackPanel>
175181
<Path Height="20" Style="{StaticResource IconLinkedElement}" />
176182
<TextBlock >Linked</TextBlock>
177183
</StackPanel>
178-
</Button>
184+
</Button>-->
179185
<Button Click="SelectorButton_Click" Tag="Schemas" ToolTip="Snoop Extensible Storage framework schemas located in memory">
180186
<StackPanel>
181187
<Path Height="20" Style="{StaticResource IconSchemas}" />

sources/RevitDBExplorer/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ private void GlobalKeyboardHook_KeyDown(object sender, System.Windows.Forms.KeyE
385385
private DispatcherTimer window_SizeChanged_Debouncer;
386386
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
387387
{
388-
IsWiderThan800px = this.Width > 737;
388+
IsWiderThan800px = this.Width > 696;
389389
window_SizeChanged_Debouncer = window_SizeChanged_Debouncer.Debounce(TimeSpan.FromSeconds(4), SaveUserSettings);
390390
}
391391
private void SaveUserSettings()

sources/RevitDBExplorer/UIComponents/Trees/Base/BaseTreeView.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
</Style>
147147
<!--<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Yellow"/>-->
148148
</Style.Resources>
149-
<Style.Triggers>
149+
<Style.Triggers>
150150
<Trigger Property="IsSelected" Value="True">
151151
<Setter Property="BorderBrush" Value="{DynamicResource TreeViewItem.BorderBrush.IsSelected}" />
152152
</Trigger>
@@ -158,6 +158,9 @@
158158
<Setter Property="Foreground" Value="{DynamicResource TreeViewItem.InactiveSelectionHighlightTextBrushKey}"/>
159159
<Setter Property="Border.Background" Value="red"/>
160160
</MultiTrigger>
161+
<DataTrigger Binding="{Binding IsSelectedInRevit}" Value="True">
162+
<Setter Property="BorderBrush" Value="{DynamicResource TextBox.Focus.Border}" />
163+
</DataTrigger>
161164
</Style.Triggers>
162165
</Style>
163166
</TreeView.ItemContainerStyle>

sources/RevitDBExplorer/UIComponents/Trees/Base/BaseTreeViewModel.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.ObjectModel;
44
using System.Linq;
55
using Autodesk.Revit.DB;
6+
using RevitDBExplorer.Domain.DataModel;
67
using RevitDBExplorer.Domain.RevitDatabaseScripting;
78
using RevitDBExplorer.UIComponents.Trees.Base.Items;
89
using RevitDBExplorer.WPF;
@@ -17,6 +18,7 @@ internal class BaseTreeViewModel : BaseViewModel
1718
private ObservableCollection<TreeItem> treeItems = new();
1819
private TreeItem selectedItem;
1920
private bool allowToFrezeeItem;
21+
private bool enrichWithVisibilityData;
2022

2123
public event Action<TreeSelectedItemChangedEventArgs> SelectedItemChanged;
2224

@@ -57,6 +59,18 @@ public bool AllowToFrezeeItem
5759
OnPropertyChanged();
5860
}
5961
}
62+
public bool EnrichWithVisibilityData
63+
{
64+
get
65+
{
66+
return enrichWithVisibilityData;
67+
}
68+
set
69+
{
70+
enrichWithVisibilityData = value;
71+
OnPropertyChanged();
72+
}
73+
}
6074

6175

6276
public BaseTreeViewModel()
@@ -73,7 +87,16 @@ public void RaiseSelectedItemChanged(TreeItem item)
7387
}
7488

7589

76-
90+
public IEnumerable<SnoopableObjectTreeItem> StreamSnoopableObjectTreeItems()
91+
{
92+
foreach (var item in TreeItems)
93+
{
94+
foreach (var item2 in item.GetAllSnoopableObjectTreeItems())
95+
{
96+
yield return item2;
97+
}
98+
}
99+
}
77100

78101

79102
public static IEnumerable<object> GetObjectsForTransfer(TreeItem treeViewItem)

sources/RevitDBExplorer/UIComponents/Trees/Base/Items/TreeItem.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal abstract class TreeItem : BaseViewModel
1515
private bool isSelected = false;
1616
private bool isExpanded = false;
1717
private bool isEnabled = true;
18+
private bool isSelectedinRevit = false;
1819
private ObservableCollection<TreeItem> items = null;
1920

2021
public bool IsSelected
@@ -53,6 +54,18 @@ public bool IsEnabled
5354
OnPropertyChanged();
5455
}
5556
}
57+
public bool IsSelectedInRevit
58+
{
59+
get
60+
{
61+
return isSelectedinRevit;
62+
}
63+
set
64+
{
65+
isSelectedinRevit = value;
66+
OnPropertyChanged();
67+
}
68+
}
5669
public TreeItemsCommands Commands { get; }
5770
public ObservableCollection<TreeItem> Items
5871
{
@@ -146,5 +159,30 @@ public IEnumerable<SnoopableObject> GetAllSnoopableObjects()
146159
}
147160
}
148161
}
162+
public IEnumerable<SnoopableObjectTreeItem> GetAllSnoopableObjectTreeItems()
163+
{
164+
if (this is SnoopableObjectTreeItem snoopableObjectTreeVM)
165+
{
166+
yield return snoopableObjectTreeVM;
167+
}
168+
if (Items != null)
169+
{
170+
var collectionView = CollectionViewSource.GetDefaultView(Items);
171+
foreach (var item in collectionView.OfType<SnoopableObjectTreeItem>())
172+
{
173+
if (item.Object != null)
174+
{
175+
yield return item;
176+
}
177+
}
178+
foreach (var group in Items.OfType<GroupTreeItem>())
179+
{
180+
foreach (var item in group.GetAllSnoopableObjectTreeItems())
181+
{
182+
yield return item;
183+
}
184+
}
185+
}
186+
}
149187
}
150188
}

0 commit comments

Comments
 (0)