@@ -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,
0 commit comments