@geode/opengeodeweb-front 12.2.0-rc.4 → 12.2.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/app/components/ClippingPlanes.vue +1 -1
  2. package/app/components/FactorFilterPanel.vue +1 -1
  3. package/app/components/Launcher.vue +3 -2
  4. package/app/components/ThresholdFilter.vue +1 -2
  5. package/app/components/Viewer/Basemap/CropOptions.vue +7 -8
  6. package/app/components/Viewer/Basemap/OpacityOptions.vue +7 -8
  7. package/app/components/Viewer/ContextMenu/CircularItems.vue +6 -43
  8. package/app/components/Viewer/ContextMenu/ContextMenu.vue +1 -6
  9. package/app/components/Viewer/ContextMenu/ContextMenuItem.vue +14 -16
  10. package/app/components/Viewer/EdgedCurve/PointsOptions.vue +5 -4
  11. package/app/components/Viewer/EdgedCurve/SpecificEdgesOptions.vue +10 -13
  12. package/app/components/Viewer/Generic/Mesh/CellsOptions.vue +8 -11
  13. package/app/components/Viewer/Generic/Mesh/EdgesOptions.vue +16 -13
  14. package/app/components/Viewer/Generic/Mesh/PointsOptions.vue +28 -31
  15. package/app/components/Viewer/Generic/Mesh/PolygonsOptions.vue +9 -11
  16. package/app/components/Viewer/Generic/Mesh/PolyhedraOptions.vue +8 -11
  17. package/app/components/Viewer/Generic/Model/BlocksOptions.vue +1 -1
  18. package/app/components/Viewer/Generic/Model/CornersOptions.vue +1 -1
  19. package/app/components/Viewer/Generic/Model/CornersTypeOptions.vue +1 -1
  20. package/app/components/Viewer/Generic/Model/EdgesOptions.vue +7 -8
  21. package/app/components/Viewer/Generic/Model/LinesOptions.vue +1 -1
  22. package/app/components/Viewer/Generic/Model/LinesTypeOptions.vue +1 -1
  23. package/app/components/Viewer/Generic/Model/ModelEdgesCard.vue +5 -7
  24. package/app/components/Viewer/Generic/Model/ModelPointsCard.vue +5 -7
  25. package/app/components/Viewer/Generic/Model/ModelStyleCard.vue +5 -7
  26. package/app/components/Viewer/Generic/Model/ModelStyleOptions.vue +7 -8
  27. package/app/components/Viewer/Generic/Model/PointsOptions.vue +7 -8
  28. package/app/components/Viewer/Generic/Model/SurfacesOptions.vue +1 -1
  29. package/app/components/Viewer/Grid/2D/CellsOptions.vue +6 -4
  30. package/app/components/Viewer/Grid/2D/EdgesOptions.vue +6 -4
  31. package/app/components/Viewer/Grid/2D/PointsOptions.vue +5 -4
  32. package/app/components/Viewer/Grid/3D/CellsOptions.vue +6 -4
  33. package/app/components/Viewer/Grid/3D/EdgesOptions.vue +6 -4
  34. package/app/components/Viewer/Grid/3D/FacetsOptions.vue +6 -4
  35. package/app/components/Viewer/Grid/3D/PointsOptions.vue +5 -4
  36. package/app/components/Viewer/Image/ImageOptions.vue +10 -13
  37. package/app/components/Viewer/ObjectTree/Base/CommonTreeView.vue +5 -0
  38. package/app/components/Viewer/ObjectTree/Base/ComponentRelations.vue +2 -2
  39. package/app/components/Viewer/ObjectTree/Base/StickyHeader.vue +4 -1
  40. package/app/components/Viewer/ObjectTree/Base/TreeRow.vue +6 -8
  41. package/app/components/Viewer/ObjectTree/Views/GlobalObjects.vue +10 -15
  42. package/app/components/Viewer/ObjectTree/Views/ModelTree.vue +3 -0
  43. package/app/components/Viewer/PointSet/SpecificPointsOptions.vue +28 -31
  44. package/app/components/Viewer/Scene/BackgroundOptions.vue +4 -7
  45. package/app/components/Viewer/Scene/OrientationWidgetOptions.vue +4 -7
  46. package/app/components/Viewer/Scene/TextOptions.vue +4 -7
  47. package/app/components/Viewer/Solid/EdgesOptions.vue +6 -4
  48. package/app/components/Viewer/Solid/PointsOptions.vue +5 -4
  49. package/app/components/Viewer/Solid/PolygonsOptions.vue +6 -4
  50. package/app/components/Viewer/Solid/SpecificPolyhedraOptions.vue +8 -11
  51. package/app/components/Viewer/Surface/EdgesOptions.vue +6 -4
  52. package/app/components/Viewer/Surface/PointsOptions.vue +6 -4
  53. package/app/components/Viewer/Surface/PolygonsOptions.vue +8 -11
  54. package/app/components/Viewer/Surface/Triangulated/TrianglesOptions.vue +5 -4
  55. package/app/components/Viewer/TetrahedralSolid/TetrahedraOptions.vue +6 -4
  56. package/app/components/Viewer/TetrahedralSolid/TrianglesOptions.vue +6 -4
  57. package/app/composables/circular_menu.ts +45 -0
  58. package/app/composables/hover_highlight.ts +1 -1
  59. package/app/composables/model_menu_context.ts +7 -11
  60. package/app/composables/model_tree.ts +3 -3
  61. package/app/composables/project_manager_helpers/types.ts +2 -3
  62. package/app/composables/use_overlapping_picker.ts +7 -19
  63. package/app/composables/viewer_context_menu.ts +2 -1
  64. package/app/stores/api.ts +6 -59
  65. package/app/stores/app.ts +21 -55
  66. package/app/stores/back.ts +86 -145
  67. package/app/stores/camera_manager.ts +12 -25
  68. package/app/stores/cloud.ts +21 -101
  69. package/app/stores/crs.ts +3 -2
  70. package/app/stores/data.ts +66 -409
  71. package/app/stores/data_style.ts +99 -93
  72. package/app/stores/feedback.ts +57 -53
  73. package/app/stores/infra.ts +61 -101
  74. package/app/stores/treeview.ts +12 -31
  75. package/app/stores/viewer.ts +9 -29
  76. package/app/stores/viewer_helpers/actions.ts +1 -23
  77. package/app/utils/backend_lifecycle.ts +155 -0
  78. package/app/utils/import_item.ts +5 -4
  79. package/app/utils/threshold_sources.ts +3 -2
  80. package/app/utils/treeview.ts +25 -1
  81. package/app/utils/viewer_object_type.ts +21 -0
  82. package/internal/database/base_database.ts +2 -1
  83. package/internal/database/database.ts +90 -7
  84. package/internal/database/queries.ts +45 -0
  85. package/internal/database/tables/camera_positions.ts +11 -1
  86. package/internal/database/tables/data.ts +20 -1
  87. package/internal/database/tables/data_style.ts +3 -1
  88. package/internal/database/tables/model_component_datastyle.ts +3 -1
  89. package/internal/database/tables/model_component_type_datastyle.ts +3 -1
  90. package/internal/database/tables/model_components.ts +12 -1
  91. package/internal/database/tables/model_components_relation.ts +11 -1
  92. package/internal/database/tables/scene_style.ts +3 -1
  93. package/internal/database/tables/treeview_config.ts +31 -0
  94. package/internal/stores/data/items.ts +110 -0
  95. package/internal/stores/data/model/collections.ts +107 -0
  96. package/internal/stores/data/model/components.ts +129 -0
  97. package/internal/stores/data/model/mesh_components.ts +134 -0
  98. package/internal/stores/data/model/relations.ts +76 -0
  99. package/internal/stores/data/model/types.ts +14 -0
  100. package/internal/stores/data/registration.ts +54 -0
  101. package/internal/stores/data/snapshot.ts +83 -0
  102. package/internal/stores/data/types.ts +26 -0
  103. package/internal/stores/data_style/model/common_mutations.ts +47 -77
  104. package/internal/stores/data_style/model/selection.ts +3 -10
  105. package/internal/stores/data_style/scene.ts +2 -2
  106. package/internal/stores/data_style/state.ts +10 -8
  107. package/internal/stores/data_style/state_shared.ts +10 -7
  108. package/internal/stores/hybrid_viewer/highlight.ts +9 -14
  109. package/internal/stores/hybrid_viewer/scene.ts +1 -1
  110. package/internal/stores/microservice.ts +192 -0
  111. package/package.json +1 -1
  112. package/tests/browser/helpers/data/helpers/attribute.ts +2 -1
  113. package/app/stores/data_helpers/collections.ts +0 -122
  114. package/app/stores/data_helpers/mesh.ts +0 -167
  115. package/app/stores/data_helpers/relations.ts +0 -94
