mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-27 08:21:05 -04:00
Roslyn duplicate scans found the same code copied across layers: - Data: the three browse sessions share BrowseSession<TPage, TSort>; the remote clients share NestServerHttp (JSON options, If-Match, error text). - WinForms: five paged lists share BrowsePager for loading text, navigation, sort glyphs and failure messages. The Add Drawings to Release, Drawing Library and set browser dialogs now dispose their browse sessions. - Server: NestQueryRequest reuses DrawingLibraryRequest's helpers; revision history queries share count and paging binds. - Engine: RemnantPlateNester delegates to DefaultPlateNester; CuttingPlanService reuses JointCuttingPlanSearch.Map. - Core: LineArc and CleanHole lead-ins share LineArcApproach with unchanged arithmetic order, so output is bit-identical. - IO: Dxf.GetGeometry overloads share one reader; .nest JSON test helpers move to NestArchiveJson. Also fixes the production compiler warnings (CS8632, CS8603, CS0108) and moves a test off an obsolete forwarding API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.4 KiB
C#
65 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using OpenNest.Data;
|
|
|
|
namespace OpenNest.Forms
|
|
{
|
|
/// <summary>
|
|
/// Chooses which machine's acceleration limits time the cut, or none for full speed
|
|
/// everywhere. Remembers the choice; until one is made, the first machine is used.
|
|
/// </summary>
|
|
internal sealed class CutTimeMachineBox : ComboBox
|
|
{
|
|
private const string ConstantSpeed = "none";
|
|
|
|
private sealed record Choice(MachineConfig Machine)
|
|
{
|
|
public override string ToString() =>
|
|
Machine == null ? "None (full speed)"
|
|
: Machine.Motion == null ? $"{Machine.Name} (placeholder)"
|
|
: Machine.Name;
|
|
}
|
|
|
|
public CutTimeMachineBox()
|
|
{
|
|
DropDownStyle = ComboBoxStyle.DropDownList;
|
|
Width = 200;
|
|
|
|
var machines = SortedByName(MachineSettings.LoadMachines());
|
|
Items.Add(new Choice(null));
|
|
foreach (var machine in machines)
|
|
Items.Add(new Choice(machine));
|
|
|
|
var saved = SavedMachine(machines);
|
|
SelectedItem = Items.Cast<Choice>().First(c => c.Machine == saved);
|
|
}
|
|
|
|
private static List<MachineConfig> SortedByName(IEnumerable<MachineConfig> machines) =>
|
|
machines.OrderBy(m => m.Name, StringComparer.CurrentCultureIgnoreCase).ToList();
|
|
|
|
/// <summary>The remembered machine, the first one until a choice is saved, or null for full speed.</summary>
|
|
public static MachineConfig SavedMachine(IEnumerable<MachineConfig> machines)
|
|
{
|
|
var sorted = SortedByName(machines);
|
|
var saved = Properties.Settings.Default.CutTimeMachine;
|
|
return saved == ConstantSpeed
|
|
? null
|
|
: sorted.FirstOrDefault(m => m.Id.ToString() == saved) ?? sorted.FirstOrDefault();
|
|
}
|
|
|
|
public MachineConfig Machine => (SelectedItem as Choice)?.Machine;
|
|
|
|
/// <summary>The chosen machine's limits in <paramref name="units"/>, or null for full speed.</summary>
|
|
public MotionProfile GetMotion(Units units) =>
|
|
Machine?.GetMotionOrPlaceholder().ToProfile(Machine.Units, units);
|
|
|
|
public void SaveChoice()
|
|
{
|
|
Properties.Settings.Default.CutTimeMachine = Machine?.Id.ToString() ?? ConstantSpeed;
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
}
|
|
}
|