mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-09 01:52:32 +02:00
ea4f7e0400
- **UI:** - (Improvement) Layer navigation load time by parallel `Mat` to `Bitmap` conversion - (Improvement) Allow to show exceptions without the stack trace and detailed trigger action by using the `MessageExceiption` (#644) - (Improvement) Allow progress to have and display a detailed log (#644) - (Improvement) Convert format to another with multiple versions will now only show the possible versions for the extension - **Suggestion - Wait time before cure:** - (Improvement) Set the first wait time based on first valid layer mass rather than use the fixed limit - (Improvement) Set zero time to empty and dummy layers - (Improvement) When creating the dummy layer also increment the bottom layer count as the created layer count as one - **PCB Exposure:** - (Add) Excellon Drill Format (drl) to cut off holes (Implementation may lack some advanced features, please confirm the result) (#646) - (Fix) Arc (G03) with negative offsets (I-/J-) was not drawing the shape correctly - (Fix) Implement the rotation for the outline primitive (#645) - **File formats:** - (Improvement) Formats now sanitize the selected version before encode given the file extension, if version is out of range it will force the last known version - (Fix) CBDDLP: Remove a table from the file that might cause layer corruption - (Add) Operations - `AfterCompleteReport` property: Gets or sets an report to show to the user after complete the operation with success - (Improvement) Suggestion - Wait time after cure: Set zero time to empty and dummy layers - (Improvement) Slight improvement on the contour intersection check, yields better performance on resin and suction cup detection - (Improvement) Allow to trigger message boxes from operations and scripts (#644) - (Upgrade) .NET from 6.0.12 to 6.0.13
141 lines
5.7 KiB
C#
141 lines
5.7 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 Emgu.CV;
|
|
using Emgu.CV.CvEnum;
|
|
using Emgu.CV.Structure;
|
|
using System;
|
|
using System.Drawing;
|
|
using UVtools.Core.Extensions;
|
|
using UVtools.Core.Scripting;
|
|
|
|
namespace UVtools.ScriptSample;
|
|
|
|
/// <summary>
|
|
/// Change layer properties to random values
|
|
/// </summary>
|
|
public class ScriptVATClean : ScriptGlobals
|
|
{
|
|
private readonly ScriptNumericalInput<ushort> InputInset = new()
|
|
{
|
|
Label = "Resolution inset",
|
|
ToolTip = "Inset image resolution by this value to create a black border",
|
|
Unit = "px",
|
|
Minimum = 0,
|
|
Maximum = ushort.MaxValue,
|
|
Increment = 1
|
|
};
|
|
|
|
private readonly ScriptNumericalInput<float> InputExposureTime = new()
|
|
{
|
|
Label = "Exposure time",
|
|
ToolTip = "Time to exposure the layer",
|
|
Unit = "s",
|
|
Minimum = 0,
|
|
Maximum = 50,
|
|
DecimalPlates = 2,
|
|
Increment = 1
|
|
};
|
|
|
|
/// <summary>
|
|
/// Set configurations here, this function trigger just after load a script
|
|
/// </summary>
|
|
public void ScriptInit()
|
|
{
|
|
Script.Name = "Create a file to clean VAT exposing 1 layer";
|
|
Script.Description = "Print this file to clean your VAT by exposing 1 layer and peel it off.\n" +
|
|
"1) Load a file for your printer that you previous printed into UVtools\n" +
|
|
"2) Configure and run this script\n" +
|
|
"3) Go to File -> Save As, and give it a new name\n" +
|
|
"4) Remove head/plate\n" +
|
|
"5) Place a plastic spatula in the VAT at an angle with the handle laying on the top of the VAT frame\n" +
|
|
"6) Print the created file\n" +
|
|
"7) When print finish slowly peel the layer with the spatula";
|
|
Script.Author = "Tiago Conceição";
|
|
Script.Version = new Version(0, 2);
|
|
Script.MinimumVersionToRun = new Version(3, 0, 0);
|
|
|
|
|
|
InputInset.Maximum = (ushort) (Math.Max(SlicerFile.ResolutionX, SlicerFile.ResolutionY) / 2 - 2);
|
|
InputExposureTime.Value = SlicerFile.ExposureTime * 2;
|
|
|
|
Script.UserInputs.Add(InputInset);
|
|
Script.UserInputs.Add(InputExposureTime);
|
|
}
|
|
|
|
/// <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()
|
|
{
|
|
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()
|
|
{
|
|
Progress.Reset("Generating layers", 1); // Sets the progress name and number of items to process
|
|
|
|
var layer = SlicerFile[0];
|
|
layer.PositionZ = SlicerFile.MachineZ; // Send head to top if possible
|
|
|
|
using var mat = EmguExtensions.InitMat(SlicerFile.Resolution);
|
|
CvInvoke.Rectangle(mat, new Rectangle(
|
|
new Point(InputInset.Value, InputInset.Value),
|
|
new Size((int) (SlicerFile.ResolutionX - InputInset.Value*2)-1, (int) (SlicerFile.ResolutionY - InputInset.Value*2)-1)
|
|
), EmguExtensions.WhiteColor, -1, LineType.FourConnected);
|
|
layer.LayerMat = mat;
|
|
|
|
SlicerFile.SuppressRebuildPropertiesWork(() =>
|
|
{
|
|
SlicerFile.BottomLayerCount = 1;
|
|
|
|
SlicerFile.Layers = new[] { layer };
|
|
});
|
|
|
|
SlicerFile.BottomExposureTime =
|
|
SlicerFile.ExposureTime = InputExposureTime.Value;
|
|
|
|
SlicerFile.BottomLiftSpeed =
|
|
SlicerFile.LiftSpeed =
|
|
SlicerFile.RetractSpeed = 200;
|
|
|
|
SlicerFile.BottomLiftHeight =
|
|
SlicerFile.LiftHeight = 1;
|
|
|
|
Progress++;
|
|
|
|
SlicerFile.SetThumbnails(GetThumbnail());
|
|
|
|
// return true if not cancelled by user
|
|
return !Progress.Token.IsCancellationRequested;
|
|
}
|
|
|
|
public Mat GetThumbnail()
|
|
{
|
|
Mat thumbnail = EmguExtensions.InitMat(new Size(400, 200), 3);
|
|
var fontFace = FontFace.HersheyDuplex;
|
|
var fontScale = 1;
|
|
var fontThickness = 2;
|
|
const byte xSpacing = 45;
|
|
const byte ySpacing = 45;
|
|
CvInvoke.PutText(thumbnail, "UVtools", new Point(140, 35), fontFace, fontScale, new MCvScalar(255, 27, 245), fontThickness + 1);
|
|
CvInvoke.Line(thumbnail, new Point(xSpacing, 0), new Point(xSpacing, ySpacing + 5), new MCvScalar(255, 27, 245), 3);
|
|
CvInvoke.Line(thumbnail, new Point(xSpacing, ySpacing + 5), new Point(thumbnail.Width - xSpacing, ySpacing + 5), new MCvScalar(255, 27, 245), 3);
|
|
CvInvoke.Line(thumbnail, new Point(thumbnail.Width - xSpacing, 0), new Point(thumbnail.Width - xSpacing, ySpacing + 5), new MCvScalar(255, 27, 245), 3);
|
|
CvInvoke.PutText(thumbnail, "VAT Clean Utility", new Point(xSpacing, ySpacing * 2), fontFace, fontScale, new MCvScalar(0, 255, 255), fontThickness);
|
|
CvInvoke.PutText(thumbnail, $"Exposure time: {SlicerFile.ExposureTime}s", new Point(xSpacing, ySpacing * 3), fontFace, fontScale, EmguExtensions.WhiteColor, fontThickness);
|
|
CvInvoke.PutText(thumbnail, $"Use the spatula in!", new Point(xSpacing, ySpacing * 4), fontFace, fontScale, EmguExtensions.WhiteColor, fontThickness);
|
|
|
|
return thumbnail;
|
|
}
|
|
} |