mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 12:11:34 -05:00
Selecting parts on the plate selects their drawing in the nest window's drawing list when they all share one; a mixed or empty selection, or a drawing the list hides, leaves the list's selection as it was. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.0 KiB
C#
62 lines
2.0 KiB
C#
using OpenNest.Controls;
|
|
using OpenNest.Geometry;
|
|
using Size = OpenNest.Geometry.Size;
|
|
|
|
namespace OpenNest.WinForms.Tests.Forms;
|
|
|
|
/// <summary>Selecting parts on the plate selects their drawing in the drawing list.</summary>
|
|
public class DrawingListSelectionSyncTests
|
|
{
|
|
private static Nest TwoDrawingNest()
|
|
{
|
|
var nest = new Nest("sync");
|
|
var a = new Drawing("a", UndoTestEnv.Square(10));
|
|
var b = new Drawing("b", UndoTestEnv.Square(12));
|
|
nest.Drawings.Add(a);
|
|
nest.Drawings.Add(b);
|
|
var plate = nest.CreatePlate();
|
|
plate.Size = new Size(100, 100);
|
|
plate.Parts.Add(new Part(a, new Vector(5, 5)));
|
|
plate.Parts.Add(new Part(b, new Vector(40, 5)));
|
|
return nest;
|
|
}
|
|
|
|
private static DrawingListBox List(UndoTestEnv env) =>
|
|
(DrawingListBox)Assert.Single(env.Editor.Controls.Find("drawingListBox1", true));
|
|
|
|
private static void Select(UndoTestEnv env, params string[] drawings)
|
|
{
|
|
env.View.DeselectAll();
|
|
foreach (var layout in env.View.LayoutParts.Where(p => drawings.Contains(p.BasePart.BaseDrawing.Name)))
|
|
env.View.SelectedParts.Add(layout);
|
|
env.View.NotifySelectionChanged();
|
|
}
|
|
|
|
[Fact]
|
|
public void SelectingAPartSelectsItsDrawing() => UndoTestEnv.Run(env =>
|
|
{
|
|
env.Editor.PlateManager.LoadAt(0);
|
|
var list = List(env);
|
|
|
|
Select(env, "b");
|
|
Assert.Equal("b", ((Drawing)list.SelectedItem!).Name);
|
|
|
|
Select(env, "a");
|
|
Assert.Equal("a", ((Drawing)list.SelectedItem!).Name);
|
|
}, TwoDrawingNest);
|
|
|
|
[Fact]
|
|
public void MixedOrEmptySelectionKeepsTheListSelection() => UndoTestEnv.Run(env =>
|
|
{
|
|
env.Editor.PlateManager.LoadAt(0);
|
|
var list = List(env);
|
|
|
|
Select(env, "b");
|
|
Select(env, "a", "b");
|
|
Assert.Equal("b", ((Drawing)list.SelectedItem!).Name);
|
|
|
|
Select(env);
|
|
Assert.Equal("b", ((Drawing)list.SelectedItem!).Name);
|
|
}, TwoDrawingNest);
|
|
}
|