fix(simulator): fill parts one gray under the heat map

The heat layer is translucent where it is cool, so each part's drawing
color showed through and shifted the scale's hues: a green part under
cool cyan read as the warm middle of the scale, and purple parts blended
into the cool blue. The same temperature looked different on different
parts.

While the heat layer shows, cut and cutting parts are filled with one
neutral gray set apart from the sheet color, so the hues mean only
temperature and holes and dropped slugs still stand out. Outlines,
numbers, pending parts and selection keep their usual look, and the
drawing colors return when heat is off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-12-02 12:41:49 -05:00
1 parent c130985c92
commit d45e5ff202
5 files changed
+77 -7

No files matched your search

@@ -1,5 +1,6 @@
using System.Drawing;
using OpenNest.CNC;
using OpenNest.CNC.Thermal;
using OpenNest.Controls;
using OpenNest.Geometry;
using static OpenNest.WinForms.Tests.FormTesting;
@@ -161,6 +162,53 @@ public class CutSimulationOverlayTests
Assert.Single(view.SelectedParts);
});
[Fact]
public void PartsShareOneGrayUnderTheHeatLayer() => RunSta(() =>
{
var plate = TwoSquares();
plate.Parts[0].BaseDrawing.Color = Color.FromArgb(60, 200, 60);
using var view = new PlateView { Plate = plate, Size = new System.Drawing.Size(400, 400) };
view.ZoomToFit();
var sim = CutSimulation.Build(plate, Parameters);
view.CutSimulation.Load(sim);
view.CutSimulation.Time = sim.TotalTime; // both parts cut, so neither is muted
var heat = new PlateHeatSimulation(plate, sim, new ThermalParameters
{
Thickness = 0.25,
Units = Units.Inches,
});
// A scale no cell comes near keeps the layer clear, leaving the part fill to read.
view.CutSimulation.LoadHeat(heat, 1e9f);
var center = view.PointWorldToControl(new Vector(7, 7)); // clear of the number label
view.CutSimulation.HeatMode = HeatView.Now;
var gray = CutSimulationOverlay.HeatPartFill(view.ColorScheme.LayoutFillColor);
Assert.Equal(gray.ToArgb(), PaintedPixel(view, center).ToArgb());
view.CutSimulation.HeatMode = HeatView.Off;
Assert.Equal(Color.FromArgb(60, 200, 60).ToArgb(), PaintedPixel(view, center).ToArgb());
});
[Theory]
[InlineData(242, 242, 242)]
[InlineData(52, 48, 58)]
public void HeatPartFillIsANeutralGrayApartFromTheSheet(int r, int g, int b)
{
var sheet = Color.FromArgb(r, g, b);
var fill = CutSimulationOverlay.HeatPartFill(sheet);
Assert.True(fill.R == fill.G && fill.G == fill.B);
Assert.True(System.Math.Abs(fill.R - sheet.G) >= 50);
}
private static Color PaintedPixel(PlateView view, System.Drawing.Point at)
{
using var bitmap = new Bitmap(view.Width, view.Height);
using (var graphics = Graphics.FromImage(bitmap))
Raise(view, "OnPaint", new System.Windows.Forms.PaintEventArgs(graphics, view.ClientRectangle));
return bitmap.GetPixel(at.X, at.Y);
}
private static Color Pixel(PlateView view, Bitmap bitmap, Vector world)
{
var point = view.PointWorldToGraph(world);
+13
View File
@@ -353,6 +353,19 @@ internal sealed class CutSimulationOverlay : IDisposable
/// <summary>True while the heat layer is drawn, so the cursor reading applies.</summary>
public bool ShowsHeat => heat != null && heatMode != HeatView.Off && Simulation is { Steps.Count: > 0 };
/// <summary>
/// The one gray every part is filled with while the heat layer shows. The layer is translucent
/// where it is cool, so drawing colors under it would shift its hues (a green part under cool
/// cyan reads as the scale's warm middle). The gray stands apart from the sheet in
/// <paramref name="layoutFill"/>, so holes and dropped slugs still show.
/// </summary>
internal static Color HeatPartFill(Color layoutFill)
{
var luma = (int)(0.299f * layoutFill.R + 0.587f * layoutFill.G + 0.114f * layoutFill.B);
var gray = luma >= 128 ? luma - 60 : luma + 60;
return Color.FromArgb(gray, gray, gray);
}
// While playing, the reading would change every frame, too fast to read; it refreshes at
// most this often unless the cursor moves to another cell.
private const long ReadingIntervalMs = 1000;
+6 -2
View File
@@ -139,6 +139,10 @@ namespace OpenNest.Controls
var viewBounds = view.GetViewBounds();
var layoutParts = view.DisplayLayoutParts;
cutOffLabels.Clear();
// Under the heat layer every part shares one gray, so its hues mean only temperature.
using var heatFill = !view.HasProposalDisplay && view.CutSimulation.ShowsHeat
? new SolidBrush(CutSimulationOverlay.HeatPartFill(view.ColorScheme.LayoutFillColor))
: null;
for (var i = 0; i < layoutParts.Count; ++i)
{
@@ -158,11 +162,11 @@ namespace OpenNest.Controls
&& view.PreviewSequence.TryGetValue(part.BasePart, out var preview) ? preview : i + 1;
if (part.BasePart.BaseDrawing.IsCutOff)
{
part.Draw(g, muted);
part.Draw(g, muted, heatFill);
cutOffLabels.Add((part, number.ToString(), muted));
}
else
part.Draw(g, number.ToString(), muted);
part.Draw(g, number.ToString(), muted, heatFill);
DrawBendLines(g, part.BasePart, muted);
DrawEtchMarks(g, part.BasePart, muted);
}
+6 -4
View File
@@ -132,12 +132,14 @@ namespace OpenNest
public void Draw(Graphics g) => Draw(g, false);
internal void Draw(Graphics g, bool muted)
/// <param name="fill">Fills the part in place of its drawing color, unless it is muted or
/// selected; null for its own color.</param>
internal void Draw(Graphics g, bool muted, Brush fill = null)
{
RefreshColors();
using var schemeSelectionBrush = IsSelected && !colorScheme.SelectedPartColor.IsEmpty
? new SolidBrush(colorScheme.SelectedPartColor) : null;
g.FillPath(muted ? Brushes.Gainsboro : schemeSelectionBrush ?? (IsSelected ? SelectedBrush : brush),
g.FillPath(muted ? Brushes.Gainsboro : schemeSelectionBrush ?? (IsSelected ? SelectedBrush : fill ?? brush),
MaterialPath);
DrawDisplay(g, muted);
DrawEtch(g, muted);
@@ -167,9 +169,9 @@ namespace OpenNest
public void Draw(Graphics g, string id) => Draw(g, id, false);
internal void Draw(Graphics g, string id, bool muted)
internal void Draw(Graphics g, string id, bool muted, Brush fill = null)
{
Draw(g, muted);
Draw(g, muted, fill);
if (LabelFits(MeasureLabel(g, id)))
DrawLabel(g, id, muted);
}
+4 -1
View File
@@ -71,7 +71,10 @@ before.
The simulator colors the field against the 99.5th percentile of the whole cut's peaks: a pierce
puts its energy into a single cell, and scaling to that cell would hide the areas where heat
builds up. Cells whose slug fell away are transparent. The simulator passes the plate's support
builds up. Cells whose slug fell away are transparent. Cool cells are translucent, so while the
layer shows, every cut or cutting part is filled with one neutral gray set apart from the sheet
color instead of its drawing color, which would shift the scale's hues; outlines, numbers, pending
parts and selection keep their usual look. The simulator passes the plate's support
bed, and its heat label says whether the sheet is cooled by air only or by air and the slats
(or support grid).