mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-13 03:47:40 +02:00
a4bdf8f9f3
* (Add) Tools: Warn where layer preview is critical for use the tool, must disable layer rotation first (#100) * (Add) CWS: Bottom lift speed property * (Add) CWS: Support Wanhao Workshop CWX and Wanhao Creation Workshop file types (#98) * (Add) CWS: Split format into virtual extensions (.cws, .rgb.cws, .xml.cws) to support diferent file formats and diferent printers under same main .cws extensions. That will affect file converts only to let UVtools know what type of encoding to use. Load and save a xxx.cws file will always auto decode/encode the file for the correct target format no matter the extension. * (Improvement) CWS: It no longer search for a specific filename in the zip file, instead it look for extension to get the files to ensure it always found them no matter the file name system * (Fix) CWS: When "Save as" the file were generating sub files with .cws extension, eg: filename0001.cws.png * (Change) Allow read empty layers without error from Anycubic files (PWS, PW0, PWxx) due a bug on slicer software under macOS
300 lines
11 KiB
C#
300 lines
11 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.Drawing;
|
|
using UVtools.Core.Objects;
|
|
|
|
namespace UVtools.Core.Operations
|
|
{
|
|
[Serializable]
|
|
public class OperationCalculator : Operation
|
|
{
|
|
public override string Title => "Calculator";
|
|
public override string Description => null;
|
|
|
|
public override string ConfirmationText => null;
|
|
|
|
public override string ProgressTitle => null;
|
|
|
|
public override string ProgressAction => null;
|
|
|
|
public override Enumerations.LayerRangeSelection StartLayerRangeSelection => Enumerations.LayerRangeSelection.None;
|
|
public override bool CanROI => false;
|
|
|
|
public override bool CanHaveProfiles => false;
|
|
|
|
public MillimetersToPixels CalcMillimetersToPixels { get; set; }
|
|
public LightOffDelayC CalcLightOffDelay { get; set; }
|
|
|
|
public OperationCalculator()
|
|
{
|
|
}
|
|
|
|
public abstract class Calculation : BindableBase
|
|
{
|
|
public abstract string Description { get; }
|
|
public abstract string Formula { get; }
|
|
}
|
|
|
|
public sealed class MillimetersToPixels : Calculation
|
|
{
|
|
private uint _resolutionX;
|
|
private uint _resolutionY;
|
|
private decimal _displayWidth;
|
|
private decimal _displayHeight;
|
|
private decimal _millimeters = 1;
|
|
|
|
public override string Description => "Converts from Millimeters to Pixels";
|
|
public override string Formula => "Pixels = Resolution / Display * Millimeters";
|
|
|
|
public MillimetersToPixels(Size resolution, SizeF display, decimal millimeters = 1)
|
|
{
|
|
_resolutionX = (uint) resolution.Width;
|
|
_resolutionY = (uint) resolution.Height;
|
|
|
|
_displayWidth = (decimal) display.Width;
|
|
_displayHeight = (decimal) display.Height;
|
|
|
|
_millimeters = millimeters;
|
|
}
|
|
|
|
public uint ResolutionX
|
|
{
|
|
get => _resolutionX;
|
|
set
|
|
{
|
|
if(!RaiseAndSetIfChanged(ref _resolutionX, value)) return;
|
|
RaisePropertyChanged(nameof(PixelsPerMillimeterX));
|
|
RaisePropertyChanged(nameof(PixelsX));
|
|
}
|
|
}
|
|
|
|
public uint ResolutionY
|
|
{
|
|
get => _resolutionY;
|
|
set
|
|
{
|
|
if(!RaiseAndSetIfChanged(ref _resolutionY, value)) return;
|
|
RaisePropertyChanged(nameof(PixelsPerMillimeterY));
|
|
RaisePropertyChanged(nameof(PixelsY));
|
|
}
|
|
}
|
|
|
|
public decimal DisplayWidth
|
|
{
|
|
get => _displayWidth;
|
|
set
|
|
{
|
|
if(!RaiseAndSetIfChanged(ref _displayWidth, value)) return;
|
|
RaisePropertyChanged(nameof(PixelsPerMillimeterX));
|
|
RaisePropertyChanged(nameof(PixelsX));
|
|
}
|
|
}
|
|
|
|
public decimal DisplayHeight
|
|
{
|
|
get => _displayHeight;
|
|
set
|
|
{
|
|
if(!RaiseAndSetIfChanged(ref _displayHeight, value)) return;
|
|
RaisePropertyChanged(nameof(PixelsPerMillimeterY));
|
|
RaisePropertyChanged(nameof(PixelsY));
|
|
}
|
|
}
|
|
|
|
public decimal Millimeters
|
|
{
|
|
get => _millimeters;
|
|
set
|
|
{
|
|
if(!RaiseAndSetIfChanged(ref _millimeters, value)) return;
|
|
RaisePropertyChanged(nameof(PixelsX));
|
|
RaisePropertyChanged(nameof(PixelsY));
|
|
}
|
|
}
|
|
|
|
public decimal PixelsPerMillimeterX => DisplayWidth > 0 ? Math.Round(ResolutionX / DisplayWidth, 2) : 0;
|
|
public decimal PixelsPerMillimeterY => DisplayHeight > 0 ? Math.Round(ResolutionY / DisplayHeight, 2) : 0;
|
|
|
|
public decimal PixelsX => Math.Round(PixelsPerMillimeterX * Millimeters, 2);
|
|
public decimal PixelsY => Math.Round(PixelsPerMillimeterY * Millimeters, 2);
|
|
|
|
|
|
}
|
|
|
|
public sealed class LightOffDelayC : Calculation
|
|
{
|
|
private decimal _liftHeight;
|
|
private decimal _bottomLiftHeight;
|
|
private decimal _liftSpeed;
|
|
private decimal _bottomLiftSpeed;
|
|
private decimal _retractSpeed;
|
|
private decimal _bottomRetractSpeed;
|
|
private decimal _waitTime = 2.5m;
|
|
private decimal _bottomWaitTime = 3m;
|
|
|
|
public override string Description =>
|
|
"Calculates the required light-off delay (Moving time from the build plate + additional time for resin to stabilize) given The lifting height, speed and retract to wait x seconds before cure a new layer.\n" +
|
|
"Light-off delay is crucial for gaining higher-resolution and sharper prints.\n" +
|
|
"When the build plate retracts, it is important to allow enough time for the resin to stabilize before the UV lights turn on. This would ideally be around 2-3s.";
|
|
|
|
public override string Formula => "Light-off delay = Lifting height / (Lifting speed / 60) + Lifting height / (Retract speed / 60) + Desired wait seconds";
|
|
|
|
public decimal LiftHeight
|
|
{
|
|
get => _liftHeight;
|
|
set
|
|
{
|
|
if(!RaiseAndSetIfChanged(ref _liftHeight, value)) return;
|
|
RaisePropertyChanged(nameof(LightOffDelay));
|
|
}
|
|
}
|
|
|
|
public decimal BottomLiftHeight
|
|
{
|
|
get => _bottomLiftHeight;
|
|
set
|
|
{
|
|
if(!RaiseAndSetIfChanged(ref _bottomLiftHeight, value)) return;
|
|
RaisePropertyChanged(nameof(BottomLightOffDelay));
|
|
}
|
|
}
|
|
|
|
public decimal LiftSpeed
|
|
{
|
|
get => _liftSpeed;
|
|
set
|
|
{
|
|
if(!RaiseAndSetIfChanged(ref _liftSpeed, value)) return;
|
|
RaisePropertyChanged(nameof(LightOffDelay));
|
|
}
|
|
}
|
|
|
|
public decimal BottomLiftSpeed
|
|
{
|
|
get => _bottomLiftSpeed;
|
|
set
|
|
{
|
|
if(!RaiseAndSetIfChanged(ref _bottomLiftSpeed, value)) return;
|
|
RaisePropertyChanged(nameof(BottomLightOffDelay));
|
|
}
|
|
}
|
|
|
|
public decimal RetractSpeed
|
|
{
|
|
get => _retractSpeed;
|
|
set
|
|
{
|
|
if(!RaiseAndSetIfChanged(ref _retractSpeed, value)) return;
|
|
RaisePropertyChanged(nameof(LightOffDelay));
|
|
|
|
BottomRetractSpeed = _retractSpeed;
|
|
}
|
|
}
|
|
|
|
public decimal BottomRetractSpeed
|
|
{
|
|
get => _bottomRetractSpeed;
|
|
set
|
|
{
|
|
if (!RaiseAndSetIfChanged(ref _bottomRetractSpeed, value)) return;
|
|
RaisePropertyChanged(nameof(BottomLightOffDelay));
|
|
}
|
|
}
|
|
|
|
public decimal WaitTime
|
|
{
|
|
get => _waitTime;
|
|
set
|
|
{
|
|
if(!RaiseAndSetIfChanged(ref _waitTime, value)) return;
|
|
RaisePropertyChanged(nameof(LightOffDelay));
|
|
}
|
|
}
|
|
|
|
public decimal BottomWaitTime
|
|
{
|
|
get => _bottomWaitTime;
|
|
set
|
|
{
|
|
if (!RaiseAndSetIfChanged(ref _bottomWaitTime, value)) return;
|
|
RaisePropertyChanged(nameof(BottomLightOffDelay));
|
|
}
|
|
}
|
|
|
|
public decimal LightOffDelay => CalculateSeconds(_liftHeight, _liftSpeed, _retractSpeed, _waitTime);
|
|
|
|
public decimal BottomLightOffDelay => CalculateSeconds(_bottomLiftHeight, _bottomLiftSpeed, _bottomRetractSpeed, _bottomWaitTime);
|
|
|
|
public LightOffDelayC()
|
|
{
|
|
}
|
|
|
|
public LightOffDelayC(decimal liftHeight, decimal bottomLiftHeight, decimal liftSpeed, decimal bottomLiftSpeed, decimal retractSpeed, decimal bottomRetractSpeed, decimal waitTime = 2.5m, decimal bottomWaitTime = 3m)
|
|
{
|
|
_liftHeight = liftHeight;
|
|
_bottomLiftHeight = bottomLiftHeight;
|
|
_liftSpeed = liftSpeed;
|
|
_bottomLiftSpeed = bottomLiftSpeed;
|
|
_retractSpeed = retractSpeed;
|
|
_bottomRetractSpeed = bottomRetractSpeed;
|
|
_waitTime = waitTime;
|
|
_bottomWaitTime = bottomWaitTime;
|
|
}
|
|
|
|
public static decimal CalculateSeconds(decimal liftHeight, decimal liftSpeed, decimal retract, decimal waitTime = 0)
|
|
{
|
|
try
|
|
{
|
|
return Math.Round(liftHeight / (liftSpeed / 60m) + liftHeight / (retract / 60m) + waitTime, 2);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public static float CalculateSeconds(float liftHeight, float liftSpeed, float retract, float extraWaitTime = 0)
|
|
{
|
|
try
|
|
{
|
|
return (float) Math.Round(liftHeight / (liftSpeed / 60f) + liftHeight / (retract / 60f) + extraWaitTime, 2);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
public static uint CalculateMilliseconds(float liftHeight, float liftSpeed, float retract, float extraWaitTime = 0) =>
|
|
(uint)(CalculateSeconds(liftHeight, liftSpeed, retract, extraWaitTime) * 1000);
|
|
|
|
|
|
public static float CalculateSecondsLiftOnly(float liftHeight, float liftSpeed, float extraWaitTime = 0)
|
|
{
|
|
try
|
|
{
|
|
return (float)Math.Round(liftHeight / (liftSpeed / 60f) + extraWaitTime, 2);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
public static uint CalculateMillisecondsLiftOnly(float liftHeight, float liftSpeed, float extraWaitTime = 0) =>
|
|
(uint)(CalculateSecondsLiftOnly(liftHeight, liftSpeed, extraWaitTime) * 1000);
|
|
|
|
|
|
}
|
|
}
|
|
}
|