mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-04 07:19:24 -05:00
feat(simulator): show the heat under the cursor when the heat map is visible
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9a5feb6fbc
commit
d54ad5330a
2 files changed
+82
No files matched your search
@@ -350,6 +350,66 @@ 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 };
|
||||
|
||||
// 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;
|
||||
private int readingCell = -1;
|
||||
private long readingAt;
|
||||
private string readingText;
|
||||
|
||||
/// <summary>
|
||||
/// Draws the heat layer's value under <paramref name="cursor"/> (control pixels) just below
|
||||
/// it; nothing off the plate or where material fell away. Call after <see cref="Draw"/>.
|
||||
/// </summary>
|
||||
public void DrawHeatReading(Graphics graphics, Point cursor, Font font)
|
||||
{
|
||||
if (!ShowsHeat)
|
||||
return;
|
||||
var cell = heat.CellAt(view.PointControlToWorld(cursor));
|
||||
if (cell < 0 || heat.IsRemoved(cell))
|
||||
{
|
||||
readingCell = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
var now = Environment.TickCount64;
|
||||
if (cell != readingCell || !IsPlaying || now - readingAt >= ReadingIntervalMs)
|
||||
{
|
||||
var values = heatMode == HeatView.Peak ? heat.Peaks : heat.Temperatures;
|
||||
readingText = heatMode == HeatView.Peak ? $"Peak +{values[cell]:0} °C" : $"+{values[cell]:0} °C";
|
||||
readingCell = cell;
|
||||
readingAt = now;
|
||||
}
|
||||
|
||||
var state = graphics.Save();
|
||||
try
|
||||
{
|
||||
graphics.ResetTransform();
|
||||
graphics.SmoothingMode = SmoothingMode.HighSpeed;
|
||||
var size = graphics.MeasureString(readingText, font);
|
||||
var width = size.Width + 6;
|
||||
var height = size.Height + 4;
|
||||
var client = view.ClientSize;
|
||||
var x = System.Math.Clamp(cursor.X - width / 2, 0, System.Math.Max(0, client.Width - width - 1));
|
||||
var y = cursor.Y + 22f * view.DeviceDpi / 96f;
|
||||
if (y + height > client.Height)
|
||||
y = cursor.Y - height - 6;
|
||||
|
||||
var rect = new RectangleF(x, y, width, height);
|
||||
using (var background = new SolidBrush(Color.FromArgb(230, Color.White)))
|
||||
graphics.FillRectangle(background, rect);
|
||||
graphics.DrawRectangle(Pens.DimGray, rect.X, rect.Y, rect.Width, rect.Height);
|
||||
graphics.DrawString(readingText, font, Brushes.Black, x + 3, y + 2);
|
||||
}
|
||||
finally
|
||||
{
|
||||
graphics.Restore(state);
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly (float At, Color Color)[] HeatStops =
|
||||
{
|
||||
(0f, Color.FromArgb(40, 60, 200)),
|
||||
|
||||
@@ -448,6 +448,11 @@ namespace OpenNest.Controls
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
ClearHover();
|
||||
if (heatCursor != null)
|
||||
{
|
||||
heatCursor = null;
|
||||
Invalidate();
|
||||
}
|
||||
base.OnMouseLeave(e);
|
||||
}
|
||||
|
||||
@@ -632,10 +637,24 @@ namespace OpenNest.Controls
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
// Where the cut simulator's heat reading follows the mouse, in control pixels.
|
||||
private Point? heatCursor;
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
if (e.Button != MouseButtons.None)
|
||||
ClearHover();
|
||||
if (cutSimulation.ShowsHeat)
|
||||
{
|
||||
heatCursor = e.Location;
|
||||
// Playback repaints on its own timer.
|
||||
if (!cutSimulation.IsPlaying)
|
||||
Invalidate();
|
||||
}
|
||||
else
|
||||
{
|
||||
heatCursor = null;
|
||||
}
|
||||
if (e.Button == MouseButtons.Middle)
|
||||
{
|
||||
if (AllowPan)
|
||||
@@ -885,6 +904,9 @@ namespace OpenNest.Controls
|
||||
|
||||
base.OnPaint(e);
|
||||
|
||||
if (heatCursor != null && !HasProposalDisplay)
|
||||
cutSimulation.DrawHeatReading(e.Graphics, heatCursor.Value, Font);
|
||||
|
||||
if (!InspectionOnly && !overlapOverlay.DrawHover(e.Graphics) && hoveredPart != null && showTooltip)
|
||||
{
|
||||
e.Graphics.ResetTransform();
|
||||
|
||||
Reference in new issue
Block a user