using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Xml.Serialization; namespace RGB.NET.Core.Layout { /// /// Represents the serializable layout of a . /// [Serializable] [XmlRoot("Device")] public class DeviceLayout { #region Properties & Fields /// /// Gets or sets the name of the . /// [XmlElement("Name")] public string Name { get; set; } /// /// Gets or sets the description of the . /// [XmlElement("Description")] public string Description { get; set; } /// /// Gets or sets the of the . /// [XmlElement("Type")] public RGBDeviceType Type { get; set; } /// /// Gets or sets the of the . /// [XmlElement("Lighting")] public RGBDeviceLighting Lighting { get; set; } /// /// Gets or sets the vendor of the . /// [XmlElement("Vendor")] public string Vendor { get; set; } /// /// Gets or sets the model of the . /// [XmlElement("Model")] public string Model { get; set; } /// /// Gets or sets the of the . /// [XmlElement("Shape")] [DefaultValue(Shape.Rectangle)] public Shape Shape { get; set; } = Shape.Rectangle; /// /// Gets or sets the width of the . /// [XmlElement("Width")] public double Width { get; set; } /// /// Gets or sets the height of the . /// [XmlElement("Height")] public double Height { get; set; } /// /// Gets or sets the width of one 'unit' used for the calculation of led positions and sizes. /// [XmlElement("LedUnitWidth")] [DefaultValue(19.0)] public double LedUnitWidth { get; set; } = 19.0; /// /// Gets or sets the height of one 'unit' used for the calculation of led positions and sizes. /// [XmlElement("LedUnitHeight")] [DefaultValue(19.0)] public double LedUnitHeight { get; set; } = 19.0; /// /// The path images for this device are collected in. /// [XmlElement("ImageBasePath")] public string ImageBasePath { get; set; } /// /// The image file for this device. /// [XmlElement("DeviceImage")] public string DeviceImage { get; set; } /// /// Gets or sets a list of representing all the of the . /// [XmlArray("Leds")] public List Leds { get; set; } = new List(); /// /// Gets or sets a list of representing the layouts for the images of all the of the . /// [XmlArray("LedImageLayouts")] public List LedImageLayouts { get; set; } = new List(); #endregion #region Methods /// /// Creates a new from the given xml. /// /// The path to the xml file. /// The deserialized . public static DeviceLayout Load(string path) { if (!File.Exists(path)) return null; try { XmlSerializer serializer = new XmlSerializer(typeof(DeviceLayout)); using (StreamReader reader = new StreamReader(path)) { DeviceLayout layout = serializer.Deserialize(reader) as DeviceLayout; if (layout?.Leds != null) { LedLayout lastLed = null; foreach (LedLayout led in layout.Leds) { led.CalculateValues(layout, lastLed); lastLed = led; } } return layout; } } catch { return null; } } #endregion } }