1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Data bindings - WIP commit

This commit is contained in:
SpoinkyNL 2020-09-06 20:00:56 +02:00
parent 7bcac904fc
commit 1dc58fd09a
42 changed files with 902 additions and 356 deletions

View File

@ -9,7 +9,11 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Cconditions_005Cabstract/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Cconditions_005Coperators/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Cdatabindings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Cdatabindings_005Cconverters/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Cdatabindings_005Cdatabindingproperties/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Cdatabindings_005Cdatabindingproperties_005Cabstract/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Cdatabindings_005Cmodifiers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Cdatabindings_005Cmodifiers_005Cabstract/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Clayerproperties/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Clayerproperties_005Cattributes/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Clayerproperties_005Ctypes/@EntryIndexedValue">True</s:Boolean>

View File

@ -0,0 +1,17 @@
using System;
namespace Artemis.Core
{
public class DataBindingPropertyUpdatedEvent<T> : EventArgs
{
public DataBindingPropertyUpdatedEvent(T value)
{
Value = value;
}
/// <summary>
/// The updated value that should be applied to the layer property
/// </summary>
public T Value { get; }
}
}

View File

@ -86,5 +86,13 @@ namespace Artemis.Core
);
return castable;
}
/// <summary>
/// Returns the default value of the given type
/// </summary>
public static object GetDefault(this Type type)
{
return type.IsValueType ? Activator.CreateInstance(type) : null;
}
}
}

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Artemis.Core.Models.Profile.DataBindings.Converters
{
public class FloatDataBindingConverter : IDataBindingConverter
{
public BaseLayerProperty BaseLayerProperty { get; set; }
public object Sum(object a, object b)
{
return (float) a + (float) b;
}
public object Interpolate(object a, object b, float progress)
{
throw new NotImplementedException();
}
public void ApplyValue(object value)
{
throw new NotImplementedException();
}
public object GetValue()
{
throw new NotImplementedException();
}
}
}

View File

@ -17,15 +17,23 @@ namespace Artemis.Core
private readonly List<DataBindingModifier> _modifiers = new List<DataBindingModifier>();
private bool _isInitialized;
internal DataBinding(BaseLayerProperty layerProperty, PropertyInfo targetProperty)
private object _currentValue;
private object _previousValue;
private float _easingProgress;
internal DataBinding(DataBindingRegistration dataBindingRegistration)
{
LayerProperty = layerProperty;
TargetProperty = targetProperty;
LayerProperty = dataBindingRegistration.LayerProperty;
TargetProperty = dataBindingRegistration.Property;
Registration = dataBindingRegistration;
Entity = new DataBindingEntity();
ApplyToEntity();
}
public DataBindingRegistration Registration { get; private set; }
internal DataBinding(BaseLayerProperty layerProperty, DataBindingEntity entity)
{
LayerProperty = layerProperty;
@ -87,6 +95,8 @@ namespace Artemis.Core
{
modifier.DataBinding = this;
_modifiers.Add(modifier);
OnModifiersUpdated();
}
}
@ -99,6 +109,8 @@ namespace Artemis.Core
{
modifier.DataBinding = null;
_modifiers.Remove(modifier);
OnModifiersUpdated();
}
}
@ -132,14 +144,6 @@ namespace Artemis.Core
/// <returns></returns>
public object GetValue(object baseValue)
{
// Validating this is kinda expensive, it'll fail on ChangeType later anyway ^^
// var targetType = TargetProperty.PropertyType;
// if (!targetType.IsCastableFrom(baseValue.GetType()))
// {
// throw new ArtemisCoreException($"The provided current value type ({baseValue.GetType().Name}) not match the " +
// $"target property type ({targetType.Name})");
// }
if (CompiledTargetAccessor == null)
return baseValue;
@ -147,11 +151,54 @@ namespace Artemis.Core
foreach (var dataBindingModifier in Modifiers)
dataBindingValue = dataBindingModifier.Apply(dataBindingValue);
return Convert.ChangeType(dataBindingValue, TargetProperty.PropertyType);
var value = Convert.ChangeType(dataBindingValue, TargetProperty.PropertyType);
// If no easing is to be applied simple return whatever the current value is
if (EasingTime == TimeSpan.Zero)
return value;
// If the value changed, update the current and previous values used for easing
if (!Equals(value, _currentValue))
{
_previousValue = GetInterpolatedValue();
_currentValue = value;
_easingProgress = 0f;
}
// Apply interpolation between the previous and current value
return GetInterpolatedValue();
}
internal void Update(double deltaTime)
/// <summary>
/// Returns the type of the source property of this data binding
/// </summary>
public Type GetSourceType()
{
return SourceDataModel?.GetTypeAtPath(SourcePropertyPath);
}
/// <summary>
/// Updates the smoothing progress of the data binding
/// </summary>
/// <param name="deltaTime"></param>
public void Update(double deltaTime)
{
}
/// <summary>
/// Applies the data binding to the <see cref="Property"/>
/// </summary>
public void ApplyToProperty()
{
}
private object GetInterpolatedValue()
{
if (_easingProgress >= 1.0f)
return _currentValue;
return Registration.Converter.Interpolate(_previousValue, _currentValue, _easingProgress);
}
internal void ApplyToEntity()
@ -227,6 +274,20 @@ namespace Artemis.Core
var lambda = Expression.Lambda<Func<DataModel, object>>(returnValue, parameter);
CompiledTargetAccessor = lambda.Compile();
}
#region Events
/// <summary>
/// Occurs when a modifier is added or removed
/// </summary>
public event EventHandler ModifiersUpdated;
protected virtual void OnModifiersUpdated()
{
ModifiersUpdated?.Invoke(this, EventArgs.Empty);
}
#endregion
}
/// <summary>

View File

