Skip to content

Commit

Permalink
first step for adding specialized view for parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
NeVeSpl committed Oct 9, 2023
1 parent 601cfb2 commit 62a4c8f
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 21 deletions.
17 changes: 16 additions & 1 deletion sources/RevitDBExplorer/Domain/DataModel/SnoopableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public bool IsFrozen
OnPropertyChanged();
}
}
public bool HasParameters => Object is Element;


public SnoopableObject(Document document, object @object) : this(document, @object, null)
Expand Down Expand Up @@ -109,7 +110,6 @@ public virtual IEnumerable<SnoopableMember> GetMembers(UIApplication app)
yield return member;
}
}

private static IEnumerable<SnoopableMember> CreateMembers(SnoopableObject snoopableObject)
{
foreach (var descriptor in MemberStreamer.StreamDescriptors(snoopableObject.Context, snoopableObject.Object))
Expand All @@ -120,6 +120,21 @@ private static IEnumerable<SnoopableMember> CreateMembers(SnoopableObject snoopa
}


public IEnumerable<SnoopableParameter> GetParameters(UIApplication app)
{
if (Object is Element element)
{
var parameters = element.Parameters;
foreach (var parameter in parameters)
{
var snoopableParameter = new SnoopableParameter(parameter as Parameter);
snoopableParameter.Read();
yield return snoopableParameter;
}
}
}


private bool isFrozen = false;
IList<SnoopableMember> frozenMembers;
private static readonly Type[] doNotFreeze = new Type[] { typeof(Document) , typeof(View), typeof(Element), typeof(Transform) };
Expand Down
60 changes: 53 additions & 7 deletions sources/RevitDBExplorer/Domain/DataModel/SnoopableParameter.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using RevitDBExplorer.WPF;

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

namespace RevitDBExplorer.Domain.DataModel
{
internal class SnoopableParameter
internal class SnoopableParameter : BaseViewModel
{
private Parameter parameter;



public string Name => parameter.Definition.Name;
public string Value { get; private set; }


public SnoopableParameter(Parameter parameter)
{
this.parameter = parameter;

}


public void Read()
{
var dataType = parameter.Definition.GetDataType();
bool isMeasurableSpec = UnitUtils.IsMeasurableSpec(dataType);
string value = "";
if (isMeasurableSpec)
{
value = parameter.AsValueString();
}
else
{

switch (parameter.StorageType)
{
case StorageType.String:
value = parameter.AsString();
break;
case StorageType.Integer:
value = parameter.AsInteger().ToString();
break;
case StorageType.ElementId:
value = parameter.AsValueString();
break;
case StorageType.Double:
value += parameter.AsDouble().ToString();
break;

}
}
Value = value;
OnPropertyChanged(nameof(Value));
}


}
}
}
50 changes: 42 additions & 8 deletions sources/RevitDBExplorer/UIComponents/List/ListVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ internal class ListVM : BaseViewModel
private ObservableCollection<ListItem> listItems = new();
private ObservableCollection<DynamicGridViewColumn> columns = new();
private ListItem listSelectedItem = null;
private TreeItem treeSelectedItem = null;
private string filterPhrase = "";
private bool isMemberViewVisible = true;


private bool hasParameters;


public ObservableCollection<ListItem> ListItems
{
get
Expand Down Expand Up @@ -95,10 +97,11 @@ public bool IsMemberViewVisible
{
isMemberViewVisible = value;
OnPropertyChanged();
OnPropertyChanged(nameof(IsProperyViewVisible));
OnPropertyChanged(nameof(IsParameterViewVisible));
PopulateListView();
}
}
public bool IsProperyViewVisible
public bool IsParameterViewVisible
{
get
{
Expand All @@ -109,6 +112,18 @@ public bool IsProperyViewVisible
IsMemberViewVisible = !value;
}
}
public bool HasParameters
{
get
{
return hasParameters;
}
set
{
hasParameters = value;
OnPropertyChanged();
}
}


