Skip to content

Commit 6c3c9cf

Browse files
committed
Merge branch 'feat/save_and_load' of https://github.com/Geode-solutions/OpenGeodeWeb-Front into feat/save_and_load
2 parents 2375805 + 57e13f3 commit 6c3c9cf

File tree

12 files changed

+311
-70
lines changed

12 files changed

+311
-70
lines changed

composables/project_manager.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,18 @@ export function useProjectManager() {
3333
async function importProjectFile(file) {
3434
geode.start_request()
3535
try {
36-
const infra = useInfraStore()
37-
await infra.create_connection()
36+
await useInfraStore().create_connection()
3837

38+
const schemaImport = back_schemas.opengeodeweb_back.import_project
3939
const form = new FormData()
40-
form.append("file", file, file.name || "project.zip")
41-
42-
const importPath =
43-
back_schemas.opengeodeweb_back.import_project?.$id ||
44-
"opengeodeweb_back/import_project"
40+
form.append("file", file, file?.name)
4541

46-
const result = await $fetch(importPath, {
42+
const result = await $fetch(schemaImport.$id, {
4743
baseURL: geode.base_url,
4844
method: "POST",
4945
body: form,
5046
})
47+
const snapshot = result?.snapshot ?? {}
5148

5249
await viewer_call({
5350
schema: viewer_schemas.opengeodeweb_viewer.import_project,
@@ -58,12 +55,32 @@ export function useProjectManager() {
5855
params: {},
5956
})
6057

61-
// const dataBaseStore = useDataBaseStore()
6258
const treeviewStore = useTreeviewStore()
6359
treeviewStore.isImporting = true
60+
await treeviewStore.importStores(snapshot?.treeview)
61+
62+
const hybridViewerStore = useHybridViewerStore()
63+
await hybridViewerStore.initHybridViewer()
64+
hybridViewerStore.clear()
65+
66+
const snapshotDataBase = snapshot?.dataBase?.db || {}
67+
const items = Object.entries(snapshotDataBase).map(([id, item]) => ({
68+
id,
69+
object_type: item.object_type,
70+
geode_object: item.geode_object,
71+
native_filename: item.native_filename,
72+
viewable_filename: item.viewable_filename,
73+
displayed_name: item.displayed_name,
74+
vtk_js: { binary_light_viewable: item?.vtk_js?.binary_light_viewable },
75+
}))
76+
77+
await importWorkflowFromSnapshot(items)
6478

65-
await appStore.importStores(result.snapshot)
79+
const dataStyleStore = useDataStyleStore()
80+
await dataStyleStore.importStores(snapshot?.dataStyle)
81+
await dataStyleStore.applyAllStylesFromState()
6682

83+
treeviewStore.finalizeImportSelection()
6784
treeviewStore.isImporting = false
6885
} finally {
6986
geode.stop_request()

internal_stores/mesh/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ export default function useMeshStyle() {
3939

4040
function applyMeshStyle(id) {
4141
const style = dataStyleStore.getStyle(id)
42+
console.log(
43+
"[MeshStyle] applyMeshDefaultStyle for id:",
44+
id,
45+
"style:",
46+
style,
47+
)
4248
const promise_array = []
4349
for (const [key, value] of Object.entries(style)) {
4450
if (key === "visibility") {

internal_stores/model/blocks.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,21 @@ export function useModelBlocksStyle() {
8080
}
8181

8282
function applyModelBlocksStyle(id) {
83-
const style = modelBlocksStyle(id)
84-
const blocks_ids = dataBaseStore.getBlocksUuids(id)
85-
return Promise.all([
86-
setModelBlocksVisibility(id, blocks_ids, style.visibility),
87-
setModelBlocksColor(id, blocks_ids, style.color),
88-
])
83+
const style = dataStyleStore.getStyle(id).blocks
84+
const block_ids = dataBaseStore.getBlocksUuids(id)
85+
86+
if (!block_ids || block_ids.length === 0) {
87+
return Promise.resolve()
88+
}
89+
90+
const promises = []
91+
if (typeof style?.visibility === "boolean") {
92+
promises.push(setModelBlocksVisibility(id, block_ids, style.visibility))
93+
}
94+
if (style?.color) {
95+
promises.push(setModelBlocksColor(id, block_ids, style.color))
96+
}
97+
return Promise.all(promises)
8998
}
9099

91100
return {

internal_stores/model/corners.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,19 @@ export function useModelCornersStyle() {
8282
function applyModelCornersStyle(id) {
8383
const style = modelCornersStyle(id)
8484
const corner_ids = dataBaseStore.getCornersUuids(id)
85-
return Promise.all([
86-
setModelCornersVisibility(id, corner_ids, style.visibility),
87-
setModelCornersColor(id, corner_ids, style.color),
88-
])
85+
86+
if (!corner_ids || corner_ids.length === 0) {
87+
return Promise.resolve()
88+
}
89+
90+
const promises = []
91+
if (typeof style?.visibility === "boolean") {
92+
promises.push(setModelCornersVisibility(id, corner_ids, style.visibility))
93+
}
94+
if (style?.color) {
95+
promises.push(setModelCornersColor(id, corner_ids, style.color))
96+
}
97+
return Promise.all(promises)
8998
}
9099

91100
return {

internal_stores/model/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ export default function useModelStyle() {
127127
[component_id],
128128
visibility,
129129
)
130+
} else if (component_type === "Edge") {
131+
return modelEdgesStyleStore.setModelEdgesVisibility(id, visibility)
130132
} else {
131133
throw new Error("Unknown model component_type: " + component_type)
132134
}
@@ -180,10 +182,8 @@ export default function useModelStyle() {
180182
return {
181183
modelVisibility,
182184
visibleMeshComponents,
183-
modelMeshComponentVisibility,
184185
setModelVisibility,
185186
setModelColor,
186-
setModelMeshComponentVisibility,
187187
applyModelStyle,
188188
setModelMeshComponentsDefaultStyle,
189189
...useModelBlocksStyle(),

internal_stores/model/surfaces.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,21 @@ export function useModelSurfacesStyle() {
7979
function applyModelSurfacesStyle(id) {
8080
const style = modelSurfacesStyle(id)
8181
const surface_ids = dataBaseStore.getSurfacesUuids(id)
82-
return Promise.all([
83-
setModelSurfacesVisibility(id, surface_ids, style.visibility),
84-
setModelSurfacesColor(id, surface_ids, style.color),
85-
])
82+
83+
if (!surface_ids || surface_ids.length === 0) {
84+
return Promise.resolve()
85+
}
86+
87+
const promises = []
88+
if (typeof style?.visibility === "boolean") {
89+
promises.push(
90+
setModelSurfacesVisibility(id, surface_ids, style.visibility),
91+
)
92+
}
93+
if (style?.color) {
94+
promises.push(setModelSurfacesColor(id, surface_ids, style.color))
95+
}
96+
return Promise.all(promises)
8697
}
8798

8899
return {

stores/app.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ export const useAppStore = defineStore("app", () => {
2020
let exportCount = 0
2121

2222
for (const store of stores) {
23-
if (!store.exportStores) {
24-
continue
25-
}
23+
if (!store.exportStores) continue
2624
const storeId = store.$id
2725
try {
2826
snapshot[storeId] = store.exportStores()
@@ -31,7 +29,10 @@ export const useAppStore = defineStore("app", () => {
3129
console.error(`[AppStore] Error exporting store "${storeId}":`, error)
3230
}
3331
}
34-
console.log(`[AppStore] Exported ${exportCount} stores`)
32+
console.log(
33+
`[AppStore] Exported ${exportCount} stores; snapshot keys:`,
34+
Object.keys(snapshot),
35+
)
3536
return snapshot
3637
}
3738

@@ -40,6 +41,8 @@ export const useAppStore = defineStore("app", () => {
4041
console.warn("[AppStore] import called with invalid snapshot")
4142
return
4243
}
44+
console.log("[AppStore] Import snapshot keys:", Object.keys(snapshot || {}))
45+
4346
let importedCount = 0
4447
const notFoundStores = []
4548
for (const store of stores) {

stores/data_base.js

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export const useDataBaseStore = defineStore("dataBase", () => {
4848
})
4949
}
5050

51+
const treeviewStore = useTreeviewStore()
52+
const hybridViewerStore = useHybridViewerStore()
53+
5154
async function addItem(
5255
id,
5356
value = {
@@ -59,7 +62,17 @@ export const useDataBaseStore = defineStore("dataBase", () => {
5962
vtk_js: { binary_light_viewable },
6063
},
6164
) {
65+
console.log("[DataBase] addItem start", {
66+
id,
67+
object_type: value.object_type,
68+
geode_object: value.geode_object,
69+
})
6270
db[id] = value
71+
72+
if (value.object_type === "model") {
73+
await fetchMeshComponents(id)
74+
await fetchUuidToFlatIndexDict(id)
75+
}
6376
}
6477

6578
async function fetchMeshComponents(id) {
@@ -93,6 +106,37 @@ export const useDataBaseStore = defineStore("dataBase", () => {
93106
)
94107
}
95108

109+
function exportStores() {
110+
const snapshotDb = {}
111+
for (const [id, item] of Object.entries(db)) {
112+
if (!item) continue
113+
snapshotDb[id] = {
114+
object_type: item.object_type,
115+
geode_object: item.geode_object,
116+
native_filename: item.native_filename,
117+
viewable_filename: item.viewable_filename,
118+
displayed_name: item.displayed_name,
119+
vtk_js: {
120+
binary_light_viewable: item?.vtk_js?.binary_light_viewable,
121+
},
122+
}
123+
}
124+
return { db: snapshotDb }
125+
}
126+
127+
async function importStores(snapshot) {
128+
await hybridViewerStore.initHybridViewer()
129+
hybridViewerStore.clear()
130+
console.log(
131+
"[DataBase] importStores entries:",
132+
Object.keys(snapshot?.db || {}),
133+
)
134+
for (const [id, item] of Object.entries(snapshot?.db || {})) {
135+
await registerObject(id)
136+
await addItem(id, item)
137+
}
138+
}
139+
96140
function getCornersUuids(id) {
97141
const { mesh_components } = itemMetaDatas(id)
98142
return Object.values(mesh_components["Corner"])
@@ -120,21 +164,6 @@ export const useDataBaseStore = defineStore("dataBase", () => {
120164
return flat_indexes
121165
}
122166

123-
function exportStores() {
124-
return { db: JSON.parse(JSON.stringify(db)) }
125-
}
126-
127-
async function importStores(snapshot) {
128-
const entries = snapshot?.db || {}
129-
const hybrid_store = useHybridViewerStore()
130-
await hybrid_store.initHybridViewer()
131-
hybrid_store.clear()
132-
for (const [id, item] of Object.entries(entries)) {
133-
await registerObject(id)
134-
await addItem(id, item)
135-
}
136-
}
137-
138167
return {
139168
db,
140169
itemMetaDatas,

stores/data_style.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
3434
if (!object_type) return Promise.resolve([])
3535

3636
if (object_type === "mesh") {
37-
return Promise.all([meshStyleStore.setMeshVisibility(id, visible)])
37+
return Promise.all([meshStyleStore.setMeshVisibility(id, visibility)])
3838
} else if (object_type === "model") {
39-
return Promise.all([modelStyleStore.setModelVisibility(id, visible)])
39+
return Promise.all([modelStyleStore.setModelVisibility(id, visibility)])
4040
}
4141
return Promise.resolve([])
4242
}
@@ -59,12 +59,33 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
5959
}
6060

6161
async function importStores(snapshot) {
62-
dataStyleState.styles = snapshot?.styles || {}
62+
const stylesSnapshot = snapshot?.styles || {}
63+
for (const id of Object.keys(dataStyleState.styles))
64+
delete dataStyleState.styles[id]
65+
for (const [id, style] of Object.entries(stylesSnapshot)) {
66+
dataStyleState.styles[id] = style
67+
}
68+
}
69+
70+
async function applyAllStylesFromState() {
71+
const ids = Object.keys(dataStyleState.styles || {})
72+
for (const id of ids) {
73+
const meta = dataBaseStore.itemMetaDatas(id)
74+
const objectType = meta?.object_type
75+
const style = dataStyleState.styles[id]
76+
if (!style || !objectType) continue
77+
if (objectType === "mesh") {
78+
await meshStyleStore.applyMeshStyle(id)
79+
} else if (objectType === "model") {
80+
await modelStyleStore.applyModelStyle(id)
81+
}
82+
}
6383
}
6484

6585
return {
6686
...dataStyleState,
6787
addDataStyle,
88+
applyDefaultStyle,
6889
setVisibility,
6990
setModelEdgesVisibility,
7091
modelEdgesVisibility,

0 commit comments

Comments
 (0)