diff options
Diffstat (limited to 'UVtools.Core/Operations/OperationCalibrateGrayscale.cs')
-rw-r--r-- | UVtools.Core/Operations/OperationCalibrateGrayscale.cs | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/UVtools.Core/Operations/OperationCalibrateGrayscale.cs b/UVtools.Core/Operations/OperationCalibrateGrayscale.cs index 7d78d6f..844d7fd 100644 --- a/UVtools.Core/Operations/OperationCalibrateGrayscale.cs +++ b/UVtools.Core/Operations/OperationCalibrateGrayscale.cs @@ -10,7 +10,6 @@ using System; using System.Drawing; using System.Text; using System.Threading.Tasks; -using System.Xml.Serialization; using Emgu.CV; using Emgu.CV.CvEnum; using Emgu.CV.Structure; @@ -25,7 +24,6 @@ namespace UVtools.Core.Operations public sealed class OperationCalibrateGrayscale : Operation { #region Members - private Size _resolution = Size.Empty; private decimal _layerHeight = 0.05M; private ushort _bottomLayers = 10; private ushort _interfaceLayers = 5; @@ -100,15 +98,21 @@ namespace UVtools.Core.Operations #endregion - #region Properties + #region Constructor + + public OperationCalibrateGrayscale() { } - [XmlIgnore] - public Size Resolution + public OperationCalibrateGrayscale(FileFormat slicerFile) : base(slicerFile) { - get => _resolution; - set => RaiseAndSetIfChanged(ref _resolution, value); + _layerHeight = (decimal)slicerFile.LayerHeight; + _bottomLayers = slicerFile.BottomLayerCount; + _bottomExposure = (decimal)slicerFile.BottomExposureTime; + _normalExposure = (decimal)slicerFile.ExposureTime; + _mirrorOutput = slicerFile.MirrorDisplay; } + #endregion + #region Properties public decimal LayerHeight { @@ -340,10 +344,10 @@ namespace UVtools.Core.Operations { Mat[] layers = new Mat[3]; - layers[0] = EmguExtensions.InitMat(Resolution); + layers[0] = EmguExtensions.InitMat(SlicerFile.Resolution); - int radius = Math.Max(100, Math.Min(Resolution.Width, Resolution.Height) - _outerMargin * 2) / 2 ; - Point center = new Point(Resolution.Width / 2, Resolution.Height / 2); + int radius = Math.Max(100, Math.Min(SlicerFile.Resolution.Width, SlicerFile.Resolution.Height) - _outerMargin * 2) / 2 ; + Point center = new Point(SlicerFile.Resolution.Width / 2, SlicerFile.Resolution.Height / 2); int innerRadius = Math.Max(100, radius - _innerMargin); double topLineLength = 0; @@ -452,32 +456,22 @@ namespace UVtools.Core.Operations return thumbnail; } - public override bool Execute(FileFormat slicerFile, OperationProgress progress = null) + protected override bool ExecuteInternally(OperationProgress progress) { - progress ??= new OperationProgress(); - progress.Reset(ProgressAction, LayerCount); - slicerFile.SuppressRebuildProperties = true; - + progress.ItemCount = LayerCount; var newLayers = new Layer[LayerCount]; - slicerFile.LayerHeight = (float)LayerHeight; - slicerFile.BottomExposureTime = (float)BottomExposure; - slicerFile.ExposureTime = (float)NormalExposure; - slicerFile.BottomLayerCount = BottomLayers; - var layers = GetLayers(); - progress++; - - var bottomLayer = new Layer(0, layers[0], slicerFile.LayerManager) + var bottomLayer = new Layer(0, layers[0], SlicerFile.LayerManager) { IsModified = true }; - var interfaceLayer = InterfaceLayers > 0 && layers[1] is not null ? new Layer(0, layers[1], slicerFile.LayerManager) + var interfaceLayer = InterfaceLayers > 0 && layers[1] is not null ? new Layer(0, layers[1], SlicerFile.LayerManager) { IsModified = true } : null; - var layer = new Layer(0, layers[2], slicerFile.LayerManager) + var layer = new Layer(0, layers[2], SlicerFile.LayerManager) { IsModified = true }; @@ -511,17 +505,20 @@ namespace UVtools.Core.Operations } - if (slicerFile.ThumbnailsCount > 0) - slicerFile.SetThumbnails(GetThumbnail()); + if (SlicerFile.ThumbnailsCount > 0) + SlicerFile.SetThumbnails(GetThumbnail()); - progress++; + SlicerFile.SuppressRebuildProperties = true; + SlicerFile.LayerHeight = (float)LayerHeight; + SlicerFile.BottomExposureTime = (float)BottomExposure; + SlicerFile.ExposureTime = (float)NormalExposure; + SlicerFile.BottomLayerCount = BottomLayers; + SlicerFile.LayerManager.Layers = newLayers; + SlicerFile.LayerManager.RebuildLayersProperties(); + SlicerFile.SuppressRebuildProperties = false; - slicerFile.LayerManager.Layers = newLayers; - slicerFile.SuppressRebuildProperties = false; - slicerFile.LayerManager.RebuildLayersProperties(); - - return true; + return !progress.Token.IsCancellationRequested; } #endregion |