mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 06:41:42 -05:00
Plate > Calculate Cut Time and Nest > Calculate Cut Time ask for the outside feed, rapid, pierce time, hole feed, acceleration machine and etch choice (remembered in the settings both apps share, saved however the dialog closes, as WinForms), then show the timing as the WinForms Timing Information window. Plate > Simulate Cutting and its toolbar button open the Cut Simulator: play and pause at 1x to 250x, restart and end, part and cutout jumps, move stepping with the arrow keys, scrubbing, and the time, part, drawing and motion at the playhead, retimed as the feeds change and following the shown plate. The plate view draws the cut trail, travel, the torch and pierces, and mutes parts and cut-off segments the torch has not reached. While it is open the nest is view-only, as WinForms: only the plate view and its header stay live, Escape closes it and Ctrl+Plus and Ctrl+Minus still zoom. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
4.8 KiB
C#
116 lines
4.8 KiB
C#
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;
|
|
var machines = await DesktopSettings.RefreshMachinesAsync();
|
|
// The nest may have changed or closed, or the simulator opened, while the machines were read.
|
|
if (closed || simulator != null || ActiveView != view || view.PlateView.Plate == null)
|
|
return;
|
|
|
|
// As WinForms: the plate tool ends and the nest is view-only until the simulator closes.
|
|
view.PlateView.Tools.EndTool();
|
|
view.CancelPickup();
|
|
inspection = new InspectionLock(this, view.PlateView, view.InspectionControls);
|
|
simulator = new CutSimulatorWindow(view, machines);
|
|
simulator.Closed += (_, _) =>
|
|
{
|
|
inspection?.Dispose();
|
|
inspection = null;
|
|
simulator = null;
|
|
};
|
|
simulator.Show(this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// While the simulator is open, 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)
|
|
{
|
|
if (simulator == 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;
|
|
}
|
|
}
|
|
}
|