diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a499212..e7263140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -186,6 +186,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. - A graphic style (`GStyleElem`) no longer gets a name from bytes that only look like one, from a string stored near its id or from a linked type, and no `FamilyName` through such a link. The class stores no name and has no type, so its `FamilyName` is now `null`, and so is its `Name` unless the element name table of the file holds one. String built-in diff --git a/src/RvtIO/Parsing/R22Transcoder.cs b/src/RvtIO/Parsing/R22Transcoder.cs index b86e5e9b..aecf0874 100644 --- a/src/RvtIO/Parsing/R22Transcoder.cs +++ b/src/RvtIO/Parsing/R22Transcoder.cs @@ -636,7 +636,7 @@ private sealed class Context(byte[] data, int pos, int end) c.Cutting = true; ReadObject(c, tag); c.Cutting = false; - c.Edits.RemoveAll(e => e.Start > start || (e.Start == start && (_forReader || e.End > start))); + c.Edits.RemoveAll(e => e.Start > start || (e.Start == start && e.End > 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); c.Slot = -1; diff --git a/tests/RvtIO.Tests/R22TranscoderTests.cs b/tests/RvtIO.Tests/R22TranscoderTests.cs index f165415f..75e39c76 100644 --- a/tests/RvtIO.Tests/R22TranscoderTests.cs +++ b/tests/RvtIO.Tests/R22TranscoderTests.cs @@ -123,6 +123,39 @@ 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 + [Theory] + [InlineData(false)] + [InlineData(true)] + public void Payload_KeepsTheFieldsAddedAtTheEndOfAnObjectBeforeOneItCuts(bool forReader) + { + 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, forReader: forReader).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() {