feat(io): persist grid/snap display state to the active VPort

Mirror the in-app grid and grid-snap toggles (plus the adaptive grid
spacing) onto the *Active VPort entries so a saved DWG/DXF reflects what
the user actually has on, instead of always writing VPort defaults. The
flags are stamped when the toggles change and again before a save, and
carried across the camera-sync VPort rebuild so they survive an orbit/pan.

Only grid_on, snap_on and grid_spacing have an OCS counterpart; the other
VPort view fields (view twist, clip planes, lens length, etc.) have no
in-app source and stay at their faithful defaults.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 4.8 committed 2026-06-18 22:05:25 +03:00
1 parent aa81d7fe7e
commit cd17096f65
2 files changed
+50

No files matched your search

+30
View File
@@ -5573,6 +5573,15 @@ impl Scene {
}
let table_handle = self.document.vports.handle();
// Carry the grid/snap display state from the existing `*Active` entry
// across the rebuild — these flags track the in-app toggles and must
// not reset to VPort defaults each camera sync. (#121)
let display = self
.document
.vports
.iter()
.find(|v| v.name == "*Active")
.map(|v| (v.grid_on, v.snap_on, v.grid_spacing, v.snap_spacing, v.snap_base));
let preserved_vps: Vec<acadrust::tables::VPort> = self
.document
.vports
@@ -5604,11 +5613,32 @@ impl Scene {
let (ll, ur) = Self::tile_rect_to_vport(tile.rect);
let mut entry = self.vport_from_camera("*Active", &tile.camera, ll, ur);
entry.render_mode = tile.render_mode;
if let Some((grid_on, snap_on, grid_spacing, snap_spacing, snap_base)) = display {
entry.grid_on = grid_on;
entry.snap_on = snap_on;
entry.grid_spacing = grid_spacing;
entry.snap_spacing = snap_spacing;
entry.snap_base = snap_base;
}
entry.handle = self.document.allocate_handle();
self.document.vports.add_allow_duplicate(entry);
}
}
/// Stamp the grid/snap display state onto every `*Active` VPort entry so a
/// saved file reflects the in-app grid/snap toggles (otherwise other CAD
/// apps read VPort defaults). `grid_spacing` is applied to both axes and
/// mirrored to the snap spacing. (#121)
pub fn set_active_vport_display(&mut self, grid_on: bool, snap_on: bool, grid_spacing: f64) {
let spacing = acadrust::types::Vector2 { x: grid_spacing, y: grid_spacing };
for vp in self.document.vports.iter_mut().filter(|v| v.name == "*Active") {
vp.grid_on = grid_on;
vp.snap_on = snap_on;
vp.grid_spacing = spacing;
vp.snap_spacing = spacing;
}
}
/// 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.
///