Skip to content

feat(dxf): write the ENTITIES section of 15 kinds, paired with AutoCAD's export (#126) - #358

Merged
DrunkOnJava merged 25 commits into
mainfrom
feat/dxf-entities
Oct 27, 2026
Merged

DrunkOnJava merged 25 commits into
mainfrom
feat/dxf-entities

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

dwg-to-dxf now writes the ENTITIES section: the model space and paper space entities of 15 kinds whose decoders close on the corpus, each with AutoCAD's group codes in AutoCAD's order, and a new probe (probe_dxf_entities, wired into the Corpus job) pairs every written entity with the one in AutoCAD's own export and compares it group for group. Follow-on to #347 and #357 (#126), one PR per section.

Kinds written: LINE, POINT, CIRCLE, ARC, ELLIPSE, SOLID, RAY, XLINE, 3DFACE, TEXT, LWPOLYLINE, MTEXT (before R2018: no background fill, columns or embedded-object form yet), POLYLINE (2D, 3D and polyface) with VERTEX and SEQEND. An INSERT, with its ATTRIBs and SEQEND, is written by the code but skipped (and counted) until the block it names is a written definition: BLOCKS writes only the two space blocks today, so no output holds an INSERT of a block it lacks, and the BLOCKS PR lifts the gate and measures them. A decoded entity of any other kind is not written, and the probe counts them by kind. Children are written after their parent in the order its handle stream names them, SEQEND last.

What the writer needed from the decoders:

  • The common entity data kept what it consumed and dropped: the colour word, true colour and transparency, linetype scale and flags, Nolinks, the visual style flags (CommonEntityData).
  • src/entity_refs.rs: the handles an entity's handle stream holds (layer, linetype, material, plot style, shadow and colour book handles) resolved against the tables.
  • TABLES writes a complex linetype (text and shape dashes, the X 9 text area, LtypeEntry::text_area), which the header probe had listed as an omission.

Spec reference

ODA v5.4.1 §20.4.1 common entity data and common entity handle data, §2.11 CMC colour, and the entity sections §20.4.2 to §20.4.50 and §20.4.60 for the 15 kinds above. Group codes and order are AutoCAD's, read from its exports of the corpus (the AcDbEntity run is 67, 8, 6, 347, 62, 420, 430, 440, 48, 60, 370).

  • src/dxf_entities.rs: the writer, one function per kind.
  • src/dxf_convert.rs: convert builds the tables, then the entities with the handles it knows.
  • src/common_entity.rs: the kept fields, and one decoder fix below.

Test plan

  • cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings, RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features, all clean on this head (rebased on b9beccb).
  • Shown working on real files, no new unit tests: cargo run --release --features dxf-reader --example probe_dxf_entities -- <dwg-corpus> pairs every written entity with AutoCAD's export of the same drawing (42 drawings R2000 to R2018, 10 without a twin of the release skipped): 732 entities written, 732 paired, 5,099 groups, 5,099 agree, 0 disagree, 0 extra, and each entity's groups in AutoCAD's order. The probe expects every export record of a kind dxf_entities::kinds(release) lists to be written, whatever the output holds. Exit 0.
kind            written  paired  groups  agree  disagree  extra  om.grp not written
3DFACE                6       6      78     78         0      0       0          0
ARC                  11      11      77     77         0      0       0          0
CIRCLE               53      53     271    271         0      0      38          0
ELLIPSE              11      11     143    143         0      0       0          0
LINE                161     161    1377   1377         0      0       6          0
LWPOLYLINE          131     131     810    810         0      0      42          0
MTEXT                25      25     295    295         0      0      89          5
POINT                46      46     243    243         0      0       4          0
POLYLINE             12      12      84     84         0      0       0          0
RAY                   6       6      42     42         0      0       0          0
SEQEND               12      12      12     12         0      0       0         12
SOLID                 6       6      83     83         0      0       0          0
TEXT                174     174    1140   1140         0      0     396          0
VERTEX               72      72     402    402         0      0       0          0
XLINE                 6       6      42     42         0      0       0          0

Kinds the writer does not write yet, counted as entities in AutoCAD's exports of the corpus that the converter did not write (the "not written" column; the 5 MTEXT and 1 of the ATTRIB are R2018 embedded-object forms): INSERT 36, ATTRIB 24 and 12 SEQENDs of INSERTs (these three wait for BLOCKS), DIMENSION 66, MULTILEADER 90, HATCH 48, MLINE 18, TOLERANCE 18, 3DSOLID 12, ACAD_TABLE 12, MESH 12, SPLINE 12, VIEWPORT 12, IMAGE 6, LEADER 6, PDFUNDERLAY 6, REGION 6, SHAPE 6, WIPEOUT 6.

