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:
Hakan SevenandClaude Opus 4.8 committed 2026-07-12 01:01:40 +03:00
1 parent 5215a9773b
commit dd3ce6767c
6 files changed
+53 -8

No files matched your search

+14
View File
@@ -530,6 +530,20 @@ fn set_vardict_value(doc: &mut CadDocument, name: &str, value: &str) {
}
}
/// The layout tab that was active when the drawing was saved — the `CTAB`
/// system variable (stored in the variable dictionary as a `DICTIONARYVAR`).
/// `None` when the file recorded no current tab.
pub fn saved_active_layout(doc: &CadDocument) -> Option<String> {
vardict_value(doc, "CTAB").filter(|s| !s.is_empty())
}
/// Record `name` as the active layout tab (`CTAB`) so the next save round-trips
/// which space was open. No-op when the document has no `CTAB` entry yet; the
/// `$TILEMODE` header (model vs paper) remains the guaranteed fallback.
pub fn set_saved_active_layout(doc: &mut CadDocument, name: &str) {
set_vardict_value(doc, "CTAB", name);
}
/// Materialise the current-style choices into their format-specific storage
/// before saving, treating the current-style *names* as the single source of
/// truth: