internal Folder(Profile profile, ProfileElement parent, FolderEntity folderEntity) { FolderEntity = folderEntity; EntityId = folderEntity.Id; Profile = profile; Parent = parent; Name = folderEntity.Name; Order = folderEntity.Order; // TODO: Load conditions // Load child folders foreach (var childFolder in Profile.ProfileEntity.Folders.Where(f => f.ParentId == EntityId)) { _children.Add(new Folder(profile, this, childFolder)); } // Load child layers foreach (var childLayer in Profile.ProfileEntity.Layers.Where(f => f.ParentId == EntityId)) { _children.Add(new Layer(profile, this, childLayer)); } // Ensure order integrity, should be unnecessary but no one is perfect specially me _children = _children.OrderBy(c => c.Order).ToList(); for (var index = 0; index < _children.Count; index++) { var profileElement = _children[index]; profileElement.Order = index + 1; } }
public Folder(Profile profile, ProfileElement parent, string name) { FolderEntity = new FolderEntity(); EntityId = Guid.NewGuid(); Profile = profile; Parent = parent; Name = name; }
public Layer(Profile profile, ProfileElement parent, string name) { LayerEntity = new LayerEntity(); EntityId = Guid.NewGuid(); Profile = profile; Parent = parent; Name = name; _leds = new List <ArtemisLed>(); _properties = new Dictionary <string, BaseLayerProperty>(); CreateDefaultProperties(); }
/// <summary> /// Removes a profile element from the <see cref="Children" /> collection /// </summary> /// <param name="child">The profile element to remove</param> public void RemoveChild(ProfileElement child) { lock (_children) { _children.Remove(child); // Shift everything after the given order foreach (var profileElement in _children.Where(c => c.Order > child.Order).ToList()) { profileElement.Order--; } child.Parent = null; } }
internal Layer(Profile profile, ProfileElement parent, LayerEntity layerEntity) { LayerEntity = layerEntity; EntityId = layerEntity.Id; Profile = profile; Parent = parent; Name = layerEntity.Name; Order = layerEntity.Order; _leds = new List <ArtemisLed>(); _properties = new Dictionary <string, BaseLayerProperty>(); CreateDefaultProperties(); switch (layerEntity.ShapeEntity?.Type) { case ShapeEntityType.Ellipse: LayerShape = new Ellipse(this, layerEntity.ShapeEntity); break; case ShapeEntityType.Fill: LayerShape = new Fill(this, layerEntity.ShapeEntity); break; case ShapeEntityType.Polygon: LayerShape = new Polygon(this, layerEntity.ShapeEntity); break; case ShapeEntityType.Rectangle: LayerShape = new Rectangle(this, layerEntity.ShapeEntity); break; case null: LayerShape = null; break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Adds a profile element to the <see cref="Children" /> collection, optionally at the given position (1-based) /// </summary> /// <param name="child">The profile element to add</param> /// <param name="order">The order where to place the child (1-based), defaults to the end of the collection</param> public void AddChild(ProfileElement child, int?order = null) { lock (_children) { // Add to the end of the list if (order == null) { _children.Add(child); child.Order = _children.Count; return; } // Shift everything after the given order foreach (var profileElement in _children.Where(c => c.Order >= order).ToList()) { profileElement.Order++; } int targetIndex; if (order == 0) { targetIndex = 0; } else if (order > _children.Count) { targetIndex = _children.Count; } else { targetIndex = _children.FindIndex(c => c.Order == order + 1); } _children.Insert(targetIndex, child); child.Order = order.Value; child.Parent = this; } }