Repository navigation
feat(dxf): write the symbol tables from the decoded records (#126) - #347
Conversation
…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.
… 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.
…coded records (#126) src/dxf_tables.rs writes each TABLE block under its control object's handle and every record under its own, owned by the table, in the group order of AutoCAD's exports. The header now names a layer, text style or linetype whenever a written table defines it, which brings the header's agreeing variables from 9,224 to 9,350. examples/probe_dxf_tables.rs pairs every record written with the export's record of the same handle (a record the export registered again under another handle pairs by name): 789 records, 3,183 groups, every one equal, none extra. What is omitted has a reason the probe checks: handle-stream groups the decoder does not read (linetype, plot style, material, visual style, extension dictionary), a true colour's 420 and 62, extended data, and a linetype with a shape or text dash. The Corpus job runs it. ACAD_SPLINE_DATA is not written because AutoCAD's export omits it on every drawing that holds it. Targets before R2000 keep the default layer.
… handle groups (#126) VPORT now surfaces what its decoders read and dropped (circle zoom, fast zoom, UCS icon, snap and grid switches, the viewport's UCS, and from R2007 the lighting and grid block) and BLOCK_RECORD the insert count, preview bitmap and R2007 insert units, explodability and scaling. dwg-to-dxf writes both tables, an empty UCS table when the drawing has no UCS record, and from each record's handle stream (the new tables::handles) the reactors, extension dictionary, layout handle, and a layer's linetype, plot style, material and visual style. A handle group is written only when OBJECTS defines the object it names. The header names a block when the BLOCK_RECORD table defines it. The probe pairs 1101 records of the 42 corpus drawings with AutoCAD's export: 6992 groups agree, 5 are relations it names (a later save's active view, a dynamic block AutoCAD loads as *U17), none disagree and every omission has a stated reason.
…the record (#126) tables::dimstyle::decode_with_vars returns all the variables an R2000 to R2018 DIMSTYLE stores, by AutoCAD's name and in stored order, where DimStyleEntry kept 15 of them. dwg-to-dxf writes a group only when the value differs from the imperial default AutoCAD leaves out (measured on the 108 DIMSTYLE records of the corpus), the text style, blocks and linetypes by handle, the table header's 71 and 340 list from the control object, and the header's $DIMSTYLE now names a style the table defines. The probe pairs 108 records with AutoCAD's export: 1433 groups agree, 4 are a true-colour fill colour whose index the DWG does not store, none disagree. The whole tables probe over the 42 drawings: 1209 records, 8425 groups agree, 9 named relations, 0 disagree, 0 extra.
# Conflicts: # .github/workflows/ci.yml # ARCHITECTURE.md # Cargo.toml # examples/probe_dxf_header.rs # src/dxf_convert.rs # src/dxf_header.rs # src/dxf_sections.rs
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d6a8f1548b
ℹ️ 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".
# Conflicts: # ARCHITECTURE.md
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b57a87df4
ℹ️ 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".
…on a visible layer (#126) Table text is written through the header's release-aware escaping: before R2007 what is not ASCII is a \U+XXXX escape and a control character caret notation, so a layer name in TABLES reads the way $CLAYER names it. The converter's entities, which carry no layer of their own yet, go on layer 0 when it is neither frozen nor off, else on the first layer that is, so the decoded layer table cannot hide them.
# Conflicts: # ARCHITECTURE.md
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 77813eb325
ℹ️ 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".
…ite and to untyped objects (#126) The header's $DIMBLK family and a DIMSTYLE's 341 to 344 name an arrowhead block only when BLOCKS writes it, which is the two empty blocks it writes today (dxf_tables::BLOCKS_EXPORTED): lift that when BLOCKS writes block contents. A handle group names an object only when OBJECTS writes it under its own type: a layout, material or visual style is written as an untyped record, so a block's 340 to a layout, a layer's 347 and 348 and a viewport's 348 are left out until those objects are written as what they are. The tables probe is unchanged in what it proves (1,209 records, 0 disagree, 0 extra) and lists each left-out group with its reason; the header probe omits 269 names where it omitted 263.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e0437f7982
ℹ️ 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".
…release that stores them (#126) R13 and R14 layers carry neither, and the decoder leaves them clear: that read as a layer that does not plot (290 = 0) and as lineweight 0 (370 = 0) in an R14 to R2000+ DXF. They are written from the source release R2000 on, as before.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 83890acc21
ℹ️ 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".
# Conflicts: # ARCHITECTURE.md
#126) visible_layer skips a layer with group 290 of 0 (an omitted 290 is the plottable default), so a non-plotting layer 0 or a non-plotting first visible layer such as Defpoints does not take the converter's entities out of a plot.
Summary
dwg-to-dxfnow writes the VPORT, LTYPE, LAYER, STYLE, UCS, APPID, DIMSTYLE and BLOCK_RECORD tables from the decoded symbol-table records, each record under its own handle and owner, with the groups of AutoCAD's own export, and a probe pairs every record written with the export's record of the same handle and compares it group by group. Follow-on to #320 (#126); one PR per section, so VIEW (waiting on #284's view-mode fix) and the other sections follow.The header names a layer, text style, linetype, dimension style or block only when a written table defines it, so
$DIMSTYLEand$DIMBLKare now written where #320 had to omit them. A record the export itself creates while saving (a handle at or above the DWG's$HANDSEED) is not in the DWG and not written. UCS is the one exception to "paired with the export": no drawing of the corpus holds a UCS record, so it is written as AutoCAD's empty table when the drawing has none and left out when it has (#285: the decoder has never read a real record and skips a secondBSthat §20.4.62 lists).Spec reference
ODA v5.4.1 §20.4.52 (BLOCK_HEADER), §20.4.54 (LAYER), §20.4.56 (STYLE), §20.4.58 (LTYPE), §20.4.64 (VPORT), §20.4.68 (DIMSTYLE), and each section's "Handle refs" list; the group codes, the order and the values AutoCAD omits are measured on the 42 AutoCAD DXF exports (R2000 to R2018) of the public corpus.
ARCHITECTURE.md§7ac has the tables and the findings.src/dxf_tables.rs: the builders and the writer.DIM_GROUPSis the DIMSTYLE group table with the imperial default AutoCAD leaves out of each (measured by pairing every decoded variable with the export's record); a block's name is the one itsBLOCKentity gives; a handle group is written only when the OBJECTS section defines the object it names.src/tables/handles.rs(new): the handle stream of a table entry: the control object, the reactors, the extension dictionary, and the entry's own handles by position. Measured layouts: LAYER 3, 4 and 5 handles by release (R2000, R2007, R2013), VPORT 3 and 6, DIMSTYLE 6 and 9, BLOCK_RECORD from §20.4.52's list; a list whose length is not the one that order gives is not read.src/tables/vport.rs,block_record.rs,dimstyle.rs: what the decoders read and dropped is now surfaced (VPORT's snap and grid switches, its UCS and R2007 lighting block; BLOCK_RECORD's insert count, preview and R2007 units;dimstyle::decode_with_varsreturns every dimension variable of the record). The structs gain fields; the fields they had are unchanged.src/common_entity.rs:CommonObjectDatakeeps theXDic Missing Flagit read and dropped.Test plan
cargo fmt --all -- --check,cargo clippy --all-targets --all-features -- -D warnings,RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-featurescargo run --release --features dxf-reader --example probe_dxf_tables -- <dwg-corpus>over the 42 drawings that have an AutoCAD export (AC1014 and the two drawings without a twin are skipped and listed), wired into the Corpus job:Relation is a difference the way the export was made explains: the active viewport of
geoloc.dwg, whose export is a later save (its$TDUUPDATEis 1.94 days later) with another view height and centre; the dynamic block of the R2000, R2004 and R2007 saves, which AutoCAD loads as*U17; and the fill colour of four DIMSTYLE records, a true colour whose index the DWG does not store. Groups omitted have a stated reason the probe checks: extended data, a true colour's index, a layer colour name, the entities that react to a record or insert a block (ENTITIES carries no handles yet), the object a handle names where OBJECTS does not write it, and a linetype with a shape or text dash (24 records, written by none). One without a reason fails the probe.probe_dxf_header(feat(dxf): write the decoded header into dwg-to-dxf's HEADER section (#126) #320) over the same drawings: 9,571 written, 9,398 agree, 173 relation, 0 disagree, 0 extra, omitted 311 to 263 ($DIMSTYLEand the$DIMBLKfamily are written now);probe_header_varsunchanged.cargo test --release --all-featurespasses.Existing tests and code changed
None of the existing tests changed.
CommonObjectData,VportEntryandBlockRecordgain fields (nothing in the crate builds them but the decoders);dimstyle::read_cmc_inlinenow returns the colour it read, where it returned its index.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:
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.