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

Core - Renamed LayerService to RenderElementService

Display conditions - Implemented persistent storage
This commit is contained in:
SpoinkyNL 2020-07-10 23:00:35 +02:00
parent 16c2b7f7fd
commit 0e873a48cf
32 changed files with 209 additions and 111 deletions

View File

@ -1,13 +1,11 @@
using System; using System.Collections.Generic;
using System.Collections.Generic; using Artemis.Core.Services.Interfaces;
using System.Linq; using Artemis.Storage.Entities.Profile.Abstract;
namespace Artemis.Core.Models.Profile.Conditions.Abstract namespace Artemis.Core.Models.Profile.Conditions.Abstract
{ {
public abstract class DisplayConditionPart public abstract class DisplayConditionPart
{ {
public Guid EntityId { get; internal set; }
private readonly List<DisplayConditionPart> _children; private readonly List<DisplayConditionPart> _children;
protected DisplayConditionPart() protected DisplayConditionPart()
@ -36,6 +34,9 @@ namespace Artemis.Core.Models.Profile.Conditions.Abstract
} }
} }
public abstract void ApplyToEntity(); public abstract DisplayConditionPartEntity GetEntity();
internal abstract void ApplyToEntity();
internal abstract void Initialize(IDataModelService dataModelService);
} }
} }

View File

