mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 03:11:34 -05:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
eba15791e7
57 files changed
+1303
-221
No files matched your search
@@ -114,8 +114,7 @@ jobs:
|
||||
publish:
|
||||
if: >-
|
||||
github.repository == 'ajisaacs/OpenNest' &&
|
||||
((github.event_name == 'release' && github.event.release.prerelease == false) ||
|
||||
(github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master'))
|
||||
github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 40
|
||||
permissions:
|
||||
|
||||
@@ -70,9 +70,11 @@ internal enum SupportEntries
|
||||
/// <summary>
|
||||
/// One automatic start candidate: the owned contour choice plus its preference kind and a
|
||||
/// stable geometry tie key for deterministic ranking. The choice keeps this preparation as
|
||||
/// owner; nothing here exposes or mutates the underlying shape.
|
||||
/// owner; nothing here exposes or mutates the underlying shape. <paramref name="CornerReach"/>
|
||||
/// is how far a corner fillet's joint lies from the sharp corner it rounds (0 otherwise), so
|
||||
/// ranking can count it on both of that corner's sides.
|
||||
/// </summary>
|
||||
internal sealed record ContourEntryCandidate(ContourChoice Choice, AutomaticEntryKind Kind)
|
||||
internal sealed record ContourEntryCandidate(ContourChoice Choice, AutomaticEntryKind Kind, double CornerReach = 0)
|
||||
{
|
||||
/// <summary>
|
||||
/// Stable geometric tie key: the point quantized to the preparation epsilon grid, so
|
||||
|
||||
@@ -107,16 +107,18 @@ internal static class ContourEntryRanking
|
||||
if (target != null)
|
||||
{
|
||||
// Nearest side(s) of the candidate bounding rectangle (a corner belongs to two
|
||||
// sides within tolerance); count how many of them are facing sides.
|
||||
// sides within tolerance, a fillet's joint within its reach of the corner it
|
||||
// rounds); count how many of them are facing sides.
|
||||
var left = p.X - minX;
|
||||
var right = maxX - p.X;
|
||||
var bottom = p.Y - minY;
|
||||
var top = maxY - p.Y;
|
||||
var min = System.Math.Min(System.Math.Min(left, right), System.Math.Min(bottom, top));
|
||||
if (facingRight && right <= min + PostVerificationGeometry.Epsilon) facing++;
|
||||
if (!facingRight && left <= min + PostVerificationGeometry.Epsilon) facing++;
|
||||
if (facingTop && top <= min + PostVerificationGeometry.Epsilon) facing++;
|
||||
if (!facingTop && bottom <= min + PostVerificationGeometry.Epsilon) facing++;
|
||||
var near = min + PostVerificationGeometry.Epsilon + candidate.CornerReach;
|
||||
if (facingRight && right <= near) facing++;
|
||||
if (!facingRight && left <= near) facing++;
|
||||
if (facingTop && top <= near) facing++;
|
||||
if (!facingTop && bottom <= near) facing++;
|
||||
}
|
||||
var travel = (arrival != null ? arrival.Value.DistanceTo(p) : 0.0)
|
||||
+ (target != null ? p.DistanceTo(target.Value) : 0.0);
|
||||
|
||||
@@ -602,7 +602,7 @@ public sealed class PreparedContours
|
||||
/// <summary>Preferred tier: convex corners, straight midpoints, tangent joints.</summary>
|
||||
private List<ContourEntryCandidate> PreferredCandidates(Shape shape, int contourOrdinal, CancellationToken token)
|
||||
=> CataloguePoints(shape, token)
|
||||
.Select(p => new ContourEntryCandidate(Entry(contourOrdinal, p.EntityOrdinal, p.Point), p.Kind))
|
||||
.Select(p => new ContourEntryCandidate(Entry(contourOrdinal, p.EntityOrdinal, p.Point), p.Kind, p.CornerReach))
|
||||
.ToList();
|
||||
|
||||
/// <summary>
|
||||
@@ -763,12 +763,14 @@ public sealed class PreparedContours
|
||||
/// <summary>
|
||||
/// The preferred catalogue points for one contour: for each entity, its convex corner
|
||||
/// (end vertex, classified from the contour's own winding) and its straight-edge midpoint,
|
||||
/// plus tangent line/arc joints. Reflex, cusp and collinear-split vertices contribute
|
||||
/// plus tangent line/arc joints. The joints of a corner fillet (see <see cref="FilletReach"/>)
|
||||
/// are that corner's convex corners. Reflex, cusp and collinear-split vertices contribute
|
||||
/// nothing; a single whole circle yields no points at all.
|
||||
/// </summary>
|
||||
private List<(int EntityOrdinal, Vector Point, AutomaticEntryKind Kind)> CataloguePoints(Shape shape, CancellationToken token)
|
||||
private List<(int EntityOrdinal, Vector Point, AutomaticEntryKind Kind, double CornerReach)> CataloguePoints(
|
||||
Shape shape, CancellationToken token)
|
||||
{
|
||||
var found = new List<(int, Vector, AutomaticEntryKind)>();
|
||||
var found = new List<(int, Vector, AutomaticEntryKind, double)>();
|
||||
var count = shape.Entities.Count;
|
||||
if (count == 1 && shape.Entities[0] is Circle)
|
||||
{
|
||||
@@ -792,29 +794,65 @@ public sealed class PreparedContours
|
||||
switch (corner.Kind)
|
||||
{
|
||||
case ContourCuttingStrategy.CornerKind.Convex:
|
||||
found.Add((i, vertex, AutomaticEntryKind.ConvexCorner));
|
||||
found.Add((i, vertex, AutomaticEntryKind.ConvexCorner, 0));
|
||||
break;
|
||||
case ContourCuttingStrategy.CornerKind.Smooth
|
||||
when entity is Line && Next(i) is Arc:
|
||||
// A line leaving into an arc: the tangent joint. The reverse travel
|
||||
// order classifies the same joint from the arc, matched below.
|
||||
found.Add((i, vertex, AutomaticEntryKind.TangentJoint));
|
||||
found.Add(Joint(i, vertex, (i + 1) % count));
|
||||
break;
|
||||
// Reflex, cusp, collinear splits (smooth line→line) and arc→line joins
|
||||
// of a plain straight edge are not preferred automatic starts here.
|
||||
case ContourCuttingStrategy.CornerKind.Smooth
|
||||
when entity is Arc && Next(i) is Line:
|
||||
found.Add((i, vertex, AutomaticEntryKind.TangentJoint));
|
||||
found.Add(Joint(i, vertex, i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (entity is Line line)
|
||||
found.Add((i, line.MidPoint, AutomaticEntryKind.StraightMidpoint));
|
||||
found.Add((i, line.MidPoint, AutomaticEntryKind.StraightMidpoint, 0));
|
||||
}
|
||||
return found;
|
||||
|
||||
Entity Next(int index) => shape.Entities[(index + 1) % count];
|
||||
|
||||
(int, Vector, AutomaticEntryKind, double) Joint(int entityOrdinal, Vector vertex, int arcOrdinal) =>
|
||||
FilletReach(shape, arcOrdinal) is { } reach
|
||||
? (entityOrdinal, vertex, AutomaticEntryKind.ConvexCorner, reach)
|
||||
: (entityOrdinal, vertex, AutomaticEntryKind.TangentJoint, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How far the joints of the arc at <paramref name="arcOrdinal"/> lie from the sharp corner it
|
||||
/// rounds, when it is a corner fillet: tangent to straight edges at both ends, turning less
|
||||
/// than a half circle the convex way, and reaching back along each edge no further than the
|
||||
/// edge is long. A fillet's joints start the cut at the corner, where the mismatch when the
|
||||
/// cut closes is least seen, instead of on a straight edge. Null for any other arc.
|
||||
/// </summary>
|
||||
private static double? FilletReach(Shape shape, int arcOrdinal)
|
||||
{
|
||||
var count = shape.Entities.Count;
|
||||
if (shape.Entities[arcOrdinal] is not Arc arc
|
||||
|| shape.Entities[(arcOrdinal + count - 1) % count] is not Line before
|
||||
|| shape.Entities[(arcOrdinal + 1) % count] is not Line after)
|
||||
return null;
|
||||
var sweep = arc.SweepAngle();
|
||||
if (sweep >= System.Math.PI - OpenNest.Math.Tolerance.Epsilon)
|
||||
return null;
|
||||
if (!IsSmooth(before.EndPoint, before) || !IsSmooth(arc.EndPoint(), arc))
|
||||
return null;
|
||||
var winding = ContourCuttingStrategy.DetermineWinding(shape);
|
||||
if (ContourCuttingStrategy.ClassifyTurn((before.EndPoint - before.StartPoint).Normalize(),
|
||||
(after.EndPoint - after.StartPoint).Normalize(), winding) != ContourCuttingStrategy.CornerKind.Convex)
|
||||
return null;
|
||||
var reach = arc.Radius * System.Math.Tan(sweep / 2);
|
||||
return reach <= System.Math.Min(before.Length, after.Length) ? reach : null;
|
||||
|
||||
bool IsSmooth(Vector vertex, Entity entity) =>
|
||||
ContourCuttingStrategy.TryClassifyAutomaticStartCorner(shape, vertex, entity, out var corner)
|
||||
&& corner.Kind == ContourCuttingStrategy.CornerKind.Smooth;
|
||||
}
|
||||
|
||||
/// <summary>Emits every contour once in caller order, holes before perimeter, with scribes once.</summary>
|
||||
|
||||
@@ -867,10 +867,18 @@ namespace OpenNest.CNC.CuttingStrategy
|
||||
/// A turn whose offset over the tangent is within chaining tolerance is smooth,
|
||||
/// not a corner.
|
||||
/// </summary>
|
||||
private static CornerKind ClassifyCorner(ContourCorner corner, RotationType winding)
|
||||
private static CornerKind ClassifyCorner(ContourCorner corner, RotationType winding) =>
|
||||
ClassifyTurn(corner.TangentIn, corner.TangentOut, winding);
|
||||
|
||||
/// <summary>
|
||||
/// The corner a contour of <paramref name="winding"/> would make turning from travel
|
||||
/// direction <paramref name="tangentIn"/> to <paramref name="tangentOut"/>, classified
|
||||
/// exactly as a shared vertex is (see <see cref="TryClassifyAutomaticStartCorner"/>).
|
||||
/// </summary>
|
||||
internal static CornerKind ClassifyTurn(Vector tangentIn, Vector tangentOut, RotationType winding)
|
||||
{
|
||||
var cross = corner.TangentIn.X * corner.TangentOut.Y - corner.TangentIn.Y * corner.TangentOut.X;
|
||||
var dot = corner.TangentIn.DotProduct(corner.TangentOut);
|
||||
var cross = tangentIn.X * tangentOut.Y - tangentIn.Y * tangentOut.X;
|
||||
var dot = tangentIn.DotProduct(tangentOut);
|
||||
var turn = winding == RotationType.CCW ? cross : -cross;
|
||||
|
||||
if (System.Math.Abs(turn) <= Tolerance.Epsilon)
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace OpenNest.CNC
|
||||
if (HasDisplayPerimeterMotion(executed))
|
||||
throw new InvalidOperationException(
|
||||
$"{partName} has a display perimeter (a supplied blank's outline that is never cut) but no "
|
||||
+ "cutting plan. Run Plan Cutting before posting so only its cutouts are cut.");
|
||||
+ "cutting plan. Plan cutting first (Plate > Plan Cutting..., or --plan-cutting) so only its cutouts are cut.");
|
||||
return executed;
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ public static class PostVerificationAnalyzer
|
||||
// perimeter left is an unplanned blank whose outline a post would refuse.
|
||||
if (moves.Any(move => move.Layer == LayerType.DisplayPerimeter))
|
||||
Incomplete("This part has a display perimeter (a supplied blank's outline that is never cut) "
|
||||
+ "but no cutting plan; posts refuse it. Run Plan Cutting so only its cutouts are cut.");
|
||||
+ "but no cutting plan; posts refuse it. Plan cutting first (Plate > Plan Cutting..., or --plan-cutting) so only its cutouts are cut.");
|
||||
if (expectsCuts && !moves.Any(move => !move.Rapid
|
||||
&& move.Layer is LayerType.Cut or LayerType.Display
|
||||
&& move.Curve.Length > PostVerificationGeometry.Epsilon))
|
||||
|
||||
@@ -23,9 +23,11 @@ public enum ClampSettingsStatus
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The machine's fixed edge-clamp rail, persisted to a single JSON file (by default
|
||||
/// %APPDATA%\OpenNest\clamps.json). Off by default: until <see cref="Enabled"/> is set
|
||||
/// with at least one center, new nests get no clamps and behave exactly as before.
|
||||
/// An edge-clamp rail in given units, as a machine gives new nests (see
|
||||
/// <see cref="MachineConfig.GetClampSettings"/>) and as the legacy single
|
||||
/// %APPDATA%\OpenNest\clamps.json held it before each machine kept its own; that file is now
|
||||
/// read only to copy it onto a machine once (<see cref="LegacyClampMigration"/>). Off by default:
|
||||
/// until <see cref="Enabled"/> is set with at least one center, new nests get no clamps.
|
||||
/// Loading never throws; values are validated field by field.
|
||||
/// </summary>
|
||||
public sealed class ClampSettings
|
||||
|
||||
@@ -46,7 +46,7 @@ public sealed class DrawingLibraryBrowseSession : BrowseSession<DrawingLibraryPa
|
||||
public override string Summary =>
|
||||
PageSummary("drawings",
|
||||
Search.Length > 0 ? "No drawings match the search."
|
||||
: IsFilteredToNest ? "No library drawings match this nest's material and thickness. Choose Show all to see every drawing."
|
||||
: IsFilteredToNest ? "No library drawings match this nest's material and thickness. Tick Show all materials to see every drawing."
|
||||
: "No drawings in the library.");
|
||||
|
||||
/// <summary>Lifts or restores the nest filter and returns to the first page.</summary>
|
||||
|
||||
@@ -30,7 +30,7 @@ public sealed class DrawingLibraryEditSession
|
||||
if (listed.Id == Guid.Empty || listed.Revision < 1)
|
||||
throw new ArgumentException("Choose a listed library drawing to edit.", nameof(listed));
|
||||
if (listed.Archived)
|
||||
throw new ArgumentException("An archived library drawing cannot be edited. Restore it first.", nameof(listed));
|
||||
throw new ArgumentException("An archived library drawing cannot be edited.", nameof(listed));
|
||||
SavedBy = savedBy ?? "";
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace OpenNest.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Moves the single legacy clamps.json (or its shared copy) onto a machine once. The legacy
|
||||
/// rail is copied only while no machine has clamps of its own; after that it is never read.
|
||||
/// </summary>
|
||||
public static class LegacyClampMigration
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether <paramref name="legacy"/> (null when there is no legacy file) still has to be
|
||||
/// copied: it lists at least one clamp and none of <paramref name="machines"/> has clamps yet.
|
||||
/// </summary>
|
||||
public static bool IsNeeded(ClampSettings? legacy, IReadOnlyCollection<MachineConfig> machines) =>
|
||||
legacy is { ClampCount: > 0 } && machines.Count > 0 && machines.All(m => m.Clamps == null);
|
||||
|
||||
/// <summary>
|
||||
/// The machine that takes the legacy rail without asking: the nest defaults' machine when it
|
||||
/// is on file, otherwise the only machine. Null when there are several and none is the
|
||||
/// default, so the user has to choose.
|
||||
/// </summary>
|
||||
public static MachineConfig? Target(IReadOnlyCollection<MachineConfig> machines, Guid? defaultMachineId) =>
|
||||
machines.FirstOrDefault(m => m.Id == defaultMachineId)
|
||||
?? (machines.Count == 1 ? machines.First() : null);
|
||||
|
||||
/// <summary>Gives <paramref name="machine"/> the legacy rail, converted to the machine's units.</summary>
|
||||
public static void Apply(ClampSettings legacy, MachineConfig machine)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(legacy);
|
||||
ArgumentNullException.ThrowIfNull(machine);
|
||||
machine.Clamps = MachineClamps.FromSettings(legacy, machine.Units);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
namespace OpenNest.Data;
|
||||
|
||||
/// <summary>
|
||||
/// A machine's fixed edge-clamp rail, stored on its <see cref="MachineConfig"/> in the machine's
|
||||
/// units. New nests assigned the machine copy it as their own rail; editing it never changes an
|
||||
/// existing nest. <see cref="ToSettings"/> validates the stored values field by field.
|
||||
/// </summary>
|
||||
public sealed class MachineClamps
|
||||
{
|
||||
/// <summary>Whether new nests assigned this machine receive the rail. Default off.</summary>
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
/// <summary>Clamp extent along its edge.</summary>
|
||||
public double Width { get; set; } = ClampSettings.DefaultWidth;
|
||||
|
||||
/// <summary>Clamp intrusion into the sheet from its edge.</summary>
|
||||
public double Depth { get; set; } = ClampSettings.DefaultDepth;
|
||||
|
||||
/// <summary>Minutes to remove one clamp and put it back after cutting; never scaled.</summary>
|
||||
public double RemovalMinutes { get; set; } = ClampRail.DefaultRemovalMinutes;
|
||||
|
||||
/// <summary>Origin-side clamp centers along X, measured from the plate origin.</summary>
|
||||
public List<double> Centers { get; set; } = new();
|
||||
|
||||
/// <summary>Far-side clamp centers along X, measured from the plate origin.</summary>
|
||||
public List<double> FarSideCenters { get; set; } = new();
|
||||
|
||||
/// <summary>Origin-end clamp centers along Y, measured from the plate origin.</summary>
|
||||
public List<double> OriginEndCenters { get; set; } = new();
|
||||
|
||||
/// <summary>Far-end clamp centers along Y, measured from the plate origin.</summary>
|
||||
public List<double> FarEndCenters { get; set; } = new();
|
||||
|
||||
/// <summary>The <see cref="Units"/> matching a machine's <see cref="UnitSystem"/>.</summary>
|
||||
public static Units UnitsOf(UnitSystem units) =>
|
||||
units == UnitSystem.Millimeters ? Units.Millimeters : Units.Inches;
|
||||
|
||||
/// <summary>
|
||||
/// <paramref name="settings"/> converted to a machine in <paramref name="units"/>, e.g. for
|
||||
/// "Save as Machine Defaults" from a nest in other units or the clamps.json migration.
|
||||
/// </summary>
|
||||
public static MachineClamps FromSettings(ClampSettings settings, UnitSystem units)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
var converted = settings.ConvertedTo(UnitsOf(units));
|
||||
return new MachineClamps
|
||||
{
|
||||
Enabled = converted.Enabled,
|
||||
Width = converted.Width,
|
||||
Depth = converted.Depth,
|
||||
RemovalMinutes = converted.RemovalMinutes,
|
||||
Centers = converted.Centers.ToList(),
|
||||
FarSideCenters = converted.FarSideCenters.ToList(),
|
||||
OriginEndCenters = converted.OriginEndCenters.ToList(),
|
||||
FarEndCenters = converted.FarEndCenters.ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The rail as clamp settings in the machine's <paramref name="units"/>. An invalid size or
|
||||
/// removal time falls back to the default, and an invalid center is dropped, as when
|
||||
/// <see cref="ClampSettings.Parse"/> reads a file.
|
||||
/// </summary>
|
||||
public ClampSettings ToSettings(UnitSystem units)
|
||||
{
|
||||
var defaults = ClampSettings.FromRail(null, UnitsOf(units), Enabled);
|
||||
if (IsLength(Width) && Width > 0)
|
||||
defaults.Width = Width;
|
||||
if (IsLength(Depth) && Depth > 0)
|
||||
defaults.Depth = Depth;
|
||||
if (IsLength(RemovalMinutes) && RemovalMinutes >= 0)
|
||||
defaults.RemovalMinutes = RemovalMinutes;
|
||||
defaults.Centers = Valid(Centers);
|
||||
defaults.FarSideCenters = Valid(FarSideCenters);
|
||||
defaults.OriginEndCenters = Valid(OriginEndCenters);
|
||||
defaults.FarEndCenters = Valid(FarEndCenters);
|
||||
return defaults;
|
||||
}
|
||||
|
||||
private static double[] Valid(IEnumerable<double>? centers) =>
|
||||
(centers ?? Enumerable.Empty<double>()).Where(c => IsLength(c) && c >= 0).Distinct().Order().ToArray();
|
||||
|
||||
// Finite in either unit, so converting to an inch or millimeter nest cannot overflow.
|
||||
private static bool IsLength(double value) => double.IsFinite(value) && double.IsFinite(value * 25.4);
|
||||
}
|
||||
@@ -20,8 +20,18 @@ public class MachineConfig
|
||||
/// </summary>
|
||||
public SupportGridSettings? SupportGrid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The edge-clamp rail new nests assigned this machine receive, in <see cref="Units"/>; null
|
||||
/// until set (the machine then gives nests no clamps).
|
||||
/// </summary>
|
||||
public MachineClamps? Clamps { get; set; }
|
||||
|
||||
public MotionConfig GetMotionOrPlaceholder() => Motion ?? MotionConfig.Placeholder(Units);
|
||||
|
||||
/// <summary>The machine's clamps in its units; off, at the default clamp size, when it has none.</summary>
|
||||
public ClampSettings GetClampSettings() =>
|
||||
Clamps?.ToSettings(Units) ?? ClampSettings.FromRail(null, MachineClamps.UnitsOf(Units), enabled: false);
|
||||
|
||||
public ThicknessConfig? GetParameters(string material, double thickness) =>
|
||||
GetParameters(material, null, thickness);
|
||||
|
||||
|
||||
@@ -40,7 +40,10 @@ public static class SharedSettingKinds
|
||||
/// <summary>A post processor's settings, keyed by the post's type name.</summary>
|
||||
public const string Post = "post";
|
||||
|
||||
/// <summary>The <see cref="ClampSettings"/> new nests start from, under <see cref="DefaultKey"/>.</summary>
|
||||
/// <summary>
|
||||
/// The legacy <see cref="ClampSettings"/> new nests started from before each machine held its
|
||||
/// clamps, under <see cref="DefaultKey"/>; read only to copy them onto a machine once.
|
||||
/// </summary>
|
||||
public const string Clamps = "clamps";
|
||||
|
||||
/// <summary>The <see cref="NestDefaults"/> new nests start from, under <see cref="DefaultKey"/>.</summary>
|
||||
|
||||
@@ -447,6 +447,8 @@ public sealed class CuttingPlanProposal
|
||||
Quadrant = source.Quadrant,
|
||||
PartSpacing = source.PartSpacing,
|
||||
EdgeSpacing = source.EdgeSpacing,
|
||||
// View > Draw Support shows the proposal on the same bed.
|
||||
SupportBed = source.SupportBed,
|
||||
};
|
||||
// Machine clamps stay visible while inspecting the proposal; zones are immutable.
|
||||
foreach (var zone in source.ClampZones)
|
||||
|
||||
@@ -52,7 +52,7 @@ internal static class JointCuttingPlanSearch
|
||||
{
|
||||
var inserted = CutOffInsertion.Insert(snapshot, outcome.Order, attached, walk.CountExpansion, token);
|
||||
if (inserted != null)
|
||||
return walk.Ready(inserted);
|
||||
return walk.Ready(walk.FollowSegments(inserted));
|
||||
}
|
||||
catch (BudgetExceededException)
|
||||
{
|
||||
@@ -196,26 +196,35 @@ internal static class JointCuttingPlanSearch
|
||||
}
|
||||
|
||||
// "Cut the blocked part before every part whose cut contour its approach crossed", unless that
|
||||
// would contradict an order already required. False when nothing new was learned.
|
||||
// would contradict an order already required. When every such rule would (a sheet separator
|
||||
// is cut after everything), the blocked part cannot come earlier, so the tool must arrive
|
||||
// from beyond those parts instead: "cut the part it left from before them". False when
|
||||
// nothing new was learned.
|
||||
private static bool Learn(Attempt attempt, HashSet<int>[] prerequisites)
|
||||
{
|
||||
if (attempt.Blocked is not int blocked)
|
||||
return false;
|
||||
var learned = false;
|
||||
foreach (var crossed in attempt.Crossed.Order())
|
||||
{
|
||||
if (crossed == blocked || prerequisites[crossed].Contains(blocked) || Precedes(crossed, blocked, prerequisites))
|
||||
continue;
|
||||
prerequisites[crossed].Add(blocked);
|
||||
learned = true;
|
||||
}
|
||||
return learned;
|
||||
var rules = Rules(attempt, prerequisites).ToArray();
|
||||
foreach (var (first, then) in rules)
|
||||
prerequisites[then].Add(first);
|
||||
return rules.Length != 0;
|
||||
}
|
||||
|
||||
// True when a crossing of the blocked part's approach would teach a new order rule.
|
||||
private static bool CanLearn(Attempt attempt, HashSet<int>[] prerequisites) =>
|
||||
attempt.Blocked is int blocked && attempt.Crossed.Any(crossed => crossed != blocked
|
||||
&& !prerequisites[crossed].Contains(blocked) && !Precedes(crossed, blocked, prerequisites));
|
||||
Rules(attempt, prerequisites).Any();
|
||||
|
||||
// The rules Learn would add, as (cut first, cut then) pairs.
|
||||
private static IEnumerable<(int First, int Then)> Rules(Attempt attempt, HashSet<int>[] prerequisites)
|
||||
{
|
||||
if (attempt.Blocked is not int blocked)
|
||||
return [];
|
||||
var before = New(blocked);
|
||||
return before.Length != 0 || attempt.LastCut?.SourceOrdinal is not int departed ? before : New(departed);
|
||||
|
||||
(int, int)[] New(int first) => attempt.Crossed.Order()
|
||||
.Where(crossed => crossed != blocked && crossed != first && !prerequisites[crossed].Contains(first)
|
||||
&& !Precedes(crossed, first, prerequisites))
|
||||
.Select(crossed => (first, crossed)).ToArray();
|
||||
}
|
||||
|
||||
// True when 'first' must already come before 'second' through the prerequisite chain.
|
||||
private static bool Precedes(int first, int second, HashSet<int>[] prerequisites)
|
||||
@@ -334,10 +343,10 @@ internal static class JointCuttingPlanSearch
|
||||
}
|
||||
// A cutoff is a fixed program cut the same way wherever it goes, so replanning
|
||||
// the parts before it can only change where its approach starts. Cutting it
|
||||
// earlier never makes its own cut harder; learn that rather than stall here.
|
||||
// earlier never makes its own cut harder, and a sheet separator that cannot come
|
||||
// earlier needs the approach from elsewhere; learn that rather than stall here.
|
||||
if (prerequisites != null && sequence != null && attempt.Blocked is int blocked
|
||||
&& snapshot.Placements[blocked] is { IsCutOff: true, SeparatesSheet: false }
|
||||
&& CanLearn(attempt, prerequisites))
|
||||
&& snapshot.Placements[blocked].IsCutOff && CanLearn(attempt, prerequisites))
|
||||
return attempt;
|
||||
if (attempt.Advance(node))
|
||||
progressExpansions = Expansions;
|
||||
@@ -523,8 +532,9 @@ internal static class JointCuttingPlanSearch
|
||||
CountExpansion(source);
|
||||
var checker = node.Checker.Copy();
|
||||
if (Check(cut, cut.Execution, node.Position, checker, attempt))
|
||||
// A segment is transparent: the part after it ranks its entries and hole route
|
||||
// from where the tool was before the segment, as planned without it.
|
||||
// A segment is transparent to the part after it: that part ranks its outside entry
|
||||
// from where the tool was before the segment, as planned without it. Its hole
|
||||
// route starts where the tool is, the segment's end, as FollowSegments plans it.
|
||||
yield return new(new([.. node.Order, cut], cut.Execution.DeparturePoint, checker, null, node,
|
||||
IsSegment(cut) ? node.RoutePosition : null),
|
||||
cut.Execution.RapidDistanceFrom(node.Position), cut.SourceOrdinal, -1, -1);
|
||||
@@ -559,7 +569,7 @@ internal static class JointCuttingPlanSearch
|
||||
}
|
||||
var preference = node.Active?.Preference;
|
||||
if (node.Active?.Perimeter is { } outside && preference == null)
|
||||
preference = PlanHoles(node.Active, outside);
|
||||
preference = PlanHoles(node.Active.Source, node.Active.Boundary.Position, outside);
|
||||
var choices = node.Active?.Choices ?? [];
|
||||
var arrival = node.Active?.Arrival ?? node.Position;
|
||||
var before = node.Active?.Before ?? node.Checker;
|
||||
@@ -1216,12 +1226,13 @@ internal static class JointCuttingPlanSearch
|
||||
return ordered;
|
||||
}
|
||||
|
||||
private HolePreference PlanHoles(ActivePart active, ContourChoice perimeter)
|
||||
// The hole route and preferred hole entries from the tool's global arrival onto the part,
|
||||
// ending at the outside entry.
|
||||
private HolePreference PlanHoles(FixedProgramPlacement source, Vector arrival, ContourChoice perimeter)
|
||||
{
|
||||
var source = active.Source;
|
||||
var prepared = source.Prepared;
|
||||
var holes = Enumerable.Range(0, prepared.PerimeterOrdinal).ToArray();
|
||||
var localArrival = active.Boundary.RoutePosition - source.Location;
|
||||
var localArrival = arrival - source.Location;
|
||||
var centres = CuttingHoleOrder.Centres(prepared, localArrival, token);
|
||||
var endpoint = perimeter.Point;
|
||||
var entries = new Dictionary<int, ContourChoice>();
|
||||
@@ -1255,6 +1266,72 @@ internal static class JointCuttingPlanSearch
|
||||
return new(route, entries, pierces, endpoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The order with segments placed, where each holed part cut straight after a segment
|
||||
/// takes the hole route and entries planned from the segment's end, where the tool
|
||||
/// really is. The free search planned the part as if the segment were not there, from
|
||||
/// where the tool was before it. The part's outside entry and the order stay, so the
|
||||
/// route is still the one planned without the lines; a kept order replanned later plans
|
||||
/// the same holes from the same point. A part keeps its planned holes when the new
|
||||
/// route has no preferred entry for every hole or does not pass the checks.
|
||||
/// </summary>
|
||||
internal IReadOnlyList<FixedProgramPlacement> FollowSegments(IReadOnlyList<FixedProgramPlacement> order)
|
||||
{
|
||||
var followed = order.ToArray();
|
||||
var checker = new ReleasedContourState(reportMissingLeadIns: false);
|
||||
var position = snapshot.StartPoint;
|
||||
try
|
||||
{
|
||||
for (var index = 0; index < followed.Length; index++)
|
||||
{
|
||||
if (index > 0 && IsSegment(followed[index - 1])
|
||||
&& FromSegment(followed[index], position, checker) is { } replanned)
|
||||
followed[index] = replanned;
|
||||
var placement = followed[index];
|
||||
checker.Check(placement.Execution, position, placement.SourceOrdinal + 1, placement.IsCutOff,
|
||||
placement.FixedMotions(placement.Execution), token);
|
||||
position = placement.Execution.DeparturePoint;
|
||||
}
|
||||
}
|
||||
catch (BudgetExceededException)
|
||||
{
|
||||
// The plan is complete without this refinement; keep it as placed.
|
||||
return order;
|
||||
}
|
||||
return followed;
|
||||
}
|
||||
|
||||
// The part re-planned from arrival with its outside entry kept, or null to keep it.
|
||||
private FixedProgramPlacement FromSegment(FixedProgramPlacement placement, Vector arrival,
|
||||
ReleasedContourState checker)
|
||||
{
|
||||
var source = snapshot.Placements[placement.SourceOrdinal];
|
||||
var prepared = source.Prepared;
|
||||
if (prepared is not { HasCutPerimeter: true } || prepared.PerimeterOrdinal == 0
|
||||
|| placement.ContourChoices.Count != prepared.Count
|
||||
|| placement.ContourChoices[^1].ContourOrdinal != prepared.PerimeterOrdinal)
|
||||
return null;
|
||||
var perimeter = placement.ContourChoices[^1];
|
||||
var preference = PlanHoles(source, arrival, perimeter);
|
||||
if (preference.Entries.Count != prepared.PerimeterOrdinal)
|
||||
return null;
|
||||
var choices = preference.Route.Select(hole => preference.Entries[hole]).Append(perimeter).ToArray();
|
||||
Program program;
|
||||
OwnedExecution execution;
|
||||
try
|
||||
{
|
||||
CountExpansion(source);
|
||||
program = prepared.Emit(choices);
|
||||
execution = ExecutionMotionReader.Read(program, source.Location, arrival, token);
|
||||
}
|
||||
catch (Exception ex) when (ex is ArgumentException or InvalidOperationException or ArithmeticException or NotSupportedException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return Check(source, execution, arrival, checker.Copy(), new Attempt(null), choices)
|
||||
? source.Propose(program, execution, choices, token) : null;
|
||||
}
|
||||
|
||||
// The placements cut at a node, and the excluded ones, which count as cut throughout.
|
||||
private HashSet<int> Finished(Node node)
|
||||
{
|
||||
@@ -1568,8 +1645,8 @@ internal static class JointCuttingPlanSearch
|
||||
ContourChoice Perimeter = null, HolePreference Preference = null);
|
||||
/// <summary>
|
||||
/// A search state; Previous links a whole-part boundary to the boundary before it. Anchor,
|
||||
/// when set, is where the tool was before the cut-off segments cut last: entries and hole
|
||||
/// routes rank from <see cref="RoutePosition"/>, every rapid is checked from Position.
|
||||
/// when set, is where the tool was before the cut-off segments cut last: outside entries
|
||||
/// rank from <see cref="RoutePosition"/>; hole routes and every rapid start from Position.
|
||||
/// </summary>
|
||||
private sealed record Node(FixedProgramPlacement[] Order, Vector Position, ReleasedContourState Checker,
|
||||
ActivePart Active, Node Previous, Vector? Anchor = null)
|
||||
|
||||
@@ -19,4 +19,17 @@ public class ClampZonePreviewTests
|
||||
Assert.Equal(2, preview.ClampZones.Count);
|
||||
Assert.Null(preview.ClampRail); // a detached display copy never re-resolves
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PreviewCarriesThePlatesSupportBed()
|
||||
{
|
||||
var plate = BestEffortCuttingPlanTests.Plate(BestEffortCuttingPlanTests.TouchingContours());
|
||||
plate.SupportBed = new OpenNest.Support.SupportGrid(25, 100, 2, 2, stabilityMargin: 0.1);
|
||||
|
||||
var proposal = CuttingPlanBatch.Capture([plate], ExplicitContourTests.Parameters(), false).Plan();
|
||||
var preview = proposal.BuildPreview(0);
|
||||
|
||||
Assert.NotNull(preview);
|
||||
Assert.Same(plate.SupportBed, preview.SupportBed);
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,97 @@ public class ContourEntryCandidateTests
|
||||
Assert.Equal(8, forward.Count);
|
||||
}
|
||||
|
||||
/// <summary>Square 0..10 whose corners are 0.5-radius fillets, counterclockwise or clockwise.</summary>
|
||||
internal static Program RoundedSquare(bool clockwise)
|
||||
{
|
||||
var p = new Program();
|
||||
p.MoveTo(0.5, 0);
|
||||
if (clockwise)
|
||||
{
|
||||
p.ArcTo(new Vector(0, 0.5), new Vector(0.5, 0.5), RotationType.CW);
|
||||
p.LineTo(0, 9.5);
|
||||
p.ArcTo(new Vector(0.5, 10), new Vector(0.5, 9.5), RotationType.CW);
|
||||
p.LineTo(9.5, 10);
|
||||
p.ArcTo(new Vector(10, 9.5), new Vector(9.5, 9.5), RotationType.CW);
|
||||
p.LineTo(10, 0.5);
|
||||
p.ArcTo(new Vector(9.5, 0), new Vector(9.5, 0.5), RotationType.CW);
|
||||
p.LineTo(0.5, 0);
|
||||
return p;
|
||||
}
|
||||
p.LineTo(9.5, 0);
|
||||
p.ArcTo(new Vector(10, 0.5), new Vector(9.5, 0.5), RotationType.CCW);
|
||||
p.LineTo(10, 9.5);
|
||||
p.ArcTo(new Vector(9.5, 10), new Vector(9.5, 9.5), RotationType.CCW);
|
||||
p.LineTo(0.5, 10);
|
||||
p.ArcTo(new Vector(0, 9.5), new Vector(0.5, 9.5), RotationType.CCW);
|
||||
p.LineTo(0, 0.5);
|
||||
p.ArcTo(new Vector(0.5, 0), new Vector(0.5, 0.5), RotationType.CCW);
|
||||
return p;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void CornerFilletJoints_AreConvexCorners(bool clockwise)
|
||||
{
|
||||
var prepared = Capture(RoundedSquare(clockwise));
|
||||
|
||||
var candidates = prepared.AutomaticEntryCandidates(prepared.PerimeterOrdinal);
|
||||
|
||||
// Both joints of each fillet start the cut at its corner, one radius from the sharp corner.
|
||||
var corners = candidates.Where(c => c.Kind == AutomaticEntryKind.ConvexCorner).ToList();
|
||||
Assert.Equal(8, corners.Count);
|
||||
Assert.All(corners, c => Assert.Equal(0.5, c.CornerReach, 9));
|
||||
Assert.Contains(corners, c => Distance(c.Choice.Point, new Vector(10, 9.5)) < 1e-6);
|
||||
Assert.Contains(corners, c => Distance(c.Choice.Point, new Vector(9.5, 10)) < 1e-6);
|
||||
Assert.DoesNotContain(candidates, c => c.Kind == AutomaticEntryKind.TangentJoint);
|
||||
Assert.Equal(4, candidates.Count(c => c.Kind == AutomaticEntryKind.StraightMidpoint));
|
||||
Assert.All(candidates.Where(c => c.Kind == AutomaticEntryKind.StraightMidpoint),
|
||||
c => Assert.Equal(0, c.CornerReach));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FilletLongerThanItsEdge_StaysATangentJoint()
|
||||
{
|
||||
// A 5-radius quarter arc after a 1-long bottom edge is a curve, not a rounded corner.
|
||||
var p = new Program();
|
||||
p.MoveTo(0, 0);
|
||||
p.LineTo(1, 0);
|
||||
p.ArcTo(new Vector(6, 5), new Vector(1, 5), RotationType.CCW);
|
||||
p.LineTo(6, 6);
|
||||
p.LineTo(0, 6);
|
||||
p.LineTo(0, 0);
|
||||
var prepared = Capture(p);
|
||||
|
||||
var candidates = prepared.AutomaticEntryCandidates(prepared.PerimeterOrdinal);
|
||||
|
||||
Assert.Equal(2, candidates.Count(c => c.Kind == AutomaticEntryKind.TangentJoint));
|
||||
Assert.DoesNotContain(candidates, c => c.Kind == AutomaticEntryKind.ConvexCorner
|
||||
&& (Distance(c.Choice.Point, new Vector(1, 0)) < 1e-6 || Distance(c.Choice.Point, new Vector(6, 5)) < 1e-6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InsideCornerFillet_StaysATangentJoint()
|
||||
{
|
||||
// An L whose inside corner is rounded: that fillet turns the reflex way.
|
||||
var p = new Program();
|
||||
p.MoveTo(0, 0);
|
||||
p.LineTo(10, 0);
|
||||
p.LineTo(10, 4);
|
||||
p.LineTo(5, 4);
|
||||
p.ArcTo(new Vector(4, 5), new Vector(5, 5), RotationType.CW);
|
||||
p.LineTo(4, 10);
|
||||
p.LineTo(0, 10);
|
||||
p.LineTo(0, 0);
|
||||
var prepared = Capture(p);
|
||||
|
||||
var candidates = prepared.AutomaticEntryCandidates(prepared.PerimeterOrdinal);
|
||||
|
||||
var joints = candidates.Where(c => c.Kind == AutomaticEntryKind.TangentJoint).ToList();
|
||||
Assert.Contains(joints, c => Distance(c.Choice.Point, new Vector(5, 4)) < 1e-6);
|
||||
Assert.Contains(joints, c => Distance(c.Choice.Point, new Vector(4, 5)) < 1e-6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TangentLineArcJoint_IsTangentJoint_NotACorner()
|
||||
{
|
||||
|
||||
@@ -93,6 +93,22 @@ public class ContourEntryRankingTests
|
||||
Assert.True(rightMid < bottomMid);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void FilletedCorner_BeatsAFacingMidpointNearerTheRoute(bool clockwise)
|
||||
{
|
||||
// Travel favours the right edge's midpoint, but a long edge's middle is a last resort:
|
||||
// the joints of the facing rounded corner count on both of its sides and lead.
|
||||
var ranked = Catalogue(ContourEntryCandidateTests.RoundedSquare(clockwise))
|
||||
.RankTowardNextCut(new Vector(14, 6), new Vector(12, 5)).ToList();
|
||||
|
||||
Assert.Equal(AutomaticEntryKind.ConvexCorner, ranked[0].Kind);
|
||||
Assert.True(At(ranked[0], 10, 9.5) || At(ranked[0], 9.5, 10));
|
||||
var rightMid = ranked.FindIndex(c => c.Kind == AutomaticEntryKind.StraightMidpoint && At(c, 10, 5));
|
||||
Assert.True(ranked.FindIndex(c => At(c, 10, 0.5)) < rightMid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TangentAndMidpoint_ShareARankTier()
|
||||
{
|
||||
|
||||
@@ -109,6 +109,65 @@ public class CutOffSegmentPlanningTests
|
||||
Assert.Equal(result.RapidDistance, kept.RapidDistance, 6);
|
||||
}
|
||||
|
||||
// A frame with two small holes on its left strip, one above the other, and a window,
|
||||
// between a locked square A at the top left, cut before it, and a locked square B to its
|
||||
// right, cut after it. A line through the frame's right strip stops halfway up, so its one
|
||||
// segment runs from the bottom edge to just below the frame and is cut straight before it.
|
||||
// Planned without the segment, from A, the frame would cut its upper hole first; the tool
|
||||
// is really at the bottom, so it cuts the lower hole first instead of crossing its own
|
||||
// rapid. Replanned with the order kept, the frame plans the same holes from the same point.
|
||||
[Fact]
|
||||
public void PartAfterSegment_PlansItsHolesFromTheSegmentsEnd()
|
||||
{
|
||||
var parameters = ExplicitContourTests.Parameters();
|
||||
var nest = new Nest();
|
||||
var plate = nest.CreatePlate();
|
||||
plate.Size = new Size(60, 120);
|
||||
plate.Parts.Add(LockedSquare("A", new Vector(2, 42), topLeft: false));
|
||||
var frame = new Part(new Drawing("frame", Frame()), new Vector(30, 5));
|
||||
plate.Parts.Add(frame);
|
||||
plate.Parts.Add(LockedSquare("B", new Vector(80, 40), topLeft: false));
|
||||
var cutOff = new CutOff(new Vector(65, 0), CutOffAxis.Vertical) { EndLimit = 25 };
|
||||
plate.CutOffs.Add(cutOff);
|
||||
plate.RegenerateCutOffs(new CutOffSettings());
|
||||
PlateSequencing.PlaceCutOffs(plate, [cutOff]);
|
||||
Assert.Single(CutOffSegments.Of(plate, cutOff));
|
||||
|
||||
var result = CuttingPlanService.Plan(CuttingPlanRequest.ForPlate(plate, confirmedParameters: parameters));
|
||||
|
||||
Assert.True(result.Status == CuttingPlanStatus.Ready && result.IndependentlyReplayed, Describe(result));
|
||||
var order = result.ProposedOrder.Select(o => o.SourcePart.BaseDrawing.IsCutOff ? "s" : o.SourcePart.BaseDrawing.Name);
|
||||
Assert.Equal("A s frame B", string.Join(" ", order));
|
||||
var planned = result.ProposedOrder[2];
|
||||
var rapids = planned.Execution.Motions.Where(m => m.Rapid).Select(m => m.End).ToArray();
|
||||
// Into the lower hole (y 14.5 to 15.1 on the sheet), then the upper one (34.5 to 35.1).
|
||||
Assert.InRange(rapids[0].Y, 14, 16);
|
||||
Assert.InRange(rapids[1].Y, 34, 36);
|
||||
|
||||
Assert.Equal(CuttingCommitStatus.Applied, CuttingPlanService.Apply([result]).Status);
|
||||
var kept = CuttingPlanService.Plan(CuttingPlanRequest.ForPlate(plate, confirmedParameters: parameters,
|
||||
preservePartOrder: true));
|
||||
Assert.True(kept.Status == CuttingPlanStatus.Ready && kept.IndependentlyReplayed, Describe(kept));
|
||||
Assert.Equal(result.RapidDistance, kept.RapidDistance, 6);
|
||||
}
|
||||
|
||||
// 40 x 40 with 0.6 square holes at (2.5, 9.5) and (2.5, 29.5) and an 18 x 30 window.
|
||||
private static Program Frame()
|
||||
{
|
||||
var program = new Program();
|
||||
void Loop(params Vector[] points)
|
||||
{
|
||||
program.MoveTo(points[0].X, points[0].Y);
|
||||
foreach (var point in points.Skip(1).Append(points[0]))
|
||||
program.LineTo(point.X, point.Y);
|
||||
}
|
||||
Loop(new(0, 0), new(0, 40), new(40, 40), new(40, 0));
|
||||
foreach (var y in new[] { 29.5, 9.5 })
|
||||
Loop(new(2.5, y), new(3.1, y), new(3.1, y + 0.6), new(2.5, y + 0.6));
|
||||
Loop(new(12, 5), new(30, 5), new(30, 35), new(12, 35));
|
||||
return program;
|
||||
}
|
||||
|
||||
private const double Gap = 0.25, Width = 10.6, Neck = 5.6, Height = 20, Margin = 0.25;
|
||||
// The slanted shoulders need more horizontal room than the gap.
|
||||
private const double Pitch = (Width + Neck) / 2 + 2 * Gap;
|
||||
|
||||
@@ -79,6 +79,43 @@ public class CuttingDependencyTests
|
||||
&& f.Message.Contains("before the sheet is separated"));
|
||||
}
|
||||
|
||||
// A column of two wide parts under three narrow ones, beside a sheet separator at X 12.5
|
||||
// pierced at (12.5, 0). Climbing the column ends at the top, where the straight approach to
|
||||
// that pierce crosses the wide parts, and the separator cannot be cut any earlier. The search
|
||||
// learns the other way round, the part the approach left from before the parts it crossed,
|
||||
// and so finishes beside the pierce. It used to learn nothing and spend its whole budget.
|
||||
[Fact]
|
||||
public void Plan_ApproachIntoASeparatorCrossingCutParts_LearnsToLeaveFromBeyondThem()
|
||||
{
|
||||
var (plate, column, separator) = ColumnBesideSeparator();
|
||||
|
||||
var result = CuttingPlanService.Plan(CuttingPlanRequest.ForPlate(plate,
|
||||
confirmedParameters: ExplicitContourTests.Parameters()));
|
||||
|
||||
Assert.True(result.Status == CuttingPlanStatus.Ready, Describe(result));
|
||||
var order = result.ProposedOrder.Select(o => o.SourcePart).ToList();
|
||||
Assert.Same(separator, order[^1]);
|
||||
Assert.Contains(order[^2], column[..2]);
|
||||
Assert.True(result.Expansions < 400, Describe(result));
|
||||
}
|
||||
|
||||
private static (Plate, Part[] Column, Part Separator) ColumnBesideSeparator()
|
||||
{
|
||||
var nest = new Nest();
|
||||
var plate = nest.CreatePlate();
|
||||
plate.Size = new Size(100, 100);
|
||||
Part[] column =
|
||||
[
|
||||
Rectangle(2, 2, 10, 10), Rectangle(2, 14, 10, 10),
|
||||
Rectangle(2, 26, 5, 10), Rectangle(2, 38, 5, 10), Rectangle(2, 50, 5, 10),
|
||||
];
|
||||
foreach (var part in column)
|
||||
plate.Parts.Add(part);
|
||||
plate.CutOffs.Add(new CutOff(new Vector(12.5, 0), CutOffAxis.Vertical));
|
||||
plate.RegenerateCutOffs(new CutOffSettings());
|
||||
return (plate, column, plate.Parts.Single(p => p.BaseDrawing.IsCutOff));
|
||||
}
|
||||
|
||||
// The tour cuts B, then the locked rectangle A (leaving right), then the cutoff pierced at
|
||||
// (10, 0) below-left of A: that approach crosses A. Replanning B's entries can never fix it,
|
||||
// so the search learns "cutoff first" at once instead of retrying each of B's entries.
|
||||
|
||||
@@ -100,7 +100,7 @@ public class DrawingLibraryBrowseSessionTests
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false, "", "No library drawings match this nest's material and thickness. Choose Show all to see every drawing.")]
|
||||
[InlineData(false, "", "No library drawings match this nest's material and thickness. Tick Show all materials to see every drawing.")]
|
||||
[InlineData(true, "", "No drawings in the library.")]
|
||||
[InlineData(false, "no such text", "No drawings match the search.")]
|
||||
public async Task Summary_ExplainsAnEmptyResult(bool showAll, string search, string expected)
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
using OpenNest.Data;
|
||||
|
||||
namespace OpenNest.Tests.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Each machine's own clamp rail (<see cref="MachineConfig.Clamps"/>, in the machine's units),
|
||||
/// the rail new nests copy from it, and the one-time copy of the legacy clamps.json onto a machine.
|
||||
/// </summary>
|
||||
public class MachineClampsTests : IDisposable
|
||||
{
|
||||
private readonly string _directory = Path.Combine(Path.GetTempPath(), "OpenNestTests", Guid.NewGuid().ToString());
|
||||
|
||||
public MachineClampsTests() => Directory.CreateDirectory(_directory);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Directory.Exists(_directory))
|
||||
Directory.Delete(_directory, recursive: true);
|
||||
}
|
||||
|
||||
private static MachineClamps Rail(bool enabled = true) => new()
|
||||
{
|
||||
Enabled = enabled,
|
||||
Width = 1.5,
|
||||
Depth = 0.625,
|
||||
RemovalMinutes = 3,
|
||||
Centers = new List<double> { 6, 21, 36 },
|
||||
FarEndCenters = new List<double> { 10 },
|
||||
};
|
||||
|
||||
private static ClampSettings Legacy(Units units = Units.Inches) => new()
|
||||
{
|
||||
Enabled = true,
|
||||
Units = units,
|
||||
Width = 2,
|
||||
Depth = 0.5,
|
||||
RemovalMinutes = 4,
|
||||
Centers = new double[] { 12, 24 },
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void SaveMachine_RoundTripsTheClamps()
|
||||
{
|
||||
var provider = new LocalJsonProvider(_directory);
|
||||
var machine = new MachineConfig { Name = "Laser", Clamps = Rail() };
|
||||
|
||||
provider.SaveMachine(machine);
|
||||
var clamps = provider.GetMachine(machine.Id)!.Clamps!;
|
||||
|
||||
Assert.True(clamps.Enabled);
|
||||
Assert.Equal(1.5, clamps.Width);
|
||||
Assert.Equal(0.625, clamps.Depth);
|
||||
Assert.Equal(3, clamps.RemovalMinutes);
|
||||
Assert.Equal(new double[] { 6, 21, 36 }, clamps.Centers);
|
||||
Assert.Empty(clamps.FarSideCenters);
|
||||
Assert.Equal(new double[] { 10 }, clamps.FarEndCenters);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MachineSavedBeforeClamps_LoadsWithoutClamps()
|
||||
{
|
||||
var provider = new LocalJsonProvider(_directory);
|
||||
var machine = new MachineConfig { Name = "Laser" };
|
||||
provider.SaveMachine(machine);
|
||||
|
||||
var loaded = provider.GetMachine(machine.Id)!;
|
||||
|
||||
Assert.Null(loaded.Clamps);
|
||||
Assert.Null(loaded.GetClampSettings().RailFor(Units.Inches));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MachineWithoutClamps_GivesNoRailAtTheDefaultSizeInItsUnits()
|
||||
{
|
||||
var machine = new MachineConfig { Units = UnitSystem.Millimeters };
|
||||
|
||||
var settings = machine.GetClampSettings();
|
||||
|
||||
Assert.False(settings.Enabled);
|
||||
Assert.Equal(Units.Millimeters, settings.Units);
|
||||
Assert.Equal(ClampSettings.DefaultWidth * 25.4, settings.Width, 9);
|
||||
Assert.Equal(0, settings.ClampCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DisabledClamps_GiveNewNestsNoRail()
|
||||
{
|
||||
var machine = new MachineConfig { Clamps = Rail(enabled: false) };
|
||||
var nest = new Nest { Units = Units.Inches };
|
||||
|
||||
machine.GetClampSettings().ApplyToNewNest(nest);
|
||||
|
||||
Assert.Null(nest.PlateDefaults.ClampRail);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MillimeterMachine_GivesAnInchNestItsRailConverted()
|
||||
{
|
||||
var machine = new MachineConfig
|
||||
{
|
||||
Units = UnitSystem.Millimeters,
|
||||
Clamps = new MachineClamps
|
||||
{
|
||||
Enabled = true,
|
||||
Width = 38.1,
|
||||
Depth = 12.7,
|
||||
RemovalMinutes = 2,
|
||||
Centers = new List<double> { 254 },
|
||||
},
|
||||
};
|
||||
var nest = new Nest { Units = Units.Inches };
|
||||
|
||||
machine.GetClampSettings().ApplyToNewNest(nest);
|
||||
|
||||
var rail = nest.PlateDefaults.ClampRail!;
|
||||
Assert.Equal(1.5, rail.Width, 9);
|
||||
Assert.Equal(0.5, rail.Depth, 9);
|
||||
Assert.Equal(2, rail.RemovalMinutes);
|
||||
Assert.Equal(10, Assert.Single(rail.Clamps).Center, 9);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EditingTheMachine_NeverMovesAnExistingNestsClamps()
|
||||
{
|
||||
var machine = new MachineConfig { Clamps = Rail() };
|
||||
var nest = new Nest { Units = Units.Inches };
|
||||
machine.GetClampSettings().ApplyToNewNest(nest);
|
||||
|
||||
machine.Clamps!.Centers = new List<double> { 50 };
|
||||
machine.Clamps.Width = 3;
|
||||
|
||||
var rail = nest.PlateDefaults.ClampRail!;
|
||||
Assert.Equal(1.5, rail.Width);
|
||||
Assert.Equal(new double[] { 6, 21, 36 },
|
||||
rail.Clamps.Where(c => c.Edge == ClampEdge.OriginSide).Select(c => c.Center));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidStoredValues_FallBackOrAreDropped()
|
||||
{
|
||||
var clamps = new MachineClamps
|
||||
{
|
||||
Enabled = true,
|
||||
Width = -1,
|
||||
Depth = double.NaN,
|
||||
RemovalMinutes = -2,
|
||||
Centers = new List<double> { 30, -5, double.PositiveInfinity, 10, 30 },
|
||||
FarSideCenters = null!,
|
||||
};
|
||||
|
||||
var settings = clamps.ToSettings(UnitSystem.Inches);
|
||||
|
||||
Assert.Equal(ClampSettings.DefaultWidth, settings.Width);
|
||||
Assert.Equal(ClampSettings.DefaultDepth, settings.Depth);
|
||||
Assert.Equal(ClampRail.DefaultRemovalMinutes, settings.RemovalMinutes);
|
||||
Assert.Equal(new double[] { 10, 30 }, settings.Centers);
|
||||
Assert.Empty(settings.FarSideCenters);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromSettings_ConvertsToTheMachineUnits()
|
||||
{
|
||||
var clamps = MachineClamps.FromSettings(Legacy(), UnitSystem.Millimeters);
|
||||
|
||||
Assert.True(clamps.Enabled);
|
||||
Assert.Equal(50.8, clamps.Width, 9);
|
||||
Assert.Equal(12.7, clamps.Depth, 9);
|
||||
Assert.Equal(4, clamps.RemovalMinutes);
|
||||
Assert.Equal(new[] { 304.8, 609.6 }, clamps.Centers.Select(c => System.Math.Round(c, 9)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Migration_IsNeededOnlyWhileNoMachineHasClamps()
|
||||
{
|
||||
var a = new MachineConfig { Name = "A" };
|
||||
var b = new MachineConfig { Name = "B" };
|
||||
|
||||
Assert.True(LegacyClampMigration.IsNeeded(Legacy(), new[] { a, b }));
|
||||
Assert.False(LegacyClampMigration.IsNeeded(null, new[] { a, b }));
|
||||
Assert.False(LegacyClampMigration.IsNeeded(new ClampSettings { Enabled = true }, new[] { a, b }));
|
||||
Assert.False(LegacyClampMigration.IsNeeded(Legacy(), Array.Empty<MachineConfig>()));
|
||||
|
||||
LegacyClampMigration.Apply(Legacy(), a);
|
||||
|
||||
Assert.False(LegacyClampMigration.IsNeeded(Legacy(), new[] { a, b }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Migration_TargetsTheDefaultMachine()
|
||||
{
|
||||
var a = new MachineConfig { Name = "A" };
|
||||
var b = new MachineConfig { Name = "B" };
|
||||
|
||||
Assert.Same(b, LegacyClampMigration.Target(new[] { a, b }, b.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Migration_TargetsTheOnlyMachine()
|
||||
{
|
||||
var only = new MachineConfig { Name = "Only" };
|
||||
|
||||
Assert.Same(only, LegacyClampMigration.Target(new[] { only }, null));
|
||||
Assert.Same(only, LegacyClampMigration.Target(new[] { only }, Guid.NewGuid()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Migration_WithSeveralMachinesAndNoDefault_LeavesTheChoiceToTheUser()
|
||||
{
|
||||
var machines = new[] { new MachineConfig { Name = "A" }, new MachineConfig { Name = "B" } };
|
||||
|
||||
Assert.Null(LegacyClampMigration.Target(machines, null));
|
||||
Assert.Null(LegacyClampMigration.Target(machines, Guid.NewGuid()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Migration_CopiesTheLegacyFileIntoTheMachineUnits()
|
||||
{
|
||||
var path = Path.Combine(_directory, "clamps.json");
|
||||
Legacy().Save(path);
|
||||
var machine = new MachineConfig { Units = UnitSystem.Millimeters };
|
||||
|
||||
LegacyClampMigration.Apply(ClampSettings.Load(path), machine);
|
||||
|
||||
var rail = machine.GetClampSettings().RailFor(Units.Inches)!;
|
||||
Assert.Equal(2, rail.Width, 9);
|
||||
Assert.Equal(4, rail.RemovalMinutes);
|
||||
Assert.Equal(new[] { 12.0, 24.0 }, rail.Clamps.Select(c => System.Math.Round(c.Center, 9)));
|
||||
Assert.Equal(new[] { 304.8, 609.6 }, machine.Clamps!.Centers.Select(c => System.Math.Round(c, 9)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using OpenNest.Bending;
|
||||
using OpenNest.Controls;
|
||||
using OpenNest.Geometry;
|
||||
using OpenNest.Math;
|
||||
|
||||
namespace OpenNest.WinForms.Tests.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Bends are kept in the drawing's source frame while its program starts at the origin, so a
|
||||
/// placed part draws them with <c>Source.Offset</c> removed.
|
||||
/// </summary>
|
||||
public class BendLinePlacementTests
|
||||
{
|
||||
[Fact]
|
||||
public void BendToWorld_RemovesSourceOffsetBeforePlacing()
|
||||
{
|
||||
var drawing = new Drawing("bent", new CNC.Program());
|
||||
drawing.Source.Offset = new Vector(100, 50);
|
||||
// In the source frame the bend runs across the part at local x = 5.
|
||||
var bend = new Bend { StartPoint = new Vector(105, 50), EndPoint = new Vector(105, 60) };
|
||||
var part = new Part(drawing, new Vector(10, 20));
|
||||
|
||||
Assert.Equal(new Vector(15, 20), PlateRenderer.BendToWorld(part, bend.StartPoint));
|
||||
Assert.Equal(new Vector(15, 30), PlateRenderer.BendToWorld(part, bend.EndPoint));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BendToWorld_RotatesAboutTheProgramOrigin()
|
||||
{
|
||||
var drawing = new Drawing("bent", new CNC.Program());
|
||||
drawing.Source.Offset = new Vector(100, 50);
|
||||
var part = new Part(drawing, new Vector(10, 20));
|
||||
part.Rotate(Angle.HalfPI, part.Location);
|
||||
|
||||
var world = PlateRenderer.BendToWorld(part, new Vector(105, 50));
|
||||
|
||||
Assert.Equal(10, world.X, 9);
|
||||
Assert.Equal(25, world.Y, 9);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
using System.Windows.Forms;
|
||||
using OpenNest.Data;
|
||||
using OpenNest.Forms;
|
||||
|
||||
namespace OpenNest.WinForms.Tests.Forms;
|
||||
|
||||
/// <summary>
|
||||
/// Machine clamps in the desktop: the Clamps tab of Machine Configuration edits a machine's rail,
|
||||
/// and Nest > Clamps saves its machine defaults to the nest's machine.
|
||||
/// </summary>
|
||||
public class MachineClampsFormsTests
|
||||
{
|
||||
[Fact]
|
||||
public void ClampsTab_EditsTheMachineRail()
|
||||
{
|
||||
RunSta(() =>
|
||||
{
|
||||
var directory = Path.Combine(Path.GetTempPath(), "OpenNestTests", Guid.NewGuid().ToString());
|
||||
Directory.CreateDirectory(directory);
|
||||
try
|
||||
{
|
||||
var provider = new LocalJsonProvider(directory);
|
||||
var machine = new MachineConfig { Name = "Laser" };
|
||||
provider.SaveMachine(machine);
|
||||
|
||||
using var form = new MachineConfigForm(provider);
|
||||
var node = Find<TreeView>(form, "_tree").Nodes.Cast<TreeNode>().Single(n => n.Tag is MachineConfig);
|
||||
// A hidden tree raises no AfterSelect, so show the machine as selecting it would.
|
||||
typeof(MachineConfigForm)
|
||||
.GetMethod("Tree_AfterSelect", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!
|
||||
.Invoke(form, new object[] { null, new TreeViewEventArgs(node) });
|
||||
var shown = (MachineConfig)node.Tag;
|
||||
Assert.Null(shown.Clamps);
|
||||
|
||||
var tab = All<TabControl>(form).Single().TabPages.Cast<TabPage>().Single(p => p.Text == "Clamps");
|
||||
All<CheckBox>(tab).Single(c => c.Text == "Give new nests these clamps").Checked = true;
|
||||
var add = All<Button>(tab).Single(b => b.Text == "Add");
|
||||
All<System.Windows.Forms.NumericUpDown>(add.Parent).Single().Value = 24;
|
||||
Click(add);
|
||||
|
||||
Assert.NotNull(shown.Clamps);
|
||||
Assert.True(shown.Clamps!.Enabled);
|
||||
Assert.Equal(new double[] { 24 }, shown.Clamps.Centers);
|
||||
Assert.Equal(ClampSettings.DefaultWidth, shown.Clamps.Width);
|
||||
Assert.NotNull(shown.GetClampSettings().RailFor(Units.Inches));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Directory.Delete(directory, recursive: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClampsDialog_WithoutAMachine_CannotSaveMachineDefaults()
|
||||
{
|
||||
RunSta(() =>
|
||||
{
|
||||
using var form = new ClampsForm(null, Units.Inches, ClampSettings.Fallback, null, null);
|
||||
|
||||
Assert.False(All<Button>(form).Single(b => b.Text == "Save as Machine Defaults").Enabled);
|
||||
Assert.Contains(All<GroupBox>(form), g => g.Text == "Machine defaults (no machine assigned)");
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClampsDialog_SavesToTheNestsMachine_AndLoadsWhatItSaved()
|
||||
{
|
||||
RunSta(() =>
|
||||
{
|
||||
var rail = new ClampRail(1.5, 0.625, new[] { new RailClamp(ClampEdge.OriginSide, 6) });
|
||||
ClampSettings saved = null;
|
||||
using var form = new ClampsForm(rail, Units.Inches, ClampSettings.Fallback, "Fiber", s => saved = s);
|
||||
Assert.Contains(All<GroupBox>(form), g => g.Text == "Machine defaults (Fiber)");
|
||||
|
||||
All<CheckBox>(form).Single(c => c.Text == "Give new nests these clamps").Checked = true;
|
||||
Click(All<Button>(form).Single(b => b.Text == "Save as Machine Defaults"));
|
||||
|
||||
Assert.NotNull(saved);
|
||||
Assert.True(saved.Enabled);
|
||||
Assert.Equal(new double[] { 6 }, saved.Centers);
|
||||
|
||||
form.Editor.RemoveCenterAt(0);
|
||||
Click(All<Button>(form).Single(b => b.Text == "Load Machine Defaults"));
|
||||
Assert.Equal(6, Assert.Single(form.Editor.Clamps).Center);
|
||||
});
|
||||
}
|
||||
|
||||
// PerformClick does nothing on a form that is not shown.
|
||||
private static void Click(Button button) =>
|
||||
typeof(Control).GetMethod("OnClick", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!
|
||||
.Invoke(button, new object[] { EventArgs.Empty });
|
||||
|
||||
private static T Find<T>(Control root, string name) where T : Control =>
|
||||
Assert.IsType<T>(root.Controls.Find(name, true).Single());
|
||||
|
||||
private static IEnumerable<T> All<T>(Control root) where T : Control
|
||||
{
|
||||
foreach (Control child in root.Controls)
|
||||
{
|
||||
if (child is T match)
|
||||
yield return match;
|
||||
foreach (var nested in All<T>(child))
|
||||
yield return nested;
|
||||
}
|
||||
}
|
||||
|
||||
private static void RunSta(System.Action action) =>
|
||||
StaTestThread.Run(action, Timeout.InfiniteTimeSpan, "The STA test did not complete.");
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class UndoRecordingTests
|
||||
{
|
||||
UndoTestEnv.AcceptWhenShown<SupportGridForm>(form =>
|
||||
AllControls(form).OfType<CheckBox>().First(box => box.Text.StartsWith("This nest's sheets")).Checked = true);
|
||||
env.AssertOneUndoableEdit("Support Grid", () => env.Click("SupportGrid_Click"));
|
||||
env.AssertOneUndoableEdit("Support Bed", () => env.Click("SupportGrid_Click"));
|
||||
});
|
||||
|
||||
[Fact]
|
||||
@@ -228,7 +228,7 @@ public class UndoRecordingTests
|
||||
{
|
||||
env.Editor.PlateManager.LoadAt(0);
|
||||
using var form = new AutomaticCutOffForm(env.View, env.Nest.Units);
|
||||
env.AssertOneUndoableEdit("Automatic Cut-Offs", () => UndoTestEnv.Invoke(form, "ApplyButton_Click", null, EventArgs.Empty));
|
||||
env.AssertOneUndoableEdit("Automatic Scrap Cutoffs", () => UndoTestEnv.Invoke(form, "ApplyButton_Click", null, EventArgs.Empty));
|
||||
});
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -84,9 +84,9 @@ namespace OpenNest.Actions
|
||||
|
||||
private Units Units => Nest?.Units ?? Units.Inches;
|
||||
|
||||
// A nest without clamps takes its first clamp's size from the machine defaults.
|
||||
// A nest without clamps takes its first clamp's size from its machine's clamps.
|
||||
private ClampSettings Defaults =>
|
||||
defaults ??= MachineSettings.LoadSavedClampSettings(out _).ConvertedTo(Units);
|
||||
defaults ??= MachineSettings.LoadClampSettings(MachineSettings.FindMachine(Nest?.Machine)).ConvertedTo(Units);
|
||||
|
||||
private double ClampWidth => Rail?.Width ?? Defaults.Width;
|
||||
|
||||
|
||||
@@ -509,7 +509,7 @@ namespace OpenNest.Controls
|
||||
{
|
||||
ShowMessage(current == null
|
||||
? $"'{listed.Name}' is no longer in the library."
|
||||
: $"'{listed.Name}' was archived. Restore it to release it.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
: $"'{listed.Name}' was archived, so it can't be released.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -465,25 +465,25 @@ namespace OpenNest.Controls
|
||||
|
||||
foreach (var bend in part.BaseDrawing.Bends)
|
||||
{
|
||||
var start = bend.StartPoint;
|
||||
var end = bend.EndPoint;
|
||||
|
||||
if (part.Rotation != 0)
|
||||
{
|
||||
start = start.Rotate(part.Rotation);
|
||||
end = end.Rotate(part.Rotation);
|
||||
}
|
||||
|
||||
start = start + part.Location;
|
||||
end = end + part.Location;
|
||||
|
||||
var pt1 = view.PointWorldToGraph(start);
|
||||
var pt2 = view.PointWorldToGraph(end);
|
||||
var pt1 = view.PointWorldToGraph(BendToWorld(part, bend.StartPoint));
|
||||
var pt2 = view.PointWorldToGraph(BendToWorld(part, bend.EndPoint));
|
||||
|
||||
g.DrawLine(bendPen, pt1, pt2);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a bend point to world space. Bends stay in the drawing's source frame while the
|
||||
/// program is moved by -<c>Source.Offset</c>, so the offset comes off before placing.
|
||||
/// </summary>
|
||||
internal static Vector BendToWorld(Part part, Vector point)
|
||||
{
|
||||
var local = point - part.BaseDrawing.Source.Offset;
|
||||
if (part.Rotation != 0)
|
||||
local = local.Rotate(part.Rotation);
|
||||
return local + part.Location;
|
||||
}
|
||||
|
||||
private void DrawEtchMarks(Graphics g, Part part, bool muted)
|
||||
{
|
||||
if (
|
||||
@@ -501,17 +501,8 @@ namespace OpenNest.Controls
|
||||
if (bend.Direction != BendDirection.Up)
|
||||
continue;
|
||||
|
||||
var start = bend.StartPoint;
|
||||
var end = bend.EndPoint;
|
||||
|
||||
if (part.Rotation != 0)
|
||||
{
|
||||
start = start.Rotate(part.Rotation);
|
||||
end = end.Rotate(part.Rotation);
|
||||
}
|
||||
|
||||
start = start + part.Location;
|
||||
end = end + part.Location;
|
||||
var start = BendToWorld(part, bend.StartPoint);
|
||||
var end = BendToWorld(part, bend.EndPoint);
|
||||
|
||||
var length = bend.Length;
|
||||
var angle = bend.StartPoint.AngleTo(bend.EndPoint) + part.Rotation;
|
||||
|
||||
@@ -771,10 +771,11 @@ namespace OpenNest.Controls
|
||||
{
|
||||
renderer.DrawActiveWorkArea(e.Graphics);
|
||||
renderer.DrawDebugRemnants(e.Graphics);
|
||||
if (DrawSupport)
|
||||
supportOverlay.Draw(e.Graphics, this);
|
||||
DrawOverlapOverlay(e.Graphics);
|
||||
}
|
||||
// The support overlay follows the displayed plate, so it shows a proposal's tabbed parts too.
|
||||
if (DrawSupport)
|
||||
supportOverlay.Draw(e.Graphics, this);
|
||||
// Plan Cutting marks findings on its proposal as well as on the live plate.
|
||||
validationOverlay.Draw(e.Graphics);
|
||||
if (!HasProposalDisplay)
|
||||
|
||||
@@ -638,7 +638,7 @@ namespace OpenNest.Controls
|
||||
}
|
||||
if (current.Archived)
|
||||
{
|
||||
ShowMessage($"'{current.Name}' is archived in the library. Restore it there before editing it.",
|
||||
ShowMessage($"'{current.Name}' is archived in the library, so it can't be edited.",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -49,8 +49,10 @@ namespace OpenNest.Controls
|
||||
using var supportedPen = new Pen(SupportedColor, 2f);
|
||||
using var tippingPen = new Pen(TippingColor, 2f);
|
||||
using var tabBrush = new SolidBrush(TabColor);
|
||||
// Tab points keep clear of inside corners as Plan Cutting's do.
|
||||
var clearance = SupportAnalyzer.InsideCornerClearance(plate.CuttingParameters?.TabConfig?.Size ?? 0);
|
||||
// Tab points keep clear of inside corners as Plan Cutting's do. A proposal preview has no
|
||||
// parameters of its own, so it uses the live plate's.
|
||||
var parameters = plate.CuttingParameters ?? view.Plate?.CuttingParameters;
|
||||
var clearance = SupportAnalyzer.InsideCornerClearance(parameters?.TabConfig?.Size ?? 0);
|
||||
foreach (var part in plate.Parts)
|
||||
{
|
||||
if (part?.BaseDrawing == null || part.BaseDrawing.IsCutOff)
|
||||
|
||||
@@ -377,7 +377,7 @@ public partial class AutomaticCutOffForm : Form
|
||||
// The batch service replans every plate before mutating any; never accept previews.
|
||||
Plate[] plates;
|
||||
IReadOnlyList<AutomaticCutOffPlan> plans;
|
||||
using (var change = plateView.BeginChange("Automatic Cut-Offs"))
|
||||
using (var change = plateView.BeginChange("Automatic Scrap Cutoffs"))
|
||||
{
|
||||
(plates, plans) = Calculate(apply: true);
|
||||
// A blocked batch changes nothing.
|
||||
|
||||
@@ -408,9 +408,9 @@ namespace OpenNest.Forms
|
||||
var jobName = txtJobName.Text.Trim();
|
||||
var nestsCreated = 0;
|
||||
var importErrors = new List<string>();
|
||||
// Read when the nests are created, warning (once per session) like New does.
|
||||
var clamps = MachineSettings.LoadClampSettings(this);
|
||||
// Read when the nests are created, like New does.
|
||||
var machine = MachineSettings.DefaultMachine(_defaults, MachineSettings.LoadMachines());
|
||||
var clamps = MachineSettings.LoadClampSettings(machine);
|
||||
|
||||
foreach (var group in groups)
|
||||
{
|
||||
|
||||
@@ -10,13 +10,13 @@ namespace OpenNest.Forms;
|
||||
/// <summary>
|
||||
/// Nest > Clamps...: edits the current nest's machine clamp rail (identical clamps, each on
|
||||
/// one sheet edge with its center measured from the plate origin along it). OK applies the rail
|
||||
/// to every plate of this nest; Cancel discards those edits. Save as Machine Defaults writes
|
||||
/// clamps.json immediately and is not undone by Cancel. All decisions live in
|
||||
/// to every plate of this nest; Cancel discards those edits. Save as Machine Defaults writes the
|
||||
/// nest's machine configuration immediately and is not undone by Cancel. All decisions live in
|
||||
/// <see cref="ClampRailEditor"/>; this form only renders and forwards input.
|
||||
/// </summary>
|
||||
public sealed class ClampsForm : Form
|
||||
{
|
||||
private readonly ClampSettings machineDefaults;
|
||||
private ClampSettings machineDefaults;
|
||||
private readonly Action<ClampSettings> saveDefaults;
|
||||
private readonly NumericUpDown widthBox;
|
||||
private readonly NumericUpDown depthBox;
|
||||
@@ -30,11 +30,17 @@ public sealed class ClampsForm : Form
|
||||
private readonly CheckBox applyToNewNestsBox;
|
||||
private readonly Label savedLabel;
|
||||
|
||||
/// <param name="saveDefaults">Saves the machine defaults; this PC's clamp settings file when omitted.</param>
|
||||
public ClampsForm(ClampRail rail, Units units, ClampSettings machineDefaults, Action<ClampSettings> saveDefaults = null)
|
||||
/// <param name="machineDefaults">The clamps of the nest's machine, in any units.</param>
|
||||
/// <param name="machineName">The nest's machine, or null when none is assigned.</param>
|
||||
/// <param name="saveDefaults">
|
||||
/// Saves the clamps as the nest's machine's; null when the nest has no machine on file, which
|
||||
/// disables saving.
|
||||
/// </param>
|
||||
public ClampsForm(ClampRail rail, Units units, ClampSettings machineDefaults, string machineName,
|
||||
Action<ClampSettings> saveDefaults)
|
||||
{
|
||||
this.machineDefaults = machineDefaults ?? ClampSettings.Fallback;
|
||||
this.saveDefaults = saveDefaults ?? (settings => settings.Save(ClampSettings.DefaultPath));
|
||||
this.saveDefaults = saveDefaults;
|
||||
Editor = new ClampRailEditor(rail, units, this.machineDefaults.Enabled);
|
||||
var unit = UnitsHelper.GetShortString(units);
|
||||
|
||||
@@ -113,7 +119,7 @@ public sealed class ClampsForm : Form
|
||||
|
||||
var defaultsGroup = new GroupBox
|
||||
{
|
||||
Text = "Machine defaults (clamps.json)",
|
||||
Text = string.IsNullOrEmpty(machineName) ? "Machine defaults (no machine assigned)" : $"Machine defaults ({machineName})",
|
||||
Dock = DockStyle.Top,
|
||||
AutoSize = true,
|
||||
Padding = new Padding(8),
|
||||
@@ -140,10 +146,13 @@ public sealed class ClampsForm : Form
|
||||
{
|
||||
AutoSize = true,
|
||||
MaximumSize = new Size(430, 0),
|
||||
Text =
|
||||
"Save as Machine Defaults writes the file immediately; Cancel below does not undo "
|
||||
+ "it. OK and Cancel only affect this nest.",
|
||||
Text = saveDefaults == null
|
||||
? "Assign this nest a machine on file in Nest > Machine to save its clamps."
|
||||
: "Save as Machine Defaults writes the machine configuration immediately; Cancel below "
|
||||
+ "does not undo it. OK and Cancel only affect this nest.",
|
||||
};
|
||||
applyToNewNestsBox.Enabled = saveDefaults != null;
|
||||
saveDefaultsButton.Enabled = saveDefaults != null;
|
||||
defaultsLayout.Controls.Add(applyToNewNestsBox);
|
||||
defaultsLayout.Controls.Add(defaultsButtons);
|
||||
defaultsLayout.Controls.Add(savedLabel);
|
||||
@@ -270,6 +279,7 @@ public sealed class ClampsForm : Form
|
||||
{
|
||||
var settings = Editor.ToMachineDefaults();
|
||||
saveDefaults(settings);
|
||||
machineDefaults = settings;
|
||||
savedLabel.Text = settings.Enabled
|
||||
? $"Saved {DateTime.Now:t}: new nests get these {settings.ClampCount} clamps. Cancel does not undo this."
|
||||
: $"Saved {DateTime.Now:t}: new nests get no clamps. Cancel does not undo this.";
|
||||
|
||||
@@ -288,7 +288,7 @@ namespace OpenNest.Forms
|
||||
ShowMemberDrawing(current);
|
||||
if (current.Archived)
|
||||
{
|
||||
ShowMessage($"'{current.Name}' is archived in the library. Restore it there before editing it.",
|
||||
ShowMessage($"'{current.Name}' is archived in the library, so it can't be edited.",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -250,8 +250,8 @@ namespace OpenNest.Forms
|
||||
return;
|
||||
|
||||
var confirm = MessageBox.Show(
|
||||
"Changing units does not convert existing thickness, kerf, lead and "
|
||||
+ "motion values — they will keep their current numbers. Continue?",
|
||||
"Changing units does not convert existing thickness, kerf, lead, "
|
||||
+ "motion and clamp values — they will keep their current numbers. Continue?",
|
||||
"Change Units",
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Warning
|
||||
@@ -267,9 +267,139 @@ namespace OpenNest.Forms
|
||||
AddField(layout, ref row, "Units:", unitsCombo);
|
||||
|
||||
group.Controls.Add(layout);
|
||||
var general = new Panel { Dock = DockStyle.Fill, AutoScroll = true };
|
||||
// Docked to the top, so the last added sits first.
|
||||
_detailPanel.Controls.Add(BuildMotionGroup(machine));
|
||||
_detailPanel.Controls.Add(group);
|
||||
general.Controls.Add(BuildMotionGroup(machine));
|
||||
general.Controls.Add(group);
|
||||
|
||||
var tabs = new TabControl { Dock = DockStyle.Fill };
|
||||
tabs.TabPages.Add(CreateTab("General", general));
|
||||
tabs.TabPages.Add(CreateTab("Clamps", BuildClampsTab(machine)));
|
||||
|
||||
var host = new Panel { Dock = DockStyle.Fill, Height = 420 };
|
||||
host.Controls.Add(tabs);
|
||||
_detailPanel.Controls.Add(host);
|
||||
}
|
||||
|
||||
// The machine's edge-clamp rail, which new nests assigned the machine copy. The first edit
|
||||
// stores the shown values (the default clamp size, off, when it has none) with the change.
|
||||
private Control BuildClampsTab(MachineConfig machine)
|
||||
{
|
||||
var shown = machine.GetClampSettings();
|
||||
var editor = new ClampRailEditor(null, shown.Units, shown.Enabled);
|
||||
editor.LoadMachineDefaults(shown);
|
||||
|
||||
MachineClamps Clamps() => machine.Clamps ??= new MachineClamps
|
||||
{
|
||||
Enabled = shown.Enabled,
|
||||
Width = shown.Width,
|
||||
Depth = shown.Depth,
|
||||
RemovalMinutes = shown.RemovalMinutes,
|
||||
};
|
||||
|
||||
void Set(Action<MachineClamps> apply)
|
||||
{
|
||||
var clamps = Clamps();
|
||||
apply(clamps);
|
||||
var edges = new ClampSettings();
|
||||
edges.SetClamps(editor.Clamps);
|
||||
clamps.Centers = edges.Centers.ToList();
|
||||
clamps.FarSideCenters = edges.FarSideCenters.ToList();
|
||||
clamps.OriginEndCenters = edges.OriginEndCenters.ToList();
|
||||
clamps.FarEndCenters = edges.FarEndCenters.ToList();
|
||||
MarkDirty();
|
||||
}
|
||||
|
||||
var layout = CreateDetailLayout();
|
||||
var row = 0;
|
||||
var enabledBox = new CheckBox
|
||||
{
|
||||
Text = "Give new nests these clamps",
|
||||
AutoSize = true,
|
||||
Checked = shown.Enabled,
|
||||
};
|
||||
enabledBox.CheckedChanged += (s, e) => Set(c => c.Enabled = enabledBox.Checked);
|
||||
AddField(layout, ref row, "New nests:", enabledBox);
|
||||
AddField(layout, ref row, "Clamp width:",
|
||||
CreateLabeledNumeric(shown.Width, v => Set(c => c.Width = v), 4, LengthUnitSuffix, 1000, 0.125m));
|
||||
AddField(layout, ref row, "Clamp depth:",
|
||||
CreateLabeledNumeric(shown.Depth, v => Set(c => c.Depth = v), 4, LengthUnitSuffix, 1000, 0.125m));
|
||||
AddField(layout, ref row, "Removal time:",
|
||||
CreateLabeledNumeric(shown.RemovalMinutes, v => Set(c => c.RemovalMinutes = v), 2, _ => "min per clamp", 1000, 0.5m));
|
||||
|
||||
var centersGroup = new GroupBox
|
||||
{
|
||||
Text = $"Clamp centers, measured from the plate origin ({LengthUnitSuffix(null)})",
|
||||
Dock = DockStyle.Fill,
|
||||
Padding = new Padding(8),
|
||||
};
|
||||
var centersList = new ListBox { Dock = DockStyle.Fill, IntegralHeight = false };
|
||||
var entry = new FlowLayoutPanel { Dock = DockStyle.Bottom, AutoSize = true, WrapContents = false };
|
||||
var edgeBox = new ComboBox { DropDownStyle = ComboBoxStyle.DropDownList, Width = 120 };
|
||||
foreach (var edge in ClampEdgeText.All)
|
||||
edgeBox.Items.Add(ClampEdgeText.Name(edge));
|
||||
edgeBox.SelectedIndex = 0;
|
||||
var centerBox = CreateNumericBox(0, _ => { }, 4, 100000, 0.125m);
|
||||
var addButton = new Button { Text = "Add", AutoSize = true };
|
||||
var removeButton = new Button { Text = "Remove", AutoSize = true, Enabled = false };
|
||||
entry.Controls.Add(edgeBox);
|
||||
entry.Controls.Add(new Label { Text = "Center:", AutoSize = true, Padding = new Padding(0, 6, 0, 0) });
|
||||
entry.Controls.Add(centerBox);
|
||||
entry.Controls.Add(addButton);
|
||||
entry.Controls.Add(removeButton);
|
||||
centersGroup.Controls.Add(centersList);
|
||||
centersGroup.Controls.Add(entry);
|
||||
|
||||
void RefreshCenters()
|
||||
{
|
||||
centersList.BeginUpdate();
|
||||
centersList.Items.Clear();
|
||||
foreach (var clamp in editor.Clamps)
|
||||
centersList.Items.Add(
|
||||
$"{ClampEdgeText.Name(clamp.Edge)}: {clamp.Center.ToString("0.####", System.Globalization.CultureInfo.CurrentCulture)}");
|
||||
centersList.EndUpdate();
|
||||
removeButton.Enabled = centersList.SelectedIndex >= 0;
|
||||
}
|
||||
|
||||
addButton.Click += (s, e) =>
|
||||
{
|
||||
var clamp = new RailClamp(ClampEdgeText.All[edgeBox.SelectedIndex], (double)centerBox.Value);
|
||||
if (!editor.TryAddClamp(clamp, out var error))
|
||||
{
|
||||
MessageBox.Show(this, error, Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
Set(_ => { });
|
||||
RefreshCenters();
|
||||
};
|
||||
removeButton.Click += (s, e) =>
|
||||
{
|
||||
var index = centersList.SelectedIndex;
|
||||
editor.RemoveCenterAt(index);
|
||||
Set(_ => { });
|
||||
RefreshCenters();
|
||||
if (centersList.Items.Count > 0)
|
||||
centersList.SelectedIndex = System.Math.Min(index, centersList.Items.Count - 1);
|
||||
};
|
||||
centersList.SelectedIndexChanged += (s, e) => removeButton.Enabled = centersList.SelectedIndex >= 0;
|
||||
RefreshCenters();
|
||||
|
||||
var note = new Label
|
||||
{
|
||||
Dock = DockStyle.Top,
|
||||
AutoSize = true,
|
||||
MaximumSize = new Size(560, 0),
|
||||
ForeColor = SystemColors.GrayText,
|
||||
Padding = new Padding(4, 0, 0, 8),
|
||||
Text = "New nests assigned this machine copy these clamps. Changing them here never "
|
||||
+ "moves the clamps of existing nests; use Load Machine Defaults in Nest > Clamps for that.",
|
||||
};
|
||||
|
||||
var panel = new Panel { Dock = DockStyle.Fill, Padding = new Padding(10) };
|
||||
panel.Controls.Add(centersGroup);
|
||||
panel.Controls.Add(note);
|
||||
panel.Controls.Add(layout);
|
||||
return panel;
|
||||
}
|
||||
|
||||
private GroupBox BuildMotionGroup(MachineConfig machine)
|
||||
|
||||
@@ -11,15 +11,13 @@ using OpenNest.IO;
|
||||
namespace OpenNest.Forms
|
||||
{
|
||||
/// <summary>
|
||||
/// The desktop entry points for the persisted machines, machine clamp settings and nest
|
||||
/// The desktop entry points for the persisted machines (with their clamps) and nest
|
||||
/// defaults. In Database mode each comes from the nest server once it holds a shared copy
|
||||
/// (<see cref="SharedSettings"/>), otherwise from this PC's files. The warning variants
|
||||
/// report unusable settings once per session.
|
||||
/// </summary>
|
||||
internal static class MachineSettings
|
||||
{
|
||||
private static bool clampSettingsWarned;
|
||||
|
||||
/// <summary>
|
||||
/// The machine configurations edited in Tools > Machine Configuration: the server's when
|
||||
/// it holds any, otherwise this PC's. <paramref name="refresh"/> re-reads the server first.
|
||||
@@ -66,37 +64,100 @@ namespace OpenNest.Forms
|
||||
/// <summary>Every material and grade on file across the readable machine configurations.</summary>
|
||||
public static IEnumerable<MaterialConfig> LoadMaterials() =>
|
||||
LoadMachines().SelectMany(machine => machine.Materials);
|
||||
|
||||
private static bool defaultsWarned;
|
||||
private static bool clampMigrationAsked;
|
||||
|
||||
/// <summary>
|
||||
/// Loads the machine clamp settings for creating new nests (New, BOM import); an
|
||||
/// unreadable or partly invalid file warns once per session, because the new nest's
|
||||
/// clamps may not match the machine.
|
||||
/// The clamps new nests assigned <paramref name="machine"/> receive (New, BOM import, Load
|
||||
/// Machine Defaults); off when there is no machine or it has no clamps.
|
||||
/// </summary>
|
||||
public static ClampSettings LoadClampSettings(IWin32Window owner)
|
||||
{
|
||||
var settings = LoadSavedClampSettings(out var status);
|
||||
public static ClampSettings LoadClampSettings(MachineConfig machine) =>
|
||||
machine?.GetClampSettings() ?? ClampSettings.Fallback;
|
||||
|
||||
if (
|
||||
status is ClampSettingsStatus.Invalid or ClampSettingsStatus.Partial
|
||||
&& !clampSettingsWarned
|
||||
)
|
||||
/// <summary>Saves <paramref name="settings"/> as the clamps of the machine with <paramref name="machineId"/>.</summary>
|
||||
public static void SaveClampSettings(Guid machineId, ClampSettings settings)
|
||||
{
|
||||
var provider = CreateMachineProvider();
|
||||
var machine = provider.GetMachine(machineId)
|
||||
?? throw new IOException("The machine configuration is no longer on file.");
|
||||
machine.Clamps = MachineClamps.FromSettings(settings, machine.Units);
|
||||
provider.SaveMachine(machine);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the legacy clamps.json (or the server's shared copy) onto a machine once, while
|
||||
/// no machine has clamps of its own: the nest defaults' machine, or the only machine. With
|
||||
/// several machines and no default the user picks one, asked once per session.
|
||||
/// </summary>
|
||||
public static void MigrateLegacyClamps(IWin32Window owner)
|
||||
{
|
||||
try
|
||||
{
|
||||
clampSettingsWarned = true;
|
||||
var problem =
|
||||
status == ClampSettingsStatus.Invalid
|
||||
? "could not be read, so new nests have no clamps"
|
||||
: "have invalid values that were ignored, so new nests may be missing clamps";
|
||||
var source = SharedClamps() != null ? "on the nest server" : ClampSettings.DefaultPath;
|
||||
MessageBox.Show(
|
||||
owner,
|
||||
$"The clamp settings {problem}:\n{source}\n\nCheck the clamps in Nest > Clamps and use Save as Machine Defaults to rewrite them.",
|
||||
"Clamps",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Warning
|
||||
);
|
||||
var legacy = LoadLegacyClampSettings();
|
||||
var provider = CreateMachineProvider();
|
||||
var machines = ReadMachines(() => provider)
|
||||
.OrderBy(m => m.Name, StringComparer.CurrentCultureIgnoreCase)
|
||||
.ToList();
|
||||
if (!LegacyClampMigration.IsNeeded(legacy, machines))
|
||||
return;
|
||||
|
||||
var target = LegacyClampMigration.Target(machines, LoadSavedNestDefaults(out _).MachineId);
|
||||
if (target == null)
|
||||
{
|
||||
if (clampMigrationAsked)
|
||||
return;
|
||||
clampMigrationAsked = true;
|
||||
target = AskClampMachine(owner, machines);
|
||||
if (target == null)
|
||||
return;
|
||||
}
|
||||
|
||||
LegacyClampMigration.Apply(legacy, target);
|
||||
provider.SaveMachine(target);
|
||||
}
|
||||
return settings;
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
MessageBox.Show(owner,
|
||||
$"The clamp settings could not be copied to a machine:\n\n{ex.Message}\n\n"
|
||||
+ "New nests get no clamps until a machine has them (Tools > Machine Configuration).",
|
||||
"Clamps", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
// The pre-machine clamp settings: the server's shared copy once it holds one, otherwise
|
||||
// this PC's clamps.json; null when neither exists.
|
||||
private static ClampSettings LoadLegacyClampSettings()
|
||||
{
|
||||
if (SharedSettings.Find(SharedSettingKinds.Clamps, SharedSettingKinds.DefaultKey) is { } shared)
|
||||
return ClampSettings.Parse(shared.Json, out _);
|
||||
return File.Exists(ClampSettings.DefaultPath) ? ClampSettings.Load(ClampSettings.DefaultPath) : null;
|
||||
}
|
||||
|
||||
private static MachineConfig AskClampMachine(IWin32Window owner, IReadOnlyList<MachineConfig> machines)
|
||||
{
|
||||
var page = new TaskDialogPage
|
||||
{
|
||||
Caption = "Clamps",
|
||||
Heading = "Which machine are these clamps on?",
|
||||
Text = "Clamps are now kept with each machine. Choose the machine that gets the clamps "
|
||||
+ "saved before, or choose later in Tools > Machine Configuration. Until then new "
|
||||
+ "nests get no clamps.",
|
||||
Icon = TaskDialogIcon.Information,
|
||||
AllowCancel = true,
|
||||
};
|
||||
foreach (var machine in machines)
|
||||
page.RadioButtons.Add(new TaskDialogRadioButton(machine.Name) { Tag = machine });
|
||||
page.RadioButtons[0].Checked = true;
|
||||
var copy = new TaskDialogButton("Copy Clamps");
|
||||
page.Buttons.Add(copy);
|
||||
page.Buttons.Add(new TaskDialogButton("Not Now"));
|
||||
|
||||
var handle = owner?.Handle ?? IntPtr.Zero;
|
||||
var result = handle == IntPtr.Zero ? TaskDialog.ShowDialog(page) : TaskDialog.ShowDialog(handle, page);
|
||||
return result == copy
|
||||
? page.RadioButtons.FirstOrDefault(b => b.Checked)?.Tag as MachineConfig
|
||||
: null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -189,29 +250,6 @@ namespace OpenNest.Forms
|
||||
provider.SaveMachine(machine);
|
||||
}
|
||||
|
||||
/// <summary>The single desktop entry point for the persisted machine clamp settings.</summary>
|
||||
public static ClampSettings LoadSavedClampSettings(out ClampSettingsStatus status) =>
|
||||
SharedClamps() is { } shared
|
||||
? ClampSettings.Parse(shared.Json, out status)
|
||||
: ClampSettings.Load(ClampSettings.DefaultPath, out status);
|
||||
|
||||
/// <summary>
|
||||
/// Saves the clamp settings new nests start from where they are read: the server once it
|
||||
/// holds them, otherwise this PC's file. Throws <see cref="IOException"/> when the server
|
||||
/// cannot take them.
|
||||
/// </summary>
|
||||
public static void SaveClampSettings(ClampSettings settings)
|
||||
{
|
||||
if (SharedSettings.Current() is { } current
|
||||
&& current.Get(SharedSettingKinds.Clamps, SharedSettingKinds.DefaultKey) != null)
|
||||
current.Save(SharedSettingKinds.Clamps, SharedSettingKinds.DefaultKey, settings.ToJson());
|
||||
else
|
||||
settings.Save(ClampSettings.DefaultPath);
|
||||
}
|
||||
|
||||
private static SharedSettingRecord SharedClamps() =>
|
||||
SharedSettings.Find(SharedSettingKinds.Clamps, SharedSettingKinds.DefaultKey);
|
||||
|
||||
/// <summary>
|
||||
/// Loads the persisted nest defaults (see <see cref="LoadSavedNestDefaults"/>);
|
||||
/// a corrupt or unreadable file warns once per session.
|
||||
|
||||
@@ -135,8 +135,12 @@ namespace OpenNest.Forms
|
||||
return;
|
||||
}
|
||||
|
||||
var defaults = MachineSettings.LoadSavedClampSettings(out _);
|
||||
using var form = new ClampsForm(nest.PlateDefaults.ClampRail, nest.Units, defaults, MachineSettings.SaveClampSettings);
|
||||
var machine = MachineSettings.FindMachine(nest.Machine);
|
||||
Action<ClampSettings> save = machine == null
|
||||
? null
|
||||
: settings => MachineSettings.SaveClampSettings(machine.Id, settings);
|
||||
using var form = new ClampsForm(nest.PlateDefaults.ClampRail, nest.Units, MachineSettings.LoadClampSettings(machine),
|
||||
machine?.Name ?? nest.Machine?.Name, save);
|
||||
if (form.ShowDialog(this) != DialogResult.OK)
|
||||
return;
|
||||
|
||||
@@ -170,7 +174,7 @@ namespace OpenNest.Forms
|
||||
if (form.ShowDialog(this) != DialogResult.OK)
|
||||
return;
|
||||
|
||||
editForm.RecordChange("Support Grid", () => nest.SetSupportBed(form.Bed));
|
||||
editForm.RecordChange("Support Bed", () => nest.SetSupportBed(form.Bed));
|
||||
foreach (var view in views)
|
||||
view.Invalidate();
|
||||
}
|
||||
|
||||
@@ -213,8 +213,13 @@ namespace OpenNest.Forms
|
||||
mnuNestPost.Visible = mnuNestPost.DropDownItems.Count > 0;
|
||||
postButton.Visible = postButton.DropDownItems.Count > 0;
|
||||
|
||||
// Database mode: offer this PC's settings to a server that has none yet.
|
||||
Shown += (_, _) => SharedSettings.OfferUpload(this, posts.PostProcessors);
|
||||
// Database mode: offer this PC's settings to a server that has none yet; then move
|
||||
// the clamps saved before machines held them onto a machine, once.
|
||||
Shown += (_, _) =>
|
||||
{
|
||||
SharedSettings.OfferUpload(this, posts.PostProcessors);
|
||||
MachineSettings.MigrateLegacyClamps(this);
|
||||
};
|
||||
|
||||
if (posts.Failures.Count > 0)
|
||||
Shown += (_, _) => MessageBox.Show(this,
|
||||
|
||||
@@ -41,6 +41,9 @@ namespace OpenNest.Forms
|
||||
|
||||
sourceLabel.Text = source.Text;
|
||||
saveButton.Enabled = !source.ReadOnly;
|
||||
// Nothing typed here could be saved, so show the values without inviting edits.
|
||||
foreach (var group in new Control[] { generalGroup, plateGroup, quadrantGroup, spacingGroup })
|
||||
group.Enabled = !source.ReadOnly;
|
||||
}
|
||||
|
||||
private NestDefaultsForm() => InitializeComponent();
|
||||
|
||||
@@ -40,8 +40,9 @@ namespace OpenNest.Forms
|
||||
var defaults = MachineSettings.LoadNestDefaults();
|
||||
(units is { } converted ? defaults.ConvertedTo(converted) : defaults).ApplyTo(nest);
|
||||
// After the defaults so the rail and grid are converted to the new nest's units.
|
||||
MachineSettings.LoadClampSettings(owner).ApplyToNewNest(nest);
|
||||
MachineSettings.AssignMachine(nest, MachineSettings.DefaultMachine(defaults, MachineSettings.LoadMachines()));
|
||||
var machine = MachineSettings.DefaultMachine(defaults, MachineSettings.LoadMachines());
|
||||
MachineSettings.LoadClampSettings(machine).ApplyToNewNest(nest);
|
||||
MachineSettings.AssignMachine(nest, machine);
|
||||
return nest;
|
||||
}
|
||||
|
||||
|
||||
Generated
+1
-1
@@ -300,7 +300,7 @@
|
||||
this.ledgerGroupBox.Size = new System.Drawing.Size(684, 92);
|
||||
this.ledgerGroupBox.TabIndex = 4;
|
||||
this.ledgerGroupBox.TabStop = false;
|
||||
this.ledgerGroupBox.Text = "MaterialLedger (optional; Auto Nest loads stock from it; set per machine)";
|
||||
this.ledgerGroupBox.Text = "MaterialLedger (optional; Auto Nest loads stock from it; saved for this Windows user)";
|
||||
//
|
||||
// ledgerUrlLabel
|
||||
//
|
||||
|
||||
+1
-1
@@ -87,12 +87,12 @@ namespace OpenNest.Forms
|
||||
layoutTable.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||
layoutTable.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||
layoutTable.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||
layoutTable.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||
layoutTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
||||
layoutTable.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||
layoutTable.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||
layoutTable.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||
layoutTable.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||
layoutTable.RowStyles.Add(new System.Windows.Forms.RowStyle());
|
||||
layoutTable.Size = new System.Drawing.Size(584, 481);
|
||||
layoutTable.TabIndex = 0;
|
||||
//
|
||||
|
||||
@@ -307,18 +307,23 @@ public sealed class SavedNestsForm : Form
|
||||
findBar.Controls.Add(nextButton);
|
||||
findBar.Controls.Add(summaryLabel);
|
||||
|
||||
var bottom = new TableLayoutPanel
|
||||
// The find bar sits between the Nests header and the grid it filters, and comes
|
||||
// first in the tab order.
|
||||
var findPanel = new TableLayoutPanel
|
||||
{
|
||||
Dock = DockStyle.Bottom,
|
||||
Dock = DockStyle.Top,
|
||||
AutoSize = true,
|
||||
ColumnCount = 1,
|
||||
Padding = new Padding(3, 3, 3, 6),
|
||||
Padding = new Padding(3, 0, 3, 3),
|
||||
TabIndex = 0,
|
||||
};
|
||||
bottom.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
|
||||
bottom.Controls.Add(findBar);
|
||||
findPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
|
||||
findPanel.Controls.Add(findBar);
|
||||
nestGrid.TabIndex = 1;
|
||||
split.Panel1.Controls.Add(findPanel);
|
||||
split.Panel1.Controls.SetChildIndex(findPanel, 1);
|
||||
|
||||
Controls.Add(split);
|
||||
Controls.Add(bottom);
|
||||
|
||||
Load += (_, _) =>
|
||||
{
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace OpenNest.Forms
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When the server holds none of this PC's machines, post settings, clamp settings or nest
|
||||
/// When the server holds none of this PC's machines (with their clamps), post settings or nest
|
||||
/// defaults, offers to upload them so every workstation uses them. Documents the server
|
||||
/// already holds are never replaced.
|
||||
/// </summary>
|
||||
@@ -200,10 +200,6 @@ namespace OpenNest.Forms
|
||||
if (current.Get(SharedSettingKinds.Post, PostKey(post)) == null)
|
||||
uploads.Add((SharedSettingKinds.Post, PostKey(post), post.SerializeConfig(), $"Post settings: {post.Name}"));
|
||||
}
|
||||
if (current.Get(SharedSettingKinds.Clamps, SharedSettingKinds.DefaultKey) == null
|
||||
&& File.Exists(ClampSettings.DefaultPath))
|
||||
uploads.Add((SharedSettingKinds.Clamps, SharedSettingKinds.DefaultKey,
|
||||
ClampSettings.Load(ClampSettings.DefaultPath).ToJson(), "Clamp settings"));
|
||||
if (current.Get(SharedSettingKinds.NestDefaults, SharedSettingKinds.DefaultKey) == null
|
||||
&& File.Exists(NestDefaults.DefaultPath))
|
||||
uploads.Add((SharedSettingKinds.NestDefaults, SharedSettingKinds.DefaultKey,
|
||||
|
||||
@@ -77,7 +77,7 @@ public sealed class SupportGridForm : Form
|
||||
+ "first at the offset from the plate origin into the sheet; or slats, each a strip of "
|
||||
+ "the slat thickness running the full length or width of the table, one every pitch, "
|
||||
+ "the first centered at the offset. A part whose center of gravity is not inside its "
|
||||
+ "contacts by the stability margin can tip; with \"Tab parts the support grid cannot "
|
||||
+ "contacts by the stability margin can tip; with \"Only tab parts the support grid can't "
|
||||
+ "hold level\" in Cutting Settings, Plan Cutting tabs it where the tab steadies it. "
|
||||
+ "The registration tolerance allows for a sheet loaded off its place.",
|
||||
});
|
||||
|
||||
+23
-10
@@ -66,18 +66,31 @@ the origin: the origin side and far side run along X, the origin end and far
|
||||
end along Y. **Nest > Clamps...** edits the current nest's rail as a list, and
|
||||
**Plate > Edit Clamps** edits it on the plate view (below). **OK** applies it to every plate of the nest (**Cancel** discards
|
||||
the edits); removing every center removes the clamps. **Load Machine Defaults**
|
||||
only fills the dialog. **Save as Machine Defaults** writes
|
||||
`%APPDATA%\OpenNest\clamps.json` (or, in Database mode once the server holds them, the
|
||||
[shared clamp settings](shared-settings.md)) immediately, with the clamps, their units and
|
||||
whether new nests receive them; Cancel does not undo that write. The dialog
|
||||
only fills the dialog with the clamps of the nest's machine (**Nest > Machine**).
|
||||
**Save as Machine Defaults** writes the clamps, and whether new nests receive them,
|
||||
into that machine's configuration immediately (in Database mode, the
|
||||
[shared machine](shared-settings.md) once the server holds it); Cancel does not undo
|
||||
that write. A nest without a machine on file cannot save its clamps. The dialog
|
||||
refuses to open while nesting or a plate action is running.
|
||||
|
||||
Clamps are off by default. Until `clamps.json` is saved with clamps enabled and
|
||||
at least one center, New and BOM import create nests without clamps exactly as
|
||||
before. When enabled, a new nest gets the rail converted to its units. A missing
|
||||
file keeps clamps off; an unreadable file, or one with ignored invalid values
|
||||
(a bad clamp center is dropped), warns once per session that new nests may not
|
||||
match the machine.
|
||||
Clamps are physical fixtures of a machine, so each machine keeps its own rail on the
|
||||
**Clamps** tab of **Tools > Machine Configuration**: whether new nests get it, the
|
||||
clamp width and depth, the minutes to remove one clamp, and the clamp centers, all in
|
||||
the machine's units. New and BOM import give a new nest the rail of the machine they
|
||||
assign it (the **Tools > Nest Defaults** machine, or the first by name), converted to
|
||||
the nest's units. A nest keeps its own copy: editing a machine's clamps, or assigning a
|
||||
nest another machine, never moves the clamps of an existing nest; use **Load Machine
|
||||
Defaults** for that. Clamps are off by default: a machine without clamps, or with them
|
||||
switched off or without a center, gives new nests none. A stored size or removal time
|
||||
that is not valid falls back to the default and an invalid center is dropped.
|
||||
|
||||
Before machines held clamps, one `%APPDATA%\OpenNest\clamps.json` (or the server's
|
||||
shared clamp settings) served every machine. At startup, while no machine has clamps of
|
||||
its own, OpenNest copies that rail once into the Nest Defaults machine, or the only
|
||||
machine, converted to the machine's units. With several machines and no default it asks
|
||||
which machine has those clamps (once per session; **Not Now** leaves new nests without
|
||||
clamps until a machine has some). Once any machine has clamps the old file is no longer
|
||||
read; it is left in place.
|
||||
|
||||
Every plate follows the nest's rail at its own size and quadrant: clamps wholly
|
||||
beyond a shorter sheet are left off it, one still reaching onto the sheet keeps
|
||||
|
||||
+17
-6
@@ -218,7 +218,10 @@ from the start point. Its 2-opt and Or-opt passes would grow with the square of
|
||||
part count. Replans after a learned rule use the plain tour. If a part on that order cannot be
|
||||
reached without crossing parts already cut, the search learns "cut this part
|
||||
before those", backs up to just before the earliest of them and re-plans the rest
|
||||
from the tool position there; parts cut before that point are kept. The first pass
|
||||
from the tool position there; parts cut before that point are kept. When the part
|
||||
cannot come earlier (a sheet separator is cut after everything), it learns the other
|
||||
way round, "cut the part the approach left from before those", so the tool arrives
|
||||
from beyond them. The first pass
|
||||
along an order that teaches such a rule ends the round; the directed-recovery and
|
||||
full passes run only when the lighter pass taught nothing. An attempt
|
||||
stops backtracking after a stall of 8 x entries x contours expansions without
|
||||
@@ -227,7 +230,8 @@ parts before it. The contours are the larger count of the blocked part and the p
|
||||
cut just before it, whose departure a retry changes, so one many-holed part elsewhere
|
||||
on the plate does not lengthen every stall. A cutoff is the exception: it is a fixed program and cutting it earlier never
|
||||
makes its own cut harder, so an approach into a non-separating cutoff that crosses parts already
|
||||
cut teaches "cut the cutoff before them" at once, without that stall. A rule that would contradict an order already required is skipped.
|
||||
cut teaches "cut the cutoff before them" at once, without that stall, and one into a sheet
|
||||
separator teaches its other-way-round rule at once. A rule that would contradict an order already required is skipped.
|
||||
"Cut before" rules are a heuristic (a part blocked straight after another may be
|
||||
reachable via a third), so once nothing new can be learned the remaining budget
|
||||
first tries sequence-free recovery, visiting dependency-ready parts lazily by
|
||||
@@ -247,7 +251,14 @@ segment that must precede some part (`CutOffInsertion`) goes as late as it can b
|
||||
the first part in its span of the line, into the latest gap where both rapids cross
|
||||
nothing cut before that point: the part after it keeps the program it was planned with,
|
||||
and only its incoming rapid is checked again from the segment's end. Segments due in the
|
||||
same gap are chained in the order placed, latest-due first. This keeps cutting local:
|
||||
same gap are chained in the order placed, latest-due first. A holed part cut straight
|
||||
after a segment was planned from where the tool was before the segment, but the tool is
|
||||
at the segment's end, often across the part from there: its holes were routed toward the
|
||||
wrong side and the rapid onto its first hole could cross the rapids between the others.
|
||||
So once the segments are placed, each such part keeps its outside entry and its place in
|
||||
the order, and takes the hole route and preferred hole entries planned from the
|
||||
segment's end; it keeps its planned holes when that route has no preferred entry for
|
||||
every hole or fails the checks. This keeps cutting local:
|
||||
the segment below a row of parts is cut while the route passes it, not up front, and
|
||||
never before a part it need not precede unless the geometry allows nothing later (a
|
||||
segment whose pierce is walled off by every part cut after a point goes before that
|
||||
@@ -258,8 +269,8 @@ separator or a line through open scrap precedes nothing and is planned like a pa
|
||||
separator after everything, the other at its tour position.
|
||||
|
||||
Wherever a segment sits in an order, the search looks through it: the part before it
|
||||
faces the next part, not the segment, and the part after it ranks its entries and hole
|
||||
route from where the tool was before the segment, while every rapid is still checked
|
||||
faces the next part, not the segment, and the part after it ranks its outside entry
|
||||
from where the tool was before the segment, while its hole route and every rapid start
|
||||
from the segment's end. A kept order with segments where a plan put them (an applied
|
||||
plan replanned with `Keep the current part order`) therefore gets the entries and
|
||||
routes the plan had, and replays Ready again.
|
||||
@@ -637,7 +648,7 @@ panel is wired in the editor. Non-editor callers still use the shared analyzer.
|
||||
plan keeps locked lead-ins and existing cut-offs unchanged. `Clear Lead-ins &
|
||||
Cut-offs...` asks first, then removes every applied lead-in (locked and hand-placed
|
||||
ones too), every cut-off and the plates' recorded cutting settings, keeping part
|
||||
poses, order and quantities, and replans from scratch. There is no undo. The button stays
|
||||
poses, order and quantities, and replans from scratch. To reverse it, close the panel and use Edit > Undo. The button stays
|
||||
enabled while a plan runs: confirming cancels that run, then clears once the cancellation
|
||||
lands (so the plates never change under the planner) and replans.
|
||||
- `Add scrap cut-offs` runs the automatic cut-off planner (defaults 35 in /
|
||||
|
||||
@@ -50,6 +50,21 @@ normal, so an arc lead-out starts on its own radius and the tab gap stays uncut.
|
||||
program generation and the manual preview share them. Other lead-in styles are
|
||||
unchanged.
|
||||
|
||||
## Rounded corners in Plan Cutting
|
||||
|
||||
Plan Cutting prefers to start a contour at a convex corner. The tool returns to the start
|
||||
after it has put heat into the plate, so a start partway along a straight edge can leave a
|
||||
step. A start at a corner hides it. An edge midpoint is a fallback, used only when no corner on
|
||||
a side facing the next cut fits.
|
||||
|
||||
A corner rounded by a small fillet counts as a corner. The fillet must be tangent to straight
|
||||
edges at both ends, turn convexly through less than a half circle, and have a reach
|
||||
(`radius * tan(sweep / 2)`) no longer than either edge. Each of its two tangent joints is then
|
||||
a convex corner entry (`PreparedContours.FilletReach`). Ranking counts the joint on both sides of
|
||||
the corner it rounds, as it would a sharp corner. Longer curves, half-circle ends and inside
|
||||
(reflex) fillets keep their tangent joints, which rank level with edge midpoints. The lead-in at
|
||||
a fillet's joint is the normal one for its edge, since emission still sees a smooth joint there.
|
||||
|
||||
## Curved leads
|
||||
|
||||
Every curved lead (Arc, Line + Arc, Clean Hole, the arc lead-out) meets the cut tangentially and
|
||||
|
||||
@@ -118,8 +118,9 @@ utilization, cut sequence or CNC output. Files without the key load with no
|
||||
zones, and an individually malformed entry (blank id, non-positive size) is
|
||||
dropped while the rest of the nest loads.
|
||||
|
||||
`plateDefaults.clampRail` optionally stores the nest's machine clamp rail:
|
||||
`width` (along the edge), `depth` (into the sheet) and `centers` (X positions
|
||||
`plateDefaults.clampRail` optionally stores the nest's machine clamp rail, the nest's
|
||||
own copy (a new nest copies it from its `machine`'s clamps; later machine edits do not
|
||||
change it): `width` (along the edge), `depth` (into the sheet) and `centers` (X positions
|
||||
measured from the plate origin along the origin-side edge). Clamps on the other
|
||||
edges are listed in optional `farSideCenters` (X, along the edge across the
|
||||
sheet's width from the origin), `originEndCenters` (Y, along the edge through
|
||||
|
||||
@@ -29,7 +29,7 @@ The desktop app can save nests two ways:
|
||||
without binding an editable document, and **Download selected version...** saves
|
||||
its exact archived bytes.
|
||||
Select a nest and click **Nest Information...** above the list (or use the
|
||||
row's right-click menu) to edit the same information as **Nest > Nest Info**,
|
||||
row's right-click menu) to edit the same information as **Nest > Edit**,
|
||||
including the name, without opening the nest in the main editor. **OK** saves immediately to the
|
||||
same database ID as a new version, then refreshes the list, preview and history;
|
||||
**Cancel** makes no change. The dialog starts with the latest saved metadata.
|
||||
@@ -222,7 +222,7 @@ allocate the year's next name and show it in an editable dialog: OK uploads
|
||||
under the chosen name, Cancel saves nothing. If the check or the allocation
|
||||
fails or takes longer than 3 seconds, the nest uploads under its current name.
|
||||
|
||||
In Database mode the name can be edited in **Nest > Nest Info** (it uploads with
|
||||
In Database mode the name can be edited in **Nest > Edit** (it uploads with
|
||||
the next Save) and in the saved-nest browser's **Nest Information...** (saved
|
||||
immediately). In File mode it stays read-only, since the file name is the nest
|
||||
name. If another active nest already has the exact new name, a warning asks
|
||||
@@ -426,7 +426,7 @@ so the range is drawn faded. Dragging a handle moves it in whole degrees (Shift:
|
||||
15°) within 0° ≤ start ≤ end ≤ 360°; the end can be dragged past 0° to a full
|
||||
turn. With focus, the arrow keys move a handle and Space switches handles.
|
||||
|
||||
When the new details would give the drawing another identity (D4: normalized
|
||||
When the new details would give the drawing another identity (normalized
|
||||
customer, name, material and grade, exact thickness, units and cut type), Save
|
||||
first looks up active library drawings that already have them and, if any do,
|
||||
names them and asks before saving; a failed lookup also asks. Editing only notes
|
||||
@@ -565,7 +565,7 @@ Add to Release as its only buttons; File > Import BOM stays the familiar way in.
|
||||
are kept: the drawing is stored with a blank material and thickness 0, and the
|
||||
set editor's note column leads to Edit Drawing to fix it before Make Nests.
|
||||
2. Each drawing is matched to the library (`OpenNest.Data.DrawingSetImport`) by
|
||||
its identity (D4: normalized customer, name, material and grade, exact
|
||||
its identity (normalized customer, name, material and grade, exact
|
||||
thickness, units and cut type; the name is the file name without extension,
|
||||
the grade blank, the units the new-nest default and the cut type the one last
|
||||
saved to the library on this PC) and its geometry:
|
||||
|
||||
+7
-10
@@ -72,16 +72,13 @@ or attestations (`--provenance=false --sbom=false`), and runs the real-client
|
||||
container persistence/backup/restore smoke. A Windows `v*` tag build alone never
|
||||
publishes a server image.
|
||||
|
||||
Publication requires owner-approved release intent: a **published, non-prerelease GitHub Release**
|
||||
or an explicit `Server image` dispatch **from `master`**, naming an existing strict
|
||||
`vX.Y.Z` tag (no prerelease suffix, leading zero, or extra suffix). GitHub pre-releases
|
||||
publish only the Windows assets; they skip the server image publish and verification
|
||||
jobs. Changing a pre-release to a full release later is a separate publication
|
||||
decision. The tag must resolve to
|
||||
a full commit already on `master`. For a published Release, that peeled commit
|
||||
must also equal the event's full `GITHUB_SHA`; a retargeted tag is refused. Manual
|
||||
dispatch intentionally resolves the approved existing tag, not the workflow's
|
||||
`master` SHA. The job checks out that exact source, reruns all
|
||||
Publication requires an explicit, owner-approved `Server image` dispatch **from
|
||||
`master`**, naming an existing strict `vX.Y.Z` tag (no prerelease suffix, leading
|
||||
zero, or extra suffix). Publishing a GitHub Release, stable or pre-release, only
|
||||
validates the image; it never publishes it, so a desktop release and a server image
|
||||
release are separate decisions. The tag must resolve to a full commit already on
|
||||
`master`. The dispatch intentionally resolves the approved existing tag, not the
|
||||
workflow's `master` SHA. The job checks out that exact source, reruns all
|
||||
server/image gates, and pushes the *same smoked image* to
|
||||
`ghcr.io/ajisaacs/opennest-server:X.Y.Z` and `:sha-<full-commit>` only. Both tags must
|
||||
be absent; retries after even a partial upload stop instead of overwriting. There
|
||||
|
||||
@@ -6,9 +6,9 @@ building nests and posts the same way:
|
||||
|
||||
| Kind | Key | What it holds | This PC's own copy |
|
||||
|---|---|---|---|
|
||||
| `machine` | machine id | A Tools > Machine Configuration entry: materials, grades, thicknesses, leads, kerf, cut-offs, motion limits, plate sizes, support grid | `%APPDATA%\OpenNest\Machines\<id>.json` |
|
||||
| `machine` | machine id | A Tools > Machine Configuration entry: materials, grades, thicknesses, leads, kerf, cut-offs, motion limits, plate sizes, support grid, clamps | `%APPDATA%\OpenNest\Machines\<id>.json` |
|
||||
| `post` | post type name, e.g. `OpenNest.Posts.CincinnatiCIFiber.CIFiberPostProcessor` | A post's settings, as its JSON file holds them | `<post>.json` beside the post DLL in `Posts\` |
|
||||
| `clamps` | `default` | Machine clamp defaults (Save as Machine Defaults) | `%APPDATA%\OpenNest\clamps.json` |
|
||||
| `clamps` | `default` | Legacy clamp settings, read only to copy them onto a machine once (machines now hold their clamps) | `%APPDATA%\OpenNest\clamps.json` |
|
||||
| `nest-defaults` | `default` | Tools > Nest Defaults: units, sheet size, quadrant, spacing, default machine | `%APPDATA%\OpenNest\defaults.json` |
|
||||
|
||||
File mode, the console, MCP and API front ends use only this PC's copies.
|
||||
@@ -21,7 +21,7 @@ one), posts per post, clamps and nest defaults as single documents. Saves go whe
|
||||
settings were read, so editing a kind the server does not hold yet changes only this PC.
|
||||
|
||||
When the desktop opens in Database mode and the server lacks any of this PC's machines (all
|
||||
of them, when it holds none), post settings, clamp settings or nest defaults, it lists them
|
||||
of them, when it holds none), post settings or nest defaults, it lists them
|
||||
and offers to upload them. The first workstation to answer Yes seeds the server; a document
|
||||
the server already holds is never replaced, so later workstations only add what is missing
|
||||
(a post installed on just one PC, for example). Declining keeps that PC on its own copies and
|
||||
@@ -45,7 +45,8 @@ saved first the server refuses it and the desktop takes their copy:
|
||||
even though the Cincinnati post records the material library the nest selected.
|
||||
- Machine Configuration: the unsaved machines stay pending; reopen the window to see the
|
||||
other changes.
|
||||
- Clamps, nest defaults, support grid: the save reports the conflict.
|
||||
- Nest > Clamps and Nest > Support Grid machine defaults, nest defaults: the save reports
|
||||
the conflict.
|
||||
|
||||
The window title of Tools > Machine Configuration says whether it edits the shared machines,
|
||||
this PC's (not shared yet), or a read-only copy. Tools > Nest Defaults says the same beside
|
||||
|
||||
@@ -75,7 +75,8 @@ inside corner. Only when every outline point is too close does the clearance giv
|
||||
View > Draw Support shows the grid or the slats, cut off to the sheet (while its points or slats
|
||||
are at least 6 pixels apart), each part's
|
||||
contacts, and its center of gravity: green when supported, red when it can tip, with an orange
|
||||
diamond on a red part's best tab point (keeping the plate's tab-size clearance).
|
||||
diamond on a red part's best tab point (keeping the plate's tab-size clearance). While Plan
|
||||
Cutting inspects a proposal, the overlay shows the proposal's parts on the same bed.
|
||||
|
||||
## Support tabs in Plan Cutting
|
||||
|
||||
|
||||
+3
-3
@@ -28,7 +28,7 @@ Everything stored in the nest:
|
||||
cut-offs;
|
||||
- drawings: import, Shape Library, edit in the converter, drawing properties and quantities, delete, clean
|
||||
unused, Drawing Library adds, a drawing's library link after Save to Drawing Library;
|
||||
- the nest: its machine and the Nest Info fields other than identity (below).
|
||||
- the nest: its machine and the Nest > Edit fields other than identity (below).
|
||||
|
||||
The Edit menu names the step: "Undo Rotate", "Redo Fill". `UndoRecordingTests` holds one test
|
||||
per recorded edit with its label.
|
||||
@@ -43,7 +43,7 @@ Deliberately excluded:
|
||||
and post configuration, nest defaults;
|
||||
- view state: zoom, pan, view toggles, selection, the active side panel;
|
||||
- the nest's identity: `Name`, `Status`, `MadeBy` and `DateCreated`. A restore carries them
|
||||
over from the live nest, so a Nest Info edit of only these records nothing. All `Document`
|
||||
over from the live nest, so a Nest > Edit change of only these records nothing. All `Document`
|
||||
state (save path, server id and revision) stays too: the `Document` is never replaced.
|
||||
|
||||
A save does not clear the history; it marks a save point (`UndoHistory.MarkSaved`,
|
||||
@@ -152,7 +152,7 @@ when it has none does the nest undo.
|
||||
- 50 undo steps and 128 MB per open nest (`UndoHistory.DefaultMaxDepth`, `DefaultMaxBytes`);
|
||||
the oldest states are evicted first, never the current one.
|
||||
- Typical nests take a few kilobytes and a few milliseconds per state. Measured on the
|
||||
heaviest production nests (E0323-02, 7000 parts; K0924-17, 101 drawings) with every part
|
||||
heaviest production nests (one of about 7,000 parts, one with 101 drawings) with every part
|
||||
planned: capture about 350 ms and 2.2 MB, Undo about 1 s, most of it the plate reload
|
||||
(`LayoutPart.Create` per part, the same as switching to that plate). Opening a nest pays one
|
||||
capture for the history's first state.
|
||||
|
||||
@@ -698,11 +698,12 @@ class ImmutableTagCollisions(unittest.TestCase):
|
||||
|
||||
|
||||
class WorkflowBehavior(unittest.TestCase):
|
||||
def test_prerelease_skips_ghcr_publish_but_stable_release_and_manual_dispatch_remain(self):
|
||||
def test_only_a_manual_dispatch_from_master_publishes_to_ghcr(self):
|
||||
workflow = pathlib.Path(__file__).resolve().parents[1] / ".github/workflows/server-image.yml"
|
||||
publish = workflow.read_text().split("\n publish:\n", 1)[1].split("\n verify-published:\n", 1)[0]
|
||||
condition = publish.split(" if: >-\n", 1)[1].split(" runs-on:", 1)[0]
|
||||
self.assertIn("github.event_name == 'release' && github.event.release.prerelease == false", condition)
|
||||
# Publishing a GitHub Release, stable or pre-release, never publishes the image.
|
||||
self.assertNotIn("'release'", condition)
|
||||
self.assertIn("github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master'", condition)
|
||||
|
||||
def test_build_log_pipeline_preserves_docker_failure(self):
|
||||
|
||||
Reference in new issue
Block a user