Make Display size float rounding equal in all properties and formats

This commit is contained in:
Tiago Conceição
2023-01-06 18:08:57 +00:00
parent 9b6416241a
commit 8a0ba6719e
23 changed files with 120 additions and 184 deletions
+3 -2
View File
@@ -13,10 +13,11 @@ namespace UVtools.Core.Extensions;
public static class SpanExtensions
{
public static unsafe void Fill<T>(this Span<T> span, Func<T> provider) where T : struct
public static unsafe void Fill<T>(this Span<T> span, Func<T> provider, int cores = -1) where T : struct
{
if (cores <= 0) cores = Environment.ProcessorCount;
int
cores = Environment.ProcessorCount,
batch = span.Length / cores,
mod = span.Length % cores,
size = Unsafe.SizeOf<T>();
+2 -2
View File
@@ -699,13 +699,13 @@ public sealed class CTBEncryptedFile : FileFormat
public override float DisplayWidth
{
get => Settings.DisplayWidth;
set => base.DisplayWidth = Settings.DisplayWidth = (float)Math.Round(value, 2);
set => base.DisplayWidth = Settings.DisplayWidth = RoundDisplaySize(value);
}
public override float DisplayHeight
{
get => Settings.DisplayHeight;
set => base.DisplayHeight = Settings.DisplayHeight = (float)Math.Round(value, 2);
set => base.DisplayHeight = Settings.DisplayHeight = RoundDisplaySize(value);
}
public override float MachineZ
+9 -4
View File
@@ -402,13 +402,13 @@ public sealed class CWSFile : FileFormat
public override float DisplayWidth
{
get => OutputSettings.PlatformXSize;
set => base.DisplayWidth = OutputSettings.PlatformXSize = (float)Math.Round(value, 2);
set => base.DisplayWidth = OutputSettings.PlatformXSize = RoundDisplaySize(value);
}
public override float DisplayHeight
{
get => OutputSettings.PlatformYSize;
set => base.DisplayHeight = OutputSettings.PlatformYSize = (float)Math.Round(value, 2);
set => base.DisplayHeight = OutputSettings.PlatformYSize = RoundDisplaySize(value);
}
public override float MachineZ
@@ -586,12 +586,17 @@ public sealed class CWSFile : FileFormat
GCode.CommandShowImageM6054.Set(";<Slice>", "{0}");
GCode.CommandWaitSyncDelay.Set(";<Delay>", "0{0}");
GCode.CommandWaitG4.Set(";<Delay>", "{0}");
}
#endregion
#region Methods
protected override void OnBeforeEncode(bool isPartialEncode)
{
SliceSettings.Xppm = Xppmm;
SliceSettings.Yppm = Yppmm;
}
protected override void EncodeInternally(OperationProgress progress)
{
//var filename = fileFullPath.EndsWith(TemporaryFileAppend) ? Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(fileFullPath)) : Path.GetFileNameWithoutExtension(fileFullPath);
+2 -2
View File
@@ -1268,13 +1268,13 @@ public sealed class ChituboxFile : FileFormat
public override float DisplayWidth
{
get => HeaderSettings.BedSizeX;
set => base.DisplayWidth = HeaderSettings.BedSizeX = (float) Math.Round(value, 2);
set => base.DisplayWidth = HeaderSettings.BedSizeX = RoundDisplaySize(value);
}
public override float DisplayHeight
{
get => HeaderSettings.BedSizeY;
set => base.DisplayHeight = HeaderSettings.BedSizeY = (float)Math.Round(value, 2);
set => base.DisplayHeight = HeaderSettings.BedSizeY = RoundDisplaySize(value);
}
public override float MachineZ
+2 -2
View File
@@ -158,13 +158,13 @@ public sealed class ChituboxZipFile : FileFormat
public override float DisplayWidth
{
get => HeaderSettings.MachineX;
set => base.DisplayWidth = HeaderSettings.MachineX = (float)Math.Round(value, 2);
set => base.DisplayWidth = HeaderSettings.MachineX = RoundDisplaySize(value);
}
public override float DisplayHeight
{
get => HeaderSettings.MachineY;
set => base.DisplayHeight = HeaderSettings.MachineY = (float)Math.Round(value, 2);
set => base.DisplayHeight = HeaderSettings.MachineY = RoundDisplaySize(value);
}
public override float MachineZ
+2 -2
View File
@@ -693,14 +693,14 @@ public sealed class FDGFile : FileFormat
public override float DisplayWidth
{
get => HeaderSettings.BedSizeX;
set => base.DisplayWidth = HeaderSettings.BedSizeX = (float)Math.Round(value, 2);
set => base.DisplayWidth = HeaderSettings.BedSizeX = RoundDisplaySize(value);
}
public override float DisplayHeight
{
get => HeaderSettings.BedSizeY;
set => base.DisplayHeight = HeaderSettings.BedSizeY = (float)Math.Round(value, 2);
set => base.DisplayHeight = HeaderSettings.BedSizeY = RoundDisplaySize(value);
}
public override float MachineZ
+48 -32
View File
@@ -43,6 +43,11 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
{
#region Constants
/// <summary>
/// Gets the decimal precision for display properties
/// </summary>
public const byte DisplayFloatPrecision = 3;
public const SpeedUnit CoreSpeedUnit = SpeedUnit.MillimetersPerMinute;
public const string TemporaryFileAppend = ".tmp";
public const ushort ExtraPrintTime = 300;
@@ -605,6 +610,10 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
public static Task<FileFormat?> OpenAsync(string fileFullPath, OperationProgress? progress = null) => OpenAsync(fileFullPath, FileDecodeType.Full, progress);
public static float RoundDisplaySize(float value) => (float) Math.Round(value, DisplayFloatPrecision);
public static double RoundDisplaySize(double value) => Math.Round(value, DisplayFloatPrecision);
public static decimal RoundDisplaySize(decimal value) => (decimal) Math.Round(value, DisplayFloatPrecision);
/// <summary>
/// Copy parameters from one file to another
/// </summary>
@@ -1536,6 +1545,13 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
set
{
if(!RaiseAndSetIfChanged(ref _resolutionX, value)) return;
RaisePropertyChanged(nameof(Resolution));
RaisePropertyChanged(nameof(ResolutionRectangle));
RaisePropertyChanged(nameof(DisplayPixelCount));
RaisePropertyChanged(nameof(DisplayAspectRatio));
RaisePropertyChanged(nameof(DisplayAspectRatioStr));
RaisePropertyChanged(nameof(IsDisplayPortrait));
RaisePropertyChanged(nameof(IsDisplayLandscape));
NotifyAspectChange();
}
}
@@ -1549,6 +1565,13 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
set
{
if(!RaiseAndSetIfChanged(ref _resolutionY, value)) return;
RaisePropertyChanged(nameof(Resolution));
RaisePropertyChanged(nameof(ResolutionRectangle));
RaisePropertyChanged(nameof(DisplayPixelCount));
RaisePropertyChanged(nameof(DisplayAspectRatio));
RaisePropertyChanged(nameof(DisplayAspectRatioStr));
RaisePropertyChanged(nameof(IsDisplayPortrait));
RaisePropertyChanged(nameof(IsDisplayLandscape));
NotifyAspectChange();
}
}
@@ -1571,8 +1594,8 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
get => new(DisplayWidth, DisplayHeight);
set
{
DisplayWidth = (float)Math.Round(value.Width, 4);
DisplayHeight = (float)Math.Round(value.Height, 4);
DisplayWidth = RoundDisplaySize(value.Width);
DisplayHeight = RoundDisplaySize(value.Height);
RaisePropertyChanged();
}
}
@@ -1585,7 +1608,10 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
get => _displayWidth;
set
{
if (!RaiseAndSetIfChanged(ref _displayWidth, (float)Math.Round(value, 2))) return;
if (!RaiseAndSetIfChanged(ref _displayWidth, RoundDisplaySize(value))) return;
RaisePropertyChanged(nameof(Display));
RaisePropertyChanged(nameof(DisplayDiagonal));
RaisePropertyChanged(nameof(DisplayDiagonalInches));
NotifyAspectChange();
}
}
@@ -1598,7 +1624,10 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
get => _displayHeight;
set
{
if(!RaiseAndSetIfChanged(ref _displayHeight, (float)Math.Round(value, 2))) return;
if(!RaiseAndSetIfChanged(ref _displayHeight, RoundDisplaySize(value))) return;
RaisePropertyChanged(nameof(Display));
RaisePropertyChanged(nameof(DisplayDiagonal));
RaisePropertyChanged(nameof(DisplayDiagonalInches));
NotifyAspectChange();
}
}
@@ -3029,27 +3058,25 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
{
IssueManager = new(this);
Thumbnails = new Mat[ThumbnailsCount];
PropertyChanged += OnPropertyChanged;
_queueTimerPrintTime.Elapsed += (sender, e) => UpdatePrintTime();
}
private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e)
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (SuppressRebuildProperties) return;
if (
e.PropertyName
if (e.PropertyName
is nameof(BottomLayerCount)
or nameof(BottomLightOffDelay)
or nameof(LightOffDelay)
or nameof(BottomWaitTimeBeforeCure)
or nameof(WaitTimeBeforeCure)
or nameof(BottomExposureTime)
or nameof(BottomExposureTime)
or nameof(ExposureTime)
or nameof(BottomWaitTimeAfterCure)
or nameof(WaitTimeAfterCure)
or nameof(BottomLiftHeight)
or nameof(BottomLiftHeight)
or nameof(BottomLiftSpeed)
or nameof(LiftHeight)
or nameof(LiftHeight)
or nameof(LiftSpeed)
or nameof(BottomLiftHeight2)
or nameof(BottomLiftSpeed2)
@@ -3057,26 +3084,26 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
or nameof(LiftSpeed2)
or nameof(BottomWaitTimeAfterLift)
or nameof(WaitTimeAfterLift)
or nameof(BottomRetractSpeed)
or nameof(BottomRetractSpeed)
or nameof(RetractSpeed)
or nameof(BottomRetractHeight2)
or nameof(BottomRetractSpeed2)
or nameof(RetractHeight2)
or nameof(RetractSpeed2)
or nameof(BottomLightPWM)
or nameof(RetractSpeed2)
or nameof(BottomLightPWM)
or nameof(LightPWM)
)
{
RebuildLayersProperties(false, e.PropertyName);
if(e.PropertyName
is nameof(BottomLayerCount)
if (e.PropertyName
is nameof(BottomLayerCount)
or nameof(BottomExposureTime)
or nameof(ExposureTime)
&& TransitionLayerType == TransitionLayerTypes.Software
) ResetCurrentTransitionLayers(false);
if(e.PropertyName
is not nameof(BottomLightPWM)
if (e.PropertyName
is not nameof(BottomLightPWM)
and not nameof(LightPWM)
) UpdatePrintTimeQueued();
@@ -3200,14 +3227,6 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
/// </summary>
protected void NotifyAspectChange()
{
RaisePropertyChanged(nameof(ResolutionRectangle));
RaisePropertyChanged(nameof(DisplayPixelCount));
RaisePropertyChanged(nameof(DisplayDiagonal));
RaisePropertyChanged(nameof(DisplayDiagonalInches));
RaisePropertyChanged(nameof(DisplayAspectRatio));
RaisePropertyChanged(nameof(DisplayAspectRatioStr));
RaisePropertyChanged(nameof(IsDisplayPortrait));
RaisePropertyChanged(nameof(IsDisplayLandscape));
RaisePropertyChanged(nameof(Xppmm));
RaisePropertyChanged(nameof(Yppmm));
RaisePropertyChanged(nameof(Ppmm));
@@ -3235,12 +3254,9 @@ public abstract class FileFormat : BindableBase, IDisposable, IEquatable<FileFor
_layers = Array.Empty<Layer>();
GCode?.Clear();
if (Thumbnails is not null)
for (int i = 0; i < Thumbnails.Length; i++)
{
for (int i = 0; i < Thumbnails.Length; i++)
{
Thumbnails[i]?.Dispose();
}
Thumbnails[i]?.Dispose();
}
}
@@ -291,14 +291,14 @@ public sealed class FlashForgeSVGXFile : FileFormat
public override float DisplayWidth
{
get => SVGDocument.PrintParameters.DisplayWidth;
set => base.DisplayWidth = SVGDocument.PrintParameters.DisplayWidth = (float)Math.Round(value, 2);
set => base.DisplayWidth = SVGDocument.PrintParameters.DisplayWidth = RoundDisplaySize(value);
}
public override float DisplayHeight
{
get => SVGDocument.PrintParameters.DisplayHeight;
set => base.DisplayHeight = SVGDocument.PrintParameters.DisplayHeight = (float)Math.Round(value, 2);
set => base.DisplayHeight = SVGDocument.PrintParameters.DisplayHeight = RoundDisplaySize(value);
}
public override FlipDirection DisplayMirror
+2 -2
View File
@@ -85,13 +85,13 @@ public sealed class GenericZIPFile : FileFormat
public override float DisplayWidth
{
get => ManifestFile.DisplayWidth;
set => base.DisplayWidth = ManifestFile.DisplayWidth = (float)Math.Round(value, 2);
set => base.DisplayWidth = ManifestFile.DisplayWidth = RoundDisplaySize(value);
}
public override float DisplayHeight
{
get => ManifestFile.DisplayHeight;
set => base.DisplayHeight = ManifestFile.DisplayHeight = (float)Math.Round(value, 2);
set => base.DisplayHeight = ManifestFile.DisplayHeight = RoundDisplaySize(value);
}
public override float MachineZ
+18 -16
View File
@@ -11,6 +11,7 @@ using Emgu.CV;
using Emgu.CV.CvEnum;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
@@ -434,26 +435,27 @@ public sealed class LGSFile : FileFormat
#region Constructors
public LGSFile()
{
PropertyChanged += (_, e) =>
{
switch (e.PropertyName)
{
case nameof(Xppmm):
HeaderSettings.PixelPerMmX = Xppmm;
RaisePropertyChanged(nameof(DisplayWidth));
break;
case nameof(Yppmm):
HeaderSettings.PixelPerMmY = Yppmm;
RaisePropertyChanged(nameof(DisplayHeight));
break;
}
};
}
{ }
#endregion
#region Methods
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
switch (e.PropertyName)
{
case nameof(Xppmm):
HeaderSettings.PixelPerMmX = Xppmm;
RaisePropertyChanged(nameof(DisplayWidth));
break;
case nameof(Yppmm):
HeaderSettings.PixelPerMmY = Yppmm;
RaisePropertyChanged(nameof(DisplayHeight));
break;
}
}
protected override void EncodeInternally(OperationProgress progress)
{
if (FileEndsWith(".lgs")) // Longer Orange 10
+2 -2
View File
@@ -328,14 +328,14 @@ public sealed class OSLAFile : FileFormat
public override float DisplayWidth
{
get => HeaderSettings.DisplayWidth;
set => base.DisplayWidth = HeaderSettings.DisplayWidth = (float)Math.Round(value, 2);
set => base.DisplayWidth = HeaderSettings.DisplayWidth = RoundDisplaySize(value);
}
public override float DisplayHeight
{
get => HeaderSettings.DisplayHeight;
set => base.DisplayHeight = HeaderSettings.DisplayHeight = (float)Math.Round(value, 2);
set => base.DisplayHeight = HeaderSettings.DisplayHeight = RoundDisplaySize(value);
}
public override float MachineZ
+2 -2
View File
@@ -709,14 +709,14 @@ public sealed class PHZFile : FileFormat
public override float DisplayWidth
{
get => HeaderSettings.BedSizeX;
set => base.DisplayWidth = HeaderSettings.BedSizeX = (float)Math.Round(value, 2);
set => base.DisplayWidth = HeaderSettings.BedSizeX = RoundDisplaySize(value);
}
public override float DisplayHeight
{
get => HeaderSettings.BedSizeY;
set => base.DisplayHeight = HeaderSettings.BedSizeY = (float)Math.Round(value, 2);
set => base.DisplayHeight = HeaderSettings.BedSizeY = RoundDisplaySize(value);
}
public override float MachineZ
@@ -782,7 +782,7 @@ public sealed class PhotonWorkshopFile : FileFormat
private Mat DecodePW0()
{
var mat = EmguExtensions.InitMat(Parent.Resolution);
var mat = Parent.CreateMat();
var imageLength = mat.GetLength();
int pixelPos = 0;
@@ -1163,7 +1163,7 @@ public sealed class PhotonWorkshopFile : FileFormat
_ => 0
};
}
set => base.DisplayWidth = MachineSettings.DisplayWidth = (float)Math.Round(value, 2);
set => base.DisplayWidth = MachineSettings.DisplayWidth = RoundDisplaySize(value);
}
public override float DisplayHeight
{
@@ -1190,7 +1190,7 @@ public sealed class PhotonWorkshopFile : FileFormat
_ => 0
};
}
set => base.DisplayHeight = MachineSettings.DisplayHeight = (float)Math.Round(value, 2);
set => base.DisplayHeight = MachineSettings.DisplayHeight = RoundDisplaySize(value);
}
public override float MachineZ
+2 -2
View File
@@ -373,13 +373,13 @@ public sealed class SL1File : FileFormat
public override float DisplayWidth
{
get => PrinterSettings.DisplayWidth;
set => base.DisplayWidth = PrinterSettings.DisplayWidth = (float)Math.Round(value, 2);
set => base.DisplayWidth = PrinterSettings.DisplayWidth = RoundDisplaySize(value);
}
public override float DisplayHeight
{
get => PrinterSettings.DisplayHeight;
set => base.DisplayHeight = PrinterSettings.DisplayHeight = (float)Math.Round(value, 2);
set => base.DisplayHeight = PrinterSettings.DisplayHeight = RoundDisplaySize(value);
}
public override float MachineZ
+2 -2
View File
@@ -254,13 +254,13 @@ public sealed class UVJFile : FileFormat
public override float DisplayWidth
{
get => JsonSettings.Properties.Size.Millimeter.X;
set => base.DisplayWidth = JsonSettings.Properties.Size.Millimeter.X = (float)Math.Round(value, 2);
set => base.DisplayWidth = JsonSettings.Properties.Size.Millimeter.X = RoundDisplaySize(value);
}
public override float DisplayHeight
{
get => JsonSettings.Properties.Size.Millimeter.Y;
set => base.DisplayHeight = JsonSettings.Properties.Size.Millimeter.Y = (float)Math.Round(value, 2);
set => base.DisplayHeight = JsonSettings.Properties.Size.Millimeter.Y = RoundDisplaySize(value);
}
public override FlipDirection DisplayMirror { get; set; }
+2 -2
View File
@@ -209,7 +209,7 @@ public sealed class VDAFile : FileFormat
}
set
{
base.DisplayWidth = ManifestFile.Machines.XLength = (float) Math.Round(value, 2);
base.DisplayWidth = ManifestFile.Machines.XLength = RoundDisplaySize(value);
ManifestFile.Machines.PixelXSize = $"{PixelWidthMicrons}um";
}
}
@@ -231,7 +231,7 @@ public sealed class VDAFile : FileFormat
}
set
{
base.DisplayHeight = ManifestFile.Machines.YWidth = (float)Math.Round(value, 2);
base.DisplayHeight = ManifestFile.Machines.YWidth = RoundDisplaySize(value);
ManifestFile.Machines.PixelYSize = $"{PixelHeightMicrons}um";
}
}
+2 -2
View File
@@ -305,13 +305,13 @@ public sealed class VDTFile : FileFormat
public override float DisplayWidth
{
get => ManifestFile.Machine.DisplayWidth;
set => base.DisplayWidth = ManifestFile.Machine.DisplayWidth = (float) Math.Round(value, 2);
set => base.DisplayWidth = ManifestFile.Machine.DisplayWidth = RoundDisplaySize(value);
}
public override float DisplayHeight
{
get => ManifestFile.Machine.DisplayHeight;
set => base.DisplayHeight = ManifestFile.Machine.DisplayHeight = (float)Math.Round(value, 2);
set => base.DisplayHeight = ManifestFile.Machine.DisplayHeight = RoundDisplaySize(value);
}
public override float MachineZ
@@ -362,7 +362,7 @@ public sealed class OperationCalibrateExposureFinder : Operation
get => _displayWidth;
set
{
if(!RaiseAndSetIfChanged(ref _displayWidth, Math.Round(value, 2))) return;
if(!RaiseAndSetIfChanged(ref _displayWidth, FileFormat.RoundDisplaySize(value))) return;
RaisePropertyChanged(nameof(Xppmm));
}
}
@@ -372,7 +372,7 @@ public sealed class OperationCalibrateExposureFinder : Operation
get => _displayHeight;
set
{
if(!RaiseAndSetIfChanged(ref _displayHeight, Math.Round(value, 2))) return;
if(!RaiseAndSetIfChanged(ref _displayHeight, FileFormat.RoundDisplaySize(value))) return;
RaisePropertyChanged(nameof(Yppmm));
}
}
@@ -128,7 +128,7 @@ public sealed class OperationCalibrateStressTower : Operation
get => _displayWidth;
set
{
if(!RaiseAndSetIfChanged(ref _displayWidth, Math.Round(value, 2))) return;
if(!RaiseAndSetIfChanged(ref _displayWidth, FileFormat.RoundDisplaySize(value))) return;
}
}
@@ -137,7 +137,7 @@ public sealed class OperationCalibrateStressTower : Operation
get => _displayHeight;
set
{
if(!RaiseAndSetIfChanged(ref _displayHeight, Math.Round(value, 2))) return;
if(!RaiseAndSetIfChanged(ref _displayHeight, FileFormat.RoundDisplaySize(value))) return;
}
}
@@ -127,7 +127,7 @@ public sealed class OperationCalibrateTolerance : Operation
get => _displayWidth;
set
{
if(!RaiseAndSetIfChanged(ref _displayWidth, Math.Round(value, 2))) return;
if(!RaiseAndSetIfChanged(ref _displayWidth, FileFormat.RoundDisplaySize(value))) return;
RaisePropertyChanged(nameof(Xppmm));
}
}
@@ -137,7 +137,7 @@ public sealed class OperationCalibrateTolerance : Operation
get => _displayHeight;
set
{
if(!RaiseAndSetIfChanged(ref _displayHeight, Math.Round(value, 2))) return;
if(!RaiseAndSetIfChanged(ref _displayHeight, FileFormat.RoundDisplaySize(value))) return;
RaisePropertyChanged(nameof(Yppmm));
}
}
@@ -123,7 +123,7 @@ public sealed class OperationCalibrateXYZAccuracy : Operation
get => _displayWidth;
set
{
if(!RaiseAndSetIfChanged(ref _displayWidth, Math.Round(value, 2))) return;
if(!RaiseAndSetIfChanged(ref _displayWidth, FileFormat.RoundDisplaySize(value))) return;
RaisePropertyChanged(nameof(Xppmm));
}
}
@@ -133,7 +133,7 @@ public sealed class OperationCalibrateXYZAccuracy : Operation
get => _displayHeight;
set
{
if(!RaiseAndSetIfChanged(ref _displayHeight, Math.Round(value, 2))) return;
if(!RaiseAndSetIfChanged(ref _displayHeight, FileFormat.RoundDisplaySize(value))) return;
RaisePropertyChanged(nameof(Yppmm));
}
}