Skip to content

Commit

Permalink
refactoring & final adjustment of RDV
Browse files Browse the repository at this point in the history
  • Loading branch information
NeVeSpl committed Oct 29, 2023
1 parent 464d288 commit 398610b
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 188 deletions.
12 changes: 6 additions & 6 deletions sources/RevitDBExplorer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="1*" MinHeight="200"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="{Binding Scripting.Height, Mode=TwoWay}" />
<RowDefinition Height="0" />
</Grid.RowDefinitions>

<Grid Margin="2 2 2 0" >
Expand Down Expand Up @@ -256,7 +256,7 @@

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

<componentList:CompareAndPinToolInfo Visibility="{Binding DataContext.RightView, Converter={StaticResource EnumMatchToVisibilityConverter}, ConverterParameter=CompareAndPinToolInfo, RelativeSource={RelativeSource AncestorType=Grid}}"/>
</Grid>

Expand Down Expand Up @@ -309,11 +309,11 @@
</Grid>
</ToggleButton>

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

<Button Grid.Column="3" Style="{StaticResource ToolButton}" ToolTip="RDBE Configuration" Click="Window_MenuItem_ConfigurationClick" >
<Button Grid.Column="3" Style="{StaticResource ToolButton}" ToolTip="RDBE Configuration" Click="ConfigurationButton_Click" >
<Path Style="{StaticResource IconConfig}" Opacity="0.91" />
</Button>
</StackPanel>
Expand All @@ -329,8 +329,8 @@
</Grid>
</Grid>

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

