mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 11:01:36 -05:00
refactor: share duplicated fill, cache, settings and toggle code
- fill_plate and fill_area share one MCP fill helper - FillLinear uses FillHelpers.HasOverlappingParts - BestFitCache and FillResultCache entries derive from DrawingCacheEntry - NestDefaults and ClampSettings read through SettingsFile.TryReadText - MainForm view toggles share one ToggleView handler Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4b61d249c0
commit
d77693aaff
10 files changed
+178
-217
No files matched your search
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace OpenNest.Engine
|
||||
{
|
||||
/// <summary>
|
||||
/// A per-drawing cache entry that is current while the drawing keeps the program
|
||||
/// reference and source angle it was built from.
|
||||
/// </summary>
|
||||
internal abstract class DrawingCacheEntry
|
||||
{
|
||||
private readonly CNC.Program program;
|
||||
private readonly double sourceAngle;
|
||||
|
||||
protected DrawingCacheEntry(Drawing source)
|
||||
{
|
||||
program = source.Program;
|
||||
sourceAngle = source.Source?.Angle ?? 0.0;
|
||||
}
|
||||
|
||||
public bool IsCurrentFor(Drawing source) =>
|
||||
ReferenceEquals(program, source.Program)
|
||||
&& sourceAngle == (source.Source?.Angle ?? 0.0);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current entry for <paramref name="source"/>, replacing a missing or
|
||||
/// stale one under <paramref name="gate"/>.
|
||||
/// </summary>
|
||||
public static TEntry GetOrCreate<TEntry>(
|
||||
ConditionalWeakTable<Drawing, TEntry> entries,
|
||||
object gate,
|
||||
Drawing source,
|
||||
Func<Drawing, TEntry> create
|
||||
)
|
||||
where TEntry : DrawingCacheEntry
|
||||
{
|
||||
if (entries.TryGetValue(source, out var entry) && entry.IsCurrentFor(source))
|
||||
return entry;
|
||||
|
||||
lock (gate)
|
||||
{
|
||||
if (entries.TryGetValue(source, out entry) && entry.IsCurrentFor(source))
|
||||
return entry;
|
||||
|
||||
entry = create(source);
|
||||
entries.AddOrUpdate(source, entry);
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user