SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Extrude: with every body hidden, a new extrude stays New Body instead of turning to Cut (#9919) (#9920)
N3MI-DG6b247754139f
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 2068807412..595e1fa978 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -3027,20 +3027,33 @@ fn auto_operation(app: &SolveApp, d: &mut Dialog) {smart.start = start;smart.latch = None;}+ // Showing or hiding a body changes what the extrude meets: the latch was decided among the+ // bodies shown before (#9919).+ let shown = solidcraft_engine::shown_scope(&app.session);+ if let Kind::Extrude { smart, .. } = &mut d.kind+ && smart.shown != shown+ {+ smart.shown = shown.clone();+ smart.latch = None;+ }// To an object, the extrude goes to it on whichever side it is: that is the side (#1633).if params.get("to").is_some()&& let Some(reach) = solidcraft_engine::extrude_reach(&app.session, ¶ms){side = crate::smart_extrude::side(reach, 0);}- // Hidden bodies are out of its scope (#6901).+ // Hidden bodies are out of its scope (#6901). With none shown there is nothing to join or+ // cut: an empty `participants` would read as every body, hidden ones too (#9919).let mut params = params;- if let Some(shown) = solidcraft_engine::shown_scope(&app.session)+ let mut nothing_shown = false;+ if let Some(shown) = shown&& params.get("participants").is_none(){+ nothing_shown = shown.is_empty();params["participants"] = json!(shown);}- let Some(fresh) = solidcraft_engine::auto_operation(&app.session, ¶ms).and_then(|op| OPS.iter().position(|o| *o == op)) else {+ let fresh = if nothing_shown { Some("new") } else { solidcraft_engine::auto_operation(&app.session, ¶ms) };+ let Some(fresh) = fresh.and_then(|op| OPS.iter().position(|o| *o == op)) else {return;};if let Kind::Extrude { operation, smart, .. } = &mut d.kind {diff --git a/crates/ui-egui/src/op_auto_tests.rs b/crates/ui-egui/src/op_auto_tests.rsindex 6275214bf4..39f058d9c4 100644--- a/crates/ui-egui/src/op_auto_tests.rs+++ b/crates/ui-egui/src/op_auto_tests.rs@@ -214,6 +214,29 @@ fn hidden_bodies_take_no_part() {assert_eq!(op(&mut h), NEW);}+#[test]+fn into_a_hidden_body_with_nothing_shown_is_a_new_body_until_it_is_shown() {+ // The profile on the hidden cube's base, extruded into it (#9919).+ let mut h = cube();+ h.app.run("browser.visibility", json!({"items": ["Base"], "visible": false})).unwrap();+ rect_sketch(&mut h, [0.0, 0.0], [10.0, 10.0]);+ h.step(&json!({"start": "solid.extrude"})).unwrap();+ checked(&mut h);+ assert_eq!(op(&mut h), NEW, "nothing shown to cut");+ let preview = h.app.dialog.as_ref().map(|d| crate::dialogs::apply_commands(&h.app, d));+ assert!(preview.is_some_and(|c| c.is_ok_and(|c| !c.is_empty())), "the extrude runs");+ // Shown while the window is open: the extrude goes into it, a Cut.+ h.app.run("browser.visibility", json!({"items": ["Base"], "visible": true})).unwrap();+ checked(&mut h);+ assert_eq!(op(&mut h), CUT, "the shown cube is cut");+ // Hidden again: New Body again.+ h.app.run("browser.visibility", json!({"items": ["Base"], "visible": false})).unwrap();+ checked(&mut h);+ assert_eq!(op(&mut h), NEW);+ ok(&mut h);+ assert_eq!(bodies(&h).len(), 2, "{:?}", bodies(&h));+}+#[test]fn an_edited_feature_keeps_its_operation() {let mut h = cube();diff --git a/crates/ui-egui/src/smart_extrude.rs b/crates/ui-egui/src/smart_extrude.rsindex 8dd2259dc5..a5615b70ae 100644--- a/crates/ui-egui/src/smart_extrude.rs+++ b/crates/ui-egui/src/smart_extrude.rs@@ -11,7 +11,9 @@//! one that starts as a Join does not turn into a Cut when it reaches another body. When//! the distance passes through zero onto the other side (a drag reversed past the start, or//! Reverse), the operation is decided afresh for that side and latched there. So is a new-//! start (From Object, a start offset): it moves the extrude to other bodies (#467). A zero+//! start (From Object, a start offset): it moves the extrude to other bodies (#467), and+//! so is a body shown or hidden while the window is open (#9919). With no body shown it is a+//! New Body: there is nothing to join or cut. A zero//! distance changes nothing. Choosing an operation by hand ends the automatic choice for//! the rest of the extrude.@@ -31,6 +33,8 @@ pub struct Smart {pub target: Option<Sel>,/// Where the extrude starts (its From Object and start offset) when the latch was decided.pub start: serde_json::Value,+ /// The bodies shown when the latch was decided (None: every one), as `shown_scope` gives them.+ pub shown: Option<Vec<String>>,/// Picks off the profile plane become the To Object target (Preferences › Design).pub auto_to_object: bool,}