mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-17 21:07:40 -05:00
fix(cutting): start planning from the user's settings
Edits in the Cutting Parameters dialog only reached user settings, while a plate's stored parameters took priority, so a change was lost on any planned plate unless Apply succeeded. User settings now win; a plate's own are the fallback when none are saved or readable. WinForms tests saved to the real user-settings.json, and with user settings winning a test's lead-ins would feed real planning, so they now use a temp file and skip the legacy settings carry-over. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bb6bdc8213
commit
667beb4334
9 files changed
+99
-20
No files matched your search
@@ -42,7 +42,7 @@ Releases: follow [the release procedure](docs/releasing.md) and `scripts/Publish
|
||||
- `OpenNest.Engine`: whole-job API in `Jobs/`, interactive proposals via `PlateFillService`, fill strategies, best-fit pairs, packing, sequencing and rapid planning. `INestingEngine.Solve(NestJob)` returns stock IDs/poses; boundary adapters map drawings and materialize results. `NestJobRunner` validates its candidates before committing demand/stock accounting. Do not assume arbitrary plug-in output or interactive paths received that validation. Job identity is reference-based, not drawing-name-based.
|
||||
- Built-in whole-job engines live in `OpenNest.Engine/NestingEngines/<Name>/`, named for the jobs they suit; see [nesting engines](docs/nesting-engines.md). A change must beat that engine's current benchmark result with every layout valid. External plug-ins implement `INestingEngine` with a public parameterless constructor and load from `Engines/` beside the host; keep their projects out of this solution.
|
||||
- `OpenNest.IO`: ACadSharp import/export and ZIP-based `.nest` persistence; depends on Core only (an IO.Tests guard enforces it). Best fits persist only when callers pass `BestFitCacheStore.Shared` as `NestReader`/`NestWriter.BestFitStore`. All DXF-to-Drawing conversion goes through `CadImporter`: `Import` + `BuildDrawing` for editable/reporting flows, `ImportDrawing` for headless callers. Preserve source offsets, entity IDs, suppressed entities and bends. Bend repair is opt-in, requires explicit source units and may not alter cut geometry or unrelated marks.
|
||||
- `OpenNest`: WinForms UI (`Forms/`, `Controls/PlateView`, `Actions/`). `OpenNest.Data` holds cross-platform persistence; new-nest defaults live in `%APPDATA%\OpenNest\defaults.json` (in Database mode, the server's shared copy once it holds one). WinForms `Properties.Settings` persist to `%APPDATA%\OpenNest\user-settings.json` through `AppDataSettingsProvider`, never inside the Velopack install folder. Posts live in `Posts/OpenNest.Posts.<Name>/` and deploy to the desktop output's `Posts/` directory. Desktop nest edits go through `BeginChange`/`RecordChange`; see [undo and redo](docs/undo-redo.md).
|
||||
- `OpenNest`: WinForms UI (`Forms/`, `Controls/PlateView`, `Actions/`). `OpenNest.Data` holds cross-platform persistence; new-nest defaults live in `%APPDATA%\OpenNest\defaults.json` (in Database mode, the server's shared copy once it holds one). WinForms `Properties.Settings` persist to `%APPDATA%\OpenNest\user-settings.json` through `AppDataSettingsProvider`, never inside the Velopack install folder; `OpenNest.WinForms.Tests` redirects them to a temp file, so a test run never writes the user's settings. Posts live in `Posts/OpenNest.Posts.<Name>/` and deploy to the desktop output's `Posts/` directory. Desktop nest edits go through `BeginChange`/`RecordChange`; see [undo and redo](docs/undo-redo.md).
|
||||
- `OpenNest.Desktop` (net8.0): toolkit-neutral desktop logic shared by the WinForms app and `OpenNest.Avalonia`, the cross-platform desktop in progress. It must not reference WinForms/WindowsDesktop, `System.Drawing.Common` or Avalonia (`OpenNest.Desktop.Tests` guards this, including transitive packages); put toolkit-specific rendering, dialogs and settings behind adapters in the front ends.
|
||||
- `OpenNest.Console`, `OpenNest.Mcp`, `OpenNest.Api`: front ends; `OpenNest.Benchmark`: whole-job engine comparisons; `OpenNest.Gpu`: GPU evaluators; `OpenNest.Training`: ML data collection and the Python sketch-search prototype (`sketch-search/README.md`). Benchmark timing comparisons require `--parallel 1`; validate layouts and fulfillment, not just elapsed time.
|
||||
|
||||
|
||||
@@ -567,6 +567,37 @@ public class CuttingInspectionPanelTests
|
||||
Assert.Equal(0.3, ((LineLeadIn)captured.ExternalLeadIn).Length);
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public void UserSettingsWinOverThePlatesOwn() => RunSta(() =>
|
||||
{
|
||||
using var editor = Editor();
|
||||
var user = new CuttingParameters { ExternalLeadIn = new LineLeadIn { Length = 0.7 } };
|
||||
WithUserSettings(CuttingParametersSerializer.Serialize(user), () =>
|
||||
{
|
||||
editor.Show();
|
||||
editor.PlateManager.LoadAt(0);
|
||||
editor.OpenCuttingInspection();
|
||||
var panel = Assert.IsType<CuttingInspectionPanel>(editor.CuttingInspection);
|
||||
var opened = Field<CuttingParameters>(panel, "parameters");
|
||||
Assert.Equal(0.7, ((LineLeadIn)opened.ExternalLeadIn).Length);
|
||||
panel.RequestClose();
|
||||
PumpUntil(() => panel.IsDisposed);
|
||||
});
|
||||
});
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData("{not json")]
|
||||
public void ThePlatesOwnSettingsAreTheFallback(string json) => RunSta(() =>
|
||||
{
|
||||
using var editor = Editor();
|
||||
WithUserSettings(json, () =>
|
||||
{
|
||||
var plate = editor.Nest.Plates[0];
|
||||
Assert.Same(plate.CuttingParameters, MachineSettings.CuttingParametersFor(plate, editor.Nest));
|
||||
});
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public void EmptySentinelIsNotNumberedAsAnOccupiedPlate() => RunSta(() =>
|
||||
{
|
||||
@@ -1021,6 +1052,8 @@ public class CuttingInspectionPanelTests
|
||||
|
||||
private static EditNestForm Editor()
|
||||
{
|
||||
// The plate's own settings below apply only while the user has none.
|
||||
OpenNest.Properties.Settings.Default.CuttingParametersJson = "";
|
||||
var nest = new Nest();
|
||||
var plate = nest.CreatePlate();
|
||||
plate.Size = new OpenNest.Geometry.Size(100, 100);
|
||||
@@ -1072,6 +1105,21 @@ public class CuttingInspectionPanelTests
|
||||
Assert.True(condition(), "Timed out waiting for cutting inspection.");
|
||||
}
|
||||
|
||||
private static void WithUserSettings(string json, System.Action action)
|
||||
{
|
||||
var settings = OpenNest.Properties.Settings.Default;
|
||||
var saved = settings.CuttingParametersJson;
|
||||
settings.CuttingParametersJson = json;
|
||||
try
|
||||
{
|
||||
action();
|
||||
}
|
||||
finally
|
||||
{
|
||||
settings.CuttingParametersJson = saved;
|
||||
}
|
||||
}
|
||||
|
||||
private static void RunSta(System.Action action) =>
|
||||
StaTestThread.Run(action, TimeSpan.FromSeconds(45), "STA cutting inspection test timed out.");
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using OpenNest.Properties;
|
||||
|
||||
namespace OpenNest.WinForms.Tests;
|
||||
|
||||
internal static class IsolatedUserSettings
|
||||
{
|
||||
#pragma warning disable CA2255 // Must run before anything reads Settings.Default.
|
||||
[ModuleInitializer]
|
||||
internal static void Redirect() =>
|
||||
AppDataSettingsProvider.PathOverride = Path.Combine(
|
||||
Path.GetTempPath(), "OpenNest.WinForms.Tests", Guid.NewGuid().ToString("N"), "user-settings.json");
|
||||
#pragma warning restore CA2255
|
||||
}
|
||||
@@ -104,9 +104,7 @@ namespace OpenNest.Actions
|
||||
cuttingPanel = new CuttingPanel();
|
||||
cuttingPanel.ParametersChanged += OnToolParametersChanged;
|
||||
|
||||
// Load current parameters or defaults
|
||||
var plate = plateView.Plate;
|
||||
cuttingPanel.LoadFromParameters(plate?.CuttingParameters ?? MachineSettings.DefaultCuttingParameters(form.Nest));
|
||||
cuttingPanel.LoadFromParameters(MachineSettings.CuttingParametersFor(plateView.Plate, form.Nest));
|
||||
loadedParameters = CuttingParametersSerializer.Serialize(cuttingPanel.BuildParameters());
|
||||
|
||||
form.ShowSidePanel(cuttingPanel, "Place Lead-in");
|
||||
|
||||
@@ -341,7 +341,7 @@ namespace OpenNest.Forms
|
||||
if (CuttingInspection != null)
|
||||
return;
|
||||
PlateView.EndAction();
|
||||
var panel = new CuttingInspectionPanel(this, PlateView.Plate.CuttingParameters ?? MachineSettings.DefaultCuttingParameters(Nest), allPlates, mode)
|
||||
var panel = new CuttingInspectionPanel(this, MachineSettings.CuttingParametersFor(PlateView.Plate, Nest), allPlates, mode)
|
||||
{
|
||||
BeforePlan = CuttingBeforePlan
|
||||
};
|
||||
@@ -1351,8 +1351,8 @@ namespace OpenNest.Forms
|
||||
if (PlateView?.Plate == null)
|
||||
return;
|
||||
|
||||
// The tool's panel starts from the plate's parameters or the defaults; the plate
|
||||
// takes them with its first lead-in, so opening the tool changes nothing.
|
||||
// The tool's panel starts from the user's parameters; the plate takes them with
|
||||
// its first lead-in, so opening the tool changes nothing.
|
||||
PlateView.SetAction(typeof(Actions.ActionLeadIn));
|
||||
}
|
||||
|
||||
|
||||
@@ -211,8 +211,21 @@ namespace OpenNest.Forms
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The cutting parameters to plan or place lead-ins on <paramref name="plate"/> with: the
|
||||
/// user's (see <see cref="DefaultCuttingParameters"/>), so an edit reaches nests already
|
||||
/// planned. The plate's own are used only when no user settings are saved or readable.
|
||||
/// </summary>
|
||||
public static CuttingParameters CuttingParametersFor(Plate plate, Nest nest) =>
|
||||
plate?.CuttingParameters != null && ReadLastCuttingParameters() == null
|
||||
? plate.CuttingParameters
|
||||
: DefaultCuttingParameters(nest);
|
||||
|
||||
/// <summary>The cutting parameters last applied, or the built-in defaults when none are saved or readable.</summary>
|
||||
public static CuttingParameters LastCuttingParameters()
|
||||
public static CuttingParameters LastCuttingParameters() =>
|
||||
ReadLastCuttingParameters() ?? new CuttingParameters();
|
||||
|
||||
private static CuttingParameters ReadLastCuttingParameters()
|
||||
{
|
||||
var json = Properties.Settings.Default.CuttingParametersJson;
|
||||
if (!string.IsNullOrEmpty(json))
|
||||
@@ -225,7 +238,7 @@ namespace OpenNest.Forms
|
||||
{ /* fall through */
|
||||
}
|
||||
}
|
||||
return new CuttingParameters();
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenNest.Properties
|
||||
private readonly Func<SettingsProvider> _legacyProvider;
|
||||
|
||||
public AppDataSettingsProvider()
|
||||
: this(DefaultPath, () => new LocalFileSettingsProvider()) { }
|
||||
: this(DefaultPath, PathOverride == null ? () => new LocalFileSettingsProvider() : null) { }
|
||||
|
||||
/// <param name="path">The settings file.</param>
|
||||
/// <param name="legacyProvider">Supplies values to carry over when <paramref name="path"/> does not exist; null for none.</param>
|
||||
@@ -36,8 +36,11 @@ namespace OpenNest.Properties
|
||||
_legacyProvider = legacyProvider;
|
||||
}
|
||||
|
||||
/// <summary>Replaces <see cref="DefaultPath"/>, so test runs never write the user's settings.</summary>
|
||||
internal static string PathOverride { get; set; }
|
||||
|
||||
/// <summary>%APPDATA%\OpenNest\user-settings.json.</summary>
|
||||
public static string DefaultPath => Path.Combine(
|
||||
public static string DefaultPath => PathOverride ?? Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"OpenNest", "user-settings.json");
|
||||
|
||||
|
||||
@@ -17,15 +17,16 @@ machine's units to the nest's.
|
||||
|
||||
## Lead-ins and lead-outs
|
||||
|
||||
A plate with no cutting parameters of its own (Plan Cutting, Place Lead-in) starts from the
|
||||
last applied parameters, as before, with the machine's leads and kerf laid over them and the
|
||||
machine, material, grade and thickness recorded on the parameters. When the last parameters
|
||||
Plan Cutting and Place Lead-in start from the user's last applied parameters, with the machine's
|
||||
leads and kerf laid over them and the machine, material, grade and thickness recorded on the
|
||||
parameters. A plate's own parameters are used only when no user parameters are saved or readable,
|
||||
so an edit reaches nests already planned. When the last parameters
|
||||
already record the same machine, material, grade and thickness, the machine's settings are not
|
||||
laid over them again, so lead and tab edits made for that job stick; the cutting panel keeps the
|
||||
record (and the kerf) through an edit. Plan Cutting saves its settings as the last parameters as
|
||||
soon as its settings dialog is accepted, not only on Apply. A plate that already has
|
||||
parameters keeps them: changing the machine, material or thickness does not rewrite leads
|
||||
the plate was planned with.
|
||||
soon as its settings dialog is accepted, not only on Apply. Changing the settings, machine,
|
||||
material or thickness does not rewrite the leads a plate was planned with: its programs and
|
||||
stored parameters stay until a plan is applied.
|
||||
|
||||
Each thickness holds a lead-in and lead-out for outside cuts (the Outside Cuts tab, external
|
||||
contours) and, optionally, its own pair for inside cuts (the Inside Cuts tab, internal contours,
|
||||
|
||||
@@ -105,9 +105,11 @@ older version.
|
||||
|
||||
## Plate cutting parameters
|
||||
|
||||
Each plate's optional `cuttingParameters` stores the settings used by Assign
|
||||
Lead-ins and Place Lead-in. Missing settings stay null, preserving the old default
|
||||
selection behavior. `OpenNest.IO.CuttingParametersSerializer` owns the shared
|
||||
Each plate's optional `cuttingParameters` stores the settings last applied to it.
|
||||
The desktop starts Plan Cutting and Place Lead-in from the user's settings and falls
|
||||
back to these only when it has none (see
|
||||
[machine cutting defaults](machine-cutting-defaults.md)). Missing settings stay null,
|
||||
preserving the old default selection behavior. `OpenNest.IO.CuttingParametersSerializer` owns the shared
|
||||
cross-platform DTO mapping; the desktop settings serializer delegates to it so
|
||||
existing saved settings keep their JSON contract. Settings are independent of
|
||||
the saved part programs: restoring settings never regenerates those programs.
|
||||
|
||||
Reference in new issue
Block a user