diff --git a/src/Artemis.Core/Models/Profile/Conditions/Abstract/DisplayConditionPart.cs b/src/Artemis.Core/Models/Profile/Conditions/Abstract/DisplayConditionPart.cs index a72efd032..36a73ea76 100644 --- a/src/Artemis.Core/Models/Profile/Conditions/Abstract/DisplayConditionPart.cs +++ b/src/Artemis.Core/Models/Profile/Conditions/Abstract/DisplayConditionPart.cs @@ -1,13 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; +using Artemis.Core.Services.Interfaces; +using Artemis.Storage.Entities.Profile.Abstract; namespace Artemis.Core.Models.Profile.Conditions.Abstract { public abstract class DisplayConditionPart { - public Guid EntityId { get; internal set; } - private readonly List _children; 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); } } \ No newline at end of file diff --git a/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionGroup.cs b/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionGroup.cs index c4529322f..960387384 100644 --- a/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionGroup.cs +++ b/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionGroup.cs @@ -1,6 +1,9 @@ using System; +using System.Linq; using Artemis.Core.Models.Profile.Conditions.Abstract; +using Artemis.Core.Services.Interfaces; using Artemis.Storage.Entities.Profile; +using Artemis.Storage.Entities.Profile.Abstract; namespace Artemis.Core.Models.Profile.Conditions { @@ -9,7 +12,6 @@ namespace Artemis.Core.Models.Profile.Conditions public DisplayConditionGroup(DisplayConditionPart parent) { Parent = parent; - EntityId = Guid.NewGuid(); DisplayConditionGroupEntity = new DisplayConditionGroupEntity(); } @@ -17,7 +19,6 @@ namespace Artemis.Core.Models.Profile.Conditions { Parent = parent; DisplayConditionGroupEntity = entity; - EntityId = DisplayConditionGroupEntity.Id; BooleanOperator = (BooleanOperator) DisplayConditionGroupEntity.BooleanOperator; foreach (var childEntity in DisplayConditionGroupEntity.Children) @@ -32,15 +33,26 @@ namespace Artemis.Core.Models.Profile.Conditions public BooleanOperator BooleanOperator { 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.Children.Clear(); + DisplayConditionGroupEntity.Children.AddRange(Children.Select(c => c.GetEntity())); foreach (var child in Children) 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 diff --git a/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionListPredicate.cs b/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionListPredicate.cs index 40d379ef6..d5596b0b8 100644 --- a/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionListPredicate.cs +++ b/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionListPredicate.cs @@ -1,4 +1,6 @@ using Artemis.Core.Models.Profile.Conditions.Abstract; +using Artemis.Core.Services.Interfaces; +using Artemis.Storage.Entities.Profile.Abstract; namespace Artemis.Core.Models.Profile.Conditions { @@ -6,9 +8,17 @@ namespace Artemis.Core.Models.Profile.Conditions { 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; } } diff --git a/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionPredicate.cs b/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionPredicate.cs index 458ffb4ee..4b694d69d 100644 --- a/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionPredicate.cs +++ b/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionPredicate.cs @@ -5,7 +5,10 @@ using Artemis.Core.Exceptions; using Artemis.Core.Extensions; using Artemis.Core.Models.Profile.Conditions.Abstract; using Artemis.Core.Plugins.Abstract.DataModels; +using Artemis.Core.Services.Interfaces; using Artemis.Storage.Entities.Profile; +using Artemis.Storage.Entities.Profile.Abstract; +using Newtonsoft.Json; namespace Artemis.Core.Models.Profile.Conditions { @@ -22,10 +25,6 @@ namespace Artemis.Core.Models.Profile.Conditions { Parent = parent; 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; } @@ -122,13 +121,77 @@ namespace Artemis.Core.Models.Profile.Conditions 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() { - if (LeftDataModel == null) + if (LeftDataModel == null || Operator == null) return; var leftType = LeftDataModel.GetTypeAtPath(LeftPropertyPath); @@ -136,7 +199,6 @@ namespace Artemis.Core.Models.Profile.Conditions Operator = null; } - /// /// Validates the right side, ensuring it is still compatible with the current left side /// @@ -217,7 +279,7 @@ namespace Artemis.Core.Models.Profile.Conditions private void CreateStaticExpression() { - if (LeftDataModel == null) + if (LeftDataModel == null || Operator == null) return; var leftSideParameter = Expression.Parameter(typeof(DataModel), "leftDataModel"); diff --git a/src/Artemis.Core/Models/Profile/Folder.cs b/src/Artemis.Core/Models/Profile/Folder.cs index ff7900999..f1dd44db7 100644 --- a/src/Artemis.Core/Models/Profile/Folder.cs +++ b/src/Artemis.Core/Models/Profile/Folder.cs @@ -58,8 +58,7 @@ namespace Artemis.Core.Models.Profile } internal FolderEntity FolderEntity { get; set; } - internal override PropertiesEntity PropertiesEntity => FolderEntity; - internal override EffectsEntity EffectsEntity => FolderEntity; + internal override RenderElementEntity RenderElementEntity => FolderEntity; public override void Update(double deltaTime) { @@ -189,6 +188,7 @@ namespace Artemis.Core.Models.Profile ApplyLayerEffectsToEntity(); // Conditions + RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.DisplayConditionGroupEntity; DisplayConditionGroup?.ApplyToEntity(); } diff --git a/src/Artemis.Core/Models/Profile/Layer.cs b/src/Artemis.Core/Models/Profile/Layer.cs index 41be991d5..a96d9b15a 100644 --- a/src/Artemis.Core/Models/Profile/Layer.cs +++ b/src/Artemis.Core/Models/Profile/Layer.cs @@ -19,8 +19,8 @@ using SkiaSharp; namespace Artemis.Core.Models.Profile { /// - /// Represents a layer on a profile. To create new layers use the by injecting - /// into your code + /// Represents a layer on a profile. To create new layers use the by injecting + /// into your code /// public sealed class Layer : RenderProfileElement { @@ -72,8 +72,7 @@ namespace Artemis.Core.Models.Profile } internal LayerEntity LayerEntity { get; set; } - internal override PropertiesEntity PropertiesEntity => LayerEntity; - internal override EffectsEntity EffectsEntity => LayerEntity; + internal override RenderElementEntity RenderElementEntity => LayerEntity; /// /// A collection of all the LEDs this layer is assigned to. @@ -158,6 +157,7 @@ namespace Artemis.Core.Models.Profile } // Conditions + RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.DisplayConditionGroupEntity; DisplayConditionGroup?.ApplyToEntity(); } diff --git a/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs b/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs index 87a6b6a33..44d4503b3 100644 --- a/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs +++ b/src/Artemis.Core/Models/Profile/LayerPropertyGroup.cs @@ -129,7 +129,7 @@ namespace Artemis.Core.Models.Profile 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) throw new ArgumentNullException(nameof(path)); @@ -177,7 +177,7 @@ namespace Artemis.Core.Models.Profile instance.GroupDescription = (PropertyGroupDescriptionAttribute) propertyGroupDescription; instance.LayerBrush = LayerBrush; instance.LayerEffect = LayerEffect; - instance.InitializeProperties(layerService, profileElement, $"{path}{propertyInfo.Name}."); + instance.InitializeProperties(renderElementService, profileElement, $"{path}{propertyInfo.Name}."); propertyInfo.SetValue(this, instance); _layerPropertyGroups.Add(instance); @@ -246,13 +246,13 @@ namespace Artemis.Core.Models.Profile else 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; if (entity == null) { fromStorage = false; entity = new PropertyEntity {PluginGuid = pluginGuid, Path = path}; - profileElement.PropertiesEntity.PropertyEntities.Add(entity); + profileElement.RenderElementEntity.PropertyEntities.Add(entity); } instance.ApplyToLayerProperty(entity, this, fromStorage); diff --git a/src/Artemis.Core/Models/Profile/RenderProfileElement.cs b/src/Artemis.Core/Models/Profile/RenderProfileElement.cs index 19fbb7070..80338b462 100644 --- a/src/Artemis.Core/Models/Profile/RenderProfileElement.cs +++ b/src/Artemis.Core/Models/Profile/RenderProfileElement.cs @@ -16,7 +16,7 @@ namespace Artemis.Core.Models.Profile #region Properties private SKPath _path; - internal abstract PropertiesEntity PropertiesEntity { get; } + internal abstract RenderElementEntity RenderElementEntity { get; } /// /// 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 protected List _layerEffects; - internal abstract EffectsEntity EffectsEntity { get; } /// /// Gets a read-only collection of the layer effects on this entity @@ -77,7 +76,7 @@ namespace Artemis.Core.Models.Profile protected void ApplyLayerEffectsToEntity() { - EffectsEntity.LayerEffects.Clear(); + RenderElementEntity.LayerEffects.Clear(); foreach (var layerEffect in LayerEffects) { var layerEffectEntity = new LayerEffectEntity @@ -90,7 +89,7 @@ namespace Artemis.Core.Models.Profile HasBeenRenamed = layerEffect.HasBeenRenamed, Order = layerEffect.Order }; - EffectsEntity.LayerEffects.Add(layerEffectEntity); + RenderElementEntity.LayerEffects.Add(layerEffectEntity); layerEffect.BaseProperties.ApplyToEntity(); } } diff --git a/src/Artemis.Core/Plugins/LayerBrush/Abstract/BaseLayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/Abstract/BaseLayerBrush.cs index f34fb431d..d8277af34 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/Abstract/BaseLayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/Abstract/BaseLayerBrush.cs @@ -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 // but LayerBrush and RgbNetLayerBrush 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); diff --git a/src/Artemis.Core/Plugins/LayerBrush/Abstract/LayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/Abstract/LayerBrush.cs index 545fac339..aaef52bd1 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/Abstract/LayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/Abstract/LayerBrush.cs @@ -27,9 +27,9 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract Render(canvas, canvasInfo, path, paint); } - internal override void Initialize(ILayerService layerService) + internal override void Initialize(IRenderElementService renderElementService) { - InitializeProperties(layerService); + InitializeProperties(renderElementService); } } } \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/LayerBrush/Abstract/PropertiesLayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/Abstract/PropertiesLayerBrush.cs index 2f964052c..5adb2513d 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/Abstract/PropertiesLayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/Abstract/PropertiesLayerBrush.cs @@ -35,11 +35,11 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract internal set => _properties = value; } - internal void InitializeProperties(ILayerService layerService) + internal void InitializeProperties(IRenderElementService renderElementService) { Properties = Activator.CreateInstance(); Properties.LayerBrush = this; - Properties.InitializeProperties(layerService, Layer, "LayerBrush."); + Properties.InitializeProperties(renderElementService, Layer, "LayerBrush."); PropertiesInitialized = true; EnableLayerBrush(); diff --git a/src/Artemis.Core/Plugins/LayerBrush/Abstract/RgbNetLayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrush/Abstract/RgbNetLayerBrush.cs index 8c7d06bad..6e38a6913 100644 --- a/src/Artemis.Core/Plugins/LayerBrush/Abstract/RgbNetLayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrush/Abstract/RgbNetLayerBrush.cs @@ -39,12 +39,12 @@ namespace Artemis.Core.Plugins.LayerBrush.Abstract LedGroup.Brush = GetBrush(); } - internal override void Initialize(ILayerService layerService) + internal override void Initialize(IRenderElementService renderElementService) { LedGroup = new ListLedGroup(); Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated; - InitializeProperties(layerService); + InitializeProperties(renderElementService); UpdateLedGroup(); } diff --git a/src/Artemis.Core/Plugins/LayerEffect/Abstract/BaseLayerEffect.cs b/src/Artemis.Core/Plugins/LayerEffect/Abstract/BaseLayerEffect.cs index d7488f1ce..212eb9368 100644 --- a/src/Artemis.Core/Plugins/LayerEffect/Abstract/BaseLayerEffect.cs +++ b/src/Artemis.Core/Plugins/LayerEffect/Abstract/BaseLayerEffect.cs @@ -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 // but LayerEffect outside the core - internal abstract void Initialize(ILayerService layerService); + internal abstract void Initialize(IRenderElementService renderElementService); /// diff --git a/src/Artemis.Core/Plugins/LayerEffect/Abstract/LayerEffect.cs b/src/Artemis.Core/Plugins/LayerEffect/Abstract/LayerEffect.cs index 6b322fb64..c70bc32e8 100644 --- a/src/Artemis.Core/Plugins/LayerEffect/Abstract/LayerEffect.cs +++ b/src/Artemis.Core/Plugins/LayerEffect/Abstract/LayerEffect.cs @@ -36,19 +36,19 @@ namespace Artemis.Core.Plugins.LayerEffect.Abstract internal set => _properties = value; } - internal void InitializeProperties(ILayerService layerService) + internal void InitializeProperties(IRenderElementService renderElementService) { Properties = Activator.CreateInstance(); Properties.LayerEffect = this; - Properties.InitializeProperties(layerService, ProfileElement, PropertyRootPath); + Properties.InitializeProperties(renderElementService, ProfileElement, PropertyRootPath); PropertiesInitialized = true; EnableLayerEffect(); } - internal override void Initialize(ILayerService layerService) + internal override void Initialize(IRenderElementService renderElementService) { - InitializeProperties(layerService); + InitializeProperties(renderElementService); } } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/DataModelService.cs b/src/Artemis.Core/Services/DataModelService.cs index 60b8b48c2..ba67bf455 100644 --- a/src/Artemis.Core/Services/DataModelService.cs +++ b/src/Artemis.Core/Services/DataModelService.cs @@ -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() { RegisterConditionOperator(Constants.CorePluginInfo, new EqualsConditionOperator()); diff --git a/src/Artemis.Core/Services/Interfaces/IDataModelService.cs b/src/Artemis.Core/Services/Interfaces/IDataModelService.cs index e6190ba40..f3d291cfc 100644 --- a/src/Artemis.Core/Services/Interfaces/IDataModelService.cs +++ b/src/Artemis.Core/Services/Interfaces/IDataModelService.cs @@ -58,5 +58,6 @@ namespace Artemis.Core.Services.Interfaces void RemoveConditionOperator([NotNull] DisplayConditionOperator displayConditionOperator); List GetCompatibleConditionOperators(Type type); + DisplayConditionOperator GetConditionOperator(Guid operatorPluginGuid, string operatorType); } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/Interfaces/ILayerService.cs b/src/Artemis.Core/Services/Interfaces/IRenderElementService.cs similarity index 94% rename from src/Artemis.Core/Services/Interfaces/ILayerService.cs rename to src/Artemis.Core/Services/Interfaces/IRenderElementService.cs index 43fe7a6fd..70f8e0681 100644 --- a/src/Artemis.Core/Services/Interfaces/ILayerService.cs +++ b/src/Artemis.Core/Services/Interfaces/IRenderElementService.cs @@ -6,7 +6,7 @@ using Artemis.Core.Plugins.LayerEffect.Abstract; namespace Artemis.Core.Services.Interfaces { - public interface ILayerService : IArtemisService + public interface IRenderElementService : IArtemisService { /// /// Creates a new layer @@ -55,5 +55,7 @@ namespace Artemis.Core.Services.Interfaces BaseLayerEffect AddLayerEffect(RenderProfileElement renderProfileElement, LayerEffectDescriptor layerEffectDescriptor); void RemoveLayerEffect(BaseLayerEffect layerEffect); + + void InstantiateDisplayConditions(RenderProfileElement renderElement); } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/LayerService.cs b/src/Artemis.Core/Services/RenderElementService.cs similarity index 86% rename from src/Artemis.Core/Services/LayerService.cs rename to src/Artemis.Core/Services/RenderElementService.cs index d2491f9b4..ed7024a5a 100644 --- a/src/Artemis.Core/Services/LayerService.cs +++ b/src/Artemis.Core/Services/RenderElementService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Artemis.Core.Exceptions; using Artemis.Core.Models.Profile; +using Artemis.Core.Models.Profile.Conditions; using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.LayerBrush.Abstract; using Artemis.Core.Plugins.LayerEffect; @@ -14,17 +15,19 @@ using Serilog; namespace Artemis.Core.Services { - public class LayerService : ILayerService + public class RenderElementService : IRenderElementService { private readonly IKernel _kernel; private readonly ILogger _logger; 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; _logger = logger; _pluginService = pluginService; + _dataModelService = dataModelService; } 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 InstantiateLayerBrush(layer); InstantiateLayerEffects(layer); + InstantiateDisplayConditions(layer); return layer; } @@ -112,7 +116,7 @@ namespace Artemis.Core.Services { var layerEffectProviders = _pluginService.GetPluginsOfType(); 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) { @@ -143,10 +147,15 @@ namespace Artemis.Core.Services _logger.Debug("Instantiated layer effect with root path {rootPath}", effect.PropertyRootPath); } } - + 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; } } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/Storage/ProfileService.cs b/src/Artemis.Core/Services/Storage/ProfileService.cs index ce5801eb1..3406dabc2 100644 --- a/src/Artemis.Core/Services/Storage/ProfileService.cs +++ b/src/Artemis.Core/Services/Storage/ProfileService.cs @@ -19,18 +19,18 @@ namespace Artemis.Core.Services.Storage /// public class ProfileService : IProfileService { - private readonly ILayerService _layerService; + private readonly IRenderElementService _renderElementService; private readonly ILogger _logger; private readonly IPluginService _pluginService; private readonly IProfileRepository _profileRepository; 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; _pluginService = pluginService; _surfaceService = surfaceService; - _layerService = layerService; + _renderElementService = renderElementService; _profileRepository = profileRepository; _surfaceService.ActiveSurfaceConfigurationSelected += OnActiveSurfaceConfigurationSelected; @@ -170,9 +170,9 @@ namespace Artemis.Core.Services.Storage foreach (var layer in profile.GetAllLayers()) { if (!layer.General.PropertiesInitialized) - layer.General.InitializeProperties(_layerService, layer, "General."); + layer.General.InitializeProperties(_renderElementService, layer, "General."); 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()) { // Instantiate effects - _layerService.InstantiateLayerEffects(folder); + _renderElementService.InstantiateLayerEffects(folder); // Remove effects of plugins that are disabled var disabledEffects = new List(folder.LayerEffects.Where(layerLayerEffect => !layerLayerEffect.PluginInfo.Enabled)); 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 if (layer.LayerBrush == null) - _layerService.InstantiateLayerBrush(layer); + _renderElementService.InstantiateLayerBrush(layer); // Remove brush if plugin is disabled else if (!layer.LayerBrush.PluginInfo.Enabled) - _layerService.DeactivateLayerBrush(layer); + _renderElementService.DeactivateLayerBrush(layer); // Instantiate effects - _layerService.InstantiateLayerEffects(layer); + _renderElementService.InstantiateLayerEffects(layer); // Remove effects of plugins that are disabled var disabledEffects = new List(layer.LayerEffects.Where(layerLayerEffect => !layerLayerEffect.PluginInfo.Enabled)); foreach (var layerLayerEffect in disabledEffects) - _layerService.RemoveLayerEffect(layerLayerEffect); + _renderElementService.RemoveLayerEffect(layerLayerEffect); + + _renderElementService.InstantiateDisplayConditions(layer); } } diff --git a/src/Artemis.Storage/Entities/Profile/Abstract/DisplayConditionPartEntity.cs b/src/Artemis.Storage/Entities/Profile/Abstract/DisplayConditionPartEntity.cs index c80d7fc09..f1397fd35 100644 --- a/src/Artemis.Storage/Entities/Profile/Abstract/DisplayConditionPartEntity.cs +++ b/src/Artemis.Storage/Entities/Profile/Abstract/DisplayConditionPartEntity.cs @@ -1,13 +1,9 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace Artemis.Storage.Entities.Profile.Abstract { public abstract class DisplayConditionPartEntity { - public Guid Id { get; set; } - public Guid ParentId { get; set; } - public List Children { get; set; } } } \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Profile/Abstract/EffectsEntity.cs b/src/Artemis.Storage/Entities/Profile/Abstract/EffectsEntity.cs deleted file mode 100644 index 2840a76e3..000000000 --- a/src/Artemis.Storage/Entities/Profile/Abstract/EffectsEntity.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace Artemis.Storage.Entities.Profile.Abstract -{ - public abstract class EffectsEntity : PropertiesEntity - { - public List LayerEffects { get; set; } - } -} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Profile/Abstract/PropertiesEntity.cs b/src/Artemis.Storage/Entities/Profile/Abstract/RenderElementEntity.cs similarity index 55% rename from src/Artemis.Storage/Entities/Profile/Abstract/PropertiesEntity.cs rename to src/Artemis.Storage/Entities/Profile/Abstract/RenderElementEntity.cs index 121307668..990b545ff 100644 --- a/src/Artemis.Storage/Entities/Profile/Abstract/PropertiesEntity.cs +++ b/src/Artemis.Storage/Entities/Profile/Abstract/RenderElementEntity.cs @@ -2,9 +2,12 @@ namespace Artemis.Storage.Entities.Profile.Abstract { - public abstract class PropertiesEntity + public abstract class RenderElementEntity { + public List LayerEffects { get; set; } public List PropertyEntities { get; set; } public List ExpandedPropertyGroups { get; set; } + + public DisplayConditionGroupEntity RootDisplayCondition { get; set; } } } \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Profile/DisplayConditionPredicateEntity.cs b/src/Artemis.Storage/Entities/Profile/DisplayConditionPredicateEntity.cs index 0ade47a6f..567a5b066 100644 --- a/src/Artemis.Storage/Entities/Profile/DisplayConditionPredicateEntity.cs +++ b/src/Artemis.Storage/Entities/Profile/DisplayConditionPredicateEntity.cs @@ -5,12 +5,15 @@ namespace Artemis.Storage.Entities.Profile { public class DisplayConditionPredicateEntity : DisplayConditionPartEntity { - public Guid LeftDataModelGuid { get; set; } + public Guid? LeftDataModelGuid { get; set; } public string LeftPropertyPath { get; set; } - public Guid RightDataModelGuid { get; set; } + public Guid? RightDataModelGuid { 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 public string RightStaticValue { get; set; } } diff --git a/src/Artemis.Storage/Entities/Profile/FolderEntity.cs b/src/Artemis.Storage/Entities/Profile/FolderEntity.cs index 3cfc24d3b..57614e6e9 100644 --- a/src/Artemis.Storage/Entities/Profile/FolderEntity.cs +++ b/src/Artemis.Storage/Entities/Profile/FolderEntity.cs @@ -5,7 +5,7 @@ using LiteDB; namespace Artemis.Storage.Entities.Profile { - public class FolderEntity : EffectsEntity + public class FolderEntity : RenderElementEntity { public FolderEntity() { diff --git a/src/Artemis.Storage/Entities/Profile/LayerEntity.cs b/src/Artemis.Storage/Entities/Profile/LayerEntity.cs index 04a640eb6..df72c7d27 100644 --- a/src/Artemis.Storage/Entities/Profile/LayerEntity.cs +++ b/src/Artemis.Storage/Entities/Profile/LayerEntity.cs @@ -5,7 +5,7 @@ using LiteDB; namespace Artemis.Storage.Entities.Profile { - public class LayerEntity : EffectsEntity + public class LayerEntity : RenderElementEntity { public LayerEntity() { diff --git a/src/Artemis.UI/PropertyInput/BrushPropertyInputViewModel.cs b/src/Artemis.UI/PropertyInput/BrushPropertyInputViewModel.cs index b6e2485bc..86008bd5b 100644 --- a/src/Artemis.UI/PropertyInput/BrushPropertyInputViewModel.cs +++ b/src/Artemis.UI/PropertyInput/BrushPropertyInputViewModel.cs @@ -13,14 +13,14 @@ namespace Artemis.UI.PropertyInput { public class BrushPropertyInputViewModel : PropertyInputViewModel { - private readonly ILayerService _layerService; + private readonly IRenderElementService _renderElementService; private readonly IPluginService _pluginService; private List _descriptors; public BrushPropertyInputViewModel(LayerProperty layerProperty, IProfileEditorService profileEditorService, - ILayerService layerService, IPluginService pluginService) : base(layerProperty, profileEditorService) + IRenderElementService renderElementService, IPluginService pluginService) : base(layerProperty, profileEditorService) { - _layerService = layerService; + _renderElementService = renderElementService; _pluginService = pluginService; _pluginService.PluginEnabled += PluginServiceOnPluginLoaded; @@ -59,8 +59,8 @@ namespace Artemis.UI.PropertyInput { if (LayerProperty.ProfileElement is Layer layer) { - _layerService.RemoveLayerBrush(layer); - _layerService.InstantiateLayerBrush(layer); + _renderElementService.RemoveLayerBrush(layer); + _renderElementService.InstantiateLayerBrush(layer); } } diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsViewModel.cs index 72cca788a..dfaf3a250 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/LayerEffects/EffectsViewModel.cs @@ -12,16 +12,16 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.LayerEffects { public class EffectsViewModel : PropertyChangedBase { - private readonly ILayerService _layerService; + private readonly IRenderElementService _renderElementService; private readonly IPluginService _pluginService; private readonly IProfileEditorService _profileEditorService; private BindableCollection _layerEffectDescriptors; 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; - _layerService = layerService; + _renderElementService = renderElementService; _profileEditorService = profileEditorService; LayerPropertiesViewModel = layerPropertiesViewModel; LayerEffectDescriptors = new BindableCollection(); @@ -70,7 +70,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.LayerEffects Execute.PostToUIThread(async () => { await Task.Delay(500); - _layerService.AddLayerEffect(renderElement, SelectedLayerEffectDescriptor); + _renderElementService.AddLayerEffect(renderElement, SelectedLayerEffectDescriptor); _profileEditorService.UpdateSelectedProfileElement(); }); } diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Tree/TreePropertyGroupViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Tree/TreePropertyGroupViewModel.cs index f48ef27d3..67981d27e 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Tree/TreePropertyGroupViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/LayerProperties/Tree/TreePropertyGroupViewModel.cs @@ -13,14 +13,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree { private readonly IDialogService _dialogService; private readonly IWindowManager _windowManager; - private readonly ILayerService _layerService; + private readonly IRenderElementService _renderElementService; private readonly IProfileEditorService _profileEditorService; public TreePropertyGroupViewModel(LayerPropertyBaseViewModel layerPropertyBaseViewModel, - IProfileEditorService profileEditorService, ILayerService layerService, IDialogService dialogService, IWindowManager windowManager) + IProfileEditorService profileEditorService, IRenderElementService renderElementService, IDialogService dialogService, IWindowManager windowManager) { _profileEditorService = profileEditorService; - _layerService = layerService; + _renderElementService = renderElementService; _dialogService = dialogService; _windowManager = windowManager; LayerPropertyGroupViewModel = (LayerPropertyGroupViewModel) layerPropertyBaseViewModel; @@ -78,7 +78,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Tree public void DeleteEffect() { - _layerService.RemoveLayerEffect(LayerPropertyGroupViewModel.LayerPropertyGroup.LayerEffect); + _renderElementService.RemoveLayerEffect(LayerPropertyGroupViewModel.LayerPropertyGroup.LayerEffect); _profileEditorService.UpdateSelectedProfile(); } diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/FolderViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/FolderViewModel.cs index 4dd168414..06f613eb8 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/FolderViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/FolderViewModel.cs @@ -23,10 +23,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem public FolderViewModel(ProfileElement folder, IProfileEditorService profileEditorService, IDialogService dialogService, - ILayerService layerService, + IRenderElementService renderElementService, IFolderVmFactory folderVmFactory, 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, IProfileEditorService profileEditorService, IDialogService dialogService, - ILayerService layerService, + IRenderElementService renderElementService, IFolderVmFactory folderVmFactory, ILayerVmFactory layerVmFactory) : - base(parent, folder, profileEditorService, dialogService, layerService, folderVmFactory, layerVmFactory) + base(parent, folder, profileEditorService, dialogService, renderElementService, folderVmFactory, layerVmFactory) { } diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/LayerViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/LayerViewModel.cs index 99a4b506c..31ea44012 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/LayerViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/LayerViewModel.cs @@ -11,10 +11,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem ProfileElement folder, IProfileEditorService profileEditorService, IDialogService dialogService, - ILayerService layerService, + IRenderElementService renderElementService, IFolderVmFactory folderVmFactory, ILayerVmFactory layerVmFactory) : - base(parent, folder, profileEditorService, dialogService, layerService, folderVmFactory, layerVmFactory) + base(parent, folder, profileEditorService, dialogService, renderElementService, folderVmFactory, layerVmFactory) { } diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/TreeItemViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/TreeItemViewModel.cs index d8c3718f5..f360b8c6f 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/TreeItemViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileTree/TreeItem/TreeItemViewModel.cs @@ -16,7 +16,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem { private readonly IDialogService _dialogService; private readonly IFolderVmFactory _folderVmFactory; - private readonly ILayerService _layerService; + private readonly IRenderElementService _renderElementService; private readonly ILayerVmFactory _layerVmFactory; private readonly IProfileEditorService _profileEditorService; private BindableCollection _children; @@ -27,13 +27,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem ProfileElement profileElement, IProfileEditorService profileEditorService, IDialogService dialogService, - ILayerService layerService, + IRenderElementService renderElementService, IFolderVmFactory folderVmFactory, ILayerVmFactory layerVmFactory) { _profileEditorService = profileEditorService; _dialogService = dialogService; - _layerService = layerService; + _renderElementService = renderElementService; _folderVmFactory = folderVmFactory; _layerVmFactory = layerVmFactory; @@ -145,7 +145,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem if (!SupportsChildren) 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(); _profileEditorService.UpdateSelectedProfile(); } diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/SelectionToolViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/SelectionToolViewModel.cs index 988fc9304..372fe0102 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/SelectionToolViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/SelectionToolViewModel.cs @@ -11,13 +11,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools { public class SelectionToolViewModel : VisualizationToolViewModel { - private readonly ILayerService _layerService; + private readonly IRenderElementService _renderElementService; private Rect _dragRectangle; - public SelectionToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerService layerService) + public SelectionToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, IRenderElementService renderElementService) : base(profileViewModel, profileEditorService) { - _layerService = layerService; + _renderElementService = renderElementService; using (var stream = new MemoryStream(Resources.aero_crosshair)) { 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 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); ProfileEditorService.ChangeSelectedProfileElement(newLayer); ProfileEditorService.UpdateSelectedProfileElement(); @@ -66,7 +66,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools else { 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); ProfileEditorService.ChangeSelectedProfileElement(newLayer); ProfileEditorService.UpdateSelectedProfileElement();