@ -4,6 +4,7 @@ using System.Linq.Expressions;
using Artemis.Core.DataModelExpansions;
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile.DataBindings;
using LiteDB.Engine;
using Microsoft.VisualBasic;
using Newtonsoft.Json;
@ -82,14 +83,9 @@ namespace Artemis.Core
public object ParameterStaticValue { get; private set; }
/// <summary>
/// Gets the compiled function that evaluates this predicate if it of a dynamic <see cref="ParameterType" />
/// A compiled expression tree that when given a matching data model returns the value of the modifiers parameter
/// </summary>
public Func<object, DataModel, object> CompiledDynamicPredicate { get; private set; }
/// <summary>
/// Gets the compiled function that evaluates this predicate if it is of a static <see cref="ParameterType" />
/// </summary>
public Func<object, object> CompiledStaticPredicate { get; private set; }
public Func<DataModel, object> CompiledParameterAccessor { get; set; }
internal DataBindingModifierEntity Entity { get; set; }
@ -100,10 +96,14 @@ namespace Artemis.Core
/// <returns>The modified value</returns>
public object Apply(object currentValue)
{
if (CompiledDynamicPredicate != null)
return CompiledDynamicPredicate(currentValue, ParameterDataModel);
if (CompiledStaticPredicate != null)
return CompiledStaticPredicate(currentValue);
if (ParameterType == ProfileRightSideType.Dynamic && CompiledParameterAccessor != null)
{
var value = CompiledParameterAccessor(ParameterDataModel);
return ModifierType.Apply(currentValue, value);
}
if (ParameterType == ProfileRightSideType.Static)
return ModifierType.Apply(currentValue, ParameterStaticValue);
return currentValue;
}
@ -122,7 +122,7 @@ namespace Artemis.Core
return;
}
var targetType = DataBinding.TargetProperty.GetType();
var targetType = DataBinding.TargetProperty.PropertyType;
if (!modifierType.SupportsType(targetType))
{
throw new ArtemisCoreException($"Cannot apply modifier type {modifierType.GetType().Name} to this modifier because " +
@ -168,7 +168,7 @@ namespace Artemis.Core
ParameterDataModel = null;
ParameterPropertyPath = null;
var targetType = DataBinding.TargetProperty.GetType();
var targetType = DataBinding.TargetProperty.PropertyType;
// If not null ensure the types match and if not, convert it
if (staticValue != null && staticValue.GetType() == targetType)
@ -208,7 +208,7 @@ namespace Artemis.Core
else if (ParameterType == ProfileRightSideType.Static && Entity.ParameterStaticValue != null)
{
// Use the target type so JSON.NET has a better idea what to do
var targetType = DataBinding.TargetProperty.GetType();
var targetType = DataBinding.TargetProperty.PropertyType;
object staticValue;
try
@ -231,52 +231,23 @@ namespace Artemis.Core
private void CreateExpression()
{
CompiledDynamicPredicate = null;
CompiledStaticPredicate = null;
CompiledParameterAccessor = null;
if (ModifierType == null || DataBinding == null)
return;
if (ParameterType == ProfileRightSideType.Dynamic && ModifierType.SupportsParameter)
CreateDynamicExpression();
else
CreateStaticExpression();
{
if (ParameterDataModel == null)
return;
// If the right side value is null, the constant type cannot be inferred and must be provided based on the data binding target
var parameterAccessor = CreateAccessor(ParameterDataModel, ParameterPropertyPath, "parameter", out var rightSideParameter);
var lambda = Expression.Lambda<Func<DataModel, object>>(Expression.Convert(parameterAccessor, typeof(object)), rightSideParameter);
CompiledParameterAccessor = lambda.Compile();
}
}
private void CreateDynamicExpression()
{
if (ParameterDataModel == null)
return;
var currentValueParameter = Expression.Parameter(DataBinding.TargetProperty.GetType());
// If the right side value is null, the constant type cannot be inferred and must be provided based on the data binding target
var rightSideAccessor = CreateAccessor(ParameterDataModel, ParameterPropertyPath, "right", out var rightSideParameter);
// A conversion may be required if the types differ
// This can cause issues if the DisplayConditionOperator wasn't accurate in it's supported types but that is not a concern here
if (rightSideAccessor.Type != DataBinding.TargetProperty.GetType())
rightSideAccessor = Expression.Convert(rightSideAccessor, DataBinding.TargetProperty.GetType());
var modifierExpression = ModifierType.CreateExpression(currentValueParameter, rightSideAccessor);
var lambda = Expression.Lambda<Func<object, DataModel, object>>(modifierExpression, currentValueParameter, rightSideParameter);
CompiledDynamicPredicate = lambda.Compile();
}
private void CreateStaticExpression()
{
var currentValueParameter = Expression.Parameter(DataBinding.TargetProperty.GetType());
// If the right side value is null, the constant type cannot be inferred and must be provided based on the data binding target
var rightSideConstant = ParameterStaticValue != null
? Expression.Constant(ParameterStaticValue)
: Expression.Constant(null, DataBinding.TargetProperty.GetType());
var modifierExpression = ModifierType.CreateExpression(currentValueParameter, rightSideConstant);
var lambda = Expression.Lambda<Func<object, object>>(modifierExpression, currentValueParameter);
CompiledStaticPredicate = lambda.Compile();
}
private Expression CreateAccessor(DataModel dataModel, string path, string parameterName, out ParameterExpression parameter)
{
var listType = dataModel.GetListTypeInPath(path);

View File

@ -0,0 +1,19 @@
using System;
using System.Reflection;
namespace Artemis.Core
{
public class DataBindingRegistration
{
internal DataBindingRegistration(BaseLayerProperty layerProperty, PropertyInfo property, IDataBindingConverter converter)
{
LayerProperty = layerProperty ?? throw new ArgumentNullException(nameof(layerProperty));
Property = property ?? throw new ArgumentNullException(nameof(property));
Converter = converter ?? throw new ArgumentNullException(nameof(converter));
}
public BaseLayerProperty LayerProperty { get; set; }
public PropertyInfo Property { get; set; }
public IDataBindingConverter Converter { get; set; }
}
}

View File

@ -0,0 +1,38 @@
namespace Artemis.Core
{
/// <summary>
/// A data binding converter that acts as the bridge between a <see cref="DataBinding" /> and a
/// <see cref="LayerProperty{T}" />
/// </summary>
public interface IDataBindingConverter
{
public BaseLayerProperty BaseLayerProperty { get; set; }
/// <summary>
/// Returns the sum of <paramref name="a" /> and <paramref name="b" />
/// </summary>
object Sum(object a, object b);
/// <summary>
/// Returns the the interpolated value between <paramref name="a" /> and <paramref name="b" /> on a scale (generally)
/// between <c>0.0</c> and <c>1.0</c> defined by the <paramref name="progress" />
/// <para>Note: The progress may go be negative or go beyond <c>1.0</c> depending on the easing method used</para>
/// </summary>
/// <param name="a">The value to interpolate away from</param>
/// <param name="b">The value to interpolate towards</param>
/// <param name="progress">The progress of the interpolation between 0.0 and 1.0</param>
/// <returns></returns>
object Interpolate(object a, object b, float progress);
/// <summary>
/// Applies the <paramref name="value" /> to the layer property
/// </summary>
/// <param name="value"></param>
void ApplyValue(object value);
/// <summary>
/// Returns the current base value of the data binding
/// </summary>
object GetValue();
}
}

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Artemis.Core.Services;
namespace Artemis.Core
@ -51,12 +50,19 @@ namespace Artemis.Core
}
/// <summary>
/// Creates a binary expression comparing two types
/// Called whenever the modifier must apply to a specific value, must be a value of a type contained in
/// <see cref="CompatibleTypes" />
/// </summary>
/// <param name="currentValue">The current value of the data binding</param>
/// <param name="modifierArgument">An argument passed to the modifier, either static of dynamic</param>
/// <returns></returns>
public abstract Expression<object> CreateExpression(ParameterExpression currentValue, Expression modifierArgument);
/// <param name="currentValue">
/// The current value before modification, is always of a type contained in
/// <see cref="CompatibleTypes" />
/// </param>
/// <param name="parameterValue">
/// The parameter to use for the modification, is always of a type contained in
/// <see cref="CompatibleTypes" />
/// </param>
/// <returns>The modified value, must be a value of a type contained in <see cref="CompatibleTypes" /></returns>
public abstract object Apply(object currentValue, object parameterValue);
internal void Register(PluginInfo pluginInfo, IDataBindingService dataBindingService)
{

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core
{
internal class DivideModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Description => "Divide by";
public override string Icon => "Divide";
public override object Apply(object currentValue, object parameterValue)
{
var parameter = Convert.ToSingle(parameterValue);
// Ye ye none of that
if (parameter == 0)
return 0;
return Convert.ToSingle(currentValue) / parameter;
}
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core
{
internal class MultiplicationModifierType : DataBindingModifierType
{
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Description => "Multiply by";
public override string Icon => "Close";
public override object Apply(object currentValue, object parameterValue)
{
return Convert.ToSingle(currentValue) * Convert.ToSingle(parameterValue);
}
}
}

View File

@ -186,9 +186,6 @@ namespace Artemis.Core
Transform.ApplyToEntity();
LayerBrush?.BaseProperties.ApplyToEntity();
// Effects
ApplyRenderElementToEntity();
// LEDs
LayerEntity.Leds.Clear();
foreach (var artemisLed in Leds)
@ -204,6 +201,8 @@ namespace Artemis.Core
// Conditions
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.Entity;
DisplayConditionGroup?.ApplyToEntity();
ApplyRenderElementToEntity();
}
#endregion
@ -313,6 +312,18 @@ namespace Artemis.Core
}
}
/// <inheritdoc />
public override List<BaseLayerProperty> GetAllLayerProperties()
{
var result = base.GetAllLayerProperties();
result.AddRange(General.GetAllLayerProperties());
result.AddRange(Transform.GetAllLayerProperties());
if (LayerBrush?.BaseProperties != null)
result.AddRange(LayerBrush.BaseProperties.GetAllLayerProperties());
return result;
}
/// <inheritdoc />
public override void Render(double deltaTime, SKCanvas canvas, SKImageInfo canvasInfo)
{

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core
@ -11,6 +12,7 @@ namespace Artemis.Core
public abstract class BaseLayerProperty
{
protected readonly List<DataBinding> _dataBindings = new List<DataBinding>();
protected readonly List<DataBindingRegistration> _dataBindingRegistrations = new List<DataBindingRegistration>();
private bool _isHidden;
private bool _keyframesEnabled;
@ -18,6 +20,11 @@ namespace Artemis.Core
{
}
/// <summary>
/// Gets a list containing the active data bindings
/// </summary>
public IReadOnlyList<DataBinding> DataBindings => _dataBindings.AsReadOnly();
/// <summary>
/// Gets the profile element (such as layer or folder) this effect is applied to
/// </summary>
@ -38,11 +45,6 @@ namespace Artemis.Core
/// </summary>
public bool DataBindingsSupported { get; protected internal set; } = true;
/// <summary>
/// Gets a read-only collection of the currently applied data bindings
/// </summary>
public IReadOnlyCollection<DataBinding> DataBindings => _dataBindings.AsReadOnly();
/// <summary>
/// Gets or sets whether keyframes are enabled on this property, has no effect if <see cref="KeyframesSupported" /> is
/// False
@ -104,18 +106,6 @@ namespace Artemis.Core
/// </summary>
public abstract Type GetPropertyType();
/// <summary>
/// Returns a list of properties to which data bindings can be applied
/// </summary>
/// <returns></returns>
public abstract List<PropertyInfo> GetDataBindingProperties();
/// <summary>
/// Called when the provided data binding must be applied to a property
/// </summary>
/// <param name="dataBinding"></param>
protected abstract void ApplyDataBinding(DataBinding dataBinding);
/// <summary>
/// Applies the provided property entity to the layer property by deserializing the JSON base value and keyframe values
/// </summary>
@ -132,23 +122,26 @@ namespace Artemis.Core
#region Data bindings
/// <summary>
/// Applies the current <see cref="DataBindings" /> to the layer property
/// </summary>
public void ApplyDataBindings()
internal DataBindingRegistration RegisterDataBindingProperty(PropertyInfo property, IDataBindingConverter converter)
{
var registration = new DataBindingRegistration(this, property, converter);
_dataBindingRegistrations.Add(registration);
return registration;
}
internal void InitializeDataBindings(IDataModelService dataModelService, IDataBindingService dataBindingService)
{
foreach (var dataBinding in DataBindings)
ApplyDataBinding(dataBinding);
dataBinding.Initialize(dataModelService, dataBindingService);
}
/// <summary>
/// Adds a new data binding targeting the given property to the <see cref="DataBindings" /> collection
/// </summary>
/// <param name="targetProperty">The property the new data binding should target</param>
/// <returns>The newly created data binding</returns>
public DataBinding AddDataBinding(PropertyInfo targetProperty)
public DataBinding EnableDataBinding(DataBindingRegistration dataBindingRegistration)
{
var dataBinding = new DataBinding(this, targetProperty);
var dataBinding = new DataBinding(this, dataBindingProperty);
_dataBindings.Add(dataBinding);
return dataBinding;
@ -158,13 +151,11 @@ namespace Artemis.Core
/// Removes the provided data binding from the <see cref="DataBindings" /> collection
/// </summary>
/// <param name="dataBinding">The data binding to remove</param>
public void RemoveDataBinding(DataBinding dataBinding)
public void DisableDataBinding(DataBinding dataBinding)
{
_dataBindings.Remove(dataBinding);
}
#endregion
#region Events

View File

@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Artemis.Core.DataModelExpansions;
using Artemis.Storage.Entities.Profile;
using Newtonsoft.Json;
@ -16,7 +18,7 @@ namespace Artemis.Core
/// </para>
/// </summary>
/// <typeparam name="T">The type of property encapsulated in this layer property</typeparam>
public class LayerProperty<T> : BaseLayerProperty
public abstract class LayerProperty<T> : BaseLayerProperty
{
private T _baseValue;
private bool _isInitialized;
@ -198,41 +200,6 @@ namespace Artemis.Core
OnUpdated();
}
private void UpdateKeyframes()
{
if (!KeyframesSupported || !KeyframesEnabled)
return;
// The current keyframe is the last keyframe before the current time
CurrentKeyframe = _keyframes.LastOrDefault(k => k.Position <= ProfileElement.TimelinePosition);
// Keyframes are sorted by position so we can safely assume the next keyframe's position is after the current
var nextIndex = _keyframes.IndexOf(CurrentKeyframe) + 1;
NextKeyframe = _keyframes.Count > nextIndex ? _keyframes[nextIndex] : null;
// No need to update the current value if either of the keyframes are null
if (CurrentKeyframe == null)
CurrentValue = _keyframes.Any() ? _keyframes[0].Value : BaseValue;
else if (NextKeyframe == null)
CurrentValue = CurrentKeyframe.Value;
// Only determine progress and current value if both keyframes are present
else
{
var timeDiff = NextKeyframe.Position - CurrentKeyframe.Position;
var keyframeProgress = (float) ((ProfileElement.TimelinePosition - CurrentKeyframe.Position).TotalMilliseconds / timeDiff.TotalMilliseconds);
var keyframeProgressEased = (float) Easings.Interpolate(keyframeProgress, CurrentKeyframe.EasingFunction);
UpdateCurrentValue(keyframeProgress, keyframeProgressEased);
}
}
private void UpdateDataBindings(double deltaTime)
{
foreach (var dataBinding in DataBindings)
{
dataBinding.Update(deltaTime);
ApplyDataBinding(dataBinding);
}
}
/// <summary>
/// Sorts the keyframes in ascending order by position
/// </summary>
@ -303,20 +270,88 @@ namespace Artemis.Core
Position = k.Position,
EasingFunction = (int) k.EasingFunction
}));
PropertyEntity.DataBindingEntities.Clear();
foreach (var dataBinding in DataBindings)
{
dataBinding.ApplyToEntity();
PropertyEntity.DataBindingEntities.Add(dataBinding.Entity);
}
}
private void UpdateKeyframes()
{
if (!KeyframesSupported || !KeyframesEnabled)
return;
// The current keyframe is the last keyframe before the current time
CurrentKeyframe = _keyframes.LastOrDefault(k => k.Position <= ProfileElement.TimelinePosition);
// Keyframes are sorted by position so we can safely assume the next keyframe's position is after the current
var nextIndex = _keyframes.IndexOf(CurrentKeyframe) + 1;
NextKeyframe = _keyframes.Count > nextIndex ? _keyframes[nextIndex] : null;
// No need to update the current value if either of the keyframes are null
if (CurrentKeyframe == null)
CurrentValue = _keyframes.Any() ? _keyframes[0].Value : BaseValue;
else if (NextKeyframe == null)
CurrentValue = CurrentKeyframe.Value;
// Only determine progress and current value if both keyframes are present
else
{
var timeDiff = NextKeyframe.Position - CurrentKeyframe.Position;
var keyframeProgress = (float) ((ProfileElement.TimelinePosition - CurrentKeyframe.Position).TotalMilliseconds / timeDiff.TotalMilliseconds);
var keyframeProgressEased = (float) Easings.Interpolate(keyframeProgress, CurrentKeyframe.EasingFunction);
UpdateCurrentValue(keyframeProgress, keyframeProgressEased);
}
}
#region Data bindings
/// <inheritdoc />
public override List<PropertyInfo> GetDataBindingProperties()
public void RegisterDataBindingProperty<TProperty>(Expression<Func<T, TProperty>> propertyLambda, IDataBindingConverter converter)
{
return new List<PropertyInfo> {GetType().GetProperty(nameof(CurrentValue))};
var propertyInfo = ReflectionUtilities.GetPropertyInfo(CurrentValue, propertyLambda);
}
/// <inheritdoc />
protected override void ApplyDataBinding(DataBinding dataBinding)
/// <summary>
/// Registers the provided property to be available for data binding using a data binding property of type
/// <typeparamref name="TD" />
/// </summary>
/// <typeparam name="TD">The type of data binding property to use</typeparam>
/// <param name="propertyName">The name of the property</param>
/// <returns></returns>
public TD RegisterDataBindingProperty<TD>(string propertyName, IDataBindingConverter converter) where TD : BaseDataBindingProperty
{
CurrentValue = (T) dataBinding.GetValue(CurrentValue);
var property = typeof(T).GetProperty(propertyName);
if (property == null)
{
throw new ArtemisCoreException($"Cannot register data binding property for property {propertyName} " +
$"because it does not exist on type {typeof(T).Name}");
}
// Create an instance of the converter
var dataBindingOperator = (TD) Activator.CreateInstance(typeof(TD), property);
if (dataBindingOperator == null)
throw new ArtemisCoreException($"Cannot register data binding, failed to create an instance of {typeof(TD).Name}");
if (dataBindingOperator.PropertyType != property.PropertyType)
{
throw new ArtemisCoreException($"Cannot register data binding property for property {propertyName} using a {typeof(TD).Name} " +
$"because it does not support type {typeof(T).Name}");
}
AddDataBindingConverter(dataBindingOperator);
return dataBindingOperator;
}
private void UpdateDataBindings(double deltaTime)
{
foreach (var dataBinding in DataBindings)
{
dataBinding.Update(deltaTime);
dataBinding.ApplyToProperty();
}
}
#endregion

View File

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using SkiaSharp;
namespace Artemis.Core
@ -11,10 +8,15 @@ namespace Artemis.Core
{
internal SKColorLayerProperty()
{
RegisterDataBindingProperty(color => color.Alpha, new SKColorDataBindingConverter(SKColorDataBindingConverter.Channel.Alpha));
RegisterDataBindingProperty(color => color.Red, new SKColorDataBindingConverter(SKColorDataBindingConverter.Channel.Red));
RegisterDataBindingProperty(color => color.Green, new SKColorDataBindingConverter(SKColorDataBindingConverter.Channel.Green));
RegisterDataBindingProperty(color => color.Blue, new SKColorDataBindingConverter(SKColorDataBindingConverter.Channel.Blue));
RegisterDataBindingProperty(color => color.Hue, new SKColorDataBindingConverter(SKColorDataBindingConverter.Channel.Hue));
}
/// <summary>
/// Implicitly converts an <see cref="SKColorLayerProperty" /> to an <see cref="SKColor" />
/// Implicitly converts an <see cref="SKColorLayerProperty" /> to an <see cref="SKColor" />
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
@ -28,29 +30,84 @@ namespace Artemis.Core
{
CurrentValue = CurrentKeyframe.Value.Interpolate(NextKeyframe.Value, keyframeProgressEased);
}
}
/// <inheritdoc />
public override List<PropertyInfo> GetDataBindingProperties()
internal class SKColorDataBindingConverter : IDataBindingConverter
{
private readonly Channel _channel;
public SKColorDataBindingConverter(Channel channel)
{
return typeof(SKColor).GetProperties().ToList();
_channel = channel;
}
/// <inheritdoc />
protected override void ApplyDataBinding(DataBinding dataBinding)
public BaseLayerProperty BaseLayerProperty { get; set; }
public object Sum(object a, object b)
{
if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Alpha))
CurrentValue = CurrentValue.WithAlpha((byte) dataBinding.GetValue(BaseValue.Alpha));
else if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Red))
CurrentValue = CurrentValue.WithRed((byte) dataBinding.GetValue(BaseValue.Red));
else if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Green))
CurrentValue = CurrentValue.WithGreen((byte) dataBinding.GetValue(BaseValue.Green));
else if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Blue))
CurrentValue = CurrentValue.WithBlue((byte) dataBinding.GetValue(BaseValue.Blue));
else if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Hue))
return (float) a + (float) b;
}
public object Interpolate(object a, object b, float progress)
{
var diff = (float) b - (float) a;
return diff * progress;
}
public void ApplyValue(object value)
{
var property = (SKColorLayerProperty) BaseLayerProperty;
switch (_channel)
{
CurrentValue.ToHsv(out var h, out var s, out var v);
CurrentValue = SKColor.FromHsv((float) dataBinding.GetValue(h), s, v);
case Channel.Alpha:
property.CurrentValue = property.CurrentValue.WithAlpha((byte) value);
break;
case Channel.Red:
property.CurrentValue = property.CurrentValue.WithRed((byte) value);
break;
case Channel.Green:
property.CurrentValue = property.CurrentValue.WithGreen((byte) value);
break;
case Channel.Blue:
property.CurrentValue = property.CurrentValue.WithBlue((byte) value);
break;
case Channel.Hue:
property.CurrentValue.ToHsv(out var h, out var s, out var v);
property.CurrentValue = SKColor.FromHsv((float) value, s, v);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
public object GetValue()
{
var property = (SKColorLayerProperty) BaseLayerProperty;
switch (_channel)
{
case Channel.Alpha:
return property.CurrentValue.Alpha;
case Channel.Red:
return property.CurrentValue.Red;
case Channel.Green:
return property.CurrentValue.Green;
case Channel.Blue:
return property.CurrentValue.Blue;
case Channel.Hue:
property.CurrentValue.ToHsv(out var h, out _, out _);
return h;
default:
throw new ArgumentOutOfRangeException();
}
}
public enum Channel
{
Alpha,
Red,
Green,
Blue,
Hue
}
}
}

