Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'UVtools.Core/Operations/OperationRotate.cs')
-rw-r--r--UVtools.Core/Operations/OperationRotate.cs56
1 files changed, 49 insertions, 7 deletions
diff --git a/UVtools.Core/Operations/OperationRotate.cs b/UVtools.Core/Operations/OperationRotate.cs
index 4d32762..f9a864e 100644
--- a/UVtools.Core/Operations/OperationRotate.cs
+++ b/UVtools.Core/Operations/OperationRotate.cs
@@ -7,13 +7,21 @@
*/
using System;
+using System.Threading.Tasks;
+using Emgu.CV;
+using UVtools.Core.Extensions;
+using UVtools.Core.FileFormats;
namespace UVtools.Core.Operations
{
[Serializable]
public class OperationRotate : Operation
{
+ #region Members
private decimal _angleDegrees = 90;
+ #endregion
+
+ #region Overrides
public override string Title => "Rotate";
public override string Description =>
"Rotate the layers of the model.\n";
@@ -25,19 +33,22 @@ namespace UVtools.Core.Operations
$"Rotating layers {LayerIndexStart} through {LayerIndexEnd} {(AngleDegrees < 0 ? "counter-clockwise" : "clockwise")} by {Math.Abs(AngleDegrees)}°";
public override string ProgressAction => "Rotated layers";
-
- public decimal AngleDegrees
- {
- get => _angleDegrees;
- set => RaiseAndSetIfChanged(ref _angleDegrees, value);
- }
-
+
public override string ToString()
{
var result = $"[Angle: {Math.Abs(_angleDegrees)}º {(AngleDegrees < 0 ? "CCW" : "CW")}]" + LayerRangeString;
if (!string.IsNullOrEmpty(ProfileName)) result = $"{ProfileName}: {result}";
return result;
}
+ #endregion
+
+ #region Properties
+ public decimal AngleDegrees
+ {
+ get => _angleDegrees;
+ set => RaiseAndSetIfChanged(ref _angleDegrees, value);
+ }
+ #endregion
#region Equality
@@ -60,5 +71,36 @@ namespace UVtools.Core.Operations
}
#endregion
+
+ #region Methods
+
+ public override bool Execute(FileFormat slicerFile, OperationProgress progress = null)
+ {
+ progress ??= new OperationProgress();
+ progress.Reset(ProgressAction, LayerRangeCount);
+ Parallel.For(LayerIndexStart, LayerIndexEnd + 1, layerIndex =>
+ {
+ if (progress.Token.IsCancellationRequested) return;
+ using var mat = slicerFile[layerIndex].LayerMat;
+ Execute(mat);
+ slicerFile[layerIndex].LayerMat = mat;
+ lock (progress.Mutex)
+ {
+ progress++;
+ }
+ });
+ progress.Token.ThrowIfCancellationRequested();
+
+ return true;
+ }
+
+ public override bool Execute(Mat mat, params object[] arguments)
+ {
+ Mat target = GetRoiOrDefault(mat);
+ target.Rotate((double)AngleDegrees);
+ return true;
+ }
+
+ #endregion
}
}