/// <summary> /// Creates a new <see cref="DeviceLayout"/> from the given xml. /// </summary> /// <param name="path">The path to the xml file.</param> /// <returns>The deserialized <see cref="DeviceLayout"/>.</returns> 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); } }
/// <summary> /// Calculates the position- and size-data from the respective descriptive values. /// </summary> /// <param name="device">The <see cref="DeviceLayout"/> this <see cref="LedLayout"/> belongs to.</param> /// <param name="lastLed">The <see cref="LedLayout"/> previously calculated.</param> public void CalculateValues(DeviceLayout device, LedLayout lastLed) { if (!Enum.TryParse(DescriptiveShape, true, out Shape shape)) { shape = Shape.Custom; ShapeData = DescriptiveShape; } Shape = shape; Width = GetSizeValue(DescriptiveWidth, device.LedUnitWidth); Height = GetSizeValue(DescriptiveHeight, device.LedUnitHeight); X = GetLocationValue(DescriptiveX, lastLed?.X ?? 0, Width, lastLed?.Width ?? 0); Y = GetLocationValue(DescriptiveY, lastLed?.Y ?? 0, Height, lastLed?.Height ?? 0); }