Profiles - Only load nodes after the entire profile structure loaded

Profiles - Added API to get all render elements
Nodes - Added layer property node
This commit is contained in:
Robert committed 2021-08-21 13:51:25 +02:00
1 parent 836e979991
commit a4667fdc03
11 files changed
+317 -57

No files matched your search

@@ -0,0 +1,80 @@
using System.Collections.Generic;
using System.Linq;
using Artemis.Core;
using Stylet;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
{
public class LayerPropertyNodeCustomViewModel : CustomNodeViewModel
{
private readonly LayerPropertyNode _node;
private RenderProfileElement _selectedProfileElement;
private ILayerProperty _selectedLayerProperty;
public LayerPropertyNodeCustomViewModel(LayerPropertyNode node) : base(node)
{
_node = node;
}
public BindableCollection<RenderProfileElement> ProfileElements { get; } = new();
public RenderProfileElement SelectedProfileElement
{
get => _selectedProfileElement;
set
{
if (!SetAndNotify(ref _selectedProfileElement, value)) return;
_node.ChangeProfileElement(_selectedProfileElement);
GetLayerProperties();
}
}
public BindableCollection<ILayerProperty> LayerProperties { get; } = new();
public ILayerProperty SelectedLayerProperty
{
get => _selectedLayerProperty;
set
{
if (!SetAndNotify(ref _selectedLayerProperty, value)) return;
_node.ChangeLayerProperty(_selectedLayerProperty);
}
}
private void GetProfileElements()
{
ProfileElements.Clear();
if (_node.Script.Context is not Profile profile)
return;
List<RenderProfileElement> elements = new(profile.GetAllRenderElements());
ProfileElements.AddRange(elements.OrderBy(e => e.Order));
_selectedProfileElement = _node.ProfileElement;
NotifyOfPropertyChange(nameof(SelectedProfileElement));
}
private void GetLayerProperties()
{
LayerProperties.Clear();
if (_node.ProfileElement == null)
return;
LayerProperties.AddRange(_node.ProfileElement.GetAllLayerProperties().Where(l => l.GetAllDataBindingRegistrations().Any()));
_selectedLayerProperty = _node.LayerProperty;
NotifyOfPropertyChange(nameof(SelectedLayerProperty));
}
#region Overrides of CustomNodeViewModel
/// <inheritdoc />
protected override void OnDisplay()
{
GetProfileElements();
GetLayerProperties();
}
#endregion
}
}
@@ -0,0 +1,18 @@
<UserControl x:Class="Artemis.VisualScripting.Nodes.CustomViews.LayerPropertyNodeCustomView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.VisualScripting.Nodes.CustomViews"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<StackPanel>
<ComboBox Margin="8 0"
ItemsSource="{Binding ProfileElements}"
SelectedValue="{Binding SelectedProfileElement}" />
<ComboBox Margin="8 0"
ItemsSource="{Binding LayerProperties}"
SelectedValue="{Binding SelectedLayerProperty}"
DisplayMemberPath="PropertyDescription.Name"/>
</StackPanel>
</UserControl>
@@ -0,0 +1,130 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core;
using Artemis.VisualScripting.Nodes.CustomViewModels;
namespace Artemis.VisualScripting.Nodes
{
[Node("Layer/Folder Property", "Outputs the property of a selected layer or folder")]
public class LayerPropertyNode : Node<LayerPropertyNodeCustomViewModel>
{
private readonly object _layerPropertyLock = new();
public INodeScript Script { get; private set; }
public RenderProfileElement ProfileElement { get; private set; }
public ILayerProperty LayerProperty { get; private set; }
public override void Evaluate()
{
lock (_layerPropertyLock)
{
// In this case remove the pins so no further evaluations occur
if (LayerProperty == null)
{
CreatePins();
return;
}
List<IDataBindingRegistration> list = LayerProperty.GetAllDataBindingRegistrations();
int index = 0;
foreach (IPin pin in Pins)
{
OutputPin outputPin = (OutputPin) pin;
IDataBindingRegistration dataBindingRegistration = list[index];
index++;
// TODO: Is this really non-nullable?
outputPin.Value = dataBindingRegistration.GetValue();
}
}
}
public override void Initialize(INodeScript script)
{
Script = script;
if (script.Context is Profile profile)
profile.ChildRemoved += ProfileOnChildRemoved;
LoadLayerProperty();
}
public void LoadLayerProperty()
{
lock (_layerPropertyLock)
{
if (Script.Context is not Profile profile)
return;
if (Storage is not LayerPropertyNodeEntity entity)
return;
RenderProfileElement element = profile.GetAllRenderElements().FirstOrDefault(l => l.EntityId == entity.ElementId);
ProfileElement = element;
LayerProperty = element?.GetAllLayerProperties().FirstOrDefault(p => p.Path == entity.PropertyPath);
CreatePins();
}
}
public void ChangeProfileElement(RenderProfileElement profileElement)
{
lock (_layerPropertyLock)
{
ProfileElement = profileElement;
LayerProperty = null;
Storage = new LayerPropertyNodeEntity
{
ElementId = ProfileElement?.EntityId ?? Guid.Empty,
PropertyPath = null
};
CreatePins();
}
}
public void ChangeLayerProperty(ILayerProperty layerProperty)
{
lock (_layerPropertyLock)
{
LayerProperty = layerProperty;
Storage = new LayerPropertyNodeEntity
{
ElementId = ProfileElement?.EntityId ?? Guid.Empty,
PropertyPath = LayerProperty?.Path
};
CreatePins();
}
}
private void CreatePins()
{
while (Pins.Any())
RemovePin((Pin) Pins.First());
if (LayerProperty == null)
return;
foreach (IDataBindingRegistration dataBindingRegistration in LayerProperty.GetAllDataBindingRegistrations())
CreateOutputPin(dataBindingRegistration.ValueType, dataBindingRegistration.DisplayName);
}
private void ProfileOnChildRemoved(object? sender, EventArgs e)
{
if (Script.Context is not Profile profile)
return;
if (!profile.GetAllRenderElements().Contains(ProfileElement))
ChangeProfileElement(null);
}
}
public class LayerPropertyNodeEntity
{
public Guid ElementId { get; set; }
public string PropertyPath { get; set; }
}
}