@ -1,6 +1,9 @@
using System; using System;
using System.Linq;
using Artemis.Core.Models.Profile.Conditions.Abstract; using Artemis.Core.Models.Profile.Conditions.Abstract;
using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Entities.Profile; using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Entities.Profile.Abstract;
namespace Artemis.Core.Models.Profile.Conditions namespace Artemis.Core.Models.Profile.Conditions
{ {
@ -9,7 +12,6 @@ namespace Artemis.Core.Models.Profile.Conditions
public DisplayConditionGroup(DisplayConditionPart parent) public DisplayConditionGroup(DisplayConditionPart parent)
{ {
Parent = parent; Parent = parent;
EntityId = Guid.NewGuid();
DisplayConditionGroupEntity = new DisplayConditionGroupEntity(); DisplayConditionGroupEntity = new DisplayConditionGroupEntity();
} }
@ -17,7 +19,6 @@ namespace Artemis.Core.Models.Profile.Conditions
{ {
Parent = parent; Parent = parent;
DisplayConditionGroupEntity = entity; DisplayConditionGroupEntity = entity;
EntityId = DisplayConditionGroupEntity.Id;
BooleanOperator = (BooleanOperator) DisplayConditionGroupEntity.BooleanOperator; BooleanOperator = (BooleanOperator) DisplayConditionGroupEntity.BooleanOperator;
foreach (var childEntity in DisplayConditionGroupEntity.Children) foreach (var childEntity in DisplayConditionGroupEntity.Children)
@ -32,15 +33,26 @@ namespace Artemis.Core.Models.Profile.Conditions
public BooleanOperator BooleanOperator { get; set; } public BooleanOperator BooleanOperator { get; set; }
public DisplayConditionGroupEntity DisplayConditionGroupEntity { get; set; } public DisplayConditionGroupEntity DisplayConditionGroupEntity { get; set; }
public override void ApplyToEntity() internal override void ApplyToEntity()
{ {
DisplayConditionGroupEntity.Id = EntityId;
DisplayConditionGroupEntity.ParentId = Parent?.EntityId ?? Guid.Empty;
DisplayConditionGroupEntity.BooleanOperator = (int) BooleanOperator; DisplayConditionGroupEntity.BooleanOperator = (int) BooleanOperator;
DisplayConditionGroupEntity.Children.Clear();
DisplayConditionGroupEntity.Children.AddRange(Children.Select(c => c.GetEntity()));
foreach (var child in Children) foreach (var child in Children)
child.ApplyToEntity(); child.ApplyToEntity();
} }
internal override void Initialize(IDataModelService dataModelService)
{
foreach (var child in Children)
child.Initialize(dataModelService);
}
public override DisplayConditionPartEntity GetEntity()
{
return DisplayConditionGroupEntity;
}
} }
public enum BooleanOperator public enum BooleanOperator

View File

@ -1,4 +1,6 @@
using Artemis.Core.Models.Profile.Conditions.Abstract; using Artemis.Core.Models.Profile.Conditions.Abstract;
using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Entities.Profile.Abstract;
namespace Artemis.Core.Models.Profile.Conditions namespace Artemis.Core.Models.Profile.Conditions
{ {
@ -6,9 +8,17 @@ namespace Artemis.Core.Models.Profile.Conditions
{ {
public ListOperator ListOperator { get; set; } public ListOperator ListOperator { get; set; }
public override void ApplyToEntity() internal override void ApplyToEntity()
{ {
}
internal override void Initialize(IDataModelService dataModelService)
{
}
public override DisplayConditionPartEntity GetEntity()
{
return null;
} }
} }

View File

@ -5,7 +5,10 @@ using Artemis.Core.Exceptions;
using Artemis.Core.Extensions; using Artemis.Core.Extensions;
using Artemis.Core.Models.Profile.Conditions.Abstract; using Artemis.Core.Models.Profile.Conditions.Abstract;
using Artemis.Core.Plugins.Abstract.DataModels; using Artemis.Core.Plugins.Abstract.DataModels;
using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Entities.Profile; using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Entities.Profile.Abstract;
using Newtonsoft.Json;
namespace Artemis.Core.Models.Profile.Conditions namespace Artemis.Core.Models.Profile.Conditions
{ {
@ -22,10 +25,6 @@ namespace Artemis.Core.Models.Profile.Conditions
{ {
Parent = parent; Parent = parent;
DisplayConditionPredicateEntity = entity; DisplayConditionPredicateEntity = entity;
// TODO: This has to be done from somewhere
// LeftDataModel = dataModelService.GetPluginDataModelByGuid(DisplayConditionPredicateEntity.LeftDataModelGuid);
// RightDataModel = dataModelService.GetPluginDataModelByGuid(DisplayConditionPredicateEntity.RightDataModelGuid);
} }
public DisplayConditionPredicateEntity DisplayConditionPredicateEntity { get; set; } public DisplayConditionPredicateEntity DisplayConditionPredicateEntity { get; set; }
@ -122,13 +121,77 @@ namespace Artemis.Core.Models.Profile.Conditions
CreateStaticExpression(); CreateStaticExpression();
} }
public override void ApplyToEntity() internal override void ApplyToEntity()
{ {
DisplayConditionPredicateEntity.LeftDataModelGuid = LeftDataModel?.PluginInfo?.Guid;
DisplayConditionPredicateEntity.LeftPropertyPath = LeftPropertyPath;
DisplayConditionPredicateEntity.RightDataModelGuid = RightDataModel?.PluginInfo?.Guid;
DisplayConditionPredicateEntity.RightPropertyPath = RightPropertyPath;
DisplayConditionPredicateEntity.RightStaticValue = JsonConvert.SerializeObject(RightStaticValue);
DisplayConditionPredicateEntity.OperatorPluginGuid = Operator?.PluginInfo?.Guid;
DisplayConditionPredicateEntity.OperatorType = Operator?.GetType().Name;
}
internal override void Initialize(IDataModelService dataModelService)
{
// Left side
if (DisplayConditionPredicateEntity.LeftDataModelGuid != null)
{
var dataModel = dataModelService.GetPluginDataModelByGuid(DisplayConditionPredicateEntity.LeftDataModelGuid.Value);
if (dataModel != null)
UpdateLeftSide(dataModel, DisplayConditionPredicateEntity.LeftPropertyPath);
}
// Operator
if (DisplayConditionPredicateEntity.OperatorPluginGuid != null)
{
var conditionOperator = dataModelService.GetConditionOperator(DisplayConditionPredicateEntity.OperatorPluginGuid.Value, DisplayConditionPredicateEntity.OperatorType);
if (conditionOperator != null)
UpdateOperator(conditionOperator);
}
// Right side dynamic
if (DisplayConditionPredicateEntity.RightDataModelGuid != null)
{
var dataModel = dataModelService.GetPluginDataModelByGuid(DisplayConditionPredicateEntity.RightDataModelGuid.Value);
if (dataModel != null)
UpdateRightSide(dataModel, DisplayConditionPredicateEntity.RightPropertyPath);
}
// Right side static
else if (DisplayConditionPredicateEntity.RightStaticValue != null)
{
try
{
if (LeftDataModel != null)
{
// Use the left side type so JSON.NET has a better idea what to do
var leftSideType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
UpdateRightSide(JsonConvert.DeserializeObject(DisplayConditionPredicateEntity.RightStaticValue, leftSideType));
}
else
{
// Hope for the best...
UpdateRightSide(JsonConvert.DeserializeObject(DisplayConditionPredicateEntity.RightStaticValue));
}
}
catch (JsonReaderException)
{
// ignored
// TODO: Some logging would be nice
}
}
}
public override DisplayConditionPartEntity GetEntity()
{
return DisplayConditionPredicateEntity;
} }
private void ValidateOperator() private void ValidateOperator()
{ {
if (LeftDataModel == null) if (LeftDataModel == null || Operator == null)
return; return;
var leftType = LeftDataModel.GetTypeAtPath(LeftPropertyPath); var leftType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
@ -136,7 +199,6 @@ namespace Artemis.Core.Models.Profile.Conditions
Operator = null; Operator = null;
} }
/// <summary> /// <summary>
/// Validates the right side, ensuring it is still compatible with the current left side /// Validates the right side, ensuring it is still compatible with the current left side
/// </summary> /// </summary>
@ -217,7 +279,7 @@ namespace Artemis.Core.Models.Profile.Conditions
private void CreateStaticExpression() private void CreateStaticExpression()
{ {
if (LeftDataModel == null) if (LeftDataModel == null || Operator == null)
return; return;
var leftSideParameter = Expression.Parameter(typeof(DataModel), "leftDataModel"); var leftSideParameter = Expression.Parameter(typeof(DataModel), "leftDataModel");

View File

@ -58,8 +58,7 @@ namespace Artemis.Core.Models.Profile
} }
internal FolderEntity FolderEntity { get; set; } internal FolderEntity FolderEntity { get; set; }
internal override PropertiesEntity PropertiesEntity => FolderEntity; internal override RenderElementEntity RenderElementEntity => FolderEntity;
internal override EffectsEntity EffectsEntity => FolderEntity;
public override void Update(double deltaTime) public override void Update(double deltaTime)
{ {
@ -189,6 +188,7 @@ namespace Artemis.Core.Models.Profile
ApplyLayerEffectsToEntity(); ApplyLayerEffectsToEntity();
// Conditions // Conditions
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.DisplayConditionGroupEntity;
DisplayConditionGroup?.ApplyToEntity(); DisplayConditionGroup?.ApplyToEntity();
} }

View File

@ -19,8 +19,8 @@ using SkiaSharp;
namespace Artemis.Core.Models.Profile namespace Artemis.Core.Models.Profile
{ {
/// <summary> /// <summary>
/// Represents a layer on a profile. To create new layers use the <see cref="LayerService" /> by injecting /// Represents a layer on a profile. To create new layers use the <see cref="RenderElementService" /> by injecting
/// <see cref="ILayerService" /> into your code /// <see cref="IRenderElementService" /> into your code
/// </summary> /// </summary>
public sealed class Layer : RenderProfileElement public sealed class Layer : RenderProfileElement
{ {
@ -72,8 +72,7 @@ namespace Artemis.Core.Models.Profile
} }
internal LayerEntity LayerEntity { get; set; } internal LayerEntity LayerEntity { get; set; }
internal override PropertiesEntity PropertiesEntity => LayerEntity; internal override RenderElementEntity RenderElementEntity => LayerEntity;
internal override EffectsEntity EffectsEntity => LayerEntity;
/// <summary> /// <summary>
/// A collection of all the LEDs this layer is assigned to. /// A collection of all the LEDs this layer is assigned to.
@ -158,6 +157,7 @@ namespace Artemis.Core.Models.Profile
} }
// Conditions // Conditions
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.DisplayConditionGroupEntity;
DisplayConditionGroup?.ApplyToEntity(); DisplayConditionGroup?.ApplyToEntity();
} }

View File

@ -129,7 +129,7 @@ namespace Artemis.Core.Models.Profile
PropertyGroupInitialized?.Invoke(this, EventArgs.Empty); PropertyGroupInitialized?.Invoke(this, EventArgs.Empty);
} }
internal void InitializeProperties(ILayerService layerService, RenderProfileElement profileElement, [NotNull] string path) internal void InitializeProperties(IRenderElementService renderElementService, RenderProfileElement profileElement, [NotNull] string path)
{ {
if (path == null) if (path == null)
throw new ArgumentNullException(nameof(path)); throw new ArgumentNullException(nameof(path));
@ -177,7 +177,7 @@ namespace Artemis.Core.Models.Profile
instance.GroupDescription = (PropertyGroupDescriptionAttribute) propertyGroupDescription; instance.GroupDescription = (PropertyGroupDescriptionAttribute) propertyGroupDescription;
instance.LayerBrush = LayerBrush; instance.LayerBrush = LayerBrush;
instance.LayerEffect = LayerEffect; instance.LayerEffect = LayerEffect;
instance.InitializeProperties(layerService, profileElement, $"{path}{propertyInfo.Name}."); instance.InitializeProperties(renderElementService, profileElement, $"{path}{propertyInfo.Name}.");
propertyInfo.SetValue(this, instance); propertyInfo.SetValue(this, instance);
_layerPropertyGroups.Add(instance); _layerPropertyGroups.Add(instance);
@ -246,13 +246,13 @@ namespace Artemis.Core.Models.Profile
else else
pluginGuid = instance.Parent.LayerEffect.PluginInfo.Guid; pluginGuid = instance.Parent.LayerEffect.PluginInfo.Guid;
var entity = profileElement.PropertiesEntity.PropertyEntities.FirstOrDefault(p => p.PluginGuid == pluginGuid && p.Path == path); var entity = profileElement.RenderElementEntity.PropertyEntities.FirstOrDefault(p => p.PluginGuid == pluginGuid && p.Path == path);
var fromStorage = true; var fromStorage = true;
if (entity == null) if (entity == null)
{ {
fromStorage = false; fromStorage = false;
entity = new PropertyEntity {PluginGuid = pluginGuid, Path = path}; entity = new PropertyEntity {PluginGuid = pluginGuid, Path = path};
profileElement.PropertiesEntity.PropertyEntities.Add(entity); profileElement.RenderElementEntity.PropertyEntities.Add(entity);
} }
instance.ApplyToLayerProperty(entity, this, fromStorage); instance.ApplyToLayerProperty(entity, this, fromStorage);

View File

@ -16,7 +16,7 @@ namespace Artemis.Core.Models.Profile
#region Properties #region Properties
private SKPath _path; private SKPath _path;
internal abstract PropertiesEntity PropertiesEntity { get; } internal abstract RenderElementEntity RenderElementEntity { get; }
/// <summary> /// <summary>
/// Gets the path containing all the LEDs this entity is applied to, any rendering outside the entity Path is /// Gets the path containing all the LEDs this entity is applied to, any rendering outside the entity Path is
@ -68,7 +68,6 @@ namespace Artemis.Core.Models.Profile
#region Effects #region Effects
protected List<BaseLayerEffect> _layerEffects; protected List<BaseLayerEffect> _layerEffects;
internal abstract EffectsEntity EffectsEntity { get; }
/// <summary> /// <summary>
/// Gets a read-only collection of the layer effects on this entity /// Gets a read-only collection of the layer effects on this entity
@ -77,7 +76,7 @@ namespace Artemis.Core.Models.Profile
protected void ApplyLayerEffectsToEntity() protected void ApplyLayerEffectsToEntity()
{ {
EffectsEntity.LayerEffects.Clear(); RenderElementEntity.LayerEffects.Clear();
foreach (var layerEffect in LayerEffects) foreach (var layerEffect in LayerEffects)
{ {
var layerEffectEntity = new LayerEffectEntity var layerEffectEntity = new LayerEffectEntity
@ -90,7 +89,7 @@ namespace Artemis.Core.Models.Profile
HasBeenRenamed = layerEffect.HasBeenRenamed, HasBeenRenamed = layerEffect.HasBeenRenamed,
Order = layerEffect.Order Order = layerEffect.Order
}; };
EffectsEntity.LayerEffects.Add(layerEffectEntity); RenderElementEntity.LayerEffects.Add(layerEffectEntity);
layerEffect.BaseProperties.ApplyToEntity(); layerEffect.BaseProperties.ApplyToEntity();
} }
} }

