diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aa4964..5960af2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ API between minor releases. - `ioviewer` reads Navisworks `.nwc` caches through `NwcIO.Scene` 0.13.0. - Standalone HTML opens with the section box or cutting planes saved in `ViewerDocument`. +### Fixed + +- Preserve all 64 bits of element IDs in HTML properties, Copy Id, clash results and 4D tasks. + ## [0.3.1] - 2026-11-13 ### Fixed diff --git a/docs/public-api.md b/docs/public-api.md index 898e98b..75539d9 100644 --- a/docs/public-api.md +++ b/docs/public-api.md @@ -38,6 +38,7 @@ The model data is the IOScene scene model, referenced by the `IOViewer` package. ### Exporters (`IOViewer.Exporters`) - `HtmlViewerExporter`: Generates self-contained, offline-ready 3D HTML viewers using packed Base64 binary buffers. Takes a `ViewerDocument` or a `SceneDocument`. The page is written to the output stream as it is produced. + Embedded element IDs and their clash and schedule references use decimal strings outside JavaScript's safe integer range. - `HtmlViewerOptions`: Title, which data to include (properties, viewpoints, grids, 4D schedule, clashes), the initial display mode (`InitialWireframe`, `InitialWhiteMode`), and `MaxMeshVertices`, which is unlimited by default; when a lower limit leaves meshes out, the viewer shows how many were written. - `JsonViewerExporter`: Writes a `ViewerDocument` as viewer JSON (`"Kind": "ioviewer"`, `"Format": 2`). A scene alone is written with IOScene's `SceneJson`. diff --git a/src/IOViewer/Exporters/ViewerPayloadWriter.cs b/src/IOViewer/Exporters/ViewerPayloadWriter.cs index e9eb08a..31fbc43 100644 --- a/src/IOViewer/Exporters/ViewerPayloadWriter.cs +++ b/src/IOViewer/Exporters/ViewerPayloadWriter.cs @@ -24,6 +24,7 @@ internal sealed class ViewerPayloadWriter { private const int FlushThreshold = 1 << 16; private const int MaxSectionPlanes = 6; // Matches the viewer's MAX_PLANES. + private const long MaxSafeElementId = (1L << 53) - 1; private static readonly RgbaColor DefaultColor = new(200, 200, 200); private readonly SceneDocument _scene; @@ -619,7 +620,8 @@ public void WriteMeta(Stream output) foreach (var el in _scene.Elements) { w.WriteStartObject(); - w.WriteNumber("id", el.Id); + w.WritePropertyName("id"); + WriteElementId(w, el.Id); w.WriteString("name", el.Name); w.WriteString("category", string.IsNullOrEmpty(el.Category) ? "General" : el.Category); w.WriteString("type", el.TypeName); @@ -747,7 +749,7 @@ void WriteTask(SceneTask t) if (t.PlannedCost.HasValue) w.WriteNumber("cost", t.PlannedCost.Value); w.WriteNumber("progress", t.Progress); w.WriteStartArray("attachedElements"); - foreach (var id in t.ElementIds) w.WriteNumberValue(id); + foreach (var id in t.ElementIds) WriteElementId(w, id); w.WriteEndArray(); w.WriteEndObject(); foreach (var child in t.Children) WriteTask(child); @@ -788,8 +790,10 @@ private void WriteClashTests(Utf8JsonWriter w) w.WriteString("name", clash.Name); w.WriteString("element1Name", clash.Element1Name); w.WriteString("element2Name", clash.Element2Name); - WriteNullableNumber(w, "element1Id", clash.Element1Id); - WriteNullableNumber(w, "element2Id", clash.Element2Id); + w.WritePropertyName("element1Id"); + WriteElementId(w, clash.Element1Id); + w.WritePropertyName("element2Id"); + WriteElementId(w, clash.Element2Id); WriteVector(w, "point", clash.Point - _rtcOffset); // Null when the source does not report it. if (clash.Distance is double distance) w.WriteNumber("distance", distance); @@ -805,10 +809,12 @@ private void WriteClashTests(Utf8JsonWriter w) w.WriteEndArray(); } - private static void WriteNullableNumber(Utf8JsonWriter w, string name, long? value) + // Elements and their references use the same representation so the browser can match them exactly. + private static void WriteElementId(Utf8JsonWriter w, long? id) { - if (value is long v) w.WriteNumber(name, v); - else w.WriteNull(name); + if (id is not long value) w.WriteNullValue(); + else if (value is >= -MaxSafeElementId and <= MaxSafeElementId) w.WriteNumberValue(value); + else w.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); } private static void WriteView(Utf8JsonWriter w, string name, BlobView? view) diff --git a/src/IOViewer/Viewer/test/e2e/global-setup.js b/src/IOViewer/Viewer/test/e2e/global-setup.js index 66a1406..7de873a 100644 --- a/src/IOViewer/Viewer/test/e2e/global-setup.js +++ b/src/IOViewer/Viewer/test/e2e/global-setup.js @@ -63,6 +63,15 @@ export default function globalSetup() { exportHtml(shear, 'shear'); const results = path.join(viewerDir, 'test-results'); + const wide = largeModel(2); + for (const [i, id] of ['9007199254740992', '9007199254740993'].entries()) { + wide.Elements[i].Id = wide.Meshes[i].ElementId = JSON.rawJSON(id); + wide.Elements[i].Properties = { 'Identity Data': { Mark: `Wide ${i}` } }; + } + const widePath = path.join(results, 'wide-ids.json'); + writeFileSync(widePath, JSON.stringify(wide)); + exportHtml(widePath, 'wide-ids'); + const building = JSON.parse(readFileSync(path.join(fixturesDir, 'building.json'), 'utf8')); const planes = [{ Axis: 3, Normal: [0, 0, 2], Offset: 2 }, { Axis: 0, Offset: -100, Enabled: false }]; for (const [name, box] of [ diff --git a/src/IOViewer/Viewer/test/e2e/ui.spec.js b/src/IOViewer/Viewer/test/e2e/ui.spec.js index b1b30fd..01fae0f 100644 --- a/src/IOViewer/Viewer/test/e2e/ui.spec.js +++ b/src/IOViewer/Viewer/test/e2e/ui.spec.js @@ -384,6 +384,25 @@ test('Copy Id falls back to execCommand when the clipboard API is refused', asyn expect(errors).toEqual([]); }); +test('adjacent 64-bit IDs stay distinct in properties and on the clipboard', async ({ page }) => { + await page.addInitScript(() => { + window.__copied = []; + Object.defineProperty(navigator, 'clipboard', { value: { writeText: async (text) => window.__copied.push(text) } }); + }); + const errors = await open(page, 'wide-ids'); + const ids = ['9007199254740992', '9007199254740993']; + const properties = page.locator('#ioviewer-properties'); + for (const [i, id] of ids.entries()) { + await page.mouse.click(...(await screenAt(page, i)), { button: 'right' }); + expect(await selected(page)).toEqual([i]); + await expect(properties.getByRole('cell', { name: id, exact: true })).toBeVisible(); + await expect(properties.locator('tr', { hasText: 'Mark' }).locator('td')).toHaveText(`Wide ${i}`); + await menuItem(page, 'Копировать Id').click(); + await expect.poll(() => page.evaluate(() => window.__copied)).toEqual(ids.slice(0, i + 1)); + } + expect(errors).toEqual([]); +}); + test('Copy Id reports a failure when no way to copy works', async ({ page }) => { await page.addInitScript(() => { Object.defineProperty(navigator, 'clipboard', { value: { writeText: () => Promise.reject(new DOMException('denied')) } }); diff --git a/tests/IOViewer.Tests/HtmlViewerExporterTests.cs b/tests/IOViewer.Tests/HtmlViewerExporterTests.cs index 91ffb73..365866e 100644 --- a/tests/IOViewer.Tests/HtmlViewerExporterTests.cs +++ b/tests/IOViewer.Tests/HtmlViewerExporterTests.cs @@ -811,6 +811,36 @@ public void ClashIds_AreWritten() Assert.Equal("Active", StatusOf(doc)); } + [Theory] + [InlineData(long.MinValue, true)] + [InlineData(-9007199254740992L, true)] + [InlineData(-9007199254740991L, false)] + [InlineData(9007199254740991L, false)] + [InlineData(9007199254740992L, true)] + [InlineData(9007199254740993L, true)] + [InlineData(long.MaxValue, true)] + public void ElementIds_KeepPrecisionInElementsAndReferences(long id, bool asString) + { + var doc = GeoreferencedModel(); + doc.Scene.Elements[0].Id = id; + doc.Scene.Instances[0].ElementId = id; + doc.Scene.Schedules[0].Tasks[0].ElementIds = [id]; + var clash = doc.Scene.ClashTests[0].Clashes[0]; + clash.Element1Id = id; + clash.Element2Id = id; + + var view = ViewerHtml.Export(doc); + var written = view.Meta.GetProperty("clashTests")[0].GetProperty("clashes")[0]; + string key = id.ToString(CultureInfo.InvariantCulture); + string expected = asString ? $"\"{key}\"" : key; + + Assert.Equal(expected, view.Meta.GetProperty("elements")[0].GetProperty("id").GetRawText()); + Assert.Equal(expected, view.Meta.GetProperty("timeliner").GetProperty("tasks")[0].GetProperty("attachedElements")[0].GetRawText()); + Assert.Equal(expected, written.GetProperty("element1Id").GetRawText()); + Assert.Equal(expected, written.GetProperty("element2Id").GetRawText()); + Assert.Equal("300 mm", view.Props.GetProperty(key).GetProperty("Dimensions").GetProperty("Thickness").GetString()); + } + [Fact] public void ClashDistance_IsNullWhenNotReported() {