Skip to content

Commit 398610b

Browse files
committed
refactoring & final adjustment of RDV
1 parent 464d288 commit 398610b

File tree

5 files changed

+74
-188
lines changed

5 files changed

+74
-188
lines changed

sources/RevitDBExplorer/MainWindow.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<Grid.RowDefinitions>
5757
<RowDefinition Height="1*" MinHeight="200"/>
5858
<RowDefinition Height="auto"/>
59-
<RowDefinition Height="{Binding Scripting.Height, Mode=TwoWay}" />
59+
<RowDefinition Height="0" />
6060
</Grid.RowDefinitions>
6161

6262
<Grid Margin="2 2 2 0" >
@@ -256,7 +256,7 @@
256256

257257
<Grid Grid.Row="2" Grid.Column="2" Margin="-2 0 0 0">
258258
<componentList:ListView DataContext="{Binding List}" Visibility="{Binding DataContext.RightView, Converter={StaticResource EnumMatchToVisibilityConverter}, ConverterParameter=List, RelativeSource={RelativeSource AncestorType=Grid}}"/>
259-
<componentCAndC:CommandAndControlView DataContext="{Binding CommandAndControl}" Margin="2 2 0 0" Visibility="{Binding DataContext.RightView, Converter={StaticResource EnumMatchToVisibilityConverter}, ConverterParameter=CommandAndControl, RelativeSource={RelativeSource AncestorType=Grid}}"/>
259+
260260
<componentList:CompareAndPinToolInfo Visibility="{Binding DataContext.RightView, Converter={StaticResource EnumMatchToVisibilityConverter}, ConverterParameter=CompareAndPinToolInfo, RelativeSource={RelativeSource AncestorType=Grid}}"/>
261261
</Grid>
262262

@@ -309,11 +309,11 @@
309309
</Grid>
310310
</ToggleButton>
311311

312-
<Button Grid.Column="2" Style="{StaticResource ToolButton}" ToolTip="Open Revit Database Scripting" Click="RDS_Click" Background="#FFF200" >
312+
<Button Grid.Column="2" Style="{StaticResource ToolButton}" ToolTip="Open Revit Database Scripting" Click="RDSButton_Click" Background="#FFF200" >
313313
<TextBlock Text="S" Foreground="#ED1A24" FontWeight="Heavy" FontFamily="Arial" FontSize="15"/>
314314
</Button>
315315

316-
<Button Grid.Column="3" Style="{StaticResource ToolButton}" ToolTip="RDBE Configuration" Click="Window_MenuItem_ConfigurationClick" >
316+
<Button Grid.Column="3" Style="{StaticResource ToolButton}" ToolTip="RDBE Configuration" Click="ConfigurationButton_Click" >
317317
<Path Style="{StaticResource IconConfig}" Opacity="0.91" />
318318
</Button>
319319
</StackPanel>
@@ -329,8 +329,8 @@
329329
</Grid>
330330
</Grid>
331331

332-
<GridSplitter Grid.Row="1" Background="{DynamicResource GridSplitter.Background}" Height="3" HorizontalAlignment="Stretch" Visibility="{Binding Scripting.IsOpen, Converter={StaticResource BoolToVisibilityConverterCollapsed}}"/>
332+
<GridSplitter Grid.Row="1" Background="{DynamicResource GridSplitter.Background}" Height="3" HorizontalAlignment="Stretch" Visibility="Collapsed"/>
333333

334-
<componentScripting:RDScriptingView DataContext="{Binding Scripting}" Grid.Row="2" Visibility="{Binding IsOpen, Converter={StaticResource BoolToVisibilityConverterCollapsed}}"/>
334+
<componentScripting:RDScriptingView Grid.Row="2" Visibility="Collapsed"/>
335335
</Grid>
336336
</Window>