View File

@ -113,7 +113,7 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
// Not only is this needed to initialize properties on the layer brushes, it also prevents implementing anything // Not only is this needed to initialize properties on the layer brushes, it also prevents implementing anything
// but LayerBrush<T> and RgbNetLayerBrush<T> outside the core // but LayerBrush<T> and RgbNetLayerBrush<T> outside the core
internal abstract void Initialize(ILayerService layerService); internal abstract void Initialize(IRenderElementService renderElementService);
internal abstract void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint); internal abstract void InternalRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint);

View File

@ -27,9 +27,9 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
Render(canvas, canvasInfo, path, paint); Render(canvas, canvasInfo, path, paint);
} }
internal override void Initialize(ILayerService layerService) internal override void Initialize(IRenderElementService renderElementService)
{ {
InitializeProperties(layerService); InitializeProperties(renderElementService);
} }
} }
} }

View File

@ -35,11 +35,11 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
internal set => _properties = value; internal set => _properties = value;
} }
internal void InitializeProperties(ILayerService layerService) internal void InitializeProperties(IRenderElementService renderElementService)
{ {
Properties = Activator.CreateInstance<T>(); Properties = Activator.CreateInstance<T>();
Properties.LayerBrush = this; Properties.LayerBrush = this;
Properties.InitializeProperties(layerService, Layer, "LayerBrush."); Properties.InitializeProperties(renderElementService, Layer, "LayerBrush.");
PropertiesInitialized = true; PropertiesInitialized = true;
EnableLayerBrush(); EnableLayerBrush();

View File

@ -39,12 +39,12 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract
LedGroup.Brush = GetBrush(); LedGroup.Brush = GetBrush();
} }
internal override void Initialize(ILayerService layerService) internal override void Initialize(IRenderElementService renderElementService)
{ {
LedGroup = new ListLedGroup(); LedGroup = new ListLedGroup();
Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated; Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
InitializeProperties(layerService); InitializeProperties(renderElementService);
UpdateLedGroup(); UpdateLedGroup();
} }

