@@ -33,10 +33,76 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
3333 if ( object_type === "mesh" ) {
3434 return meshStyleStore . applyMeshStyle ( id )
3535 } else if ( object_type === "model" ) {
36- return modelStyleStore . applyModelStyle ( id )
37- } else {
38- throw new Error ( "Unknown object_type: " + object_type )
36+ return Promise . all ( [ modelStyleStore . setModelVisibility ( id , visible ) ] )
3937 }
38+ return Promise . resolve ( [ ] )
39+ }
40+
41+ function setModelEdgesVisibility ( id , visibility ) {
42+ modelStyleStore . setModelMeshComponentVisibility (
43+ id ,
44+ "Edge" ,
45+ null ,
46+ visibility ,
47+ )
48+ }
49+
50+ function modelEdgesVisibility ( id ) {
51+ return modelStyleStore . modelMeshComponentVisibility ( id , "Edge" , null )
52+ }
53+
54+ function exportStores ( ) {
55+ return { styles : dataStyleState . styles }
56+ }
57+
58+ async function importStores ( snapshot ) {
59+ const stylesSnapshot = snapshot ?. styles || { }
60+ console . log (
61+ "[DataStyle] importStores snapshot ids:" ,
62+ Object . keys ( stylesSnapshot ) ,
63+ )
64+
65+ // Conserver la référence réactive -> clear + merge
66+ for ( const id of Object . keys ( dataStyleState . styles ) )
67+ delete dataStyleState . styles [ id ]
68+ for ( const [ id , style ] of Object . entries ( stylesSnapshot ) ) {
69+ dataStyleState . styles [ id ] = style
70+ }
71+ console . log (
72+ "[DataStyle] importStores merged ids:" ,
73+ Object . keys ( dataStyleState . styles ) ,
74+ )
75+ }
76+
77+ async function applyAllStylesFromState ( ) {
78+ const ids = Object . keys ( dataStyleState . styles || { } )
79+ console . log ( "[DataStyle] applyAllStylesFromState start ids:" , ids )
80+
81+ // Séquentiel par id pour mieux tracer et éviter les courses
82+ for ( const id of ids ) {
83+ const meta = dataBaseStore . itemMetaDatas ( id )
84+ const objectType = meta ?. object_type
85+ const style = dataStyleState . styles [ id ]
86+ if ( ! style || ! objectType ) {
87+ console . warn ( "[DataStyle] applyAllStylesFromState skip:" , {
88+ id,
89+ hasStyle : ! ! style ,
90+ objectType,
91+ } )
92+ continue
93+ }
94+ console . log ( "[DataStyle] applyAllStylesFromState applying:" , {
95+ id,
96+ objectType,
97+ } )
98+ if ( objectType === "mesh" ) {
99+ await meshStyleStore . applyMeshDefaultStyle ( id )
100+ } else if ( objectType === "model" ) {
101+ await modelStyleStore . applyModelDefaultStyle ( id )
102+ }
103+ console . log ( "[DataStyle] applyAllStylesFromState applied:" , id )
104+ }
105+ console . log ( "[DataStyle] applyAllStylesFromState finished" )
40106 }
41107
42108 return {
0 commit comments