mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-05 04:49:25 -05:00
The Cut Simulator had grown a row per input and was crowding the window. The slider now leads, with the time under it, then the transport and four equal jump buttons spanning exactly the slider's track. Part, drawing, motion and the heat view sit on a Status tab; the feeds, pierce, heat input and etch choice move to a Settings tab, so the window is shorter and the time stays visible while settings change. The Acceleration picker is gone: the simulator always times with the nest's machine (Nest > Machine), shown by name on the Settings tab, and falls back to full speed when the nest has none. Calculate Cut Time's remembered machine is left alone. The Avalonia simulator follows suit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
5.5 KiB
C#
127 lines
5.5 KiB
C#
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Input;
|
|
using Avalonia.Interactivity;
|
|
using OpenNest.Forms;
|
|
|
|
namespace OpenNest.Avalonia
|
|
{
|
|
/// <summary>
|
|
/// Plate > Calculate Cut Time, Nest > Calculate Cut Time and Plate > Simulate Cutting (also
|
|
/// on the toolbar), as the WinForms main window. Calculate Cut Time asks for the feeds,
|
|
/// pierce, acceleration and etch choice, then shows the timing. The simulator holds the nest
|
|
/// view-only while it is open: only the plate view, its header's plate and zoom buttons and
|
|
/// the zoom keys stay live, and Escape closes it.
|
|
/// </summary>
|
|
public partial class MainWindow
|
|
{
|
|
private CutSimulatorWindow simulator;
|
|
private InspectionLock inspection;
|
|
|
|
private void UpdateCutTimeCommands()
|
|
{
|
|
var hasPlate = ActiveView?.PlateView.Plate != null;
|
|
PlateCutTimeMenuItem.IsEnabled = hasPlate;
|
|
SimulateCuttingMenuItem.IsEnabled = hasPlate;
|
|
SimulateCuttingButton.IsEnabled = hasPlate;
|
|
NestCutTimeMenuItem.IsEnabled = ActiveView != null;
|
|
}
|
|
|
|
private async void OnCalculatePlateCutTime(object sender, RoutedEventArgs e) => await CalculateCutTimeAsync(wholeNest: false);
|
|
|
|
private async void OnCalculateNestCutTime(object sender, RoutedEventArgs e) => await CalculateCutTimeAsync(wholeNest: true);
|
|
|
|
private async Task CalculateCutTimeAsync(bool wholeNest)
|
|
{
|
|
var view = ActiveView;
|
|
if (view == null || simulator != null || (!wholeNest && view.PlateView.Plate == null)
|
|
|| IsNesting(view.Tab, "calculating its cut time"))
|
|
return;
|
|
// As the WinForms machine list, read each time it opens.
|
|
var machines = await DesktopSettings.RefreshMachinesAsync();
|
|
if (closed)
|
|
return;
|
|
var nest = view.Tab.Document.Nest;
|
|
var parameters = await CutTimeDialog.ShowAsync(this, nest.Units, machines, saveSettings: !snapshotMode);
|
|
if (parameters == null || closed)
|
|
return;
|
|
var plate = view.PlateView.Plate;
|
|
if (!wholeNest && plate == null)
|
|
return;
|
|
var report = wholeNest
|
|
? CutTimeReport.ForNest(nest, parameters)
|
|
: CutTimeReport.ForPlate(plate, parameters, nest.Units);
|
|
await TimingDialog.ShowAsync(this, report);
|
|
}
|
|
|
|
private async void OnSimulateCutting(object sender, RoutedEventArgs e)
|
|
{
|
|
if (simulator != null)
|
|
{
|
|
simulator.Activate();
|
|
return;
|
|
}
|
|
var view = ActiveView;
|
|
if (view?.PlateView.Plate == null || IsNesting(view.Tab, "simulating its cutting"))
|
|
return;
|
|
// As WinForms: the plate tool ends and the nest is view-only until the simulator closes.
|
|
// The lock is taken before the machines are read, so Auto Nest, Nest > Edit or
|
|
// another edit cannot start while they load and then run under the simulator.
|
|
view.PlateView.Tools.EndTool();
|
|
view.CancelPickup();
|
|
var opening = new InspectionLock(this, view.PlateView, view.InspectionControls);
|
|
inspection = opening;
|
|
var machines = await DesktopSettings.RefreshMachinesAsync();
|
|
// The window may have closed, or the user switched tabs, while the machines were read.
|
|
if (closed || ActiveView != view || view.PlateView.Plate == null)
|
|
{
|
|
opening.Dispose();
|
|
if (ReferenceEquals(inspection, opening))
|
|
inspection = null;
|
|
return;
|
|
}
|
|
var nestMachine = view.Tab.Document.Nest.Machine;
|
|
var machine = nestMachine == null ? null : machines.FirstOrDefault(m => m.Id == nestMachine.Id);
|
|
simulator = new CutSimulatorWindow(view, machine);
|
|
simulator.Closed += (_, _) =>
|
|
{
|
|
inspection?.Dispose();
|
|
inspection = null;
|
|
simulator = null;
|
|
};
|
|
simulator.Show(this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// While the simulator is open (or opening), as the WinForms main window while inspecting: Escape
|
|
/// closes it, the zoom keys zoom, and other Ctrl, Alt and command shortcuts (which could
|
|
/// change the nest) are swallowed. True when the key was taken.
|
|
/// </summary>
|
|
private bool ProcessSimulatorKeys(KeyEventArgs e)
|
|
{
|
|
// Also while the simulator is opening: the lock is already held then.
|
|
if (inspection == null)
|
|
return false;
|
|
var modifiers = e.KeyModifiers;
|
|
if (e.Key == Key.Escape && modifiers == KeyModifiers.None)
|
|
{
|
|
simulator?.Close();
|
|
return true;
|
|
}
|
|
if (modifiers == KeyModifiers.Control && e.Key is Key.OemPlus or Key.Add)
|
|
{
|
|
OnZoomIn(null, null);
|
|
return true;
|
|
}
|
|
if (modifiers == KeyModifiers.Control && e.Key is Key.OemMinus or Key.Subtract)
|
|
{
|
|
OnZoomOut(null, null);
|
|
return true;
|
|
}
|
|
// F5 and F6 open the increment dialogs, whose menu items are locked.
|
|
return (modifiers & (KeyModifiers.Control | KeyModifiers.Alt | KeyModifiers.Meta)) != 0
|
|
|| e.Key is Key.F5 or Key.F6;
|
|
}
|
|
}
|
|
}
|