mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-12 19:42: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
158 lines
5.7 KiB
C#
158 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.Util;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using UVtools.Core.Extensions;
|
|
|
|
namespace UVtools.Core.Gerber.Primitives;
|
|
|
|
/// <summary>
|
|
/// An outline primitive is an area defined by its outline or contour.
|
|
/// The outline is a polygon, consisting of linear segments only, defined by its start vertex and n subsequent vertices.
|
|
/// The outline must be closed, i.e. the last vertex must be equal to the start vertex.
|
|
/// The outline must comply with all the requirements of a contour according to 4.10.3.
|
|
/// </summary>
|
|
public class OutlinePrimitive : Primitive
|
|
{
|
|
#region Constants
|
|
public const byte Code = 4;
|
|
#endregion
|
|
|
|
#region Properties
|
|
public override string Name => "Outline";
|
|
|
|
/// <summary>
|
|
/// Exposure off/on (0/1)
|
|
/// 1
|
|
/// </summary>
|
|
public string ExposureExpression { get; set; } = "1";
|
|
public byte Exposure { get; set; } = 1;
|
|
|
|
/// <summary>
|
|
/// The number of vertices of the outline = the number of coordinate pairs minus one. An integer ≥3.
|
|
/// 2
|
|
/// </summary>
|
|
public string VerticesCountExpression { get; set; } = string.Empty;
|
|
public ushort VerticesCount => (ushort) Coordinates.Length;
|
|
|
|
/// <summary>
|
|
/// subsequent X and Y coordinates.
|
|
/// The X and Y coordinates are not modal: both X and Y must be specified for all points.
|
|
/// 2+n
|
|
/// </summary>
|
|
public string[] CoordinatesExpression { get; set; } = Array.Empty<string>();
|
|
|
|
public PointF[] Coordinates { get; set; } = Array.Empty<PointF>();
|
|
|
|
/// <summary>
|
|
/// Rotation angle, in degrees counterclockwise, a decimal.
|
|
/// The primitive is rotated around the origin of the macro definition, i.e. the (0, 0) point of macro coordinates.
|
|
/// </summary>
|
|
public string RotationExpression { get; set; } = "0";
|
|
public float Rotation { get; set; } = 0;
|
|
#endregion
|
|
|
|
protected OutlinePrimitive(GerberFormat document) : base(document) { }
|
|
|
|
public OutlinePrimitive(GerberFormat document, string exposureExpression, string[] coordinatesExpression, string rotationExpression) : base(document)
|
|
{
|
|
ExposureExpression = exposureExpression;
|
|
CoordinatesExpression = coordinatesExpression;
|
|
RotationExpression = rotationExpression;
|
|
}
|
|
|
|
|
|
public override void DrawFlashD3(Mat mat, PointF at, LineType lineType = LineType.EightConnected)
|
|
{
|
|
if (Coordinates.Length < 3) return;
|
|
|
|
if (Rotation != 0)
|
|
{
|
|
//throw new NotImplementedException($"{Name} primitive with code {Code} have a rotation value of {Rotation} which is not implemented. Open a issue regarding this problem and provide a sample file to be able to implement rotation correctly on this primitive.");
|
|
}
|
|
|
|
var points = new List<Point>();
|
|
for (int i = 0; i < Coordinates.Length-1; i++)
|
|
{
|
|
var point = new PointF(at.X + Coordinates[i].X, at.Y + Coordinates[i].Y).Rotate(-Rotation, at);
|
|
var pt = Document.PositionMmToPx(point);
|
|
if(points.Count > 0 && points[^1] == pt) continue; // Prevent series of duplicates
|
|
points.Add(pt);
|
|
}
|
|
|
|
using var vec = new VectorOfPoint(points.ToArray());
|
|
CvInvoke.FillPoly(mat, vec, Document.GetPolarityColor(Exposure), lineType);
|
|
}
|
|
|
|
public override void ParseExpressions(params string[] args)
|
|
{
|
|
string csharpExp;
|
|
float num;
|
|
var exp = new DataTable();
|
|
|
|
if (byte.TryParse(ExposureExpression, out var exposure)) Exposure = exposure;
|
|
else
|
|
{
|
|
csharpExp = string.Format(Regex.Replace(ExposureExpression, @"\$(\d+)", "{$1}"), args);
|
|
var temp = exp.Compute(csharpExp, null);
|
|
if (temp is not DBNull) Exposure = Convert.ToByte(temp);
|
|
}
|
|
|
|
float? x = null;
|
|
var coordinates = new List<PointF>();
|
|
foreach (var coordinate in CoordinatesExpression)
|
|
{
|
|
if (!float.TryParse(coordinate, NumberStyles.Float, CultureInfo.InvariantCulture, out num))
|
|
{
|
|
csharpExp = string.Format(Regex.Replace(coordinate, @"\$(\d+)", "{$1}"), args);
|
|
var temp = exp.Compute(csharpExp, null);
|
|
if (temp is not DBNull) num = Convert.ToSingle(temp);
|
|
}
|
|
|
|
if (x is null)
|
|
{
|
|
x = num;
|
|
}
|
|
else
|
|
{
|
|
coordinates.Add(Document.GetMillimeters(new PointF(x.Value, num)));
|
|
x = null;
|
|
}
|
|
}
|
|
|
|
Coordinates = coordinates.ToArray();
|
|
|
|
if (float.TryParse(RotationExpression, NumberStyles.Float, CultureInfo.InvariantCulture, out num)) Rotation = (short)num;
|
|
else
|
|
{
|
|
csharpExp = Regex.Replace(RotationExpression, @"\$(\d+)", "{$1}");
|
|
csharpExp = string.Format(csharpExp, args);
|
|
var temp = exp.Compute(csharpExp, null);
|
|
if (temp is not DBNull) Rotation = Convert.ToSingle(temp);
|
|
}
|
|
|
|
IsParsed = true;
|
|
}
|
|
|
|
public override Primitive Clone()
|
|
{
|
|
var primitive = MemberwiseClone() as OutlinePrimitive;
|
|
primitive!.CoordinatesExpression = primitive.CoordinatesExpression.ToArray();
|
|
primitive.Coordinates = primitive.Coordinates.ToArray();
|
|
return primitive;
|
|
}
|
|
} |