View File

@ -27,20 +27,5 @@ namespace Artemis.Core
var yDiff = NextKeyframe.Value.Y - CurrentKeyframe.Value.Y;
CurrentValue = new SKPoint(CurrentKeyframe.Value.X + xDiff * keyframeProgressEased, CurrentKeyframe.Value.Y + yDiff * keyframeProgressEased);
}
/// <inheritdoc />
public override List<PropertyInfo> GetDataBindingProperties()
{
return typeof(SKPoint).GetProperties().Where(p => p.CanWrite).ToList();
}
/// <inheritdoc />
protected override void ApplyDataBinding(DataBinding dataBinding)
{
if (dataBinding.TargetProperty.Name == nameof(CurrentValue.X))
CurrentValue = new SKPoint((float) dataBinding.GetValue(BaseValue), CurrentValue.Y);
else if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Y))
CurrentValue = new SKPoint(CurrentValue.X, (float) dataBinding.GetValue(BaseValue));
}
}
}

View File

@ -27,20 +27,5 @@ namespace Artemis.Core
var heightDiff = NextKeyframe.Value.Height - CurrentKeyframe.Value.Height;
CurrentValue = new SKSize(CurrentKeyframe.Value.Width + widthDiff * keyframeProgressEased, CurrentKeyframe.Value.Height + heightDiff * keyframeProgressEased);
}
/// <inheritdoc />
public override List<PropertyInfo> GetDataBindingProperties()
{
return typeof(SKSize).GetProperties().Where(p => p.CanWrite).ToList();
}
/// <inheritdoc />
protected override void ApplyDataBinding(DataBinding dataBinding)
{
if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Height))
CurrentValue = new SKSize(CurrentValue.Width, (float) dataBinding.GetValue(BaseValue));
else if (dataBinding.TargetProperty.Name == nameof(CurrentValue.Width))
CurrentValue = new SKSize((float) dataBinding.GetValue(BaseValue), CurrentValue.Width);
}
}
}

