Skip to content

feat(dxf): write the BLOCKS section, paired with AutoCAD's export (#126) - #371

Merged
DrunkOnJava merged 13 commits into
mainfrom
feat/dxf-blocks
Oct 27, 2026
Merged

DrunkOnJava merged 13 commits into
mainfrom
feat/dxf-blocks

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

dwg-to-dxf now writes the BLOCKS section: one block per BLOCK_RECORD, in the table's order, each with its BLOCK, the entities the ENTITIES writer collects for it and its ENDBLK, and probe_dxf_entities --section=BLOCKS (wired into the Corpus job) pairs every record with AutoCAD's own export. Follow-on to #358 (#126), one PR per section. It lifts the gate #358 put on INSERT, so the INSERTs, ATTRIBs and ATTDEFs that wait for a written block definition are written now. An INSERT is written only when the block it names is: block_markers decides the blocks written before any entity is accepted, and an INSERT of a block that cannot be written (its layer or linetype is not in the tables, a base point that is not finite) is counted INSERT (its block is not written) with its ATTRIBs, so no output names a block it lacks. The BLOCKS write groups the entity records by block once instead of rescanning them for every block.

The tables are built a second time knowing which entities and blocks are written, so the header's $DIMBLK family, a DIMSTYLE's arrowhead blocks and a BLOCK_RECORD's {BLKREFS name only what is in the output (the BLOCKS_EXPORTED constant #347 added for that is gone).

Spec reference

ODA v5.4.1 §20.4.6 BLOCK and §20.4.7 ENDBLK, §20.4.5 ATTDEF, §20.4.52 BLOCK HEADER for the record each block hangs from, and the entity sections of #358 for the contents.

  • src/dxf_blocks.rs: the writer; src/dxf_entities.rs: block_markers (the BLOCK and ENDBLK of each record, with AcDbBlockBegin and AcDbBlockEnd), ATTDEF, the children order, the INSERT gate lifted.
  • src/dxf_blocks.rs: the records grouped by owning block once (O(blocks + entities)); src/dxf_entities.rs: the INSERT gate on the set of blocks written.
  • src/dxf_convert.rs: tables built twice; src/dxf_tables.rs: defined takes the written blocks; src/dxf_header.rs: $DIMBLK resolves through them.

Test plan

  • cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings, RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
  • cargo test --release --all-features: 921 passed, 0 failed across 26 result lines, run on c982644, the head of this branch; this branch adds no unit test.
  • Shown working on real files, no new unit tests: cargo run --release --features dxf-reader --example probe_dxf_entities -- --section=BLOCKS <dwg-corpus> pairs every record of the section with the export's of the same handle (42 drawings R2000 to R2018, 10 without a twin of the release skipped): 1,532 written, 1,503 paired, 12,583 groups, 12,577 agree, 0 disagree, 0 extra, in AutoCAD's order. Exit 0.
kind            written  paired  groups  agree  disagree  extra  om.grp not written
ARC                  12      12     118    118         0      0       0          0
ATTDEF               29      29     324    324         0      0      20          1
BLOCK               270     264    2274   2268         0      0       0          0
CIRCLE               30      30     150    150         0      0      72          0
ENDBLK              270     264     420    420         0      0       0          0
INSERT               48      36     378    378         0      0      24          0
LINE                432     432    4472   4472         0      0       0          0
LWPOLYLINE           12      12      90     90         0      0       0          0
MTEXT               147     142    1990   1990         0      0     122         38
POINT               204     204    1190   1190         0      0       0          0
SOLID                78      78    1177   1177         0      0       0          0

