mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-03 15:39:26 -05:00
Moves the Drawings tab's row content (quantity, size, area, highlight and quantity bar, the hidden-list note), Delete Drawing, Remove Unused Drawings and the Drawing Properties dialog's values and color rules into OpenNest.Desktop so the Avalonia app can share them. The WinForms list, nest window and Edit Drawing form delegate to them unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
135 lines
4.5 KiB
C#
135 lines
4.5 KiB
C#
using System.Drawing;
|
|
|
|
namespace OpenNest.Desktop.Tests.Drawings;
|
|
|
|
[Collection(ColorSchemeState.Collection)]
|
|
public class DrawingPropertiesTests
|
|
{
|
|
private static Drawing Square(string name = "square")
|
|
{
|
|
var drawing = TestNests.OneSquare().Drawings.First();
|
|
drawing.Name = name;
|
|
return drawing;
|
|
}
|
|
|
|
[Fact]
|
|
public void ReadsTheDrawingsValues()
|
|
{
|
|
var drawing = Square("bracket");
|
|
drawing.Customer = "Acme";
|
|
drawing.Quantity.Required = 5;
|
|
drawing.Priority = 2;
|
|
drawing.CutFirst = true;
|
|
drawing.Source = new SourceInfo { Path = "/parts/bracket.dxf" };
|
|
|
|
var properties = new DrawingProperties(drawing);
|
|
|
|
Assert.Equal("bracket", properties.Name);
|
|
Assert.Equal("Acme", properties.Customer);
|
|
Assert.Equal(5, properties.Quantity);
|
|
Assert.Equal(2, properties.Priority);
|
|
Assert.True(properties.CutFirst);
|
|
Assert.False(properties.AllowCommonLine);
|
|
Assert.False(properties.Formed);
|
|
Assert.Equal("Drawing Properties - bracket", properties.Title);
|
|
Assert.Equal("10 x 10", properties.SizeText);
|
|
Assert.Equal("100", properties.AreaText);
|
|
Assert.Equal("bracket.dxf", properties.SourceText);
|
|
Assert.Equal("/parts/bracket.dxf", properties.SourcePath);
|
|
}
|
|
|
|
[Fact]
|
|
public void WithoutASource_ShowsADash()
|
|
{
|
|
var properties = new DrawingProperties(Square());
|
|
|
|
Assert.Null(properties.SourcePath);
|
|
Assert.Equal("-", properties.SourceText);
|
|
}
|
|
|
|
[Fact]
|
|
public void NestedText_CountsRemainingAgainstTheEditedQuantity()
|
|
{
|
|
var nest = TestNests.OneSquare();
|
|
nest.Plates[0].Quantity = 1;
|
|
nest.UpdateDrawingQuantities();
|
|
var properties = new DrawingProperties(nest.Drawings.First(), nest);
|
|
Assert.Equal("1 nested, 0 remaining", properties.NestedText);
|
|
|
|
properties.Quantity = 4;
|
|
|
|
Assert.Equal("1 nested, 3 remaining", properties.NestedText);
|
|
}
|
|
|
|
[Fact]
|
|
public void OnlyAPickedColorBecomesCustom()
|
|
{
|
|
var drawing = Square();
|
|
drawing.Color = Color.Coral;
|
|
var unchanged = new DrawingProperties(drawing);
|
|
Assert.Equal(DrawingProperties.AutomaticColorText, unchanged.ColorModeText);
|
|
Assert.False(unchanged.CanUseAutomaticColor);
|
|
unchanged.ApplyTo(drawing);
|
|
Assert.False(drawing.HasCustomColor);
|
|
|
|
var picked = new DrawingProperties(drawing);
|
|
picked.PickColor(Color.Red);
|
|
Assert.Equal(DrawingProperties.CustomColorText, picked.ColorModeText);
|
|
Assert.True(picked.CanUseAutomaticColor);
|
|
picked.ApplyTo(drawing);
|
|
|
|
Assert.True(drawing.HasCustomColor);
|
|
Assert.Equal(Color.Red.ToArgb(), drawing.Color.ToArgb());
|
|
}
|
|
|
|
[Fact]
|
|
public void AutomaticColor_ClearsTheCustomColor_WithTheDrawingsPaletteSlot()
|
|
{
|
|
var state = new ColorSchemeState();
|
|
try
|
|
{
|
|
ColorSchemeRegistry.Apply(ColorSchemeRegistry.Get("Classic"));
|
|
var nest = new Nest("Automatic");
|
|
nest.Drawings.Add(new Drawing("First"));
|
|
nest.Drawings.Add(new Drawing("Cutoff") { IsCutOff = true });
|
|
var drawing = new Drawing("Bracket") { Color = Color.Red, HasCustomColor = true };
|
|
nest.Drawings.Add(drawing);
|
|
|
|
var properties = new DrawingProperties(drawing, nest);
|
|
Assert.Equal(DrawingProperties.CustomColorText, properties.ColorModeText);
|
|
|
|
properties.UseAutomaticColor();
|
|
|
|
Assert.Equal(DrawingProperties.AutomaticColorText, properties.ColorModeText);
|
|
Assert.False(properties.CanUseAutomaticColor);
|
|
Assert.True(drawing.HasCustomColor);
|
|
|
|
properties.ApplyTo(drawing);
|
|
|
|
Assert.False(drawing.HasCustomColor);
|
|
Assert.Equal(Drawing.GetPartColor(1).ToArgb(), drawing.Color.ToArgb());
|
|
Assert.Equal(DrawingProperties.AutomaticColorText, new DrawingProperties(drawing, nest).ColorModeText);
|
|
}
|
|
finally
|
|
{
|
|
state.Restore();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void APickedColorCancelsAPendingAutomatic()
|
|
{
|
|
var drawing = Square();
|
|
drawing.Color = Color.Red;
|
|
drawing.HasCustomColor = true;
|
|
var properties = new DrawingProperties(drawing);
|
|
properties.UseAutomaticColor();
|
|
|
|
properties.PickColor(Color.Blue);
|
|
properties.ApplyTo(drawing);
|
|
|
|
Assert.True(drawing.HasCustomColor);
|
|
Assert.Equal(Color.Blue.ToArgb(), drawing.Color.ToArgb());
|
|
}
|
|
}
|