View File

@ -311,5 +311,17 @@ namespace Artemis.Core
}
#endregion
/// <summary>
/// Returns all the layer properties of this profile element
/// </summary>
public virtual List<BaseLayerProperty> GetAllLayerProperties()
{
var result = new List<BaseLayerProperty>();
foreach (var baseLayerEffect in LayerEffects)
result.AddRange(baseLayerEffect.BaseProperties.GetAllLayerProperties());
return result;
}
}
}

View File

@ -15,6 +15,8 @@ namespace Artemis.Core.Services
{
_logger = logger;
_registeredDataBindingModifierTypes = new List<DataBindingModifierType>();
RegisterBuiltInModifiers();
}
public IReadOnlyCollection<DataBindingModifierType> RegisteredDataBindingModifierTypes
@ -98,5 +100,10 @@ namespace Artemis.Core.Services
dataBindingModifier.Entity.ModifierType
);
}
private void RegisterBuiltInModifiers()
{
RegisterModifierType(Constants.CorePluginInfo, new MultiplicationModifierType());
}
}
}

View File

@ -54,5 +54,6 @@ namespace Artemis.Core.Services
void RemoveLayerEffect(BaseLayerEffect layerEffect);
void InstantiateDisplayConditions(RenderProfileElement renderElement);
void InstantiateDataBindings(RenderProfileElement renderElement);
}
}

View File

