mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 07:51:33 -05:00
- 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>
52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|
|
}
|