sources/RevitDBExplorer/MainWindow.xaml.cs

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
using RevitDBExplorer.Domain.Selectors;
1717
using RevitDBExplorer.Properties;
1818
using RevitDBExplorer.UIComponents.Breadcrumbs;
19-
using RevitDBExplorer.UIComponents.CommandAndControl;
2019
using RevitDBExplorer.UIComponents.List;
2120
using RevitDBExplorer.UIComponents.QueryVisualization;
22-
using RevitDBExplorer.UIComponents.Scripting;
2321
using RevitDBExplorer.UIComponents.Trees.Base;
2422
using RevitDBExplorer.UIComponents.Trees.Base.Items;
2523
using RevitDBExplorer.UIComponents.Trees.Explorer;
@@ -39,10 +37,8 @@ internal partial class MainWindow : Window, IAmWindowOpener, IAmQueryExecutor, I
3937
{
4038
private readonly ExplorerTreeViewModel explorerTreeViewModel = new();
4139
private readonly UtilityTreeViewModel utilityTreeViewModel = new();
42-
private readonly ListVM listVM;
43-
private readonly CommandAndControlVM commandAndControlVM = new();
44-
private readonly QueryVisualizationVM queryVisualizationVM = new();
45-
private readonly RDScriptingVM rdscriptingVM;
40+
private readonly ListVM listVM;
41+
private readonly QueryVisualizationVM queryVisualizationVM = new();
4642
private readonly BreadcrumbsVM breadcrumbs;
4743
private RightView rightView;
4844
private string databaseQuery = string.Empty;
@@ -60,10 +56,8 @@ internal partial class MainWindow : Window, IAmWindowOpener, IAmQueryExecutor, I
6056

6157
public ExplorerTreeViewModel ExplorerTree => explorerTreeViewModel;
6258
public UtilityTreeViewModel UtilityTree => utilityTreeViewModel;
63-
public ListVM List => listVM;
64-
public CommandAndControlVM CommandAndControl => commandAndControlVM;
65-
public QueryVisualizationVM QueryVisualization => queryVisualizationVM;
66-
public RDScriptingVM Scripting => rdscriptingVM;
59+
public ListVM List => listVM;
60+
public QueryVisualizationVM QueryVisualization => queryVisualizationVM;
6761
public BreadcrumbsVM Breadcrumbs => breadcrumbs;
6862
public RightView RightView
6963
{
@@ -196,6 +190,7 @@ public bool IsBoundingBoxVisualizerEnabled
196190
set
197191
{
198192
rdvController.IsEnabled = value;
193+
UpdateRDV();
199194
OnPropertyChanged();
200195
}
201196
}
@@ -215,24 +210,23 @@ public MainWindow()
215210
{
216211
Dispatcher.UnhandledException += Dispatcher_UnhandledException;
217212
listVM = new ListVM(this, this);
213+
breadcrumbs = new BreadcrumbsVM();
218214

219215
InitializeComponent();
220216
InitializeAsync().Forget();
221217

222-
this.DataContext = this;
223-
rdscriptingVM = new RDScriptingVM();
224-
breadcrumbs = new BreadcrumbsVM();
218+
this.DataContext = this;
225219

226220
Title = WindowTitleGenerator.Get();
227221

228222
isRevitBusyDispatcher = new DispatcherTimer(TimeSpan.FromMilliseconds(500), DispatcherPriority.Background, IsRevitBusyDispatcher_Tick, Dispatcher.CurrentDispatcher);
229223

230224
ExplorerTree.SelectedItemChanged += Tree_SelectedItemChanged;
231-
ExplorerTree.ScriptWasGenerated += RDSOpenWithCommand;
225+
ExplorerTree.ScriptWasGenerated += OpenRDSWithGivenScript;
232226
UtilityTree.SelectedItemChanged += Tree_SelectedItemChanged;
233-
UtilityTree.ScriptWasGenerated += RDSOpenWithCommand;
227+
UtilityTree.ScriptWasGenerated += OpenRDSWithGivenScript;
234228

235-
OpenScriptingWithQueryCommand = new RelayCommand(RDSOpenWithQuery);
229+
OpenScriptingWithQueryCommand = new RelayCommand(GenerateScriptForQueryAndOpenRDS);
236230
SaveQueryAsFavoriteCommand = new RelayCommand(SaveQueryAsFavorite, x => !string.IsNullOrEmpty(DatabaseQuery) );
237231
rdvController = RevitDatabaseVisualizationFactory.CreateController();
238232
}
@@ -311,9 +305,9 @@ private async void Tree_SelectedItemChanged(SelectedItemChangedEventArgs eventAr
311305

312306
if (eventArgs.NewOne is SnoopableObjectTreeItem snoopableObjectTreeItem)
313307
{
314-
RightView = RightView.List;
315-
await List.PopulateListView(snoopableObjectTreeItem);
316-
rdvController.AddDrawingVisuals(snoopableObjectTreeItem.Object.GetVisualization());
308+
RightView = RightView.List;
309+
UpdateRDV();
310+
await List.PopulateListView(snoopableObjectTreeItem);
317311
return;
318312
}
319313
rdvController.RemoveAll();
@@ -384,23 +378,45 @@ private void ResetDatabaseQuery()
384378
DatabaseQueryToolTip = "";
385379
QueryVisualization.Update(Enumerable.Empty<RDQCommand>()).Forget();
386380
}
381+
private void SaveQueryAsFavorite()
382+
{
383+
FavoritesManager.Add(DatabaseQuery);
384+
}
385+
387386

388-
389-
private void RDSOpenWithQuery(object parameter)
387+
private void UpdateRDV()
390388
{
391-
var scriptText = CodeGenerator.GenerateQueryFor(DatabaseQueryToolTip);
392-
OpenRDS();
393-
Application.RDSController.SetText(scriptText);
389+
rdvController.RemoveAll();
390+
if (rdvController.IsEnabled)
391+
{
392+
var snoopableObjectTreeItem = ExplorerTree.SelectedItem as SnoopableObjectTreeItem;
393+
snoopableObjectTreeItem ??= UtilityTree.SelectedItem as SnoopableObjectTreeItem;
394+
if (snoopableObjectTreeItem != null)
395+
{
396+
rdvController.AddDrawingVisuals(snoopableObjectTreeItem.Object.GetVisualization());
397+
}
398+
}
399+
}
400+
401+
402+
private void GenerateScriptForQueryAndOpenRDS()
403+
{
404+
var scriptText = CodeGenerator.GenerateQueryFor(DatabaseQueryToolTip);
405+
OpenRDSWithGivenScript(scriptText);
394406
}
395-
private void RDSOpenWithCommand(string scriptText)
407+
private void OpenRDSWithGivenScript(string scriptText)
396408
{
397409
OpenRDS();
398410
Application.RDSController.SetText(scriptText);
399411
}
400-
private void SaveQueryAsFavorite(object parameter)
412+
private void RDSButton_Click(object sender, RoutedEventArgs e)
401413
{
402-
FavoritesManager.Add(DatabaseQuery);
414+
OpenRDS();
403415
}
416+
private void OpenRDS()
417+
{
418+
Application.RDSController.Open(this.Left, this.Top + this.ActualHeight);
419+
}
404420

405421

406422
private void Window_Closed(object sender, EventArgs e)
@@ -410,9 +426,9 @@ private void Window_Closed(object sender, EventArgs e)
410426
Dispatcher.UnhandledException -= Dispatcher_UnhandledException;
411427
isRevitBusyDispatcher.Tick -= IsRevitBusyDispatcher_Tick;
412428
ExplorerTree.SelectedItemChanged -= Tree_SelectedItemChanged;
413-
ExplorerTree.ScriptWasGenerated -= RDSOpenWithCommand;
429+
ExplorerTree.ScriptWasGenerated -= OpenRDSWithGivenScript;
414430
UtilityTree.SelectedItemChanged -= Tree_SelectedItemChanged;
415-
UtilityTree.ScriptWasGenerated -= RDSOpenWithCommand;
431+
UtilityTree.ScriptWasGenerated -= OpenRDSWithGivenScript;
416432
}
417433
private void Window_Closing(object sender, EventArgs e)
418434
{
@@ -436,7 +452,7 @@ private void Window_KeyDown(object sender, KeyEventArgs e)
436452
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
437453
{
438454
IsWiderThan800px = this.Width > 848;
439-
window_SizeChanged_Debouncer = window_SizeChanged_Debouncer.Debounce(TimeSpan.FromSeconds(1), SaveUserSettings);
455+
window_SizeChanged_Debouncer = window_SizeChanged_Debouncer.Debounce(TimeSpan.FromSeconds(4), SaveUserSettings);
440456
}
441457
private void SaveUserSettings()
442458
{
@@ -445,28 +461,15 @@ private void SaveUserSettings()
445461
AppSettings.Default.FirstColumnWidth = cFirstColumnDefinition.Width.Value;
446462
AppSettings.Default.Save();
447463
}
448-
private void Window_MenuItem_ConfigurationClick(object sender, RoutedEventArgs e)
464+
private void ConfigurationButton_Click(object sender, RoutedEventArgs e)
449465
{
450466
var window = new ConfigWindow();
451467
window.Owner = this;
452468
window.ShowDialog();
453-
foreach (ResourceDictionary dict in Resources.MergedDictionaries)
454-
{
455-
if (dict is ThemeResourceDictionary skinDict)
456-
skinDict.UpdateSource();
457-
}
469+
ThemeResourceDictionary.Update(Resources);
458470
}
459471

460472

461-
private void RDS_Click(object sender, RoutedEventArgs e)
462-
{
463-
OpenRDS();
464-
}
465-
private void OpenRDS()
466-
{
467-
Application.RDSController.Open(this.Left, this.Top + this.ActualHeight);
468-
}
469-
470473
#region INotifyPropertyChanged
471474

472475
public event PropertyChangedEventHandler PropertyChanged;
Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,19 @@
1-
using System.Collections.ObjectModel;
2-
using System.Linq;
3-
using System.Threading.Tasks;
4-
using System.Windows.Controls;
5-
using Autodesk.Revit.DB;
6-
using RevitDBExplorer.Domain;
7-
using RevitDBExplorer.UIComponents.Trees.Base.Items;
8-
using RevitDBExplorer.WPF;
9-
using Binding = System.Windows.Data.Binding;
1+
using RevitDBExplorer.WPF;
102

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

135
namespace RevitDBExplorer.UIComponents.CommandAndControl
146
{
157
internal class CommandAndControlVM : BaseViewModel
168
{
17-
private GroupTreeItem selectedGroup;
18-
private int itemsCount;
19-
20-
21-
public int ItemsCount
22-
{
23-
get
24-
{
25-
return itemsCount;
26-
}
27-
set
28-
{
29-
itemsCount = value;
30-
OnPropertyChanged();
31-
}
32-
}
9+
3310

3411

35-
3612
public CommandAndControlVM()
3713
{
3814

3915
}
4016

4117

42-
public async Task SetInput(GroupTreeItem groupTreeItemVM)
43-
{
44-
selectedGroup = groupTreeItemVM;
45-
ItemsCount = selectedGroup.GetAllSnoopableObjects().Select(x => x.Object).OfType<Element>().Count();
46-
var elements = selectedGroup.GetAllSnoopableObjects().Select(x => x.Object).OfType<Element>().Take(100).ToArray();
47-
48-
49-
}
5018
}
5119
}

0 commit comments

Comments
 (0)