@ -10,16 +10,18 @@ namespace Artemis.Core.Services
internal class RenderElementService : IRenderElementService
{
private readonly IDataModelService _dataModelService;
private readonly IDataBindingService _dataBindingService;
private readonly IKernel _kernel;
private readonly ILogger _logger;
private readonly IPluginService _pluginService;
public RenderElementService(IKernel kernel, ILogger logger, IPluginService pluginService, IDataModelService dataModelService)
public RenderElementService(IKernel kernel, ILogger logger, IPluginService pluginService, IDataModelService dataModelService, IDataBindingService dataBindingService)
{
_kernel = kernel;
_logger = logger;
_pluginService = pluginService;
_dataModelService = dataModelService;
_dataBindingService = dataBindingService;
}
public Layer CreateLayer(Profile profile, ProfileElement parent, string name)
@ -35,6 +37,7 @@ namespace Artemis.Core.Services
InstantiateLayerBrush(layer);
InstantiateLayerEffects(layer);
InstantiateDisplayConditions(layer);
InstantiateDataBindings(layer);
return layer;
}
@ -156,5 +159,11 @@ namespace Artemis.Core.Services
_logger.Warning(e, $"Failed to init display conditions for {renderElement}");
}
}
public void InstantiateDataBindings(RenderProfileElement renderElement)
{
foreach (var baseLayerProperty in renderElement.GetAllLayerProperties())
baseLayerProperty.InitializeDataBindings(_dataModelService, _dataBindingService);
}
}
}

View File

@ -299,6 +299,7 @@ namespace Artemis.Core.Services
_renderElementService.RemoveLayerEffect(layerLayerEffect);
_renderElementService.InstantiateDisplayConditions(folder);
_renderElementService.InstantiateDataBindings(folder);
}
}
@ -324,6 +325,7 @@ namespace Artemis.Core.Services
_renderElementService.RemoveLayerEffect(layerLayerEffect);
_renderElementService.InstantiateDisplayConditions(layer);
_renderElementService.InstantiateDataBindings(layer);
}
}

View File

@ -14,9 +14,9 @@ namespace Artemis.UI.Shared
private bool _closed;
private T _inputValue;
protected DataModelInputViewModel(DataModelPropertyAttribute description, T initialValue)
protected DataModelInputViewModel(DataModelPropertyAttribute targetDescription, T initialValue)
{
Description = description;
TargetDescription = targetDescription;
InputValue = initialValue;
}
@ -26,7 +26,7 @@ namespace Artemis.UI.Shared
set => SetAndNotify(ref _inputValue, value);
}
public DataModelPropertyAttribute Description { get; }
public DataModelPropertyAttribute TargetDescription { get; }
internal override object InternalGuard { get; } = null;
/// <inheritdoc />

View File

@ -1,60 +0,0 @@
<UserControl x:Class="Artemis.UI.Shared.DataModelSelectionView"
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:shared="clr-namespace:Artemis.UI.Shared"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance shared:DataModelSelectionViewModel}">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Artemis.UI.Shared;component/ResourceDictionaries/DisplayConditions.xaml" />
<ResourceDictionary>
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
<shared:BindingProxy x:Key="DataContextProxy" Data="{Binding}" />
<DataTemplate x:Key="DataModelDataTemplate">
<Control x:Name="TemplateControl" Focusable="False" Template="{StaticResource DataModelSelectionTemplate}" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Data.ShowDataModelValues.Value, Source={StaticResource DataContextProxy}}" Value="True">
<Setter TargetName="TemplateControl" Property="Template" Value="{StaticResource DataModelSelectionTemplateWithValues}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Button Background="{Binding ButtonBrush}"
BorderBrush="{Binding ButtonBrush}"
Style="{StaticResource DisplayConditionButton}"
ToolTip="{Binding SelectedPropertyViewModel.DisplayPropertyPath}"
IsEnabled="{Binding IsEnabled}"
HorizontalAlignment="Left"
Click="PropertyButton_OnClick">
<Button.ContextMenu>
<ContextMenu ItemsSource="{Binding DataModelViewModel.Children}" IsOpen="{Binding IsDataModelViewModelOpen, Mode=OneWayToSource}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
<Setter Property="ItemsSource" Value="{Binding Children}" />
<Setter Property="Command" Value="{Binding Data.SelectPropertyCommand, Source={StaticResource DataContextProxy}}" />
<Setter Property="CommandParameter" Value="{Binding}" />
<Setter Property="CommandTarget" Value="{Binding}" />
<Setter Property="IsEnabled" Value="{Binding IsMatchingFilteredTypes}" />
<Setter Property="IsSubmenuOpen" Value="{Binding IsVisualizationExpanded, Mode=TwoWay}" />
<Setter Property="HeaderTemplate" Value="{StaticResource DataModelDataTemplate}" />
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
</Button.ContextMenu>
<Grid>
<TextBlock Text="{Binding SelectedPropertyViewModel.PropertyDescription.Name}"
Visibility="{Binding SelectedPropertyViewModel, Converter={StaticResource NullToVisibilityConverter}}" />
<TextBlock FontStyle="Italic"
Visibility="{Binding SelectedPropertyViewModel, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
<Run Text="« "/><Run Text="{Binding Placeholder}"/><Run Text=" »"/>
</TextBlock>
</Grid>
</Button>
</UserControl>

View File

@ -0,0 +1,69 @@
<UserControl x:Class="Artemis.UI.Shared.Input.DataModelDynamicView"
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:shared="clr-namespace:Artemis.UI.Shared"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:input="clr-namespace:Artemis.UI.Shared.Input"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance input:DataModelDynamicViewModel}">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Artemis.UI.Shared;component/ResourceDictionaries/DisplayConditions.xaml" />
<ResourceDictionary>
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
<shared:BindingProxy x:Key="DataContextProxy" Data="{Binding}" />
<DataTemplate x:Key="DataModelDataTemplate">
<Control x:Name="TemplateControl" Focusable="False" Template="{StaticResource DataModelSelectionTemplate}" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Data.ShowDataModelValues.Value, Source={StaticResource DataContextProxy}}" Value="True">
<Setter TargetName="TemplateControl" Property="Template" Value="{StaticResource DataModelSelectionTemplateWithValues}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Button Background="{Binding ButtonBrush}"
BorderBrush="{Binding ButtonBrush}"
Style="{StaticResource DisplayConditionButton}"
ToolTip="{Binding SelectedPropertyViewModel.DisplayPropertyPath}"
IsEnabled="{Binding IsEnabled}"
HorizontalAlignment="Left"
Click="PropertyButton_OnClick"
Visibility="{Binding ShowFreeInput, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
<Button.ContextMenu>
<ContextMenu ItemsSource="{Binding DataModelViewModel.Children}" IsOpen="{Binding IsDataModelViewModelOpen, Mode=OneWayToSource}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
<Setter Property="ItemsSource" Value="{Binding Children}" />
<Setter Property="Command" Value="{Binding Data.SelectPropertyCommand, Source={StaticResource DataContextProxy}}" />
<Setter Property="CommandParameter" Value="{Binding}" />
<Setter Property="CommandTarget" Value="{Binding}" />
<Setter Property="IsEnabled" Value="{Binding IsMatchingFilteredTypes}" />
<Setter Property="IsSubmenuOpen" Value="{Binding IsVisualizationExpanded, Mode=TwoWay}" />
<Setter Property="HeaderTemplate" Value="{StaticResource DataModelDataTemplate}" />
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
</Button.ContextMenu>
<Grid>
<TextBlock Text="{Binding SelectedPropertyViewModel.PropertyDescription.Name}"
Visibility="{Binding SelectedPropertyViewModel, Converter={StaticResource NullToVisibilityConverter}}" />
<TextBlock FontStyle="Italic"
Visibility="{Binding SelectedPropertyViewModel, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
<Run Text="« " /><Run Text="{Binding Placeholder}" /><Run Text=" »" />
</TextBlock>
</Grid>
</Button>
</UserControl>

View File

