fix: Cincinnati post processor arc feedrate, G89 spacing, pallet exchange, and preamble

- Add radius-based arc feedrate calculation (Variables/Percentages modes)
  with configurable radius ranges (#123/#124/#125 or inline expressions)
- Fix arc distance in SpeedClassifier using actual arc length instead of
  chord length (full circles previously computed as zero)
- Fix G89 P spacing: P now adjacent to filename per CL-707 manual syntax
- Add lead-out feedrate support (#129) and arc lead-in feedrate (#127)
- Fix pallet exchange: StartAndEnd emits M50 in preamble + last sheet only
- Add G121 Smart Rapids emission when UseSmartRapids is enabled
- Add G90 absolute mode to main program preamble alongside G20/G21

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-30 09:33:50 -04:00
parent 722f758e94
commit 3d4204db7b
10 changed files with 515 additions and 22 deletions

View File

@@ -32,7 +32,7 @@ public class CincinnatiSheetWriterTests
Assert.Contains("#110=", output);
Assert.Contains("#111=", output);
Assert.Contains("G92 X#5021 Y#5022", output);
Assert.Contains("G89 P MS135N2PANEL.lib", output);
Assert.Contains("G89 PMS135N2PANEL.lib", output);
Assert.Contains("M99", output);
}
@@ -137,9 +137,110 @@ public class CincinnatiSheetWriterTests
Assert.True(g85Idx < g84Idx, "G85 (etch) should come before G84 (cut)");
// Etch uses etch library
Assert.Contains("G89 P EtchN2.lib", output);
Assert.Contains("G89 PEtchN2.lib", output);
// Cut uses cut library
Assert.Contains("G89 P MS250O2.lib", output);
Assert.Contains("G89 PMS250O2.lib", output);
}
[Fact]
public void WriteSheet_StartAndEnd_NoM50OnNonLastSheet()
{
var config = new CincinnatiPostConfig
{
PalletExchange = PalletMode.StartAndEnd,
PostedAccuracy = 4
};
var plate = new Plate(48.0, 96.0);
plate.Parts.Add(new Part(new Drawing("TestPart", CreateSimpleProgram())));
var sb = new StringBuilder();
using var sw = new StringWriter(sb);
var sheetWriter = new CincinnatiSheetWriter(config, new ProgramVariableManager());
sheetWriter.Write(sw, plate, "TestNest", 1, 101, "", "", isLastSheet: false);
var output = sb.ToString();
Assert.DoesNotContain("M50", output);
}
[Fact]
public void WriteSheet_StartAndEnd_M50OnLastSheet()
{
var config = new CincinnatiPostConfig
{
PalletExchange = PalletMode.StartAndEnd,
PostedAccuracy = 4
};
var plate = new Plate(48.0, 96.0);
plate.Parts.Add(new Part(new Drawing("TestPart", CreateSimpleProgram())));
var sb = new StringBuilder();
using var sw = new StringWriter(sb);
var sheetWriter = new CincinnatiSheetWriter(config, new ProgramVariableManager());
sheetWriter.Write(sw, plate, "TestNest", 1, 101, "", "", isLastSheet: true);
var output = sb.ToString();
Assert.Contains("M50", output);
}
[Fact]
public void WriteSheet_EndOfSheet_AlwaysEmitsM50()
{
var config = new CincinnatiPostConfig
{
PalletExchange = PalletMode.EndOfSheet,
PostedAccuracy = 4
};
var plate = new Plate(48.0, 96.0);
plate.Parts.Add(new Part(new Drawing("TestPart", CreateSimpleProgram())));
var sb = new StringBuilder();
using var sw = new StringWriter(sb);
var sheetWriter = new CincinnatiSheetWriter(config, new ProgramVariableManager());
sheetWriter.Write(sw, plate, "TestNest", 1, 101, "", "", isLastSheet: false);
var output = sb.ToString();
Assert.Contains("M50", output);
}
[Fact]
public void ComputeArcLength_FullCircle_Returns2PiR()
{
var start = new Vector(10.0, 20.0);
var arc = new ArcMove(new Vector(10.0, 20.0), new Vector(15.0, 20.0), RotationType.CW);
var length = FeatureUtils.ComputeArcLength(start, arc);
// Radius = 5, full circle = 2 * PI * 5 ≈ 31.416
Assert.Equal(2.0 * System.Math.PI * 5.0, length, 4);
}
[Fact]
public void ComputeArcLength_Semicircle_ReturnsPiR()
{
// Semicircle from (0,0) to (10,0) with center at (5,0), CCW → goes through (5,5)
var start = new Vector(0.0, 0.0);
var arc = new ArcMove(new Vector(10.0, 0.0), new Vector(5.0, 0.0), RotationType.CCW);
var length = FeatureUtils.ComputeArcLength(start, arc);
// Radius = 5, semicircle = PI * 5 ≈ 15.708
Assert.Equal(System.Math.PI * 5.0, length, 4);
}
[Fact]
public void ComputeCutDistance_WithArcs_UsesArcLengthNotChord()
{
// Full circle: chord = 0 but arc length = 2πr
var codes = new List<ICode>
{
new RapidMove(10.0, 20.0),
new ArcMove(new Vector(10.0, 20.0), new Vector(15.0, 20.0), RotationType.CW) { Layer = LayerType.Cut }
};
var distance = FeatureUtils.ComputeCutDistance(codes);
// Full circle with R=5 → 2πr ≈ 31.416
Assert.True(distance > 30.0, $"Expected arc length > 30 but got {distance}");
}
[Fact]