mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-27 20:51:06 -04:00
- Add Drawing.HasCustomColor, set when a color is picked in Drawing Properties or comes from a library record with a stored color. - Persist it as customColor in .nest files (omitted when false) and keep it out of drawing packages; split pieces inherit it. - Recolor non-custom drawings from the active palette when a nest opens and when the scheme changes; custom colors keep their palette slot. - Library settings store a color only when it is custom. - Document drawing colors in nest-file-format.md and nesting-view-colors.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.3 KiB
C#
62 lines
2.3 KiB
C#
using System.Drawing;
|
|
using OpenNest.Forms;
|
|
|
|
namespace OpenNest.WinForms.Tests;
|
|
|
|
[Collection("Fill operation lifetime")]
|
|
public class CustomDrawingColorTests
|
|
{
|
|
[Fact]
|
|
public void RecolorKeepsCustomColorsInTheirSlotsAndSkipsCutoffs()
|
|
{
|
|
var previous = ColorSchemeSerializer.Deserialize(ColorSchemeSerializer.Serialize(ColorScheme.Default));
|
|
try
|
|
{
|
|
ColorSchemeRegistry.Apply(ColorSchemeRegistry.Get("Classic"));
|
|
var nest = new Nest("Recolor");
|
|
var first = new Drawing("First") { Color = Color.Coral };
|
|
var custom = new Drawing("Custom") { Color = Color.Red, HasCustomColor = true };
|
|
var cutoff = new Drawing("Cutoff") { IsCutOff = true, Color = Color.Gray };
|
|
var third = new Drawing("Third") { Color = Color.Coral };
|
|
nest.Drawings.Add(first);
|
|
nest.Drawings.Add(custom);
|
|
nest.Drawings.Add(cutoff);
|
|
nest.Drawings.Add(third);
|
|
|
|
ColorSchemeRegistry.RecolorDrawings(nest);
|
|
|
|
Assert.Equal(Drawing.GetPartColor(0), first.Color);
|
|
Assert.Equal(Color.Red, custom.Color);
|
|
Assert.Equal(Color.Gray, cutoff.Color);
|
|
Assert.Equal(Drawing.GetPartColor(2), third.Color);
|
|
}
|
|
finally
|
|
{
|
|
ColorSchemeRegistry.Apply(previous);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void DrawingPropertiesMarksOnlyAChangedColorAsCustom() => StaTestThread.Run(() =>
|
|
{
|
|
var drawing = new Drawing("Bracket") { Color = Color.Coral };
|
|
using (var unchanged = new EditDrawingForm())
|
|
{
|
|
unchanged.LoadDrawing(drawing);
|
|
unchanged.SaveDrawing(drawing);
|
|
}
|
|
Assert.False(drawing.HasCustomColor);
|
|
|
|
using var picked = new EditDrawingForm();
|
|
picked.LoadDrawing(drawing);
|
|
var dialog = (System.Windows.Forms.ColorDialog)typeof(EditDrawingForm)
|
|
.GetField("colorDialog1", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)!
|
|
.GetValue(picked)!;
|
|
dialog.Color = Color.Red;
|
|
picked.SaveDrawing(drawing);
|
|
|
|
Assert.True(drawing.HasCustomColor);
|
|
Assert.Equal(Color.Red.ToArgb(), drawing.Color.ToArgb());
|
|
}, TimeSpan.FromMinutes(1), "Drawing properties color test timed out.");
|
|
}
|