From 1cbebe21bf768c7cd11fdd386c80a0434cd81389 Mon Sep 17 00:00:00 2001 From: SilentWolf75 <134335235+SilentWolf75@users.noreply.github.com> Date: Mon, 2 Nov 2026 02:39:25 +0000 Subject: [PATCH] Edit Hole: seed the face where the hole is now (#10689) (#10860) * claim: #10689 Co-authored-by: Cursor * Edit Hole: seed the face where the hole is now (#10689) Project the stored position onto the drilled face along the hole direction when opening the editor, matching evaluation, so OK works after a parameter moves the face. Co-authored-by: Cursor --------- Co-authored-by: Cursor --- crates/doc/src/eval.rs | 5 ++-- crates/doc/src/lib.rs | 4 +-- crates/ui-egui/src/dialogs.rs | 47 ++++++++++++++++++++++++++++++++--- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs index ca2c70104..6e50a9a98 100644 --- a/crates/doc/src/eval.rs +++ b/crates/doc/src/eval.rs @@ -3936,8 +3936,9 @@ fn body_at(st: &ModelState, body: &Option, points: &[Vec3]) -> /// A hole stays on its face when the model changes: a position now inside a body moves back /// against the drilling direction to the surface, one now above it moves down onto it. Only the -/// bodies in `scope` count (every body when it is empty, see [`hole_scope`]). -fn hole_on_surface(st: &ModelState, p: Vec3, dir: Vec3, scope: &[String]) -> Vec3 { +/// bodies in `scope` count (every body when it is empty, see [`hole_scope`]). Edit Hole seeds from +/// this point so the dialog's face pick matches where evaluation drills (#10689). +pub fn hole_on_surface(st: &ModelState, p: Vec3, dir: Vec3, scope: &[String]) -> Vec3 { let size = st.bodies.iter().map(|b| b.body.size()).fold(1.0, f64::max); let eps = size * 1e-6; let mut best: Option = None; diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs index bd89b493b..4a48dd9e3 100644 --- a/crates/doc/src/lib.rs +++ b/crates/doc/src/lib.rs @@ -86,8 +86,8 @@ pub use assembly::{ pub use document::*; pub use eval::{ EdgeRef, FeatureResult, Model, ModelBody, ModelState, PlacedBodies, RevolveExtent, SavedModel, SolvedSketch, ThreadInfo, curve_pick_error, - edge_names_for, edge_refs, face_point_names, face_point_state, hole_direction_at, import_body_names, join_pieces_added, map_wire, - metric_thread_sizes, object_height, parse_metric_thread, pattern_matrices, revolve_extent, revolve_extent_for_handle, + edge_names_for, edge_refs, face_point_names, face_point_state, hole_direction_at, hole_on_surface, import_body_names, join_pieces_added, + map_wire, metric_thread_sizes, object_height, parse_metric_thread, pattern_matrices, revolve_extent, revolve_extent_for_handle, revolve_extent_with_convention, select_profiles, sketch_hole_direction, sketch_line_plane, state_in_frame, state_in_frame_at, suggested_thread, tangent_face_chain, through_all_distance, world_state, world_state_reusing, }; diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index baf004a22..df2e2ae34 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -6087,14 +6087,19 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option) -> Option { + // Evaluation projects the stored point onto the face along the drill + // direction when the body moves; seed the Face pick there too (#10689). + // Keep `position_exprs.point` as the stored value so expressions stay only + // when the pick is still that point (a moved face drops them for numbers). + let on_face = solidcraft_engine::doc::hole_on_surface(&s.world_state(), position.0, direction.0, &[]); if let Some(inp) = d.inputs.first_mut() { - inp.items = vec![face_sel(s, position.0).unwrap_or(Sel::Face { body: String::new(), index: 0, point: position.0 })]; + inp.items = vec![face_sel(s, on_face).unwrap_or(Sel::Face { body: String::new(), index: 0, point: on_face })]; } d.extra.insert("direction".into(), pt3(direction.0)); // A position given as expressions (#1678) is sent again while the pick // stays where the hole is; a new pick places it by the point picked. - if let Some(at) = at { - let exprs: Vec<&str> = at.iter().map(|e| e.as_str()).collect(); + if let Some(exprs) = at { + let exprs: Vec<&str> = exprs.iter().map(|e| e.as_str()).collect(); d.extra.insert("position_exprs".into(), json!({"at": exprs, "point": pt3(position.0)})); } crate::hole_refs::restore(s, &mut d, references, &f.edge_names, app.preferences.length_decimals); @@ -7109,6 +7114,42 @@ mod refused_ok_tests { let bore = h.app.session.execute("timeline.inspect", &json!({"feature": "Bore"})).unwrap(); assert!(bore.to_string().contains("\"depth\":\"5\""), "{bore}"); } + + /// After a parameter moves the drilled face, Edit Hole seeds the face where the hole is + /// now — not the stored raw position above or inside the body (#10689). + #[test] + fn editing_a_hole_after_its_face_moves_seeds_the_face() { + let mut h = Harness::new(); + steps( + &mut h, + &[ + json!({"call": "engine.execute", "params": {"command": "parameters.add", "params": {"name": "t", "expression": "10 mm"}}}), + json!({"call": "engine.execute", "params": {"command": "solid.box", "params": {"name": "Base", "body_name": "Base", "length": 40, "width": 30, "height": "t"}}}), + json!({"call": "engine.execute", "params": {"command": "solid.hole", "params": {"name": "Hole1", "position": [30, 15, 10], "diameter": 5, "depth": 4}}}), + json!({"call": "engine.execute", "params": {"command": "parameters.change", "params": {"name": "t", "expression": "8 mm"}}}), + json!({"call": "ui.editFeature", "params": {"feature": "Hole1"}}), + ], + ); + assert!(h.app.dialog.as_ref().is_some_and(|d| d.editing.is_some())); + let face = h.app.dialog.as_ref().and_then(|d| d.inputs.first()).and_then(|i| i.items.first()); + let Some(Sel::Face { point, body, .. }) = face else { + panic!("Edit Hole seeds a face pick, got {face:?}"); + }; + assert!(!body.is_empty(), "the face has a body name"); + assert!((point.z - 8.0).abs() < 1e-3, "seeded on the face at z=8, got {point:?}"); + h.frames(2); + assert_eq!(shown(&mut h), None, "no off-face refusal"); + if let Some(Kind::Hole { diameter, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) { + *diameter = "6 mm".into(); + } + h.frames(2); + assert_eq!(shown(&mut h), None); + steps(&mut h, &[json!({"key": "Enter"})]); + assert!(h.app.dialog.is_none()); + let vol = h.app.session.execute("inspect.measure", &json!({})).unwrap(); + let volume = vol["total"]["volume_mm3"].as_f64().expect("volume"); + assert!((volume - 9486.90).abs() < 0.1, "Ø6 hole on the moved face: {volume}"); + } } /// Whether two picks are the same face of the same body (wherever on it they were made).