SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
control::execute: check the undo depth before placing the world for the first-body fit (#5940)
SS-EN6578d591ac57
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rsindex aaa068cebe..3940b3f15b 100644--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@ -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);diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rsindex 9c481a5176..5fb0c577c5 100644--- a/crates/ui-egui/src/control.rs+++ b/crates/ui-egui/src/control.rs@@ -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]