Skip to content

Flat-pattern DXF for a laser shop: layers by role, dashed bend lines, bend notes, text cut or etched, a file per body - #1324

Merged
bherbruck merged 3 commits into
tangency-labs:mainfrom
NOWN-DEV:feat/dxf-production
Oct 15, 2026
Merged

bherbruck merged 3 commits into
tangency-labs:mainfrom
NOWN-DEV:feat/dxf-production

Conversation

@NOWN-DEV

Copy link
Copy Markdown
Contributor

Change

Closes #1284.

Problem. sheet.export_dxf is what a laser shop gets, and a shop's nesting or CAM program works on the file layer by layer: cut the holes, then the outline, mark what is to be marked, fold on the bend lines. The flat pattern's DXF put every contour on OUTLINE (outer contour, holes, slots and letters with their counters, the outline in the middle of the file), drew the bend lines continuous (told apart by colour only), gave text no layer of its own (cut letters among the holes, engraved ones on a POCKET_… layer named by its depth), annotated no bend, and with two sheet bodies wrote one file and left the other body out without a word.

Fix. The layers are now by role, with colours (AutoCAD index) and linetypes the file defines (the LTYPE table has DASHED):

Layer Colour Line Holds
OUTLINE 7 continuous the outer contour of each piece
CUT 4 cyan continuous what is cut out inside it: holes, slots, a loose piece a cut leaves
TEXT 2 yellow continuous letters that text cut through the sheet, counters included
ETCH 6 magenta continuous letters as single contours to be marked, not cut; always text machined to a depth
BEND_UP, BEND_DOWN 1 red, 5 blue DASHED the bend centre lines
BEND_NOTES 8 grey continuous the notes, only when asked for
POCKET_…, PERFORATION 3 green continuous as before

Inner contours are written before the outline, so a program that follows the file's order cuts inside-out. A region inside another region's hole (a letter's counter, the middle of a ring cut) is a loose piece, not an outline.

  • Text. A cut whose sketch holds Sketch Text marks the cut-outs it makes as the sheet's letters (SheetBody::labels: flat regions, derived from the timeline like pockets, never saved: no design file field, the format stays 21). A letter that another cut-out overlaps or the sheet's edge clips has become one shape with it and stays on CUT. text: "cut" (default) writes the letters cut through the sheet as contours on TEXT; "etch" writes them as single contours on ETCH, the sheet keeps its material.
  • Bend notes. bend_notes: true writes a TEXT entity on BEND_NOTES beside each bend line: B1 UP 90° R1 (number, direction, angle, inner radius), note_height mm high (default 3), parallel to the line, readable from below or from the right. Off by default: a program that cuts or marks every layer would mark them.
  • One file per body. per_body: true writes <path>-<body>.dxf for each sheet body (a character a file name cannot hold becomes _, two bodies that would share a file get _2, _3…) and lists them under files; without a path it returns their texts. It is refused together with body; every file is made before the first is written.
  • A text, bend_notes, note_height or per_body value the export cannot use is refused.

The writer (crates/io/src/dxf_out.rs, first commit) learns what this needs: a layer's linetype, the STYLE table and a centred TEXT entity (%%d is AutoCAD's degree sign; other non-ASCII letters are \U+XXXX; the extents hold the text). The command's parameter list and the guide's sheet-metal page say all of it.

Not in this PR: layer names a user sets, XDATA, a bend-table block, etch for pockets that are not text, a change of the Flat Pattern dialog (it has no export options; it calls the command without them, so it gets the new layers).

Validation

