Skip to content

feat(dxf): write the decoded header into dwg-to-dxf's HEADER section (#126) - #320

Merged
DrunkOnJava merged 7 commits into
mainfrom
feat/dxf-header
Oct 26, 2026
Merged

DrunkOnJava merged 7 commits into
mainfrom
feat/dxf-header

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

dwg-to-dxf now writes the decoded AcDb:Header into the DXF HEADER section under the names and group codes AutoCAD's own export uses, and a probe reads its output back and compares every $VARIABLE with that export. Follow-on to #302 (#126).

A variable AutoCAD's export omits is omitted here too; nothing is written with a default. R12 and R14 targets keep $ACADVER alone: no AutoCAD export of either is in the corpus to measure the set against.

Spec reference

ODA v5.4.1 §9 (the variables), §22 ($MEASUREMENT), §3.2.5 and §4.1 (code page). The group codes and the first release of each variable are measured on the 50 AutoCAD DXF exports (AC1015 to AC1032) of the public corpus, which agree with each other; ARCHITECTURE.md §7r (the section #302 landed as 7n, renumbered here because three sections now carry 7n) has the table and the rules.

  • src/dxf_header.rs: the table ($NAME, group codes, first release) and the conversion. Handles DXF writes as names go through the decoded symbol-table records (an undecodable record still gives its name as the first string of its string stream); $CMLSTYLE takes its ACAD_MLINESTYLE dictionary key's case; a standard arrowhead block loses its underscore; a colour is its AutoCAD index (a true colour has none and is omitted); a null handle variable is omitted; $ANGBASE is converted from radians to degrees (DXF group 50); before R2007 non-ASCII text is written as \U+XXXX escapes; the underscore is dropped only from AutoCAD's standard arrowhead names; before R2010 $XCLIPFRAME is the flag 290 and 2 is written false. $MEASUREMENT is read from AcDb:Template, $DWGCODEPAGE from the file header (29 and 30 measured) and $LASTSAVEDBY from AcDb:SummaryInfo.
  • src/dxf_sections.rs: HeaderValue::Groups / HeaderGroup for explicit group codes; reals are written shortest round-trip with DXF's exponent form.
  • examples/probe_dxf_header.rs (dxf-reader feature), wired into the Corpus job.
  • Finding: from R2007 the AcDb:Template description length counts UTF-16 units (AutoCAD writes 1 and two bytes), where §22 counts bytes.

Test plan

  • cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings
  • Shown working on real files, no new unit tests: cargo run --release --features dxf-reader --example probe_dxf_header -- <dwg-corpus> over the 42 drawings that have an AutoCAD export (AC1014 and the two drawings without a twin are skipped and listed):
release        files  written  agree  relation  disagree  extra  omitted
AC1015 (2000)      8     1527   1494        33         0      0       65
AC1018 (2004)      8     1622   1589        33         0      0       66
AC1021 (2007)      8     1939   1907        32         0      0       69
AC1024 (2010)      8     1947   1914        33         0      0       69
AC1027 (2013)      8     1941   1908        33         0      0       83
AC1032 (2018)      2      483    474         9         0      0       23
TOTAL             42     9459   9286       173         0      0      375

Relation is the later-save rule for $TDUUPDATE, $TDINDWG, $TDUSRTIMER, $HANDSEED and $VERSIONGUID (the twin is saved after the DWG). Extra is a variable written that the export omits: none. Each of the 375 omissions has a stated reason the probe checks: local $TDCREATE and $TDUPDATE (the DWG holds universal time), $ACADMAINTVER (not derivable from the file header), a true-colour $CECOLOR, a null $INTERFEREOBJVS or $INTERFEREVPVS where AutoCAD names a default visual style, and a name for a symbol record the output does not define (the converter writes layer 0 and no other symbol table, so $TEXTSTYLE, $DIMSTYLE, $CELTYPE, $CMLSTYLE, a non-zero $CLAYER and the like are omitted until those tables are written, rather than left pointing at nothing). One without a reason fails the probe.

  • The real CLI: dwg-to-dxf line_2013.dwg out.dxf --version R2013 writes 248 $ variables.
  • probe_header_vars (from feat(sections): decode every AcDb:Header variable from one table (§9, #126) #302) unchanged: 52 of 52 close, 11,544 agree, 316 relation, 0 disagree. cargo test --all-features --test integration_dxf_roundtrip passes; the full cargo test --release --all-features (929 tests) passed on the branch before the rebase and before the Codex fixes. The $ANGBASE conversion (the corpus value is zero) and the \U+XXXX escape (all corpus header text is ASCII) are not measured on the corpus.

Existing tests and code changed

  • tests/integration_dxf_roundtrip.rs::output_is_valid_utf8_with_line_based_pairs told group-code lines from value lines by their shape (a short all-digit line is a code); $TREEDEPTH's value 3020 is such a line. It now reads the file as the code and value pairs it is. Assertion kept: every code is an integer in 0..=1071, and there are at least ten.
  • A pre-existing bug fixed in passing: src/bin/dwg_to_dxf.rs panicked at startup in debug builds (clap: the custom --version <R2018> argument clashes with clap's own version flag). disable_version_flag = true.

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 §9 and §22.
  • 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 26, 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-26T18:30:44.680277Z 7d1e0de 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.

@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: 3dd56b298c

ℹ️ 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_header.rs Resolved
Comment thread src/dxf_header.rs Resolved
Comment thread src/dxf_header.rs Resolved
…126)

src/dxf_header.rs turns the decoded AcDb:Header into the $VARIABLE groups
AutoCAD's own export writes for the same drawing, and nothing else: a variable
the export omits ($PELLIPSE, $FACETRES, the unknown slots, control-object
handles) is omitted, and so is one the DWG cannot give (local $TDCREATE and
$TDUPDATE, $ACADMAINTVER, a true colour, a null default visual style). Group
codes and the first release of each variable are measured on the 50 AutoCAD
exports of the corpus. Handles that DXF writes as names are resolved through
the decoded symbol-table records (an undecodable record still gives its name
as the first string of its string stream); $CMLSTYLE takes the dictionary key's
case and a standard arrowhead block loses its underscore. $MEASUREMENT is read
from AcDb:Template (§22), $DWGCODEPAGE from the file header and $LASTSAVEDBY
from AcDb:SummaryInfo. R12 and R14 targets keep $ACADVER alone: no AutoCAD
export of either exists to measure against.

examples/probe_dxf_header.rs converts every drawing that has an AutoCAD export,
reads dwg-to-dxf's output back with dxf_reader and compares every variable:
9,514 agree, 173 hold a stated relation (a later save), 0 disagree, 0 extra, and
each of the 147 omissions has a stated reason. The Corpus job runs it.

tests/integration_dxf_roundtrip.rs told group-code lines from value lines by
their shape, which a header value such as $TREEDEPTH's 3020 defeats; it now
reads the file as the code and value pairs it is.
…s angles, text and arrowheads as DXF reads them (#126)

The converter writes layer 0 and no other symbol table, so a header naming any
other layer, style, linetype, dimension style, mline style, UCS or block would
point at nothing: those names are omitted (an empty name is kept), and the probe
lists each as an omission with that reason. $ANGBASE is radians in the database
and degrees in DXF group 50, so groups 50 to 58 are converted. Before R2007,
whose DXF reads bytes in $DWGCODEPAGE, non-ASCII header text is written as
\U+XXXX escapes. The leading underscore is dropped only from AutoCAD's standard
arrowhead block names; any other block keeps its name.

@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: 9d23373272

ℹ️ 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_header.rs Resolved
Comment thread src/dxf_header.rs Resolved
… every value on one line (#126)

$CMATERIAL, $INTERFEREOBJVS and $INTERFEREVPVS name MATERIAL and VISUALSTYLE
objects, which the converter exports as untyped placeholders; the references
are omitted until it exports them as their types ($HANDSEED, the next free
handle, is still written). A control character in a header string, a line feed
above all, would have put the rest of the value on the next group-code line; it
is now written in DXF's caret notation, with the caret itself as a caret and a
space.
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 26, 2026 18:31
@DrunkOnJava
DrunkOnJava merged commit 0534313 into main Oct 26, 2026
25 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/dxf-header branch October 26, 2026 18:35
DrunkOnJava added a commit that referenced this pull request Oct 26, 2026
…R14 (#119)

#320 matched Version exhaustively; the AC1012 variant it was written
without made clippy --all-targets fail on the merged tree.
DrunkOnJava added a commit that referenced this pull request Oct 28, 2026
…d say what measured them (#140, #147, #148, #133, #127) (#398)

Seven rows leave partial for closes because no record of any kind errors on the
52 drawings of run 40532346172 and the errors their notes still quote were
fixed: TEXT, ATTRIB, ATTDEF (#258), MTEXT (#261), VIEW (#263, #284), DIMSTYLE
(#293) and HATCH (#264, the R14 records routed). §22 AcDb:Template goes from
missing to partial: dxf_header reads $MEASUREMENT from it (#320). §9 stays
closes, now tracked by #127 (R13) and carrying the per-release evidence behind
closing #128, #129 and #130. The page's Last measured line and the paragraph
that said closes came from a local 19-file corpus are updated.
DrunkOnJava added a commit that referenced this pull request Oct 28, 2026
…ain run (#195) (#401)

* docs(spec-coverage): move the rows the 2026-10-27 main run proves, and say what measured them (#140, #147, #148, #133, #127)

Seven rows leave partial for closes because no record of any kind errors on the
52 drawings of run 40532346172 and the errors their notes still quote were
fixed: TEXT, ATTRIB, ATTDEF (#258), MTEXT (#261), VIEW (#263, #284), DIMSTYLE
(#293) and HATCH (#264, the R14 records routed). §22 AcDb:Template goes from
missing to partial: dxf_header reads $MEASUREMENT from it (#320). §9 stays
closes, now tracked by #127 (R13) and carrying the per-release evidence behind
closing #128, #129 and #130. The page's Last measured line and the paragraph
that said closes came from a local 19-file corpus are updated.

* docs(criteria): re-measure the 1.0 requirements from the 2026-10-27 main run (#195)

Header, R2, R3, R4, R8, X1 and S3 now carry what run 40542129639 (main 61255e9)
and docs/data/spec-coverage.tsv say: 52 drawings with 0 errored records and 533
skipped, 53 sections scored by the DXF oracle with 22 values disagreeing, 90
closes, 13 partial, 6 decoder and 29 missing rows, a wasm32 compile of the
library in the Clippy job. X1 (DXF) moves from not measured to failed: the HEADER,
TABLES, ENTITIES and BLOCKS probes pair the written records with AutoCAD's export
and find 0 groups disagreeing, and 342 entity records of 18 kinds and the OBJECTS
section are not written. No other status changes.

* docs(criteria): R3 counts the rows #398 moves: 97 closes, 7 partial, 6 decoder, 28 missing (#195)

The counts are those of docs/data/spec-coverage.tsv with #398, whose moves run
40532346172 proves.
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