mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-19 21:47:42 -05:00
On an enclosed machine a cutout slug that tips once cut free can stand up above the sheet and catch the enclosure door when the pallet changes. The head already keeps off cut cutouts, so this is about clearing the door, not the head. Cutting Settings > Cutouts > "Slice slugs the support grid can't hold level" (CuttingParameters.SliceTippingSlugs, off by default, saved per machine thickness and written only when on) makes Plan Cutting cut each such slug along the bed's contact lines (grid rows and columns, slat center lines) before the cutout, so no piece keeps a contact and the pieces drop between the supports. Each slice stops a kerf short of the cutout, so the pieces stay attached until the cutout's own kerf frees them together. A slug the bed holds level, or one on no contact, is left whole; a cutout holding another part or another of its part's cuts is never sliced. Slices are break cuts emitted right after the drawing's own break cuts, pierced on themselves and led straight back to their start. The released-contour proof now leaves out straight break cuts lying wholly inside one of the part's closed holes, since the grid cells they free are scrap; break cuts in material still take part. The plan fingerprint only changes when the setting is on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
147 lines
7.4 KiB
C#
147 lines
7.4 KiB
C#
using System;
|
|
using OpenNest.CNC.CuttingStrategy;
|
|
|
|
namespace OpenNest.CNC.CuttingPlanning;
|
|
|
|
/// <summary>Copies only supported, exact setting types; never slices custom subclasses.</summary>
|
|
internal static class OwnedCuttingParameters
|
|
{
|
|
internal static CuttingParameters Copy(CuttingParameters source)
|
|
{
|
|
Exact<CuttingParameters>(source);
|
|
Exact<SequenceParameters>(source.Sequencing);
|
|
Exact<AssignmentParameters>(source.Assignment);
|
|
var sequence = source.Sequencing;
|
|
var assignment = source.Assignment;
|
|
if (!Enum.IsDefined(sequence.Method) || !Enum.IsDefined(assignment.Method))
|
|
throw new ArgumentException("Unsupported sequence method.");
|
|
if (assignment.Preference == null)
|
|
throw new ArgumentException("Missing assignment preference.");
|
|
if (!double.IsFinite(source.LeadInAngleIncrement) || source.LeadInAngleIncrement <= 0
|
|
|| source.LeadInAngleIncrement > 360)
|
|
throw new ArgumentException("Angle increment must be in (0, 360] degrees.");
|
|
return new CuttingParameters
|
|
{
|
|
Id = source.Id,
|
|
MachineName = source.MachineName,
|
|
MaterialName = source.MaterialName,
|
|
Grade = source.Grade,
|
|
Thickness = Dimension(source.Thickness),
|
|
Kerf = Dimension(source.Kerf),
|
|
PartSpacing = Dimension(source.PartSpacing),
|
|
PierceClearance = Dimension(source.PierceClearance),
|
|
PierceDiameter = Dimension(source.PierceDiameter),
|
|
ExternalLeadIn = CopyLeadIn(source.ExternalLeadIn),
|
|
InternalLeadIn = CopyLeadIn(source.InternalLeadIn),
|
|
ExternalLeadOut = CopyLeadOut(source.ExternalLeadOut),
|
|
InternalLeadOut = CopyLeadOut(source.InternalLeadOut),
|
|
RoundLeadInAngles = source.RoundLeadInAngles,
|
|
LeadInAngleIncrement = source.LeadInAngleIncrement,
|
|
TabConfig = source.TabConfig == null
|
|
? source.TabsEnabled ? throw new ArgumentException("Enabled tabs require a configuration.") : null
|
|
: CopyTab(source.TabConfig),
|
|
TabsEnabled = source.TabsEnabled,
|
|
SupportTabs = source.SupportTabs,
|
|
TabBySize = source.TabBySize,
|
|
TabSizeMinWidth = Dimension(source.TabSizeMinWidth),
|
|
TabSizeMaxWidth = Dimension(source.TabSizeMaxWidth),
|
|
TabHeldMaxLength = Dimension(source.TabHeldMaxLength),
|
|
SliceTippingSlugs = source.SliceTippingSlugs,
|
|
Sequencing = new SequenceParameters
|
|
{
|
|
Method = sequence.Method,
|
|
SmallCutoutWidth = Dimension(sequence.SmallCutoutWidth),
|
|
SmallCutoutHeight = Dimension(sequence.SmallCutoutHeight),
|
|
MediumCutoutWidth = Dimension(sequence.MediumCutoutWidth),
|
|
MediumCutoutHeight = Dimension(sequence.MediumCutoutHeight),
|
|
DistanceMediumSmall = Dimension(sequence.DistanceMediumSmall),
|
|
AlternateRowsColumns = sequence.AlternateRowsColumns,
|
|
AlternateCutoutsWithinRowColumn = sequence.AlternateCutoutsWithinRowColumn,
|
|
MinDistanceBetweenRowsColumns = Dimension(sequence.MinDistanceBetweenRowsColumns)
|
|
},
|
|
Assignment = new AssignmentParameters
|
|
{
|
|
Method = assignment.Method,
|
|
Preference = assignment.Preference,
|
|
MinGeometryLength = Dimension(assignment.MinGeometryLength)
|
|
}
|
|
};
|
|
}
|
|
|
|
internal static LeadIn CopyLeadIn(LeadIn source) => source switch
|
|
{
|
|
NoLeadIn n when n.GetType() == typeof(NoLeadIn) => new NoLeadIn(),
|
|
LineLeadIn n when n.GetType() == typeof(LineLeadIn) => new LineLeadIn
|
|
{ Length = Dimension(n.Length), ApproachAngle = Angle(n.ApproachAngle) },
|
|
ArcLeadIn n when n.GetType() == typeof(ArcLeadIn) => new ArcLeadIn
|
|
{ Radius = Dimension(n.Radius), SweepAngle = Sweep(n.SweepAngle) },
|
|
LineArcLeadIn n when n.GetType() == typeof(LineArcLeadIn) => new LineArcLeadIn
|
|
{ LineLength = Dimension(n.LineLength), ArcRadius = Dimension(n.ArcRadius), ApproachAngle = Angle(n.ApproachAngle) },
|
|
LineLineLeadIn n when n.GetType() == typeof(LineLineLeadIn) => new LineLineLeadIn
|
|
{
|
|
Length1 = Dimension(n.Length1),
|
|
Length2 = Dimension(n.Length2),
|
|
ApproachAngle1 = Angle(n.ApproachAngle1),
|
|
ApproachAngle2 = Angle(n.ApproachAngle2)
|
|
},
|
|
CleanHoleLeadIn n when n.GetType() == typeof(CleanHoleLeadIn) => new CleanHoleLeadIn
|
|
{ LineLength = Dimension(n.LineLength), ArcRadius = Dimension(n.ArcRadius), Kerf = Dimension(n.Kerf) },
|
|
null => throw new ArgumentException("Missing lead-in settings."),
|
|
_ => throw new NotSupportedException("Unsupported lead-in runtime type.")
|
|
};
|
|
|
|
internal static LeadOut CopyLeadOut(LeadOut source) => source switch
|
|
{
|
|
NoLeadOut n when n.GetType() == typeof(NoLeadOut) => new NoLeadOut(),
|
|
LineLeadOut n when n.GetType() == typeof(LineLeadOut) => new LineLeadOut
|
|
{ Length = Dimension(n.Length), ApproachAngle = Angle(n.ApproachAngle) },
|
|
ArcLeadOut n when n.GetType() == typeof(ArcLeadOut) => new ArcLeadOut { Radius = Dimension(n.Radius) },
|
|
null => throw new ArgumentException("Missing lead-out settings."),
|
|
_ => throw new NotSupportedException("Unsupported lead-out runtime type.")
|
|
};
|
|
|
|
internal static Tab CopyTab(Tab source)
|
|
{
|
|
Tab copy = source switch
|
|
{
|
|
NormalTab n when n.GetType() == typeof(NormalTab) => new NormalTab
|
|
{
|
|
CutoutMinWidth = Dimension(n.CutoutMinWidth),
|
|
CutoutMinHeight = Dimension(n.CutoutMinHeight),
|
|
CutoutMaxWidth = Dimension(n.CutoutMaxWidth),
|
|
CutoutMaxHeight = Dimension(n.CutoutMaxHeight)
|
|
},
|
|
BreakerTab n when n.GetType() == typeof(BreakerTab) => new BreakerTab
|
|
{
|
|
BreakerDepth = Dimension(n.BreakerDepth),
|
|
BreakerLeadInLength = Dimension(n.BreakerLeadInLength),
|
|
BreakerAngle = Angle(n.BreakerAngle)
|
|
},
|
|
MachineTab n when n.GetType() == typeof(MachineTab) => new MachineTab { MachineTabId = n.MachineTabId },
|
|
_ => throw new NotSupportedException("Unsupported tab runtime type.")
|
|
};
|
|
copy.Size = Dimension(source.Size);
|
|
copy.TabLeadIn = source.TabLeadIn == null ? null : CopyLeadIn(source.TabLeadIn);
|
|
copy.TabLeadOut = source.TabLeadOut == null ? null : CopyLeadOut(source.TabLeadOut);
|
|
return copy;
|
|
}
|
|
|
|
private static void Exact<T>(T value) where T : class
|
|
{
|
|
if (value == null)
|
|
throw new ArgumentException("Missing cutting settings.");
|
|
if (value.GetType() != typeof(T))
|
|
throw new NotSupportedException("Unsupported settings runtime type.");
|
|
}
|
|
|
|
private static double Dimension(double value) => double.IsFinite(value) && value >= 0
|
|
? value : throw new ArgumentException("Dimensions must be finite and nonnegative.");
|
|
|
|
// Approach angles are degrees, not lengths. Signed and periodic angles are valid.
|
|
private static double Angle(double value) => double.IsFinite(value)
|
|
? value : throw new ArgumentException("Angles must be finite.");
|
|
|
|
private static double Sweep(double value) => double.IsFinite(value) && value > 0 && value <= 180
|
|
? value : throw new ArgumentException("Arc sweep must be in (0, 180] degrees.");
|
|
}
|