View File

@ -144,7 +144,7 @@ namespace Artemis.Core.Plugins.LayerEffect.Abstract
// Not only is this needed to initialize properties on the layer effects, it also prevents implementing anything // Not only is this needed to initialize properties on the layer effects, it also prevents implementing anything
// but LayerEffect<T> outside the core // but LayerEffect<T> outside the core
internal abstract void Initialize(ILayerService layerService); internal abstract void Initialize(IRenderElementService renderElementService);
/// <summary> /// <summary>

View File

@ -36,19 +36,19 @@ namespace Artemis.Core.Plugins.LayerEffect.Abstract
internal set => _properties = value; internal set => _properties = value;
} }
internal void InitializeProperties(ILayerService layerService) internal void InitializeProperties(IRenderElementService renderElementService)
{ {
Properties = Activator.CreateInstance<T>(); Properties = Activator.CreateInstance<T>();
Properties.LayerEffect = this; Properties.LayerEffect = this;
Properties.InitializeProperties(layerService, ProfileElement, PropertyRootPath); Properties.InitializeProperties(renderElementService, ProfileElement, PropertyRootPath);
PropertiesInitialized = true; PropertiesInitialized = true;
EnableLayerEffect(); EnableLayerEffect();
} }
internal override void Initialize(ILayerService layerService) internal override void Initialize(IRenderElementService renderElementService)
{ {
InitializeProperties(layerService); InitializeProperties(renderElementService);
} }
} }
} }

View File

@ -155,6 +155,11 @@ namespace Artemis.Core.Services
} }
} }
public DisplayConditionOperator GetConditionOperator(Guid operatorPluginGuid, string operatorType)
{
return RegisteredConditionOperators.FirstOrDefault(o => o.PluginInfo.Guid == operatorPluginGuid && o.GetType().Name == operatorType);
}
private void RegisterBuiltInConditionOperators() private void RegisterBuiltInConditionOperators()
{ {
RegisterConditionOperator(Constants.CorePluginInfo, new EqualsConditionOperator()); RegisterConditionOperator(Constants.CorePluginInfo, new EqualsConditionOperator());

View File

@ -58,5 +58,6 @@ namespace Artemis.Core.Services.Interfaces
void RemoveConditionOperator([NotNull] DisplayConditionOperator displayConditionOperator); void RemoveConditionOperator([NotNull] DisplayConditionOperator displayConditionOperator);
List<DisplayConditionOperator> GetCompatibleConditionOperators(Type type); List<DisplayConditionOperator> GetCompatibleConditionOperators(Type type);
DisplayConditionOperator GetConditionOperator(Guid operatorPluginGuid, string operatorType);
} }
} }

View File