<componentScripting:RDScriptingView DataContext="{Binding Scripting}" Grid.Row="2" Visibility="{Binding IsOpen, Converter={StaticResource BoolToVisibilityConverterCollapsed}}"/>
<componentScripting:RDScriptingView Grid.Row="2" Visibility="Collapsed"/>
</Grid>
</Window>
93 changes: 48 additions & 45 deletions sources/RevitDBExplorer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
using RevitDBExplorer.Domain.Selectors;
using RevitDBExplorer.Properties;
using RevitDBExplorer.UIComponents.Breadcrumbs;
using RevitDBExplorer.UIComponents.CommandAndControl;
using RevitDBExplorer.UIComponents.List;
using RevitDBExplorer.UIComponents.QueryVisualization;
using RevitDBExplorer.UIComponents.Scripting;
using RevitDBExplorer.UIComponents.Trees.Base;
using RevitDBExplorer.UIComponents.Trees.Base.Items;
using RevitDBExplorer.UIComponents.Trees.Explorer;
Expand All @@ -39,10 +37,8 @@ internal partial class MainWindow : Window, IAmWindowOpener, IAmQueryExecutor, I
{
private readonly ExplorerTreeViewModel explorerTreeViewModel = new();
private readonly UtilityTreeViewModel utilityTreeViewModel = new();
private readonly ListVM listVM;
private readonly CommandAndControlVM commandAndControlVM = new();
private readonly QueryVisualizationVM queryVisualizationVM = new();
private readonly RDScriptingVM rdscriptingVM;
private readonly ListVM listVM;
private readonly QueryVisualizationVM queryVisualizationVM = new();
private readonly BreadcrumbsVM breadcrumbs;
private RightView rightView;
private string databaseQuery = string.Empty;
Expand All @@ -60,10 +56,8 @@ internal partial class MainWindow : Window, IAmWindowOpener, IAmQueryExecutor, I

public ExplorerTreeViewModel ExplorerTree => explorerTreeViewModel;
public UtilityTreeViewModel UtilityTree => utilityTreeViewModel;
public ListVM List => listVM;
public CommandAndControlVM CommandAndControl => commandAndControlVM;
public QueryVisualizationVM QueryVisualization => queryVisualizationVM;
public RDScriptingVM Scripting => rdscriptingVM;
public ListVM List => listVM;
public QueryVisualizationVM QueryVisualization => queryVisualizationVM;
public BreadcrumbsVM Breadcrumbs => breadcrumbs;
public RightView RightView
{
Expand Down Expand Up @@ -196,6 +190,7 @@ public bool IsBoundingBoxVisualizerEnabled
set
{
rdvController.IsEnabled = value;
UpdateRDV();
OnPropertyChanged();
}
}
Expand All @@ -215,24 +210,23 @@ public MainWindow()
{
Dispatcher.UnhandledException += Dispatcher_UnhandledException;
listVM = new ListVM(this, this);
breadcrumbs = new BreadcrumbsVM();

InitializeComponent();
InitializeAsync().Forget();

this.DataContext = this;
rdscriptingVM = new RDScriptingVM();
breadcrumbs = new BreadcrumbsVM();
this.DataContext = this;

Title = WindowTitleGenerator.Get();

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

ExplorerTree.SelectedItemChanged += Tree_SelectedItemChanged;
ExplorerTree.ScriptWasGenerated += RDSOpenWithCommand;
ExplorerTree.ScriptWasGenerated += OpenRDSWithGivenScript;
UtilityTree.SelectedItemChanged += Tree_SelectedItemChanged;
UtilityTree.ScriptWasGenerated += RDSOpenWithCommand;
UtilityTree.ScriptWasGenerated += OpenRDSWithGivenScript;

OpenScriptingWithQueryCommand = new RelayCommand(RDSOpenWithQuery);
OpenScriptingWithQueryCommand = new RelayCommand(GenerateScriptForQueryAndOpenRDS);
SaveQueryAsFavoriteCommand = new RelayCommand(SaveQueryAsFavorite, x => !string.IsNullOrEmpty(DatabaseQuery) );
rdvController = RevitDatabaseVisualizationFactory.CreateController();
}
Expand Down Expand Up @@ -311,9 +305,9 @@ private async void Tree_SelectedItemChanged(SelectedItemChangedEventArgs eventAr

if (eventArgs.NewOne is SnoopableObjectTreeItem snoopableObjectTreeItem)
{
RightView = RightView.List;
await List.PopulateListView(snoopableObjectTreeItem);
rdvController.AddDrawingVisuals(snoopableObjectTreeItem.Object.GetVisualization());
RightView = RightView.List;
UpdateRDV();
await List.PopulateListView(snoopableObjectTreeItem);
return;
}
rdvController.RemoveAll();
Expand Down Expand Up @@ -384,23 +378,45 @@ private void ResetDatabaseQuery()
DatabaseQueryToolTip = "";
QueryVisualization.Update(Enumerable.Empty<RDQCommand>()).Forget();
}
private void SaveQueryAsFavorite()
{
FavoritesManager.Add(DatabaseQuery);
}



private void RDSOpenWithQuery(object parameter)
private void UpdateRDV()
{
var scriptText = CodeGenerator.GenerateQueryFor(DatabaseQueryToolTip);
OpenRDS();
Application.RDSController.SetText(scriptText);
rdvController.RemoveAll();
if (rdvController.IsEnabled)
{
var snoopableObjectTreeItem = ExplorerTree.SelectedItem as SnoopableObjectTreeItem;
snoopableObjectTreeItem ??= UtilityTree.SelectedItem as SnoopableObjectTreeItem;
if (snoopableObjectTreeItem != null)
{
rdvController.AddDrawingVisuals(snoopableObjectTreeItem.Object.GetVisualization());
}
}
}


private void GenerateScriptForQueryAndOpenRDS()
{
var scriptText = CodeGenerator.GenerateQueryFor(DatabaseQueryToolTip);
OpenRDSWithGivenScript(scriptText);
}
private void RDSOpenWithCommand(string scriptText)
private void OpenRDSWithGivenScript(string scriptText)
{
OpenRDS();
Application.RDSController.SetText(scriptText);
}
private void SaveQueryAsFavorite(object parameter)
private void RDSButton_Click(object sender, RoutedEventArgs e)
{
FavoritesManager.Add(DatabaseQuery);
OpenRDS();
}
private void OpenRDS()
{
Application.RDSController.Open(this.Left, this.Top + this.ActualHeight);
}


private void Window_Closed(object sender, EventArgs e)
Expand All @@ -410,9 +426,9 @@ private void Window_Closed(object sender, EventArgs e)
Dispatcher.UnhandledException -= Dispatcher_UnhandledException;
isRevitBusyDispatcher.Tick -= IsRevitBusyDispatcher_Tick;
ExplorerTree.SelectedItemChanged -= Tree_SelectedItemChanged;
ExplorerTree.ScriptWasGenerated -= RDSOpenWithCommand;
ExplorerTree.ScriptWasGenerated -= OpenRDSWithGivenScript;
UtilityTree.SelectedItemChanged -= Tree_SelectedItemChanged;
UtilityTree.ScriptWasGenerated -= RDSOpenWithCommand;
UtilityTree.ScriptWasGenerated -= OpenRDSWithGivenScript;
}
private void Window_Closing(object sender, EventArgs e)
{
Expand All @@ -436,7 +452,7 @@ private void Window_KeyDown(object sender, KeyEventArgs e)
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
IsWiderThan800px = this.Width > 848;
window_SizeChanged_Debouncer = window_SizeChanged_Debouncer.Debounce(TimeSpan.FromSeconds(1), SaveUserSettings);
window_SizeChanged_Debouncer = window_SizeChanged_Debouncer.Debounce(TimeSpan.FromSeconds(4), SaveUserSettings);
}
private void SaveUserSettings()
{
Expand All @@ -445,28 +461,15 @@ private void SaveUserSettings()
AppSettings.Default.FirstColumnWidth = cFirstColumnDefinition.Width.Value;
AppSettings.Default.Save();
}
private void Window_MenuItem_ConfigurationClick(object sender, RoutedEventArgs e)
private void ConfigurationButton_Click(object sender, RoutedEventArgs e)
{
var window = new ConfigWindow();
window.Owner = this;
window.ShowDialog();
foreach (ResourceDictionary dict in Resources.MergedDictionaries)
{
if (dict is ThemeResourceDictionary skinDict)
skinDict.UpdateSource();
}
ThemeResourceDictionary.Update(Resources);
}


private void RDS_Click(object sender, RoutedEventArgs e)
{
OpenRDS();
}
private void OpenRDS()
{
Application.RDSController.Open(this.Left, this.Top + this.ActualHeight);
}

#region INotifyPropertyChanged

public event PropertyChangedEventHandler PropertyChanged;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,19 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Controls;
using Autodesk.Revit.DB;
using RevitDBExplorer.Domain;
using RevitDBExplorer.UIComponents.Trees.Base.Items;
using RevitDBExplorer.WPF;
using Binding = System.Windows.Data.Binding;
using RevitDBExplorer.WPF;

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

namespace RevitDBExplorer.UIComponents.CommandAndControl
{
internal class CommandAndControlVM : BaseViewModel
{
private GroupTreeItem selectedGroup;
private int itemsCount;


public int ItemsCount
{
get
{
return itemsCount;
}
set
{
itemsCount = value;
OnPropertyChanged();
}
}




public CommandAndControlVM()
{

}


public async Task SetInput(GroupTreeItem groupTreeItemVM)
{
selectedGroup = groupTreeItemVM;
ItemsCount = selectedGroup.GetAllSnoopableObjects().Select(x => x.Object).OfType<Element>().Count();
var elements = selectedGroup.GetAllSnoopableObjects().Select(x => x.Object).OfType<Element>().Take(100).ToArray();


}
}
}
Loading

0 comments on commit 398610b

Please sign in to comment.