mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-12 11:32:33 +02:00
b2bd1c41f1
* (Add) PrusaSlicer Printer: Elegoo Mars 2 Pro * (Add) PrusaSlicer Printer: Creality LD-002H * (Add) PrusaSlicer Printer: Voxelab Polaris * (Add) File Format: UVJ (#8) * (Add) Mutataor: Pixel Dimming * (Add) Pixel Editor tab with new drawing functions * (Add) Pixel Editor: Bursh area and shape * (Add) Pixel Editor: Supports * (Add) Pixel Editor: Drain holes * (Add) Settings for pixel editor * (Add) Setting: File open default directory * (Add) Setting: File save default directory * (Add) Setting: File extract default directory * (Add) Setting: File convert default directory * (Add) Setting: File save prompt for overwrite (#10) * (Add) Setting: File save preffix and suffix name * (Add) Setting: UVtools version to the title bar * (Improvement) Force same directory as input file on dialogs * (Improvement) Pattern: Better positioning when not using an anchor, now it's more center friendly * (Change) Setting: Start maximized defaults to true * (Fix) Pattern: Calculated volume was appending one margin width/height more * (Fix) When cancel a file load, some shortcuts can crash the program as it assume file is loaded * (Fix) pws: Encode using the same count-of-threshold method as CBDDLP (ezrec/uv3dp#79)
121 lines
3.9 KiB
C#
121 lines
3.9 KiB
C#
/*
|
|
* 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;
|
|
using System.Threading;
|
|
|
|
namespace UVtools.Core.Operations
|
|
{
|
|
public sealed class OperationProgress
|
|
{
|
|
public const string StatusDecodeThumbnails = "Decoding Thumbnails";
|
|
public const string StatusGatherLayers = "Gathering Layers";
|
|
public const string StatusDecodeLayers = "Decoding Layers";
|
|
public const string StatusEncodeLayers = "Encoding Layers";
|
|
public const string StatusWritingFile = "Writing File";
|
|
public const string StatusEncodeGcode = "Encoding GCode";
|
|
|
|
public const string StatusOptimizingBounds = "Gathering Bounds";
|
|
public const string StatusCalculatingBounds = "Calculating Bounds";
|
|
|
|
public const string StatusExtracting = "Extracting";
|
|
|
|
public const string StatusIslands = "Islands";
|
|
public const string StatusResinTraps = "Resin traps";
|
|
public const string StatusRepairLayers = "Repair Layers";
|
|
|
|
public object Mutex = new object();
|
|
|
|
public CancellationTokenSource TokenSource { get; } = new CancellationTokenSource();
|
|
public CancellationToken Token => TokenSource.Token;
|
|
|
|
private bool _canCancel = true;
|
|
|
|
public OperationProgress()
|
|
{
|
|
}
|
|
|
|
public OperationProgress(bool canCancel)
|
|
{
|
|
_canCancel = canCancel;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets if operation can be cancelled
|
|
/// </summary>
|
|
public bool CanCancel
|
|
{
|
|
get
|
|
{
|
|
if (!_canCancel) return _canCancel;
|
|
return !Token.IsCancellationRequested && Token.CanBeCanceled && _canCancel;
|
|
}
|
|
set => _canCancel = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the item name for the operation
|
|
/// </summary>
|
|
public string ItemName { get; set; } = StatusDecodeLayers;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the number of processed items
|
|
/// </summary>
|
|
public uint ProcessedItems { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the total of item count on this operation
|
|
/// </summary>
|
|
public uint ItemCount { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets the remaining items to be processed
|
|
/// </summary>
|
|
public uint RemainingItems => ItemCount - ProcessedItems;
|
|
|
|
public int ProgressStep => (int) Math.Min(ProcessedItems * 100 / ItemCount, 100);
|
|
|
|
/// <summary>
|
|
/// Gets the progress from 0 to 100%
|
|
/// </summary>
|
|
public double ProgressPercent => Math.Round(ProcessedItems * 100.0 / ItemCount, 2);
|
|
|
|
public static OperationProgress operator +(OperationProgress progress, uint value)
|
|
{
|
|
progress.ProcessedItems += value;
|
|
return progress;
|
|
}
|
|
|
|
public static OperationProgress operator ++(OperationProgress progress)
|
|
{
|
|
progress.ProcessedItems++;
|
|
return progress;
|
|
}
|
|
|
|
public static OperationProgress operator --(OperationProgress progress)
|
|
{
|
|
progress.ProcessedItems--;
|
|
return progress;
|
|
}
|
|
|
|
public void Reset(string name = "", uint itemCount = 0, uint items = 0)
|
|
{
|
|
ItemName = name;
|
|
ItemCount = itemCount;
|
|
ProcessedItems = items;
|
|
}
|
|
|
|
|
|
public override string ToString()
|
|
{
|
|
return ItemCount == 0 ?
|
|
$"{ProcessedItems} / ? {ItemName}" :
|
|
$"{RemainingItems} / {ItemCount} / {ProcessedItems} | {ItemName} | {ProgressPercent:0.00}%";
|
|
}
|
|
}
|
|
}
|