@ -6,7 +6,7 @@ using Artemis.Core.Plugins.LayerEffect.Abstract;
namespace Artemis.Core.Services.Interfaces namespace Artemis.Core.Services.Interfaces
{ {
public interface ILayerService : IArtemisService public interface IRenderElementService : IArtemisService
{ {
/// <summary> /// <summary>
/// Creates a new layer /// Creates a new layer
@ -55,5 +55,7 @@ namespace Artemis.Core.Services.Interfaces
BaseLayerEffect AddLayerEffect(RenderProfileElement renderProfileElement, LayerEffectDescriptor layerEffectDescriptor); BaseLayerEffect AddLayerEffect(RenderProfileElement renderProfileElement, LayerEffectDescriptor layerEffectDescriptor);
void RemoveLayerEffect(BaseLayerEffect layerEffect); void RemoveLayerEffect(BaseLayerEffect layerEffect);
void InstantiateDisplayConditions(RenderProfileElement renderElement);
} }
} }

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Artemis.Core.Exceptions; using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Conditions;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.LayerBrush.Abstract; using Artemis.Core.Plugins.LayerBrush.Abstract;
using Artemis.Core.Plugins.LayerEffect; using Artemis.Core.Plugins.LayerEffect;
@ -14,17 +15,19 @@ using Serilog;
namespace Artemis.Core.Services namespace Artemis.Core.Services
{ {
public class LayerService : ILayerService public class RenderElementService : IRenderElementService
{ {
private readonly IKernel _kernel; private readonly IKernel _kernel;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IPluginService _pluginService; private readonly IPluginService _pluginService;
private readonly IDataModelService _dataModelService;
public LayerService(IKernel kernel, ILogger logger, IPluginService pluginService, IDataModelService dataModelService) public RenderElementService(IKernel kernel, ILogger logger, IPluginService pluginService, IDataModelService dataModelService)
{ {
_kernel = kernel; _kernel = kernel;
_logger = logger; _logger = logger;
_pluginService = pluginService; _pluginService = pluginService;
_dataModelService = dataModelService;
} }
public Layer CreateLayer(Profile profile, ProfileElement parent, string name) public Layer CreateLayer(Profile profile, ProfileElement parent, string name)
@ -39,6 +42,7 @@ namespace Artemis.Core.Services
// With the properties loaded, the layer brush and effect can be instantiated // With the properties loaded, the layer brush and effect can be instantiated
InstantiateLayerBrush(layer); InstantiateLayerBrush(layer);
InstantiateLayerEffects(layer); InstantiateLayerEffects(layer);
InstantiateDisplayConditions(layer);
return layer; return layer;
} }
@ -112,7 +116,7 @@ namespace Artemis.Core.Services
{ {
var layerEffectProviders = _pluginService.GetPluginsOfType<LayerEffectProvider>(); var layerEffectProviders = _pluginService.GetPluginsOfType<LayerEffectProvider>();
var descriptors = layerEffectProviders.SelectMany(l => l.LayerEffectDescriptors).ToList(); var descriptors = layerEffectProviders.SelectMany(l => l.LayerEffectDescriptors).ToList();
var entities = renderElement.EffectsEntity.LayerEffects.OrderByDescending(e => e.Order).ToList(); var entities = renderElement.RenderElementEntity.LayerEffects.OrderByDescending(e => e.Order).ToList();
foreach (var layerEffectEntity in entities) foreach (var layerEffectEntity in entities)
{ {
@ -143,10 +147,15 @@ namespace Artemis.Core.Services
_logger.Debug("Instantiated layer effect with root path {rootPath}", effect.PropertyRootPath); _logger.Debug("Instantiated layer effect with root path {rootPath}", effect.PropertyRootPath);
} }
} }
public void InstantiateDisplayConditions(RenderProfileElement renderElement) public void InstantiateDisplayConditions(RenderProfileElement renderElement)
{ {
var displayCondition = renderElement.RenderElementEntity.RootDisplayCondition != null
? new DisplayConditionGroup(null, renderElement.RenderElementEntity.RootDisplayCondition)
: new DisplayConditionGroup(null);
displayCondition.Initialize(_dataModelService);
renderElement.DisplayConditionGroup = displayCondition;
} }
} }
} }

View File

@ -19,18 +19,18 @@ namespace Artemis.Core.Services.Storage
/// </summary> /// </summary>
public class ProfileService : IProfileService public class ProfileService : IProfileService
{ {
private readonly ILayerService _layerService; private readonly IRenderElementService _renderElementService;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IPluginService _pluginService; private readonly IPluginService _pluginService;
private readonly IProfileRepository _profileRepository; private readonly IProfileRepository _profileRepository;
private readonly ISurfaceService _surfaceService; private readonly ISurfaceService _surfaceService;
internal ProfileService(ILogger logger, IPluginService pluginService, ISurfaceService surfaceService, ILayerService layerService, IProfileRepository profileRepository) internal ProfileService(ILogger logger, IPluginService pluginService, ISurfaceService surfaceService, IRenderElementService renderElementService, IProfileRepository profileRepository)
{ {
_logger = logger; _logger = logger;
_pluginService = pluginService; _pluginService = pluginService;
_surfaceService = surfaceService; _surfaceService = surfaceService;
_layerService = layerService; _renderElementService = renderElementService;
_profileRepository = profileRepository; _profileRepository = profileRepository;
_surfaceService.ActiveSurfaceConfigurationSelected += OnActiveSurfaceConfigurationSelected; _surfaceService.ActiveSurfaceConfigurationSelected += OnActiveSurfaceConfigurationSelected;
@ -170,9 +170,9 @@ namespace Artemis.Core.Services.Storage
foreach (var layer in profile.GetAllLayers()) foreach (var layer in profile.GetAllLayers())
{ {
if (!layer.General.PropertiesInitialized) if (!layer.General.PropertiesInitialized)
layer.General.InitializeProperties(_layerService, layer, "General."); layer.General.InitializeProperties(_renderElementService, layer, "General.");
if (!layer.Transform.PropertiesInitialized) if (!layer.Transform.PropertiesInitialized)
layer.Transform.InitializeProperties(_layerService, layer, "Transform."); layer.Transform.InitializeProperties(_renderElementService, layer, "Transform.");
} }
} }
@ -181,11 +181,13 @@ namespace Artemis.Core.Services.Storage
foreach (var folder in profile.GetAllFolders()) foreach (var folder in profile.GetAllFolders())
{ {
// Instantiate effects // Instantiate effects
_layerService.InstantiateLayerEffects(folder); _renderElementService.InstantiateLayerEffects(folder);
// Remove effects of plugins that are disabled // Remove effects of plugins that are disabled
var disabledEffects = new List<BaseLayerEffect>(folder.LayerEffects.Where(layerLayerEffect => !layerLayerEffect.PluginInfo.Enabled)); var disabledEffects = new List<BaseLayerEffect>(folder.LayerEffects.Where(layerLayerEffect => !layerLayerEffect.PluginInfo.Enabled));
foreach (var layerLayerEffect in disabledEffects) foreach (var layerLayerEffect in disabledEffects)
_layerService.RemoveLayerEffect(layerLayerEffect); _renderElementService.RemoveLayerEffect(layerLayerEffect);
_renderElementService.InstantiateDisplayConditions(folder);
} }
} }
@ -195,17 +197,19 @@ namespace Artemis.Core.Services.Storage
{ {
// Instantiate brush // Instantiate brush
if (layer.LayerBrush == null) if (layer.LayerBrush == null)
_layerService.InstantiateLayerBrush(layer); _renderElementService.InstantiateLayerBrush(layer);
// Remove brush if plugin is disabled // Remove brush if plugin is disabled
else if (!layer.LayerBrush.PluginInfo.Enabled) else if (!layer.LayerBrush.PluginInfo.Enabled)
_layerService.DeactivateLayerBrush(layer); _renderElementService.DeactivateLayerBrush(layer);
// Instantiate effects // Instantiate effects
_layerService.InstantiateLayerEffects(layer); _renderElementService.InstantiateLayerEffects(layer);
// Remove effects of plugins that are disabled // Remove effects of plugins that are disabled
var disabledEffects = new List<BaseLayerEffect>(layer.LayerEffects.Where(layerLayerEffect => !layerLayerEffect.PluginInfo.Enabled)); var disabledEffects = new List<BaseLayerEffect>(layer.LayerEffects.Where(layerLayerEffect => !layerLayerEffect.PluginInfo.Enabled));
foreach (var layerLayerEffect in disabledEffects) foreach (var layerLayerEffect in disabledEffects)
_layerService.RemoveLayerEffect(layerLayerEffect); _renderElementService.RemoveLayerEffect(layerLayerEffect);
_renderElementService.InstantiateDisplayConditions(layer);
} }
} }