New tests, numbers derived by hand. crates/engine/src/cmd/sheet_dxf_tests.rs (a 100 × 60 plate or a 2 mm tray, text "AB-12" in the default font):

  • the_flat_pattern_is_on_layers_by_role_and_inner_contours_come_first: a tray with a Ø5 hole, a slot and "AB-12" cut through its base, walls up and one down: OUTLINE is the outer contour alone (one entity for each of its segments, lines and arcs), CUT the Ø5 hole as one CIRCLE and the slot's four lines, TEXT the letters and counters; the last inner contour comes before the first outline entity; the layer table is exactly 0, OUTLINE (7), CUT (4), TEXT (2), BEND_UP (1, DASHED), BEND_DOWN (5, DASHED).
  • letters_can_be_etched_instead_of_cut, engraved_text_is_etched_and_other_pockets_keep_their_depth_layer: the same letters on ETCH with the same entities, nothing left on TEXT; text engraved 0.5 deep is on ETCH for both text values, and a rectangular pocket keeps its POCKET_… layer.
  • a_bend_note_sits_beside_each_bend_line_when_asked_for: none unless asked for; then one note per bend (4), each B<n> UP|DOWN 90%%d R1 for the bend's own number and direction, centred (72 = 1), 3 mm high (5 with note_height), at 0° along x and 90° along y, 1.5 mm from the middle of the line on its left.
  • each_sheet_body_can_have_a_file_of_its_own: a lid and a side wall: files lists Lid and Side Wall with 0 and 1 bends; each text equals the export of that body alone; written to a path they are panel-Lid.dxf and panel-Side Wall.dxf with no text in the reply and the same content on disk. the_file_of_a_body_is_named_after_it_and_no_two_share_a_name: the naming rules (extension, forbidden characters, empty name, case-insensitive duplicates).
  • bad_export_options_are_refused_not_ignored: ten bad values are errors; a plain export after them still works.
  • crates/io/src/dxf_out.rs: a_dashed_layer_names_its_linetype_and_the_table_defines_it (the four linetypes, DASHED = dash 12.7, gap 6.35, total 19.05, the table's count), text_is_centred_on_its_point_and_the_reader_gets_it_back (the group codes, read_dxf finds the text where it was put, as high and turned), the_extents_hold_the_text. crates/doc/src/sheet.rs: loops_lie_on_the_curves_they_are_made_of, a_sheet_knows_the_letters_it_carries.
  • Existing tests adapted, nothing else about them changes: flat_dxf_preserves_exact_cutout_entities (its two flat_dxf calls take &DxfOptions::default()), the helper in sheet_tests.rs that picks the lines of the outline and its holes out of a DXF (it reads OUTLINE and CUT), and bend_lines_and_layers_are_still_there (the cut-out is on CUT).

Against main's export (new io writer, old engine code) the six of these engine tests that call only the command, with the adapted bend_lines_and_layers_are_still_there, fail on assertions that name what is missing; the naming test, the io tests and the doc tests use the new API and do not compile on main.

The CLI, a 120 × 80 tray in 2 mm sheet (R 1, K 0.5): two Ø5 holes, a 30 × 5 slot, "AB-12" (14 mm high) cut through the base, "R-07" (8 mm) engraved 0.5 mm, three walls up and one down (solidcraft-cli run, sheet.export_dxf; 162 entities in both: only their layers change):

main (d73cd8a1) this change
OUTLINE 109: the outer contour, the holes and the letters (72 LINE, 35 SPLINE, 2 CIRCLE) 26 LINE: the outer contour
CUT none 2 CIRCLE, 4 LINE
TEXT none 42 LINE, 35 SPLINE ("AB-12")
ETCH none; "R-07" on POCKET_BOTTOM_Z0.000000_TO_0.500000_MM: 49 20 LINE, 29 SPLINE ("R-07")
text: "etch" ETCH 62 LINE, 64 SPLINE; nothing on TEXT
BEND_UP, BEND_DOWN 3 and 1 LINE, Continuous 3 and 1 LINE, DASHED
bend_notes: true (ignored) 4 TEXT on BEND_NOTES: B1 UP 90%%d R1, B2 UP …, B3 UP …, B4 DOWN …
order in the file part of the letter "A" first; the outer contour from the 22nd entity, the round holes 51st and 52nd the 132 inner contours (letters, holes, slot, engraving), then the 26 OUTLINE entities, then the bend lines
two bodies, per_body: true one file, panel.dxf, with the side wall (8 OUTLINE, 1 BEND_UP); the lid is missing panel-Lid.dxf (4 OUTLINE) and panel-Side Wall.dxf (8 OUTLINE, 1 BEND_UP)

Read by OpenSCAD 2021.01, layer by layer (import("x.dxf", layer="OUTLINE"), then "CUT"): on main the OUTLINE layer is 13 contours; here OUTLINE is 1 contour (the outer outline) and CUT is 3 (the slot and the two holes). OpenSCAD does not implement SPLINE and warns of it where letters are (on main's OUTLINE, here on none of the layers asked for). Our reader (sketch.insert_dxf of the file with the notes) gets 162 curves and 4 texts. Not opened in AutoCAD, BricsCAD, LibreCAD or a cutting machine's software: that they take the DASHED linetype, the STYLE table and the TEXT entities as written is read from Autodesk's DXF reference, not observed.

On the head fcd4db98 (on d73cd8a1): cargo fmt --all --check clean; cargo clippy -p solidcraft-io -p solidcraft-engine -p solidcraft-doc -p solidcraft-ui-egui -p solidcraft-cli --all-targets --profile ci --locked -- -D warnings clean; cargo test --profile ci --locked -p solidcraft-io -p solidcraft-engine --lib -- dxf sheet: 151 engine tests and 12 io tests passed; cargo test --profile ci --locked -p solidcraft-doc: 218 passed, 1 ignored. Each of the two commits also builds and passes alone (the first: fmt, clippy for io and engine, 144 engine and 12 io tests).

The whole cargo xtask ci ran once on Windows for these two commits (fcd4db98, on d73cd8a1) merged with another independent change of mine, which will be posted as its own pull request (combined commit 94efd5df, on bd8db8ea). It passes fmt, assets, licences, layers, clippy -D warnings, the wasm32 check, the doc tests and the render tests. What failed is not these changes':

  • The tests plain main fails on this machine (41f0c3d0, the same night): the robustness goldens all_0 to all_3 and issue_851_tests::arc_top_edge_sizes_never_panic in the kernel; crash::tests::startup_steps_survive_a_rebase_and_running_ends_startup (Native crash capture on Windows, and startup steps in crash reports #1215), which reads the journal through a second handle while the journal holds its exclusive lock, and Windows refuses that, as crash.rs says at read_live_journal; and render_workspace::tests::control_render_export_respects_upstream_file_scope, whose temporary folder here has a short (8.3) name, which the scope check refuses before it gets to the rule the test checks.
  • thread_tests::fillet_beside_a_modelled_thread_finishes failed beside the other test binaries and passes alone (main does the same). These commits change crates/io/src/dxf_out.rs and lib.rs, crates/doc/src/sheet.rs and eval_more.rs, crates/engine/src/cmd/sheet.rs with its two test files, and the sheet-metal guide page.

Screenshots of the behavior (when observable)

The tray's flat pattern drawn from the files (colours and dashes as the file says, a legend of the layers with their entity counts):

Before: every contour on OUTLINE, the bend lines continuous
After: OUTLINE, CUT, TEXT, ETCH, dashed bend lines

text: "etch" (the cut letters as single contours on ETCH) and bend_notes: true:

After, text etch
After, bend notes

Two sheet bodies (a 100 × 60 lid and a 50 × 40 side wall with a 15 mm flange): before, one file with the side wall; after, one file each:

Before: one file, the lid missing
After: the lid
After: the side wall

Integration status

Two commits on main d73cd8a1; it merges cleanly with today's main (0ee5e97d, #1312); of the 32 merges since its base, three touch these files in other places: #1280 (crates/doc/src/eval_more.rs), #1311 (a test added to crates/engine/src/cmd/sheet_tests.rs) and #1312 (a new type in crates/io/src/lib.rs). Not stacked, nothing depends on it. No design file field (the format stays 21) and no change of the Flat Pattern dialog or of any locale. Action matrix: not run; no action of it exports a DXF.

🤖 Generated with Claude Code

NOWN-DEV and others added 3 commits October 15, 2026 04:27
The writer behind the flat pattern's DXF (dxf_out.rs) knew only continuous layers and had
no text. A layer now has a linetype (DxfLayer::new makes a continuous one, .dashed() a
dashed one), the LTYPE table defines DASHED (a dash of 12.7 mm and a gap of 6.35 mm) beside
the three every drawing has, and the STYLE table holds "Standard". DxfShape::Text writes
one line as a TEXT entity centred on its point (justification 1, with both alignment
points, so a reader that takes either puts the middle there), at a height and an angle;
%%d, %%p and %%c are AutoCAD's degree, plus-minus and diameter signs, other letters outside
ASCII are written as \U+XXXX, and the extents hold the text.

Nothing writes either yet: the flat pattern still uses continuous layers only (its one
call is adapted to DxfLayer::new).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…tters cut or etched, a file per body

sheet.export_dxf wrote every contour of the flat pattern on one layer (OUTLINE, holes
included), the bend lines as plain continuous lines, text as anonymous curves, and only
one body's file. Now:

- Layers by role: OUTLINE is the outer contour of each piece, CUT what is cut out inside it
  (holes, slots, the loose middle of a ring cut), TEXT the letters, ETCH letters to be marked
  and not cut, BEND_UP and BEND_DOWN the bend centre lines, dashed. Colours and linetypes are
  in the guide. Inner contours are written before the outline, so a program that follows the
  file's order cuts inside-out. A piece inside another piece's hole is a loose piece, not an
  outline.
- Letters: a cut whose sketch holds Sketch Text marks the cut-outs it makes as the sheet's
  letters, counters included (SheetBody::labels, derived from the timeline like the pockets;
  no stored field, the format stays 21). A letter another cut-out overlaps or the sheet's edge
  clips is one shape with it and stays on CUT. `text: cut|etch` chooses TEXT (contours cut
  through) or ETCH (single contours, the material stays); text machined to a depth is always
  ETCH.
- Bend notes beside each bend line, off unless `bend_notes: true`: `B1 UP 90° R2.5` (number,
  direction, angle, inner radius), `note_height` mm high (3), on BEND_NOTES, parallel to the
  line and readable from below or from the right.
- `per_body: true` writes one file for each sheet body (`<path>-<body>.dxf`), or returns their
  DXF texts without a path; before, the export took one body and said nothing of the others.
- A `text`, `bend_notes`, `note_height` or `per_body` it cannot use is refused.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The export's parameter list keeps the new layers and names main's pocket layers
(POCKET_<BOTTOM|TOP|INTERNAL>_Z<from>_TO_<to>_MM).
@bherbruck
bherbruck merged commit d7a4a29 into tangency-labs:main Oct 15, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sheet metal: the flat-pattern DXF puts every contour on one layer, draws the bend lines continuous and writes one body only

2 participants