diff options
author | Tiago Conceição <Tiago_caza@hotmail.com> | 2021-05-13 05:24:36 +0300 |
---|---|---|
committer | Tiago Conceição <Tiago_caza@hotmail.com> | 2021-05-13 05:24:36 +0300 |
commit | edd9984a31a90791edf3bcf594855d08507428b5 (patch) | |
tree | be296b13d7587d6d14811ddc2bff1821fa59e324 | |
parent | 3cd46728f1ca599d1f2211d9ff07273135d670af (diff) |
v2.11.2v2.11.2
- (Improvement) Applied some refactorings on code
- (Fix) MDLP, GR1 and CXDLP: Bad enconde of display width, display height and layer height properties
27 files changed, 180 insertions, 136 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 44e3e6b..e4b7b1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 13/05/2021 - v2.11.2 + +- (Improvement) Applied some refactorings on code +- (Fix) MDLP, GR1 and CXDLP: Bad enconde of display width, display height and layer height properties + ## 11/05/2021 - v2.11.1 - **Shortcuts:** diff --git a/UVtools.Core/Enumerations.cs b/UVtools.Core/Enumerations.cs index 13f3f7a..468b389 100644 --- a/UVtools.Core/Enumerations.cs +++ b/UVtools.Core/Enumerations.cs @@ -1,7 +1,11 @@ -using System; -using System.Collections.Generic; +/* + * GNU AFFERO GENERAL PUBLIC LICENSE + * Version 3, 19 November 2007 + * Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + */ using System.ComponentModel; -using System.Text; namespace UVtools.Core { diff --git a/UVtools.Core/FileFormats/CXDLPFile.cs b/UVtools.Core/FileFormats/CXDLPFile.cs index bd44c26..0c4129e 100644 --- a/UVtools.Core/FileFormats/CXDLPFile.cs +++ b/UVtools.Core/FileFormats/CXDLPFile.cs @@ -97,7 +97,7 @@ namespace UVtools.Core.FileFormats [FieldOrder(1)] [FieldLength(nameof(DisplayWidthDataSize))] - public byte[] DisplayWidth { get; set; } + public byte[] DisplayWidthBytes { get; set; } [FieldOrder(2)] [FieldEndianness(Endianness.Big)] @@ -105,7 +105,7 @@ namespace UVtools.Core.FileFormats [FieldOrder(3)] [FieldLength(nameof(DisplayHeightDataSize))] - public byte[] DisplayHeight { get; set; } + public byte[] DisplayHeightBytes { get; set; } [FieldOrder(4)] [FieldEndianness(Endianness.Big)] @@ -113,7 +113,7 @@ namespace UVtools.Core.FileFormats [FieldOrder(5)] [FieldLength(nameof(LayerHeightDataSize))] - public byte[] LayerHeight { get; set; } + public byte[] LayerHeightBytes { get; set; } [FieldOrder(6)] [FieldEndianness(Endianness.Big)] @@ -328,7 +328,7 @@ namespace UVtools.Core.FileFormats public override float DisplayWidth { - get => float.Parse(SlicerInfoSettings.DisplayWidth.Where(b => b != 0).Aggregate(string.Empty, (current, b) => current + System.Convert.ToChar(b))); + get => float.Parse(Encoding.ASCII.GetString(SlicerInfoSettings.DisplayWidthBytes.Where(b => b != 0).ToArray())); set { string str = Math.Round(value, 2).ToString(CultureInfo.InvariantCulture); @@ -336,17 +336,17 @@ namespace UVtools.Core.FileFormats var data = new byte[SlicerInfoSettings.DisplayWidthDataSize]; for (var i = 0; i < str.Length; i++) { - data[i * 2] = System.Convert.ToByte(str[i]); + data[i * 2 + 1] = System.Convert.ToByte(str[i]); } - SlicerInfoSettings.DisplayWidth = data; + SlicerInfoSettings.DisplayWidthBytes = data; RaisePropertyChanged(); } } public override float DisplayHeight { - get => float.Parse(SlicerInfoSettings.DisplayHeight.Where(b => b != 0).Aggregate(string.Empty, (current, b) => current + System.Convert.ToChar(b))); + get => float.Parse(Encoding.ASCII.GetString(SlicerInfoSettings.DisplayHeightBytes.Where(b => b != 0).ToArray())); set { string str = Math.Round(value, 2).ToString(CultureInfo.InvariantCulture); @@ -354,10 +354,10 @@ namespace UVtools.Core.FileFormats var data = new byte[SlicerInfoSettings.DisplayHeightDataSize]; for (var i = 0; i < str.Length; i++) { - data[i * 2] = System.Convert.ToByte(str[i]); + data[i * 2 + 1] = System.Convert.ToByte(str[i]); } - SlicerInfoSettings.DisplayHeight = data; + SlicerInfoSettings.DisplayHeightBytes = data; RaisePropertyChanged(); } } @@ -370,7 +370,7 @@ namespace UVtools.Core.FileFormats public override float LayerHeight { - get => float.Parse(SlicerInfoSettings.LayerHeight.Where(b => b != 0).Aggregate(string.Empty, (current, b) => current + System.Convert.ToChar(b))); + get => float.Parse(Encoding.ASCII.GetString(SlicerInfoSettings.LayerHeightBytes.Where(b => b != 0).ToArray())); set { string str = Layer.RoundHeight(value).ToString(CultureInfo.InvariantCulture); @@ -378,10 +378,10 @@ namespace UVtools.Core.FileFormats var data = new byte[SlicerInfoSettings.LayerHeightDataSize]; for (var i = 0; i < str.Length; i++) { - data[i * 2] = System.Convert.ToByte(str[i]); + data[i * 2 + 1] = System.Convert.ToByte(str[i]); } - SlicerInfoSettings.LayerHeight = data; + SlicerInfoSettings.LayerHeightBytes = data; RaisePropertyChanged(); } } diff --git a/UVtools.Core/FileFormats/FileFormat.cs b/UVtools.Core/FileFormats/FileFormat.cs index 8b4e801..0f0ade7 100644 --- a/UVtools.Core/FileFormats/FileFormat.cs +++ b/UVtools.Core/FileFormats/FileFormat.cs @@ -1271,7 +1271,7 @@ namespace UVtools.Core.FileFormats public bool Equals(FileFormat other) { - if (ReferenceEquals(null, other)) return false; + if (other is null) return false; if (ReferenceEquals(this, other)) return true; return FileFullPath == other.FileFullPath; } @@ -1283,6 +1283,7 @@ namespace UVtools.Core.FileFormats public void Dispose() { + GC.SuppressFinalize(this); Clear(); } @@ -1614,40 +1615,38 @@ namespace UVtools.Core.FileFormats { if (LayerCount > 0) { - using (TextWriter tw = new StreamWriter(Path.Combine(path, "Layers.ini"))) + using TextWriter tw = new StreamWriter(Path.Combine(path, "Layers.ini")); + for (int layerIndex = 0; layerIndex < LayerCount; layerIndex++) { - for (int layerIndex = 0; layerIndex < LayerCount; layerIndex++) + var layer = this[layerIndex]; + tw.WriteLine($"[{layerIndex}]"); + tw.WriteLine($"{nameof(layer.NonZeroPixelCount)}: {layer.NonZeroPixelCount}"); + tw.WriteLine($"{nameof(layer.BoundingRectangle)}: {layer.BoundingRectangle}"); + tw.WriteLine($"{nameof(layer.IsBottomLayer)}: {layer.IsBottomLayer}"); + tw.WriteLine($"{nameof(layer.LayerHeight)}: {layer.LayerHeight}"); + tw.WriteLine($"{nameof(layer.PositionZ)}: {layer.PositionZ}"); + tw.WriteLine($"{nameof(layer.ExposureTime)}: {layer.ExposureTime}"); + + if (HavePrintParameterPerLayerModifier(PrintParameterModifier.LightOffDelay)) + tw.WriteLine($"{nameof(layer.LightOffDelay)}: {layer.LightOffDelay}"); + if (HavePrintParameterPerLayerModifier(PrintParameterModifier.LiftHeight)) + tw.WriteLine($"{nameof(layer.LiftHeight)}: {layer.LiftHeight}"); + if (HavePrintParameterPerLayerModifier(PrintParameterModifier.LiftSpeed)) + tw.WriteLine($"{nameof(layer.LiftSpeed)}: {layer.LiftSpeed}"); + if (HavePrintParameterPerLayerModifier(PrintParameterModifier.RetractSpeed)) + tw.WriteLine($"{nameof(layer.RetractSpeed)}: {layer.RetractSpeed}"); + if (HavePrintParameterPerLayerModifier(PrintParameterModifier.LightPWM)) + tw.WriteLine($"{nameof(layer.LightPWM)}: {layer.LightPWM}"); + + var materialMillilitersPercent = layer.MaterialMillilitersPercent; + if (!float.IsNaN(materialMillilitersPercent)) { - var layer = this[layerIndex]; - tw.WriteLine($"[{layerIndex}]"); - tw.WriteLine($"{nameof(layer.NonZeroPixelCount)}: {layer.NonZeroPixelCount}"); - tw.WriteLine($"{nameof(layer.BoundingRectangle)}: {layer.BoundingRectangle}"); - tw.WriteLine($"{nameof(layer.IsBottomLayer)}: {layer.IsBottomLayer}"); - tw.WriteLine($"{nameof(layer.LayerHeight)}: {layer.LayerHeight}"); - tw.WriteLine($"{nameof(layer.PositionZ)}: {layer.PositionZ}"); - tw.WriteLine($"{nameof(layer.ExposureTime)}: {layer.ExposureTime}"); - - if (HavePrintParameterPerLayerModifier(PrintParameterModifier.LightOffDelay)) - tw.WriteLine($"{nameof(layer.LightOffDelay)}: {layer.LightOffDelay}"); - if (HavePrintParameterPerLayerModifier(PrintParameterModifier.LiftHeight)) - tw.WriteLine($"{nameof(layer.LiftHeight)}: {layer.LiftHeight}"); - if (HavePrintParameterPerLayerModifier(PrintParameterModifier.LiftSpeed)) - tw.WriteLine($"{nameof(layer.LiftSpeed)}: {layer.LiftSpeed}"); - if (HavePrintParameterPerLayerModifier(PrintParameterModifier.RetractSpeed)) - tw.WriteLine($"{nameof(layer.RetractSpeed)}: {layer.RetractSpeed}"); - if (HavePrintParameterPerLayerModifier(PrintParameterModifier.LightPWM)) - tw.WriteLine($"{nameof(layer.LightPWM)}: {layer.LightPWM}"); - - var materialMillilitersPercent = layer.MaterialMillilitersPercent; - if (!float.IsNaN(materialMillilitersPercent)) - { - tw.WriteLine($"{nameof(layer.MaterialMilliliters)}: {layer.MaterialMilliliters}ml ({materialMillilitersPercent:F2}%)"); - } - - tw.WriteLine(); + tw.WriteLine($"{nameof(layer.MaterialMilliliters)}: {layer.MaterialMilliliters}ml ({materialMillilitersPercent:F2}%)"); } - tw.Close(); + + tw.WriteLine(); } + tw.Close(); } } diff --git a/UVtools.Core/FileFormats/GR1File.cs b/UVtools.Core/FileFormats/GR1File.cs index 74b4019..4374b38 100644 --- a/UVtools.Core/FileFormats/GR1File.cs +++ b/UVtools.Core/FileFormats/GR1File.cs @@ -15,6 +15,7 @@ using System.Drawing; using System.Globalization; using System.IO; using System.Linq; +using System.Text; using System.Threading.Tasks; using BinarySerialization; using Emgu.CV; @@ -65,12 +66,12 @@ namespace UVtools.Core.FileFormats [FieldOrder(1)] [FieldEndianness(Endianness.Big)] public ushort ResolutionX { get; set; } [FieldOrder(2)] [FieldEndianness(Endianness.Big)] public ushort ResolutionY { get; set; } [FieldOrder(3)] [FieldEndianness(Endianness.Big)] public uint DisplayWidthDataSize { get; set; } = 6; - [FieldOrder(4)] [FieldLength(nameof(DisplayWidthDataSize))] public byte[] DisplayWidth { get; set; } + [FieldOrder(4)] [FieldLength(nameof(DisplayWidthDataSize))] public byte[] DisplayWidthBytes { get; set; } [FieldOrder(5)] [FieldEndianness(Endianness.Big)] public uint DisplayHeightDataSize { get; set; } = 6; - [FieldOrder(6)] [FieldLength(nameof(DisplayHeightDataSize))] public byte[] DisplayHeight { get; set; } + [FieldOrder(6)] [FieldLength(nameof(DisplayHeightDataSize))] public byte[] DisplayHeightBytes { get; set; } [FieldOrder(7)] [FieldEndianness(Endianness.Big)] public uint LayerHeightDataSize { get; set; } = 6; - [FieldOrder(8)] [FieldLength(nameof(LayerHeightDataSize))] public byte[] LayerHeight { get; set; } + [FieldOrder(8)] [FieldLength(nameof(LayerHeightDataSize))] public byte[] LayerHeightBytes { get; set; } [FieldOrder(9)] [FieldEndianness(Endianness.Big)] public ushort ExposureTime { get; set; } [FieldOrder(10)] [FieldEndianness(Endianness.Big)] public ushort LightOffDelay { get; set; } [FieldOrder(11)] [FieldEndianness(Endianness.Big)] public ushort BottomExposureTime { get; set; } @@ -185,7 +186,7 @@ namespace UVtools.Core.FileFormats public override float DisplayWidth { - get => float.Parse(SlicerInfoSettings.DisplayWidth.Where(b => b != 0).Aggregate(string.Empty, (current, b) => current + System.Convert.ToChar(b))); + get => float.Parse(Encoding.ASCII.GetString(SlicerInfoSettings.DisplayWidthBytes.Where(b => b != 0).ToArray())); set { string str = Math.Round(value, 2).ToString(CultureInfo.InvariantCulture); @@ -193,17 +194,17 @@ namespace UVtools.Core.FileFormats var data = new byte[SlicerInfoSettings.DisplayWidthDataSize]; for (var i = 0; i < str.Length; i++) { - data[i * 2] = System.Convert.ToByte(str[i]); + data[i * 2 + 1] = System.Convert.ToByte(str[i]); } - SlicerInfoSettings.DisplayWidth = data; + SlicerInfoSettings.DisplayWidthBytes = data; RaisePropertyChanged(); } } public override float DisplayHeight { - get => float.Parse(SlicerInfoSettings.DisplayHeight.Where(b => b != 0).Aggregate(string.Empty, (current, b) => current + System.Convert.ToChar(b))); + get => float.Parse(Encoding.ASCII.GetString(SlicerInfoSettings.DisplayHeightBytes.Where(b => b != 0).ToArray())); set { string str = Math.Round(value, 2).ToString(CultureInfo.InvariantCulture); @@ -211,10 +212,10 @@ namespace UVtools.Core.FileFormats var data = new byte[SlicerInfoSettings.DisplayHeightDataSize]; for (var i = 0; i < str.Length; i++) { - data[i * 2] = System.Convert.ToByte(str[i]); + data[i * 2 + 1] = System.Convert.ToByte(str[i]); } - SlicerInfoSettings.DisplayHeight = data; + SlicerInfoSettings.DisplayHeightBytes = data; RaisePropertyChanged(); } } @@ -229,7 +230,7 @@ namespace UVtools.Core.FileFormats public override float LayerHeight { - get => float.Parse(SlicerInfoSettings.LayerHeight.Where(b => b != 0).Aggregate(string.Empty, (current, b) => current + System.Convert.ToChar(b))); + get => float.Parse(Encoding.ASCII.GetString(SlicerInfoSettings.LayerHeightBytes.Where(b => b != 0).ToArray())); set { string str = Layer.RoundHeight(value).ToString(CultureInfo.InvariantCulture); @@ -237,10 +238,10 @@ namespace UVtools.Core.FileFormats var data = new byte[SlicerInfoSettings.LayerHeightDataSize]; for (var i = 0; i < str.Length; i++) { - data[i * 2] = System.Convert.ToByte(str[i]); + data[i * 2 + 1] = System.Convert.ToByte(str[i]); } - SlicerInfoSettings.LayerHeight = data; + SlicerInfoSettings.LayerHeightBytes = data; RaisePropertyChanged(); } } diff --git a/UVtools.Core/FileFormats/MDLPFile.cs b/UVtools.Core/FileFormats/MDLPFile.cs index 475150f..7530199 100644 --- a/UVtools.Core/FileFormats/MDLPFile.cs +++ b/UVtools.Core/FileFormats/MDLPFile.cs @@ -15,6 +15,7 @@ using System.Drawing; using System.Globalization; using System.IO; using System.Linq; +using System.Text; using System.Threading.Tasks; using BinarySerialization; using Emgu.CV; @@ -70,12 +71,12 @@ namespace UVtools.Core.FileFormats [FieldOrder(1)] [FieldEndianness(Endianness.Big)] public ushort ResolutionX { get; set; } [FieldOrder(2)] [FieldEndianness(Endianness.Big)] public ushort ResolutionY { get; set; } [FieldOrder(3)] [FieldEndianness(Endianness.Big)] public uint DisplayWidthDataSize { get; set; } = 6; - [FieldOrder(4)] [FieldLength(nameof(DisplayWidthDataSize))] public byte[] DisplayWidth { get; set; } + [FieldOrder(4)] [FieldLength(nameof(DisplayWidthDataSize))] public byte[] DisplayWidthBytes { get; set; } [FieldOrder(5)] [FieldEndianness(Endianness.Big)] public uint DisplayHeightDataSize { get; set; } = 6; - [FieldOrder(6)] [FieldLength(nameof(DisplayHeightDataSize))] public byte[] DisplayHeight { get; set; } + [FieldOrder(6)] [FieldLength(nameof(DisplayHeightDataSize))] public byte[] DisplayHeightBytes { get; set; } [FieldOrder(7)] [FieldEndianness(Endianness.Big)] public uint LayerHeightDataSize { get; set; } = 6; - [FieldOrder(8)] [FieldLength(nameof(LayerHeightDataSize))] public byte[] LayerHeight { get; set; } + [FieldOrder(8)] [FieldLength(nameof(LayerHeightDataSize))] public byte[] LayerHeightBytes { get; set; } [FieldOrder(9)] [FieldEndianness(Endianness.Big)] public ushort ExposureTime { get; set; } [FieldOrder(10)] [FieldEndianness(Endianness.Big)] public ushort LightOffDelay { get; set; } [FieldOrder(11)] [FieldEndianness(Endianness.Big)] public ushort BottomExposureTime { get; set; } @@ -189,7 +190,7 @@ namespace UVtools.Core.FileFormats public override float DisplayWidth { - get => float.Parse(SlicerInfoSettings.DisplayWidth.Where(b => b != 0).Aggregate(string.Empty, (current, b) => current + System.Convert.ToChar(b))); + get => float.Parse(Encoding.ASCII.GetString(SlicerInfoSettings.DisplayWidthBytes.Where(b => b != 0).ToArray())); set { string str = Math.Round(value, 2).ToString(CultureInfo.InvariantCulture); @@ -197,17 +198,17 @@ namespace UVtools.Core.FileFormats var data = new byte[SlicerInfoSettings.DisplayWidthDataSize]; for (var i = 0; i < str.Length; i++) { - data[i * 2] = System.Convert.ToByte(str[i]); + data[i * 2 + 1] = System.Convert.ToByte(str[i]); } - SlicerInfoSettings.DisplayWidth = data; + SlicerInfoSettings.DisplayWidthBytes = data; RaisePropertyChanged(); } } public override float DisplayHeight { - get => float.Parse(SlicerInfoSettings.DisplayHeight.Where(b => b != 0).Aggregate(string.Empty, (current, b) => current + System.Convert.ToChar(b))); + get => float.Parse(Encoding.ASCII.GetString(SlicerInfoSettings.DisplayHeightBytes.Where(b => b != 0).ToArray())); set { string str = Math.Round(value, 2).ToString(CultureInfo.InvariantCulture); @@ -215,10 +216,10 @@ namespace UVtools.Core.FileFormats var data = new byte[SlicerInfoSettings.DisplayHeightDataSize]; for (var i = 0; i < str.Length; i++) { - data[i * 2] = System.Convert.ToByte(str[i]); + data[i * 2 + 1] = System.Convert.ToByte(str[i]); } - SlicerInfoSettings.DisplayHeight = data; + SlicerInfoSettings.DisplayHeightBytes = data; RaisePropertyChanged(); } } @@ -233,7 +234,7 @@ namespace UVtools.Core.FileFormats public override float LayerHeight { - get => float.Parse(SlicerInfoSettings.LayerHeight.Where(b => b != 0).Aggregate(string.Empty, (current, b) => current + System.Convert.ToChar(b))); + get => float.Parse(Encoding.ASCII.GetString(SlicerInfoSettings.LayerHeightBytes.Where(b => b != 0).ToArray())); set { string str = Layer.RoundHeight(value).ToString(CultureInfo.InvariantCulture); @@ -241,10 +242,10 @@ namespace UVtools.Core.FileFormats var data = new byte[SlicerInfoSettings.LayerHeightDataSize]; for (var i = 0; i < str.Length; i++) { - data[i * 2] = System.Convert.ToByte(str[i]); + data[i * 2 + 1] = System.Convert.ToByte(str[i]); } - SlicerInfoSettings.LayerHeight = data; + SlicerInfoSettings.LayerHeightBytes = data; RaisePropertyChanged(); } } diff --git a/UVtools.Core/Objects/RangeObservableCollection.cs b/UVtools.Core/Objects/RangeObservableCollection.cs index 2c52e67..9e529d8 100644 --- a/UVtools.Core/Objects/RangeObservableCollection.cs +++ b/UVtools.Core/Objects/RangeObservableCollection.cs @@ -696,8 +696,8 @@ /// </remarks> internal static class EventArgsCache { - internal static readonly PropertyChangedEventArgs CountPropertyChanged = new PropertyChangedEventArgs("Count"); - internal static readonly PropertyChangedEventArgs IndexerPropertyChanged = new PropertyChangedEventArgs("Item[]"); - internal static readonly NotifyCollectionChangedEventArgs ResetCollectionChanged = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset); + internal static readonly PropertyChangedEventArgs CountPropertyChanged = new("Count"); + internal static readonly PropertyChangedEventArgs IndexerPropertyChanged = new("Item[]"); + internal static readonly NotifyCollectionChangedEventArgs ResetCollectionChanged = new(NotifyCollectionChangedAction.Reset); } }
\ No newline at end of file diff --git a/UVtools.Core/Operations/Operation.cs b/UVtools.Core/Operations/Operation.cs index 166446d..b7f7955 100644 --- a/UVtools.Core/Operations/Operation.cs +++ b/UVtools.Core/Operations/Operation.cs @@ -354,7 +354,7 @@ namespace UVtools.Core.Operations SelectLastLayer(); break; default: - throw new ArgumentOutOfRangeException(); + throw new NotImplementedException(); } } @@ -507,7 +507,7 @@ namespace UVtools.Core.Operations return result; } - public virtual void Dispose() { } + public virtual void Dispose() { GC.SuppressFinalize(this); } #endregion #region Static Methods diff --git a/UVtools.Core/Operations/OperationCalibrateExposureFinder.cs b/UVtools.Core/Operations/OperationCalibrateExposureFinder.cs index 8f79702..9109e29 100644 --- a/UVtools.Core/Operations/OperationCalibrateExposureFinder.cs +++ b/UVtools.Core/Operations/OperationCalibrateExposureFinder.cs @@ -787,9 +787,8 @@ namespace UVtools.Core.Operations { get { - List<decimal> layerHeights = new List<decimal>(); + List<decimal> layerHeights = new(); var endLayerHeight = _multipleLayerHeight ? _multipleLayerHeightMaximum : _layerHeight; - List<ExposureItem> list = new(); for (decimal layerHeight = _layerHeight; layerHeight <= endLayerHeight; layerHeight += _multipleLayerHeightStep) { layerHeights.Add(Layer.RoundHeight(layerHeight)); diff --git a/UVtools.Core/Operations/OperationMask.cs b/UVtools.Core/Operations/OperationMask.cs index f3571fb..c310ae5 100644 --- a/UVtools.Core/Operations/OperationMask.cs +++ b/UVtools.Core/Operations/OperationMask.cs @@ -41,7 +41,7 @@ namespace UVtools.Core.Operations public override string ValidateInternally() { var sb = new StringBuilder(); - if (Mask is null) + if (!HaveInputMask) { sb.AppendLine("The mask can not be empty."); } @@ -54,7 +54,7 @@ namespace UVtools.Core.Operations [XmlIgnore] public Mat Mask { get; set; } - public bool HaveMask => !(Mask is null); + public bool HaveInputMask => Mask is not null; #endregion #region Constructor @@ -69,7 +69,7 @@ namespace UVtools.Core.Operations public void InvertMask() { - if (!HaveMask) return; + if (!HaveInputMask) return; CvInvoke.BitwiseNot(Mask, Mask); } diff --git a/UVtools.Core/UVtools.Core.csproj b/UVtools.Core/UVtools.Core.csproj index b0630af..d3eac6a 100644 --- a/UVtools.Core/UVtools.Core.csproj +++ b/UVtools.Core/UVtools.Core.csproj @@ -10,7 +10,7 @@ <RepositoryUrl>https://github.com/sn4k3/UVtools</RepositoryUrl> <PackageProjectUrl>https://github.com/sn4k3/UVtools</PackageProjectUrl> <Description>MSLA/DLP, file analysis, calibration, repair, conversion and manipulation</Description> - <Version>2.11.1</Version> + <Version>2.11.2</Version> <Copyright>Copyright © 2020 PTRTECH</Copyright> <PackageIcon>UVtools.png</PackageIcon> <Platforms>AnyCPU;x64</Platforms> diff --git a/UVtools.WPF/App.axaml.cs b/UVtools.WPF/App.axaml.cs index f6854f0..20c37ca 100644 --- a/UVtools.WPF/App.axaml.cs +++ b/UVtools.WPF/App.axaml.cs @@ -33,7 +33,7 @@ namespace UVtools.WPF public static MainWindow MainWindow; public static FileFormat SlicerFile = null; - public static AppVersionChecker VersionChecker { get; } = new AppVersionChecker(); + public static AppVersionChecker VersionChecker { get; } = new(); public override void Initialize() { @@ -95,8 +95,8 @@ namespace UVtools.WPF #region Utilities - public static string AppExecutable = Path.Combine(ApplicationPath, About.Software); - public static string AppExecutableQuoted = $"\"{AppExecutable}\""; + public static readonly string AppExecutable = Path.Combine(ApplicationPath, About.Software); + public static readonly string AppExecutableQuoted = $"\"{AppExecutable}\""; public static void NewInstance(string filePath) { try @@ -182,7 +182,7 @@ namespace UVtools.WPF return res; } - public static Bitmap GetBitmapFromAsset(string url) => new Bitmap(GetAsset(url)); + public static Bitmap GetBitmapFromAsset(string url) => new(GetAsset(url)); public static string ApplicationPath => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); diff --git a/UVtools.WPF/Controls/AdvancedImageBox.axaml b/UVtools.WPF/Controls/AdvancedImageBox.axaml index 3b2d361..2c288f6 100644 --- a/UVtools.WPF/Controls/AdvancedImageBox.axaml +++ b/UVtools.WPF/Controls/AdvancedImageBox.axaml @@ -6,8 +6,7 @@ x:Class="UVtools.WPF.Controls.AdvancedImageBox"> <Grid RowDefinitions="*,Auto" - ColumnDefinitions="*,Auto" - > + ColumnDefinitions="*,Auto"> <ContentControl Name="ViewPort" @@ -16,7 +15,7 @@ <ScrollBar Name="VerticalScrollBar" - Grid.Column="1" + Grid.Row="0" Grid.Column="1" Orientation="Vertical" ViewportSize="{Binding #ViewPort.Bounds.Height}" Minimum="0" @@ -26,7 +25,7 @@ <ScrollBar Name="HorizontalScrollBar" - Grid.Row="1" + Grid.Row="1" Grid.Column="0" Orientation="Horizontal" ViewportSize="{Binding #ViewPort.Bounds.Width}" Minimum="0" diff --git a/UVtools.WPF/Controls/AdvancedImageBox.axaml.cs b/UVtools.WPF/Controls/AdvancedImageBox.axaml.cs index 7776ce0..02e8f87 100644 --- a/UVtools.WPF/Controls/AdvancedImageBox.axaml.cs +++ b/UVtools.WPF/Controls/AdvancedImageBox.axaml.cs @@ -30,7 +30,7 @@ namespace UVtools.WPF.Controls public Vector Offset { - get => new Vector(HorizontalScrollBar.Value, VerticalScrollBar.Value); + get => new(HorizontalScrollBar.Value, VerticalScrollBar.Value); set { HorizontalScrollBar.Value = value.X; @@ -49,7 +49,7 @@ namespace UVtools.WPF.Controls private PropertyChangedEventHandler _propertyChanged; private readonly List<string> events = new (); - public event PropertyChangedEventHandler PropertyChanged + public new event PropertyChangedEventHandler PropertyChanged { add { _propertyChanged += value; events.Add("added"); } remove { _propertyChanged -= value; events.Add("removed"); } @@ -1259,7 +1259,7 @@ namespace UVtools.WPF.Controls /// Resets the zoom to 100%. /// </summary> /// <param name="source">The source that initiated the action.</param> - private void PerformActualSize() + public void PerformActualSize() { SizeMode = SizeModes.Normal; //SetZoom(100, ImageZoomActions.ActualSize | (Zoom < 100 ? ImageZoomActions.ZoomIn : ImageZoomActions.ZoomOut)); @@ -1512,7 +1512,7 @@ namespace UVtools.WPF.Controls var offsetX = Offset.X % pixelSize; var offsetY = Offset.Y % pixelSize; - Pen pen = new Pen(PixelGridColor); + Pen pen = new(PixelGridColor); for (double x = viewport.X + pixelSize - offsetX; x < viewport.Right; x += pixelSize) { context.DrawLine(pen, new Avalonia.Point(x, viewport.X), new Avalonia.Point(x, viewport.Bottom)); diff --git a/UVtools.WPF/Controls/KernelControl.axaml.cs b/UVtools.WPF/Controls/KernelControl.axaml.cs index 3c8926b..1e4535a 100644 --- a/UVtools.WPF/Controls/KernelControl.axaml.cs +++ b/UVtools.WPF/Controls/KernelControl.axaml.cs @@ -46,7 +46,7 @@ namespace UVtools.WPF.Controls set => RaiseAndSetIfChanged(ref _matrixHeight, value); } - public Size MatrixSize => new Size((int)_matrixWidth, (int)_matrixHeight); + public Size MatrixSize => new((int)_matrixWidth, (int)_matrixHeight); public int AnchorX { @@ -61,7 +61,7 @@ namespace UVtools.WPF.Controls } - public Point Anchor => new Point(_anchorX, _anchorY); + public Point Anchor => new(_anchorX, _anchorY); public KernelControl() @@ -90,28 +90,26 @@ namespace UVtools.WPF.Controls return; } - using (var kernel = CvInvoke.GetStructuringElement(SelectedKernelShape, MatrixSize, Anchor)) + using var kernel = CvInvoke.GetStructuringElement(SelectedKernelShape, MatrixSize, Anchor); + string text = string.Empty; + for (int y = 0; y < kernel.Height; y++) { - string text = string.Empty; - for (int y = 0; y < kernel.Height; y++) + var span = kernel.GetPixelRowSpan<byte>(y); + var line = string.Empty; + for (int x = 0; x < span.Length; x++) { - var span = kernel.GetPixelRowSpan<byte>(y); - var line = string.Empty; - for (int x = 0; x < span.Length; x++) - { - line += $" {span[x]}"; - } - - line = line.Remove(0, 1); - text += line; - if (y < kernel.Height - 1) - { - text += '\n'; - } + line += $" {span[x]}"; } - MatrixText = text; + line = line.Remove(0, 1); + text += line; + if (y < kernel.Height - 1) + { + text += '\n'; + } } + + MatrixText = text; } public void ResetKernel() diff --git a/UVtools.WPF/Controls/Tools/ToolDynamicLayerHeightControl.axaml.cs b/UVtools.WPF/Controls/Tools/ToolDynamicLayerHeightControl.axaml.cs index 489c950..10398aa 100644 --- a/UVtools.WPF/Controls/Tools/ToolDynamicLayerHeightControl.axaml.cs +++ b/UVtools.WPF/Controls/Tools/ToolDynamicLayerHeightControl.axaml.cs @@ -17,7 +17,7 @@ namespace UVtools.WPF.Controls.Tools public double MinimumLayerHeight => Layer.RoundHeight(SlicerFile.LayerHeight * 2); public double MaximumLayerHeight => FileFormat.MaximumLayerHeight; - private DataGrid ExposureTable; + private readonly DataGrid ExposureTable; public ToolDynamicLayerHeightControl() { diff --git a/UVtools.WPF/Controls/Tools/ToolMaskControl.axaml.cs b/UVtools.WPF/Controls/Tools/ToolMaskControl.axaml.cs index bd389d6..c368acf 100644 --- a/UVtools.WPF/Controls/Tools/ToolMaskControl.axaml.cs +++ b/UVtools.WPF/Controls/Tools/ToolMaskControl.axaml.cs @@ -28,7 +28,7 @@ namespace UVtools.WPF.Controls.Tools set { if(!RaiseAndSetIfChanged(ref _isMaskInverted, value)) return; - if (!Operation.HaveMask) return; + if (!Operation.HaveInputMask) return; Operation.InvertMask(); MaskImage = Operation.Mask.ToBitmap(); } @@ -62,7 +62,7 @@ namespace UVtools.WPF.Controls.Tools { if(!RaiseAndSetIfChanged(ref _maskImage, value)) return; RaisePropertyChanged(nameof(InfoMaskResolutionStr)); - ParentWindow.ButtonOkEnabled = Operation.HaveMask; + ParentWindow.ButtonOkEnabled = Operation.HaveInputMask; } } diff --git a/UVtools.WPF/Controls/UserControlEx.cs b/UVtools.WPF/Controls/UserControlEx.cs index 47a2bd4..0b1a806 100644 --- a/UVtools.WPF/Controls/UserControlEx.cs +++ b/UVtools.WPF/Controls/UserControlEx.cs @@ -15,7 +15,7 @@ namespace UVtools.WPF.Controls private PropertyChangedEventHandler _propertyChanged; private readonly List<string> events = new(); - public event PropertyChangedEventHandler PropertyChanged + public new event PropertyChangedEventHandler PropertyChanged { add { _propertyChanged += value; events.Add("added"); } remove { _propertyChanged -= value; events.Add("removed"); } diff --git a/UVtools.WPF/Controls/WindowEx.cs b/UVtools.WPF/Controls/WindowEx.cs index e3a643d..5d7b0c3 100644 --- a/UVtools.WPF/Controls/WindowEx.cs +++ b/UVtools.WPF/Controls/WindowEx.cs @@ -29,7 +29,7 @@ namespace UVtools.WPF.Controls private PropertyChangedEventHandler _propertyChanged; private readonly List<string> events = new(); - public event PropertyChangedEventHandler PropertyChanged + public new event PropertyChangedEventHandler PropertyChanged { add { _propertyChanged += value; events.Add("added"); } remove { _propertyChanged -= value; events.Add("removed"); } diff --git a/UVtools.WPF/MainWindow.GCode.cs b/UVtools.WPF/MainWindow.GCode.cs index 18a7b27..716864a 100644 --- a/UVtools.WPF/MainWindow.GCode.cs +++ b/UVtools.WPF/MainWindow.GCode.cs @@ -48,11 +48,9 @@ namespace UVtools.WPF try { - using (TextWriter tw = new StreamWriter(file)) - { - tw.Write(SlicerFile.GCodeStr); - tw.Close(); - } + await using TextWriter tw = new StreamWriter(file); + await tw.WriteAsync(SlicerFile.GCodeStr); + tw.Close(); } catch (Exception e) { diff --git a/UVtools.WPF/MainWindow.Issues.cs b/UVtools.WPF/MainWindow.Issues.cs index c765f6f..6871d75 100644 --- a/UVtools.WPF/MainWindow.Issues.cs +++ b/UVtools.WPF/MainWindow.Issues.cs @@ -43,7 +43,7 @@ namespace UVtools.WPF private set => RaiseAndSetIfChanged(ref _issues, value); } - public readonly List<LayerIssue> IgnoredIssues = new List<LayerIssue>(); + public readonly List<LayerIssue> IgnoredIssues = new(); public bool IssueCanGoPrevious => Issues.Count > 0 && _issueSelectedIndex > 0; public bool IssueCanGoNext => Issues.Count > 0 && _issueSelectedIndex < Issues.Count - 1; @@ -83,8 +83,8 @@ namespace UVtools.WPF "Warning: Removing an island can cause other issues to appear if there is material present in the layers above it.\n" + "Always check previous and next layers before performing an island removal.", $"Remove {IssuesGrid.SelectedItems.Count} Issues?") != ButtonResult.Yes) return; - Dictionary<uint, List<LayerIssue>> processIssues = new Dictionary<uint, List<LayerIssue>>(); - List<uint> layersRemove = new List<uint>(); + Dictionary<uint, List<LayerIssue>> processIssues = new(); + List<uint> layersRemove = new(); foreach (LayerIssue issue in IssuesGrid.SelectedItems) @@ -335,7 +335,7 @@ namespace UVtools.WPF private void IssuesGridOnSelectionChanged(object? sender, SelectionChangedEventArgs e) { - if (!(IssuesGrid.SelectedItem is LayerIssue issue)) + if (IssuesGrid.SelectedItem is not LayerIssue issue) { ShowLayer(); return; @@ -374,7 +374,7 @@ namespace UVtools.WPF private void IssuesGridOnCellPointerPressed(object? sender, DataGridCellPointerPressedEventArgs e) { if (e.PointerPressedEventArgs.ClickCount == 2) return; - if (!(IssuesGrid.SelectedItem is LayerIssue issue)) return; + if (IssuesGrid.SelectedItem is not LayerIssue) return; // Double clicking an issue will center and zoom into the // selected issue. Left click on an issue will zoom to fit. diff --git a/UVtools.WPF/MainWindow.Progress.cs b/UVtools.WPF/MainWindow.Progress.cs index 6f2d304..14f5eaf 100644 --- a/UVtools.WPF/MainWindow.Progress.cs +++ b/UVtools.WPF/MainWindow.Progress.cs @@ -18,7 +18,7 @@ namespace UVtools.WPF { #region Members public OperationProgress Progress { get; } = new(); - private Timer _progressTimer = new(200) { AutoReset = true }; + private readonly Timer _progressTimer = new(200) { AutoReset = true }; private long _progressLastTotalSeconds; private LogItem _progressLogItem; private bool _isProgressVisible; diff --git a/UVtools.WPF/MainWindow.axaml.cs b/UVtools.WPF/MainWindow.axaml.cs index 29d85ba..b8c454e 100644 --- a/UVtools.WPF/MainWindow.axaml.cs +++ b/UVtools.WPF/MainWindow.axaml.cs @@ -814,7 +814,7 @@ namespace UVtools.WPF public async void MenuFileSettingsClicked() { - SettingsWindow settingsWindow = new SettingsWindow(); + SettingsWindow settingsWindow = new(); await settingsWindow.ShowDialog(this); } @@ -891,7 +891,7 @@ namespace UVtools.WPF IsGUIEnabled = false; ShowProgressWindow($"Downloading: {VersionChecker.Filename}", false); - var task = await Task.Factory.StartNew(async () => + var task = await Task.Factory.StartNew( () => { try { @@ -1262,7 +1262,7 @@ namespace UVtools.WPF } else { - await Dispatcher.UIThread.InvokeAsync(async () => + await Dispatcher.UIThread.InvokeAsync(() => { ProgressShow(title, canCancel); /*try @@ -1285,7 +1285,7 @@ namespace UVtools.WPF if (sender is not MenuItem item) return; if (item.Tag is not FileExtension fileExtension) return; - SaveFileDialog dialog = new SaveFileDialog + SaveFileDialog dialog = new() { InitialFileName = Path.GetFileNameWithoutExtension(SlicerFile.FileFullPath), Filters = Helpers.ToAvaloniaFilter(fileExtension.Description, fileExtension.Extension), @@ -1434,7 +1434,7 @@ namespace UVtools.WPF { if (!IsFileLoaded) return; string fileNameNoExt = Path.GetFileNameWithoutExtension(SlicerFile.FileFullPath); - OpenFolderDialog dialog = new OpenFolderDialog + OpenFolderDialog dialog = new() { Directory = string.IsNullOrEmpty(Settings.General.DefaultDirectoryExtractFile) ? Path.GetDirectoryName(SlicerFile.FileFullPath) diff --git a/UVtools.WPF/Structures/AppVersionChecker.cs b/UVtools.WPF/Structures/AppVersionChecker.cs index c043435..83ba22a 100644 --- a/UVtools.WPF/Structures/AppVersionChecker.cs +++ b/UVtools.WPF/Structures/AppVersionChecker.cs @@ -88,7 +88,7 @@ namespace UVtools.WPF.Structures public string VersionAnnouncementText => $"New version v{_version} is available!"; - public string UrlLatestRelease => $"{About.Website}/releases/latest"; + public string UrlLatestRelease = $"{About.Website}/releases/latest"; public string DownloadLink => string.IsNullOrEmpty(Filename) ? null : $"{About.Website}/releases/download/v{_version}/{Filename}"; @@ -181,7 +181,7 @@ namespace UVtools.WPF.Structures var targetDir = Path.Combine(App.ApplicationPath, upgradeFolder); using (var stream = File.Open(DownloadedFile, FileMode.Open)) { - using ZipArchive zip = new ZipArchive(stream, ZipArchiveMode.Read); + using ZipArchive zip = new(stream, ZipArchiveMode.Read); zip.ExtractToDirectory(targetDir, true); } diff --git a/UVtools.WPF/UVtools.WPF.csproj b/UVtools.WPF/UVtools.WPF.csproj index e1abb73..f5b81db 100644 --- a/UVtools.WPF/UVtools.WPF.csproj +++ b/UVtools.WPF/UVtools.WPF.csproj @@ -12,7 +12,7 @@ <PackageLicenseFile>LICENSE</PackageLicenseFile> <RepositoryUrl>https://github.com/sn4k3/UVtools</RepositoryUrl> <RepositoryType>Git</RepositoryType> - <Version>2.11.1</Version> + <Version>2.11.2</Version> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> diff --git a/UVtools.WPF/Windows/ShortcutsWindow.axaml b/UVtools.WPF/Windows/ShortcutsWindow.axaml new file mode 100644 index 0000000..bfd309f --- /dev/null +++ b/UVtools.WPF/Windows/ShortcutsWindow.axaml @@ -0,0 +1,11 @@ +<controls:WindowEx xmlns="https://github.com/avaloniaui" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:controls="clr-namespace:UVtools.WPF.Controls" + mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + x:Class="UVtools.WPF.Windows.ShortcutsWindow" + WindowStartupLocation="CenterOwner" + Title="ShortcutsWindow"> + Welcome to Avalonia! +</controls:WindowEx> diff --git a/UVtools.WPF/Windows/ShortcutsWindow.axaml.cs b/UVtools.WPF/Windows/ShortcutsWindow.axaml.cs new file mode 100644 index 0000000..45f8ce7 --- /dev/null +++ b/UVtools.WPF/Windows/ShortcutsWindow.axaml.cs @@ -0,0 +1,29 @@ +/* + * GNU AFFERO GENERAL PUBLIC LICENSE + * Version 3, 19 November 2007 + * Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + */ +using Avalonia; +using Avalonia.Markup.Xaml; +using UVtools.WPF.Controls; + +namespace UVtools.WPF.Windows +{ + public partial class ShortcutsWindow : WindowEx + { + public ShortcutsWindow() + { + InitializeComponent(); +#if DEBUG + this.AttachDevTools(); +#endif + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +} |