The 29 records that do not pair are the BLOCK, ENDBLK and entities of one block per drawing that the export registers again under new handles (*U25 of the ACadSharp saves; the tables probe pairs the record by name), counted with their reason. The six groups that do not agree are a relation the probe names: a dynamic block of R2000 to R2007 is my-dynamic-block in the DWG and *U17 in the export. Not written yet, counted by kind: 24 VIEWPORTs, one multi-line ATTDEF (R2018) and 38 MTEXTs with a background fill or an embedded object. The ENTITIES probe with the INSERTs and ATTRIBs back: 803 entities, 5,627 groups, 0 disagree; tables: 1,239 records, 0 disagree, 0 extra.

  • No INSERT names a block the output lacks, measured two ways: --section=BLOCKS converts every drawing to every release the writer writes it to and checks each INSERT's group 2 against the BLOCKs of the same output (510 INSERTs in 264 conversions, 0 unresolved), and, since no corpus drawing has a block the writer must leave out, builds each drawing's entities once per layer with that layer out of the tables (160 builds, 283 blocks left out, 85 INSERTs counted INSERT (its block is not written), 0 of the 1,580 written unresolved). With the gate temporarily disabled the second run exits 1 (18 of 1,598 INSERTs name a block not written). Negative run of the first check, PROBE_DXF_ENTITIES_DROP_BLOCK=1: 72 unresolved, exit 1. Either check that measures nothing prints NOT MEASURED: at line start, which the Corpus step fails on.
  • A block left out takes its entities with it, and the tables are told only what is written: the per-layer builds read the BLOCKS and ENTITIES writers back and compare (39,429 handles told to the tables, 0 not in the output; with the entity filter taken out 589 of 40,018 are not and the probe exits 1), and every BLKREFS handle is a written record (366 handles in 264 conversions plus 1,124 in the per-layer tables, 0 not written). The dangling BLKREFS entry itself is not observed in the corpus even without the filter, so that symptom is covered by the check, not measured. Table sort: a handle-to-index map per table instead of a linear position search per key (synthetic 50,000 records: 120.8 s before, 11 ms after, measured on the sort-key expression in isolation).
  • BLOCKS write time: 255 us before, 263 us after on the largest corpus drawing (27 blocks, 265 records; noise); a synthetic 5,000 blocks x 20 records: 2,559,896 us before, 32,336 us after.
  • python3 tools/maintainer/train/arch.py check and python3 tools/ci/spec_coverage.py --check: 0 problems.
  • Not measured on the corpus: R13 and R14 blocks (the probes skip AC1014 drawings); a block left out for a non-finite base point or an unresolved linetype (the removed-layer run stands for the family).

Existing tests and code changed

None of the existing tests changed. dxf_tables::BLOCKS_EXPORTED is removed and defined takes the written blocks.

Source-provenance declaration

By submitting this PR I certify that my contribution does not incorporate executable code from any source whose license is incompatible with Apache-2.0. Specifically:

  • No Autodesk DWG SDK source (RealDWG, ObjectARX, ObjectDBX) or NDA-protected Autodesk documentation was consulted or imported.
  • No Open Design Alliance Teigha / Drawings SDK source was consulted or imported. The ODA's public Open Design Specification for .dwg files PDF (v5.4.1) is the source for §20.4.5, §20.4.6, §20.4.7 and §20.4.52.
  • No GPL-licensed DWG implementation source (LibreDWG, etc.) was consulted or imported.

The only other inputs are the public corpus and AutoCAD's own DXF exports of its drawings. No algorithm-description comments in other projects were read.

Developer Certificate of Origin

I affirm the contribution is my own work and may be distributed under the project's Apache-2.0 license.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T14:10:05.397701Z 96e332a New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 27, 2026 09:06

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 33bcaad69c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/dxf_convert.rs Resolved
Comment thread src/dxf_blocks.rs Resolved
@DrunkOnJava
DrunkOnJava disabled auto-merge October 27, 2026 09:07

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 273c820aaf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/dxf_entities.rs Resolved
Comment thread src/dxf_tables.rs Resolved
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 27, 2026 14:15
@DrunkOnJava
DrunkOnJava merged commit 2bab7b2 into main Oct 27, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/dxf-blocks branch October 27, 2026 14:18
DrunkOnJava added a commit that referenced this pull request Oct 28, 2026
…10-27 (#416)

* docs: bring README, ROADMAP and CHANGELOG up to the landings of 2026-10-27

README's code-page and DXF writer text named work in review that has landed
(#371, #380, #382, #384); jev_review.py prose ranked those sentences 0.72 to
0.96. ROADMAP's "where it stands" table was a 2026-10-21 snapshot whose
numbers, CI row and release row were all out of date; it now points to the
rendered numbers instead of repeating them. CHANGELOG gains #371, #380, #382,
#384, #385 and #404.

* docs(changelog): record the CI-only merge train (#408)

* docs: OBJECTS landed (#372): README, ROADMAP and CHANGELOG

* docs: LAYOUT, GROUP and MLINESTYLE (#373), the class map writer (#405) and the double-byte round trip (#414) landed

* docs: VISUALSTYLE landed (#413)

* docs(readme): name the skipped types still in review without per-type counts; MATERIAL landed (#325)

* docs(readme): point to the open decoder PRs instead of a list that each landing makes stale
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.

1 participant