Repository navigation
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
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
Closes #1284.
Problem.
sheet.export_dxfis 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 onOUTLINE(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 aPOCKET_…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
LTYPEtable hasDASHED):OUTLINECUTTEXTETCHBEND_UP,BEND_DOWNDASHEDBEND_NOTESPOCKET_…,PERFORATIONInner 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.
SheetBody::labels: flat regions, derived from the timeline likepockets, 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 onCUT.text: "cut"(default) writes the letters cut through the sheet as contours onTEXT;"etch"writes them as single contours onETCH, the sheet keeps its material.bend_notes: truewrites aTEXTentity onBEND_NOTESbeside each bend line:B1 UP 90° R1(number, direction, angle, inner radius),note_heightmm 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.per_body: truewrites<path>-<body>.dxffor each sheet body (a character a file name cannot hold becomes_, two bodies that would share a file get_2,_3…) and lists them underfiles; without a path it returns their texts. It is refused together withbody; every file is made before the first is written.text,bend_notes,note_heightorper_bodyvalue the export cannot use is refused.The writer (
crates/io/src/dxf_out.rs, first commit) learns what this needs: a layer's linetype, theSTYLEtable and a centredTEXTentity (%%dis 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,
etchfor 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:OUTLINEis the outer contour alone (one entity for each of its segments, lines and arcs),CUTthe Ø5 hole as oneCIRCLEand the slot's four lines,TEXTthe letters and counters; the last inner contour comes before the first outline entity; the layer table is exactly0,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 onETCHwith the same entities, nothing left onTEXT; text engraved 0.5 deep is onETCHfor bothtextvalues, and a rectangular pocket keeps itsPOCKET_…layer.a_bend_note_sits_beside_each_bend_line_when_asked_for: none unless asked for; then one note per bend (4), eachB<n> UP|DOWN 90%%d R1for the bend's own number and direction, centred (72 = 1), 3 mm high (5 withnote_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:fileslistsLidandSide Wallwith 0 and 1 bends; each text equals the export of that body alone; written to a path they arepanel-Lid.dxfandpanel-Side Wall.dxfwith 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_dxffinds 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.flat_dxf_preserves_exact_cutout_entities(its twoflat_dxfcalls take&DxfOptions::default()), the helper insheet_tests.rsthat picks the lines of the outline and its holes out of a DXF (it readsOUTLINEandCUT), andbend_lines_and_layers_are_still_there(the cut-out is onCUT).Against
main's export (new io writer, old engine code) the six of these engine tests that call only the command, with the adaptedbend_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 onmain.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)OUTLINELINE, 35SPLINE, 2CIRCLE)LINE: the outer contourCUTCIRCLE, 4LINETEXTLINE, 35SPLINE("AB-12")ETCHPOCKET_BOTTOM_Z0.000000_TO_0.500000_MM: 49LINE, 29SPLINE("R-07")text: "etch"ETCH62LINE, 64SPLINE; nothing onTEXTBEND_UP,BEND_DOWNLINE,ContinuousLINE,DASHEDbend_notes: trueTEXTonBEND_NOTES:B1 UP 90%%d R1,B2 UP …,B3 UP …,B4 DOWN …OUTLINEentities, then the bend linesper_body: truepanel.dxf, with the side wall (8OUTLINE, 1BEND_UP); the lid is missingpanel-Lid.dxf(4OUTLINE) andpanel-Side Wall.dxf(8OUTLINE, 1BEND_UP)Read by OpenSCAD 2021.01, layer by layer (
import("x.dxf", layer="OUTLINE"), then"CUT"): onmaintheOUTLINElayer is 13 contours; hereOUTLINEis 1 contour (the outer outline) andCUTis 3 (the slot and the two holes). OpenSCAD does not implementSPLINEand warns of it where letters are (onmain'sOUTLINE, here on none of the layers asked for). Our reader (sketch.insert_dxfof 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 theDASHEDlinetype, theSTYLEtable and theTEXTentities as written is read from Autodesk's DXF reference, not observed.On the head
fcd4db98(ond73cd8a1):cargo fmt --all --checkclean;cargo clippy -p solidcraft-io -p solidcraft-engine -p solidcraft-doc -p solidcraft-ui-egui -p solidcraft-cli --all-targets --profile ci --locked -- -D warningsclean;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 ciran once on Windows for these two commits (fcd4db98, ond73cd8a1) merged with another independent change of mine, which will be posted as its own pull request (combined commit94efd5df, onbd8db8ea). 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':mainfails on this machine (41f0c3d0, the same night): the robustness goldensall_0toall_3andissue_851_tests::arc_top_edge_sizes_never_panicin 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, ascrash.rssays atread_live_journal; andrender_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_finishesfailed beside the other test binaries and passes alone (main does the same). These commits changecrates/io/src/dxf_out.rsandlib.rs,crates/doc/src/sheet.rsandeval_more.rs,crates/engine/src/cmd/sheet.rswith 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):
text: "etch"(the cut letters as single contours onETCH) andbend_notes: true: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:
Integration status
Two commits on
maind73cd8a1; it merges cleanly with today'smain(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 tocrates/engine/src/cmd/sheet_tests.rs) and #1312 (a new type incrates/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