From f9146cdd5887af90b0999c8dbd8f4fb8ae0f7f18 Mon Sep 17 00:00:00 2001 From: jeromehzl <51324719+jeromehzl@users.noreply.github.com> Date: Fri, 30 Oct 2026 09:37:53 +0000 Subject: [PATCH] Hole: a Hole at sketch points hides its sketch as an Extrude does (#9082) (#9211) sketch_consumed knew Extrude, Revolve and the sheet metal flanges but not a Hole drilled at a sketch's points, so that sketch stayed drawn inside the holes. A Multiple hole now counts as using its sketch; Edit Feature shows its points while the dialog is open. Single holes keep their sketch shown, since a hidden sketch offers no points to snap to. --- crates/engine/src/cmd/browser.rs | 37 +++++++++++++++++++ crates/engine/src/view.rs | 10 +++-- crates/ui-egui/src/dialogs.rs | 9 +++-- crates/ui-egui/src/hole_direction_ui_tests.rs | 5 +++ 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/browser.rs b/crates/engine/src/cmd/browser.rs index 4ecc83297..1ea32cb0a 100644 --- a/crates/engine/src/cmd/browser.rs +++ b/crates/engine/src/cmd/browser.rs @@ -1731,6 +1731,43 @@ mod tests { assert!(crate::view::sketch_shown(&s, wall) && !crate::view::sketch_shown(&s, base)); } + #[test] + fn a_hole_at_sketch_points_hides_its_sketch_as_an_extrude_does() { + // #9082: a Hole's points sketch stayed shown, and its points were drawn in the holes. A + // Single hole snapped to one point (#2110) leaves its sketch shown: it was placed on a face, + // and a hidden sketch offers no points for the next one to snap to. + let mut s = Session::default(); + let plate = run(&mut s, "sketch.create", json!({"plane": "XY", "name": "PlateSketch"}))["sketch"].as_u64().unwrap(); + run(&mut s, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [40, 30]})); + run(&mut s, "sketch.finish", json!({})); + run(&mut s, "solid.extrude", json!({"sketch": plate, "distance": 6})); + assert!(!crate::view::sketch_shown(&s, plate), "the Extrude used its sketch"); + let pts = run(&mut s, "sketch.create", json!({"plane": "XY", "name": "HolePts", "offset": 6}))["sketch"].as_u64().unwrap(); + run(&mut s, "sketch.point", json!({"point": [10, 10]})); + run(&mut s, "sketch.point", json!({"point": [30, 20]})); + run(&mut s, "sketch.finish", json!({})); + let spot = run(&mut s, "sketch.create", json!({"plane": "XY", "name": "Spot", "offset": 6}))["sketch"].as_u64().unwrap(); + run(&mut s, "sketch.point", json!({"point": [20, 15], "id": "c"})); + run(&mut s, "sketch.finish", json!({})); + assert!(crate::view::sketch_shown(&s, pts) && crate::view::sketch_shown(&s, spot), "unused sketches are shown"); + run(&mut s, "solid.hole", json!({"sketch": "HolePts", "diameter": 3, "name": "Holes"})); + assert!(!crate::view::sketch_shown(&s, pts), "the Hole used its points sketch"); + run(&mut s, "solid.hole", json!({"sketch": "Spot", "points": ["c"], "single": true, "diameter": 3, "depth": 3, "name": "One"})); + assert!(crate::view::sketch_shown(&s, spot), "a Single hole leaves the sketch it snapped to shown"); + let d = run(&mut s, "document.inspect", json!({})); + let visible = |id: u64| d["sketches"].as_array().unwrap().iter().find(|x| x["id"] == id).unwrap()["visible"].clone(); + assert_eq!((visible(pts), visible(spot)), (json!(false), json!(true)), "{d}"); + // While the Hole is edited it is drawn, then hidden again; shown on its own, it stays drawn. + s.feature_edit_sketch = Some(pts); + assert!(crate::view::sketch_shown(&s, pts)); + s.feature_edit_sketch = None; + assert!(!crate::view::sketch_shown(&s, pts)); + run(&mut s, "browser.visibility", json!({"items": [pts], "visible": true})); + assert!(crate::view::sketch_shown(&s, pts) && !crate::view::sketch_shown(&s, plate)); + run(&mut s, "browser.visibility", json!({"items": [pts], "visible": false})); + assert!(!crate::view::sketch_shown(&s, pts)); + } + #[test] fn helper_sketches_hide_and_show() { let mut s = Session::default(); diff --git a/crates/engine/src/view.rs b/crates/engine/src/view.rs index eb92d7a41..611151ba6 100644 --- a/crates/engine/src/view.rs +++ b/crates/engine/src/view.rs @@ -864,12 +864,16 @@ fn sketch_component_visible(s: &Session, id: u64) -> bool { /// Is a sketch used by a later feature? A sheet metal base or contour flange uses its sketch as /// an Extrude does: shown, its lines lie on the sheet's edges and take the clicks meant for -/// them (#6804). +/// them (#6804). So does a Hole at sketch points: shown, its points are drawn in the holes +/// (#9082). A Single hole snapped to one point (#2110) does not: it was placed on a face, not +/// built from the sketch, and hiding the sketch would take its other points from the next +/// Single hole's snap. pub fn sketch_consumed(s: &Session, id: u64) -> bool { - use solidcraft_doc::FeatureKind; + use solidcraft_doc::{FeatureKind, SketchPoints}; s.doc.features.iter().any(|f| { matches!(f.kind, FeatureKind::Extrude { sketch, .. } | FeatureKind::Revolve { sketch, .. } - | FeatureKind::SheetBase { sketch, .. } | FeatureKind::SheetContour { sketch, .. } if sketch == id) + | FeatureKind::SheetBase { sketch, .. } | FeatureKind::SheetContour { sketch, .. } + | FeatureKind::Hole { points: Some(SketchPoints { sketch, single: false, .. }), .. } if sketch == id) }) } diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 6a09f933c..e3219dac1 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -2999,15 +2999,16 @@ fn picked_side(app: &SolveApp, d: &Dialog, first: &Sel) -> Option { Some(crate::smart_extrude::picked_direction(crate::smart_extrude::view_ray(&app.cam, at), normal, false)) } -/// Show the sketch of the Extrude, Revolve or sheet metal base or contour flange the open dialog -/// edits, and only while it is open: whichever way the dialog closed (OK, Cancel, another tool, -/// another design), the sketch returns to its own visibility. +/// Show the sketch of the Extrude, Revolve, sheet metal base or contour flange, or Hole at sketch +/// points the open dialog edits, and only while it is open: whichever way the dialog closed (OK, +/// Cancel, another tool, another design), the sketch returns to its own visibility. pub(crate) fn sync_feature_edit_sketch(app: &mut SolveApp) { app.session.feature_edit_sketch = app.dialog.as_ref().and_then(|d| d.editing).and_then(|(id, _)| match &app.session.doc.feature(id)?.kind { FeatureKind::Extrude { sketch, .. } | FeatureKind::Revolve { sketch, .. } | FeatureKind::SheetBase { sketch, .. } - | FeatureKind::SheetContour { sketch, .. } => Some(**sketch), + | FeatureKind::SheetContour { sketch, .. } + | FeatureKind::Hole { points: Some(solidcraft_engine::doc::SketchPoints { sketch, single: false, .. }), .. } => Some(**sketch), _ => None, }); } diff --git a/crates/ui-egui/src/hole_direction_ui_tests.rs b/crates/ui-egui/src/hole_direction_ui_tests.rs index 98b137fa2..5aedf8562 100644 --- a/crates/ui-egui/src/hole_direction_ui_tests.rs +++ b/crates/ui-egui/src/hole_direction_ui_tests.rs @@ -124,12 +124,17 @@ fn flip_drills_holes_at_sketch_points_the_other_way() { assert!(h.app.dialog.is_none(), "OK closed the dialog: {:?}", h.app.dialog.as_ref().map(|d| &d.error)); assert!(!solid_at(&h, Vec3::new(10.0, 10.0, 2.5)), "flipped: the hole comes up from the bottom"); assert!(solid_at(&h, Vec3::new(10.0, 10.0, 17.5)), "and not down from the top"); + assert!(!solidcraft_engine::view::sketch_shown(&h.app.session, sketch), "the Hole used its points sketch"); // Edit Feature shows Flip on, and OK keeps it. let id = h.app.session.doc.features.last().unwrap().id; h.step(&json!({"call": "ui.editFeature", "params": {"feature": id}})).unwrap(); h.frames(4); let d = h.app.dialog.as_ref().expect("the hole dialog"); assert_eq!(d.extra.get("flip"), Some(&json!(true))); + assert_eq!(h.app.session.feature_edit_sketch, Some(sketch), "editing shows its points to pick"); + assert!(solidcraft_engine::view::sketch_shown(&h.app.session, sketch), "editing shows its points to pick"); h.step(&json!({"key": "Enter"})).unwrap(); assert!(!solid_at(&h, Vec3::new(10.0, 10.0, 2.5)) && solid_at(&h, Vec3::new(10.0, 10.0, 17.5))); + assert_eq!(h.app.session.feature_edit_sketch, None); + assert!(!solidcraft_engine::view::sketch_shown(&h.app.session, sketch)); }