-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.js
More file actions
208 lines (197 loc) · 6.21 KB
/
state.js
File metadata and controls
208 lines (197 loc) · 6.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/**
* State Management Module
* Handles localStorage persistence for checkbox states and settings
*/
/**
* Save movement type checkbox states to localStorage.
*/
export function saveCheckboxStates() {
const states = {};
document.querySelectorAll('.legend-checkbox:not(.axis-checkbox):not(.settings-checkbox)').forEach(checkbox => {
states[checkbox.dataset.type] = checkbox.checked;
});
try {
localStorage.setItem('visualizer-checkbox-states', JSON.stringify(states));
} catch (error) {
console.warn('Failed to save checkbox states to localStorage:', error);
}
}
/**
* Load movement type checkbox states from localStorage.
*/
export function loadCheckboxStates() {
try {
const saved = localStorage.getItem('visualizer-checkbox-states');
if (saved) {
const states = JSON.parse(saved);
document.querySelectorAll('.legend-checkbox:not(.axis-checkbox):not(.settings-checkbox)').forEach(checkbox => {
if (checkbox.dataset.type in states) {
checkbox.checked = states[checkbox.dataset.type];
}
});
}
} catch (error) {
console.warn('Failed to load checkbox states from localStorage:', error);
}
}
/**
* Save axis checkbox states to localStorage.
*/
export function saveAxisCheckboxStates() {
const states = {};
document.querySelectorAll('.axis-checkbox').forEach(checkbox => {
states[checkbox.dataset.axis] = checkbox.checked;
});
try {
localStorage.setItem('visualizer-axis-checkbox-states', JSON.stringify(states));
} catch (error) {
console.warn('Failed to save axis checkbox states to localStorage:', error);
}
}
/**
* Load axis checkbox states from localStorage.
*/
export function loadAxisCheckboxStates(axesLines, gridHelper) {
try {
const saved = localStorage.getItem('visualizer-axis-checkbox-states');
if (saved) {
const states = JSON.parse(saved);
document.querySelectorAll('.axis-checkbox').forEach(checkbox => {
const axis = checkbox.dataset.axis;
if (axis in states) {
checkbox.checked = states[axis];
// Apply the visibility state to the axis line or grid
if (axis === 'grid') {
if (gridHelper) {
gridHelper.visible = checkbox.checked;
}
} else if (axesLines) {
const axisIndex = axis === 'x' ? 0 : axis === 'y' ? 1 : 2;
axesLines[axisIndex].visible = checkbox.checked;
}
}
});
}
} catch (error) {
console.warn('Failed to load axis checkbox states from localStorage:', error);
}
}
/**
* Save settings states to localStorage.
*/
export function saveSettingsStates() {
const states = {};
const thickLinesCheckbox = document.getElementById('thick-lines-checkbox');
const translucentLinesCheckbox = document.getElementById('translucent-lines-checkbox');
if (thickLinesCheckbox) {
states.thickLines = thickLinesCheckbox.checked;
}
if (translucentLinesCheckbox) {
states.translucentLines = translucentLinesCheckbox.checked;
}
try {
localStorage.setItem('visualizer-settings-states', JSON.stringify(states));
} catch (error) {
console.warn('Failed to save settings states to localStorage:', error);
}
}
/**
* Load settings states from localStorage.
*/
export function loadSettingsStates() {
try {
const saved = localStorage.getItem('visualizer-settings-states');
if (saved) {
const states = JSON.parse(saved);
const thickLinesCheckbox = document.getElementById('thick-lines-checkbox');
const translucentLinesCheckbox = document.getElementById('translucent-lines-checkbox');
if (thickLinesCheckbox && 'thickLines' in states) {
thickLinesCheckbox.checked = states.thickLines;
}
if (translucentLinesCheckbox && 'translucentLines' in states) {
translucentLinesCheckbox.checked = states.translucentLines;
}
}
} catch (error) {
console.warn('Failed to load settings states from localStorage:', error);
}
}
/**
* Save slicing settings to localStorage.
*/
export function saveSlicingSettings(params) {
const settings = {
rotationX: params.rotationX,
rotationY: params.rotationY,
rotationZ: params.rotationZ,
printer: params.printer,
filament: params.filament,
nozzleTemperature: params.nozzleTemperature,
bedTemperature: params.bedTemperature,
fanSpeed: params.fanSpeed,
layerHeight: params.layerHeight,
shellWallThickness: params.shellWallThickness,
shellSkinThickness: params.shellSkinThickness,
infillDensity: params.infillDensity,
infillPattern: params.infillPattern,
adhesionEnabled: params.adhesionEnabled,
adhesionType: params.adhesionType,
supportEnabled: params.supportEnabled,
supportType: params.supportType,
supportPlacement: params.supportPlacement,
supportThreshold: params.supportThreshold
};
try {
localStorage.setItem('visualizer-slicing-settings', JSON.stringify(settings));
} catch (error) {
console.warn('Failed to save slicing settings to localStorage:', error);
}
}
/**
* Load slicing settings from localStorage.
*/
export function loadSlicingSettings() {
try {
const saved = localStorage.getItem('visualizer-slicing-settings');
if (saved) {
return JSON.parse(saved);
}
} catch (error) {
console.warn('Failed to load slicing settings from localStorage:', error);
}
return null;
}
/**
* Clear slicing settings from localStorage.
*/
export function clearSlicingSettings() {
try {
localStorage.removeItem('visualizer-slicing-settings');
} catch (error) {
console.warn('Failed to clear slicing settings from localStorage:', error);
}
}
/**
* Save folder open/closed states to localStorage.
*/
export function saveFolderStates(states) {
try {
localStorage.setItem('visualizer-folder-states', JSON.stringify(states));
} catch (error) {
console.warn('Failed to save folder states to localStorage:', error);
}
}
/**
* Load folder open/closed states from localStorage.
*/
export function loadFolderStates() {
try {
const saved = localStorage.getItem('visualizer-folder-states');
if (saved) {
return JSON.parse(saved);
}
} catch (error) {
console.warn('Failed to load folder states from localStorage:', error);
}
return null;
}