feat: save body and occurrence visibility with the design (#531) (#592)

Hidden bodies, occurrence placements, sketches and origin items are saved with the design and come back when it is reopened. Visibility is still not an undo step, but hiding or showing something now counts as an unsaved change. Additive field under format 16. Fixes #531.

Co-authored-by: jonaswre <jonas.wrede@beyondit.gmbh>
This commit is contained in:
Jonas Wrede authored and GitHub committed 2026-10-13 04:16:49 -04:00
1 parent 2a434d59c3
commit 135a63f549
10 files changed
+152 -31

No files matched your search

+5 -4
View File
@@ -143,7 +143,8 @@ pub struct Autosaver {
/// Autosave this often while there are unsaved changes.
pub interval: Duration,
lock: Option<File>,
last: Option<Arc<Document>>,
/// The design and what was hidden at the last autosave.
last: Option<(Arc<Document>, crate::Visibility)>,
last_at: Instant,
has_entry: bool,
}
@@ -189,17 +190,17 @@ impl Autosaver {
crate::crash::rebased(s, s.path.as_deref().map(Path::new), false);
return Ok(false);
}
if self.last.as_ref().is_some_and(|l| Arc::ptr_eq(l, &s.doc) || **l == *s.doc) {
if self.last.as_ref().is_some_and(|(l, v)| (Arc::ptr_eq(l, &s.doc) || **l == *s.doc) && *v == s.visibility) {
return Ok(false);
}
let io = |e: std::io::Error| EngineError::Other(format!("autosave: {e}"));
let bytes = solidcraft_io::write_design_container(&s.doc)?;
let bytes = solidcraft_io::write_design_container(&s.design())?;
solidcraft_io::write_atomic(&file(&self.dir, &self.id, solidcraft_io::DESIGN_EXT), &bytes, false).map_err(io)?;
let entry =
Entry { id: self.id.clone(), path: s.path.clone(), name: s.doc.name.clone(), saved_at: unix_now(), features: s.doc.features.len() };
let meta = serde_json::to_vec_pretty(&entry).map_err(|e| EngineError::Other(e.to_string()))?;
solidcraft_io::write_atomic(&file(&self.dir, &self.id, "json"), &meta, false).map_err(io)?;
self.last = Some(s.doc.clone());
self.last = Some((s.doc.clone(), s.visibility.clone()));
self.has_entry = true;
// Crash replays start from this autosave from here.
crate::crash::rebased(s, Some(&file(&self.dir, &self.id, solidcraft_io::DESIGN_EXT)), true);