From 90097749d4c6bb374538a58021b6fda3a2e79c34 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 14:32:10 +0100 Subject: [PATCH 001/121] feat(scenes): add scene scope and useSceneId Co-Authored-By: Claude Opus 5.5 --- app/composables/scene_id.ts | 18 +++++++ internal/stores/scenes/scene_scope.ts | 53 ++++++++++++++++++++ internal/stores/scenes/types.ts | 21 ++++++++ tests/unit/composables/scene_id.nuxt.test.ts | 33 ++++++++++++ tests/unit/stores/scene_scope.nuxt.test.ts | 39 ++++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 app/composables/scene_id.ts create mode 100644 internal/stores/scenes/scene_scope.ts create mode 100644 internal/stores/scenes/types.ts create mode 100644 tests/unit/composables/scene_id.nuxt.test.ts create mode 100644 tests/unit/stores/scene_scope.nuxt.test.ts diff --git a/app/composables/scene_id.ts b/app/composables/scene_id.ts new file mode 100644 index 000000000..d05192b09 --- /dev/null +++ b/app/composables/scene_id.ts @@ -0,0 +1,18 @@ +import { type InjectionKey, inject, provide } from "vue"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; + +const SCENE_ID_KEY: InjectionKey = Symbol("scene_id"); + +function provideSceneId(sceneId: SceneId): void { + provide(SCENE_ID_KEY, sceneId); +} + +function useSceneId(): SceneId { + const sceneId = inject(SCENE_ID_KEY, undefined); + if (sceneId === undefined) { + throw new Error("useSceneId called outside a SceneView"); + } + return sceneId; +} + +export { SCENE_ID_KEY, provideSceneId, useSceneId }; diff --git a/internal/stores/scenes/scene_scope.ts b/internal/stores/scenes/scene_scope.ts new file mode 100644 index 000000000..477b4c372 --- /dev/null +++ b/internal/stores/scenes/scene_scope.ts @@ -0,0 +1,53 @@ +import { type EffectScope, effectScope } from "vue"; +import type { SceneId } from "./types"; + +interface SceneScopeEntry { + scope: EffectScope; + instances: Map; +} + +const sceneScopes = new Map(); + +function getEntry(sceneId: SceneId): SceneScopeEntry { + let entry = sceneScopes.get(sceneId); + if (!entry) { + // Detached: the scope must outlive whichever component first asked for it + entry = { scope: effectScope(true), instances: new Map() }; + sceneScopes.set(sceneId, entry); + } + return entry; +} + +// Instances are stored type-erased: the caller's (sceneId, key) pair fixes the type +function isInstance(_value: unknown, _factory: () => Instance): _value is Instance { + return true; +} + +// One instance per (sceneId, key), created inside the scene's own effectScope. +// Replaces createSharedComposable for per-scene slices. +function runInSceneScope( + sceneId: SceneId, + key: string, + factory: () => Instance, +): Instance { + const entry = getEntry(sceneId); + if (!entry.instances.has(key)) { + entry.instances.set(key, entry.scope.run(factory)); + } + const instance = entry.instances.get(key); + if (!isInstance(instance, factory)) { + throw new Error(`Scene instance ${key} is missing`); + } + return instance; +} + +function disposeSceneScope(sceneId: SceneId): void { + const entry = sceneScopes.get(sceneId); + if (!entry) { + return; + } + entry.scope.stop(); + sceneScopes.delete(sceneId); +} + +export { disposeSceneScope, runInSceneScope }; diff --git a/internal/stores/scenes/types.ts b/internal/stores/scenes/types.ts new file mode 100644 index 000000000..9cf6367e7 --- /dev/null +++ b/internal/stores/scenes/types.ts @@ -0,0 +1,21 @@ +type SceneId = string; +type SceneMode = "empty" | "duplicate" | "duplicate_linked"; +type LinkChannel = "camera" | "content"; + +interface SceneRecord { + id: SceneId; + name: string; + view_id: string; +} + +interface SceneLink { + id: string; + sceneIds: SceneId[]; + channels: LinkChannel[]; +} + +const INITIAL_SCENE_ID = "scene_1"; +const MAX_SCENES = 4; + +export type { LinkChannel, SceneId, SceneLink, SceneMode, SceneRecord }; +export { INITIAL_SCENE_ID, MAX_SCENES }; diff --git a/tests/unit/composables/scene_id.nuxt.test.ts b/tests/unit/composables/scene_id.nuxt.test.ts new file mode 100644 index 000000000..1e7b461ac --- /dev/null +++ b/tests/unit/composables/scene_id.nuxt.test.ts @@ -0,0 +1,33 @@ +import { type SetupContext, defineComponent, h } from "vue"; +import { describe, expect, test, vi } from "vitest"; +import { provideSceneId, useSceneId } from "@ogw_front/composables/scene_id"; +import { mount } from "@vue/test-utils"; + +vi.setConfig({ testTimeout: 10_000 }); + +describe("scene id injection", () => { + test("useSceneId throws outside a SceneView", () => { + expect(() => useSceneId()).toThrow("useSceneId called outside a SceneView"); + }); + + test("useSceneId reads the provided id", () => { + let read = ""; + const Child = defineComponent({ + setup(): () => ReturnType { + read = useSceneId(); + return () => h("div"); + }, + }); + const Parent = defineComponent({ + setup( + _props: object, + _context: SetupContext, + ): () => ReturnType { + provideSceneId("scene_2"); + return () => h(Child); + }, + }); + mount(Parent); + expect(read).toBe("scene_2"); + }); +}); diff --git a/tests/unit/stores/scene_scope.nuxt.test.ts b/tests/unit/stores/scene_scope.nuxt.test.ts new file mode 100644 index 000000000..c4d00a683 --- /dev/null +++ b/tests/unit/stores/scene_scope.nuxt.test.ts @@ -0,0 +1,39 @@ +import { afterEach, describe, expect, test, vi } from "vitest"; +import { + disposeSceneScope, + runInSceneScope, +} from "@ogw_internal/stores/scenes/scene_scope"; +import { nextTick, ref, watch } from "vue"; + +vi.setConfig({ testTimeout: 10_000 }); + +function createInstance(): object { + return {}; +} + +describe("scene scope", () => { + afterEach(() => { + disposeSceneScope("scene_1"); + disposeSceneScope("scene_2"); + }); + + test("runInSceneScope returns one instance per scene", () => { + const first = runInSceneScope("scene_1", "slice", createInstance); + expect(runInSceneScope("scene_1", "slice", createInstance)).toBe(first); + expect(runInSceneScope("scene_2", "slice", createInstance)).not.toBe(first); + }); + + test("disposeSceneScope recreates the instance", async () => { + const source = ref(0); + const spy = vi.fn<() => void>(); + const first = runInSceneScope("scene_1", "slice", () => { + watch(source, spy); + return {}; + }); + disposeSceneScope("scene_1"); + expect(runInSceneScope("scene_1", "slice", createInstance)).not.toBe(first); + source.value += 1; + await nextTick(); + expect(spy).not.toHaveBeenCalled(); + }); +}); From 0f8d9bc10c6d6e4dd71e65182725ff19c7fe8e1c Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 14:41:51 +0100 Subject: [PATCH 002/121] feat(scenes): add scene link helpers Co-Authored-By: Claude Opus 5.5 --- internal/stores/scenes/links.ts | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 internal/stores/scenes/links.ts diff --git a/internal/stores/scenes/links.ts b/internal/stores/scenes/links.ts new file mode 100644 index 000000000..3456d96ea --- /dev/null +++ b/internal/stores/scenes/links.ts @@ -0,0 +1,58 @@ +import type { LinkChannel, SceneId, SceneLink } from "./types"; + +// The other scenes linked to a scene on a channel +function linkedScenes( + links: readonly SceneLink[], + sceneId: SceneId, + channel: LinkChannel, +): SceneId[] { + const linked = new Set(); + for (const link of links) { + if (link.channels.includes(channel) && link.sceneIds.includes(sceneId)) { + for (const linkedId of link.sceneIds) { + linked.add(linkedId); + } + } + } + linked.delete(sceneId); + return [...linked]; +} + +// A scene linked to an already linked scene joins its group: links are never duplicated +function joinLink( + links: readonly SceneLink[], + sourceId: SceneId, + newId: SceneId, + channels: readonly LinkChannel[], +): SceneLink[] { + const group = links.find((link) => link.sceneIds.includes(sourceId)); + if (!group) { + // A new scene id is never reused, so neither is the id of its link + return [ + ...links, + { + id: `link_${newId}`, + sceneIds: [sourceId, newId], + channels: [...channels], + }, + ]; + } + return links.map((link) => { + if (link !== group) { + return link; + } + return { ...link, sceneIds: [...link.sceneIds, newId] }; + }); +} + +// A group left with a single scene links nothing anymore +function leaveLinks(links: readonly SceneLink[], sceneId: SceneId): SceneLink[] { + return links + .map((link) => ({ + ...link, + sceneIds: link.sceneIds.filter((id) => id !== sceneId), + })) + .filter((link) => link.sceneIds.length > 1); +} + +export { joinLink, leaveLinks, linkedScenes }; From 691b18452702d271ba35960c1c6b2a52ffc77dc2 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 14:42:18 +0100 Subject: [PATCH 003/121] feat(scenes): create and close scenes Co-Authored-By: Claude Opus 5.5 --- app/stores/scenes.ts | 105 +++++++++++++++++++++++++ internal/stores/scenes/scene_stores.ts | 92 ++++++++++++++++++++++ tests/unit/stores/scenes.nuxt.test.ts | 103 ++++++++++++++++++++++++ tests/unit/stores/scenes_helpers.ts | 101 ++++++++++++++++++++++++ 4 files changed, 401 insertions(+) create mode 100644 app/stores/scenes.ts create mode 100644 internal/stores/scenes/scene_stores.ts create mode 100644 tests/unit/stores/scenes.nuxt.test.ts create mode 100644 tests/unit/stores/scenes_helpers.ts diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts new file mode 100644 index 000000000..f182daa6c --- /dev/null +++ b/app/stores/scenes.ts @@ -0,0 +1,105 @@ +// Third party imports +import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; +import { defineStore } from "pinia"; +import { ref } from "vue"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; + +// Local imports +import { + INITIAL_SCENE_ID, + MAX_SCENES, + type SceneId, + type SceneLink, + type SceneMode, + type SceneRecord, +} from "@ogw_internal/stores/scenes/types"; +import { + deleteFromProject, + disposeSceneStores, + duplicateSceneStores, +} from "@ogw_internal/stores/scenes/scene_stores"; +import { joinLink, leaveLinks } from "@ogw_internal/stores/scenes/links"; +import { useViewerStore } from "@ogw_front/stores/viewer"; + +const viewerSchemas = viewer_schemas.opengeodeweb_viewer.viewer; + +export const useScenesStore = defineStore("scenes", () => { + const scenes = ref([]); + const contents = ref>({}); + const links = ref([]); + const lastUsedSceneId = ref(INITIAL_SCENE_ID); + // Scene ids are never reused: scene_ + const counter = ref(0); + + // A data stays in the project while a scene shows it + async function deleteIfHidden(dataIds: readonly DataId[]): Promise { + const shown = new Set(Object.values(contents.value).flat()); + await Promise.all( + dataIds + .filter((dataId) => !shown.has(dataId)) + .map(async (dataId) => { + await deleteFromProject(dataId); + }), + ); + } + + // A duplicated scene shows the data of its source: the last used scene by default + async function createScene(mode: SceneMode, sourceId?: SceneId): Promise { + if (scenes.value.length >= MAX_SCENES) { + throw new Error(`A project shows at most ${MAX_SCENES} scenes`); + } + counter.value += 1; + const sceneId = `scene_${counter.value}`; + const { view_id } = await useViewerStore().request({ + schema: viewerSchemas.create_scene, + params: { scene_id: sceneId }, + }); + scenes.value.push({ id: sceneId, name: `Scene ${counter.value}`, view_id }); + contents.value[sceneId] = []; + if (mode === "empty") { + return sceneId; + } + const source = sourceId ?? lastUsedSceneId.value; + const content = [...(contents.value[source] ?? [])]; + contents.value[sceneId] = content; + await duplicateSceneStores(source, sceneId, content); + if (mode === "duplicate_linked") { + links.value = joinLink(links.value, source, sceneId, ["camera", "content"]); + } + return sceneId; + } + + async function closeScene(sceneId: SceneId): Promise { + if (scenes.value.length <= 1) { + throw new Error("The last scene cannot be closed"); + } + disposeSceneStores(sceneId); + await useViewerStore().request({ + schema: viewerSchemas.delete_scene, + params: { scene_id: sceneId }, + }); + links.value = leaveLinks(links.value, sceneId); + const closedContent = contents.value[sceneId] ?? []; + scenes.value = scenes.value.filter((scene) => scene.id !== sceneId); + Reflect.deleteProperty(contents.value, sceneId); + if (lastUsedSceneId.value === sceneId) { + lastUsedSceneId.value = scenes.value[0]?.id ?? INITIAL_SCENE_ID; + } + await deleteIfHidden(closedContent); + } + + function setLastUsed(sceneId: SceneId): void { + lastUsedSceneId.value = sceneId; + } + + return { + scenes, + contents, + links, + lastUsedSceneId, + counter, + createScene, + closeScene, + setLastUsed, + }; +}); diff --git a/internal/stores/scenes/scene_stores.ts b/internal/stores/scenes/scene_stores.ts new file mode 100644 index 000000000..a329b2192 --- /dev/null +++ b/internal/stores/scenes/scene_stores.ts @@ -0,0 +1,92 @@ +// Third party imports +import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; +import { toRaw } from "vue"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; + +// Local imports +import type { DataItem } from "@ogw_internal/database/tables/data"; +import type { SceneId } from "./types"; +import { disposeSceneScope } from "./scene_scope"; +import { useAppStore } from "@ogw_front/stores/app"; +import { useDataStore } from "@ogw_front/stores/data"; +import { useDataStyleStore } from "@ogw_front/stores/data_style"; +import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; +import { useTreeviewStore } from "@ogw_front/stores/treeview"; +import { useViewerStore } from "@ogw_front/stores/viewer"; + +const viewerSchemas = viewer_schemas.opengeodeweb_viewer.viewer; + +// Only the data the viewer holds a pipeline for is shown in the scene +async function showInViewer(sceneId: SceneId, dataId: DataId): Promise { + if (!useDataStore().isRegistered(dataId)) { + return; + } + await useViewerStore().request({ + schema: viewerSchemas.add_to_scene, + params: { scene_id: sceneId, id: dataId }, + }); + await useHybridViewerStore(sceneId).addItem(dataId); +} + +// Lists the data in the scene tree, loading until the scene shows it +async function showItem(sceneId: SceneId, item: DataItem): Promise { + const treeviewStore = useTreeviewStore(sceneId); + treeviewStore.addItem( + item.geode_object_type, + item.name, + item.data_id, + item.geode_id, + item.viewer_object_type, + ); + await treeviewStore.untilLoaded(item.data_id, showInViewer(sceneId, item.data_id)); +} + +async function deleteFromProject(dataId: DataId): Promise { + const dataStore = useDataStore(); + await dataStore.deregisterObject(dataId); + await dataStore.deleteItem(dataId); +} + +// Copies what the source scene shows, its styles, its tree and its camera +async function duplicateSceneStores( + sourceId: SceneId, + sceneId: SceneId, + content: readonly DataId[], +): Promise { + const dataStore = useDataStore(); + await Promise.all( + content.map(async (dataId) => { + await showItem(sceneId, await dataStore.item(dataId)); + }), + ); + + const dataStyleStore = useDataStyleStore(sceneId); + await dataStyleStore.importStores(useDataStyleStore(sourceId).exportStores()); + await dataStyleStore.applyAllStylesFromState(); + + const treeviewStore = useTreeviewStore(sceneId); + treeviewStore.importStores(useTreeviewStore(sourceId).exportStores()); + treeviewStore.finalizeImportSelection(); + + // Applied by the scene's hybrid viewer once it is created + const hybridViewerStore = useHybridViewerStore(sceneId); + const { zScale, camera_options } = useHybridViewerStore(sourceId).exportStores(); + hybridViewerStore.zScale = zScale; + Object.assign(hybridViewerStore.camera_options, structuredClone(toRaw(camera_options))); +} + +// The stores of a closed scene are no longer saved in projects +function disposeSceneStores(sceneId: SceneId): void { + const appStore = useAppStore(); + for (const store of [ + useDataStyleStore(sceneId), + useHybridViewerStore(sceneId), + useTreeviewStore(sceneId), + ]) { + store.$dispose(); + appStore.unregisterStore(store.$id); + } + disposeSceneScope(sceneId); +} + +export { deleteFromProject, disposeSceneStores, duplicateSceneStores }; diff --git a/tests/unit/stores/scenes.nuxt.test.ts b/tests/unit/stores/scenes.nuxt.test.ts new file mode 100644 index 000000000..1b9ee21e6 --- /dev/null +++ b/tests/unit/stores/scenes.nuxt.test.ts @@ -0,0 +1,103 @@ +// Third party imports +import { type Mock, beforeEach, describe, expect, test, vi } from "vitest"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; + +// Local imports +import { + type Request, + fakeSceneStore, + fakeStores, + mockViewer, + sentTo, +} from "@ogw_tests/unit/stores/scenes_helpers"; +import { MAX_SCENES } from "@ogw_internal/stores/scenes/types"; +import { setupActivePinia } from "@ogw_tests/utils"; +import { useScenesStore } from "@ogw_front/stores/scenes"; + +vi.setConfig({ testTimeout: 10_000 }); + +vi.mock(import("@ogw_front/stores/data_style") as Promise, async () => { + const helpers = await import("@ogw_tests/unit/stores/scenes_helpers"); + return { + useDataStyleStore: (sceneId: string): Record => + helpers.fakeSceneStore("dataStyle", sceneId), + }; +}); +vi.mock(import("@ogw_front/stores/hybrid_viewer") as Promise, async () => { + const helpers = await import("@ogw_tests/unit/stores/scenes_helpers"); + return { + useHybridViewerStore: (sceneId: string): Record => + helpers.fakeSceneStore("hybridViewer", sceneId), + }; +}); +vi.mock(import("@ogw_front/stores/treeview") as Promise, async () => { + const helpers = await import("@ogw_tests/unit/stores/scenes_helpers"); + return { + useTreeviewStore: (sceneId: string): Record => + helpers.fakeSceneStore("treeview", sceneId), + }; +}); + +const { viewer } = viewer_schemas.opengeodeweb_viewer; + +describe("scenes store", () => { + let request: Mock = vi.fn(); + + beforeEach(async () => { + setupActivePinia(); + fakeStores.clear(); + request = mockViewer(); + await useScenesStore().createScene("empty"); + }); + + test("createScene duplicate_linked links camera and content", async () => { + const scenesStore = useScenesStore(); + + await scenesStore.createScene("duplicate_linked", "scene_1"); + + expect(scenesStore.links).toStrictEqual([ + { + id: "link_scene_2", + sceneIds: ["scene_1", "scene_2"], + channels: ["camera", "content"], + }, + ]); + }); + + test("createScene refuses beyond MAX_SCENES", async () => { + const scenesStore = useScenesStore(); + await scenesStore.createScene("empty"); + await scenesStore.createScene("empty"); + await scenesStore.createScene("empty"); + expect(scenesStore.scenes).toHaveLength(MAX_SCENES); + + await expect(scenesStore.createScene("empty")).rejects.toThrow("at most"); + expect(scenesStore.scenes).toHaveLength(MAX_SCENES); + }); + + test("closeScene keeps the remaining link", async () => { + const scenesStore = useScenesStore(); + await scenesStore.createScene("duplicate_linked", "scene_1"); + await scenesStore.createScene("duplicate_linked", "scene_2"); + + await scenesStore.closeScene("scene_3"); + + expect(scenesStore.scenes.map((scene) => scene.id)).toStrictEqual(["scene_1", "scene_2"]); + expect(scenesStore.links).toStrictEqual([ + { + id: "link_scene_2", + sceneIds: ["scene_1", "scene_2"], + channels: ["camera", "content"], + }, + ]); + expect(sentTo(request, viewer.delete_scene)).toStrictEqual(["scene_3"]); + expect(fakeSceneStore("treeview", "scene_3").$dispose).toHaveBeenCalledWith(); + }); + + test("closeScene refuses the last scene", async () => { + const scenesStore = useScenesStore(); + + await expect(scenesStore.closeScene("scene_1")).rejects.toThrow("last scene"); + expect(scenesStore.scenes).toHaveLength(1); + }); +}); diff --git a/tests/unit/stores/scenes_helpers.ts b/tests/unit/stores/scenes_helpers.ts new file mode 100644 index 000000000..5f5440e22 --- /dev/null +++ b/tests/unit/stores/scenes_helpers.ts @@ -0,0 +1,101 @@ +// Third party imports +import { type Mock, vi } from "vitest"; + +// Local imports +import { mockAs } from "@ogw_tests/utils"; +import { useDataStore } from "@ogw_front/stores/data"; +import { useViewerStore } from "@ogw_front/stores/viewer"; + +// The stores of each scene are faked: only what the scenes store calls on them +const fakeStores = new Map>(); + +function resolves(): () => Promise { + return vi.fn<() => Promise>(async () => { + await Promise.resolve(); + }); +} + +async function untilLoaded(_dataId: string, loading: Promise): Promise { + await loading; +} + +function fakeSceneStore(storeId: string, sceneId: string): Record { + const key = `${storeId}-${sceneId}`; + const instance = fakeStores.get(key) ?? { + $id: key, + $dispose: vi.fn<() => void>(), + zScale: 1, + camera_options: {}, + addItem: resolves(), + removeItem: vi.fn<() => void>(), + closeView: vi.fn<() => void>(), + untilLoaded: vi.fn(untilLoaded), + addDataStyle: resolves(), + applyDefaultStyle: resolves(), + applyAllStylesFromState: resolves(), + exportStores: vi.fn<() => object>(() => ({})), + importStores: resolves(), + finalizeImportSelection: vi.fn<() => void>(), + }; + fakeStores.set(key, instance); + return instance; +} + +const DATA_ID_LENGTH = 32; +const DATA_ID = "a".repeat(DATA_ID_LENGTH); + +interface SentRequest { + schema: { $id: string }; + params: Record; +} + +type Request = (request: SentRequest) => Promise; + +// The viewer answers create_scene with a view of its own +function mockViewer(): Mock { + const viewerStore = useViewerStore(); + const request = vi.fn(async (sent) => { + await Promise.resolve(); + return { view_id: `view_${String(sent.params.scene_id)}` }; + }); + viewerStore.request = mockAs(request); + return request; +} + +function sentTo(request: Mock, schema: { $id: string }): unknown[] { + return request.mock.calls + .filter(([sent]) => sent.schema.$id === schema.$id) + .map(([sent]) => sent.params.scene_id); +} + +// The data is registered in the viewer: the deletion from the project is spied +function mockData(): { deleteItem: Mock<(dataId: string) => Promise> } { + const dataStore = useDataStore(); + const item = { + data_id: DATA_ID, + name: "data", + geode_id: "geode", + geode_object_type: "PointSet3D", + viewer_object_type: "mesh", + }; + dataStore.item = mockAs( + vi.fn<() => Promise>(async () => { + await Promise.resolve(); + return item; + }), + ); + dataStore.isRegistered = mockAs(vi.fn<() => boolean>(() => true)); + dataStore.deregisterObject = mockAs( + vi.fn<() => Promise>(async () => { + await Promise.resolve(); + }), + ); + const deleteItem = vi.fn<(dataId: string) => Promise>(async () => { + await Promise.resolve(); + }); + dataStore.deleteItem = mockAs(deleteItem); + return { deleteItem }; +} + +export { DATA_ID, fakeSceneStore, fakeStores, mockData, mockViewer, sentTo }; +export type { Request }; From 49ad372b7d1aef517c5b368993dc6f4680f1b81e Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 14:42:28 +0100 Subject: [PATCH 004/121] feat(scenes): add and remove data per scene Co-Authored-By: Claude Opus 5.5 --- app/stores/scenes.ts | 45 ++++++++++++- internal/stores/scenes/scene_stores.ts | 33 +++++++++- tests/unit/stores/scenes.nuxt.test.ts | 88 ++++++++++++++++++++++++++ 3 files changed, 164 insertions(+), 2 deletions(-) diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index f182daa6c..266179e47 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -14,15 +14,18 @@ import { type SceneRecord, } from "@ogw_internal/stores/scenes/types"; import { + addToSceneStores, deleteFromProject, disposeSceneStores, duplicateSceneStores, + removeFromSceneStores, } from "@ogw_internal/stores/scenes/scene_stores"; -import { joinLink, leaveLinks } from "@ogw_internal/stores/scenes/links"; +import { joinLink, leaveLinks, linkedScenes } from "@ogw_internal/stores/scenes/links"; import { useViewerStore } from "@ogw_front/stores/viewer"; const viewerSchemas = viewer_schemas.opengeodeweb_viewer.viewer; +// The only place that knows the content links: data are added to and removed from scenes here export const useScenesStore = defineStore("scenes", () => { const scenes = ref([]); const contents = ref>({}); @@ -31,6 +34,25 @@ export const useScenesStore = defineStore("scenes", () => { // Scene ids are never reused: scene_ const counter = ref(0); + // A scene and the scenes linked to it on content, keeping those where the data is shown or not + function contentTargets(sceneId: SceneId, dataId: DataId, shown: boolean): SceneId[] { + return [sceneId, ...linkedScenes(links.value, sceneId, "content")].filter( + (targetId) => (contents.value[targetId] ?? []).includes(dataId) === shown, + ); + } + + async function addData(sceneId: SceneId, dataId: DataId): Promise { + const targets = contentTargets(sceneId, dataId, false); + for (const targetId of targets) { + contents.value[targetId] = [...(contents.value[targetId] ?? []), dataId]; + } + await Promise.all( + targets.map(async (targetId) => { + await addToSceneStores(targetId, dataId); + }), + ); + } + // A data stays in the project while a scene shows it async function deleteIfHidden(dataIds: readonly DataId[]): Promise { const shown = new Set(Object.values(contents.value).flat()); @@ -43,6 +65,19 @@ export const useScenesStore = defineStore("scenes", () => { ); } + async function removeData(sceneId: SceneId, dataId: DataId): Promise { + const targets = contentTargets(sceneId, dataId, true); + for (const targetId of targets) { + contents.value[targetId] = (contents.value[targetId] ?? []).filter((id) => id !== dataId); + } + await Promise.all( + targets.map(async (targetId) => { + await removeFromSceneStores(targetId, dataId); + }), + ); + await deleteIfHidden([dataId]); + } + // A duplicated scene shows the data of its source: the last used scene by default async function createScene(mode: SceneMode, sourceId?: SceneId): Promise { if (scenes.value.length >= MAX_SCENES) { @@ -88,6 +123,11 @@ export const useScenesStore = defineStore("scenes", () => { await deleteIfHidden(closedContent); } + // The scene keeps what it shows and diverges from its group + function unlink(sceneId: SceneId): void { + links.value = leaveLinks(links.value, sceneId); + } + function setLastUsed(sceneId: SceneId): void { lastUsedSceneId.value = sceneId; } @@ -100,6 +140,9 @@ export const useScenesStore = defineStore("scenes", () => { counter, createScene, closeScene, + addData, + removeData, + unlink, setLastUsed, }; }); diff --git a/internal/stores/scenes/scene_stores.ts b/internal/stores/scenes/scene_stores.ts index a329b2192..26e02333c 100644 --- a/internal/stores/scenes/scene_stores.ts +++ b/internal/stores/scenes/scene_stores.ts @@ -41,6 +41,31 @@ async function showItem(sceneId: SceneId, item: DataItem): Promise { await treeviewStore.untilLoaded(item.data_id, showInViewer(sceneId, item.data_id)); } +// A data added to a scene gets the default style of that scene +async function addToSceneStores(sceneId: SceneId, dataId: DataId): Promise { + const item = await useDataStore().item(dataId); + const dataStyleStore = useDataStyleStore(sceneId); + await dataStyleStore.addDataStyle(dataId, item.geode_object_type); + await showItem(sceneId, item); + if (useDataStore().isRegistered(dataId)) { + await dataStyleStore.applyDefaultStyle(dataId); + } +} + +async function removeFromSceneStores(sceneId: SceneId, dataId: DataId): Promise { + const treeviewStore = useTreeviewStore(sceneId); + treeviewStore.removeItem(dataId); + treeviewStore.closeView(dataId); + useHybridViewerStore(sceneId).removeItem(dataId); + if (!useDataStore().isRegistered(dataId)) { + return; + } + await useViewerStore().request({ + schema: viewerSchemas.remove_from_scene, + params: { scene_id: sceneId, id: dataId }, + }); +} + async function deleteFromProject(dataId: DataId): Promise { const dataStore = useDataStore(); await dataStore.deregisterObject(dataId); @@ -89,4 +114,10 @@ function disposeSceneStores(sceneId: SceneId): void { disposeSceneScope(sceneId); } -export { deleteFromProject, disposeSceneStores, duplicateSceneStores }; +export { + addToSceneStores, + deleteFromProject, + disposeSceneStores, + duplicateSceneStores, + removeFromSceneStores, +}; diff --git a/tests/unit/stores/scenes.nuxt.test.ts b/tests/unit/stores/scenes.nuxt.test.ts index 1b9ee21e6..b98ca1151 100644 --- a/tests/unit/stores/scenes.nuxt.test.ts +++ b/tests/unit/stores/scenes.nuxt.test.ts @@ -4,9 +4,11 @@ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed // Local imports import { + DATA_ID, type Request, fakeSceneStore, fakeStores, + mockData, mockViewer, sentTo, } from "@ogw_tests/unit/stores/scenes_helpers"; @@ -50,6 +52,35 @@ describe("scenes store", () => { await useScenesStore().createScene("empty"); }); + test("createScene empty has no content", async () => { + const scenesStore = useScenesStore(); + mockData(); + await scenesStore.addData("scene_1", DATA_ID); + + const sceneId = await scenesStore.createScene("empty"); + + expect(sceneId).toBe("scene_2"); + expect(scenesStore.contents.scene_2).toStrictEqual([]); + expect(scenesStore.scenes.map((scene) => scene.view_id)).toStrictEqual([ + "view_scene_1", + "view_scene_2", + ]); + expect(scenesStore.links).toStrictEqual([]); + }); + + test("createScene duplicate copies content without link", async () => { + const scenesStore = useScenesStore(); + mockData(); + await scenesStore.addData("scene_1", DATA_ID); + + await scenesStore.createScene("duplicate", "scene_1"); + + expect(scenesStore.contents.scene_2).toStrictEqual([DATA_ID]); + expect(sentTo(request, viewer.add_to_scene)).toStrictEqual(["scene_1", "scene_2"]); + expect(fakeSceneStore("dataStyle", "scene_2").applyAllStylesFromState).toHaveBeenCalledWith(); + expect(scenesStore.links).toStrictEqual([]); + }); + test("createScene duplicate_linked links camera and content", async () => { const scenesStore = useScenesStore(); @@ -75,6 +106,50 @@ describe("scenes store", () => { expect(scenesStore.scenes).toHaveLength(MAX_SCENES); }); + test("addData propagates only through content links", async () => { + const scenesStore = useScenesStore(); + mockData(); + await scenesStore.createScene("duplicate_linked", "scene_1"); + await scenesStore.createScene("duplicate", "scene_1"); + + await scenesStore.addData("scene_1", DATA_ID); + + expect(scenesStore.contents).toStrictEqual({ + scene_1: [DATA_ID], + scene_2: [DATA_ID], + scene_3: [], + }); + expect(sentTo(request, viewer.add_to_scene)).toStrictEqual(["scene_1", "scene_2"]); + }); + + test("removeData keeps data shown elsewhere", async () => { + const scenesStore = useScenesStore(); + const { deleteItem } = mockData(); + await scenesStore.addData("scene_1", DATA_ID); + await scenesStore.createScene("duplicate", "scene_1"); + + await scenesStore.removeData("scene_1", DATA_ID); + + expect(scenesStore.contents).toStrictEqual({ + scene_1: [], + scene_2: [DATA_ID], + }); + expect(sentTo(request, viewer.remove_from_scene)).toStrictEqual(["scene_1"]); + expect(deleteItem).not.toHaveBeenCalled(); + }); + + test("removeData deletes data when last", async () => { + const scenesStore = useScenesStore(); + const { deleteItem } = mockData(); + await scenesStore.addData("scene_1", DATA_ID); + await scenesStore.createScene("duplicate_linked", "scene_1"); + + await scenesStore.removeData("scene_2", DATA_ID); + + expect(scenesStore.contents).toStrictEqual({ scene_1: [], scene_2: [] }); + expect(deleteItem).toHaveBeenCalledWith(DATA_ID); + }); + test("closeScene keeps the remaining link", async () => { const scenesStore = useScenesStore(); await scenesStore.createScene("duplicate_linked", "scene_1"); @@ -94,6 +169,19 @@ describe("scenes store", () => { expect(fakeSceneStore("treeview", "scene_3").$dispose).toHaveBeenCalledWith(); }); + test("closeScene drops a link of one", async () => { + const scenesStore = useScenesStore(); + const { deleteItem } = mockData(); + await scenesStore.addData("scene_1", DATA_ID); + await scenesStore.createScene("duplicate_linked", "scene_1"); + + await scenesStore.closeScene("scene_2"); + + expect(scenesStore.links).toStrictEqual([]); + expect(scenesStore.contents).toStrictEqual({ scene_1: [DATA_ID] }); + expect(deleteItem).not.toHaveBeenCalled(); + }); + test("closeScene refuses the last scene", async () => { const scenesStore = useScenesStore(); From 2ca581017416c3162f06b9cf279b00d241eaae12 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 14:42:28 +0100 Subject: [PATCH 005/121] feat(scenes): export and import scenes state Co-Authored-By: Claude Opus 5.5 --- app/stores/scenes.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index 266179e47..133201477 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -25,6 +25,14 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; const viewerSchemas = viewer_schemas.opengeodeweb_viewer.viewer; +interface ScenesSnapshot { + scenes: SceneRecord[]; + contents: Record; + links: SceneLink[]; + lastUsedSceneId: SceneId; + counter: number; +} + // The only place that knows the content links: data are added to and removed from scenes here export const useScenesStore = defineStore("scenes", () => { const scenes = ref([]); @@ -132,6 +140,32 @@ export const useScenesStore = defineStore("scenes", () => { lastUsedSceneId.value = sceneId; } + function exportStores(): ScenesSnapshot { + return { + scenes: scenes.value, + contents: contents.value, + links: links.value, + lastUsedSceneId: lastUsedSceneId.value, + counter: counter.value, + }; + } + + function importStores(snapshot: ScenesSnapshot): void { + scenes.value = structuredClone(snapshot.scenes); + contents.value = structuredClone(snapshot.contents); + links.value = structuredClone(snapshot.links); + lastUsedSceneId.value = snapshot.lastUsedSceneId; + counter.value = snapshot.counter; + } + + function clear(): void { + scenes.value = []; + contents.value = {}; + links.value = []; + lastUsedSceneId.value = INITIAL_SCENE_ID; + counter.value = 0; + } + return { scenes, contents, @@ -144,5 +178,10 @@ export const useScenesStore = defineStore("scenes", () => { removeData, unlink, setLastUsed, + exportStores, + importStores, + clear, }; }); + +export type { ScenesSnapshot }; From 0010d883b48cf58269fec4825991ca13831c3345 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 14:45:52 +0100 Subject: [PATCH 006/121] fix(scenes): require a source scene to duplicate Co-Authored-By: Claude Opus 5.5 --- app/stores/scenes.ts | 27 +++++++++++++++++---------- tests/unit/stores/scenes.nuxt.test.ts | 7 +++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index 133201477..44dae1967 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -86,11 +86,7 @@ export const useScenesStore = defineStore("scenes", () => { await deleteIfHidden([dataId]); } - // A duplicated scene shows the data of its source: the last used scene by default - async function createScene(mode: SceneMode, sourceId?: SceneId): Promise { - if (scenes.value.length >= MAX_SCENES) { - throw new Error(`A project shows at most ${MAX_SCENES} scenes`); - } + async function newScene(): Promise { counter.value += 1; const sceneId = `scene_${counter.value}`; const { view_id } = await useViewerStore().request({ @@ -99,15 +95,26 @@ export const useScenesStore = defineStore("scenes", () => { }); scenes.value.push({ id: sceneId, name: `Scene ${counter.value}`, view_id }); contents.value[sceneId] = []; + return sceneId; + } + + // A duplicated scene shows the data of its source scene, given by the caller + async function createScene(mode: SceneMode, sourceId?: SceneId): Promise { + if (scenes.value.length >= MAX_SCENES) { + throw new Error(`A project shows at most ${MAX_SCENES} scenes`); + } if (mode === "empty") { - return sceneId; + return newScene(); + } + if (sourceId === undefined) { + throw new Error("A duplicated scene needs its source scene"); } - const source = sourceId ?? lastUsedSceneId.value; - const content = [...(contents.value[source] ?? [])]; + const sceneId = await newScene(); + const content = [...(contents.value[sourceId] ?? [])]; contents.value[sceneId] = content; - await duplicateSceneStores(source, sceneId, content); + await duplicateSceneStores(sourceId, sceneId, content); if (mode === "duplicate_linked") { - links.value = joinLink(links.value, source, sceneId, ["camera", "content"]); + links.value = joinLink(links.value, sourceId, sceneId, ["camera", "content"]); } return sceneId; } diff --git a/tests/unit/stores/scenes.nuxt.test.ts b/tests/unit/stores/scenes.nuxt.test.ts index b98ca1151..650461b4f 100644 --- a/tests/unit/stores/scenes.nuxt.test.ts +++ b/tests/unit/stores/scenes.nuxt.test.ts @@ -182,6 +182,13 @@ describe("scenes store", () => { expect(deleteItem).not.toHaveBeenCalled(); }); + test("createScene refuses a duplicate without source", async () => { + const scenesStore = useScenesStore(); + + await expect(scenesStore.createScene("duplicate")).rejects.toThrow("source scene"); + expect(scenesStore.scenes).toHaveLength(1); + }); + test("closeScene refuses the last scene", async () => { const scenesStore = useScenesStore(); From 70b890fe79c262a8f29c2da4bffd861ab4fa2db2 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 14:46:06 +0100 Subject: [PATCH 007/121] fix(scenes): reject unknown scene ids Co-Authored-By: Claude Opus 5.5 --- app/stores/scenes.ts | 9 +++++++++ tests/unit/stores/scenes.nuxt.test.ts | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index 44dae1967..a8aaf5898 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -86,6 +86,13 @@ export const useScenesStore = defineStore("scenes", () => { await deleteIfHidden([dataId]); } + // An unknown id would create the stores of a scene that does not exist + function assertScene(sceneId: SceneId): void { + if (!scenes.value.some((scene) => scene.id === sceneId)) { + throw new Error(`Unknown scene: ${sceneId}`); + } + } + async function newScene(): Promise { counter.value += 1; const sceneId = `scene_${counter.value}`; @@ -109,6 +116,7 @@ export const useScenesStore = defineStore("scenes", () => { if (sourceId === undefined) { throw new Error("A duplicated scene needs its source scene"); } + assertScene(sourceId); const sceneId = await newScene(); const content = [...(contents.value[sourceId] ?? [])]; contents.value[sceneId] = content; @@ -120,6 +128,7 @@ export const useScenesStore = defineStore("scenes", () => { } async function closeScene(sceneId: SceneId): Promise { + assertScene(sceneId); if (scenes.value.length <= 1) { throw new Error("The last scene cannot be closed"); } diff --git a/tests/unit/stores/scenes.nuxt.test.ts b/tests/unit/stores/scenes.nuxt.test.ts index 650461b4f..46cfde8a3 100644 --- a/tests/unit/stores/scenes.nuxt.test.ts +++ b/tests/unit/stores/scenes.nuxt.test.ts @@ -189,6 +189,16 @@ describe("scenes store", () => { expect(scenesStore.scenes).toHaveLength(1); }); + test("unknown scene ids are rejected", async () => { + const scenesStore = useScenesStore(); + await scenesStore.createScene("empty"); + + await expect(scenesStore.createScene("duplicate", "scene_9")).rejects.toThrow("Unknown scene"); + await expect(scenesStore.closeScene("scene_9")).rejects.toThrow("Unknown scene"); + expect(scenesStore.scenes).toHaveLength(2); + expect(fakeStores.size).toBe(0); + }); + test("closeScene refuses the last scene", async () => { const scenesStore = useScenesStore(); From d996afad8f9b073aa6572da4103d509223047648 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 14:46:33 +0100 Subject: [PATCH 008/121] fix(scenes): ignore removal of data a scene does not show Co-Authored-By: Claude Opus 5.5 --- app/stores/scenes.ts | 4 ++++ tests/unit/stores/scenes.nuxt.test.ts | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index a8aaf5898..ff114e8af 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -75,6 +75,10 @@ export const useScenesStore = defineStore("scenes", () => { async function removeData(sceneId: SceneId, dataId: DataId): Promise { const targets = contentTargets(sceneId, dataId, true); + // A data the scene does not show is neither removed nor deleted + if (targets.length === 0) { + return; + } for (const targetId of targets) { contents.value[targetId] = (contents.value[targetId] ?? []).filter((id) => id !== dataId); } diff --git a/tests/unit/stores/scenes.nuxt.test.ts b/tests/unit/stores/scenes.nuxt.test.ts index 46cfde8a3..69059dfb9 100644 --- a/tests/unit/stores/scenes.nuxt.test.ts +++ b/tests/unit/stores/scenes.nuxt.test.ts @@ -136,6 +136,20 @@ describe("scenes store", () => { }); expect(sentTo(request, viewer.remove_from_scene)).toStrictEqual(["scene_1"]); expect(deleteItem).not.toHaveBeenCalled(); + + await scenesStore.removeData("scene_2", DATA_ID); + + expect(deleteItem).toHaveBeenCalledWith(DATA_ID); + }); + + test("removeData ignores data the scene does not show", async () => { + const scenesStore = useScenesStore(); + const { deleteItem } = mockData(); + + await scenesStore.removeData("scene_1", DATA_ID); + + expect(scenesStore.contents).toStrictEqual({ scene_1: [] }); + expect(deleteItem).not.toHaveBeenCalled(); }); test("removeData deletes data when last", async () => { From 75693fd807100b6aa2b01cf21871b045275a561c Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:05:04 +0100 Subject: [PATCH 009/121] feat(database): key style tables by scene The style, component style, component type style, scene style and treeview config rows gain a scene_id that leads their key. The treeview keeps one row under the initial scene until it is scoped by scene. Co-Authored-By: Claude Opus 5.5 --- app/stores/treeview.ts | 7 ++++--- internal/database/database.ts | 20 ++++++++++++------- internal/database/tables/data_style.ts | 2 +- .../tables/model_component_datastyle.ts | 2 +- .../tables/model_component_type_datastyle.ts | 2 +- internal/database/tables/scene_style.ts | 2 +- internal/database/tables/treeview_config.ts | 5 +++-- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/app/stores/treeview.ts b/app/stores/treeview.ts index 87a739a63..bfcbb2eb1 100644 --- a/app/stores/treeview.ts +++ b/app/stores/treeview.ts @@ -23,6 +23,7 @@ import { physicalPropertiesViewId, viewModelId, } from "@ogw_front/utils/treeview"; +import { INITIAL_SCENE_ID } from "@ogw_internal/stores/scenes/types"; import { treeviewConfigDb } from "@ogw_internal/database/database"; const PANEL_WIDTH = 300; @@ -108,7 +109,7 @@ export const useTreeviewStore = defineStore("treeview", () => { async function loadConfig(): Promise { try { - const config = await treeviewConfigTable.get("main"); + const config = await treeviewConfigTable.get(INITIAL_SCENE_ID); if (config?.opened_views) { opened_views.value = withModelTreeColors(config.opened_views); } @@ -144,7 +145,7 @@ export const useTreeviewStore = defineStore("treeview", () => { // Best-effort persistence: a failure is logged, not thrown. try { await treeviewConfigTable.put({ - id: "main", + scene_id: INITIAL_SCENE_ID, opened_views: clean_opened_views, panelWidth: panelWidth.value, additionalPanelWidth: additionalPanelWidth.value, @@ -453,7 +454,7 @@ export const useTreeviewStore = defineStore("treeview", () => { rowHeights.value = [...heights]; } - function exportStores(): Omit { + function exportStores(): Omit { return { opened_views: opened_views.value, panelWidth: panelWidth.value, diff --git a/internal/database/database.ts b/internal/database/database.ts index eb8732351..1532a9953 100644 --- a/internal/database/database.ts +++ b/internal/database/database.ts @@ -19,6 +19,7 @@ import { import { type TreeviewConfigRecord, treeviewConfigTable } from "./tables/treeview_config"; import { BaseDatabase } from "./base_database"; import { ExtendedDatabase } from "./extended_database"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { dataStyleTable } from "./tables/data_style"; import { modelComponentDataStyleTable } from "./tables/model_component_datastyle"; import { modelComponentTypeDataStyleTable } from "./tables/model_component_type_datastyle"; @@ -195,21 +196,25 @@ function modelPhysicalPropertiesDb(): Table { +// The style tables are keyed by scene: the same data can be styled differently in two scenes +type SceneKeyed = Row & { scene_id: SceneId }; +type ComponentStyleKey = [SceneId, string, string]; + +function dataStyleDb(): Table, [SceneId, string]> { return liveTable(dataStyleTable.name); } -// Keyed by [id_model, id_component] -function componentDataStyleDb(): Table { +// Keyed by [scene_id, id_model, id_component] +function componentDataStyleDb(): Table, ComponentStyleKey> { return liveTable(modelComponentDataStyleTable.name); } -// Keyed by [id_model, type] -function componentTypeDataStyleDb(): Table { +// Keyed by [scene_id, id_model, type] +function componentTypeDataStyleDb(): Table, ComponentStyleKey> { return liveTable(modelComponentTypeDataStyleTable.name); } -function sceneStyleDb(): Table { +function sceneStyleDb(): Table, SceneId> { return liveTable(sceneStyleTable.name); } @@ -218,7 +223,7 @@ function cameraPositionsDb(): Table { return liveTable(cameraPositionsTable.name); } -function treeviewConfigDb(): Table { +function treeviewConfigDb(): Table { return liveTable(treeviewConfigTable.name); } @@ -248,3 +253,4 @@ export { treeviewConfigDb, writeTransaction, }; +export type { SceneKeyed }; diff --git a/internal/database/tables/data_style.ts b/internal/database/tables/data_style.ts index 17886d23d..617c8f538 100644 --- a/internal/database/tables/data_style.ts +++ b/internal/database/tables/data_style.ts @@ -2,7 +2,7 @@ import type { TableDefinition } from "./table_definition"; const dataStyleTable: TableDefinition = { name: "data_style", - schema: "data_id", + schema: "[scene_id+data_id], scene_id", }; export { dataStyleTable }; diff --git a/internal/database/tables/model_component_datastyle.ts b/internal/database/tables/model_component_datastyle.ts index d232a73b7..868435a79 100644 --- a/internal/database/tables/model_component_datastyle.ts +++ b/internal/database/tables/model_component_datastyle.ts @@ -2,7 +2,7 @@ import type { TableDefinition } from "./table_definition"; const modelComponentDataStyleTable: TableDefinition = { name: "model_component_datastyle", - schema: "[id_model+id_component], id_model", + schema: "[scene_id+id_model+id_component], [scene_id+id_model]", }; export { modelComponentDataStyleTable }; diff --git a/internal/database/tables/model_component_type_datastyle.ts b/internal/database/tables/model_component_type_datastyle.ts index 0c9728db6..3d3dc91d3 100644 --- a/internal/database/tables/model_component_type_datastyle.ts +++ b/internal/database/tables/model_component_type_datastyle.ts @@ -2,7 +2,7 @@ import type { TableDefinition } from "./table_definition"; const modelComponentTypeDataStyleTable: TableDefinition = { name: "model_component_type_datastyle", - schema: "[id_model+type], id_model", + schema: "[scene_id+id_model+type], [scene_id+id_model]", }; export { modelComponentTypeDataStyleTable }; diff --git a/internal/database/tables/scene_style.ts b/internal/database/tables/scene_style.ts index 5da010672..1c67a037c 100644 --- a/internal/database/tables/scene_style.ts +++ b/internal/database/tables/scene_style.ts @@ -2,7 +2,7 @@ import type { TableDefinition } from "./table_definition"; const sceneStyleTable: TableDefinition = { name: "scene_style", - schema: "id", + schema: "scene_id", }; export { sceneStyleTable }; diff --git a/internal/database/tables/treeview_config.ts b/internal/database/tables/treeview_config.ts index ed557bf6e..0727842e8 100644 --- a/internal/database/tables/treeview_config.ts +++ b/internal/database/tables/treeview_config.ts @@ -1,4 +1,5 @@ import type { GeodeObjectTyped } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { TableDefinition } from "./table_definition"; interface OpenedView extends Partial { @@ -17,7 +18,7 @@ interface OpenedView extends Partial { } interface TreeviewConfigRecord { - id: string; + scene_id: SceneId; opened_views: OpenedView[]; panelWidth: number; additionalPanelWidth: number; @@ -27,7 +28,7 @@ interface TreeviewConfigRecord { const treeviewConfigTable: TableDefinition = { name: "treeview_config", - schema: "id", + schema: "scene_id", }; export { treeviewConfigTable }; From 24124823f68fd7dce5e3ceb6ad5cfc4e146aaff4 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:05:04 +0100 Subject: [PATCH 010/121] feat(data_style): scope shared style state by scene Each scene gets its own cached styles, read and written under its scene_id. The model selection cache is kept per scene. Co-Authored-By: Claude Opus 5.5 --- app/types/identifiers.ts | 2 + .../data_style/model/common_mutations.ts | 46 +++++++++++++------ internal/stores/data_style/model/selection.ts | 11 ++++- internal/stores/data_style/state.ts | 11 +++-- internal/stores/data_style/state_shared.ts | 25 +++++----- internal/stores/data_style/time_step.ts | 5 +- internal/stores/data_style/types.ts | 1 + 7 files changed, 65 insertions(+), 36 deletions(-) diff --git a/app/types/identifiers.ts b/app/types/identifiers.ts index a694caefd..b3e91f5f1 100644 --- a/app/types/identifiers.ts +++ b/app/types/identifiers.ts @@ -68,3 +68,5 @@ export type { SurfaceId, ViewerObjectTyped, }; +// A scene is identified like the data it shows +export type { SceneId } from "@ogw_internal/stores/scenes/types"; diff --git a/internal/stores/data_style/model/common_mutations.ts b/internal/stores/data_style/model/common_mutations.ts index 5209324a7..c2608de52 100644 --- a/internal/stores/data_style/model/common_mutations.ts +++ b/internal/stores/data_style/model/common_mutations.ts @@ -4,10 +4,12 @@ import type { StyleValues, } from "@ogw_internal/stores/data_style/types.js"; import { + type SceneKeyed, componentDataStyleDb, componentTypeDataStyleDb, writeTransaction, } from "@ogw_internal/database/database"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import merge from "lodash/merge"; import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; @@ -44,8 +46,8 @@ interface UseModelComponentsPerComponentStyleMutationReturn { ) => Promise; } -function useModelComponentStyleMutations(): UseModelComponentStyleMutationsReturn { - const dataStyleState = useDataStyleState(); +function useModelComponentStyleMutations(sceneId: SceneId): UseModelComponentStyleMutationsReturn { + const dataStyleState = useDataStyleState(sceneId); const componentDataStyleTable = componentDataStyleDb(); const componentTypeDataStyleTable = componentTypeDataStyleDb(); @@ -55,8 +57,9 @@ function useModelComponentStyleMutations(): UseModelComponentStyleMutationsRetur values: StyleValues, ): Promise { dataStyleState.updateComponentStyleCache(id_model, id_component, values); - const key: [string, string] = [id_model, id_component]; - const entry: ModelComponentStyle = (await componentDataStyleTable.get(key)) ?? { + const key: [SceneId, string, string] = [sceneId, id_model, id_component]; + const entry: SceneKeyed = (await componentDataStyleTable.get(key)) ?? { + scene_id: sceneId, id_model, id_component, }; @@ -71,8 +74,11 @@ function useModelComponentStyleMutations(): UseModelComponentStyleMutationsRetur ): Promise { dataStyleState.updateModelComponentTypeStyleCache(id_model, type, values); await writeTransaction([componentTypeDataStyleTable], async () => { - const key: [string, string] = [id_model, type]; - const entry: ModelComponentTypeStyle = (await componentTypeDataStyleTable.get(key)) ?? { + const key: [SceneId, string, string] = [sceneId, id_model, type]; + const entry: SceneKeyed = (await componentTypeDataStyleTable.get( + key, + )) ?? { + scene_id: sceneId, id_model, type, }; @@ -87,8 +93,8 @@ function useModelComponentStyleMutations(): UseModelComponentStyleMutationsRetur }; } -function useModelComponentsStyleMutation(): UseModelComponentsStyleMutationReturn { - const dataStyleState = useDataStyleState(); +function useModelComponentsStyleMutation(sceneId: SceneId): UseModelComponentsStyleMutationReturn { + const dataStyleState = useDataStyleState(sceneId); const componentDataStyleTable = componentDataStyleDb(); async function mutateComponentStyles( @@ -98,13 +104,18 @@ function useModelComponentsStyleMutation(): UseModelComponentsStyleMutationRetur ): Promise { dataStyleState.bulkUpdateComponentStylesCache(id_model, id_components, values); await writeTransaction([componentDataStyleTable], async () => { - const keys: [string, string][] = id_components.map((id_component) => [ + const keys: [SceneId, string, string][] = id_components.map((id_component) => [ + sceneId, id_model, id_component, ]); const existing = await componentDataStyleTable.bulkGet(keys); const updates = id_components.map((id_component, index) => { - const style: ModelComponentStyle = existing[index] ?? { id_model, id_component }; + const style: SceneKeyed = existing[index] ?? { + scene_id: sceneId, + id_model, + id_component, + }; merge(style, values); return toRaw(style); }); @@ -118,8 +129,10 @@ function useModelComponentsStyleMutation(): UseModelComponentsStyleMutationRetur }; } -function useModelComponentsPerComponentStyleMutation(): UseModelComponentsPerComponentStyleMutationReturn { - const dataStyleState = useDataStyleState(); +function useModelComponentsPerComponentStyleMutation( + sceneId: SceneId, +): UseModelComponentsPerComponentStyleMutationReturn { + const dataStyleState = useDataStyleState(sceneId); const componentDataStyleTable = componentDataStyleDb(); async function bulkMutateComponentStylesPerComponent( @@ -128,13 +141,18 @@ function useModelComponentsPerComponentStyleMutation(): UseModelComponentsPerCom ): Promise { dataStyleState.bulkUpdateComponentStyleCache(id_model, component_updates); await writeTransaction([componentDataStyleTable], async () => { - const keys: [string, string][] = component_updates.map((update) => [ + const keys: [SceneId, string, string][] = component_updates.map((update) => [ + sceneId, id_model, update.id_component, ]); const existing = await componentDataStyleTable.bulkGet(keys); const updates = component_updates.map(({ id_component, values }, index) => { - const style: ModelComponentStyle = existing[index] ?? { id_model, id_component }; + const style: SceneKeyed = existing[index] ?? { + scene_id: sceneId, + id_model, + id_component, + }; merge(style, values); return toRaw(style); }); diff --git a/internal/stores/data_style/model/selection.ts b/internal/stores/data_style/model/selection.ts index 986cb2a23..406e4cd10 100644 --- a/internal/stores/data_style/model/selection.ts +++ b/internal/stores/data_style/model/selection.ts @@ -1,8 +1,10 @@ import type { ModelId, ModelIdentified } from "@ogw_front/types/identifiers"; import { MESH_COMPONENT_TYPES } from "@ogw_front/utils/default_styles"; import type { ModelComponentRecord } from "@ogw_internal/stores/data/model/mesh_components"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import { modelComponentsOf } from "@ogw_internal/database/queries"; +import { runInSceneScope } from "@ogw_internal/stores/scenes/scene_scope"; import type { useDataStyleState } from "@ogw_internal/stores/data_style/state"; type DataStyleState = ReturnType; @@ -86,9 +88,8 @@ function buildSelection( return selection; } -const selectionCache = new Map>(); - function useModelSelection( + sceneId: SceneId, modelId: ModelId | undefined, dataStyleState: DataStyleState, ): ComputedRef { @@ -96,6 +97,12 @@ function useModelSelection( return computed(() => []); } + // Each scene caches the selections of its own styles + const selectionCache = runInSceneScope( + sceneId, + "modelSelection", + () => new Map>(), + ); const cacheKey = modelId; const cachedSelection = selectionCache.get(cacheKey); if (cachedSelection !== undefined) { diff --git a/internal/stores/data_style/state.ts b/internal/stores/data_style/state.ts index cdf27e5d5..b4e907929 100644 --- a/internal/stores/data_style/state.ts +++ b/internal/stores/data_style/state.ts @@ -12,6 +12,7 @@ import { sceneStyleDb, } from "@ogw_internal/database/database"; import type { ModelId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { getDefaultSceneStyle } from "@ogw_front/utils/default_styles"; import merge from "lodash/merge"; @@ -26,12 +27,12 @@ interface DataStyleStateApi extends SharedState { } // oxlint-disable-next-line max-lines-per-function -export function useDataStyleState(): DataStyleStateApi { +export function useDataStyleState(sceneId: SceneId): DataStyleStateApi { const dataStyleTable = dataStyleDb(); const modelComponentDataStyleTable = componentDataStyleDb(); const modelComponentTypeDataStyleTable = componentTypeDataStyleDb(); - const state = getSharedState(); + const state = getSharedState(sceneId); const { styles, modelComponentTypeStyles, componentStyles } = state; const objectVisibility = computed(() => (objectId: string): boolean | undefined => { @@ -64,10 +65,10 @@ export function useDataStyleState(): DataStyleStateApi { state.updateStyleCache(objectId, styleValues); const currentStyle = getStyle(objectId); merge(currentStyle, styleValues); - const savedId = await dataStyleTable.put( - structuredClone({ ...toRaw(currentStyle), data_id: objectId }), + await dataStyleTable.put( + structuredClone({ ...toRaw(currentStyle), data_id: objectId, scene_id: sceneId }), ); - return savedId; + return objectId; } function getComponentStyle(modelId: ModelId, componentId: string): ModelComponentStyle { diff --git a/internal/stores/data_style/state_shared.ts b/internal/stores/data_style/state_shared.ts index d6928e97b..4472917bc 100644 --- a/internal/stores/data_style/state_shared.ts +++ b/internal/stores/data_style/state_shared.ts @@ -13,9 +13,11 @@ import { } from "@ogw_internal/database/database"; import type { ModelId } from "@ogw_front/types/identifiers"; import type { Observable as RxObservable } from "rxjs"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { getDefaultSceneStyle } from "@ogw_front/utils/default_styles"; import { liveQuery } from "dexie"; import merge from "lodash/merge"; +import { runInSceneScope } from "@ogw_internal/stores/scenes/scene_scope"; import { useObservable } from "@vueuse/rxjs"; interface SharedState { @@ -49,14 +51,8 @@ interface SharedState { updateStyleCache: (objectId: string, styleValues: StyleValues) => void; } -let sharedState: SharedState | undefined = undefined; - // oxlint-disable-next-line max-lines-per-function -function getSharedState(): SharedState { - if (sharedState) { - return sharedState; - } - +function createSharedState(sceneId: SceneId): SharedState { const dataStyleTable = dataStyleDb(); const modelComponentDataStyleTable = componentDataStyleDb(); const modelComponentTypeDataStyleTable = componentTypeDataStyleDb(); @@ -65,7 +61,7 @@ function getSharedState(): SharedState { // From rxjs's `Observable` that `useObservable` (from @vueuse/rxjs) expects, even // Though they're interoperable at runtime (both are plain subscribe-based streams). const dataStyleLiveQuery = liveQuery(async () => { - const objectStyles = await dataStyleTable.toArray(); + const objectStyles = await dataStyleTable.where("scene_id").equals(sceneId).toArray(); const stylesByObjectId: Record = {}; for (const objectStyle of objectStyles) { stylesByObjectId[objectStyle.data_id] = objectStyle; @@ -86,9 +82,9 @@ function getSharedState(): SharedState { async function loadFromDatabase(): Promise { const [fetchedTypeStyles, fetchedComponentStyles, fetchedSceneStyle] = await Promise.all([ - modelComponentTypeDataStyleTable.toArray(), - modelComponentDataStyleTable.toArray(), - sceneStyleTable.get("scene"), + modelComponentTypeDataStyleTable.where("scene_id").equals(sceneId).toArray(), + modelComponentDataStyleTable.where("scene_id").equals(sceneId).toArray(), + sceneStyleTable.get(sceneId), ]); sceneStyle.value = fetchedSceneStyle ?? getDefaultSceneStyle(); const typeStylesMap: Record = {}; @@ -184,7 +180,7 @@ function getSharedState(): SharedState { merge(styles.value[objectId], styleValues); } - sharedState = { + return { styles, modelComponentTypeStyles, componentStyles, @@ -196,8 +192,11 @@ function getSharedState(): SharedState { updateModelComponentTypeStyleCache, updateStyleCache, }; +} - return sharedState; +// One state per scene: the same data can be styled differently in two scenes +function getSharedState(sceneId: SceneId): SharedState { + return runInSceneScope(sceneId, "dataStyleShared", () => createSharedState(sceneId)); } export { getSharedState }; export type { SharedState }; diff --git a/internal/stores/data_style/time_step.ts b/internal/stores/data_style/time_step.ts index 56abab868..794038e94 100644 --- a/internal/stores/data_style/time_step.ts +++ b/internal/stores/data_style/time_step.ts @@ -1,6 +1,7 @@ import type { AttributeName } from "@geode/opengeodeweb-viewer/schema_types"; import type { AttributeTimeStep } from "@ogw_front/types/attribute"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { attributeArrayName } from "@ogw_front/utils/attributes"; import { useDataStyleState } from "./state"; @@ -45,8 +46,8 @@ async function reapplySameSeries( // The key of a series is a schema $id: the back attribute names schema for meshes // (cards share a step), the viewer attribute schema for models (one step per component type) -function useAttributeTimeStepStyle(): UseAttributeTimeStepStyleReturn { - const dataStyleState = useDataStyleState(); +function useAttributeTimeStepStyle(sceneId: SceneId): UseAttributeTimeStepStyleReturn { + const dataStyleState = useDataStyleState(sceneId); function attributeTimeStep( dataId: DataId, diff --git a/internal/stores/data_style/types.ts b/internal/stores/data_style/types.ts index 285eb2e4a..1ff331367 100644 --- a/internal/stores/data_style/types.ts +++ b/internal/stores/data_style/types.ts @@ -52,3 +52,4 @@ export type { SceneStyle, StyleValues, }; +export type { SceneId } from "@ogw_front/types/identifiers"; From 52ceb50c2881771217da5cebdfaf975e68bdfcbf Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:05:04 +0100 Subject: [PATCH 011/121] feat(data_style): scope mesh styles by scene Co-Authored-By: Claude Opus 5.5 --- internal/stores/data_style/mesh/base_style.ts | 9 +++++---- internal/stores/data_style/mesh/cells/cell.ts | 13 +++++++----- .../data_style/mesh/cells/cell_config.ts | 17 ++++++++++------ .../stores/data_style/mesh/cells/color.ts | 11 ++++++---- .../stores/data_style/mesh/cells/common.ts | 5 +++-- .../stores/data_style/mesh/cells/index.ts | 15 +++++++------- .../stores/data_style/mesh/cells/opacity.ts | 7 ++++--- .../stores/data_style/mesh/cells/textures.ts | 7 ++++--- .../stores/data_style/mesh/cells/vertex.ts | 15 +++++++++----- .../data_style/mesh/cells/vertex_config.ts | 19 ++++++++++++------ .../data_style/mesh/cells/visibility.ts | 7 ++++--- .../stores/data_style/mesh/edges/color.ts | 11 ++++++---- .../stores/data_style/mesh/edges/common.ts | 5 +++-- internal/stores/data_style/mesh/edges/edge.ts | 13 +++++++----- .../data_style/mesh/edges/edge_config.ts | 17 ++++++++++------ .../stores/data_style/mesh/edges/index.ts | 15 +++++++------- .../stores/data_style/mesh/edges/opacity.ts | 7 ++++--- .../stores/data_style/mesh/edges/vertex.ts | 15 +++++++++----- .../data_style/mesh/edges/vertex_config.ts | 19 ++++++++++++------ .../data_style/mesh/edges/visibility.ts | 7 ++++--- .../stores/data_style/mesh/edges/width.ts | 7 ++++--- internal/stores/data_style/mesh/index.ts | 20 ++++++++++--------- .../stores/data_style/mesh/points/color.ts | 11 ++++++---- .../stores/data_style/mesh/points/common.ts | 5 +++-- .../stores/data_style/mesh/points/index.ts | 13 ++++++------ .../stores/data_style/mesh/points/opacity.ts | 7 ++++--- .../stores/data_style/mesh/points/size.ts | 7 ++++--- .../stores/data_style/mesh/points/vertex.ts | 15 +++++++++----- .../data_style/mesh/points/vertex_config.ts | 19 ++++++++++++------ .../data_style/mesh/points/visibility.ts | 7 ++++--- .../stores/data_style/mesh/polygons/color.ts | 11 ++++++---- .../stores/data_style/mesh/polygons/common.ts | 5 +++-- .../stores/data_style/mesh/polygons/index.ts | 15 +++++++------- .../data_style/mesh/polygons/opacity.ts | 7 ++++--- .../data_style/mesh/polygons/polygon.ts | 15 +++++++++----- .../mesh/polygons/polygon_config.ts | 19 ++++++++++++------ .../data_style/mesh/polygons/textures.ts | 7 ++++--- .../stores/data_style/mesh/polygons/vertex.ts | 15 +++++++++----- .../data_style/mesh/polygons/vertex_config.ts | 19 ++++++++++++------ .../data_style/mesh/polygons/visibility.ts | 7 ++++--- .../stores/data_style/mesh/polyhedra/color.ts | 11 ++++++---- .../data_style/mesh/polyhedra/common.ts | 5 +++-- .../stores/data_style/mesh/polyhedra/index.ts | 13 ++++++------ .../data_style/mesh/polyhedra/opacity.ts | 7 ++++--- .../data_style/mesh/polyhedra/polyhedron.ts | 15 +++++++++----- .../mesh/polyhedra/polyhedron_config.ts | 19 ++++++++++++------ .../data_style/mesh/polyhedra/vertex.ts | 15 +++++++++----- .../mesh/polyhedra/vertex_config.ts | 19 ++++++++++++------ .../data_style/mesh/polyhedra/visibility.ts | 7 ++++--- 49 files changed, 359 insertions(+), 217 deletions(-) diff --git a/internal/stores/data_style/mesh/base_style.ts b/internal/stores/data_style/mesh/base_style.ts index 2957a95dc..1db2497ee 100644 --- a/internal/stores/data_style/mesh/base_style.ts +++ b/internal/stores/data_style/mesh/base_style.ts @@ -1,5 +1,6 @@ import type { ColorRGBA, Visibility } from "@geode/opengeodeweb-viewer/schema_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -19,17 +20,17 @@ interface MeshBaseStyle { setMeshColor: (meshId: MeshId, color: ColorRGBA) => Promise; } -export function useMeshBaseStyle(): MeshBaseStyle { +export function useMeshBaseStyle(sceneId: SceneId): MeshBaseStyle { const hybridViewerStore = useHybridViewerStore(); const viewerStore = useViewerStore(); - const dataStyleState = useDataStyleState(); + const dataStyleState = useDataStyleState(sceneId); function meshVisibility(meshId: MeshId): Visibility | undefined { return dataStyleState.getStyle(meshId).visibility; } async function setMeshVisibility(meshId: MeshId, visibility: Visibility): Promise { const schema = meshSchemas.visibility; - const params = { id: meshId, visibility }; + const params = { scene_id: sceneId, id: meshId, visibility }; const result = await viewerStore.request( { schema, @@ -55,7 +56,7 @@ export function useMeshBaseStyle(): MeshBaseStyle { async function setMeshColor(meshId: MeshId, color: ColorRGBA): Promise { const schema = meshSchemas.color; - const params = { id: meshId, color }; + const params = { scene_id: sceneId, id: meshId, color }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/cells/cell.ts b/internal/stores/data_style/mesh/cells/cell.ts index dab640927..c95b04aaa 100644 --- a/internal/stores/data_style/mesh/cells/cell.ts +++ b/internal/stores/data_style/mesh/cells/cell.ts @@ -8,6 +8,7 @@ import type { } from "@geode/opengeodeweb-viewer/schema_types"; import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attribute_types"; // Third party imports import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; @@ -30,8 +31,9 @@ const attributeNamesSchema = back_schemas.opengeodeweb_back.cell_attribute_names const meshCellsCellAttributeSchemas = viewer_schemas.opengeodeweb_viewer.mesh.cells.attribute.cell; // oxlint-disable-next-line max-lines-per-function -function useMeshCellsCellAttributeStyle(): UseMeshCellsCellAttributeStyleReturn { - const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useMeshCellsCellAttributeStyle(sceneId: SceneId): UseMeshCellsCellAttributeStyleReturn { + const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = + useAttributeTimeStepStyle(sceneId); const viewerStore = useViewerStore(); const { meshCellsCellAttribute, @@ -39,14 +41,14 @@ function useMeshCellsCellAttributeStyle(): UseMeshCellsCellAttributeStyleReturn meshCellsCellAttributeLastItem, meshCellsCellAttributeItem, meshCellsCellAttributeStoredConfig, - } = useMeshCellsCellAttributeConfig(); + } = useMeshCellsCellAttributeConfig(sceneId); const { meshCellsCellAttributeRange, meshCellsCellAttributeColorMap, meshCellsCellAttributeNoDataColor, - } = useMeshCellsCellAttributeConfigValues(); + } = useMeshCellsCellAttributeConfigValues(sceneId); const { mutateMeshCellsCellStyle, setMeshCellsCellAttributeStoredConfig } = - useMeshCellsCellAttributeConfigWriter(); + useMeshCellsCellAttributeConfigWriter(sceneId); function meshCellsCellAttributeTimeStep(meshId: MeshId): AttributeTimeStep | undefined { return attributeTimeStep(meshId, attributeNamesSchema.$id, meshCellsCellAttribute(meshId).name); } @@ -74,6 +76,7 @@ function useMeshCellsCellAttributeStyle(): UseMeshCellsCellAttributeStyleReturn const points = [...getRGBPointsFromPreset(colorMap)]; const schema = meshCellsCellAttributeSchemas.attribute; const params = { + scene_id: sceneId, id: meshId, name: seriesArrayName(meshId, attributeNamesSchema.$id, name), item, diff --git a/internal/stores/data_style/mesh/cells/cell_config.ts b/internal/stores/data_style/mesh/cells/cell_config.ts index 54793fdb7..17e00aefd 100644 --- a/internal/stores/data_style/mesh/cells/cell_config.ts +++ b/internal/stores/data_style/mesh/cells/cell_config.ts @@ -9,6 +9,7 @@ import type { AttributeStoredConfig, } from "@ogw_internal/stores/data_style/attribute_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { defaultAttributeStoredConfig } from "@ogw_internal/stores/data_style/attribute_default"; // Local imports @@ -36,8 +37,8 @@ interface UseMeshCellsCellAttributeConfigWriterReturn { ) => Promise; } -function useMeshCellsCellAttributeConfig(): UseMeshCellsCellAttributeConfigReturn { - const meshCellsCommonStyle = useMeshCellsCommonStyle(); +function useMeshCellsCellAttributeConfig(sceneId: SceneId): UseMeshCellsCellAttributeConfigReturn { + const meshCellsCommonStyle = useMeshCellsCommonStyle(sceneId); function meshCellsCellAttribute(meshId: MeshId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.cell shape is defined by the data style schema. return meshCellsCommonStyle.meshCellsColoring(meshId).cell as AttributeState; @@ -85,12 +86,14 @@ interface UseMeshCellsCellAttributeConfigValuesReturn { meshCellsCellAttributeNoDataColor: (meshId: MeshId) => ColorRGBA; } -function useMeshCellsCellAttributeConfigValues(): UseMeshCellsCellAttributeConfigValuesReturn { +function useMeshCellsCellAttributeConfigValues( + sceneId: SceneId, +): UseMeshCellsCellAttributeConfigValuesReturn { const { meshCellsCellAttributeName, meshCellsCellAttributeItem, meshCellsCellAttributeStoredConfig, - } = useMeshCellsCellAttributeConfig(); + } = useMeshCellsCellAttributeConfig(sceneId); function meshCellsCellAttributeRange(meshId: MeshId): AttributeRange { const name = meshCellsCellAttributeName(meshId); const item = meshCellsCellAttributeItem(meshId); @@ -116,8 +119,10 @@ function useMeshCellsCellAttributeConfigValues(): UseMeshCellsCellAttributeConfi }; } -function useMeshCellsCellAttributeConfigWriter(): UseMeshCellsCellAttributeConfigWriterReturn { - const meshCellsCommonStyle = useMeshCellsCommonStyle(); +function useMeshCellsCellAttributeConfigWriter( + sceneId: SceneId, +): UseMeshCellsCellAttributeConfigWriterReturn { + const meshCellsCommonStyle = useMeshCellsCommonStyle(sceneId); async function mutateMeshCellsCellStyle( meshId: MeshId, values: Record, diff --git a/internal/stores/data_style/mesh/cells/color.ts b/internal/stores/data_style/mesh/cells/color.ts index b91547f85..74ef3ab0e 100644 --- a/internal/stores/data_style/mesh/cells/color.ts +++ b/internal/stores/data_style/mesh/cells/color.ts @@ -1,5 +1,6 @@ import type { ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -11,19 +12,21 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.cells.color; -export function useMeshCellsColorStyle(): ReturnType & { +export function useMeshCellsColorStyle(sceneId: SceneId): ReturnType< + typeof useMeshCellsOpacityStyle +> & { meshCellsColor: (meshId: MeshId) => ColorRGBA | undefined; setMeshCellsColor: (meshId: MeshId, color: ColorRGBA) => Promise; } { const viewerStore = useViewerStore(); - const meshCellsCommonStyle = useMeshCellsCommonStyle(); + const meshCellsCommonStyle = useMeshCellsCommonStyle(sceneId); function meshCellsColor(meshId: MeshId): ColorRGBA | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.constant shape is defined by the data style schema. return meshCellsCommonStyle.meshCellsColoring(meshId).constant as ColorRGBA | undefined; } async function setMeshCellsColor(meshId: MeshId, color: ColorRGBA): Promise { - const params = { id: meshId, color }; + const params = { scene_id: sceneId, id: meshId, color }; const result = await viewerStore.request( { schema, @@ -44,6 +47,6 @@ export function useMeshCellsColorStyle(): ReturnType StyleValues; meshCellsColoring: (meshId: MeshId) => StyleValues; mutateMeshCellsStyle: (meshId: MeshId, values: StyleValues) => Promise; mutateMeshCellsColoring: (meshId: MeshId, values: StyleValues) => Promise; mutateMeshCellsCellStyle: (meshId: MeshId, values: StyleValues) => Promise; } { - const dataStyleState = useDataStyleState(); + const dataStyleState = useDataStyleState(sceneId); async function mutateMeshCellsStyle(meshId: MeshId, values: StyleValues): Promise { const result = await dataStyleState.mutateStyle(meshId, { diff --git a/internal/stores/data_style/mesh/cells/index.ts b/internal/stores/data_style/mesh/cells/index.ts index fd0a0a32d..b6a2f1371 100644 --- a/internal/stores/data_style/mesh/cells/index.ts +++ b/internal/stores/data_style/mesh/cells/index.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports // Local imports @@ -132,13 +133,13 @@ type UseMeshCellsStyleReturn = ReturnType & { ReturnType & ReturnType; -export function useMeshCellsStyle(): UseMeshCellsStyleReturn { - const meshCellsCommonStyle = useMeshCellsCommonStyle(); - const meshCellsVisibility = useMeshCellsVisibilityStyle(); - const meshCellsColorStyle = useMeshCellsColorStyle(); - const meshCellsTexturesStore = useMeshCellsTexturesStyle(); - const meshCellsVertexAttributeStyle = useMeshCellsVertexAttributeStyle(); - const meshCellsCellAttributeStyle = useMeshCellsCellAttributeStyle(); +export function useMeshCellsStyle(sceneId: SceneId): UseMeshCellsStyleReturn { + const meshCellsCommonStyle = useMeshCellsCommonStyle(sceneId); + const meshCellsVisibility = useMeshCellsVisibilityStyle(sceneId); + const meshCellsColorStyle = useMeshCellsColorStyle(sceneId); + const meshCellsTexturesStore = useMeshCellsTexturesStyle(sceneId); + const meshCellsVertexAttributeStyle = useMeshCellsVertexAttributeStyle(sceneId); + const meshCellsCellAttributeStyle = useMeshCellsCellAttributeStyle(sceneId); const activeColoringDeps: MeshCellsActiveColoringDeps = { commonStyle: meshCellsCommonStyle, diff --git a/internal/stores/data_style/mesh/cells/opacity.ts b/internal/stores/data_style/mesh/cells/opacity.ts index eb0c210f1..cde7b7550 100644 --- a/internal/stores/data_style/mesh/cells/opacity.ts +++ b/internal/stores/data_style/mesh/cells/opacity.ts @@ -1,5 +1,6 @@ import type { ColorRGBA, Opacity } from "@geode/opengeodeweb-viewer/schema_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -11,12 +12,12 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; const schema = viewer_schemas.opengeodeweb_viewer.mesh.cells.opacity; // The opacity is the constant color alpha, the viewer applies it whatever the coloring -export function useMeshCellsOpacityStyle(): { +export function useMeshCellsOpacityStyle(sceneId: SceneId): { meshCellsOpacity: (meshId: MeshId) => Opacity | undefined; setMeshCellsOpacity: (meshId: MeshId, opacity: Opacity) => Promise; } { const viewerStore = useViewerStore(); - const meshCellsCommonStyle = useMeshCellsCommonStyle(); + const meshCellsCommonStyle = useMeshCellsCommonStyle(sceneId); function meshCellsConstantColor(meshId: MeshId): ColorRGBA | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.constant shape is defined by the data style schema. @@ -26,7 +27,7 @@ export function useMeshCellsOpacityStyle(): { return meshCellsConstantColor(meshId)?.alpha; } async function setMeshCellsOpacity(meshId: MeshId, opacity: Opacity): Promise { - const params = { id: meshId, opacity }; + const params = { scene_id: sceneId, id: meshId, opacity }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/cells/textures.ts b/internal/stores/data_style/mesh/cells/textures.ts index c30b366bd..e0dfc143c 100644 --- a/internal/stores/data_style/mesh/cells/textures.ts +++ b/internal/stores/data_style/mesh/cells/textures.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas, { type MeshApplyTexturesParams, @@ -11,7 +12,7 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.apply_textures; -export function useMeshCellsTexturesStyle(): { +export function useMeshCellsTexturesStyle(sceneId: SceneId): { meshCellsTextures: (meshId: MeshId) => MeshApplyTexturesParams["textures"] | undefined; setMeshCellsTextures: ( meshId: MeshId, @@ -19,7 +20,7 @@ export function useMeshCellsTexturesStyle(): { ) => Promise; } { const viewerStore = useViewerStore(); - const meshCellsCommonStyle = useMeshCellsCommonStyle(); + const meshCellsCommonStyle = useMeshCellsCommonStyle(sceneId); function meshCellsTextures(meshId: MeshId): MeshApplyTexturesParams["textures"] | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- textures shape is defined by the data style schema. @@ -31,7 +32,7 @@ export function useMeshCellsTexturesStyle(): { meshId: MeshId, textures: MeshApplyTexturesParams["textures"], ): Promise { - const params = { id: meshId, textures }; + const params = { scene_id: sceneId, id: meshId, textures }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/cells/vertex.ts b/internal/stores/data_style/mesh/cells/vertex.ts index 25f22d033..8aaee95cd 100644 --- a/internal/stores/data_style/mesh/cells/vertex.ts +++ b/internal/stores/data_style/mesh/cells/vertex.ts @@ -8,6 +8,7 @@ import type { } from "@geode/opengeodeweb-viewer/schema_types"; import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attribute_types"; // Third party imports import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; @@ -31,8 +32,11 @@ const meshCellsVertexAttributeSchemas = viewer_schemas.opengeodeweb_viewer.mesh.cells.attribute.vertex; // oxlint-disable-next-line max-lines-per-function -function useMeshCellsVertexAttributeStyle(): UseMeshCellsVertexAttributeStyleReturn { - const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useMeshCellsVertexAttributeStyle( + sceneId: SceneId, +): UseMeshCellsVertexAttributeStyleReturn { + const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = + useAttributeTimeStepStyle(sceneId); const viewerStore = useViewerStore(); const { meshCellsVertexAttribute, @@ -40,14 +44,14 @@ function useMeshCellsVertexAttributeStyle(): UseMeshCellsVertexAttributeStyleRet meshCellsVertexAttributeLastItem, meshCellsVertexAttributeItem, meshCellsVertexAttributeStoredConfig, - } = useMeshCellsVertexAttributeConfig(); + } = useMeshCellsVertexAttributeConfig(sceneId); const { meshCellsVertexAttributeRange, meshCellsVertexAttributeColorMap, meshCellsVertexAttributeNoDataColor, - } = useMeshCellsVertexAttributeConfigValues(); + } = useMeshCellsVertexAttributeConfigValues(sceneId); const { mutateMeshCellsVertexStyle, setMeshCellsVertexAttributeStoredConfig } = - useMeshCellsVertexAttributeConfigWriter(); + useMeshCellsVertexAttributeConfigWriter(sceneId); function meshCellsVertexAttributeTimeStep(meshId: MeshId): AttributeTimeStep | undefined { return attributeTimeStep( meshId, @@ -79,6 +83,7 @@ function useMeshCellsVertexAttributeStyle(): UseMeshCellsVertexAttributeStyleRet const points = [...getRGBPointsFromPreset(colorMap)]; const schema = meshCellsVertexAttributeSchemas.attribute; const params = { + scene_id: sceneId, id: meshId, name: seriesArrayName(meshId, attributeNamesSchema.$id, name), item, diff --git a/internal/stores/data_style/mesh/cells/vertex_config.ts b/internal/stores/data_style/mesh/cells/vertex_config.ts index e7c162dc5..eb9a1e925 100644 --- a/internal/stores/data_style/mesh/cells/vertex_config.ts +++ b/internal/stores/data_style/mesh/cells/vertex_config.ts @@ -9,6 +9,7 @@ import type { AttributeStoredConfig, } from "@ogw_internal/stores/data_style/attribute_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { defaultAttributeStoredConfig } from "@ogw_internal/stores/data_style/attribute_default"; // Local imports @@ -36,8 +37,10 @@ interface UseMeshCellsVertexAttributeConfigWriterReturn { ) => Promise; } -function useMeshCellsVertexAttributeConfig(): UseMeshCellsVertexAttributeConfigReturn { - const meshCellsCommonStyle = useMeshCellsCommonStyle(); +function useMeshCellsVertexAttributeConfig( + sceneId: SceneId, +): UseMeshCellsVertexAttributeConfigReturn { + const meshCellsCommonStyle = useMeshCellsCommonStyle(sceneId); function meshCellsVertexAttribute(meshId: MeshId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.vertex shape is defined by the data style schema. return meshCellsCommonStyle.meshCellsColoring(meshId).vertex as AttributeState; @@ -88,12 +91,14 @@ interface UseMeshCellsVertexAttributeConfigValuesReturn { meshCellsVertexAttributeNoDataColor: (meshId: MeshId) => ColorRGBA; } -function useMeshCellsVertexAttributeConfigValues(): UseMeshCellsVertexAttributeConfigValuesReturn { +function useMeshCellsVertexAttributeConfigValues( + sceneId: SceneId, +): UseMeshCellsVertexAttributeConfigValuesReturn { const { meshCellsVertexAttributeName, meshCellsVertexAttributeItem, meshCellsVertexAttributeStoredConfig, - } = useMeshCellsVertexAttributeConfig(); + } = useMeshCellsVertexAttributeConfig(sceneId); function meshCellsVertexAttributeRange(meshId: MeshId): AttributeRange { const name = meshCellsVertexAttributeName(meshId); const item = meshCellsVertexAttributeItem(meshId); @@ -119,8 +124,10 @@ function useMeshCellsVertexAttributeConfigValues(): UseMeshCellsVertexAttributeC }; } -function useMeshCellsVertexAttributeConfigWriter(): UseMeshCellsVertexAttributeConfigWriterReturn { - const meshCellsCommonStyle = useMeshCellsCommonStyle(); +function useMeshCellsVertexAttributeConfigWriter( + sceneId: SceneId, +): UseMeshCellsVertexAttributeConfigWriterReturn { + const meshCellsCommonStyle = useMeshCellsCommonStyle(sceneId); async function mutateMeshCellsVertexStyle( meshId: MeshId, values: Record, diff --git a/internal/stores/data_style/mesh/cells/visibility.ts b/internal/stores/data_style/mesh/cells/visibility.ts index 3e58499bf..d62235459 100644 --- a/internal/stores/data_style/mesh/cells/visibility.ts +++ b/internal/stores/data_style/mesh/cells/visibility.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -10,19 +11,19 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.cells.visibility; -export function useMeshCellsVisibilityStyle(): { +export function useMeshCellsVisibilityStyle(sceneId: SceneId): { meshCellsVisibility: (meshId: MeshId) => Visibility | undefined; setMeshCellsVisibility: (meshId: MeshId, visibility: Visibility) => Promise; } { const viewerStore = useViewerStore(); - const meshCellsCommonStyle = useMeshCellsCommonStyle(); + const meshCellsCommonStyle = useMeshCellsCommonStyle(sceneId); function meshCellsVisibility(meshId: MeshId): Visibility | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- visibility is defined as boolean in the data style schema. return meshCellsCommonStyle.meshCellsStyle(meshId).visibility as Visibility | undefined; } async function setMeshCellsVisibility(meshId: MeshId, visibility: Visibility): Promise { - const params = { id: meshId, visibility }; + const params = { scene_id: sceneId, id: meshId, visibility }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/edges/color.ts b/internal/stores/data_style/mesh/edges/color.ts index 9ceb3ebeb..4c60db4e7 100644 --- a/internal/stores/data_style/mesh/edges/color.ts +++ b/internal/stores/data_style/mesh/edges/color.ts @@ -1,5 +1,6 @@ import type { ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -11,19 +12,21 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.edges.color; -export function useMeshEdgesColorStyle(): ReturnType & { +export function useMeshEdgesColorStyle(sceneId: SceneId): ReturnType< + typeof useMeshEdgesOpacityStyle +> & { meshEdgesColor: (meshId: MeshId) => ColorRGBA | undefined; setMeshEdgesColor: (meshId: MeshId, color: ColorRGBA) => Promise; } { const viewerStore = useViewerStore(); - const meshEdgesCommonStyle = useMeshEdgesCommonStyle(); + const meshEdgesCommonStyle = useMeshEdgesCommonStyle(sceneId); function meshEdgesColor(meshId: MeshId): ColorRGBA | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.constant shape is defined by the data style schema. return meshEdgesCommonStyle.meshEdgesColoring(meshId).constant as ColorRGBA | undefined; } async function setMeshEdgesColor(meshId: MeshId, color: ColorRGBA): Promise { - const params = { id: meshId, color }; + const params = { scene_id: sceneId, id: meshId, color }; const result = await viewerStore.request( { schema, @@ -44,6 +47,6 @@ export function useMeshEdgesColorStyle(): ReturnType StyleValues; meshEdgesColoring: (meshId: MeshId) => StyleValues; mutateMeshEdgesStyle: (meshId: MeshId, values: StyleValues) => Promise; mutateMeshEdgesColoring: (meshId: MeshId, values: StyleValues) => Promise; } { - const dataStyleState = useDataStyleState(); + const dataStyleState = useDataStyleState(sceneId); async function mutateMeshEdgesStyle(meshId: MeshId, values: StyleValues): Promise { const result = await dataStyleState.mutateStyle(meshId, { diff --git a/internal/stores/data_style/mesh/edges/edge.ts b/internal/stores/data_style/mesh/edges/edge.ts index a2115fbcc..8cdf00937 100644 --- a/internal/stores/data_style/mesh/edges/edge.ts +++ b/internal/stores/data_style/mesh/edges/edge.ts @@ -8,6 +8,7 @@ import type { } from "@geode/opengeodeweb-viewer/schema_types"; import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attribute_types"; // Third party imports import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; @@ -30,8 +31,9 @@ const attributeNamesSchema = back_schemas.opengeodeweb_back.edge_attribute_names const meshEdgesEdgeAttributeSchemas = viewer_schemas.opengeodeweb_viewer.mesh.edges.attribute.edge; // oxlint-disable-next-line max-lines-per-function -function useMeshEdgesEdgeAttributeStyle(): UseMeshEdgesEdgeAttributeStyleReturn { - const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useMeshEdgesEdgeAttributeStyle(sceneId: SceneId): UseMeshEdgesEdgeAttributeStyleReturn { + const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = + useAttributeTimeStepStyle(sceneId); const viewerStore = useViewerStore(); const { meshEdgesEdgeAttribute, @@ -39,14 +41,14 @@ function useMeshEdgesEdgeAttributeStyle(): UseMeshEdgesEdgeAttributeStyleReturn meshEdgesEdgeAttributeLastItem, meshEdgesEdgeAttributeItem, meshEdgesEdgeAttributeStoredConfig, - } = useMeshEdgesEdgeAttributeConfig(); + } = useMeshEdgesEdgeAttributeConfig(sceneId); const { meshEdgesEdgeAttributeRange, meshEdgesEdgeAttributeColorMap, meshEdgesEdgeAttributeNoDataColor, - } = useMeshEdgesEdgeAttributeConfigValues(); + } = useMeshEdgesEdgeAttributeConfigValues(sceneId); const { mutateMeshEdgesEdgeStyle, setMeshEdgesEdgeAttributeStoredConfig } = - useMeshEdgesEdgeAttributeConfigWriter(); + useMeshEdgesEdgeAttributeConfigWriter(sceneId); function meshEdgesEdgeAttributeTimeStep(meshId: MeshId): AttributeTimeStep | undefined { return attributeTimeStep(meshId, attributeNamesSchema.$id, meshEdgesEdgeAttribute(meshId).name); } @@ -74,6 +76,7 @@ function useMeshEdgesEdgeAttributeStyle(): UseMeshEdgesEdgeAttributeStyleReturn const points = [...getRGBPointsFromPreset(colorMap)]; const schema = meshEdgesEdgeAttributeSchemas.attribute; const params = { + scene_id: sceneId, id: meshId, name: seriesArrayName(meshId, attributeNamesSchema.$id, name), item, diff --git a/internal/stores/data_style/mesh/edges/edge_config.ts b/internal/stores/data_style/mesh/edges/edge_config.ts index ecf49f5e8..9b451e511 100644 --- a/internal/stores/data_style/mesh/edges/edge_config.ts +++ b/internal/stores/data_style/mesh/edges/edge_config.ts @@ -9,6 +9,7 @@ import type { AttributeStoredConfig, } from "@ogw_internal/stores/data_style/attribute_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { defaultAttributeStoredConfig } from "@ogw_internal/stores/data_style/attribute_default"; // Local imports @@ -36,8 +37,8 @@ interface UseMeshEdgesEdgeAttributeConfigWriterReturn { ) => Promise; } -function useMeshEdgesEdgeAttributeConfig(): UseMeshEdgesEdgeAttributeConfigReturn { - const meshEdgesCommonStyle = useMeshEdgesCommonStyle(); +function useMeshEdgesEdgeAttributeConfig(sceneId: SceneId): UseMeshEdgesEdgeAttributeConfigReturn { + const meshEdgesCommonStyle = useMeshEdgesCommonStyle(sceneId); function meshEdgesEdgeAttribute(meshId: MeshId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.edge shape is defined by the data style schema. return meshEdgesCommonStyle.meshEdgesColoring(meshId).edge as AttributeState; @@ -85,12 +86,14 @@ interface UseMeshEdgesEdgeAttributeConfigValuesReturn { meshEdgesEdgeAttributeNoDataColor: (meshId: MeshId) => ColorRGBA; } -function useMeshEdgesEdgeAttributeConfigValues(): UseMeshEdgesEdgeAttributeConfigValuesReturn { +function useMeshEdgesEdgeAttributeConfigValues( + sceneId: SceneId, +): UseMeshEdgesEdgeAttributeConfigValuesReturn { const { meshEdgesEdgeAttributeName, meshEdgesEdgeAttributeItem, meshEdgesEdgeAttributeStoredConfig, - } = useMeshEdgesEdgeAttributeConfig(); + } = useMeshEdgesEdgeAttributeConfig(sceneId); function meshEdgesEdgeAttributeRange(meshId: MeshId): AttributeRange { const name = meshEdgesEdgeAttributeName(meshId); const item = meshEdgesEdgeAttributeItem(meshId); @@ -116,8 +119,10 @@ function useMeshEdgesEdgeAttributeConfigValues(): UseMeshEdgesEdgeAttributeConfi }; } -function useMeshEdgesEdgeAttributeConfigWriter(): UseMeshEdgesEdgeAttributeConfigWriterReturn { - const meshEdgesCommonStyle = useMeshEdgesCommonStyle(); +function useMeshEdgesEdgeAttributeConfigWriter( + sceneId: SceneId, +): UseMeshEdgesEdgeAttributeConfigWriterReturn { + const meshEdgesCommonStyle = useMeshEdgesCommonStyle(sceneId); async function mutateMeshEdgesEdgeStyle( meshId: MeshId, values: Record, diff --git a/internal/stores/data_style/mesh/edges/index.ts b/internal/stores/data_style/mesh/edges/index.ts index 97a079a18..8beac7f6d 100644 --- a/internal/stores/data_style/mesh/edges/index.ts +++ b/internal/stores/data_style/mesh/edges/index.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports // Local imports @@ -127,13 +128,13 @@ type UseMeshEdgesStyleReturn = ReturnType & { ReturnType & ReturnType; -export function useMeshEdgesStyle(): UseMeshEdgesStyleReturn { - const meshEdgesCommonStyle = useMeshEdgesCommonStyle(); - const meshEdgesVisibility = useMeshEdgesVisibilityStyle(); - const meshEdgesColorStyle = useMeshEdgesColorStyle(); - const meshEdgesWidthStyle = useMeshEdgesWidthStyle(); - const meshEdgesVertexAttributeStyle = useMeshEdgesVertexAttributeStyle(); - const meshEdgesEdgeAttributeStyle = useMeshEdgesEdgeAttributeStyle(); +export function useMeshEdgesStyle(sceneId: SceneId): UseMeshEdgesStyleReturn { + const meshEdgesCommonStyle = useMeshEdgesCommonStyle(sceneId); + const meshEdgesVisibility = useMeshEdgesVisibilityStyle(sceneId); + const meshEdgesColorStyle = useMeshEdgesColorStyle(sceneId); + const meshEdgesWidthStyle = useMeshEdgesWidthStyle(sceneId); + const meshEdgesVertexAttributeStyle = useMeshEdgesVertexAttributeStyle(sceneId); + const meshEdgesEdgeAttributeStyle = useMeshEdgesEdgeAttributeStyle(sceneId); const activeColoringDeps: MeshEdgesActiveColoringDeps = { commonStyle: meshEdgesCommonStyle, diff --git a/internal/stores/data_style/mesh/edges/opacity.ts b/internal/stores/data_style/mesh/edges/opacity.ts index 99e3580f7..4f511d13a 100644 --- a/internal/stores/data_style/mesh/edges/opacity.ts +++ b/internal/stores/data_style/mesh/edges/opacity.ts @@ -1,5 +1,6 @@ import type { ColorRGBA, Opacity } from "@geode/opengeodeweb-viewer/schema_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -11,12 +12,12 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; const schema = viewer_schemas.opengeodeweb_viewer.mesh.edges.opacity; // The opacity is the constant color alpha, the viewer applies it whatever the coloring -export function useMeshEdgesOpacityStyle(): { +export function useMeshEdgesOpacityStyle(sceneId: SceneId): { meshEdgesOpacity: (meshId: MeshId) => Opacity | undefined; setMeshEdgesOpacity: (meshId: MeshId, opacity: Opacity) => Promise; } { const viewerStore = useViewerStore(); - const meshEdgesCommonStyle = useMeshEdgesCommonStyle(); + const meshEdgesCommonStyle = useMeshEdgesCommonStyle(sceneId); function meshEdgesConstantColor(meshId: MeshId): ColorRGBA | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.constant shape is defined by the data style schema. @@ -26,7 +27,7 @@ export function useMeshEdgesOpacityStyle(): { return meshEdgesConstantColor(meshId)?.alpha; } async function setMeshEdgesOpacity(meshId: MeshId, opacity: Opacity): Promise { - const params = { id: meshId, opacity }; + const params = { scene_id: sceneId, id: meshId, opacity }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/edges/vertex.ts b/internal/stores/data_style/mesh/edges/vertex.ts index 49574172a..4c68f3660 100644 --- a/internal/stores/data_style/mesh/edges/vertex.ts +++ b/internal/stores/data_style/mesh/edges/vertex.ts @@ -8,6 +8,7 @@ import type { } from "@geode/opengeodeweb-viewer/schema_types"; import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attribute_types"; // Third party imports import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; @@ -31,8 +32,11 @@ const meshEdgesVertexAttributeSchemas = viewer_schemas.opengeodeweb_viewer.mesh.edges.attribute.vertex; // oxlint-disable-next-line max-lines-per-function -function useMeshEdgesVertexAttributeStyle(): UseMeshEdgesVertexAttributeStyleReturn { - const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useMeshEdgesVertexAttributeStyle( + sceneId: SceneId, +): UseMeshEdgesVertexAttributeStyleReturn { + const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = + useAttributeTimeStepStyle(sceneId); const viewerStore = useViewerStore(); const { meshEdgesVertexAttribute, @@ -40,14 +44,14 @@ function useMeshEdgesVertexAttributeStyle(): UseMeshEdgesVertexAttributeStyleRet meshEdgesVertexAttributeLastItem, meshEdgesVertexAttributeItem, meshEdgesVertexAttributeStoredConfig, - } = useMeshEdgesVertexAttributeConfig(); + } = useMeshEdgesVertexAttributeConfig(sceneId); const { meshEdgesVertexAttributeRange, meshEdgesVertexAttributeColorMap, meshEdgesVertexAttributeNoDataColor, - } = useMeshEdgesVertexAttributeConfigValues(); + } = useMeshEdgesVertexAttributeConfigValues(sceneId); const { mutateMeshEdgesVertexStyle, setMeshEdgesVertexAttributeStoredConfig } = - useMeshEdgesVertexAttributeConfigWriter(); + useMeshEdgesVertexAttributeConfigWriter(sceneId); function meshEdgesVertexAttributeTimeStep(meshId: MeshId): AttributeTimeStep | undefined { return attributeTimeStep( meshId, @@ -79,6 +83,7 @@ function useMeshEdgesVertexAttributeStyle(): UseMeshEdgesVertexAttributeStyleRet const points = [...getRGBPointsFromPreset(colorMap)]; const schema = meshEdgesVertexAttributeSchemas.attribute; const params = { + scene_id: sceneId, id: meshId, name: seriesArrayName(meshId, attributeNamesSchema.$id, name), item, diff --git a/internal/stores/data_style/mesh/edges/vertex_config.ts b/internal/stores/data_style/mesh/edges/vertex_config.ts index 1585b9ce6..b26620281 100644 --- a/internal/stores/data_style/mesh/edges/vertex_config.ts +++ b/internal/stores/data_style/mesh/edges/vertex_config.ts @@ -9,6 +9,7 @@ import type { AttributeStoredConfig, } from "@ogw_internal/stores/data_style/attribute_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { defaultAttributeStoredConfig } from "@ogw_internal/stores/data_style/attribute_default"; // Local imports @@ -36,8 +37,10 @@ interface UseMeshEdgesVertexAttributeConfigWriterReturn { ) => Promise; } -function useMeshEdgesVertexAttributeConfig(): UseMeshEdgesVertexAttributeConfigReturn { - const meshEdgesCommonStyle = useMeshEdgesCommonStyle(); +function useMeshEdgesVertexAttributeConfig( + sceneId: SceneId, +): UseMeshEdgesVertexAttributeConfigReturn { + const meshEdgesCommonStyle = useMeshEdgesCommonStyle(sceneId); function meshEdgesVertexAttribute(meshId: MeshId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.vertex shape is defined by the data style schema. return meshEdgesCommonStyle.meshEdgesColoring(meshId).vertex as AttributeState; @@ -88,12 +91,14 @@ interface UseMeshEdgesVertexAttributeConfigValuesReturn { meshEdgesVertexAttributeNoDataColor: (meshId: MeshId) => ColorRGBA; } -function useMeshEdgesVertexAttributeConfigValues(): UseMeshEdgesVertexAttributeConfigValuesReturn { +function useMeshEdgesVertexAttributeConfigValues( + sceneId: SceneId, +): UseMeshEdgesVertexAttributeConfigValuesReturn { const { meshEdgesVertexAttributeName, meshEdgesVertexAttributeItem, meshEdgesVertexAttributeStoredConfig, - } = useMeshEdgesVertexAttributeConfig(); + } = useMeshEdgesVertexAttributeConfig(sceneId); function meshEdgesVertexAttributeRange(meshId: MeshId): AttributeRange { const name = meshEdgesVertexAttributeName(meshId); const item = meshEdgesVertexAttributeItem(meshId); @@ -119,8 +124,10 @@ function useMeshEdgesVertexAttributeConfigValues(): UseMeshEdgesVertexAttributeC }; } -function useMeshEdgesVertexAttributeConfigWriter(): UseMeshEdgesVertexAttributeConfigWriterReturn { - const meshEdgesCommonStyle = useMeshEdgesCommonStyle(); +function useMeshEdgesVertexAttributeConfigWriter( + sceneId: SceneId, +): UseMeshEdgesVertexAttributeConfigWriterReturn { + const meshEdgesCommonStyle = useMeshEdgesCommonStyle(sceneId); async function mutateMeshEdgesVertexStyle( meshId: MeshId, values: Record, diff --git a/internal/stores/data_style/mesh/edges/visibility.ts b/internal/stores/data_style/mesh/edges/visibility.ts index 56dc25063..642b083b8 100644 --- a/internal/stores/data_style/mesh/edges/visibility.ts +++ b/internal/stores/data_style/mesh/edges/visibility.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -9,19 +10,19 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.edges.visibility; -export function useMeshEdgesVisibilityStyle(): { +export function useMeshEdgesVisibilityStyle(sceneId: SceneId): { meshEdgesVisibility: (meshId: MeshId) => Visibility | undefined; setMeshEdgesVisibility: (meshId: MeshId, visibility: Visibility) => Promise; } { const viewerStore = useViewerStore(); - const meshEdgesCommonStyle = useMeshEdgesCommonStyle(); + const meshEdgesCommonStyle = useMeshEdgesCommonStyle(sceneId); function meshEdgesVisibility(meshId: MeshId): Visibility | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- visibility is defined as boolean in the data style schema. return meshEdgesCommonStyle.meshEdgesStyle(meshId).visibility as Visibility | undefined; } async function setMeshEdgesVisibility(meshId: MeshId, visibility: Visibility): Promise { - const params = { id: meshId, visibility }; + const params = { scene_id: sceneId, id: meshId, visibility }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/edges/width.ts b/internal/stores/data_style/mesh/edges/width.ts index 9d017be35..393ac9ea9 100644 --- a/internal/stores/data_style/mesh/edges/width.ts +++ b/internal/stores/data_style/mesh/edges/width.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -9,19 +10,19 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.edges.width; -export function useMeshEdgesWidthStyle(): { +export function useMeshEdgesWidthStyle(sceneId: SceneId): { meshEdgesWidth: (meshId: MeshId) => EdgeWidth | undefined; setMeshEdgesWidth: (meshId: MeshId, width: EdgeWidth) => Promise; } { const viewerStore = useViewerStore(); - const meshEdgesCommonStyle = useMeshEdgesCommonStyle(); + const meshEdgesCommonStyle = useMeshEdgesCommonStyle(sceneId); function meshEdgesWidth(meshId: MeshId): EdgeWidth | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- width is defined as number in the data style schema. return meshEdgesCommonStyle.meshEdgesStyle(meshId).width as EdgeWidth | undefined; } async function setMeshEdgesWidth(meshId: MeshId, width: EdgeWidth): Promise { - const params = { id: meshId, width }; + const params = { scene_id: sceneId, id: meshId, width }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/index.ts b/internal/stores/data_style/mesh/index.ts index e48770007..0c6e619f2 100644 --- a/internal/stores/data_style/mesh/index.ts +++ b/internal/stores/data_style/mesh/index.ts @@ -3,6 +3,7 @@ import type { AttributeTimeStep } from "@ogw_front/types/attribute"; import type { MeshId } from "@ogw_front/types/identifiers"; // Local imports +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; import { useMeshBaseStyle } from "./base_style"; import { useMeshCellsStyle } from "./cells"; @@ -13,7 +14,7 @@ import { useMeshPolyhedraStyle } from "./polyhedra"; import { whenDefined } from "@ogw_internal/stores/data_style/when_defined"; // oxlint-disable-next-line max-lines-per-function -export function useMeshStyle(): { +export function useMeshStyle(sceneId: SceneId): { meshVisibility: (meshId: MeshId) => Visibility | undefined; setMeshVisibility: (meshId: MeshId, visibility: Visibility) => Promise; meshColor: (meshId: MeshId) => ColorRGBA | undefined; @@ -24,13 +25,13 @@ export function useMeshStyle(): { ReturnType & ReturnType & ReturnType { - const dataStyleState = useDataStyleState(); - const { meshVisibility, setMeshVisibility, meshColor, setMeshColor } = useMeshBaseStyle(); - const meshPointsStyle = useMeshPointsStyle(); - const meshEdgesStyle = useMeshEdgesStyle(); - const meshCellsStyle = useMeshCellsStyle(); - const meshPolygonsStyle = useMeshPolygonsStyle(); - const meshPolyhedraStyle = useMeshPolyhedraStyle(); + const dataStyleState = useDataStyleState(sceneId); + const { meshVisibility, setMeshVisibility, meshColor, setMeshColor } = useMeshBaseStyle(sceneId); + const meshPointsStyle = useMeshPointsStyle(sceneId); + const meshEdgesStyle = useMeshEdgesStyle(sceneId); + const meshCellsStyle = useMeshCellsStyle(sceneId); + const meshPolygonsStyle = useMeshPolygonsStyle(sceneId); + const meshPolyhedraStyle = useMeshPolyhedraStyle(sceneId); const pointsCard = { key: "points", @@ -129,7 +130,8 @@ export function useMeshStyle(): { key === "surfaces" || key === "blocks" || key === "attributes" || - key === "data_id" + key === "data_id" || + key === "scene_id" ) { // These keys are either handled elsewhere or not applicable to mesh objects continue; diff --git a/internal/stores/data_style/mesh/points/color.ts b/internal/stores/data_style/mesh/points/color.ts index e501d59d5..bee0eefeb 100644 --- a/internal/stores/data_style/mesh/points/color.ts +++ b/internal/stores/data_style/mesh/points/color.ts @@ -1,5 +1,6 @@ import type { ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -11,19 +12,21 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.points.color; -export function useMeshPointsColorStyle(): ReturnType & { +export function useMeshPointsColorStyle(sceneId: SceneId): ReturnType< + typeof useMeshPointsOpacityStyle +> & { meshPointsColor: (meshId: MeshId) => ColorRGBA | undefined; setMeshPointsColor: (meshId: MeshId, color: ColorRGBA) => Promise; } { const viewerStore = useViewerStore(); - const meshPointsCommonStyle = useMeshPointsCommonStyle(); + const meshPointsCommonStyle = useMeshPointsCommonStyle(sceneId); function meshPointsColor(meshId: MeshId): ColorRGBA | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.constant shape is defined by the data style schema. return meshPointsCommonStyle.meshPointsColoring(meshId).constant as ColorRGBA | undefined; } async function setMeshPointsColor(meshId: MeshId, color: ColorRGBA): Promise { - const params = { id: meshId, color }; + const params = { scene_id: sceneId, id: meshId, color }; const result = await viewerStore.request( { schema, @@ -44,6 +47,6 @@ export function useMeshPointsColorStyle(): ReturnType StyleValues; meshPointsColoring: (meshId: MeshId) => StyleValues; mutateMeshPointsColoring: (meshId: MeshId, values: StyleValues) => Promise; mutateMeshPointsStyle: (meshId: MeshId, values: StyleValues) => Promise; mutateMeshPointsVisibility: (response: { id: string; visibility: Visibility }) => Promise; } { - const dataStyleState = useDataStyleState(); + const dataStyleState = useDataStyleState(sceneId); async function mutateMeshPointsStyle(meshId: MeshId, values: StyleValues): Promise { const result = await dataStyleState.mutateStyle(meshId, { diff --git a/internal/stores/data_style/mesh/points/index.ts b/internal/stores/data_style/mesh/points/index.ts index 82841b381..91fa37b9e 100644 --- a/internal/stores/data_style/mesh/points/index.ts +++ b/internal/stores/data_style/mesh/points/index.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports // Local imports @@ -104,12 +105,12 @@ type UseMeshPointsStyleReturn = ReturnType & { ReturnType & ReturnType; -export function useMeshPointsStyle(): UseMeshPointsStyleReturn { - const meshPointsCommonStyle = useMeshPointsCommonStyle(); - const meshPointsVisibility = useMeshPointsVisibilityStyle(); - const meshPointsColorStyle = useMeshPointsColorStyle(); - const meshPointsSizeStyle = useMeshPointsSizeStyle(); - const meshPointsVertexAttributeStyle = useMeshPointsVertexAttributeStyle(); +export function useMeshPointsStyle(sceneId: SceneId): UseMeshPointsStyleReturn { + const meshPointsCommonStyle = useMeshPointsCommonStyle(sceneId); + const meshPointsVisibility = useMeshPointsVisibilityStyle(sceneId); + const meshPointsColorStyle = useMeshPointsColorStyle(sceneId); + const meshPointsSizeStyle = useMeshPointsSizeStyle(sceneId); + const meshPointsVertexAttributeStyle = useMeshPointsVertexAttributeStyle(sceneId); const activeColoringDeps: MeshPointsActiveColoringDeps = { commonStyle: meshPointsCommonStyle, diff --git a/internal/stores/data_style/mesh/points/opacity.ts b/internal/stores/data_style/mesh/points/opacity.ts index bcb146eb9..65d17d6ef 100644 --- a/internal/stores/data_style/mesh/points/opacity.ts +++ b/internal/stores/data_style/mesh/points/opacity.ts @@ -1,5 +1,6 @@ import type { ColorRGBA, Opacity } from "@geode/opengeodeweb-viewer/schema_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -11,12 +12,12 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; const schema = viewer_schemas.opengeodeweb_viewer.mesh.points.opacity; // The opacity is the constant color alpha, the viewer applies it whatever the coloring -export function useMeshPointsOpacityStyle(): { +export function useMeshPointsOpacityStyle(sceneId: SceneId): { meshPointsOpacity: (meshId: MeshId) => Opacity | undefined; setMeshPointsOpacity: (meshId: MeshId, opacity: Opacity) => Promise; } { const viewerStore = useViewerStore(); - const meshPointsCommonStyle = useMeshPointsCommonStyle(); + const meshPointsCommonStyle = useMeshPointsCommonStyle(sceneId); function meshPointsConstantColor(meshId: MeshId): ColorRGBA | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.constant shape is defined by the data style schema. @@ -26,7 +27,7 @@ export function useMeshPointsOpacityStyle(): { return meshPointsConstantColor(meshId)?.alpha; } async function setMeshPointsOpacity(meshId: MeshId, opacity: Opacity): Promise { - const params = { id: meshId, opacity }; + const params = { scene_id: sceneId, id: meshId, opacity }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/points/size.ts b/internal/stores/data_style/mesh/points/size.ts index f98ce2b25..4dc2cb481 100644 --- a/internal/stores/data_style/mesh/points/size.ts +++ b/internal/stores/data_style/mesh/points/size.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -10,19 +11,19 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.points.size; -export function useMeshPointsSizeStyle(): { +export function useMeshPointsSizeStyle(sceneId: SceneId): { meshPointsSize: (meshId: MeshId) => PointSize | undefined; setMeshPointsSize: (meshId: MeshId, size: PointSize) => Promise; } { const viewerStore = useViewerStore(); - const meshPointsCommonStyle = useMeshPointsCommonStyle(); + const meshPointsCommonStyle = useMeshPointsCommonStyle(sceneId); function meshPointsSize(meshId: MeshId): PointSize | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- size is defined as number in the data style schema. return meshPointsCommonStyle.meshPointsStyle(meshId).size as PointSize | undefined; } async function setMeshPointsSize(meshId: MeshId, size: PointSize): Promise { - const params = { id: meshId, size }; + const params = { scene_id: sceneId, id: meshId, size }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/points/vertex.ts b/internal/stores/data_style/mesh/points/vertex.ts index 548c792c3..177ae1bbe 100644 --- a/internal/stores/data_style/mesh/points/vertex.ts +++ b/internal/stores/data_style/mesh/points/vertex.ts @@ -8,6 +8,7 @@ import type { } from "@geode/opengeodeweb-viewer/schema_types"; import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attribute_types"; // Third party imports import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; @@ -31,8 +32,11 @@ const meshPointsVertexAttributeSchemas = viewer_schemas.opengeodeweb_viewer.mesh.points.attribute.vertex; // oxlint-disable-next-line max-lines-per-function -function useMeshPointsVertexAttributeStyle(): UseMeshPointsVertexAttributeStyleReturn { - const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useMeshPointsVertexAttributeStyle( + sceneId: SceneId, +): UseMeshPointsVertexAttributeStyleReturn { + const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = + useAttributeTimeStepStyle(sceneId); const viewerStore = useViewerStore(); const { meshPointsVertexAttribute, @@ -40,14 +44,14 @@ function useMeshPointsVertexAttributeStyle(): UseMeshPointsVertexAttributeStyleR meshPointsVertexAttributeLastItem, meshPointsVertexAttributeItem, meshPointsVertexAttributeStoredConfig, - } = useMeshPointsVertexAttributeConfig(); + } = useMeshPointsVertexAttributeConfig(sceneId); const { meshPointsVertexAttributeRange, meshPointsVertexAttributeColorMap, meshPointsVertexAttributeNoDataColor, - } = useMeshPointsVertexAttributeConfigValues(); + } = useMeshPointsVertexAttributeConfigValues(sceneId); const { mutateMeshPointsVertexStyle, setMeshPointsVertexAttributeStoredConfig } = - useMeshPointsVertexAttributeConfigWriter(); + useMeshPointsVertexAttributeConfigWriter(sceneId); function meshPointsVertexAttributeTimeStep(meshId: MeshId): AttributeTimeStep | undefined { return attributeTimeStep( meshId, @@ -79,6 +83,7 @@ function useMeshPointsVertexAttributeStyle(): UseMeshPointsVertexAttributeStyleR const points = [...getRGBPointsFromPreset(colorMap)]; const schema = meshPointsVertexAttributeSchemas.attribute; const params = { + scene_id: sceneId, id: meshId, name: seriesArrayName(meshId, attributeNamesSchema.$id, name), item, diff --git a/internal/stores/data_style/mesh/points/vertex_config.ts b/internal/stores/data_style/mesh/points/vertex_config.ts index a5989775f..a29d18a0c 100644 --- a/internal/stores/data_style/mesh/points/vertex_config.ts +++ b/internal/stores/data_style/mesh/points/vertex_config.ts @@ -9,6 +9,7 @@ import type { AttributeStoredConfig, } from "@ogw_internal/stores/data_style/attribute_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { defaultAttributeStoredConfig } from "@ogw_internal/stores/data_style/attribute_default"; // Local imports @@ -36,8 +37,10 @@ interface UseMeshPointsVertexAttributeConfigWriterReturn { ) => Promise; } -function useMeshPointsVertexAttributeConfig(): UseMeshPointsVertexAttributeConfigReturn { - const meshPointsCommonStyle = useMeshPointsCommonStyle(); +function useMeshPointsVertexAttributeConfig( + sceneId: SceneId, +): UseMeshPointsVertexAttributeConfigReturn { + const meshPointsCommonStyle = useMeshPointsCommonStyle(sceneId); function meshPointsVertexAttribute(meshId: MeshId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.vertex shape is defined by the data style schema. return meshPointsCommonStyle.meshPointsColoring(meshId).vertex as AttributeState; @@ -88,12 +91,14 @@ interface UseMeshPointsVertexAttributeConfigValuesReturn { meshPointsVertexAttributeNoDataColor: (meshId: MeshId) => ColorRGBA; } -function useMeshPointsVertexAttributeConfigValues(): UseMeshPointsVertexAttributeConfigValuesReturn { +function useMeshPointsVertexAttributeConfigValues( + sceneId: SceneId, +): UseMeshPointsVertexAttributeConfigValuesReturn { const { meshPointsVertexAttributeName, meshPointsVertexAttributeItem, meshPointsVertexAttributeStoredConfig, - } = useMeshPointsVertexAttributeConfig(); + } = useMeshPointsVertexAttributeConfig(sceneId); function meshPointsVertexAttributeRange(meshId: MeshId): AttributeRange { const name = meshPointsVertexAttributeName(meshId); const item = meshPointsVertexAttributeItem(meshId); @@ -119,8 +124,10 @@ function useMeshPointsVertexAttributeConfigValues(): UseMeshPointsVertexAttribut }; } -function useMeshPointsVertexAttributeConfigWriter(): UseMeshPointsVertexAttributeConfigWriterReturn { - const meshPointsCommonStyle = useMeshPointsCommonStyle(); +function useMeshPointsVertexAttributeConfigWriter( + sceneId: SceneId, +): UseMeshPointsVertexAttributeConfigWriterReturn { + const meshPointsCommonStyle = useMeshPointsCommonStyle(sceneId); async function mutateMeshPointsVertexStyle( meshId: MeshId, values: Record, diff --git a/internal/stores/data_style/mesh/points/visibility.ts b/internal/stores/data_style/mesh/points/visibility.ts index bdb08d3c0..bc3795550 100644 --- a/internal/stores/data_style/mesh/points/visibility.ts +++ b/internal/stores/data_style/mesh/points/visibility.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -10,19 +11,19 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.points.visibility; -export function useMeshPointsVisibilityStyle(): { +export function useMeshPointsVisibilityStyle(sceneId: SceneId): { meshPointsVisibility: (meshId: MeshId) => Visibility | undefined; setMeshPointsVisibility: (meshId: MeshId, visibility: Visibility) => Promise; } { const viewerStore = useViewerStore(); - const meshPointsCommonStyle = useMeshPointsCommonStyle(); + const meshPointsCommonStyle = useMeshPointsCommonStyle(sceneId); function meshPointsVisibility(meshId: MeshId): Visibility | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- visibility is defined as boolean in the data style schema. return meshPointsCommonStyle.meshPointsStyle(meshId).visibility as Visibility | undefined; } async function setMeshPointsVisibility(meshId: MeshId, visibility: Visibility): Promise { - const params = { id: meshId, visibility }; + const params = { scene_id: sceneId, id: meshId, visibility }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/polygons/color.ts b/internal/stores/data_style/mesh/polygons/color.ts index 47323e1b1..bfe14747f 100644 --- a/internal/stores/data_style/mesh/polygons/color.ts +++ b/internal/stores/data_style/mesh/polygons/color.ts @@ -1,5 +1,6 @@ import type { ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -11,19 +12,21 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.polygons.color; -export function useMeshPolygonsColorStyle(): ReturnType & { +export function useMeshPolygonsColorStyle(sceneId: SceneId): ReturnType< + typeof useMeshPolygonsOpacityStyle +> & { meshPolygonsColor: (meshId: MeshId) => ColorRGBA | undefined; setMeshPolygonsColor: (meshId: MeshId, color: ColorRGBA) => Promise; } { const viewerStore = useViewerStore(); - const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(); + const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(sceneId); function meshPolygonsColor(meshId: MeshId): ColorRGBA | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.constant shape is defined by the data style schema. return meshPolygonsCommonStyle.meshPolygonsColoring(meshId).constant as ColorRGBA | undefined; } async function setMeshPolygonsColor(meshId: MeshId, color: ColorRGBA): Promise { - const params = { id: meshId, color }; + const params = { scene_id: sceneId, id: meshId, color }; const result = await viewerStore.request( { schema, @@ -44,6 +47,6 @@ export function useMeshPolygonsColorStyle(): ReturnType StyleValues; meshPolygonsColoring: (meshId: MeshId) => StyleValues; mutateMeshPolygonsStyle: (meshId: MeshId, values: StyleValues) => Promise; mutateMeshPolygonsColoring: (meshId: MeshId, values: StyleValues) => Promise; mutateMeshPolygonsPolygonStyle: (meshId: MeshId, values: StyleValues) => Promise; } { - const dataStyleState = useDataStyleState(); + const dataStyleState = useDataStyleState(sceneId); async function mutateMeshPolygonsStyle(meshId: MeshId, values: StyleValues): Promise { const result = await dataStyleState.mutateStyle(meshId, { diff --git a/internal/stores/data_style/mesh/polygons/index.ts b/internal/stores/data_style/mesh/polygons/index.ts index 5b568fae3..33951131f 100644 --- a/internal/stores/data_style/mesh/polygons/index.ts +++ b/internal/stores/data_style/mesh/polygons/index.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports // Local imports @@ -139,13 +140,13 @@ type UseMeshPolygonsStyleReturn = ReturnType ReturnType & ReturnType; -export function useMeshPolygonsStyle(): UseMeshPolygonsStyleReturn { - const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(); - const meshPolygonsVisibility = useMeshPolygonsVisibilityStyle(); - const meshPolygonsColorStyle = useMeshPolygonsColorStyle(); - const meshPolygonsTexturesStore = useMeshPolygonsTexturesStyle(); - const meshPolygonsVertexAttributeStyle = useMeshPolygonsVertexAttributeStyle(); - const meshPolygonsPolygonAttributeStyle = useMeshPolygonsPolygonAttributeStyle(); +export function useMeshPolygonsStyle(sceneId: SceneId): UseMeshPolygonsStyleReturn { + const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(sceneId); + const meshPolygonsVisibility = useMeshPolygonsVisibilityStyle(sceneId); + const meshPolygonsColorStyle = useMeshPolygonsColorStyle(sceneId); + const meshPolygonsTexturesStore = useMeshPolygonsTexturesStyle(sceneId); + const meshPolygonsVertexAttributeStyle = useMeshPolygonsVertexAttributeStyle(sceneId); + const meshPolygonsPolygonAttributeStyle = useMeshPolygonsPolygonAttributeStyle(sceneId); const activeColoringDeps: MeshPolygonsActiveColoringDeps = { commonStyle: meshPolygonsCommonStyle, diff --git a/internal/stores/data_style/mesh/polygons/opacity.ts b/internal/stores/data_style/mesh/polygons/opacity.ts index 0b38df6d4..df69cee07 100644 --- a/internal/stores/data_style/mesh/polygons/opacity.ts +++ b/internal/stores/data_style/mesh/polygons/opacity.ts @@ -1,5 +1,6 @@ import type { ColorRGBA, Opacity } from "@geode/opengeodeweb-viewer/schema_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -11,12 +12,12 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; const schema = viewer_schemas.opengeodeweb_viewer.mesh.polygons.opacity; // The opacity is the constant color alpha, the viewer applies it whatever the coloring -export function useMeshPolygonsOpacityStyle(): { +export function useMeshPolygonsOpacityStyle(sceneId: SceneId): { meshPolygonsOpacity: (meshId: MeshId) => Opacity | undefined; setMeshPolygonsOpacity: (meshId: MeshId, opacity: Opacity) => Promise; } { const viewerStore = useViewerStore(); - const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(); + const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(sceneId); function meshPolygonsConstantColor(meshId: MeshId): ColorRGBA | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.constant shape is defined by the data style schema. @@ -26,7 +27,7 @@ export function useMeshPolygonsOpacityStyle(): { return meshPolygonsConstantColor(meshId)?.alpha; } async function setMeshPolygonsOpacity(meshId: MeshId, opacity: Opacity): Promise { - const params = { id: meshId, opacity }; + const params = { scene_id: sceneId, id: meshId, opacity }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/polygons/polygon.ts b/internal/stores/data_style/mesh/polygons/polygon.ts index 8ff0f40c7..8a720ce6b 100644 --- a/internal/stores/data_style/mesh/polygons/polygon.ts +++ b/internal/stores/data_style/mesh/polygons/polygon.ts @@ -8,6 +8,7 @@ import type { } from "@geode/opengeodeweb-viewer/schema_types"; import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attribute_types"; // Third party imports import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; @@ -31,8 +32,11 @@ const meshPolygonsPolygonAttributeSchemas = viewer_schemas.opengeodeweb_viewer.mesh.polygons.attribute.polygon; // oxlint-disable-next-line max-lines-per-function -function useMeshPolygonsPolygonAttributeStyle(): UseMeshPolygonsPolygonAttributeStyleReturn { - const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useMeshPolygonsPolygonAttributeStyle( + sceneId: SceneId, +): UseMeshPolygonsPolygonAttributeStyleReturn { + const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = + useAttributeTimeStepStyle(sceneId); const viewerStore = useViewerStore(); const { meshPolygonsPolygonAttribute, @@ -40,14 +44,14 @@ function useMeshPolygonsPolygonAttributeStyle(): UseMeshPolygonsPolygonAttribute meshPolygonsPolygonAttributeLastItem, meshPolygonsPolygonAttributeItem, meshPolygonsPolygonAttributeStoredConfig, - } = useMeshPolygonsPolygonAttributeConfig(); + } = useMeshPolygonsPolygonAttributeConfig(sceneId); const { meshPolygonsPolygonAttributeRange, meshPolygonsPolygonAttributeColorMap, meshPolygonsPolygonAttributeNoDataColor, - } = useMeshPolygonsPolygonAttributeConfigValues(); + } = useMeshPolygonsPolygonAttributeConfigValues(sceneId); const { mutateMeshPolygonsPolygonStyle, setMeshPolygonsPolygonAttributeStoredConfig } = - useMeshPolygonsPolygonAttributeConfigWriter(); + useMeshPolygonsPolygonAttributeConfigWriter(sceneId); function meshPolygonsPolygonAttributeTimeStep(meshId: MeshId): AttributeTimeStep | undefined { return attributeTimeStep( meshId, @@ -79,6 +83,7 @@ function useMeshPolygonsPolygonAttributeStyle(): UseMeshPolygonsPolygonAttribute const points = [...getRGBPointsFromPreset(colorMap)]; const schema = meshPolygonsPolygonAttributeSchemas.attribute; const params = { + scene_id: sceneId, id: meshId, name: seriesArrayName(meshId, attributeNamesSchema.$id, name), item, diff --git a/internal/stores/data_style/mesh/polygons/polygon_config.ts b/internal/stores/data_style/mesh/polygons/polygon_config.ts index ddc9082bd..072bb7d93 100644 --- a/internal/stores/data_style/mesh/polygons/polygon_config.ts +++ b/internal/stores/data_style/mesh/polygons/polygon_config.ts @@ -9,6 +9,7 @@ import type { AttributeStoredConfig, } from "@ogw_internal/stores/data_style/attribute_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { defaultAttributeStoredConfig } from "@ogw_internal/stores/data_style/attribute_default"; // Local imports @@ -39,8 +40,10 @@ interface UseMeshPolygonsPolygonAttributeConfigWriterReturn { ) => Promise; } -function useMeshPolygonsPolygonAttributeConfig(): UseMeshPolygonsPolygonAttributeConfigReturn { - const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(); +function useMeshPolygonsPolygonAttributeConfig( + sceneId: SceneId, +): UseMeshPolygonsPolygonAttributeConfigReturn { + const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(sceneId); function meshPolygonsPolygonAttribute(meshId: MeshId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.polygon shape is defined by the data style schema. return meshPolygonsCommonStyle.meshPolygonsColoring(meshId).polygon as AttributeState; @@ -91,12 +94,14 @@ interface UseMeshPolygonsPolygonAttributeConfigValuesReturn { meshPolygonsPolygonAttributeNoDataColor: (meshId: MeshId) => ColorRGBA; } -function useMeshPolygonsPolygonAttributeConfigValues(): UseMeshPolygonsPolygonAttributeConfigValuesReturn { +function useMeshPolygonsPolygonAttributeConfigValues( + sceneId: SceneId, +): UseMeshPolygonsPolygonAttributeConfigValuesReturn { const { meshPolygonsPolygonAttributeName, meshPolygonsPolygonAttributeItem, meshPolygonsPolygonAttributeStoredConfig, - } = useMeshPolygonsPolygonAttributeConfig(); + } = useMeshPolygonsPolygonAttributeConfig(sceneId); function meshPolygonsPolygonAttributeRange(meshId: MeshId): AttributeRange { const name = meshPolygonsPolygonAttributeName(meshId); const item = meshPolygonsPolygonAttributeItem(meshId); @@ -122,8 +127,10 @@ function useMeshPolygonsPolygonAttributeConfigValues(): UseMeshPolygonsPolygonAt }; } -function useMeshPolygonsPolygonAttributeConfigWriter(): UseMeshPolygonsPolygonAttributeConfigWriterReturn { - const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(); +function useMeshPolygonsPolygonAttributeConfigWriter( + sceneId: SceneId, +): UseMeshPolygonsPolygonAttributeConfigWriterReturn { + const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(sceneId); async function mutateMeshPolygonsPolygonStyle( meshId: MeshId, values: Record, diff --git a/internal/stores/data_style/mesh/polygons/textures.ts b/internal/stores/data_style/mesh/polygons/textures.ts index 8b5d96ebf..9cd2f0eb0 100644 --- a/internal/stores/data_style/mesh/polygons/textures.ts +++ b/internal/stores/data_style/mesh/polygons/textures.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas, { type MeshApplyTexturesParams, @@ -11,7 +12,7 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.apply_textures; -export function useMeshPolygonsTexturesStyle(): { +export function useMeshPolygonsTexturesStyle(sceneId: SceneId): { meshPolygonsTextures: (meshId: MeshId) => MeshApplyTexturesParams["textures"] | undefined; setMeshPolygonsTextures: ( meshId: MeshId, @@ -19,7 +20,7 @@ export function useMeshPolygonsTexturesStyle(): { ) => Promise; } { const viewerStore = useViewerStore(); - const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(); + const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(sceneId); function meshPolygonsTextures(meshId: MeshId): MeshApplyTexturesParams["textures"] | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- textures shape is defined by the data style schema. @@ -31,7 +32,7 @@ export function useMeshPolygonsTexturesStyle(): { meshId: MeshId, textures: MeshApplyTexturesParams["textures"], ): Promise { - const params = { id: meshId, textures }; + const params = { scene_id: sceneId, id: meshId, textures }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/polygons/vertex.ts b/internal/stores/data_style/mesh/polygons/vertex.ts index 6300c9677..af53c981e 100644 --- a/internal/stores/data_style/mesh/polygons/vertex.ts +++ b/internal/stores/data_style/mesh/polygons/vertex.ts @@ -8,6 +8,7 @@ import type { } from "@geode/opengeodeweb-viewer/schema_types"; import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attribute_types"; // Third party imports import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; @@ -31,8 +32,11 @@ const meshPolygonsVertexAttributeSchemas = viewer_schemas.opengeodeweb_viewer.mesh.polygons.attribute.vertex; // oxlint-disable-next-line max-lines-per-function -function useMeshPolygonsVertexAttributeStyle(): UseMeshPolygonsVertexAttributeStyleReturn { - const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useMeshPolygonsVertexAttributeStyle( + sceneId: SceneId, +): UseMeshPolygonsVertexAttributeStyleReturn { + const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = + useAttributeTimeStepStyle(sceneId); const viewerStore = useViewerStore(); const { meshPolygonsVertexAttribute, @@ -40,14 +44,14 @@ function useMeshPolygonsVertexAttributeStyle(): UseMeshPolygonsVertexAttributeSt meshPolygonsVertexAttributeLastItem, meshPolygonsVertexAttributeItem, meshPolygonsVertexAttributeStoredConfig, - } = useMeshPolygonsVertexAttributeConfig(); + } = useMeshPolygonsVertexAttributeConfig(sceneId); const { meshPolygonsVertexAttributeRange, meshPolygonsVertexAttributeColorMap, meshPolygonsVertexAttributeNoDataColor, - } = useMeshPolygonsVertexAttributeConfigValues(); + } = useMeshPolygonsVertexAttributeConfigValues(sceneId); const { mutateMeshPolygonsVertexStyle, setMeshPolygonsVertexAttributeStoredConfig } = - useMeshPolygonsVertexAttributeConfigWriter(); + useMeshPolygonsVertexAttributeConfigWriter(sceneId); function meshPolygonsVertexAttributeTimeStep(meshId: MeshId): AttributeTimeStep | undefined { return attributeTimeStep( meshId, @@ -79,6 +83,7 @@ function useMeshPolygonsVertexAttributeStyle(): UseMeshPolygonsVertexAttributeSt const points = [...getRGBPointsFromPreset(colorMap)]; const schema = meshPolygonsVertexAttributeSchemas.attribute; const params = { + scene_id: sceneId, id: meshId, name: seriesArrayName(meshId, attributeNamesSchema.$id, name), item, diff --git a/internal/stores/data_style/mesh/polygons/vertex_config.ts b/internal/stores/data_style/mesh/polygons/vertex_config.ts index 345153670..a6132d5e8 100644 --- a/internal/stores/data_style/mesh/polygons/vertex_config.ts +++ b/internal/stores/data_style/mesh/polygons/vertex_config.ts @@ -9,6 +9,7 @@ import type { AttributeStoredConfig, } from "@ogw_internal/stores/data_style/attribute_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { defaultAttributeStoredConfig } from "@ogw_internal/stores/data_style/attribute_default"; // Local imports @@ -39,8 +40,10 @@ interface UseMeshPolygonsVertexAttributeConfigWriterReturn { ) => Promise; } -function useMeshPolygonsVertexAttributeConfig(): UseMeshPolygonsVertexAttributeConfigReturn { - const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(); +function useMeshPolygonsVertexAttributeConfig( + sceneId: SceneId, +): UseMeshPolygonsVertexAttributeConfigReturn { + const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(sceneId); function meshPolygonsVertexAttribute(meshId: MeshId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.vertex shape is defined by the data style schema. return meshPolygonsCommonStyle.meshPolygonsColoring(meshId).vertex as AttributeState; @@ -91,12 +94,14 @@ interface UseMeshPolygonsVertexAttributeConfigValuesReturn { meshPolygonsVertexAttributeNoDataColor: (meshId: MeshId) => ColorRGBA; } -function useMeshPolygonsVertexAttributeConfigValues(): UseMeshPolygonsVertexAttributeConfigValuesReturn { +function useMeshPolygonsVertexAttributeConfigValues( + sceneId: SceneId, +): UseMeshPolygonsVertexAttributeConfigValuesReturn { const { meshPolygonsVertexAttributeName, meshPolygonsVertexAttributeItem, meshPolygonsVertexAttributeStoredConfig, - } = useMeshPolygonsVertexAttributeConfig(); + } = useMeshPolygonsVertexAttributeConfig(sceneId); function meshPolygonsVertexAttributeRange(meshId: MeshId): AttributeRange { const name = meshPolygonsVertexAttributeName(meshId); const item = meshPolygonsVertexAttributeItem(meshId); @@ -122,8 +127,10 @@ function useMeshPolygonsVertexAttributeConfigValues(): UseMeshPolygonsVertexAttr }; } -function useMeshPolygonsVertexAttributeConfigWriter(): UseMeshPolygonsVertexAttributeConfigWriterReturn { - const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(); +function useMeshPolygonsVertexAttributeConfigWriter( + sceneId: SceneId, +): UseMeshPolygonsVertexAttributeConfigWriterReturn { + const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(sceneId); async function mutateMeshPolygonsVertexStyle( meshId: MeshId, values: Record, diff --git a/internal/stores/data_style/mesh/polygons/visibility.ts b/internal/stores/data_style/mesh/polygons/visibility.ts index a64ddec13..9ef4ec2d9 100644 --- a/internal/stores/data_style/mesh/polygons/visibility.ts +++ b/internal/stores/data_style/mesh/polygons/visibility.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -10,12 +11,12 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.polygons.visibility; -export function useMeshPolygonsVisibilityStyle(): { +export function useMeshPolygonsVisibilityStyle(sceneId: SceneId): { meshPolygonsVisibility: (meshId: MeshId) => Visibility | undefined; setMeshPolygonsVisibility: (meshId: MeshId, visibility: Visibility) => Promise; } { const viewerStore = useViewerStore(); - const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(); + const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(sceneId); function meshPolygonsVisibility(meshId: MeshId): Visibility | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- visibility is defined as boolean in the data style schema. @@ -25,7 +26,7 @@ export function useMeshPolygonsVisibilityStyle(): { meshId: MeshId, visibility: Visibility, ): Promise { - const params = { id: meshId, visibility }; + const params = { scene_id: sceneId, id: meshId, visibility }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/polyhedra/color.ts b/internal/stores/data_style/mesh/polyhedra/color.ts index 590f7f417..941aa6bb8 100644 --- a/internal/stores/data_style/mesh/polyhedra/color.ts +++ b/internal/stores/data_style/mesh/polyhedra/color.ts @@ -1,5 +1,6 @@ import type { ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -11,19 +12,21 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.polyhedra.color; -export function useMeshPolyhedraColorStyle(): ReturnType & { +export function useMeshPolyhedraColorStyle(sceneId: SceneId): ReturnType< + typeof useMeshPolyhedraOpacityStyle +> & { meshPolyhedraColor: (meshId: MeshId) => ColorRGBA | undefined; setMeshPolyhedraColor: (meshId: MeshId, color: ColorRGBA) => Promise; } { const viewerStore = useViewerStore(); - const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(); + const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(sceneId); function meshPolyhedraColor(meshId: MeshId): ColorRGBA | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.constant shape is defined by the data style schema. return meshPolyhedraCommonStyle.meshPolyhedraColoring(meshId).constant as ColorRGBA | undefined; } async function setMeshPolyhedraColor(meshId: MeshId, color: ColorRGBA): Promise { - const params = { id: meshId, color }; + const params = { scene_id: sceneId, id: meshId, color }; const result = await viewerStore.request( { schema, @@ -47,6 +50,6 @@ export function useMeshPolyhedraColorStyle(): ReturnType StyleValues; meshPolyhedraColoring: (meshId: MeshId) => StyleValues; mutateMeshPolyhedraStyle: (meshId: MeshId, values: StyleValues) => Promise; mutateMeshPolyhedraColoring: (meshId: MeshId, values: StyleValues) => Promise; } { - const dataStyleState = useDataStyleState(); + const dataStyleState = useDataStyleState(sceneId); async function mutateMeshPolyhedraStyle(meshId: MeshId, values: StyleValues): Promise { const result = await dataStyleState.mutateStyle(meshId, { diff --git a/internal/stores/data_style/mesh/polyhedra/index.ts b/internal/stores/data_style/mesh/polyhedra/index.ts index 5dcb9ff0f..4f8196513 100644 --- a/internal/stores/data_style/mesh/polyhedra/index.ts +++ b/internal/stores/data_style/mesh/polyhedra/index.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports // Local imports @@ -131,12 +132,12 @@ type UseMeshPolyhedraStyleReturn = ReturnType & ReturnType; -export function useMeshPolyhedraStyle(): UseMeshPolyhedraStyleReturn { - const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(); - const meshPolyhedraVisibility = useMeshPolyhedraVisibilityStyle(); - const meshPolyhedraColorStyle = useMeshPolyhedraColorStyle(); - const meshPolyhedraVertexAttributeStyle = useMeshPolyhedraVertexAttributeStyle(); - const meshPolyhedraPolyhedronAttributeStyle = useMeshPolyhedraPolyhedronAttributeStyle(); +export function useMeshPolyhedraStyle(sceneId: SceneId): UseMeshPolyhedraStyleReturn { + const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(sceneId); + const meshPolyhedraVisibility = useMeshPolyhedraVisibilityStyle(sceneId); + const meshPolyhedraColorStyle = useMeshPolyhedraColorStyle(sceneId); + const meshPolyhedraVertexAttributeStyle = useMeshPolyhedraVertexAttributeStyle(sceneId); + const meshPolyhedraPolyhedronAttributeStyle = useMeshPolyhedraPolyhedronAttributeStyle(sceneId); const activeColoringDeps: MeshPolyhedraActiveColoringDeps = { commonStyle: meshPolyhedraCommonStyle, diff --git a/internal/stores/data_style/mesh/polyhedra/opacity.ts b/internal/stores/data_style/mesh/polyhedra/opacity.ts index c1dfe1d7c..22dd7371d 100644 --- a/internal/stores/data_style/mesh/polyhedra/opacity.ts +++ b/internal/stores/data_style/mesh/polyhedra/opacity.ts @@ -1,5 +1,6 @@ import type { ColorRGBA, Opacity } from "@geode/opengeodeweb-viewer/schema_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -11,12 +12,12 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; const schema = viewer_schemas.opengeodeweb_viewer.mesh.polyhedra.opacity; // The opacity is the constant color alpha, the viewer applies it whatever the coloring -export function useMeshPolyhedraOpacityStyle(): { +export function useMeshPolyhedraOpacityStyle(sceneId: SceneId): { meshPolyhedraOpacity: (meshId: MeshId) => Opacity | undefined; setMeshPolyhedraOpacity: (meshId: MeshId, opacity: Opacity) => Promise; } { const viewerStore = useViewerStore(); - const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(); + const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(sceneId); function meshPolyhedraConstantColor(meshId: MeshId): ColorRGBA | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.constant shape is defined by the data style schema. @@ -26,7 +27,7 @@ export function useMeshPolyhedraOpacityStyle(): { return meshPolyhedraConstantColor(meshId)?.alpha; } async function setMeshPolyhedraOpacity(meshId: MeshId, opacity: Opacity): Promise { - const params = { id: meshId, opacity }; + const params = { scene_id: sceneId, id: meshId, opacity }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/mesh/polyhedra/polyhedron.ts b/internal/stores/data_style/mesh/polyhedra/polyhedron.ts index 422da09d8..888cf8bff 100644 --- a/internal/stores/data_style/mesh/polyhedra/polyhedron.ts +++ b/internal/stores/data_style/mesh/polyhedra/polyhedron.ts @@ -8,6 +8,7 @@ import type { } from "@geode/opengeodeweb-viewer/schema_types"; import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attribute_types"; // Third party imports import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; @@ -31,8 +32,11 @@ const meshPolyhedraPolyhedronAttributeSchemas = viewer_schemas.opengeodeweb_viewer.mesh.polyhedra.attribute.polyhedron; // oxlint-disable-next-line max-lines-per-function -function useMeshPolyhedraPolyhedronAttributeStyle(): UseMeshPolyhedraPolyhedronAttributeStyleReturn { - const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useMeshPolyhedraPolyhedronAttributeStyle( + sceneId: SceneId, +): UseMeshPolyhedraPolyhedronAttributeStyleReturn { + const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = + useAttributeTimeStepStyle(sceneId); const viewerStore = useViewerStore(); const { meshPolyhedraPolyhedronAttribute, @@ -40,14 +44,14 @@ function useMeshPolyhedraPolyhedronAttributeStyle(): UseMeshPolyhedraPolyhedronA meshPolyhedraPolyhedronAttributeLastItem, meshPolyhedraPolyhedronAttributeItem, meshPolyhedraPolyhedronAttributeStoredConfig, - } = useMeshPolyhedraPolyhedronAttributeConfig(); + } = useMeshPolyhedraPolyhedronAttributeConfig(sceneId); const { meshPolyhedraPolyhedronAttributeRange, meshPolyhedraPolyhedronAttributeColorMap, meshPolyhedraPolyhedronAttributeNoDataColor, - } = useMeshPolyhedraPolyhedronAttributeConfigValues(); + } = useMeshPolyhedraPolyhedronAttributeConfigValues(sceneId); const { mutateMeshPolyhedraPolyhedronStyle, setMeshPolyhedraPolyhedronAttributeStoredConfig } = - useMeshPolyhedraPolyhedronAttributeConfigWriter(); + useMeshPolyhedraPolyhedronAttributeConfigWriter(sceneId); function meshPolyhedraPolyhedronAttributeTimeStep(meshId: MeshId): AttributeTimeStep | undefined { return attributeTimeStep( meshId, @@ -79,6 +83,7 @@ function useMeshPolyhedraPolyhedronAttributeStyle(): UseMeshPolyhedraPolyhedronA const points = [...getRGBPointsFromPreset(colorMap)]; const schema = meshPolyhedraPolyhedronAttributeSchemas.attribute; const params = { + scene_id: sceneId, id: meshId, name: seriesArrayName(meshId, attributeNamesSchema.$id, name), item, diff --git a/internal/stores/data_style/mesh/polyhedra/polyhedron_config.ts b/internal/stores/data_style/mesh/polyhedra/polyhedron_config.ts index 6fe75d403..c2a390db3 100644 --- a/internal/stores/data_style/mesh/polyhedra/polyhedron_config.ts +++ b/internal/stores/data_style/mesh/polyhedra/polyhedron_config.ts @@ -9,6 +9,7 @@ import type { AttributeStoredConfig, } from "@ogw_internal/stores/data_style/attribute_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { defaultAttributeStoredConfig } from "@ogw_internal/stores/data_style/attribute_default"; // Local imports @@ -42,8 +43,10 @@ interface UseMeshPolyhedraPolyhedronAttributeConfigWriterReturn { ) => Promise; } -function useMeshPolyhedraPolyhedronAttributeConfig(): UseMeshPolyhedraPolyhedronAttributeConfigReturn { - const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(); +function useMeshPolyhedraPolyhedronAttributeConfig( + sceneId: SceneId, +): UseMeshPolyhedraPolyhedronAttributeConfigReturn { + const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(sceneId); function meshPolyhedraPolyhedronAttribute(meshId: MeshId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.polyhedron shape is defined by the data style schema. return meshPolyhedraCommonStyle.meshPolyhedraColoring(meshId).polyhedron as AttributeState; @@ -94,12 +97,14 @@ interface UseMeshPolyhedraPolyhedronAttributeConfigValuesReturn { meshPolyhedraPolyhedronAttributeNoDataColor: (meshId: MeshId) => ColorRGBA; } -function useMeshPolyhedraPolyhedronAttributeConfigValues(): UseMeshPolyhedraPolyhedronAttributeConfigValuesReturn { +function useMeshPolyhedraPolyhedronAttributeConfigValues( + sceneId: SceneId, +): UseMeshPolyhedraPolyhedronAttributeConfigValuesReturn { const { meshPolyhedraPolyhedronAttributeName, meshPolyhedraPolyhedronAttributeItem, meshPolyhedraPolyhedronAttributeStoredConfig, - } = useMeshPolyhedraPolyhedronAttributeConfig(); + } = useMeshPolyhedraPolyhedronAttributeConfig(sceneId); function meshPolyhedraPolyhedronAttributeRange(meshId: MeshId): AttributeRange { const name = meshPolyhedraPolyhedronAttributeName(meshId); const item = meshPolyhedraPolyhedronAttributeItem(meshId); @@ -125,8 +130,10 @@ function useMeshPolyhedraPolyhedronAttributeConfigValues(): UseMeshPolyhedraPoly }; } -function useMeshPolyhedraPolyhedronAttributeConfigWriter(): UseMeshPolyhedraPolyhedronAttributeConfigWriterReturn { - const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(); +function useMeshPolyhedraPolyhedronAttributeConfigWriter( + sceneId: SceneId, +): UseMeshPolyhedraPolyhedronAttributeConfigWriterReturn { + const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(sceneId); async function mutateMeshPolyhedraPolyhedronStyle( meshId: MeshId, values: Record, diff --git a/internal/stores/data_style/mesh/polyhedra/vertex.ts b/internal/stores/data_style/mesh/polyhedra/vertex.ts index 8eca9c2ad..db1a18acd 100644 --- a/internal/stores/data_style/mesh/polyhedra/vertex.ts +++ b/internal/stores/data_style/mesh/polyhedra/vertex.ts @@ -8,6 +8,7 @@ import type { } from "@geode/opengeodeweb-viewer/schema_types"; import { DEFAULT_NO_DATA_COLOR } from "@ogw_front/utils/default_styles/constants"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attribute_types"; // Third party imports import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js"; @@ -31,8 +32,11 @@ const meshPolyhedraVertexAttributeSchemas = viewer_schemas.opengeodeweb_viewer.mesh.polyhedra.attribute.vertex; // oxlint-disable-next-line max-lines-per-function -function useMeshPolyhedraVertexAttributeStyle(): UseMeshPolyhedraVertexAttributeStyleReturn { - const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useMeshPolyhedraVertexAttributeStyle( + sceneId: SceneId, +): UseMeshPolyhedraVertexAttributeStyleReturn { + const { attributeTimeStep, setAttributeTimeStep, seriesArrayName } = + useAttributeTimeStepStyle(sceneId); const viewerStore = useViewerStore(); const { meshPolyhedraVertexAttribute, @@ -40,14 +44,14 @@ function useMeshPolyhedraVertexAttributeStyle(): UseMeshPolyhedraVertexAttribute meshPolyhedraVertexAttributeLastItem, meshPolyhedraVertexAttributeItem, meshPolyhedraVertexAttributeStoredConfig, - } = useMeshPolyhedraVertexAttributeConfig(); + } = useMeshPolyhedraVertexAttributeConfig(sceneId); const { meshPolyhedraVertexAttributeRange, meshPolyhedraVertexAttributeColorMap, meshPolyhedraVertexAttributeNoDataColor, - } = useMeshPolyhedraVertexAttributeConfigValues(); + } = useMeshPolyhedraVertexAttributeConfigValues(sceneId); const { mutateMeshPolyhedraVertexStyle, setMeshPolyhedraVertexAttributeStoredConfig } = - useMeshPolyhedraVertexAttributeConfigWriter(); + useMeshPolyhedraVertexAttributeConfigWriter(sceneId); function meshPolyhedraVertexAttributeTimeStep(meshId: MeshId): AttributeTimeStep | undefined { return attributeTimeStep( meshId, @@ -79,6 +83,7 @@ function useMeshPolyhedraVertexAttributeStyle(): UseMeshPolyhedraVertexAttribute const points = [...getRGBPointsFromPreset(colorMap)]; const schema = meshPolyhedraVertexAttributeSchemas.attribute; const params = { + scene_id: sceneId, id: meshId, name: seriesArrayName(meshId, attributeNamesSchema.$id, name), item, diff --git a/internal/stores/data_style/mesh/polyhedra/vertex_config.ts b/internal/stores/data_style/mesh/polyhedra/vertex_config.ts index 54db08180..e91134990 100644 --- a/internal/stores/data_style/mesh/polyhedra/vertex_config.ts +++ b/internal/stores/data_style/mesh/polyhedra/vertex_config.ts @@ -9,6 +9,7 @@ import type { AttributeStoredConfig, } from "@ogw_internal/stores/data_style/attribute_types"; import type { MeshId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { defaultAttributeStoredConfig } from "@ogw_internal/stores/data_style/attribute_default"; // Local imports @@ -39,8 +40,10 @@ interface UseMeshPolyhedraVertexAttributeConfigWriterReturn { ) => Promise; } -function useMeshPolyhedraVertexAttributeConfig(): UseMeshPolyhedraVertexAttributeConfigReturn { - const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(); +function useMeshPolyhedraVertexAttributeConfig( + sceneId: SceneId, +): UseMeshPolyhedraVertexAttributeConfigReturn { + const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(sceneId); function meshPolyhedraVertexAttribute(meshId: MeshId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.vertex shape is defined by the data style schema. return meshPolyhedraCommonStyle.meshPolyhedraColoring(meshId).vertex as AttributeState; @@ -91,12 +94,14 @@ interface UseMeshPolyhedraVertexAttributeConfigValuesReturn { meshPolyhedraVertexAttributeNoDataColor: (meshId: MeshId) => ColorRGBA; } -function useMeshPolyhedraVertexAttributeConfigValues(): UseMeshPolyhedraVertexAttributeConfigValuesReturn { +function useMeshPolyhedraVertexAttributeConfigValues( + sceneId: SceneId, +): UseMeshPolyhedraVertexAttributeConfigValuesReturn { const { meshPolyhedraVertexAttributeName, meshPolyhedraVertexAttributeItem, meshPolyhedraVertexAttributeStoredConfig, - } = useMeshPolyhedraVertexAttributeConfig(); + } = useMeshPolyhedraVertexAttributeConfig(sceneId); function meshPolyhedraVertexAttributeRange(meshId: MeshId): AttributeRange { const name = meshPolyhedraVertexAttributeName(meshId); const item = meshPolyhedraVertexAttributeItem(meshId); @@ -122,8 +127,10 @@ function useMeshPolyhedraVertexAttributeConfigValues(): UseMeshPolyhedraVertexAt }; } -function useMeshPolyhedraVertexAttributeConfigWriter(): UseMeshPolyhedraVertexAttributeConfigWriterReturn { - const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(); +function useMeshPolyhedraVertexAttributeConfigWriter( + sceneId: SceneId, +): UseMeshPolyhedraVertexAttributeConfigWriterReturn { + const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(sceneId); async function mutateMeshPolyhedraVertexStyle( meshId: MeshId, values: Record, diff --git a/internal/stores/data_style/mesh/polyhedra/visibility.ts b/internal/stores/data_style/mesh/polyhedra/visibility.ts index de1c74e9c..ac7786ec2 100644 --- a/internal/stores/data_style/mesh/polyhedra/visibility.ts +++ b/internal/stores/data_style/mesh/polyhedra/visibility.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -10,12 +11,12 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.mesh.polyhedra.visibility; -export function useMeshPolyhedraVisibilityStyle(): { +export function useMeshPolyhedraVisibilityStyle(sceneId: SceneId): { meshPolyhedraVisibility: (meshId: MeshId) => Visibility | undefined; setMeshPolyhedraVisibility: (meshId: MeshId, visibility: Visibility) => Promise; } { const viewerStore = useViewerStore(); - const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(); + const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(sceneId); function meshPolyhedraVisibility(meshId: MeshId): Visibility | undefined { // oxlint-disable-next-line no-unsafe-type-assertion -- visibility is defined as boolean in the data style schema. @@ -25,7 +26,7 @@ export function useMeshPolyhedraVisibilityStyle(): { meshId: MeshId, visibility: Visibility, ): Promise { - const params = { id: meshId, visibility }; + const params = { scene_id: sceneId, id: meshId, visibility }; const result = await viewerStore.request( { schema, From 90edda56224e77def4a67dc2fac38cc10ecdbd79 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:05:04 +0100 Subject: [PATCH 012/121] feat(data_style): scope model styles by scene Co-Authored-By: Claude Opus 5.5 --- .../stores/data_style/model/blocks/color.ts | 11 +++++---- .../stores/data_style/model/blocks/common.ts | 7 +++--- .../stores/data_style/model/blocks/edges.ts | 5 ++-- .../stores/data_style/model/blocks/index.ts | 17 +++++++------- .../stores/data_style/model/blocks/points.ts | 5 ++-- .../data_style/model/blocks/polyhedron.ts | 15 ++++++++---- .../stores/data_style/model/blocks/vertex.ts | 13 +++++++---- .../data_style/model/blocks/visibility.ts | 7 +++--- internal/stores/data_style/model/color.ts | 10 +++++--- internal/stores/data_style/model/common.ts | 14 +++++++---- .../stores/data_style/model/corners/color.ts | 9 ++++---- .../stores/data_style/model/corners/common.ts | 7 +++--- .../stores/data_style/model/corners/index.ts | 11 +++++---- .../stores/data_style/model/corners/vertex.ts | 13 +++++++---- .../data_style/model/corners/visibility.ts | 7 +++--- .../stores/data_style/model/edges/common.ts | 5 ++-- .../data_style/model/edges/component.ts | 12 +++++----- .../stores/data_style/model/edges/index.ts | 11 +++++---- .../data_style/model/edges/visibility.ts | 11 +++++---- .../stores/data_style/model/edges/width.ts | 9 ++++---- internal/stores/data_style/model/index.ts | 23 ++++++++++--------- .../stores/data_style/model/lines/color.ts | 11 +++++---- .../stores/data_style/model/lines/common.ts | 7 +++--- .../stores/data_style/model/lines/edge.ts | 13 +++++++---- .../stores/data_style/model/lines/index.ts | 15 ++++++------ .../stores/data_style/model/lines/points.ts | 5 ++-- .../stores/data_style/model/lines/vertex.ts | 13 +++++++---- .../data_style/model/lines/visibility.ts | 7 +++--- .../stores/data_style/model/points/common.ts | 5 ++-- .../data_style/model/points/component.ts | 12 +++++----- .../stores/data_style/model/points/index.ts | 9 ++++---- .../stores/data_style/model/points/size.ts | 9 ++++---- .../data_style/model/points/visibility.ts | 9 ++++---- .../stores/data_style/model/surfaces/color.ts | 11 +++++---- .../data_style/model/surfaces/common.ts | 7 +++--- .../stores/data_style/model/surfaces/edges.ts | 5 ++-- .../stores/data_style/model/surfaces/index.ts | 17 +++++++------- .../data_style/model/surfaces/points.ts | 5 ++-- .../data_style/model/surfaces/polygon.ts | 15 ++++++++---- .../data_style/model/surfaces/vertex.ts | 13 +++++++---- .../data_style/model/surfaces/visibility.ts | 7 +++--- .../stores/data_style/model/visibility.ts | 15 ++++++------ 42 files changed, 248 insertions(+), 184 deletions(-) diff --git a/internal/stores/data_style/model/blocks/color.ts b/internal/stores/data_style/model/blocks/color.ts index 548839724..c6826ec55 100644 --- a/internal/stores/data_style/model/blocks/color.ts +++ b/internal/stores/data_style/model/blocks/color.ts @@ -1,5 +1,6 @@ import type { BlockId, ModelId } from "@ogw_front/types/identifiers"; import type { ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import { isAttributeValid } from "@ogw_internal/stores/data_style/attribute_valid"; import { useDataStore } from "@ogw_front/stores/data"; @@ -11,7 +12,7 @@ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed const schema = viewer_schemas.opengeodeweb_viewer.model.blocks.color; -export function useModelBlocksColor(): { +export function useModelBlocksColor(sceneId: SceneId): { modelBlockColoring: (modelId: ModelId, block_id?: BlockId) => StyleValues; modelBlockColor: (modelId: ModelId, block_id?: BlockId) => ColorRGBA | undefined; setModelBlocksColor: ( @@ -30,10 +31,10 @@ export function useModelBlocksColor(): { ) => Promise; } { const dataStore = useDataStore(); - const modelCommonStyle = useModelCommonStyle(); - const modelBlocksCommonStyle = useModelBlocksCommonStyle(); - const modelBlocksVertexAttribute = useModelBlocksVertexAttribute(); - const modelBlocksPolyhedronAttribute = useModelBlocksPolyhedronAttribute(); + const modelCommonStyle = useModelCommonStyle(sceneId); + const modelBlocksCommonStyle = useModelBlocksCommonStyle(sceneId); + const modelBlocksVertexAttribute = useModelBlocksVertexAttribute(sceneId); + const modelBlocksPolyhedronAttribute = useModelBlocksPolyhedronAttribute(sceneId); function modelBlockColoring(modelId: ModelId, block_id?: BlockId): StyleValues { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring shape is defined by the data style schema. diff --git a/internal/stores/data_style/model/blocks/common.ts b/internal/stores/data_style/model/blocks/common.ts index 540c119cf..ae00243d3 100644 --- a/internal/stores/data_style/model/blocks/common.ts +++ b/internal/stores/data_style/model/blocks/common.ts @@ -1,10 +1,11 @@ import type { BlockId, ModelId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import merge from "lodash/merge"; import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; import { useModelCommonStyle } from "@ogw_internal/stores/data_style/model/common"; -export function useModelBlocksCommonStyle(): { +export function useModelBlocksCommonStyle(sceneId: SceneId): { modelBlocksStyle: (modelId: ModelId) => StyleValues; modelBlockStyle: (modelId: ModelId, block_id?: BlockId) => StyleValues; modelBlockColoring: (modelId: ModelId, block_id?: BlockId) => StyleValues; @@ -15,8 +16,8 @@ export function useModelBlocksCommonStyle(): { ) => Promise; mutateModelBlocksTypeColoring: (modelId: ModelId, values: StyleValues) => Promise; } { - const dataStyleState = useDataStyleState(); - const modelCommonStyle = useModelCommonStyle(); + const dataStyleState = useDataStyleState(sceneId); + const modelCommonStyle = useModelCommonStyle(sceneId); function modelBlocksStyle(modelId: ModelId): StyleValues { return dataStyleState.getStyle(modelId).blocks ?? {}; diff --git a/internal/stores/data_style/model/blocks/edges.ts b/internal/stores/data_style/model/blocks/edges.ts index a6c6323d8..7cb5b9dbb 100644 --- a/internal/stores/data_style/model/blocks/edges.ts +++ b/internal/stores/data_style/model/blocks/edges.ts @@ -2,6 +2,7 @@ import { type ModelComponentEdgesStyle, useModelComponentEdgesStyle, } from "@ogw_internal/stores/data_style/model/edges/component"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; interface UseModelBlocksEdgesStyleReturn { modelBlockEdgesVisibility: ModelComponentEdgesStyle["visibility"]; @@ -25,8 +26,8 @@ interface UseModelBlocksEdgesStyleReturn { applyModelBlocksEdgesStyle: ModelComponentEdgesStyle["applyEdgesStyle"]; } -export function useModelBlocksEdgesStyle(): UseModelBlocksEdgesStyleReturn { - const edges = useModelComponentEdgesStyle("Block"); +export function useModelBlocksEdgesStyle(sceneId: SceneId): UseModelBlocksEdgesStyleReturn { + const edges = useModelComponentEdgesStyle(sceneId, "Block"); return { modelBlockEdgesVisibility: edges.visibility, modelBlockEdgesWidth: edges.width, diff --git a/internal/stores/data_style/model/blocks/index.ts b/internal/stores/data_style/model/blocks/index.ts index db94bba59..ed370181b 100644 --- a/internal/stores/data_style/model/blocks/index.ts +++ b/internal/stores/data_style/model/blocks/index.ts @@ -4,6 +4,7 @@ import { applyModelBlocksPolyhedronColoring, applyModelBlocksVertexColoring, } from "./apply_coloring"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { useDataStore } from "@ogw_front/stores/data"; import { useModelBlocksColor } from "./color"; import { useModelBlocksCommonStyle } from "./common"; @@ -29,15 +30,15 @@ type UseModelBlocksStyleReturn = { ReturnType; // oxlint-disable-next-line max-lines-per-function -export function useModelBlocksStyle(): UseModelBlocksStyleReturn { +export function useModelBlocksStyle(sceneId: SceneId): UseModelBlocksStyleReturn { const dataStore = useDataStore(); - const modelCommonStyle = useModelBlocksCommonStyle(); - const modelVisibilityStyle = useModelBlocksVisibility(); - const modelColorStyle = useModelBlocksColor(); - const modelBlocksVertexAttribute = useModelBlocksVertexAttribute(); - const modelBlocksPolyhedronAttribute = useModelBlocksPolyhedronAttribute(); - const modelBlocksPointsStyle = useModelBlocksPointsStyle(); - const modelBlocksEdgesStyle = useModelBlocksEdgesStyle(); + const modelCommonStyle = useModelBlocksCommonStyle(sceneId); + const modelVisibilityStyle = useModelBlocksVisibility(sceneId); + const modelColorStyle = useModelBlocksColor(sceneId); + const modelBlocksVertexAttribute = useModelBlocksVertexAttribute(sceneId); + const modelBlocksPolyhedronAttribute = useModelBlocksPolyhedronAttribute(sceneId); + const modelBlocksPointsStyle = useModelBlocksPointsStyle(sceneId); + const modelBlocksEdgesStyle = useModelBlocksEdgesStyle(sceneId); async function applyModelBlocksVisibilityStyle( modelId: ModelId, diff --git a/internal/stores/data_style/model/blocks/points.ts b/internal/stores/data_style/model/blocks/points.ts index 942b39dbf..137e0b2dc 100644 --- a/internal/stores/data_style/model/blocks/points.ts +++ b/internal/stores/data_style/model/blocks/points.ts @@ -2,6 +2,7 @@ import { type ModelComponentPointsStyle, useModelComponentPointsStyle, } from "@ogw_internal/stores/data_style/model/points/component"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; interface UseModelBlocksPointsStyleReturn { modelBlockPointsVisibility: ModelComponentPointsStyle["visibility"]; @@ -25,8 +26,8 @@ interface UseModelBlocksPointsStyleReturn { applyModelBlocksPointsStyle: ModelComponentPointsStyle["applyPointsStyle"]; } -export function useModelBlocksPointsStyle(): UseModelBlocksPointsStyleReturn { - const points = useModelComponentPointsStyle("Block"); +export function useModelBlocksPointsStyle(sceneId: SceneId): UseModelBlocksPointsStyleReturn { + const points = useModelComponentPointsStyle(sceneId, "Block"); return { modelBlockPointsVisibility: points.visibility, modelBlockPointsSize: points.size, diff --git a/internal/stores/data_style/model/blocks/polyhedron.ts b/internal/stores/data_style/model/blocks/polyhedron.ts index 73d2dbe57..73d45cdba 100644 --- a/internal/stores/data_style/model/blocks/polyhedron.ts +++ b/internal/stores/data_style/model/blocks/polyhedron.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // oxlint-disable eslint/max-lines import type { AttributeColorMap, @@ -117,9 +118,10 @@ type ModelBlocksPolyhedronAttributeGetters = Pick< // oxlint-disable-next-line max-lines-per-function function useModelBlocksPolyhedronAttributeGetters( + sceneId: SceneId, modelBlocksCommonStyle: ReturnType, ): ModelBlocksPolyhedronAttributeGetters { - const { attributeTimeStep } = useAttributeTimeStepStyle(); + const { attributeTimeStep } = useAttributeTimeStepStyle(sceneId); function modelBlocksPolyhedronAttribute(modelId: ModelId, blockId?: BlockId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.polyhedron shape is defined by the data style schema. return modelBlocksCommonStyle.modelBlockColoring(modelId, blockId).polyhedron as AttributeState; @@ -214,10 +216,12 @@ function useModelBlocksPolyhedronAttributeGetters( } // oxlint-disable-next-line max-lines-per-function -function useModelBlocksPolyhedronAttribute(): UseModelBlocksPolyhedronAttributeReturn { - const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useModelBlocksPolyhedronAttribute( + sceneId: SceneId, +): UseModelBlocksPolyhedronAttributeReturn { + const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(sceneId); const dataStore = useDataStore(); - const modelBlocksCommonStyle = useModelBlocksCommonStyle(); + const modelBlocksCommonStyle = useModelBlocksCommonStyle(sceneId); const { modelBlocksPolyhedronAttributeStoredConfig, modelBlocksPolyhedronAttributeName, @@ -227,7 +231,7 @@ function useModelBlocksPolyhedronAttribute(): UseModelBlocksPolyhedronAttributeR modelBlocksPolyhedronAttributeColorMap, modelBlocksPolyhedronAttributeNoDataColor, modelBlocksPolyhedronAttributeTimeStep, - } = useModelBlocksPolyhedronAttributeGetters(modelBlocksCommonStyle); + } = useModelBlocksPolyhedronAttributeGetters(sceneId, modelBlocksCommonStyle); const viewerStore = useViewerStore(); async function mutateModelBlocksPolyhedronStyle( modelId: ModelId, @@ -293,6 +297,7 @@ function useModelBlocksPolyhedronAttribute(): UseModelBlocksPolyhedronAttributeR const points = [...getRGBPointsFromPreset(colorMap)]; const viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, blockIds); const params = { + scene_id: sceneId, id: modelId, block_ids: viewer_ids, name: seriesArrayName(modelId, modelBlockPolyhedronAttributeSchema.$id, name), diff --git a/internal/stores/data_style/model/blocks/vertex.ts b/internal/stores/data_style/model/blocks/vertex.ts index e8f85c449..c3b8571b6 100644 --- a/internal/stores/data_style/model/blocks/vertex.ts +++ b/internal/stores/data_style/model/blocks/vertex.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // oxlint-disable eslint/max-lines import type { AttributeColorMap, @@ -116,9 +117,10 @@ type ModelBlocksVertexAttributeGetters = Pick< // oxlint-disable-next-line max-lines-per-function function useModelBlocksVertexAttributeGetters( + sceneId: SceneId, modelBlocksCommonStyle: ReturnType, ): ModelBlocksVertexAttributeGetters { - const { attributeTimeStep } = useAttributeTimeStepStyle(); + const { attributeTimeStep } = useAttributeTimeStepStyle(sceneId); function modelBlocksVertexAttribute(modelId: ModelId, blockId?: BlockId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.vertex shape is defined by the data style schema. return modelBlocksCommonStyle.modelBlockColoring(modelId, blockId).vertex as AttributeState; @@ -207,10 +209,10 @@ function useModelBlocksVertexAttributeGetters( } // oxlint-disable-next-line max-lines-per-function -function useModelBlocksVertexAttribute(): UseModelBlocksVertexAttributeReturn { - const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useModelBlocksVertexAttribute(sceneId: SceneId): UseModelBlocksVertexAttributeReturn { + const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(sceneId); const dataStore = useDataStore(); - const modelBlocksCommonStyle = useModelBlocksCommonStyle(); + const modelBlocksCommonStyle = useModelBlocksCommonStyle(sceneId); const { modelBlocksVertexAttributeStoredConfig, modelBlocksVertexAttributeName, @@ -220,7 +222,7 @@ function useModelBlocksVertexAttribute(): UseModelBlocksVertexAttributeReturn { modelBlocksVertexAttributeColorMap, modelBlocksVertexAttributeNoDataColor, modelBlocksVertexAttributeTimeStep, - } = useModelBlocksVertexAttributeGetters(modelBlocksCommonStyle); + } = useModelBlocksVertexAttributeGetters(sceneId, modelBlocksCommonStyle); const viewerStore = useViewerStore(); async function mutateModelBlocksVertexStyle( modelId: ModelId, @@ -286,6 +288,7 @@ function useModelBlocksVertexAttribute(): UseModelBlocksVertexAttributeReturn { const points = [...getRGBPointsFromPreset(colorMap)]; const block_viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, blockIds); const params = { + scene_id: sceneId, id: modelId, block_ids: block_viewer_ids, name: seriesArrayName(modelId, attributeSchema.$id, name), diff --git a/internal/stores/data_style/model/blocks/visibility.ts b/internal/stores/data_style/model/blocks/visibility.ts index bfaea6972..b0640baf8 100644 --- a/internal/stores/data_style/model/blocks/visibility.ts +++ b/internal/stores/data_style/model/blocks/visibility.ts @@ -1,4 +1,5 @@ import type { BlockId, ModelId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { Visibility } from "@geode/opengeodeweb-viewer/schema_types"; import { useModelBlocksCommonStyle } from "./common"; import { useModelCommonStyle } from "@ogw_internal/stores/data_style/model/common"; @@ -6,7 +7,7 @@ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed const schema = viewer_schemas.opengeodeweb_viewer.model.blocks.visibility; -export function useModelBlocksVisibility(): { +export function useModelBlocksVisibility(sceneId: SceneId): { setModelBlocksVisibility: ( modelId: ModelId, blocks_ids: BlockId[], @@ -14,8 +15,8 @@ export function useModelBlocksVisibility(): { ) => Promise; modelBlockVisibility: (modelId: ModelId, block_id?: BlockId) => unknown; } { - const modelCommonStyle = useModelCommonStyle(); - const modelBlocksCommonStyle = useModelBlocksCommonStyle(); + const modelCommonStyle = useModelCommonStyle(sceneId); + const modelBlocksCommonStyle = useModelBlocksCommonStyle(sceneId); function modelBlockVisibility(modelId: ModelId, block_id?: BlockId): unknown { return modelBlocksCommonStyle.modelBlockStyle(modelId, block_id).visibility; diff --git a/internal/stores/data_style/model/color.ts b/internal/stores/data_style/model/color.ts index cdac9806a..6af7fccc1 100644 --- a/internal/stores/data_style/model/color.ts +++ b/internal/stores/data_style/model/color.ts @@ -7,6 +7,7 @@ import type { } from "@geode/opengeodeweb-viewer/schema_types"; import type { ModelId } from "@ogw_front/types/identifiers"; // oxlint-disable eslint/max-lines +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import { dispatchToComponentTypes } from "./visibility"; import { useDataStore } from "@ogw_front/stores/data"; @@ -83,7 +84,10 @@ async function applyAttributeAccessors( } // oxlint-disable-next-line max-lines-per-function -function useModelColorStyle(componentStyleFunctions: ComponentStyleFunctions): { +function useModelColorStyle( + sceneId: SceneId, + componentStyleFunctions: ComponentStyleFunctions, +): { getModelColor: (modelId: ModelId) => ColorRGBA | undefined; getModelActiveColoring: (modelId: ModelId) => unknown; getModelComponentColor: (modelId: ModelId, componentId: string) => unknown; @@ -110,8 +114,8 @@ function useModelColorStyle(componentStyleFunctions: ComponentStyleFunctions): { ) => Promise; } { const dataStore = useDataStore(); - const dataStyleState = useDataStyleState(); - const modelCommonStyle = useModelCommonStyle(); + const dataStyleState = useDataStyleState(sceneId); + const modelCommonStyle = useModelCommonStyle(sceneId); // oxlint-disable-next-line no-unsafe-type-assertion -- componentStyleFunctions is a dynamic dispatch table typed any by design; see ComponentStyleFunctions comment above. const Surface = componentStyleFunctions.Surface as DynamicStyleFunctions; // oxlint-disable-next-line no-unsafe-type-assertion -- componentStyleFunctions is a dynamic dispatch table typed any by design; see ComponentStyleFunctions comment above. diff --git a/internal/stores/data_style/model/common.ts b/internal/stores/data_style/model/common.ts index 601169999..723365d2a 100644 --- a/internal/stores/data_style/model/common.ts +++ b/internal/stores/data_style/model/common.ts @@ -7,6 +7,7 @@ import { } from "./common_mutations"; import type { ModelId } from "@ogw_front/types/identifiers"; import type { ParamsOf } from "@ogw_shared/utils/types.js"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import { useDataStore } from "@ogw_front/stores/data"; import { useViewerStore } from "@ogw_front/stores/viewer"; @@ -62,12 +63,14 @@ interface UseModelCommonStyleReturn { } // oxlint-disable-next-line max-lines-per-function -export function useModelCommonStyle(): UseModelCommonStyleReturn { +export function useModelCommonStyle(sceneId: SceneId): UseModelCommonStyleReturn { const dataStore = useDataStore(); const viewerStore = useViewerStore(); - const { mutateComponentStyle, mutateModelComponentTypeStyle } = useModelComponentStyleMutations(); - const { mutateComponentStyles } = useModelComponentsStyleMutation(); - const { bulkMutateComponentStylesPerComponent } = useModelComponentsPerComponentStyleMutation(); + const { mutateComponentStyle, mutateModelComponentTypeStyle } = + useModelComponentStyleMutations(sceneId); + const { mutateComponentStyles } = useModelComponentsStyleMutation(sceneId); + const { bulkMutateComponentStylesPerComponent } = + useModelComponentsPerComponentStyleMutation(sceneId); async function setModelTypeColor( modelId: ModelId, component_ids: string[], @@ -96,6 +99,7 @@ export function useModelCommonStyle(): UseModelCommonStyleReturn { throw new Error(`Unknown model color mode: ${activeColoring}`); } const params = { + scene_id: sceneId, id: modelId, block_ids: viewer_ids, color_mode: activeColoring, @@ -150,7 +154,7 @@ export function useModelCommonStyle(): UseModelCommonStyleReturn { if (!viewer_ids?.length) { return undefined; } - const params = { id: modelId, block_ids: viewer_ids, visibility }; + const params = { scene_id: sceneId, id: modelId, block_ids: viewer_ids, visibility }; const result = await viewerStore.request( { schema, params }, { diff --git a/internal/stores/data_style/model/corners/color.ts b/internal/stores/data_style/model/corners/color.ts index 649f98af1..a36e4602c 100644 --- a/internal/stores/data_style/model/corners/color.ts +++ b/internal/stores/data_style/model/corners/color.ts @@ -1,5 +1,6 @@ import type { CornerId, ModelId } from "@ogw_front/types/identifiers"; import type { ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import { isAttributeValid } from "@ogw_internal/stores/data_style/attribute_valid"; import { useDataStore } from "@ogw_front/stores/data"; @@ -29,11 +30,11 @@ interface ModelCornersColorApi { ) => Promise; } -export function useModelCornersColor(): ModelCornersColorApi { +export function useModelCornersColor(sceneId: SceneId): ModelCornersColorApi { const dataStore = useDataStore(); - const modelCommonStyle = useModelCommonStyle(); - const modelCornersCommonStyle = useModelCornersCommonStyle(); - const modelCornersVertexAttribute = useModelCornersVertexAttribute(); + const modelCommonStyle = useModelCommonStyle(sceneId); + const modelCornersCommonStyle = useModelCornersCommonStyle(sceneId); + const modelCornersVertexAttribute = useModelCornersVertexAttribute(sceneId); function modelCornerColoring(modelId: ModelId, corner_id?: CornerId): StyleValues { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring is a StyleValues sub-object stored under a StyleValues index signature. diff --git a/internal/stores/data_style/model/corners/common.ts b/internal/stores/data_style/model/corners/common.ts index afc54a0d7..1c6d8e1c9 100644 --- a/internal/stores/data_style/model/corners/common.ts +++ b/internal/stores/data_style/model/corners/common.ts @@ -1,10 +1,11 @@ import type { CornerId, ModelId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import merge from "lodash/merge"; import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; import { useModelCommonStyle } from "@ogw_internal/stores/data_style/model/common"; -export function useModelCornersCommonStyle(): { +export function useModelCornersCommonStyle(sceneId: SceneId): { modelCornersStyle: (modelId: ModelId) => StyleValues; modelCornerStyle: (modelId: ModelId, corner_id?: CornerId) => StyleValues; modelCornerColoring: (modelId: ModelId, corner_id?: CornerId) => StyleValues; @@ -15,8 +16,8 @@ export function useModelCornersCommonStyle(): { ) => Promise; mutateModelCornersTypeColoring: (modelId: ModelId, values: StyleValues) => Promise; } { - const dataStyleState = useDataStyleState(); - const modelCommonStyle = useModelCommonStyle(); + const dataStyleState = useDataStyleState(sceneId); + const modelCommonStyle = useModelCommonStyle(sceneId); function modelCornersStyle(modelId: ModelId): StyleValues { const { corners } = dataStyleState.getStyle(modelId); diff --git a/internal/stores/data_style/model/corners/index.ts b/internal/stores/data_style/model/corners/index.ts index 6134792dd..9433f7c6c 100644 --- a/internal/stores/data_style/model/corners/index.ts +++ b/internal/stores/data_style/model/corners/index.ts @@ -1,5 +1,6 @@ import type { CornerId, ModelId } from "@ogw_front/types/identifiers"; import type { ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attribute_types"; import { isAttributeValid } from "@ogw_internal/stores/data_style/attribute_valid"; import { useDataStore } from "@ogw_front/stores/data"; @@ -29,12 +30,12 @@ type ModelCornersStyleApi = ReturnType & setModelCornersDefaultStyle: (modelId: ModelId) => Promise; }; -export function useModelCornersStyle(): ModelCornersStyleApi { +export function useModelCornersStyle(sceneId: SceneId): ModelCornersStyleApi { const dataStore = useDataStore(); - const modelCommonStyle = useModelCornersCommonStyle(); - const modelVisibilityStyle = useModelCornersVisibility(); - const modelColorStyle = useModelCornersColor(); - const modelCornersVertexAttribute = useModelCornersVertexAttribute(); + const modelCommonStyle = useModelCornersCommonStyle(sceneId); + const modelVisibilityStyle = useModelCornersVisibility(sceneId); + const modelColorStyle = useModelCornersColor(sceneId); + const modelCornersVertexAttribute = useModelCornersVertexAttribute(sceneId); async function applyModelCornersVisibilityStyle( modelId: ModelId, diff --git a/internal/stores/data_style/model/corners/vertex.ts b/internal/stores/data_style/model/corners/vertex.ts index b66d72b10..43889d552 100644 --- a/internal/stores/data_style/model/corners/vertex.ts +++ b/internal/stores/data_style/model/corners/vertex.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // oxlint-disable eslint/max-lines import type { AttributeColorMap, @@ -102,9 +103,10 @@ type ModelCornersVertexAttributeGetters = Pick< // oxlint-disable-next-line max-lines-per-function function useModelCornersVertexAttributeGetters( + sceneId: SceneId, modelCornersCommonStyle: ReturnType, ): ModelCornersVertexAttributeGetters { - const { attributeTimeStep } = useAttributeTimeStepStyle(); + const { attributeTimeStep } = useAttributeTimeStepStyle(sceneId); function modelCornersVertexAttribute(modelId: ModelId, cornerId?: CornerId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- vertex is a StyleValues sub-object stored under a StyleValues index signature. return modelCornersCommonStyle.modelCornerColoring(modelId, cornerId).vertex as AttributeState; @@ -198,10 +200,10 @@ function useModelCornersVertexAttributeGetters( } // oxlint-disable-next-line max-lines-per-function -function useModelCornersVertexAttribute(): ModelCornersVertexAttributeApi { - const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useModelCornersVertexAttribute(sceneId: SceneId): ModelCornersVertexAttributeApi { + const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(sceneId); const dataStore = useDataStore(); - const modelCornersCommonStyle = useModelCornersCommonStyle(); + const modelCornersCommonStyle = useModelCornersCommonStyle(sceneId); const { modelCornersVertexAttributeStoredConfig, modelCornersVertexAttributeName, @@ -211,7 +213,7 @@ function useModelCornersVertexAttribute(): ModelCornersVertexAttributeApi { modelCornersVertexAttributeColorMap, modelCornersVertexAttributeNoDataColor, modelCornersVertexAttributeTimeStep, - } = useModelCornersVertexAttributeGetters(modelCornersCommonStyle); + } = useModelCornersVertexAttributeGetters(sceneId, modelCornersCommonStyle); const viewerStore = useViewerStore(); async function mutateModelCornersVertexStyle( modelId: ModelId, @@ -269,6 +271,7 @@ function useModelCornersVertexAttribute(): ModelCornersVertexAttributeApi { const points = [...getRGBPointsFromPreset(colorMap)]; const corner_viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, cornerIds); const params = { + scene_id: sceneId, id: modelId, block_ids: corner_viewer_ids, name: seriesArrayName(modelId, attributeSchema.$id, name), diff --git a/internal/stores/data_style/model/corners/visibility.ts b/internal/stores/data_style/model/corners/visibility.ts index 99b58b65f..0367b6503 100644 --- a/internal/stores/data_style/model/corners/visibility.ts +++ b/internal/stores/data_style/model/corners/visibility.ts @@ -1,4 +1,5 @@ import type { CornerId, ModelId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { Visibility } from "@geode/opengeodeweb-viewer/schema_types"; import { useModelCommonStyle } from "@ogw_internal/stores/data_style/model/common"; import { useModelCornersCommonStyle } from "./common"; @@ -15,9 +16,9 @@ interface ModelCornersVisibilityApi { modelCornerVisibility: (modelId: ModelId, corner_id?: CornerId) => unknown; } -export function useModelCornersVisibility(): ModelCornersVisibilityApi { - const modelCommonStyle = useModelCommonStyle(); - const modelCornersCommonStyle = useModelCornersCommonStyle(); +export function useModelCornersVisibility(sceneId: SceneId): ModelCornersVisibilityApi { + const modelCommonStyle = useModelCommonStyle(sceneId); + const modelCornersCommonStyle = useModelCornersCommonStyle(sceneId); function modelCornerVisibility(modelId: ModelId, corner_id?: CornerId): unknown { return modelCornersCommonStyle.modelCornerStyle(modelId, corner_id).visibility; diff --git a/internal/stores/data_style/model/edges/common.ts b/internal/stores/data_style/model/edges/common.ts index 386eb11e0..df054b8af 100644 --- a/internal/stores/data_style/model/edges/common.ts +++ b/internal/stores/data_style/model/edges/common.ts @@ -1,12 +1,13 @@ import type { ModelId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; -export function useModelEdgesCommonStyle(): { +export function useModelEdgesCommonStyle(sceneId: SceneId): { modelEdgesStyle: (modelId: ModelId) => StyleValues; mutateModelEdgesStyle: (modelId: ModelId, values: StyleValues) => Promise; } { - const dataStyleState = useDataStyleState(); + const dataStyleState = useDataStyleState(sceneId); async function mutateModelEdgesStyle(modelId: ModelId, values: StyleValues): Promise { const result = await dataStyleState.mutateStyle(modelId, { diff --git a/internal/stores/data_style/model/edges/component.ts b/internal/stores/data_style/model/edges/component.ts index e88d3c747..646df23d7 100644 --- a/internal/stores/data_style/model/edges/component.ts +++ b/internal/stores/data_style/model/edges/component.ts @@ -18,7 +18,7 @@ import { EDGES_DEFAULT_VISIBILITY, EDGES_DEFAULT_WIDTH, } from "@ogw_front/utils/default_styles/constants"; -import type { ModelId } from "@ogw_front/types/identifiers"; +import type { ModelId, SceneId } from "@ogw_front/types/identifiers"; import { defaultAttributeStoredConfig } from "@ogw_internal/stores/data_style/attribute_default"; import { getRGBPointsFromPreset } from "@ogw_front/utils/colormap"; import { groupBy } from "@ogw_internal/stores/data_style/model/component_style"; @@ -60,12 +60,12 @@ interface EdgesStyle { // Return type is inferred, see ModelComponentEdgesStyle: signatures live on the functions only // oxlint-disable-next-line max-lines-per-function, max-statements, typescript/explicit-function-return-type, typescript/explicit-module-boundary-types -function useModelComponentEdgesStyle(type: EdgesComponentType) { +function useModelComponentEdgesStyle(sceneId: SceneId, type: EdgesComponentType) { const dataStore = useDataStore(); - const dataStyleState = useDataStyleState(); - const modelCommonStyle = useModelCommonStyle(); + const dataStyleState = useDataStyleState(sceneId); + const modelCommonStyle = useModelCommonStyle(sceneId); const viewerStore = useViewerStore(); - const { seriesArrayName } = useAttributeTimeStepStyle(); + const { seriesArrayName } = useAttributeTimeStepStyle(sceneId); const schemas = modelSchemas[COMPONENT_TYPE_KEYS[type]].edges; // Without an explicit edges style, components follow the model edges style @@ -186,7 +186,7 @@ function useModelComponentEdgesStyle(type: EdgesComponentType) { const { style, ...params } = values; const result = await viewerStore.request( // oxlint-disable-next-line no-unsafe-type-assertion, no-unnecessary-type-assertion -- params match the edges schema of every component type. - { schema, params: { id: modelId, block_ids, ...params } } as Parameters< + { schema, params: { scene_id: sceneId, id: modelId, block_ids, ...params } } as Parameters< typeof viewerStore.request >[0], { diff --git a/internal/stores/data_style/model/edges/index.ts b/internal/stores/data_style/model/edges/index.ts index 91c692b0f..8fd9cdc94 100644 --- a/internal/stores/data_style/model/edges/index.ts +++ b/internal/stores/data_style/model/edges/index.ts @@ -1,13 +1,16 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { useModelEdgesCommonStyle } from "./common"; import { useModelEdgesVisibilityStyle } from "./visibility"; import { useModelEdgesWidthStyle } from "./width"; -export function useModelEdgesStyle(): ReturnType & +export function useModelEdgesStyle( + sceneId: SceneId, +): ReturnType & ReturnType & ReturnType { - const modelEdgesCommonStyle = useModelEdgesCommonStyle(); - const modelEdgesVisibilityStyle = useModelEdgesVisibilityStyle(); - const modelEdgesWidthStyle = useModelEdgesWidthStyle(); + const modelEdgesCommonStyle = useModelEdgesCommonStyle(sceneId); + const modelEdgesVisibilityStyle = useModelEdgesVisibilityStyle(sceneId); + const modelEdgesWidthStyle = useModelEdgesWidthStyle(sceneId); return { ...modelEdgesCommonStyle, diff --git a/internal/stores/data_style/model/edges/visibility.ts b/internal/stores/data_style/model/edges/visibility.ts index e668ac131..6ffef087a 100644 --- a/internal/stores/data_style/model/edges/visibility.ts +++ b/internal/stores/data_style/model/edges/visibility.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -21,12 +22,12 @@ interface ModelEdgesVisibilityStyleApi { applyModelEdgesStyle: (modelId: ModelId) => Promise; } -export function useModelEdgesVisibilityStyle(): ModelEdgesVisibilityStyleApi { +export function useModelEdgesVisibilityStyle(sceneId: SceneId): ModelEdgesVisibilityStyleApi { const viewerStore = useViewerStore(); - const modelEdgesCommonStyle = useModelEdgesCommonStyle(); - const modelEdgesWidthStyle = useModelEdgesWidthStyle(); + const modelEdgesCommonStyle = useModelEdgesCommonStyle(sceneId); + const modelEdgesWidthStyle = useModelEdgesWidthStyle(sceneId); const componentsEdgesStyles = EDGES_COMPONENT_TYPES.map((type) => - useModelComponentEdgesStyle(type), + useModelComponentEdgesStyle(sceneId, type), ); function modelEdgesVisibility(modelId: ModelId): Visibility | undefined { @@ -41,7 +42,7 @@ export function useModelEdgesVisibilityStyle(): ModelEdgesVisibilityStyleApi { modelId: ModelId, visibility: Visibility, ): Promise { - const params = { id: modelId, visibility }; + const params = { scene_id: sceneId, id: modelId, visibility }; const result = await viewerStore.request( { schema, params }, { diff --git a/internal/stores/data_style/model/edges/width.ts b/internal/stores/data_style/model/edges/width.ts index c903b50a6..0c58b0475 100644 --- a/internal/stores/data_style/model/edges/width.ts +++ b/internal/stores/data_style/model/edges/width.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -14,14 +15,14 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.model.edges.width; -export function useModelEdgesWidthStyle(): { +export function useModelEdgesWidthStyle(sceneId: SceneId): { modelEdgesWidth: (modelId: ModelId) => EdgeWidth | undefined; setModelEdgesWidth: (modelId: ModelId, width: EdgeWidth) => Promise; } { const viewerStore = useViewerStore(); - const modelEdgesCommonStyle = useModelEdgesCommonStyle(); + const modelEdgesCommonStyle = useModelEdgesCommonStyle(sceneId); const componentsEdgesStyles = EDGES_COMPONENT_TYPES.map((type) => - useModelComponentEdgesStyle(type), + useModelComponentEdgesStyle(sceneId, type), ); function modelEdgesWidth(modelId: ModelId): EdgeWidth | undefined { @@ -30,7 +31,7 @@ export function useModelEdgesWidthStyle(): { } async function setModelEdgesWidth(modelId: ModelId, width: EdgeWidth): Promise { - const params = { id: modelId, width }; + const params = { scene_id: sceneId, id: modelId, width }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/model/index.ts b/internal/stores/data_style/model/index.ts index 3a3d57875..bedd5428d 100644 --- a/internal/stores/data_style/model/index.ts +++ b/internal/stores/data_style/model/index.ts @@ -1,5 +1,6 @@ import type { ComputedRef } from "vue"; import type { ModelId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { useDataStore } from "@ogw_front/stores/data"; import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; import { useModelBlocksStyle } from "./blocks"; @@ -26,15 +27,15 @@ type UseModelStyleReturn = ReturnType & }; // oxlint-disable-next-line max-lines-per-function, max-statements -function useModelStyle(): UseModelStyleReturn { +function useModelStyle(sceneId: SceneId): UseModelStyleReturn { const dataStore = useDataStore(); - const dataStyleState = useDataStyleState(); - const modelCornersStyle = useModelCornersStyle(); - const modelBlocksStyle = useModelBlocksStyle(); - const modelEdgesStyle = useModelEdgesStyle(); - const modelLinesStyle = useModelLinesStyle(); - const modelPointsStyle = useModelPointsStyle(); - const modelSurfacesStyle = useModelSurfacesStyle(); + const dataStyleState = useDataStyleState(sceneId); + const modelCornersStyle = useModelCornersStyle(sceneId); + const modelBlocksStyle = useModelBlocksStyle(sceneId); + const modelEdgesStyle = useModelEdgesStyle(sceneId); + const modelLinesStyle = useModelLinesStyle(sceneId); + const modelPointsStyle = useModelPointsStyle(sceneId); + const modelSurfacesStyle = useModelSurfacesStyle(sceneId); const componentStyleFunctions = { Corner: modelCornersStyle, @@ -43,11 +44,11 @@ function useModelStyle(): UseModelStyleReturn { Block: modelBlocksStyle, }; - const modelColorStyle = useModelColorStyle(componentStyleFunctions); - const modelVisibilityStyle = useModelVisibilityStyle(componentStyleFunctions); + const modelColorStyle = useModelColorStyle(sceneId, componentStyleFunctions); + const modelVisibilityStyle = useModelVisibilityStyle(sceneId, componentStyleFunctions); function visibleMeshComponents(modelId: ModelId): ComputedRef { - return useModelSelection(modelId, dataStyleState); + return useModelSelection(sceneId, modelId, dataStyleState); } async function applyModelStyle(modelId: ModelId): Promise { diff --git a/internal/stores/data_style/model/lines/color.ts b/internal/stores/data_style/model/lines/color.ts index df1e839bf..27d24d78f 100644 --- a/internal/stores/data_style/model/lines/color.ts +++ b/internal/stores/data_style/model/lines/color.ts @@ -1,5 +1,6 @@ import type { LineId, ModelId } from "@ogw_front/types/identifiers"; import type { ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import { isAttributeValid } from "@ogw_internal/stores/data_style/attribute_valid"; import { useDataStore } from "@ogw_front/stores/data"; @@ -11,7 +12,7 @@ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed const schema = viewer_schemas.opengeodeweb_viewer.model.lines.color; -export function useModelLinesColor(): { +export function useModelLinesColor(sceneId: SceneId): { setModelLinesColor: ( modelId: ModelId, lines_ids: LineId[], @@ -30,10 +31,10 @@ export function useModelLinesColor(): { ) => Promise; } { const dataStore = useDataStore(); - const modelCommonStyle = useModelCommonStyle(); - const modelLinesCommonStyle = useModelLinesCommonStyle(); - const modelLinesVertexAttribute = useModelLinesVertexAttribute(); - const modelLinesEdgeAttribute = useModelLinesEdgeAttribute(); + const modelCommonStyle = useModelCommonStyle(sceneId); + const modelLinesCommonStyle = useModelLinesCommonStyle(sceneId); + const modelLinesVertexAttribute = useModelLinesVertexAttribute(sceneId); + const modelLinesEdgeAttribute = useModelLinesEdgeAttribute(sceneId); function modelLineColoring(modelId: ModelId, line_id?: LineId): StyleValues { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring shape is defined by the data style schema. diff --git a/internal/stores/data_style/model/lines/common.ts b/internal/stores/data_style/model/lines/common.ts index b2a7b8616..22c252b87 100644 --- a/internal/stores/data_style/model/lines/common.ts +++ b/internal/stores/data_style/model/lines/common.ts @@ -1,10 +1,11 @@ import type { LineId, ModelId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import merge from "lodash/merge"; import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; import { useModelCommonStyle } from "@ogw_internal/stores/data_style/model/common"; -export function useModelLinesCommonStyle(): { +export function useModelLinesCommonStyle(sceneId: SceneId): { modelLinesStyle: (modelId: ModelId) => StyleValues; modelLineStyle: (modelId: ModelId, line_id?: LineId) => StyleValues; modelLineColoring: (modelId: ModelId, line_id?: LineId) => StyleValues; @@ -15,8 +16,8 @@ export function useModelLinesCommonStyle(): { ) => Promise; mutateModelLinesTypeColoring: (modelId: ModelId, values: StyleValues) => Promise; } { - const dataStyleState = useDataStyleState(); - const modelCommonStyle = useModelCommonStyle(); + const dataStyleState = useDataStyleState(sceneId); + const modelCommonStyle = useModelCommonStyle(sceneId); function modelLinesStyle(modelId: ModelId): StyleValues { return dataStyleState.getStyle(modelId).lines ?? {}; diff --git a/internal/stores/data_style/model/lines/edge.ts b/internal/stores/data_style/model/lines/edge.ts index fb478fe85..4094cd2db 100644 --- a/internal/stores/data_style/model/lines/edge.ts +++ b/internal/stores/data_style/model/lines/edge.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // oxlint-disable eslint/max-lines import type { AttributeColorMap, @@ -113,9 +114,10 @@ type ModelLinesEdgeAttributeGetters = Pick< // oxlint-disable-next-line max-lines-per-function function useModelLinesEdgeAttributeGetters( + sceneId: SceneId, modelLinesCommonStyle: ReturnType, ): ModelLinesEdgeAttributeGetters { - const { attributeTimeStep } = useAttributeTimeStepStyle(); + const { attributeTimeStep } = useAttributeTimeStepStyle(sceneId); function modelLinesEdgeAttribute(modelId: ModelId, lineId?: LineId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.edge shape is defined by the data style schema. return modelLinesCommonStyle.modelLineColoring(modelId, lineId).edge as AttributeState; @@ -203,10 +205,10 @@ function useModelLinesEdgeAttributeGetters( } // oxlint-disable-next-line max-lines-per-function -function useModelLinesEdgeAttribute(): UseModelLinesEdgeAttributeReturn { - const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useModelLinesEdgeAttribute(sceneId: SceneId): UseModelLinesEdgeAttributeReturn { + const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(sceneId); const dataStore = useDataStore(); - const modelLinesCommonStyle = useModelLinesCommonStyle(); + const modelLinesCommonStyle = useModelLinesCommonStyle(sceneId); const { modelLinesEdgeAttributeStoredConfig, modelLinesEdgeAttributeName, @@ -216,7 +218,7 @@ function useModelLinesEdgeAttribute(): UseModelLinesEdgeAttributeReturn { modelLinesEdgeAttributeColorMap, modelLinesEdgeAttributeNoDataColor, modelLinesEdgeAttributeTimeStep, - } = useModelLinesEdgeAttributeGetters(modelLinesCommonStyle); + } = useModelLinesEdgeAttributeGetters(sceneId, modelLinesCommonStyle); const viewerStore = useViewerStore(); async function mutateModelLinesEdgeStyle( modelId: ModelId, @@ -282,6 +284,7 @@ function useModelLinesEdgeAttribute(): UseModelLinesEdgeAttributeReturn { const points = [...getRGBPointsFromPreset(colorMap)]; const line_viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, lineIds); const params = { + scene_id: sceneId, id: modelId, block_ids: line_viewer_ids, name: seriesArrayName(modelId, attributeSchema.$id, name), diff --git a/internal/stores/data_style/model/lines/index.ts b/internal/stores/data_style/model/lines/index.ts index 59ca72f87..f8671e9db 100644 --- a/internal/stores/data_style/model/lines/index.ts +++ b/internal/stores/data_style/model/lines/index.ts @@ -4,6 +4,7 @@ import { applyModelLinesEdgeColoring, applyModelLinesVertexColoring, } from "./apply_coloring"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { useDataStore } from "@ogw_front/stores/data"; import { useModelLinesColor } from "./color"; import { useModelLinesCommonStyle } from "./common"; @@ -17,7 +18,7 @@ async function setModelLinesDefaultStyle(_id: string): Promise { } // oxlint-disable-next-line max-lines-per-function -export function useModelLinesStyle(): ReturnType & +export function useModelLinesStyle(sceneId: SceneId): ReturnType & ReturnType & ReturnType & ReturnType & @@ -27,12 +28,12 @@ export function useModelLinesStyle(): ReturnType Promise; } { const dataStore = useDataStore(); - const modelCommonStyle = useModelLinesCommonStyle(); - const modelVisibilityStyle = useModelLinesVisibility(); - const modelColorStyle = useModelLinesColor(); - const modelLinesVertexAttribute = useModelLinesVertexAttribute(); - const modelLinesEdgeAttribute = useModelLinesEdgeAttribute(); - const modelLinesPointsStyle = useModelLinesPointsStyle(); + const modelCommonStyle = useModelLinesCommonStyle(sceneId); + const modelVisibilityStyle = useModelLinesVisibility(sceneId); + const modelColorStyle = useModelLinesColor(sceneId); + const modelLinesVertexAttribute = useModelLinesVertexAttribute(sceneId); + const modelLinesEdgeAttribute = useModelLinesEdgeAttribute(sceneId); + const modelLinesPointsStyle = useModelLinesPointsStyle(sceneId); async function applyModelLinesVisibilityStyle( modelId: ModelId, diff --git a/internal/stores/data_style/model/lines/points.ts b/internal/stores/data_style/model/lines/points.ts index 6590cb9c6..935125c1e 100644 --- a/internal/stores/data_style/model/lines/points.ts +++ b/internal/stores/data_style/model/lines/points.ts @@ -2,6 +2,7 @@ import { type ModelComponentPointsStyle, useModelComponentPointsStyle, } from "@ogw_internal/stores/data_style/model/points/component"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; interface UseModelLinesPointsStyleReturn { modelLinePointsVisibility: ModelComponentPointsStyle["visibility"]; @@ -25,8 +26,8 @@ interface UseModelLinesPointsStyleReturn { applyModelLinesPointsStyle: ModelComponentPointsStyle["applyPointsStyle"]; } -export function useModelLinesPointsStyle(): UseModelLinesPointsStyleReturn { - const points = useModelComponentPointsStyle("Line"); +export function useModelLinesPointsStyle(sceneId: SceneId): UseModelLinesPointsStyleReturn { + const points = useModelComponentPointsStyle(sceneId, "Line"); return { modelLinePointsVisibility: points.visibility, modelLinePointsSize: points.size, diff --git a/internal/stores/data_style/model/lines/vertex.ts b/internal/stores/data_style/model/lines/vertex.ts index 06a1cdf76..0344f20e8 100644 --- a/internal/stores/data_style/model/lines/vertex.ts +++ b/internal/stores/data_style/model/lines/vertex.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // oxlint-disable eslint/max-lines import type { AttributeColorMap, @@ -113,9 +114,10 @@ type ModelLinesVertexAttributeGetters = Pick< // oxlint-disable-next-line max-lines-per-function function useModelLinesVertexAttributeGetters( + sceneId: SceneId, modelLinesCommonStyle: ReturnType, ): ModelLinesVertexAttributeGetters { - const { attributeTimeStep } = useAttributeTimeStepStyle(); + const { attributeTimeStep } = useAttributeTimeStepStyle(sceneId); function modelLinesVertexAttribute(modelId: ModelId, lineId?: LineId): AttributeState { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.vertex shape is defined by the data style schema. return modelLinesCommonStyle.modelLineColoring(modelId, lineId).vertex as AttributeState; @@ -204,10 +206,10 @@ function useModelLinesVertexAttributeGetters( } // oxlint-disable-next-line max-lines-per-function -function useModelLinesVertexAttribute(): UseModelLinesVertexAttributeReturn { - const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useModelLinesVertexAttribute(sceneId: SceneId): UseModelLinesVertexAttributeReturn { + const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(sceneId); const dataStore = useDataStore(); - const modelLinesCommonStyle = useModelLinesCommonStyle(); + const modelLinesCommonStyle = useModelLinesCommonStyle(sceneId); const { modelLinesVertexAttributeStoredConfig, modelLinesVertexAttributeName, @@ -217,7 +219,7 @@ function useModelLinesVertexAttribute(): UseModelLinesVertexAttributeReturn { modelLinesVertexAttributeColorMap, modelLinesVertexAttributeNoDataColor, modelLinesVertexAttributeTimeStep, - } = useModelLinesVertexAttributeGetters(modelLinesCommonStyle); + } = useModelLinesVertexAttributeGetters(sceneId, modelLinesCommonStyle); const viewerStore = useViewerStore(); async function mutateModelLinesVertexStyle( modelId: ModelId, @@ -283,6 +285,7 @@ function useModelLinesVertexAttribute(): UseModelLinesVertexAttributeReturn { const points = [...getRGBPointsFromPreset(colorMap)]; const line_viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, lineIds); const params = { + scene_id: sceneId, id: modelId, block_ids: line_viewer_ids, name: seriesArrayName(modelId, attributeSchema.$id, name), diff --git a/internal/stores/data_style/model/lines/visibility.ts b/internal/stores/data_style/model/lines/visibility.ts index b9d86abb6..f5c996f9b 100644 --- a/internal/stores/data_style/model/lines/visibility.ts +++ b/internal/stores/data_style/model/lines/visibility.ts @@ -1,4 +1,5 @@ import type { LineId, ModelId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { Visibility } from "@geode/opengeodeweb-viewer/schema_types"; import { useModelCommonStyle } from "@ogw_internal/stores/data_style/model/common"; import { useModelLinesCommonStyle } from "./common"; @@ -6,7 +7,7 @@ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed const schema = viewer_schemas.opengeodeweb_viewer.model.lines.visibility; -export function useModelLinesVisibility(): { +export function useModelLinesVisibility(sceneId: SceneId): { setModelLinesVisibility: ( modelId: ModelId, lines_ids: LineId[], @@ -14,8 +15,8 @@ export function useModelLinesVisibility(): { ) => Promise; modelLineVisibility: (modelId: ModelId, line_id?: LineId) => unknown; } { - const modelCommonStyle = useModelCommonStyle(); - const modelLinesCommonStyle = useModelLinesCommonStyle(); + const modelCommonStyle = useModelCommonStyle(sceneId); + const modelLinesCommonStyle = useModelLinesCommonStyle(sceneId); function modelLineVisibility(modelId: ModelId, line_id?: LineId): unknown { return modelLinesCommonStyle.modelLineStyle(modelId, line_id).visibility; diff --git a/internal/stores/data_style/model/points/common.ts b/internal/stores/data_style/model/points/common.ts index 4261b714b..de00022a9 100644 --- a/internal/stores/data_style/model/points/common.ts +++ b/internal/stores/data_style/model/points/common.ts @@ -1,12 +1,13 @@ import type { ModelId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; -export function useModelPointsCommonStyle(): { +export function useModelPointsCommonStyle(sceneId: SceneId): { modelPointsStyle: (modelId: ModelId) => StyleValues; mutateModelPointsStyle: (modelId: ModelId, values: StyleValues) => Promise; } { - const dataStyleState = useDataStyleState(); + const dataStyleState = useDataStyleState(sceneId); async function mutateModelPointsStyle(modelId: ModelId, values: StyleValues): Promise { const result = await dataStyleState.mutateStyle(modelId, { diff --git a/internal/stores/data_style/model/points/component.ts b/internal/stores/data_style/model/points/component.ts index af54cbc91..e6a2df2b2 100644 --- a/internal/stores/data_style/model/points/component.ts +++ b/internal/stores/data_style/model/points/component.ts @@ -13,12 +13,12 @@ import type { AttributeState, AttributeStoredConfig, } from "@ogw_internal/stores/data_style/attribute_types"; +import type { ModelId, SceneId } from "@ogw_front/types/identifiers"; import { POINTS_DEFAULT_COLOR, POINTS_DEFAULT_SIZE, POINTS_DEFAULT_VISIBILITY, } from "@ogw_front/utils/default_styles/constants"; -import type { ModelId } from "@ogw_front/types/identifiers"; import { defaultAttributeStoredConfig } from "@ogw_internal/stores/data_style/attribute_default"; import { getRGBPointsFromPreset } from "@ogw_front/utils/colormap"; import { groupBy } from "@ogw_internal/stores/data_style/model/component_style"; @@ -61,12 +61,12 @@ interface PointsStyle { // Return type is inferred, see ModelComponentPointsStyle: signatures live on the functions only // oxlint-disable-next-line max-lines-per-function, max-statements, typescript/explicit-function-return-type, typescript/explicit-module-boundary-types -function useModelComponentPointsStyle(type: PointsComponentType) { +function useModelComponentPointsStyle(sceneId: SceneId, type: PointsComponentType) { const dataStore = useDataStore(); - const dataStyleState = useDataStyleState(); - const modelCommonStyle = useModelCommonStyle(); + const dataStyleState = useDataStyleState(sceneId); + const modelCommonStyle = useModelCommonStyle(sceneId); const viewerStore = useViewerStore(); - const { seriesArrayName } = useAttributeTimeStepStyle(); + const { seriesArrayName } = useAttributeTimeStepStyle(sceneId); const schemas = modelSchemas[COMPONENT_TYPE_KEYS[type]].points; // Without an explicit points style, components follow the model points style @@ -189,7 +189,7 @@ function useModelComponentPointsStyle(type: PointsComponentType) { const { style, ...params } = values; const result = await viewerStore.request( // oxlint-disable-next-line no-unsafe-type-assertion, no-unnecessary-type-assertion -- params match the points schema of every component type. - { schema, params: { id: modelId, block_ids, ...params } } as Parameters< + { schema, params: { scene_id: sceneId, id: modelId, block_ids, ...params } } as Parameters< typeof viewerStore.request >[0], { diff --git a/internal/stores/data_style/model/points/index.ts b/internal/stores/data_style/model/points/index.ts index ce9317e27..b87fb2d92 100644 --- a/internal/stores/data_style/model/points/index.ts +++ b/internal/stores/data_style/model/points/index.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Local imports import type { PointSize, Visibility } from "@geode/opengeodeweb-viewer/schema_types"; import type { ModelId } from "@ogw_front/types/identifiers"; @@ -6,14 +7,14 @@ import { useModelPointsSizeStyle } from "./size"; import { useModelPointsVisibilityStyle } from "./visibility"; import { whenDefined } from "@ogw_internal/stores/data_style/when_defined"; -export function useModelPointsStyle(): { +export function useModelPointsStyle(sceneId: SceneId): { applyModelPointsStyle: (modelId: ModelId) => Promise; } & ReturnType & ReturnType & ReturnType { - const modelPointsCommonStyle = useModelPointsCommonStyle(); - const modelPointsVisibilityStyle = useModelPointsVisibilityStyle(); - const modelPointsSizeStyle = useModelPointsSizeStyle(); + const modelPointsCommonStyle = useModelPointsCommonStyle(sceneId); + const modelPointsVisibilityStyle = useModelPointsVisibilityStyle(sceneId); + const modelPointsSizeStyle = useModelPointsSizeStyle(sceneId); async function applyModelPointsStyle(modelId: ModelId): Promise { const style = modelPointsCommonStyle.modelPointsStyle(modelId); diff --git a/internal/stores/data_style/model/points/size.ts b/internal/stores/data_style/model/points/size.ts index 34ff48247..ea477f5bf 100644 --- a/internal/stores/data_style/model/points/size.ts +++ b/internal/stores/data_style/model/points/size.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -14,14 +15,14 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.model.points.size; -export function useModelPointsSizeStyle(): { +export function useModelPointsSizeStyle(sceneId: SceneId): { modelPointsSize: (modelId: ModelId) => PointSize | undefined; setModelPointsSize: (modelId: ModelId, size: PointSize) => Promise; } { const viewerStore = useViewerStore(); - const modelPointsCommonStyle = useModelPointsCommonStyle(); + const modelPointsCommonStyle = useModelPointsCommonStyle(sceneId); const componentsPointsStyles = POINTS_COMPONENT_TYPES.map((type) => - useModelComponentPointsStyle(type), + useModelComponentPointsStyle(sceneId, type), ); function modelPointsSize(modelId: ModelId): PointSize | undefined { @@ -30,7 +31,7 @@ export function useModelPointsSizeStyle(): { } async function setModelPointsSize(modelId: ModelId, size: PointSize): Promise { - const params = { id: modelId, size }; + const params = { scene_id: sceneId, id: modelId, size }; const result = await viewerStore.request( { schema, diff --git a/internal/stores/data_style/model/points/visibility.ts b/internal/stores/data_style/model/points/visibility.ts index a5e300880..b507a17ff 100644 --- a/internal/stores/data_style/model/points/visibility.ts +++ b/internal/stores/data_style/model/points/visibility.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -14,14 +15,14 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants const schema = viewer_schemas.opengeodeweb_viewer.model.points.visibility; -export function useModelPointsVisibilityStyle(): { +export function useModelPointsVisibilityStyle(sceneId: SceneId): { modelPointsVisibility: (modelId: ModelId) => Visibility | undefined; setModelPointsVisibility: (modelId: ModelId, visibility: Visibility) => Promise; } { const viewerStore = useViewerStore(); - const modelPointsCommonStyle = useModelPointsCommonStyle(); + const modelPointsCommonStyle = useModelPointsCommonStyle(sceneId); const componentsPointsStyles = POINTS_COMPONENT_TYPES.map((type) => - useModelComponentPointsStyle(type), + useModelComponentPointsStyle(sceneId, type), ); function modelPointsVisibility(modelId: ModelId): Visibility | undefined { @@ -33,7 +34,7 @@ export function useModelPointsVisibilityStyle(): { modelId: ModelId, visibility: Visibility, ): Promise { - const params = { id: modelId, visibility }; + const params = { scene_id: sceneId, id: modelId, visibility }; const result = await viewerStore.request( { schema, params }, { diff --git a/internal/stores/data_style/model/surfaces/color.ts b/internal/stores/data_style/model/surfaces/color.ts index 08297e214..e1bb033c6 100644 --- a/internal/stores/data_style/model/surfaces/color.ts +++ b/internal/stores/data_style/model/surfaces/color.ts @@ -1,5 +1,6 @@ import type { ModelId, SurfaceId } from "@ogw_front/types/identifiers"; import type { ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import { isAttributeValid } from "@ogw_internal/stores/data_style/attribute_valid"; import { useDataStore } from "@ogw_front/stores/data"; @@ -11,7 +12,7 @@ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed const schema = viewer_schemas.opengeodeweb_viewer.model.surfaces.color; -export function useModelSurfacesColor(): { +export function useModelSurfacesColor(sceneId: SceneId): { setModelSurfacesColor: ( modelId: ModelId, surfaces_ids: SurfaceId[], @@ -30,10 +31,10 @@ export function useModelSurfacesColor(): { ) => Promise; } { const dataStore = useDataStore(); - const modelCommonStyle = useModelCommonStyle(); - const modelSurfacesCommonStyle = useModelSurfacesCommonStyle(); - const modelSurfacesVertexAttribute = useModelSurfacesVertexAttribute(); - const modelSurfacesPolygonAttribute = useModelSurfacesPolygonAttribute(); + const modelCommonStyle = useModelCommonStyle(sceneId); + const modelSurfacesCommonStyle = useModelSurfacesCommonStyle(sceneId); + const modelSurfacesVertexAttribute = useModelSurfacesVertexAttribute(sceneId); + const modelSurfacesPolygonAttribute = useModelSurfacesPolygonAttribute(sceneId); function modelSurfaceColoring(modelId: ModelId, surface_id?: SurfaceId): StyleValues { // oxlint-disable-next-line no-unsafe-type-assertion -- coloring shape is defined by the data style schema. diff --git a/internal/stores/data_style/model/surfaces/common.ts b/internal/stores/data_style/model/surfaces/common.ts index 53452565b..532c06d00 100644 --- a/internal/stores/data_style/model/surfaces/common.ts +++ b/internal/stores/data_style/model/surfaces/common.ts @@ -1,4 +1,5 @@ import type { ModelId, SurfaceId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { StyleValues } from "@ogw_internal/stores/data_style/types.js"; import merge from "lodash/merge"; import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; @@ -16,9 +17,9 @@ interface UseModelSurfacesCommonStyleReturn { mutateModelSurfacesTypeColoring: (modelId: ModelId, values: StyleValues) => Promise; } -export function useModelSurfacesCommonStyle(): UseModelSurfacesCommonStyleReturn { - const dataStyleState = useDataStyleState(); - const modelCommonStyle = useModelCommonStyle(); +export function useModelSurfacesCommonStyle(sceneId: SceneId): UseModelSurfacesCommonStyleReturn { + const dataStyleState = useDataStyleState(sceneId); + const modelCommonStyle = useModelCommonStyle(sceneId); function modelSurfacesStyle(modelId: ModelId): StyleValues { return dataStyleState.getStyle(modelId).surfaces ?? {}; diff --git a/internal/stores/data_style/model/surfaces/edges.ts b/internal/stores/data_style/model/surfaces/edges.ts index 9117f57c1..94371aeda 100644 --- a/internal/stores/data_style/model/surfaces/edges.ts +++ b/internal/stores/data_style/model/surfaces/edges.ts @@ -2,6 +2,7 @@ import { type ModelComponentEdgesStyle, useModelComponentEdgesStyle, } from "@ogw_internal/stores/data_style/model/edges/component"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; interface UseModelSurfacesEdgesStyleReturn { modelSurfaceEdgesVisibility: ModelComponentEdgesStyle["visibility"]; @@ -25,8 +26,8 @@ interface UseModelSurfacesEdgesStyleReturn { applyModelSurfacesEdgesStyle: ModelComponentEdgesStyle["applyEdgesStyle"]; } -export function useModelSurfacesEdgesStyle(): UseModelSurfacesEdgesStyleReturn { - const edges = useModelComponentEdgesStyle("Surface"); +export function useModelSurfacesEdgesStyle(sceneId: SceneId): UseModelSurfacesEdgesStyleReturn { + const edges = useModelComponentEdgesStyle(sceneId, "Surface"); return { modelSurfaceEdgesVisibility: edges.visibility, modelSurfaceEdgesWidth: edges.width, diff --git a/internal/stores/data_style/model/surfaces/index.ts b/internal/stores/data_style/model/surfaces/index.ts index 234b13878..d6d301fa3 100644 --- a/internal/stores/data_style/model/surfaces/index.ts +++ b/internal/stores/data_style/model/surfaces/index.ts @@ -4,6 +4,7 @@ import { applyModelSurfacesPolygonColoring, applyModelSurfacesVertexColoring, } from "./apply_coloring"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { useDataStore } from "@ogw_front/stores/data"; import { useModelSurfacesColor } from "./color"; import { useModelSurfacesCommonStyle } from "./common"; @@ -29,15 +30,15 @@ type UseModelSurfacesStyleReturn = ReturnType, ): ModelSurfacesPolygonAttributeGetters { - const { attributeTimeStep } = useAttributeTimeStepStyle(); + const { attributeTimeStep } = useAttributeTimeStepStyle(sceneId); function modelSurfacesPolygonAttribute(modelId: ModelId, surfaceId?: SurfaceId): AttributeState { return ( // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.polygon shape is defined by the data style schema. @@ -219,10 +221,12 @@ function useModelSurfacesPolygonAttributeGetters( } // oxlint-disable-next-line max-lines-per-function -function useModelSurfacesPolygonAttribute(): UseModelSurfacesPolygonAttributeReturn { - const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useModelSurfacesPolygonAttribute( + sceneId: SceneId, +): UseModelSurfacesPolygonAttributeReturn { + const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(sceneId); const dataStore = useDataStore(); - const modelSurfacesCommonStyle = useModelSurfacesCommonStyle(); + const modelSurfacesCommonStyle = useModelSurfacesCommonStyle(sceneId); const { modelSurfacesPolygonAttributeStoredConfig, modelSurfacesPolygonAttributeName, @@ -232,7 +236,7 @@ function useModelSurfacesPolygonAttribute(): UseModelSurfacesPolygonAttributeRet modelSurfacesPolygonAttributeColorMap, modelSurfacesPolygonAttributeNoDataColor, modelSurfacesPolygonAttributeTimeStep, - } = useModelSurfacesPolygonAttributeGetters(modelSurfacesCommonStyle); + } = useModelSurfacesPolygonAttributeGetters(sceneId, modelSurfacesCommonStyle); const viewerStore = useViewerStore(); async function mutateModelSurfacesPolygonStyle( modelId: ModelId, @@ -287,6 +291,7 @@ function useModelSurfacesPolygonAttribute(): UseModelSurfacesPolygonAttributeRet const points = [...getRGBPointsFromPreset(colorMap)]; const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, surfaceIds); const params = { + scene_id: sceneId, id: modelId, block_ids: surface_viewer_ids, name: seriesArrayName(modelId, attributeSchema.$id, name), diff --git a/internal/stores/data_style/model/surfaces/vertex.ts b/internal/stores/data_style/model/surfaces/vertex.ts index 539782465..627d17e14 100644 --- a/internal/stores/data_style/model/surfaces/vertex.ts +++ b/internal/stores/data_style/model/surfaces/vertex.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // oxlint-disable eslint/max-lines import type { AttributeColorMap, @@ -117,9 +118,10 @@ type ModelSurfacesVertexAttributeGetters = Pick< // oxlint-disable-next-line max-lines-per-function function useModelSurfacesVertexAttributeGetters( + sceneId: SceneId, modelSurfacesCommonStyle: ReturnType, ): ModelSurfacesVertexAttributeGetters { - const { attributeTimeStep } = useAttributeTimeStepStyle(); + const { attributeTimeStep } = useAttributeTimeStepStyle(sceneId); function modelSurfacesVertexAttribute(modelId: ModelId, surfaceId?: SurfaceId): AttributeState { return ( // oxlint-disable-next-line no-unsafe-type-assertion -- coloring.vertex shape is defined by the data style schema. @@ -219,10 +221,10 @@ function useModelSurfacesVertexAttributeGetters( } // oxlint-disable-next-line max-lines-per-function -function useModelSurfacesVertexAttribute(): UseModelSurfacesVertexAttributeReturn { - const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(); +function useModelSurfacesVertexAttribute(sceneId: SceneId): UseModelSurfacesVertexAttributeReturn { + const { setAttributeTimeStep, seriesArrayName } = useAttributeTimeStepStyle(sceneId); const dataStore = useDataStore(); - const modelSurfacesCommonStyle = useModelSurfacesCommonStyle(); + const modelSurfacesCommonStyle = useModelSurfacesCommonStyle(sceneId); const { modelSurfacesVertexAttributeStoredConfig, modelSurfacesVertexAttributeName, @@ -232,7 +234,7 @@ function useModelSurfacesVertexAttribute(): UseModelSurfacesVertexAttributeRetur modelSurfacesVertexAttributeColorMap, modelSurfacesVertexAttributeNoDataColor, modelSurfacesVertexAttributeTimeStep, - } = useModelSurfacesVertexAttributeGetters(modelSurfacesCommonStyle); + } = useModelSurfacesVertexAttributeGetters(sceneId, modelSurfacesCommonStyle); const viewerStore = useViewerStore(); async function mutateModelSurfacesVertexStyle( modelId: ModelId, @@ -287,6 +289,7 @@ function useModelSurfacesVertexAttribute(): UseModelSurfacesVertexAttributeRetur const points = [...getRGBPointsFromPreset(colorMap)]; const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds(modelId, surfaceIds); const params = { + scene_id: sceneId, id: modelId, block_ids: surface_viewer_ids, name: seriesArrayName(modelId, attributeSchema.$id, name), diff --git a/internal/stores/data_style/model/surfaces/visibility.ts b/internal/stores/data_style/model/surfaces/visibility.ts index 8b27f72bd..02246f47f 100644 --- a/internal/stores/data_style/model/surfaces/visibility.ts +++ b/internal/stores/data_style/model/surfaces/visibility.ts @@ -1,4 +1,5 @@ import type { ModelId, SurfaceId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { Visibility } from "@geode/opengeodeweb-viewer/schema_types"; import { useModelCommonStyle } from "@ogw_internal/stores/data_style/model/common"; import { useModelSurfacesCommonStyle } from "./common"; @@ -6,7 +7,7 @@ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed const schema = viewer_schemas.opengeodeweb_viewer.model.surfaces.visibility; -export function useModelSurfacesVisibility(): { +export function useModelSurfacesVisibility(sceneId: SceneId): { setModelSurfacesVisibility: ( modelId: ModelId, surfaces_ids: readonly SurfaceId[], @@ -14,8 +15,8 @@ export function useModelSurfacesVisibility(): { ) => Promise; modelSurfaceVisibility: (modelId: ModelId, surface_id?: SurfaceId) => unknown; } { - const modelCommonStyle = useModelCommonStyle(); - const modelSurfacesCommonStyle = useModelSurfacesCommonStyle(); + const modelCommonStyle = useModelCommonStyle(sceneId); + const modelSurfacesCommonStyle = useModelSurfacesCommonStyle(sceneId); function modelSurfaceVisibility(modelId: ModelId, surface_id?: SurfaceId): unknown { return modelSurfacesCommonStyle.modelSurfaceStyle(modelId, surface_id).visibility; diff --git a/internal/stores/data_style/model/visibility.ts b/internal/stores/data_style/model/visibility.ts index 4eb33c036..196866c96 100644 --- a/internal/stores/data_style/model/visibility.ts +++ b/internal/stores/data_style/model/visibility.ts @@ -1,6 +1,7 @@ import { type ComponentStyleFunctions, dispatchToComponentTypes } from "./visibility_dispatch"; import { MESH_COMPONENT_TYPES } from "@ogw_front/utils/default_styles"; import type { ModelId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { Visibility } from "@geode/opengeodeweb-viewer/schema_types"; import { useDataStore } from "@ogw_front/stores/data"; import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; @@ -30,22 +31,20 @@ interface UseModelVisibilityStyleReturn { // oxlint-disable-next-line max-lines-per-function function useModelVisibilityStyle( + sceneId: SceneId, componentStyleFunctions: ComponentStyleFunctions, ): UseModelVisibilityStyleReturn { const dataStore = useDataStore(); - const dataStyleState = useDataStyleState(); + const dataStyleState = useDataStyleState(sceneId); const hybridViewerStore = useHybridViewerStore(); const viewerStore = useViewerStore(); - const modelCommonStyle = useModelCommonStyle(); + const modelCommonStyle = useModelCommonStyle(sceneId); function modelVisibility(modelId: ModelId): Visibility | undefined { return dataStyleState.getStyle(modelId).visibility; } async function setModelVisibility(modelId: ModelId, visibility: Visibility): Promise { const schema = model_schemas.visibility; - const params = { - id: modelId, - visibility, - }; + const params = { scene_id: sceneId, id: modelId, visibility }; const result = await viewerStore.request( { schema, @@ -116,11 +115,11 @@ function useModelVisibilityStyle( return results; } function modelComponentVisibility(modelId: ModelId, componentId: string): Visibility { - const selection = useModelSelection(modelId, dataStyleState); + const selection = useModelSelection(sceneId, modelId, dataStyleState); return selection.value.includes(componentId); } function modelComponentTypeVisibility(modelId: ModelId, componentType: string): Visibility { - const selection = useModelSelection(modelId, dataStyleState); + const selection = useModelSelection(sceneId, modelId, dataStyleState); return selection.value.includes(componentType); } return { From e9761fe51903479ccf2ff91e9339c3072549b76f Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:05:04 +0100 Subject: [PATCH 013/121] feat(data_style): scope image and scene styles by scene Co-Authored-By: Claude Opus 5.5 --- internal/stores/data_style/image/index.ts | 11 ++++++----- internal/stores/data_style/scene.ts | 10 ++++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/internal/stores/data_style/image/index.ts b/internal/stores/data_style/image/index.ts index cd7f1a032..5e291b6bf 100644 --- a/internal/stores/data_style/image/index.ts +++ b/internal/stores/data_style/image/index.ts @@ -1,5 +1,6 @@ import type { Opacity, Visibility } from "@geode/opengeodeweb-viewer/schema_types"; import type { ImageId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -22,16 +23,16 @@ interface ImageStyleStore { // An image shows its own colors: only its visibility and its opacity are styled // oxlint-disable-next-line max-lines-per-function -export function useImageStyle(): ImageStyleStore { +export function useImageStyle(sceneId: SceneId): ImageStyleStore { const hybridViewerStore = useHybridViewerStore(); const viewerStore = useViewerStore(); - const dataStyleState = useDataStyleState(); + const dataStyleState = useDataStyleState(sceneId); function imageVisibility(imageId: ImageId): Visibility | undefined { return dataStyleState.getStyle(imageId).visibility; } async function setImageVisibility(imageId: ImageId, visibility: Visibility): Promise { - const params = { id: imageId, visibility }; + const params = { scene_id: sceneId, id: imageId, visibility }; const result = await viewerStore.request( { schema: imageSchemas.visibility, @@ -53,7 +54,7 @@ export function useImageStyle(): ImageStyleStore { return dataStyleState.getStyle(imageId).opacity as Opacity | undefined; } async function setImageOpacity(imageId: ImageId, opacity: Opacity): Promise { - const params = { id: imageId, opacity }; + const params = { scene_id: sceneId, id: imageId, opacity }; const result = await viewerStore.request( { schema: imageSchemas.opacity, @@ -87,7 +88,7 @@ export function useImageStyle(): ImageStyleStore { return applied; }), ); - } else if (key === "data_id") { + } else if (key === "data_id" || key === "scene_id") { continue; } else { throw new Error(`Unknown image key: ${key}`); diff --git a/internal/stores/data_style/scene.ts b/internal/stores/data_style/scene.ts index 188050dfb..5d0a940e1 100644 --- a/internal/stores/data_style/scene.ts +++ b/internal/stores/data_style/scene.ts @@ -1,5 +1,6 @@ import type { SceneFontFamily, SceneOrientationWidget, SceneStyle } from "./types"; import type { ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; // Third party imports import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -21,7 +22,7 @@ const text_style_schema = viewer_schemas.opengeodeweb_viewer.viewer.set_text_sty const orientation_widget_schema = viewer_schemas.opengeodeweb_viewer.viewer.set_orientation_widget; // oxlint-disable-next-line max-lines-per-function -export function useSceneStyle(): { +export function useSceneStyle(sceneId: SceneId): { setSceneBackgroundColor: (color: ColorRGBA) => Promise; setSceneTextColor: (color: ColorRGBA) => Promise; setSceneFontFamily: (font_family: SceneFontFamily) => Promise; @@ -31,7 +32,7 @@ export function useSceneStyle(): { } { const viewerStore = useViewerStore(); const hybridViewerStore = useHybridViewerStore(); - const { sceneStyle } = useDataStyleState(); + const { sceneStyle } = useDataStyleState(sceneId); const sceneStyleTable = sceneStyleDb(); async function saveSceneStyle(values: Partial>): Promise { @@ -39,13 +40,14 @@ export function useSceneStyle(): { // oxlint-disable-next-line unicorn/prefer-structured-clone, no-unsafe-type-assertion -- JSON round-trip of a known-shape style. const plainStyle = JSON.parse(JSON.stringify({ ...sceneStyle.value, ...values })) as SceneStyle; sceneStyle.value = plainStyle; - await sceneStyleTable.put(plainStyle); + await sceneStyleTable.put({ ...plainStyle, scene_id: sceneId }); } async function requestTextStyle(text: SceneStyle["text"]): Promise { // Update right away so a quick second change builds on this one instead of the saved state sceneStyle.value = { ...sceneStyle.value, text }; const params = { + scene_id: sceneId, color: toViewerColor(text.color), font_family: text.font_family, opacity: text.color.alpha, @@ -66,7 +68,7 @@ export function useSceneStyle(): { const viewerMarker = viewerOrientationMarker(marker); try { const result = await viewerStore.request( - { schema: orientation_widget_schema, params: { marker: viewerMarker } }, + { schema: orientation_widget_schema, params: { scene_id: sceneId, marker: viewerMarker } }, { response_function: async () => { await saveSceneStyle({ orientation_widget: marker }); From 7c1cae93b2dd8b70c4307e1e8ae2939245cc92b4 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:05:04 +0100 Subject: [PATCH 014/121] feat(data_style): one data style store per scene useDataStyleStore(sceneId) returns the store dataStyle-. Its public API is unchanged. Co-Authored-By: Claude Opus 5.5 --- app/stores/data_style.ts | 102 +++++++++--------- internal/stores/data_style/viewer_type.ts | 41 +++++++ tests/unit/stores/data_style.nuxt.test.ts | 43 ++++++++ .../unit/stores/data_style_image.nuxt.test.ts | 20 ++-- tests/unit/stores/image_style.nuxt.test.ts | 34 +++--- tests/unit/stores/mesh_style.nuxt.test.ts | 4 +- 6 files changed, 170 insertions(+), 74 deletions(-) create mode 100644 internal/stores/data_style/viewer_type.ts create mode 100644 tests/unit/stores/data_style.nuxt.test.ts diff --git a/app/stores/data_style.ts b/app/stores/data_style.ts index 7917c04de..7645e65cb 100644 --- a/app/stores/data_style.ts +++ b/app/stores/data_style.ts @@ -3,6 +3,7 @@ import type { ModelComponentStyle, ModelComponentTypeStyle, ObjectStyle, + SceneId, SceneStyle, } from "@ogw_internal/stores/data_style/types"; import { @@ -12,13 +13,12 @@ import { sceneStyleDb, writeTransaction, } from "@ogw_internal/database/database.js"; -import { isImage, isMesh, isModel } from "@ogw_front/utils/viewer_object_type"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; import type { Visibility } from "@geode/opengeodeweb-viewer/schema_types"; +import { forViewerType } from "@ogw_internal/stores/data_style/viewer_type"; import { getDefaultStyle } from "@ogw_front/utils/default_styles"; import { useAttributeTimeStepStyle } from "@ogw_internal/stores/data_style/time_step"; -import { useDataStore } from "@ogw_front/stores/data"; import { useDataStyleState } from "@ogw_internal/stores/data_style/state"; import { useImageStyle } from "@ogw_internal/stores/data_style/image/index"; import { useMeshStyle } from "@ogw_internal/stores/data_style/mesh/index"; @@ -38,15 +38,31 @@ function isRecord(value: unknown): value is Record { return typeof value === "object" && value !== null; } +interface DataStyleStoreActions { + addDataStyle: (dataId: DataId, geodeObjectType: GeodeObjectType) => Promise; + applyDefaultStyle: (dataId: DataId) => Promise; + setVisibility: (dataId: DataId, visibility: Visibility) => Promise; + exportStores: () => DataStyleSnapshot; + importStores: (snapshot: DataStyleSnapshot) => Promise; + applyAllStylesFromState: () => Promise; +} + +type DataStyleStoreSetup = DataStyleStoreActions & + ReturnType & + ReturnType & + ReturnType & + ReturnType & + ReturnType & + ReturnType; + // oxlint-disable-next-line max-lines-per-function -export const useDataStyleStore = defineStore("dataStyle", () => { - const dataStyleState = useDataStyleState(); - const imageStyleStore = useImageStyle(); - const meshStyleStore = useMeshStyle(); - const modelStyleStore = useModelStyle(); - const sceneStyleStore = useSceneStyle(); - const attributeTimeStepStyle = useAttributeTimeStepStyle(); - const dataStore = useDataStore(); +function setupDataStyleStore(sceneId: SceneId): DataStyleStoreSetup { + const dataStyleState = useDataStyleState(sceneId); + const imageStyleStore = useImageStyle(sceneId); + const meshStyleStore = useMeshStyle(sceneId); + const modelStyleStore = useModelStyle(sceneId); + const sceneStyleStore = useSceneStyle(sceneId); + const attributeTimeStepStyle = useAttributeTimeStepStyle(sceneId); const dataStyleTable = dataStyleDb(); // Keyed by [id_model, type] and [id_model, id_component] const componentTypeDataStyleTable = componentTypeDataStyleDb(); @@ -55,45 +71,14 @@ export const useDataStyleStore = defineStore("dataStyle", () => { async function addDataStyle(dataId: DataId, geodeObjectType: GeodeObjectType): Promise { const defaultStyle = getDefaultStyle(geodeObjectType); await dataStyleTable.put( - structuredClone({ data_id: dataId, ...(isRecord(defaultStyle) ? defaultStyle : {}) }), + structuredClone({ + ...(isRecord(defaultStyle) ? defaultStyle : {}), + data_id: dataId, + scene_id: sceneId, + }), ); } - // Runs the image, the mesh or the model implementation for a data, or `notViewable` for a data the viewer - // Does not show. An unknown viewer_object_type throws, unless `unknownType` handles it - async function forViewerType( - dataId: DataId, - handlers: { - image: (id: DataId) => Promise; - mesh: (id: DataId) => Promise; - model: (id: DataId) => Promise; - notViewable: (id: DataId) => Promise | Result; - unknownType?: (id: DataId) => Result; - }, - ): Promise { - const item = await dataStore.item(dataId); - if (!(await dataStore.fetchIsViewable(dataId))) { - const result = await handlers.notViewable(dataId); - return result; - } - if (isImage(item)) { - const result = await handlers.image(dataId); - return result; - } - if (isMesh(item)) { - const result = await handlers.mesh(dataId); - return result; - } - if (isModel(item)) { - const result = await handlers.model(dataId); - return result; - } - if (handlers.unknownType) { - return handlers.unknownType(dataId); - } - throw new Error(`Unknown viewer_object_type: ${item.viewer_object_type}`); - } - // A data the viewer does not show only keeps its visibility in its style async function setVisibility(dataId: DataId, visibility: Visibility): Promise { const result = await forViewerType(dataId, { @@ -147,11 +132,18 @@ export const useDataStyleStore = defineStore("dataStyle", () => { const styles = Object.entries(stylesSnapshot).map( // oxlint-disable-next-line prefer-readonly-parameter-types -- same external ObjectStyle limitation as above. ([dataId, style]: readonly [string, LegacyDataId | ObjectStyle]) => - structuredClone({ ...fromLegacyDataId(style), data_id: dataId }), + structuredClone({ + ...fromLegacyDataId(style), + data_id: dataId, + scene_id: sceneId, + }), ); - const componentStyles = structuredClone(Object.values(componentStylesSnapshot)); - const modelComponentTypeStyles = structuredClone( - Object.values(modelComponentTypeStylesSnapshot), + // The rows are written under this scene, whichever scene the snapshot comes from + const componentStyles = Object.values(componentStylesSnapshot).map((style) => + structuredClone({ ...style, scene_id: sceneId }), + ); + const modelComponentTypeStyles = Object.values(modelComponentTypeStylesSnapshot).map((style) => + structuredClone({ ...style, scene_id: sceneId }), ); // The snapshot replaces the stored styles as a whole: a failed import leaves the previous ones @@ -198,6 +190,14 @@ export const useDataStyleStore = defineStore("dataStyle", () => { ...modelStyleStore, ...sceneStyleStore, }; -}); +} + +// Each scene has its own store: the same data can be styled differently in two scenes +function useDataStyleStore( + sceneId: SceneId, +): ReturnType>> { + return defineStore(`dataStyle-${sceneId}`, () => setupDataStyleStore(sceneId))(); +} +export { useDataStyleStore }; export type { DataStyleSnapshot }; diff --git a/internal/stores/data_style/viewer_type.ts b/internal/stores/data_style/viewer_type.ts new file mode 100644 index 000000000..5914fc93a --- /dev/null +++ b/internal/stores/data_style/viewer_type.ts @@ -0,0 +1,41 @@ +import { isImage, isMesh, isModel } from "@ogw_front/utils/viewer_object_type"; +import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; +import { useDataStore } from "@ogw_front/stores/data"; + +// Runs the image, the mesh or the model implementation for a data, or `notViewable` for a data the viewer +// Does not show. An unknown viewer_object_type throws, unless `unknownType` handles it +async function forViewerType( + dataId: DataId, + handlers: { + image: (id: DataId) => Promise; + mesh: (id: DataId) => Promise; + model: (id: DataId) => Promise; + notViewable: (id: DataId) => Promise | Result; + unknownType?: (id: DataId) => Result; + }, +): Promise { + const dataStore = useDataStore(); + const item = await dataStore.item(dataId); + if (!(await dataStore.fetchIsViewable(dataId))) { + const result = await handlers.notViewable(dataId); + return result; + } + if (isImage(item)) { + const result = await handlers.image(dataId); + return result; + } + if (isMesh(item)) { + const result = await handlers.mesh(dataId); + return result; + } + if (isModel(item)) { + const result = await handlers.model(dataId); + return result; + } + if (handlers.unknownType) { + return handlers.unknownType(dataId); + } + throw new Error(`Unknown viewer_object_type: ${item.viewer_object_type}`); +} + +export { forViewerType }; diff --git a/tests/unit/stores/data_style.nuxt.test.ts b/tests/unit/stores/data_style.nuxt.test.ts new file mode 100644 index 000000000..70c7b9ede --- /dev/null +++ b/tests/unit/stores/data_style.nuxt.test.ts @@ -0,0 +1,43 @@ +// Third party imports +import { beforeEach, describe, expect, test, vi } from "vitest"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; + +// Local imports +import { mockViewer, sentRequests } from "@ogw_tests/unit/stores/image_style_helpers"; +import { setupActivePinia } from "@ogw_tests/utils"; +import { useDataStyleStore } from "@ogw_front/stores/data_style"; + +vi.setConfig({ testTimeout: 10_000 }); + +const points_schemas = viewer_schemas.opengeodeweb_viewer.mesh.points; +const RED = { red: 255, green: 0, blue: 0, alpha: 1 }; + +describe("data style store by scene", () => { + // Styles persist in the database between tests: each test styles its own mesh + let meshId = ""; + + beforeEach(() => { + setupActivePinia(); + meshId = crypto.randomUUID(); + }); + + test("styles are isolated per scene", async () => { + const request = mockViewer(); + const scene1 = useDataStyleStore("scene_1"); + const scene2 = useDataStyleStore("scene_2"); + await scene1.addDataStyle(meshId, "PointSet3D"); + await scene2.addDataStyle(meshId, "PointSet3D"); + await vi.waitFor(() => { + expect(scene2.styles[meshId]).toBeDefined(); + }); + const defaultColor = scene2.meshPointsColor(meshId); + + await scene1.setMeshPointsColor(meshId, RED); + + expect(scene1.meshPointsColor(meshId)).toStrictEqual(RED); + expect(scene2.meshPointsColor(meshId)).toStrictEqual(defaultColor); + expect(sentRequests(request)).toStrictEqual([ + { schema: points_schemas.color, params: { scene_id: "scene_1", id: meshId, color: RED } }, + ]); + }); +}); diff --git a/tests/unit/stores/data_style_image.nuxt.test.ts b/tests/unit/stores/data_style_image.nuxt.test.ts index f9f65bdf0..54ea1a0a4 100644 --- a/tests/unit/stores/data_style_image.nuxt.test.ts +++ b/tests/unit/stores/data_style_image.nuxt.test.ts @@ -33,7 +33,7 @@ describe("data style store with images", () => { const request = mockViewer(); mockHybridVisibility(); mockImageItem(imageId, type); - const dataStyleStore = useDataStyleStore(); + const dataStyleStore = useDataStyleStore("scene_1"); await dataStyleStore.addDataStyle(imageId, type); await vi.waitFor(() => { expect(dataStyleStore.styles[imageId]).toBeDefined(); @@ -53,12 +53,15 @@ describe("data style store with images", () => { const request = mockViewer(); const setVisibility = mockHybridVisibility(); mockImageItem(imageId, type); - const dataStyleStore = useDataStyleStore(); + const dataStyleStore = useDataStyleStore("scene_1"); await dataStyleStore.setVisibility(imageId, false); expect(sentRequests(request)).toStrictEqual([ - { schema: image_schemas.visibility, params: { id: imageId, visibility: false } }, + { + schema: image_schemas.visibility, + params: { scene_id: "scene_1", id: imageId, visibility: false }, + }, ]); expect(setVisibility).toHaveBeenCalledWith(imageId, false); expect(dataStyleStore.objectVisibility(imageId)).toBe(false); @@ -72,17 +75,20 @@ describe("data style store with images", () => { hybridViewerStore.setBackgroundColor = mockAs( vi.fn<() => Promise>().mockResolvedValue(), ); - await useDataStyleState().mutateStyle(imageId, { visibility: true, opacity: STORED_OPACITY }); + await useDataStyleState("scene_1").mutateStyle(imageId, { + visibility: true, + opacity: STORED_OPACITY, + }); - await useDataStyleStore().applyAllStylesFromState(); + await useDataStyleStore("scene_1").applyAllStylesFromState(); expect(sentRequests(request)).toContainEqual({ schema: image_schemas.opacity, - params: { id: imageId, opacity: STORED_OPACITY }, + params: { scene_id: "scene_1", id: imageId, opacity: STORED_OPACITY }, }); expect(sentRequests(request)).toContainEqual({ schema: image_schemas.visibility, - params: { id: imageId, visibility: true }, + params: { scene_id: "scene_1", id: imageId, visibility: true }, }); }); }); diff --git a/tests/unit/stores/image_style.nuxt.test.ts b/tests/unit/stores/image_style.nuxt.test.ts index 129d03755..e878cab03 100644 --- a/tests/unit/stores/image_style.nuxt.test.ts +++ b/tests/unit/stores/image_style.nuxt.test.ts @@ -39,17 +39,17 @@ describe("image style", () => { test("applying a style holding only its data_id applies nothing", async () => { const request = mockViewer(); - await useDataStyleState().mutateStyle(imageId, {}); + await useDataStyleState("scene_1").mutateStyle(imageId, {}); - await expect(useImageStyle().applyImageStyle(imageId)).resolves.toStrictEqual([]); + await expect(useImageStyle("scene_1").applyImageStyle(imageId)).resolves.toStrictEqual([]); expect(request).not.toHaveBeenCalled(); }); test("an unknown style key is refused", async () => { mockViewer(); - await useDataStyleState().mutateStyle(imageId, { points: {} }); + await useDataStyleState("scene_1").mutateStyle(imageId, { points: {} }); - await expect(useImageStyle().applyImageStyle(imageId)).rejects.toThrow( + await expect(useImageStyle("scene_1").applyImageStyle(imageId)).rejects.toThrow( "Unknown image key: points", ); }); @@ -57,12 +57,15 @@ describe("image style", () => { test.each([true, false])("visibility %s is sent and stored", async (visibility) => { const request = mockViewer(); const setVisibility = mockHybridVisibility(); - const imageStyle = useImageStyle(); + const imageStyle = useImageStyle("scene_1"); await imageStyle.setImageVisibility(imageId, visibility); expect(sentRequests(request)).toStrictEqual([ - { schema: image_schemas.visibility, params: { id: imageId, visibility } }, + { + schema: image_schemas.visibility, + params: { scene_id: "scene_1", id: imageId, visibility }, + }, ]); expect(setVisibility).toHaveBeenCalledWith(imageId, visibility); expect(imageStyle.imageVisibility(imageId)).toBe(visibility); @@ -70,12 +73,12 @@ describe("image style", () => { test.each([0, HALF_OPACITY, 1])("opacity %s is sent and stored", async (opacity) => { const request = mockViewer(); - const imageStyle = useImageStyle(); + const imageStyle = useImageStyle("scene_1"); await imageStyle.setImageOpacity(imageId, opacity); expect(sentRequests(request)).toStrictEqual([ - { schema: image_schemas.opacity, params: { id: imageId, opacity } }, + { schema: image_schemas.opacity, params: { scene_id: "scene_1", id: imageId, opacity } }, ]); expect(imageStyle.imageOpacity(imageId)).toBe(opacity); }); @@ -85,8 +88,8 @@ describe("image style", () => { viewerStore.request = mockAs( vi.fn<() => Promise>().mockRejectedValue(new Error("viewer down")), ); - await useDataStyleState().mutateStyle(imageId, { visibility: true, opacity: 1 }); - const imageStyle = useImageStyle(); + await useDataStyleState("scene_1").mutateStyle(imageId, { visibility: true, opacity: 1 }); + const imageStyle = useImageStyle("scene_1"); await expect(imageStyle.setImageOpacity(imageId, LOW_OPACITY)).rejects.toThrow("viewer down"); await expect(imageStyle.setImageVisibility(imageId, false)).rejects.toThrow("viewer down"); @@ -97,19 +100,22 @@ describe("image style", () => { test("applying the stored style sends its visibility and opacity", async () => { const request = mockViewer(); mockHybridVisibility(); - await useDataStyleState().mutateStyle(imageId, { visibility: false, opacity: STORED_OPACITY }); + await useDataStyleState("scene_1").mutateStyle(imageId, { + visibility: false, + opacity: STORED_OPACITY, + }); - await useImageStyle().applyImageStyle(imageId); + await useImageStyle("scene_1").applyImageStyle(imageId); const sent = sentRequests(request); expect(sent).toHaveLength(2); expect(sent).toContainEqual({ schema: image_schemas.visibility, - params: { id: imageId, visibility: false }, + params: { scene_id: "scene_1", id: imageId, visibility: false }, }); expect(sent).toContainEqual({ schema: image_schemas.opacity, - params: { id: imageId, opacity: STORED_OPACITY }, + params: { scene_id: "scene_1", id: imageId, opacity: STORED_OPACITY }, }); }); }); diff --git a/tests/unit/stores/mesh_style.nuxt.test.ts b/tests/unit/stores/mesh_style.nuxt.test.ts index 7636ec0b6..1a6d667ea 100644 --- a/tests/unit/stores/mesh_style.nuxt.test.ts +++ b/tests/unit/stores/mesh_style.nuxt.test.ts @@ -11,8 +11,8 @@ describe("mesh style", () => { }); test("applying a style holding only its data_id applies nothing", async () => { - await useDataStyleState().mutateStyle(MESH_ID, {}); + await useDataStyleState("scene_1").mutateStyle(MESH_ID, {}); - await expect(useMeshStyle().applyMeshStyle(MESH_ID)).resolves.toStrictEqual([]); + await expect(useMeshStyle("scene_1").applyMeshStyle(MESH_ID)).resolves.toStrictEqual([]); }); }); From f52b2421a60e7fab7198e8aa269efd813dd2eb89 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:05:42 +0100 Subject: [PATCH 015/121] feat(data_style): import styles under the importing scene Importing a snapshot clears and writes the rows of the importing scene only, so a duplicated scene never overwrites its source. A live snapshot of another scene is read raw so IndexedDB can clone it. Co-Authored-By: Claude Opus 5.5 --- app/stores/data_style.ts | 7 ++++--- internal/stores/data_style/state.ts | 9 ++++---- tests/unit/stores/data_style.nuxt.test.ts | 25 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/app/stores/data_style.ts b/app/stores/data_style.ts index 7645e65cb..6f35be4f4 100644 --- a/app/stores/data_style.ts +++ b/app/stores/data_style.ts @@ -125,9 +125,10 @@ function setupDataStyleStore(sceneId: SceneId): DataStyleStoreSetup { // oxlint-disable-next-line prefer-readonly-parameter-types -- ObjectStyle (external type) has a mutable index signature and mutable nested StyleValues fields that can't be marked readonly from here. async function importStores(snapshot: DataStyleSnapshot): Promise { - const stylesSnapshot = snapshot.styles; - const componentStylesSnapshot = snapshot.componentStyles; - const modelComponentTypeStylesSnapshot = snapshot.modelComponentTypeStyles ?? {}; + // The snapshot of another scene holds its reactive styles, which IndexedDB cannot clone + const stylesSnapshot = toRaw(snapshot.styles); + const componentStylesSnapshot = toRaw(snapshot.componentStyles); + const modelComponentTypeStylesSnapshot = toRaw(snapshot.modelComponentTypeStyles ?? {}); const styles = Object.entries(stylesSnapshot).map( // oxlint-disable-next-line prefer-readonly-parameter-types -- same external ObjectStyle limitation as above. diff --git a/internal/stores/data_style/state.ts b/internal/stores/data_style/state.ts index b4e907929..26cafb8b0 100644 --- a/internal/stores/data_style/state.ts +++ b/internal/stores/data_style/state.ts @@ -84,12 +84,13 @@ export function useDataStyleState(sceneId: SceneId): DataStyleStateApi { return merge({ coloring: {} }, modelComponentTypeStyles.value[cacheKey]); } + // Deletes the styles of this scene only: the other scenes keep theirs async function clear(): Promise { await Promise.all([ - dataStyleTable.clear(), - modelComponentDataStyleTable.clear(), - modelComponentTypeDataStyleTable.clear(), - sceneStyleDb().clear(), + dataStyleTable.where("scene_id").equals(sceneId).delete(), + modelComponentDataStyleTable.where("scene_id").equals(sceneId).delete(), + modelComponentTypeDataStyleTable.where("scene_id").equals(sceneId).delete(), + sceneStyleDb().delete(sceneId), ]); modelComponentTypeStyles.value = {}; componentStyles.value = {}; diff --git a/tests/unit/stores/data_style.nuxt.test.ts b/tests/unit/stores/data_style.nuxt.test.ts index 70c7b9ede..2290ae14b 100644 --- a/tests/unit/stores/data_style.nuxt.test.ts +++ b/tests/unit/stores/data_style.nuxt.test.ts @@ -4,6 +4,7 @@ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed // Local imports import { mockViewer, sentRequests } from "@ogw_tests/unit/stores/image_style_helpers"; +import { dataStyleDb } from "@ogw_internal/database/database"; import { setupActivePinia } from "@ogw_tests/utils"; import { useDataStyleStore } from "@ogw_front/stores/data_style"; @@ -12,6 +13,12 @@ vi.setConfig({ testTimeout: 10_000 }); const points_schemas = viewer_schemas.opengeodeweb_viewer.mesh.points; const RED = { red: 255, green: 0, blue: 0, alpha: 1 }; +// The style rows a scene holds for a data +async function storedStyle(sceneId: string, dataId: string): Promise { + const style = await dataStyleDb().get([sceneId, dataId]); + return style; +} + describe("data style store by scene", () => { // Styles persist in the database between tests: each test styles its own mesh let meshId = ""; @@ -40,4 +47,22 @@ describe("data style store by scene", () => { { schema: points_schemas.color, params: { scene_id: "scene_1", id: meshId, color: RED } }, ]); }); + + test("a duplicated scene styles its own copy", async () => { + mockViewer(); + const source = useDataStyleStore("scene_1"); + await source.addDataStyle(meshId, "PointSet3D"); + await vi.waitFor(() => { + expect(source.styles[meshId]).toBeDefined(); + }); + const sourceColor = source.meshPointsColor(meshId); + const copy = useDataStyleStore("scene_3"); + + await copy.importStores(source.exportStores()); + await copy.setMeshPointsColor(meshId, RED); + + expect(source.meshPointsColor(meshId)).toStrictEqual(sourceColor); + await expect(storedStyle("scene_1", meshId)).resolves.toMatchObject({ scene_id: "scene_1" }); + await expect(storedStyle("scene_3", meshId)).resolves.toMatchObject({ scene_id: "scene_3" }); + }); }); From d9d1a70b4b7d86cf8266da2f39b378dda86311e9 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:06:02 +0100 Subject: [PATCH 016/121] feat(data_style): delete scene styles on close Closing a scene deletes its rows of the 5 scene keyed tables before its stores are disposed. Co-Authored-By: Claude Opus 5.5 --- app/stores/scenes.ts | 2 +- internal/stores/scenes/scene_stores.ts | 7 +++++-- tests/unit/stores/data_style.nuxt.test.ts | 10 ++++++++++ tests/unit/stores/scenes_helpers.ts | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index ff114e8af..cbcd821ec 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -136,7 +136,7 @@ export const useScenesStore = defineStore("scenes", () => { if (scenes.value.length <= 1) { throw new Error("The last scene cannot be closed"); } - disposeSceneStores(sceneId); + await disposeSceneStores(sceneId); await useViewerStore().request({ schema: viewerSchemas.delete_scene, params: { scene_id: sceneId }, diff --git a/internal/stores/scenes/scene_stores.ts b/internal/stores/scenes/scene_stores.ts index 26e02333c..fc2232275 100644 --- a/internal/stores/scenes/scene_stores.ts +++ b/internal/stores/scenes/scene_stores.ts @@ -7,6 +7,7 @@ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed import type { DataItem } from "@ogw_internal/database/tables/data"; import type { SceneId } from "./types"; import { disposeSceneScope } from "./scene_scope"; +import { treeviewConfigDb } from "@ogw_internal/database/database"; import { useAppStore } from "@ogw_front/stores/app"; import { useDataStore } from "@ogw_front/stores/data"; import { useDataStyleStore } from "@ogw_front/stores/data_style"; @@ -100,8 +101,10 @@ async function duplicateSceneStores( Object.assign(hybridViewerStore.camera_options, structuredClone(toRaw(camera_options))); } -// The stores of a closed scene are no longer saved in projects -function disposeSceneStores(sceneId: SceneId): void { +// The stores of a closed scene are no longer saved in projects, nor its rows in the database +async function disposeSceneStores(sceneId: SceneId): Promise { + await useDataStyleStore(sceneId).clear(); + await treeviewConfigDb().delete(sceneId); const appStore = useAppStore(); for (const store of [ useDataStyleStore(sceneId), diff --git a/tests/unit/stores/data_style.nuxt.test.ts b/tests/unit/stores/data_style.nuxt.test.ts index 2290ae14b..658e33440 100644 --- a/tests/unit/stores/data_style.nuxt.test.ts +++ b/tests/unit/stores/data_style.nuxt.test.ts @@ -48,6 +48,16 @@ describe("data style store by scene", () => { ]); }); + test("clear deletes the styles of its scene only", async () => { + await useDataStyleStore("scene_1").addDataStyle(meshId, "PointSet3D"); + await useDataStyleStore("scene_2").addDataStyle(meshId, "PointSet3D"); + + await useDataStyleStore("scene_2").clear(); + + await expect(storedStyle("scene_1", meshId)).resolves.toBeDefined(); + await expect(storedStyle("scene_2", meshId)).resolves.toBeUndefined(); + }); + test("a duplicated scene styles its own copy", async () => { mockViewer(); const source = useDataStyleStore("scene_1"); diff --git a/tests/unit/stores/scenes_helpers.ts b/tests/unit/stores/scenes_helpers.ts index 5f5440e22..a321c4688 100644 --- a/tests/unit/stores/scenes_helpers.ts +++ b/tests/unit/stores/scenes_helpers.ts @@ -35,6 +35,7 @@ function fakeSceneStore(storeId: string, sceneId: string): Record object>(() => ({})), importStores: resolves(), + clear: resolves(), finalizeImportSelection: vi.fn<() => void>(), }; fakeStores.set(key, instance); From ffe83f799021952e224c9dbf487423bf5d417db0 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:11:13 +0100 Subject: [PATCH 017/121] fix(data_style): test scene style deletion on close closeScene must clear the scene's styles and delete its treeview config row. clear must delete the scene's rows in all 4 style tables. A duplicate must keep the source row's colour. Co-Authored-By: Claude Opus 5.5 --- tests/unit/stores/data_style.nuxt.test.ts | 45 ++++++++++++++++++++--- tests/unit/stores/scenes.nuxt.test.ts | 19 ++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/tests/unit/stores/data_style.nuxt.test.ts b/tests/unit/stores/data_style.nuxt.test.ts index 658e33440..80d2e0f29 100644 --- a/tests/unit/stores/data_style.nuxt.test.ts +++ b/tests/unit/stores/data_style.nuxt.test.ts @@ -3,8 +3,14 @@ import { beforeEach, describe, expect, test, vi } from "vitest"; import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; // Local imports +import { + componentDataStyleDb, + componentTypeDataStyleDb, + dataStyleDb, + sceneStyleDb, +} from "@ogw_internal/database/database"; import { mockViewer, sentRequests } from "@ogw_tests/unit/stores/image_style_helpers"; -import { dataStyleDb } from "@ogw_internal/database/database"; +import { getDefaultSceneStyle } from "@ogw_front/utils/default_styles"; import { setupActivePinia } from "@ogw_tests/utils"; import { useDataStyleStore } from "@ogw_front/stores/data_style"; @@ -19,6 +25,24 @@ async function storedStyle(sceneId: string, dataId: string): Promise { return style; } +// One row in each of the 4 style tables for the scene +async function seedStyles(sceneId: string, dataId: string): Promise { + await dataStyleDb().put({ scene_id: sceneId, data_id: dataId }); + await componentDataStyleDb().put({ scene_id: sceneId, id_model: dataId, id_component: "c" }); + await componentTypeDataStyleDb().put({ scene_id: sceneId, id_model: dataId, type: "Surface" }); + await sceneStyleDb().put({ ...getDefaultSceneStyle(), scene_id: sceneId }); +} + +async function storedRows(sceneId: string, dataId: string): Promise { + const rows = await Promise.all([ + dataStyleDb().get([sceneId, dataId]), + componentDataStyleDb().get([sceneId, dataId, "c"]), + componentTypeDataStyleDb().get([sceneId, dataId, "Surface"]), + sceneStyleDb().get(sceneId), + ]); + return rows; +} + describe("data style store by scene", () => { // Styles persist in the database between tests: each test styles its own mesh let meshId = ""; @@ -49,13 +73,19 @@ describe("data style store by scene", () => { }); test("clear deletes the styles of its scene only", async () => { - await useDataStyleStore("scene_1").addDataStyle(meshId, "PointSet3D"); - await useDataStyleStore("scene_2").addDataStyle(meshId, "PointSet3D"); + await seedStyles("scene_1", meshId); + await seedStyles("scene_2", meshId); await useDataStyleStore("scene_2").clear(); - await expect(storedStyle("scene_1", meshId)).resolves.toBeDefined(); - await expect(storedStyle("scene_2", meshId)).resolves.toBeUndefined(); + const kept = await storedRows("scene_1", meshId); + expect(kept.every((row) => row !== undefined)).toBe(true); + await expect(storedRows("scene_2", meshId)).resolves.toStrictEqual([ + undefined, + undefined, + undefined, + undefined, + ]); }); test("a duplicated scene styles its own copy", async () => { @@ -72,7 +102,10 @@ describe("data style store by scene", () => { await copy.setMeshPointsColor(meshId, RED); expect(source.meshPointsColor(meshId)).toStrictEqual(sourceColor); - await expect(storedStyle("scene_1", meshId)).resolves.toMatchObject({ scene_id: "scene_1" }); + await expect(storedStyle("scene_1", meshId)).resolves.toMatchObject({ + scene_id: "scene_1", + points: { coloring: { constant: sourceColor } }, + }); await expect(storedStyle("scene_3", meshId)).resolves.toMatchObject({ scene_id: "scene_3" }); }); }); diff --git a/tests/unit/stores/scenes.nuxt.test.ts b/tests/unit/stores/scenes.nuxt.test.ts index 69059dfb9..a2ca0bde5 100644 --- a/tests/unit/stores/scenes.nuxt.test.ts +++ b/tests/unit/stores/scenes.nuxt.test.ts @@ -14,6 +14,7 @@ import { } from "@ogw_tests/unit/stores/scenes_helpers"; import { MAX_SCENES } from "@ogw_internal/stores/scenes/types"; import { setupActivePinia } from "@ogw_tests/utils"; +import { treeviewConfigDb } from "@ogw_internal/database/database"; import { useScenesStore } from "@ogw_front/stores/scenes"; vi.setConfig({ testTimeout: 10_000 }); @@ -41,6 +42,13 @@ vi.mock(import("@ogw_front/stores/treeview") as Promise, async () => { }); const { viewer } = viewer_schemas.opengeodeweb_viewer; +const TREEVIEW_CONFIG = { + opened_views: [], + panelWidth: 0, + additionalPanelWidth: 0, + selectionIds: [], + rowHeights: [], +}; describe("scenes store", () => { let request: Mock = vi.fn(); @@ -183,6 +191,17 @@ describe("scenes store", () => { expect(fakeSceneStore("treeview", "scene_3").$dispose).toHaveBeenCalledWith(); }); + test("closeScene deletes the rows of the scene", async () => { + const scenesStore = useScenesStore(); + await scenesStore.createScene("empty"); + await treeviewConfigDb().put({ ...TREEVIEW_CONFIG, scene_id: "scene_2" }); + + await scenesStore.closeScene("scene_2"); + + expect(fakeSceneStore("dataStyle", "scene_2").clear).toHaveBeenCalledWith(); + await expect(treeviewConfigDb().get("scene_2")).resolves.toBeUndefined(); + }); + test("closeScene drops a link of one", async () => { const scenesStore = useScenesStore(); const { deleteItem } = mockData(); From fe4656d5a7fd4a68292cb6cebc6f4c2e1d8fc30c Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:30:23 +0100 Subject: [PATCH 018/121] feat(hybrid_viewer): scope core and camera slices by scene The core, camera and scene slices become one instance per scene (runInSceneScope) instead of createSharedComposable singletons. Every scene RPC they send (render, update_camera, set_z_scaling, set_background_color) carries the scene id. setCameraOptions moves the local and the viewer cameras; the end of an interaction goes through it. The light viewable reading moves to light_viewable.ts. Co-Authored-By: Claude Opus 5.5 --- internal/stores/hybrid_viewer/camera.ts | 110 +++++++++++------- .../stores/hybrid_viewer/camera_helpers.ts | 5 +- .../hybrid_viewer/camera_orientation.ts | 11 +- internal/stores/hybrid_viewer/core.ts | 26 ++++- .../stores/hybrid_viewer/light_viewable.ts | 37 ++++++ internal/stores/hybrid_viewer/scene.ts | 97 ++++++++------- 6 files changed, 192 insertions(+), 94 deletions(-) create mode 100644 internal/stores/hybrid_viewer/light_viewable.ts diff --git a/internal/stores/hybrid_viewer/camera.ts b/internal/stores/hybrid_viewer/camera.ts index adf867828..f04a49691 100644 --- a/internal/stores/hybrid_viewer/camera.ts +++ b/internal/stores/hybrid_viewer/camera.ts @@ -3,40 +3,70 @@ import { animateCamera, computeAnimationDuration, getCameraOptions } from "./cam import { requireRenderWindow, useHybridViewerCore } from "./core"; import type { CameraOptions } from "./vtk_types"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { animateCameraOrientation } from "./camera_orientation"; +import { runInSceneScope } from "@ogw_internal/stores/scenes/scene_scope"; import { useHybridViewerScene } from "./scene"; import { useViewerStore } from "@ogw_front/stores/viewer"; import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; -// Shared via createSharedComposable (rather than merged into the parent hybridViewer store) so sibling slices, e.g. viewport.ts and ruler.ts, can read camera_options/setCamera/syncRemoteCamera directly without importing the parent store and creating a cycle. A Pinia store would work too but its $id/$patch/... properties would leak into the composed store's spread and collapse its inferred type. -const useHybridViewerCamera = createSharedComposable(() => { +interface HybridViewerCamera { + camera_options: Record; + setCameraOptions: (options: CameraOptions) => Promise; + syncRemoteCamera: () => void; + syncRemoteCameraAsync: () => Promise; + setCamera: (targetCameraOptions: CameraOptions) => void; + resetCamera: () => void; + focusCameraOnObject: (dataId: DataId, block_ids?: number[]) => Promise; + setCameraOrientation: (orientation: string) => void; +} + +const CAMERA_OPTION_KEYS = ["focal_point", "view_up", "position", "view_angle"]; + +// The camera options of a scene are empty until its viewer has a camera +function isCameraOptions( + options: Record, +): options is CameraOptions & Record { + return CAMERA_OPTION_KEYS.every((key) => key in options); +} + +function createHybridViewerCamera(sceneId: SceneId): HybridViewerCamera { const camera_options = reactive>({}); - async function syncRemoteCameraAsync(): Promise { - const { genericRenderWindow, remoteRender } = useHybridViewerCore(); - const viewerStore = useViewerStore(); - const renderer = requireRenderWindow(genericRenderWindow).getRenderer(); - const options_camera = getCameraOptions(renderer.getActiveCamera()); - await viewerStore.request({ + // Moves the local and the viewer cameras + async function setCameraOptions(options: CameraOptions): Promise { + const { genericRenderWindow, remoteRender } = useHybridViewerCore(sceneId); + let sentOptions = options; + if (genericRenderWindow.value) { + const renderer = genericRenderWindow.value.getRenderer(); + const camera = renderer.getActiveCamera(); + applyCameraOptions(camera, options); + renderer.resetCameraClippingRange(); + genericRenderWindow.value.getRenderWindow().render(); + sentOptions = getCameraOptions(camera); + } + await useViewerStore().request({ schema: viewer_schemas.opengeodeweb_viewer.viewer.update_camera, - params: { camera_options: options_camera }, + params: { scene_id: sceneId, camera_options: sentOptions }, }); await remoteRender(); - Object.assign(camera_options, options_camera); + Object.assign(camera_options, sentOptions); } - function performSyncRemoteCamera(): void { - // oxlint-disable-next-line promise/prefer-await-to-then -- fire-and-forget inside a sync caller; see codebase convention in global_attribute_style.ts. - syncRemoteCameraAsync().catch(() => undefined); + async function syncRemoteCameraAsync(): Promise { + const { genericRenderWindow } = useHybridViewerCore(sceneId); + const renderer = requireRenderWindow(genericRenderWindow).getRenderer(); + await setCameraOptions(getCameraOptions(renderer.getActiveCamera())); } function syncRemoteCamera(): void { - performSyncRemoteCamera(); + // oxlint-disable-next-line promise/prefer-await-to-then -- fire-and-forget inside a sync caller; see codebase convention in global_attribute_style.ts. + syncRemoteCameraAsync().catch(() => undefined); } - function performSetCamera(targetCameraOptions: CameraOptions): void { - const { genericRenderWindow, is_moving } = useHybridViewerCore(); - const imageStyle = getImageStyle(); + function setCamera(targetCameraOptions: CameraOptions): void { + const { genericRenderWindow, is_moving } = useHybridViewerCore(sceneId); + const imageStyle = getImageStyle(sceneId); const renderer = requireRenderWindow(genericRenderWindow).getRenderer(); const camera = renderer.getActiveCamera(); const startState = getCameraOptions(camera); @@ -63,17 +93,13 @@ const useHybridViewerCamera = createSharedComposable(() => { const renderWindow = requireRenderWindow(genericRenderWindow).getRenderWindow(); renderWindow.render(); is_moving.value = false; - performSyncRemoteCamera(); + syncRemoteCamera(); }, }); } - function setCamera(targetCameraOptions: CameraOptions): void { - performSetCamera(targetCameraOptions); - } - function resetCamera(): void { - const { genericRenderWindow } = useHybridViewerCore(); + const { genericRenderWindow } = useHybridViewerCore(sceneId); const renderer = requireRenderWindow(genericRenderWindow).getRenderer(); renderer.resetCamera(); const renderWindow = requireRenderWindow(genericRenderWindow).getRenderWindow(); @@ -81,12 +107,9 @@ const useHybridViewerCamera = createSharedComposable(() => { syncRemoteCamera(); } - async function performFocusCameraOnObject( - dataId: DataId, - block_ids: number[] = [], - ): Promise { - const { genericRenderWindow } = useHybridViewerCore(); - const { hybridDb } = useHybridViewerScene(); + async function focusCameraOnObject(dataId: DataId, block_ids: number[] = []): Promise { + const { genericRenderWindow } = useHybridViewerCore(sceneId); + const { hybridDb } = useHybridViewerScene(sceneId); if (!hybridDb[dataId]) { return; } @@ -109,19 +132,16 @@ const useHybridViewerCamera = createSharedComposable(() => { renderer.resetCamera(bounds); const targetOptions = getCameraOptions(camera); applyCameraOptions(camera, startOptions); - performSetCamera(targetOptions); - } - - async function focusCameraOnObject(dataId: DataId, block_ids: number[] = []): Promise { - await performFocusCameraOnObject(dataId, block_ids); + setCamera(targetOptions); } function setCameraOrientation(orientation: string): void { - animateCameraOrientation(orientation, performSyncRemoteCamera); + animateCameraOrientation(sceneId, orientation, syncRemoteCamera); } return { camera_options, + setCameraOptions, syncRemoteCamera, syncRemoteCameraAsync, setCamera, @@ -129,22 +149,30 @@ const useHybridViewerCamera = createSharedComposable(() => { focusCameraOnObject, setCameraOrientation, }; -}); +} + +// One instance per scene (runInSceneScope, rather than merged into the parent hybridViewer store) so sibling slices, e.g. viewport.ts and ruler.ts, can read camera_options/setCamera/syncRemoteCamera directly without importing the parent store and creating a cycle. A Pinia store would work too but its $id/$patch/... properties would leak into the composed store's spread and collapse its inferred type. +function useHybridViewerCamera(sceneId: SceneId): HybridViewerCamera { + return runInSceneScope(sceneId, "hybridViewerCamera", () => createHybridViewerCamera(sceneId)); +} interface CameraSnapshot { zScale?: number; camera_options?: CameraOptions; } -async function applySnapshot(snapshot: CameraSnapshot | undefined): Promise { +async function applySnapshot( + sceneId: SceneId, + snapshot: CameraSnapshot | undefined, +): Promise { if (!snapshot) { return; } if (typeof snapshot.zScale === "number") { - await useHybridViewerScene().setZScaling(snapshot.zScale); + await useHybridViewerScene(sceneId).setZScaling(snapshot.zScale); } if (snapshot.camera_options) { - useHybridViewerCamera().setCamera(snapshot.camera_options); + useHybridViewerCamera(sceneId).setCamera(snapshot.camera_options); } } export { @@ -155,5 +183,5 @@ export { applyCameraOptions, centerCameraOnPosition, } from "./camera_helpers"; -export { applySnapshot, useHybridViewerCamera }; -export type { CameraSnapshot }; +export { applySnapshot, isCameraOptions, useHybridViewerCamera }; +export type { CameraSnapshot, HybridViewerCamera }; diff --git a/internal/stores/hybrid_viewer/camera_helpers.ts b/internal/stores/hybrid_viewer/camera_helpers.ts index bb6756c1c..0dc0f9ed9 100644 --- a/internal/stores/hybrid_viewer/camera_helpers.ts +++ b/internal/stores/hybrid_viewer/camera_helpers.ts @@ -1,4 +1,5 @@ import type { CameraOptions, Vector3, vtkCamera, vtkOpenGLRenderWindow } from "./vtk_types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { dot } from "@kitware/vtk.js/Common/Core/Math"; import { useHybridViewerCore } from "./core"; @@ -38,8 +39,8 @@ const ORIENTATIONS: Record = { }, }; -function getImageStyle(): CSSStyleDeclaration | undefined { - const { genericRenderWindow } = useHybridViewerCore(); +function getImageStyle(sceneId: SceneId): CSSStyleDeclaration | undefined { + const { genericRenderWindow } = useHybridViewerCore(sceneId); if (!genericRenderWindow.value) { return undefined; } diff --git a/internal/stores/hybrid_viewer/camera_orientation.ts b/internal/stores/hybrid_viewer/camera_orientation.ts index 670cb2c54..94de54af8 100644 --- a/internal/stores/hybrid_viewer/camera_orientation.ts +++ b/internal/stores/hybrid_viewer/camera_orientation.ts @@ -13,15 +13,20 @@ import { getCameraOptions, } from "./camera_animation"; import { requireRenderWindow, useHybridViewerCore } from "./core"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { dot } from "@kitware/vtk.js/Common/Core/Math"; -function animateCameraOrientation(orientation: string, syncRemoteCamera: () => void): void { +function animateCameraOrientation( + sceneId: SceneId, + orientation: string, + syncRemoteCamera: () => void, +): void { const config = ORIENTATIONS[orientation.toLowerCase()]; if (!config) { return; } - const { genericRenderWindow, is_moving } = useHybridViewerCore(); - const imageStyle = getImageStyle(); + const { genericRenderWindow, is_moving } = useHybridViewerCore(sceneId); + const imageStyle = getImageStyle(sceneId); const renderer = requireRenderWindow(genericRenderWindow).getRenderer(); const camera = renderer.getActiveCamera(); const startState = getCameraOptions(camera); diff --git a/internal/stores/hybrid_viewer/core.ts b/internal/stores/hybrid_viewer/core.ts index 23eeb7e2c..9f5b77980 100644 --- a/internal/stores/hybrid_viewer/core.ts +++ b/internal/stores/hybrid_viewer/core.ts @@ -1,6 +1,8 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { Status } from "@ogw_front/utils/status"; import type { ViewStreamLike } from "./vtk_types"; import type { vtkGenericRenderWindow as VtkGenericRenderWindow } from "@kitware/vtk.js/Rendering/Misc/GenericRenderWindow"; +import { runInSceneScope } from "@ogw_internal/stores/scenes/scene_scope"; import { useViewerStore } from "@ogw_front/stores/viewer"; import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -16,8 +18,16 @@ function requireRenderWindow(holder: GenericRenderWindowHolder): VtkGenericRende return holder.value; } -// Render-window, status and drag/pick state shared across the hybrid viewer's slice composables (app/stores/hybrid_viewer.ts and internal/stores/hybrid_viewer/*), plus the debounced remote-render call they all trigger. Shared via createSharedComposable (a singleton per mounted tree, not a Pinia store) so those slices can depend on it directly instead of on the composed hybridViewer store, which would create an import cycle; a real Pinia store here would also pull its own $id/$patch/... properties into the composed store's spread and collapse its inferred type. -const useHybridViewerCore = createSharedComposable(() => { +interface HybridViewerCore { + genericRenderWindow: GenericRenderWindowHolder; + status: Ref; + is_moving: Ref; + is_picking: Ref; + viewStream: Ref; + remoteRender: () => Promise; +} + +function createHybridViewerCore(sceneId: SceneId): HybridViewerCore { const genericRenderWindow = reactive({}); const status = ref(Status.NOT_CREATED); const is_moving = ref(false); @@ -27,6 +37,7 @@ const useHybridViewerCore = createSharedComposable(() => { let renderPromise: Promise | undefined = undefined; let renderPending = false; + // Renders the scene's own view only async function remoteRender(): Promise { if (renderPromise) { renderPending = true; @@ -38,7 +49,7 @@ const useHybridViewerCore = createSharedComposable(() => { try { const viewerStore = useViewerStore(); const schema = viewer_schemas.opengeodeweb_viewer.viewer.render; - await viewerStore.request({ schema }); + await viewerStore.request({ schema, params: { scene_id: sceneId } }); } finally { renderPromise = undefined; if (renderPending) { @@ -58,7 +69,12 @@ const useHybridViewerCore = createSharedComposable(() => { viewStream, remoteRender, }; -}); +} + +// Render-window, status and drag/pick state shared across the hybrid viewer's slice composables (app/stores/hybrid_viewer.ts and internal/stores/hybrid_viewer/*), plus the debounced remote-render call they all trigger. One instance per scene (runInSceneScope, not a Pinia store) so those slices can depend on it directly instead of on the composed hybridViewer store, which would create an import cycle; a real Pinia store here would also pull its own $id/$patch/... properties into the composed store's spread and collapse its inferred type. +function useHybridViewerCore(sceneId: SceneId): HybridViewerCore { + return runInSceneScope(sceneId, "hybridViewerCore", () => createHybridViewerCore(sceneId)); +} export { requireRenderWindow, useHybridViewerCore }; -export type { GenericRenderWindowHolder }; +export type { GenericRenderWindowHolder, HybridViewerCore }; diff --git a/internal/stores/hybrid_viewer/light_viewable.ts b/internal/stores/hybrid_viewer/light_viewable.ts new file mode 100644 index 000000000..37d4dc39f --- /dev/null +++ b/internal/stores/hybrid_viewer/light_viewable.ts @@ -0,0 +1,37 @@ +import { ACTOR_COLOR } from "./constants"; +import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; +import type { HybridDbEntry } from "./vtk_types"; +import { base64ToArrayBuffer } from "./base64"; +import { useDataStore } from "@ogw_front/stores/data"; +import { newInstance as vtkActor } from "@kitware/vtk.js/Rendering/Core/Actor"; +import { newInstance as vtkMapper } from "@kitware/vtk.js/Rendering/Core/Mapper"; +import type vtkPolyData from "@kitware/vtk.js/Common/DataModel/PolyData"; +import { newInstance as vtkXMLPolyDataReader } from "@kitware/vtk.js/IO/XML/XMLPolyDataReader"; + +async function fetchBinaryLightViewable(dataId: DataId): Promise { + const dataStore = useDataStore(); + const isViewable = await dataStore.fetchIsViewable(dataId); + if (!isViewable) { + return undefined; + } + const value = await dataStore.item(dataId); + return value.binary_light_viewable; +} + +function createHybridDbEntry(binaryLightViewable: string, zScale: number): HybridDbEntry { + const reader = vtkXMLPolyDataReader(); + reader.parseAsArrayBuffer(base64ToArrayBuffer(binaryLightViewable)); + const actor = vtkActor(); + const mapper = vtkMapper(); + // oxlint-disable-next-line no-unsafe-type-assertion -- vtk.js's algorithm interface types getOutputData as `any`; this reader always produces polydata. + const polydata = reader.getOutputData(0) as unknown as vtkPolyData; + mapper.setInputData(polydata); + const property = actor.getProperty(); + property.setColor(ACTOR_COLOR); + actor.setMapper(mapper); + actor.setScale(1, 1, zScale); + const compactPoints = Float64Array.from(polydata.getPoints().getData()); + return { actor, polydata, mapper, compactPoints }; +} + +export { createHybridDbEntry, fetchBinaryLightViewable }; diff --git a/internal/stores/hybrid_viewer/scene.ts b/internal/stores/hybrid_viewer/scene.ts index 30b9e0a34..5d720e8ce 100644 --- a/internal/stores/hybrid_viewer/scene.ts +++ b/internal/stores/hybrid_viewer/scene.ts @@ -1,20 +1,23 @@ -import { ACTOR_COLOR, RGB_MAX } from "./constants"; -import type { HybridDb, HybridDbEntry, vtkActor as VtkActorInstance, vtkCamera } from "./vtk_types"; +import type { + HybridDb, + vtkActor as VtkActorInstance, + vtkGenericRenderWindow as VtkGenericRenderWindow, + vtkCamera, +} from "./vtk_types"; +import { createHybridDbEntry, fetchBinaryLightViewable } from "./light_viewable"; import { requireRenderWindow, useHybridViewerCore } from "./core"; import viewer_schemas, { type ViewerSetBackgroundColorParams, } from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; +import { RGB_MAX } from "./constants"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { Visibility } from "@geode/opengeodeweb-viewer/schema_types"; -import { base64ToArrayBuffer } from "./base64"; import { getCameraOptions } from "./camera_animation"; import { getDefaultSceneStyle } from "@ogw_front/utils/default_styles"; -import { useDataStore } from "@ogw_front/stores/data"; +import { runInSceneScope } from "@ogw_internal/stores/scenes/scene_scope"; import { useViewerStore } from "@ogw_front/stores/viewer"; -import { newInstance as vtkActor } from "@kitware/vtk.js/Rendering/Core/Actor"; -import { newInstance as vtkMapper } from "@kitware/vtk.js/Rendering/Core/Mapper"; -import type vtkPolyData from "@kitware/vtk.js/Common/DataModel/PolyData"; -import { newInstance as vtkXMLPolyDataReader } from "@kitware/vtk.js/IO/XML/XMLPolyDataReader"; +import { newInstance as vtkGenericRenderWindow } from "@kitware/vtk.js/Rendering/Misc/GenericRenderWindow"; // The local renderer shows while the camera moves: it starts on the scene background the viewer gets after a reset function localBackgroundColor(): [number, number, number] { @@ -22,8 +25,19 @@ function localBackgroundColor(): [number, number, number] { return [red / RGB_MAX, green / RGB_MAX, blue / RGB_MAX]; } -async function setBackgroundColor(color: ViewerSetBackgroundColorParams["color"]): Promise { - const { genericRenderWindow, remoteRender } = useHybridViewerCore(); +// The render window drawing the scene locally while its camera moves +function createLocalRenderWindow(): VtkGenericRenderWindow { + return vtkGenericRenderWindow({ + background: localBackgroundColor(), + listenWindowResize: false, + }); +} + +async function applyBackgroundColor( + sceneId: SceneId, + color: ViewerSetBackgroundColorParams["color"], +): Promise { + const { genericRenderWindow, remoteRender } = useHybridViewerCore(sceneId); const renderer = requireRenderWindow(genericRenderWindow).getRenderer(); renderer.setBackground([color.red / RGB_MAX, color.green / RGB_MAX, color.blue / RGB_MAX]); const renderWindow = requireRenderWindow(genericRenderWindow).getRenderWindow(); @@ -31,6 +45,7 @@ async function setBackgroundColor(color: ViewerSetBackgroundColorParams["color"] const viewerStore = useViewerStore(); const schema = viewer_schemas.opengeodeweb_viewer.viewer.set_background_color; const params = { + scene_id: sceneId, color, }; await viewerStore.request({ @@ -49,39 +64,23 @@ function followZScaling(camera: vtkCamera, ratio: number): void { camera.setPosition(positionX, positionY, positionZ + offset); } -async function fetchBinaryLightViewable(dataId: DataId): Promise { - const dataStore = useDataStore(); - const isViewable = await dataStore.fetchIsViewable(dataId); - if (!isViewable) { - return undefined; - } - const value = await dataStore.item(dataId); - return value.binary_light_viewable; -} - -function createHybridDbEntry(binaryLightViewable: string, zScale: number): HybridDbEntry { - const reader = vtkXMLPolyDataReader(); - reader.parseAsArrayBuffer(base64ToArrayBuffer(binaryLightViewable)); - const actor = vtkActor(); - const mapper = vtkMapper(); - // oxlint-disable-next-line no-unsafe-type-assertion -- vtk.js's algorithm interface types getOutputData as `any`; this reader always produces polydata. - const polydata = reader.getOutputData(0) as unknown as vtkPolyData; - mapper.setInputData(polydata); - const property = actor.getProperty(); - property.setColor(ACTOR_COLOR); - actor.setMapper(mapper); - actor.setScale(1, 1, zScale); - const compactPoints = Float64Array.from(polydata.getPoints().getData()); - return { actor, polydata, mapper, compactPoints }; +interface HybridViewerScene { + hybridDb: HybridDb; + zScale: Ref; + addItem: (dataId: DataId) => Promise; + removeItem: (dataId: DataId) => void; + setVisibility: (dataId: DataId, visibility: Visibility) => void; + setZScaling: (z_scale: number) => Promise; + setBackgroundColor: (color: ViewerSetBackgroundColorParams["color"]) => Promise; + clear: () => void; } -// Shared via createSharedComposable (rather than merged into the parent hybridViewer store) so sibling slices, e.g. camera.ts and ruler.ts, can read hybridDb/setZScaling directly without importing the parent store and creating a cycle. A Pinia store would work too but its $id/$patch/... properties would leak into the composed store's spread and collapse its inferred type. -const useHybridViewerScene = createSharedComposable(() => { +function createHybridViewerScene(sceneId: SceneId): HybridViewerScene { const hybridDb = reactive({}); const zScale = ref(1); async function addItem(dataId: DataId): Promise { - const { genericRenderWindow } = useHybridViewerCore(); + const { genericRenderWindow } = useHybridViewerCore(sceneId); if (!genericRenderWindow.value) { return; } @@ -105,7 +104,7 @@ const useHybridViewerScene = createSharedComposable(() => { } function removeItem(dataId: DataId): void { - const { genericRenderWindow } = useHybridViewerCore(); + const { genericRenderWindow } = useHybridViewerCore(sceneId); if (!hybridDb[dataId]) { return; } @@ -117,7 +116,7 @@ const useHybridViewerScene = createSharedComposable(() => { } function setVisibility(dataId: DataId, visibility: Visibility): void { - const { genericRenderWindow } = useHybridViewerCore(); + const { genericRenderWindow } = useHybridViewerCore(sceneId); if (!hybridDb[dataId]) { return; } @@ -127,7 +126,7 @@ const useHybridViewerScene = createSharedComposable(() => { } async function setZScaling(z_scale: number): Promise { - const { genericRenderWindow, remoteRender } = useHybridViewerCore(); + const { genericRenderWindow, remoteRender } = useHybridViewerCore(sceneId); const ratio = z_scale / zScale.value; zScale.value = z_scale; const renderer = requireRenderWindow(genericRenderWindow).getRenderer(); @@ -145,20 +144,26 @@ const useHybridViewerScene = createSharedComposable(() => { await viewerStore.request({ schema: viewer_schemas.opengeodeweb_viewer.viewer.set_z_scaling, params: { + scene_id: sceneId, z_scale, }, }); await viewerStore.request({ schema: viewer_schemas.opengeodeweb_viewer.viewer.update_camera, params: { + scene_id: sceneId, camera_options: getCameraOptions(camera), }, }); await remoteRender(); } + async function setBackgroundColor(color: ViewerSetBackgroundColorParams["color"]): Promise { + await applyBackgroundColor(sceneId, color); + } + function clear(): void { - const { genericRenderWindow } = useHybridViewerCore(); + const { genericRenderWindow } = useHybridViewerCore(sceneId); const renderer = requireRenderWindow(genericRenderWindow).getRenderer(); for (const actor of renderer.getActors()) { renderer.removeActor(actor); @@ -180,6 +185,12 @@ const useHybridViewerScene = createSharedComposable(() => { setBackgroundColor, clear, }; -}); +} + +// One instance per scene (runInSceneScope, rather than merged into the parent hybridViewer store) so sibling slices, e.g. camera.ts and ruler.ts, can read hybridDb/setZScaling directly without importing the parent store and creating a cycle. A Pinia store would work too but its $id/$patch/... properties would leak into the composed store's spread and collapse its inferred type. +function useHybridViewerScene(sceneId: SceneId): HybridViewerScene { + return runInSceneScope(sceneId, "hybridViewerScene", () => createHybridViewerScene(sceneId)); +} -export { followZScaling, localBackgroundColor, useHybridViewerScene }; +export { createLocalRenderWindow, followZScaling, localBackgroundColor, useHybridViewerScene }; +export type { HybridViewerScene }; From dc6430f74afa67c60e11dda6a6a12d0a0003dbce Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:30:36 +0100 Subject: [PATCH 019/121] feat(hybrid_viewer): scope highlight, zoom box and ruler by scene The highlight and zoom box slices become one instance per scene, the ruler takes its scene. Their highlight, ruler, reset_ruler and get_point_position requests carry the scene id: the viewer store's pick_world_position and set_picked_point take the scene they pick in. Co-Authored-By: Claude Opus 5.5 --- app/stores/viewer.ts | 9 ++--- app/stores/viewer_helpers/actions.ts | 10 ++++-- internal/stores/hybrid_viewer/highlight.ts | 34 +++++++++++++++---- internal/stores/hybrid_viewer/ruler.ts | 23 ++++++++----- internal/stores/hybrid_viewer/zoom_box.ts | 22 +++++++++--- .../stores/hybrid_viewer_ruler.nuxt.test.ts | 10 +++--- .../hybrid_viewer_zoom_box.nuxt.test.ts | 7 ++-- 7 files changed, 80 insertions(+), 35 deletions(-) diff --git a/app/stores/viewer.ts b/app/stores/viewer.ts index 8166ccf0d..ff4e352ae 100644 --- a/app/stores/viewer.ts +++ b/app/stores/viewer.ts @@ -25,6 +25,7 @@ import { useInfraStore } from "@ogw_front/stores/infra"; import type { JsonRpcSchema, RequestHandlers, ResponseOf } from "@ogw_shared/utils/types.js"; import type { RpcClient } from "@ogw_shared/utils/call_raw.js"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; interface ViewSize { width: number; @@ -89,12 +90,12 @@ export const useViewerStore = defineStore( const result = await callViewer(microservice, args, callbacks); return result; } - async function pick_world_position(x: number, y: number): Promise { - const position = await pickWorldPosition(request, x, y); + async function pick_world_position(sceneId: SceneId, x: number, y: number): Promise { + const position = await pickWorldPosition(request, sceneId, x, y); return position; } - async function set_picked_point(x: number, y: number): Promise { - const [world_x, world_y, world_z] = await pick_world_position(x, y); + async function set_picked_point(sceneId: SceneId, x: number, y: number): Promise { + const [world_x, world_y, world_z] = await pick_world_position(sceneId, x, y); picked_point.value = { x: world_x, y: world_y, z: world_z }; } async function ws_connect(): Promise { diff --git a/app/stores/viewer_helpers/actions.ts b/app/stores/viewer_helpers/actions.ts index 59987ea3c..ee90c7a1a 100644 --- a/app/stores/viewer_helpers/actions.ts +++ b/app/stores/viewer_helpers/actions.ts @@ -1,3 +1,4 @@ +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { Vector3 } from "@kitware/vtk.js/types"; import type { ViewerRequest } from "./request.js"; import { consola } from "consola"; @@ -6,7 +7,12 @@ import opengeodeweb_viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb import { useAppStore } from "@ogw_front/stores/app"; import { useFeedbackStore } from "@ogw_front/stores/feedback"; -async function pickWorldPosition(request: ViewerRequest, x: number, y: number): Promise { +async function pickWorldPosition( + request: ViewerRequest, + sceneId: SceneId, + x: number, + y: number, +): Promise { const schema = opengeodeweb_viewer_schemas.opengeodeweb_viewer.viewer.get_point_position; const { x: world_x, @@ -14,7 +20,7 @@ async function pickWorldPosition(request: ViewerRequest, x: number, y: number): z: world_z, } = await request({ schema, - params: { x: Math.round(x), y: Math.round(y) }, + params: { scene_id: sceneId, x: Math.round(x), y: Math.round(y) }, }); return [world_x, world_y, world_z]; } diff --git a/internal/stores/hybrid_viewer/highlight.ts b/internal/stores/hybrid_viewer/highlight.ts index bbda5f000..b7389d4e1 100644 --- a/internal/stores/hybrid_viewer/highlight.ts +++ b/internal/stores/hybrid_viewer/highlight.ts @@ -6,8 +6,10 @@ import viewer_schemas, { } from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; import type { GeodeId } from "@geode/opengeodeweb-microservice/schema_types"; import type { ModelId } from "@ogw_front/types/identifiers"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { dataDb } from "@ogw_internal/database/database.js"; import { modelComponent } from "@ogw_internal/database/queries.js"; +import { runInSceneScope } from "@ogw_internal/stores/scenes/scene_scope"; import { useHybridViewerCore } from "./core"; import { useHybridViewerScene } from "./scene"; import { useViewerStore } from "@ogw_front/stores/viewer"; @@ -35,8 +37,16 @@ async function lookupComponentInfo( }; } -// Shared via createSharedComposable (rather than merged into the parent hybridViewer store) so sibling slices, e.g. ruler.ts and viewport.ts, can read hover state/clearHoverHighlight/hoverHighlight directly without importing the parent store and creating a cycle. A Pinia store would work too but its $id/$patch/... properties would leak into the composed store's spread and collapse its inferred type. -const useHybridViewerHighlight = createSharedComposable(() => { +interface HybridViewerHighlight { + is_hover_highlight: Ref; + hover_highlight_field_type: Ref; + hoverData: Ref; + hoverPosition: Ref<{ x: number; y: number }>; + clearHoverHighlight: () => void; + hoverHighlight: (event: MouseEvent) => Promise; +} + +function createHybridViewerHighlight(sceneId: SceneId): HybridViewerHighlight { const is_hover_highlight = ref(false); const hover_highlight_field_type = ref("CELL"); const hoverData = ref(undefined); @@ -63,8 +73,8 @@ const useHybridViewerHighlight = createSharedComposable(() => { if (!is_hover_highlight.value) { return; } - const { genericRenderWindow } = useHybridViewerCore(); - const { hybridDb } = useHybridViewerScene(); + const { genericRenderWindow } = useHybridViewerCore(sceneId); + const { hybridDb } = useHybridViewerScene(sceneId); const container = genericRenderWindow.value?.getContainer(); if (!container) { return; @@ -73,6 +83,7 @@ const useHybridViewerHighlight = createSharedComposable(() => { const rect = container.getBoundingClientRect(); const schema = viewer_schemas.opengeodeweb_viewer.viewer.highlight; const params = { + scene_id: sceneId, x: Math.round(event.clientX - rect.left), y: Math.round(rect.height - (event.clientY - rect.top)), field_type: hover_highlight_field_type.value, @@ -134,7 +145,7 @@ const useHybridViewerHighlight = createSharedComposable(() => { } const hoverHighlight = useDebounceFn((event: MouseEvent) => { - const { genericRenderWindow } = useHybridViewerCore(); + const { genericRenderWindow } = useHybridViewerCore(sceneId); const containerElement = genericRenderWindow.value?.getContainer(); let relativeMousePosition = { x: event.clientX, @@ -152,10 +163,11 @@ const useHybridViewerHighlight = createSharedComposable(() => { }, HOVER_DEBOUNCE_MS); function requestClearHoverHighlight(): void { - const { hybridDb } = useHybridViewerScene(); + const { hybridDb } = useHybridViewerScene(sceneId); const viewerStore = useViewerStore(); const schema = viewer_schemas.opengeodeweb_viewer.viewer.highlight; const params = { + scene_id: sceneId, x: -1, y: -1, field_type: hover_highlight_field_type.value, @@ -183,6 +195,14 @@ const useHybridViewerHighlight = createSharedComposable(() => { clearHoverHighlight, hoverHighlight, }; -}); +} + +// One instance per scene (runInSceneScope, rather than merged into the parent hybridViewer store) so sibling slices, e.g. ruler.ts and viewport.ts, can read hover state/clearHoverHighlight/hoverHighlight directly without importing the parent store and creating a cycle. A Pinia store would work too but its $id/$patch/... properties would leak into the composed store's spread and collapse its inferred type. +function useHybridViewerHighlight(sceneId: SceneId): HybridViewerHighlight { + return runInSceneScope(sceneId, "hybridViewerHighlight", () => + createHybridViewerHighlight(sceneId), + ); +} export { useHybridViewerHighlight }; +export type { HybridViewerHighlight }; diff --git a/internal/stores/hybrid_viewer/ruler.ts b/internal/stores/hybrid_viewer/ruler.ts index a95f35297..48cba6b58 100644 --- a/internal/stores/hybrid_viewer/ruler.ts +++ b/internal/stores/hybrid_viewer/ruler.ts @@ -1,6 +1,7 @@ import viewer_schemas, { type PickedFieldType, } from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { useHybridViewerCore } from "./core"; import { useHybridViewerHighlight } from "./highlight"; import { useHybridViewerScene } from "./scene"; @@ -11,7 +12,7 @@ interface RulerHoverState { fieldType: PickedFieldType; } -function useHybridViewerRuler(): { +function useHybridViewerRuler(sceneId: SceneId): { is_ruler_active: Ref; ruler_snap: Ref; ruler_point1: Ref; @@ -34,7 +35,7 @@ function useHybridViewerRuler(): { function updateRulerSnapHighlight(): void { const { is_hover_highlight, hover_highlight_field_type, clearHoverHighlight } = - useHybridViewerHighlight(); + useHybridViewerHighlight(sceneId); if (is_ruler_active.value && ruler_snap.value) { hover_state_before_snap = { @@ -63,21 +64,25 @@ function useHybridViewerRuler(): { if (ruler_point2.value) { points.push(ruler_point2.value); } - const { remoteRender } = useHybridViewerCore(); + const { remoteRender } = useHybridViewerCore(sceneId); const viewerStore = useViewerStore(); const schema = viewer_schemas.opengeodeweb_viewer.viewer.ruler; - const { distance } = await viewerStore.request({ schema, params: { points } }); + const { distance } = await viewerStore.request({ + schema, + params: { scene_id: sceneId, points }, + }); ruler_distance.value = distance; await remoteRender(); } async function handleRulerClick(x: number, y: number): Promise { - const { hybridDb } = useHybridViewerScene(); + const { hybridDb } = useHybridViewerScene(sceneId); const viewerStore = useViewerStore(); let coords: number[] | undefined = undefined; if (ruler_snap.value) { const schema = viewer_schemas.opengeodeweb_viewer.viewer.highlight; const params = { + scene_id: sceneId, x: Math.round(x), y: Math.round(y), field_type: "POINT" as const, @@ -87,7 +92,7 @@ function useHybridViewerRuler(): { const coordinates = attributes?.coordinates; coords = Array.isArray(coordinates) ? coordinates : undefined; } else { - coords = await viewerStore.pick_world_position(x, y); + coords = await viewerStore.pick_world_position(sceneId, x, y); } if (!coords) { return; @@ -106,7 +111,7 @@ function useHybridViewerRuler(): { } function deactivateRuler(): void { - const { clearHoverHighlight } = useHybridViewerHighlight(); + const { clearHoverHighlight } = useHybridViewerHighlight(sceneId); is_ruler_active.value = false; clearHoverHighlight(); } @@ -117,10 +122,10 @@ function useHybridViewerRuler(): { ruler_distance.value = undefined; ruler_awaiting_point.value = 1; deactivateRuler(); - const { remoteRender } = useHybridViewerCore(); + const { remoteRender } = useHybridViewerCore(sceneId); const viewerStore = useViewerStore(); const schema = viewer_schemas.opengeodeweb_viewer.viewer.reset_ruler; - await viewerStore.request({ schema }); + await viewerStore.request({ schema, params: { scene_id: sceneId } }); await remoteRender(); } diff --git a/internal/stores/hybrid_viewer/zoom_box.ts b/internal/stores/hybrid_viewer/zoom_box.ts index 5eaf57f58..6e6e671bd 100644 --- a/internal/stores/hybrid_viewer/zoom_box.ts +++ b/internal/stores/hybrid_viewer/zoom_box.ts @@ -2,7 +2,9 @@ import type { CameraOptions, Vector3 } from "./vtk_types"; import { applyCameraOptions, centerCameraOnPosition, useHybridViewerCamera } from "./camera"; import { requireRenderWindow, useHybridViewerCore } from "./core"; import type { Position } from "@vueuse/core"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { getCameraOptions } from "./camera_animation"; +import { runInSceneScope } from "@ogw_internal/stores/scenes/scene_scope"; import { useViewerStore } from "@ogw_front/stores/viewer"; import { newInstance as vtkCamera } from "@kitware/vtk.js/Rendering/Core/Camera"; @@ -44,18 +46,24 @@ function computeZoomToBoxCamera( return getCameraOptions(zoomCamera); } -const useHybridViewerZoomBox = createSharedComposable(() => { +interface HybridViewerZoomBox { + is_zoom_box_active: Ref; + zoomToBox: (box: ZoomBox, viewport: Viewport) => Promise; +} + +function createHybridViewerZoomBox(sceneId: SceneId): HybridViewerZoomBox { const is_zoom_box_active = ref(false); // Leaves the mode first so a second box cannot be drawn while the pick is pending. Request errors are reported by the viewer store. async function zoomToBox(box: ZoomBox, viewport: Viewport): Promise { is_zoom_box_active.value = false; const target = await useViewerStore().pick_world_position( + sceneId, (box.start.x + box.end.x) / 2, viewport.height - (box.start.y + box.end.y) / 2, ); - const { genericRenderWindow } = useHybridViewerCore(); - const { setCamera } = useHybridViewerCamera(); + const { genericRenderWindow } = useHybridViewerCore(sceneId); + const { setCamera } = useHybridViewerCamera(sceneId); const camera = requireRenderWindow(genericRenderWindow).getRenderer().getActiveCamera(); setCamera(computeZoomToBoxCamera(getCameraOptions(camera), box, viewport, target)); } @@ -64,7 +72,11 @@ const useHybridViewerZoomBox = createSharedComposable(() => { is_zoom_box_active, zoomToBox, }; -}); +} + +function useHybridViewerZoomBox(sceneId: SceneId): HybridViewerZoomBox { + return runInSceneScope(sceneId, "hybridViewerZoomBox", () => createHybridViewerZoomBox(sceneId)); +} export { computeZoomToBoxCamera, useHybridViewerZoomBox, viewportShapedBox }; -export type { ZoomBox }; +export type { HybridViewerZoomBox, ZoomBox }; diff --git a/tests/unit/stores/hybrid_viewer_ruler.nuxt.test.ts b/tests/unit/stores/hybrid_viewer_ruler.nuxt.test.ts index 72b56a63c..7ff6ab3ef 100644 --- a/tests/unit/stores/hybrid_viewer_ruler.nuxt.test.ts +++ b/tests/unit/stores/hybrid_viewer_ruler.nuxt.test.ts @@ -8,15 +8,15 @@ import { useHybridViewerRuler } from "@ogw_internal/stores/hybrid_viewer/ruler"; describe("ruler hover highlight", () => { beforeEach(() => { - const highlight = useHybridViewerHighlight(); + const highlight = useHybridViewerHighlight("scene_1"); vi.spyOn(highlight, "clearHoverHighlight").mockReturnValue(); highlight.is_hover_highlight.value = true; highlight.hover_highlight_field_type.value = "CELL"; }); test("leaves the user hover highlight untouched without snap", async () => { - const { is_hover_highlight, hover_highlight_field_type } = useHybridViewerHighlight(); - const ruler = useHybridViewerRuler(); + const { is_hover_highlight, hover_highlight_field_type } = useHybridViewerHighlight("scene_1"); + const ruler = useHybridViewerRuler("scene_1"); ruler.is_ruler_active.value = true; await nextTick(); @@ -26,8 +26,8 @@ describe("ruler hover highlight", () => { }); test("snaps on points, then restores the user hover highlight", async () => { - const { is_hover_highlight, hover_highlight_field_type } = useHybridViewerHighlight(); - const ruler = useHybridViewerRuler(); + const { is_hover_highlight, hover_highlight_field_type } = useHybridViewerHighlight("scene_1"); + const ruler = useHybridViewerRuler("scene_1"); ruler.is_ruler_active.value = true; ruler.ruler_snap.value = true; diff --git a/tests/unit/stores/hybrid_viewer_zoom_box.nuxt.test.ts b/tests/unit/stores/hybrid_viewer_zoom_box.nuxt.test.ts index 35b02ec93..0fb2d12b7 100644 --- a/tests/unit/stores/hybrid_viewer_zoom_box.nuxt.test.ts +++ b/tests/unit/stores/hybrid_viewer_zoom_box.nuxt.test.ts @@ -82,12 +82,12 @@ describe("zoomToBox", () => { getActiveCamera: (): typeof camera => camera, }), }; - const { genericRenderWindow } = useHybridViewerCore(); + const { genericRenderWindow } = useHybridViewerCore("scene_1"); // oxlint-disable-next-line typescript/no-unsafe-type-assertion genericRenderWindow.value = renderWindow as never; const pick = vi.spyOn(useViewerStore(), "pick_world_position").mockResolvedValue(TARGET); - const setCamera = vi.spyOn(useHybridViewerCamera(), "setCamera").mockReturnValue(); - const zoomBox = useHybridViewerZoomBox(); + const setCamera = vi.spyOn(useHybridViewerCamera("scene_1"), "setCamera").mockReturnValue(); + const zoomBox = useHybridViewerZoomBox("scene_1"); zoomBox.is_zoom_box_active.value = true; const expected = computeZoomToBoxCamera(getCameraOptions(camera), HALF_BOX, VIEWPORT, TARGET); @@ -95,6 +95,7 @@ describe("zoomToBox", () => { // Box center (150, 20) from the top-left corner is (150, 80) in VTK display coordinates. expect(pick).toHaveBeenCalledExactlyOnceWith( + "scene_1", HALF_BOX_CENTER_X, VIEWPORT.height - HALF_BOX_CENTER_Y, ); From ed27d7a516f2f9a96d8ed05557025610c7351ae1 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:30:42 +0100 Subject: [PATCH 020/121] feat(hybrid_viewer): scope filters and brightness by scene The filter requests (clipping planes, shrink, explode, slice, threshold) carry the calling scene and render it. The brightness sampling reads the render window of its own scene. Co-Authored-By: Claude Opus 5.5 --- internal/stores/hybrid_viewer/brightness.ts | 9 +- internal/stores/hybrid_viewer/filters.ts | 155 +++++++++++--------- 2 files changed, 93 insertions(+), 71 deletions(-) diff --git a/internal/stores/hybrid_viewer/brightness.ts b/internal/stores/hybrid_viewer/brightness.ts index c84389cb3..908fa0b9f 100644 --- a/internal/stores/hybrid_viewer/brightness.ts +++ b/internal/stores/hybrid_viewer/brightness.ts @@ -1,4 +1,5 @@ import { RGB_MAX } from "./constants"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { getDefaultSceneStyle } from "@ogw_front/utils/default_styles"; import { useHybridViewerCore } from "./core"; @@ -17,6 +18,7 @@ interface Rect { type DrawableImage = CanvasImageSource & { width: number; height: number }; interface BrightnessOptions { + sceneId: SceneId; latestImage: DrawableImage | undefined; offscreenCtx: CanvasRenderingContext2D | undefined; offscreenCanvas: HTMLCanvasElement | undefined; @@ -86,8 +88,8 @@ function defaultBackgroundRange(): BrightnessRange { } function computeBrightnessRange(rect: Rect, options: BrightnessOptions): BrightnessRange { - const { latestImage, offscreenCtx, offscreenCanvas } = options; - const { genericRenderWindow } = useHybridViewerCore(); + const { sceneId, latestImage, offscreenCtx, offscreenCanvas } = options; + const { genericRenderWindow } = useHybridViewerCore(sceneId); if (!latestImage || !offscreenCtx || !offscreenCanvas || !genericRenderWindow.value) { return defaultBackgroundRange(); } @@ -123,7 +125,7 @@ function createOffscreenCanvas(): HTMLCanvasElement | undefined { return document.createElement("canvas"); } -function useHybridViewerBrightness(): { +function useHybridViewerBrightness(sceneId: SceneId): { latestImage: Ref; getBrightnessRange: (rect: Rect) => BrightnessRange; } { @@ -136,6 +138,7 @@ function useHybridViewerBrightness(): { : undefined; function getBrightnessRange(rect: Rect): BrightnessRange { return computeBrightnessRange(rect, { + sceneId, latestImage: latestImage.value, offscreenCtx, offscreenCanvas, diff --git a/internal/stores/hybrid_viewer/filters.ts b/internal/stores/hybrid_viewer/filters.ts index 66adee6a3..997d27344 100644 --- a/internal/stores/hybrid_viewer/filters.ts +++ b/internal/stores/hybrid_viewer/filters.ts @@ -6,17 +6,36 @@ import viewer_schemas, { } from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; import type { AttributeName } from "@geode/opengeodeweb-viewer/schema_types"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { SliceAxis } from "@ogw_front/utils/slice"; import { useHybridViewerCamera } from "./camera"; import { useHybridViewerScene } from "./scene"; import { useViewerStore } from "@ogw_front/stores/viewer"; +interface ThresholdAttribute { + name: string; + location: "point" | "cell"; + item: number; + minimum: number; + maximum: number; +} +interface Threshold { + id: number; + sourceIndex: number | undefined; + attributeName: AttributeName | undefined; + item: number; + minimum: number | undefined; + maximum: number | undefined; + thresholdAttribute: ThresholdAttribute | undefined; +} + async function requestAndRender( + sceneId: SceneId, schema: Schema, params: ParamsOf, ): Promise> { const viewerStore = useViewerStore(); - const { remoteRender } = useHybridViewerCore(); + const { remoteRender } = useHybridViewerCore(sceneId); const response = await viewerStore.request({ schema, params, @@ -25,25 +44,13 @@ async function requestAndRender( return response; } -async function setClippingPlanes( - ids: string[], - planes: ViewerClippingPlanesParams["planes"], -): Promise { - await requestAndRender(viewer_schemas.opengeodeweb_viewer.viewer.clipping_planes, { - ids, - planes, - }); -} -async function setShrink(ids: string[], shrink_factor: number): Promise { - await requestAndRender(viewer_schemas.opengeodeweb_viewer.viewer.shrink, { - ids, - shrink_factor, - }); -} // The simplified view shown while the camera moves follows the explosion, and so does the camera -function explodeLightViewables(explodedBounds: { id: DataId; bounds: number[] }[]): void { - const { genericRenderWindow } = useHybridViewerCore(); - const { hybridDb } = useHybridViewerScene(); +function explodeLightViewables( + sceneId: SceneId, + explodedBounds: { id: DataId; bounds: number[] }[], +): void { + const { genericRenderWindow } = useHybridViewerCore(sceneId); + const { hybridDb } = useHybridViewerScene(sceneId); const renderer = requireRenderWindow(genericRenderWindow).getRenderer(); const boundsBefore = renderer.computeVisiblePropBounds(); for (const { id, bounds } of explodedBounds) { @@ -59,55 +66,16 @@ function explodeLightViewables(explodedBounds: { id: DataId; bounds: number[] }[ followCenter(camera, boundsBefore, renderer.computeVisiblePropBounds()); renderer.resetCameraClippingRange(); } -async function setExplode(ids: string[], explode_factor: number): Promise { - const viewerStore = useViewerStore(); - const { exploded_bounds } = await viewerStore.request({ - schema: viewer_schemas.opengeodeweb_viewer.viewer.explode, - params: { ids, explode_factor }, - }); - explodeLightViewables(exploded_bounds); - await useHybridViewerCamera().syncRemoteCameraAsync(); -} -async function setSlice( - ids: string[], - slices: { axis: SliceAxis; index: number }[], -): Promise<[number, number, number]> { - const { - max_indices: [max_i = 0, max_j = 0, max_k = 0], - } = await requestAndRender(viewer_schemas.opengeodeweb_viewer.viewer.slice, { - ids, - slices, - }); - return [max_i, max_j, max_k]; -} -interface ThresholdAttribute { - name: string; - location: "point" | "cell"; - item: number; - minimum: number; - maximum: number; -} -interface Threshold { - id: number; - sourceIndex: number | undefined; - attributeName: AttributeName | undefined; - item: number; - minimum: number | undefined; - maximum: number | undefined; - thresholdAttribute: ThresholdAttribute | undefined; -} -async function setThreshold(ids: string[], attributes: ThresholdAttribute[]): Promise { - await requestAndRender(viewer_schemas.opengeodeweb_viewer.viewer.threshold, { - ids, - attributes, - }); -} -function useHybridViewerFilters(): { - setClippingPlanes: typeof setClippingPlanes; - setShrink: typeof setShrink; - setExplode: typeof setExplode; - setSlice: typeof setSlice; - setThreshold: typeof setThreshold; + +function useHybridViewerFilters(sceneId: SceneId): { + setClippingPlanes: (ids: string[], planes: ViewerClippingPlanesParams["planes"]) => Promise; + setShrink: (ids: string[], shrink_factor: number) => Promise; + setExplode: (ids: string[], explode_factor: number) => Promise; + setSlice: ( + ids: string[], + slices: { axis: SliceAxis; index: number }[], + ) => Promise<[number, number, number]>; + setThreshold: (ids: string[], attributes: ThresholdAttribute[]) => Promise; getThresholds: (dataId: DataId) => Threshold[]; addThreshold: (dataId: DataId) => void; removeThreshold: (dataId: DataId, index: number) => void; @@ -116,6 +84,57 @@ function useHybridViewerFilters(): { const thresholds = reactive>({}); let lastThresholdId = 0; + async function setClippingPlanes( + ids: string[], + planes: ViewerClippingPlanesParams["planes"], + ): Promise { + await requestAndRender(sceneId, viewer_schemas.opengeodeweb_viewer.viewer.clipping_planes, { + scene_id: sceneId, + ids, + planes, + }); + } + + async function setShrink(ids: string[], shrink_factor: number): Promise { + await requestAndRender(sceneId, viewer_schemas.opengeodeweb_viewer.viewer.shrink, { + scene_id: sceneId, + ids, + shrink_factor, + }); + } + + async function setExplode(ids: string[], explode_factor: number): Promise { + const viewerStore = useViewerStore(); + const { exploded_bounds } = await viewerStore.request({ + schema: viewer_schemas.opengeodeweb_viewer.viewer.explode, + params: { scene_id: sceneId, ids, explode_factor }, + }); + explodeLightViewables(sceneId, exploded_bounds); + await useHybridViewerCamera(sceneId).syncRemoteCameraAsync(); + } + + async function setSlice( + ids: string[], + slices: { axis: SliceAxis; index: number }[], + ): Promise<[number, number, number]> { + const { + max_indices: [max_i = 0, max_j = 0, max_k = 0], + } = await requestAndRender(sceneId, viewer_schemas.opengeodeweb_viewer.viewer.slice, { + scene_id: sceneId, + ids, + slices, + }); + return [max_i, max_j, max_k]; + } + + async function setThreshold(ids: string[], attributes: ThresholdAttribute[]): Promise { + await requestAndRender(sceneId, viewer_schemas.opengeodeweb_viewer.viewer.threshold, { + scene_id: sceneId, + ids, + attributes, + }); + } + function getThresholds(dataId: DataId): Threshold[] { return thresholds[dataId] ?? []; } From c095f3993d71c3d1edce23180529466953483753 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:30:52 +0100 Subject: [PATCH 021/121] feat(hybrid_viewer): resize and render the scene's own view A scene's viewport resizes its own canvas and view stream, and renders its own view only. Test: resize targets its own view. Co-Authored-By: Claude Opus 5.5 --- internal/stores/hybrid_viewer/viewport.ts | 38 +++++++---- .../hybrid_viewer_viewport.nuxt.test.ts | 67 ++++++++++++++----- 2 files changed, 78 insertions(+), 27 deletions(-) diff --git a/internal/stores/hybrid_viewer/viewport.ts b/internal/stores/hybrid_viewer/viewport.ts index f39910ae8..cd55774e2 100644 --- a/internal/stores/hybrid_viewer/viewport.ts +++ b/internal/stores/hybrid_viewer/viewport.ts @@ -1,4 +1,5 @@ import { centerCameraOnPosition, useHybridViewerCamera } from "./camera"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { Status } from "@ogw_front/utils/status"; import type { ViewStreamLike } from "./vtk_types"; import { WHEEL_TIME_OUT_MS } from "./constants"; @@ -14,8 +15,9 @@ interface HybridViewerViewport { viewStream: Ref; } -async function resize(width: number, height: number): Promise { - const { genericRenderWindow, remoteRender, status, viewStream } = useHybridViewerCore(); +// Resizes the scene's own view only: its local canvas, its view stream and its remote render +async function resizeView(sceneId: SceneId, width: number, height: number): Promise { + const { genericRenderWindow, remoteRender, status, viewStream } = useHybridViewerCore(sceneId); const viewerStore = useViewerStore(); if (viewerStore.status !== Status.CONNECTED || status.value !== Status.CREATED) { return; @@ -46,14 +48,16 @@ async function resize(width: number, height: number): Promise { } async function performClickPicking( + sceneId: SceneId, event: MouseEvent, containerElement: HTMLElement, ): Promise { - const { genericRenderWindow } = useHybridViewerCore(); - const { syncRemoteCamera } = useHybridViewerCamera(); + const { genericRenderWindow } = useHybridViewerCore(sceneId); + const { syncRemoteCamera } = useHybridViewerCamera(sceneId); const viewerStore = useViewerStore(); const rect = containerElement.getBoundingClientRect(); const pickedPos = await viewerStore.pick_world_position( + sceneId, event.clientX - rect.left, rect.height - (event.clientY - rect.top), ); @@ -67,14 +71,14 @@ async function performClickPicking( syncRemoteCamera(); } -function setContainer(container: ContainerRef | undefined): void { +function attachContainer(sceneId: SceneId, container: ContainerRef | undefined): void { if (!container || !container.value) { return; } const containerElement = container.value.$el; - const { genericRenderWindow, is_picking, is_moving } = useHybridViewerCore(); - const { syncRemoteCamera } = useHybridViewerCamera(); - const { hoverHighlight } = useHybridViewerHighlight(); + const { genericRenderWindow, is_picking, is_moving } = useHybridViewerCore(sceneId); + const { syncRemoteCamera } = useHybridViewerCamera(sceneId); + const { hoverHighlight } = useHybridViewerHighlight(sceneId); if (!genericRenderWindow.value) { return; } @@ -92,7 +96,7 @@ function setContainer(container: ContainerRef | undefined): void { transition: "opacity 0.1s ease-in", zIndex: 1, }); - void resize(containerElement.offsetWidth, containerElement.offsetHeight); + void resizeView(sceneId, containerElement.offsetWidth, containerElement.offsetHeight); let has_dragged = false; useMousePressed({ target: containerElement, @@ -104,7 +108,7 @@ function setContainer(container: ContainerRef | undefined): void { return; } if (event.button === 0 && is_picking.value) { - void performClickPicking(event, containerElement); + void performClickPicking(sceneId, event, containerElement); is_picking.value = false; return; } @@ -155,8 +159,17 @@ function setContainer(container: ContainerRef | undefined): void { }, WHEEL_TIME_OUT_MS); }); } -function useHybridViewerViewport(): HybridViewerViewport { - const { viewStream } = useHybridViewerCore(); +function useHybridViewerViewport(sceneId: SceneId): HybridViewerViewport { + const { viewStream } = useHybridViewerCore(sceneId); + + function setContainer(container: ContainerRef | undefined): void { + attachContainer(sceneId, container); + } + + async function resize(width: number, height: number): Promise { + await resizeView(sceneId, width, height); + } + return { setContainer, resize, @@ -164,4 +177,5 @@ function useHybridViewerViewport(): HybridViewerViewport { }; } export { performClickPicking, useHybridViewerViewport }; +export type { HybridViewerViewport }; export type { ViewStreamLike } from "./vtk_types"; diff --git a/tests/unit/stores/hybrid_viewer_viewport.nuxt.test.ts b/tests/unit/stores/hybrid_viewer_viewport.nuxt.test.ts index 85a7bcd2e..ffd2eff2b 100644 --- a/tests/unit/stores/hybrid_viewer_viewport.nuxt.test.ts +++ b/tests/unit/stores/hybrid_viewer_viewport.nuxt.test.ts @@ -1,8 +1,11 @@ // Third party imports -import { describe, expect, test, vi } from "vitest"; +import { type Mock, afterEach, describe, expect, test, vi } from "vitest"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; // Local imports import { Status } from "@ogw_front/utils/status"; +import { disposeSceneScope } from "@ogw_internal/stores/scenes/scene_scope"; +import { mockViewer } from "@ogw_tests/unit/stores/scenes_helpers"; import { useHybridViewerCore } from "@ogw_internal/stores/hybrid_viewer/core"; import { useHybridViewerViewport } from "@ogw_internal/stores/hybrid_viewer/viewport"; import { useViewerStore } from "@ogw_front/stores/viewer"; @@ -12,25 +15,59 @@ const HEIGHT = 600.6; const ROUNDED_WIDTH = 800; const ROUNDED_HEIGHT = 601; +type SetSize = (width: number, height: number) => void; + +// A created scene viewer, with the view stream of its own view +function createdViewer(sceneId: string): Mock { + const core = useHybridViewerCore(sceneId); + core.status.value = Status.CREATED; + const renderWindow = { + getApiSpecificRenderWindow: (): unknown => ({ + getCanvas: (): HTMLCanvasElement => document.createElement("canvas"), + setSize: vi.fn(), + }), + getRenderWindow: (): { render: () => void } => ({ render: vi.fn<() => void>() }), + }; + // oxlint-disable-next-line typescript/no-unsafe-type-assertion + core.genericRenderWindow.value = renderWindow as never; + const setSize = vi.fn(); + core.viewStream.value = { + setSize, + onImageReady: vi.fn<() => void>(), + }; + return setSize; +} + describe("hybrid viewer resize", () => { + afterEach(() => { + disposeSceneScope("scene_1"); + disposeSceneScope("scene_2"); + }); + test("stores the rounded view size used as the default screenshot size", async () => { const viewerStore = useViewerStore(); viewerStore.status = Status.CONNECTED; - const core = useHybridViewerCore(); - core.status.value = Status.CREATED; - const renderWindow = { - getApiSpecificRenderWindow: (): unknown => ({ - getCanvas: (): HTMLCanvasElement => document.createElement("canvas"), - setSize: vi.fn<(width: number, height: number) => void>(), - }), - getRenderWindow: (): { render: () => void } => ({ render: vi.fn<() => void>() }), - }; - // oxlint-disable-next-line typescript/no-unsafe-type-assertion - core.genericRenderWindow.value = renderWindow as never; - vi.spyOn(core, "remoteRender").mockResolvedValue(); - - await useHybridViewerViewport().resize(WIDTH, HEIGHT); + mockViewer(); + createdViewer("scene_1"); + + await useHybridViewerViewport("scene_1").resize(WIDTH, HEIGHT); expect(viewerStore.view_size).toStrictEqual({ width: ROUNDED_WIDTH, height: ROUNDED_HEIGHT }); }); + + test("resize targets its own view", async () => { + useViewerStore().status = Status.CONNECTED; + const request = mockViewer(); + const firstSetSize = createdViewer("scene_1"); + const secondSetSize = createdViewer("scene_2"); + + await useHybridViewerViewport("scene_2").resize(WIDTH, HEIGHT); + + expect(secondSetSize).toHaveBeenCalledExactlyOnceWith(WIDTH, HEIGHT); + expect(firstSetSize).not.toHaveBeenCalled(); + // The only request renders the resized view + expect(request.mock.calls.map(([sent]) => sent)).toStrictEqual([ + { schema: viewer_schemas.opengeodeweb_viewer.viewer.render, params: { scene_id: "scene_2" } }, + ]); + }); }); From e79064e9060213c80e34bedcfb0203170993b832 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:31:11 +0100 Subject: [PATCH 022/121] feat(hybrid_viewer): one viewer store per scene useHybridViewerStore(sceneId) returns the store hybridViewer-, composed of the slices of that scene, with the same API. importStores restores the snapshot in its own scene. Co-Authored-By: Claude Opus 5.5 --- app/stores/hybrid_viewer.ts | 94 +++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 24 deletions(-) diff --git a/app/stores/hybrid_viewer.ts b/app/stores/hybrid_viewer.ts index 54a2658c0..4dbefa5d0 100644 --- a/app/stores/hybrid_viewer.ts +++ b/app/stores/hybrid_viewer.ts @@ -1,40 +1,76 @@ import { + type CameraSnapshot, + type HybridViewerCamera, + applySnapshot, + useHybridViewerCamera, +} from "@ogw_internal/stores/hybrid_viewer/camera"; +import { + type HybridViewerCore, + useHybridViewerCore, +} from "@ogw_internal/stores/hybrid_viewer/core"; +import { + type HybridViewerHighlight, + useHybridViewerHighlight, +} from "@ogw_internal/stores/hybrid_viewer/highlight"; +import { + type HybridViewerScene, + createLocalRenderWindow, + useHybridViewerScene, +} from "@ogw_internal/stores/hybrid_viewer/scene"; +import { + type HybridViewerViewport, type ViewStreamLike, useHybridViewerViewport, } from "@ogw_internal/stores/hybrid_viewer/viewport"; -import { applySnapshot, useHybridViewerCamera } from "@ogw_internal/stores/hybrid_viewer/camera"; import { - localBackgroundColor, - useHybridViewerScene, -} from "@ogw_internal/stores/hybrid_viewer/scene"; + type HybridViewerZoomBox, + useHybridViewerZoomBox, +} from "@ogw_internal/stores/hybrid_viewer/zoom_box"; import type { CameraOptions } from "@ogw_internal/stores/hybrid_viewer/vtk_types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { getCameraOptions } from "@ogw_internal/stores/hybrid_viewer/camera_animation"; import { useHybridViewerBrightness } from "@ogw_internal/stores/hybrid_viewer/brightness"; -import { useHybridViewerCore } from "@ogw_internal/stores/hybrid_viewer/core"; import { useHybridViewerFilters } from "@ogw_internal/stores/hybrid_viewer/filters"; -import { useHybridViewerHighlight } from "@ogw_internal/stores/hybrid_viewer/highlight"; import { useHybridViewerRuler } from "@ogw_internal/stores/hybrid_viewer/ruler"; -import { useHybridViewerZoomBox } from "@ogw_internal/stores/hybrid_viewer/zoom_box"; -import { newInstance as vtkGenericRenderWindow } from "@kitware/vtk.js/Rendering/Misc/GenericRenderWindow"; import { Status } from "@ogw_front/utils/status"; import { useViewerStore } from "@ogw_front/stores/viewer"; +interface HybridViewerStoreActions { + initHybridViewer: () => Promise; + exportStores: () => { + zScale: number; + camera_options: CameraOptions | Record; + }; + importStores: (snapshot: CameraSnapshot | undefined) => Promise; +} + +type HybridViewerStoreSetup = HybridViewerStoreActions & + Omit & + ReturnType & + HybridViewerScene & + HybridViewerViewport & + ReturnType & + HybridViewerHighlight & + ReturnType & + HybridViewerCamera & + HybridViewerZoomBox; + // oxlint-disable max-lines-per-function, max-statements -export const useHybridViewerStore = defineStore("hybridViewer", () => { +function setupHybridViewerStore(sceneId: SceneId): HybridViewerStoreSetup { const viewerStore = useViewerStore(); const { genericRenderWindow, status, is_moving, is_picking, remoteRender } = - useHybridViewerCore(); + useHybridViewerCore(sceneId); let imageStyle: CSSStyleDeclaration | undefined = undefined; - const brightnessStore = useHybridViewerBrightness(); - const sceneStore = useHybridViewerScene(); - const filtersStore = useHybridViewerFilters(); - const highlightStore = useHybridViewerHighlight(); - const rulerStore = useHybridViewerRuler(); - const cameraStore = useHybridViewerCamera(); - const viewportStore = useHybridViewerViewport(); - const zoomBoxStore = useHybridViewerZoomBox(); + const brightnessStore = useHybridViewerBrightness(sceneId); + const sceneStore = useHybridViewerScene(sceneId); + const filtersStore = useHybridViewerFilters(sceneId); + const highlightStore = useHybridViewerHighlight(sceneId); + const rulerStore = useHybridViewerRuler(sceneId); + const cameraStore = useHybridViewerCamera(sceneId); + const viewportStore = useHybridViewerViewport(sceneId); + const zoomBoxStore = useHybridViewerZoomBox(sceneId); const is_cursor_crosshair = computed(() => is_picking.value || rulerStore.is_ruler_active.value); @@ -59,10 +95,7 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => { return; } status.value = Status.CREATING; - genericRenderWindow.value = vtkGenericRenderWindow({ - background: localBackgroundColor(), - listenWindowResize: false, - }); + genericRenderWindow.value = createLocalRenderWindow(); const webGLRenderWindow = // oxlint-disable-next-line no-unsafe-type-assertion -- trusted vtk.js OpenGL render window API boundary. genericRenderWindow.value.getApiSpecificRenderWindow() as unknown as { @@ -117,6 +150,10 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => { }; } + async function importStores(snapshot: CameraSnapshot | undefined): Promise { + await applySnapshot(sceneId, snapshot); + } + return { genericRenderWindow, status, @@ -125,7 +162,7 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => { initHybridViewer, remoteRender, exportStores, - importStores: applySnapshot, + importStores, ...brightnessStore, ...sceneStore, ...viewportStore, @@ -135,4 +172,13 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => { ...cameraStore, ...zoomBoxStore, }; -}); +} + +// Each scene has its own viewer: its own render window, view and camera +function useHybridViewerStore( + sceneId: SceneId, +): ReturnType>> { + return defineStore(`hybridViewer-${sceneId}`, () => setupHybridViewerStore(sceneId))(); +} + +export { useHybridViewerStore }; From 205855ca6fc3181863f5d7603744dbd35019e70b Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:31:18 +0100 Subject: [PATCH 023/121] feat(hybrid_viewer): stream each scene's own view initHybridViewer opens the view stream of the scene's view_id instead of "-1": the views share one image topic and each stream only takes the images of its own view. A duplicated scene then shows the content, the z-scaling and the camera copied from its source. The hybrid viewer loads the scenes store when it needs it (load_store.ts), as the scenes store creates the hybrid viewers. Co-Authored-By: Claude Opus 5.5 --- app/stores/hybrid_viewer.ts | 8 +++- internal/stores/hybrid_viewer/restore.ts | 53 ++++++++++++++++++++++++ internal/stores/scenes/load_store.ts | 12 ++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 internal/stores/hybrid_viewer/restore.ts create mode 100644 internal/stores/scenes/load_store.ts diff --git a/app/stores/hybrid_viewer.ts b/app/stores/hybrid_viewer.ts index 4dbefa5d0..86a569be3 100644 --- a/app/stores/hybrid_viewer.ts +++ b/app/stores/hybrid_viewer.ts @@ -26,6 +26,7 @@ import { type HybridViewerZoomBox, useHybridViewerZoomBox, } from "@ogw_internal/stores/hybrid_viewer/zoom_box"; +import { copiedCamera, restoreScene, shownScene } from "@ogw_internal/stores/hybrid_viewer/restore"; import type { CameraOptions } from "@ogw_internal/stores/hybrid_viewer/vtk_types"; import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { getCameraOptions } from "@ogw_internal/stores/hybrid_viewer/camera_animation"; @@ -95,6 +96,8 @@ function setupHybridViewerStore(sceneId: SceneId): HybridViewerStoreSetup { return; } status.value = Status.CREATING; + // The local camera overwrites the camera options, which a duplicated scene holds before it is shown + const camera_copy = copiedCamera(sceneId); genericRenderWindow.value = createLocalRenderWindow(); const webGLRenderWindow = // oxlint-disable-next-line no-unsafe-type-assertion -- trusted vtk.js OpenGL render window API boundary. @@ -108,6 +111,7 @@ function setupHybridViewerStore(sceneId: SceneId): HybridViewerStoreSetup { zIndex: 1, }); await viewerStore.ws_connect(); + const { view_id, content } = await shownScene(sceneId); // oxlint-disable-next-line no-unsafe-type-assertion -- trusted @kitware/vtk.js WebSocket client API boundary. const clientApi = viewerStore.client as unknown as { getImageStream: () => { @@ -115,7 +119,8 @@ function setupHybridViewerStore(sceneId: SceneId): HybridViewerStoreSetup { }; }; const imageStream = clientApi.getImageStream(); - viewportStore.viewStream.value = imageStream.createViewStream("-1"); + // All the views share one image topic: the view stream only takes the images of the scene's own view + viewportStore.viewStream.value = imageStream.createViewStream(view_id); viewportStore.viewStream.value?.onImageReady((event: { image: unknown }) => { if (is_moving.value) { return; @@ -135,6 +140,7 @@ function setupHybridViewerStore(sceneId: SceneId): HybridViewerStoreSetup { camera.onModified(() => { Object.assign(cameraStore.camera_options, getCameraOptions(camera)); }); + await restoreScene(sceneId, content, camera_copy); status.value = Status.CREATED; } diff --git a/internal/stores/hybrid_viewer/restore.ts b/internal/stores/hybrid_viewer/restore.ts new file mode 100644 index 000000000..1c61fb010 --- /dev/null +++ b/internal/stores/hybrid_viewer/restore.ts @@ -0,0 +1,53 @@ +import { isCameraOptions, useHybridViewerCamera } from "./camera"; +import type { CameraOptions } from "./vtk_types"; +import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; +import { loadScenesStore } from "@ogw_internal/stores/scenes/load_store"; +import { toRaw } from "vue"; +import { useHybridViewerScene } from "./scene"; + +interface ShownScene { + view_id: string; + content: DataId[]; +} + +// The view of the scene in the viewer, and the data the scene shows +async function shownScene(sceneId: SceneId): Promise { + const scenesStore = await loadScenesStore(); + const scene = scenesStore.scenes.find((record) => record.id === sceneId); + if (!scene) { + throw new Error(`Unknown scene: ${sceneId}`); + } + return { view_id: scene.view_id, content: scenesStore.contents[sceneId] ?? [] }; +} + +// A duplicated scene holds the camera of its source scene before its viewer has a camera +function copiedCamera(sceneId: SceneId): CameraOptions | undefined { + const { camera_options } = useHybridViewerCamera(sceneId); + if (!isCameraOptions(camera_options)) { + return undefined; + } + return structuredClone(toRaw(camera_options)); +} + +// A duplicated scene shows the content, the z-scaling and the camera copied from its source scene +async function restoreScene( + sceneId: SceneId, + content: readonly DataId[], + camera: CameraOptions | undefined, +): Promise { + const { addItem, setZScaling, zScale } = useHybridViewerScene(sceneId); + await Promise.all( + content.map(async (dataId) => { + await addItem(dataId); + }), + ); + if (zScale.value !== 1) { + await setZScaling(zScale.value); + } + if (camera) { + await useHybridViewerCamera(sceneId).setCameraOptions(camera); + } +} + +export { copiedCamera, restoreScene, shownScene }; diff --git a/internal/stores/scenes/load_store.ts b/internal/stores/scenes/load_store.ts new file mode 100644 index 000000000..9c884e197 --- /dev/null +++ b/internal/stores/scenes/load_store.ts @@ -0,0 +1,12 @@ +import type { useScenesStore } from "@ogw_front/stores/scenes"; + +type ScenesStore = ReturnType; + +// The scenes store creates the stores of each scene and talks to the viewer: the stores it creates, and the viewer +// Store, load it when they need it rather than import it, which would make them import each other +async function loadScenesStore(): Promise { + const scenes = await import("@ogw_front/stores/scenes"); + return scenes.useScenesStore(); +} + +export { loadScenesStore }; From 054d0669113de971f21b18ee832c3d936174f71b Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:31:42 +0100 Subject: [PATCH 024/121] feat(scenes): link cameras between scenes setCameraOptions and setZScaling propagate by default: once applied to their scene, scenesStore.propagateCamera(sceneId) gives the z-scaling and the camera to each scene linked on camera, with propagate = false so that nothing comes back. The end of an interaction, resetCamera, the camera orientation and camera_manager presets (now applied to a given scene) go through them. Tests: propagateCamera does not re-propagate, propagateCamera ignores unlinked scenes. Co-Authored-By: Claude Opus 5.5 --- app/stores/camera_manager.ts | 12 +-- app/stores/scenes.ts | 23 ++++- internal/stores/hybrid_viewer/camera.ts | 14 ++- internal/stores/hybrid_viewer/restore.ts | 4 +- internal/stores/hybrid_viewer/scene.ts | 10 +- .../stores/hybrid_viewer_camera.nuxt.test.ts | 97 ++++++++++++++++++- 6 files changed, 141 insertions(+), 19 deletions(-) diff --git a/app/stores/camera_manager.ts b/app/stores/camera_manager.ts index f0dd30794..66c0396bd 100644 --- a/app/stores/camera_manager.ts +++ b/app/stores/camera_manager.ts @@ -1,14 +1,13 @@ // Local imports import type { CameraOptions } from "@ogw_internal/stores/hybrid_viewer/vtk_types.js"; import type { CameraPositionRecord } from "@ogw_internal/database/tables/camera_positions"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { cameraPositionsDb } from "@ogw_internal/database/database.js"; import { liveObservable } from "@ogw_front/utils/live_observable"; +import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; import { useObservable } from "@vueuse/rxjs"; -import { useViewerStore } from "@ogw_front/stores/viewer"; -import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; // oxlint-disable-next-line max-lines-per-function export const useCameraManagerStore = defineStore("cameraManager", () => { - const viewerStore = useViewerStore(); // Keyed by an auto-incremented number const cameraPositionsTable = cameraPositionsDb(); @@ -34,12 +33,11 @@ export const useCameraManagerStore = defineStore("cameraManager", () => { }); } - async function restoreCameraPosition(id: number): Promise { + // The position applies to the given scene, and to the scenes linked to its camera + async function restoreCameraPosition(sceneId: SceneId, id: number): Promise { const position = await cameraPositionsTable.get(id); if (position) { - const schema = viewer_schemas.opengeodeweb_viewer.viewer.update_camera; - const params = { camera_options: position.camera_options }; - await viewerStore.request({ schema, params }); + await useHybridViewerStore(sceneId).setCameraOptions(position.camera_options); } } diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index cbcd821ec..8c4949d35 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -1,7 +1,7 @@ // Third party imports +import { ref, toRaw } from "vue"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; import { defineStore } from "pinia"; -import { ref } from "vue"; import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; // Local imports @@ -21,6 +21,8 @@ import { removeFromSceneStores, } from "@ogw_internal/stores/scenes/scene_stores"; import { joinLink, leaveLinks, linkedScenes } from "@ogw_internal/stores/scenes/links"; +import { isCameraOptions } from "@ogw_internal/stores/hybrid_viewer/camera"; +import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; import { useViewerStore } from "@ogw_front/stores/viewer"; const viewerSchemas = viewer_schemas.opengeodeweb_viewer.viewer; @@ -156,6 +158,24 @@ export const useScenesStore = defineStore("scenes", () => { links.value = leaveLinks(links.value, sceneId); } + // The scenes linked on camera take the z-scaling and the camera of the scene, without propagating them back + async function propagateCamera(sceneId: SceneId): Promise { + const source = useHybridViewerStore(sceneId); + if (!isCameraOptions(source.camera_options)) { + return; + } + const options = structuredClone(toRaw(source.camera_options)); + await Promise.all( + linkedScenes(links.value, sceneId, "camera").map(async (targetId) => { + const target = useHybridViewerStore(targetId); + if (target.zScale !== source.zScale) { + await target.setZScaling(source.zScale, false); + } + await target.setCameraOptions(options, false); + }), + ); + } + function setLastUsed(sceneId: SceneId): void { lastUsedSceneId.value = sceneId; } @@ -197,6 +217,7 @@ export const useScenesStore = defineStore("scenes", () => { addData, removeData, unlink, + propagateCamera, setLastUsed, exportStores, importStores, diff --git a/internal/stores/hybrid_viewer/camera.ts b/internal/stores/hybrid_viewer/camera.ts index f04a49691..e5690934b 100644 --- a/internal/stores/hybrid_viewer/camera.ts +++ b/internal/stores/hybrid_viewer/camera.ts @@ -5,6 +5,7 @@ import type { CameraOptions } from "./vtk_types"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { animateCameraOrientation } from "./camera_orientation"; +import { loadScenesStore } from "@ogw_internal/stores/scenes/load_store"; import { runInSceneScope } from "@ogw_internal/stores/scenes/scene_scope"; import { useHybridViewerScene } from "./scene"; import { useViewerStore } from "@ogw_front/stores/viewer"; @@ -12,7 +13,7 @@ import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed interface HybridViewerCamera { camera_options: Record; - setCameraOptions: (options: CameraOptions) => Promise; + setCameraOptions: (options: CameraOptions, propagate?: boolean) => Promise; syncRemoteCamera: () => void; syncRemoteCameraAsync: () => Promise; setCamera: (targetCameraOptions: CameraOptions) => void; @@ -33,8 +34,8 @@ function isCameraOptions( function createHybridViewerCamera(sceneId: SceneId): HybridViewerCamera { const camera_options = reactive>({}); - // Moves the local and the viewer cameras - async function setCameraOptions(options: CameraOptions): Promise { + // Moves the local and the viewer cameras, then the cameras of the linked scenes, which do not propagate back + async function setCameraOptions(options: CameraOptions, propagate = true): Promise { const { genericRenderWindow, remoteRender } = useHybridViewerCore(sceneId); let sentOptions = options; if (genericRenderWindow.value) { @@ -51,6 +52,10 @@ function createHybridViewerCamera(sceneId: SceneId): HybridViewerCamera { }); await remoteRender(); Object.assign(camera_options, sentOptions); + if (propagate) { + const scenesStore = await loadScenesStore(); + await scenesStore.propagateCamera(sceneId); + } } async function syncRemoteCameraAsync(): Promise { @@ -161,6 +166,7 @@ interface CameraSnapshot { camera_options?: CameraOptions; } +// Each scene restores its own z-scaling: the linked scenes have theirs in the snapshot async function applySnapshot( sceneId: SceneId, snapshot: CameraSnapshot | undefined, @@ -169,7 +175,7 @@ async function applySnapshot( return; } if (typeof snapshot.zScale === "number") { - await useHybridViewerScene(sceneId).setZScaling(snapshot.zScale); + await useHybridViewerScene(sceneId).setZScaling(snapshot.zScale, false); } if (snapshot.camera_options) { useHybridViewerCamera(sceneId).setCamera(snapshot.camera_options); diff --git a/internal/stores/hybrid_viewer/restore.ts b/internal/stores/hybrid_viewer/restore.ts index 1c61fb010..e273b9e7a 100644 --- a/internal/stores/hybrid_viewer/restore.ts +++ b/internal/stores/hybrid_viewer/restore.ts @@ -43,10 +43,10 @@ async function restoreScene( }), ); if (zScale.value !== 1) { - await setZScaling(zScale.value); + await setZScaling(zScale.value, false); } if (camera) { - await useHybridViewerCamera(sceneId).setCameraOptions(camera); + await useHybridViewerCamera(sceneId).setCameraOptions(camera, false); } } diff --git a/internal/stores/hybrid_viewer/scene.ts b/internal/stores/hybrid_viewer/scene.ts index 5d720e8ce..bfce85b1b 100644 --- a/internal/stores/hybrid_viewer/scene.ts +++ b/internal/stores/hybrid_viewer/scene.ts @@ -15,6 +15,7 @@ import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { Visibility } from "@geode/opengeodeweb-viewer/schema_types"; import { getCameraOptions } from "./camera_animation"; import { getDefaultSceneStyle } from "@ogw_front/utils/default_styles"; +import { loadScenesStore } from "@ogw_internal/stores/scenes/load_store"; import { runInSceneScope } from "@ogw_internal/stores/scenes/scene_scope"; import { useViewerStore } from "@ogw_front/stores/viewer"; import { newInstance as vtkGenericRenderWindow } from "@kitware/vtk.js/Rendering/Misc/GenericRenderWindow"; @@ -70,7 +71,7 @@ interface HybridViewerScene { addItem: (dataId: DataId) => Promise; removeItem: (dataId: DataId) => void; setVisibility: (dataId: DataId, visibility: Visibility) => void; - setZScaling: (z_scale: number) => Promise; + setZScaling: (z_scale: number, propagate?: boolean) => Promise; setBackgroundColor: (color: ViewerSetBackgroundColorParams["color"]) => Promise; clear: () => void; } @@ -125,7 +126,8 @@ function createHybridViewerScene(sceneId: SceneId): HybridViewerScene { renderWindow.render(); } - async function setZScaling(z_scale: number): Promise { + // Stretches the local and the viewer scenes, then the linked scenes, which do not propagate back + async function setZScaling(z_scale: number, propagate = true): Promise { const { genericRenderWindow, remoteRender } = useHybridViewerCore(sceneId); const ratio = z_scale / zScale.value; zScale.value = z_scale; @@ -156,6 +158,10 @@ function createHybridViewerScene(sceneId: SceneId): HybridViewerScene { }, }); await remoteRender(); + if (propagate) { + const scenesStore = await loadScenesStore(); + await scenesStore.propagateCamera(sceneId); + } } async function setBackgroundColor(color: ViewerSetBackgroundColorParams["color"]): Promise { diff --git a/tests/unit/stores/hybrid_viewer_camera.nuxt.test.ts b/tests/unit/stores/hybrid_viewer_camera.nuxt.test.ts index e7490fbf3..a23439c11 100644 --- a/tests/unit/stores/hybrid_viewer_camera.nuxt.test.ts +++ b/tests/unit/stores/hybrid_viewer_camera.nuxt.test.ts @@ -1,8 +1,17 @@ -import { describe, expect, test } from "vitest"; +// Third party imports +import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; +import { newInstance as vtkCamera } from "@kitware/vtk.js/Rendering/Core/Camera"; -import type { Vector3 } from "@ogw_internal/stores/hybrid_viewer/vtk_types"; +// Local imports +import type { CameraOptions, Vector3 } from "@ogw_internal/stores/hybrid_viewer/vtk_types"; +import { mockViewer, sentTo } from "@ogw_tests/unit/stores/scenes_helpers"; import { centerCameraOnPosition } from "@ogw_internal/stores/hybrid_viewer/camera"; -import { newInstance as vtkCamera } from "@kitware/vtk.js/Rendering/Core/Camera"; +import { disposeSceneScope } from "@ogw_internal/stores/scenes/scene_scope"; +import { setupActivePinia } from "@ogw_tests/utils"; +import { useHybridViewerCore } from "@ogw_internal/stores/hybrid_viewer/core"; +import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; +import { useScenesStore } from "@ogw_front/stores/scenes"; const INITIAL_CAMERA_Z = 100; const PICKED_X = 20; @@ -35,3 +44,85 @@ describe("centerCameraOnPosition helper", () => { expect(camera.getFocalPoint()).toStrictEqual([0, 0, 0]); }); }); + +const LINKED_POSITION: Vector3 = [PICKED_X, PICKED_Y, PICKED_Z]; +const VIEW_ANGLE = 30; +const FAR_CLIPPING = 200; +const CAMERA_OPTIONS: CameraOptions = { + focal_point: [0, 0, 0], + view_up: [0, 1, 0], + position: LINKED_POSITION, + view_angle: VIEW_ANGLE, + clipping_range: [1, FAR_CLIPPING], + distance: INITIAL_CAMERA_Z, +}; + +// A scene viewer drawing with a real vtk.js camera +function createdViewer(sceneId: string): ReturnType { + const camera = vtkCamera(); + const renderer = { + getActiveCamera: (): typeof camera => camera, + getActors: (): never[] => [], + resetCameraClippingRange: vi.fn<() => void>(), + }; + const renderWindow = { + getRenderer: (): typeof renderer => renderer, + getRenderWindow: (): { render: () => void } => ({ render: vi.fn<() => void>() }), + }; + // oxlint-disable-next-line typescript/no-unsafe-type-assertion + useHybridViewerCore(sceneId).genericRenderWindow.value = renderWindow as never; + return camera; +} + +// Scene 1 and scene 2 are linked, scene 3 is not +function linkScenes(): void { + const scenes = ["scene_1", "scene_2", "scene_3"]; + useScenesStore().importStores({ + scenes: scenes.map((id) => ({ id, name: id, view_id: `view_${id}` })), + contents: Object.fromEntries(scenes.map((id) => [id, []])), + links: [{ id: "link_scene_2", sceneIds: ["scene_1", "scene_2"], channels: ["camera"] }], + lastUsedSceneId: "scene_1", + counter: scenes.length, + }); +} + +describe("camera link", () => { + beforeEach(() => { + setupActivePinia(); + linkScenes(); + }); + + afterEach(() => { + for (const sceneId of ["scene_1", "scene_2", "scene_3"]) { + disposeSceneScope(sceneId); + } + }); + + test("propagateCamera does not re-propagate", async () => { + const request = mockViewer(); + createdViewer("scene_1"); + const linkedCamera = createdViewer("scene_2"); + + await useHybridViewerStore("scene_1").setCameraOptions(CAMERA_OPTIONS); + + expect(sentTo(request, viewer_schemas.opengeodeweb_viewer.viewer.update_camera)).toStrictEqual([ + "scene_1", + "scene_2", + ]); + expect(linkedCamera.getPosition()).toStrictEqual(LINKED_POSITION); + }); + + test("propagateCamera ignores unlinked scenes", async () => { + const request = mockViewer(); + createdViewer("scene_1"); + createdViewer("scene_2"); + const unlinkedCamera = createdViewer("scene_3"); + + await useHybridViewerStore("scene_3").setCameraOptions(CAMERA_OPTIONS); + + expect(sentTo(request, viewer_schemas.opengeodeweb_viewer.viewer.update_camera)).toStrictEqual([ + "scene_3", + ]); + expect(unlinkedCamera.getPosition()).toStrictEqual(LINKED_POSITION); + }); +}); From 4a50912406f634e290a6fee17948d77e262b78be Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:31:56 +0100 Subject: [PATCH 025/121] feat(data_style): use the scene's hybrid viewer The scene, mesh, image and model visibility styles of a scene act on the hybrid viewer of that same scene, captured at store creation. Co-Authored-By: Claude Opus 5.5 --- internal/stores/data_style/image/index.ts | 2 +- internal/stores/data_style/mesh/base_style.ts | 2 +- internal/stores/data_style/model/visibility.ts | 2 +- internal/stores/data_style/scene.ts | 2 +- tests/unit/stores/data_style_image.nuxt.test.ts | 2 +- tests/unit/stores/image_style_helpers.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/stores/data_style/image/index.ts b/internal/stores/data_style/image/index.ts index 5e291b6bf..26047b35d 100644 --- a/internal/stores/data_style/image/index.ts +++ b/internal/stores/data_style/image/index.ts @@ -24,7 +24,7 @@ interface ImageStyleStore { // An image shows its own colors: only its visibility and its opacity are styled // oxlint-disable-next-line max-lines-per-function export function useImageStyle(sceneId: SceneId): ImageStyleStore { - const hybridViewerStore = useHybridViewerStore(); + const hybridViewerStore = useHybridViewerStore(sceneId); const viewerStore = useViewerStore(); const dataStyleState = useDataStyleState(sceneId); diff --git a/internal/stores/data_style/mesh/base_style.ts b/internal/stores/data_style/mesh/base_style.ts index 1db2497ee..69cda0cff 100644 --- a/internal/stores/data_style/mesh/base_style.ts +++ b/internal/stores/data_style/mesh/base_style.ts @@ -21,7 +21,7 @@ interface MeshBaseStyle { } export function useMeshBaseStyle(sceneId: SceneId): MeshBaseStyle { - const hybridViewerStore = useHybridViewerStore(); + const hybridViewerStore = useHybridViewerStore(sceneId); const viewerStore = useViewerStore(); const dataStyleState = useDataStyleState(sceneId); diff --git a/internal/stores/data_style/model/visibility.ts b/internal/stores/data_style/model/visibility.ts index 196866c96..7d823d242 100644 --- a/internal/stores/data_style/model/visibility.ts +++ b/internal/stores/data_style/model/visibility.ts @@ -36,7 +36,7 @@ function useModelVisibilityStyle( ): UseModelVisibilityStyleReturn { const dataStore = useDataStore(); const dataStyleState = useDataStyleState(sceneId); - const hybridViewerStore = useHybridViewerStore(); + const hybridViewerStore = useHybridViewerStore(sceneId); const viewerStore = useViewerStore(); const modelCommonStyle = useModelCommonStyle(sceneId); function modelVisibility(modelId: ModelId): Visibility | undefined { diff --git a/internal/stores/data_style/scene.ts b/internal/stores/data_style/scene.ts index 5d0a940e1..261ef5080 100644 --- a/internal/stores/data_style/scene.ts +++ b/internal/stores/data_style/scene.ts @@ -31,7 +31,7 @@ export function useSceneStyle(sceneId: SceneId): { importSceneStyle: (snapshot: SceneStyle | undefined) => Promise; } { const viewerStore = useViewerStore(); - const hybridViewerStore = useHybridViewerStore(); + const hybridViewerStore = useHybridViewerStore(sceneId); const { sceneStyle } = useDataStyleState(sceneId); const sceneStyleTable = sceneStyleDb(); diff --git a/tests/unit/stores/data_style_image.nuxt.test.ts b/tests/unit/stores/data_style_image.nuxt.test.ts index 54ea1a0a4..db69bf864 100644 --- a/tests/unit/stores/data_style_image.nuxt.test.ts +++ b/tests/unit/stores/data_style_image.nuxt.test.ts @@ -71,7 +71,7 @@ describe("data style store with images", () => { const request = mockViewer(); mockHybridVisibility(); mockImageItem(imageId, type); - const hybridViewerStore = useHybridViewerStore(); + const hybridViewerStore = useHybridViewerStore("scene_1"); hybridViewerStore.setBackgroundColor = mockAs( vi.fn<() => Promise>().mockResolvedValue(), ); diff --git a/tests/unit/stores/image_style_helpers.ts b/tests/unit/stores/image_style_helpers.ts index 3e316b59f..f976938cb 100644 --- a/tests/unit/stores/image_style_helpers.ts +++ b/tests/unit/stores/image_style_helpers.ts @@ -37,7 +37,7 @@ function sentRequests(request: Mock): SentRequest[] { } function mockHybridVisibility(): Mock<(dataId: string, visibility: boolean) => void> { - const hybridViewerStore = useHybridViewerStore(); + const hybridViewerStore = useHybridViewerStore("scene_1"); const setVisibility = vi.fn<(dataId: string, visibility: boolean) => void>(); hybridViewerStore.setVisibility = mockAs(setVisibility); return setVisibility; From 747c1558b36c74b890bc240ea8b6daee97b0c5ac Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:32:14 +0100 Subject: [PATCH 026/121] feat(scenes): render every scene showing a filtered data The viewer renders a filter (clipping planes, shrink, explode, slice, threshold) in the calling scene only, while the filter applies to the data: every other scene showing that data, read from scenesStore.contents, is rendered too. Test: renders every scene showing the filtered data. Co-Authored-By: Claude Opus 5.5 --- internal/stores/hybrid_viewer/filters.ts | 20 ++++++++- .../stores/hybrid_viewer_filters.nuxt.test.ts | 43 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/unit/stores/hybrid_viewer_filters.nuxt.test.ts diff --git a/internal/stores/hybrid_viewer/filters.ts b/internal/stores/hybrid_viewer/filters.ts index 997d27344..24385216e 100644 --- a/internal/stores/hybrid_viewer/filters.ts +++ b/internal/stores/hybrid_viewer/filters.ts @@ -8,6 +8,7 @@ import type { AttributeName } from "@geode/opengeodeweb-viewer/schema_types"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { SliceAxis } from "@ogw_front/utils/slice"; +import { loadScenesStore } from "@ogw_internal/stores/scenes/load_store"; import { useHybridViewerCamera } from "./camera"; import { useHybridViewerScene } from "./scene"; import { useViewerStore } from "@ogw_front/stores/viewer"; @@ -29,10 +30,25 @@ interface Threshold { thresholdAttribute: ThresholdAttribute | undefined; } +// A filter changes the data, which the viewer renders in the calling scene only: the other scenes showing it are +// Rendered here +async function renderOtherScenesShowing(sceneId: SceneId, ids: readonly DataId[]): Promise { + const { contents } = await loadScenesStore(); + const showing = Object.keys(contents).filter( + (otherId) => + otherId !== sceneId && ids.some((dataId) => (contents[otherId] ?? []).includes(dataId)), + ); + await Promise.all( + showing.map(async (otherId) => { + await useHybridViewerCore(otherId).remoteRender(); + }), + ); +} + async function requestAndRender( sceneId: SceneId, schema: Schema, - params: ParamsOf, + params: ParamsOf & { ids: DataId[] }, ): Promise> { const viewerStore = useViewerStore(); const { remoteRender } = useHybridViewerCore(sceneId); @@ -41,6 +57,7 @@ async function requestAndRender( params, }); await remoteRender(); + await renderOtherScenesShowing(sceneId, params.ids); return response; } @@ -111,6 +128,7 @@ function useHybridViewerFilters(sceneId: SceneId): { }); explodeLightViewables(sceneId, exploded_bounds); await useHybridViewerCamera(sceneId).syncRemoteCameraAsync(); + await renderOtherScenesShowing(sceneId, ids); } async function setSlice( diff --git a/tests/unit/stores/hybrid_viewer_filters.nuxt.test.ts b/tests/unit/stores/hybrid_viewer_filters.nuxt.test.ts new file mode 100644 index 000000000..807fe7d38 --- /dev/null +++ b/tests/unit/stores/hybrid_viewer_filters.nuxt.test.ts @@ -0,0 +1,43 @@ +// Third party imports +import { afterEach, beforeEach, describe, expect, test } from "vitest"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; + +// Local imports +import { DATA_ID, mockViewer, sentTo } from "@ogw_tests/unit/stores/scenes_helpers"; +import { disposeSceneScope } from "@ogw_internal/stores/scenes/scene_scope"; +import { setupActivePinia } from "@ogw_tests/utils"; +import { useHybridViewerFilters } from "@ogw_internal/stores/hybrid_viewer/filters"; +import { useScenesStore } from "@ogw_front/stores/scenes"; + +const SCENES = ["scene_1", "scene_2", "scene_3"]; +const SHRINK_FACTOR = 0.5; + +describe("hybrid viewer filters", () => { + beforeEach(() => { + setupActivePinia(); + // Scene 1 and scene 2 show the data, scene 3 does not + useScenesStore().importStores({ + scenes: SCENES.map((id) => ({ id, name: id, view_id: `view_${id}` })), + contents: { scene_1: [DATA_ID], scene_2: [DATA_ID], scene_3: [] }, + links: [], + lastUsedSceneId: "scene_1", + counter: SCENES.length, + }); + }); + + afterEach(() => { + for (const sceneId of SCENES) { + disposeSceneScope(sceneId); + } + }); + + test("renders every scene showing the filtered data", async () => { + const request = mockViewer(); + + await useHybridViewerFilters("scene_1").setShrink([DATA_ID], SHRINK_FACTOR); + + const { viewer } = viewer_schemas.opengeodeweb_viewer; + expect(sentTo(request, viewer.shrink)).toStrictEqual(["scene_1"]); + expect(sentTo(request, viewer.render)).toStrictEqual(["scene_1", "scene_2"]); + }); +}); From b44ea8a8d57efd4af73f2c73ef62c2e1edf2e297 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:32:28 +0100 Subject: [PATCH 027/121] feat(viewer): create the first scene once connected A new viewer holds no scene and reset_visualization now needs one: once connected, ws_connect creates scene_1 when the project has no scene yet, before any hybrid viewer opens its view. Co-Authored-By: Claude Opus 5.5 --- app/stores/viewer.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/stores/viewer.ts b/app/stores/viewer.ts index ff4e352ae..e69599945 100644 --- a/app/stores/viewer.ts +++ b/app/stores/viewer.ts @@ -4,7 +4,6 @@ import "@kitware/vtk.js/Rendering/OpenGL/Profiles/Geometry"; import type { Vector3 } from "@kitware/vtk.js/types"; import { connectImageStream } from "@kitware/vtk.js/Rendering/Misc/RemoteView"; import { initWebSocketClient } from "@ogw_internal/utils/ws_client"; -import opengeodeweb_viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; // Local imports import { type ViewerRequestArgs, callViewer } from "./viewer_helpers/request.js"; @@ -21,6 +20,7 @@ import { import { useMicroserviceVersion, useRequestCounter } from "@ogw_internal/stores/microservice"; import { Status } from "@ogw_front/utils/status"; import { afterViewerReset } from "@ogw_front/composables/viewer_reset"; +import { loadScenesStore } from "@ogw_internal/stores/scenes/load_store"; import { useInfraStore } from "@ogw_front/stores/infra"; import type { JsonRpcSchema, RequestHandlers, ResponseOf } from "@ogw_shared/utils/types.js"; @@ -118,12 +118,11 @@ export const useViewerStore = defineStore( connectImageStream(client.value.getConnection().getSession()); // oxlint-disable-next-line no-unsafe-type-assertion -- endBusy is not part of the RpcClient type. (client.value as unknown as { endBusy: () => void }).endBusy(); - const schema = opengeodeweb_viewer_schemas.opengeodeweb_viewer.viewer.reset_visualization; - const timeout = undefined; - await request({ - schema, - timeout, - }); + // A new viewer holds no scene: the project shows at least one + const scenesStore = await loadScenesStore(); + if (scenesStore.scenes.length === 0) { + await scenesStore.createScene("empty"); + } await afterViewerReset(request); status.value = Status.CONNECTED; } catch (error) { From 25e95b2b272745630e30857abcaccad46b772a79 Mon Sep 17 00:00:00 2001 From: MaxNumerique <144453705+MaxNumerique@users.noreply.github.com> Date: Mon, 30 Nov 2026 14:33:02 +0000 Subject: [PATCH 028/121] Apply prepare changes --- tests/unit/composables/scene_id.nuxt.test.ts | 5 +---- tests/unit/stores/scene_scope.nuxt.test.ts | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/unit/composables/scene_id.nuxt.test.ts b/tests/unit/composables/scene_id.nuxt.test.ts index 1e7b461ac..35f962924 100644 --- a/tests/unit/composables/scene_id.nuxt.test.ts +++ b/tests/unit/composables/scene_id.nuxt.test.ts @@ -19,10 +19,7 @@ describe("scene id injection", () => { }, }); const Parent = defineComponent({ - setup( - _props: object, - _context: SetupContext, - ): () => ReturnType { + setup(_props: object, _context: SetupContext): () => ReturnType { provideSceneId("scene_2"); return () => h(Child); }, diff --git a/tests/unit/stores/scene_scope.nuxt.test.ts b/tests/unit/stores/scene_scope.nuxt.test.ts index c4d00a683..299dab1d8 100644 --- a/tests/unit/stores/scene_scope.nuxt.test.ts +++ b/tests/unit/stores/scene_scope.nuxt.test.ts @@ -1,8 +1,5 @@ import { afterEach, describe, expect, test, vi } from "vitest"; -import { - disposeSceneScope, - runInSceneScope, -} from "@ogw_internal/stores/scenes/scene_scope"; +import { disposeSceneScope, runInSceneScope } from "@ogw_internal/stores/scenes/scene_scope"; import { nextTick, ref, watch } from "vue"; vi.setConfig({ testTimeout: 10_000 }); From c4ffd78d2f6431fc83b7ee62d7d10616c020696b Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:33:05 +0100 Subject: [PATCH 029/121] fix(hybrid_viewer): release the view of a closed scene Disposing a scene's scope deletes its view stream, which stops observing the images of its view, and its local render window. Test: a closed scene releases its view. Co-Authored-By: Claude Opus 5.5 --- internal/stores/hybrid_viewer/core.ts | 6 ++++++ internal/stores/hybrid_viewer/vtk_types.ts | 2 ++ .../stores/hybrid_viewer_camera.nuxt.test.ts | 1 + .../stores/hybrid_viewer_viewport.nuxt.test.ts | 17 +++++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/internal/stores/hybrid_viewer/core.ts b/internal/stores/hybrid_viewer/core.ts index 9f5b77980..19b150b3c 100644 --- a/internal/stores/hybrid_viewer/core.ts +++ b/internal/stores/hybrid_viewer/core.ts @@ -34,6 +34,12 @@ function createHybridViewerCore(sceneId: SceneId): HybridViewerCore { const is_picking = ref(false); const viewStream = ref(undefined); + // A closed scene releases its view and its local render window + onScopeDispose(() => { + viewStream.value?.delete(); + genericRenderWindow.value?.delete(); + }); + let renderPromise: Promise | undefined = undefined; let renderPending = false; diff --git a/internal/stores/hybrid_viewer/vtk_types.ts b/internal/stores/hybrid_viewer/vtk_types.ts index 117fc8b1f..d4fa9bb62 100644 --- a/internal/stores/hybrid_viewer/vtk_types.ts +++ b/internal/stores/hybrid_viewer/vtk_types.ts @@ -42,6 +42,8 @@ interface HoverData extends ModelIdentified { interface ViewStreamLike { setSize: (width: number, height: number) => void; onImageReady: (callback: (event: { image: unknown }) => void) => void; + // Stops observing the view's images + delete: () => void; } export type { Vector3 } from "@kitware/vtk.js/types"; diff --git a/tests/unit/stores/hybrid_viewer_camera.nuxt.test.ts b/tests/unit/stores/hybrid_viewer_camera.nuxt.test.ts index a23439c11..41bb7dc04 100644 --- a/tests/unit/stores/hybrid_viewer_camera.nuxt.test.ts +++ b/tests/unit/stores/hybrid_viewer_camera.nuxt.test.ts @@ -68,6 +68,7 @@ function createdViewer(sceneId: string): ReturnType { const renderWindow = { getRenderer: (): typeof renderer => renderer, getRenderWindow: (): { render: () => void } => ({ render: vi.fn<() => void>() }), + delete: vi.fn<() => void>(), }; // oxlint-disable-next-line typescript/no-unsafe-type-assertion useHybridViewerCore(sceneId).genericRenderWindow.value = renderWindow as never; diff --git a/tests/unit/stores/hybrid_viewer_viewport.nuxt.test.ts b/tests/unit/stores/hybrid_viewer_viewport.nuxt.test.ts index ffd2eff2b..2d2b1df08 100644 --- a/tests/unit/stores/hybrid_viewer_viewport.nuxt.test.ts +++ b/tests/unit/stores/hybrid_viewer_viewport.nuxt.test.ts @@ -27,6 +27,7 @@ function createdViewer(sceneId: string): Mock { setSize: vi.fn(), }), getRenderWindow: (): { render: () => void } => ({ render: vi.fn<() => void>() }), + delete: vi.fn<() => void>(), }; // oxlint-disable-next-line typescript/no-unsafe-type-assertion core.genericRenderWindow.value = renderWindow as never; @@ -34,6 +35,7 @@ function createdViewer(sceneId: string): Mock { core.viewStream.value = { setSize, onImageReady: vi.fn<() => void>(), + delete: vi.fn<() => void>(), }; return setSize; } @@ -71,3 +73,18 @@ describe("hybrid viewer resize", () => { ]); }); }); + +describe("hybrid viewer close", () => { + test("a closed scene releases its view", () => { + const releaseView = vi.fn<() => void>(); + useHybridViewerCore("scene_1").viewStream.value = { + setSize: vi.fn(), + onImageReady: vi.fn<() => void>(), + delete: releaseView, + }; + + disposeSceneScope("scene_1"); + + expect(releaseView).toHaveBeenCalledExactlyOnceWith(); + }); +}); From 33abbc26236984d0026f8efe3ea0404c28c7d79d Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:33:11 +0100 Subject: [PATCH 030/121] fix(scenes): define each scene store once useDataStyleStore and useHybridViewerStore keep the store definition of each scene instead of calling defineStore on every call. Co-Authored-By: Claude Opus 5.5 --- app/stores/data_style.ts | 16 ++++++++++++---- app/stores/hybrid_viewer.ts | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/stores/data_style.ts b/app/stores/data_style.ts index 6f35be4f4..9c67aca1d 100644 --- a/app/stores/data_style.ts +++ b/app/stores/data_style.ts @@ -193,11 +193,19 @@ function setupDataStyleStore(sceneId: SceneId): DataStyleStoreSetup { }; } +type DataStyleStoreDefinition = ReturnType>; + +// A scene keeps the store definition it was given first +const dataStyleStoreDefinitions = new Map(); + // Each scene has its own store: the same data can be styled differently in two scenes -function useDataStyleStore( - sceneId: SceneId, -): ReturnType>> { - return defineStore(`dataStyle-${sceneId}`, () => setupDataStyleStore(sceneId))(); +function useDataStyleStore(sceneId: SceneId): ReturnType { + let definition = dataStyleStoreDefinitions.get(sceneId); + if (!definition) { + definition = defineStore(`dataStyle-${sceneId}`, () => setupDataStyleStore(sceneId)); + dataStyleStoreDefinitions.set(sceneId, definition); + } + return definition(); } export { useDataStyleStore }; diff --git a/app/stores/hybrid_viewer.ts b/app/stores/hybrid_viewer.ts index 86a569be3..9ebfdc51c 100644 --- a/app/stores/hybrid_viewer.ts +++ b/app/stores/hybrid_viewer.ts @@ -180,11 +180,19 @@ function setupHybridViewerStore(sceneId: SceneId): HybridViewerStoreSetup { }; } +type HybridViewerStoreDefinition = ReturnType>; + +// A scene keeps the store definition it was given first +const hybridViewerStoreDefinitions = new Map(); + // Each scene has its own viewer: its own render window, view and camera -function useHybridViewerStore( - sceneId: SceneId, -): ReturnType>> { - return defineStore(`hybridViewer-${sceneId}`, () => setupHybridViewerStore(sceneId))(); +function useHybridViewerStore(sceneId: SceneId): ReturnType { + let definition = hybridViewerStoreDefinitions.get(sceneId); + if (!definition) { + definition = defineStore(`hybridViewer-${sceneId}`, () => setupHybridViewerStore(sceneId)); + hybridViewerStoreDefinitions.set(sceneId, definition); + } + return definition(); } export { useHybridViewerStore }; From 50b4a043dbdd43e84c6c69c8f269e33c347c6225 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:43:44 +0100 Subject: [PATCH 031/121] fix(scenes): propagate the z-scaling to a scene not shown yet A linked scene without a render window threw in setZScaling, and the rejection was swallowed. It now keeps its z-scaling, as it keeps the camera, and the viewer gets set_z_scaling: its actors take it when they are added. The z-scaling propagates even when the source camera options are still empty. Test: propagateCamera keeps the z-scaling of a scene not shown yet. Co-Authored-By: Claude Opus 5.5 --- app/stores/scenes.ts | 12 +++-- internal/stores/hybrid_viewer/scene.ts | 50 ++++++++++++------- .../stores/hybrid_viewer_camera.nuxt.test.ts | 16 ++++++ 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index 8c4949d35..95592657f 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -21,6 +21,7 @@ import { removeFromSceneStores, } from "@ogw_internal/stores/scenes/scene_stores"; import { joinLink, leaveLinks, linkedScenes } from "@ogw_internal/stores/scenes/links"; +import type { CameraOptions } from "@ogw_internal/stores/hybrid_viewer/vtk_types"; import { isCameraOptions } from "@ogw_internal/stores/hybrid_viewer/camera"; import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; import { useViewerStore } from "@ogw_front/stores/viewer"; @@ -161,17 +162,20 @@ export const useScenesStore = defineStore("scenes", () => { // The scenes linked on camera take the z-scaling and the camera of the scene, without propagating them back async function propagateCamera(sceneId: SceneId): Promise { const source = useHybridViewerStore(sceneId); - if (!isCameraOptions(source.camera_options)) { - return; + // The camera options of a scene stay empty until its viewer has a camera + let options: CameraOptions | undefined = undefined; + if (isCameraOptions(source.camera_options)) { + options = structuredClone(toRaw(source.camera_options)); } - const options = structuredClone(toRaw(source.camera_options)); await Promise.all( linkedScenes(links.value, sceneId, "camera").map(async (targetId) => { const target = useHybridViewerStore(targetId); if (target.zScale !== source.zScale) { await target.setZScaling(source.zScale, false); } - await target.setCameraOptions(options, false); + if (options) { + await target.setCameraOptions(options, false); + } }), ); } diff --git a/internal/stores/hybrid_viewer/scene.ts b/internal/stores/hybrid_viewer/scene.ts index bfce85b1b..103afec21 100644 --- a/internal/stores/hybrid_viewer/scene.ts +++ b/internal/stores/hybrid_viewer/scene.ts @@ -1,4 +1,5 @@ import type { + CameraOptions, HybridDb, vtkActor as VtkActorInstance, vtkGenericRenderWindow as VtkGenericRenderWindow, @@ -65,6 +66,25 @@ function followZScaling(camera: vtkCamera, ratio: number): void { camera.setPosition(positionX, positionY, positionZ + offset); } +// Stretches the local actors along z, the camera following the point it looks at +function stretchLocalScene( + renderWindow: VtkGenericRenderWindow, + z_scale: number, + ratio: number, +): CameraOptions { + const renderer = renderWindow.getRenderer(); + // oxlint-disable-next-line no-unsafe-type-assertion -- renderer.getActors() is typed as vtkProp[] in vtk.js, but this scene only ever adds vtkActor instances. + for (const actor of renderer.getActors() as VtkActorInstance[]) { + const scale = actor.getScale(); + actor.setScale(scale[0] ?? 1, scale[1] ?? 1, z_scale); + } + const camera = renderer.getActiveCamera(); + followZScaling(camera, ratio); + renderer.resetCameraClippingRange(); + renderWindow.getRenderWindow().render(); + return getCameraOptions(camera); +} + interface HybridViewerScene { hybridDb: HybridDb; zScale: Ref; @@ -131,17 +151,11 @@ function createHybridViewerScene(sceneId: SceneId): HybridViewerScene { const { genericRenderWindow, remoteRender } = useHybridViewerCore(sceneId); const ratio = z_scale / zScale.value; zScale.value = z_scale; - const renderer = requireRenderWindow(genericRenderWindow).getRenderer(); - // oxlint-disable-next-line no-unsafe-type-assertion -- renderer.getActors() is typed as vtkProp[] in vtk.js, but this scene only ever adds vtkActor instances. - for (const actor of renderer.getActors() as VtkActorInstance[]) { - const scale = actor.getScale(); - actor.setScale(scale[0] ?? 1, scale[1] ?? 1, z_scale); + // A scene not shown yet keeps its z-scaling: its actors take it when they are added + let camera_options: CameraOptions | undefined = undefined; + if (genericRenderWindow.value) { + camera_options = stretchLocalScene(genericRenderWindow.value, z_scale, ratio); } - const camera = renderer.getActiveCamera(); - followZScaling(camera, ratio); - renderer.resetCameraClippingRange(); - const renderWindow = requireRenderWindow(genericRenderWindow).getRenderWindow(); - renderWindow.render(); const viewerStore = useViewerStore(); await viewerStore.request({ schema: viewer_schemas.opengeodeweb_viewer.viewer.set_z_scaling, @@ -150,13 +164,15 @@ function createHybridViewerScene(sceneId: SceneId): HybridViewerScene { z_scale, }, }); - await viewerStore.request({ - schema: viewer_schemas.opengeodeweb_viewer.viewer.update_camera, - params: { - scene_id: sceneId, - camera_options: getCameraOptions(camera), - }, - }); + if (camera_options) { + await viewerStore.request({ + schema: viewer_schemas.opengeodeweb_viewer.viewer.update_camera, + params: { + scene_id: sceneId, + camera_options, + }, + }); + } await remoteRender(); if (propagate) { const scenesStore = await loadScenesStore(); diff --git a/tests/unit/stores/hybrid_viewer_camera.nuxt.test.ts b/tests/unit/stores/hybrid_viewer_camera.nuxt.test.ts index 41bb7dc04..3d9e26d40 100644 --- a/tests/unit/stores/hybrid_viewer_camera.nuxt.test.ts +++ b/tests/unit/stores/hybrid_viewer_camera.nuxt.test.ts @@ -48,6 +48,7 @@ describe("centerCameraOnPosition helper", () => { const LINKED_POSITION: Vector3 = [PICKED_X, PICKED_Y, PICKED_Z]; const VIEW_ANGLE = 30; const FAR_CLIPPING = 200; +const Z_SCALE = 3; const CAMERA_OPTIONS: CameraOptions = { focal_point: [0, 0, 0], view_up: [0, 1, 0], @@ -126,4 +127,19 @@ describe("camera link", () => { ]); expect(unlinkedCamera.getPosition()).toStrictEqual(LINKED_POSITION); }); + + test("propagateCamera keeps the z-scaling of a scene not shown yet", async () => { + const request = mockViewer(); + createdViewer("scene_1"); + const source = useHybridViewerStore("scene_1"); + Object.assign(source.camera_options, CAMERA_OPTIONS); + + await source.setZScaling(Z_SCALE); + + expect(sentTo(request, viewer_schemas.opengeodeweb_viewer.viewer.set_z_scaling)).toStrictEqual([ + "scene_1", + "scene_2", + ]); + expect(useHybridViewerStore("scene_2").zScale).toBe(Z_SCALE); + }); }); From 6dc7b3ab75d6fadac2d213de98e909a2d83158ff Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:44:41 +0100 Subject: [PATCH 032/121] fix(scenes): move the camera propagation out of the scenes store propagateCamera stays in the scenes store and gives the scenes linked on camera to propagateToLinkedScenes (internal/stores/scenes/camera_link.ts), so that the store stays under the file size limit. Co-Authored-By: Claude Opus 5.5 --- app/stores/scenes.ts | 24 +++----------------- internal/stores/scenes/camera_link.ts | 32 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 internal/stores/scenes/camera_link.ts diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index 95592657f..b80c625f3 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -1,7 +1,7 @@ // Third party imports -import { ref, toRaw } from "vue"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; import { defineStore } from "pinia"; +import { ref } from "vue"; import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; // Local imports @@ -21,9 +21,7 @@ import { removeFromSceneStores, } from "@ogw_internal/stores/scenes/scene_stores"; import { joinLink, leaveLinks, linkedScenes } from "@ogw_internal/stores/scenes/links"; -import type { CameraOptions } from "@ogw_internal/stores/hybrid_viewer/vtk_types"; -import { isCameraOptions } from "@ogw_internal/stores/hybrid_viewer/camera"; -import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; +import { propagateToLinkedScenes } from "@ogw_internal/stores/scenes/camera_link"; import { useViewerStore } from "@ogw_front/stores/viewer"; const viewerSchemas = viewer_schemas.opengeodeweb_viewer.viewer; @@ -161,23 +159,7 @@ export const useScenesStore = defineStore("scenes", () => { // The scenes linked on camera take the z-scaling and the camera of the scene, without propagating them back async function propagateCamera(sceneId: SceneId): Promise { - const source = useHybridViewerStore(sceneId); - // The camera options of a scene stay empty until its viewer has a camera - let options: CameraOptions | undefined = undefined; - if (isCameraOptions(source.camera_options)) { - options = structuredClone(toRaw(source.camera_options)); - } - await Promise.all( - linkedScenes(links.value, sceneId, "camera").map(async (targetId) => { - const target = useHybridViewerStore(targetId); - if (target.zScale !== source.zScale) { - await target.setZScaling(source.zScale, false); - } - if (options) { - await target.setCameraOptions(options, false); - } - }), - ); + await propagateToLinkedScenes(linkedScenes(links.value, sceneId, "camera"), sceneId); } function setLastUsed(sceneId: SceneId): void { diff --git a/internal/stores/scenes/camera_link.ts b/internal/stores/scenes/camera_link.ts new file mode 100644 index 000000000..c8a179e66 --- /dev/null +++ b/internal/stores/scenes/camera_link.ts @@ -0,0 +1,32 @@ +import type { CameraOptions } from "@ogw_internal/stores/hybrid_viewer/vtk_types"; +import type { SceneId } from "./types"; +import { isCameraOptions } from "@ogw_internal/stores/hybrid_viewer/camera"; +import { toRaw } from "vue"; +import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; + +// The linked scenes take the z-scaling and the camera of the source scene, with propagate = false so that nothing +// Comes back +async function propagateToLinkedScenes( + linkedSceneIds: readonly SceneId[], + sourceId: SceneId, +): Promise { + const source = useHybridViewerStore(sourceId); + // The camera options of a scene stay empty until its viewer has a camera + let options: CameraOptions | undefined = undefined; + if (isCameraOptions(source.camera_options)) { + options = structuredClone(toRaw(source.camera_options)); + } + await Promise.all( + linkedSceneIds.map(async (targetId) => { + const target = useHybridViewerStore(targetId); + if (target.zScale !== source.zScale) { + await target.setZScaling(source.zScale, false); + } + if (options) { + await target.setCameraOptions(options, false); + } + }), + ); +} + +export { propagateToLinkedScenes }; From 84a98b3697208e42f6b5a23e12548720956bdefd Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:45:48 +0100 Subject: [PATCH 033/121] fix(scenes): give every new scene the app colors and marker afterViewerReset(request, sceneId) sends set_background_color, set_text_style and set_orientation_widget with the scene id (hideViewerMarker, hideViewerMarkerRequest and withViewerMarker take the scene too). The scenes store calls it for each scene it creates, so scene_1 and every later scene draw the app colors; ws_connect no longer calls it without a scene. Test: a new scene gets the app colors. Co-Authored-By: Claude Opus 5.5 --- app/composables/orientation_overlay.ts | 19 ++++--- app/composables/viewer_reset.ts | 16 +++--- app/stores/scenes.ts | 6 +- app/stores/viewer.ts | 2 - .../Viewer/OrientationOverlay.nuxt.test.ts | 4 +- .../orientation_overlay.nuxt.test.ts | 14 ++--- .../composables/viewer_reset.nuxt.test.ts | 19 +++++-- tests/unit/stores/scenes_viewer.nuxt.test.ts | 56 +++++++++++++++++++ 8 files changed, 103 insertions(+), 33 deletions(-) create mode 100644 tests/unit/stores/scenes_viewer.nuxt.test.ts diff --git a/app/composables/orientation_overlay.ts b/app/composables/orientation_overlay.ts index b2cc69deb..732d050f1 100644 --- a/app/composables/orientation_overlay.ts +++ b/app/composables/orientation_overlay.ts @@ -1,4 +1,5 @@ import type { ComputedRef, Ref } from "vue"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { SceneOrientationWidget } from "@ogw_internal/stores/data_style/types"; import { consola } from "consola"; import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; @@ -32,25 +33,26 @@ function viewerOrientationMarker(marker: SceneOrientationWidget): ViewerOrientat interface HideViewerMarkerRequest { schema: typeof viewer_schemas.opengeodeweb_viewer.viewer.set_orientation_widget; - params: { marker: typeof NO_VIEWER_MARKER }; + params: { scene_id: SceneId; marker: typeof NO_VIEWER_MARKER }; } -// Request hiding the VTK marker, undefined when the app keeps it -function hideViewerMarkerRequest(): HideViewerMarkerRequest | undefined { +// Request hiding the VTK marker of a scene, undefined when the app keeps it +function hideViewerMarkerRequest(sceneId: SceneId): HideViewerMarkerRequest | undefined { if (!isOrientationOverlayEnabled()) { return undefined; } return { schema: viewer_schemas.opengeodeweb_viewer.viewer.set_orientation_widget, - params: { marker: NO_VIEWER_MARKER }, + params: { scene_id: sceneId, marker: NO_VIEWER_MARKER }, }; } // To call after each viewer reset, which brings the VTK axes back async function hideViewerMarker( + sceneId: SceneId, request: (args: HideViewerMarkerRequest) => Promise, ): Promise { - const hideMarker = hideViewerMarkerRequest(); + const hideMarker = hideViewerMarkerRequest(sceneId); if (!hideMarker) { return; } @@ -94,12 +96,13 @@ function resetOrientationMarkerVisibility(): void { interface ViewerMarkerRequest { schema: typeof viewer_schemas.opengeodeweb_viewer.viewer.set_orientation_widget; - params: { marker: ViewerOrientationMarker }; + params: { scene_id: SceneId; marker: ViewerOrientationMarker }; } // The viewer renders the scene screenshots, without the front overlay: with the overlay on, the VTK marker of the // User's choice is drawn for the time of the capture, then hidden again (also when the capture fails) async function withViewerMarker( + sceneId: SceneId, marker: SceneOrientationWidget, request: (args: ViewerMarkerRequest) => Promise, capture: () => Promise, @@ -109,12 +112,12 @@ async function withViewerMarker( } await request({ schema: viewer_schemas.opengeodeweb_viewer.viewer.set_orientation_widget, - params: { marker }, + params: { scene_id: sceneId, marker }, }); try { return await capture(); } finally { - await hideViewerMarker(request); + await hideViewerMarker(sceneId, request); } } diff --git a/app/composables/viewer_reset.ts b/app/composables/viewer_reset.ts index 7f76b98d9..92d8d49b3 100644 --- a/app/composables/viewer_reset.ts +++ b/app/composables/viewer_reset.ts @@ -1,4 +1,5 @@ import type { ColorRGB, ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import type { ViewerRequest } from "@ogw_front/stores/viewer_helpers/request"; // Third party imports import { consola } from "consola"; @@ -18,19 +19,20 @@ function toViewerColor({ red, green, blue }: ColorRGBA): ColorRGB { // A reset viewer draws its own scene colors: give it the app's (`ogwFront.sceneColors`), which the default // Scene style shows -async function applyAppSceneColors(request: ViewerRequest): Promise { +async function applyAppSceneColors(request: ViewerRequest, sceneId: SceneId): Promise { const sceneColors = getSceneColors(); const { background_color, text } = getDefaultSceneStyle(); if (sceneColors.background) { await request({ schema: viewer_schemas.opengeodeweb_viewer.viewer.set_background_color, - params: { color: toViewerColor(background_color) }, + params: { scene_id: sceneId, color: toViewerColor(background_color) }, }); } if (sceneColors.text) { await request({ schema: viewer_schemas.opengeodeweb_viewer.viewer.set_text_style, params: { + scene_id: sceneId, color: toViewerColor(text.color), font_family: text.font_family, opacity: text.color.alpha, @@ -39,16 +41,16 @@ async function applyAppSceneColors(request: ViewerRequest): Promise { } } -// To call after each viewer reset (reset_visualization), which brings back the viewer's own scene. Neither -// Step fails the reset: the viewer stays usable with its own colors, and the marker is hidden either way -async function afterViewerReset(request: ViewerRequest): Promise { +// To call on each new or reset viewer scene, which draws the viewer's own colors and marker. Neither step fails +// The scene: the viewer stays usable with its own colors, and the marker is hidden either way +async function afterViewerReset(request: ViewerRequest, sceneId: SceneId): Promise { resetOrientationMarkerVisibility(); try { - await applyAppSceneColors(request); + await applyAppSceneColors(request, sceneId); } catch (error) { consola.warn("[SceneColors] The viewer kept its own scene colors:", error); } - await hideViewerMarker(request); + await hideViewerMarker(sceneId, request); } export { afterViewerReset, toViewerColor }; diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index b80c625f3..30c32fcf7 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -21,6 +21,7 @@ import { removeFromSceneStores, } from "@ogw_internal/stores/scenes/scene_stores"; import { joinLink, leaveLinks, linkedScenes } from "@ogw_internal/stores/scenes/links"; +import { afterViewerReset } from "@ogw_front/composables/viewer_reset"; import { propagateToLinkedScenes } from "@ogw_internal/stores/scenes/camera_link"; import { useViewerStore } from "@ogw_front/stores/viewer"; @@ -101,10 +102,13 @@ export const useScenesStore = defineStore("scenes", () => { async function newScene(): Promise { counter.value += 1; const sceneId = `scene_${counter.value}`; - const { view_id } = await useViewerStore().request({ + const viewerStore = useViewerStore(); + const { view_id } = await viewerStore.request({ schema: viewerSchemas.create_scene, params: { scene_id: sceneId }, }); + // A new viewer scene draws the app colors, not its own + await afterViewerReset(viewerStore.request, sceneId); scenes.value.push({ id: sceneId, name: `Scene ${counter.value}`, view_id }); contents.value[sceneId] = []; return sceneId; diff --git a/app/stores/viewer.ts b/app/stores/viewer.ts index e69599945..9788144b9 100644 --- a/app/stores/viewer.ts +++ b/app/stores/viewer.ts @@ -19,7 +19,6 @@ import { } from "./viewer_helpers/actions.js"; import { useMicroserviceVersion, useRequestCounter } from "@ogw_internal/stores/microservice"; import { Status } from "@ogw_front/utils/status"; -import { afterViewerReset } from "@ogw_front/composables/viewer_reset"; import { loadScenesStore } from "@ogw_internal/stores/scenes/load_store"; import { useInfraStore } from "@ogw_front/stores/infra"; @@ -123,7 +122,6 @@ export const useViewerStore = defineStore( if (scenesStore.scenes.length === 0) { await scenesStore.createScene("empty"); } - await afterViewerReset(request); status.value = Status.CONNECTED; } catch (error) { status.value = Status.NOT_CONNECTED; diff --git a/tests/unit/components/Viewer/OrientationOverlay.nuxt.test.ts b/tests/unit/components/Viewer/OrientationOverlay.nuxt.test.ts index f8f61483e..b4fb10b3b 100644 --- a/tests/unit/components/Viewer/OrientationOverlay.nuxt.test.ts +++ b/tests/unit/components/Viewer/OrientationOverlay.nuxt.test.ts @@ -155,9 +155,9 @@ describe("orientation marker sent to the viewer", () => { setupActivePinia(); setOrientationOverlay(true); expect(viewerOrientationMarker("compass")).toBe("none"); - expect(hideViewerMarkerRequest()).toStrictEqual({ + expect(hideViewerMarkerRequest("scene_1")).toStrictEqual({ schema: set_orientation_widget, - params: { marker: "none" }, + params: { scene_id: "scene_1", marker: "none" }, }); const viewerStore = useViewerStore(); viewerStore.request = mockAs( diff --git a/tests/unit/composables/orientation_overlay.nuxt.test.ts b/tests/unit/composables/orientation_overlay.nuxt.test.ts index d1fa1854f..5359792dc 100644 --- a/tests/unit/composables/orientation_overlay.nuxt.test.ts +++ b/tests/unit/composables/orientation_overlay.nuxt.test.ts @@ -22,7 +22,7 @@ describe("orientation marker sent to the viewer", () => { test("is the scene style choice without the overlay", () => { setOrientationOverlay(false); expect(viewerOrientationMarker("compass")).toBe("compass"); - expect(hideViewerMarkerRequest()).toBeUndefined(); + expect(hideViewerMarkerRequest("scene_1")).toBeUndefined(); }); test("hides the VTK marker after a viewer reset only with the overlay", async () => { @@ -30,14 +30,14 @@ describe("orientation marker sent to the viewer", () => { await Promise.reject(new Error("unknown marker")); }); setOrientationOverlay(false); - await hideViewerMarker(request); + await hideViewerMarker("scene_1", request); expect(request).not.toHaveBeenCalled(); setOrientationOverlay(true); // An older viewer rejecting the "none" marker does not fail the reset - await expect(hideViewerMarker(request)).resolves.toBeUndefined(); + await expect(hideViewerMarker("scene_1", request)).resolves.toBeUndefined(); expect(request).toHaveBeenCalledWith({ schema: set_orientation_widget, - params: { marker: "none" }, + params: { scene_id: "scene_1", marker: "none" }, }); }); @@ -53,11 +53,11 @@ describe("orientation marker sent to the viewer", () => { return "image"; } setOrientationOverlay(false); - await expect(withViewerMarker("compass", request, capture)).resolves.toBe("image"); + await expect(withViewerMarker("scene_1", "compass", request, capture)).resolves.toBe("image"); expect(calls).toStrictEqual(["capture"]); calls.length = 0; setOrientationOverlay(true); - await expect(withViewerMarker("compass", request, capture)).resolves.toBe("image"); + await expect(withViewerMarker("scene_1", "compass", request, capture)).resolves.toBe("image"); expect(calls).toStrictEqual(["compass", "capture", "none"]); }); @@ -69,7 +69,7 @@ describe("orientation marker sent to the viewer", () => { }); setOrientationOverlay(true); await expect( - withViewerMarker("axes", request, async () => { + withViewerMarker("scene_1", "axes", request, async () => { await Promise.reject(new Error("capture failed")); }), ).rejects.toThrow("capture failed"); diff --git a/tests/unit/composables/viewer_reset.nuxt.test.ts b/tests/unit/composables/viewer_reset.nuxt.test.ts index c85f8d22b..4a1288026 100644 --- a/tests/unit/composables/viewer_reset.nuxt.test.ts +++ b/tests/unit/composables/viewer_reset.nuxt.test.ts @@ -29,7 +29,7 @@ describe("after a viewer reset", () => { test("leaves the viewer as is for an app without scene colors nor overlay", async () => { const { request } = recordRequests(); - await afterViewerReset(request); + await afterViewerReset(request, "scene_1"); expect(request).not.toHaveBeenCalled(); }); @@ -37,15 +37,20 @@ describe("after a viewer reset", () => { setSceneColors({ background: BRAND_BACKGROUND, text: BRAND_TEXT }); setOrientationOverlay(true); const { request, schemas } = recordRequests(); - await afterViewerReset(request); + await afterViewerReset(request, "scene_1"); expect(schemas).toStrictEqual([set_background_color, set_text_style, set_orientation_widget]); expect(request).toHaveBeenCalledWith({ schema: set_background_color, - params: { color: { red: 160, green: 180, blue: 187 } }, + params: { scene_id: "scene_1", color: { red: 160, green: 180, blue: 187 } }, }); expect(request).toHaveBeenCalledWith({ schema: set_text_style, - params: { color: { red: 31, green: 46, blue: 51 }, font_family: "arial", opacity: 1 }, + params: { + scene_id: "scene_1", + color: { red: 31, green: 46, blue: 51 }, + font_family: "arial", + opacity: 1, + }, }); }); @@ -56,7 +61,9 @@ describe("after a viewer reset", () => { .fn<(args: { schema: unknown }) => Promise>() .mockRejectedValueOnce(new Error("timeout")) .mockResolvedValue({}); - await expect(afterViewerReset(mockAs(request))).resolves.toBeUndefined(); + await expect( + afterViewerReset(mockAs(request), "scene_1"), + ).resolves.toBeUndefined(); expect(request.mock.calls.map(([args]) => args.schema)).toStrictEqual([ set_background_color, set_orientation_widget, @@ -67,7 +74,7 @@ describe("after a viewer reset", () => { const { request } = recordRequests(); await setOrientationMarkerVisibility(false, request); expect(useOrientationMarkerVisible().value).toBe(false); - await afterViewerReset(request); + await afterViewerReset(request, "scene_1"); expect(useOrientationMarkerVisible().value).toBe(true); }); }); diff --git a/tests/unit/stores/scenes_viewer.nuxt.test.ts b/tests/unit/stores/scenes_viewer.nuxt.test.ts new file mode 100644 index 000000000..5c4020041 --- /dev/null +++ b/tests/unit/stores/scenes_viewer.nuxt.test.ts @@ -0,0 +1,56 @@ +// Third party imports +import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; + +// Local imports +import { fakeStores, mockViewer, sentTo } from "@ogw_tests/unit/stores/scenes_helpers"; +import { setSceneColors } from "@ogw_front/utils/default_styles"; +import { setupActivePinia } from "@ogw_tests/utils"; +import { useScenesStore } from "@ogw_front/stores/scenes"; + +vi.setConfig({ testTimeout: 10_000 }); + +vi.mock(import("@ogw_front/stores/data_style") as Promise, async () => { + const helpers = await import("@ogw_tests/unit/stores/scenes_helpers"); + return { + useDataStyleStore: (sceneId: string): Record => + helpers.fakeSceneStore("dataStyle", sceneId), + }; +}); +vi.mock(import("@ogw_front/stores/hybrid_viewer") as Promise, async () => { + const helpers = await import("@ogw_tests/unit/stores/scenes_helpers"); + return { + useHybridViewerStore: (sceneId: string): Record => + helpers.fakeSceneStore("hybridViewer", sceneId), + }; +}); +vi.mock(import("@ogw_front/stores/treeview") as Promise, async () => { + const helpers = await import("@ogw_tests/unit/stores/scenes_helpers"); + return { + useTreeviewStore: (sceneId: string): Record => + helpers.fakeSceneStore("treeview", sceneId), + }; +}); + +const { viewer } = viewer_schemas.opengeodeweb_viewer; +const BRAND_BACKGROUND = { red: 160, green: 180, blue: 187, alpha: 1 }; + +describe("scenes in the viewer", () => { + beforeEach(() => { + setupActivePinia(); + fakeStores.clear(); + }); + + afterEach(() => { + setSceneColors({}); + }); + + test("a new scene gets the app colors", async () => { + const request = mockViewer(); + setSceneColors({ background: BRAND_BACKGROUND }); + + await useScenesStore().createScene("empty"); + + expect(sentTo(request, viewer.set_background_color)).toStrictEqual(["scene_1"]); + }); +}); From 2269ab534918cea2b33c99b18f00fc92559369e6 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:47:01 +0100 Subject: [PATCH 034/121] fix(viewer): start over from scene_1 on each connection A viewer that outlives the front (page reload, reconnection) still held scene_1 and later scenes: create_scene then conflicted and ws_connect failed. ws_connect now calls scenesStore.resetScenes(), which sends reset_scenes, disposes the stores of the front scenes, clears the scenes state and creates scene_1. assertScene moves to module level to keep the store setup within the statement limit. Test: connecting twice to the same viewer ends with scene_1 alone. Co-Authored-By: Claude Opus 5.5 --- app/stores/scenes.ts | 32 ++++++++++---- app/stores/viewer.ts | 6 +-- tests/unit/stores/scenes_viewer.nuxt.test.ts | 45 +++++++++++++++++++- 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index 30c32fcf7..2c78956d6 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -35,6 +35,13 @@ interface ScenesSnapshot { counter: number; } +// An unknown id would create the stores of a scene that does not exist +function assertScene(scenes: readonly SceneRecord[], sceneId: SceneId): void { + if (!scenes.some((scene) => scene.id === sceneId)) { + throw new Error(`Unknown scene: ${sceneId}`); + } +} + // The only place that knows the content links: data are added to and removed from scenes here export const useScenesStore = defineStore("scenes", () => { const scenes = ref([]); @@ -92,13 +99,6 @@ export const useScenesStore = defineStore("scenes", () => { await deleteIfHidden([dataId]); } - // An unknown id would create the stores of a scene that does not exist - function assertScene(sceneId: SceneId): void { - if (!scenes.value.some((scene) => scene.id === sceneId)) { - throw new Error(`Unknown scene: ${sceneId}`); - } - } - async function newScene(): Promise { counter.value += 1; const sceneId = `scene_${counter.value}`; @@ -125,7 +125,7 @@ export const useScenesStore = defineStore("scenes", () => { if (sourceId === undefined) { throw new Error("A duplicated scene needs its source scene"); } - assertScene(sourceId); + assertScene(scenes.value, sourceId); const sceneId = await newScene(); const content = [...(contents.value[sourceId] ?? [])]; contents.value[sceneId] = content; @@ -137,7 +137,7 @@ export const useScenesStore = defineStore("scenes", () => { } async function closeScene(sceneId: SceneId): Promise { - assertScene(sceneId); + assertScene(scenes.value, sceneId); if (scenes.value.length <= 1) { throw new Error("The last scene cannot be closed"); } @@ -196,6 +196,19 @@ export const useScenesStore = defineStore("scenes", () => { counter.value = 0; } + // The viewer may hold the scenes of an earlier connection, after a reload or a reconnection: the viewer and the + // Front start over from scene_1 alone + async function resetScenes(): Promise { + await useViewerStore().request({ schema: viewerSchemas.reset_scenes, params: {} }); + await Promise.all( + scenes.value.map(async (scene) => { + await disposeSceneStores(scene.id); + }), + ); + clear(); + return createScene("empty"); + } + return { scenes, contents, @@ -211,6 +224,7 @@ export const useScenesStore = defineStore("scenes", () => { setLastUsed, exportStores, importStores, + resetScenes, clear, }; }); diff --git a/app/stores/viewer.ts b/app/stores/viewer.ts index 9788144b9..1c3f12fed 100644 --- a/app/stores/viewer.ts +++ b/app/stores/viewer.ts @@ -117,11 +117,9 @@ export const useViewerStore = defineStore( connectImageStream(client.value.getConnection().getSession()); // oxlint-disable-next-line no-unsafe-type-assertion -- endBusy is not part of the RpcClient type. (client.value as unknown as { endBusy: () => void }).endBusy(); - // A new viewer holds no scene: the project shows at least one + // The project starts from scene_1 alone, whatever scenes the viewer still holds const scenesStore = await loadScenesStore(); - if (scenesStore.scenes.length === 0) { - await scenesStore.createScene("empty"); - } + await scenesStore.resetScenes(); status.value = Status.CONNECTED; } catch (error) { status.value = Status.NOT_CONNECTED; diff --git a/tests/unit/stores/scenes_viewer.nuxt.test.ts b/tests/unit/stores/scenes_viewer.nuxt.test.ts index 5c4020041..89a83e283 100644 --- a/tests/unit/stores/scenes_viewer.nuxt.test.ts +++ b/tests/unit/stores/scenes_viewer.nuxt.test.ts @@ -3,10 +3,16 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; // Local imports -import { fakeStores, mockViewer, sentTo } from "@ogw_tests/unit/stores/scenes_helpers"; +import { + type Request, + fakeStores, + mockViewer, + sentTo, +} from "@ogw_tests/unit/stores/scenes_helpers"; +import { mockAs, setupActivePinia } from "@ogw_tests/utils"; import { setSceneColors } from "@ogw_front/utils/default_styles"; -import { setupActivePinia } from "@ogw_tests/utils"; import { useScenesStore } from "@ogw_front/stores/scenes"; +import { useViewerStore } from "@ogw_front/stores/viewer"; vi.setConfig({ testTimeout: 10_000 }); @@ -35,6 +41,26 @@ vi.mock(import("@ogw_front/stores/treeview") as Promise, async () => { const { viewer } = viewer_schemas.opengeodeweb_viewer; const BRAND_BACKGROUND = { red: 160, green: 180, blue: 187, alpha: 1 }; +// A viewer that outlives the front: it keeps its scenes and refuses to create one twice +function mockLastingViewer(viewerScenes: Set): void { + const viewerStore = useViewerStore(); + viewerStore.request = mockAs( + vi.fn(async ({ schema, params }) => { + await Promise.resolve(); + const sceneId = String(params.scene_id); + if (schema.$id === viewer.reset_scenes.$id) { + viewerScenes.clear(); + } else if (schema.$id === viewer.create_scene.$id) { + if (viewerScenes.has(sceneId)) { + throw new Error(`Scene ${sceneId} already exists`); + } + viewerScenes.add(sceneId); + } + return { view_id: `view_${sceneId}` }; + }), + ); +} + describe("scenes in the viewer", () => { beforeEach(() => { setupActivePinia(); @@ -53,4 +79,19 @@ describe("scenes in the viewer", () => { expect(sentTo(request, viewer.set_background_color)).toStrictEqual(["scene_1"]); }); + + test("connecting twice to the same viewer ends with scene_1 alone", async () => { + const viewerScenes = new Set(); + mockLastingViewer(viewerScenes); + await useScenesStore().resetScenes(); + await useScenesStore().createScene("empty"); + + // The page reloads: a new front connects to the same viewer + setupActivePinia(); + mockLastingViewer(viewerScenes); + await useScenesStore().resetScenes(); + + expect(useScenesStore().scenes.map((scene) => scene.id)).toStrictEqual(["scene_1"]); + expect([...viewerScenes]).toStrictEqual(["scene_1"]); + }); }); From de757ca229cbc84d879796a3515e807149f4b822 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:52:15 +0100 Subject: [PATCH 035/121] feat(treeview): one tree view store per scene Each scene has its own tree view, saved under its own scene_id in the treeview_config table. Co-Authored-By: Claude Opus 5.5 --- app/stores/treeview.ts | 85 +++++++++++++++++-- tests/unit/stores/treeview.nuxt.test.ts | 50 ++++++++--- .../stores/treeview_model_trees.nuxt.test.ts | 14 +-- .../treeview_physical_properties.nuxt.test.ts | 10 +-- 4 files changed, 130 insertions(+), 29 deletions(-) diff --git a/app/stores/treeview.ts b/app/stores/treeview.ts index bfcbb2eb1..47f326827 100644 --- a/app/stores/treeview.ts +++ b/app/stores/treeview.ts @@ -12,8 +12,8 @@ import type { OpenedView, TreeviewConfigRecord, } from "@ogw_internal/database/tables/treeview_config"; +import { type Ref, ref, watch } from "vue"; import type { TreeGroup, TreeNode } from "@ogw_front/types/tree"; -import { ref, watch } from "vue"; import { consola } from "consola"; // Not auto-fixable (eslint's sort-imports core rule has no autofixer) and this file's import order doesn't match its syntax-kind-then-alphabetical requirement - left as-is rather than manually reordered across the codebase for a purely cosmetic rule. // oxlint-disable eslint/sort-imports, eslint/max-lines @@ -23,7 +23,7 @@ import { physicalPropertiesViewId, viewModelId, } from "@ogw_front/utils/treeview"; -import { INITIAL_SCENE_ID } from "@ogw_internal/stores/scenes/types"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { treeviewConfigDb } from "@ogw_internal/database/database"; const PANEL_WIDTH = 300; @@ -89,8 +89,65 @@ function snapshotSelectionIds(snapshot: ReadonlyTreeviewSnapshot | undefined): s ); } +interface TreeviewStoreSetup { + items: Ref; + selection: Ref; + activeItems: Ref; + opened_views: Ref; + panelWidth: Ref; + additionalPanelWidth: Ref; + isImporting: Ref; + pendingImports: Ref; + rowHeights: Ref; + hoveredModelId: Ref; + openedModelColor: (modelId: string) => string | undefined; + viewColor: (viewId: string) => string | undefined; + setHoveredModel: (id: string | undefined) => void; + addItem: ( + geodeObjectType: GeodeObjectType, + name: string, + dataId: DataId, + geodeId: GeodeId, + viewerObjectType: ViewerObjectType, + ) => void; + whilePendingImport: ( + geodeObjectType: GeodeObjectType, + filename: string, + conversion: Promise, + ) => Promise; + untilLoaded: (dataId: DataId, importing: Promise) => Promise; + removeItem: (dataId: DataId) => void; + renameItem: (dataId: DataId, newName: string) => void; + displayAdditionalTree: ( + id: string, + title: string | undefined, + geodeObjectType: GeodeObjectType, + ) => void; + displayPhysicalPropertiesTree: ( + modelId: string, + title: string | undefined, + geodeObjectType: GeodeObjectType | undefined, + ) => void; + closeView: (id: string) => void; + toggleView: (id: string) => void; + setCollapsed: (id: string, collapsed: boolean) => void; + toggleCollapsed: (id: string) => void; + setAllCollapsed: (collapsed: boolean) => void; + moveView: (fromIndex: number, toIndex: number) => void; + importStores: (snapshot: ReadonlyTreeviewSnapshot | undefined) => void; + displayFileTree: () => void; + setPanelWidth: (width: number) => void; + setAdditionalPanelWidth: (width: number) => void; + setScrollTop: (viewId: string, scrollTop: number) => void; + setOpened: (viewId: string, opened: readonly string[]) => void; + setRowHeights: (heights: readonly number[]) => void; + exportStores: () => Omit; + finalizeImportSelection: () => void; + clear: () => void; +} + // oxlint-disable-next-line max-lines-per-function, max-statements -export const useTreeviewStore = defineStore("treeview", () => { +function setupTreeviewStore(sceneId: SceneId): TreeviewStoreSetup { const items = ref([]); const selection = ref([]); const activeItems = ref([]); @@ -109,7 +166,7 @@ export const useTreeviewStore = defineStore("treeview", () => { async function loadConfig(): Promise { try { - const config = await treeviewConfigTable.get(INITIAL_SCENE_ID); + const config = await treeviewConfigTable.get(sceneId); if (config?.opened_views) { opened_views.value = withModelTreeColors(config.opened_views); } @@ -145,7 +202,7 @@ export const useTreeviewStore = defineStore("treeview", () => { // Best-effort persistence: a failure is logged, not thrown. try { await treeviewConfigTable.put({ - scene_id: INITIAL_SCENE_ID, + scene_id: sceneId, opened_views: clean_opened_views, panelWidth: panelWidth.value, additionalPanelWidth: additionalPanelWidth.value, @@ -521,6 +578,22 @@ export const useTreeviewStore = defineStore("treeview", () => { finalizeImportSelection, clear, }; -}); +} + +type TreeviewStoreDefinition = ReturnType>; + +// A scene keeps the store definition it was given first +const treeviewStoreDefinitions = new Map(); + +// Each scene has its own tree view: its items, opened views and selection +function useTreeviewStore(sceneId: SceneId): ReturnType { + let definition = treeviewStoreDefinitions.get(sceneId); + if (!definition) { + definition = defineStore(`treeview-${sceneId}`, () => setupTreeviewStore(sceneId)); + treeviewStoreDefinitions.set(sceneId, definition); + } + return definition(); +} +export { useTreeviewStore }; export type { TreeviewSnapshot }; diff --git a/tests/unit/stores/treeview.nuxt.test.ts b/tests/unit/stores/treeview.nuxt.test.ts index 6d2d534bf..8959ddd03 100644 --- a/tests/unit/stores/treeview.nuxt.test.ts +++ b/tests/unit/stores/treeview.nuxt.test.ts @@ -1,10 +1,13 @@ // Third party imports -import { beforeEach, describe, expect, expectTypeOf, test } from "vitest"; +import { beforeEach, describe, expect, expectTypeOf, test, vi } from "vitest"; // Local imports import { setupActivePinia } from "@ogw_tests/utils"; +import { treeviewConfigDb } from "@ogw_internal/database/database"; import { useTreeviewStore } from "@ogw_front/stores/treeview"; +const WIDER_PANEL = 400; + function sortByTitle(itemA: { title: string }, itemB: { title: string }): number { return itemA.title.localeCompare(itemB.title, undefined, { numeric: true, @@ -18,14 +21,14 @@ describe("treeview store state", () => { }); test("initial state", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); expectTypeOf(treeviewStore.items).toBeArray(); }); }); describe("treeview store actions", () => { test("addItem sorted check", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); const testItems = [ { geode_object_type: "BRep" as const, @@ -75,7 +78,7 @@ describe("treeview store actions", () => { }); function viewColor(id: string): string | undefined { - return useTreeviewStore().opened_views.find((view) => view.id === id)?.color; + return useTreeviewStore("scene_1").opened_views.find((view) => view.id === id)?.color; } describe("treeview store model tree link", () => { @@ -84,7 +87,7 @@ describe("treeview store model tree link", () => { }); test("each opened model tree gets its own color", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayAdditionalTree("a", "corbi", "BRep"); treeviewStore.displayAdditionalTree("b", "corbi", "BRep"); expect(viewColor("a")).toBeDefined(); @@ -93,7 +96,7 @@ describe("treeview store model tree link", () => { }); test("a color stays with its tree when another one closes", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayAdditionalTree("a", "corbi", "BRep"); treeviewStore.displayAdditionalTree("b", "corbi", "BRep"); const colorB = viewColor("b"); @@ -105,7 +108,7 @@ describe("treeview store model tree link", () => { }); test("model trees restored without a color get distinct ones", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.importStores({ opened_views: [ { type: "object", id: "main", title: "Objects", scrollTop: 0, opened: [] }, @@ -120,7 +123,7 @@ describe("treeview store model tree link", () => { }); test("hovered model is shared and cleared", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.setHoveredModel("a"); expect(treeviewStore.hoveredModelId).toBe("a"); treeviewStore.setHoveredModel(undefined); @@ -128,7 +131,7 @@ describe("treeview store model tree link", () => { }); test("closing a hovered view clears the hovered model", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayAdditionalTree("a", "corbi", "BRep"); treeviewStore.setHoveredModel("a"); treeviewStore.closeView("a"); @@ -136,7 +139,7 @@ describe("treeview store model tree link", () => { }); test("closing another view keeps the hovered model", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayAdditionalTree("a", "corbi", "BRep"); treeviewStore.setHoveredModel("b"); treeviewStore.closeView("a"); @@ -144,10 +147,35 @@ describe("treeview store model tree link", () => { }); test("removing a hovered data clears the hovered model", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.addItem("BRep", "corbi", "a", "geode-a", "model"); treeviewStore.setHoveredModel("a"); treeviewStore.removeItem("a"); expect(treeviewStore.hoveredModelId).toBeUndefined(); }); }); + +describe("treeview store per scene", () => { + beforeEach(() => { + setupActivePinia(); + }); + + test("opened views are kept per scene", () => { + useTreeviewStore("scene_1").displayAdditionalTree("a", "corbi", "BRep"); + expect(useTreeviewStore("scene_1").opened_views.map((view) => view.id)).toContain("a"); + expect(useTreeviewStore("scene_2").opened_views.map((view) => view.id)).not.toContain("a"); + }); + + test("each scene saves its own config row", async () => { + useTreeviewStore("scene_1").displayAdditionalTree("a", "corbi", "BRep"); + useTreeviewStore("scene_2").setPanelWidth(WIDER_PANEL); + await vi.waitFor(async () => { + const row1 = await treeviewConfigDb().get("scene_1"); + const row2 = await treeviewConfigDb().get("scene_2"); + expect(row1?.opened_views.map((view) => view.id)).toContain("a"); + expect(row2?.panelWidth).toBe(WIDER_PANEL); + }); + const row2 = await treeviewConfigDb().get("scene_2"); + expect(row2?.opened_views.map((view) => view.id)).not.toContain("a"); + }); +}); diff --git a/tests/unit/stores/treeview_model_trees.nuxt.test.ts b/tests/unit/stores/treeview_model_trees.nuxt.test.ts index 7a02108bb..8274df99a 100644 --- a/tests/unit/stores/treeview_model_trees.nuxt.test.ts +++ b/tests/unit/stores/treeview_model_trees.nuxt.test.ts @@ -6,7 +6,7 @@ import { setupActivePinia } from "@ogw_tests/utils"; import { useTreeviewStore } from "@ogw_front/stores/treeview"; function modelView(id: string): { collapsed?: boolean; opened: string[] } | undefined { - return useTreeviewStore().opened_views.find((view) => view.id === id); + return useTreeviewStore("scene_1").opened_views.find((view) => view.id === id); } describe("treeview store collapsed model tree", () => { @@ -15,7 +15,7 @@ describe("treeview store collapsed model tree", () => { }); test("collapsing a model tree keeps it open with its state", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayAdditionalTree("a", "corbi", "BRep"); treeviewStore.setOpened("a", ["Surface"]); treeviewStore.toggleCollapsed("a"); @@ -26,7 +26,7 @@ describe("treeview store collapsed model tree", () => { }); test("the row button closes a collapsed model tree", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayAdditionalTree("a", "corbi", "BRep"); treeviewStore.toggleCollapsed("a"); treeviewStore.displayAdditionalTree("a", "corbi", "BRep"); @@ -34,7 +34,7 @@ describe("treeview store collapsed model tree", () => { }); test("all the model trees collapse and show again at once", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayAdditionalTree("a", "corbi", "BRep"); treeviewStore.displayAdditionalTree("b", "cube", "BRep"); treeviewStore.toggleCollapsed("a"); @@ -48,7 +48,7 @@ describe("treeview store collapsed model tree", () => { }); test("model trees move among themselves, the objects tree stays first", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayAdditionalTree("a", "corbi", "BRep"); treeviewStore.displayAdditionalTree("b", "cube", "BRep"); treeviewStore.displayAdditionalTree("c", "test", "BRep"); @@ -70,7 +70,7 @@ describe("treeview store collapsed model tree", () => { }); test("the first model tree moves while the objects tree is closed", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayAdditionalTree("a", "corbi", "BRep"); treeviewStore.displayAdditionalTree("b", "cube", "BRep"); treeviewStore.toggleView("main"); @@ -79,7 +79,7 @@ describe("treeview store collapsed model tree", () => { }); test("a model tree is collapsed or shown explicitly", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayAdditionalTree("a", "corbi", "BRep"); treeviewStore.setCollapsed("a", true); treeviewStore.setCollapsed("a", true); diff --git a/tests/unit/stores/treeview_physical_properties.nuxt.test.ts b/tests/unit/stores/treeview_physical_properties.nuxt.test.ts index 529915e07..816d5072e 100644 --- a/tests/unit/stores/treeview_physical_properties.nuxt.test.ts +++ b/tests/unit/stores/treeview_physical_properties.nuxt.test.ts @@ -14,7 +14,7 @@ function view( ): | { type: string; model_id?: string; title: string; color?: string; collapsed?: boolean } | undefined { - return useTreeviewStore().opened_views.find((openedView) => openedView.id === id); + return useTreeviewStore("scene_1").opened_views.find((openedView) => openedView.id === id); } describe("treeview store physical properties tree", () => { @@ -23,7 +23,7 @@ describe("treeview store physical properties tree", () => { }); test("the physical properties of a model open in their own tree, closed by the same button", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayPhysicalPropertiesTree(MODEL_ID, "corbi", "BRep"); expect(view(PHYSICAL_PROPERTIES_VIEW_ID)).toMatchObject({ type: "physical_properties", @@ -37,7 +37,7 @@ describe("treeview store physical properties tree", () => { }); test("the trees of a model share its color, other models get another one", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayPhysicalPropertiesTree(MODEL_ID, "corbi", "BRep"); treeviewStore.displayAdditionalTree(OTHER_MODEL_ID, "cube", "BRep"); treeviewStore.displayAdditionalTree(MODEL_ID, "corbi", "BRep"); @@ -50,7 +50,7 @@ describe("treeview store physical properties tree", () => { }); test("it collapses with the model trees", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayAdditionalTree(MODEL_ID, "corbi", "BRep"); treeviewStore.displayPhysicalPropertiesTree(MODEL_ID, "corbi", "BRep"); treeviewStore.setAllCollapsed(true); @@ -59,7 +59,7 @@ describe("treeview store physical properties tree", () => { }); test("renaming the model renames both its trees", () => { - const treeviewStore = useTreeviewStore(); + const treeviewStore = useTreeviewStore("scene_1"); treeviewStore.displayAdditionalTree(MODEL_ID, "corbi", "BRep"); treeviewStore.displayPhysicalPropertiesTree(MODEL_ID, "corbi", "BRep"); treeviewStore.renameItem(MODEL_ID, "picasso"); From 5985dc8fc1d57d4d8996c42e71dd581d5ea3efa6 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:55:25 +0100 Subject: [PATCH 036/121] feat(scenes): keep the config row of the other scenes when one closes Co-Authored-By: Claude Opus 5.5 --- tests/unit/stores/scenes.nuxt.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/stores/scenes.nuxt.test.ts b/tests/unit/stores/scenes.nuxt.test.ts index a2ca0bde5..72c524781 100644 --- a/tests/unit/stores/scenes.nuxt.test.ts +++ b/tests/unit/stores/scenes.nuxt.test.ts @@ -191,15 +191,17 @@ describe("scenes store", () => { expect(fakeSceneStore("treeview", "scene_3").$dispose).toHaveBeenCalledWith(); }); - test("closeScene deletes the rows of the scene", async () => { + test("closeScene deletes the rows of the scene only", async () => { const scenesStore = useScenesStore(); await scenesStore.createScene("empty"); + await treeviewConfigDb().put({ ...TREEVIEW_CONFIG, scene_id: "scene_1" }); await treeviewConfigDb().put({ ...TREEVIEW_CONFIG, scene_id: "scene_2" }); await scenesStore.closeScene("scene_2"); expect(fakeSceneStore("dataStyle", "scene_2").clear).toHaveBeenCalledWith(); await expect(treeviewConfigDb().get("scene_2")).resolves.toBeUndefined(); + await expect(treeviewConfigDb().get("scene_1")).resolves.toBeDefined(); }); test("closeScene drops a link of one", async () => { From 4fcc71a0649ece3ef0c60ff655c8f3fc680b9ff3 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 15:55:25 +0100 Subject: [PATCH 037/121] feat(scenes): move import state to the scenes store isImporting, pendingImports and whilePendingImport are not specific to a scene: the scenes store exposes them, and drops a finished import from the selection of every scene. Co-Authored-By: Claude Opus 5.5 --- app/stores/scenes.ts | 2 + app/stores/treeview.ts | 45 ------------- internal/stores/scenes/import_state.ts | 67 ++++++++++++++++++++ tests/unit/stores/scenes_helpers.ts | 1 + tests/unit/stores/scenes_import.nuxt.test.ts | 48 ++++++++++++++ 5 files changed, 118 insertions(+), 45 deletions(-) create mode 100644 internal/stores/scenes/import_state.ts create mode 100644 tests/unit/stores/scenes_import.nuxt.test.ts diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index 2c78956d6..437ae43fa 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -23,6 +23,7 @@ import { import { joinLink, leaveLinks, linkedScenes } from "@ogw_internal/stores/scenes/links"; import { afterViewerReset } from "@ogw_front/composables/viewer_reset"; import { propagateToLinkedScenes } from "@ogw_internal/stores/scenes/camera_link"; +import { useImportState } from "@ogw_internal/stores/scenes/import_state"; import { useViewerStore } from "@ogw_front/stores/viewer"; const viewerSchemas = viewer_schemas.opengeodeweb_viewer.viewer; @@ -215,6 +216,7 @@ export const useScenesStore = defineStore("scenes", () => { links, lastUsedSceneId, counter, + ...useImportState(scenes), createScene, closeScene, addData, diff --git a/app/stores/treeview.ts b/app/stores/treeview.ts index 47f326827..bd261867a 100644 --- a/app/stores/treeview.ts +++ b/app/stores/treeview.ts @@ -33,11 +33,6 @@ interface TreeviewChild extends TreeNode, GeodeIdentified, GeodeObjectTyped, Vie loading?: boolean; } -// A file being imported: shown in its type group while the back-end converts it, before its data exist -interface PendingImport extends TreeNode, GeodeObjectTyped { - loading: true; -} - type TreeviewGroup = TreeGroup; interface TreeviewSnapshot { @@ -96,8 +91,6 @@ interface TreeviewStoreSetup { opened_views: Ref; panelWidth: Ref; additionalPanelWidth: Ref; - isImporting: Ref; - pendingImports: Ref; rowHeights: Ref; hoveredModelId: Ref; openedModelColor: (modelId: string) => string | undefined; @@ -110,11 +103,6 @@ interface TreeviewStoreSetup { geodeId: GeodeId, viewerObjectType: ViewerObjectType, ) => void; - whilePendingImport: ( - geodeObjectType: GeodeObjectType, - filename: string, - conversion: Promise, - ) => Promise; untilLoaded: (dataId: DataId, importing: Promise) => Promise; removeItem: (dataId: DataId) => void; renameItem: (dataId: DataId, newName: string) => void; @@ -154,9 +142,6 @@ function setupTreeviewStore(sceneId: SceneId): TreeviewStoreSetup { const opened_views = ref(defaultOpenedViews()); const panelWidth = ref(PANEL_WIDTH); const additionalPanelWidth = ref(PANEL_WIDTH); - const isImporting = ref(false); - const pendingImports = ref([]); - let lastPendingImport = 0; const pendingSelectionIds = ref([]); const rowHeights = ref([]); // Model hovered in the objects tree or on its model tree header: not saved @@ -281,32 +266,6 @@ function setupTreeviewStore(sceneId: SceneId): TreeviewStoreSetup { selection.value = [...selection.value, dataId]; } - function removePendingImport(id: string): void { - pendingImports.value = pendingImports.value.filter((pending) => pending.id !== id); - // Its type group shown or hidden as a whole may have selected it - if (selection.value.includes(id)) { - selection.value = selection.value.filter((selectionId) => selectionId !== id); - } - } - - // The file is listed in the tree, by its name, until its conversion is done - async function whilePendingImport( - geodeObjectType: GeodeObjectType, - filename: string, - conversion: Promise, - ): Promise { - lastPendingImport += 1; - const id = `pending-import-${lastPendingImport}`; - const title = filename.split("/").pop() ?? filename; - pendingImports.value.push({ id, title, geode_object_type: geodeObjectType, loading: true }); - try { - const result = await conversion; - return result; - } finally { - removePendingImport(id); - } - } - // Added as loading, a data stops loading once its import is done, or has failed async function untilLoaded(dataId: DataId, importing: Promise): Promise { try { @@ -473,7 +432,6 @@ function setupTreeviewStore(sceneId: SceneId): TreeviewStoreSetup { selection.value = []; activeItems.value = []; pendingSelectionIds.value = []; - pendingImports.value = []; opened_views.value = defaultOpenedViews(); } @@ -547,15 +505,12 @@ function setupTreeviewStore(sceneId: SceneId): TreeviewStoreSetup { opened_views, panelWidth, additionalPanelWidth, - isImporting, - pendingImports, rowHeights, hoveredModelId, openedModelColor, viewColor, setHoveredModel, addItem, - whilePendingImport, untilLoaded, removeItem, renameItem, diff --git a/internal/stores/scenes/import_state.ts b/internal/stores/scenes/import_state.ts new file mode 100644 index 000000000..8d532a1be --- /dev/null +++ b/internal/stores/scenes/import_state.ts @@ -0,0 +1,67 @@ +// Third party imports +import { type Ref, ref } from "vue"; + +// Local imports +import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; +import type { GeodeObjectTyped } from "@ogw_front/types/identifiers"; +import type { SceneRecord } from "./types"; +import type { TreeNode } from "@ogw_front/types/tree"; +import { useTreeviewStore } from "@ogw_front/stores/treeview"; + +// A file being imported: shown in its type group while the back-end converts it, before its data exist +interface PendingImport extends TreeNode, GeodeObjectTyped { + loading: true; +} + +interface ImportState { + isImporting: Ref; + pendingImports: Ref; + whilePendingImport: ( + geodeObjectType: GeodeObjectType, + filename: string, + conversion: Promise, + ) => Promise; +} + +// An import is not specific to a scene: it is listed in the tree of every scene, by the scenes store +function useImportState(scenes: Ref): ImportState { + const isImporting = ref(false); + const pendingImports = ref([]); + let lastPendingImport = 0; + + function removePendingImport(id: string): void { + pendingImports.value = pendingImports.value.filter((pending) => pending.id !== id); + // Its type group shown or hidden as a whole may have selected it + for (const scene of scenes.value) { + const treeviewStore = useTreeviewStore(scene.id); + if (treeviewStore.selection.includes(id)) { + treeviewStore.selection = treeviewStore.selection.filter( + (selectionId) => selectionId !== id, + ); + } + } + } + + // The file is listed in the tree, by its name, until its conversion is done + async function whilePendingImport( + geodeObjectType: GeodeObjectType, + filename: string, + conversion: Promise, + ): Promise { + lastPendingImport += 1; + const id = `pending-import-${lastPendingImport}`; + const title = filename.split("/").pop() ?? filename; + pendingImports.value.push({ id, title, geode_object_type: geodeObjectType, loading: true }); + try { + const result = await conversion; + return result; + } finally { + removePendingImport(id); + } + } + + return { isImporting, pendingImports, whilePendingImport }; +} + +export type { ImportState, PendingImport }; +export { useImportState }; diff --git a/tests/unit/stores/scenes_helpers.ts b/tests/unit/stores/scenes_helpers.ts index a321c4688..186a9c863 100644 --- a/tests/unit/stores/scenes_helpers.ts +++ b/tests/unit/stores/scenes_helpers.ts @@ -26,6 +26,7 @@ function fakeSceneStore(storeId: string, sceneId: string): Record void>(), zScale: 1, camera_options: {}, + selection: [], addItem: resolves(), removeItem: vi.fn<() => void>(), closeView: vi.fn<() => void>(), diff --git a/tests/unit/stores/scenes_import.nuxt.test.ts b/tests/unit/stores/scenes_import.nuxt.test.ts new file mode 100644 index 000000000..796dde147 --- /dev/null +++ b/tests/unit/stores/scenes_import.nuxt.test.ts @@ -0,0 +1,48 @@ +// Third party imports +import { beforeEach, describe, expect, test, vi } from "vitest"; + +// Local imports +import { setupActivePinia } from "@ogw_tests/utils"; +import { useScenesStore } from "@ogw_front/stores/scenes"; +import { useTreeviewStore } from "@ogw_front/stores/treeview"; + +vi.setConfig({ testTimeout: 10_000 }); + +describe("scenes store import state", () => { + beforeEach(() => { + setupActivePinia(); + useScenesStore().importStores({ + scenes: [{ id: "scene_1", name: "Scene 1", view_id: "view_scene_1" }], + contents: { scene_1: [] }, + links: [], + lastUsedSceneId: "scene_1", + counter: 1, + }); + }); + + test("whilePendingImport lists the file until its conversion is done", async () => { + const scenesStore = useScenesStore(); + const { promise, resolve } = Promise.withResolvers(); + + const importing = scenesStore.whilePendingImport("BRep", "/tmp/corbi.og_brep", promise); + + expect(scenesStore.pendingImports.map((pending) => pending.title)).toStrictEqual([ + "corbi.og_brep", + ]); + resolve("done"); + await expect(importing).resolves.toBe("done"); + expect(scenesStore.pendingImports).toStrictEqual([]); + }); + + test("a pending import is no longer selected once it is done", async () => { + const scenesStore = useScenesStore(); + const { promise, resolve } = Promise.withResolvers(); + const importing = scenesStore.whilePendingImport("BRep", "corbi.og_brep", promise); + useTreeviewStore("scene_1").selection = scenesStore.pendingImports.map((pending) => pending.id); + + resolve("done"); + await importing; + + expect(useTreeviewStore("scene_1").selection).toStrictEqual([]); + }); +}); From cd306e56bf4dae87303a8935b0c58274b8ecf0ef Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 16:11:15 +0100 Subject: [PATCH 038/121] feat(import): import a data into a given scene The data is registered once, then added through scenesStore.addData, which shows it in the scene and in the scenes linked to it on content. importFile, importFiles and importWorkflow take the target scene; the camera reset of an empty scene and the render target that scene. A project's data are added to the scenes that show them, from its contents. Co-Authored-By: Claude Opus 5.5 --- app/utils/import_item.ts | 125 +++++++++++------- app/utils/import_workflow.ts | 60 +++------ tests/unit/stores/scenes_helpers.ts | 34 +++-- tests/unit/utils/import_item.nuxt.test.ts | 62 +++++++++ tests/unit/utils/import_workflow.nuxt.test.ts | 38 ++++-- .../utils/import_workflow_crs.nuxt.test.ts | 35 +++-- .../utils/import_workflow_image.nuxt.test.ts | 28 ++-- .../utils/import_workflow_tree.nuxt.test.ts | 44 ++++-- 8 files changed, 285 insertions(+), 141 deletions(-) create mode 100644 tests/unit/utils/import_item.nuxt.test.ts diff --git a/app/utils/import_item.ts b/app/utils/import_item.ts index e7d9fdbf0..48c9767c6 100644 --- a/app/utils/import_item.ts +++ b/app/utils/import_item.ts @@ -1,11 +1,15 @@ +// Third party imports +import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; +import { consola } from "consola"; + // Local imports import { type LegacyDataId, fromLegacyDataId } from "@ogw_front/utils/legacy_data_id"; import { type NewDataItem, useDataStore } from "@ogw_front/stores/data"; +import type { SceneId } from "@ogw_internal/stores/scenes/types"; import { isModel } from "@ogw_front/utils/viewer_object_type"; -import { useDataStyleStore } from "@ogw_front/stores/data_style"; import { useFeedbackStore } from "@ogw_front/stores/feedback"; import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; -import { useTreeviewStore } from "@ogw_front/stores/treeview"; +import { useScenesStore } from "@ogw_front/stores/scenes"; // Steps that need the data stored first, and run only for the data the viewer shows async function registerWhenViewable(item: NewDataItem, added: Promise): Promise { @@ -17,26 +21,6 @@ async function registerWhenViewable(item: NewDataItem, added: Promise): return dataStore.registerObject(item.data_id, item.name ?? item.data_id); } -async function addToViewerWhenViewable( - item: NewDataItem, - added: Promise, -): Promise { - const dataStore = useDataStore(); - await added; - if (!(await dataStore.fetchIsViewable(item.data_id))) { - return undefined; - } - return useHybridViewerStore().addItem(item.data_id); -} - -async function applyStyleWhenReady(item: NewDataItem, ready: Promise): Promise { - await ready; - if (!(await useDataStore().fetchIsViewable(item.data_id))) { - return undefined; - } - return useDataStyleStore().applyDefaultStyle(item.data_id); -} - // Nothing waits for the relations and the physical properties of a model but the end of its import async function addModelDetails(item: NewDataItem): Promise { const dataStore = useDataStore(); @@ -48,12 +32,13 @@ async function addModelDetails(item: NewDataItem): Promise { return details; } +// The data is stored and registered in the viewer once, whichever scenes show it: the scenes then add it, with +// The model components their style needs // NewDataItem has mutable array fields (mesh_components, collection_components), so it can't // Satisfy prefer-readonly-parameter-types deeply; left unfixed (same pattern as app/plugins/auto_store_register.ts). -async function importDataItem(item: NewDataItem): Promise { +async function importDataItem(item: NewDataItem, sceneIds: readonly SceneId[]): Promise { const dataStore = useDataStore(); - const dataStyleStore = useDataStyleStore(); - const treeviewStore = useTreeviewStore(); + const scenesStore = useScenesStore(); if (item.nb_vertices === 0) { const feedbackStore = useFeedbackStore(); feedbackStore.add_warning(`"${item.geode_object_type}" with name "${item.name}" is empty`); @@ -66,34 +51,80 @@ async function importDataItem(item: NewDataItem): Promise { addDataComponentsTask = dataStore.addComponents(item); addModelDetailsTask = addModelDetails(item); } - treeviewStore.addItem( - item.geode_object_type, - item.name ?? item.data_id, - item.data_id, - item.geode_id, - item.viewer_object_type, - ); - const addDataStyleTask = dataStyleStore.addDataStyle(item.data_id, item.geode_object_type); - const addViewerTask = addToViewerWhenViewable(item, addDataTask); - const applyStyleTask = applyStyleWhenReady( - item, - Promise.all([registerTask, addDataComponentsTask, addDataStyleTask]), - ); + await Promise.all([addDataTask, registerTask, addDataComponentsTask]); await Promise.all([ - registerTask, - addDataTask, - addDataComponentsTask, addModelDetailsTask, - addViewerTask, - applyStyleTask, + ...sceneIds.map(async (sceneId) => { + await scenesStore.addData(sceneId, item.data_id); + }), ]); return item.data_id; } + // Every item comes through here: from the back-end, which still names its data id `id`, or from a project -async function importItem(imported: LegacyDataId | NewDataItem): Promise { - const item = fromLegacyDataId(imported); - const dataId = await useTreeviewStore().untilLoaded(item.data_id, importDataItem(item)); +async function importItemToScenes( + imported: LegacyDataId | NewDataItem, + sceneIds: readonly SceneId[], +): Promise { + const dataId = await importDataItem(fromLegacyDataId(imported), sceneIds); + return dataId; +} + +// An imported data is new: it shows in the scene, and in the scenes linked to it on content +async function importItem( + imported: LegacyDataId | NewDataItem, + sceneId: SceneId, +): Promise { + const dataId = await importItemToScenes(imported, [sceneId]); return dataId; } -export { importItem }; +// The scenes that show a data, from the contents of a project +function scenesShowing( + contents: Readonly>, + dataId: DataId, +): SceneId[] { + return Object.keys(contents).filter((sceneId) => (contents[sceneId] ?? []).includes(dataId)); +} + +// Each data is registered once, then added to the scenes that show it in the project +// NewDataItem has mutable array fields (mesh_components, collection_components), so a readonly array of it can't satisfy prefer-readonly-parameter-types deeply; left unfixed (same pattern as app/plugins/auto_store_register.ts). +async function importWorkflowFromSnapshot( + items: readonly (LegacyDataId | NewDataItem)[], + contents: Readonly>, +): Promise { + consola.debug("[importWorkflowFromSnapshot] start", { count: items?.length }); + const chunk_size = 5; + const chunks: (LegacyDataId | NewDataItem)[][] = []; + for (let i = 0; i < items.length; i += chunk_size) { + chunks.push(items.slice(i, i + chunk_size)); + } + const ids: string[] = []; + async function processChunk(chunkIndex: number): Promise { + if (chunkIndex >= chunks.length) { + return; + } + const chunk = chunks[chunkIndex] ?? []; + const chunk_ids = await Promise.all( + chunk.map(async (item) => { + const { data_id } = fromLegacyDataId(item); + const dataId = await importItemToScenes(item, scenesShowing(contents, data_id)); + return dataId; + }), + ); + ids.push(...chunk_ids); + await processChunk(chunkIndex + 1); + } + await processChunk(0); + await Promise.all( + Object.keys(contents).map(async (sceneId) => { + await useHybridViewerStore(sceneId).remoteRender(); + }), + ); + consola.debug("[importWorkflowFromSnapshot] done", { + ids, + }); + return ids; +} + +export { importItem, importWorkflowFromSnapshot }; diff --git a/app/utils/import_workflow.ts b/app/utils/import_workflow.ts index 0311be983..59aa4c185 100644 --- a/app/utils/import_workflow.ts +++ b/app/utils/import_workflow.ts @@ -4,6 +4,7 @@ import { consola } from "consola"; // Local imports import { type NewDataItem, useDataStore } from "@ogw_front/stores/data"; +import { type SceneId, useScenesStore } from "@ogw_front/stores/scenes"; import type { CRS } from "@geode/opengeodeweb-back/schema_types"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types"; @@ -15,19 +16,22 @@ import { useBackStore } from "@ogw_front/stores/back"; import { useCrsStore } from "@ogw_front/stores/crs"; import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; import { useProjectCrs } from "@ogw_front/composables/project_crs"; -import { useTreeviewStore } from "@ogw_front/stores/treeview"; interface FileToImport extends Readonly { readonly filename: string; } // A single file can hold several objects: every one of them is imported, ids are returned in the response order -async function importFile(filename: string, geode_object_type: GeodeObjectType): Promise { +async function importFile( + filename: string, + geode_object_type: GeodeObjectType, + sceneId: SceneId, +): Promise { const backStore = useBackStore(); const schema = back_schemas.opengeodeweb_back.save_viewable_file; const params = { geode_object_type, filename }; // The conversion can be long: the file shows in the tree meanwhile, then is replaced by its objects - const response = await useTreeviewStore().whilePendingImport( + const response = await useScenesStore().whilePendingImport( geode_object_type, filename, backStore.request({ schema, params }), @@ -36,15 +40,15 @@ async function importFile(filename: string, geode_object_type: GeodeObjectType): const items = response.data as LegacyDataId[]; const dataIds = await Promise.all( items.map(async (item) => { - const dataId = await importItem(item); + const dataId = await importItem(item, sceneId); return dataId; }), ); return dataIds; } -async function importFiles(files: readonly FileToImport[]): Promise { - const hybridViewerStore = useHybridViewerStore(); +async function importFiles(files: readonly FileToImport[], sceneId: SceneId): Promise { + const hybridViewerStore = useHybridViewerStore(sceneId); // Files are imported concurrently and the viewer only frames the first actor to arrive, so the camera is reset once everything is loaded const wasSceneEmpty = Object.keys(hybridViewerStore.hybridDb).length === 0; const chunk_size = 5; @@ -63,7 +67,7 @@ async function importFiles(files: readonly FileToImport[]): Promise { // A failing file does not prevent the other files from being imported const chunk_results = await Promise.allSettled( chunk.map(async ({ filename, geode_object_type }) => { - const dataIds = await importFile(filename, geode_object_type); + const dataIds = await importFile(filename, geode_object_type, sceneId); return dataIds; }), ); @@ -99,12 +103,12 @@ async function harmonize(ids: string[], projectCrs: CRS | undefined): Promise { +async function importWorkflow(files: readonly FileToImport[], sceneId: SceneId): Promise { const { projectCrs } = useCrsStore(); const existingItems = await useDataStore().allItems(); const existingIds = new Set(existingItems.map((item) => item.data_id)); try { - const ids = await importFiles(files); + const ids = await importFiles(files, sceneId); return ids; } finally { const items = await useDataStore().allItems(); @@ -114,40 +118,6 @@ async function importWorkflow(files: readonly FileToImport[]): Promise } } -// NewDataItem has mutable array fields (mesh_components, collection_components), so a readonly array of it can't satisfy prefer-readonly-parameter-types deeply; left unfixed (same pattern as app/plugins/auto_store_register.ts). -async function importWorkflowFromSnapshot( - items: readonly (LegacyDataId | NewDataItem)[], -): Promise { - consola.debug("[importWorkflowFromSnapshot] start", { count: items?.length }); - const hybridViewerStore = useHybridViewerStore(); - const chunk_size = 5; - const chunks: (LegacyDataId | NewDataItem)[][] = []; - for (let i = 0; i < items.length; i += chunk_size) { - chunks.push(items.slice(i, i + chunk_size)); - } - const ids: string[] = []; - async function processChunk(chunkIndex: number): Promise { - if (chunkIndex >= chunks.length) { - return; - } - const chunk = chunks[chunkIndex] ?? []; - const chunk_ids = await Promise.all( - chunk.map(async (item) => { - const dataId = await importItem(item); - return dataId; - }), - ); - ids.push(...chunk_ids); - await processChunk(chunkIndex + 1); - } - await processChunk(0); - await hybridViewerStore.remoteRender(); - consola.debug("[importWorkflowFromSnapshot] done", { - ids, - }); - return ids; -} - // The time series only adds attributes to the model, so the viewer object is reloaded. async function applyTimeSeriesWorkflow(filename: string, dataId: DataId): Promise { const backStore = useBackStore(); @@ -159,6 +129,6 @@ async function applyTimeSeriesWorkflow(filename: string, dataId: DataId): Promis return dataId; } -export { importFile, importWorkflow, importWorkflowFromSnapshot, applyTimeSeriesWorkflow }; -export { importItem } from "@ogw_front/utils/import_item"; +export { importFile, importWorkflow, applyTimeSeriesWorkflow }; +export { importItem, importWorkflowFromSnapshot } from "@ogw_front/utils/import_item"; export { reloadObject } from "@ogw_front/utils/reload_object"; diff --git a/tests/unit/stores/scenes_helpers.ts b/tests/unit/stores/scenes_helpers.ts index 186a9c863..d6447e649 100644 --- a/tests/unit/stores/scenes_helpers.ts +++ b/tests/unit/stores/scenes_helpers.ts @@ -70,16 +70,32 @@ function sentTo(request: Mock, schema: { $id: string }): unknown[] { .map(([sent]) => sent.params.scene_id); } -// The data is registered in the viewer: the deletion from the project is spied +const DATA_ITEM = { + data_id: DATA_ID, + name: "data", + geode_id: "geode", + geode_object_type: "PointSet3D", + viewer_object_type: "mesh", +} as const; + +// The data is stored and registered in the viewer: the deletion from the project is spied function mockData(): { deleteItem: Mock<(dataId: string) => Promise> } { const dataStore = useDataStore(); - const item = { - data_id: DATA_ID, - name: "data", - geode_id: "geode", - geode_object_type: "PointSet3D", - viewer_object_type: "mesh", - }; + const item = DATA_ITEM; + dataStore.addItem = mockAs( + vi.fn<() => Promise>(async () => { + await Promise.resolve(); + return DATA_ID; + }), + ); + dataStore.fetchIsViewable = mockAs( + vi.fn<() => Promise>(async () => { + await Promise.resolve(); + return true; + }), + ); + dataStore.registerObject = mockAs(resolves()); + dataStore.importStores = mockAs(resolves()); dataStore.item = mockAs( vi.fn<() => Promise>(async () => { await Promise.resolve(); @@ -99,5 +115,5 @@ function mockData(): { deleteItem: Mock<(dataId: string) => Promise> } { return { deleteItem }; } -export { DATA_ID, fakeSceneStore, fakeStores, mockData, mockViewer, sentTo }; +export { DATA_ID, DATA_ITEM, fakeSceneStore, fakeStores, mockData, mockViewer, sentTo }; export type { Request }; diff --git a/tests/unit/utils/import_item.nuxt.test.ts b/tests/unit/utils/import_item.nuxt.test.ts new file mode 100644 index 000000000..47fd289f3 --- /dev/null +++ b/tests/unit/utils/import_item.nuxt.test.ts @@ -0,0 +1,62 @@ +// Third party imports +import { beforeEach, describe, expect, test, vi } from "vitest"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; + +// Local imports +import { + DATA_ID, + DATA_ITEM, + fakeStores, + mockData, + mockViewer, + sentTo, +} from "@ogw_tests/unit/stores/scenes_helpers"; +import { importItem } from "@ogw_front/utils/import_item"; +import { setupActivePinia } from "@ogw_tests/utils"; +import { useScenesStore } from "@ogw_front/stores/scenes"; + +vi.setConfig({ testTimeout: 10_000 }); + +vi.mock(import("@ogw_front/stores/data_style") as Promise, async () => { + const helpers = await import("@ogw_tests/unit/stores/scenes_helpers"); + return { + useDataStyleStore: (sceneId: string): Record => + helpers.fakeSceneStore("dataStyle", sceneId), + }; +}); +vi.mock(import("@ogw_front/stores/hybrid_viewer") as Promise, async () => { + const helpers = await import("@ogw_tests/unit/stores/scenes_helpers"); + return { + useHybridViewerStore: (sceneId: string): Record => + helpers.fakeSceneStore("hybridViewer", sceneId), + }; +}); +vi.mock(import("@ogw_front/stores/treeview") as Promise, async () => { + const helpers = await import("@ogw_tests/unit/stores/scenes_helpers"); + return { + useTreeviewStore: (sceneId: string): Record => + helpers.fakeSceneStore("treeview", sceneId), + }; +}); + +const { viewer } = viewer_schemas.opengeodeweb_viewer; + +describe("import item", () => { + beforeEach(() => { + setupActivePinia(); + fakeStores.clear(); + }); + + test("importItem adds the data to the given scene only", async () => { + const request = mockViewer(); + mockData(); + const scenesStore = useScenesStore(); + await scenesStore.createScene("empty"); + await scenesStore.createScene("duplicate", "scene_1"); + + await importItem({ ...DATA_ITEM }, "scene_2"); + + expect(scenesStore.contents).toStrictEqual({ scene_1: [], scene_2: [DATA_ID] }); + expect(sentTo(request, viewer.add_to_scene)).toStrictEqual(["scene_2"]); + }); +}); diff --git a/tests/unit/utils/import_workflow.nuxt.test.ts b/tests/unit/utils/import_workflow.nuxt.test.ts index 1c2dde5d9..a282f7779 100644 --- a/tests/unit/utils/import_workflow.nuxt.test.ts +++ b/tests/unit/utils/import_workflow.nuxt.test.ts @@ -14,9 +14,18 @@ import { useBackStore } from "@ogw_front/stores/back"; import { useDataStore } from "@ogw_front/stores/data"; import { useDataStyleStore } from "@ogw_front/stores/data_style"; import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; +import { useScenesStore } from "@ogw_front/stores/scenes"; vi.setConfig({ testTimeout: 10_000 }); +// Scene 1 is shown, without asking the viewer +function showScene(): void { + useScenesStore().$patch((state) => { + state.scenes = [{ id: "scene_1", name: "Scene 1", view_id: "view_scene_1" }]; + state.contents = { scene_1: [] }; + }); +} + function setup(): { calls: string[]; request: Mock; @@ -25,11 +34,12 @@ function setup(): { remoteRender: Mock; addHybridItem: Mock; } { + showScene(); const calls: string[] = []; const backStore = useBackStore(); const dataStore = useDataStore(); - const dataStyleStore = useDataStyleStore(); - const hybridViewerStore = useHybridViewerStore(); + const dataStyleStore = useDataStyleStore("scene_1"); + const hybridViewerStore = useHybridViewerStore("scene_1"); const request = vi.fn().mockResolvedValue({ id: "brep_id", viewer_object_type: "model" }); const applyDefaultStyle = vi.fn().mockImplementation(() => { calls.push("style"); @@ -127,10 +137,13 @@ describe("import workflow", () => { ); await expect( - importWorkflow([ - { filename: "broken.vtu", geode_object_type: "TetrahedralSolid3D" }, - { filename: "model.og_brep", geode_object_type: "BRep" }, - ]), + importWorkflow( + [ + { filename: "broken.vtu", geode_object_type: "TetrahedralSolid3D" }, + { filename: "model.og_brep", geode_object_type: "BRep" }, + ], + "scene_1", + ), ).rejects.toThrow("1 file(s) could not be imported"); expect(dataStore.addItem).toHaveBeenCalledWith( expect.objectContaining({ data_id: "model.og_brep" }), @@ -154,10 +167,13 @@ describe("import workflow", () => { vi.fn().mockResolvedValue(false), ); - const ids = await importWorkflow([ - { filename: "first.vtu", geode_object_type: "TetrahedralSolid3D" }, - { filename: "second.vtu", geode_object_type: "TetrahedralSolid3D" }, - ]); + const ids = await importWorkflow( + [ + { filename: "first.vtu", geode_object_type: "TetrahedralSolid3D" }, + { filename: "second.vtu", geode_object_type: "TetrahedralSolid3D" }, + ], + "scene_1", + ); expect(ids).toStrictEqual(["first_a", "first_b", "second"]); }); @@ -180,7 +196,7 @@ describe("import file", () => { vi.fn().mockResolvedValue(false), ); - const ids = await importFile("several.vtp", "PolygonalSurface3D"); + const ids = await importFile("several.vtp", "PolygonalSurface3D", "scene_1"); expect(ids).toStrictEqual(["surface", "curve"]); expect(dataStore.addItem).toHaveBeenCalledWith(expect.objectContaining({ data_id: "surface" })); diff --git a/tests/unit/utils/import_workflow_crs.nuxt.test.ts b/tests/unit/utils/import_workflow_crs.nuxt.test.ts index 6d4835ac0..ab30d5f6f 100644 --- a/tests/unit/utils/import_workflow_crs.nuxt.test.ts +++ b/tests/unit/utils/import_workflow_crs.nuxt.test.ts @@ -12,6 +12,7 @@ import { useDataStyleStore } from "@ogw_front/stores/data_style"; import { useFeedbackStore } from "@ogw_front/stores/feedback"; import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; import type { useProjectCrs } from "@ogw_front/composables/project_crs"; +import { useScenesStore } from "@ogw_front/stores/scenes"; interface ProjectCrsModule { useProjectCrs: typeof useProjectCrs; @@ -19,6 +20,14 @@ interface ProjectCrsModule { vi.setConfig({ testTimeout: 10_000 }); +// Scene 1 is shown, without asking the viewer +function showScene(): void { + useScenesStore().$patch((state) => { + state.scenes = [{ id: "scene_1", name: "Scene 1", view_id: "view_scene_1" }]; + state.contents = { scene_1: [] }; + }); +} + const harmonizeImportedCrs = vi.hoisted(() => vi.fn()); vi.mock(import("@ogw_front/composables/project_crs"), () => ({ useProjectCrs: vi.fn().mockReturnValue({ harmonizeImportedCrs, adoptProjectCrs: vi.fn() }), @@ -32,11 +41,12 @@ function setup(): { remoteRender: Mock; addHybridItem: Mock; } { + showScene(); const calls: string[] = []; const backStore = useBackStore(); const dataStore = useDataStore(); - const dataStyleStore = useDataStyleStore(); - const hybridViewerStore = useHybridViewerStore(); + const dataStyleStore = useDataStyleStore("scene_1"); + const hybridViewerStore = useHybridViewerStore("scene_1"); const request = vi.fn().mockResolvedValue({ id: "brep_id", viewer_object_type: "model" }); const applyDefaultStyle = vi.fn().mockImplementation(() => { calls.push("style"); @@ -100,7 +110,10 @@ describe("import workflow crs harmonization", () => { const crs = { authority: "EPSG", code: "2193", name: "NZGD2000" }; useCrsStore().projectCrs = crs; - await importWorkflow([{ filename: "new.vtu", geode_object_type: "TetrahedralSolid3D" }]); + await importWorkflow( + [{ filename: "new.vtu", geode_object_type: "TetrahedralSolid3D" }], + "scene_1", + ); expect(harmonizeImportedCrs).toHaveBeenCalledExactlyOnceWith(["new"], crs); }); @@ -113,10 +126,13 @@ describe("import workflow crs harmonization", () => { stubData([], ["ok"]); await expect( - importWorkflow([ - { filename: "ok.vtu", geode_object_type: "TetrahedralSolid3D" }, - { filename: "broken.vtu", geode_object_type: "TetrahedralSolid3D" }, - ]), + importWorkflow( + [ + { filename: "ok.vtu", geode_object_type: "TetrahedralSolid3D" }, + { filename: "broken.vtu", geode_object_type: "TetrahedralSolid3D" }, + ], + "scene_1", + ), ).rejects.toThrow("1 file(s) could not be imported"); expect(harmonizeImportedCrs).toHaveBeenCalledWith(["ok"], undefined); @@ -132,7 +148,10 @@ describe("import workflow crs harmonization", () => { harmonizeImportedCrs.mockImplementation(actual.useProjectCrs().harmonizeImportedCrs); const addSnackbar = vi.spyOn(useFeedbackStore(), "add_warning"); - await importWorkflow([{ filename: "new.vtu", geode_object_type: "TetrahedralSolid3D" }]); + await importWorkflow( + [{ filename: "new.vtu", geode_object_type: "TetrahedralSolid3D" }], + "scene_1", + ); await vi.waitFor(() => { expect(harmonizeImportedCrs).toHaveBeenCalledExactlyOnceWith(["new"], undefined); }); diff --git a/tests/unit/utils/import_workflow_image.nuxt.test.ts b/tests/unit/utils/import_workflow_image.nuxt.test.ts index 83210efa0..04bd71ddb 100644 --- a/tests/unit/utils/import_workflow_image.nuxt.test.ts +++ b/tests/unit/utils/import_workflow_image.nuxt.test.ts @@ -13,16 +13,25 @@ import { mockAs, setupActivePinia } from "@ogw_tests/utils"; import { importFile } from "@ogw_front/utils/import_workflow"; import { useBackStore } from "@ogw_front/stores/back"; import { useDataStore } from "@ogw_front/stores/data"; -import { useDataStyleStore } from "@ogw_front/stores/data_style"; import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; +import { useScenesStore } from "@ogw_front/stores/scenes"; vi.setConfig({ testTimeout: 10_000 }); +// Scene 1 is shown, without asking the viewer +function showScene(): void { + useScenesStore().$patch((state) => { + state.scenes = [{ id: "scene_1", name: "Scene 1", view_id: "view_scene_1" }]; + state.contents = { scene_1: [] }; + }); +} + const image_schemas = viewer_schemas.opengeodeweb_viewer.image; describe("import file of a raster image", () => { test.each(IMAGE_TYPES)("a %s is styled as an image", async (geode_object_type) => { setupActivePinia(); + showScene(); const imageId = crypto.randomUUID(); const image = { id: imageId, @@ -39,21 +48,20 @@ describe("import file of a raster image", () => { dataStore.item = mockAs( vi.fn<() => Promise>().mockResolvedValue({ ...image, data_id: imageId }), ); - // The viewer registration takes long enough for the default style to be stored - const dataStyleStore = useDataStyleStore(); - const registerObject = vi.fn<() => Promise>(async () => { - await vi.waitFor(() => { - expect(dataStyleStore.styles[imageId]).toBeDefined(); - }); - }); + const registerObject = vi.fn<() => Promise>().mockResolvedValue(); dataStore.registerObject = mockAs(registerObject); - const hybridViewerStore = useHybridViewerStore(); + dataStore.isRegistered = mockAs( + vi.fn<() => boolean>().mockReturnValue(true), + ); + const hybridViewerStore = useHybridViewerStore("scene_1"); const addItem = vi.fn<() => Promise>().mockResolvedValue(); hybridViewerStore.addItem = mockAs(addItem); mockHybridVisibility(); const request = mockViewer(); - await expect(importFile("image.og_img2d", geode_object_type)).resolves.toStrictEqual([imageId]); + await expect(importFile("image.og_img2d", geode_object_type, "scene_1")).resolves.toStrictEqual( + [imageId], + ); const schemas = sentRequests(request).map(({ schema }) => schema); expect(registerObject).toHaveBeenCalledWith(imageId, "image"); diff --git a/tests/unit/utils/import_workflow_tree.nuxt.test.ts b/tests/unit/utils/import_workflow_tree.nuxt.test.ts index eae29f41f..ae30453f6 100644 --- a/tests/unit/utils/import_workflow_tree.nuxt.test.ts +++ b/tests/unit/utils/import_workflow_tree.nuxt.test.ts @@ -9,17 +9,29 @@ import { useBackStore } from "@ogw_front/stores/back"; import { useDataStore } from "@ogw_front/stores/data"; import { useDataStyleStore } from "@ogw_front/stores/data_style"; import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; +import { useScenesStore } from "@ogw_front/stores/scenes"; import { useTreeviewStore } from "@ogw_front/stores/treeview"; +import { useViewerStore } from "@ogw_front/stores/viewer"; vi.setConfig({ testTimeout: 10_000 }); +// Scene 1 is shown, without asking the viewer +function showScene(): void { + useScenesStore().$patch((state) => { + state.scenes = [{ id: "scene_1", name: "Scene 1", view_id: "view_scene_1" }]; + state.contents = { scene_1: [] }; + }); +} + const SURFACE = { id: "surface", name: "surface", viewer_object_type: "mesh" }; +// The data are registered in the viewer, which shows them in the scene function setup(): { request: Mock; addHybridItem: Mock } { + showScene(); const backStore = useBackStore(); const dataStore = useDataStore(); - const dataStyleStore = useDataStyleStore(); - const hybridViewerStore = useHybridViewerStore(); + const dataStyleStore = useDataStyleStore("scene_1"); + const hybridViewerStore = useHybridViewerStore("scene_1"); const request = vi.fn().mockResolvedValue({ data: [SURFACE] }); const addHybridItem = vi.fn(); backStore.request = mockAs(request); @@ -28,6 +40,15 @@ function setup(): { request: Mock; addHybridItem: Mock } { vi.fn().mockResolvedValue(true), ); dataStore.registerObject = mockAs(vi.fn()); + dataStore.isRegistered = mockAs(vi.fn().mockReturnValue(true)); + dataStore.item = mockAs( + vi.fn(async (data_id: string) => { + await Promise.resolve(); + return { ...SURFACE, data_id, geode_object_type: "PolygonalSurface3D" }; + }), + ); + const viewerStore = useViewerStore(); + viewerStore.request = mockAs(vi.fn().mockResolvedValue(undefined)); dataStyleStore.addDataStyle = mockAs(vi.fn()); dataStyleStore.applyDefaultStyle = mockAs(vi.fn()); hybridViewerStore.addItem = mockAs(addHybridItem); @@ -35,7 +56,7 @@ function setup(): { request: Mock; addHybridItem: Mock } { } function isLoading(dataId: string): boolean | undefined { - return useTreeviewStore() + return useTreeviewStore("scene_1") .items.flatMap((group) => group.children) .find((child) => child.id === dataId)?.loading; } @@ -45,13 +66,12 @@ describe("import progress in the object tree", () => { test("shows the file as pending in the tree until its objects arrive", async () => { const { request } = setup(); - const treeviewStore = useTreeviewStore(); const { promise, resolve } = Promise.withResolvers(); request.mockReturnValueOnce(promise); - const importing = importFile("folder/surface.vtp", "PolygonalSurface3D"); + const importing = importFile("folder/surface.vtp", "PolygonalSurface3D", "scene_1"); - expect(treeviewStore.pendingImports).toStrictEqual([ + expect(useScenesStore().pendingImports).toStrictEqual([ expect.objectContaining({ title: "surface.vtp", geode_object_type: "PolygonalSurface3D", @@ -60,17 +80,17 @@ describe("import progress in the object tree", () => { ]); resolve({ data: [SURFACE] }); await importing; - expect(treeviewStore.pendingImports).toStrictEqual([]); + expect(useScenesStore().pendingImports).toStrictEqual([]); }); test("the pending file leaves the tree when its conversion fails", async () => { const { request } = setup(); request.mockRejectedValueOnce(new Error("conversion failed")); - await expect(importFile("broken.vtp", "PolygonalSurface3D")).rejects.toThrow( + await expect(importFile("broken.vtp", "PolygonalSurface3D", "scene_1")).rejects.toThrow( "conversion failed", ); - expect(useTreeviewStore().pendingImports).toStrictEqual([]); + expect(useScenesStore().pendingImports).toStrictEqual([]); }); test("an object shows as loading until it is in the viewer", async () => { @@ -81,7 +101,7 @@ describe("import progress in the object tree", () => { loadingStates.push(isLoading("slow_surface")); }); - await importFile("surface.vtp", "PolygonalSurface3D"); + await importFile("surface.vtp", "PolygonalSurface3D", "scene_1"); expect(loadingStates).toStrictEqual([true]); expect(isLoading("slow_surface")).toBe(false); @@ -92,7 +112,9 @@ describe("import progress in the object tree", () => { request.mockResolvedValueOnce({ data: [{ ...SURFACE, id: "broken_surface" }] }); addHybridItem.mockRejectedValueOnce(new Error("viewer failed")); - await expect(importFile("surface.vtp", "PolygonalSurface3D")).rejects.toThrow("viewer failed"); + await expect(importFile("surface.vtp", "PolygonalSurface3D", "scene_1")).rejects.toThrow( + "viewer failed", + ); expect(isLoading("broken_surface")).toBe(false); }); }); From f2bf483a4eed173822a91751ffeaf9ecd260b5c6 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 16:11:28 +0100 Subject: [PATCH 039/121] feat(project): export every scene's stores Each scene's stores are saved under their own id by the registry. The style rows are saved without their scene id: the snapshot key names the scene, and an import writes them under the importing scene. Co-Authored-By: Claude Opus 5.5 --- app/stores/data_style.ts | 22 ++++++++++++++++++---- tests/unit/stores/data_style.nuxt.test.ts | 5 ++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/stores/data_style.ts b/app/stores/data_style.ts index 9c67aca1d..bea1d834f 100644 --- a/app/stores/data_style.ts +++ b/app/stores/data_style.ts @@ -38,6 +38,20 @@ function isRecord(value: unknown): value is Record { return typeof value === "object" && value !== null; } +// The rows of a scene are saved without its id: the snapshot key names the scene, and an import writes them under +// The importing scene +function withoutSceneId(row: Row): Row { + const copy = { ...toRaw(row) }; + Reflect.deleteProperty(copy, "scene_id"); + return copy; +} + +function rowsWithoutSceneId(rows: Record): Record { + return Object.fromEntries( + Object.entries(toRaw(rows)).map(([key, row]) => [key, withoutSceneId(row)]), + ); +} + interface DataStyleStoreActions { addDataStyle: (dataId: DataId, geodeObjectType: GeodeObjectType) => Promise; applyDefaultStyle: (dataId: DataId) => Promise; @@ -116,10 +130,10 @@ function setupDataStyleStore(sceneId: SceneId): DataStyleStoreSetup { function exportStores(): DataStyleSnapshot { return { - styles: dataStyleState.styles.value, - componentStyles: dataStyleState.componentStyles.value, - modelComponentTypeStyles: dataStyleState.modelComponentTypeStyles.value, - sceneStyle: dataStyleState.sceneStyle.value, + styles: rowsWithoutSceneId(dataStyleState.styles.value), + componentStyles: rowsWithoutSceneId(dataStyleState.componentStyles.value), + modelComponentTypeStyles: rowsWithoutSceneId(dataStyleState.modelComponentTypeStyles.value), + sceneStyle: withoutSceneId(dataStyleState.sceneStyle.value), }; } diff --git a/tests/unit/stores/data_style.nuxt.test.ts b/tests/unit/stores/data_style.nuxt.test.ts index 80d2e0f29..2fdf508e3 100644 --- a/tests/unit/stores/data_style.nuxt.test.ts +++ b/tests/unit/stores/data_style.nuxt.test.ts @@ -98,9 +98,12 @@ describe("data style store by scene", () => { const sourceColor = source.meshPointsColor(meshId); const copy = useDataStyleStore("scene_3"); - await copy.importStores(source.exportStores()); + const exported = source.exportStores(); + await copy.importStores(exported); await copy.setMeshPointsColor(meshId, RED); + // The snapshot is not tied to the scene it comes from + expect(exported.styles[meshId]).not.toHaveProperty("scene_id"); expect(source.meshPointsColor(meshId)).toStrictEqual(sourceColor); await expect(storedStyle("scene_1", meshId)).resolves.toMatchObject({ scene_id: "scene_1", From 3f071abf23a66022436d72c7b0c001f39d2419a9 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 16:11:55 +0100 Subject: [PATCH 040/121] feat(project): reset every scene on project reset The project reset goes through scenesStore.resetScenes: the viewer scenes are reset and scene_1 is created again with the app colours, instead of resetting a single scene. Clearing the scenes store also forgets the pending imports. Co-Authored-By: Claude Opus 5.5 --- .../project_manager_helpers/reset.ts | 17 +++----------- app/stores/scenes.ts | 22 +++++-------------- internal/stores/scenes/scene_stores.ts | 17 +++++++++++++- tests/unit/stores/scenes_import.nuxt.test.ts | 12 ++++++++++ 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/app/composables/project_manager_helpers/reset.ts b/app/composables/project_manager_helpers/reset.ts index b54bafb9c..450466911 100644 --- a/app/composables/project_manager_helpers/reset.ts +++ b/app/composables/project_manager_helpers/reset.ts @@ -1,34 +1,23 @@ -import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; - -import { afterViewerReset } from "@ogw_front/composables/viewer_reset"; import { releaseViewerDatabase } from "@ogw_front/composables/project_manager_helpers/viewer_session"; import { useBasemapStore } from "@ogw_front/stores/basemap"; import { useCrsStore } from "@ogw_front/stores/crs"; import { useDataStore } from "@ogw_front/stores/data"; -import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; -import { useTreeviewStore } from "@ogw_front/stores/treeview"; +import { useScenesStore } from "@ogw_front/stores/scenes"; import { useViewerStore } from "@ogw_front/stores/viewer"; -// Empties the viewer and every store, ready to receive an imported project. +// Empties the viewer and every store, ready to receive an imported project: scene_1 alone is left, empty. async function resetProject(): Promise { const viewerStore = useViewerStore(); const dataStore = useDataStore(); - const treeviewStore = useTreeviewStore(); - const hybridViewerStore = useHybridViewerStore(); const crsStore = useCrsStore(); const basemapStore = useBasemapStore(); await viewerStore.ws_connect(); await releaseViewerDatabase(viewerStore.client); - const resetVisualizationSchema = viewer_schemas.opengeodeweb_viewer.viewer.reset_visualization; - const timeout = undefined; - await viewerStore.request({ schema: resetVisualizationSchema, timeout }); - await afterViewerReset(viewerStore.request); + await useScenesStore().resetScenes(); - treeviewStore.clear(); await dataStore.clear(); - hybridViewerStore.clear(); crsStore.reset(); basemapStore.reset(); } diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index 437ae43fa..e1180cd76 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -15,7 +15,7 @@ import { } from "@ogw_internal/stores/scenes/types"; import { addToSceneStores, - deleteFromProject, + deleteHiddenFromProject, disposeSceneStores, duplicateSceneStores, removeFromSceneStores, @@ -51,6 +51,7 @@ export const useScenesStore = defineStore("scenes", () => { const lastUsedSceneId = ref(INITIAL_SCENE_ID); // Scene ids are never reused: scene_ const counter = ref(0); + const importState = useImportState(scenes); // A scene and the scenes linked to it on content, keeping those where the data is shown or not function contentTargets(sceneId: SceneId, dataId: DataId, shown: boolean): SceneId[] { @@ -71,18 +72,6 @@ export const useScenesStore = defineStore("scenes", () => { ); } - // A data stays in the project while a scene shows it - async function deleteIfHidden(dataIds: readonly DataId[]): Promise { - const shown = new Set(Object.values(contents.value).flat()); - await Promise.all( - dataIds - .filter((dataId) => !shown.has(dataId)) - .map(async (dataId) => { - await deleteFromProject(dataId); - }), - ); - } - async function removeData(sceneId: SceneId, dataId: DataId): Promise { const targets = contentTargets(sceneId, dataId, true); // A data the scene does not show is neither removed nor deleted @@ -97,7 +86,7 @@ export const useScenesStore = defineStore("scenes", () => { await removeFromSceneStores(targetId, dataId); }), ); - await deleteIfHidden([dataId]); + await deleteHiddenFromProject(contents.value, [dataId]); } async function newScene(): Promise { @@ -154,7 +143,7 @@ export const useScenesStore = defineStore("scenes", () => { if (lastUsedSceneId.value === sceneId) { lastUsedSceneId.value = scenes.value[0]?.id ?? INITIAL_SCENE_ID; } - await deleteIfHidden(closedContent); + await deleteHiddenFromProject(contents.value, closedContent); } // The scene keeps what it shows and diverges from its group @@ -195,6 +184,7 @@ export const useScenesStore = defineStore("scenes", () => { links.value = []; lastUsedSceneId.value = INITIAL_SCENE_ID; counter.value = 0; + importState.pendingImports.value = []; } // The viewer may hold the scenes of an earlier connection, after a reload or a reconnection: the viewer and the @@ -216,7 +206,7 @@ export const useScenesStore = defineStore("scenes", () => { links, lastUsedSceneId, counter, - ...useImportState(scenes), + ...importState, createScene, closeScene, addData, diff --git a/internal/stores/scenes/scene_stores.ts b/internal/stores/scenes/scene_stores.ts index fc2232275..37eec3add 100644 --- a/internal/stores/scenes/scene_stores.ts +++ b/internal/stores/scenes/scene_stores.ts @@ -73,6 +73,21 @@ async function deleteFromProject(dataId: DataId): Promise { await dataStore.deleteItem(dataId); } +// A data stays in the project while a scene shows it +async function deleteHiddenFromProject( + contents: Readonly>, + dataIds: readonly DataId[], +): Promise { + const shown = new Set(Object.values(contents).flat()); + await Promise.all( + dataIds + .filter((dataId) => !shown.has(dataId)) + .map(async (dataId) => { + await deleteFromProject(dataId); + }), + ); +} + // Copies what the source scene shows, its styles, its tree and its camera async function duplicateSceneStores( sourceId: SceneId, @@ -119,7 +134,7 @@ async function disposeSceneStores(sceneId: SceneId): Promise { export { addToSceneStores, - deleteFromProject, + deleteHiddenFromProject, disposeSceneStores, duplicateSceneStores, removeFromSceneStores, diff --git a/tests/unit/stores/scenes_import.nuxt.test.ts b/tests/unit/stores/scenes_import.nuxt.test.ts index 796dde147..178acbd02 100644 --- a/tests/unit/stores/scenes_import.nuxt.test.ts +++ b/tests/unit/stores/scenes_import.nuxt.test.ts @@ -45,4 +45,16 @@ describe("scenes store import state", () => { expect(useTreeviewStore("scene_1").selection).toStrictEqual([]); }); + + test("clear forgets the pending imports", async () => { + const scenesStore = useScenesStore(); + const { promise, resolve } = Promise.withResolvers(); + const importing = scenesStore.whilePendingImport("BRep", "corbi.og_brep", promise); + + scenesStore.clear(); + + expect(scenesStore.pendingImports).toStrictEqual([]); + resolve("done"); + await importing; + }); }); From f5faa8dede445ea6a7e065736c8309396f3bd63b Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 16:12:24 +0100 Subject: [PATCH 041/121] feat(project): restore several scenes scenesStore.importStores creates the viewer scenes of the project again, empty, after the stores of the previous scenes are disposed. The stores of each scene are then restored from their own snapshot key, in the former order, and the project's data are added to the scenes through addData, according to their contents. Co-Authored-By: Claude Opus 5.5 --- .../project_manager_helpers/restore.ts | 81 ++++++++++++------ .../project_manager_helpers/types.ts | 13 ++- app/stores/scenes.ts | 54 +++++------- internal/stores/scenes/scene_stores.ts | 11 ++- internal/stores/scenes/types.ts | 12 ++- internal/stores/scenes/viewer_scene.ts | 20 +++++ tests/unit/stores/scenes_helpers.ts | 2 + tests/unit/stores/scenes_import.nuxt.test.ts | 12 +-- tests/unit/stores/scenes_project.nuxt.test.ts | 85 +++++++++++++++++++ 9 files changed, 221 insertions(+), 69 deletions(-) create mode 100644 internal/stores/scenes/viewer_scene.ts create mode 100644 tests/unit/stores/scenes_project.nuxt.test.ts diff --git a/app/composables/project_manager_helpers/restore.ts b/app/composables/project_manager_helpers/restore.ts index 57c3a0aa6..289e6e38e 100644 --- a/app/composables/project_manager_helpers/restore.ts +++ b/app/composables/project_manager_helpers/restore.ts @@ -1,4 +1,5 @@ import type { ProjectSnapshot } from "@ogw_front/composables/project_manager_helpers/types"; +import type { ScenesSnapshot } from "@ogw_internal/stores/scenes/types"; import { importProjectToViewer } from "@ogw_front/composables/project_manager_helpers/viewer_session"; import { importWorkflowFromSnapshot } from "@ogw_front/utils/import_workflow"; import { oldestCrs } from "@ogw_front/utils/crs"; @@ -7,9 +8,24 @@ import { useCrsStore } from "@ogw_front/stores/crs"; import { useDataStore } from "@ogw_front/stores/data"; import { useDataStyleStore } from "@ogw_front/stores/data_style"; import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; +import { useScenesStore } from "@ogw_front/stores/scenes"; import { useTreeviewStore } from "@ogw_front/stores/treeview"; import { useViewerStore } from "@ogw_front/stores/viewer"; +type ScenesProject = ProjectSnapshot & { scenes: ScenesSnapshot }; + +// The scenes are restored first: they create the stores of each scene +function withScenes(snapshot: ProjectSnapshot): ScenesProject { + if (snapshot.scenes === undefined) { + throw new Error("The project has no scenes"); + } + return { ...snapshot, scenes: snapshot.scenes }; +} + +function sceneIds(project: ScenesProject): string[] { + return project.scenes.scenes.map((scene) => scene.id); +} + // After every data item is added: on partial data the project CRS would follow them. // A project saved without a project CRS takes the one of its oldest data, read in the // Snapshot: the stored items carry the import time as creation date @@ -22,46 +38,61 @@ function restoreCrs(snapshot: ProjectSnapshot): void { } } -async function restoreData(snapshot: ProjectSnapshot): Promise { +async function restoreData(project: ScenesProject): Promise { const dataStore = useDataStore(); - const treeviewStore = useTreeviewStore(); - const hybridViewerStore = useHybridViewerStore(); - treeviewStore.importStores(snapshot.treeview); - if (snapshot.data !== undefined) { - await dataStore.importStores(snapshot.data); + for (const sceneId of sceneIds(project)) { + useTreeviewStore(sceneId).importStores(project[`treeview-${sceneId}`]); } - await hybridViewerStore.initHybridViewer(); - await importWorkflowFromSnapshot(snapshot.data?.items ?? []); + if (project.data !== undefined) { + await dataStore.importStores(project.data); + } + await Promise.all( + sceneIds(project).map(async (sceneId) => { + await useHybridViewerStore(sceneId).initHybridViewer(); + }), + ); + await importWorkflowFromSnapshot(project.data?.items ?? [], project.scenes.contents); } -async function restoreViews(snapshot: ProjectSnapshot): Promise { - const dataStyleStore = useDataStyleStore(); - const hybridViewerStore = useHybridViewerStore(); - const basemapStore = useBasemapStore(); - - restoreCrs(snapshot); - await basemapStore.importStores(snapshot.basemap); - await hybridViewerStore.importStores(snapshot.hybridViewer); - if (snapshot.dataStyle !== undefined) { - await dataStyleStore.importStores(snapshot.dataStyle); +async function restoreSceneView(project: ScenesProject, sceneId: string): Promise { + const dataStyleStore = useDataStyleStore(sceneId); + await useHybridViewerStore(sceneId).importStores(project[`hybridViewer-${sceneId}`]); + const dataStyle = project[`dataStyle-${sceneId}`]; + if (dataStyle !== undefined) { + await dataStyleStore.importStores(dataStyle); } await dataStyleStore.applyAllStylesFromState(); } -// Loads a project snapshot into the (already reset) viewer and stores. +async function restoreViews(project: ScenesProject): Promise { + restoreCrs(project); + await useBasemapStore().importStores(project.basemap); + await Promise.all( + sceneIds(project).map(async (sceneId) => { + await restoreSceneView(project, sceneId); + }), + ); +} + +// Loads a project snapshot into the (already reset) viewer and stores: its scenes first, then the stores of +// Each scene async function restoreProject(snapshot: ProjectSnapshot): Promise { const viewerStore = useViewerStore(); - const treeviewStore = useTreeviewStore(); + const scenesStore = useScenesStore(); + const project = withScenes(snapshot); - treeviewStore.isImporting = true; + scenesStore.isImporting = true; await importProjectToViewer(viewerStore.client); - await restoreData(snapshot); - await restoreViews(snapshot); + await scenesStore.importStores(project.scenes); + await restoreData(project); + await restoreViews(project); - treeviewStore.finalizeImportSelection(); - treeviewStore.isImporting = false; + for (const sceneId of sceneIds(project)) { + useTreeviewStore(sceneId).finalizeImportSelection(); + } + scenesStore.isImporting = false; } export { restoreProject }; diff --git a/app/composables/project_manager_helpers/types.ts b/app/composables/project_manager_helpers/types.ts index 82735de71..5d4e07452 100644 --- a/app/composables/project_manager_helpers/types.ts +++ b/app/composables/project_manager_helpers/types.ts @@ -6,6 +6,7 @@ import type { LegacyDataId } from "@ogw_front/utils/legacy_data_id"; import type { ModelComponentRecord } from "@ogw_internal/stores/data/model/mesh_components"; import type { ModelComponentRelationRecord } from "@ogw_internal/stores/data/model/relations"; import type { NewDataItem } from "@ogw_front/stores/data"; +import type { ScenesSnapshot } from "@ogw_internal/stores/scenes/types"; import type { TreeviewSnapshot } from "@ogw_front/stores/treeview"; // Projects saved before data_id existed hold the data id of their rows as `id` interface ProjectDataSnapshot { @@ -17,13 +18,19 @@ interface ProjectDataSnapshot { )[]; } +// Each store of a scene is saved under its own id, as the registry exports it interface ProjectSnapshot { - treeview?: TreeviewSnapshot; + scenes?: ScenesSnapshot; data?: ProjectDataSnapshot; - hybridViewer?: CameraSnapshot; - dataStyle?: DataStyleSnapshot; crs?: { projectCrs?: CRS }; basemap?: BasemapSnapshot; + [treeviewId: `treeview-${string}`]: TreeviewSnapshot | undefined; + [hybridViewerId: `hybridViewer-${string}`]: CameraSnapshot | undefined; + [dataStyleId: `dataStyle-${string}`]: DataStyleSnapshot | undefined; + // Projects saved with a single scene hold the stores of that scene under their own name + treeview?: TreeviewSnapshot; + hybridViewer?: CameraSnapshot; + dataStyle?: DataStyleSnapshot; } export type { ProjectSnapshot }; diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index e1180cd76..e5d461667 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -1,7 +1,7 @@ // Third party imports +import { ref, toRaw } from "vue"; import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; import { defineStore } from "pinia"; -import { ref } from "vue"; import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; // Local imports @@ -12,30 +12,24 @@ import { type SceneLink, type SceneMode, type SceneRecord, + type ScenesSnapshot, } from "@ogw_internal/stores/scenes/types"; import { addToSceneStores, deleteHiddenFromProject, + disposeEverySceneStores, disposeSceneStores, duplicateSceneStores, removeFromSceneStores, } from "@ogw_internal/stores/scenes/scene_stores"; import { joinLink, leaveLinks, linkedScenes } from "@ogw_internal/stores/scenes/links"; -import { afterViewerReset } from "@ogw_front/composables/viewer_reset"; +import { openViewerScene } from "@ogw_internal/stores/scenes/viewer_scene"; import { propagateToLinkedScenes } from "@ogw_internal/stores/scenes/camera_link"; import { useImportState } from "@ogw_internal/stores/scenes/import_state"; import { useViewerStore } from "@ogw_front/stores/viewer"; const viewerSchemas = viewer_schemas.opengeodeweb_viewer.viewer; -interface ScenesSnapshot { - scenes: SceneRecord[]; - contents: Record; - links: SceneLink[]; - lastUsedSceneId: SceneId; - counter: number; -} - // An unknown id would create the stores of a scene that does not exist function assertScene(scenes: readonly SceneRecord[], sceneId: SceneId): void { if (!scenes.some((scene) => scene.id === sceneId)) { @@ -92,13 +86,7 @@ export const useScenesStore = defineStore("scenes", () => { async function newScene(): Promise { counter.value += 1; const sceneId = `scene_${counter.value}`; - const viewerStore = useViewerStore(); - const { view_id } = await viewerStore.request({ - schema: viewerSchemas.create_scene, - params: { scene_id: sceneId }, - }); - // A new viewer scene draws the app colors, not its own - await afterViewerReset(viewerStore.request, sceneId); + const view_id = await openViewerScene(sceneId); scenes.value.push({ id: sceneId, name: `Scene ${counter.value}`, view_id }); contents.value[sceneId] = []; return sceneId; @@ -170,14 +158,6 @@ export const useScenesStore = defineStore("scenes", () => { }; } - function importStores(snapshot: ScenesSnapshot): void { - scenes.value = structuredClone(snapshot.scenes); - contents.value = structuredClone(snapshot.contents); - links.value = structuredClone(snapshot.links); - lastUsedSceneId.value = snapshot.lastUsedSceneId; - counter.value = snapshot.counter; - } - function clear(): void { scenes.value = []; contents.value = {}; @@ -187,15 +167,27 @@ export const useScenesStore = defineStore("scenes", () => { importState.pendingImports.value = []; } + // The viewer scenes of a project are created again, empty: its data are added to them by addData + async function importStores(snapshot: ScenesSnapshot): Promise { + await disposeEverySceneStores(scenes.value); + clear(); + scenes.value = await Promise.all( + snapshot.scenes.map(async (scene) => { + const view_id = await openViewerScene(scene.id); + return { id: scene.id, name: scene.name, view_id }; + }), + ); + contents.value = Object.fromEntries(scenes.value.map((scene) => [scene.id, []])); + links.value = structuredClone(toRaw(snapshot.links)); + lastUsedSceneId.value = snapshot.lastUsedSceneId; + counter.value = snapshot.counter; + } + // The viewer may hold the scenes of an earlier connection, after a reload or a reconnection: the viewer and the // Front start over from scene_1 alone async function resetScenes(): Promise { await useViewerStore().request({ schema: viewerSchemas.reset_scenes, params: {} }); - await Promise.all( - scenes.value.map(async (scene) => { - await disposeSceneStores(scene.id); - }), - ); + await disposeEverySceneStores(scenes.value); clear(); return createScene("empty"); } @@ -221,4 +213,4 @@ export const useScenesStore = defineStore("scenes", () => { }; }); -export type { ScenesSnapshot }; +export type { SceneId, ScenesSnapshot } from "@ogw_internal/stores/scenes/types"; diff --git a/internal/stores/scenes/scene_stores.ts b/internal/stores/scenes/scene_stores.ts index 37eec3add..b89938e80 100644 --- a/internal/stores/scenes/scene_stores.ts +++ b/internal/stores/scenes/scene_stores.ts @@ -4,8 +4,8 @@ import { toRaw } from "vue"; import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; // Local imports +import type { SceneId, SceneRecord } from "./types"; import type { DataItem } from "@ogw_internal/database/tables/data"; -import type { SceneId } from "./types"; import { disposeSceneScope } from "./scene_scope"; import { treeviewConfigDb } from "@ogw_internal/database/database"; import { useAppStore } from "@ogw_front/stores/app"; @@ -132,9 +132,18 @@ async function disposeSceneStores(sceneId: SceneId): Promise { disposeSceneScope(sceneId); } +async function disposeEverySceneStores(scenes: readonly SceneRecord[]): Promise { + await Promise.all( + scenes.map(async (scene) => { + await disposeSceneStores(scene.id); + }), + ); +} + export { addToSceneStores, deleteHiddenFromProject, + disposeEverySceneStores, disposeSceneStores, duplicateSceneStores, removeFromSceneStores, diff --git a/internal/stores/scenes/types.ts b/internal/stores/scenes/types.ts index 9cf6367e7..f08fdac4d 100644 --- a/internal/stores/scenes/types.ts +++ b/internal/stores/scenes/types.ts @@ -1,3 +1,5 @@ +import type { DataId } from "@geode/opengeodeweb-microservice/schema_types"; + type SceneId = string; type SceneMode = "empty" | "duplicate" | "duplicate_linked"; type LinkChannel = "camera" | "content"; @@ -14,8 +16,16 @@ interface SceneLink { channels: LinkChannel[]; } +interface ScenesSnapshot { + scenes: SceneRecord[]; + contents: Record; + links: SceneLink[]; + lastUsedSceneId: SceneId; + counter: number; +} + const INITIAL_SCENE_ID = "scene_1"; const MAX_SCENES = 4; -export type { LinkChannel, SceneId, SceneLink, SceneMode, SceneRecord }; +export type { LinkChannel, SceneId, SceneLink, SceneMode, SceneRecord, ScenesSnapshot }; export { INITIAL_SCENE_ID, MAX_SCENES }; diff --git a/internal/stores/scenes/viewer_scene.ts b/internal/stores/scenes/viewer_scene.ts new file mode 100644 index 000000000..9c166759d --- /dev/null +++ b/internal/stores/scenes/viewer_scene.ts @@ -0,0 +1,20 @@ +// Third party imports +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js"; + +// Local imports +import type { SceneId } from "./types"; +import { afterViewerReset } from "@ogw_front/composables/viewer_reset"; +import { useViewerStore } from "@ogw_front/stores/viewer"; + +// A new viewer scene draws the app colors, not its own +async function openViewerScene(sceneId: SceneId): Promise { + const viewerStore = useViewerStore(); + const { view_id } = await viewerStore.request({ + schema: viewer_schemas.opengeodeweb_viewer.viewer.create_scene, + params: { scene_id: sceneId }, + }); + await afterViewerReset(viewerStore.request, sceneId); + return view_id; +} + +export { openViewerScene }; diff --git a/tests/unit/stores/scenes_helpers.ts b/tests/unit/stores/scenes_helpers.ts index d6447e649..30ce23ba2 100644 --- a/tests/unit/stores/scenes_helpers.ts +++ b/tests/unit/stores/scenes_helpers.ts @@ -38,6 +38,8 @@ function fakeSceneStore(storeId: string, sceneId: string): Record void>(), + initHybridViewer: resolves(), + remoteRender: resolves(), }; fakeStores.set(key, instance); return instance; diff --git a/tests/unit/stores/scenes_import.nuxt.test.ts b/tests/unit/stores/scenes_import.nuxt.test.ts index 178acbd02..e6c2c2ecb 100644 --- a/tests/unit/stores/scenes_import.nuxt.test.ts +++ b/tests/unit/stores/scenes_import.nuxt.test.ts @@ -2,6 +2,7 @@ import { beforeEach, describe, expect, test, vi } from "vitest"; // Local imports +import { mockViewer } from "@ogw_tests/unit/stores/scenes_helpers"; import { setupActivePinia } from "@ogw_tests/utils"; import { useScenesStore } from "@ogw_front/stores/scenes"; import { useTreeviewStore } from "@ogw_front/stores/treeview"; @@ -9,15 +10,10 @@ import { useTreeviewStore } from "@ogw_front/stores/treeview"; vi.setConfig({ testTimeout: 10_000 }); describe("scenes store import state", () => { - beforeEach(() => { + beforeEach(async () => { setupActivePinia(); - useScenesStore().importStores({ - scenes: [{ id: "scene_1", name: "Scene 1", view_id: "view_scene_1" }], - contents: { scene_1: [] }, - links: [], - lastUsedSceneId: "scene_1", - counter: 1, - }); + mockViewer(); + await useScenesStore().createScene("empty"); }); test("whilePendingImport lists the file until its conversion is done", async () => { diff --git a/tests/unit/stores/scenes_project.nuxt.test.ts b/tests/unit/stores/scenes_project.nuxt.test.ts new file mode 100644 index 000000000..b9cbdac2f --- /dev/null +++ b/tests/unit/stores/scenes_project.nuxt.test.ts @@ -0,0 +1,85 @@ +// Third party imports +import { beforeEach, describe, expect, test, vi } from "vitest"; + +// Local imports +import { + DATA_ID, + DATA_ITEM, + fakeSceneStore, + fakeStores, + mockData, + mockViewer, +} from "@ogw_tests/unit/stores/scenes_helpers"; +import { restoreProject } from "@ogw_front/composables/project_manager_helpers/restore"; +import { setupActivePinia } from "@ogw_tests/utils"; +import { useScenesStore } from "@ogw_front/stores/scenes"; + +vi.setConfig({ testTimeout: 10_000 }); + +vi.mock(import("@ogw_front/stores/data_style") as Promise, async () => { + const helpers = await import("@ogw_tests/unit/stores/scenes_helpers"); + return { + useDataStyleStore: (sceneId: string): Record => + helpers.fakeSceneStore("dataStyle", sceneId), + }; +}); +vi.mock(import("@ogw_front/stores/hybrid_viewer") as Promise, async () => { + const helpers = await import("@ogw_tests/unit/stores/scenes_helpers"); + return { + useHybridViewerStore: (sceneId: string): Record => + helpers.fakeSceneStore("hybridViewer", sceneId), + }; +}); +vi.mock(import("@ogw_front/stores/treeview") as Promise, async () => { + const helpers = await import("@ogw_tests/unit/stores/scenes_helpers"); + return { + useTreeviewStore: (sceneId: string): Record => + helpers.fakeSceneStore("treeview", sceneId), + }; +}); +vi.mock(import("@ogw_front/stores/basemap") as Promise, async () => { + const helpers = await import("@ogw_tests/unit/stores/scenes_helpers"); + return { + useBasemapStore: (): Record => helpers.fakeSceneStore("basemap", "project"), + }; +}); + +const DATA_STYLE = { + styles: { [DATA_ID]: { data_id: DATA_ID, visibility: true } }, + componentStyles: {}, +}; + +describe("scenes of a project", () => { + beforeEach(() => { + setupActivePinia(); + fakeStores.clear(); + }); + + test("export then import keeps two scenes and their link", async () => { + mockViewer(); + mockData(); + const scenesStore = useScenesStore(); + await scenesStore.createScene("empty"); + await scenesStore.addData("scene_1", DATA_ID); + await scenesStore.createScene("duplicate_linked", "scene_1"); + const exported = scenesStore.exportStores(); + const { links } = exported; + + // The project is opened in a new session + setupActivePinia(); + fakeStores.clear(); + mockViewer(); + mockData(); + await restoreProject({ + scenes: exported, + data: { items: [DATA_ITEM], modelComponents: [], modelComponentsRelations: [] }, + "dataStyle-scene_2": DATA_STYLE, + }); + + const restored = useScenesStore(); + expect(restored.scenes.map((scene) => scene.id)).toStrictEqual(["scene_1", "scene_2"]); + expect(restored.links).toStrictEqual(links); + expect(restored.contents).toStrictEqual({ scene_1: [DATA_ID], scene_2: [DATA_ID] }); + expect(fakeSceneStore("dataStyle", "scene_2").importStores).toHaveBeenCalledWith(DATA_STYLE); + }); +}); From 13516e33f15d3cfbaf4e5428742f7a3000dbde6d Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Mon, 30 Nov 2026 16:12:51 +0100 Subject: [PATCH 042/121] feat(project): open a single-scene project as scene_1 A project saved before the scenes has no scenes key: it opens as scene_1, showing all its data, with its treeview, hybridViewer and dataStyle snapshots restored as those of scene_1. Co-Authored-By: Claude Opus 5.5 --- .../project_manager_helpers/restore.ts | 24 ++++++++++++++---- .../composables/project_manager.nuxt.test.ts | 16 +++++++++++- tests/unit/stores/scenes_project.nuxt.test.ts | 25 +++++++++++++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/app/composables/project_manager_helpers/restore.ts b/app/composables/project_manager_helpers/restore.ts index 289e6e38e..07dd603c6 100644 --- a/app/composables/project_manager_helpers/restore.ts +++ b/app/composables/project_manager_helpers/restore.ts @@ -1,5 +1,6 @@ +import { INITIAL_SCENE_ID, type ScenesSnapshot } from "@ogw_internal/stores/scenes/types"; import type { ProjectSnapshot } from "@ogw_front/composables/project_manager_helpers/types"; -import type { ScenesSnapshot } from "@ogw_internal/stores/scenes/types"; +import { fromLegacyDataId } from "@ogw_front/utils/legacy_data_id"; import { importProjectToViewer } from "@ogw_front/composables/project_manager_helpers/viewer_session"; import { importWorkflowFromSnapshot } from "@ogw_front/utils/import_workflow"; import { oldestCrs } from "@ogw_front/utils/crs"; @@ -14,12 +15,25 @@ import { useViewerStore } from "@ogw_front/stores/viewer"; type ScenesProject = ProjectSnapshot & { scenes: ScenesSnapshot }; -// The scenes are restored first: they create the stores of each scene +// A project saved with a single scene opens as scene_1, showing all its data with the stores of that scene function withScenes(snapshot: ProjectSnapshot): ScenesProject { - if (snapshot.scenes === undefined) { - throw new Error("The project has no scenes"); + if (snapshot.scenes !== undefined) { + return { ...snapshot, scenes: snapshot.scenes }; } - return { ...snapshot, scenes: snapshot.scenes }; + const dataIds = (snapshot.data?.items ?? []).map((item) => fromLegacyDataId(item).data_id); + return { + ...snapshot, + scenes: { + scenes: [{ id: INITIAL_SCENE_ID, name: "Scene 1", view_id: "" }], + contents: { [INITIAL_SCENE_ID]: dataIds }, + links: [], + lastUsedSceneId: INITIAL_SCENE_ID, + counter: 1, + }, + [`treeview-${INITIAL_SCENE_ID}`]: snapshot.treeview, + [`hybridViewer-${INITIAL_SCENE_ID}`]: snapshot.hybridViewer, + [`dataStyle-${INITIAL_SCENE_ID}`]: snapshot.dataStyle, + }; } function sceneIds(project: ScenesProject): string[] { diff --git a/tests/unit/composables/project_manager.nuxt.test.ts b/tests/unit/composables/project_manager.nuxt.test.ts index 07883d7bb..5280c551d 100644 --- a/tests/unit/composables/project_manager.nuxt.test.ts +++ b/tests/unit/composables/project_manager.nuxt.test.ts @@ -103,9 +103,11 @@ const infraStoreMock = { const viewerStoreMock = { ws_connect: vi.fn().mockResolvedValue(undefined), base_url: vi.fn(() => ""), - request: vi.fn().mockResolvedValue(undefined), + // Each scene of the project is created again in the viewer + request: vi.fn().mockResolvedValue({ view_id: "view" }), }; const treeviewStoreMock = { + $dispose: vi.fn(), clear: vi.fn(), importStores: vi.fn().mockResolvedValue(undefined), finalizeImportSelection: vi.fn(), @@ -121,9 +123,19 @@ const dataStoreMock = { addItem: vi.fn().mockResolvedValue(undefined), importStores: vi.fn().mockResolvedValue(undefined), isViewable: vi.fn().mockReturnValue(true), + isRegistered: vi.fn().mockReturnValue(true), + item: vi.fn().mockResolvedValue({ + data_id: "abc123", + geode_id: "11111111-1111-1111-1111-111111111111", + viewer_object_type: "mesh", + geode_object_type: "PointSet2D", + name: "My Data", + }), fetchIsViewable: vi.fn().mockResolvedValue(true), }; const dataStyleStoreMock = { + $dispose: vi.fn(), + clear: vi.fn().mockResolvedValue(undefined), importStores: vi.fn().mockResolvedValue(undefined), applyAllStylesFromState: vi.fn().mockResolvedValue(undefined), addDataStyle: vi.fn().mockResolvedValue(undefined), @@ -146,6 +158,7 @@ interface HybridViewerSnapshot { } const hybridViewerStoreMock = { + $dispose: vi.fn(), clear: vi.fn(), initHybridViewer: vi.fn().mockResolvedValue(undefined), importStores: vi.fn((snapshot?: HybridViewerSnapshot) => { @@ -209,6 +222,7 @@ vi.mock(import("@ogw_front/stores/crs") as Promise, () => ({ })); const appStoreMock = { exportStores: vi.fn(() => ({ projectName: "mockedProject" })), + unregisterStore: vi.fn(), }; vi.mock(import("@ogw_front/stores/app") as Promise, () => ({ diff --git a/tests/unit/stores/scenes_project.nuxt.test.ts b/tests/unit/stores/scenes_project.nuxt.test.ts index b9cbdac2f..a736f1726 100644 --- a/tests/unit/stores/scenes_project.nuxt.test.ts +++ b/tests/unit/stores/scenes_project.nuxt.test.ts @@ -44,6 +44,8 @@ vi.mock(import("@ogw_front/stores/basemap") as Promise, async () => { }; }); +const PANEL_WIDTH = 320; +const Z_SCALE = 2; const DATA_STYLE = { styles: { [DATA_ID]: { data_id: DATA_ID, visibility: true } }, componentStyles: {}, @@ -82,4 +84,27 @@ describe("scenes of a project", () => { expect(restored.contents).toStrictEqual({ scene_1: [DATA_ID], scene_2: [DATA_ID] }); expect(fakeSceneStore("dataStyle", "scene_2").importStores).toHaveBeenCalledWith(DATA_STYLE); }); + + test("importStores maps a legacy snapshot to scene_1", async () => { + mockViewer(); + mockData(); + const treeview = { panelWidth: PANEL_WIDTH }; + const hybridViewer = { zScale: Z_SCALE }; + + await restoreProject({ + data: { items: [DATA_ITEM], modelComponents: [], modelComponentsRelations: [] }, + treeview, + hybridViewer, + dataStyle: DATA_STYLE, + }); + + const scenesStore = useScenesStore(); + expect(scenesStore.scenes.map((scene) => scene.id)).toStrictEqual(["scene_1"]); + expect(scenesStore.contents).toStrictEqual({ scene_1: [DATA_ID] }); + expect(fakeSceneStore("dataStyle", "scene_1").importStores).toHaveBeenCalledWith(DATA_STYLE); + expect(fakeSceneStore("treeview", "scene_1").importStores).toHaveBeenCalledWith(treeview); + expect(fakeSceneStore("hybridViewer", "scene_1").importStores).toHaveBeenCalledWith( + hybridViewer, + ); + }); }); From 5980d36c4f85d0ebe5bc7cccc148a176af38adc1 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Tue, 1 Dec 2026 09:52:13 +0100 Subject: [PATCH 043/121] fix(scenes): drop the per-scene data removal Data deletion stays in the data manager; closeScene still deletes the data no remaining scene shows. Co-Authored-By: Claude Opus 5.5 --- app/stores/scenes.ts | 29 +++--------------- internal/stores/scenes/scene_stores.ts | 15 --------- tests/unit/stores/scenes.nuxt.test.ts | 42 -------------------------- 3 files changed, 5 insertions(+), 81 deletions(-) diff --git a/app/stores/scenes.ts b/app/stores/scenes.ts index e5d461667..e5183d5c0 100644 --- a/app/stores/scenes.ts +++ b/app/stores/scenes.ts @@ -20,7 +20,6 @@ import { disposeEverySceneStores, disposeSceneStores, duplicateSceneStores, - removeFromSceneStores, } from "@ogw_internal/stores/scenes/scene_stores"; import { joinLink, leaveLinks, linkedScenes } from "@ogw_internal/stores/scenes/links"; import { openViewerScene } from "@ogw_internal/stores/scenes/viewer_scene"; @@ -37,7 +36,7 @@ function assertScene(scenes: readonly SceneRecord[], sceneId: SceneId): void { } } -// The only place that knows the content links: data are added to and removed from scenes here +// The only place that knows the content links: data are added to scenes here export const useScenesStore = defineStore("scenes", () => { const scenes = ref([]); const contents = ref>({}); @@ -47,15 +46,15 @@ export const useScenesStore = defineStore("scenes", () => { const counter = ref(0); const importState = useImportState(scenes); - // A scene and the scenes linked to it on content, keeping those where the data is shown or not - function contentTargets(sceneId: SceneId, dataId: DataId, shown: boolean): SceneId[] { + // A scene and the scenes linked to it on content, keeping those where the data is not shown yet + function contentTargets(sceneId: SceneId, dataId: DataId): SceneId[] { return [sceneId, ...linkedScenes(links.value, sceneId, "content")].filter( - (targetId) => (contents.value[targetId] ?? []).includes(dataId) === shown, + (targetId) => !(contents.value[targetId] ?? []).includes(dataId), ); } async function addData(sceneId: SceneId, dataId: DataId): Promise { - const targets = contentTargets(sceneId, dataId, false); + const targets = contentTargets(sceneId, dataId); for (const targetId of targets) { contents.value[targetId] = [...(contents.value[targetId] ?? []), dataId]; } @@ -66,23 +65,6 @@ export const useScenesStore = defineStore("scenes", () => { ); } - async function removeData(sceneId: SceneId, dataId: DataId): Promise { - const targets = contentTargets(sceneId, dataId, true); - // A data the scene does not show is neither removed nor deleted - if (targets.length === 0) { - return; - } - for (const targetId of targets) { - contents.value[targetId] = (contents.value[targetId] ?? []).filter((id) => id !== dataId); - } - await Promise.all( - targets.map(async (targetId) => { - await removeFromSceneStores(targetId, dataId); - }), - ); - await deleteHiddenFromProject(contents.value, [dataId]); - } - async function newScene(): Promise { counter.value += 1; const sceneId = `scene_${counter.value}`; @@ -202,7 +184,6 @@ export const useScenesStore = defineStore("scenes", () => { createScene, closeScene, addData, - removeData, unlink, propagateCamera, setLastUsed, diff --git a/internal/stores/scenes/scene_stores.ts b/internal/stores/scenes/scene_stores.ts index b89938e80..deec21f51 100644 --- a/internal/stores/scenes/scene_stores.ts +++ b/internal/stores/scenes/scene_stores.ts @@ -53,20 +53,6 @@ async function addToSceneStores(sceneId: SceneId, dataId: DataId): Promise } } -async function removeFromSceneStores(sceneId: SceneId, dataId: DataId): Promise { - const treeviewStore = useTreeviewStore(sceneId); - treeviewStore.removeItem(dataId); - treeviewStore.closeView(dataId); - useHybridViewerStore(sceneId).removeItem(dataId); - if (!useDataStore().isRegistered(dataId)) { - return; - } - await useViewerStore().request({ - schema: viewerSchemas.remove_from_scene, - params: { scene_id: sceneId, id: dataId }, - }); -} - async function deleteFromProject(dataId: DataId): Promise { const dataStore = useDataStore(); await dataStore.deregisterObject(dataId); @@ -146,5 +132,4 @@ export { disposeEverySceneStores, disposeSceneStores, duplicateSceneStores, - removeFromSceneStores, }; diff --git a/tests/unit/stores/scenes.nuxt.test.ts b/tests/unit/stores/scenes.nuxt.test.ts index 72c524781..95e18d2d3 100644 --- a/tests/unit/stores/scenes.nuxt.test.ts +++ b/tests/unit/stores/scenes.nuxt.test.ts @@ -130,48 +130,6 @@ describe("scenes store", () => { expect(sentTo(request, viewer.add_to_scene)).toStrictEqual(["scene_1", "scene_2"]); }); - test("removeData keeps data shown elsewhere", async () => { - const scenesStore = useScenesStore(); - const { deleteItem } = mockData(); - await scenesStore.addData("scene_1", DATA_ID); - await scenesStore.createScene("duplicate", "scene_1"); - - await scenesStore.removeData("scene_1", DATA_ID); - - expect(scenesStore.contents).toStrictEqual({ - scene_1: [], - scene_2: [DATA_ID], - }); - expect(sentTo(request, viewer.remove_from_scene)).toStrictEqual(["scene_1"]); - expect(deleteItem).not.toHaveBeenCalled(); - - await scenesStore.removeData("scene_2", DATA_ID); - - expect(deleteItem).toHaveBeenCalledWith(DATA_ID); - }); - - test("removeData ignores data the scene does not show", async () => { - const scenesStore = useScenesStore(); - const { deleteItem } = mockData(); - - await scenesStore.removeData("scene_1", DATA_ID); - - expect(scenesStore.contents).toStrictEqual({ scene_1: [] }); - expect(deleteItem).not.toHaveBeenCalled(); - }); - - test("removeData deletes data when last", async () => { - const scenesStore = useScenesStore(); - const { deleteItem } = mockData(); - await scenesStore.addData("scene_1", DATA_ID); - await scenesStore.createScene("duplicate_linked", "scene_1"); - - await scenesStore.removeData("scene_2", DATA_ID); - - expect(scenesStore.contents).toStrictEqual({ scene_1: [], scene_2: [] }); - expect(deleteItem).toHaveBeenCalledWith(DATA_ID); - }); - test("closeScene keeps the remaining link", async () => { const scenesStore = useScenesStore(); await scenesStore.createScene("duplicate_linked", "scene_1"); From 81039b83ed80fd378569b3a4ef9d6b3269e24bca Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Tue, 1 Dec 2026 09:53:42 +0100 Subject: [PATCH 044/121] fix(import): render every scene showing the imported data Scenes content-linked to the import scene get the data too: reset the camera of those that were empty and render each of them after the import. Co-Authored-By: Claude Opus 5.5 --- app/utils/import_workflow.ts | 33 +++++++++++++++---- tests/unit/utils/import_workflow.nuxt.test.ts | 31 +++++++++++++++++ 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/app/utils/import_workflow.ts b/app/utils/import_workflow.ts index 59aa4c185..50ab1bda6 100644 --- a/app/utils/import_workflow.ts +++ b/app/utils/import_workflow.ts @@ -47,10 +47,25 @@ async function importFile( return dataIds; } +function isSceneEmpty(sceneId: SceneId): boolean { + return Object.keys(useHybridViewerStore(sceneId).hybridDb).length === 0; +} + +// The scenes that show at least one of the data, whether imported there or through a content link +function scenesShowing(dataIds: readonly string[]): SceneId[] { + return Object.entries(useScenesStore().contents) + .filter(([, content]) => content.some((id) => dataIds.includes(id))) + .map(([id]) => id); +} + async function importFiles(files: readonly FileToImport[], sceneId: SceneId): Promise { - const hybridViewerStore = useHybridViewerStore(sceneId); // Files are imported concurrently and the viewer only frames the first actor to arrive, so the camera is reset once everything is loaded - const wasSceneEmpty = Object.keys(hybridViewerStore.hybridDb).length === 0; + // Scenes linked on content get the data too: the emptiness is taken for every scene before the import + const emptyScenes = new Set( + useScenesStore() + .scenes.map((scene) => scene.id) + .filter((id) => isSceneEmpty(id)), + ); const chunk_size = 5; const chunks: FileToImport[][] = []; for (let i = 0; i < files.length; i += chunk_size) { @@ -81,11 +96,15 @@ async function importFiles(files: readonly FileToImport[], sceneId: SceneId): Pr await processChunk(chunkIndex + 1); } await processChunk(0); - const isSceneFilled = Object.keys(hybridViewerStore.hybridDb).length > 0; - if (wasSceneEmpty && isSceneFilled) { - hybridViewerStore.resetCamera(); - } - await hybridViewerStore.remoteRender(); + await Promise.all( + [...new Set([sceneId, ...scenesShowing(results)])].map(async (id) => { + const hybridViewerStore = useHybridViewerStore(id); + if (emptyScenes.has(id) && !isSceneEmpty(id)) { + hybridViewerStore.resetCamera(); + } + await hybridViewerStore.remoteRender(); + }), + ); if (errors.length > 0) { throw new AggregateError(errors, `${errors.length} file(s) could not be imported`); } diff --git a/tests/unit/utils/import_workflow.nuxt.test.ts b/tests/unit/utils/import_workflow.nuxt.test.ts index a282f7779..871775f65 100644 --- a/tests/unit/utils/import_workflow.nuxt.test.ts +++ b/tests/unit/utils/import_workflow.nuxt.test.ts @@ -177,6 +177,37 @@ describe("import workflow", () => { expect(ids).toStrictEqual(["first_a", "first_b", "second"]); }); + + test("resets and renders every scene linked on content to the import scene", async () => { + setup().request.mockResolvedValueOnce({ + data: [{ id: "model.og_brep", name: "model", viewer_object_type: "mesh" }], + }); + useScenesStore().$patch((state) => { + state.scenes.push({ id: "scene_2", name: "Scene 2", view_id: "view_scene_2" }); + state.contents.scene_2 = []; + state.links = [{ id: "link_1", sceneIds: ["scene_1", "scene_2"], channels: ["content"] }]; + }); + const viewers = ["scene_1", "scene_2"].map((id) => { + const store = useHybridViewerStore(id); + store.resetCamera = mockAs(vi.fn()); + store.remoteRender = mockAs(vi.fn()); + return store; + }); + useDataStore().addItem = mockAs["addItem"]>( + vi.fn().mockImplementation(() => { + for (const store of viewers) { + store.hybridDb["model.og_brep"] = mockAs<(typeof store.hybridDb)[string]>({}); + } + }), + ); + + await importWorkflow([{ filename: "model.og_brep", geode_object_type: "BRep" }], "scene_1"); + + for (const store of viewers) { + expect(store.resetCamera).toHaveBeenCalledWith(); + expect(store.remoteRender).toHaveBeenCalledWith(); + } + }); }); describe("import file", () => { From 48ec020451196c90f1a55a46e3cc4ca07854739a Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Tue, 1 Dec 2026 09:56:40 +0100 Subject: [PATCH 045/121] feat(scenes): add scene view and title bar Co-Authored-By: Claude Opus 5.5 --- app/components/Scene/SceneTitleBar.vue | 65 ++++++++++++++++++++++++++ app/components/Scene/SceneView.vue | 48 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 app/components/Scene/SceneTitleBar.vue create mode 100644 app/components/Scene/SceneView.vue diff --git a/app/components/Scene/SceneTitleBar.vue b/app/components/Scene/SceneTitleBar.vue new file mode 100644 index 000000000..5456717dd --- /dev/null +++ b/app/components/Scene/SceneTitleBar.vue @@ -0,0 +1,65 @@ + + + + + diff --git a/app/components/Scene/SceneView.vue b/app/components/Scene/SceneView.vue new file mode 100644 index 000000000..f5b2f2f94 --- /dev/null +++ b/app/components/Scene/SceneView.vue @@ -0,0 +1,48 @@ + + + + + From ebea82d294c781b5cdbffbbc591e93a358135f14 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Tue, 1 Dec 2026 09:56:40 +0100 Subject: [PATCH 046/121] feat(scenes): lay out scenes and add one from the plus menu Co-Authored-By: Claude Opus 5.5 --- app/components/Scene/SceneAddMenu.vue | 43 ++++++ app/components/Scene/ScenesLayout.vue | 141 ++++++++++++++++++ .../unit/components/ScenesLayout.nuxt.test.ts | 39 +++++ 3 files changed, 223 insertions(+) create mode 100644 app/components/Scene/SceneAddMenu.vue create mode 100644 app/components/Scene/ScenesLayout.vue create mode 100644 tests/unit/components/ScenesLayout.nuxt.test.ts diff --git a/app/components/Scene/SceneAddMenu.vue b/app/components/Scene/SceneAddMenu.vue new file mode 100644 index 000000000..6f6525f71 --- /dev/null +++ b/app/components/Scene/SceneAddMenu.vue @@ -0,0 +1,43 @@ + + + diff --git a/app/components/Scene/ScenesLayout.vue b/app/components/Scene/ScenesLayout.vue new file mode 100644 index 000000000..8140a0989 --- /dev/null +++ b/app/components/Scene/ScenesLayout.vue @@ -0,0 +1,141 @@ + + + + + diff --git a/tests/unit/components/ScenesLayout.nuxt.test.ts b/tests/unit/components/ScenesLayout.nuxt.test.ts new file mode 100644 index 000000000..98c25f213 --- /dev/null +++ b/tests/unit/components/ScenesLayout.nuxt.test.ts @@ -0,0 +1,39 @@ +// Third party imports +import { beforeEach, describe, expect, test, vi } from "vitest"; +import { flushPromises } from "@vue/test-utils"; +import { mountSuspended } from "@nuxt/test-utils/runtime"; + +// Local imports +import ScenesLayout from "@ogw_front/components/Scene/ScenesLayout.vue"; +import { vuetify } from "@ogw_tests/utils"; +import { useScenesStore } from "@ogw_front/stores/scenes"; + +const SCENE_VIEW = '[data-testid="sceneView"]'; +const CLOSE_BUTTON = '[data-testid="sceneClose"]'; + +describe("scenes layout", () => { + beforeEach(() => { + const scenesStore = useScenesStore(); + scenesStore.scenes = [ + { id: "scene_1", name: "Scene 1", view_id: "1" }, + { id: "scene_2", name: "Scene 2", view_id: "2" }, + ]; + vi.spyOn(scenesStore, "closeScene").mockImplementation((sceneId) => { + scenesStore.scenes = scenesStore.scenes.filter((scene) => scene.id !== sceneId); + return Promise.resolve(); + }); + }); + + test("renders one SceneView per scene and hides close on the last", async () => { + const wrapper = await mountSuspended(ScenesLayout, { + global: { plugins: [vuetify], stubs: { HybridRenderingView: true } }, + }); + expect(wrapper.findAll(SCENE_VIEW)).toHaveLength(2); + expect(wrapper.findAll(CLOSE_BUTTON)).toHaveLength(2); + + await wrapper.find(CLOSE_BUTTON).trigger("click"); + await flushPromises(); + expect(wrapper.findAll(SCENE_VIEW)).toHaveLength(1); + expect(wrapper.findAll(CLOSE_BUTTON)).toHaveLength(0); + }); +}); From 2dbdc25ffe345a8009eac6dbb4d0af7f0601f379 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Tue, 1 Dec 2026 10:12:11 +0100 Subject: [PATCH 047/121] fix(scenes): lint the scene layout test Co-Authored-By: Claude Opus 5.5 --- tests/unit/components/ScenesLayout.nuxt.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/components/ScenesLayout.nuxt.test.ts b/tests/unit/components/ScenesLayout.nuxt.test.ts index 98c25f213..59b47a36e 100644 --- a/tests/unit/components/ScenesLayout.nuxt.test.ts +++ b/tests/unit/components/ScenesLayout.nuxt.test.ts @@ -5,8 +5,8 @@ import { mountSuspended } from "@nuxt/test-utils/runtime"; // Local imports import ScenesLayout from "@ogw_front/components/Scene/ScenesLayout.vue"; -import { vuetify } from "@ogw_tests/utils"; import { useScenesStore } from "@ogw_front/stores/scenes"; +import { vuetify } from "@ogw_tests/utils"; const SCENE_VIEW = '[data-testid="sceneView"]'; const CLOSE_BUTTON = '[data-testid="sceneClose"]'; @@ -18,9 +18,9 @@ describe("scenes layout", () => { { id: "scene_1", name: "Scene 1", view_id: "1" }, { id: "scene_2", name: "Scene 2", view_id: "2" }, ]; - vi.spyOn(scenesStore, "closeScene").mockImplementation((sceneId) => { + vi.spyOn(scenesStore, "closeScene").mockImplementation(async (sceneId) => { scenesStore.scenes = scenesStore.scenes.filter((scene) => scene.id !== sceneId); - return Promise.resolve(); + await Promise.resolve(); }); }); @@ -31,7 +31,7 @@ describe("scenes layout", () => { expect(wrapper.findAll(SCENE_VIEW)).toHaveLength(2); expect(wrapper.findAll(CLOSE_BUTTON)).toHaveLength(2); - await wrapper.find(CLOSE_BUTTON).trigger("click"); + await wrapper.get(CLOSE_BUTTON).trigger("click"); await flushPromises(); expect(wrapper.findAll(SCENE_VIEW)).toHaveLength(1); expect(wrapper.findAll(CLOSE_BUTTON)).toHaveLength(0); From b3ff17a15d6f65885b536537df644ce6268c8a07 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Tue, 1 Dec 2026 10:12:17 +0100 Subject: [PATCH 048/121] feat(viewer): pass the scene to viewer components Co-Authored-By: Claude Opus 5.5 --- app/components/CameraManager/List.vue | 6 +- app/components/CameraManager/Saver.vue | 4 +- app/components/CameraOrientation.vue | 6 +- app/components/ClippingPlanes.vue | 4 +- app/components/ExplodeFilter.vue | 4 +- app/components/FactorFilterPanel.vue | 4 +- app/components/HybridRenderingView.vue | 8 ++- app/components/HybridViewerTooltip.vue | 4 +- app/components/RemoteRenderingView.vue | 10 ++-- app/components/Ruler.vue | 4 +- app/components/Scene/SceneViewerUi.vue | 55 +++++++++++++++++++ app/components/ShrinkFilter.vue | 4 +- app/components/ThresholdCard.vue | 4 +- app/components/ThresholdFilter.vue | 4 +- app/components/ViewToolbar.vue | 4 +- .../Viewer/ContextMenu/ContextMenu.vue | 6 +- .../Viewer/ContextMenu/ContextMenuItem.vue | 6 +- app/components/Viewer/OrientationCompass.vue | 4 +- app/components/Viewer/OrientationGlobe.vue | 6 +- app/components/Viewer/Ui.vue | 17 ++++-- app/components/ZoomBoxOverlay.vue | 4 +- app/composables/batch_style.ts | 4 +- app/composables/batch_style_model.ts | 4 +- app/composables/compass_dial.ts | 4 +- app/composables/crs_align.ts | 21 +++++-- app/composables/hover_highlight.ts | 4 ++ app/composables/use_adaptive_styles.ts | 5 +- app/composables/use_overlapping_picker.ts | 6 +- app/composables/use_quick_colormap.ts | 5 +- app/composables/view_toolbar_options.ts | 10 +++- app/composables/view_toolbar_tools.ts | 4 +- app/composables/viewer_context_menu.ts | 5 +- app/stores/menu.ts | 32 +++++++---- tests/browser/components/ViewerApp.vue | 44 +++------------ tests/browser/shim/load.ts | 3 +- tests/integration/setup.ts | 2 +- tests/unit/components/CrsAlign.nuxt.test.ts | 10 ++-- .../components/CrsAlignScope.nuxt.test.ts | 4 +- .../components/FactorFilterPanel.nuxt.test.ts | 4 +- .../components/ThresholdFilter.nuxt.test.ts | 8 +-- .../components/ZoomBoxOverlay.nuxt.test.ts | 9 ++- .../unit/composables/batch_style.nuxt.test.ts | 2 + tests/unit/composables/crs_align.nuxt.test.ts | 6 +- .../composables/hover_highlight.nuxt.test.ts | 7 ++- .../use_overlapping_picker.nuxt.test.ts | 6 +- .../viewer_context_menu.nuxt.test.ts | 5 +- tests/unit/helpers/camera_orientation_dial.ts | 6 +- tests/unit/helpers/crs_align.ts | 7 ++- tests/utils.ts | 14 ++++- 49 files changed, 275 insertions(+), 134 deletions(-) create mode 100644 app/components/Scene/SceneViewerUi.vue diff --git a/app/components/CameraManager/List.vue b/app/components/CameraManager/List.vue index e84a479fe..39f952fa5 100644 --- a/app/components/CameraManager/List.vue +++ b/app/components/CameraManager/List.vue @@ -1,9 +1,11 @@