View File

@ -1,13 +1,9 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
namespace Artemis.Storage.Entities.Profile.Abstract namespace Artemis.Storage.Entities.Profile.Abstract
{ {
public abstract class DisplayConditionPartEntity public abstract class DisplayConditionPartEntity
{ {
public Guid Id { get; set; }
public Guid ParentId { get; set; }
public List<DisplayConditionPartEntity> Children { get; set; } public List<DisplayConditionPartEntity> Children { get; set; }
} }
} }

View File

@ -1,9 +0,0 @@
using System.Collections.Generic;
namespace Artemis.Storage.Entities.Profile.Abstract
{
public abstract class EffectsEntity : PropertiesEntity
{
public List<LayerEffectEntity> LayerEffects { get; set; }
}
}

View File

@ -2,9 +2,12 @@
namespace Artemis.Storage.Entities.Profile.Abstract namespace Artemis.Storage.Entities.Profile.Abstract
{ {
public abstract class PropertiesEntity public abstract class RenderElementEntity
{ {
public List<LayerEffectEntity> LayerEffects { get; set; }
public List<PropertyEntity> PropertyEntities { get; set; } public List<PropertyEntity> PropertyEntities { get; set; }
public List<string> ExpandedPropertyGroups { get; set; } public List<string> ExpandedPropertyGroups { get; set; }
public DisplayConditionGroupEntity RootDisplayCondition { get; set; }
} }
} }

View File