Every omitted group carries a stated reason in the probe's output, and none is a disagreement: extended data on entities (not decoded, 1000 to 1071), the ACAD_REACTORS bracket (the reacting entities are not all written with their handles), group 347 (the material object is still written as an untyped record), groups 420 and 430 for a colour book colour (its RGB and name are in an AcDbColor object), and an extension dictionary the export made itself (its handle is at or above the DWG's $HANDSEED).

  • The other probes on this head, still exit 0: tables (1,239 records including the 6 VIEWs of feat(dxf): write the VIEW table, with its associated UCS (#126) #357, 0 disagree, 0 extra; 9 named relations unchanged), header (9,577 written, 9,404 agree, 173 relation, 0 disagree, 0 extra), header variables.
  • python3 tools/maintainer/train/arch.py check and python3 tools/ci/spec_coverage.py --check: 0 problems.
  • cargo test --release --all-features runs in CI; I did not run it locally on this head (every cargo job on this Mac waits on a governor lease).
  • Not measured on the corpus: R13 and R14 entities (the probe skips AC1014 drawings, which have no AutoCAD export of the release); MTEXT on R2018; a polyline whose vertex handle is newer than its SEQEND (none in the corpus; the order follows the parent's handle list by construction); MTEXT with non-ASCII text on R2000 or R2004; a justified TEXT whose DWG omits the alignment point (written as the insertion point by §20.4.3's default, not counted separately).

Existing tests and code changed

  • src/common_entity.rs: the entity colour's two optional words were read in the wrong order. §2.11 puts the RGB word first and the transparency after; the decoder read the transparency first. The twin of a LINE writes 420 8404418 and 440 16777216 where the stream reads 0xC2802142 then 0x01000000, which fixes the order. The words were read and dropped, so no decoded count moves.
  • src/tables/ltype.rs: LtypeEntry gains text_area.
  • src/graph.rs: one existing unit test builds an LtypeEntry by field, so it gains text_area: Vec::new() to compile. Nothing it asserts changed.
  • src/entity_refs.rs: EntityRefs gains links (the R13 to R2000 previous and next entity handles, which order a polyline's vertices before R2004).
  • examples/probe_dxf_header.rs: the omission reason for $CELTYPE, $DIMLTYPE and $DIMLTEX1/2 naming a complex linetype is gone, since TABLES writes one now (the probe pairs them).
  • examples/probe_dxf_tables.rs: the group order check, and group_reason no longer takes a document it does not read.

No other test changed.

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 and §2.11.
  • 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-27T06:43:09.827459Z d87469e 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: 8fa266851f

ℹ️ 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_entities.rs Resolved
Comment thread examples/probe_dxf_entities.rs Resolved
Comment thread src/dxf_entities.rs Resolved
Comment thread src/dxf_entities.rs Resolved
@DrunkOnJava DrunkOnJava changed the title feat(dxf): write the ENTITIES section of 17 kinds, paired with AutoCAD's export (#126) feat(dxf): write the ENTITIES section of 15 kinds, paired with AutoCAD's export (#126) Oct 27, 2026

@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: 6084acfc28

ℹ️ 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_entities.rs Resolved

@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: 805622abb1

ℹ️ 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

@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: 8992aeaf32

ℹ️ 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 examples/probe_dxf_entities.rs Resolved

@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: b198c12e1e

ℹ️ 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_tables.rs Resolved
Comment thread examples/probe_dxf_entities.rs Resolved
Comment thread src/dxf_entities.rs Resolved
DrunkOnJava added a commit that referenced this pull request Oct 27, 2026
Codex's review of #358 linked LibreDWG source as evidence for a finding,
which CLEANROOM.md bans the project from consulting. Codex follows the
Review guidelines of a committed AGENTS.md, so this one points every agent
to CLAUDE.md and tells the reviewer to ground findings in the spec, the
public DXF Reference, the pinned AutoCAD output or this repository, never
in a banned implementation, and not to ask for unit tests.
@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) October 27, 2026 06:03

@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: 98a57db66a

ℹ️ 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_tables.rs Resolved
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