@@ -1,6 +1,17 @@
1
+ import type { DataIdentified, GeodeIdentified } from "@ogw_front/types/identifiers";
1
2
  import type { TableDefinition } from "./table_definition";
2
3
 
3
- export const modelComponentsTable: TableDefinition = {
4
+ interface ModelComponentRecord extends DataIdentified, GeodeIdentified {
5
+ type: string;
6
+ viewer_id: string | number;
7
+ name: string;
8
+ is_active: boolean;
9
+ }
10
+
11
+ const modelComponentsTable: TableDefinition = {
4
12
  name: "model_components",
5
13
  schema: "[data_id+geode_id], data_id, [data_id+type], viewer_id, name, is_active",
6
14
  };
15
+
16
+ export { modelComponentsTable };
17
+ export type { ModelComponentRecord };
@@ -1,6 +1,16 @@
1
+ import type { DataIdentified } from "@ogw_front/types/identifiers";
1
2
  import type { TableDefinition } from "./table_definition";
2
3
 
3
- export const modelComponentsRelationTable: TableDefinition = {
4
+ interface ModelComponentRelationRecord extends DataIdentified {
5
+ parent: string;
6
+ child: string;
7
+ type: string;
8
+ }
9
+
10
+ const modelComponentsRelationTable: TableDefinition = {
4
11
  name: "model_components_relation",
5
12
  schema: "[data_id+parent+child], data_id, type",
6
13
  };
14
+
15
+ export { modelComponentsRelationTable };
16
+ export type { ModelComponentRelationRecord };
@@ -1,6 +1,8 @@
1
1
  import type { TableDefinition } from "./table_definition";
2
2
 
3
- export const sceneStyleTable: TableDefinition = {
3
+ const sceneStyleTable: TableDefinition = {
4
4
  name: "scene_style",
5
5
  schema: "id",
6
6
  };
7
+
8
+ export { sceneStyleTable };
@@ -0,0 +1,31 @@
1
+ import type { GeodeObjectTyped } from "@ogw_front/types/identifiers";
2
+ import type { TableDefinition } from "./table_definition";
3
+
4
+ interface OpenedView extends Partial<GeodeObjectTyped> {
5
+ type: "object" | "component";
6
+ id: string;
7
+ title: string;
8
+ scrollTop: number;
9
+ opened: string[];
10
+ // Ties a model tree to its row in the objects tree
11
+ color?: string;
12
+ // A model tree reduced to its button in the activity bar: still open, with its state kept
13
+ collapsed?: boolean;
14
+ }
15
+
16
+ interface TreeviewConfigRecord {
17
+ id: string;
18
+ opened_views: OpenedView[];
19
+ panelWidth: number;
20
+ additionalPanelWidth: number;
21
+ selectionIds: string[];
22
+ rowHeights: number[];
23
+ }
24
+
25
+ const treeviewConfigTable: TableDefinition = {
26
+ name: "treeview_config",
27
+ schema: "id",
28
+ };
29
+
30
+ export { treeviewConfigTable };
31
+ export type { OpenedView, TreeviewConfigRecord };
@@ -0,0 +1,110 @@
1
+ import type { ComputedRef, Ref } from "vue";
2
+ import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
3
+ import type { DataItem } from "@ogw_internal/database/tables/data";
4
+ import type { NewDataItem } from "./types";
5
+ import { dataDb } from "@ogw_internal/database/database.js";
6
+ import { liveObservable } from "@ogw_front/utils/live_observable";
7
+ import { useObservable } from "@vueuse/rxjs";
8
+
9
+ const dataTable = dataDb();
10
+
11
+ // A missing data is not viewable. Data imported before `is_viewable` existed fall back on their viewable file
12
+ function isDataItemViewable(dataItem: DataItem | undefined): boolean {
13
+ if (dataItem === undefined) {
14
+ return false;
15
+ }
16
+ if (dataItem.is_viewable !== undefined) {
17
+ return dataItem.is_viewable;
18
+ }
19
+ if (dataItem.binary_light_viewable !== undefined) {
20
+ return dataItem.binary_light_viewable !== "not_viewable";
21
+ }
22
+ return dataItem.geode_object_type !== "HorizonStack3D";
23
+ }
24
+
25
+ async function item(dataId: DataId): Promise<DataItem> {
26
+ const dataItem = await dataTable.get(dataId);
27
+ if (!dataItem) {
28
+ throw new Error(`Item not found: ${dataId}`);
29
+ }
30
+ return dataItem;
31
+ }
32
+
33
+ async function allItems(): Promise<DataItem[]> {
34
+ const storedItems = await dataTable.toArray();
35
+ return storedItems;
36
+ }
37
+
38
+ function refItem(dataId: DataId): Ref<DataItem | undefined> {
39
+ return useObservable(
40
+ liveObservable(async () => {
41
+ const dataItem = await dataTable.get(dataId);
42
+ return dataItem;
43
+ }),
44
+ {
45
+ // oxlint-disable-next-line no-unsafe-type-assertion -- placeholder until the live query resolves; consumers must treat this as possibly incomplete.
46
+ initialValue: {} as DataItem,
47
+ },
48
+ );
49
+ }
50
+
51
+ // From the database: for code right after a write, which the live items may not show yet
52
+ async function fetchIsViewable(dataId: DataId): Promise<boolean> {
53
+ const dataItem = await dataTable.get(dataId);
54
+ return isDataItemViewable(dataItem);
55
+ }
56
+
57
+ // NewDataItem has mutable array fields (mesh_components, collection_components), so it can't
58
+ // Satisfy prefer-readonly-parameter-types deeply; same pattern as app/utils/import_workflow.ts.
59
+ async function addItem(newItem: NewDataItem): Promise<string> {
60
+ const itemData: DataItem = {
61
+ data_id: newItem.data_id,
62
+ geode_id: newItem.geode_id,
63
+ name: newItem.name ?? newItem.data_id,
64
+ viewer_object_type: newItem.viewer_object_type,
65
+ geode_object_type: newItem.geode_object_type,
66
+ visible: true,
67
+ created_at: new Date().toISOString(),
68
+ is_viewable: newItem.is_viewable,
69
+ };
70
+ if (newItem.binary_light_viewable !== undefined && newItem.binary_light_viewable !== null) {
71
+ itemData.binary_light_viewable = newItem.binary_light_viewable;
72
+ }
73
+ if (newItem.crs !== undefined) {
74
+ itemData.crs = newItem.crs;
75
+ }
76
+ const dataId = await dataTable.put(itemData);
77
+ return dataId;
78
+ }
79
+
80
+ async function updateItem(dataId: DataId, changes: Partial<DataItem>): Promise<void> {
81
+ await dataTable.update(dataId, changes);
82
+ }
83
+
84
+ // A single live query of the data table, shared by every reader
85
+ function useDataItems(): {
86
+ items: ComputedRef<DataItem[]>;
87
+ itemsById: ComputedRef<Map<string, DataItem>>;
88
+ isViewable: (dataId: DataId) => boolean;
89
+ } {
90
+ const liveItems = useObservable(
91
+ liveObservable(async () => {
92
+ const storedItems = await dataTable.toArray();
93
+ return storedItems;
94
+ }),
95
+ { initialValue: [] as DataItem[] },
96
+ );
97
+ const items = computed(() => liveItems.value);
98
+ const itemsById = computed(
99
+ () => new Map(items.value.map((dataItem) => [dataItem.data_id, dataItem])),
100
+ );
101
+
102
+ // From the live items: reactive, for the data already shown
103
+ function isViewable(dataId: DataId): boolean {
104
+ return isDataItemViewable(itemsById.value.get(dataId));
105
+ }
106
+
107
+ return { items, itemsById, isViewable };
108
+ }
109
+
110
+ export { addItem, allItems, fetchIsViewable, item, refItem, updateItem, useDataItems };
@@ -0,0 +1,107 @@
1
+ import {
2
+ type FormattedComponent,
3
+ type ModelComponentRecord,
4
+ getAllMeshComponents,
5
+ } from "./mesh_components.js";
6
+ import { modelComponentRelationsOf, modelComponentsOf } from "@ogw_internal/database/queries.js";
7
+ import { MESH_COMPONENT_TYPES } from "@ogw_front/utils/default_styles";
8
+ import type { ModelComponentRelationRecord } from "./relations.js";
9
+ import type { ModelId } from "@ogw_front/types/identifiers";
10
+ import type { ReadonlyTreeGroup } from "@ogw_front/types/tree";
11
+ import type { Ref } from "vue";
12
+ import { liveObservable } from "@ogw_front/utils/live_observable";
13
+ import { pluralize } from "@ogw_front/utils/string";
14
+ import { useObservable } from "@vueuse/rxjs";
15
+
16
+ interface CollectionComponent extends FormattedComponent {
17
+ readonly children: readonly FormattedComponent[];
18
+ }
19
+
20
+ type CollectionComponentGroup = ReadonlyTreeGroup<CollectionComponent>;
21
+
22
+ async function hasCollectionComponents(modelId: ModelId): Promise<boolean> {
23
+ const count = await modelComponentsOf(modelId)
24
+ .and((component: ModelComponentRecord) => !MESH_COMPONENT_TYPES.includes(component.type))
25
+ .count();
26
+ return count > 0;
27
+ }
28
+
29
+ async function getAllCollectionComponents(modelId: ModelId): Promise<FormattedComponent[]> {
30
+ const items = await modelComponentsOf(modelId).toArray();
31
+ return items
32
+ .filter((component: ModelComponentRecord) => !MESH_COMPONENT_TYPES.includes(component.type))
33
+ .map((component: ModelComponentRecord) => ({
34
+ id: component.geode_id,
35
+ geode_id: component.geode_id,
36
+ title: component.name,
37
+ category: component.type,
38
+ viewer_id: Number(component.viewer_id),
39
+ is_active: component.is_active,
40
+ }));
41
+ }
42
+
43
+ async function fetchAllCollectionComponents(
44
+ modelId: ModelId,
45
+ ): Promise<Record<string, CollectionComponent[]>> {
46
+ const components = await getAllCollectionComponents(modelId);
47
+ const relations = await modelComponentRelationsOf(modelId).toArray();
48
+ const allMeshComponents = await getAllMeshComponents(modelId);
49
+ const meshComponentsById: Record<string, FormattedComponent> = {};
50
+ for (const meshComponent of allMeshComponents) {
51
+ meshComponentsById[meshComponent.id] = meshComponent;
52
+ }
53
+
54
+ const byType: Record<string, CollectionComponent[]> = {};
55
+ for (const component of components) {
56
+ byType[component.category] ??= [];
57
+ const itemRelations = relations.filter(
58
+ (relation: ModelComponentRelationRecord) =>
59
+ relation.parent === component.id && relation.type === "collection",
60
+ );
61
+ const children = itemRelations
62
+ .map((relation: ModelComponentRelationRecord) => meshComponentsById[relation.child])
63
+ .filter((child): child is FormattedComponent => Boolean(child));
64
+ byType[component.category]?.push({
65
+ ...component,
66
+ children,
67
+ });
68
+ }
69
+ return byType;
70
+ }
71
+
72
+ async function formatedCollectionComponents(modelId: ModelId): Promise<CollectionComponentGroup[]> {
73
+ const byType = await fetchAllCollectionComponents(modelId);
74
+ const collectionTypes = Object.keys(byType);
75
+
76
+ return collectionTypes
77
+ .filter((type) => (byType[type]?.length ?? 0) > 0)
78
+ .map((type) => ({
79
+ id: type,
80
+ title: pluralize(type),
81
+ children: byType[type] ?? [],
82
+ }));
83
+ }
84
+
85
+ function refFormatedCollectionComponents(
86
+ modelId: ModelId,
87
+ ): Ref<CollectionComponentGroup[] | undefined> {
88
+ return useObservable(
89
+ liveObservable(async () => {
90
+ const groups = await formatedCollectionComponents(modelId);
91
+ return groups;
92
+ }),
93
+ {
94
+ initialValue: undefined,
95
+ },
96
+ );
97
+ }
98
+
99
+ export type { CollectionComponent, CollectionComponentGroup };
100
+
101
+ export {
102
+ fetchAllCollectionComponents,
103
+ formatedCollectionComponents,
104
+ getAllCollectionComponents,
105
+ hasCollectionComponents,
106
+ refFormatedCollectionComponents,
107
+ };
@@ -0,0 +1,129 @@
1
+ import {
2
+ modelComponent,
3
+ modelComponentsByGeodeIds,
4
+ modelComponentsOf,
5
+ } from "@ogw_internal/database/queries.js";
6
+ import { modelComponentsDb, modelComponentsRelationDb } from "@ogw_internal/database/database.js";
7
+ import type { GeodeId } from "@geode/opengeodeweb-microservice/schema_types";
8
+ import type { ModelComponentInput } from "@ogw_internal/stores/data/model/types";
9
+ import type { ModelComponentRecord } from "@ogw_internal/database/tables/model_components";
10
+ import type { ModelComponentRelationRecord } from "@ogw_internal/database/tables/model_components_relation";
11
+ import type { ModelId } from "@ogw_front/types/identifiers";
12
+ import type { NewDataItem } from "@ogw_internal/stores/data/types";
13
+
14
+ const modelComponentsTable = modelComponentsDb();
15
+ const modelComponentsRelationTable = modelComponentsRelationDb();
16
+
17
+ async function meshComponentType(modelId: ModelId, geodeId: GeodeId): Promise<string | undefined> {
18
+ const component = await modelComponent(modelId, geodeId).first();
19
+ return component?.type;
20
+ }
21
+
22
+ async function getAllModelComponentsViewerIds(modelId: ModelId): Promise<number[]> {
23
+ const components = await modelComponentsOf(modelId).toArray();
24
+ return components.map((component: ModelComponentRecord) =>
25
+ Math.trunc(Number(component.viewer_id)),
26
+ );
27
+ }
28
+
29
+ async function getMeshComponentsViewerIds(
30
+ modelId: ModelId,
31
+ meshComponentGeodeIds: readonly string[],
32
+ ): Promise<number[]> {
33
+ const components = await modelComponentsByGeodeIds(modelId, meshComponentGeodeIds).toArray();
34
+ return components.map((component: ModelComponentRecord) =>
35
+ Math.trunc(Number(component.viewer_id)),
36
+ );
37
+ }
38
+
39
+ async function getComponentByViewerId(
40
+ modelId: ModelId,
41
+ viewerId: string | number,
42
+ ): Promise<ModelComponentRecord | undefined> {
43
+ const component = await modelComponentsTable
44
+ .where("viewer_id")
45
+ .equals(Number(viewerId))
46
+ .and((candidate: ModelComponentRecord) => candidate.data_id === modelId)
47
+ .first();
48
+ return component;
49
+ }
50
+
51
+ async function getComponentsByViewerIds(
52
+ modelId: ModelId,
53
+ viewerIds: number[],
54
+ ): Promise<ModelComponentRecord[]> {
55
+ const components = await modelComponentsTable
56
+ .where("viewer_id")
57
+ .anyOf(viewerIds)
58
+ .and((candidate: ModelComponentRecord) => candidate.data_id === modelId)
59
+ .toArray();
60
+ return components;
61
+ }
62
+
63
+ // NewDataItem has mutable array fields (mesh_components, collection_components), so it can't
64
+ // Satisfy prefer-readonly-parameter-types deeply; same pattern as app/utils/import_workflow.ts.
65
+ async function addComponents(newItem: NewDataItem): Promise<string> {
66
+ const allComponents: ModelComponentRecord[] = [];
67
+ // ModelComponentInput has mutable array fields (boundaries, internals, items), so a readonly
68
+ // Array of it can't satisfy prefer-readonly-parameter-types deeply; same limitation as above.
69
+ function addModelComponents(components: readonly ModelComponentInput[]): void {
70
+ for (const component of components) {
71
+ allComponents.push({
72
+ data_id: newItem.data_id,
73
+ geode_id: component.geode_id,
74
+ type: component.type,
75
+ viewer_id: component.viewer_id,
76
+ name: component.name,
77
+ is_active: component.is_active,
78
+ });
79
+ }
80
+ }
81
+ if (newItem.mesh_components) {
82
+ addModelComponents(newItem.mesh_components);
83
+ }
84
+ if (newItem.collection_components) {
85
+ addModelComponents(newItem.collection_components);
86
+ }
87
+ const lastKey = await modelComponentsTable.bulkPut(allComponents);
88
+ return lastKey;
89
+ }
90
+
91
+ // NewDataItem has mutable array fields (mesh_components, collection_components), so it can't
92
+ // Satisfy prefer-readonly-parameter-types deeply; same pattern as app/utils/import_workflow.ts.
93
+ async function addComponentRelations(newItem: NewDataItem): Promise<string> {
94
+ const relations: ModelComponentRelationRecord[] = [];
95
+ function addModelComponentRelations(
96
+ components: readonly string[],
97
+ parent: string,
98
+ type: string,
99
+ ): void {
100
+ for (const child of components) {
101
+ relations.push({ data_id: newItem.data_id, parent, child, type });
102
+ }
103
+ }
104
+ for (const component of newItem.mesh_components ?? []) {
105
+ if (component.boundaries) {
106
+ addModelComponentRelations(component.boundaries, component.geode_id, "boundary");
107
+ }
108
+ if (component.internals) {
109
+ addModelComponentRelations(component.internals, component.geode_id, "internal");
110
+ }
111
+ }
112
+ for (const component of newItem.collection_components ?? []) {
113
+ if (component.items) {
114
+ addModelComponentRelations(component.items, component.geode_id, "collection");
115
+ }
116
+ }
117
+ const lastKey = await modelComponentsRelationTable.bulkPut(relations);
118
+ return lastKey;
119
+ }
120
+
121
+ export {
122
+ addComponentRelations,
123
+ addComponents,
124
+ getAllModelComponentsViewerIds,
125
+ getComponentByViewerId,
126
+ getComponentsByViewerIds,
127
+ getMeshComponentsViewerIds,
128
+ meshComponentType,
129
+ };
@@ -0,0 +1,134 @@
1
+ import type { GeodeIdentified, ModelId } from "@ogw_front/types/identifiers";
2
+ import { modelComponentsOf, modelComponentsOfType } from "@ogw_internal/database/queries.js";
3
+ import type { ModelComponentRecord } from "@ogw_internal/database/tables/model_components";
4
+ import type { ReadonlyTreeGroup } from "@ogw_front/types/tree";
5
+ import type { ViewerId } from "@geode/opengeodeweb-viewer/schema_types";
6
+ import { liveObservable } from "@ogw_front/utils/live_observable";
7
+ import { useObservable } from "@vueuse/rxjs";
8
+
9
+ interface FormattedComponent extends Readonly<GeodeIdentified> {
10
+ readonly id: string;
11
+ readonly title: string;
12
+ readonly category: string;
13
+ readonly viewer_id: ViewerId;
14
+ readonly is_active: boolean;
15
+ }
16
+
17
+ type FormattedComponentGroup = ReadonlyTreeGroup<FormattedComponent>;
18
+
19
+ function toFormattedComponent(meshComponent: ModelComponentRecord): FormattedComponent {
20
+ return {
21
+ id: meshComponent.geode_id,
22
+ geode_id: meshComponent.geode_id,
23
+ title: meshComponent.name,
24
+ category: meshComponent.type,
25
+ viewer_id: Math.trunc(Number(meshComponent.viewer_id)),
26
+ is_active: meshComponent.is_active,
27
+ };
28
+ }
29
+
30
+ async function getMeshComponentGeodeIds(modelId: ModelId, type: string): Promise<string[]> {
31
+ const components = await modelComponentsOfType(modelId, type).toArray();
32
+ return components.map((component: ModelComponentRecord) => component.geode_id);
33
+ }
34
+
35
+ async function formatedMeshComponents(modelId: ModelId): Promise<FormattedComponentGroup[]> {
36
+ const items = await modelComponentsOf(modelId).toArray();
37
+ const componentTitles: Record<string, string> = {
38
+ Corner: "Corners",
39
+ Line: "Lines",
40
+ Surface: "Surfaces",
41
+ Block: "Blocks",
42
+ };
43
+
44
+ const componentsByType: Record<string, ModelComponentRecord[]> = {};
45
+ for (const component_item of items) {
46
+ if (componentTitles[component_item.type] !== undefined) {
47
+ componentsByType[component_item.type] ??= [];
48
+ componentsByType[component_item.type]?.push(component_item);
49
+ }
50
+ }
51
+
52
+ return Object.keys(componentTitles)
53
+ .filter((type) => componentsByType[type])
54
+ .map((type) => ({
55
+ id: type,
56
+ title: componentTitles[type] ?? type,
57
+ children: (componentsByType[type] ?? []).map((item: ModelComponentRecord) =>
58
+ toFormattedComponent(item),
59
+ ),
60
+ }));
61
+ }
62
+
63
+ function refFormatedMeshComponents(modelId: ModelId): Ref<FormattedComponentGroup[] | undefined> {
64
+ return useObservable(
65
+ liveObservable(async () => {
66
+ const components = await formatedMeshComponents(modelId);
67
+ return components;
68
+ }),
69
+ {
70
+ initialValue: undefined,
71
+ },
72
+ );
73
+ }
74
+
75
+ async function getMeshComponentsByType(
76
+ modelId: ModelId,
77
+ type: string,
78
+ ): Promise<FormattedComponent[]> {
79
+ const components = await modelComponentsOfType(modelId, type).toArray();
80
+ return components.map((item: ModelComponentRecord) => toFormattedComponent(item));
81
+ }
82
+
83
+ async function getAllMeshComponents(modelId: ModelId): Promise<FormattedComponent[]> {
84
+ const items = await modelComponentsOf(modelId).toArray();
85
+ return items.map((item: ModelComponentRecord) => toFormattedComponent(item));
86
+ }
87
+
88
+ async function fetchAllMeshComponents(
89
+ modelId: ModelId,
90
+ ): Promise<Record<string, FormattedComponent[]>> {
91
+ const components = await getAllMeshComponents(modelId);
92
+ const byType: Record<string, FormattedComponent[]> = {};
93
+ for (const component of components) {
94
+ byType[component.category] ??= [];
95
+ byType[component.category]?.push(component);
96
+ }
97
+ return byType;
98
+ }
99
+
100
+ async function getCornersGeodeIds(modelId: ModelId): Promise<string[]> {
101
+ const geodeIds = await getMeshComponentGeodeIds(modelId, "Corner");
102
+ return geodeIds;
103
+ }
104
+
105
+ async function getLinesGeodeIds(modelId: ModelId): Promise<string[]> {
106
+ const geodeIds = await getMeshComponentGeodeIds(modelId, "Line");
107
+ return geodeIds;
108
+ }
109
+
110
+ async function getSurfacesGeodeIds(modelId: ModelId): Promise<string[]> {
111
+ const geodeIds = await getMeshComponentGeodeIds(modelId, "Surface");
112
+ return geodeIds;
113
+ }
114
+
115
+ async function getBlocksGeodeIds(modelId: ModelId): Promise<string[]> {
116
+ const geodeIds = await getMeshComponentGeodeIds(modelId, "Block");
117
+ return geodeIds;
118
+ }
119
+
120
+ export {
121
+ fetchAllMeshComponents,
122
+ formatedMeshComponents,
123
+ getAllMeshComponents,
124
+ getBlocksGeodeIds,
125
+ getCornersGeodeIds,
126
+ getLinesGeodeIds,
127
+ getMeshComponentGeodeIds,
128
+ getMeshComponentsByType,
129
+ getSurfacesGeodeIds,
130
+ refFormatedMeshComponents,
131
+ toFormattedComponent,
132
+ };
133
+ export type { FormattedComponent, FormattedComponentGroup };
134
+ export type { ModelComponentRecord } from "@ogw_internal/database/tables/model_components";
@@ -0,0 +1,76 @@
1
+ import { type FormattedComponent, toFormattedComponent } from "./mesh_components.js";
2
+ import {
3
+ componentRelationsOf,
4
+ modelComponentRelationsOf,
5
+ modelComponentsByGeodeIds,
6
+ } from "@ogw_internal/database/queries.js";
7
+ import type { ModelComponentRelationRecord } from "@ogw_internal/database/tables/model_components_relation";
8
+ import type { ModelId } from "@ogw_front/types/identifiers";
9
+
10
+ interface ComponentRelations {
11
+ readonly boundaries: readonly FormattedComponent[];
12
+ readonly internals: readonly FormattedComponent[];
13
+ }
14
+
15
+ const RELATION_KEYS: Readonly<Record<string, keyof ComponentRelations>> = {
16
+ boundary: "boundaries",
17
+ internal: "internals",
18
+ };
19
+
20
+ type MutableComponentRelations = { [Key in keyof ComponentRelations]: FormattedComponent[] };
21
+
22
+ function groupRelationsByParent(
23
+ relations: readonly ModelComponentRelationRecord[],
24
+ components: readonly FormattedComponent[],
25
+ ): Record<string, ComponentRelations> {
26
+ const componentsById = new Map(components.map((component) => [component.id, component]));
27
+ const byParent: Record<string, MutableComponentRelations> = {};
28
+ for (const relation of relations) {
29
+ const key = RELATION_KEYS[relation.type];
30
+ const child = componentsById.get(relation.child);
31
+ if (key !== undefined && child !== undefined) {
32
+ byParent[relation.parent] ??= { boundaries: [], internals: [] };
33
+ byParent[relation.parent]?.[key].push(child);
34
+ }
35
+ }
36
+ return byParent;
37
+ }
38
+
39
+ async function getRelatedComponents(
40
+ modelId: ModelId,
41
+ relations: readonly ModelComponentRelationRecord[],
42
+ type: string,
43
+ ): Promise<FormattedComponent[]> {
44
+ const childIds = relations
45
+ .filter((relation) => relation.type === type)
46
+ .map((relation) => relation.child);
47
+ const components = await modelComponentsByGeodeIds(modelId, childIds).toArray();
48
+ return components.map((component) => toFormattedComponent(component));
49
+ }
50
+
51
+ async function getComponentRelations(
52
+ modelId: ModelId,
53
+ componentId: string,
54
+ ): Promise<ComponentRelations> {
55
+ const relations = await componentRelationsOf(modelId, componentId).toArray();
56
+ const [boundaries, internals] = await Promise.all([
57
+ getRelatedComponents(modelId, relations, "boundary"),
58
+ getRelatedComponents(modelId, relations, "internal"),
59
+ ]);
60
+ return { boundaries, internals };
61
+ }
62
+
63
+ // The boundaries and internals of every component of the model, among the given components:
64
+ // The caller already holds them, so only the relations are read
65
+ async function fetchAllComponentRelations(
66
+ modelId: ModelId,
67
+ components: readonly FormattedComponent[],
68
+ ): Promise<Record<string, ComponentRelations>> {
69
+ const relations = await modelComponentRelationsOf(modelId).toArray();
70
+ return groupRelationsByParent(relations, components);
71
+ }
72
+
73
+ export type { ComponentRelations };
74
+ export type { ModelComponentRelationRecord } from "@ogw_internal/database/tables/model_components_relation";
75
+
76
+ export { fetchAllComponentRelations, getComponentRelations };
@@ -0,0 +1,14 @@
1
+ import type { GeodeIdentified } from "@ogw_front/types/identifiers";
2
+
3
+ // A model component as the back sends it, with the ids of its related components
4
+ interface ModelComponentInput extends GeodeIdentified {
5
+ type: string;
6
+ viewer_id: string | number;
7
+ name: string;
8
+ is_active: boolean;
9
+ boundaries?: string[];
10
+ internals?: string[];
11
+ items?: string[];
12
+ }
13
+
14
+ export type { ModelComponentInput };