Files
OpenNest/Posts/OpenNest.Posts.CincinnatiCIFiber/CIFiberFormatter.cs
T
aj 82feb78b0f feat(posts): add Cincinnati CI Fiber (TF5200) post-processor
New post-processor plugin OpenNest.Posts.CincinnatiCIFiber for the CI
Fiber laser family (nLight CLX / Beckhoff TF5200 / Precitec ProCutter,
e.g. the CI Fiber 4020 8kW). Named by machine family, not table size.

Emits the machine program contract of the Cincinnati-supplied sample NC
(12992-4SS_NEST.nc): V.E.* header, restart jump, per-part V.E.R4 blocks,
per-contour N labels with V.E.R3, skippable /L macro lines (L0/L2+G41
interior, L4+G42 exterior, L6 cut-on, ZHSOFF cut-end), G162 incremental
arc I/J, trimmed 3-decimal spaceless coordinates, CRLF, M50/M30/%.

Contour classification (interior vs exterior) derives from the material
side of the closed cut path, not hardcoded winding. SubProgramCall holes
are flattened to sheet coordinates (rotation-safe). Arc lead-ins are
rejected per TF5200 13.2.4.1 (first motion block after G41/G42 selection
must be linear). Table envelope (default 160.25 x 81.25 in) validated.

Tests: structure golden on a square-with-hole nest, rotated-hole flatten,
coordinate format, arc-lead-in rejection, table validation, suppressed/
scribe skipping, plus a SkippableFact regression against the real sample
NC (109 parts, 2071 contours, L2=1962, L4=109, perimeter vertices match
within 0.001). Fixtures configure through OpenNest.Tests/test-config.json
and the regression skips when absent.
2026-09-27 04:10:22 -04:00

56 lines
2.0 KiB
C#

using System;
using System.Globalization;
namespace OpenNest.Posts.CincinnatiCIFiber
{
/// <summary>
/// Formats numeric values for the CI Fiber machine program.
/// Coordinates: up to <see cref="PostedAccuracy"/> decimals with trailing
/// zeros trimmed ("3.706", "5.01", "0"), never "-0" (sample NC format).
/// Header values (V.E.*) use fixed decimals.
/// </summary>
public sealed class CIFiberFormatter
{
private readonly int _accuracy;
private readonly string _trimFormat;
private readonly string _fixedFormat;
public CIFiberFormatter(int accuracy)
{
_accuracy = System.Math.Max(0, accuracy);
_trimFormat = _accuracy == 0 ? "0" : "0." + new string('#', _accuracy);
_fixedFormat = _accuracy == 0 ? "0" : "0." + new string('0', _accuracy);
}
/// <summary>
/// Variable-trim coordinate/number format: rounded to the accuracy,
/// trailing zeros removed, "0" for zero, never "-0".
/// </summary>
public string Coord(double value)
{
var rounded = System.Math.Round(value, _accuracy, MidpointRounding.AwayFromZero);
if (rounded == 0.0)
rounded = 0.0; // collapse -0
return rounded.ToString(_trimFormat, CultureInfo.InvariantCulture);
}
/// <summary>Fixed-decimal format for the V.E.* header variables.</summary>
public string Fixed(double value)
{
var rounded = System.Math.Round(value, _accuracy, MidpointRounding.AwayFromZero);
if (rounded == 0.0)
rounded = 0.0;
return rounded.ToString(_fixedFormat, CultureInfo.InvariantCulture);
}
/// <summary>CRLF line writing helper matching the machine sample exactly.</summary>
public static void Line(System.IO.TextWriter w, string text)
{
w.Write(text);
w.Write("\r\n");
}
}
}