mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-27 05:01:05 -04:00
Clamps could only sit on the origin-side edge and be edited as a list in Nest > Clamps. Setting them up against a real sheet is easier by dragging them where they are, so Plate > Edit Clamps adds an edit mode: drag a clamp along its edge or onto another edge, click near an edge to add one, click a clamp's locating dimension to type its distance from the origin, Delete to remove. Dimensions measure to the clamp center or its near edge (remembered per user). Edits replace the nest's rail so every sheet follows, like the dialog. Rail clamps now carry a ClampEdge (origin side, far side, origin end, far end), positioned from the origin along that edge. Origin-side clamps keep their ids and files; other edges persist in optional per-edge arrays in .nest files and clamps.json, omitted when empty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
using System;
|
|
|
|
namespace OpenNest
|
|
{
|
|
/// <summary>
|
|
/// The sheet edge a <see cref="ClampRail"/> clamp sits on, named relative to the plate
|
|
/// origin so one rail resolves onto every sheet size and quadrant.
|
|
/// </summary>
|
|
public enum ClampEdge
|
|
{
|
|
/// <summary>The edge along X through the origin (operator side).</summary>
|
|
OriginSide = 0,
|
|
|
|
/// <summary>The edge along X across the sheet's width from the origin.</summary>
|
|
FarSide = 1,
|
|
|
|
/// <summary>The edge along Y through the origin.</summary>
|
|
OriginEnd = 2,
|
|
|
|
/// <summary>The edge along Y across the sheet's length from the origin.</summary>
|
|
FarEnd = 3,
|
|
}
|
|
|
|
public static class ClampEdges
|
|
{
|
|
/// <summary>True for the two edges along X, whose clamp positions are X distances.</summary>
|
|
public static bool RunsAlongX(this ClampEdge edge) =>
|
|
edge is ClampEdge.OriginSide or ClampEdge.FarSide;
|
|
|
|
public static bool IsDefined(ClampEdge edge) =>
|
|
edge is ClampEdge.OriginSide or ClampEdge.FarSide or ClampEdge.OriginEnd or ClampEdge.FarEnd;
|
|
}
|
|
|
|
/// <summary>
|
|
/// One clamp of a <see cref="ClampRail"/>: its edge and its center measured from the plate
|
|
/// origin along that edge (X for the sides, Y for the ends). Orders by edge, then center.
|
|
/// </summary>
|
|
public readonly record struct RailClamp(ClampEdge Edge, double Center) : IComparable<RailClamp>
|
|
{
|
|
public int CompareTo(RailClamp other)
|
|
{
|
|
var edge = Edge.CompareTo(other.Edge);
|
|
return edge != 0 ? edge : Center.CompareTo(other.Center);
|
|
}
|
|
}
|
|
}
|