mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-25 11:17:40 -05:00
feat(labels): find the label box for half-inch text, stepping down to fit
Quarter-inch etching is hard for the shop to read, and most of the crew would rather have half-inch text. Find Best Location now tries half-inch, then three-eighths, then quarter-inch text (12, 9, 6 mm) and keeps the largest that fits, so big parts get readable labels and small parts still get one. Only when even the quarter-inch label fits nowhere is a box placed for hand adjustment, at that smallest size. Boxes already placed keep their size until found again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
75f7444aab
commit
7634c95fc7
5 files changed
+65
-18
No files matched your search
@@ -42,10 +42,21 @@ namespace OpenNest.Labels
|
||||
Clearance = clearance,
|
||||
};
|
||||
|
||||
/// <summary>A quarter inch (6 mm) label of <see cref="DefaultCharacters"/> characters, an eighth inch (3 mm) from anything else.</summary>
|
||||
public static LabelBoxOptions Default(Units units) => units == Units.Millimeters
|
||||
? ForText(DefaultCharacters, 6, 3)
|
||||
: ForText(DefaultCharacters, 0.25, 0.125);
|
||||
/// <summary>
|
||||
/// The label sizes to try, largest first: <see cref="DefaultCharacters"/> characters of
|
||||
/// half inch, three eighths and quarter inch text (12, 9 and 6 mm), each an eighth inch
|
||||
/// (3 mm) from anything else. Big text reads from farther off; smaller parts take the
|
||||
/// largest that fits.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<LabelBoxOptions> Sizes(Units units) => units == Units.Millimeters
|
||||
? [ForText(DefaultCharacters, 12, 3), ForText(DefaultCharacters, 9, 3), ForText(DefaultCharacters, 6, 3)]
|
||||
: [ForText(DefaultCharacters, 0.5, 0.125), ForText(DefaultCharacters, 0.375, 0.125), ForText(DefaultCharacters, 0.25, 0.125)];
|
||||
|
||||
/// <summary>The largest of <see cref="Sizes"/>: a half inch (12 mm) label.</summary>
|
||||
public static LabelBoxOptions Default(Units units) => Sizes(units)[0];
|
||||
|
||||
/// <summary>The smallest of <see cref="Sizes"/>: a quarter inch (6 mm) label.</summary>
|
||||
public static LabelBoxOptions Smallest(Units units) => Sizes(units)[^1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -229,6 +229,13 @@ public class LabelBoxFinderTests
|
||||
Assert.Equal(0.25, options.Height, 9);
|
||||
Assert.Equal(0.125, options.Clearance, 9);
|
||||
Assert.True(LabelBoxOptions.Default(Units.Millimeters).Height > LabelBoxOptions.Default(Units.Inches).Height);
|
||||
|
||||
var sizes = LabelBoxOptions.Sizes(Units.Inches);
|
||||
Assert.Equal([0.5, 0.375, 0.25], sizes.Select(size => size.Height));
|
||||
Assert.Equal(0.5, LabelBoxOptions.Default(Units.Inches).Height, 9);
|
||||
Assert.Equal(0.25, LabelBoxOptions.Smallest(Units.Inches).Height, 9);
|
||||
Assert.All(sizes, size => Assert.Equal(0.125, size.Clearance, 9));
|
||||
Assert.Equal([12.0, 9, 6], LabelBoxOptions.Sizes(Units.Millimeters).Select(size => size.Height));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -72,8 +72,28 @@ public class CadConverterLabelBoxTests
|
||||
form.Close();
|
||||
});
|
||||
|
||||
[Theory]
|
||||
[InlineData(10, 6, 0.5)]
|
||||
[InlineData(2.6, 0.7, 0.375)]
|
||||
[InlineData(2.2, 0.6, 0.25)]
|
||||
public void Finding_TakesTheLargestTextThatFits(double width, double height, double textHeight) =>
|
||||
ArchUnitsTests.RunSta(() =>
|
||||
{
|
||||
// Half inch text needs about 3.25 x 0.75 of flat part, three eighths 2.5 x 0.625.
|
||||
using var form = new LabelTestForm();
|
||||
Show(form);
|
||||
form.LoadDrawings([Part(width, height)]);
|
||||
var item = Field<FileListControl>(form, "fileList").SelectedItem!;
|
||||
|
||||
Invoke(form, "OnLabelBoxClick", null, EventArgs.Empty);
|
||||
|
||||
Assert.Equal(textHeight, item.LabelBox!.Height, 6);
|
||||
Assert.Empty(form.Messages);
|
||||
form.Close();
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public void NoRoom_PlacesAFullSizeBoxOnTheRoomiestSpotToAdjustByHand() => ArchUnitsTests.RunSta(() =>
|
||||
public void NoRoom_PlacesASmallestSizeBoxOnTheRoomiestSpotToAdjustByHand() => ArchUnitsTests.RunSta(() =>
|
||||
{
|
||||
using var form = new LabelTestForm();
|
||||
Show(form);
|
||||
@@ -84,7 +104,7 @@ public class CadConverterLabelBoxTests
|
||||
Invoke(form, "OnLabelBoxClick", null, EventArgs.Empty);
|
||||
|
||||
var box = item.LabelBox!;
|
||||
var full = LabelBoxOptions.Default(Units.Inches);
|
||||
var full = LabelBoxOptions.Smallest(Units.Inches);
|
||||
Assert.Equal(full.Width, box.Width, 6);
|
||||
Assert.Equal(full.Height, box.Height, 6);
|
||||
Assert.Equal(0.5, box.Center.X, 3);
|
||||
|
||||
@@ -55,8 +55,9 @@ namespace OpenNest.Forms
|
||||
private static readonly double[] FallbackLabelScales = { 0.75, 0.5, 0.25 };
|
||||
|
||||
/// <summary>
|
||||
/// Places the label box on the best flat area of the part as it will be cut. When the label
|
||||
/// does not fit, a box is still placed for the user to adjust by hand: the full-size box
|
||||
/// Places the label box on the best flat area of the part as it will be cut, at the largest
|
||||
/// text size that fits (<see cref="LabelBoxOptions.Sizes"/>). When even the smallest label
|
||||
/// does not fit, a box is still placed for the user to adjust by hand: the smallest-size box
|
||||
/// centered on the roomiest flat spot a smaller label fits, else on the middle of the part,
|
||||
/// and the user is told so.
|
||||
/// </summary>
|
||||
@@ -70,9 +71,13 @@ namespace OpenNest.Forms
|
||||
.Select(l => (System.Collections.Generic.IEnumerable<Geometry.Entity>)l.Scrap)
|
||||
.ToList();
|
||||
|
||||
// The largest label size that fits; only when even the smallest does not is a box
|
||||
// placed for hand adjustment, at that smallest size.
|
||||
var entities = DimensionedEntities(item);
|
||||
var options = LabelBoxOptions.Default(DrawingUnits);
|
||||
var box = LabelBoxFinder.Find(entities, item.Bends, options, scrap);
|
||||
var sizes = LabelBoxOptions.Sizes(DrawingUnits);
|
||||
var box = sizes.Select(size => LabelBoxFinder.Find(entities, item.Bends, size, scrap))
|
||||
.FirstOrDefault(found => found != null);
|
||||
var options = sizes[^1];
|
||||
if (box != null)
|
||||
{
|
||||
item.LabelBox = box;
|
||||
|
||||
+12
-8
@@ -5,7 +5,10 @@ etched, found on flat material clear of everything else. The CAD Converter store
|
||||
placement; Plan Cutting etches the text when **Etch part label** is not Off (see
|
||||
[Etching the label](#etching-the-label)).
|
||||
|
||||
In the CAD Converter, **Label Box...** (bottom bar) finds the best spot for the shown part.
|
||||
In the CAD Converter, **Label Box...** (bottom bar) finds the best spot for the shown part, for
|
||||
the largest text that fits: half inch text if the part has room for it, so the shop can read it
|
||||
from farther off, else three eighths, else a quarter inch (12, 9 or 6 mm). The box height is the
|
||||
text height, so a box can also be resized by hand to change it.
|
||||
The box is drawn as a dashed rectangle. Drag its body to move it, a corner to resize it
|
||||
(the opposite corner stays put) and the round handle above its top side to turn it about its
|
||||
center, in 5° steps or freely with Shift held. Once a box exists the button offers **Find Best
|
||||
@@ -22,9 +25,9 @@ leaves it under half the box height, the box turns red, the shrunk text is drawn
|
||||
**Too small to etch** shows under it, because Plan Cutting would etch nothing there. To run the
|
||||
text up the part, turn the box first (**Rotate 90°**) and then resize it.
|
||||
|
||||
When the label fits nowhere, the button still places a full-size box for hand placement and
|
||||
says so: centered on the roomiest flat spot a smaller label (three quarters, half, then a
|
||||
quarter of its size) fits clear of everything, at that spot's angle, or in the middle of the
|
||||
When even the quarter inch label fits nowhere, the button still places a quarter inch box for
|
||||
hand placement and says so: centered on the roomiest flat spot a smaller label (three quarters,
|
||||
half, then a quarter of its size) fits clear of everything, at that spot's angle, or in the middle of the
|
||||
part's bounds when even the smallest does not fit. The box may then overlap edges or bend
|
||||
lines until it is moved or resized.
|
||||
|
||||
@@ -38,10 +41,11 @@ nesting geometry, cut time or posts, and it does not appear in DXF, DWG or SVG e
|
||||
converter's entities. Null when none is set.
|
||||
- `LabelBoxFinder` (`OpenNest.Core/Labels`) is a pure, deterministic function of the part as
|
||||
it will be cut (visible, roles, breakoffs and tabbed cutouts applied, as the Dimensions
|
||||
code reads it), its bends and a `LabelBoxOptions`. The converter uses
|
||||
`LabelBoxOptions.Default(units)`: eight characters (room for a four-digit part number and two
|
||||
circled bend group letters, `1234 AB`) of a quarter inch (6 mm) stroke font, an eighth inch
|
||||
(3 mm) clear of anything else.
|
||||
code reads it), its bends and a `LabelBoxOptions`. The converter tries
|
||||
`LabelBoxOptions.Sizes(units)` largest first and keeps the first box found: eight characters
|
||||
(room for a four-digit part number and two circled bend group letters, `1234 AB`) of a half
|
||||
inch, three eighths and quarter inch (12, 9 and 6 mm) stroke font, each an eighth inch (3 mm)
|
||||
clear of anything else. Boxes placed before keep their size until found again.
|
||||
- Material is what nesting reads (`NestingMaterial.ForNesting`, marks excluded), so a tabbed
|
||||
cutout's slug counts as part and etch, scribe and break cuts do not. The material is
|
||||
eroded by the clearance with the same Clipper inward offset the pierce search uses, a band
|
||||
|
||||
Reference in new issue
Block a user