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 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-07-10 15:45:08 +03:00
commit da2c600953
7 changed files with 220 additions and 3 deletions

View file

@ -664,11 +664,17 @@ impl OpenCADStudio {
// ── Document tabs ─────────────────────────────────────────────
Message::TabNew => {
// Preserve the outgoing drawing's Ortho / running OSNAP.
self.stamp_header_sysvars(self.active_tab);
self.tab_counter += 1;
let new_tab = super::document::DocumentTab::new_drawing(self.tab_counter);
self.tabs.push(new_tab);
self.active_tab = self.tabs.len() - 1;
let idx = self.active_tab;
// A fresh drawing inherits the app's current Ortho / OSNAP so
// creating one doesn't silently reset them (its header default is
// 0 = no snaps); saving then persists them into the file.
self.stamp_header_sysvars(idx);
self.apply_bg_default(idx);
self.sync_ribbon_layers();
self.sync_ribbon_styles();
@ -687,6 +693,10 @@ impl OpenCADStudio {
// The attribute editor is tab-scoped; leaving its tab
// drops it (its handle is that document's, not this one's).
self.cancel_attr_editor();
// Persist the outgoing drawing's Ortho / running OSNAP
// before leaving it, so switching back restores them.
let prev = self.active_tab;
self.stamp_header_sysvars(prev);
}
self.active_tab = idx;
self.sync_ribbon_layers();
@ -698,6 +708,8 @@ impl OpenCADStudio {
self.sync_ribbon_from_selection();
// Grid/snap follow the newly active drawing's viewport.
self.adopt_view_display(idx);
// Ortho / running OSNAP follow the newly active drawing.
self.adopt_header_sysvars(idx);
// Shared CJK ideographs follow the newly active drawing's
// language; re-tessellate if it differs from the last. (#141)
if crate::scene::text::web_font::set_cjk_lang_from_codepage(