mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-28 21:51:06 -04:00
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>
54 lines
2.1 KiB
C#
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.");
|
|
}
|