feat(sysvars): persist Ortho, running OSNAP and Isolate in the drawing

Ortho and the running object-snap set were app-global (settings.txt only) and
Isolate/Hide was a session-only view state, so none survived save/reopen and
none were per-drawing. Bind all three to the file like AutoCAD:

- Ortho -> header.ortho_mode ($ORTHOMODE); running OSNAP <-> header
  .object_snap_mode ($OSMODE bitmask) via a new SnapType<->bit map in settings
  (osmode_from_snaps / snaps_from_osmode, round-trip tested). The header is the
  per-drawing store, live state mirrors the active drawing: adopt header->live
  on open and tab-switch, stamp live->header on save and when leaving a tab, a
  fresh drawing inherits the current values, and SETVAR ORTHOMODE/OSMODE now
  also update the live state. settings.txt stays as the boot/new-drawing
  default; the per-file header overrides it on open.
- Isolate/Hide now set each entity's persisted invisible flag (DXF code 60,
  which acadrust round-trips in DXF and DWG) in addition to the session set;
  End Isolation clears it. The set is reseeded from invisible entities on load
  and after undo/redo, the commands are undoable and mark the tab dirty. The
  renderer already skipped invisible entities, so no render change was needed.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 4.8 committed 2026-07-10 15:45:08 +03:00
1 parent 7cba5c8679
commit da2c600953
7 files changed
+220 -3

No files matched your search

+35 -3
View File
@@ -1951,12 +1951,16 @@ impl Scene {
return;
}
let keep = self.selected.clone();
self.hidden = self
let hide: Vec<Handle> = self
.document
.entities()
.map(|e| e.common().handle)
.filter(|h| !h.is_null() && !keep.contains(h))
.collect();
// Persist the hidden state on each entity (DXF code 60) so it survives
// save/reopen — the renderer already skips `invisible` entities.
self.set_invisible(&hide, true);
self.hidden = hide.into_iter().collect();
self.selected.clear();
self.bump_geometry();
}
@@ -1966,22 +1970,50 @@ impl Scene {
if self.selected.is_empty() {
return;
}
for h in self.selected.iter().copied() {
let sel: Vec<Handle> = self.selected.iter().copied().collect();
for h in sel.iter().copied() {
self.hidden.insert(h);
}
self.set_invisible(&sel, true);
self.selected.clear();
self.bump_geometry();
}
/// Clear isolation — bring every hidden entity back (End Isolation).
/// Clear isolation — bring every hidden entity back (End Isolation),
/// clearing the persisted invisible flag too so the reveal is saved.
pub fn end_isolation(&mut self) {
if self.hidden.is_empty() {
return;
}
let restore: Vec<Handle> = self.hidden.iter().copied().collect();
self.set_invisible(&restore, false);
self.hidden.clear();
self.bump_geometry();
}
/// Set the persisted visibility flag (DXF code 60) on each handle.
fn set_invisible(&mut self, handles: &[Handle], invisible: bool) {
for &h in handles {
if let Some(e) = self.document.get_entity_mut(h) {
e.common_mut().invisible = invisible;
}
}
}
/// Rebuild the Isolate/Hide set (`hidden`) from the entities the document
/// currently marks invisible (DXF code 60). Call after loading a file or
/// restoring an undo/redo snapshot so the session set matches the persisted
/// per-entity visibility (and End Isolation stays available).
pub fn sync_hidden_from_invisible(&mut self) {
self.hidden = self
.document
.entities()
.filter(|e| e.common().invisible)
.map(|e| e.common().handle)
.filter(|h| !h.is_null())
.collect();
}
/// True if any currently selected entity is a Viewport.
/// Used to enable the scale picker when a viewport is selected in paper space.
pub fn has_selected_viewport(&self) -> bool {