control::execute: check the undo depth before placing the world for the first-body fit (#5940)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SS-EN
2026-11-04 21:30:48 +00:00
committed by GitHub
parent d9421bf2ca
commit 6578d591ac
2 changed files with 29 additions and 3 deletions
+3 -2
View File
@@ -1133,8 +1133,9 @@ impl Session {
self.model.forget_fingerprints();
}
/// Prepared placements only: optional save caches must not compute a cold world.
pub(crate) fn cached_world_state(&self) -> Option<Arc<solidcraft_doc::ModelState>> {
/// Prepared placements only: optional save caches must not compute a cold world. `None`
/// when the design has components and nothing has placed them since it last changed.
pub fn cached_world_state(&self) -> Option<Arc<solidcraft_doc::ModelState>> {
let state = self.model.state();
if self.doc.occurrences.is_empty() {
return Some(state);
+26 -1
View File
@@ -327,8 +327,10 @@ fn execute(app: &mut SolveApp, id: &str, params: Value) -> Result<Value, String>
)
&& !id.starts_with("settings.")
&& app.session.active_sketch.is_none()
&& crate::open_meshing::session_world(&app.session).bodies.len() == 1
// Cheap test first: placing the world (`world_state`) after every step of a batch in a
// design with components placed every component's bodies again once per step.
&& app.session.undo.len() <= 2
&& crate::open_meshing::session_world(&app.session).bodies.len() == 1
{
app.fit_view();
}
@@ -2287,6 +2289,29 @@ mod tests {
}
}
/// A step of a long design leaves its components unplaced: the first-body fit's check
/// (`execute`) looks at the undo history before placing the world, which used to place
/// every component's bodies after every step of a batch.
#[test]
fn a_step_does_not_place_the_world_for_the_first_body_fit() {
let mut h = crate::scenario::Harness::new();
let v = batch(
&mut h,
json!({"commands": [
{"command": "solid.box", "params": {"length": 10, "width": 10, "height": 10, "body_name": "Cube"}},
{"command": "component.from_bodies", "params": {"bodies": ["Cube"]}},
{"command": "occurrence.copy", "params": {"component": "Cube", "translate": [0, 40, 0]}},
]}),
);
assert!(v["result"].get("failed").is_none(), "{v}");
assert!(h.app.session.undo.len() > 2, "past the first-body fit");
// Straight to `execute`, with no frame: drawing places the world too.
let r = super::execute(&mut h.app, "solid.sphere", json!({"radius": 3, "center": [80, 0, 0], "operation": "new"}));
assert!(r.is_ok(), "{r:?}");
assert!(h.app.session.cached_world_state().is_none(), "the step placed the components again");
assert_eq!(crate::open_meshing::session_world(&h.app.session).bodies.len(), 3);
}
/// #743: a batch is one request through the app's queue, answered within a frame, however
/// many steps it has.
#[test]