From d45e5ff202749aba9687f232ccf29b2a614b37ee Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Wed, 2 Dec 2026 12:41:49 -0500 Subject: [PATCH] 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 --- .../Controls/CutSimulationOverlayTests.cs | 48 +++++++++++++++++++ OpenNest/Controls/CutSimulationOverlay.cs | 13 +++++ OpenNest/Controls/PlateRenderer.cs | 8 +++- OpenNest/LayoutPart.cs | 10 ++-- docs/plate-heat-map.md | 5 +- 5 files changed, 77 insertions(+), 7 deletions(-) diff --git a/OpenNest.WinForms.Tests/Controls/CutSimulationOverlayTests.cs b/OpenNest.WinForms.Tests/Controls/CutSimulationOverlayTests.cs index 177d7440..93231a85 100644 --- a/OpenNest.WinForms.Tests/Controls/CutSimulationOverlayTests.cs +++ b/OpenNest.WinForms.Tests/Controls/CutSimulationOverlayTests.cs @@ -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); diff --git a/OpenNest/Controls/CutSimulationOverlay.cs b/OpenNest/Controls/CutSimulationOverlay.cs index 527cfbb8..64dc1fc8 100644 --- a/OpenNest/Controls/CutSimulationOverlay.cs +++ b/OpenNest/Controls/CutSimulationOverlay.cs @@ -353,6 +353,19 @@ internal sealed class CutSimulationOverlay : IDisposable /// True while the heat layer is drawn, so the cursor reading applies. public bool ShowsHeat => heat != null && heatMode != HeatView.Off && Simulation is { Steps.Count: > 0 }; + /// + /// 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 + /// , so holes and dropped slugs still show. + /// + 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; diff --git a/OpenNest/Controls/PlateRenderer.cs b/OpenNest/Controls/PlateRenderer.cs index dd5adfdf..50c04da1 100644 --- a/OpenNest/Controls/PlateRenderer.cs +++ b/OpenNest/Controls/PlateRenderer.cs @@ -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); } diff --git a/OpenNest/LayoutPart.cs b/OpenNest/LayoutPart.cs index 6fa91d2f..24fab697 100644 --- a/OpenNest/LayoutPart.cs +++ b/OpenNest/LayoutPart.cs @@ -132,12 +132,14 @@ namespace OpenNest public void Draw(Graphics g) => Draw(g, false); - internal void Draw(Graphics g, bool muted) + /// Fills the part in place of its drawing color, unless it is muted or + /// selected; null for its own color. + 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); } diff --git a/docs/plate-heat-map.md b/docs/plate-heat-map.md index b315a9b1..fd40b38d 100644 --- a/docs/plate-heat-map.md +++ b/docs/plate-heat-map.md @@ -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).