mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-12 17:01:09 -05:00
fix(avalonia): keep default view toggles out of settings and copy boxes for drawing
Write PlateViewDrawRapid/PlateViewDrawBounds only when changed from the default or already saved, as the WinForms settings provider does, so a later default change still applies. Give the render thread a copy of a broken common-line part's box, and prune the label-point cache with the part paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f0bd24534
commit
f146cf63f5
3 files changed
+42
-4
No files matched your search
@@ -98,11 +98,15 @@ namespace OpenNest.Avalonia.Controls
|
||||
if (plate == null)
|
||||
{
|
||||
paths.Clear();
|
||||
labelPoints.Clear();
|
||||
return;
|
||||
}
|
||||
var shown = new HashSet<Part>(plate.Parts);
|
||||
foreach (var stale in paths.Keys.Where(part => !shown.Contains(part)).ToList())
|
||||
paths.Remove(stale);
|
||||
var drawings = new HashSet<Drawing>(plate.Parts.Select(part => part.BaseDrawing));
|
||||
foreach (var stale in labelPoints.Keys.Where(drawing => !drawings.Contains(drawing)).ToList())
|
||||
labelPoints.Remove(stale);
|
||||
}
|
||||
|
||||
public void ZoomToFit()
|
||||
@@ -263,7 +267,11 @@ namespace OpenNest.Avalonia.Controls
|
||||
foreach (var path in CommonLineGeometry.Paths(cached.Check.Spans, group.Kerf))
|
||||
scene.CommonLines.Add(path.Points);
|
||||
foreach (var problem in cached.Check.Problems)
|
||||
scene.CommonLineProblems.Add(problem.Part.BoundingBox);
|
||||
{
|
||||
// A copy: moving the part changes its box in place while the render thread draws.
|
||||
var box = problem.Part.BoundingBox;
|
||||
scene.CommonLineProblems.Add(new Box(box.X, box.Y, box.Length, box.Width));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -255,6 +255,25 @@ public class PlateViewOptionsTests
|
||||
Assert.False(read.DrawSupport);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Untouched_defaults_stay_out_of_the_settings()
|
||||
{
|
||||
var settings = new Dictionary<string, string> { ["Other"] = "kept" };
|
||||
new PlateViewOptions().WriteTo(settings);
|
||||
|
||||
Assert.Single(settings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_saved_toggle_set_back_to_its_default_is_written()
|
||||
{
|
||||
var settings = new Dictionary<string, string> { ["PlateViewDrawRapid"] = "True" };
|
||||
new PlateViewOptions().WriteTo(settings);
|
||||
|
||||
Assert.Equal("False", settings["PlateViewDrawRapid"]);
|
||||
Assert.False(settings.ContainsKey("PlateViewDrawBounds"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Unreadable_values_are_defaults()
|
||||
{
|
||||
|
||||
@@ -45,11 +45,22 @@ public sealed class PlateViewOptions
|
||||
return options;
|
||||
}
|
||||
|
||||
/// <summary>Stores the rapids and bounds toggles in the WinForms format.</summary>
|
||||
/// <summary>
|
||||
/// Stores the rapids and bounds toggles in the WinForms format. As the WinForms settings
|
||||
/// provider does, a toggle still at its default is left out unless the file already holds it,
|
||||
/// so a later default change still applies.
|
||||
/// </summary>
|
||||
public void WriteTo(IDictionary<string, string> settings)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
settings[DrawRapidName] = UserSettingText.Format(DrawRapid);
|
||||
settings[DrawBoundsName] = UserSettingText.Format(DrawBounds);
|
||||
var defaults = new PlateViewOptions();
|
||||
Write(settings, DrawRapidName, DrawRapid, defaults.DrawRapid);
|
||||
Write(settings, DrawBoundsName, DrawBounds, defaults.DrawBounds);
|
||||
}
|
||||
|
||||
private static void Write(IDictionary<string, string> settings, string name, bool value, bool fallback)
|
||||
{
|
||||
if (value != fallback || settings.ContainsKey(name))
|
||||
settings[name] = UserSettingText.Format(value);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user