refactor: make grid visibility per-drawing, not a global setting

Grid on/off now round-trips through the drawing's *Active VPort, so it is a
per-file view setting like every other CAD app treats it. Drop show_grid
from UserSettings (and its settings.txt key) and instead adopt the opened
file's saved grid_on on load. A legacy "grid=" line in an old settings file
is harmlessly ignored.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 4.8 committed 2026-06-18 22:11:27 +03:00
1 parent cd17096f65
commit b2feeb716b
3 files changed
+17 -7

No files matched your search

+1 -5
View File
@@ -65,7 +65,6 @@ pub struct UserSettings {
pub ortho: bool,
pub polar: bool,
pub polar_increment_deg: f32,
pub show_grid: bool,
pub snap_enabled: bool,
pub otrack: bool,
/// Active snap modes, in `SNAP_ORDER`.
@@ -90,7 +89,6 @@ impl Default for UserSettings {
ortho: false,
polar: false,
polar_increment_deg: 45.0,
show_grid: false,
snap_enabled: false,
otrack: false,
snap_modes: vec![
@@ -135,7 +133,6 @@ impl UserSettings {
s.polar_increment_deg = v;
}
}
"grid" => s.show_grid = val == "1",
"osnap" => s.snap_enabled = val == "1",
"otrack" => s.otrack = val == "1",
"default_assoc_prompted" => s.default_assoc_prompted = val == "1",
@@ -180,12 +177,11 @@ impl UserSettings {
.collect::<Vec<_>>()
.join(",");
let body = format!(
"dyn={}\northo={}\npolar={}\npolar_increment_deg={}\ngrid={}\nosnap={}\notrack={}\ndefault_assoc_prompted={}\nsnap_modes={}\ndisabled_plugins={}\nplugin_repos={}\n",
"dyn={}\northo={}\npolar={}\npolar_increment_deg={}\nosnap={}\notrack={}\ndefault_assoc_prompted={}\nsnap_modes={}\ndisabled_plugins={}\nplugin_repos={}\n",
b(self.dyn_input),
b(self.ortho),
b(self.polar),
self.polar_increment_deg,
b(self.show_grid),
b(self.snap_enabled),
b(self.otrack),
b(self.default_assoc_prompted),
+5 -2
View File
@@ -185,7 +185,6 @@ impl OpenCADStudio {
ortho: self.ortho_mode,
polar: self.polar_mode,
polar_increment_deg: self.polar_increment_deg,
show_grid: self.show_grid,
snap_enabled: self.snapper.snap_enabled,
otrack: self.snapper.otrack_enabled,
snap_modes: super::settings::UserSettings::modes_from(self.snapper.enabled.iter()),
@@ -205,7 +204,6 @@ impl OpenCADStudio {
self.ortho_mode = s.ortho;
self.polar_mode = s.polar;
self.polar_increment_deg = s.polar_increment_deg;
self.show_grid = s.show_grid;
self.snapper.snap_enabled = s.snap_enabled;
self.snapper.otrack_enabled = s.otrack;
self.snapper.enabled = s.snap_modes.iter().copied().collect();
@@ -600,6 +598,11 @@ impl OpenCADStudio {
// selected — see #21.
self.sync_ribbon_from_selection();
self.tabs[i].scene.restore_saved_camera();
// Grid visibility is a per-drawing view setting — adopt the
// opened file's saved state rather than a global preference.
if let Some(grid_on) = self.tabs[i].scene.active_vport_grid_on() {
self.show_grid = grid_on;
}
self.sync_render_mode_to_active_tile(i);
self.tabs[i].last_synced_camera_gen = self.tabs[i].scene.camera_generation;
self.tabs[i].dirty = false;
+11
View File
@@ -5639,6 +5639,17 @@ impl Scene {
}
}
/// Grid visibility stored on the `*Active` VPort entry, applied to the app's
/// grid toggle when a file loads (grid is a per-drawing view setting, not a
/// global preference). `None` when there is no active entry. (#121)
pub fn active_vport_grid_on(&self) -> Option<bool> {
self.document
.vports
.iter()
.find(|v| v.name == "*Active")
.map(|v| v.grid_on)
}
/// Set the paper-space camera from the sheet viewport's stored view.
/// Returns true if a valid sheet viewport was found and the camera was set.
///