@ -5,12 +5,15 @@ namespace Artemis.Storage.Entities.Profile
{ {
public class DisplayConditionPredicateEntity : DisplayConditionPartEntity public class DisplayConditionPredicateEntity : DisplayConditionPartEntity
{ {
public Guid LeftDataModelGuid { get; set; } public Guid? LeftDataModelGuid { get; set; }
public string LeftPropertyPath { get; set; } public string LeftPropertyPath { get; set; }
public Guid RightDataModelGuid { get; set; } public Guid? RightDataModelGuid { get; set; }
public string RightPropertyPath { get; set; } public string RightPropertyPath { get; set; }
public string OperatorType { get; set; }
public Guid? OperatorPluginGuid { get; set; }
// Stored as a string to be able to control serialization and deserialization ourselves // Stored as a string to be able to control serialization and deserialization ourselves
public string RightStaticValue { get; set; } public string RightStaticValue { get; set; }
} }

View File

@ -5,7 +5,7 @@ using LiteDB;
namespace Artemis.Storage.Entities.Profile namespace Artemis.Storage.Entities.Profile
{ {
public class FolderEntity : EffectsEntity public class FolderEntity : RenderElementEntity
{ {
public FolderEntity() public FolderEntity()
{ {

View File

@ -5,7 +5,7 @@ using LiteDB;
namespace Artemis.Storage.Entities.Profile namespace Artemis.Storage.Entities.Profile
{ {
public class LayerEntity : EffectsEntity public class LayerEntity : RenderElementEntity
{ {
public LayerEntity() public LayerEntity()
{ {

View File

@ -13,14 +13,14 @@ namespace Artemis.UI.PropertyInput
{ {
public class BrushPropertyInputViewModel : PropertyInputViewModel<LayerBrushReference> public class BrushPropertyInputViewModel : PropertyInputViewModel<LayerBrushReference>
{ {
private readonly ILayerService _layerService; private readonly IRenderElementService _renderElementService;
private readonly IPluginService _pluginService; private readonly IPluginService _pluginService;
private List<LayerBrushDescriptor> _descriptors; private List<LayerBrushDescriptor> _descriptors;
public BrushPropertyInputViewModel(LayerProperty<LayerBrushReference> layerProperty, IProfileEditorService profileEditorService, public BrushPropertyInputViewModel(LayerProperty<LayerBrushReference> layerProperty, IProfileEditorService profileEditorService,
ILayerService layerService, IPluginService pluginService) : base(layerProperty, profileEditorService) IRenderElementService renderElementService, IPluginService pluginService) : base(layerProperty, profileEditorService)
{ {
_layerService = layerService; _renderElementService = renderElementService;
_pluginService = pluginService; _pluginService = pluginService;
_pluginService.PluginEnabled += PluginServiceOnPluginLoaded; _pluginService.PluginEnabled += PluginServiceOnPluginLoaded;
@ -59,8 +59,8 @@ namespace Artemis.UI.PropertyInput
{ {
if (LayerProperty.ProfileElement is Layer layer) if (LayerProperty.ProfileElement is Layer layer)
{ {
_layerService.RemoveLayerBrush(layer); _renderElementService.RemoveLayerBrush(layer);
_layerService.InstantiateLayerBrush(layer); _renderElementService.InstantiateLayerBrush(layer);
} }
} }

View File

@ -12,16 +12,16 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.LayerEffects
{ {
public class EffectsViewModel : PropertyChangedBase public class EffectsViewModel : PropertyChangedBase
{ {
private readonly ILayerService _layerService; private readonly IRenderElementService _renderElementService;
private readonly IPluginService _pluginService; private readonly IPluginService _pluginService;
private readonly IProfileEditorService _profileEditorService; private readonly IProfileEditorService _profileEditorService;
private BindableCollection<LayerEffectDescriptor> _layerEffectDescriptors; private BindableCollection<LayerEffectDescriptor> _layerEffectDescriptors;
private LayerEffectDescriptor _selectedLayerEffectDescriptor; private LayerEffectDescriptor _selectedLayerEffectDescriptor;
public EffectsViewModel(LayerPropertiesViewModel layerPropertiesViewModel, IPluginService pluginService, ILayerService layerService, IProfileEditorService profileEditorService) public EffectsViewModel(LayerPropertiesViewModel layerPropertiesViewModel, IPluginService pluginService, IRenderElementService renderElementService, IProfileEditorService profileEditorService)
{ {
_pluginService = pluginService; _pluginService = pluginService;
_layerService = layerService; _renderElementService = renderElementService;
_profileEditorService = profileEditorService; _profileEditorService = profileEditorService;
LayerPropertiesViewModel = layerPropertiesViewModel; LayerPropertiesViewModel = layerPropertiesViewModel;
LayerEffectDescriptors = new BindableCollection<LayerEffectDescriptor>(); LayerEffectDescriptors = new BindableCollection<LayerEffectDescriptor>();
@ -70,7 +70,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.LayerEffects
Execute.PostToUIThread(async () => Execute.PostToUIThread(async () =>
{ {
await Task.Delay(500); await Task.Delay(500);
_layerService.AddLayerEffect(renderElement, SelectedLayerEffectDescriptor); _renderElementService.AddLayerEffect(renderElement, SelectedLayerEffectDescriptor);
_profileEditorService.UpdateSelectedProfileElement(); _profileEditorService.UpdateSelectedProfileElement();
}); });
} }

View File

@ -13,14 +13,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree
{ {
private readonly IDialogService _dialogService; private readonly IDialogService _dialogService;
private readonly IWindowManager _windowManager; private readonly IWindowManager _windowManager;
private readonly ILayerService _layerService; private readonly IRenderElementService _renderElementService;
private readonly IProfileEditorService _profileEditorService; private readonly IProfileEditorService _profileEditorService;
public TreePropertyGroupViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel, public TreePropertyGroupViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel,
IProfileEditorService profileEditorService, ILayerService layerService, IDialogService dialogService, IWindowManager windowManager) IProfileEditorService profileEditorService, IRenderElementService renderElementService, IDialogService dialogService, IWindowManager windowManager)
{ {
_profileEditorService = profileEditorService; _profileEditorService = profileEditorService;
_layerService = layerService; _renderElementService = renderElementService;
_dialogService = dialogService; _dialogService = dialogService;
_windowManager = windowManager; _windowManager = windowManager;
LayerPropertyGroupViewModel = (LayerPropertyGroupViewModel) layerPropertyBaseViewModel; LayerPropertyGroupViewModel = (LayerPropertyGroupViewModel) layerPropertyBaseViewModel;
@ -78,7 +78,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree
public void DeleteEffect() public void DeleteEffect()
{ {
_layerService.RemoveLayerEffect(LayerPropertyGroupViewModel.LayerPropertyGroup.LayerEffect); _renderElementService.RemoveLayerEffect(LayerPropertyGroupViewModel.LayerPropertyGroup.LayerEffect);
_profileEditorService.UpdateSelectedProfile(); _profileEditorService.UpdateSelectedProfile();
} }

View File

@ -23,10 +23,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
public FolderViewModel(ProfileElement folder, public FolderViewModel(ProfileElement folder,
IProfileEditorService profileEditorService, IProfileEditorService profileEditorService,
IDialogService dialogService, IDialogService dialogService,
ILayerService layerService, IRenderElementService renderElementService,
IFolderVmFactory folderVmFactory, IFolderVmFactory folderVmFactory,
ILayerVmFactory layerVmFactory) : ILayerVmFactory layerVmFactory) :
base(null, folder, profileEditorService, dialogService, layerService, folderVmFactory, layerVmFactory) base(null, folder, profileEditorService, dialogService, renderElementService, folderVmFactory, layerVmFactory)
{ {
} }
@ -34,10 +34,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
ProfileElement folder, ProfileElement folder,
IProfileEditorService profileEditorService, IProfileEditorService profileEditorService,
IDialogService dialogService, IDialogService dialogService,
ILayerService layerService, IRenderElementService renderElementService,
IFolderVmFactory folderVmFactory, IFolderVmFactory folderVmFactory,
ILayerVmFactory layerVmFactory) : ILayerVmFactory layerVmFactory) :
base(parent, folder, profileEditorService, dialogService, layerService, folderVmFactory, layerVmFactory) base(parent, folder, profileEditorService, dialogService, renderElementService, folderVmFactory, layerVmFactory)
{ {
} }

View File

@ -11,10 +11,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
ProfileElement folder, ProfileElement folder,
IProfileEditorService profileEditorService, IProfileEditorService profileEditorService,
IDialogService dialogService, IDialogService dialogService,
ILayerService layerService, IRenderElementService renderElementService,
IFolderVmFactory folderVmFactory, IFolderVmFactory folderVmFactory,
ILayerVmFactory layerVmFactory) : ILayerVmFactory layerVmFactory) :
base(parent, folder, profileEditorService, dialogService, layerService, folderVmFactory, layerVmFactory) base(parent, folder, profileEditorService, dialogService, renderElementService, folderVmFactory, layerVmFactory)
{ {
} }

View File

@ -16,7 +16,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
{ {
private readonly IDialogService _dialogService; private readonly IDialogService _dialogService;
private readonly IFolderVmFactory _folderVmFactory; private readonly IFolderVmFactory _folderVmFactory;
private readonly ILayerService _layerService; private readonly IRenderElementService _renderElementService;
private readonly ILayerVmFactory _layerVmFactory; private readonly ILayerVmFactory _layerVmFactory;
private readonly IProfileEditorService _profileEditorService; private readonly IProfileEditorService _profileEditorService;
private BindableCollection<TreeItemViewModel> _children; private BindableCollection<TreeItemViewModel> _children;
@ -27,13 +27,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
ProfileElement profileElement, ProfileElement profileElement,
IProfileEditorService profileEditorService, IProfileEditorService profileEditorService,
IDialogService dialogService, IDialogService dialogService,
ILayerService layerService, IRenderElementService renderElementService,
IFolderVmFactory folderVmFactory, IFolderVmFactory folderVmFactory,
ILayerVmFactory layerVmFactory) ILayerVmFactory layerVmFactory)
{ {
_profileEditorService = profileEditorService; _profileEditorService = profileEditorService;
_dialogService = dialogService; _dialogService = dialogService;
_layerService = layerService; _renderElementService = renderElementService;
_folderVmFactory = folderVmFactory; _folderVmFactory = folderVmFactory;
_layerVmFactory = layerVmFactory; _layerVmFactory = layerVmFactory;
@ -145,7 +145,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
if (!SupportsChildren) if (!SupportsChildren)
throw new ArtemisUIException("Cannot add a layer to a profile element of type " + ProfileElement.GetType().Name); throw new ArtemisUIException("Cannot add a layer to a profile element of type " + ProfileElement.GetType().Name);
_layerService.CreateLayer(ProfileElement.Profile, ProfileElement, "New layer"); _renderElementService.CreateLayer(ProfileElement.Profile, ProfileElement, "New layer");
UpdateProfileElements(); UpdateProfileElements();
_profileEditorService.UpdateSelectedProfile(); _profileEditorService.UpdateSelectedProfile();
} }

View File

@ -11,13 +11,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{ {
public class SelectionToolViewModel : VisualizationToolViewModel public class SelectionToolViewModel : VisualizationToolViewModel
{ {
private readonly ILayerService _layerService; private readonly IRenderElementService _renderElementService;
private Rect _dragRectangle; private Rect _dragRectangle;
public SelectionToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerService layerService) public SelectionToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, IRenderElementService renderElementService)
: base(profileViewModel, profileEditorService) : base(profileViewModel, profileEditorService)
{ {
_layerService = layerService; _renderElementService = renderElementService;
using (var stream = new MemoryStream(Resources.aero_crosshair)) using (var stream = new MemoryStream(Resources.aero_crosshair))
{ {
Cursor = new Cursor(stream); Cursor = new Cursor(stream);
@ -57,7 +57,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
// If no layer selected, apply it to a new layer in the selected folder // If no layer selected, apply it to a new layer in the selected folder
else if (ProfileEditorService.SelectedProfileElement is Folder folder) else if (ProfileEditorService.SelectedProfileElement is Folder folder)
{ {
var newLayer = _layerService.CreateLayer(folder.Profile, folder, "New layer"); var newLayer = _renderElementService.CreateLayer(folder.Profile, folder, "New layer");
newLayer.AddLeds(selectedLeds); newLayer.AddLeds(selectedLeds);
ProfileEditorService.ChangeSelectedProfileElement(newLayer); ProfileEditorService.ChangeSelectedProfileElement(newLayer);
ProfileEditorService.UpdateSelectedProfileElement(); ProfileEditorService.UpdateSelectedProfileElement();
@ -66,7 +66,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
else else
{ {
var rootFolder = ProfileEditorService.SelectedProfile.GetRootFolder(); var rootFolder = ProfileEditorService.SelectedProfile.GetRootFolder();
var newLayer = _layerService.CreateLayer(rootFolder.Profile, rootFolder, "New layer"); var newLayer = _renderElementService.CreateLayer(rootFolder.Profile, rootFolder, "New layer");
newLayer.AddLeds(selectedLeds); newLayer.AddLeds(selectedLeds);
ProfileEditorService.ChangeSelectedProfileElement(newLayer); ProfileEditorService.ChangeSelectedProfileElement(newLayer);
ProfileEditorService.UpdateSelectedProfileElement(); ProfileEditorService.UpdateSelectedProfileElement();