mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-09 18:12:32 +02:00
554794d0d8
- **Core:**
- (Add) Utilities methods (`MinimumSpeed`, `MaximumSpeed`, `CreateMat`, `CreateMatWithDummyPixel`, `FileFormat.CopyParameters`)
- (Improvement) Issues - Print Height: Group all layers outside the valid print height
- **FileFormats:**
- (Add) Generic / Phrozen ZIP format
- (Add) Information/modifier to file formats to tell whatever is possible to use custom PositionZ per layer
- (Add) Safe checks in order to run some tools, related to the previous "PositionZ" point
- (Improvement) if blank, allow the previous layer to have a higher Z position than the successor layer
- (Improvement) SL1: Implement the missing keys from new features of PrusaSlicer 2.4.0
- (Fix) Calling a partial save action without a progress instance would cause a crash
- (Fix) GCode: Unable to parse the "Wait time after lift" when a second lift (TSMC) was present, leading to a sum on "Wait time before cure"
- **Tools:**
- (Add) Timelapse: Raise the build platform to a set position every odd-even height to be able to take a photo and create a time-lapse video of the print
- (Add) Scripting: ScriptToggleSwitchInput
- **Raise on print finish:**
- (Add) Reapply check and prevent run the tool in that case
- (Fix) It was incorrectly marked to be able to run in partial mode
- (Fix) The dummy pixel was beeing set to a wrong location
- **Layers:**:
- (Change) When set Wait times to a negative value, it will set the global wait time value accordingly
- (Change) Allow ExposureTime to be 0
- **Commandline arguments**
- (Add) --run-operation \<input_file\> \<operation_file.uvtop\>
- (Add) --run-script \<input_file\> \<script_file.cs\>
- (Add) --copy-parameters \<from_file\> \<to_file\>
- **UI:**
- (Add) When open a file with missing crucial information, prompt the user to fill in that information (Optional)
- (Add) Warn user about misfunction when open a file with invalid layer height of 0mm
- (Improvement) Layer information: Only show the "Exposure time" when its availiable on the file format
- (Improvement) When a file is about to get auto-converted once loaded and the output file already exists, prompt user for overwrite action
- (Improvement) Set default culture info at top most of the program to avoid strange problems with commandline arguments
- (Upgrade) .NET from 5.0.13 to 5.0.14
- (Downgrade) OpenCV from 4.5.5 to 4.5.4 due the crash while detecting islands (Linux and MacOS) (#411, #415, #416)
193 lines
7.1 KiB
C#
193 lines
7.1 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 UVtools.Core.Extensions;
|
|
using UVtools.Core.Layers;
|
|
using UVtools.Core.Scripting;
|
|
|
|
namespace UVtools.ScriptSample
|
|
{
|
|
/// <summary>
|
|
/// Change layer properties to random values
|
|
/// </summary>
|
|
public class ScriptTimelapseSample : ScriptGlobals
|
|
{
|
|
ScriptNumericalInput<float> InputPositionZ = new()
|
|
{
|
|
Label = "Z position to lift to",
|
|
Unit = "mm",
|
|
Minimum = 0.01f,
|
|
Maximum = 1000,
|
|
Increment = 1f,
|
|
Value = 0.5f,
|
|
DecimalPlates = 2
|
|
};
|
|
|
|
ScriptNumericalInput<ushort> InputRaiseEveryLayerN = new()
|
|
{
|
|
Label = "Raise every",
|
|
Unit = "layer(s)",
|
|
Minimum = 1,
|
|
Maximum = 1000,
|
|
Increment = 1,
|
|
Value = 10,
|
|
DecimalPlates = 0
|
|
};
|
|
|
|
ScriptNumericalInput<float> InputWaitTime = new()
|
|
{
|
|
Label = "Time to wait on still position",
|
|
Unit = "s",
|
|
ToolTip = "Note: Not always possible to wait in some cases",
|
|
Minimum = 0,
|
|
Maximum = 30,
|
|
Increment = 1,
|
|
Value = 2,
|
|
DecimalPlates = 2
|
|
};
|
|
|
|
private ScriptToggleSwitchInput InputUseVirtualLayer = new()
|
|
{
|
|
OnText = "Use blank layers to go to the target height",
|
|
OffText = "Use lift movement to go to the target height",
|
|
ToolTip = "Use this option if you printer is unable to use large lifts or waits after lift"
|
|
};
|
|
|
|
ScriptNumericalInput<float> InputLiftSpeed = new()
|
|
{
|
|
Label = "Virtual layer lift speed",
|
|
Unit = "mm/min",
|
|
Minimum = 50,
|
|
Maximum = 1000,
|
|
Increment = 10,
|
|
Value = 200,
|
|
DecimalPlates = 2
|
|
};
|
|
|
|
ScriptNumericalInput<float> InputRetractSpeed = new()
|
|
{
|
|
Label = "Virtual layer retract speed",
|
|
Unit = "mm/min",
|
|
Minimum = 50,
|
|
Maximum = 1000,
|
|
Increment = 10,
|
|
Value = 200,
|
|
DecimalPlates = 2
|
|
};
|
|
|
|
/// <summary>
|
|
/// Set configurations here, this function trigger just after load a script
|
|
/// </summary>
|
|
public void ScriptInit()
|
|
{
|
|
Script.Name = "Timelapse position setter";
|
|
Script.Description = "Raises the build platform to a set position to take a timelapse photo every n layers.\n" +
|
|
"Do not execute this script twice!";
|
|
Script.Author = "Tiago Conceição";
|
|
Script.Version = new Version(0, 1);
|
|
|
|
InputPositionZ.Value = (float)Math.Round(SlicerFile.PrintHeight + 1, 2);
|
|
InputPositionZ.Minimum = (float) Math.Round(SlicerFile.PrintHeight + 0.1, 2);
|
|
Script.UserInputs.Add(InputPositionZ);
|
|
Script.UserInputs.Add(InputRaiseEveryLayerN);
|
|
Script.UserInputs.Add(InputWaitTime);
|
|
|
|
if (!SlicerFile.SupportsGCode)
|
|
{
|
|
InputUseVirtualLayer.Value = true;
|
|
}
|
|
|
|
if (SlicerFile.CanUseLayerLiftHeight)
|
|
{
|
|
Script.UserInputs.Add(InputUseVirtualLayer);
|
|
}
|
|
else
|
|
{
|
|
InputUseVirtualLayer.Value = true; // Must use layer height
|
|
}
|
|
|
|
Script.UserInputs.Add(InputLiftSpeed);
|
|
Script.UserInputs.Add(InputRetractSpeed);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validate user inputs here, this function trigger when user click on execute
|
|
/// </summary>
|
|
/// <returns>A error message, empty or null if validation passes.</returns>
|
|
public string ScriptValidate()
|
|
{
|
|
if (!SlicerFile.SupportPerLayerSettings) return "This script is not compatible with your printer / file format";
|
|
if (InputPositionZ.Value <= SlicerFile.PrintHeight) return $"{InputPositionZ.Label} must be greater than {SlicerFile.PrintHeight}mm";
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Execute the script, this function trigger when when user click on execute and validation passes
|
|
/// </summary>
|
|
/// <returns>True if executes successfully to the end, otherwise false.</returns>
|
|
public bool ScriptExecute()
|
|
{
|
|
if (InputUseVirtualLayer.Value)
|
|
{
|
|
using var mat = EmguExtensions.InitMat(SlicerFile.Resolution);
|
|
var pixelPos = SlicerFile.BoundingRectangle.Center();
|
|
mat.SetByte(pixelPos.X, pixelPos.Y, 1); // Print a very fade pixel to ignore empty layer detection
|
|
var layer = new Layer(SlicerFile.LayerCount, mat, SlicerFile)
|
|
{
|
|
PositionZ = InputPositionZ.Value,
|
|
ExposureTime = SlicerFile.SupportsGCode ? 0 : 0.05f,
|
|
LiftSpeed = InputLiftSpeed.Value,
|
|
RetractSpeed = InputRetractSpeed.Value
|
|
};
|
|
|
|
if (InputWaitTime.Value > 0)
|
|
{
|
|
if (SlicerFile.CanUseWaitTimeBeforeCure)
|
|
{
|
|
layer.WaitTimeBeforeCure = InputWaitTime.Value;
|
|
}
|
|
else
|
|
{
|
|
layer.ExposureTime = InputWaitTime.Value;
|
|
}
|
|
}
|
|
|
|
|
|
SlicerFile.SuppressRebuildPropertiesWork(() =>
|
|
{
|
|
uint createdLayers = 0;
|
|
for (uint layerIndex = Math.Max(1, Operation.LayerIndexStart + InputRaiseEveryLayerN.Value); layerIndex <= Operation.LayerIndexEnd; layerIndex += InputRaiseEveryLayerN.Value)
|
|
{
|
|
SlicerFile.LayerManager.Insert((int)(layerIndex + createdLayers), layer.Clone());
|
|
createdLayers++;
|
|
Progress.ProcessedItems = layerIndex;
|
|
}
|
|
});
|
|
|
|
}
|
|
else
|
|
{
|
|
for (uint layerIndex = Math.Max(1, Operation.LayerIndexStart + InputRaiseEveryLayerN.Value - 1); layerIndex <= Operation.LayerIndexEnd; layerIndex += InputRaiseEveryLayerN.Value)
|
|
{
|
|
var layer = SlicerFile[layerIndex];
|
|
layer.LiftHeightTotal = Math.Max(SlicerFile.LiftHeightTotal, InputPositionZ.Value - layer.PositionZ);
|
|
if (SlicerFile.CanUseLayerWaitTimeAfterLift && InputWaitTime.Value > 0)
|
|
{
|
|
layer.WaitTimeAfterLift = InputWaitTime.Value;
|
|
}
|
|
Progress.ProcessedItems = layerIndex;
|
|
}
|
|
}
|
|
|
|
// return true if not cancelled by user
|
|
return !Progress.Token.IsCancellationRequested;
|
|
}
|
|
}
|
|
}
|