Skip to content

Preserve orphan and nested FIELD objects in DXF output - #1351

Open
jogibear9988 wants to merge 1 commit into
DomCR:masterfrom
jogibear9988:codex/fix-dxf-field-serialization
Open

jogibear9988 wants to merge 1 commit into
DomCR:masterfrom
jogibear9988:codex/fix-dxf-field-serialization

Conversation

@jogibear9988

Copy link
Copy Markdown

Description

A FIELD referenced only by a FIELDLIST can reach the DXF writer without an owner or registered handle. This can throw while writing the owner reference and leaves HANDSEED/the class table inconsistent with objects discovered later. Nested FIELD children are also referenced with group 360 but never queued for the OBJECTS section, so their records can be omitted.

Prepare the reachable FIELD graphs before writing the header and class table: preserve existing child/dictionary owners, assign a list owner only to otherwise orphan fields, register parent graphs before their children, and refresh DXF classes when registration adds fields. Queue nested children during output and reuse the existing handle deduplication so fields shared through multiple references are emitted once.

Tasks done in this PR

  • Allocate orphan FIELD graph handles before HANDSEED and class-table serialization.
  • Serialize nested FIELD records while retaining hard-child ownership and existing dictionary ownership.
  • Add six regressions for dictionary/list roots, child-first order, high preassigned handles, shared references, extension dictionaries and stable repeated writes.

Related Issues / Pull Requests

Extracted from #1316, source commit fe5d20d1, based on acad-ts 5bf4c0ee and 60b92017. This PR contains one implementation commit on current master (90c6f871) and has no dependency on the modeler or other changes in #1316. The aggregate PR remains unchanged.

Notes for reviewer

Minimal reproduction:

var document = new CadDocument();
var list = new FieldList { Name = "PORT_FIELDS" };
document.RootDictionary.Add(list);
var parent = new Field { FormatString = string.Empty };
parent.Children.Add(new Field { FormatString = string.Empty });
list.Fields.Add(parent);
DxfWriter.Write("fields.dxf", document);

After the fix, both FIELD records are emitted with valid ownership/child references, and their handles are below the written HANDSEED. The tests inspect the actual DXF records, reject duplicate FIELD handles, check registration in the document, and confirm a second write keeps the same handle seed.

Validation on this isolated branch:

  • dotnet test src/ACadSharp.Tests/ACadSharp.Tests.csproj -f net9.0 --filter FullyQualifiedName~FieldWriterRegressionTests: 6 passed.
  • Full .NET 9 suite: 2,504 passed, 2 skipped, 3 failed. The failures are the previously observed ArcTests.CreateFromBulgeTest, ArcTests.GetCenter, and the culture/scientific-format case in DimensionStyleTests.GetLinearMeasurementText.
  • Library builds for net8.0, net9.0, net10.0, net48, netstandard2.0 and netstandard2.1.
  • git diff --check passes.

AI-assisted port and extraction, with source comparison, isolated regression testing and review of the resulting diff.

Port acad-ts 5bf4c0ee and 60b92017. FIELDLIST references can contain orphan
fields whose handles and owners have not been assigned. Register their
parent graphs before HANDSEED and the DXF class table, preserve existing
child/dictionary ownership, and enqueue nested FIELD records for output.
Retain C# observable child collections and existing handle deduplication.

Six regressions cover list/dictionary roots, nested references, child-first
order, high handles, extension dictionaries and stable repeated writes.

This branch has not been deployed

No deployments
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