diff options
Diffstat (limited to 'UVtools.Core/Operations/OperationPattern.cs')
-rw-r--r-- | UVtools.Core/Operations/OperationPattern.cs | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/UVtools.Core/Operations/OperationPattern.cs b/UVtools.Core/Operations/OperationPattern.cs index 97d75f7..3cd36bf 100644 --- a/UVtools.Core/Operations/OperationPattern.cs +++ b/UVtools.Core/Operations/OperationPattern.cs @@ -186,19 +186,21 @@ namespace UVtools.Core.Operations public Size GetPatternVolume => new(Cols * ROI.Width + (Cols - 1) * ColSpacing, Rows * ROI.Height + (Rows - 1) * RowSpacing); #endregion - public OperationPattern() - { - } + #region Constructor - public OperationPattern(Rectangle srcRoi, Size resolution) + public OperationPattern() { } + + public OperationPattern(FileFormat slicerFile, Rectangle srcRoi = default) : base(slicerFile) { - ImageWidth = (uint) resolution.Width; - ImageHeight = (uint) resolution.Height; + ImageWidth = slicerFile.ResolutionX; + ImageHeight = slicerFile.ResolutionY; - SetRoi(srcRoi); + SetRoi(srcRoi.IsEmpty ? slicerFile.BoundingRectangle : srcRoi); Fill(); } + #endregion + #region Methods public void SetAnchor(byte value) { @@ -272,16 +274,13 @@ namespace UVtools.Core.Operations return result; } - public override bool Execute(FileFormat slicerFile, OperationProgress progress = null) + protected override bool ExecuteInternally(OperationProgress progress) { - progress ??= new OperationProgress(); - progress.Reset(ProgressAction, LayerRangeCount); - Parallel.For(LayerIndexStart, LayerIndexEnd + 1, layerIndex => { if (progress.Token.IsCancellationRequested) return; - using var mat = slicerFile[layerIndex].LayerMat; + using var mat = SlicerFile[layerIndex].LayerMat; using var layerRoi = new Mat(mat, ROI); using var dstLayer = mat.CloneBlank(); for (ushort col = 0; col < Cols; col++) @@ -292,7 +291,7 @@ namespace UVtools.Core.Operations layerRoi.CopyTo(dstRoi); } //Execute(mat); - slicerFile[layerIndex].LayerMat = dstLayer; + SlicerFile[layerIndex].LayerMat = dstLayer; lock (progress.Mutex) { @@ -300,19 +299,19 @@ namespace UVtools.Core.Operations } }); - slicerFile.LayerManager.BoundingRectangle = Rectangle.Empty; + SlicerFile.LayerManager.BoundingRectangle = Rectangle.Empty; progress.Token.ThrowIfCancellationRequested(); if (Anchor == Enumerations.Anchor.None) return true; - var operationMove = new OperationMove(slicerFile.LayerManager.BoundingRectangle, ImageWidth, ImageHeight, Anchor) + var operationMove = new OperationMove(SlicerFile, Anchor) { LayerIndexStart = LayerIndexStart, LayerIndexEnd = LayerIndexEnd }; - operationMove.Execute(slicerFile, progress); + operationMove.Execute(progress); - return true; + return !progress.Token.IsCancellationRequested; } /*public override bool Execute(Mat mat, params object[] arguments) |