forked from 1b-agent/opencadstudio-upstream
Layouts reopen in the viewport they were saved in (#1670)
A save records the entered model viewport (or the sheet) as the layout's last active viewport, and opening the layout enters it again with its UCS. Picks up the codec fix that kept a last-active link from being read as the sheet viewport (codec d57097c, kernel b40fa59, graph 2360341). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
072aeb9dbf
commit
2c329b2889
9 files changed
+102
-13
No files matched your search
@@ -2196,6 +2196,12 @@ impl OpenCADStudio {
|
||||
self.tabs[i].scene.load_current_layout_state();
|
||||
self.tabs[i].refresh_active_ucs();
|
||||
}
|
||||
// A layout saved with a model viewport entered reopens inside it,
|
||||
// with that viewport's UCS (#1670).
|
||||
let enter_viewport_task = self.tabs[i]
|
||||
.scene
|
||||
.saved_entered_viewport()
|
||||
.map_or_else(Task::none, |handle| Task::done(Message::EnterViewport(handle)));
|
||||
|
||||
// The tab may have been reused for the newly opened file. Any Plot
|
||||
// dialog cache belongs to the previous/startup drawing and must not
|
||||
@@ -2317,6 +2323,7 @@ impl OpenCADStudio {
|
||||
interaction_task,
|
||||
startup_script_task,
|
||||
sheet_set_task,
|
||||
enter_viewport_task,
|
||||
])
|
||||
}
|
||||
|
||||
@@ -2640,6 +2647,7 @@ impl OpenCADStudio {
|
||||
if self.tabs[i].active_block_edit.is_none() {
|
||||
self.tabs[i].scene.sync_camera_to_document();
|
||||
self.tabs[i].last_synced_camera_gen = self.tabs[i].scene.camera_generation;
|
||||
self.tabs[i].scene.sync_active_viewport_to_document();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4661,6 +4661,46 @@ impl Scene {
|
||||
crate::io::set_saved_active_layout(&mut self.document, &self.current_layout);
|
||||
}
|
||||
|
||||
/// Record the entered viewport (or the sheet, in paper space) as the
|
||||
/// current layout's last active viewport, which reopens it (#1670).
|
||||
pub fn sync_active_viewport_to_document(&mut self) {
|
||||
let Some(handle) = self.current_layout_object_handle() else {
|
||||
return;
|
||||
};
|
||||
let sheet = match self.document.objects.get(&handle) {
|
||||
Some(ObjectType::Layout(layout)) => {
|
||||
Self::layout_sheet_viewport_handle(&self.document, layout)
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
let active = self.active_viewport.unwrap_or(sheet);
|
||||
if let Some(ObjectType::Layout(layout)) = self.document.objects.get_mut(&handle) {
|
||||
layout.viewport = active;
|
||||
}
|
||||
}
|
||||
|
||||
/// The model viewport the current layout was saved with entered: its
|
||||
/// last active viewport when that is an on viewport other than the sheet.
|
||||
pub fn saved_entered_viewport(&self) -> Option<Handle> {
|
||||
let handle = self.current_layout_object_handle()?;
|
||||
let Some(ObjectType::Layout(layout)) = self.document.objects.get(&handle) else {
|
||||
return None;
|
||||
};
|
||||
let viewport = layout.viewport;
|
||||
let sheet = Self::layout_sheet_viewport_handle(&self.document, layout);
|
||||
if viewport.is_null() || viewport == sheet {
|
||||
return None;
|
||||
}
|
||||
match self.document.get_entity(viewport) {
|
||||
Some(EntityType::Viewport(vp))
|
||||
if vp.common.owner_handle == layout.block_record && !vp.status.is_off =>
|
||||
{
|
||||
Some(viewport)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn layout_sheet_viewport_handle(
|
||||
document: &codec::CadDocument,
|
||||
layout: &codec::objects::Layout,
|
||||
|
||||
Reference in new issue
Block a user