forked from 1b-agent/opencadstudio-upstream
feat(layout): reopen a drawing in the space it was saved in
Files saved while a paper layout was active reopened in Model space because the loader hardcoded the current layout to "Model" and never consulted the space recorded in the file. The active space is a standard part of the format and acadrust already round-trips it: $TILEMODE (header.show_model_space) for model-vs-paper, and the CTAB current-tab variable for the exact layout name. - Read: on open, pick the current layout from CTAB (when it names a layout that exists), else $TILEMODE (Model, or the first paper layout). - Write: Scene::sync_active_space_to_document() mirrors the active layout back into the document (show_model_space + CTAB). It runs from set_current_layout, so every active-layout change — the status-bar tab, the Layout Manager's Set Current, create / rename / delete, and undo/redo — keeps the document in sync for the next save. $TILEMODE is the guaranteed mechanism (read and written for both DXF and DWG); CTAB refines the exact tab when the variable is present. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
5215a9773b
commit
dd3ce6767c
6 files changed
+53
-8
No files matched your search
@@ -89,6 +89,7 @@ impl Scene {
|
||||
// If the deleted layout was active, fall back to Model space.
|
||||
if self.current_layout == name {
|
||||
self.current_layout = "Model".to_string();
|
||||
self.sync_active_space_to_document();
|
||||
}
|
||||
|
||||
self.bump_geometry();
|
||||
|
||||
@@ -1333,11 +1333,22 @@ impl Scene {
|
||||
pub fn set_current_layout(&mut self, name: String) {
|
||||
if self.current_layout != name {
|
||||
self.current_layout = name;
|
||||
self.sync_active_space_to_document();
|
||||
self.recolor_meshes();
|
||||
self.bump_geometry();
|
||||
}
|
||||
}
|
||||
|
||||
/// Mirror the active space (Model tile-mode vs a paper layout) into the
|
||||
/// document's persisted settings so it round-trips on save: the `$TILEMODE`
|
||||
/// header (`show_model_space`) and the `CTAB` current-tab variable. The
|
||||
/// reader restores it via [`current_layout`] on open. Called whenever the
|
||||
/// active layout changes; the file otherwise always reopened in Model.
|
||||
pub fn sync_active_space_to_document(&mut self) {
|
||||
self.document.header.show_model_space = self.current_layout == "Model";
|
||||
crate::io::set_saved_active_layout(&mut self.document, &self.current_layout);
|
||||
}
|
||||
|
||||
/// Returns true if this viewport should display model-space content
|
||||
/// (i.e. it is a user viewport, not the sheet/overall viewport).
|
||||
///
|
||||
|
||||
Reference in new issue
Block a user