public ListVM(IAmWindowOpener windowOpener)
Expand Down Expand Up @@ -140,13 +155,32 @@ public void ClearItems()
}
public async Task PopulateListView(SnoopableObjectTreeItem snoopableObjectTreeItem)
{
Columns = columnsFor1;
var members = await ExternalExecutor.ExecuteInRevitContextAsync(x => snoopableObjectTreeItem.Object.GetMembers(x).ToList());
ListItems = new(members.Select(x => new ListItemForSM(x, null, Reload)));
SetupListView();
treeSelectedItem = snoopableObjectTreeItem;
await PopulateListView();
}
private async Task PopulateListView()
{
HasParameters = false;
if (treeSelectedItem is SnoopableObjectTreeItem snoopableObjectTreeItem)
{
HasParameters = snoopableObjectTreeItem.Object.HasParameters;
Columns = columnsFor1;
if (IsMemberViewVisible)
{
var members = await ExternalExecutor.ExecuteInRevitContextAsync(x => snoopableObjectTreeItem.Object.GetMembers(x).ToList());
ListItems = new(members.Select(x => new ListItemForSM(x, null, Reload)));
SetupListView();
}
else
{
var parameters = await ExternalExecutor.ExecuteInRevitContextAsync(x => snoopableObjectTreeItem.Object.GetParameters(x).ToList());
ListItems = new(parameters.Select(x => new ListItemForSP(x, null, Reload)));
}
}
}
public async Task<bool> PopulateListView(UtilityGroupTreeItem utilityGroupTreeItem)
{
HasParameters = false;
if (utilityGroupTreeItem.Items?.Count < 2)
{
return false;
Expand Down
19 changes: 16 additions & 3 deletions sources/RevitDBExplorer/UIComponents/List/ListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<converters:StringToVisibilityConverter x:Key="StringToVisibilityConverter"/>
<converters:PercentageOfValueConverter x:Key="PercentageOfValueConverter"/>
<converters:EnumMatchToVisibilityConverter x:Key="EnumMatchToVisibilityConverter"/>
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" WhenFalse="Collapsed"/>
<converters:ToResourceWithKeyConverter x:Key="ToResourceWithKeyConverter" FrameworkElement="{Binding ElementName=cGrid}" />
<localWPF:DataTemplateSelectorForPropertyType x:Key="DataTemplateSelectorForPropertyType"/>
<localWPF:DynamicGridViewConverter x:Key="DynamicGridViewConverter" FrameworkElement="{Binding ElementName=cGrid}"/>
Expand Down Expand Up @@ -98,7 +99,12 @@
</DataTemplate.Resources>
</DataTemplate>


<DataTemplate DataType="{x:Type localVM:ListItemForSP}">
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding Name, Mode=OneWay}" Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
</StackPanel>
</DataTemplate>

<DataTemplate DataType="{x:Type dm:SnoopableMember}" >
<Border Background="Transparent">
<ContentPresenter
Expand All @@ -109,6 +115,13 @@
/>
</Border>
</DataTemplate>

<DataTemplate DataType="{x:Type dm:SnoopableParameter}" >
<Border Background="Transparent">
<TextBlock Text="{Binding Value, Mode=OneWay}"/>
</Border>
</DataTemplate>

</ResourceDictionary>
</Grid.Resources>

Expand All @@ -124,7 +137,7 @@
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>

<UniformGrid Rows="1" Margin="0 0 4 0" Visibility="Collapsed">
<UniformGrid Rows="1" Margin="0 0 4 0" Visibility="{Binding HasParameters, Converter={StaticResource BoolToVisibilityConverter}}">
<UniformGrid.Resources>
<Style TargetType="{x:Type ToggleButton}">
<Setter Property="MinWidth" Value="21"/>
Expand Down Expand Up @@ -155,7 +168,7 @@
</UniformGrid.Resources>

<ToggleButton Content="M" IsChecked="{Binding IsMemberViewVisible}" />
<ToggleButton Content="P" IsChecked="{Binding IsProperyViewVisible}"/>
<ToggleButton Content="P" IsChecked="{Binding IsParameterViewVisible}"/>
</UniformGrid>

<controls:TextBoxWithPlaceholder Grid.Column="1" Margin="0 0 2 0" Text="{Binding FilterPhrase, Mode=TwoWay, Delay=200, UpdateSourceTrigger=PropertyChanged}" Placeholder="Filter list by name or value"/>
Expand Down
18 changes: 17 additions & 1 deletion sources/RevitDBExplorer/UIComponents/List/ViewModels/ListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,25 @@ internal class ListItemForSP : ListItem, IListItem
{
private readonly SnoopableParameter snoopableParameter;

public ListItemForSP(SnoopableParameter x)
public override string Name => snoopableParameter.Name;
public SnoopableParameter this[int i]
{
get
{
return i switch { _ => snoopableParameter };
}
}


public ListItemForSP(SnoopableParameter x, SnoopableParameter y, Action askForReload)
{
this.snoopableParameter = x;
}


public override void Read()
{
snoopableParameter.Read();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<MenuItem Header="Draw in Revit (AVF)" Command="{Binding Commands.DrawInRevitAVF}" CommandParameter="{Binding}"/>
<Separator />

<MenuItem Header="Generate C# code for a UPDATE command (RDS) " Command="{Binding Commands.GenerateUpdateQueryRDSCommand}" CommandParameter="{Binding}">
<MenuItem Header="Generate C# code for an UPDATE command (RDS) " Command="{Binding Commands.GenerateUpdateQueryRDSCommand}" CommandParameter="{Binding}">
<MenuItem.Icon>
<Path Style="{StaticResource IconQuery}" Width="11" />
</MenuItem.Icon>
Expand Down

0 comments on commit 62a4c8f

Please sign in to comment.