Files
OpenNest/Posts/OpenNest.Posts.Cincinnati/CincinnatiPreambleWriter.cs
T
ajandClaude Opus 5.5 2b3f8e7b52 fix(posts): Cincinnati CL sub-program frames, head raises and dead settings
Part sub-program calls restored the sheet frame with G92 at the part
corner while the tool sat at the sub-program's last endpoint, shifting
every later part. The call now raises the head, rapids back to local 0,0
and restores there. Parts share a sub-program only when their posted
toolpaths match, so per-part lead-ins are kept.

Suppressed moves are left uncut: the cut resumes with a rapid past them.

Head raises go before the rapid that leaves a feature, one per rapid:
the safety raise now precedes the rapid to a new part instead of
following its first feature, and sub-program mode no longer posts M47
then M47 P2000. M47Mode.Auto posts M47 before rapids longer than
M47OverrideDistanceThreshold and /M47 otherwise. ExteriorM47 applies to
the contour spanning the part's cut extents.

The sheet GOTO targets FeatureLineNumberStart and is omitted without line
numbers. PrepareForNest pre-selects only the gas- and thickness-matching
library. Part programs are read through absolute copies, never switched
to absolute in place.

Removes the unimplemented UseSheetSubprograms, CoordModeBetweenParts and
ProcessParameterMode (G89Mode); old configs still load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 01:56:28 -04:00

100 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using OpenNest;
using OpenNest.CNC;
namespace OpenNest.Posts.Cincinnati;
/// <summary>
/// Emits the main program header and variable declaration subprogram
/// for a Cincinnati laser post-processor output file.
/// </summary>
public sealed class CincinnatiPreambleWriter
{
private readonly CincinnatiPostConfig _config;
public CincinnatiPreambleWriter(CincinnatiPostConfig config)
{
_config = config;
}
/// <summary>
/// Writes the main program header block.
/// </summary>
/// <param name="initialLibrary">Resolved G89 library file for the initial process setup.</param>
public void WriteMainProgram(
TextWriter w,
string nestName,
string materialDescription,
List<Plate> plates,
string initialLibrary
)
{
w.WriteLine(CoordinateFormatter.Comment($"NEST {nestName}"));
w.WriteLine(CoordinateFormatter.Comment($"CONFIGURATION - {_config.ConfigurationName}"));
w.WriteLine(
CoordinateFormatter.Comment(
DateTime.Now.ToString(
"MM-dd-yyyy hh:mm:ss tt",
System.Globalization.CultureInfo.InvariantCulture
)
)
);
if (!string.IsNullOrEmpty(materialDescription))
w.WriteLine(CoordinateFormatter.Comment($"Material = {materialDescription}"));
if (_config.UseExactStopMode)
w.WriteLine("G61");
w.WriteLine(CoordinateFormatter.Comment("MAIN PROGRAM"));
w.WriteLine(_config.PostedUnits == Units.Millimeters ? "G21 G90" : "G20 G90");
if (_config.UseSmartRapids)
w.WriteLine("G121 (SMART RAPIDS)");
w.WriteLine("M42");
if (!string.IsNullOrEmpty(initialLibrary))
w.WriteLine($"G89 P{initialLibrary}");
w.WriteLine($"M98 P{_config.VariableDeclarationSubprogram} (Variable Declaration)");
if (_config.PalletExchange == PalletMode.StartAndEnd)
w.WriteLine("M50");
w.WriteLine("GOTO1 (GOTO SHEET NUMBER)");
for (var i = 0; i < plates.Count; i++)
{
var layoutNumber = i + 1;
var subNum = _config.SheetSubprogramStart + i;
var qty = System.Math.Max(plates[i].Quantity, 1);
var lParam = qty > 1 ? $" L{qty}" : "";
var sheetLabel =
qty > 1 ? $"LAYOUT {layoutNumber} - {qty} SHEETS" : $"LAYOUT {layoutNumber}";
w.WriteLine($"N{layoutNumber} M98 P{subNum}{lParam} ({sheetLabel})");
}
w.WriteLine("M42");
w.WriteLine("M30 (END OF MAIN)");
}
/// <summary>
/// Writes the variable declaration subprogram block.
/// </summary>
public void WriteVariableDeclaration(TextWriter w, ProgramVariableManager vars)
{
w.WriteLine("(*****************************************************)");
w.WriteLine($":{_config.VariableDeclarationSubprogram}");
w.WriteLine("(Variable Declaration Start)");
foreach (var line in vars.EmitDeclarations())
w.WriteLine(line);
w.WriteLine("M99 (Variable Declaration End)");
}
}