From ec4c581ade9db1cc31a39ce23cb565afdb76ea75 Mon Sep 17 00:00:00 2001 From: mie <79989386+mahach666@users.noreply.github.com> Date: Tue, 1 Dec 2026 13:23:27 +0300 Subject: [PATCH] Keep the inserted fields of an object when the next one is cut out The rewrite into the 2022 layout inserts the fields a 2022 class adds at the end of an object where the next object starts. When that next object had no 2022 class, every edit from its start on was removed before cutting it out, so those inserts were lost and the data after them moved. Reading a cut object adds no edits, so the removal is not needed. --- CHANGELOG.md | 3 +++ src/RvtIO/Parsing/R22Transcoder.cs | 4 ++-- tests/RvtIO.Tests/R22TranscoderTests.cs | 31 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06ff5095..60dcb8d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -125,6 +125,9 @@ API between minor releases. from. An element that placed that definition, or a later build from the block, could hold the same data twice, and which elements did could differ between two reads of one file. The IFC export uses this data for triangle-set bodies and for some base quantities. +- The rewrite of a Revit 2023 or later file into the 2022 layout keeps the fields it adds at the end of an object when + the object that follows has no Revit 2022 class and is cut out. Those fields were lost, which shifted the data after + them. ## [0.6.3] - 2026-11-20 diff --git a/src/RvtIO/Parsing/R22Transcoder.cs b/src/RvtIO/Parsing/R22Transcoder.cs index ea65d1e4..1031b9c3 100644 --- a/src/RvtIO/Parsing/R22Transcoder.cs +++ b/src/RvtIO/Parsing/R22Transcoder.cs @@ -299,12 +299,12 @@ private sealed class Context(byte[] data, int pos, int end) var (tag, dropped) = c.Queue[i]; if (dropped || !_tagMap.ContainsKey(tag)) { - // an object of a class the 2022 table does not know: read it with the source grammar and cut it out + // an object of a class the 2022 table does not know: read it with the source grammar and cut it out. + // Reading it adds no edits; an insert at its start adds the last fields of the object before it int start = c.Pos, mark = c.Queue.Count; c.Cutting = true; ReadObject(c, tag); c.Cutting = false; - c.Edits.RemoveAll(e => e.Start >= start); c.Edits.Add(new(start, c.Pos, [])); for (int j = mark; j < c.Queue.Count; j++) c.Queue[j] = (c.Queue[j].Tag, true); continue; diff --git a/tests/RvtIO.Tests/R22TranscoderTests.cs b/tests/RvtIO.Tests/R22TranscoderTests.cs index 69e957aa..7cbb46c9 100644 --- a/tests/RvtIO.Tests/R22TranscoderTests.cs +++ b/tests/RvtIO.Tests/R22TranscoderTests.cs @@ -82,6 +82,37 @@ public void Payload_RenumbersCutsInsertsAndLeavesOutUnknownObjects() Assert.True(walk.Exact, walk.Error); } + // the fields the 2022 class adds at the end of an object are inserted where the next object starts: cutting that one keeps them + [Fact] + public void Payload_KeepsTheFieldsAddedAtTheEndOfAnObjectBeforeOneItCuts() + { + var target = Target(); + target.Classes[target.Classes.FindIndex(c => c.Id == 10)] = new(10, "Store", 0, 1, [Field("m_value", 4), Field("m_later", 4)], []); + var block = Bytes(w => + { + w.Write((ushort)5); + Owned(w, 3); // m_pStore + w.Write(1u); Owned(w, 4); // m_items: an Extra + w.Write(77L); w.Write(5); // m_id, m_added + w.Write(0u); // m_name, empty + w.Write(42); // Store + w.Write(9); // Extra + }); + var expected = Bytes(w => + { + w.Write((ushort)11); + Owned(w, 10); + w.Write(0u); + w.Write(77); w.Write(0); // m_id, m_gone + w.Write(0u); + w.Write(42); w.Write(0); // Store: m_value, m_later + }); + var result = new R22Transcoder(Source(), target, 8).Payload(block, 0, block.Length); + Assert.Equal(expected, result); + var walk = new WideBlockWalker(target, (_, _) => null, []).Run(result!, 0, result!.Length, 11); + Assert.True(walk.Exact, walk.Error); + } + [Fact] public void Payload_WritesFieldsInTheOrderOfThe2022Class() {