From 6b247754139f7be6e447e7e42ee1298adea87f31 Mon Sep 17 00:00:00 2001 From: N3MI-DG <129717180+N3MI-DG@users.noreply.github.com> Date: Sat, 31 Oct 2026 09:16:30 +0000 Subject: [PATCH] Extrude: with every body hidden, a new extrude stays New Body instead of turning to Cut (#9919) (#9920) * claim: #9919 Co-Authored-By: Claude Opus 5.5 * Extrude: with every body hidden, a new extrude stays New Body instead of turning to Cut (#9919) Smart Extrude passed the shown bodies as `participants` to keep hidden ones out (#6901), but with none shown that list was empty, and the engine reads an empty list as the whole scope: a profile on a hidden body chose Cut, which has no shown body to change, so nothing was previewed and OK did nothing. With no body shown it now chooses New Body. The operation it latches for a side is also decided again when a body is shown or hidden while the window is open, as a new start already does (#467): showing the body an extrude goes into turns it to Cut, hiding it again back to New Body. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/dialogs.rs | 19 ++++++++++++++++--- crates/ui-egui/src/op_auto_tests.rs | 23 +++++++++++++++++++++++ crates/ui-egui/src/smart_extrude.rs | 6 +++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 206880741..595e1fa97 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.rs index 6275214bf..39f058d9c 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.rs index 8dd2259dc..a5615b70a 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, /// 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>, /// Picks off the profile plane become the To Object target (Preferences › Design). pub auto_to_object: bool, }