Files
UVtools/UVtools.Core/Gerber/Primitives/VectorLinePrimitive.cs
T
Tiago Conceição 816898836b v3.9.0
- **File formats:**
  - (Add) File extension: .gktwo.ctb to `ChituboxFile` to be able to convert files for UniFormation GKtwo under special CTB format
  - (Add) UniFormation GKtwo compatibility under CTB format, if exporting JXS rename to CTB before open
  - (Fix) CTB, CBDDLP, PHOTON, FDG, PHZ: Read and write files larger then 4GB (#608)
- **PCB Exposure:**
  - (Add) Offset X/Y to offset the PCB from it origin
  - (Add) Allow to toggle between "Show preview image cropped by it bounds" and "Show full preview image (The final result)"
  - (Improvement) Use rectangle instead of line for center line primitive (#607)
  - (Fix) Implement rotation to polygon and center line primitives (#607)
  - (Fix) Macros in a single line was not being parsed (#607)
  - (Fix) Invert color per file was not affecting primitives
- **Network printers:**
  - (Add) Socket requests with TCP and UDP
  - (Add) AnyCubic printer preset (However it can't upload a file)
  - (Add) Scripts in request path to allow a first request to fetch data to the final request:
    -  A script starts with **<\?** and ends with **?>**
    -  First parameter is the first request to get response content from
    -  Second parameter is the regex pattern to match content with
    -  Third parameter is the final request that supports a parameter from regex matching group, eg: **{#1}** is match Group[1] value
    -  **Example:** <\? getfiles > {0}\/(\d+\.[\da-zA-Z]+), > printfile,{#1} ?>
  - (Change) Allow to print a filename without send it when upload request path is empty
  - (Fix) Do not show printers with empty requests
- (Change) Default layer compression to Lz4 instead of Png
- (Improvement) Application is now culture aware but set part of `NumberFormat` to the `InvariantCulture.NumberFormat`
- (Improvement) Material cost now show with the current culture currency symbol due previous change
- (Improvement) Better submit of bug reports using sections and forms
- (Improvement) Linux: AppImage now have a help manual with possible arguments and parameters
- (Improvement) macOS: Codesign app on auto-installer and auto-upgrade to bypass arm64 run restriction (#431)
- (Improvement) macOS: Rebuilt arm64 libcvextern.dylib to run with less dependencies (#431)
- (Improvement) macOS: Try to show missing dependencies from openCV (if any) on the error message
- (Fix) UI: layers sorted lexicographically instead of numerically in the issues list view (#611)
- (Fix) PrusaSlicer printer parameters: UniFormation GKtwo
2022-12-01 04:27:44 +00:00

191 lines
6.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.Data;
using System.Drawing;
using System.Globalization;
using System.Text.RegularExpressions;
using Emgu.CV;
using Emgu.CV.CvEnum;
using UVtools.Core.Extensions;
namespace UVtools.Core.Gerber.Primitives;
/// <summary>
/// A vector line is a rectangle defined by its line width, start and end points. The line ends are rectangular.
/// </summary>
public class VectorLinePrimitive : Primitive
{
#region Constants
public const byte Code = 20;
#endregion
#region Properties
public override string Name => "VectorLine";
/// <summary>
/// Exposure off/on (0/1)
/// 1
/// </summary>
public string ExposureExpression { get; set; } = "1";
public byte Exposure { get; set; } = 1;
/// <summary>
/// Width of the line ≥ 0
/// 2
/// </summary>
public string LineWidthExpression { get; set; } = "0";
public float LineWidth { get; set; }
/// <summary>
/// Start point X coordinate
/// 3
/// </summary>
public string StartXExpression { get; set; } = "0";
public float StartX { get; set; }
/// <summary>
/// Start point Y coordinate
/// 4
/// </summary>
public string StartYExpression { get; set; } = "0";
public float StartY { get; set; }
/// <summary>
/// End point X coordinate
/// 5
/// </summary>
public string EndXExpression { get; set; } = "0";
public float EndX { get; set; }
/// <summary>
/// Start point Y coordinate
/// 6
/// </summary>
public string EndYExpression { get; set; } = "0";
public float EndY { get; set; }
/// <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.
/// 7
/// </summary>
public string RotationExpression { get; set; } = "0";
public float Rotation { get; set; } = 0;
#endregion
protected VectorLinePrimitive(GerberDocument document) : base(document) { }
public VectorLinePrimitive(GerberDocument document, string exposureExpression, string lineWidthExpression, string startXExpression, string startYExpression, string endXExpression, string endYExpression, string rotationExpression = "0") : base(document)
{
ExposureExpression = exposureExpression;
LineWidthExpression = lineWidthExpression;
StartXExpression = startXExpression;
StartYExpression = startYExpression;
EndXExpression = endXExpression;
EndYExpression = endYExpression;
RotationExpression = rotationExpression;
}
public override void DrawFlashD3(Mat mat, PointF at, LineType lineType = LineType.EightConnected)
{
if (!IsParsed) return;
if (LineWidth <= 0) 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 pt1 = Document.PositionMmToPx(at.X + StartX, at.Y + StartY);
var pt2 = Document.PositionMmToPx(at.X + EndX, at.Y + EndY);
CvInvoke.Line(mat, pt1, pt2, Document.GetPolarityColor(Exposure), EmguExtensions.CorrectThickness(Document.SizeMmToPxOverride(LineWidth, Document.XYppmm.Height)), lineType);
//CvInvoke.Rectangle(mat, rectangle, color, -1, 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);
}
if (float.TryParse(LineWidthExpression, NumberStyles.Float, CultureInfo.InvariantCulture, out num)) LineWidth = num;
else
{
csharpExp = Regex.Replace(LineWidthExpression, @"\$(\d+)", "{$1}");
csharpExp = string.Format(csharpExp, args);
var temp = exp.Compute(csharpExp, null);
if (temp is not DBNull) LineWidth = Convert.ToSingle(temp);
}
LineWidth = Document.GetMillimeters(LineWidth);
if (float.TryParse(StartXExpression, NumberStyles.Float, CultureInfo.InvariantCulture, out num)) StartX = num;
else
{
csharpExp = Regex.Replace(StartXExpression, @"\$(\d+)", "{$1}");
csharpExp = string.Format(csharpExp, args);
var temp = exp.Compute(csharpExp, null);
if (temp is not DBNull) StartX = Convert.ToSingle(temp);
}
StartX = Document.GetMillimeters(StartX);
if (float.TryParse(EndXExpression, NumberStyles.Float, CultureInfo.InvariantCulture, out num)) EndX = num;
else
{
csharpExp = Regex.Replace(EndXExpression, @"\$(\d+)", "{$1}");
csharpExp = string.Format(csharpExp, args);
var temp = exp.Compute(csharpExp, null);
if (temp is not DBNull) EndX = Convert.ToSingle(temp);
}
EndX = Document.GetMillimeters(EndX);
if (float.TryParse(StartYExpression, NumberStyles.Float, CultureInfo.InvariantCulture, out num)) StartY = num;
else
{
csharpExp = Regex.Replace(StartYExpression, @"\$(\d+)", "{$1}");
csharpExp = string.Format(csharpExp, args);
var temp = exp.Compute(csharpExp, null);
if (temp is not DBNull) StartY = Convert.ToSingle(temp);
}
StartY = Document.GetMillimeters(StartY);
if (float.TryParse(EndYExpression, NumberStyles.Float, CultureInfo.InvariantCulture, out num)) EndY = num;
else
{
csharpExp = Regex.Replace(EndYExpression, @"\$(\d+)", "{$1}");
csharpExp = string.Format(csharpExp, args);
var temp = exp.Compute(csharpExp, null);
if (temp is not DBNull) EndY = Convert.ToSingle(temp);
}
EndY = Document.GetMillimeters(EndY);
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;
}
}