diff --git a/app/components/BasemapAttribution.vue b/app/components/BasemapAttribution.vue
index 20d12b482..6c51a0d57 100644
--- a/app/components/BasemapAttribution.vue
+++ b/app/components/BasemapAttribution.vue
@@ -9,14 +9,18 @@ const basemapStore = useBasemapStore();
{{ basemapStore.attribution }}
diff --git a/app/components/Viewer/ContextMenu/ContextMenu.vue b/app/components/Viewer/ContextMenu/ContextMenu.vue
index fe31445c2..7c46f56b5 100644
--- a/app/components/Viewer/ContextMenu/ContextMenu.vue
+++ b/app/components/Viewer/ContextMenu/ContextMenu.vue
@@ -10,6 +10,7 @@ import { provideBatchGroup } from "@ogw_front/composables/batch_style";
import { useEventListener } from "@vueuse/core";
import { useMenuStore } from "@ogw_front/stores/menu";
import { useTreeviewStore } from "@ogw_front/stores/treeview";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
// A position of the context menu in its container, in pixels
interface ContextMenuPosition {
@@ -35,7 +36,8 @@ const CENTER_BUTTON_SIZE = 52;
const CENTER_BUTTON_HALF_SIZE = 26;
const menuStore = useMenuStore();
-const treeviewStore = useTreeviewStore();
+const viewerId = useViewerId();
+const treeviewStore = useTreeviewStore(viewerId);
const meta_data = computed(() => menuStore.current_meta_data || {});
const isSceneMenu = computed(() => meta_data.value.viewer_object_type === "scene");
@@ -141,7 +143,7 @@ const isOverTreeview = computed(() => {
});
const isOverToolbar = computed(() => {
- const toolbarEl = document.querySelector(".view-toolbar");
+ const toolbarEl = document.querySelector(`[data-viewer-id="${viewerId}"] .view-toolbar`);
if (!toolbarEl) {
return false;
}
diff --git a/app/components/Viewer/ContextMenu/ContextMenuItem.vue b/app/components/Viewer/ContextMenu/ContextMenuItem.vue
index 90a14f89b..589fe512e 100644
--- a/app/components/Viewer/ContextMenu/ContextMenuItem.vue
+++ b/app/components/Viewer/ContextMenu/ContextMenuItem.vue
@@ -11,6 +11,7 @@ import { useAdaptiveStyles } from "@ogw_front/composables/use_adaptive_styles";
import { useMenuStore } from "@ogw_front/stores/menu";
import { useTheme } from "vuetify";
import { useTreeviewStore } from "@ogw_front/stores/treeview";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
const CARD_WIDTH = 300;
const CARD_HEIGHT = 500;
@@ -55,7 +56,8 @@ const TREEVIEW_MARGIN_LEFT = 10;
const TREEVIEW_MARGIN_RIGHT = 20;
const TREEVIEW_ICON_WIDTH = 48;
-const treeviewStore = useTreeviewStore();
+const viewerId = useViewerId();
+const treeviewStore = useTreeviewStore(viewerId);
const isOverTreeview = computed(() => {
const hasAdditional = treeviewStore.opened_views.some((view) => view.id !== "main");
const hasMain = treeviewStore.opened_views.some((view) => view.id === "main");
@@ -71,7 +73,7 @@ const isOverTreeview = computed(() => {
});
const isOverToolbar = computed(() => {
- const toolbarEl = document.querySelector(".view-toolbar");
+ const toolbarEl = document.querySelector(`[data-viewer-id="${viewerId}"] .view-toolbar`);
if (!toolbarEl) {
return false;
}
diff --git a/app/components/Viewer/ContextMenu/InfoCard.vue b/app/components/Viewer/ContextMenu/InfoCard.vue
index 7b3f781cd..3bd52f5a0 100644
--- a/app/components/Viewer/ContextMenu/InfoCard.vue
+++ b/app/components/Viewer/ContextMenu/InfoCard.vue
@@ -13,6 +13,7 @@ import { useCrsStore } from "@ogw_front/stores/crs";
import { useDataStore } from "@ogw_front/stores/data";
import { useLiveDataItem } from "@ogw_front/composables/live_data_item";
import { useMenuStore } from "@ogw_front/stores/menu";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
// The component of a model the context menu is opened on, as the info card shows it
interface MeshComponentInfo {
@@ -137,6 +138,7 @@ function formatId(id: DataId | ModelComponentId | undefined): string {
const formattedId = computed(() => formatId(metaData.data_id));
const crsStore = useCrsStore();
+const viewerId = useViewerId();
// A model component shares the model CRS: the CRS row is only shown for a data
const isData = computed(
() => metaData.data_id !== undefined && metaData.modelId === undefined,
@@ -202,7 +204,7 @@ const liveCrs = computed(() => liveItem.value?.crs ?? metaData.crs);
density="compact"
size="x-small"
class="ml-1"
- @click.stop="crsStore.requestCrsEdit(metaData.data_id)"
+ @click.stop="crsStore.requestCrsEdit(metaData.data_id, viewerId)"
/>
diff --git a/app/components/Viewer/CrsOverlays.vue b/app/components/Viewer/CrsOverlays.vue
index cf80f6089..75c945710 100644
--- a/app/components/Viewer/CrsOverlays.vue
+++ b/app/components/Viewer/CrsOverlays.vue
@@ -24,6 +24,6 @@ const crsStore = useCrsStore();
data-testid="crsAlignPanel"
:escape-function="crsStore.closeCrsAlign"
>
-
+
diff --git a/app/components/Viewer/EdgedCurve/SpecificEdgesColoring.vue b/app/components/Viewer/EdgedCurve/SpecificEdgesColoring.vue
index 4c8c6ce3c..12ab4e780 100644
--- a/app/components/Viewer/EdgedCurve/SpecificEdgesColoring.vue
+++ b/app/components/Viewer/EdgedCurve/SpecificEdgesColoring.vue
@@ -22,9 +22,11 @@ import ViewerOptionsColoringTypeSelector from "@ogw_front/components/Viewer/Opti
import { useBatchStyleModel } from "@ogw_front/composables/batch_style_model";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
-const dataStyleStore = useDataStyleStore();
-const hybridViewerStore = useHybridViewerStore();
+const viewerId = useViewerId();
+const dataStyleStore = useDataStyleStore(viewerId);
+const hybridViewerStore = useHybridViewerStore(viewerId);
const { applyBatchStyle } = useBatchStyle();
interface Props {
diff --git a/app/components/Viewer/EdgedCurve/SpecificEdgesOptions.vue b/app/components/Viewer/EdgedCurve/SpecificEdgesOptions.vue
index 21d5da9e5..99e79dba4 100644
--- a/app/components/Viewer/EdgedCurve/SpecificEdgesOptions.vue
+++ b/app/components/Viewer/EdgedCurve/SpecificEdgesOptions.vue
@@ -11,9 +11,11 @@ import ViewerOptionsWidthSlider from "@ogw_front/components/Viewer/Options/Slide
import { useBatchStyle } from "@ogw_front/composables/batch_style";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
-const dataStyleStore = useDataStyleStore();
-const hybridViewerStore = useHybridViewerStore();
+const viewerId = useViewerId();
+const dataStyleStore = useDataStyleStore(viewerId);
+const hybridViewerStore = useHybridViewerStore(viewerId);
const { applyBatchStyle } = useBatchStyle();
interface Props {
diff --git a/app/components/Viewer/Generic/Mesh/CellsColoring.vue b/app/components/Viewer/Generic/Mesh/CellsColoring.vue
index d99412d94..2957bc8c4 100644
--- a/app/components/Viewer/Generic/Mesh/CellsColoring.vue
+++ b/app/components/Viewer/Generic/Mesh/CellsColoring.vue
@@ -22,9 +22,11 @@ import ViewerOptionsColoringTypeSelector from "@ogw_front/components/Viewer/Opti
import { useBatchStyleModel } from "@ogw_front/composables/batch_style_model";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
-const dataStyleStore = useDataStyleStore();
-const hybridViewerStore = useHybridViewerStore();
+const viewerId = useViewerId();
+const dataStyleStore = useDataStyleStore(viewerId);
+const hybridViewerStore = useHybridViewerStore(viewerId);
const { applyBatchStyle } = useBatchStyle();
interface Props {
diff --git a/app/components/Viewer/Generic/Mesh/CellsOptions.vue b/app/components/Viewer/Generic/Mesh/CellsOptions.vue
index 78a1c6912..183daaaea 100644
--- a/app/components/Viewer/Generic/Mesh/CellsOptions.vue
+++ b/app/components/Viewer/Generic/Mesh/CellsOptions.vue
@@ -8,9 +8,11 @@ import type { Visibility } from "@geode/opengeodeweb-viewer/schema_types";
import { useBatchStyle } from "@ogw_front/composables/batch_style";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
-const dataStyleStore = useDataStyleStore();
-const hybridViewerStore = useHybridViewerStore();
+const viewerId = useViewerId();
+const dataStyleStore = useDataStyleStore(viewerId);
+const hybridViewerStore = useHybridViewerStore(viewerId);
const { applyBatchStyle } = useBatchStyle();
interface Props {
diff --git a/app/components/Viewer/Generic/Mesh/EdgesColoring.vue b/app/components/Viewer/Generic/Mesh/EdgesColoring.vue
index 26324b6ec..19bd853f6 100644
--- a/app/components/Viewer/Generic/Mesh/EdgesColoring.vue
+++ b/app/components/Viewer/Generic/Mesh/EdgesColoring.vue
@@ -22,9 +22,11 @@ import ViewerOptionsColoringTypeSelector from "@ogw_front/components/Viewer/Opti
import { useBatchStyleModel } from "@ogw_front/composables/batch_style_model";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
-const dataStyleStore = useDataStyleStore();
-const hybridViewerStore = useHybridViewerStore();
+const viewerId = useViewerId();
+const dataStyleStore = useDataStyleStore(viewerId);
+const hybridViewerStore = useHybridViewerStore(viewerId);
const { applyBatchStyle } = useBatchStyle();
interface Props {
diff --git a/app/components/Viewer/Generic/Mesh/EdgesOptions.vue b/app/components/Viewer/Generic/Mesh/EdgesOptions.vue
index 3223e895a..a4a6249b8 100644
--- a/app/components/Viewer/Generic/Mesh/EdgesOptions.vue
+++ b/app/components/Viewer/Generic/Mesh/EdgesOptions.vue
@@ -10,9 +10,11 @@ import ViewerOptionsWidthSlider from "@ogw_front/components/Viewer/Options/Slide
import { useBatchStyle } from "@ogw_front/composables/batch_style";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
-const dataStyleStore = useDataStyleStore();
-const hybridViewerStore = useHybridViewerStore();
+const viewerId = useViewerId();
+const dataStyleStore = useDataStyleStore(viewerId);
+const hybridViewerStore = useHybridViewerStore(viewerId);
const { applyBatchStyle } = useBatchStyle();
interface Props {
diff --git a/app/components/Viewer/Generic/Mesh/PointsOptions.vue b/app/components/Viewer/Generic/Mesh/PointsOptions.vue
index e579dda4c..acbc5a4e2 100644
--- a/app/components/Viewer/Generic/Mesh/PointsOptions.vue
+++ b/app/components/Viewer/Generic/Mesh/PointsOptions.vue
@@ -26,9 +26,11 @@ import ViewerOptionsSizeSlider from "@ogw_front/components/Viewer/Options/Slider
import ViewerOptionsVisibilitySwitch from "@ogw_front/components/Viewer/Options/VisibilitySwitch.vue";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
-const dataStyleStore = useDataStyleStore();
-const hybridViewerStore = useHybridViewerStore();
+const viewerId = useViewerId();
+const dataStyleStore = useDataStyleStore(viewerId);
+const hybridViewerStore = useHybridViewerStore(viewerId);
const { applyBatchStyle } = useBatchStyle();
interface Props {
diff --git a/app/components/Viewer/Generic/Mesh/PolygonsColoring.vue b/app/components/Viewer/Generic/Mesh/PolygonsColoring.vue
index 0b0c2b755..b60f28559 100644
--- a/app/components/Viewer/Generic/Mesh/PolygonsColoring.vue
+++ b/app/components/Viewer/Generic/Mesh/PolygonsColoring.vue
@@ -23,9 +23,11 @@ import ViewerOptionsColoringTypeSelector from "@ogw_front/components/Viewer/Opti
import { useBatchStyleModel } from "@ogw_front/composables/batch_style_model";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
-const dataStyleStore = useDataStyleStore();
-const hybridViewerStore = useHybridViewerStore();
+const viewerId = useViewerId();
+const dataStyleStore = useDataStyleStore(viewerId);
+const hybridViewerStore = useHybridViewerStore(viewerId);
const { applyBatchStyle } = useBatchStyle();
interface Props {
diff --git a/app/components/Viewer/Generic/Mesh/PolygonsOptions.vue b/app/components/Viewer/Generic/Mesh/PolygonsOptions.vue
index 4fc78ea3a..51e331922 100644
--- a/app/components/Viewer/Generic/Mesh/PolygonsOptions.vue
+++ b/app/components/Viewer/Generic/Mesh/PolygonsOptions.vue
@@ -9,9 +9,11 @@ import type { Visibility } from "@geode/opengeodeweb-viewer/schema_types";
import { useBatchStyle } from "@ogw_front/composables/batch_style";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
-const dataStyleStore = useDataStyleStore();
-const hybridViewerStore = useHybridViewerStore();
+const viewerId = useViewerId();
+const dataStyleStore = useDataStyleStore(viewerId);
+const hybridViewerStore = useHybridViewerStore(viewerId);
const { applyBatchStyle } = useBatchStyle();
interface Props {
diff --git a/app/components/Viewer/Generic/Mesh/PolyhedraColoring.vue b/app/components/Viewer/Generic/Mesh/PolyhedraColoring.vue
index ecca2edbd..260fb3eb9 100644
--- a/app/components/Viewer/Generic/Mesh/PolyhedraColoring.vue
+++ b/app/components/Viewer/Generic/Mesh/PolyhedraColoring.vue
@@ -21,9 +21,11 @@ import ViewerOptionsColoringTypeSelector from "@ogw_front/components/Viewer/Opti
import { useBatchStyleModel } from "@ogw_front/composables/batch_style_model";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
-const dataStyleStore = useDataStyleStore();
-const hybridViewerStore = useHybridViewerStore();
+const viewerId = useViewerId();
+const dataStyleStore = useDataStyleStore(viewerId);
+const hybridViewerStore = useHybridViewerStore(viewerId);
const { applyBatchStyle } = useBatchStyle();
interface Props {
diff --git a/app/components/Viewer/Generic/Mesh/PolyhedraOptions.vue b/app/components/Viewer/Generic/Mesh/PolyhedraOptions.vue
index 82e689f4d..856372951 100644
--- a/app/components/Viewer/Generic/Mesh/PolyhedraOptions.vue
+++ b/app/components/Viewer/Generic/Mesh/PolyhedraOptions.vue
@@ -8,9 +8,11 @@ import type { Visibility } from "@geode/opengeodeweb-viewer/schema_types";
import { useBatchStyle } from "@ogw_front/composables/batch_style";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
-const dataStyleStore = useDataStyleStore();
-const hybridViewerStore = useHybridViewerStore();
+const viewerId = useViewerId();
+const dataStyleStore = useDataStyleStore(viewerId);
+const hybridViewerStore = useHybridViewerStore(viewerId);
const { applyBatchStyle } = useBatchStyle();
interface Props {
diff --git a/app/components/Viewer/Generic/Model/BlocksOptions.vue b/app/components/Viewer/Generic/Model/BlocksOptions.vue
index fdfe03d5d..457daac61 100644
--- a/app/components/Viewer/Generic/Model/BlocksOptions.vue
+++ b/app/components/Viewer/Generic/Model/BlocksOptions.vue
@@ -1,7 +1,4 @@
diff --git a/app/components/Viewer/Generic/Model/SurfacesOptions.vue b/app/components/Viewer/Generic/Model/SurfacesOptions.vue
index cdf2d1565..defb0a168 100644
--- a/app/components/Viewer/Generic/Model/SurfacesOptions.vue
+++ b/app/components/Viewer/Generic/Model/SurfacesOptions.vue
@@ -1,7 +1,4 @@
@@ -108,7 +115,7 @@ defineExpose({ get_viewer_id });
@show-menu="(args) => emit('show-menu', args)"
/>
-
-
+
+import { onMounted, shallowRef, useTemplateRef } from "vue";
+import ViewerUI from "@ogw_front/components/Viewer/Ui.vue";
+import { useEventListener } from "@vueuse/core";
+import { useMenuStore } from "@ogw_front/stores/menu";
+import { useViewerContextMenu } from "@ogw_front/composables/viewer_context_menu";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
+
+// The UI of a viewer, with its circular menu: the right click on it opens the menu for this viewer only
+const viewerId = useViewerId();
+const menuStore = useMenuStore();
+const { display_menu } = storeToRefs(menuStore);
+const anchor = useTemplateRef("anchor");
+const viewerUI = useTemplateRef("viewerUI");
+const viewerElement = shallowRef();
+
+const { containerWidth, containerHeight, openTreeMenu, openViewerMenu } = useViewerContextMenu(
+ viewerElement,
+ viewerUI,
+ viewerId,
+);
+
+onMounted(() => {
+ viewerElement.value = anchor.value?.closest("[data-viewer-id]") ?? undefined;
+});
+
+useEventListener(viewerElement, "contextmenu", async (event: MouseEvent) => {
+ event.preventDefault();
+ await openViewerMenu(event);
+});
+
+
+
+
+
+
+
+
+
diff --git a/app/components/Viewers/ViewerOverlay.vue b/app/components/Viewers/ViewerOverlay.vue
new file mode 100644
index 000000000..97bdf0491
--- /dev/null
+++ b/app/components/Viewers/ViewerOverlay.vue
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+ {{ viewer?.name }}
+
+
+
+
+
+
diff --git a/app/components/Viewers/ViewerSyncBridge.vue b/app/components/Viewers/ViewerSyncBridge.vue
new file mode 100644
index 000000000..8d2d34a05
--- /dev/null
+++ b/app/components/Viewers/ViewerSyncBridge.vue
@@ -0,0 +1,88 @@
+
+
+
+
+
+
+
diff --git a/app/components/Viewers/ViewerView.vue b/app/components/Viewers/ViewerView.vue
new file mode 100644
index 000000000..e04a107e3
--- /dev/null
+++ b/app/components/Viewers/ViewerView.vue
@@ -0,0 +1,112 @@
+
+
+
+
+
+
+
diff --git a/app/components/Viewers/ViewersLayout.vue b/app/components/Viewers/ViewersLayout.vue
new file mode 100644
index 000000000..df63109dc
--- /dev/null
+++ b/app/components/Viewers/ViewersLayout.vue
@@ -0,0 +1,208 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/components/Viewers/ViewersLayoutSwitcher.vue b/app/components/Viewers/ViewersLayoutSwitcher.vue
new file mode 100644
index 000000000..e49ff4b9d
--- /dev/null
+++ b/app/components/Viewers/ViewersLayoutSwitcher.vue
@@ -0,0 +1,154 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/components/ZoomBoxOverlay.vue b/app/components/ZoomBoxOverlay.vue
index b824d5074..5767c4193 100644
--- a/app/components/ZoomBoxOverlay.vue
+++ b/app/components/ZoomBoxOverlay.vue
@@ -2,10 +2,12 @@
import { type ZoomBox, viewportShapedBox } from "@ogw_internal/stores/hybrid_viewer/zoom_box";
import type { Position } from "@vueuse/core";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
const MIN_ZOOM_BOX_PIXELS = 5;
-const hybridViewerStore = useHybridViewerStore();
+const viewerId = useViewerId();
+const hybridViewerStore = useHybridViewerStore(viewerId);
const overlay = useTemplateRef("overlay");
const { left, top, width, height } = useElementBounding(overlay);
const viewport = computed(() => ({ width: width.value, height: height.value }));
diff --git a/app/composables/attribute_coloring_style.ts b/app/composables/attribute_coloring_style.ts
index afbce7fe2..3eb3855e9 100644
--- a/app/composables/attribute_coloring_style.ts
+++ b/app/composables/attribute_coloring_style.ts
@@ -14,6 +14,7 @@ import type { ModelComponentId } from "@ogw_front/types/identifiers";
import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
import { useBackStore } from "@ogw_front/stores/back";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
// A style property of an attribute coloring, the suffix of its store methods ("Name", "Range", ...)
type StyleProperty = string;
@@ -82,7 +83,8 @@ function attributeSchemas(prefix: SchemaPrefix, activeColoring: ColoringType): A
// Colormap, range and time step of the attributes colored by a scalar bar
function useAttributeColoringStyle(colorings: Ref): AttributeColoringStyle {
const backStore = useBackStore();
- const hybridViewerStore = useHybridViewerStore();
+ const viewerId = useViewerId();
+ const hybridViewerStore = useHybridViewerStore(viewerId);
const currentTimeSteps = ref([]);
const temporalColoring = shallowRef(undefined);
diff --git a/app/composables/batch_style.ts b/app/composables/batch_style.ts
index 8206a98f4..dc01abe8d 100644
--- a/app/composables/batch_style.ts
+++ b/app/composables/batch_style.ts
@@ -15,6 +15,7 @@ import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
import type { ValidAttributeRange } from "@ogw_front/types/attribute";
import { useDataStore } from "@ogw_front/stores/data";
import { useTreeviewStore } from "@ogw_front/stores/treeview";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
type RangesPerData = ReadonlyMap;
@@ -64,7 +65,8 @@ async function applyActionOn(
}
function useBatchStyle(): { applyBatchStyle: typeof applyBatchStyle } {
- const treeviewStore = useTreeviewStore();
+ const viewerId = useViewerId();
+ const treeviewStore = useTreeviewStore(viewerId);
const dataStore = useDataStore();
const group = injectBatchGroup();
diff --git a/app/composables/batch_style_model.ts b/app/composables/batch_style_model.ts
index 5d57d971a..a4de9f7e5 100644
--- a/app/composables/batch_style_model.ts
+++ b/app/composables/batch_style_model.ts
@@ -2,6 +2,7 @@ import { type MaybeRefOrGetter, type WritableComputedRef, computed, toValue } fr
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
import { useBatchStyle } from "@ogw_front/composables/batch_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
// A style model applied to the whole batch of the data, then rendered
function useBatchStyleModel(
@@ -9,7 +10,8 @@ function useBatchStyleModel(
getter: (dataId: DataId) => Value | undefined,
setter: (dataId: DataId, value: Value) => Promise,
): WritableComputedRef {
- const hybridViewerStore = useHybridViewerStore();
+ const viewerId = useViewerId();
+ const hybridViewerStore = useHybridViewerStore(viewerId);
const { applyBatchStyle } = useBatchStyle();
async function applyValue(value: Value): Promise {
diff --git a/app/composables/clipping_slices.ts b/app/composables/clipping_slices.ts
index 05d265207..2588054ae 100644
--- a/app/composables/clipping_slices.ts
+++ b/app/composables/clipping_slices.ts
@@ -1,14 +1,5 @@
-import {
- DEFAULT_SLICE_AXIS,
- SLICE_AXES,
- type SliceAxis,
- areAllGrids,
-} from "@ogw_front/utils/slice";
import type { ClippingItemId } from "@ogw_front/composables/clipping_planes_widget_entries";
-import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
-import type { DataIdentified } from "@ogw_front/types/identifiers";
-import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types";
-import type { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import type { SliceAxis } from "@ogw_front/utils/slice";
// The layer of cells of a grid a slice shows, counted along the slice axis
type SliceLayer = number;
@@ -25,156 +16,4 @@ interface Slice {
index: SliceLayer;
}
-interface SliceList {
- sliceEnabled: Ref;
- slices: Ref;
- addSlice: () => void;
- removeSlice: (index: SliceIndex) => void;
- resetSlices: () => void;
-}
-
-interface SliceSyncParams {
- slices: Ref;
- sliceMaxIndices: Ref;
- isAllGrid: ComputedRef;
- isSliceActive: ComputedRef;
- targetIds: ComputedRef;
- getUntargetedIds: () => DataId[];
- hybridViewerStore: ReturnType;
-}
-
-interface ClippingSlicesParams {
- allItems: ComputedRef<(DataIdentified & { geode_object_type: GeodeObjectType })[]>;
- targetIds: ComputedRef;
- getUntargetedIds: () => DataId[];
- newItemId: () => ClippingItemId;
- hybridViewerStore: ReturnType;
-}
-
-interface ClippingSlices extends SliceList {
- sliceMaxIndices: Ref;
- isAllGrid: ComputedRef;
- isSliceActive: ComputedRef;
- applySlices: () => Promise;
- removeSlices: (allIds: DataId[]) => Promise;
-}
-
-function useSliceList(newItemId: () => ClippingItemId): SliceList {
- const sliceEnabled = ref(false);
- const slices = ref([{ id: newItemId(), axis: DEFAULT_SLICE_AXIS, index: 0 }]);
-
- function addSlice(): void {
- const lastSlice = slices.value.at(-1);
- slices.value.push({
- id: newItemId(),
- axis: lastSlice ? SLICE_AXES[lastSlice.axis].next : DEFAULT_SLICE_AXIS,
- index: 0,
- });
- }
-
- function removeSlice(index: SliceIndex): void {
- slices.value.splice(index, 1);
- }
-
- function resetSlices(): void {
- sliceEnabled.value = false;
- slices.value = [{ id: newItemId(), axis: DEFAULT_SLICE_AXIS, index: 0 }];
- }
-
- return { sliceEnabled, slices, addSlice, removeSlice, resetSlices };
-}
-
-// Runs the tasks one after the other, whatever the outcome of the previous one
-function createSliceQueue(): (task: () => Promise) => Promise {
- let pendingSlices: Promise = Promise.resolve();
-
- return async (task) => {
- const previous = pendingSlices;
- pendingSlices = (async (): Promise => {
- await Promise.allSettled([previous]);
- await task();
- })();
- await pendingSlices;
- };
-}
-
-function useSliceSync(params: SliceSyncParams): {
- applySlices: () => Promise;
- removeSlices: (allIds: DataId[]) => Promise;
-} {
- const { slices, sliceMaxIndices, isAllGrid, isSliceActive, targetIds, hybridViewerStore } =
- params;
- const queueSliceTask = createSliceQueue();
- let areSlicesApplied = false;
-
- function getSlicesPayload(isActive: boolean): Pick[] {
- if (!isActive) {
- return [];
- }
- return slices.value.map(({ axis, index }) => ({ axis, index }));
- }
-
- async function sendSlices(): Promise {
- if (!isAllGrid.value && !areSlicesApplied) {
- return;
- }
- const isActive = isSliceActive.value;
- const untargetedIds = params.getUntargetedIds();
- if (targetIds.value.length > 0) {
- const maxIndices = await hybridViewerStore.setSlice(
- targetIds.value,
- getSlicesPayload(isActive),
- );
- if (isAllGrid.value) {
- sliceMaxIndices.value = maxIndices;
- }
- if (isActive) {
- for (const slice of slices.value) {
- slice.index = Math.min(slice.index, maxIndices[slice.axis]);
- }
- }
- }
- if (areSlicesApplied && untargetedIds.length > 0) {
- await hybridViewerStore.setSlice(untargetedIds, []);
- }
- areSlicesApplied = isActive;
- }
-
- async function applySlices(): Promise {
- await queueSliceTask(sendSlices);
- }
-
- async function removeSlices(allIds: DataId[]): Promise {
- await queueSliceTask(async () => {
- if (areSlicesApplied) {
- await hybridViewerStore.setSlice(allIds, []);
- areSlicesApplied = false;
- }
- });
- }
-
- return { applySlices, removeSlices };
-}
-
-// The slices applied to the targeted grids
-function useClippingSlices(params: ClippingSlicesParams): ClippingSlices {
- const { allItems, targetIds, getUntargetedIds, newItemId, hybridViewerStore } = params;
- const list = useSliceList(newItemId);
- const sliceMaxIndices = ref([0, 0, 0]);
- const isAllGrid = computed(() => areAllGrids(allItems.value, targetIds.value));
- const isSliceActive = computed(() => isAllGrid.value && list.sliceEnabled.value);
- const sync = useSliceSync({
- slices: list.slices,
- sliceMaxIndices,
- isAllGrid,
- isSliceActive,
- targetIds,
- getUntargetedIds,
- hybridViewerStore,
- });
-
- return { ...list, ...sync, sliceMaxIndices, isAllGrid, isSliceActive };
-}
-
-export { useClippingSlices };
export type { Slice, SliceIndex, SliceLayer, SliceMaxLayers };
diff --git a/app/composables/compass_dial.ts b/app/composables/compass_dial.ts
index 4f428cdf8..427919d30 100644
--- a/app/composables/compass_dial.ts
+++ b/app/composables/compass_dial.ts
@@ -2,6 +2,7 @@ import type { ComputedRef, Ref } from "vue";
import { type ViewBasis, cameraViewBasis, toCameraPose } from "@ogw_front/utils/orientation_gizmo";
import { compassHeading, compassTilt } from "@ogw_front/utils/orientation_compass";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
interface CompassDial {
basis: ComputedRef;
@@ -15,7 +16,8 @@ interface CompassDial {
// And the compass layout of the orientation panel (CameraOrientationDial.vue) turn the same way.
// The last readable heading is kept while the camera is rolled until no heading can be read.
function useCompassDial(): CompassDial {
- const hybridViewerStore = useHybridViewerStore();
+ const viewerId = useViewerId();
+ const hybridViewerStore = useHybridViewerStore(viewerId);
const basis = computed(() => {
const pose = toCameraPose(hybridViewerStore.camera_options);
return pose && cameraViewBasis(pose);
diff --git a/app/composables/crs.ts b/app/composables/crs.ts
index 4b55794f8..078a321df 100644
--- a/app/composables/crs.ts
+++ b/app/composables/crs.ts
@@ -1,12 +1,12 @@
import type { AssignResponse, PlausibleEntry } from "@ogw_front/composables/crs_assign";
import { type DataItem, useDataStore } from "@ogw_front/stores/data";
import { formatCrsCode, sameCrs } from "@ogw_front/utils/crs";
+import { reloadObject, viewersShowing } from "@ogw_front/utils/reload_object";
import type { CRS } from "@geode/opengeodeweb-back/schema_types";
import type { Coordinate } from "@ogw_front/types/geometry";
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
import type { LightViewable } from "@ogw_front/types/data";
import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
-import { reloadObject } from "@ogw_front/utils/reload_object";
import { useBackStore } from "@ogw_front/stores/back";
import { useCrsStore } from "@ogw_front/stores/crs";
import { useFeedbackStore } from "@ogw_front/stores/feedback";
@@ -74,7 +74,12 @@ async function refresh(
// Which must no longer hold the previous coordinates
await dataStore.updateItem(item.data_id, { crs });
if (focus) {
- await useHybridViewerStore().focusCameraOnObject(item.data_id);
+ // The coordinates moved in every viewer showing the item
+ await Promise.all(
+ viewersShowing([item.data_id]).map(async (viewerId) => {
+ await useHybridViewerStore(viewerId).focusCameraOnObject(item.data_id);
+ }),
+ );
}
}
diff --git a/app/composables/crs_align.ts b/app/composables/crs_align.ts
index 4493c6943..77bae264d 100644
--- a/app/composables/crs_align.ts
+++ b/app/composables/crs_align.ts
@@ -2,6 +2,7 @@ import type { ComputedRef, Ref } from "vue";
import { onKeyStroke, watchDebounced } from "@vueuse/core";
import type { Coordinate } from "@ogw_front/types/geometry";
import type { CrsPoint } from "@ogw_front/composables/crs";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
import { useViewerStore } from "@ogw_front/stores/viewer";
import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
@@ -90,7 +91,7 @@ function targetCrsPoints({ targetPoints }: AlignState): CrsPoint[] {
return targetPoints.value.map((point) => ({ x: toNumber(point.x), y: toNumber(point.y) }));
}
-async function preview({ sourcePoints, pickedZ }: AlignState): Promise {
+async function preview(viewerId: ViewerId, { sourcePoints, pickedZ }: AlignState): Promise {
const points = sourcePoints.value
.map((point, index) => ({
x: toNumber(point.x),
@@ -100,7 +101,10 @@ async function preview({ sourcePoints, pickedZ }: AlignState): Promise {
}))
.filter(({ filled }) => filled)
.map(({ x, y, z }) => ({ x, y, z }));
- await useViewerStore().request({ schema: preview_schema, params: { points, style: "points" } });
+ await useViewerStore().request({
+ schema: preview_schema,
+ params: { viewer_id: viewerId, points, style: "points" },
+ });
}
// A point picked on the data fills the first empty source point
@@ -121,12 +125,13 @@ function placePickedPoint(
}
// Picking, preview and Escape follow the viewer while the alignment is mounted
-function followViewer(state: AlignState, reset: () => void): void {
+function followViewer(viewerId: ViewerId, state: AlignState, reset: () => void): void {
const viewerStore = useViewerStore();
watch(
() => viewerStore.picked_point,
(picked) => {
- if (state.pickingActive.value) {
+ // Only a pick made in the viewer the alignment belongs to fills its points
+ if (state.pickingActive.value && viewerStore.picked_viewer_id === viewerId) {
placePickedPoint(state, picked);
}
},
@@ -135,7 +140,7 @@ function followViewer(state: AlignState, reset: () => void): void {
watchDebounced(
state.sourcePoints,
async () => {
- await preview(state);
+ await preview(viewerId, state);
},
{
deep: true,
@@ -156,12 +161,15 @@ function followViewer(state: AlignState, reset: () => void): void {
});
onUnmounted(async () => {
reset();
- await viewerStore.request({ schema: preview_schema, params: { points: [], style: "points" } });
+ await viewerStore.request({
+ schema: preview_schema,
+ params: { viewer_id: viewerId, points: [], style: "points" },
+ });
});
}
// Source points are picked on the data (only x and y are used) or typed, target points are typed
-function useCrsAlign(): UseCrsAlignReturn {
+function useCrsAlign(viewerId: ViewerId): UseCrsAlignReturn {
const viewerStore = useViewerStore();
const state: AlignState = {
sourcePoints: ref(emptyPoints()),
@@ -202,7 +210,7 @@ function useCrsAlign(): UseCrsAlignReturn {
state.pickedSources.value = notPicked();
}
- followViewer(state, reset);
+ followViewer(viewerId, state, reset);
return {
sourcePoints: state.sourcePoints,
diff --git a/app/composables/crs_assign.ts b/app/composables/crs_assign.ts
index 548b6eb4a..eeef14545 100644
--- a/app/composables/crs_assign.ts
+++ b/app/composables/crs_assign.ts
@@ -6,6 +6,7 @@ import type { Description } from "@ogw_front/types/ui";
import { formatCrsCode } from "@ogw_front/utils/crs";
import { useCrsStore } from "@ogw_front/stores/crs";
import { useFeedbackStore } from "@ogw_front/stores/feedback";
+import { viewersShowing } from "@ogw_front/utils/reload_object";
interface AssignedEntry extends DataIdentified {
name: CrsItem["name"];
@@ -80,7 +81,11 @@ function useOpenCrsAlignment(): (target: Pick) => Promise {
// The panel needs the whole data: a linked data is only known by its CRS fields
const full = await dataStore.item(target.data_id);
- crsStore.openCrsAlign(full);
+ // The viewer that asked for the CRS edit, else the first one showing the data
+ const viewerId = crsStore.crsEditViewerId ?? viewersShowing([target.data_id])[0];
+ if (viewerId !== undefined) {
+ crsStore.openCrsAlign(full, viewerId);
+ }
};
}
diff --git a/app/composables/global_attribute_style.ts b/app/composables/global_attribute_style.ts
index 8dbdda560..df0a42a42 100644
--- a/app/composables/global_attribute_style.ts
+++ b/app/composables/global_attribute_style.ts
@@ -9,6 +9,7 @@ import {
import type { ColoringType } from "@ogw_front/types/attribute";
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
interface MeshElement {
// Element type of the store methods, e.g. "MeshPoints" for "setMeshPointsVertexAttributeRange"
@@ -34,7 +35,8 @@ function isColoring(value: unknown): value is { active?: ColoringType } {
export function useGlobalAttributeStyle(
dataIdRef: Ref,
): AttributeColoringStyle {
- const dataStyleStore = useDataStyleStore();
+ const viewerId = useViewerId();
+ const dataStyleStore = useDataStyleStore(viewerId);
function meshColoring(
dataId: DataId,
diff --git a/app/composables/hover_highlight.ts b/app/composables/hover_highlight.ts
index 1b7c71762..7188c7179 100644
--- a/app/composables/hover_highlight.ts
+++ b/app/composables/hover_highlight.ts
@@ -1,10 +1,11 @@
+import type { BlockId } from "@geode/opengeodeweb-viewer/schema_types";
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
import type { HighlightableObjectType } from "@ogw_front/types/identifiers";
import type { Milliseconds } from "@ogw_front/types/time";
import type { ParamsOf } from "@ogw_shared/utils/types";
-import type { ViewerId } from "@geode/opengeodeweb-viewer/schema_types";
import { consola } from "consola";
import { useDataStore } from "@ogw_front/stores/data";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
import { useViewerStore } from "@ogw_front/stores/viewer";
import vtk_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
@@ -13,8 +14,8 @@ const HOVER_DELAY = 200;
type HighlightSchema =
(typeof vtk_schemas)["opengeodeweb_viewer"][HighlightableObjectType]["highlight"];
type BlockIdsProvider =
- | readonly ViewerId[]
- | (() => readonly ViewerId[] | Promise);
+ | readonly BlockId[]
+ | (() => readonly BlockId[] | Promise);
// Every live instance, so a highlight can be released from outside the component that started it
const instances = new Set<(dataId: DataId) => void>();
@@ -31,6 +32,7 @@ function useHoverhighlight(): {
onHoverEnter: typeof onHoverEnter;
onHoverLeave: typeof onHoverLeave;
} {
+ const viewerId = useViewerId();
const viewerStore = useViewerStore();
const dataStore = useDataStore();
let timer: ReturnType | undefined = undefined;
@@ -78,6 +80,7 @@ function useHoverhighlight(): {
highlighted = { dataId, type };
const params = {
+ viewer_id: viewerId,
id: dataId,
visibility: true,
...(type === "model" && { block_ids }),
@@ -141,6 +144,7 @@ function useHoverhighlight(): {
const { type } = highlighted;
const schema = vtk_schemas.opengeodeweb_viewer[type].highlight;
const params = {
+ viewer_id: viewerId,
id: dataId,
visibility: false,
...(type === "model" && { block_ids: [] }),
diff --git a/app/composables/model_attribute_style.ts b/app/composables/model_attribute_style.ts
index d1244efc4..675cf9ac0 100644
--- a/app/composables/model_attribute_style.ts
+++ b/app/composables/model_attribute_style.ts
@@ -12,6 +12,7 @@ import type { ColoringType } from "@ogw_front/types/attribute";
import type { ModelComponentType } from "@ogw_front/types/model";
import { useDataStore } from "@ogw_front/stores/data";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
// Components of the same type colored by the same attribute share the store methods, e.g. "modelBlocksPolyhedronAttributeName"
interface ComponentGroup {
@@ -46,9 +47,10 @@ function modelColoring(
// Styles the model components colored by the picked scalar bar
export function useModelAttributeStyle(
modelIdRef: Ref,
- blockViewerIdsRef: Ref,
+ componentBlockIdsRef: Ref,
): AttributeColoringStyle {
- const dataStyleStore = useDataStyleStore();
+ const viewerId = useViewerId();
+ const dataStyleStore = useDataStyleStore(viewerId);
const dataStore = useDataStore();
const colorings = shallowRef([]);
@@ -56,10 +58,10 @@ export function useModelAttributeStyle(
async function loadColorings(): Promise {
const modelId = modelIdRef.value;
- const blockViewerIds = blockViewerIdsRef.value;
- const components = await dataStore.getComponentsByViewerIds(modelId, blockViewerIds);
+ const componentBlockIds = componentBlockIdsRef.value;
+ const components = await dataStore.getComponentsByBlockIds(modelId, componentBlockIds);
// A newer pick replaced this one while the components were read
- if (modelId !== modelIdRef.value || blockViewerIds !== blockViewerIdsRef.value) {
+ if (modelId !== modelIdRef.value || componentBlockIds !== componentBlockIdsRef.value) {
return;
}
const groups = new Map();
@@ -78,6 +80,6 @@ export function useModelAttributeStyle(
await style.loadTimeSteps();
}
- watch([modelIdRef, blockViewerIdsRef], loadColorings, { immediate: true });
+ watch([modelIdRef, componentBlockIdsRef], loadColorings, { immediate: true });
return style;
}
diff --git a/app/composables/model_header_hover.ts b/app/composables/model_header_hover.ts
index a093be1bf..058a81786 100644
--- a/app/composables/model_header_hover.ts
+++ b/app/composables/model_header_hover.ts
@@ -2,6 +2,7 @@ import { releaseHoverHighlight, useHoverhighlight } from "@ogw_front/composables
import type { ModelId } from "@ogw_front/types/identifiers";
import { useDataStore } from "@ogw_front/stores/data";
import { useTreeviewStore } from "@ogw_front/stores/treeview";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
import { viewModelId } from "@ogw_front/utils/treeview";
// Hovering a model tree header shows its model in the viewer and its row in the objects tree
@@ -9,7 +10,8 @@ export function useModelHeaderHover(): {
onModelHeaderEnter: (modelId: ModelId) => void;
onModelHeaderLeave: (modelId: ModelId) => void;
} {
- const treeviewStore = useTreeviewStore();
+ const viewerId = useViewerId();
+ const treeviewStore = useTreeviewStore(viewerId);
const dataStore = useDataStore();
const { onHoverEnter, onHoverLeave } = useHoverhighlight();
@@ -18,8 +20,8 @@ export function useModelHeaderHover(): {
onHoverEnter(
modelId,
async () => {
- const viewerIds = await dataStore.getAllModelComponentsViewerIds(modelId);
- return viewerIds;
+ const blockIds = await dataStore.getAllModelComponentsBlockIds(modelId);
+ return blockIds;
},
"model",
);
diff --git a/app/composables/model_style.ts b/app/composables/model_style.ts
index dee2ea98c..11eec95f7 100644
--- a/app/composables/model_style.ts
+++ b/app/composables/model_style.ts
@@ -2,6 +2,7 @@ import type { ColorRGBA, Visibility } from "@geode/opengeodeweb-viewer/schema_ty
import type { MaybeRefOrGetter, WritableComputedRef } from "vue";
import type { ModelComponentId, ModelId } from "@ogw_front/types/identifiers";
import type { ColoringType } from "@ogw_front/types/attribute";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
import { useBatchStyleModel } from "@ogw_front/composables/batch_style_model";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
@@ -13,8 +14,8 @@ interface ModelStyle {
}
// The style of a whole model, applied to the batch of the model then rendered
-export function useModelStyle(modelId: MaybeRefOrGetter): ModelStyle {
- const dataStyleStore = useDataStyleStore();
+export function useModelStyle(viewerId: ViewerId, modelId: MaybeRefOrGetter): ModelStyle {
+ const dataStyleStore = useDataStyleStore(viewerId);
function visibleComponents(targetId: ModelId): ModelComponentId[] {
return dataStyleStore.visibleMeshComponents(targetId).value;
diff --git a/app/composables/model_tree.ts b/app/composables/model_tree.ts
index d10b70b02..adedea2b5 100644
--- a/app/composables/model_tree.ts
+++ b/app/composables/model_tree.ts
@@ -15,6 +15,7 @@ import { compareSelections } from "@ogw_front/utils/treeview";
import { useDataStore } from "@ogw_front/stores/data";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
type ModelTreeCategory = FormattedComponentGroup | CollectionComponentGroup;
type ModelTreeCache = Record;
@@ -57,8 +58,9 @@ function useModelVisibility(modelId: ModelId): {
selection: typeof selection;
updateVisibility: typeof updateVisibility;
} {
- const dataStyleStore = useDataStyleStore();
- const hybridViewerStore = useHybridViewerStore();
+ const viewerId = useViewerId();
+ const dataStyleStore = useDataStyleStore(viewerId);
+ const hybridViewerStore = useHybridViewerStore(viewerId);
const selection = dataStyleStore.visibleMeshComponents(modelId);
async function updateVisibility(current: readonly ModelComponentId[]): Promise {
diff --git a/app/composables/model_tree_drag.ts b/app/composables/model_tree_drag.ts
index 7a8e5a8fb..3d1f62921 100644
--- a/app/composables/model_tree_drag.ts
+++ b/app/composables/model_tree_drag.ts
@@ -1,6 +1,7 @@
import type { TreeViewId } from "@ogw_front/types/identifiers";
import type { TreeViewIndex } from "@ogw_front/types/tree";
import { useTreeviewStore } from "@ogw_front/stores/treeview";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
// A drop target has to accept the drag over it
function onDragOver(event: DragEvent): void {
@@ -17,7 +18,8 @@ export function useModelTreeDrag(): {
onDrop: (targetId: TreeViewId) => void;
dropSide: (targetId: TreeViewId) => string | undefined;
} {
- const treeviewStore = useTreeviewStore();
+ const viewerId = useViewerId();
+ const treeviewStore = useTreeviewStore(viewerId);
const draggedId = ref(undefined);
// Model button hovered while dragging another one: the line shows where the dragged one lands
const dropTargetId = ref(undefined);
diff --git a/app/composables/orientation_overlay.ts b/app/composables/orientation_overlay.ts
index b2cc69deb..84a67cd97 100644
--- a/app/composables/orientation_overlay.ts
+++ b/app/composables/orientation_overlay.ts
@@ -1,5 +1,6 @@
import type { ComputedRef, Ref } from "vue";
import type { SceneOrientationWidget } from "@ogw_internal/stores/data_style/types";
+import type { ViewerId } from "@ogw_internal/stores/viewers/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: { viewer_id: ViewerId; 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 viewer, undefined when the app keeps it
+function hideViewerMarkerRequest(viewerId: ViewerId): HideViewerMarkerRequest | undefined {
if (!isOrientationOverlayEnabled()) {
return undefined;
}
return {
schema: viewer_schemas.opengeodeweb_viewer.viewer.set_orientation_widget,
- params: { marker: NO_VIEWER_MARKER },
+ params: { viewer_id: viewerId, marker: NO_VIEWER_MARKER },
};
}
// To call after each viewer reset, which brings the VTK axes back
async function hideViewerMarker(
+ viewerId: ViewerId,
request: (args: HideViewerMarkerRequest) => Promise,
): Promise {
- const hideMarker = hideViewerMarkerRequest();
+ const hideMarker = hideViewerMarkerRequest(viewerId);
if (!hideMarker) {
return;
}
@@ -65,41 +67,48 @@ async function hideViewerMarker(
interface AxesVisibilityRequest {
schema: typeof viewer_schemas.opengeodeweb_viewer.viewer.axes;
- params: { visibility: boolean };
+ params: { viewer_id: ViewerId; visibility: boolean };
}
-// Whether the orientation marker shows. A viewer reset shows it again
-const orientationMarkerVisible = ref(true);
+// Whether the orientation marker of each viewer shows. A viewer reset shows it again
+const orientationMarkersHidden = ref>({});
-function useOrientationMarkerVisible(): Readonly[> {
- return readonly(orientationMarkerVisible);
+function useOrientationMarkerVisible(viewerId: ViewerId): Readonly][> {
+ return computed(() => orientationMarkersHidden.value[viewerId] !== true);
+}
+
+// A closed viewer keeps no state
+function forgetOrientationMarker(viewerId: ViewerId): void {
+ Reflect.deleteProperty(orientationMarkersHidden.value, viewerId);
}
// The viewer keeps the visibility for its own marker (scene screenshots), the overlay follows it
async function setOrientationMarkerVisibility(
+ viewerId: ViewerId,
visibility: boolean,
request: (args: AxesVisibilityRequest) => Promise,
): Promise {
await request({
schema: viewer_schemas.opengeodeweb_viewer.viewer.axes,
- params: { visibility },
+ params: { viewer_id: viewerId, visibility },
});
- orientationMarkerVisible.value = visibility;
+ orientationMarkersHidden.value[viewerId] = !visibility;
}
// To call after each viewer reset, which shows the VTK marker again
-function resetOrientationMarkerVisibility(): void {
- orientationMarkerVisible.value = true;
+function resetOrientationMarkerVisibility(viewerId: ViewerId): void {
+ orientationMarkersHidden.value[viewerId] = false;
}
interface ViewerMarkerRequest {
schema: typeof viewer_schemas.opengeodeweb_viewer.viewer.set_orientation_widget;
- params: { marker: ViewerOrientationMarker };
+ params: { viewer_id: ViewerId; 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(
+ viewerId: ViewerId,
marker: SceneOrientationWidget,
request: (args: ViewerMarkerRequest) => Promise,
capture: () => Promise,
@@ -109,17 +118,18 @@ async function withViewerMarker(
}
await request({
schema: viewer_schemas.opengeodeweb_viewer.viewer.set_orientation_widget,
- params: { marker },
+ params: { viewer_id: viewerId, marker },
});
try {
return await capture();
} finally {
- await hideViewerMarker(request);
+ await hideViewerMarker(viewerId, request);
}
}
export {
NO_VIEWER_MARKER,
+ forgetOrientationMarker,
hideViewerMarker,
hideViewerMarkerRequest,
isOrientationOverlayEnabled,
diff --git a/app/composables/physical_property_coloring.ts b/app/composables/physical_property_coloring.ts
index 286c58226..d6155312e 100644
--- a/app/composables/physical_property_coloring.ts
+++ b/app/composables/physical_property_coloring.ts
@@ -11,6 +11,7 @@ import type { ValidAttributeInput } from "@ogw_internal/stores/data_style/attrib
import { useColorMapResolver } from "@ogw_front/composables/attribute_selector";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
// The coloring a component goes back to when the property coloring is removed
const CONSTANT_COLORING: ColoringType = "constant";
@@ -101,8 +102,9 @@ export function usePhysicalPropertyColoring(modelId: ModelId): {
isColoredBy: (node: PhysicalPropertyNode) => boolean;
toggleColoring: (node: PhysicalPropertyNode) => Promise;
} {
- const dataStyleStore = useDataStyleStore();
- const hybridViewerStore = useHybridViewerStore();
+ const viewerId = useViewerId();
+ const dataStyleStore = useDataStyleStore(viewerId);
+ const hybridViewerStore = useHybridViewerStore(viewerId);
const defaultColorMapFor = useColorMapResolver(() => modelId);
function nodeMethods(node: PhysicalPropertyNode): ColoringMethods | undefined {
diff --git a/app/composables/project_manager_helpers/reset.ts b/app/composables/project_manager_helpers/reset.ts
index b54bafb9c..3d598a972 100644
--- a/app/composables/project_manager_helpers/reset.ts
+++ b/app/composables/project_manager_helpers/reset.ts
@@ -1,36 +1,27 @@
-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 { useCameraManagerStore } from "@ogw_front/stores/camera_manager";
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 { useViewerStore } from "@ogw_front/stores/viewer";
+import { useViewersStore } from "@ogw_front/stores/viewers";
-// Empties the viewer and every store, ready to receive an imported project.
+// Empties the viewer and every store, ready to receive an imported project: viewer_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 useViewersStore().resetViewers();
- treeviewStore.clear();
await dataStore.clear();
- hybridViewerStore.clear();
crsStore.reset();
basemapStore.reset();
+ await useCameraManagerStore().reset();
}
export { resetProject };
diff --git a/app/composables/project_manager_helpers/restore.ts b/app/composables/project_manager_helpers/restore.ts
index 57c3a0aa6..342b2199d 100644
--- a/app/composables/project_manager_helpers/restore.ts
+++ b/app/composables/project_manager_helpers/restore.ts
@@ -1,14 +1,44 @@
+import { INITIAL_VIEWER_ID, type ViewersSnapshot } from "@ogw_internal/stores/viewers/types";
import type { ProjectSnapshot } from "@ogw_front/composables/project_manager_helpers/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";
import { useBasemapStore } from "@ogw_front/stores/basemap";
+import { useCameraManagerStore } from "@ogw_front/stores/camera_manager";
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 { useTreeviewStore } from "@ogw_front/stores/treeview";
import { useViewerStore } from "@ogw_front/stores/viewer";
+import { useViewersStore } from "@ogw_front/stores/viewers";
+
+type ViewersProject = ProjectSnapshot & { viewers: ViewersSnapshot };
+
+// A project saved with a single viewer opens as viewer_1, showing all its data with the stores of that viewer
+function withViewers(snapshot: ProjectSnapshot): ViewersProject {
+ if (snapshot.viewers !== undefined) {
+ return { ...snapshot, viewers: snapshot.viewers };
+ }
+ const dataIds = (snapshot.data?.items ?? []).map((item) => fromLegacyDataId(item).data_id);
+ return {
+ ...snapshot,
+ viewers: {
+ viewers: [{ id: INITIAL_VIEWER_ID, name: "Viewer 1", view_id: "" }],
+ contents: { [INITIAL_VIEWER_ID]: dataIds },
+ links: [],
+ counter: 1,
+ },
+ [`treeview-${INITIAL_VIEWER_ID}`]: snapshot.treeview,
+ [`hybridViewer-${INITIAL_VIEWER_ID}`]: snapshot.hybridViewer,
+ [`dataStyle-${INITIAL_VIEWER_ID}`]: snapshot.dataStyle,
+ };
+}
+
+function viewerIds(project: ViewersProject): string[] {
+ return project.viewers.viewers.map((viewer) => viewer.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
@@ -22,46 +52,65 @@ function restoreCrs(snapshot: ProjectSnapshot): void {
}
}
-async function restoreData(snapshot: ProjectSnapshot): Promise {
+async function restoreData(project: ViewersProject): 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 viewerId of viewerIds(project)) {
+ useTreeviewStore(viewerId).importStores(project[`treeview-${viewerId}`]);
}
- await hybridViewerStore.initHybridViewer();
- await importWorkflowFromSnapshot(snapshot.data?.items ?? []);
+ if (project.data !== undefined) {
+ await dataStore.importStores(project.data);
+ }
+ await Promise.all(
+ viewerIds(project).map(async (viewerId) => {
+ await useHybridViewerStore(viewerId).initHybridViewer();
+ }),
+ );
+ await importWorkflowFromSnapshot(project.data?.items ?? []);
}
-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 restoreViewerView(project: ViewersProject, viewerId: string): Promise {
+ const dataStyleStore = useDataStyleStore(viewerId);
+ const hybridViewerStore = useHybridViewerStore(viewerId);
+ await hybridViewerStore.importStores(project[`hybridViewer-${viewerId}`]);
+ const dataStyle = project[`dataStyle-${viewerId}`];
+ if (dataStyle !== undefined) {
+ await dataStyleStore.importStores(dataStyle);
}
await dataStyleStore.applyAllStylesFromState();
+ await hybridViewerStore.applyAllFiltersFromState();
}
-// Loads a project snapshot into the (already reset) viewer and stores.
+async function restoreViews(project: ViewersProject): Promise {
+ restoreCrs(project);
+ await useBasemapStore().importStores(project.basemap);
+ await useCameraManagerStore().importStores(project.cameraManager);
+ await Promise.all(
+ viewerIds(project).map(async (viewerId) => {
+ await restoreViewerView(project, viewerId);
+ }),
+ );
+}
+
+// Loads a project snapshot into the (already reset) viewer and stores: its viewers first, then the stores of
+// Each viewer
async function restoreProject(snapshot: ProjectSnapshot): Promise {
const viewerStore = useViewerStore();
- const treeviewStore = useTreeviewStore();
+ const viewersStore = useViewersStore();
+ const project = withViewers(snapshot);
- treeviewStore.isImporting = true;
+ viewersStore.isImporting = true;
+ await viewersStore.closeEveryViewer();
await importProjectToViewer(viewerStore.client);
- await restoreData(snapshot);
- await restoreViews(snapshot);
+ await viewersStore.importStores(project.viewers);
+ await restoreData(project);
+ await restoreViews(project);
- treeviewStore.finalizeImportSelection();
- treeviewStore.isImporting = false;
+ for (const viewerId of viewerIds(project)) {
+ useTreeviewStore(viewerId).finalizeImportSelection();
+ }
+ viewersStore.isImporting = false;
}
export { restoreProject };
diff --git a/app/composables/project_manager_helpers/types.ts b/app/composables/project_manager_helpers/types.ts
index 82735de71..451d9b1e2 100644
--- a/app/composables/project_manager_helpers/types.ts
+++ b/app/composables/project_manager_helpers/types.ts
@@ -1,12 +1,14 @@
import type { BasemapSnapshot } from "@ogw_front/stores/basemap";
import type { CRS } from "@geode/opengeodeweb-back/schema_types";
-import type { CameraSnapshot } from "@ogw_internal/stores/hybrid_viewer/camera";
+import type { CameraManagerSnapshot } from "@ogw_front/stores/camera_manager";
import type { DataStyleSnapshot } from "@ogw_front/stores/data_style";
+import type { HybridViewerImportSnapshot } from "@ogw_internal/stores/hybrid_viewer/vtk_types";
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 { TreeviewSnapshot } from "@ogw_front/stores/treeview";
+import type { ViewersSnapshot } from "@ogw_internal/stores/viewers/types";
// Projects saved before data_id existed hold the data id of their rows as `id`
interface ProjectDataSnapshot {
items: (LegacyDataId | NewDataItem)[];
@@ -17,13 +19,20 @@ interface ProjectDataSnapshot {
)[];
}
+// Each store of a viewer is saved under its own id, as the registry exports it
interface ProjectSnapshot {
- treeview?: TreeviewSnapshot;
+ viewers?: ViewersSnapshot;
data?: ProjectDataSnapshot;
- hybridViewer?: CameraSnapshot;
- dataStyle?: DataStyleSnapshot;
crs?: { projectCrs?: CRS };
basemap?: BasemapSnapshot;
+ cameraManager?: CameraManagerSnapshot;
+ [treeviewId: `treeview-${string}`]: TreeviewSnapshot | undefined;
+ [hybridViewerId: `hybridViewer-${string}`]: HybridViewerImportSnapshot | undefined;
+ [dataStyleId: `dataStyle-${string}`]: DataStyleSnapshot | undefined;
+ // Projects saved with a single viewer hold the stores of that viewer under their own name
+ treeview?: TreeviewSnapshot;
+ hybridViewer?: HybridViewerImportSnapshot;
+ dataStyle?: DataStyleSnapshot;
}
export type { ProjectSnapshot };
diff --git a/app/composables/screenshot_size.ts b/app/composables/screenshot_size.ts
index 0fbf34db9..e8323e392 100644
--- a/app/composables/screenshot_size.ts
+++ b/app/composables/screenshot_size.ts
@@ -3,10 +3,11 @@ import { type ComputedRef, type Ref, computed, ref } from "vue";
import { useDevicePixelRatio, useWindowSize } from "@vueuse/core";
import type { Pixels } from "@ogw_front/types/ui";
import type { Ratio } from "@ogw_front/types/geometry";
-import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
// Local imports
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
import { useViewerStore } from "@ogw_front/stores/viewer";
+import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
// The length of a side of the screenshot, in pixels
type ScreenshotLength = number;
@@ -42,7 +43,11 @@ function ratioOf(view_size: Readonly): Ratio {
return isSized(view_size) ? view_size.width / view_size.height : 1;
}
-function useScreenshotSize(include_ui: Readonly][>): ScreenshotSizeState {
+// The default size is the one of the view of the viewer captured
+function useScreenshotSize(
+ viewerId: ViewerId,
+ include_ui: Readonly][>,
+): ScreenshotSizeState {
const viewerStore = useViewerStore();
const { width: window_width, height: window_height } = useWindowSize();
const { pixelRatio } = useDevicePixelRatio();
@@ -51,7 +56,7 @@ function useScreenshotSize(include_ui: Readonly][>): ScreenshotSizeSt
const screenshot_size = ref();
function resetSize(): void {
- const { view_size } = viewerStore;
+ const view_size = viewerStore.view_size_of(viewerId);
if (isSized(view_size)) {
screenshot_size.value = {
width: clampSize(view_size.width),
@@ -64,7 +69,7 @@ function useScreenshotSize(include_ui: Readonly][>): ScreenshotSizeSt
function setWidth(value: ScreenshotLength | null | undefined): void {
if (typeof value === "number") {
// Cap the edited side so the derived one stays within the bounds and keeps the ratio
- const ratio = ratioOf(viewerStore.view_size);
+ const ratio = ratioOf(viewerStore.view_size_of(viewerId));
const width = clampSize(Math.min(value, MAX_SCREENSHOT_SIZE * ratio));
const height = clampSize(width / ratio);
screenshot_size.value = { width, height };
@@ -73,7 +78,7 @@ function useScreenshotSize(include_ui: Readonly][>): ScreenshotSizeSt
function setHeight(value: ScreenshotLength | null | undefined): void {
if (typeof value === "number") {
- const ratio = ratioOf(viewerStore.view_size);
+ const ratio = ratioOf(viewerStore.view_size_of(viewerId));
const height = clampSize(Math.min(value, MAX_SCREENSHOT_SIZE / ratio));
const width = clampSize(height * ratio);
screenshot_size.value = { width, height };
diff --git a/app/composables/use_adaptive_styles.ts b/app/composables/use_adaptive_styles.ts
index dca8d37a8..d231d8314 100644
--- a/app/composables/use_adaptive_styles.ts
+++ b/app/composables/use_adaptive_styles.ts
@@ -5,6 +5,7 @@ import { consola } from "consola";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
import { useTheme } from "vuetify";
import { useTreeviewStore } from "@ogw_front/stores/treeview";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
const LUMINANCE_THRESHOLD = 0.65;
const ADAPTIVE_EXPONENT = 0.3;
@@ -101,6 +102,18 @@ function useGlassStyles(
});
}
+// The stores of the viewer this component is shown in
+function useViewerStores(): {
+ hybridViewerStore: ReturnType;
+ treeviewStore: ReturnType;
+} {
+ const viewerId = useViewerId();
+ return {
+ hybridViewerStore: useHybridViewerStore(viewerId),
+ treeviewStore: useTreeviewStore(viewerId),
+ };
+}
+
// oxlint-disable max-lines-per-function
function useAdaptiveStyles(
target: AdaptiveStylesTarget,
@@ -109,8 +122,7 @@ function useAdaptiveStyles(
adaptiveStyles: ComputedRef;
brightness: Ref;
} {
- const hybridViewerStore = useHybridViewerStore();
- const treeviewStore = useTreeviewStore();
+ const { hybridViewerStore, treeviewStore } = useViewerStores();
const targetAsRefLike = isRefLike(target) ? target : undefined;
const isCoordinates =
diff --git a/app/composables/use_overlapping_picker.ts b/app/composables/use_overlapping_picker.ts
index 4c9010577..28ad822fc 100644
--- a/app/composables/use_overlapping_picker.ts
+++ b/app/composables/use_overlapping_picker.ts
@@ -4,32 +4,33 @@ import type {
GeodeObjectType,
ViewerObjectType,
} from "@geode/opengeodeweb-microservice/data_types";
+import type { BlockId } from "@geode/opengeodeweb-viewer/schema_types";
import type { Coordinate } from "@ogw_front/types/geometry";
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
import type { DataIdentified } from "@ogw_front/types/identifiers";
-import type { ViewerId } from "@geode/opengeodeweb-viewer/schema_types";
import { computeMenuPosition } from "@ogw_front/composables/overlapping_picker_menu";
import { isImage } from "@ogw_front/utils/viewer_object_type";
import { ref } from "vue";
import { useDataStyleStore } from "@ogw_front/stores/data_style";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
import { useViewerStore } from "@ogw_front/stores/viewer";
import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
interface PickedItem {
id: DataId;
- viewer_id: ViewerId | undefined;
+ block_id: BlockId | undefined;
}
interface ProposedItem extends DataIdentified {
- viewer_id: ViewerId | undefined;
+ block_id: BlockId | undefined;
name: DataItem["name"];
viewer_object_type: ViewerObjectType | undefined;
geode_object_type: GeodeObjectType | undefined;
}
-interface ViewerIdResult {
+interface BlockIdResult {
id: DataId | undefined;
- viewer_id: ViewerId | undefined;
+ block_id: BlockId | undefined;
// True when objects were under the cursor but the user closed the picker without choosing
dismissed?: boolean;
}
@@ -41,7 +42,7 @@ interface IntermediateMenuStyle {
top: string;
}
-interface GetViewerIdParams {
+interface GetBlockIdParams {
x: Coordinate;
y: Coordinate;
containerWidth: Pixels;
@@ -57,12 +58,13 @@ interface UseOverlappingPickerReturn {
getIntermediateMenuStyle: () => IntermediateMenuStyle;
selectIntermediateItem: (item: ProposedItem | undefined) => void;
handleIntermediateMenuUpdate: (val: boolean) => void;
- get_viewer_id: (params: GetViewerIdParams) => Promise;
+ get_block_id: (params: GetBlockIdParams) => Promise;
}
export function useOverlappingPicker(): UseOverlappingPickerReturn {
const dataStore = useDataStore();
- const dataStyleStore = useDataStyleStore();
+ const viewerId = useViewerId();
+ const dataStyleStore = useDataStyleStore(viewerId);
const viewerStore = useViewerStore();
const displayIntermediate = ref(false);
@@ -78,7 +80,7 @@ export function useOverlappingPicker(): UseOverlappingPickerReturn {
const item = await dataStore.item(pick.id);
return {
data_id: pick.id,
- viewer_id: pick.viewer_id,
+ block_id: pick.block_id,
name: item.name || "Unnamed Object",
viewer_object_type: item.viewer_object_type,
geode_object_type: item.geode_object_type,
@@ -86,7 +88,7 @@ export function useOverlappingPicker(): UseOverlappingPickerReturn {
} catch {
return {
data_id: pick.id,
- viewer_id: pick.viewer_id,
+ block_id: pick.block_id,
name: "Unnamed Object",
viewer_object_type: undefined,
geode_object_type: undefined,
@@ -132,7 +134,7 @@ export function useOverlappingPicker(): UseOverlappingPickerReturn {
}
function showIntermediateMenu(
- { x, y, containerWidth, containerHeight, containerRect }: GetViewerIdParams,
+ { x, y, containerWidth, containerHeight, containerRect }: GetBlockIdParams,
itemCount: Count,
): void {
const position = computeMenuPosition({ x, y, containerWidth, containerHeight, itemCount });
@@ -141,23 +143,23 @@ export function useOverlappingPicker(): UseOverlappingPickerReturn {
displayIntermediate.value = true;
}
- async function get_viewer_id(params: GetViewerIdParams): Promise {
+ async function get_block_id(params: GetBlockIdParams): Promise {
const ids = getViewableIds();
const schema = viewer_schemas.opengeodeweb_viewer.viewer.picked_ids;
- const { array_ids, viewer_id } = await viewerStore.request({
+ const { array_ids, block_id } = await viewerStore.request({
schema,
- params: { x: params.x, y: params.y, ids },
+ params: { viewer_id: viewerId, x: params.x, y: params.y, ids },
});
if (array_ids.length === 0) {
- return { id: undefined, viewer_id: undefined };
+ return { id: undefined, block_id: undefined };
}
- const pickedList: PickedItem[] = array_ids.map((pickId) => ({ id: pickId, viewer_id }));
+ const pickedList: PickedItem[] = array_ids.map((pickId) => ({ id: pickId, block_id }));
if (pickedList.length <= 1) {
- return { id: pickedList[0]?.id, viewer_id: pickedList[0]?.viewer_id };
+ return { id: pickedList[0]?.id, block_id: pickedList[0]?.block_id };
}
const proposedItems = await fetchProposedItems(pickedList);
@@ -165,13 +167,13 @@ export function useOverlappingPicker(): UseOverlappingPickerReturn {
showIntermediateMenu(params, proposedItems.length);
/* eslint-disable-next-line promise/avoid-new */
- return new Promise((resolve) => {
+ return new Promise((resolve) => {
resolveIntermediate = (chosenResult: ProposedItem | undefined): void => {
displayIntermediate.value = false;
if (chosenResult) {
- resolve({ id: chosenResult.data_id, viewer_id: chosenResult.viewer_id });
+ resolve({ id: chosenResult.data_id, block_id: chosenResult.block_id });
} else {
- resolve({ id: undefined, viewer_id: undefined, dismissed: true });
+ resolve({ id: undefined, block_id: undefined, dismissed: true });
}
};
});
@@ -185,8 +187,8 @@ export function useOverlappingPicker(): UseOverlappingPickerReturn {
getIntermediateMenuStyle,
selectIntermediateItem,
handleIntermediateMenuUpdate,
- get_viewer_id,
+ get_block_id,
};
}
-export type { IntermediateMenuStyle, ProposedItem, ViewerIdResult };
+export type { IntermediateMenuStyle, ProposedItem, BlockIdResult };
diff --git a/app/composables/use_quick_colormap.ts b/app/composables/use_quick_colormap.ts
index 47a90fa52..7ade760d2 100644
--- a/app/composables/use_quick_colormap.ts
+++ b/app/composables/use_quick_colormap.ts
@@ -1,11 +1,12 @@
import type { BlockIds } from "@geode/opengeodeweb-viewer/schema_types";
import type { Coordinate } from "@ogw_front/types/geometry";
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
import { consola } from "consola";
import { useViewerStore } from "@ogw_front/stores/viewer";
import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
-export function useQuickColormap(): {
+export function useQuickColormap(viewerId: ViewerId): {
pickColormap: typeof pickColormap;
quickColormap: typeof quickColormap;
} {
@@ -32,7 +33,7 @@ export function useQuickColormap(): {
): Promise {
try {
const schema = viewer_schemas.opengeodeweb_viewer.viewer.pick_colormap;
- const params = { x: offsetX, y: offsetY };
+ const params = { viewer_id: viewerId, x: offsetX, y: offsetY };
const { data_id, block_ids } = await viewerStore.request({ schema, params });
if (data_id !== undefined && data_id !== "") {
quickColormap.data_id = data_id;
diff --git a/app/composables/view_toolbar_options.ts b/app/composables/view_toolbar_options.ts
index e0c171176..817df2775 100644
--- a/app/composables/view_toolbar_options.ts
+++ b/app/composables/view_toolbar_options.ts
@@ -6,9 +6,8 @@ import {
rulerOption,
} from "@ogw_front/composables/view_toolbar_tool_options";
import type { ViewToolbarTools } from "@ogw_front/composables/view_toolbar_tools";
-import schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
-import { useViewerStore } from "@ogw_front/stores/viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
type HybridViewerStore = ReturnType;
@@ -77,46 +76,28 @@ function hoverHighlightOption(
};
}
-function gridScaleOption(
- hybridViewerStore: HybridViewerStore,
- viewerStore: ReturnType,
- gridScale: Ref,
-): CameraOptionAction {
+function gridScaleOption(hybridViewerStore: HybridViewerStore): CameraOptionAction {
return {
testId: "gridScaleButton",
tooltip: "Toggle grid scale",
icon: "ph-grid-four",
- color: gridScale.value ? "primary" : undefined,
+ color: hybridViewerStore.gridScale ? "primary" : undefined,
action: (): void => {
- const schema = schemas.opengeodeweb_viewer.viewer.grid_scale;
- const params = { visibility: !gridScale.value };
- void viewerStore.request(
- {
- schema,
- params,
- },
- {
- response_function: () => {
- gridScale.value = !gridScale.value;
- void hybridViewerStore.remoteRender();
- },
- },
- );
+ void hybridViewerStore.setGridScale(!hybridViewerStore.gridScale);
},
};
}
// The buttons of the view toolbar
function useViewToolbarOptions(tools: ViewToolbarTools): ComputedRef {
- const hybridViewerStore = useHybridViewerStore();
- const viewerStore = useViewerStore();
- const gridScale = ref(false);
+ const viewerId = useViewerId();
+ const hybridViewerStore = useHybridViewerStore(viewerId);
return computed(() => [
...pickingOptions(hybridViewerStore, tools),
hoverHighlightOption(hybridViewerStore, tools),
...panelOptions(tools),
- gridScaleOption(hybridViewerStore, viewerStore, gridScale),
+ gridScaleOption(hybridViewerStore),
...controlOptions(tools),
...filterOptions(tools),
rulerOption(tools),
diff --git a/app/composables/view_toolbar_tools.ts b/app/composables/view_toolbar_tools.ts
index 5bb80dfb3..b903d6f12 100644
--- a/app/composables/view_toolbar_tools.ts
+++ b/app/composables/view_toolbar_tools.ts
@@ -1,5 +1,6 @@
import type { PickedFieldType } from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewerId } from "@ogw_front/composables/viewer_id";
import { useViewerStore } from "@ogw_front/stores/viewer";
interface ToolRefs {
@@ -53,7 +54,8 @@ function exclusiveTools(toolRefs: ToolRefs, pickingTools: Ref[]): Ref Promise;
+ get_block_id: (x: Coordinate, y: Coordinate) => Promise;
}
interface MenuTarget {
@@ -95,12 +95,12 @@ async function treeMenuTarget(
async function viewerMenuTarget(
dataStore: ReturnType,
pickedId: DataId,
- viewer_id: ViewerId | undefined,
+ block_id: BlockIdResult["block_id"],
): Promise {
const item = await dataStore.item(pickedId);
const meta_data: MenuMetaData = { ...item };
- if (isModel(item) && viewer_id !== undefined) {
- const component = await dataStore.getComponentByViewerId(pickedId, viewer_id);
+ if (isModel(item) && block_id !== undefined) {
+ const component = await dataStore.getComponentByBlockId(pickedId, block_id);
if (component) {
meta_data.pickedComponentId = component.geode_id;
}
@@ -109,8 +109,9 @@ async function viewerMenuTarget(
}
export function useViewerContextMenu(
- container: Readonly>,
+ container: Readonly][>,
viewerUI: Readonly>,
+ viewerId: ViewerId,
): {
containerWidth: Ref;
containerHeight: Ref;
@@ -124,6 +125,7 @@ export function useViewerContextMenu(
function openMenuAt(event: MouseEvent, element: HTMLElement, target: MenuTarget): void {
const rect = element.getBoundingClientRect();
menuStore.openMenu({
+ viewer_id: viewerId,
id: target.id,
x: event.clientX - rect.left,
y: event.clientY - rect.top,
@@ -152,14 +154,14 @@ export function useViewerContextMenu(
const rect = element.getBoundingClientRect();
const x = event.clientX - rect.left;
const yPicking = containerHeight.value - (event.clientY - rect.top);
- const { id: pickedId, viewer_id, dismissed } = await viewerComponent.get_viewer_id(x, yPicking);
+ const { id: pickedId, block_id, dismissed } = await viewerComponent.get_block_id(x, yPicking);
if (pickedId === undefined) {
if (dismissed !== true) {
openMenuAt(event, element, SCENE_MENU_TARGET);
}
return;
}
- openMenuAt(event, element, await viewerMenuTarget(dataStore, pickedId, viewer_id));
+ openMenuAt(event, element, await viewerMenuTarget(dataStore, pickedId, block_id));
}
return { containerWidth, containerHeight, openTreeMenu, openViewerMenu };
diff --git a/app/composables/viewer_id.ts b/app/composables/viewer_id.ts
new file mode 100644
index 000000000..25df4c881
--- /dev/null
+++ b/app/composables/viewer_id.ts
@@ -0,0 +1,18 @@
+import { type InjectionKey, inject, provide } from "vue";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
+
+const VIEWER_ID_KEY: InjectionKey = Symbol("viewer_id");
+
+function provideViewerId(viewerId: ViewerId): void {
+ provide(VIEWER_ID_KEY, viewerId);
+}
+
+function useViewerId(): ViewerId {
+ const viewerId = inject(VIEWER_ID_KEY, undefined);
+ if (viewerId === undefined) {
+ throw new Error("useViewerId called outside a ViewerView");
+ }
+ return viewerId;
+}
+
+export { VIEWER_ID_KEY, provideViewerId, useViewerId };
diff --git a/app/composables/viewer_items.ts b/app/composables/viewer_items.ts
new file mode 100644
index 000000000..e4c6c64d4
--- /dev/null
+++ b/app/composables/viewer_items.ts
@@ -0,0 +1,14 @@
+import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
+import { useViewersStore } from "@ogw_front/stores/viewers";
+
+// A filter acts on the data of its viewer only: the filter panels list and send these
+function viewerItems]- (
+ viewerId: ViewerId,
+ items: readonly Item[],
+): Item[] {
+ const shown = useViewersStore().contents[viewerId] ?? [];
+ return items.filter((item) => shown.includes(item.data_id));
+}
+
+export { viewerItems };
diff --git a/app/composables/viewer_reset.ts b/app/composables/viewer_reset.ts
index 7f76b98d9..f518a3ab2 100644
--- a/app/composables/viewer_reset.ts
+++ b/app/composables/viewer_reset.ts
@@ -1,8 +1,4 @@
import type { ColorRGB, ColorRGBA } from "@geode/opengeodeweb-viewer/schema_types";
-import type { ViewerRequest } from "@ogw_front/stores/viewer_helpers/request";
-// Third party imports
-import { consola } from "consola";
-import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
// Local imports
import { getDefaultSceneStyle, getSceneColors } from "@ogw_front/utils/default_styles";
@@ -10,6 +6,11 @@ import {
hideViewerMarker,
resetOrientationMarkerVisibility,
} from "@ogw_front/composables/orientation_overlay";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
+import type { ViewerRequest } from "@ogw_front/stores/viewer_helpers/request";
+// Third party imports
+import { consola } from "consola";
+import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
// The scene colors of the viewer have no alpha (the text one takes it as its opacity)
function toViewerColor({ red, green, blue }: ColorRGBA): ColorRGB {
@@ -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, viewerId: ViewerId): 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: { viewer_id: viewerId, color: toViewerColor(background_color) },
});
}
if (sceneColors.text) {
await request({
schema: viewer_schemas.opengeodeweb_viewer.viewer.set_text_style,
params: {
+ viewer_id: viewerId,
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 {
- resetOrientationMarkerVisibility();
+// To call on each new or reset viewer, which draws the viewer's own colors and marker. Neither step fails
+// The viewer: the viewer stays usable with its own colors, and the marker is hidden either way
+async function afterViewerReset(request: ViewerRequest, viewerId: ViewerId): Promise {
+ resetOrientationMarkerVisibility(viewerId);
try {
- await applyAppSceneColors(request);
+ await applyAppSceneColors(request, viewerId);
} catch (error) {
consola.warn("[SceneColors] The viewer kept its own scene colors:", error);
}
- await hideViewerMarker(request);
+ await hideViewerMarker(viewerId, request);
}
export { afterViewerReset, toViewerColor };
diff --git a/app/stores/basemap_detail.ts b/app/stores/basemap_detail.ts
index 4efb9149a..dca421981 100644
--- a/app/stores/basemap_detail.ts
+++ b/app/stores/basemap_detail.ts
@@ -1,3 +1,5 @@
+import type { Ref } from "vue";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
import { useBasemapStore } from "@ogw_front/stores/basemap";
import { useDetailLayers } from "./basemap_helpers/detail_layers.js";
import { useDetailMap } from "./basemap_helpers/detail_map.js";
@@ -5,13 +7,13 @@ import { useDetailRefresh } from "./basemap_helpers/detail_refresh.js";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
// When the camera rests, the visible area of the basemap at the zoom of the screen
-export const useBasemapDetailStore = defineStore("basemapDetail", () => {
+function setupBasemapDetailStore(viewerId: ViewerId): { detailId: Ref } {
const basemapStore = useBasemapStore();
- const hybridViewerStore = useHybridViewerStore();
- const detail = useDetailMap();
+ const hybridViewerStore = useHybridViewerStore(viewerId);
+ const detail = useDetailMap(viewerId);
const { detailId, newRefresh, forget, clear } = detail;
- const layers = useDetailLayers(detail);
- const { scheduleRefresh, onCameraChange } = useDetailRefresh(detail, layers);
+ const layers = useDetailLayers(viewerId, detail);
+ const { scheduleRefresh, onCameraChange } = useDetailRefresh(viewerId, detail, layers);
watch(() => hybridViewerStore.camera_options, onCameraChange, { deep: true });
watch(
@@ -48,4 +50,32 @@ export const useBasemapDetailStore = defineStore("basemapDetail", () => {
});
return { detailId };
-});
+}
+
+type BasemapDetailStoreDefinition = ReturnType<
+ typeof defineStore>
+>;
+
+// A viewer keeps the store definition it was given first
+const basemapDetailStoreDefinitions = new Map();
+
+// Each viewer follows its own camera: the detail is built for what it shows
+function useBasemapDetailStore(viewerId: ViewerId): ReturnType {
+ let definition = basemapDetailStoreDefinitions.get(viewerId);
+ if (!definition) {
+ definition = defineStore(`basemapDetail-${viewerId}`, () => setupBasemapDetailStore(viewerId));
+ basemapDetailStoreDefinitions.set(viewerId, definition);
+ }
+ return definition();
+}
+
+// The detail of a closed viewer stops following its camera
+function disposeBasemapDetailStore(viewerId: ViewerId): void {
+ const definition = basemapDetailStoreDefinitions.get(viewerId);
+ if (definition) {
+ definition().$dispose();
+ basemapDetailStoreDefinitions.delete(viewerId);
+ }
+}
+
+export { disposeBasemapDetailStore, useBasemapDetailStore };
diff --git a/app/stores/basemap_helpers/builds.ts b/app/stores/basemap_helpers/builds.ts
index 60a09e830..5257b68bb 100644
--- a/app/stores/basemap_helpers/builds.ts
+++ b/app/stores/basemap_helpers/builds.ts
@@ -9,9 +9,9 @@ import type { CRS } from "@geode/opengeodeweb-back/schema_types";
import type { Coordinate } from "@ogw_front/types/geometry";
import type { Extent } from "./extent.js";
import type { Ref } from "vue";
+import { renderEveryViewer } from "@ogw_front/utils/render_every_viewer";
import { useBackStore } from "@ogw_front/stores/back";
import { useCrsStore } from "@ogw_front/stores/crs";
-import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
// The grid of the basemap shown, and the height it lies at
interface BasemapGrid extends Pick {
@@ -40,7 +40,6 @@ function useBasemapBuilds(
const { maps, hidden, built, layersParams, applyLayers, applyBasemap } = layers;
const backStore = useBackStore();
const crsStore = useCrsStore();
- const hybridViewerStore = useHybridViewerStore();
const { discardMap } = useBasemapViewer();
const basemapId = ref(undefined);
// The detail store compares its resolution with the screen
@@ -79,7 +78,7 @@ function useBasemapBuilds(
return;
}
await discardMap(id, true);
- await hybridViewerStore.remoteRender();
+ await renderEveryViewer();
}
async function display(build: BasemapBuildNumber, extent: Extent, crs: CRS): Promise {
@@ -130,7 +129,7 @@ function useBasemapBuilds(
await applyLayers(response.id);
}
// Always render: the first build has no previous basemap whose removal would render
- await hybridViewerStore.remoteRender();
+ await renderEveryViewer();
}
async function rebuild(): Promise {
diff --git a/app/stores/basemap_helpers/detail_layers.ts b/app/stores/basemap_helpers/detail_layers.ts
index 541fc5f12..627a099b0 100644
--- a/app/stores/basemap_helpers/detail_layers.ts
+++ b/app/stores/basemap_helpers/detail_layers.ts
@@ -2,6 +2,7 @@ import { coalesced, ignoreError, useBasemapViewer } from "./viewer.js";
import type { BasemapBuildResponse } from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
import type { DetailMap } from "./detail_map.js";
import type { SentLayers } from "./layers.js";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
import { sortedMaps } from "@ogw_front/utils/basemap_tree";
import { useBasemapStore } from "@ogw_front/stores/basemap";
import { useDataStore } from "@ogw_front/stores/data";
@@ -14,10 +15,10 @@ interface DetailLayers {
}
// What the viewer shows of the detail: its layers, and the detail replacing the previous one
-function useDetailLayers(detail: DetailMap): DetailLayers {
+function useDetailLayers(viewerId: ViewerId, detail: DetailMap): DetailLayers {
const dataStore = useDataStore();
const basemapStore = useBasemapStore();
- const hybridViewerStore = useHybridViewerStore();
+ const hybridViewerStore = useHybridViewerStore(viewerId);
const { discardMap } = useBasemapViewer();
const { detailId, shown, clear } = detail;
diff --git a/app/stores/basemap_helpers/detail_map.ts b/app/stores/basemap_helpers/detail_map.ts
index 99268fcaf..19fb144c6 100644
--- a/app/stores/basemap_helpers/detail_map.ts
+++ b/app/stores/basemap_helpers/detail_map.ts
@@ -2,6 +2,7 @@ import type { BasemapId } from "@ogw_front/types/identifiers";
import type { MapGrid } from "@ogw_front/utils/visible_map_area";
import type { MapStyle } from "@ogw_front/utils/basemap_tree";
import type { Ref } from "vue";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
import { useBasemapStore } from "@ogw_front/stores/basemap";
import { useBasemapViewer } from "./viewer.js";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
@@ -27,9 +28,9 @@ interface DetailMap {
}
// The detail shown over the basemap
-function useDetailMap(): DetailMap {
+function useDetailMap(viewerId: ViewerId): DetailMap {
const basemapStore = useBasemapStore();
- const hybridViewerStore = useHybridViewerStore();
+ const hybridViewerStore = useHybridViewerStore(viewerId);
const { discardMap } = useBasemapViewer();
const detailId = ref(undefined);
const shown: ShownDetail = { grid: undefined, maps: [] };
diff --git a/app/stores/basemap_helpers/detail_refresh.ts b/app/stores/basemap_helpers/detail_refresh.ts
index a42f83137..3d56c4fd0 100644
--- a/app/stores/basemap_helpers/detail_refresh.ts
+++ b/app/stores/basemap_helpers/detail_refresh.ts
@@ -5,6 +5,7 @@ import type { BasemapBuildResponse } from "@geode/opengeodeweb-back/opengeodeweb
import type { BasemapGrid } from "./builds.js";
import type { BasemapId } from "@ogw_front/types/identifiers";
import type { DetailLayers } from "./detail_layers.js";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
import { useBasemapStore } from "@ogw_front/stores/basemap";
import { useBasemapViewer } from "./viewer.js";
import { useDebounceFn } from "@vueuse/core";
@@ -24,10 +25,10 @@ const REST_DELAY_MILLISECONDS = 250;
const DETAIL_NAME = "basemap detail";
// Builds the detail of a view for the basemap shown, unless a newer refresh or base came meanwhile
-function useBuildDetail(detail: DetailMap, layers: DetailLayers): BuildDetail {
+function useBuildDetail(viewerId: ViewerId, detail: DetailMap, layers: DetailLayers): BuildDetail {
const basemapStore = useBasemapStore();
const { discardMap } = useBasemapViewer();
- const { detailRequest } = useDetailView();
+ const { detailRequest } = useDetailView(viewerId);
const { newRefresh, isObsolete } = detail;
// Shown unless a newer refresh or base came while it was applied
@@ -38,7 +39,7 @@ function useBuildDetail(detail: DetailMap, layers: DetailLayers): BuildDetail {
): Promise {
let sentLayers = "";
try {
- sentLayers = await basemapStore.applyBasemap(response, DETAIL_NAME, basemapId);
+ sentLayers = await basemapStore.applyBasemap(response, DETAIL_NAME, { basemapId, viewerId });
} catch {
// The request feedback already shows the error: the detail must not stay registered
await discardMap(response.id, true);
@@ -72,11 +73,15 @@ function useBuildDetail(detail: DetailMap, layers: DetailLayers): BuildDetail {
}
// The visible area of the basemap at the zoom of the screen, built when the camera rests
-function useDetailRefresh(detail: DetailMap, layers: DetailLayers): DetailRefresh {
+function useDetailRefresh(
+ viewerId: ViewerId,
+ detail: DetailMap,
+ layers: DetailLayers,
+): DetailRefresh {
const basemapStore = useBasemapStore();
- const hybridViewerStore = useHybridViewerStore();
- const { viewportSize, currentView } = useDetailView();
- const build = useBuildDetail(detail, layers);
+ const hybridViewerStore = useHybridViewerStore(viewerId);
+ const { viewportSize, currentView } = useDetailView(viewerId);
+ const build = useBuildDetail(viewerId, detail, layers);
const { shown, clear } = detail;
async function refresh(): Promise {
diff --git a/app/stores/basemap_helpers/detail_view.ts b/app/stores/basemap_helpers/detail_view.ts
index ab3fe7413..64d3e32d6 100644
--- a/app/stores/basemap_helpers/detail_view.ts
+++ b/app/stores/basemap_helpers/detail_view.ts
@@ -14,6 +14,7 @@ import type { BasemapGrid } from "./builds.js";
import type { Coordinate } from "@ogw_front/types/geometry";
import type { MapStyle } from "@ogw_front/utils/basemap_tree";
import type { Pixels } from "@ogw_front/types/ui";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
import { useBackStore } from "@ogw_front/stores/back";
import { useCrsStore } from "@ogw_front/stores/crs";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
@@ -49,10 +50,10 @@ interface DetailView {
}
// The stores are taken once: a call still running after a project reset reaches its own stores
-function useDetailView(): DetailView {
+function useDetailView(viewerId: ViewerId): DetailView {
const backStore = useBackStore();
const crsStore = useCrsStore();
- const hybridViewerStore = useHybridViewerStore();
+ const hybridViewerStore = useHybridViewerStore(viewerId);
function viewportSize(): [Pixels, Pixels] | undefined {
// The store holds the render window in a holder: the vtk.js typing of its API is partial
diff --git a/app/stores/basemap_helpers/georeferenced.ts b/app/stores/basemap_helpers/georeferenced.ts
index 9edcca470..e57e16709 100644
--- a/app/stores/basemap_helpers/georeferenced.ts
+++ b/app/stores/basemap_helpers/georeferenced.ts
@@ -4,6 +4,7 @@ import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
import { sameCrs } from "@ogw_front/utils/crs";
import { useCrsStore } from "@ogw_front/stores/crs";
import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { useViewersStore } from "@ogw_front/stores/viewers";
// What changes with the project CRS, the georeferenced data or their extent
type GeoreferencedKey = string;
@@ -21,7 +22,7 @@ interface Georeferenced {
// Project would be misplaced: only the data in the project CRS are under the basemap
function useGeoreferenced(): Georeferenced {
const crsStore = useCrsStore();
- const hybridViewerStore = useHybridViewerStore();
+ const viewersStore = useViewersStore();
function georeferencedIds(): DataId[] {
return crsStore.crsItems
@@ -36,9 +37,12 @@ function useGeoreferenced(): Georeferenced {
function dataBounds(): Extent | undefined {
const georeferenced = new Set(georeferencedIds());
return boxesExtent(
- Object.entries(hybridViewerStore.hybridDb)
- .filter(([id]) => georeferenced.has(id))
- .map(([, entry]) => entry.polydata.getBounds()),
+ // The viewers showing a data hold the same geometry: any of them gives its bounds
+ viewersStore.viewers.flatMap((viewer) =>
+ Object.entries(useHybridViewerStore(viewer.id).hybridDb)
+ .filter(([id]) => georeferenced.has(id))
+ .map(([, entry]) => entry.polydata.getBounds()),
+ ),
);
}
diff --git a/app/stores/basemap_helpers/layers.ts b/app/stores/basemap_helpers/layers.ts
index ec17760b6..7e58b27c1 100644
--- a/app/stores/basemap_helpers/layers.ts
+++ b/app/stores/basemap_helpers/layers.ts
@@ -1,5 +1,5 @@
import type { ComputedRef, Ref } from "vue";
-import { type Layer, useBasemapViewer } from "./viewer.js";
+import { type DetailOf, type Layer, useBasemapViewer } from "./viewer.js";
import type { BasemapBuildResponse } from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
import type { BasemapId } from "@ogw_front/types/identifiers";
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
@@ -29,7 +29,7 @@ interface BasemapLayers {
applyBasemap: (
response: BasemapBuildResponse,
name: DataName,
- detailOf?: BasemapId,
+ detailOf?: DetailOf,
) => Promise;
}
@@ -59,7 +59,7 @@ function useBasemapLayers(georeferencedIds: () => DataId[]): BasemapLayers {
async function applyBasemap(
response: BasemapBuildResponse,
name: DataName,
- detailOf?: BasemapId,
+ detailOf?: DetailOf,
): Promise {
const layers = layersParams();
await showMap({ response, name, layers, dataIds: georeferencedIds() }, detailOf);
diff --git a/app/stores/basemap_helpers/settings.ts b/app/stores/basemap_helpers/settings.ts
index f179dd4a1..5b2a9f1f8 100644
--- a/app/stores/basemap_helpers/settings.ts
+++ b/app/stores/basemap_helpers/settings.ts
@@ -5,7 +5,7 @@ import type { Opacity } from "@geode/opengeodeweb-viewer/schema_types";
import type { Ref } from "vue";
import { coalesced } from "./viewer.js";
import { everyMap } from "./extent.js";
-import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
+import { renderEveryViewer } from "@ogw_front/utils/render_every_viewer";
interface BasemapSnapshot {
maps?: MapStyle[];
@@ -27,14 +27,13 @@ function useBasemapSettings(
basemapId: Ref,
rebuild: () => Promise,
): BasemapSettings {
- const hybridViewerStore = useHybridViewerStore();
const { shown, hidden, maps, opacities, crop, built, applyLayers } = layers;
const recompose = coalesced(async () => {
const id = basemapId.value;
if (id !== undefined) {
await applyLayers(id);
- await hybridViewerStore.remoteRender();
+ await renderEveryViewer();
}
});
diff --git a/app/stores/basemap_helpers/viewer.ts b/app/stores/basemap_helpers/viewer.ts
index 4a2e4c641..3ac75864c 100644
--- a/app/stores/basemap_helpers/viewer.ts
+++ b/app/stores/basemap_helpers/viewer.ts
@@ -6,6 +6,7 @@ import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
import type { DataName } from "@ogw_front/types/data";
import type { MapStyle } from "@ogw_front/utils/basemap_tree";
import type { Opacity } from "@geode/opengeodeweb-viewer/schema_types";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
import { useBackStore } from "@ogw_front/stores/back";
import { useDataStore } from "@ogw_front/stores/data";
import { useViewerStore } from "@ogw_front/stores/viewer";
@@ -29,10 +30,16 @@ interface MapToShow {
dataIds: DataId[];
}
+// A detail sharpens the base map in the viewer whose camera asked for it
+interface DetailOf {
+ basemapId: BasemapId;
+ viewerId: ViewerId;
+}
+
interface BasemapViewer {
discardMap: (id: BasemapId, registered: boolean) => Promise;
sendLayers: (id: BasemapId, layers: Layer[]) => Promise;
- showMap: (map: Readonly, detailOf?: BasemapId) => Promise;
+ showMap: (map: Readonly, detailOf?: DetailOf) => Promise;
}
// The stores are taken once: a call still running after a project reset reaches its own stores
@@ -60,12 +67,19 @@ function useBasemapViewer(): BasemapViewer {
});
}
- // Registers a built map, shows it with the layers and drapes the top surfaces of the data
+ // Registers a built map, shows it with the layers and drapes the top surfaces of the data.
+ // The viewer puts a base map in every viewer; a detail goes in its own viewer only
async function showMap(
{ response, name, layers, dataIds }: Readonly,
- detailOf?: BasemapId,
+ detailOf?: DetailOf,
): Promise {
await dataStore.registerObject(response.id, name);
+ if (detailOf) {
+ await viewerStore.request({
+ schema: viewer_schemas.opengeodeweb_viewer.viewer.add_to_viewer,
+ params: { viewer_id: detailOf.viewerId, id: response.id },
+ });
+ }
await viewerStore.request({
schema: viewer_schemas.opengeodeweb_viewer.mesh.apply_basemap,
params: {
@@ -74,7 +88,7 @@ function useBasemapViewer(): BasemapViewer {
rows: response.rows,
maps: response.maps,
layers,
- detail_of: detailOf,
+ detail_of: detailOf?.basemapId,
},
});
await viewerStore.request({
@@ -114,5 +128,5 @@ function coalesced(run: () => Promise): () => Promise {
};
}
-export type { Layer };
+export type { DetailOf, Layer };
export { coalesced, ignoreError, useBasemapViewer };
diff --git a/app/stores/camera_manager.ts b/app/stores/camera_manager.ts
index 7663ab1cf..5d890805d 100644
--- a/app/stores/camera_manager.ts
+++ b/app/stores/camera_manager.ts
@@ -2,14 +2,19 @@
import type { CameraPositionId, CameraPositionName } from "@ogw_internal/database/types";
import type { CameraOptions } from "@ogw_internal/stores/hybrid_viewer/vtk_types.js";
import type { CameraPositionRecord } from "@ogw_internal/database/tables/camera_positions";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
import { cameraPositionsDb } from "@ogw_internal/database/accessors.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";
+
+// What a project saves of the camera manager: the camera positions the user saved
+interface CameraManagerSnapshot {
+ positions: CameraPositionRecord[];
+}
+
// 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();
@@ -40,12 +45,11 @@ export const useCameraManagerStore = defineStore("cameraManager", () => {
});
}
- async function restoreCameraPosition(id: CameraPositionId): Promise {
+ // The position applies to the given viewer, and to the viewers linked to its camera
+ async function restoreCameraPosition(viewerId: ViewerId, id: CameraPositionId): 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(viewerId).setCameraOptions(position.camera_options);
}
}
@@ -60,6 +64,20 @@ export const useCameraManagerStore = defineStore("cameraManager", () => {
await cameraPositionsTable.update(id, { name: newName });
}
+ async function exportStores(): Promise {
+ return { positions: await cameraPositionsTable.toArray() };
+ }
+
+ // A project saved before the camera positions were has none: the positions of the previous project are forgotten
+ async function importStores(snapshot: CameraManagerSnapshot | undefined): Promise {
+ await cameraPositionsTable.clear();
+ await cameraPositionsTable.bulkPut(snapshot?.positions ?? []);
+ }
+
+ async function reset(): Promise {
+ await cameraPositionsTable.clear();
+ }
+
return {
refAllCameraPositions,
getCameraPosition,
@@ -67,5 +85,10 @@ export const useCameraManagerStore = defineStore("cameraManager", () => {
restoreCameraPosition,
deleteCameraPosition,
renameCameraPosition,
+ exportStores,
+ importStores,
+ reset,
};
});
+
+export type { CameraManagerSnapshot };
diff --git a/app/stores/crs_helpers/requests.ts b/app/stores/crs_helpers/requests.ts
index b2a5b30b9..868bb80ae 100644
--- a/app/stores/crs_helpers/requests.ts
+++ b/app/stores/crs_helpers/requests.ts
@@ -1,19 +1,24 @@
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
import type { DataItem } from "@ogw_front/stores/data";
import type { Ref } from "vue";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
interface CrsRequests {
crsEditEnabled: Ref;
enableCrsEdit: () => void;
crsEditRequest: Ref;
- requestCrsEdit: (dataId: DataId) => void;
+ requestCrsEdit: (dataId: DataId, viewerId?: ViewerId) => void;
clearCrsEditRequest: () => void;
projectCrsEditRequest: Ref;
requestProjectCrsEdit: () => void;
clearProjectCrsEditRequest: () => void;
showCrsAlign: Ref;
crsAlignItem: Ref;
- openCrsAlign: (item: DataItem) => void;
+ // The viewer the alignment was opened from: the only one whose picks and preview it follows
+ crsAlignViewerId: Ref;
+ // The viewer the CRS edit was requested from, when a viewer asked for it
+ crsEditViewerId: Ref;
+ openCrsAlign: (item: DataItem, viewerId: ViewerId) => void;
closeCrsAlign: () => void;
}
@@ -24,6 +29,8 @@ function useCrsRequests(): CrsRequests {
const projectCrsEditRequest = ref(false);
const showCrsAlign = ref(false);
const crsAlignItem = ref(undefined);
+ const crsAlignViewerId = ref(undefined);
+ const crsEditViewerId = ref(undefined);
return {
crsEditEnabled,
@@ -31,8 +38,9 @@ function useCrsRequests(): CrsRequests {
crsEditEnabled.value = true;
},
crsEditRequest,
- requestCrsEdit: (dataId: DataId): void => {
+ requestCrsEdit: (dataId: DataId, viewerId?: ViewerId): void => {
crsEditRequest.value = dataId;
+ crsEditViewerId.value = viewerId;
},
clearCrsEditRequest: (): void => {
crsEditRequest.value = undefined;
@@ -46,13 +54,17 @@ function useCrsRequests(): CrsRequests {
},
showCrsAlign,
crsAlignItem,
- openCrsAlign: (item: DataItem): void => {
+ crsAlignViewerId,
+ crsEditViewerId,
+ openCrsAlign: (item: DataItem, viewerId: ViewerId): void => {
crsAlignItem.value = item;
+ crsAlignViewerId.value = viewerId;
showCrsAlign.value = true;
},
closeCrsAlign: (): void => {
showCrsAlign.value = false;
crsAlignItem.value = undefined;
+ crsAlignViewerId.value = undefined;
},
};
}
diff --git a/app/stores/data.ts b/app/stores/data.ts
index 84e044163..139e6c648 100644
--- a/app/stores/data.ts
+++ b/app/stores/data.ts
@@ -8,10 +8,10 @@ import {
import {
addComponentRelations,
addComponents,
- getAllModelComponentsViewerIds,
- getComponentByViewerId,
- getComponentsByViewerIds,
- getMeshComponentsViewerIds,
+ getAllModelComponentsBlockIds,
+ getComponentByBlockId,
+ getComponentsByBlockIds,
+ getMeshComponentsBlockIds,
meshComponentType,
} from "@ogw_internal/stores/data/model/components";
import {
@@ -86,10 +86,10 @@ export const useDataStore = defineStore("data", () => {
addComponentRelations,
deleteItem,
updateItem,
- getAllModelComponentsViewerIds,
- getMeshComponentsViewerIds,
- getComponentByViewerId,
- getComponentsByViewerIds,
+ getAllModelComponentsBlockIds,
+ getMeshComponentsBlockIds,
+ getComponentByBlockId,
+ getComponentsByBlockIds,
exportStores,
importStores,
clear,
diff --git a/app/stores/data_style.ts b/app/stores/data_style.ts
index 5362ee52c..188a42ff4 100644
--- a/app/stores/data_style.ts
+++ b/app/stores/data_style.ts
@@ -4,6 +4,7 @@ import type {
ModelComponentTypeStyle,
ObjectStyle,
SceneStyle,
+ ViewerId,
} from "@ogw_internal/stores/data_style/types";
import {
componentDataStyleDb,
@@ -12,13 +13,12 @@ import {
sceneStyleDb,
writeTransaction,
} from "@ogw_internal/database/accessors.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,45 @@ function isRecord(value: unknown): value is Record {
return typeof value === "object" && value !== null;
}
+// The rows of a viewer are saved without its id: the snapshot key names the viewer, and an import writes them under
+// The importing viewer
+function withoutViewerId
(row: Row): Row {
+ const copy = { ...toRaw(row) };
+ Reflect.deleteProperty(copy, "viewer_id");
+ return copy;
+}
+
+function rowsWithoutViewerId(rows: Record): Record {
+ return Object.fromEntries(
+ Object.entries(toRaw(rows)).map(([key, row]) => [key, withoutViewerId(row)]),
+ );
+}
+
+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(viewerId: ViewerId): DataStyleStoreSetup {
+ const dataStyleState = useDataStyleState(viewerId);
+ const imageStyleStore = useImageStyle(viewerId);
+ const meshStyleStore = useMeshStyle(viewerId);
+ const modelStyleStore = useModelStyle(viewerId);
+ const sceneStyleStore = useSceneStyle(viewerId);
+ const attributeTimeStepStyle = useAttributeTimeStepStyle(viewerId);
const dataStyleTable = dataStyleDb();
// Keyed by [id_model, type] and [id_model, id_component]
const componentTypeDataStyleTable = componentTypeDataStyleDb();
@@ -55,45 +85,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,
+ viewer_id: viewerId,
+ }),
);
}
- // 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, {
@@ -131,27 +130,35 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
function exportStores(): DataStyleSnapshot {
return {
- styles: dataStyleState.styles.value,
- componentStyles: dataStyleState.componentStyles.value,
- modelComponentTypeStyles: dataStyleState.modelComponentTypeStyles.value,
- sceneStyle: dataStyleState.sceneStyle.value,
+ styles: rowsWithoutViewerId(dataStyleState.styles.value),
+ componentStyles: rowsWithoutViewerId(dataStyleState.componentStyles.value),
+ modelComponentTypeStyles: rowsWithoutViewerId(dataStyleState.modelComponentTypeStyles.value),
+ sceneStyle: withoutViewerId(dataStyleState.sceneStyle.value),
};
}
// 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 viewer 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.
([dataId, style]: readonly [DataId, LegacyDataId | ObjectStyle]) =>
- structuredClone({ ...fromLegacyDataId(style), data_id: dataId }),
+ structuredClone({
+ ...fromLegacyDataId(style),
+ data_id: dataId,
+ viewer_id: viewerId,
+ }),
+ );
+ // The rows are written under this viewer, whichever viewer the snapshot comes from
+ const componentStyles = Object.values(componentStylesSnapshot).map((style) =>
+ structuredClone({ ...style, viewer_id: viewerId }),
);
- const componentStyles = structuredClone(Object.values(componentStylesSnapshot));
- const modelComponentTypeStyles = structuredClone(
- Object.values(modelComponentTypeStylesSnapshot),
+ const modelComponentTypeStyles = Object.values(modelComponentTypeStylesSnapshot).map((style) =>
+ structuredClone({ ...style, viewer_id: viewerId }),
);
// The snapshot replaces the stored styles as a whole: a failed import leaves the previous ones
@@ -198,6 +205,22 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
...modelStyleStore,
...sceneStyleStore,
};
-});
+}
+
+type DataStyleStoreDefinition = ReturnType>;
+
+// A viewer keeps the store definition it was given first
+const dataStyleStoreDefinitions = new Map();
+
+// Each viewer has its own store: the same data can be styled differently in two viewers
+function useDataStyleStore(viewerId: ViewerId): ReturnType {
+ let definition = dataStyleStoreDefinitions.get(viewerId);
+ if (!definition) {
+ definition = defineStore(`dataStyle-${viewerId}`, () => setupDataStyleStore(viewerId));
+ dataStyleStoreDefinitions.set(viewerId, definition);
+ }
+ return definition();
+}
+export { useDataStyleStore };
export type { DataStyleSnapshot };
diff --git a/app/stores/hybrid_viewer.ts b/app/stores/hybrid_viewer.ts
index 973f08157..5511a9f1a 100644
--- a/app/stores/hybrid_viewer.ts
+++ b/app/stores/hybrid_viewer.ts
@@ -1,47 +1,83 @@
import {
+ type HybridViewerCamera,
+ applySnapshot,
+ useHybridViewerCamera,
+} from "@ogw_internal/stores/hybrid_viewer/camera";
+import {
+ type HybridViewerCore,
+ useHybridViewerCore,
+} from "@ogw_internal/stores/hybrid_viewer/core";
+import {
+ type HybridViewerFilterSet,
+ useHybridViewerFilterSet,
+} from "@ogw_internal/stores/hybrid_viewer/filters_apply";
+import {
+ type HybridViewerHighlight,
+ useHybridViewerHighlight,
+} from "@ogw_internal/stores/hybrid_viewer/highlight";
+import type {
+ HybridViewerImportSnapshot,
+ HybridViewerSnapshot,
+} from "@ogw_internal/stores/hybrid_viewer/vtk_types";
+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";
-import type { CameraOptions } from "@ogw_internal/stores/hybrid_viewer/vtk_types";
-import type { ZScale } from "@ogw_front/types/geometry";
-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";
+ type HybridViewerZoomBox,
+ useHybridViewerZoomBox,
+} from "@ogw_internal/stores/hybrid_viewer/zoom_box";
+import {
+ copiedCamera,
+ restoreViewer,
+ shownViewer,
+} from "@ogw_internal/stores/hybrid_viewer/restore";
import { Status } from "@ogw_front/utils/status";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
+import { trackLocalCamera } from "@ogw_internal/stores/hybrid_viewer/camera_follow";
+import { useHybridViewerBrightness } from "@ogw_internal/stores/hybrid_viewer/brightness";
+import { useHybridViewerRuler } from "@ogw_internal/stores/hybrid_viewer/ruler";
import { useViewerStore } from "@ogw_front/stores/viewer";
-// What a project saves of the viewer: the z scale and the camera
-interface HybridViewerSnapshot {
- zScale: ZScale;
- camera_options: CameraOptions | Record;
+interface HybridViewerStoreActions {
+ initHybridViewer: () => Promise;
+ exportStores: () => HybridViewerSnapshot;
+ importStores: (snapshot: HybridViewerImportSnapshot | undefined) => Promise;
}
+type HybridViewerStoreSetup = HybridViewerStoreActions &
+ Omit &
+ ReturnType &
+ HybridViewerScene &
+ HybridViewerViewport &
+ HybridViewerFilterSet &
+ HybridViewerHighlight &
+ ReturnType &
+ HybridViewerCamera &
+ HybridViewerZoomBox;
+
// oxlint-disable max-lines-per-function, max-statements
-export const useHybridViewerStore = defineStore("hybridViewer", () => {
+function setupHybridViewerStore(viewerId: ViewerId): HybridViewerStoreSetup {
const viewerStore = useViewerStore();
const { genericRenderWindow, status, is_moving, is_picking, remoteRender } =
- useHybridViewerCore();
+ useHybridViewerCore(viewerId);
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(viewerId);
+ const sceneStore = useHybridViewerScene(viewerId);
+ const filtersStore = useHybridViewerFilterSet(viewerId);
+ const highlightStore = useHybridViewerHighlight(viewerId);
+ const rulerStore = useHybridViewerRuler(viewerId);
+ const cameraStore = useHybridViewerCamera(viewerId);
+ const viewportStore = useHybridViewerViewport(viewerId);
+ const zoomBoxStore = useHybridViewerZoomBox(viewerId);
const is_cursor_crosshair = computed(() => is_picking.value || rulerStore.is_ruler_active.value);
@@ -66,10 +102,9 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => {
return;
}
status.value = Status.CREATING;
- genericRenderWindow.value = vtkGenericRenderWindow({
- background: localBackgroundColor(),
- listenWindowResize: false,
- });
+ // The local camera overwrites the camera options, which a duplicated viewer holds before it is shown
+ const camera_copy = copiedCamera(viewerId);
+ 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 {
@@ -82,6 +117,7 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => {
zIndex: 1,
});
await viewerStore.ws_connect();
+ const { view_id, content } = await shownViewer(viewerId);
// oxlint-disable-next-line no-unsafe-type-assertion -- trusted @kitware/vtk.js WebSocket client API boundary.
const clientApi = viewerStore.client as unknown as {
getImageStream: () => {
@@ -89,7 +125,8 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => {
};
};
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 viewer's own view
+ viewportStore.viewStream.value = imageStream.createViewStream(view_id);
viewportStore.viewStream.value?.onImageReady((event: { image: unknown }) => {
if (is_moving.value) {
return;
@@ -102,25 +139,36 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => {
if (imageStyle) {
imageStyle.opacity = "1";
}
+ if (latestImage) {
+ viewportStore.imageReceived(latestImage.width, latestImage.height);
+ }
});
const renderer = genericRenderWindow.value.getRenderer();
const camera = renderer.getActiveCamera();
- Object.assign(cameraStore.camera_options, getCameraOptions(camera));
- camera.onModified(() => {
- Object.assign(cameraStore.camera_options, getCameraOptions(camera));
+ trackLocalCamera(viewerId, camera);
+ await viewportStore.prepareWhile(async () => {
+ await restoreViewer(viewerId, content, camera_copy);
});
status.value = Status.CREATED;
}
+ // The camera options follow the local camera, see trackLocalCamera
function exportStores(): HybridViewerSnapshot {
- const renderer = genericRenderWindow.value?.getRenderer();
- const camera = renderer?.getActiveCamera();
return {
zScale: sceneStore.zScale.value,
- camera_options: (camera && getCameraOptions(camera)) ?? cameraStore.camera_options,
+ camera_options: cameraStore.camera_options,
+ filters: filtersStore.exportFilters(),
};
}
+ // The tools are only set here: the viewer applies them once the project data and styles are restored
+ async function importStores(snapshot: HybridViewerImportSnapshot | undefined): Promise {
+ await applySnapshot(viewerId, snapshot);
+ if (snapshot) {
+ filtersStore.importFilters(snapshot.filters);
+ }
+ }
+
return {
genericRenderWindow,
status,
@@ -129,7 +177,7 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => {
initHybridViewer,
remoteRender,
exportStores,
- importStores: applySnapshot,
+ importStores,
...brightnessStore,
...sceneStore,
...viewportStore,
@@ -139,5 +187,21 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => {
...cameraStore,
...zoomBoxStore,
};
-});
-export type { HybridViewerSnapshot };
+}
+
+type HybridViewerStoreDefinition = ReturnType>;
+
+// A viewer keeps the store definition it was given first
+const hybridViewerStoreDefinitions = new Map();
+
+// Each viewer has its own viewer: its own render window, view and camera
+function useHybridViewerStore(viewerId: ViewerId): ReturnType {
+ let definition = hybridViewerStoreDefinitions.get(viewerId);
+ if (!definition) {
+ definition = defineStore(`hybridViewer-${viewerId}`, () => setupHybridViewerStore(viewerId));
+ hybridViewerStoreDefinitions.set(viewerId, definition);
+ }
+ return definition();
+}
+
+export { useHybridViewerStore };
diff --git a/app/stores/menu.ts b/app/stores/menu.ts
index e04f58257..bb96a8dc3 100644
--- a/app/stores/menu.ts
+++ b/app/stores/menu.ts
@@ -3,6 +3,7 @@ import type { MenuItemIndex, Pixels } from "@ogw_front/types/ui";
import type { MenuItems, MenuObjectType, MenuViewerObjectType } from "./menu_helpers/types.js";
import type { Coordinate } from "@ogw_front/types/geometry";
import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
import { menusData } from "./menu_helpers/menus_data.js";
interface MenuMetaData extends Partial {
@@ -13,6 +14,7 @@ interface MenuMetaData extends Partial {
}
interface OpenMenuOptions {
+ readonly viewer_id: ViewerId;
readonly id: TreeNodeId;
readonly x: Coordinate | undefined;
readonly y: Coordinate | undefined;
@@ -26,9 +28,24 @@ interface OpenMenuOptions {
const MENU_RADIUS = 80;
// Same gap between neighbour items as a 4-item object menu (3 items, no center button)
const SCENE_MENU_RADIUS = 65;
+// A menu does not follow the user to another page
+function closeOnNavigation(isOpen: () => boolean, closeMenu: () => void): void {
+ const router = useRouter();
+ watch(
+ () => router.currentRoute.value.path,
+ () => {
+ if (isOpen()) {
+ closeMenu();
+ }
+ },
+ );
+}
+
export const useMenuStore = defineStore("menu", () => {
const menus = shallowRef(menusData);
const display_menu = ref(false);
+ // The viewer the menu is open for: only its own viewer UI shows it
+ const current_viewer_id = ref(undefined);
const current_id = ref(undefined);
const menuX = ref(0);
const menuY = ref(0);
@@ -58,6 +75,7 @@ export const useMenuStore = defineStore("menu", () => {
function closeMenu(): void {
active_item_index.value = undefined;
+ current_viewer_id.value = undefined;
current_id.value = undefined;
current_meta_data.value = {};
menuX.value = 0;
@@ -66,7 +84,7 @@ export const useMenuStore = defineStore("menu", () => {
}
function openMenu(options: OpenMenuOptions): void {
- const { id, x, y, width, height, top, left, meta_data } = options;
+ const { viewer_id, id, x, y, width, height, top, left, meta_data } = options;
closeMenu();
if (meta_data) {
@@ -76,6 +94,7 @@ export const useMenuStore = defineStore("menu", () => {
}
}
+ current_viewer_id.value = viewer_id;
current_id.value = id;
current_meta_data.value = meta_data ?? {};
@@ -105,18 +124,11 @@ export const useMenuStore = defineStore("menu", () => {
}
}
- const router = useRouter();
- watch(
- () => router.currentRoute.value.path,
- () => {
- if (display_menu.value || active_item_index.value !== null) {
- closeMenu();
- }
- },
- );
+ closeOnNavigation(() => display_menu.value || active_item_index.value !== null, closeMenu);
return {
display_menu,
+ current_viewer_id,
current_id,
current_meta_data,
menuX,
diff --git a/app/stores/treeview.ts b/app/stores/treeview.ts
index 6f312ccbe..f3ee736a2 100644
--- a/app/stores/treeview.ts
+++ b/app/stores/treeview.ts
@@ -16,20 +16,20 @@ import type {
OpenedView,
TreeviewConfigRecord,
} from "@ogw_internal/database/tables/treeview_config";
+import { type Ref, ref, watch } from "vue";
import type { TreeGroup, TreeNode, TreeViewIndex } from "@ogw_front/types/tree";
-import { ref, watch } from "vue";
+import {
+ nextModelTreeColor,
+ physicalPropertiesViewId,
+ viewModelId,
+} from "@ogw_front/utils/treeview";
import type { DataName } from "@ogw_front/types/data";
-import type { FileName } from "@ogw_front/types/files";
+import type { ViewerId } from "@ogw_internal/stores/viewers/types";
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
import { defineStore } from "pinia";
-import {
- nextModelTreeColor,
- physicalPropertiesViewId,
- viewModelId,
-} from "@ogw_front/utils/treeview";
import { treeviewConfigDb } from "@ogw_internal/database/accessors";
const PANEL_WIDTH = 300;
@@ -40,11 +40,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,17 +91,64 @@ function snapshotSelectionIds(snapshot: ReadonlyTreeviewSnapshot | undefined): D
);
}
+interface TreeviewStoreSetup {
+ items: Ref;
+ selection: Ref;
+ activeItems: Ref;
+ opened_views: Ref;
+ panelWidth: Ref;
+ additionalPanelWidth: 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;
+ 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(viewerId: ViewerId): TreeviewStoreSetup {
const items = ref([]);
const selection = ref([]);
const activeItems = ref([]);
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
@@ -116,7 +158,7 @@ export const useTreeviewStore = defineStore("treeview", () => {
async function loadConfig(): Promise {
try {
- const config = await treeviewConfigTable.get("main");
+ const config = await treeviewConfigTable.get(viewerId);
if (config?.opened_views) {
opened_views.value = withModelTreeColors(config.opened_views);
}
@@ -152,7 +194,7 @@ export const useTreeviewStore = defineStore("treeview", () => {
// Best-effort persistence: a failure is logged, not thrown.
try {
await treeviewConfigTable.put({
- id: "main",
+ viewer_id: viewerId,
opened_views: clean_opened_views,
panelWidth: panelWidth.value,
additionalPanelWidth: additionalPanelWidth.value,
@@ -231,32 +273,6 @@ export const useTreeviewStore = defineStore("treeview", () => {
selection.value = [...selection.value, dataId];
}
- function removePendingImport(id: TreeNodeId): 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: FileName,
- 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 {
@@ -423,7 +439,6 @@ export const useTreeviewStore = defineStore("treeview", () => {
selection.value = [];
activeItems.value = [];
pendingSelectionIds.value = [];
- pendingImports.value = [];
opened_views.value = defaultOpenedViews();
}
@@ -461,7 +476,7 @@ export const useTreeviewStore = defineStore("treeview", () => {
rowHeights.value = [...heights];
}
- function exportStores(): Omit {
+ function exportStores(): Omit {
return {
opened_views: opened_views.value,
panelWidth: panelWidth.value,
@@ -497,15 +512,12 @@ export const useTreeviewStore = defineStore("treeview", () => {
opened_views,
panelWidth,
additionalPanelWidth,
- isImporting,
- pendingImports,
rowHeights,
hoveredModelId,
openedModelColor,
viewColor,
setHoveredModel,
addItem,
- whilePendingImport,
untilLoaded,
removeItem,
renameItem,
@@ -528,6 +540,22 @@ export const useTreeviewStore = defineStore("treeview", () => {
finalizeImportSelection,
clear,
};
-});
+}
+
+type TreeviewStoreDefinition = ReturnType