@ -1,14 +1,14 @@
using System.Windows;
using System.Windows.Controls;
namespace Artemis.UI.Shared
namespace Artemis.UI.Shared.Input
{
/// <summary>
/// Interaction logic for DataModelSelectionView.xaml
/// Interaction logic for DataModelDynamicView.xaml
/// </summary>
public partial class DataModelSelectionView : UserControl
public partial class DataModelDynamicView : UserControl
{
public DataModelSelectionView()
public DataModelDynamicView()
{
InitializeComponent();
}

View File

@ -11,22 +11,21 @@ using Stylet;
// Remove, annoying while working on it
#pragma warning disable 1591
namespace Artemis.UI.Shared
namespace Artemis.UI.Shared.Input
{
public class DataModelSelectionViewModel : PropertyChangedBase
public class DataModelDynamicViewModel : PropertyChangedBase
{
private readonly IDataModelUIService _dataModelUIService;
private readonly Module _module;
private readonly Timer _updateTimer;
private Brush _buttonBrush = new SolidColorBrush(Color.FromRgb(171, 71, 188));
private DataModelPropertiesViewModel _dataModelViewModel;
private bool _isDataModelViewModelOpen;
private bool _isEnabled;
private bool _isEnabled = true;
private string _placeholder = "Select a property";
private DataModelVisualizationViewModel _selectedPropertyViewModel;
public DataModelSelectionViewModel(Module module, ISettingsService settingsService, IDataModelUIService dataModelUIService)
internal DataModelDynamicViewModel(Module module, ISettingsService settingsService, IDataModelUIService dataModelUIService)
{
_module = module;
_dataModelUIService = dataModelUIService;
@ -38,22 +37,18 @@ namespace Artemis.UI.Shared
Initialize();
}
public string Placeholder
{
get => _placeholder;
set => SetAndNotify(ref _placeholder, value);
}
public Brush ButtonBrush
{
get => _buttonBrush;
set => SetAndNotify(ref _buttonBrush, value);
}
public DelegateCommand SelectPropertyCommand { get; }
public Type[] FilterTypes { get; set; }
public PluginSetting<bool> ShowDataModelValues { get; }
public string Placeholder
{
get => _placeholder;
set => SetAndNotify(ref _placeholder, value);
}
public bool IsEnabled
{
@ -61,6 +56,10 @@ namespace Artemis.UI.Shared
set => SetAndNotify(ref _isEnabled, value);
}
public Type[] FilterTypes { get; set; }
public DelegateCommand SelectPropertyCommand { get; }
public PluginSetting<bool> ShowDataModelValues { get; }
public DataModelPropertiesViewModel DataModelViewModel
{
get => _dataModelViewModel;
@ -117,14 +116,15 @@ namespace Artemis.UI.Shared
return;
SelectedPropertyViewModel = selected;
OnPropertySelected(new DataModelPropertySelectedEventArgs(selected));
OnPropertySelected(new DataModelInputDynamicEventArgs(selected));
}
#region Events
public event EventHandler<DataModelPropertySelectedEventArgs> PropertySelected;
public event EventHandler<DataModelInputDynamicEventArgs> PropertySelected;
protected virtual void OnPropertySelected(DataModelPropertySelectedEventArgs e)
protected virtual void OnPropertySelected(DataModelInputDynamicEventArgs e)
{
PropertySelected?.Invoke(this, e);
}

View File

@ -0,0 +1,56 @@
<UserControl x:Class="Artemis.UI.Shared.Input.DataModelStaticView"
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:input="clr-namespace:Artemis.UI.Shared.Input"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:shared="clr-namespace:Artemis.UI.Shared"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance input:DataModelStaticViewModel}">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Artemis.UI.Shared;component/ResourceDictionaries/DisplayConditions.xaml" />
<ResourceDictionary>
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<materialDesign:Transitioner SelectedIndex="{Binding TransitionIndex}" DefaultTransitionOrigin="0.5, 0.5" Margin="3 -4">
<Button Style="{StaticResource DisplayConditionButton}"
Background="{Binding ButtonBrush}"
BorderBrush="{Binding ButtonBrush}"
Margin="0 4"
Command="{s:Action ActivateInputViewModel}"
HorizontalAlignment="Left">
<Grid>
<StackPanel Visibility="{Binding Value, Converter={StaticResource NullToVisibilityConverter}}" Orientation="Horizontal">
<TextBlock FontWeight="Light"
Text="{Binding TargetPropertyViewModel.PropertyDescription.Prefix}"
Visibility="{Binding TargetPropertyViewModel.PropertyDescription.Prefix, Converter={StaticResource NullToVisibilityConverter}}" />
<TextBlock Text="{Binding Value}" />
<TextBlock FontWeight="Light"
Text="{Binding TargetPropertyViewModel.PropertyDescription.Affix}"
Visibility="{Binding TargetPropertyViewModel.PropertyDescription.Affix, Converter={StaticResource NullToVisibilityConverter}}" />
</StackPanel>
<TextBlock FontStyle="Italic" Visibility="{Binding Value, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
<Run Text="« " /><Run Text="{Binding Placeholder}" /><Run Text=" »" />
</TextBlock>
</Grid>
</Button>
<Border BorderBrush="{Binding ButtonBrush}"
Background="{DynamicResource MaterialDesignPaper}"
CornerRadius="3"
Padding="3"
HorizontalAlignment="Left"
MinWidth="140">
<ContentControl s:View.Model="{Binding InputViewModel}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
</Border>
</materialDesign:Transitioner>
</UserControl>

View File

@ -0,0 +1,15 @@
using System.Windows.Controls;
namespace Artemis.UI.Shared.Input
{
/// <summary>
/// Interaction logic for DataModelStaticView.xaml
/// </summary>
public partial class DataModelStaticView : UserControl
{
public DataModelStaticView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,116 @@
using System;
using System.Windows.Media;
using Artemis.Core;
using Artemis.Core.DataModelExpansions;
using Artemis.UI.Shared.Services;
using Stylet;
// Remove, annoying while working on it
#pragma warning disable 1591
namespace Artemis.UI.Shared.Input
{
public class DataModelStaticViewModel : PropertyChangedBase
{
private readonly IDataModelUIService _dataModelUIService;
private Brush _buttonBrush = new SolidColorBrush(Color.FromRgb(171, 71, 188));
private DataModelInputViewModel _inputViewModel;
private string _placeholder = "Enter a value";
private DataModelPropertyAttribute _targetDescription;
private Type _targetType;
private int _transitionIndex;
private object _value;
internal DataModelStaticViewModel(Type targetType, IDataModelUIService dataModelUIService)
{
TargetType = targetType;
_dataModelUIService = dataModelUIService;
}
public Brush ButtonBrush
{
get => _buttonBrush;
set => SetAndNotify(ref _buttonBrush, value);
}
public int TransitionIndex
{
get => _transitionIndex;
set => SetAndNotify(ref _transitionIndex, value);
}
public DataModelInputViewModel InputViewModel
{
get => _inputViewModel;
private set => SetAndNotify(ref _inputViewModel, value);
}
public Type TargetType
{
get => _targetType;
set => SetAndNotify(ref _targetType, value);
}
public DataModelPropertyAttribute TargetDescription
{
get => _targetDescription;
set => SetAndNotify(ref _targetDescription, value);
}
public object Value
{
get => _value;
set => SetAndNotify(ref _value, value);
}
public string Placeholder
{
get => _placeholder;
set => SetAndNotify(ref _placeholder, value);
}
public void ActivateInputViewModel()
{
TransitionIndex = 1;
InputViewModel = _dataModelUIService.GetDataModelInputViewModel(
TargetType,
TargetDescription,
Value,
ApplyFreeInput
);
}
public void UpdateTargetType(Type target)
{
TargetType = target ?? throw new ArgumentNullException(nameof(target));
// If the type changed, reset to the default type
if (!target.IsCastableFrom(Value.GetType()))
{
// Force the VM to close if it was open and apply the new value
ApplyFreeInput(target.GetDefault(), true);
}
}
private void ApplyFreeInput(object value, bool submitted)
{
if (submitted)
OnValueUpdated(new DataModelInputStaticEventArgs(value));
TransitionIndex = 0;
InputViewModel = null;
Value = value;
}
#region Events
public event EventHandler<DataModelInputStaticEventArgs> ValueUpdated;
protected virtual void OnValueUpdated(DataModelInputStaticEventArgs e)
{
ValueUpdated?.Invoke(this, e);
}
#endregion
}
}

View File

@ -2,11 +2,11 @@
namespace Artemis.UI.Shared
{
public class DataModelPropertySelectedEventArgs : EventArgs
public class DataModelInputDynamicEventArgs : EventArgs
{
public DataModelVisualizationViewModel DataModelVisualizationViewModel { get; }
public DataModelPropertySelectedEventArgs(DataModelVisualizationViewModel dataModelVisualizationViewModel)
public DataModelInputDynamicEventArgs(DataModelVisualizationViewModel dataModelVisualizationViewModel)
{
DataModelVisualizationViewModel = dataModelVisualizationViewModel;
}

View File

@ -0,0 +1,14 @@
using System;
namespace Artemis.UI.Shared
{
public class DataModelInputStaticEventArgs : EventArgs
{
public object Value { get; }
public DataModelInputStaticEventArgs(object value)
{
Value = value;
}
}
}

View File

@ -5,6 +5,7 @@ using Artemis.Core;
using Artemis.Core.DataModelExpansions;
using Artemis.Core.Modules;
using Artemis.Core.Services;
using Artemis.UI.Shared.Input;
using Ninject;
using Ninject.Parameters;
@ -179,9 +180,15 @@ namespace Artemis.UI.Shared.Services
}
}
public DataModelSelectionViewModel GetDataModelSelectionViewModel(Module module)
public DataModelDynamicViewModel GetDynamicSelectionViewModel(Module module)
{
return _kernel.Get<DataModelSelectionViewModel>(new ConstructorArgument("module", module));
return _kernel.Get<DataModelDynamicViewModel>(new ConstructorArgument("module", module));
}
public DataModelStaticViewModel GetStaticInputViewModel(Type targetType)
{
if (targetType == null) throw new ArgumentNullException(nameof(targetType));
return _kernel.Get<DataModelStaticViewModel>(new ConstructorArgument("targetType", targetType));
}
private DataModelInputViewModel InstantiateDataModelInputViewModel(DataModelVisualizationRegistration registration, DataModelPropertyAttribute description, object initialValue)

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using Artemis.Core;
using Artemis.Core.DataModelExpansions;
using Artemis.Core.Modules;
using Artemis.UI.Shared.Input;
namespace Artemis.UI.Shared.Services
{
@ -28,6 +29,7 @@ namespace Artemis.UI.Shared.Services
DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType);
DataModelInputViewModel GetDataModelInputViewModel(Type propertyType, DataModelPropertyAttribute description, object initialValue, Action<object, bool> updateCallback);
DataModelSelectionViewModel GetDataModelSelectionViewModel(Module module);
DataModelDynamicViewModel GetDynamicSelectionViewModel(Module module);
DataModelStaticViewModel GetStaticInputViewModel(Type targetType);
}
}

View File

@ -8,7 +8,7 @@ namespace Artemis.UI.DataModelVisualization.Input
{
public class DoubleDataModelInputViewModel : DataModelInputViewModel<double>
{
public DoubleDataModelInputViewModel(DataModelPropertyAttribute description, double initialValue) : base(description, initialValue)
public DoubleDataModelInputViewModel(DataModelPropertyAttribute targetDescription, double initialValue) : base(targetDescription, initialValue)
{
}

View File

@ -7,7 +7,7 @@ namespace Artemis.UI.DataModelVisualization.Input
{
public class IntDataModelInputViewModel : DataModelInputViewModel<int>
{
public IntDataModelInputViewModel(DataModelPropertyAttribute description, int initialValue) : base(description, initialValue)
public IntDataModelInputViewModel(DataModelPropertyAttribute targetDescription, int initialValue) : base(targetDescription, initialValue)
{
}

View File

@ -5,7 +5,7 @@ namespace Artemis.UI.DataModelVisualization.Input
{
public class StringDataModelInputViewModel : DataModelInputViewModel<string>
{
public StringDataModelInputViewModel(DataModelPropertyAttribute description, string initialValue) : base(description, initialValue)
public StringDataModelInputViewModel(DataModelPropertyAttribute targetDescription, string initialValue) : base(targetDescription, initialValue)
{
}

View File

@ -62,8 +62,8 @@
Style="{StaticResource DisplayConditionButtonLeftClickMenu}"
Background="#7B7B7B"
BorderBrush="#7B7B7B"
Content="{Binding SelectedModifierType.Description}">
<!-- Click="PropertyButton_OnClick" -->
Content="{Binding SelectedModifierType.Description}"
Click="PropertyButton_OnClick">
<Button.ContextMenu>
<ContextMenu ItemsSource="{Binding ModifierTypes}">
<ContextMenu.ItemTemplate>
@ -85,34 +85,7 @@
</Button.ContextMenu>
</Button>
<Button Grid.Column="3"
Background="#ab47bc"
BorderBrush="#ab47bc"
Style="{StaticResource DisplayConditionButton}"
ToolTip="{Binding SelectedParameterProperty.DisplayPropertyPath}"
HorizontalAlignment="Left">
<Button.ContextMenu>
<ContextMenu ItemsSource="{Binding ParameterDataModel.Children}" IsOpen="{Binding ParameterDataModelOpen, Mode=OneWayToSource}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
<Setter Property="ItemsSource" Value="{Binding Children}" />
<Setter Property="Command" Value="{Binding Data.SelectModifierTypeCommand, Source={StaticResource DataContextProxy}}" />
<Setter Property="CommandParameter" Value="{Binding}" />
<Setter Property="CommandTarget" Value="{Binding}" />
<Setter Property="IsEnabled" Value="{Binding IsMatchingFilteredTypes}" />
<Setter Property="IsSubmenuOpen" Value="{Binding IsVisualizationExpanded, Mode=TwoWay}" />
<Setter Property="HeaderTemplate" Value="{StaticResource DataModelDataTemplate}" />
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
</Button.ContextMenu>
<Grid>
<TextBlock Text="{Binding SelectedParameterProperty.PropertyDescription.Name}"
Visibility="{Binding SelectedParameterProperty, Converter={StaticResource NullToVisibilityConverter}}" />
<TextBlock Text="« Select a property »"
FontStyle="Italic"
Visibility="{Binding SelectedParameterProperty, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}" />
</Grid>
</Button>
<ContentControl Grid.Column="3" s:View.Model="{Binding DynamicSelectionViewModel}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
<ContentControl Grid.Column="3" s:View.Model="{Binding StaticInputViewModel}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
</Grid>
</UserControl>

View File

@ -22,5 +22,15 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{
InitializeComponent();
}
private void PropertyButton_OnClick(object sender, RoutedEventArgs e)
{
// DataContext is not set when using left button, I don't know why but there it is
if (sender is Button button && button.ContextMenu != null)
{
button.ContextMenu.DataContext = button.DataContext;
button.ContextMenu.IsOpen = true;
}
}
}
}

View File

@ -1,7 +1,10 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Exceptions;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Input;
using Artemis.UI.Shared.Services;
using Stylet;
@ -13,6 +16,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
private readonly IDataModelUIService _dataModelUIService;
private readonly IProfileEditorService _profileEditorService;
private DataBindingModifierType _selectedModifierType;
private DataModelDynamicViewModel _dynamicSelectionViewModel;
private DataModelStaticViewModel _staticInputViewModel;
public DataBindingModifierViewModel(DataBindingModifier modifier,
IDataBindingService dataBindingService,
@ -32,11 +37,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
SelectModifierTypeCommand = new DelegateCommand(ExecuteSelectModifierTypeCommand);
// Initialize async, no need to wait for it
Task.Run(Initialize);
Execute.PostToUIThread(Initialize);
}
public DelegateCommand SelectModifierTypeCommand { get; set; }
public DelegateCommand SelectModifierTypeCommand { get; }
public PluginSetting<bool> ShowDataModelValues { get; }
public DataBindingModifier Modifier { get; }
public BindableCollection<DataBindingModifierType> ModifierTypes { get; }
@ -47,30 +51,65 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
set => SetAndNotify(ref _selectedModifierType, value);
}
public DataModelSelectionViewModel ParameterSelectionViewModel { get; private set; }
public DataModelDynamicViewModel DynamicSelectionViewModel
{
get => _dynamicSelectionViewModel;
private set => SetAndNotify(ref _dynamicSelectionViewModel, value);
}
public DataModelStaticViewModel StaticInputViewModel
{
get => _staticInputViewModel;
private set => SetAndNotify(ref _staticInputViewModel, value);
}
private void Initialize()
{
ParameterSelectionViewModel = _dataModelUIService.GetDataModelSelectionViewModel(_profileEditorService.GetCurrentModule());
ParameterSelectionViewModel.PropertySelected += ParameterSelectionViewModelOnPropertySelected;
ParameterSelectionViewModel.FilterTypes = new[] {Modifier.DataBinding.TargetProperty.PropertyType};
var sourceType = Modifier.DataBinding.GetSourceType();
if (sourceType == null)
throw new ArtemisUIException("Cannot initialize a data binding modifier VM for a data binding without a source");
if (Modifier.ParameterType == ProfileRightSideType.Dynamic)
{
StaticInputViewModel = null;
DynamicSelectionViewModel = _dataModelUIService.GetDynamicSelectionViewModel(_profileEditorService.GetCurrentModule());
DynamicSelectionViewModel.PropertySelected += ParameterSelectionViewModelOnPropertySelected;
DynamicSelectionViewModel.FilterTypes = new[] {sourceType};
}
else
{
DynamicSelectionViewModel = null;
StaticInputViewModel = _dataModelUIService.GetStaticInputViewModel(sourceType);
StaticInputViewModel.ValueUpdated += StaticInputViewModelOnValueUpdated;
}
Update();
}
private void ParameterSelectionViewModelOnPropertySelected(object sender, DataModelPropertySelectedEventArgs e)
private void ParameterSelectionViewModelOnPropertySelected(object sender, DataModelInputDynamicEventArgs e)
{
Modifier.UpdateParameter(e.DataModelVisualizationViewModel.DataModel, e.DataModelVisualizationViewModel.PropertyPath);
}
private void StaticInputViewModelOnValueUpdated(object sender, DataModelInputStaticEventArgs e)
{
Modifier.UpdateParameter(e.Value);
}
private void Update()
{
var sourceType = Modifier.DataBinding.GetSourceType();
// Modifier type
ModifierTypes.Clear();
ModifierTypes.AddRange(_dataBindingService.GetCompatibleModifierTypes(Modifier.DataBinding.TargetProperty.PropertyType));
ModifierTypes.AddRange(_dataBindingService.GetCompatibleModifierTypes(sourceType));
SelectedModifierType = Modifier.ModifierType;
ParameterSelectionViewModel.PopulateSelectedPropertyViewModel(Modifier.ParameterDataModel, Modifier.ParameterPropertyPath);
// Parameter
if (DynamicSelectionViewModel != null)
DynamicSelectionViewModel?.PopulateSelectedPropertyViewModel(Modifier.ParameterDataModel, Modifier.ParameterPropertyPath);
else if (StaticInputViewModel != null)
StaticInputViewModel.Value = Modifier.ParameterStaticValue;
}
private void ExecuteSelectModifierTypeCommand(object context)
@ -83,5 +122,20 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
Update();
}
public void Delete()
{
Modifier.DataBinding.RemoveModifier(Modifier);
}
public void SwapType()
{
if (Modifier.ParameterType == ProfileRightSideType.Dynamic)
Modifier.UpdateParameter(Modifier.DataBinding.GetSourceType().GetDefault());
else
Modifier.UpdateParameter(null, null);
Initialize();
}
}
}

View File

@ -12,15 +12,5 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{
InitializeComponent();
}
private void PropertyButton_OnClick(object sender, RoutedEventArgs e)
{
// DataContext is not set when using left button, I don't know why but there it is
if (sender is Button button && button.ContextMenu != null)
{
button.ContextMenu.DataContext = button.DataContext;
button.ContextMenu.IsOpen = true;
}
}
}
}

View File

@ -1,33 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Timers;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Input;
using Artemis.UI.Shared.Services;
using Artemis.UI.Utilities;
using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{
public class DataBindingViewModel : PropertyChangedBase
{
private readonly IDataModelUIService _dataModelUIService;
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
private readonly IDataModelUIService _dataModelUIService;
private readonly IProfileEditorService _profileEditorService;
private readonly Timer _updateTimer;
private DataBinding _dataBinding;
private bool _isDataBindingEnabled;
private DataModelPropertiesViewModel _sourceDataModel;
private DataModelVisualizationViewModel _selectedSourceProperty;
private bool _sourceDataModelOpen;
private DataModelDynamicViewModel _targetSelectionViewModel;
private object _testInputValue;
private object _testResultValue;
private DataModelSelectionViewModel _targetSelectionViewModel;
public DataBindingViewModel(BaseLayerProperty layerProperty,
PropertyInfo targetProperty,
@ -41,12 +35,14 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
_updateTimer = new Timer(500);
DisplayName = targetProperty.Name.ToUpper();
ModifierViewModels = new BindableCollection<DataBindingModifierViewModel>();
LayerProperty = layerProperty;
TargetProperty = targetProperty;
DataBinding = layerProperty.DataBindings.FirstOrDefault(d => d.TargetProperty == targetProperty);
ModifierViewModels = new BindableCollection<DataBindingModifierViewModel>();
if (DataBinding != null)
DataBinding.ModifiersUpdated += DataBindingOnModifiersUpdated;
_isDataBindingEnabled = DataBinding != null;
@ -59,7 +55,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
public string DisplayName { get; }
public BindableCollection<DataBindingModifierViewModel> ModifierViewModels { get; }
public DataModelSelectionViewModel TargetSelectionViewModel
public DataModelDynamicViewModel TargetSelectionViewModel
{
get => _targetSelectionViewModel;
private set => SetAndNotify(ref _targetSelectionViewModel, value);
@ -106,9 +102,13 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
return;
DataBinding = LayerProperty.AddDataBinding(TargetProperty);
DataBinding.ModifiersUpdated += DataBindingOnModifiersUpdated;
Update();
_profileEditorService.UpdateSelectedProfileElement();
}
public void RemoveDataBinding()
{
if (DataBinding == null)
@ -117,7 +117,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
var toRemove = DataBinding;
DataBinding = null;
LayerProperty.RemoveDataBinding(toRemove);
toRemove.ModifiersUpdated -= DataBindingOnModifiersUpdated;
Update();
_profileEditorService.UpdateSelectedProfileElement();
}
public void AddModifier()
@ -128,12 +131,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
var modifier = new DataBindingModifier(ProfileRightSideType.Dynamic);
DataBinding.AddModifier(modifier);
ModifierViewModels.Add(_dataBindingsVmFactory.DataBindingModifierViewModel(modifier));
_profileEditorService.UpdateSelectedProfileElement();
}
private void Initialize()
{
TargetSelectionViewModel = _dataModelUIService.GetDataModelSelectionViewModel(_profileEditorService.GetCurrentModule());
TargetSelectionViewModel = _dataModelUIService.GetDynamicSelectionViewModel(_profileEditorService.GetCurrentModule());
TargetSelectionViewModel.PropertySelected += TargetSelectionViewModelOnPropertySelected;
Update();
@ -153,11 +156,19 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
TargetSelectionViewModel.IsEnabled = true;
TargetSelectionViewModel.PopulateSelectedPropertyViewModel(DataBinding.SourceDataModel, DataBinding.SourcePropertyPath);
TargetSelectionViewModel.FilterTypes = new[] {DataBinding.TargetProperty.PropertyType};
UpdateModifierViewModels();
}
private void TargetSelectionViewModelOnPropertySelected(object sender, DataModelPropertySelectedEventArgs e)
private void DataBindingOnModifiersUpdated(object sender, EventArgs e)
{
UpdateModifierViewModels();
}
private void TargetSelectionViewModelOnPropertySelected(object sender, DataModelInputDynamicEventArgs e)
{
DataBinding.UpdateSource(e.DataModelVisualizationViewModel.DataModel, e.DataModelVisualizationViewModel.PropertyPath);
_profileEditorService.UpdateSelectedProfileElement();
}
private void OnUpdateTimerOnElapsed(object sender, ElapsedEventArgs e)
@ -184,6 +195,5 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
foreach (var dataBindingModifier in DataBinding.Modifiers)
ModifierViewModels.Add(_dataBindingsVmFactory.DataBindingModifierViewModel(dataBindingModifier));
}
}
}