Files
OpenNest/OpenNest.WinForms.Tests/Forms/AutoNestFormRotationTests.cs
T
ajandClaude Opus 5.5 96d8a6874f fix(autonest): show part rotation limits in degrees
The Rot Start, Rot End and Step columns showed the drawing's radian
constraints as-is, so users had to type 1.5708 for 90 degrees. The grid now
shows and accepts degrees; rows keep the radian values, so an unedited row
passes the drawing's limits to the engine without a conversion round trip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 07:10:59 -04:00

54 lines
2.1 KiB
C#

using System.Windows.Forms;
using OpenNest.CNC;
using OpenNest.Forms;
namespace OpenNest.WinForms.Tests.Forms;
public class AutoNestFormRotationTests
{
[Fact]
public void RotationColumnsShowDegreesAndNestItemsKeepRadians()
{
RunSta(() =>
{
var drawing = new Drawing("grain", new Program()) { Quantity = { Required = 2 } };
drawing.Constraints.StartAngle = 0;
drawing.Constraints.EndAngle = System.Math.PI / 2;
drawing.Constraints.StepAngle = System.Math.PI / 2;
var nest = new Nest();
nest.Drawings.Add(drawing);
using var form = new AutoNestForm(nest);
var grid = GetGrid(form);
Assert.Equal(0.0, grid.Rows[0].Cells[Column(grid, "RotationStart")].Value);
Assert.Equal(90.0, grid.Rows[0].Cells[Column(grid, "RotationEnd")].Value);
Assert.Equal(90.0, grid.Rows[0].Cells[Column(grid, "StepAngle")].Value);
var item = Assert.Single(form.GetNestItems());
Assert.Equal(System.Math.PI / 2, item.RotationEnd);
Assert.Equal(System.Math.PI / 2, item.StepAngle);
grid.Rows[0].Cells[Column(grid, "RotationEnd")].Value = 180.0;
grid.Rows[0].Cells[Column(grid, "StepAngle")].Value = 45.0;
item = Assert.Single(form.GetNestItems());
Assert.Equal(System.Math.PI, item.RotationEnd, 12);
Assert.Equal(System.Math.PI / 4, item.StepAngle, 12);
});
}
private static DataGridView GetGrid(AutoNestForm form)
{
// Binding needs a context even when the test does not show the form.
form.BindingContext = new BindingContext();
var grid = Assert.IsType<DataGridView>(form.Controls.Find("partsGrid", true).Single());
grid.CreateControl();
return grid;
}
private static int Column(DataGridView grid, string property) =>
grid.Columns.Cast<DataGridViewColumn>().Single(c => c.DataPropertyName == property).Index;
private static void RunSta(Action action) =>
StaTestThread.Run(action, TimeSpan.FromSeconds(15), "The STA test did not complete.");
}