From 326a2d25b392bb3072a097abfd34eccc4831ece1 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 27 Oct 2026 11:43:54 +0100 Subject: [PATCH 01/38] Placement handles: a Spec with places, the dialog kept in the app (#6818) A tool's handles stand at one place (a Rest) or at one per item of its first input (a marker on each): `Spec::frame` becomes `places`, each with a key, and `move_to` and a new optional `click` name the place by it. Every tool gates itself through `serves(app, d)`, so a tool can keep its own preference instead of the shared one. `show` no longer takes the dialog out of the app: the pointer is picked under with the dialog open, so a drag snaps as a click does, and the dialog is taken out only around a change. `handle_move` takes those hits instead of picking itself. `motion::grab` measures the gap from where the button went down, not from the pointer when the drag starts: a handle that also takes clicks only knows it is dragged once the pointer has moved a few points, and measured there the gap put every drag one step behind the pointer. Rest, Boss and Snap Fit adapted; no change in what they do. Co-Authored-By: Claude Fable 5.1 --- crates/ui-egui/src/canvas.rs | 2 +- crates/ui-egui/src/dialogs_plastic.rs | 11 +- crates/ui-egui/src/motion.rs | 10 +- crates/ui-egui/src/place_gizmo.rs | 184 ++++++++++++++------- crates/ui-egui/src/place_gizmo/boss.rs | 8 +- crates/ui-egui/src/place_gizmo/rest.rs | 8 +- crates/ui-egui/src/place_gizmo/snap_fit.rs | 8 +- 7 files changed, 150 insertions(+), 81 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 518cc18ef57..2bbfa73bd50 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -430,8 +430,8 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj { draw(app, ui, painter, proj, &mut d, base, bs, dir); } - crate::place_gizmo::show(app, ui, painter, proj, &mut d); app.dialog = Some(d); + crate::place_gizmo::show(app, ui, painter, proj); // A Single hole's handles, over the depth arrow's stem: a press on a hole moves it. crate::hole_place::show(app, ui, painter, proj); } diff --git a/crates/ui-egui/src/dialogs_plastic.rs b/crates/ui-egui/src/dialogs_plastic.rs index 5baa8438fe7..4a739ad90cd 100644 --- a/crates/ui-egui/src/dialogs_plastic.rs +++ b/crates/ui-egui/src/dialogs_plastic.rs @@ -447,15 +447,14 @@ pub(crate) fn handle_frame(app: &SolveApp, d: &crate::dialogs::Dialog) -> Option } /// The placement handles' move for a feature placed through its first input: re-place it where a -/// click at `pos` would (snapped to a sketch point as a click is when the input takes points), with -/// the stored `direction` and in-face `along` carried onto the new face. False when nothing there -/// can take it. -pub(crate) fn handle_move(app: &SolveApp, d: &mut crate::dialogs::Dialog, proj: &crate::viewport::Proj, pos: egui::Pos2) -> bool { +/// click with `hits` (the pick under the pointer) would (snapped to a sketch point as a click is +/// when the input takes points), with the stored `direction` and in-face `along` carried onto the +/// new face. False when nothing there can take it. +pub(crate) fn handle_move(app: &SolveApp, d: &mut crate::dialogs::Dialog, hits: &[crate::viewport::Hit]) -> bool { use crate::place_gizmo::{angle_of, dir_at}; let s = &app.session; let turned = handle_frame(app, d).and_then(|(_, n)| d.extra.get("along").and_then(crate::dialogs::vec3_of).map(|a| angle_of(a, n))); - let hits = crate::viewport::pick(app, proj, pos); - let snap = d.face_snap(s, &hits); + let snap = d.face_snap(s, hits); let Some(to) = hits.iter().find_map(|h| d.candidate_on(s, h, snap.as_ref()).filter(|c| matches!(c, Sel::Face { .. }))) else { return false; }; diff --git a/crates/ui-egui/src/motion.rs b/crates/ui-egui/src/motion.rs index 0480e8e4683..7ea618a4b3e 100644 --- a/crates/ui-egui/src/motion.rs +++ b/crates/ui-egui/src/motion.rs @@ -62,12 +62,14 @@ pub fn tint(ctx: &Context, id: Id, colour: Option, from: Color32, s: f3 ctx.data(|d| d.get_temp::(id.with("colour"))).filter(|_| t > 0.01).map(|c| from.lerp_to_gamma(c, t)) } -/// The gap a press keeps for its drag: `at_press` measures it from the pointer when the drag -/// starts (none when it cannot), and every dragged frame gets it back, so what is dragged follows -/// the pointer from where it was grabbed instead of jumping onto it at the first move. +/// The gap a press keeps for its drag: `at_press` measures it from where the button went down +/// (none when it cannot), and every dragged frame gets it back, so what is dragged follows the +/// pointer from where it was grabbed instead of jumping onto it at the first move. Measured from +/// the press, not the pointer when the drag starts: a handle that also takes clicks only knows it +/// is dragged once the pointer has moved a few points. pub fn grab(ui: &Ui, id: Id, r: &Response, at_press: impl FnOnce(Pos2) -> Option) -> Option { if r.drag_started() - && let Some(p) = r.interact_pointer_pos() + && let Some(p) = ui.input(|i| i.pointer.press_origin()).or_else(|| r.interact_pointer_pos()) { match at_press(p) { Some(g) => { diff --git a/crates/ui-egui/src/place_gizmo.rs b/crates/ui-egui/src/place_gizmo.rs index 251cf75a654..cddf00521fb 100644 --- a/crates/ui-egui/src/place_gizmo.rs +++ b/crates/ui-egui/src/place_gizmo.rs @@ -17,7 +17,10 @@ //! //! The handles are behind the `placement_handles` preference (Preferences > Design > Placement), off by //! default: off, a feature is placed by its click only, as before, and its Position input takes faces -//! only. +//! only; each tool's [`Spec::serves`] says what turns its handles on. +//! +//! A tool has one place (a Rest) or one per item of its first input (a marker on each): [`Spec::places`] +//! lists them, and a drag or a click names the place by its key. mod boss; mod look; @@ -39,29 +42,55 @@ pub(crate) use crate::dialogs::vec3_of; use crate::motion; pub(crate) use crate::selection::point_value as pt; use crate::theme::Tokens; -use crate::viewport::Proj; +use crate::viewport::{Hit, Proj}; /// One tool's use of the handles. pub(crate) struct Spec { - /// Handle names (`:position`, `:rotate`) and widget ids. + /// Handle names (`:position`, `:rotate`; `:` with `many`) and widget ids. pub name: &'static str, - /// Is this dialog one of the tool's? - pub serves: fn(&Dialog) -> bool, + /// Is this dialog one of the tool's, with the tool's handles turned on? + pub serves: fn(&SolveApp, &Dialog) -> bool, /// The tool's commands whose face place also snaps to sketch points on the face while the /// handles are on (the place input then takes points, as a Single hole's does). pub snap_commands: &'static [&'static str], /// The move marker's tooltip. pub move_tip: &'static str, - /// The place and the direction the feature grows out of its face. - pub frame: fn(&SolveApp, &Dialog) -> Option<(Vec3, Vec3)>, - /// Re-place the feature where a click at the pointer would put it; false when nothing there - /// can take it. - pub move_to: fn(&SolveApp, &mut Dialog, &Proj, Pos2) -> bool, + /// A marker on each of the tool's places, named `:` by their order, with no ring. + /// Off: one place, `:position`, and the ring if any. + pub many: bool, + /// The places the handles stand at. + pub places: fn(&SolveApp, &Dialog) -> Vec, + /// Re-place the feature at `key` where a click with these hits (the pick under the pointer, + /// taken while the dialog is open, so it snaps as a click does) would put it; false when + /// nothing there can take it. + pub move_to: fn(&SolveApp, &mut Dialog, &[Hit], usize) -> bool, + /// What a click (a press without a drag) on the marker at `key` does. `None`: nothing. + pub click: Option, /// The footprint outlined while dragging, in world points (empty: no outline). pub footprint: fn(&SolveApp, &Dialog, Vec3, Vec3) -> Vec, pub turn: Option, } +/// One place a tool's handles stand at. +pub(crate) struct Place { + /// Which of the tool's places: the item's index in the first input for a tool with `many`, + /// 0 otherwise. + pub key: usize, + /// The place and the direction the feature grows out of its face. + pub base: Vec3, + pub n: Vec3, +} + +/// A one-place tool's places from its frame: one, or none. +pub(crate) fn one(frame: Option<(Vec3, Vec3)>) -> Vec { + frame.map(|(base, n)| Place { key: 0, base, n }).into_iter().collect() +} + +/// Are the shared handles on (Preferences > Design > Placement handles)? +pub(crate) fn on(app: &SolveApp) -> bool { + app.preferences.placement_handles +} + /// A ring whose grip turns the feature about its face normal. pub(crate) struct Turn { pub tip: &'static str, @@ -102,12 +131,9 @@ pub(crate) fn drawn_at(p: Pos2) -> bool { DRAWN.with(|h| h.borrow().iter().any(|c| c.distance(p) <= REACH)) } -/// The tool whose dialog this is, if it has handles. +/// The tool whose dialog this is, if it has handles and they are on. fn spec(app: &SolveApp, d: &Dialog) -> Option<&'static Spec> { - if !app.preferences.placement_handles { - return None; - } - TOOLS.iter().copied().find(|s| (s.serves)(d)) + TOOLS.iter().copied().find(|s| (s.serves)(app, d)) } /// How much of the screen around the base the dialog's drag arrow leaves to the move marker @@ -234,64 +260,97 @@ pub(crate) fn marker(ui: &egui::Ui, painter: &egui::Painter, id: egui::Id, c: Po crosshair(painter, c, &style, &Tokens::get()); } -/// Draw the handles and take their drags (after the dialog's own arrow, so the marker wins -/// the pointer near the base). -pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj, d: &mut Dialog) { +/// The dialog taken out of `app` for a change (a drag's move, a click, a turn), and put back. +fn with_dialog(app: &mut SolveApp, f: impl FnOnce(&SolveApp, &mut Dialog)) { + if let Some(mut d) = app.dialog.take() { + f(app, &mut d); + app.dialog = Some(d); + } +} + +/// Draw the handles of the open dialog and take their drags (after the dialog's own arrow, so the +/// marker wins the pointer near the base). The dialog stays in `app` while the pointer is picked +/// under, so a drag snaps as a click does. +pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj) { DRAWN.with(|h| h.borrow_mut().clear()); RING_ABOUT.with(|c| c.set(None)); - let Some(sp) = spec(app, d) else { return }; - let Some((base, _)) = (sp.frame)(app, d) else { return }; - let Some(bs) = proj.to_screen(base) else { return }; + let Some(sp) = app.dialog.as_ref().and_then(|d| spec(app, d)) else { return }; + let places = |app: &SolveApp| app.dialog.as_ref().map(|d| (sp.places)(app, d)).unwrap_or_default(); let t = Tokens::get(); let area = |c: Pos2| egui::Rect::from_center_size(c, vec2(2.0 * REACH, 2.0 * REACH)); let id = |what: &str| egui::Id::unique(("sc_place", sp.name, what)); - - // The crosshair that moves the feature. The press lands where the finger is, not always the - // centre: the drag keeps that gap. - let r = ui.interact(area(bs), id("position"), egui::Sense::drag()); - let off = motion::grab(ui, id("grab"), &r, |p| Some(p - bs)); - if r.dragged() { - crate::tool_modifiers::set_manipulator_dragging(true); - if let Some(p) = r.interact_pointer_pos() { - (sp.move_to)(app, d, proj, p - off.unwrap_or_default()); + let at = |key: usize, what: &str| egui::Id::unique(("sc_place", sp.name, key, what)); + let sense = if sp.click.is_some() { egui::Sense::click_and_drag() } else { egui::Sense::drag() }; + + // The crosshairs that move the feature, one per place. The press lands where the finger is, + // not always the centre: the drag keeps that gap. + let mut markers: Vec<(usize, egui::Response)> = Vec::new(); + for pl in places(app) { + let Some(bs) = proj.to_screen(pl.base) else { continue }; + let r = ui.interact(area(bs), at(pl.key, "position"), sense); + let off = motion::grab(ui, at(pl.key, "grab"), &r, |p| Some(p - bs)); + if r.dragged() { + crate::tool_modifiers::set_manipulator_dragging(true); + if let Some(p) = r.interact_pointer_pos() { + let hits = crate::viewport::pick(app, proj, p - off.unwrap_or_default()); + with_dialog(app, |app, d| { + (sp.move_to)(app, d, &hits, pl.key); + }); + } + } else if r.clicked() + && let Some(click) = sp.click + { + with_dialog(app, |app, d| click(app, d, pl.key)); } + markers.push((pl.key, r)); } - // Read the frame again: a drag moved it this frame. - let Some((base, n)) = (sp.frame)(app, d) else { return }; - let Some(bs) = proj.to_screen(base) else { return }; - crate::scenario::publish_handle(&format!("{}:position", sp.name), bs); - DRAWN.with(|h| h.borrow_mut().push(bs)); - let (hovered, dragging) = (r.hovered(), r.dragged()); - // The tip while pointing, not while dragging: the hand is busy and the footprint says it all. - if hovered && !dragging { - r.clone().backing_on_hover_text(crate::i18n::tr_label(sp.move_tip)); - } - // The handle not in use steps back while the other one works (the ring's drag is last frame's). - let turning = ui.data(|m| m.get_temp::(id("turning"))).unwrap_or(false); + // Read the places again: a drag moved one this frame, a click may have taken one out. let ctx = ui.ctx().clone(); - let style = CrossStyle { - hot: MARKER_HOT.run(&ctx, id("hot"), hovered || dragging).t, - active: MARKER_ACTIVE.run(&ctx, id("active"), dragging).t, - alpha: motion::step_back(&ctx, id("marker_dim"), turning, DIM, DIM_S), - }; - if dragging { - let pts: Option> = (sp.footprint)(app, d, base, n).into_iter().map(|p| proj.to_screen(p)).collect(); - if let Some(pts) = pts.filter(|p| p.len() >= 3) { - footprint(painter, &pts, &t); + // The marker steps back while the ring works (the ring's drag is last frame's). + let turning = ui.data(|m| m.get_temp::(id("turning"))).unwrap_or(false); + let mut first: Option<(Place, Pos2, bool)> = None; + for (n, pl) in places(app).into_iter().enumerate() { + let Some(bs) = proj.to_screen(pl.base) else { continue }; + let name = if sp.many { format!("{}:{n}", sp.name) } else { format!("{}:position", sp.name) }; + crate::scenario::publish_handle(&name, bs); + DRAWN.with(|h| h.borrow_mut().push(bs)); + let r = markers.iter().find(|(k, _)| *k == pl.key).map(|(_, r)| r); + let (hovered, dragging) = r.map_or((false, false), |r| (r.hovered(), r.dragged())); + // The tip while pointing, not while dragging: the hand is busy and the footprint says it all. + if hovered + && !dragging + && let Some(r) = r + { + r.clone().backing_on_hover_text(crate::i18n::tr_label(sp.move_tip)); + } + let style = CrossStyle { + hot: MARKER_HOT.run(&ctx, at(pl.key, "hot"), hovered || dragging).t, + active: MARKER_ACTIVE.run(&ctx, at(pl.key, "active"), dragging).t, + alpha: motion::step_back(&ctx, at(pl.key, "marker_dim"), turning, DIM, DIM_S), + }; + if dragging && let Some(d) = app.dialog.as_ref() { + let pts: Option> = (sp.footprint)(app, d, pl.base, pl.n).into_iter().map(|p| proj.to_screen(p)).collect(); + if let Some(pts) = pts.filter(|p| p.len() >= 3) { + footprint(painter, &pts, &t); + } + } + crosshair(painter, bs, &style, &t); + if hovered || dragging { + ui.ctx().set_cursor_icon(if dragging { egui::CursorIcon::Grabbing } else { egui::CursorIcon::Move }); + } + if n == 0 { + first = Some((pl, bs, dragging)); } - } - crosshair(painter, bs, &style, &t); - let moving = dragging; - if hovered || dragging { - ui.ctx().set_cursor_icon(if dragging { egui::CursorIcon::Grabbing } else { egui::CursorIcon::Move }); } - // The ring that turns it: on the face about the same centre, a fixed size on screen. + // The ring that turns a one-place feature: on the face about the same centre, a fixed size + // on screen. let Some(turn) = &sp.turn else { return }; - if (turn.reach)(app, d).is_none() { + let Some((Place { base, n, .. }, bs, moving)) = first.filter(|_| !sp.many) else { return }; + if app.dialog.as_ref().and_then(|d| (turn.reach)(app, d)).is_none() { return; } - let mut angle = (turn.angle)(app, d, n); + let Some(mut angle) = app.dialog.as_ref().map(|d| (turn.angle)(app, d, n)) else { return }; let (x, y) = axes(n); // The world radius that makes the ring RING_PX across its least foreshortened face direction // (the larger singular value of the projected x, y pair), so it keeps its size as the view @@ -320,8 +379,11 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte { crate::tool_modifiers::set_manipulator_dragging(true); if let Some(raw) = pointer_angle(p).filter(|a| a.is_finite()).map(|a| a - grab.unwrap_or(0.0)) { - angle = (turn.set)(app, d, n, raw, crate::tool_modifiers::manipulator_free()); - d.error = None; + let free = crate::tool_modifiers::manipulator_free(); + with_dialog(app, |app, d| { + angle = (turn.set)(app, d, n, raw, free); + d.error = None; + }); if let Some(g) = at(angle) { gs = g; } diff --git a/crates/ui-egui/src/place_gizmo/boss.rs b/crates/ui-egui/src/place_gizmo/boss.rs index 93563076106..cfadb433835 100644 --- a/crates/ui-egui/src/place_gizmo/boss.rs +++ b/crates/ui-egui/src/place_gizmo/boss.rs @@ -10,11 +10,13 @@ use crate::dialogs_plastic::Pl; pub(super) static SPEC: Spec = Spec { name: "boss", - serves: |d| matches!(d.kind, Kind::Plastic(Pl::Boss { .. })), + serves: |app, d| super::on(app) && matches!(d.kind, Kind::Plastic(Pl::Boss { .. })), snap_commands: &["plastic.boss"], move_tip: "Drag to move the boss across the model. It snaps to sketch points on the face.", - frame: crate::dialogs_plastic::handle_frame, - move_to: crate::dialogs_plastic::handle_move, + many: false, + places: |app, d| super::one(crate::dialogs_plastic::handle_frame(app, d)), + move_to: |app, d, hits, _| crate::dialogs_plastic::handle_move(app, d, hits), + click: None, footprint, turn: None, }; diff --git a/crates/ui-egui/src/place_gizmo/rest.rs b/crates/ui-egui/src/place_gizmo/rest.rs index 78d29cebe46..2dc84766eba 100644 --- a/crates/ui-egui/src/place_gizmo/rest.rs +++ b/crates/ui-egui/src/place_gizmo/rest.rs @@ -10,11 +10,13 @@ use crate::dialogs_plastic::Pl; pub(super) static SPEC: Spec = Spec { name: "rest", - serves: |d| matches!(d.kind, Kind::Plastic(Pl::Rest { .. })), + serves: |app, d| super::on(app) && matches!(d.kind, Kind::Plastic(Pl::Rest { .. })), snap_commands: &["plastic.rest"], move_tip: "Drag to move the rest across the model. It snaps to sketch points on the face.", - frame: crate::dialogs_plastic::handle_frame, - move_to: crate::dialogs_plastic::handle_move, + many: false, + places: |app, d| super::one(crate::dialogs_plastic::handle_frame(app, d)), + move_to: |app, d, hits, _| crate::dialogs_plastic::handle_move(app, d, hits), + click: None, footprint, turn: Some(Turn { tip: "Drag to turn the rest in 5° steps. Hold Alt or Ctrl to turn it freely.", reach, angle, set }), }; diff --git a/crates/ui-egui/src/place_gizmo/snap_fit.rs b/crates/ui-egui/src/place_gizmo/snap_fit.rs index 5a37e19807d..e5adc6488cd 100644 --- a/crates/ui-egui/src/place_gizmo/snap_fit.rs +++ b/crates/ui-egui/src/place_gizmo/snap_fit.rs @@ -11,11 +11,13 @@ use crate::dialogs_plastic::{Pl, hook_dirs}; pub(super) static SPEC: Spec = Spec { name: "snap_fit", - serves: |d| matches!(d.kind, Kind::Plastic(Pl::SnapFit { .. })), + serves: |app, d| super::on(app) && matches!(d.kind, Kind::Plastic(Pl::SnapFit { .. })), snap_commands: &["plastic.snap_fit"], move_tip: "Drag to move the snap fit across the model. It snaps to sketch points on the face.", - frame: crate::dialogs_plastic::handle_frame, - move_to: crate::dialogs_plastic::handle_move, + many: false, + places: |app, d| super::one(crate::dialogs_plastic::handle_frame(app, d)), + move_to: |app, d, hits, _| crate::dialogs_plastic::handle_move(app, d, hits), + click: None, footprint, turn: Some(Turn { tip: "Drag to point the catch in another direction.", reach, angle, set }), }; From 9550f2a92f9f1d9d723d25921e31eb1616e564e6 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 27 Oct 2026 11:43:54 +0100 Subject: [PATCH 02/38] Hole: the markers are a Spec under place_gizmo (#6818) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Step 2 of #6818. A Single hole's handle is `place_gizmo/hole.rs`: a marker on each placed hole, drawn and dragged by the shared mechanics, so a hole gets what a Rest has: the marker's press area, the grab offset that keeps the hole where it was taken instead of jumping under the pointer, the footprint of its mouth while it drags, the depth arrow starting past the marker and the value box keeping off it, and the manipulator state while it drags. A click on a marker still takes the hole out; the markers stay behind Create Hole › Move holes by clicking or dragging, not the shared Placement handles setting, and holes on sketch points (Multiple) have none. `hole_place.rs` keeps what is the hole's: its face and rim snaps, the moves of its face places and the pick that moves a hole. Its handle loop and `place_gizmo::marker` go. Tests: a press off the centre keeps its gap, one marker per hole and a drag moves only its hole, a click within the marker's reach takes the hole out, the arrow's clearance follows the setting. The 18 hole placement tests pass unchanged (`hole:` names, snapping, preferences). Co-Authored-By: Claude Fable 5.1 --- crates/ui-egui/src/canvas.rs | 5 +- crates/ui-egui/src/hole_place.rs | 94 ++-------------- crates/ui-egui/src/place_gizmo.rs | 34 +++--- crates/ui-egui/src/place_gizmo/hole.rs | 67 +++++++++++ crates/ui-egui/src/place_gizmo/hole_tests.rs | 112 +++++++++++++++++++ 5 files changed, 203 insertions(+), 109 deletions(-) create mode 100644 crates/ui-egui/src/place_gizmo/hole.rs create mode 100644 crates/ui-egui/src/place_gizmo/hole_tests.rs diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 2bbfa73bd50..cd2cbaa1f8c 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -431,9 +431,10 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj draw(app, ui, painter, proj, &mut d, base, bs, dir); } app.dialog = Some(d); + // The placement handles (a Single hole's among them), over the depth arrow's stem: a press + // on a marker moves the feature. crate::place_gizmo::show(app, ui, painter, proj); - // A Single hole's handles, over the depth arrow's stem: a press on a hole moves it. - crate::hole_place::show(app, ui, painter, proj); + crate::hole_place::marks(app, painter, proj); } struct MoveRotation { diff --git a/crates/ui-egui/src/hole_place.rs b/crates/ui-egui/src/hole_place.rs index f11e542cf6f..9276acf614f 100644 --- a/crates/ui-egui/src/hole_place.rs +++ b/crates/ui-egui/src/hole_place.rs @@ -10,17 +10,18 @@ //! //! Create Hole › Move holes by clicking or dragging (`hole_moves`): every placed hole has a handle at its //! centre that drags it across the model (snapping as a pick would) and takes it out when -//! clicked, and a pick elsewhere on a face that already has a hole moves the hole there. +//! clicked, and a pick elsewhere on a face that already has a hole moves the hole there. The handle +//! is the shared placement marker (`place_gizmo`, one per hole through `place_gizmo/hole.rs`, #6818); +//! this file keeps what is the hole's: its snaps, and the moves of its face places. //! //! Create Hole › Several holes on one face (`hole_several`): a pick elsewhere on a face that already //! has a hole adds another hole there (rather than moving it), and a pick on a hole takes it out. -use crate::ui_kit::BackingTooltipExt as _; use solidcraft_engine::geom::prelude::*; use std::cell::RefCell; use std::sync::Arc; -use egui::{Pos2, vec2}; +use egui::Pos2; use solidcore_record::Vec3; use solidcraft_engine::Sel; use solidcraft_engine::Session; @@ -38,8 +39,6 @@ use crate::viewport::{Hit, Proj}; pub(crate) const POINT_REACH: f32 = 10.0; /// How near a pick must come to a round edge to take its centre. pub(crate) const RIM_REACH: f32 = 6.0; -/// How far (screen points) from a hole's centre a press takes its handle. -const HANDLE_REACH: f32 = 9.0; /// The most triangles of one face looked through for its snaps. const MAX_TRIANGLES: usize = 1 << 18; @@ -207,7 +206,7 @@ fn snap_under(app: &SolveApp, body: &str, index: usize, point: Vec3) -> (Arc Vec<(usize, Vec3)> { +pub(crate) fn places(s: &Session, d: &Dialog) -> Vec<(usize, Vec3)> { let Some(inp) = d.inputs.first() else { return Vec::new() }; let mut taken: Vec = Vec::new(); let mut out = Vec::new(); @@ -349,86 +348,9 @@ pub(crate) fn pick_several(app: &SolveApp, d: &mut Dialog, sel: &Sel) -> bool { true } -/// The hovered face's snap marks, and the face places' handles when holes move by dragging. -/// Called after the canvas draws the dialog's arrows, so a press on a hole's centre takes the -/// hole, not the depth arrow. -pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj) { - let Some(d) = app.dialog.as_ref() else { return }; - if !matches!(&d.kind, Kind::Hole { opts, .. } if !opts.multiple) || app.applying.is_some() { - return; - } - marks(app, painter, proj); - if !app.preferences.hole_moves { - return; - } - let several = several(app, d); - let places = if several { - several_list(&app.session, d) - .into_iter() - .enumerate() - .filter_map(|(n, x)| if let Sel::Face { point, .. } = x { Some((n, point)) } else { None }) - .collect() - } else { - places(&app.session, d) - }; - let mut moved: Option<(usize, Sel)> = None; - let mut removed: Option = None; - for (n, (i, at)) in places.into_iter().enumerate() { - let Some(mut c) = proj.to_screen(at) else { continue }; - let id = egui::Id::unique(("sc_hole_place", i)); - let r = ui.interact(egui::Rect::from_center_size(c, vec2(2.0 * HANDLE_REACH, 2.0 * HANDLE_REACH)), id, egui::Sense::click_and_drag()); - // A click on the hole takes it out, as a pick of a picked face does. - if r.clicked() { - removed = Some(i); - } - if r.dragged() - && let Some(p) = r.interact_pointer_pos() - { - // Where a click under the pointer would place a hole: on a face, snapped. - let hits = crate::viewport::pick(app, proj, p); - if let Some((_, to @ Sel::Face { .. })) = crate::viewport::candidate(app, &hits) { - if let Sel::Face { point, .. } = &to - && let Some(q) = proj.to_screen(*point) - { - c = q; - } - moved = Some((i, to)); - } - } - let hot = r.hovered() || r.dragged(); - if hot { - ui.ctx().set_cursor_icon(if r.dragged() { egui::CursorIcon::Grabbing } else { egui::CursorIcon::Grab }); - } - crate::place_gizmo::marker(ui, painter, id, c, r.hovered(), r.dragged()); - crate::scenario::publish_handle(&format!("hole:{n}"), c); - if !r.dragged() { - r.backing_on_hover_text(crate::i18n::tr_label("Drag to move the hole; click to remove it")); - } - } - // With several holes on a face, `i` counts the holes rather than the input's items. - if let Some((i, to)) = moved - && let Some(d) = app.dialog.as_mut() - { - if several { - several_change(&app.session, d, i, Some(to)); - } else { - move_place(d, &app.session, i, to); - } - } - if let Some(i) = removed - && let Some(d) = app.dialog.as_mut() - { - if several { - several_change(&app.session, d, i, None); - } else { - remove_place(d, &app.session, i); - } - } -} - /// Take out the hole placed by item `i` of the face input (with the other half of a round face /// split at its seam). -fn remove_place(d: &mut Dialog, s: &Session, i: usize) { +pub(crate) fn remove_place(d: &mut Dialog, s: &Session, i: usize) { let Some(inp) = d.inputs.first_mut() else { return }; let Some(old) = inp.items.get(i).cloned() else { return }; let own = crate::viewport::grouped_selection(s, &old); @@ -437,8 +359,8 @@ fn remove_place(d: &mut Dialog, s: &Session, i: usize) { } /// The snap points of the face under the cursor while a Single hole is placed, and the one a -/// pick there takes, named. -fn marks(app: &SolveApp, painter: &egui::Painter, proj: &Proj) { +/// pick there takes, named. Called by the canvas after the placement handles. +pub(crate) fn marks(app: &SolveApp, painter: &egui::Painter, proj: &Proj) { if !snapping(app) { return; } diff --git a/crates/ui-egui/src/place_gizmo.rs b/crates/ui-egui/src/place_gizmo.rs index cddf00521fb..b1002b0251b 100644 --- a/crates/ui-egui/src/place_gizmo.rs +++ b/crates/ui-egui/src/place_gizmo.rs @@ -17,12 +17,14 @@ //! //! The handles are behind the `placement_handles` preference (Preferences > Design > Placement), off by //! default: off, a feature is placed by its click only, as before, and its Position input takes faces -//! only; each tool's [`Spec::serves`] says what turns its handles on. +//! only. A Single hole's markers (#6818) stay behind Create Hole › Move holes by clicking or dragging +//! instead, as the hole's own handle was; each tool's [`Spec::serves`] says what turns it on. //! -//! A tool has one place (a Rest) or one per item of its first input (a marker on each): [`Spec::places`] -//! lists them, and a drag or a click names the place by its key. +//! A tool has one place (a Rest) or one per item of its first input (a Single hole, a marker on each +//! hole placed): [`Spec::places`] lists them, and a drag or a click names the place by its key. mod boss; +mod hole; mod look; mod rest; mod snap_fit; @@ -55,8 +57,8 @@ pub(crate) struct Spec { pub snap_commands: &'static [&'static str], /// The move marker's tooltip. pub move_tip: &'static str, - /// A marker on each of the tool's places, named `:` by their order, with no ring. - /// Off: one place, `:position`, and the ring if any. + /// A marker on each of the tool's places, named `:` by their order, with no ring + /// (a Single hole's). Off: one place, `:position`, and the ring if any. pub many: bool, /// The places the handles stand at. pub places: fn(&SolveApp, &Dialog) -> Vec, @@ -64,7 +66,8 @@ pub(crate) struct Spec { /// taken while the dialog is open, so it snaps as a click does) would put it; false when /// nothing there can take it. pub move_to: fn(&SolveApp, &mut Dialog, &[Hit], usize) -> bool, - /// What a click (a press without a drag) on the marker at `key` does. `None`: nothing. + /// What a click (a press without a drag) on the marker at `key` does: a Single hole is taken + /// out. `None`: a click on the marker does nothing. pub click: Option, /// The footprint outlined while dragging, in world points (empty: no outline). pub footprint: fn(&SolveApp, &Dialog, Vec3, Vec3) -> Vec, @@ -86,7 +89,8 @@ pub(crate) fn one(frame: Option<(Vec3, Vec3)>) -> Vec { frame.map(|(base, n)| Place { key: 0, base, n }).into_iter().collect() } -/// Are the shared handles on (Preferences > Design > Placement handles)? +/// Are the shared handles on (Preferences > Design > Placement handles)? The gate of every +/// tool but the hole, whose markers keep the hole's own setting. pub(crate) fn on(app: &SolveApp) -> bool { app.preferences.placement_handles } @@ -108,6 +112,7 @@ pub(crate) struct Turn { #[rustfmt::skip] static TOOLS: &[&Spec] = &[ &boss::SPEC, + &hole::SPEC, &rest::SPEC, &snap_fit::SPEC, ]; @@ -247,19 +252,6 @@ fn on_plane(proj: &Proj, pos: Pos2, base: Vec3, n: Vec3) -> Option { crate::gizmo::on_plane(proj, pos, base, n).filter(|p| p.is_finite()) } -/// The move marker alone, for a handle another module owns (a Single hole's, #6818): drawn as -/// [`show`] draws its own, from the handle's hovered and dragged state, so a hole and a Rest on -/// the same model show one language for the same action. `id` is the handle's; the motions keep -/// their state under it. Nothing to step back for, so it is never dimmed. -pub(crate) fn marker(ui: &egui::Ui, painter: &egui::Painter, id: egui::Id, c: Pos2, hovered: bool, dragging: bool) { - let style = CrossStyle { - hot: MARKER_HOT.run(ui.ctx(), id.with("hot"), hovered || dragging).t, - active: MARKER_ACTIVE.run(ui.ctx(), id.with("active"), dragging).t, - alpha: 1.0, - }; - crosshair(painter, c, &style, &Tokens::get()); -} - /// The dialog taken out of `app` for a change (a drag's move, a click, a turn), and put back. fn with_dialog(app: &mut SolveApp, f: impl FnOnce(&SolveApp, &mut Dialog)) { if let Some(mut d) = app.dialog.take() { @@ -270,7 +262,7 @@ fn with_dialog(app: &mut SolveApp, f: impl FnOnce(&SolveApp, &mut Dialog)) { /// Draw the handles of the open dialog and take their drags (after the dialog's own arrow, so the /// marker wins the pointer near the base). The dialog stays in `app` while the pointer is picked -/// under, so a drag snaps as a click does. +/// under, so a drag snaps as a click does (its input's points, the hole's face and rim snaps). pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj) { DRAWN.with(|h| h.borrow_mut().clear()); RING_ABOUT.with(|c| c.set(None)); diff --git a/crates/ui-egui/src/place_gizmo/hole.rs b/crates/ui-egui/src/place_gizmo/hole.rs new file mode 100644 index 00000000000..477adced8ed --- /dev/null +++ b/crates/ui-egui/src/place_gizmo/hole.rs @@ -0,0 +1,67 @@ +//! Hole: a marker on each Single hole placed on a face drags it across the model, snapping as a +//! pick does (sketch points on the face, the face's middle and its round edges' centres when Create +//! Hole › Snap to face and edge centres is on), and a click on a marker takes the hole out, as the +//! hole's own handle from #2912 did. Behind Create Hole › Move holes by clicking or dragging, not the +//! shared Placement handles setting. No ring: a hole has nothing to turn. Holes on sketch points +//! (Multiple) have no markers: their place is the point's. + +use solidcore_record::Vec3; +use solidcraft_engine::Sel; +use solidcraft_engine::geom::prelude::*; + +use super::{Place, Spec, circle, len}; +use crate::SolveApp; +use crate::dialogs::{Dialog, Kind}; +use crate::viewport::Hit; + +pub(super) static SPEC: Spec = Spec { + name: "hole", + serves: |app, d| app.preferences.hole_moves && matches!(&d.kind, Kind::Hole { opts, .. } if !opts.multiple), + snap_commands: &[], + move_tip: "Drag to move the hole; click to remove it", + many: true, + places, + move_to, + click: Some(|app, d, key| crate::hole_place::remove_place(d, &app.session, key)), + footprint, + turn: None, +}; + +/// The holes placed so far, each at its face place, growing into the face. +fn places(app: &SolveApp, d: &Dialog) -> Vec { + let s = &app.session; + crate::hole_place::places(s, d) + .into_iter() + .filter_map(|(key, base)| { + let Some(Sel::Face { body, index, .. }) = d.inputs.first()?.items.get(key) else { return None }; + let (_, n) = crate::dialogs::planar_face(s, body, *index)?; + Some(Place { key, base, n }) + }) + .collect() +} + +/// The hole at `key` moved to the face place a click with `hits` would take (snapped as the +/// pick is), unless that face already has another hole. +fn move_to(app: &SolveApp, d: &mut Dialog, hits: &[Hit], key: usize) -> bool { + let s = &app.session; + let snap = d.face_snap(s, hits); + let Some(to) = hits.iter().find_map(|h| d.candidate_on(s, h, snap.as_ref()).filter(|c| matches!(c, Sel::Face { .. }))) else { + return false; + }; + crate::hole_place::move_place(d, s, key, to) +} + +/// The hole's mouth on the face: the counterbore's or countersink's diameter, else the bore's. +fn footprint(app: &SolveApp, d: &Dialog, base: Vec3, n: Vec3) -> Vec { + let Kind::Hole { diameter, kind, cb_diameter, cs_diameter, .. } = &d.kind else { return Vec::new() }; + let mouth = match kind { + 1 => cb_diameter, + 2 => cs_diameter, + _ => diameter, + }; + circle(base, n, len(app, mouth) * 0.5) +} + +#[cfg(test)] +#[path = "hole_tests.rs"] +mod tests; diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs new file mode 100644 index 00000000000..6ba61b721b1 --- /dev/null +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -0,0 +1,112 @@ +//! The hole markers (#6818): one per placed hole, each the shared marker with its press area and +//! its grab offset; a click on one takes the hole out; the depth arrow stands clear of them. + +use serde_json::json; +use solidcore_record::Vec3; +use solidcraft_engine::Sel; +use solidcraft_engine::geom::prelude::*; + +use crate::scenario::{Harness, handle_at}; + +/// A 40 × 30 × 20 block and a second one beside it, seen from the top, with holes moving (and +/// not snapping, so a place is exactly where it is let go). +fn blocks() -> Harness { + let mut h = Harness::new(); + h.app.set_origin_shown(false); + crate::prefs::set(&mut h.app, &json!({"hole_moves": true})).unwrap(); + h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap(); + h.app.run("solid.box", json!({"length": 20, "width": 30, "height": 20, "corner": [50, 0, 0], "body_name": "Other"})).unwrap(); + h.step(&json!({"call": "ui.view", "params": {"view": "top"}})).unwrap(); + h.settle(); + h +} + +/// Where a world point is on screen. +fn screen(h: &mut Harness, p: Vec3) -> [f64; 2] { + h.at(&json!({"world": [p.x, p.y, p.z]})).unwrap() +} + +/// The face places the open dialog holds. +fn places(h: &Harness) -> Vec { + let d = h.app.dialog.as_ref().expect("a dialog is open"); + d.inputs[0] + .items + .iter() + .map(|x| match x { + Sel::Face { point, .. } => *point, + other => panic!("a face place, not {other:?}"), + }) + .collect() +} + +#[test] +fn a_press_off_the_centre_keeps_its_gap_and_the_hole_lands_short_of_the_pointer() { + let mut h = blocks(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let start = Vec3::new(10.0, 10.0, 20.0); + let at = screen(&mut h, start); + h.step(&json!({"click": at})).unwrap(); + h.frames(2); + let c = handle_at("hole:0").expect("the placed hole has a marker"); + // Grabbed 6 pt right and 4 pt below the centre (inside the shared marker's reach, outside the + // old handle's 9 pt), and let go with the pointer the same gap from `to`: the hole lands on + // `to`, not under the pointer. + let to = Vec3::new(30.0, 20.0, 20.0); + let ts = screen(&mut h, to); + h.step(&json!({"drag": [[f64::from(c.x) + 6.0, f64::from(c.y) + 4.0], [ts[0] + 6.0, ts[1] + 4.0]], "steps": 12})).unwrap(); + h.settle(); + let p = places(&h); + assert!(matches!(p.as_slice(), [p] if p.dist(to) < 0.3), "kept the gap: {p:?}"); +} + +#[test] +fn each_placed_hole_has_its_own_marker_and_a_drag_moves_only_its_hole() { + let mut h = blocks(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let first = Vec3::new(10.0, 10.0, 20.0); + let second = Vec3::new(60.0, 15.0, 20.0); + let at = screen(&mut h, first); + h.step(&json!({"click": at})).unwrap(); + let at = screen(&mut h, second); + h.step(&json!({"click": at})).unwrap(); + h.frames(2); + assert_eq!(places(&h).len(), 2, "{:?}", places(&h)); + let (Some(a), Some(b)) = (handle_at("hole:0"), handle_at("hole:1")) else { panic!("two markers") }; + assert!(a.distance(b) > 50.0, "one marker per hole: {a:?} {b:?}"); + assert!(handle_at("hole:2").is_none()); + // The second hole dragged across its block: the first stays. + let to = Vec3::new(55.0, 25.0, 20.0); + let ts = screen(&mut h, to); + h.step(&json!({"drag": [{"handle": "hole:1"}, ts], "steps": 12})).unwrap(); + h.settle(); + let p = places(&h); + assert!(matches!(p.as_slice(), [a, b] if a.dist(first) < 1e-4 && b.dist(to) < 0.3), "{p:?}"); +} + +#[test] +fn a_click_within_the_markers_reach_takes_the_hole_out() { + let mut h = blocks(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let at = screen(&mut h, Vec3::new(10.0, 10.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + h.frames(2); + let c = handle_at("hole:0").expect("a marker"); + // 14 pt from the centre: on the marker's arm, past the old handle's 9 pt. + h.step(&json!({"click": [f64::from(c.x) + 14.0, f64::from(c.y)]})).unwrap(); + h.frames(2); + assert!(places(&h).is_empty(), "{:?}", places(&h)); + assert!(handle_at("hole:0").is_none(), "no hole, no marker"); +} + +#[test] +fn the_depth_arrow_stands_clear_of_the_marker_only_while_holes_move() { + let mut h = blocks(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let at = screen(&mut h, Vec3::new(10.0, 10.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + h.frames(2); + let d = h.app.dialog.clone().expect("a dialog"); + assert!(crate::place_gizmo::arrow_clearance(&h.app, &d) > 0.0, "the arrow starts past the marker"); + crate::prefs::set(&mut h.app, &json!({"hole_moves": false})).unwrap(); + assert_eq!(crate::place_gizmo::arrow_clearance(&h.app, &d), 0.0, "no marker, no clearance"); +} From d59a2b74e03810bf6af17aefb8b6238ce3ec58ce Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 27 Oct 2026 12:16:40 +0100 Subject: [PATCH 03/38] Placement handles, Hole: fixes from the review (#6818) A hole being edited whose face no longer resolves keeps its marker: `hole::places` falls back to the `direction` the edit restored, as a Rest's frame does (before, the marker vanished with the face). A marker drag moves the hole only while the face input is the active one: the hits were picked by the active input's rules. `place_gizmo::face_pick` is the one face pick for Rest, Boss, Snap Fit and the hole. After a click took a place out, the markers' states are left alone for that frame instead of going to the place that moved into the index. `Spec` says where the dialog is while each callback runs. Tests: the hole's markers follow Move holes by clicking or dragging, not Placement handles; a hole whose face is gone keeps its marker through `direction`, and loses it with neither. Co-Authored-By: Claude Fable 5.1 --- crates/ui-egui/src/dialogs_plastic.rs | 5 +-- crates/ui-egui/src/place_gizmo.rs | 25 ++++++++++--- crates/ui-egui/src/place_gizmo/hole.rs | 22 +++++++----- crates/ui-egui/src/place_gizmo/hole_tests.rs | 38 ++++++++++++++++++++ 4 files changed, 74 insertions(+), 16 deletions(-) diff --git a/crates/ui-egui/src/dialogs_plastic.rs b/crates/ui-egui/src/dialogs_plastic.rs index 4a739ad90cd..de96cd741c2 100644 --- a/crates/ui-egui/src/dialogs_plastic.rs +++ b/crates/ui-egui/src/dialogs_plastic.rs @@ -454,10 +454,7 @@ pub(crate) fn handle_move(app: &SolveApp, d: &mut crate::dialogs::Dialog, hits: use crate::place_gizmo::{angle_of, dir_at}; let s = &app.session; let turned = handle_frame(app, d).and_then(|(_, n)| d.extra.get("along").and_then(crate::dialogs::vec3_of).map(|a| angle_of(a, n))); - let snap = d.face_snap(s, hits); - let Some(to) = hits.iter().find_map(|h| d.candidate_on(s, h, snap.as_ref()).filter(|c| matches!(c, Sel::Face { .. }))) else { - return false; - }; + let Some(to) = crate::place_gizmo::face_pick(d, s, hits) else { return false }; if let Sel::Face { body, index, .. } = &to && let Some((_, nn)) = crate::dialogs::planar_face(s, body, *index) { diff --git a/crates/ui-egui/src/place_gizmo.rs b/crates/ui-egui/src/place_gizmo.rs index b1002b0251b..a5bc9cbd762 100644 --- a/crates/ui-egui/src/place_gizmo.rs +++ b/crates/ui-egui/src/place_gizmo.rs @@ -37,6 +37,7 @@ use look::{ use solidcore_record::Vec3; use solidcraft_engine::doc::expr::Kind as ValueKind; use solidcraft_engine::geom::prelude::*; +use solidcraft_engine::{Sel, Session}; use crate::SolveApp; use crate::dialogs::Dialog; @@ -47,6 +48,10 @@ use crate::theme::Tokens; use crate::viewport::{Hit, Proj}; /// One tool's use of the handles. +/// +/// While `places`, `footprint` and the turn's `reach` and `angle` run, the dialog is in the app; +/// inside `move_to`, `click` and [`Turn::set`] it is taken out (`app.dialog` is `None`): read the +/// session and `d` there, never `app.dialog`. pub(crate) struct Spec { /// Handle names (`:position`, `:rotate`; `:` with `many`) and widget ids. pub name: &'static str, @@ -58,7 +63,8 @@ pub(crate) struct Spec { /// The move marker's tooltip. pub move_tip: &'static str, /// A marker on each of the tool's places, named `:` by their order, with no ring - /// (a Single hole's). Off: one place, `:position`, and the ring if any. + /// (a Single hole's; `turn` is then ignored). Off: one place, `:position`, and the ring + /// if any. pub many: bool, /// The places the handles stand at. pub places: fn(&SolveApp, &Dialog) -> Vec, @@ -95,6 +101,13 @@ pub(crate) fn on(app: &SolveApp) -> bool { app.preferences.placement_handles } +/// The face place a click with `hits` would add to the dialog's first input: snapped to a sketch +/// point as a click is when the input takes points; none when nothing there is a face. +pub(crate) fn face_pick(d: &Dialog, s: &Session, hits: &[Hit]) -> Option { + let snap = d.face_snap(s, hits); + hits.iter().find_map(|h| d.candidate_on(s, h, snap.as_ref()).filter(|c| matches!(c, Sel::Face { .. }))) +} + /// A ring whose grip turns the feature about its face normal. pub(crate) struct Turn { pub tip: &'static str, @@ -296,17 +309,21 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte } markers.push((pl.key, r)); } - // Read the places again: a drag moved one this frame, a click may have taken one out. + // Read the places again: a drag moved one this frame, a click may have taken one out. A key + // is an index, not an identity: with a place gone, the ones after it have moved down, so the + // markers' states are left alone for this frame rather than given to the wrong place. + let now = places(app); + let settled = now.len() == markers.len(); let ctx = ui.ctx().clone(); // The marker steps back while the ring works (the ring's drag is last frame's). let turning = ui.data(|m| m.get_temp::(id("turning"))).unwrap_or(false); let mut first: Option<(Place, Pos2, bool)> = None; - for (n, pl) in places(app).into_iter().enumerate() { + for (n, pl) in now.into_iter().enumerate() { let Some(bs) = proj.to_screen(pl.base) else { continue }; let name = if sp.many { format!("{}:{n}", sp.name) } else { format!("{}:position", sp.name) }; crate::scenario::publish_handle(&name, bs); DRAWN.with(|h| h.borrow_mut().push(bs)); - let r = markers.iter().find(|(k, _)| *k == pl.key).map(|(_, r)| r); + let r = markers.iter().filter(|_| settled).find(|(k, _)| *k == pl.key).map(|(_, r)| r); let (hovered, dragging) = r.map_or((false, false), |r| (r.hovered(), r.dragged())); // The tip while pointing, not while dragging: the hand is busy and the footprint says it all. if hovered diff --git a/crates/ui-egui/src/place_gizmo/hole.rs b/crates/ui-egui/src/place_gizmo/hole.rs index 477adced8ed..1aa41e175e1 100644 --- a/crates/ui-egui/src/place_gizmo/hole.rs +++ b/crates/ui-egui/src/place_gizmo/hole.rs @@ -9,7 +9,7 @@ use solidcore_record::Vec3; use solidcraft_engine::Sel; use solidcraft_engine::geom::prelude::*; -use super::{Place, Spec, circle, len}; +use super::{Place, Spec, circle, face_pick, len, vec3_of}; use crate::SolveApp; use crate::dialogs::{Dialog, Kind}; use crate::viewport::Hit; @@ -27,27 +27,33 @@ pub(super) static SPEC: Spec = Spec { turn: None, }; -/// The holes placed so far, each at its face place, growing into the face. +/// The holes placed so far, each at its face place with the face's outward normal. A hole being +/// edited whose face is gone keeps its place and the `direction` the edit restored, as a Rest's +/// frame does, so it still has a marker. fn places(app: &SolveApp, d: &Dialog) -> Vec { let s = &app.session; crate::hole_place::places(s, d) .into_iter() .filter_map(|(key, base)| { let Some(Sel::Face { body, index, .. }) = d.inputs.first()?.items.get(key) else { return None }; - let (_, n) = crate::dialogs::planar_face(s, body, *index)?; + let n = crate::dialogs::planar_face(s, body, *index) + .map(|(_, n)| n) + .or_else(|| d.extra.get("direction").and_then(vec3_of)) + .and_then(|n| n.normalized())?; Some(Place { key, base, n }) }) .collect() } /// The hole at `key` moved to the face place a click with `hits` would take (snapped as the -/// pick is), unless that face already has another hole. +/// pick is), unless that face already has another hole. Only while the face input is the active +/// one: the hits were picked by the active input's rules. fn move_to(app: &SolveApp, d: &mut Dialog, hits: &[Hit], key: usize) -> bool { - let s = &app.session; - let snap = d.face_snap(s, hits); - let Some(to) = hits.iter().find_map(|h| d.candidate_on(s, h, snap.as_ref()).filter(|c| matches!(c, Sel::Face { .. }))) else { + if d.active != 0 { return false; - }; + } + let s = &app.session; + let Some(to) = face_pick(d, s, hits) else { return false }; crate::hole_place::move_place(d, s, key, to) } diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index 6ba61b721b1..f0c7a2242e0 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -110,3 +110,41 @@ fn the_depth_arrow_stands_clear_of_the_marker_only_while_holes_move() { crate::prefs::set(&mut h.app, &json!({"hole_moves": false})).unwrap(); assert_eq!(crate::place_gizmo::arrow_clearance(&h.app, &d), 0.0, "no marker, no clearance"); } + +#[test] +fn the_markers_follow_the_holes_own_setting_not_the_shared_one() { + let mut h = blocks(); + crate::prefs::set(&mut h.app, &json!({"hole_moves": false, "placement_handles": true})).unwrap(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let at = screen(&mut h, Vec3::new(10.0, 10.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + h.frames(2); + assert_eq!(places(&h).len(), 1); + assert!(handle_at("hole:0").is_none(), "Placement handles alone show no hole marker"); + crate::prefs::set(&mut h.app, &json!({"hole_moves": true, "placement_handles": false})).unwrap(); + h.frames(2); + assert!(handle_at("hole:0").is_some(), "Move holes by clicking or dragging alone shows it"); +} + +#[test] +fn a_hole_whose_face_is_gone_keeps_its_marker_through_the_restored_direction() { + // Edit Feature restores a hole whose face no longer resolves as a bare place with the + // `direction` it had (dialogs.rs); the marker stands there all the same. + let mut h = blocks(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let at = screen(&mut h, Vec3::new(10.0, 10.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + h.frames(2); + assert!(handle_at("hole:0").is_some()); + { + let d = h.app.dialog.as_mut().expect("a dialog"); + d.inputs[0].items = vec![Sel::Face { body: String::new(), index: 0, point: Vec3::new(10.0, 10.0, 20.0) }]; + d.extra.insert("direction".into(), crate::place_gizmo::pt(Vec3::new(0.0, 0.0, 1.0))); + } + h.frames(2); + assert!(handle_at("hole:0").is_some(), "the marker stays with the place"); + let d = h.app.dialog.as_mut().expect("a dialog"); + d.extra.remove("direction"); + h.frames(2); + assert!(handle_at("hole:0").is_none(), "no face and no direction: nowhere to stand"); +} From a05605cdb93297f4c68e851f7f952235bd2ddc4f Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 27 Oct 2026 15:02:56 +0100 Subject: [PATCH 04/38] Hole: a reference edge holds the hole to its line, and the marker shows how much is left to move (#6818) With one reference edge picked, the hole's distance drives its place instead of following it: a drag of the marker, or a pick elsewhere on the face, moves the hole along that edge at its typed distance (`hole_refs::drag_to`, through `ReferenceFrame::place`), and the distance text, an expression included, is left alone. With two edges the hole moves anywhere again and a move sets both distances, as a move did before any edge was picked. Before, a move always measured the distances again from wherever the hole landed. The marker says so: a `Spec` tells how freely each place moves (`Freedom`: anywhere, along a line, not at all), and the marker's arms follow it: the four screen cardinals, two along the edge as the view shows it, or none, the dot alone stepped back, with no press area, hover or move cursor. A line seen nearly end-on, or a face seen nearly edge-on where a pick is refused anyway, counts as held: a drag there would move the hole by centimetres per pixel. The marker's pick and move go by the place input whichever input is active, so a reference edge input waiting for its edge no longer leaves the marker lit but dead. Tests: one edge holds the hole to a line the marker drags along; a typed distance survives the drag; a pick elsewhere on the face keeps a held hole on its line; two edges free it again and a drag sets both distances. Co-Authored-By: Claude Fable 5.1 --- crates/ui-egui/src/hole_place.rs | 11 ++- crates/ui-egui/src/hole_refs.rs | 48 +++++++++++- crates/ui-egui/src/place_gizmo.rs | 77 ++++++++++++++++-- crates/ui-egui/src/place_gizmo/boss.rs | 1 + crates/ui-egui/src/place_gizmo/hole.rs | 22 ++++-- crates/ui-egui/src/place_gizmo/hole_tests.rs | 82 ++++++++++++++++++++ crates/ui-egui/src/place_gizmo/look.rs | 21 +++-- crates/ui-egui/src/place_gizmo/rest.rs | 1 + crates/ui-egui/src/place_gizmo/snap_fit.rs | 1 + 9 files changed, 238 insertions(+), 26 deletions(-) diff --git a/crates/ui-egui/src/hole_place.rs b/crates/ui-egui/src/hole_place.rs index 9276acf614f..c29f2a27fc2 100644 --- a/crates/ui-egui/src/hole_place.rs +++ b/crates/ui-egui/src/hole_place.rs @@ -245,7 +245,8 @@ pub(crate) fn move_place(d: &mut Dialog, s: &Session, i: usize, to: Sel) -> bool /// A Single hole's face place picked on a face that already has a hole moves that hole there /// (true), when holes move by clicking. A pick on the hole itself (within its radius) is left to -/// take it out, as before. +/// take it out, as before. A hole held along one reference edge goes along it only, and the pick +/// is spent either way (it never takes the hole out instead). pub(crate) fn pick_moves(d: &mut Dialog, s: &Session, sel: &Sel) -> bool { let Kind::Hole { opts, diameter, .. } = &d.kind else { return false }; let Sel::Face { point, .. } = sel else { return false }; @@ -260,7 +261,13 @@ pub(crate) fn pick_moves(d: &mut Dialog, s: &Session, sel: &Sel) -> bool { if was.dist(*point) <= radius { return false; } - move_place(d, s, i, sel.clone()) + match crate::hole_refs::freedom(d) { + crate::place_gizmo::Freedom::Plane => move_place(d, s, i, sel.clone()), + crate::place_gizmo::Freedom::Line(_) => { + crate::hole_refs::drag_to(s, d, i, *point); + true + } + } } /// Whether this dialog's faces take several Single holes (Preferences): a new Hole in Single diff --git a/crates/ui-egui/src/hole_refs.rs b/crates/ui-egui/src/hole_refs.rs index 157d21c48f9..8fd1ab4a9d1 100644 --- a/crates/ui-egui/src/hole_refs.rs +++ b/crates/ui-egui/src/hole_refs.rs @@ -2,8 +2,9 @@ //! dialog takes up to two straight edges of that face (Reference 1 and 2), each with the hole //! centre's distance from it (Distance 1 and 2). Picking an edge measures its distance from where //! the hole is; typing a distance (in the dialog or in its box on the canvas) moves the hole -//! there; moving the hole (another pick, or dragging its handle) measures the distances again. -//! The canvas shows each distance as a dimension from its edge to the hole's centre. OK sends the +//! there; moving the hole by a pick or its marker with one edge picked keeps its distance and goes +//! along the edge, with two edges it goes anywhere and both distances follow (#6818). The canvas +//! shows each distance as a dimension from its edge to the hole's centre. OK sends the //! edges and distances as `solid.hole`'s `references`, so the hole follows its edges when the //! part changes; Edit Feature picks the edges again where they are now. A Cylinder takes the same //! references for its base centre (#6380): its window picks the face it stands on (or takes the @@ -20,6 +21,7 @@ use solidcraft_engine::{Sel, Session}; use crate::SolveApp; use crate::dialogs::{Dialog, Kind}; +use crate::place_gizmo::Freedom; use crate::selection::{EDGES, FACES, PLANAR_FACES, SelInput, VERTICES}; use crate::theme::Tokens; use crate::viewport::Proj; @@ -198,6 +200,48 @@ fn frame(s: &Session, d: &mut Dialog) -> Option<(ReferenceFrame, Vec)> { found } +/// What the picked reference edges leave the hole free to do: with one edge, along it at its +/// distance; with two, anywhere again, a move then setting both distances (as it did before any +/// edge was picked); with none, anywhere. Read from the frame last found for these edges (`sync` +/// keeps it current); an edge picked but not framed yet, or a frame that failed, leaves the hole free. +pub(crate) fn freedom(d: &Dialog) -> Freedom { + let Kind::Hole { opts, .. } = &d.kind else { return Freedom::Plane }; + let edges = edges(d); + let Some(f) = opts.refs.frame.as_ref().filter(|f| f.edges == edges) else { return Freedom::Plane }; + match f.frame.as_ref().map(|(fr, _)| fr.lines.as_slice()) { + Some([a]) => Freedom::Line(a.along), + _ => Freedom::Plane, + } +} + +/// Move the hole at item `i` of the face input toward `near` as far as its one reference edge +/// lets it: onto the line at the typed distance from it, nearest `near`. The typed distance +/// stays as it is, an expression included, so a drag never rewrites it. False when the hole +/// cannot go there (off its face, no frame, or not exactly one edge). +pub(crate) fn drag_to(s: &Session, d: &mut Dialog, i: usize, near: Vec3) -> bool { + let Some((f, picked)) = frame(s, d) else { return false }; + if picked.len() != 1 { + return false; + } + let Kind::Hole { opts, .. } = &d.kind else { return false }; + let values: Option> = picked.iter().map(|k| opts.refs.distance.get(*k).and_then(|e| s.doc.eval(e, ValueKind::Length).ok())).collect(); + let Some(to) = values.and_then(|v| f.place(near, &v).ok()).filter(|c| on_reference_face(&crate::open_meshing::session_world(s), &f, *c)) else { + return false; + }; + let Some(Sel::Face { point, .. }) = d.inputs.first_mut().and_then(|inp| inp.items.get_mut(i)) else { return false }; + *point = to; + // In step already: the place moved by its distances, so there is nothing to measure again. + let edges = edges(d); + if let Kind::Hole { opts, .. } = &mut d.kind + && let Some(sn) = opts.refs.seen.as_mut() + { + sn.place = to; + sn.edges = edges; + } + d.error = None; + true +} + /// Keep the distances and the hole's place in step: a new place or a new edge is measured, a /// typed distance moves the place there (when it stays on the face). Run before the dialog's /// commands are made. diff --git a/crates/ui-egui/src/place_gizmo.rs b/crates/ui-egui/src/place_gizmo.rs index a5bc9cbd762..a6774307565 100644 --- a/crates/ui-egui/src/place_gizmo.rs +++ b/crates/ui-egui/src/place_gizmo.rs @@ -32,7 +32,8 @@ mod snap_fit; use crate::ui_kit::BackingTooltipExt as _; use egui::{Pos2, vec2}; use look::{ - CrossStyle, DIM, DIM_S, MARKER_ACTIVE, MARKER_HOT, RING_ACTIVE, RING_OPEN, RING_PX, RingStyle, angle_label, compass, crosshair, footprint, ring, + CARDINALS, CrossStyle, DIM, DIM_S, MARKER_ACTIVE, MARKER_HOT, RING_ACTIVE, RING_OPEN, RING_PX, RingStyle, angle_label, compass, crosshair, + footprint, ring, }; use solidcore_record::Vec3; use solidcraft_engine::doc::expr::Kind as ValueKind; @@ -77,9 +78,27 @@ pub(crate) struct Spec { pub click: Option, /// The footprint outlined while dragging, in world points (empty: no outline). pub footprint: fn(&SolveApp, &Dialog, Vec3, Vec3) -> Vec, + /// How freely the place at `key` moves on its face: anywhere, or along a line (a hole held at + /// a distance from one reference edge). The marker shows it as its arms, and does not take a + /// drag when the line cannot be dragged as the view shows it. + pub freedom: fn(&SolveApp, &Dialog, usize) -> Freedom, pub turn: Option, } +/// The ways a place can go on its face. +#[derive(Clone, Copy, Debug, PartialEq)] +pub(crate) enum Freedom { + /// Anywhere on the face. + Plane, + /// Along this world direction only (unit), in the face. + Line(Vec3), +} + +/// Every place of a tool moves anywhere on its face. +pub(crate) fn anywhere(_: &SolveApp, _: &Dialog, _: usize) -> Freedom { + Freedom::Plane +} + /// One place a tool's handles stand at. pub(crate) struct Place { /// Which of the tool's places: the item's index in the first input for a tool with `many`, @@ -273,9 +292,37 @@ fn with_dialog(app: &mut SolveApp, f: impl FnOnce(&SolveApp, &mut Dialog)) { } } +/// The marker's arms for a place's freedom, as unit screen directions: the four cardinals, the +/// two ways along a line as the view shows it, or none. A line seen nearly end-on (shorter on +/// screen than [`LINE_MIN_PX`] per millimetre, or the face itself seen nearly edge-on, where +/// [`on_plane`] refuses a pick) gets no arms and no press area: a drag there would move the +/// feature by centimetres per pixel, so the marker is the dot alone until the view turns. +fn arms(proj: &Proj, base: Vec3, n: Vec3, bs: Pos2, freedom: Freedom) -> Vec { + match freedom { + Freedom::Plane => CARDINALS.to_vec(), + Freedom::Line(dir) => { + if proj.ray(bs).1.dot(n).abs() < 0.05 { + return Vec::new(); + } + match proj.to_screen(base + dir) { + Some(p) if (p - bs).length() >= LINE_MIN_PX => { + let d = (p - bs).normalized(); + vec![d, -d] + } + _ => Vec::new(), + } + } + } +} + +/// How long a millimetre along a line of motion must be on screen for the line to be dragged. +const LINE_MIN_PX: f32 = 0.5; + /// Draw the handles of the open dialog and take their drags (after the dialog's own arrow, so the /// marker wins the pointer near the base). The dialog stays in `app` while the pointer is picked -/// under, so a drag snaps as a click does (its input's points, the hole's face and rim snaps). +/// under, so a drag snaps as a click does (its input's points, the hole's face and rim snaps); +/// the pick and the move go by the place input (the first), whichever input is active, so a +/// reference edge input waiting for its edge does not stop the marker. pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj) { DRAWN.with(|h| h.borrow_mut().clear()); RING_ABOUT.with(|c| c.set(None)); @@ -286,21 +333,29 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte let id = |what: &str| egui::Id::unique(("sc_place", sp.name, what)); let at = |key: usize, what: &str| egui::Id::unique(("sc_place", sp.name, key, what)); let sense = if sp.click.is_some() { egui::Sense::click_and_drag() } else { egui::Sense::drag() }; + let freedom_of = |app: &SolveApp, key: usize| app.dialog.as_ref().map_or(Freedom::Plane, |d| (sp.freedom)(app, d, key)); // The crosshairs that move the feature, one per place. The press lands where the finger is, - // not always the centre: the drag keeps that gap. + // not always the centre: the drag keeps that gap. A place held still has no press area. let mut markers: Vec<(usize, egui::Response)> = Vec::new(); for pl in places(app) { let Some(bs) = proj.to_screen(pl.base) else { continue }; + if arms(proj, pl.base, pl.n, bs, freedom_of(app, pl.key)).is_empty() { + continue; + } let r = ui.interact(area(bs), at(pl.key, "position"), sense); let off = motion::grab(ui, at(pl.key, "grab"), &r, |p| Some(p - bs)); if r.dragged() { crate::tool_modifiers::set_manipulator_dragging(true); if let Some(p) = r.interact_pointer_pos() { + let was = app.dialog.as_mut().map(|d| std::mem::replace(&mut d.active, 0)); let hits = crate::viewport::pick(app, proj, p - off.unwrap_or_default()); with_dialog(app, |app, d| { (sp.move_to)(app, d, &hits, pl.key); }); + if let (Some(d), Some(was)) = (app.dialog.as_mut(), was) { + d.active = was; + } } } else if r.clicked() && let Some(click) = sp.click @@ -313,17 +368,24 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte // is an index, not an identity: with a place gone, the ones after it have moved down, so the // markers' states are left alone for this frame rather than given to the wrong place. let now = places(app); - let settled = now.len() == markers.len(); let ctx = ui.ctx().clone(); // The marker steps back while the ring works (the ring's drag is last frame's). let turning = ui.data(|m| m.get_temp::(id("turning"))).unwrap_or(false); let mut first: Option<(Place, Pos2, bool)> = None; + let mut free = 0; for (n, pl) in now.into_iter().enumerate() { let Some(bs) = proj.to_screen(pl.base) else { continue }; let name = if sp.many { format!("{}:{n}", sp.name) } else { format!("{}:position", sp.name) }; crate::scenario::publish_handle(&name, bs); DRAWN.with(|h| h.borrow_mut().push(bs)); - let r = markers.iter().filter(|_| settled).find(|(k, _)| *k == pl.key).map(|(_, r)| r); + let dirs = arms(proj, pl.base, pl.n, bs, freedom_of(app, pl.key)); + let held = dirs.is_empty(); + if !held { + free += 1; + } + // A place that moved into another's index this frame (one was taken out) keeps no state. + let settled = free <= markers.len(); + let r = markers.iter().filter(|_| settled && !held).find(|(k, _)| *k == pl.key).map(|(_, r)| r); let (hovered, dragging) = r.map_or((false, false), |r| (r.hovered(), r.dragged())); // The tip while pointing, not while dragging: the hand is busy and the footprint says it all. if hovered @@ -332,10 +394,11 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte { r.clone().backing_on_hover_text(crate::i18n::tr_label(sp.move_tip)); } + // A held place steps back as a handle not in use does: there, but offering no move. let style = CrossStyle { hot: MARKER_HOT.run(&ctx, at(pl.key, "hot"), hovered || dragging).t, active: MARKER_ACTIVE.run(&ctx, at(pl.key, "active"), dragging).t, - alpha: motion::step_back(&ctx, at(pl.key, "marker_dim"), turning, DIM, DIM_S), + alpha: motion::step_back(&ctx, at(pl.key, "marker_dim"), turning || held, DIM, DIM_S), }; if dragging && let Some(d) = app.dialog.as_ref() { let pts: Option> = (sp.footprint)(app, d, pl.base, pl.n).into_iter().map(|p| proj.to_screen(p)).collect(); @@ -343,7 +406,7 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte footprint(painter, &pts, &t); } } - crosshair(painter, bs, &style, &t); + crosshair(painter, bs, &style, &dirs, &t); if hovered || dragging { ui.ctx().set_cursor_icon(if dragging { egui::CursorIcon::Grabbing } else { egui::CursorIcon::Move }); } diff --git a/crates/ui-egui/src/place_gizmo/boss.rs b/crates/ui-egui/src/place_gizmo/boss.rs index cfadb433835..ce8e276b0c6 100644 --- a/crates/ui-egui/src/place_gizmo/boss.rs +++ b/crates/ui-egui/src/place_gizmo/boss.rs @@ -18,6 +18,7 @@ pub(super) static SPEC: Spec = Spec { move_to: |app, d, hits, _| crate::dialogs_plastic::handle_move(app, d, hits), click: None, footprint, + freedom: super::anywhere, turn: None, }; diff --git a/crates/ui-egui/src/place_gizmo/hole.rs b/crates/ui-egui/src/place_gizmo/hole.rs index 1aa41e175e1..2c2ece63500 100644 --- a/crates/ui-egui/src/place_gizmo/hole.rs +++ b/crates/ui-egui/src/place_gizmo/hole.rs @@ -4,12 +4,16 @@ //! hole's own handle from #2912 did. Behind Create Hole › Move holes by clicking or dragging, not the //! shared Placement handles setting. No ring: a hole has nothing to turn. Holes on sketch points //! (Multiple) have no markers: their place is the point's. +//! +//! Reference edges (#37): with one picked, the marker has two arms along the edge and drags the +//! hole along it at its distance; with two, the marker has its four arms again and a drag sets +//! both distances. use solidcore_record::Vec3; use solidcraft_engine::Sel; use solidcraft_engine::geom::prelude::*; -use super::{Place, Spec, circle, face_pick, len, vec3_of}; +use super::{Freedom, Place, Spec, circle, face_pick, len, vec3_of}; use crate::SolveApp; use crate::dialogs::{Dialog, Kind}; use crate::viewport::Hit; @@ -24,6 +28,7 @@ pub(super) static SPEC: Spec = Spec { move_to, click: Some(|app, d, key| crate::hole_place::remove_place(d, &app.session, key)), footprint, + freedom: |_, d, _| crate::hole_refs::freedom(d), turn: None, }; @@ -46,15 +51,18 @@ fn places(app: &SolveApp, d: &Dialog) -> Vec { } /// The hole at `key` moved to the face place a click with `hits` would take (snapped as the -/// pick is), unless that face already has another hole. Only while the face input is the active -/// one: the hits were picked by the active input's rules. +/// pick is), unless that face already has another hole; held by a reference edge, as far along +/// the edge as the pick is. fn move_to(app: &SolveApp, d: &mut Dialog, hits: &[Hit], key: usize) -> bool { - if d.active != 0 { - return false; - } let s = &app.session; let Some(to) = face_pick(d, s, hits) else { return false }; - crate::hole_place::move_place(d, s, key, to) + match crate::hole_refs::freedom(d) { + Freedom::Plane => crate::hole_place::move_place(d, s, key, to), + Freedom::Line(_) => match to { + Sel::Face { point, .. } => crate::hole_refs::drag_to(s, d, key, point), + _ => false, + }, + } } /// The hole's mouth on the face: the counterbore's or countersink's diameter, else the bore's. diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index f0c7a2242e0..06b433e9154 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -148,3 +148,85 @@ fn a_hole_whose_face_is_gone_keeps_its_marker_through_the_restored_direction() { h.frames(2); assert!(handle_at("hole:0").is_none(), "no face and no direction: nowhere to stand"); } + +/// The open Hole dialog's reference distances, as typed. +fn distances(h: &Harness) -> [String; 2] { + match h.app.dialog.as_ref().map(|d| &d.kind) { + Some(crate::dialogs::Kind::Hole { opts, .. }) => opts.refs.distance.clone(), + _ => panic!("the hole dialog is open"), + } +} + +/// Reference distance `k` as a length (mm); a measured one carries floating-point noise in its text. +fn distance(h: &Harness, k: usize) -> f64 { + h.app.session.doc.eval(&distances(h)[k], solidcraft_engine::doc::expr::Kind::Length).unwrap_or(f64::NAN) +} + +/// A hole at (10, 10) on the first block's top, held by the block's left edge (x = 0) at 10 mm. +fn held_by_the_left_edge() -> Harness { + let mut h = blocks(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let at = screen(&mut h, Vec3::new(10.0, 10.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + h.step(&json!({"click": {"handle": "dialog:Reference 1"}})).unwrap(); + let left = screen(&mut h, Vec3::new(0.0, 15.0, 20.0)); + h.step(&json!({"click": left})).unwrap(); + h.settle(); + assert!(matches!(places(&h).as_slice(), [p] if p.dist(Vec3::new(10.0, 10.0, 20.0)) < 0.3), "{:?}", places(&h)); + assert!((distance(&h, 0) - 10.0).abs() < 1e-6, "measured from the pick: {:?}", distances(&h)); + h +} + +#[test] +fn one_reference_edge_holds_the_hole_to_a_line_the_marker_drags_along() { + let mut h = held_by_the_left_edge(); + // The next reference input is the active one now; the marker still moves the hole. + assert!(handle_at("hole:0").is_some(), "the held hole keeps its marker"); + let to = screen(&mut h, Vec3::new(25.0, 22.0, 20.0)); + h.step(&json!({"drag": [{"handle": "hole:0"}, to], "steps": 12})).unwrap(); + h.settle(); + let p = places(&h); + assert!(matches!(p.as_slice(), [p] if (p.x - 10.0).abs() < 1e-6 && (p.y - 22.0).abs() < 0.3), "along the edge, 10 mm from it: {p:?}"); + assert!((distance(&h, 0) - 10.0).abs() < 1e-6, "the distance is kept, not measured again: {:?}", distances(&h)); +} + +#[test] +fn a_typed_distance_survives_a_drag_along_the_edge() { + let mut h = held_by_the_left_edge(); + h.step(&json!({"click": {"handle": "dialog:Distance 1"}})).unwrap(); + h.step(&json!({"key": "A", "cmd": true})).unwrap(); + h.step(&json!({"text": "12"})).unwrap(); + h.frames(3); + assert!(matches!(places(&h).as_slice(), [p] if (p.x - 12.0).abs() < 1e-6), "typed: the hole goes to 12 mm: {:?}", places(&h)); + let to = screen(&mut h, Vec3::new(30.0, 24.0, 20.0)); + h.step(&json!({"drag": [{"handle": "hole:0"}, to], "steps": 12})).unwrap(); + h.settle(); + assert_eq!(distances(&h)[0].trim(), "12", "the typed text is left alone by the drag"); + assert!(matches!(places(&h).as_slice(), [p] if (p.x - 12.0).abs() < 1e-6 && (p.y - 24.0).abs() < 0.3), "{:?}", places(&h)); +} + +#[test] +fn a_pick_elsewhere_on_the_face_keeps_a_held_hole_on_its_line() { + let mut h = held_by_the_left_edge(); + h.step(&json!({"click": {"handle": "dialog:Face"}})).unwrap(); + let at = screen(&mut h, Vec3::new(30.0, 25.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + h.settle(); + let p = places(&h); + assert!(matches!(p.as_slice(), [p] if (p.x - 10.0).abs() < 1e-6 && (p.y - 25.0).abs() < 0.3), "moved along the edge only: {p:?}"); +} + +#[test] +fn two_reference_edges_free_the_hole_again_and_a_drag_sets_both_distances() { + let mut h = held_by_the_left_edge(); + h.step(&json!({"click": {"handle": "dialog:Reference 2"}})).unwrap(); + let front = screen(&mut h, Vec3::new(20.0, 0.0, 20.0)); + h.step(&json!({"click": front})).unwrap(); + h.settle(); + assert!((distance(&h, 1) - 10.0).abs() < 1e-4, "{:?}", distances(&h)); + let to = screen(&mut h, Vec3::new(25.0, 22.0, 20.0)); + h.step(&json!({"drag": [{"handle": "hole:0"}, to], "steps": 12})).unwrap(); + h.settle(); + assert!(matches!(places(&h).as_slice(), [p] if p.dist(Vec3::new(25.0, 22.0, 20.0)) < 0.3), "free again: {:?}", places(&h)); + assert!((distance(&h, 0) - 25.0).abs() < 0.3 && (distance(&h, 1) - 22.0).abs() < 0.3, "both distances follow: {:?}", distances(&h)); +} diff --git a/crates/ui-egui/src/place_gizmo/look.rs b/crates/ui-egui/src/place_gizmo/look.rs index 7c9d90c8c50..9c064ae2412 100644 --- a/crates/ui-egui/src/place_gizmo/look.rs +++ b/crates/ui-egui/src/place_gizmo/look.rs @@ -77,13 +77,18 @@ const HEAD_BASE: f32 = ARM_FROM + DASH + GAP; /// (the dialog's drag arrow) can keep clear of it. pub(super) const MARKER_CLEAR: f32 = HEAD_BASE + HEAD_LEN + 6.0; -/// The move marker: a dot with four arms to the screen cardinals. At rest each arm is two dashes, -/// a place that can be grabbed and nothing more. Pointed at, the outer dash becomes an arrowhead, -/// its far end narrowing to a point and its near end widening while it grows a little: the -/// feature moves straight in any direction along the face. While it drags, the inner dash runs -/// on into the head as a solid shaft. The dotted-to-solid switch is the one step that cannot -/// tween, so it flips halfway into the drag. -pub(super) fn crosshair(painter: &egui::Painter, c: Pos2, s: &CrossStyle, _t: &Tokens) { +/// The four screen cardinals: the arms of a marker whose feature moves anywhere on its face. +pub(super) const CARDINALS: [Vec2; 4] = [vec2(1.0, 0.0), vec2(-1.0, 0.0), vec2(0.0, 1.0), vec2(0.0, -1.0)]; + +/// The move marker: a dot with an arm for each way the feature can go, the four screen cardinals +/// when it moves anywhere on its face, two along a line when a reference edge holds it to one, +/// none when its references hold it still. At rest each arm is two dashes, a place that can be +/// grabbed and nothing more. Pointed at, the outer dash becomes an arrowhead, its far end +/// narrowing to a point and its near end widening while it grows a little: the feature moves +/// straight that way along the face. While it drags, the inner dash runs on into the head as a +/// solid shaft. The dotted-to-solid switch is the one step that cannot tween, so it flips halfway +/// into the drag. `arms` are unit screen directions. +pub(super) fn crosshair(painter: &egui::Painter, c: Pos2, s: &CrossStyle, arms: &[Vec2], _t: &Tokens) { let solid = s.active > 0.5; let (core, case) = (core(s.hot > 0.5).gamma_multiply(s.alpha), casing().gamma_multiply(s.alpha)); // The outer dash on its way to being the head. @@ -92,7 +97,7 @@ pub(super) fn crosshair(painter: &egui::Painter, c: Pos2, s: &CrossStyle, _t: &T let far = LINE / 2.0 * (1.0 - s.hot); let mut lines: Vec> = Vec::new(); let mut heads: Vec> = Vec::new(); - for d in [vec2(1.0, 0.0), vec2(-1.0, 0.0), vec2(0.0, 1.0), vec2(0.0, -1.0)] { + for d in arms.iter().copied() { // The inner dash, or the shaft up to the head's base. lines.push(vec![c + d * ARM_FROM, c + d * if solid { HEAD_BASE } else { ARM_FROM + DASH }]); let n: Vec2 = vec2(-d.y, d.x); diff --git a/crates/ui-egui/src/place_gizmo/rest.rs b/crates/ui-egui/src/place_gizmo/rest.rs index 2dc84766eba..33f4e61de40 100644 --- a/crates/ui-egui/src/place_gizmo/rest.rs +++ b/crates/ui-egui/src/place_gizmo/rest.rs @@ -18,6 +18,7 @@ pub(super) static SPEC: Spec = Spec { move_to: |app, d, hits, _| crate::dialogs_plastic::handle_move(app, d, hits), click: None, footprint, + freedom: super::anywhere, turn: Some(Turn { tip: "Drag to turn the rest in 5° steps. Hold Alt or Ctrl to turn it freely.", reach, angle, set }), }; diff --git a/crates/ui-egui/src/place_gizmo/snap_fit.rs b/crates/ui-egui/src/place_gizmo/snap_fit.rs index e5adc6488cd..0aecaa793b1 100644 --- a/crates/ui-egui/src/place_gizmo/snap_fit.rs +++ b/crates/ui-egui/src/place_gizmo/snap_fit.rs @@ -19,6 +19,7 @@ pub(super) static SPEC: Spec = Spec { move_to: |app, d, hits, _| crate::dialogs_plastic::handle_move(app, d, hits), click: None, footprint, + freedom: super::anywhere, turn: Some(Turn { tip: "Drag to point the catch in another direction.", reach, angle, set }), }; From 14f51e1a54a628752100e43f917c514eda92fc36 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 29 Oct 2026 15:19:37 +0100 Subject: [PATCH 05/38] Hole: reference edges hold only the hole they place (#6818) With several holes in one Hole dialog and one reference edge picked, every hole's marker and drag took the first hole's line: a drag of a hole on another face wrote a point on the first hole's line into it, off its own face, and a pick on that face did the same. The edges place the first face pick only (OK refuses them with more than one hole), so freedom and drag_to now go by the item index and hold that hole alone; any other hole moves anywhere. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/hole_place.rs | 2 +- crates/ui-egui/src/hole_refs.rs | 26 ++++++++++++++----- crates/ui-egui/src/place_gizmo/hole.rs | 10 ++++---- crates/ui-egui/src/place_gizmo/hole_tests.rs | 27 ++++++++++++++++++++ 4 files changed, 53 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/hole_place.rs b/crates/ui-egui/src/hole_place.rs index c29f2a27fc2..2baaf96fac5 100644 --- a/crates/ui-egui/src/hole_place.rs +++ b/crates/ui-egui/src/hole_place.rs @@ -261,7 +261,7 @@ pub(crate) fn pick_moves(d: &mut Dialog, s: &Session, sel: &Sel) -> bool { if was.dist(*point) <= radius { return false; } - match crate::hole_refs::freedom(d) { + match crate::hole_refs::freedom(d, i) { crate::place_gizmo::Freedom::Plane => move_place(d, s, i, sel.clone()), crate::place_gizmo::Freedom::Line(_) => { crate::hole_refs::drag_to(s, d, i, *point); diff --git a/crates/ui-egui/src/hole_refs.rs b/crates/ui-egui/src/hole_refs.rs index 8fd1ab4a9d1..b854a95db7e 100644 --- a/crates/ui-egui/src/hole_refs.rs +++ b/crates/ui-egui/src/hole_refs.rs @@ -200,12 +200,23 @@ fn frame(s: &Session, d: &mut Dialog) -> Option<(ReferenceFrame, Vec)> { found } -/// What the picked reference edges leave the hole free to do: with one edge, along it at its -/// distance; with two, anywhere again, a move then setting both distances (as it did before any -/// edge was picked); with none, anywhere. Read from the frame last found for these edges (`sync` -/// keeps it current); an edge picked but not framed yet, or a frame that failed, leaves the hole free. -pub(crate) fn freedom(d: &Dialog) -> Freedom { +/// The face input's item the reference edges place: the first face pick (see [`place`]). The +/// edges place that one hole only; OK refuses them with more than one. +fn place_item(d: &Dialog) -> Option { + d.inputs.first()?.items.iter().position(|x| matches!(x, Sel::Face { .. })) +} + +/// What the picked reference edges leave the hole at item `i` of the face input free to do: with +/// one edge, along it at its distance; with two, anywhere again, a move then setting both +/// distances (as it did before any edge was picked); with none, anywhere. Only the hole the edges +/// place (see [`place_item`]) is held; another hole in the same dialog moves anywhere. Read from +/// the frame last found for these edges (`sync` keeps it current); an edge picked but not framed +/// yet, or a frame that failed, leaves the hole free. +pub(crate) fn freedom(d: &Dialog, i: usize) -> Freedom { let Kind::Hole { opts, .. } = &d.kind else { return Freedom::Plane }; + if place_item(d) != Some(i) { + return Freedom::Plane; + } let edges = edges(d); let Some(f) = opts.refs.frame.as_ref().filter(|f| f.edges == edges) else { return Freedom::Plane }; match f.frame.as_ref().map(|(fr, _)| fr.lines.as_slice()) { @@ -217,8 +228,11 @@ pub(crate) fn freedom(d: &Dialog) -> Freedom { /// Move the hole at item `i` of the face input toward `near` as far as its one reference edge /// lets it: onto the line at the typed distance from it, nearest `near`. The typed distance /// stays as it is, an expression included, so a drag never rewrites it. False when the hole -/// cannot go there (off its face, no frame, or not exactly one edge). +/// cannot go there (off its face, no frame, not exactly one edge, or not the hole the edges place). pub(crate) fn drag_to(s: &Session, d: &mut Dialog, i: usize, near: Vec3) -> bool { + if place_item(d) != Some(i) { + return false; + } let Some((f, picked)) = frame(s, d) else { return false }; if picked.len() != 1 { return false; diff --git a/crates/ui-egui/src/place_gizmo/hole.rs b/crates/ui-egui/src/place_gizmo/hole.rs index 2c2ece63500..62748ec922d 100644 --- a/crates/ui-egui/src/place_gizmo/hole.rs +++ b/crates/ui-egui/src/place_gizmo/hole.rs @@ -5,9 +5,9 @@ //! shared Placement handles setting. No ring: a hole has nothing to turn. Holes on sketch points //! (Multiple) have no markers: their place is the point's. //! -//! Reference edges (#37): with one picked, the marker has two arms along the edge and drags the -//! hole along it at its distance; with two, the marker has its four arms again and a drag sets -//! both distances. +//! Reference edges (#37) place the first hole: with one picked, its marker has two arms along the +//! edge and drags the hole along it at its distance; with two, the marker has its four arms again +//! and a drag sets both distances. Any other hole in the dialog moves anywhere. use solidcore_record::Vec3; use solidcraft_engine::Sel; @@ -28,7 +28,7 @@ pub(super) static SPEC: Spec = Spec { move_to, click: Some(|app, d, key| crate::hole_place::remove_place(d, &app.session, key)), footprint, - freedom: |_, d, _| crate::hole_refs::freedom(d), + freedom: |_, d, key| crate::hole_refs::freedom(d, key), turn: None, }; @@ -56,7 +56,7 @@ fn places(app: &SolveApp, d: &Dialog) -> Vec { fn move_to(app: &SolveApp, d: &mut Dialog, hits: &[Hit], key: usize) -> bool { let s = &app.session; let Some(to) = face_pick(d, s, hits) else { return false }; - match crate::hole_refs::freedom(d) { + match crate::hole_refs::freedom(d, key) { Freedom::Plane => crate::hole_place::move_place(d, s, key, to), Freedom::Line(_) => match to { Sel::Face { point, .. } => crate::hole_refs::drag_to(s, d, key, point), diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index 06b433e9154..da38cb12461 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -230,3 +230,30 @@ fn two_reference_edges_free_the_hole_again_and_a_drag_sets_both_distances() { assert!(matches!(places(&h).as_slice(), [p] if p.dist(Vec3::new(25.0, 22.0, 20.0)) < 0.3), "free again: {:?}", places(&h)); assert!((distance(&h, 0) - 25.0).abs() < 0.3 && (distance(&h, 1) - 22.0).abs() < 0.3, "both distances follow: {:?}", distances(&h)); } + +#[test] +fn a_second_hole_on_another_face_moves_freely_while_the_first_is_held_by_its_edge() { + // The reference edges place the first hole only: a hole on the other block keeps its own + // face and goes where it is dragged, not onto the first hole's line. + let mut h = blocks(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let first = Vec3::new(10.0, 10.0, 20.0); + let at = screen(&mut h, first); + h.step(&json!({"click": at})).unwrap(); + let at = screen(&mut h, Vec3::new(60.0, 15.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + h.step(&json!({"click": {"handle": "dialog:Reference 1"}})).unwrap(); + let left = screen(&mut h, Vec3::new(0.0, 15.0, 20.0)); + h.step(&json!({"click": left})).unwrap(); + h.settle(); + assert!((distance(&h, 0) - 10.0).abs() < 1e-6, "measured for the first hole: {:?}", distances(&h)); + let to = Vec3::new(65.0, 25.0, 20.0); + let ts = screen(&mut h, to); + h.step(&json!({"drag": [{"handle": "hole:1"}, ts], "steps": 12})).unwrap(); + h.settle(); + let p = places(&h); + assert!(matches!(p.as_slice(), [a, b] if a.dist(first) < 1e-4 && b.dist(to) < 0.3), "the second hole went where it was dragged: {p:?}"); + let d = h.app.dialog.as_ref().expect("a dialog is open"); + assert!(matches!(&d.inputs[0].items[1], Sel::Face { body, .. } if body == "Other"), "on its own block: {:?}", d.inputs[0].items); + assert!((distance(&h, 0) - 10.0).abs() < 1e-6, "the first hole's distance is unchanged: {:?}", distances(&h)); +} From 13c4495adc8e6d48a7e8ab451a8fa811a567e70c Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 29 Oct 2026 16:00:11 +0100 Subject: [PATCH 06/38] Placement handles: a marker's press, hover and look go by a stable id, not the place's index (#6818) The markers' widget and animation ids were built from each place's key, the item's index in the first input. When a click took a hole out, the next hole took its index and with it the hover of the one taken out: egui hit-tests by the last frame's rect for that id, so the surviving marker was hovered on the next frame, drawn hot with the Move cursor, and eased back over 0.22 s. The guard meant to stop that (`settled`) could never be false after a removal. Each place now has an id by its order, kept while it moves (its key can change as a round face's halves come and go) and renewed for every place when one is gone. The guard is removed. The marker's hot factor is published as `:hot` for the scenario tests. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/place_gizmo.rs | 56 +++++++++++++------- crates/ui-egui/src/place_gizmo/hole_tests.rs | 27 ++++++++++ 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/crates/ui-egui/src/place_gizmo.rs b/crates/ui-egui/src/place_gizmo.rs index a6774307565..0a3092a3b34 100644 --- a/crates/ui-egui/src/place_gizmo.rs +++ b/crates/ui-egui/src/place_gizmo.rs @@ -318,6 +318,24 @@ fn arms(proj: &Proj, base: Vec3, n: Vec3, bs: Pos2, freedom: Freedom) -> Vec Vec { + let (mut ids, mut next) = ctx.data(|d| d.get_temp::<(Vec, u64)>(store)).unwrap_or_default(); + if ids.len() > n { + ids.clear(); + } + while ids.len() < n { + ids.push(next); + next += 1; + } + ctx.data_mut(|d| d.insert_temp(store, (ids.clone(), next))); + ids +} + /// Draw the handles of the open dialog and take their drags (after the dialog's own arrow, so the /// marker wins the pointer near the base). The dialog stays in `app` while the pointer is picked /// under, so a drag snaps as a click does (its input's points, the hole's face and rim snaps); @@ -331,20 +349,23 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte let t = Tokens::get(); let area = |c: Pos2| egui::Rect::from_center_size(c, vec2(2.0 * REACH, 2.0 * REACH)); let id = |what: &str| egui::Id::unique(("sc_place", sp.name, what)); - let at = |key: usize, what: &str| egui::Id::unique(("sc_place", sp.name, key, what)); + let at = |marker: u64, what: &str| egui::Id::unique(("sc_place", sp.name, marker, what)); + let store = id("markers"); let sense = if sp.click.is_some() { egui::Sense::click_and_drag() } else { egui::Sense::drag() }; let freedom_of = |app: &SolveApp, key: usize| app.dialog.as_ref().map_or(Freedom::Plane, |d| (sp.freedom)(app, d, key)); // The crosshairs that move the feature, one per place. The press lands where the finger is, // not always the centre: the drag keeps that gap. A place held still has no press area. - let mut markers: Vec<(usize, egui::Response)> = Vec::new(); - for pl in places(app) { + let mut markers: Vec<(u64, egui::Response)> = Vec::new(); + let before = places(app); + let ids = marker_ids(ui.ctx(), store, before.len()); + for (pl, marker) in before.into_iter().zip(ids) { let Some(bs) = proj.to_screen(pl.base) else { continue }; if arms(proj, pl.base, pl.n, bs, freedom_of(app, pl.key)).is_empty() { continue; } - let r = ui.interact(area(bs), at(pl.key, "position"), sense); - let off = motion::grab(ui, at(pl.key, "grab"), &r, |p| Some(p - bs)); + let r = ui.interact(area(bs), at(marker, "position"), sense); + let off = motion::grab(ui, at(marker, "grab"), &r, |p| Some(p - bs)); if r.dragged() { crate::tool_modifiers::set_manipulator_dragging(true); if let Some(p) = r.interact_pointer_pos() { @@ -362,30 +383,24 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte { with_dialog(app, |app, d| click(app, d, pl.key)); } - markers.push((pl.key, r)); + markers.push((marker, r)); } - // Read the places again: a drag moved one this frame, a click may have taken one out. A key - // is an index, not an identity: with a place gone, the ones after it have moved down, so the - // markers' states are left alone for this frame rather than given to the wrong place. + // Read the places again: a drag moved one this frame, a click may have taken one out (and + // the markers' ids with it, so this frame's press and hover reach none of the others). let now = places(app); + let ids = marker_ids(ui.ctx(), store, now.len()); let ctx = ui.ctx().clone(); // The marker steps back while the ring works (the ring's drag is last frame's). let turning = ui.data(|m| m.get_temp::(id("turning"))).unwrap_or(false); let mut first: Option<(Place, Pos2, bool)> = None; - let mut free = 0; - for (n, pl) in now.into_iter().enumerate() { + for (n, (pl, marker)) in now.into_iter().zip(ids).enumerate() { let Some(bs) = proj.to_screen(pl.base) else { continue }; let name = if sp.many { format!("{}:{n}", sp.name) } else { format!("{}:position", sp.name) }; crate::scenario::publish_handle(&name, bs); DRAWN.with(|h| h.borrow_mut().push(bs)); let dirs = arms(proj, pl.base, pl.n, bs, freedom_of(app, pl.key)); let held = dirs.is_empty(); - if !held { - free += 1; - } - // A place that moved into another's index this frame (one was taken out) keeps no state. - let settled = free <= markers.len(); - let r = markers.iter().filter(|_| settled && !held).find(|(k, _)| *k == pl.key).map(|(_, r)| r); + let r = markers.iter().filter(|_| !held).find(|(m, _)| *m == marker).map(|(_, r)| r); let (hovered, dragging) = r.map_or((false, false), |r| (r.hovered(), r.dragged())); // The tip while pointing, not while dragging: the hand is busy and the footprint says it all. if hovered @@ -396,10 +411,11 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte } // A held place steps back as a handle not in use does: there, but offering no move. let style = CrossStyle { - hot: MARKER_HOT.run(&ctx, at(pl.key, "hot"), hovered || dragging).t, - active: MARKER_ACTIVE.run(&ctx, at(pl.key, "active"), dragging).t, - alpha: motion::step_back(&ctx, at(pl.key, "marker_dim"), turning || held, DIM, DIM_S), + hot: MARKER_HOT.run(&ctx, at(marker, "hot"), hovered || dragging).t, + active: MARKER_ACTIVE.run(&ctx, at(marker, "active"), dragging).t, + alpha: motion::step_back(&ctx, at(marker, "marker_dim"), turning || held, DIM, DIM_S), }; + crate::scenario::publish_count(&format!("{name}:hot"), f64::from(style.hot)); if dragging && let Some(d) = app.dialog.as_ref() { let pts: Option> = (sp.footprint)(app, d, pl.base, pl.n).into_iter().map(|p| proj.to_screen(p)).collect(); if let Some(pts) = pts.filter(|p| p.len() >= 3) { diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index da38cb12461..5ded927e4bc 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -257,3 +257,30 @@ fn a_second_hole_on_another_face_moves_freely_while_the_first_is_held_by_its_edg assert!(matches!(&d.inputs[0].items[1], Sel::Face { body, .. } if body == "Other"), "on its own block: {:?}", d.inputs[0].items); assert!((distance(&h, 0) - 10.0).abs() < 1e-6, "the first hole's distance is unchanged: {:?}", distances(&h)); } + +#[test] +fn the_hole_after_one_taken_out_does_not_take_over_its_hover() { + // A click takes out the first hole under the pointer; the second takes its index, not its + // marker's state: its marker is not drawn hot on the click's frame (the press and hover are + // the first one's) and does not fade from there after it. + let mut h = blocks(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let at = screen(&mut h, Vec3::new(10.0, 10.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + let at = screen(&mut h, Vec3::new(60.0, 15.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + h.frames(2); + let c = handle_at("hole:0").expect("the first hole's marker"); + h.step(&json!({"move": [f64::from(c.x), f64::from(c.y)]})).unwrap(); + h.frames(30); + assert!(crate::scenario::count_of("hole:0:hot").is_some_and(|t| t > 0.99), "hovered: {:?}", crate::scenario::count_of("hole:0:hot")); + // The click frame by frame: the press, then the release that takes the hole out. + let button = |pressed| egui::Event::PointerButton { pos: c, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + h.frame_with(vec![button(true)]); + h.frame_with(vec![button(false)]); + let p = places(&h); + assert!(matches!(p.as_slice(), [p] if p.dist(Vec3::new(60.0, 15.0, 20.0)) < 1e-4), "the first hole is out: {p:?}"); + assert_eq!(crate::scenario::count_of("hole:0:hot"), Some(0.0), "not given the click's hover"); + h.frames(1); + assert_eq!(crate::scenario::count_of("hole:0:hot"), Some(0.0), "not fading from the hole taken out"); +} From dee38d446eb329e3d9818a3bf7e7e247d74f064e Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 29 Oct 2026 16:12:59 +0100 Subject: [PATCH 07/38] Hole: the marker tests prove what they claim (#6818) The click test passed with the old 9 pt reach too: a click 14 pt off the centre that missed the marker went to the canvas pick, which takes out a hole picked within its 5 mm radius. The hole is now 0.5 mm across, so a pick that missed the marker would move it and only the marker takes it out. The grab test's comment said the grab was outside the old handle's reach; it was inside the old 18 pt square, and the test discriminates by the gap itself (about 0.9 mm without it, and also when the gap is measured where the drag starts instead of at the press). Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/place_gizmo/hole_tests.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index 5ded927e4bc..c65bdf4419d 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -48,9 +48,9 @@ fn a_press_off_the_centre_keeps_its_gap_and_the_hole_lands_short_of_the_pointer( h.step(&json!({"click": at})).unwrap(); h.frames(2); let c = handle_at("hole:0").expect("the placed hole has a marker"); - // Grabbed 6 pt right and 4 pt below the centre (inside the shared marker's reach, outside the - // old handle's 9 pt), and let go with the pointer the same gap from `to`: the hole lands on - // `to`, not under the pointer. + // Grabbed 6 pt right and 4 pt below the centre (7.2 pt off it, inside the marker's reach), and + // let go with the pointer the same gap from `to`: the hole lands on `to`, not under the + // pointer (about 0.9 mm off here) nor where the drag only started, a few points on. let to = Vec3::new(30.0, 20.0, 20.0); let ts = screen(&mut h, to); h.step(&json!({"drag": [[f64::from(c.x) + 6.0, f64::from(c.y) + 4.0], [ts[0] + 6.0, ts[1] + 4.0]], "steps": 12})).unwrap(); @@ -87,6 +87,11 @@ fn each_placed_hole_has_its_own_marker_and_a_drag_moves_only_its_hole() { fn a_click_within_the_markers_reach_takes_the_hole_out() { let mut h = blocks(); h.step(&json!({"start": "solid.hole"})).unwrap(); + // A hole narrower than the click's 14 pt: a pick there that missed the marker would move the + // hole (a pick within the hole's radius takes it out too), so only the marker takes it out. + if let Some(crate::dialogs::Kind::Hole { diameter, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) { + *diameter = "0.5 mm".into(); + } let at = screen(&mut h, Vec3::new(10.0, 10.0, 20.0)); h.step(&json!({"click": at})).unwrap(); h.frames(2); From be92ffaed162cc568975937396ec924418ffbd58 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 29 Oct 2026 16:19:10 +0100 Subject: [PATCH 08/38] Placement handles: a place held still takes no press, so the view keeps the pointer there (#6818) A hole held by one reference edge seen nearly end-on (or its face edge-on) is drawn as the dot alone and registers no widget, but it was still listed as a drawn handle: navigation and the depth arrow yielded an 18 pt disc around it in which a drag did nothing. The drawn handles now say whether each takes a press; only those keep the pointer from navigation and the arrow, while the value box still keeps off every drawn dot. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/place_gizmo.rs | 15 ++++++++------- crates/ui-egui/src/place_gizmo/hole_tests.rs | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/place_gizmo.rs b/crates/ui-egui/src/place_gizmo.rs index 0a3092a3b34..e9183e8552f 100644 --- a/crates/ui-egui/src/place_gizmo.rs +++ b/crates/ui-egui/src/place_gizmo.rs @@ -150,9 +150,10 @@ static TOOLS: &[&Spec] = &[ ]; thread_local! { - /// Where the handles were drawn last frame (screen), for [`contains_pointer`]: navigation and - /// Select Other's press-and-hold run before the handles are drawn. - static DRAWN: std::cell::RefCell> = const { std::cell::RefCell::new(Vec::new()) }; + /// Where the handles were drawn last frame (screen), and whether each takes a press, for + /// [`contains_pointer`]: navigation and Select Other's press-and-hold run before the handles + /// are drawn. A place held still is drawn (the value box keeps off it) but takes no press. + static DRAWN: std::cell::RefCell> = const { std::cell::RefCell::new(Vec::new()) }; /// The ring's screen centre last frame, for [`yield_box`]. static RING_ABOUT: std::cell::Cell> = const { std::cell::Cell::new(None) }; } @@ -165,7 +166,7 @@ pub(crate) fn contains_pointer(app: &SolveApp, p: Pos2) -> bool { /// Is `p` within reach of a handle drawn last frame? For the dialog's own manipulators, which run /// before the handles and would otherwise take a press meant for a handle their stem crosses. pub(crate) fn drawn_at(p: Pos2) -> bool { - DRAWN.with(|h| h.borrow().iter().any(|c| c.distance(p) <= REACH)) + DRAWN.with(|h| h.borrow().iter().any(|(c, live)| *live && c.distance(p) <= REACH)) } /// The tool whose dialog this is, if it has handles and they are on. @@ -397,9 +398,9 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte let Some(bs) = proj.to_screen(pl.base) else { continue }; let name = if sp.many { format!("{}:{n}", sp.name) } else { format!("{}:position", sp.name) }; crate::scenario::publish_handle(&name, bs); - DRAWN.with(|h| h.borrow_mut().push(bs)); let dirs = arms(proj, pl.base, pl.n, bs, freedom_of(app, pl.key)); let held = dirs.is_empty(); + DRAWN.with(|h| h.borrow_mut().push((bs, !held))); let r = markers.iter().filter(|_| !held).find(|(m, _)| *m == marker).map(|(_, r)| r); let (hovered, dragging) = r.map_or((false, false), |r| (r.hovered(), r.dragged())); // The tip while pointing, not while dragging: the hand is busy and the footprint says it all. @@ -478,7 +479,7 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte } } crate::scenario::publish_handle(&format!("{}:rotate", sp.name), gs); - DRAWN.with(|h| h.borrow_mut().push(gs)); + DRAWN.with(|h| h.borrow_mut().push((gs, true))); let (hovered, dragging) = (r.hovered(), r.dragged()); ui.data_mut(|m| m.insert_temp(id("turning"), dragging)); RING_ABOUT.with(|c| c.set(Some(bs))); @@ -541,7 +542,7 @@ pub(crate) fn yield_box(ui: &egui::Ui, anchor: Pos2, at: Pos2) -> Pos2 { // starts, and the grip can never come under the box. Some(centre) => clear_of_circle(at, size, centre, RING_PX + RING_ROOM), None => { - let covers = |p: Pos2| DRAWN.with(|h| h.borrow().iter().any(|c| egui::Rect::from_min_size(p, size).expand(4.0).contains(*c))); + let covers = |p: Pos2| DRAWN.with(|h| h.borrow().iter().any(|(c, _)| egui::Rect::from_min_size(p, size).expand(4.0).contains(*c))); if covers(at) { let left = Pos2::new(anchor.x - (at.x - anchor.x) - size.x, at.y); let above = Pos2::new(at.x, anchor.y - 14.0 - size.y); diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index c65bdf4419d..22e76a0d2e5 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -289,3 +289,18 @@ fn the_hole_after_one_taken_out_does_not_take_over_its_hover() { h.frames(1); assert_eq!(crate::scenario::count_of("hole:0:hot"), Some(0.0), "not fading from the hole taken out"); } + +#[test] +fn a_held_marker_seen_end_on_leaves_the_pointer_to_the_view() { + // Seen from the front, the left edge the hole is held by runs straight into the screen: the + // marker is the dot alone and takes no press, so navigation is not kept from it either. + let mut h = held_by_the_left_edge(); + h.step(&json!({"call": "ui.view", "params": {"view": "front"}})).unwrap(); + h.settle(); + let c = handle_at("hole:0").expect("the held hole is still drawn"); + assert!(!crate::place_gizmo::contains_pointer(&h.app, c), "no press area, so the view keeps the pointer"); + h.step(&json!({"call": "ui.view", "params": {"view": "top"}})).unwrap(); + h.settle(); + let c = handle_at("hole:0").expect("the hole's marker"); + assert!(crate::place_gizmo::contains_pointer(&h.app, c), "seen from the top it drags along the edge again"); +} From 5266c7016e3801f715ea20dc38962524d9f2ea3c Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 29 Oct 2026 16:31:43 +0100 Subject: [PATCH 09/38] Hole: tests for the marker's cursor, Select Other yielding to it and the dragged footprint (#6818) The behaviour changes the change lists had no test: over a hole marker the cursor is Move (it was Grab), a press held still on it is the marker's and opens no Select Other list (without markers the same hold does), and the outline while a hole drags is its mouth, the counterbore's or countersink's diameter when it has one. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/place_gizmo/hole_tests.rs | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index 22e76a0d2e5..6acd3657f59 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -304,3 +304,59 @@ fn a_held_marker_seen_end_on_leaves_the_pointer_to_the_view() { let c = handle_at("hole:0").expect("the hole's marker"); assert!(crate::place_gizmo::contains_pointer(&h.app, c), "seen from the top it drags along the edge again"); } + +#[test] +fn over_a_hole_marker_the_cursor_is_move_and_select_other_yields_to_it() { + let mut h = blocks(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let at = screen(&mut h, Vec3::new(10.0, 10.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + h.frames(2); + let c = handle_at("hole:0").expect("a marker"); + let on = [f64::from(c.x) + 6.0, f64::from(c.y)]; + h.step(&json!({"move": on})).unwrap(); + h.frames(2); + assert_eq!(h.output.cursor_icon, egui::CursorIcon::Move, "the move cursor, as over the other markers"); + // Without markers, a hold there lists what is under the pointer. + crate::prefs::set(&mut h.app, &json!({"hole_moves": false})).unwrap(); + h.frames(2); + h.step(&json!({"hold": on})).unwrap(); + h.frames(2); + assert!(crate::select_other::is_open(&h.app), "no marker: Select Other opens there"); + h.step(&json!({"key": "Escape"})).unwrap(); + h.frames(2); + assert!(!crate::select_other::is_open(&h.app)); + assert_eq!(places(&h).len(), 1, "{:?}", places(&h)); + // With the marker, the press is the marker's: no list, and its release is the marker's click. + crate::prefs::set(&mut h.app, &json!({"hole_moves": true})).unwrap(); + h.frames(2); + h.step(&json!({"hold": on})).unwrap(); + h.frames(2); + assert!(!crate::select_other::is_open(&h.app), "Select Other yields to the marker"); + assert!(places(&h).is_empty(), "the marker took the press: {:?}", places(&h)); +} + +#[test] +fn the_dragged_footprint_is_the_holes_mouth() { + let mut h = blocks(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let base = Vec3::new(10.0, 10.0, 20.0); + let n = Vec3::new(0.0, 0.0, 1.0); + let radius = |h: &Harness| { + let d = h.app.dialog.as_ref().expect("a dialog is open"); + let pts = super::footprint(&h.app, d, base, n); + assert!(!pts.is_empty()); + pts.iter().map(|p| p.dist(base)).fold(0.0, f64::max) + }; + let set = |h: &mut Harness, k: usize| { + if let Some(crate::dialogs::Kind::Hole { diameter, kind, cb_diameter, cs_diameter, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) { + (*kind, *diameter, *cb_diameter, *cs_diameter) = (k, "4 mm".into(), "8 mm".into(), "12 mm".into()); + } + }; + set(&mut h, 0); + assert!((radius(&h) - 2.0).abs() < 1e-9, "a simple hole: the bore"); + set(&mut h, 1); + assert!((radius(&h) - 4.0).abs() < 1e-9, "a counterbore: its diameter"); + set(&mut h, 2); + assert!((radius(&h) - 6.0).abs() < 1e-9, "a countersink: its diameter"); +} From 7bc655d66ce1c92e15bcb33c9d7da35f3ab60ccb Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Nov 2026 00:56:18 +0100 Subject: [PATCH 10/38] Hole: a drag along one reference edge keeps the measured distance, not the rounded one in the field (#6818) drag_to placed the hole at the distance field's text, which shows a measured value rounded to the document's precision, while OK sends the measured value. It now reads each distance as sync does. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/hole_refs.rs | 2 +- crates/ui-egui/src/place_gizmo/hole_tests.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/hole_refs.rs b/crates/ui-egui/src/hole_refs.rs index b854a95db7e..c3b02924643 100644 --- a/crates/ui-egui/src/hole_refs.rs +++ b/crates/ui-egui/src/hole_refs.rs @@ -238,7 +238,7 @@ pub(crate) fn drag_to(s: &Session, d: &mut Dialog, i: usize, near: Vec3) -> bool return false; } let Kind::Hole { opts, .. } = &d.kind else { return false }; - let values: Option> = picked.iter().map(|k| opts.refs.distance.get(*k).and_then(|e| s.doc.eval(e, ValueKind::Length).ok())).collect(); + let values: Option> = picked.iter().map(|k| model_text(&opts.refs, *k).and_then(|e| s.doc.eval(e, ValueKind::Length).ok())).collect(); let Some(to) = values.and_then(|v| f.place(near, &v).ok()).filter(|c| on_reference_face(&crate::open_meshing::session_world(s), &f, *c)) else { return false; }; diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index 6acd3657f59..e68a0f5c8a8 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -210,6 +210,26 @@ fn a_typed_distance_survives_a_drag_along_the_edge() { assert!(matches!(places(&h).as_slice(), [p] if (p.x - 12.0).abs() < 1e-6 && (p.y - 24.0).abs() < 0.3), "{:?}", places(&h)); } +#[test] +fn a_measured_distance_finer_than_its_field_survives_a_drag_along_the_edge() { + let mut h = held_by_the_left_edge(); + // A place a few micrometres off the whole millimetre: the field shows 10.00 mm, the model + // keeps the measured value. + if let Some(Sel::Face { point, .. }) = h.app.dialog.as_mut().and_then(|d| d.inputs.first_mut()).and_then(|i| i.items.first_mut()) { + *point = Vec3::new(10.0034, 10.0, 20.0); + } + h.frames(2); + assert_eq!(distances(&h)[0], "10.00 mm"); + let to = screen(&mut h, Vec3::new(25.0, 22.0, 20.0)); + h.step(&json!({"drag": [{"handle": "hole:0"}, to], "steps": 12})).unwrap(); + h.settle(); + assert!( + matches!(places(&h).as_slice(), [p] if (p.x - 10.0034).abs() < 1e-6 && (p.y - 22.0).abs() < 0.3), + "the measured distance, not the shown one: {:?}", + places(&h) + ); +} + #[test] fn a_pick_elsewhere_on_the_face_keeps_a_held_hole_on_its_line() { let mut h = held_by_the_left_edge(); From c2725f34da812cf16b17568bc39844807e3f166b Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Nov 2026 01:39:44 +0100 Subject: [PATCH 11/38] Hole: a held hole's freedom follows a design change in the same frame (#6818) freedom read the reference frame cached for the edges without its revision, so in the frame after the design changed it could still hold the hole to an edge that was gone. It now finds the frame again when the revision moved on. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/hole_place.rs | 2 +- crates/ui-egui/src/hole_refs.rs | 24 ++++++++++++-------- crates/ui-egui/src/place_gizmo/hole.rs | 4 ++-- crates/ui-egui/src/place_gizmo/hole_tests.rs | 10 ++++++++ 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/hole_place.rs b/crates/ui-egui/src/hole_place.rs index 2baaf96fac5..93119cd09d6 100644 --- a/crates/ui-egui/src/hole_place.rs +++ b/crates/ui-egui/src/hole_place.rs @@ -261,7 +261,7 @@ pub(crate) fn pick_moves(d: &mut Dialog, s: &Session, sel: &Sel) -> bool { if was.dist(*point) <= radius { return false; } - match crate::hole_refs::freedom(d, i) { + match crate::hole_refs::freedom(s, d, i) { crate::place_gizmo::Freedom::Plane => move_place(d, s, i, sel.clone()), crate::place_gizmo::Freedom::Line(_) => { crate::hole_refs::drag_to(s, d, i, *point); diff --git a/crates/ui-egui/src/hole_refs.rs b/crates/ui-egui/src/hole_refs.rs index c3b02924643..479132a450e 100644 --- a/crates/ui-egui/src/hole_refs.rs +++ b/crates/ui-egui/src/hole_refs.rs @@ -189,17 +189,22 @@ fn frame(s: &Session, d: &mut Dialog) -> Option<(ReferenceFrame, Vec)> { { return f.frame.clone(); } - let picked: Vec<(usize, Vec3)> = edges.iter().enumerate().filter_map(|(k, e)| e.map(|p| (k, p))).collect(); - let found = direction(s, d, at).and_then(|dir| { - let pts: Vec<(Vec3, Option<&str>)> = picked.iter().map(|(_, p)| (*p, None)).collect(); - reference_frame(&crate::open_meshing::session_world(s), at, dir, &pts, true).ok().map(|f| (f, picked.iter().map(|(k, _)| *k).collect())) - }); + let found = framed(s, d, at, edges); if let Some(refs) = refs_mut(d) { refs.frame = Some(Framed { revision: s.revision, place: at, edges, frame: found.clone() }); } found } +/// The face's frame at `at` for `edges`, found from the model as it is now. +fn framed(s: &Session, d: &Dialog, at: Vec3, edges: [Option; 2]) -> Option<(ReferenceFrame, Vec)> { + let picked: Vec<(usize, Vec3)> = edges.iter().enumerate().filter_map(|(k, e)| e.map(|p| (k, p))).collect(); + direction(s, d, at).and_then(|dir| { + let pts: Vec<(Vec3, Option<&str>)> = picked.iter().map(|(_, p)| (*p, None)).collect(); + reference_frame(&crate::open_meshing::session_world(s), at, dir, &pts, true).ok().map(|f| (f, picked.iter().map(|(k, _)| *k).collect())) + }) +} + /// The face input's item the reference edges place: the first face pick (see [`place`]). The /// edges place that one hole only; OK refuses them with more than one. fn place_item(d: &Dialog) -> Option { @@ -210,16 +215,17 @@ fn place_item(d: &Dialog) -> Option { /// one edge, along it at its distance; with two, anywhere again, a move then setting both /// distances (as it did before any edge was picked); with none, anywhere. Only the hole the edges /// place (see [`place_item`]) is held; another hole in the same dialog moves anywhere. Read from -/// the frame last found for these edges (`sync` keeps it current); an edge picked but not framed -/// yet, or a frame that failed, leaves the hole free. -pub(crate) fn freedom(d: &Dialog, i: usize) -> Freedom { +/// the frame last found for these edges (`sync` keeps it current), or found again when the design +/// changed since; an edge picked but not framed yet, or a frame that failed, leaves the hole free. +pub(crate) fn freedom(s: &Session, d: &Dialog, i: usize) -> Freedom { let Kind::Hole { opts, .. } = &d.kind else { return Freedom::Plane }; if place_item(d) != Some(i) { return Freedom::Plane; } let edges = edges(d); let Some(f) = opts.refs.frame.as_ref().filter(|f| f.edges == edges) else { return Freedom::Plane }; - match f.frame.as_ref().map(|(fr, _)| fr.lines.as_slice()) { + let fresh = if f.revision == s.revision { None } else { Some(place(d).and_then(|at| framed(s, d, at, edges))) }; + match fresh.as_ref().unwrap_or(&f.frame).as_ref().map(|(fr, _)| fr.lines.as_slice()) { Some([a]) => Freedom::Line(a.along), _ => Freedom::Plane, } diff --git a/crates/ui-egui/src/place_gizmo/hole.rs b/crates/ui-egui/src/place_gizmo/hole.rs index 62748ec922d..61671a89011 100644 --- a/crates/ui-egui/src/place_gizmo/hole.rs +++ b/crates/ui-egui/src/place_gizmo/hole.rs @@ -28,7 +28,7 @@ pub(super) static SPEC: Spec = Spec { move_to, click: Some(|app, d, key| crate::hole_place::remove_place(d, &app.session, key)), footprint, - freedom: |_, d, key| crate::hole_refs::freedom(d, key), + freedom: |app, d, key| crate::hole_refs::freedom(&app.session, d, key), turn: None, }; @@ -56,7 +56,7 @@ fn places(app: &SolveApp, d: &Dialog) -> Vec { fn move_to(app: &SolveApp, d: &mut Dialog, hits: &[Hit], key: usize) -> bool { let s = &app.session; let Some(to) = face_pick(d, s, hits) else { return false }; - match crate::hole_refs::freedom(d, key) { + match crate::hole_refs::freedom(s, d, key) { Freedom::Plane => crate::hole_place::move_place(d, s, key, to), Freedom::Line(_) => match to { Sel::Face { point, .. } => crate::hole_refs::drag_to(s, d, key, point), diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index e68a0f5c8a8..f3bac04fc15 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -230,6 +230,16 @@ fn a_measured_distance_finer_than_its_field_survives_a_drag_along_the_edge() { ); } +#[test] +fn a_design_change_frees_a_held_hole_whose_edge_is_gone_in_the_same_frame() { + let mut h = held_by_the_left_edge(); + assert!(matches!(crate::hole_refs::freedom(&h.app.session, h.app.dialog.as_ref().expect("a dialog"), 0), crate::place_gizmo::Freedom::Line(_))); + // Cut the block's left 5 mm away while the dialog is open: the reference edge is gone. + h.app.run("solid.box", json!({"length": 5, "width": 40, "height": 30, "corner": [-1, -5, -5], "operation": "cut"})).unwrap(); + let d = h.app.dialog.as_ref().expect("the dialog stays open"); + assert!(matches!(crate::hole_refs::freedom(&h.app.session, d, 0), crate::place_gizmo::Freedom::Plane), "no edge to hold the hole to any more"); +} + #[test] fn a_pick_elsewhere_on_the_face_keeps_a_held_hole_on_its_line() { let mut h = held_by_the_left_edge(); From e93ec9e8639ff195936ea458273cd18101188c55 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Nov 2026 09:51:19 +0100 Subject: [PATCH 12/38] Hole: a pick a held hole's line cannot reach says why instead of doing nothing (#6818) With one reference edge, a pick elsewhere on the face moves the hole along the edge's line. On a face the line leaves before the pick (an L-shaped face, say), the pick did nothing and said nothing; the dialog now says the line leaves the face there and how to move the hole. Co-Authored-By: Claude Opus 5.5 --- .../pending/hole-held-off-its-line.json | 20 ++++++++++++++ crates/ui-egui/src/hole_place.rs | 10 +++++-- crates/ui-egui/src/place_gizmo/hole_tests.rs | 27 +++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 assets/locales/pending/hole-held-off-its-line.json diff --git a/assets/locales/pending/hole-held-off-its-line.json b/assets/locales/pending/hole-held-off-its-line.json new file mode 100644 index 00000000000..3b355579431 --- /dev/null +++ b/assets/locales/pending/hole-held-off-its-line.json @@ -0,0 +1,20 @@ +{ + "en": { + "dialog.hole_held_off_its_line": "The reference edge holds this hole on a line that leaves the face before the picked point. Pick nearer the line, or take the edge out to move the hole freely." + }, + "ar": { + "dialog.hole_held_off_its_line": "الحافة المرجعية تُبقي هذا الثقب على خط يغادر الوجه قبل النقطة المختارة. اختر نقطة أقرب إلى الخط، أو أزل الحافة لتحريك الثقب بحرية." + }, + "he": { + "dialog.hole_held_off_its_line": "קצה הייחוס מחזיק את החור על קו שיוצא מהפאה לפני הנקודה שנבחרה. יש לבחור קרוב יותר לקו, או להסיר את הקצה כדי להזיז את החור בחופשיות." + }, + "ja": { + "dialog.hole_held_off_its_line": "参照エッジがこの穴を直線上に固定していますが、その直線は選択した点より手前で面の外に出ます。直線の近くを選択するか、エッジを外すと穴を自由に移動できます。" + }, + "vi": { + "dialog.hole_held_off_its_line": "Cạnh tham chiếu giữ lỗ này trên một đường thẳng ra khỏi mặt trước điểm đã chọn. Hãy chọn gần đường hơn, hoặc bỏ cạnh để di chuyển lỗ tự do." + }, + "zh": { + "dialog.hole_held_off_its_line": "参考边将此孔固定在一条直线上,该直线在所选点之前就离开了该面。请在靠近直线处选取,或移除该边以自由移动孔。" + } +} diff --git a/crates/ui-egui/src/hole_place.rs b/crates/ui-egui/src/hole_place.rs index 93119cd09d6..13cd88c1b46 100644 --- a/crates/ui-egui/src/hole_place.rs +++ b/crates/ui-egui/src/hole_place.rs @@ -243,10 +243,14 @@ pub(crate) fn move_place(d: &mut Dialog, s: &Session, i: usize, to: Sel) -> bool true } +/// Why a pick did not move a hole one reference edge holds: its line leaves the face first. +pub(crate) const HELD_OFF_ITS_LINE: &str = "The reference edge holds this hole on a line that leaves the face before the picked point. Pick nearer the line, or take the edge out to move the hole freely."; + /// A Single hole's face place picked on a face that already has a hole moves that hole there /// (true), when holes move by clicking. A pick on the hole itself (within its radius) is left to /// take it out, as before. A hole held along one reference edge goes along it only, and the pick -/// is spent either way (it never takes the hole out instead). +/// is spent either way (it never takes the hole out instead): when the line leaves the face before +/// the pick, the dialog says so. pub(crate) fn pick_moves(d: &mut Dialog, s: &Session, sel: &Sel) -> bool { let Kind::Hole { opts, diameter, .. } = &d.kind else { return false }; let Sel::Face { point, .. } = sel else { return false }; @@ -264,7 +268,9 @@ pub(crate) fn pick_moves(d: &mut Dialog, s: &Session, sel: &Sel) -> bool { match crate::hole_refs::freedom(s, d, i) { crate::place_gizmo::Freedom::Plane => move_place(d, s, i, sel.clone()), crate::place_gizmo::Freedom::Line(_) => { - crate::hole_refs::drag_to(s, d, i, *point); + if !crate::hole_refs::drag_to(s, d, i, *point) { + d.error = Some(HELD_OFF_ITS_LINE.to_string()); + } true } } diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index f3bac04fc15..af5b1e7931f 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -251,6 +251,33 @@ fn a_pick_elsewhere_on_the_face_keeps_a_held_hole_on_its_line() { assert!(matches!(p.as_slice(), [p] if (p.x - 10.0).abs() < 1e-6 && (p.y - 25.0).abs() < 0.3), "moved along the edge only: {p:?}"); } +/// On an L-shaped face the held hole's line can leave the face before the pick: the hole stays, +/// and the dialog says why instead of taking the pick without a word. +#[test] +fn a_pick_the_held_line_cannot_reach_says_why_and_leaves_the_hole() { + let mut h = blocks(); + // A notch out of the first block's back left corner: its top is an L. + h.app.run("solid.box", json!({"length": 21, "width": 16, "height": 22, "corner": [-1, 15, -1], "operation": "cut"})).unwrap(); + h.settle(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let at = screen(&mut h, Vec3::new(10.0, 5.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + h.step(&json!({"click": {"handle": "dialog:Reference 1"}})).unwrap(); + let left = screen(&mut h, Vec3::new(0.0, 7.0, 20.0)); + h.step(&json!({"click": left})).unwrap(); + h.settle(); + let before = places(&h); + assert!(matches!(before.as_slice(), [p] if p.dist(Vec3::new(10.0, 5.0, 20.0)) < 0.3), "{before:?}"); + h.step(&json!({"click": {"handle": "dialog:Face"}})).unwrap(); + // Along the edge from here is the notch: the line at x = 10 has no face at y = 25. + let at = screen(&mut h, Vec3::new(30.0, 25.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + h.settle(); + assert_eq!(places(&h), before, "the hole stays on its line"); + let error = h.app.dialog.as_ref().and_then(|d| d.error.clone()); + assert_eq!(error.as_deref(), Some(crate::hole_place::HELD_OFF_ITS_LINE), "the dialog says why"); +} + #[test] fn two_reference_edges_free_the_hole_again_and_a_drag_sets_both_distances() { let mut h = held_by_the_left_edge(); From 5fe383e77d10187afaeff563d16843b0b0592c4b Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Nov 2026 10:29:54 +0100 Subject: [PATCH 13/38] Hole: a held hole that cannot follow says so on a drag too, until the inputs change (#6818) The message for a pick the held line cannot reach is now set through the dialog's refusal, so a changed distance or edge clears it; the marker drag gives it as well; it is shown only when the line leaves the face, not when the distance does not evaluate (which has its own error); and it tells where to pick: where the line crosses the face. Co-Authored-By: Claude Opus 5.5 --- .../pending/hole-held-off-its-line.json | 12 ++-- crates/ui-egui/src/dialogs.rs | 2 +- crates/ui-egui/src/hole_place.rs | 46 +++++++++----- crates/ui-egui/src/hole_refs.rs | 34 ++++++---- crates/ui-egui/src/place_gizmo/hole.rs | 12 +++- crates/ui-egui/src/place_gizmo/hole_tests.rs | 62 ++++++++++++++++--- crates/ui-egui/src/viewport.rs | 41 ++++++++---- 7 files changed, 148 insertions(+), 61 deletions(-) diff --git a/assets/locales/pending/hole-held-off-its-line.json b/assets/locales/pending/hole-held-off-its-line.json index 3b355579431..30b9da869d9 100644 --- a/assets/locales/pending/hole-held-off-its-line.json +++ b/assets/locales/pending/hole-held-off-its-line.json @@ -1,20 +1,20 @@ { "en": { - "dialog.hole_held_off_its_line": "The reference edge holds this hole on a line that leaves the face before the picked point. Pick nearer the line, or take the edge out to move the hole freely." + "dialog.hole_held_off_its_line": "The reference edge holds this hole on a line that leaves the face before the picked point. Pick where the line crosses the face, or take the edge out to move the hole freely." }, "ar": { - "dialog.hole_held_off_its_line": "الحافة المرجعية تُبقي هذا الثقب على خط يغادر الوجه قبل النقطة المختارة. اختر نقطة أقرب إلى الخط، أو أزل الحافة لتحريك الثقب بحرية." + "dialog.hole_held_off_its_line": "الحافة المرجعية تُبقي هذا الثقب على خط يغادر الوجه قبل النقطة المختارة. اختر حيث يعبر الخط الوجه، أو أزل الحافة لتحريك الثقب بحرية." }, "he": { - "dialog.hole_held_off_its_line": "קצה הייחוס מחזיק את החור על קו שיוצא מהפאה לפני הנקודה שנבחרה. יש לבחור קרוב יותר לקו, או להסיר את הקצה כדי להזיז את החור בחופשיות." + "dialog.hole_held_off_its_line": "קצה הייחוס מחזיק את החור על קו שיוצא מהפאה לפני הנקודה שנבחרה. יש לבחור במקום שבו הקו עובר על הפאה, או להסיר את הקצה כדי להזיז את החור בחופשיות." }, "ja": { - "dialog.hole_held_off_its_line": "参照エッジがこの穴を直線上に固定していますが、その直線は選択した点より手前で面の外に出ます。直線の近くを選択するか、エッジを外すと穴を自由に移動できます。" + "dialog.hole_held_off_its_line": "参照エッジがこの穴を直線上に固定していますが、その直線は選択した点より手前で面の外に出ます。直線が面の上を通る位置を選択するか、エッジを外すと穴を自由に移動できます。" }, "vi": { - "dialog.hole_held_off_its_line": "Cạnh tham chiếu giữ lỗ này trên một đường thẳng ra khỏi mặt trước điểm đã chọn. Hãy chọn gần đường hơn, hoặc bỏ cạnh để di chuyển lỗ tự do." + "dialog.hole_held_off_its_line": "Cạnh tham chiếu giữ lỗ này trên một đường thẳng ra khỏi mặt trước điểm đã chọn. Hãy chọn chỗ đường thẳng đi qua mặt, hoặc bỏ cạnh để di chuyển lỗ tự do." }, "zh": { - "dialog.hole_held_off_its_line": "参考边将此孔固定在一条直线上,该直线在所选点之前就离开了该面。请在靠近直线处选取,或移除该边以自由移动孔。" + "dialog.hole_held_off_its_line": "参考边将此孔固定在一条直线上,该直线在所选点之前就离开了该面。请在直线经过该面的位置选取,或移除该边以自由移动孔。" } } diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 351ce8fef2e..231b258e132 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -788,7 +788,7 @@ impl Dialog { } /// Show why OK (or starting the sketch) was refused, for as long as the inputs stay as they are. - fn refuse(&mut self, app: &SolveApp, error: String) { + pub(crate) fn refuse(&mut self, app: &SolveApp, error: String) { self.refused = Some(Refused::now(app, self)); self.error = Some(error); } diff --git a/crates/ui-egui/src/hole_place.rs b/crates/ui-egui/src/hole_place.rs index 13cd88c1b46..97555b6a4a7 100644 --- a/crates/ui-egui/src/hole_place.rs +++ b/crates/ui-egui/src/hole_place.rs @@ -243,36 +243,48 @@ pub(crate) fn move_place(d: &mut Dialog, s: &Session, i: usize, to: Sel) -> bool true } +/// What a pick on a face with a hole did to that hole (see [`pick_moves`]). +pub(crate) enum PickMove { + /// Not a move: the pick goes to the dialog as any pick does. + No, + Moved, + /// Spent, the hole left where it is (the dialog already says why, if anything does). + Spent, + /// Spent, the hole left where it is, and why. + Refused(&'static str), +} + /// Why a pick did not move a hole one reference edge holds: its line leaves the face first. -pub(crate) const HELD_OFF_ITS_LINE: &str = "The reference edge holds this hole on a line that leaves the face before the picked point. Pick nearer the line, or take the edge out to move the hole freely."; +pub(crate) const HELD_OFF_ITS_LINE: &str = "The reference edge holds this hole on a line that leaves the face before the picked point. Pick where the line crosses the face, or take the edge out to move the hole freely."; /// A Single hole's face place picked on a face that already has a hole moves that hole there /// (true), when holes move by clicking. A pick on the hole itself (within its radius) is left to /// take it out, as before. A hole held along one reference edge goes along it only, and the pick /// is spent either way (it never takes the hole out instead): when the line leaves the face before -/// the pick, the dialog says so. -pub(crate) fn pick_moves(d: &mut Dialog, s: &Session, sel: &Sel) -> bool { - let Kind::Hole { opts, diameter, .. } = &d.kind else { return false }; - let Sel::Face { point, .. } = sel else { return false }; +/// the pick, it is refused with why. +pub(crate) fn pick_moves(d: &mut Dialog, s: &Session, sel: &Sel) -> PickMove { + let Kind::Hole { opts, diameter, .. } = &d.kind else { return PickMove::No }; + let Sel::Face { point, .. } = sel else { return PickMove::No }; if opts.multiple || d.active != 0 { - return false; + return PickMove::No; } let radius = s.doc.eval(diameter, ValueKind::Length).ok().filter(|v| v.is_finite() && *v > 0.0).map_or(0.0, |v| v / 2.0); let group = crate::viewport::grouped_selection(s, sel); - let Some(inp) = d.inputs.first() else { return false }; - let Some(i) = inp.items.iter().position(|x| group.iter().any(|g| same_item(x, g))) else { return false }; - let Some(Sel::Face { point: was, .. }) = inp.items.get(i) else { return false }; + let Some(inp) = d.inputs.first() else { return PickMove::No }; + let Some(i) = inp.items.iter().position(|x| group.iter().any(|g| same_item(x, g))) else { return PickMove::No }; + let Some(Sel::Face { point: was, .. }) = inp.items.get(i) else { return PickMove::No }; if was.dist(*point) <= radius { - return false; + return PickMove::No; } match crate::hole_refs::freedom(s, d, i) { - crate::place_gizmo::Freedom::Plane => move_place(d, s, i, sel.clone()), - crate::place_gizmo::Freedom::Line(_) => { - if !crate::hole_refs::drag_to(s, d, i, *point) { - d.error = Some(HELD_OFF_ITS_LINE.to_string()); - } - true - } + crate::place_gizmo::Freedom::Plane if move_place(d, s, i, sel.clone()) => PickMove::Moved, + crate::place_gizmo::Freedom::Plane => PickMove::No, + crate::place_gizmo::Freedom::Line(_) => match crate::hole_refs::drag_to(s, d, i, *point) { + Ok(()) => PickMove::Moved, + Err(crate::hole_refs::Stuck::OffFace) => PickMove::Refused(HELD_OFF_ITS_LINE), + // A distance that does not evaluate shows its own error. + Err(crate::hole_refs::Stuck::Not) => PickMove::Spent, + }, } } diff --git a/crates/ui-egui/src/hole_refs.rs b/crates/ui-egui/src/hole_refs.rs index 479132a450e..7c1a3c3bf26 100644 --- a/crates/ui-egui/src/hole_refs.rs +++ b/crates/ui-egui/src/hole_refs.rs @@ -231,24 +231,34 @@ pub(crate) fn freedom(s: &Session, d: &Dialog, i: usize) -> Freedom { } } +/// Why [`drag_to`] left the hole where it was. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(crate) enum Stuck { + /// The line the edge holds the hole on leaves the face before the point asked for. + OffFace, + /// Anything else: not the hole the edges place, no frame, not exactly one edge, or a distance + /// that does not evaluate (which shows its own error). + Not, +} + /// Move the hole at item `i` of the face input toward `near` as far as its one reference edge /// lets it: onto the line at the typed distance from it, nearest `near`. The typed distance -/// stays as it is, an expression included, so a drag never rewrites it. False when the hole -/// cannot go there (off its face, no frame, not exactly one edge, or not the hole the edges place). -pub(crate) fn drag_to(s: &Session, d: &mut Dialog, i: usize, near: Vec3) -> bool { +/// stays as it is, an expression included, so a drag never rewrites it. +pub(crate) fn drag_to(s: &Session, d: &mut Dialog, i: usize, near: Vec3) -> Result<(), Stuck> { if place_item(d) != Some(i) { - return false; + return Err(Stuck::Not); } - let Some((f, picked)) = frame(s, d) else { return false }; + let Some((f, picked)) = frame(s, d) else { return Err(Stuck::Not) }; if picked.len() != 1 { - return false; + return Err(Stuck::Not); } - let Kind::Hole { opts, .. } = &d.kind else { return false }; + let Kind::Hole { opts, .. } = &d.kind else { return Err(Stuck::Not) }; let values: Option> = picked.iter().map(|k| model_text(&opts.refs, *k).and_then(|e| s.doc.eval(e, ValueKind::Length).ok())).collect(); - let Some(to) = values.and_then(|v| f.place(near, &v).ok()).filter(|c| on_reference_face(&crate::open_meshing::session_world(s), &f, *c)) else { - return false; - }; - let Some(Sel::Face { point, .. }) = d.inputs.first_mut().and_then(|inp| inp.items.get_mut(i)) else { return false }; + let Some(to) = values.and_then(|v| f.place(near, &v).ok()) else { return Err(Stuck::Not) }; + if !on_reference_face(&crate::open_meshing::session_world(s), &f, to) { + return Err(Stuck::OffFace); + } + let Some(Sel::Face { point, .. }) = d.inputs.first_mut().and_then(|inp| inp.items.get_mut(i)) else { return Err(Stuck::Not) }; *point = to; // In step already: the place moved by its distances, so there is nothing to measure again. let edges = edges(d); @@ -259,7 +269,7 @@ pub(crate) fn drag_to(s: &Session, d: &mut Dialog, i: usize, near: Vec3) -> bool sn.edges = edges; } d.error = None; - true + Ok(()) } /// Keep the distances and the hole's place in step: a new place or a new edge is measured, a diff --git a/crates/ui-egui/src/place_gizmo/hole.rs b/crates/ui-egui/src/place_gizmo/hole.rs index 61671a89011..7d2085e3f88 100644 --- a/crates/ui-egui/src/place_gizmo/hole.rs +++ b/crates/ui-egui/src/place_gizmo/hole.rs @@ -52,14 +52,22 @@ fn places(app: &SolveApp, d: &Dialog) -> Vec { /// The hole at `key` moved to the face place a click with `hits` would take (snapped as the /// pick is), unless that face already has another hole; held by a reference edge, as far along -/// the edge as the pick is. +/// the edge as the pick is, and where the edge's line leaves the face first, refused with why. fn move_to(app: &SolveApp, d: &mut Dialog, hits: &[Hit], key: usize) -> bool { let s = &app.session; let Some(to) = face_pick(d, s, hits) else { return false }; match crate::hole_refs::freedom(s, d, key) { Freedom::Plane => crate::hole_place::move_place(d, s, key, to), Freedom::Line(_) => match to { - Sel::Face { point, .. } => crate::hole_refs::drag_to(s, d, key, point), + Sel::Face { point, .. } => match crate::hole_refs::drag_to(s, d, key, point) { + Ok(()) => true, + // As a pick there says (see `hole_place::pick_moves`), until the inputs change. + Err(crate::hole_refs::Stuck::OffFace) => { + d.refuse(app, crate::hole_place::HELD_OFF_ITS_LINE.to_string()); + false + } + Err(crate::hole_refs::Stuck::Not) => false, + }, _ => false, }, } diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index af5b1e7931f..5ae1c978e27 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -251,12 +251,11 @@ fn a_pick_elsewhere_on_the_face_keeps_a_held_hole_on_its_line() { assert!(matches!(p.as_slice(), [p] if (p.x - 10.0).abs() < 1e-6 && (p.y - 25.0).abs() < 0.3), "moved along the edge only: {p:?}"); } -/// On an L-shaped face the held hole's line can leave the face before the pick: the hole stays, -/// and the dialog says why instead of taking the pick without a word. -#[test] -fn a_pick_the_held_line_cannot_reach_says_why_and_leaves_the_hole() { +/// A hole at (10, 5) on the first block's top, held by its left edge, the top an L: a notch out of +/// the back left corner, so along the edge from (30, 25) is the notch (the line x = 10 has no face +/// at y = 25). The Face input is active again. +fn held_on_an_l() -> Harness { let mut h = blocks(); - // A notch out of the first block's back left corner: its top is an L. h.app.run("solid.box", json!({"length": 21, "width": 16, "height": 22, "corner": [-1, 15, -1], "operation": "cut"})).unwrap(); h.settle(); h.step(&json!({"start": "solid.hole"})).unwrap(); @@ -266,16 +265,59 @@ fn a_pick_the_held_line_cannot_reach_says_why_and_leaves_the_hole() { let left = screen(&mut h, Vec3::new(0.0, 7.0, 20.0)); h.step(&json!({"click": left})).unwrap(); h.settle(); - let before = places(&h); - assert!(matches!(before.as_slice(), [p] if p.dist(Vec3::new(10.0, 5.0, 20.0)) < 0.3), "{before:?}"); + assert!(matches!(places(&h).as_slice(), [p] if p.dist(Vec3::new(10.0, 5.0, 20.0)) < 0.3), "{:?}", places(&h)); h.step(&json!({"click": {"handle": "dialog:Face"}})).unwrap(); - // Along the edge from here is the notch: the line at x = 10 has no face at y = 25. + h +} + +fn error(h: &Harness) -> Option { + h.app.dialog.as_ref().and_then(|d| d.error.clone()) +} + +/// On an L-shaped face the held hole's line can leave the face before the pick: the hole stays, +/// and the dialog says why (until the inputs change) instead of taking the pick without a word. +#[test] +fn a_pick_the_held_line_cannot_reach_says_why_and_leaves_the_hole() { + let mut h = held_on_an_l(); + let before = places(&h); let at = screen(&mut h, Vec3::new(30.0, 25.0, 20.0)); h.step(&json!({"click": at})).unwrap(); h.settle(); assert_eq!(places(&h), before, "the hole stays on its line"); - let error = h.app.dialog.as_ref().and_then(|d| d.error.clone()); - assert_eq!(error.as_deref(), Some(crate::hole_place::HELD_OFF_ITS_LINE), "the dialog says why"); + assert_eq!(error(&h).as_deref(), Some(crate::hole_place::HELD_OFF_ITS_LINE), "the dialog says why"); + // A typed distance changes what the dialog makes: the message gives way. + h.step(&json!({"click": {"handle": "dialog:Distance 1"}})).unwrap(); + h.step(&json!({"key": "A", "cmd": true})).unwrap(); + h.step(&json!({"text": "12"})).unwrap(); + h.frames(3); + assert_eq!(error(&h), None, "a changed distance clears it"); +} + +/// The marker dragged where the held line cannot follow says the same. +#[test] +fn a_marker_drag_the_held_line_cannot_follow_says_why() { + let mut h = held_on_an_l(); + let before = places(&h); + let to = screen(&mut h, Vec3::new(30.0, 25.0, 20.0)); + h.step(&json!({"drag": [{"handle": "hole:0"}, to], "steps": 1})).unwrap(); + h.settle(); + assert_eq!(places(&h), before, "the hole stays on its line"); + assert_eq!(error(&h).as_deref(), Some(crate::hole_place::HELD_OFF_ITS_LINE), "the dialog says why"); +} + +/// A distance that does not evaluate is its own error: a pick does not blame the face for it. +#[test] +fn a_pick_with_an_unreadable_distance_does_not_blame_the_face() { + let mut h = held_on_an_l(); + h.step(&json!({"click": {"handle": "dialog:Distance 1"}})).unwrap(); + h.step(&json!({"key": "A", "cmd": true})).unwrap(); + h.step(&json!({"text": "nonsense"})).unwrap(); + h.frames(3); + h.step(&json!({"click": {"handle": "dialog:Face"}})).unwrap(); + let at = screen(&mut h, Vec3::new(30.0, 25.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + h.settle(); + assert_ne!(error(&h).as_deref(), Some(crate::hole_place::HELD_OFF_ITS_LINE), "{:?}", error(&h)); } #[test] diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index 1c4137df321..f7cf1287791 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -3739,20 +3739,35 @@ pub(crate) fn dialog_pick(app: &mut SolveApp, hit: &Hit, sel: Sel) { let Some(mut d) = app.dialog.take() else { return }; // With several holes on a face (Preferences), a Single hole's pick adds a hole or takes one // out; with holes moving by clicking, a Single hole picked again on its face moves there. - if crate::hole_place::pick_several(app, &mut d, &sel) || (app.preferences.hole_moves && crate::hole_place::pick_moves(&mut d, &app.session, &sel)) - { - d.focus = true; - d.awaiting_pick = false; - d.pick_refused = None; - } else if crate::sketch_modify_ui::picks_entity(&d, &app.session, hit) { - // A curve the mirror line, centre or direction refuses joins the Entities list, and the - // window stays on the input it was on (#11700). - let on = d.active; - d.active = 0; - d.pick(&app.session, sel); - d.active = on; + let picked = if crate::hole_place::pick_several(app, &mut d, &sel) { + crate::hole_place::PickMove::Moved + } else if app.preferences.hole_moves { + crate::hole_place::pick_moves(&mut d, &app.session, &sel) } else { - d.pick(&app.session, sel); + crate::hole_place::PickMove::No + }; + match picked { + crate::hole_place::PickMove::No if crate::sketch_modify_ui::picks_entity(&d, &app.session, hit) => { + // A curve the mirror line, centre or direction refuses joins the Entities list, and the + // window stays on the input it was on (#11700). + let on = d.active; + d.active = 0; + d.pick(&app.session, sel); + d.active = on; + } + crate::hole_place::PickMove::No => d.pick(&app.session, sel), + crate::hole_place::PickMove::Moved | crate::hole_place::PickMove::Spent => { + d.focus = true; + d.awaiting_pick = false; + d.pick_refused = None; + } + // Shown until the inputs change, as a refused OK is. + crate::hole_place::PickMove::Refused(why) => { + d.focus = true; + d.awaiting_pick = false; + d.pick_refused = None; + d.refuse(app, why.to_string()); + } } if let crate::dialogs::Kind::PathPlane { sketch, .. } = &mut d.kind { *sketch = match hit { From 045a8917a8bc465c0100d9c121aa9affeab1d622 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Nov 2026 12:27:05 +0100 Subject: [PATCH 14/38] Hole: a hole on a curved face keeps its marker, standing on the face's normal where it is (#6818) Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs_assembly.rs | 2 +- crates/ui-egui/src/place_gizmo/hole.rs | 11 +++++++--- crates/ui-egui/src/place_gizmo/hole_tests.rs | 21 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/dialogs_assembly.rs b/crates/ui-egui/src/dialogs_assembly.rs index 19de666d60a..3c3f514382a 100644 --- a/crates/ui-egui/src/dialogs_assembly.rs +++ b/crates/ui-egui/src/dialogs_assembly.rs @@ -659,7 +659,7 @@ fn straight_edge_axis(pts: &[Vec3]) -> Option { } /// Normal of the mesh face `f` near `p`. -fn face_normal_near(m: &Mesh, f: u32, p: Vec3) -> Option { +pub(crate) fn face_normal_near(m: &Mesh, f: u32, p: Vec3) -> Option { m.triangles .iter() .zip(&m.tri_face) diff --git a/crates/ui-egui/src/place_gizmo/hole.rs b/crates/ui-egui/src/place_gizmo/hole.rs index 7d2085e3f88..4cf64b41701 100644 --- a/crates/ui-egui/src/place_gizmo/hole.rs +++ b/crates/ui-egui/src/place_gizmo/hole.rs @@ -32,9 +32,9 @@ pub(super) static SPEC: Spec = Spec { turn: None, }; -/// The holes placed so far, each at its face place with the face's outward normal. A hole being -/// edited whose face is gone keeps its place and the `direction` the edit restored, as a Rest's -/// frame does, so it still has a marker. +/// The holes placed so far, each at its face place with the face's outward normal (on a curved +/// face, the normal where the hole is). A hole being edited whose face is gone keeps its place +/// and the `direction` the edit restored, as a Rest's frame does, so it still has a marker. fn places(app: &SolveApp, d: &Dialog) -> Vec { let s = &app.session; crate::hole_place::places(s, d) @@ -44,6 +44,11 @@ fn places(app: &SolveApp, d: &Dialog) -> Vec { let n = crate::dialogs::planar_face(s, body, *index) .map(|(_, n)| n) .or_else(|| d.extra.get("direction").and_then(vec3_of)) + .or_else(|| { + // A curved face: its normal where the hole is. + let m = crate::open_meshing::session_world(s).body(body)?.mesh(); + crate::dialogs_assembly::face_normal_near(&m, u32::try_from(*index).ok()?, base) + }) .and_then(|n| n.normalized())?; Some(Place { key, base, n }) }) diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index 5ae1c978e27..be2e0d720d2 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -154,6 +154,27 @@ fn a_hole_whose_face_is_gone_keeps_its_marker_through_the_restored_direction() { assert!(handle_at("hole:0").is_none(), "no face and no direction: nowhere to stand"); } +#[test] +fn a_hole_on_a_curved_face_has_a_marker_standing_out_of_the_face() { + // A 20 mm round bar standing on XY, seen from the front: its side has no plane and a new + // dialog no stored direction, so the marker takes the face's normal where the hole is. + let mut h = Harness::new(); + h.app.set_origin_shown(false); + crate::prefs::set(&mut h.app, &json!({"hole_moves": true})).unwrap(); + h.app.run("solid.cylinder", json!({"radius": 10, "height": 40, "name": "Bar"})).unwrap(); + h.step(&json!({"call": "ui.view", "params": {"view": "front"}})).unwrap(); + h.settle(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let at = screen(&mut h, Vec3::new(0.0, -10.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + h.frames(2); + assert_eq!(places(&h).len(), 1, "the hole is placed on the bar's side"); + assert!(handle_at("hole:0").is_some(), "the hole on the curved face has its marker"); + let d = h.app.dialog.clone().expect("a dialog"); + let p = super::places(&h.app, &d); + assert!(matches!(p.as_slice(), [pl] if pl.n.dot(Vec3::new(0.0, -1.0, 0.0)) > 0.9), "out of the face, radially"); +} + /// The open Hole dialog's reference distances, as typed. fn distances(h: &Harness) -> [String; 2] { match h.app.dialog.as_ref().map(|d| &d.kind) { From 48546dc770cf7d7eb832a1882d4f8a16e56c3f13 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Nov 2026 12:32:00 +0100 Subject: [PATCH 15/38] Hole: a tapped hole's dragged outline is its tap drill, not the hidden Diameter field (#6818) Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs_hole.rs | 2 +- crates/ui-egui/src/place_gizmo/hole.rs | 13 +++++++------ crates/ui-egui/src/place_gizmo/hole_tests.rs | 6 ++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/dialogs_hole.rs b/crates/ui-egui/src/dialogs_hole.rs index 1c7181182ad..3f337aae05e 100644 --- a/crates/ui-egui/src/dialogs_hole.rs +++ b/crates/ui-egui/src/dialogs_hole.rs @@ -66,7 +66,7 @@ pub(crate) fn dims(kind: usize, opts: &HoleOpts, to_object: bool) -> Vec { /// Tapped bores use the engine's catalogued cut-tap drill, including Unified and parallel pipe sizes. /// A custom draft with an error must not illustrate its stale, last valid designation. -fn bore_diameter(diameter: &str, opts: &HoleOpts, eval: &dyn Fn(&str, ValueKind) -> Option) -> Option { +pub(crate) fn bore_diameter(diameter: &str, opts: &HoleOpts, eval: &dyn Fn(&str, ValueKind) -> Option) -> Option { if opts.tapped { if opts.custom_thread.as_ref().is_some_and(|draft| draft.error.is_some()) { return None; diff --git a/crates/ui-egui/src/place_gizmo/hole.rs b/crates/ui-egui/src/place_gizmo/hole.rs index 4cf64b41701..f659f21c117 100644 --- a/crates/ui-egui/src/place_gizmo/hole.rs +++ b/crates/ui-egui/src/place_gizmo/hole.rs @@ -78,15 +78,16 @@ fn move_to(app: &SolveApp, d: &mut Dialog, hits: &[Hit], key: usize) -> bool { } } -/// The hole's mouth on the face: the counterbore's or countersink's diameter, else the bore's. +/// The hole's mouth on the face: the counterbore's or countersink's diameter, else the bore's (a +/// tapped hole's tap drill). fn footprint(app: &SolveApp, d: &Dialog, base: Vec3, n: Vec3) -> Vec { - let Kind::Hole { diameter, kind, cb_diameter, cs_diameter, .. } = &d.kind else { return Vec::new() }; + let Kind::Hole { diameter, kind, cb_diameter, cs_diameter, opts, .. } = &d.kind else { return Vec::new() }; let mouth = match kind { - 1 => cb_diameter, - 2 => cs_diameter, - _ => diameter, + 1 => len(app, cb_diameter), + 2 => len(app, cs_diameter), + _ => crate::dialogs_hole::bore_diameter(diameter, opts, &|e, k| app.session.doc.eval(e, k).ok()).unwrap_or(0.0), }; - circle(base, n, len(app, mouth) * 0.5) + circle(base, n, mouth * 0.5) } #[cfg(test)] diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index be2e0d720d2..60948ee5c73 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -479,4 +479,10 @@ fn the_dragged_footprint_is_the_holes_mouth() { assert!((radius(&h) - 4.0).abs() < 1e-9, "a counterbore: its diameter"); set(&mut h, 2); assert!((radius(&h) - 6.0).abs() < 1e-9, "a countersink: its diameter"); + // A tapped hole has no Diameter field (the thread sets it): the bore is the tap drill. + set(&mut h, 0); + if let Some(crate::dialogs::Kind::Hole { opts, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) { + (opts.tapped, opts.thread, opts.drill) = (true, "M5".into(), None); + } + assert!((radius(&h) - 2.1).abs() < 1e-9, "a tapped M5: its 4.2 mm tap drill, got {}", radius(&h)); } From e1104c4aa992caf006e668d48b1b2fc5b24ab46e Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Nov 2026 12:40:38 +0100 Subject: [PATCH 16/38] Hole: where two markers' reaches overlap, the nearer one takes the press (#6818) Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/place_gizmo.rs | 11 +++++-- crates/ui-egui/src/place_gizmo/hole_tests.rs | 30 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/place_gizmo.rs b/crates/ui-egui/src/place_gizmo.rs index e9183e8552f..c432cb4c5f6 100644 --- a/crates/ui-egui/src/place_gizmo.rs +++ b/crates/ui-egui/src/place_gizmo.rs @@ -357,11 +357,18 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte // The crosshairs that move the feature, one per place. The press lands where the finger is, // not always the centre: the drag keeps that gap. A place held still has no press area. + // Where press areas overlap, egui gives the press to the last one: register the farthest from + // the pointer first, so the nearest marker takes it. let mut markers: Vec<(u64, egui::Response)> = Vec::new(); let before = places(app); let ids = marker_ids(ui.ctx(), store, before.len()); - for (pl, marker) in before.into_iter().zip(ids) { - let Some(bs) = proj.to_screen(pl.base) else { continue }; + let pointer = ui.ctx().pointer_latest_pos(); + let mut order: Vec<(Place, u64, Pos2)> = + before.into_iter().zip(ids).filter_map(|(pl, marker)| proj.to_screen(pl.base).map(|bs| (pl, marker, bs))).collect(); + if let Some(p) = pointer { + order.sort_by(|a, b| b.2.distance(p).total_cmp(&a.2.distance(p))); + } + for (pl, marker, bs) in order { if arms(proj, pl.base, pl.n, bs, freedom_of(app, pl.key)).is_empty() { continue; } diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index 60948ee5c73..4ad338f1881 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -83,6 +83,36 @@ fn each_placed_hole_has_its_own_marker_and_a_drag_moves_only_its_hole() { assert!(matches!(p.as_slice(), [a, b] if a.dist(first) < 1e-4 && b.dist(to) < 0.3), "{p:?}"); } +#[test] +fn where_two_markers_overlap_the_nearer_one_takes_the_press() { + // Two blocks 1 mm apart, a hole near each one's facing edge, 3 mm apart: their markers' + // reaches overlap between them (a face holds one hole, so they are on two faces). + let mut h = Harness::new(); + h.app.set_origin_shown(false); + crate::prefs::set(&mut h.app, &json!({"hole_moves": true})).unwrap(); + h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap(); + h.app.run("solid.box", json!({"length": 20, "width": 30, "height": 20, "corner": [41, 0, 0], "body_name": "Other"})).unwrap(); + h.step(&json!({"call": "ui.view", "params": {"view": "top"}})).unwrap(); + h.settle(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + for p in [Vec3::new(39.0, 10.0, 20.0), Vec3::new(42.0, 10.0, 20.0)] { + let at = screen(&mut h, p); + h.step(&json!({"click": at})).unwrap(); + h.frames(2); + } + let before = places(&h); + assert_eq!(before.len(), 2, "{before:?}"); + let (Some(a), Some(b)) = (handle_at("hole:0"), handle_at("hole:1")) else { panic!("two markers") }; + assert!(a.distance(b) < 36.0, "the reaches overlap: {a:?} {b:?}"); + // Pressed a third of the way from the first to the second (inside both reaches) and dragged + // down: the first moves, the second stays. + let press = [f64::from(a.x + (b.x - a.x) / 3.0), f64::from(a.y)]; + h.step(&json!({"drag": [press, [press[0], press[1] + 30.0]], "steps": 12})).unwrap(); + h.settle(); + let p = places(&h); + assert!(matches!(p.as_slice(), [x, y] if x.dist(before[0]) > 1.0 && y.dist(before[1]) < 1e-4), "the nearer marker moved: {before:?} -> {p:?}"); +} + #[test] fn a_click_within_the_markers_reach_takes_the_hole_out() { let mut h = blocks(); From 04a7a00349f815bc15a1ca5b27aebcc5ce900db0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Nov 2026 13:04:38 +0100 Subject: [PATCH 17/38] Hole: the held-line refusal reads as guidance, with no Create Issue (#6818) Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs.rs | 4 ++++ crates/ui-egui/src/place_gizmo/hole_tests.rs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 231b258e132..43b5083b2af 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -3276,8 +3276,12 @@ fn error_rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui: &mut // A command that is not available in this context ("`sketch.project` is not available // right now: no sketch is being edited") is guidance too: the context went away, not the // design, so there is nothing to report (#10181). + // A pick or drag that a hole's reference edge cannot follow is refused with what to do + // instead: guidance as well. let rect = if missing_pick(&error) { crate::ui_kit::text(ui, &shown_error(&error), crate::ui_kit::Text::Hint("missing_pick")).rect + } else if error == crate::hole_place::HELD_OFF_ITS_LINE { + crate::ui_kit::text(ui, &shown_error(&error), crate::ui_kit::Text::Hint("held_off_its_line")).rect } else if context_refusal(app, d, &error) { crate::ui_kit::text(ui, &shown_error(&error), crate::ui_kit::Text::Hint("context")).rect } else { diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index 4ad338f1881..1bf40648a3c 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -336,6 +336,12 @@ fn a_pick_the_held_line_cannot_reach_says_why_and_leaves_the_hole() { h.settle(); assert_eq!(places(&h), before, "the hole stays on its line"); assert_eq!(error(&h).as_deref(), Some(crate::hole_place::HELD_OFF_ITS_LINE), "the dialog says why"); + // A refusal of the pick, not a failure: no red report, no Create Issue. + h.frames(2); + assert!(handle_at("dialog:create_issue").is_none(), "no Create Issue for the held line"); + let _japanese = crate::i18n::scope("ja"); + assert!(!crate::i18n::tr_label(crate::hole_place::HELD_OFF_ITS_LINE).is_ascii(), "the message reads in the user's language"); + drop(_japanese); // A typed distance changes what the dialog makes: the message gives way. h.step(&json!({"click": {"handle": "dialog:Distance 1"}})).unwrap(); h.step(&json!({"key": "A", "cmd": true})).unwrap(); From 557053dbdfa282916aefc62e55809e5ef5e7319a Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Nov 2026 14:12:01 +0100 Subject: [PATCH 18/38] Hole: a hole on a curved face takes the face's normal before a stored direction, so Edit Feature does too (#6818) Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/place_gizmo/hole.rs | 2 +- crates/ui-egui/src/place_gizmo/hole_tests.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/place_gizmo/hole.rs b/crates/ui-egui/src/place_gizmo/hole.rs index f659f21c117..d0747a07c2f 100644 --- a/crates/ui-egui/src/place_gizmo/hole.rs +++ b/crates/ui-egui/src/place_gizmo/hole.rs @@ -43,12 +43,12 @@ fn places(app: &SolveApp, d: &Dialog) -> Vec { let Some(Sel::Face { body, index, .. }) = d.inputs.first()?.items.get(key) else { return None }; let n = crate::dialogs::planar_face(s, body, *index) .map(|(_, n)| n) - .or_else(|| d.extra.get("direction").and_then(vec3_of)) .or_else(|| { // A curved face: its normal where the hole is. let m = crate::open_meshing::session_world(s).body(body)?.mesh(); crate::dialogs_assembly::face_normal_near(&m, u32::try_from(*index).ok()?, base) }) + .or_else(|| d.extra.get("direction").and_then(vec3_of)) .and_then(|n| n.normalized())?; Some(Place { key, base, n }) }) diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index 1bf40648a3c..494f6673d4a 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -103,7 +103,8 @@ fn where_two_markers_overlap_the_nearer_one_takes_the_press() { let before = places(&h); assert_eq!(before.len(), 2, "{before:?}"); let (Some(a), Some(b)) = (handle_at("hole:0"), handle_at("hole:1")) else { panic!("two markers") }; - assert!(a.distance(b) < 36.0, "the reaches overlap: {a:?} {b:?}"); + // The press below lies a third of the way along: inside the second marker's 18 pt reach too. + assert!(a.distance(b) * 2.0 / 3.0 < 18.0, "the press is inside both reaches: {a:?} {b:?}"); // Pressed a third of the way from the first to the second (inside both reaches) and dragged // down: the first moves, the second stays. let press = [f64::from(a.x + (b.x - a.x) / 3.0), f64::from(a.y)]; @@ -203,6 +204,11 @@ fn a_hole_on_a_curved_face_has_a_marker_standing_out_of_the_face() { let d = h.app.dialog.clone().expect("a dialog"); let p = super::places(&h.app, &d); assert!(matches!(p.as_slice(), [pl] if pl.n.dot(Vec3::new(0.0, -1.0, 0.0)) > 0.9), "out of the face, radially"); + // Edit Feature stores the direction the hole had; the face, while it is there, still wins. + h.app.dialog.as_mut().expect("a dialog").extra.insert("direction".into(), crate::place_gizmo::pt(Vec3::new(0.0, 0.0, 1.0))); + let d = h.app.dialog.clone().expect("a dialog"); + let p = super::places(&h.app, &d); + assert!(matches!(p.as_slice(), [pl] if pl.n.dot(Vec3::new(0.0, -1.0, 0.0)) > 0.9), "the face's normal before a stored direction"); } /// The open Hole dialog's reference distances, as typed. From 10bc3e9cc45d8e98195e60687d0685b4174c291f Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 5 Nov 2026 16:16:17 +0100 Subject: [PATCH 19/38] Hole: the overlapping markers' test clicks its second hole clear of the first one's depth box (#6818) egui 0.37 makes the depth box a little taller, so a second hole clicked level with the first landed on it and was not placed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VYMtcRVatHGG6YWKYjp89v --- crates/ui-egui/src/place_gizmo/hole_tests.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index 494f6673d4a..aa87e975397 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -95,7 +95,8 @@ fn where_two_markers_overlap_the_nearer_one_takes_the_press() { h.step(&json!({"call": "ui.view", "params": {"view": "top"}})).unwrap(); h.settle(); h.step(&json!({"start": "solid.hole"})).unwrap(); - for p in [Vec3::new(39.0, 10.0, 20.0), Vec3::new(42.0, 10.0, 20.0)] { + // The second 1 mm lower: level with the first, its click lands on the first hole's depth box. + for p in [Vec3::new(39.0, 10.0, 20.0), Vec3::new(42.0, 9.0, 20.0)] { let at = screen(&mut h, p); h.step(&json!({"click": at})).unwrap(); h.frames(2); @@ -107,7 +108,7 @@ fn where_two_markers_overlap_the_nearer_one_takes_the_press() { assert!(a.distance(b) * 2.0 / 3.0 < 18.0, "the press is inside both reaches: {a:?} {b:?}"); // Pressed a third of the way from the first to the second (inside both reaches) and dragged // down: the first moves, the second stays. - let press = [f64::from(a.x + (b.x - a.x) / 3.0), f64::from(a.y)]; + let press = [f64::from(a.x + (b.x - a.x) / 3.0), f64::from(a.y + (b.y - a.y) / 3.0)]; h.step(&json!({"drag": [press, [press[0], press[1] + 30.0]], "steps": 12})).unwrap(); h.settle(); let p = places(&h); From f1b12bb8c7adcae1f94743588e818fed7aaa2acd Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 7 Nov 2026 20:20:27 +0100 Subject: [PATCH 20/38] Hole: several holes on one face keep their markers through the shared Spec (#6818) With Several holes on one face on, every hole on a face gets its own placement marker, as it had its own handle before the markers moved to place_gizmo. A drag moves that hole only, onto the face the other holes are on too, and a click on the marker takes that hole out. The marker names a hole by its item in the face input; hole_place maps it to the hole's number for several_change. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/hole_place.rs | 10 ++++++ crates/ui-egui/src/place_gizmo/hole.rs | 35 +++++++++++++++---- crates/ui-egui/src/place_gizmo/hole_tests.rs | 36 ++++++++++++++++++++ 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/hole_place.rs b/crates/ui-egui/src/hole_place.rs index 97555b6a4a7..be678037048 100644 --- a/crates/ui-egui/src/hole_place.rs +++ b/crates/ui-egui/src/hole_place.rs @@ -349,6 +349,16 @@ fn several_change(s: &Session, d: &mut Dialog, n: usize, to: Option) { set_places(s, d, places); } +/// Move the hole placed by item `i` of the face input to `to`, or take it out, when a face takes +/// several: the placement marker names a hole by its item (see `place_gizmo/hole.rs`). False when +/// item `i` places no hole. +pub(crate) fn several_change_item(s: &Session, d: &mut Dialog, i: usize, to: Option) -> bool { + let items = d.inputs.first().map(|inp| inp.items.as_slice()).unwrap_or_default(); + let Some(n) = several_places(s, items).iter().position(|&k| k == i) else { return false }; + several_change(s, d, n, to); + true +} + /// When a face takes several Single holes (Preferences), a face pick adds a hole there, or takes /// out the hole it lands on (within its radius). True when the pick was taken so. pub(crate) fn pick_several(app: &SolveApp, d: &mut Dialog, sel: &Sel) -> bool { diff --git a/crates/ui-egui/src/place_gizmo/hole.rs b/crates/ui-egui/src/place_gizmo/hole.rs index d0747a07c2f..5556055a9c2 100644 --- a/crates/ui-egui/src/place_gizmo/hole.rs +++ b/crates/ui-egui/src/place_gizmo/hole.rs @@ -8,6 +8,9 @@ //! Reference edges (#37) place the first hole: with one picked, its marker has two arms along the //! edge and drags the hole along it at its distance; with two, the marker has its four arms again //! and a drag sets both distances. Any other hole in the dialog moves anywhere. +//! +//! With Create Hole › Several holes on one face (#12480), each hole on a face has its own marker: +//! a drag moves that hole only (onto a face with other holes too) and a click takes that one out. use solidcore_record::Vec3; use solidcraft_engine::Sel; @@ -26,7 +29,13 @@ pub(super) static SPEC: Spec = Spec { many: true, places, move_to, - click: Some(|app, d, key| crate::hole_place::remove_place(d, &app.session, key)), + click: Some(|app, d, key| { + if crate::hole_place::several(app, d) { + crate::hole_place::several_change_item(&app.session, d, key, None); + } else { + crate::hole_place::remove_place(d, &app.session, key); + } + }), footprint, freedom: |app, d, key| crate::hole_refs::freedom(&app.session, d, key), turn: None, @@ -34,11 +43,23 @@ pub(super) static SPEC: Spec = Spec { /// The holes placed so far, each at its face place with the face's outward normal (on a curved /// face, the normal where the hole is). A hole being edited whose face is gone keeps its place -/// and the `direction` the edit restored, as a Rest's frame does, so it still has a marker. +/// and the `direction` the edit restored, as a Rest's frame does, so it still has a marker. When a +/// face takes several holes, each pick on it is a hole with its own marker. fn places(app: &SolveApp, d: &Dialog) -> Vec { let s = &app.session; - crate::hole_place::places(s, d) - .into_iter() + let held = if crate::hole_place::several(app, d) { + let items = d.inputs.first().map(|inp| inp.items.as_slice()).unwrap_or_default(); + crate::hole_place::several_places(s, items) + .into_iter() + .filter_map(|i| match items.get(i) { + Some(Sel::Face { point, .. }) => Some((i, *point)), + _ => None, + }) + .collect() + } else { + crate::hole_place::places(s, d) + }; + held.into_iter() .filter_map(|(key, base)| { let Some(Sel::Face { body, index, .. }) = d.inputs.first()?.items.get(key) else { return None }; let n = crate::dialogs::planar_face(s, body, *index) @@ -56,12 +77,14 @@ fn places(app: &SolveApp, d: &Dialog) -> Vec { } /// The hole at `key` moved to the face place a click with `hits` would take (snapped as the -/// pick is), unless that face already has another hole; held by a reference edge, as far along -/// the edge as the pick is, and where the edge's line leaves the face first, refused with why. +/// pick is), unless that face already has another hole and takes only one; held by a reference +/// edge, as far along the edge as the pick is, and where the edge's line leaves the face first, +/// refused with why. fn move_to(app: &SolveApp, d: &mut Dialog, hits: &[Hit], key: usize) -> bool { let s = &app.session; let Some(to) = face_pick(d, s, hits) else { return false }; match crate::hole_refs::freedom(s, d, key) { + Freedom::Plane if crate::hole_place::several(app, d) => crate::hole_place::several_change_item(s, d, key, Some(to)), Freedom::Plane => crate::hole_place::move_place(d, s, key, to), Freedom::Line(_) => match to { Sel::Face { point, .. } => match crate::hole_refs::drag_to(s, d, key, point) { diff --git a/crates/ui-egui/src/place_gizmo/hole_tests.rs b/crates/ui-egui/src/place_gizmo/hole_tests.rs index aa87e975397..7e002ed1da3 100644 --- a/crates/ui-egui/src/place_gizmo/hole_tests.rs +++ b/crates/ui-egui/src/place_gizmo/hole_tests.rs @@ -135,6 +135,42 @@ fn a_click_within_the_markers_reach_takes_the_hole_out() { assert!(handle_at("hole:0").is_none(), "no hole, no marker"); } +#[test] +fn with_several_holes_on_a_face_each_has_a_marker_that_drags_or_takes_out_only_its_hole() { + // Several holes on one face (#12480): three picks on the one top face are three holes, each + // with its own marker. A drag moves its hole across the face the others are on; a click on the + // marker's arm takes that hole out (a hole narrower than the click's 14 pt, so a pick there + // that missed the marker would add a hole instead). + let mut h = blocks(); + crate::prefs::set(&mut h.app, &json!({"hole_several": true})).unwrap(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + if let Some(crate::dialogs::Kind::Hole { diameter, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) { + *diameter = "0.5 mm".into(); + } + let spots = [Vec3::new(8.0, 8.0, 20.0), Vec3::new(20.0, 22.0, 20.0), Vec3::new(32.0, 8.0, 20.0)]; + for p in spots { + let at = screen(&mut h, p); + h.step(&json!({"click": at})).unwrap(); + h.frames(2); + } + let near = |got: &[Vec3], want: &[Vec3]| got.len() == want.len() && got.iter().zip(want).all(|(g, w)| g.dist(*w) < 0.2); + assert!(near(&places(&h), &spots), "three holes on the one face: {:?}", places(&h)); + assert!(handle_at("hole:2").is_some() && handle_at("hole:3").is_none(), "a marker per hole"); + // The middle hole dragged to another spot on the same face: the other two stay. + let moved = Vec3::new(20.0, 12.0, 20.0); + let ts = screen(&mut h, moved); + h.step(&json!({"drag": [{"handle": "hole:1"}, ts], "steps": 12})).unwrap(); + h.settle(); + assert!(near(&places(&h), &[spots[0], moved, spots[2]]), "only the dragged hole moved: {:?}", places(&h)); + // The first marker's arm clicked: that hole goes, the moved one and the last stay. + h.frames(2); + let c = handle_at("hole:0").expect("the first hole's marker"); + h.step(&json!({"click": [f64::from(c.x) + 14.0, f64::from(c.y)]})).unwrap(); + h.frames(2); + assert!(near(&places(&h), &[moved, spots[2]]), "only the clicked hole went: {:?}", places(&h)); + assert!(handle_at("hole:1").is_some() && handle_at("hole:2").is_none(), "{:?}", places(&h)); +} + #[test] fn the_depth_arrow_stands_clear_of_the_marker_only_while_holes_move() { let mut h = blocks(); From b6b834c2f34bb3dea5a67b6e71e8ef90927f51e9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 27 Oct 2026 16:09:55 +0100 Subject: [PATCH 21/38] Placement handles: a Spec says where its place is kept (#4384) A tool's place has one declared source, `Spec.place: PlaceSource`, instead of two functions each tool wrote itself. `Input(n)` is the common case: the place is the face item of the dialog's input `n`, read from there and moved by replacing the item, with `direction` and the in-face `along` carried onto the new face; the marker's pick follows that input's rules whichever input is active. Rest, Boss and Snap Fit declare `Input(0)` and lose their `places` and `move_to` lines; the frame and move they shared move from `dialogs_plastic` into `place_gizmo`, where the place lives. `Own` keeps a tool's own two functions: the hole, with a place per item. Behaviour unchanged, no test changed. Refs #4384, groundwork for the primitives (third element). Co-Authored-By: Claude Fable 5.1 --- crates/ui-egui/src/dialogs_plastic.rs | 38 --------- crates/ui-egui/src/place_gizmo.rs | 94 +++++++++++++++++++--- crates/ui-egui/src/place_gizmo/boss.rs | 5 +- crates/ui-egui/src/place_gizmo/hole.rs | 5 +- crates/ui-egui/src/place_gizmo/rest.rs | 5 +- crates/ui-egui/src/place_gizmo/snap_fit.rs | 5 +- 6 files changed, 92 insertions(+), 60 deletions(-) diff --git a/crates/ui-egui/src/dialogs_plastic.rs b/crates/ui-egui/src/dialogs_plastic.rs index de96cd741c2..4c44d558d39 100644 --- a/crates/ui-egui/src/dialogs_plastic.rs +++ b/crates/ui-egui/src/dialogs_plastic.rs @@ -434,44 +434,6 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind) -> Option<(Kind, Vec Option<(Vec3, Vec3)> { - let Sel::Face { body, index, point } = d.inputs.first()?.items.first()? else { return None }; - let n = crate::dialogs::planar_face(&app.session, body, *index) - .map(|(_, n)| n) - .or_else(|| d.extra.get("direction").and_then(crate::dialogs::vec3_of)) - .and_then(|n| n.normalized())?; - Some((*point, n)) -} - -/// The placement handles' move for a feature placed through its first input: re-place it where a -/// click with `hits` (the pick under the pointer) would (snapped to a sketch point as a click is -/// when the input takes points), with the stored `direction` and in-face `along` carried onto the -/// new face. False when nothing there can take it. -pub(crate) fn handle_move(app: &SolveApp, d: &mut crate::dialogs::Dialog, hits: &[crate::viewport::Hit]) -> bool { - use crate::place_gizmo::{angle_of, dir_at}; - let s = &app.session; - let turned = handle_frame(app, d).and_then(|(_, n)| d.extra.get("along").and_then(crate::dialogs::vec3_of).map(|a| angle_of(a, n))); - let Some(to) = crate::place_gizmo::face_pick(d, s, hits) else { return false }; - if let Sel::Face { body, index, .. } = &to - && let Some((_, nn)) = crate::dialogs::planar_face(s, body, *index) - { - if d.extra.contains_key("direction") { - d.extra.insert("direction".into(), pt(nn)); - } - if let Some(a) = turned { - d.extra.insert("along".into(), pt(dir_at(nn, a))); - } - } - if let Some(inp) = d.inputs.first_mut() { - inp.items = vec![to]; - } - d.error = None; - true -} - #[cfg(test)] #[path = "dialogs_plastic_tests.rs"] mod tests; diff --git a/crates/ui-egui/src/place_gizmo.rs b/crates/ui-egui/src/place_gizmo.rs index c432cb4c5f6..0beaa1103cc 100644 --- a/crates/ui-egui/src/place_gizmo.rs +++ b/crates/ui-egui/src/place_gizmo.rs @@ -21,7 +21,9 @@ //! instead, as the hole's own handle was; each tool's [`Spec::serves`] says what turns it on. //! //! A tool has one place (a Rest) or one per item of its first input (a Single hole, a marker on each -//! hole placed): [`Spec::places`] lists them, and a drag or a click names the place by its key. +//! hole placed): [`Spec::place`] says where they come from, and a drag or a click names the place by +//! its key. Most tools keep their place as the face item of one input ([`PlaceSource::Input`]): the +//! marker reads it from there and moves it by replacing the item, as a click on the input does. mod boss; mod hole; @@ -67,12 +69,8 @@ pub(crate) struct Spec { /// (a Single hole's; `turn` is then ignored). Off: one place, `:position`, and the ring /// if any. pub many: bool, - /// The places the handles stand at. - pub places: fn(&SolveApp, &Dialog) -> Vec, - /// Re-place the feature at `key` where a click with these hits (the pick under the pointer, - /// taken while the dialog is open, so it snaps as a click does) would put it; false when - /// nothing there can take it. - pub move_to: fn(&SolveApp, &mut Dialog, &[Hit], usize) -> bool, + /// Where the places the handles stand at come from, and how a drag moves one. + pub place: PlaceSource, /// What a click (a press without a drag) on the marker at `key` does: a Single hole is taken /// out. `None`: a click on the marker does nothing. pub click: Option, @@ -85,6 +83,81 @@ pub(crate) struct Spec { pub turn: Option, } +/// Where a tool keeps its place, so where the marker reads it and how a drag moves it. +pub(crate) enum PlaceSource { + /// The face item of the dialog's input `n` (a Rest's, Boss's or Snap Fit's Position input): + /// the picked point, growing along the face's normal, else the stored `direction` when the + /// face is gone. A drag replaces the item where a click on that input would put it, snapped + /// as the click is, carrying `direction` and the in-face `along` onto the new face. + Input(usize), + /// The tool's own: `places` lists them; `move_to` re-places the one at `key` where a click + /// with these hits (the pick under the pointer, taken while the dialog is open, so it snaps + /// as a click does) would put it, false when nothing there can take it. + Own { places: fn(&SolveApp, &Dialog) -> Vec, move_to: fn(&SolveApp, &mut Dialog, &[Hit], usize) -> bool }, +} + +impl Spec { + /// The places the handles stand at. + fn places(&self, app: &SolveApp, d: &Dialog) -> Vec { + match self.place { + PlaceSource::Input(i) => one(input_frame(app, d, i)), + PlaceSource::Own { places, .. } => places(app, d), + } + } + + /// Re-place the feature at `key` where a click with these hits would put it. + fn move_to(&self, app: &SolveApp, d: &mut Dialog, hits: &[Hit], key: usize) -> bool { + match self.place { + PlaceSource::Input(i) => input_move(app, d, hits, i), + PlaceSource::Own { move_to, .. } => move_to(app, d, hits, key), + } + } + + /// The input whose rules the marker's pick follows: the place's, else the first (a Single + /// hole's places are the items of its first input). + fn place_input(&self) -> usize { + match self.place { + PlaceSource::Input(i) => i, + PlaceSource::Own { .. } => 0, + } + } +} + +/// The place of a tool kept in its input `i`: the face item's point and the direction the +/// feature grows, the face's normal, else the stored `direction`. +fn input_frame(app: &SolveApp, d: &Dialog, i: usize) -> Option<(Vec3, Vec3)> { + let Sel::Face { body, index, point } = d.inputs.get(i)?.items.first()? else { return None }; + let n = crate::dialogs::planar_face(&app.session, body, *index) + .map(|(_, n)| n) + .or_else(|| d.extra.get("direction").and_then(vec3_of)) + .and_then(|n| n.normalized())?; + Some((*point, n)) +} + +/// The move of a tool kept in its input `i`: the item replaced where a click with `hits` would +/// put it (snapped to a sketch point as a click is when the input takes points), with the stored +/// `direction` and in-face `along` carried onto the new face. False when nothing there can take it. +fn input_move(app: &SolveApp, d: &mut Dialog, hits: &[Hit], i: usize) -> bool { + let s = &app.session; + let turned = input_frame(app, d, i).and_then(|(_, n)| d.extra.get("along").and_then(vec3_of).map(|a| angle_of(a, n))); + let Some(to) = face_pick(d, s, hits) else { return false }; + if let Sel::Face { body, index, .. } = &to + && let Some((_, nn)) = crate::dialogs::planar_face(s, body, *index) + { + if d.extra.contains_key("direction") { + d.extra.insert("direction".into(), pt(nn)); + } + if let Some(a) = turned { + d.extra.insert("along".into(), pt(dir_at(nn, a))); + } + } + if let Some(inp) = d.inputs.get_mut(i) { + inp.items = vec![to]; + } + d.error = None; + true +} + /// The ways a place can go on its face. #[derive(Clone, Copy, Debug, PartialEq)] pub(crate) enum Freedom { @@ -346,7 +419,7 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte DRAWN.with(|h| h.borrow_mut().clear()); RING_ABOUT.with(|c| c.set(None)); let Some(sp) = app.dialog.as_ref().and_then(|d| spec(app, d)) else { return }; - let places = |app: &SolveApp| app.dialog.as_ref().map(|d| (sp.places)(app, d)).unwrap_or_default(); + let places = |app: &SolveApp| app.dialog.as_ref().map(|d| sp.places(app, d)).unwrap_or_default(); let t = Tokens::get(); let area = |c: Pos2| egui::Rect::from_center_size(c, vec2(2.0 * REACH, 2.0 * REACH)); let id = |what: &str| egui::Id::unique(("sc_place", sp.name, what)); @@ -377,10 +450,11 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte if r.dragged() { crate::tool_modifiers::set_manipulator_dragging(true); if let Some(p) = r.interact_pointer_pos() { - let was = app.dialog.as_mut().map(|d| std::mem::replace(&mut d.active, 0)); + // The pick follows the place input's rules, whichever input is active. + let was = app.dialog.as_mut().map(|d| std::mem::replace(&mut d.active, sp.place_input())); let hits = crate::viewport::pick(app, proj, p - off.unwrap_or_default()); with_dialog(app, |app, d| { - (sp.move_to)(app, d, &hits, pl.key); + sp.move_to(app, d, &hits, pl.key); }); if let (Some(d), Some(was)) = (app.dialog.as_mut(), was) { d.active = was; diff --git a/crates/ui-egui/src/place_gizmo/boss.rs b/crates/ui-egui/src/place_gizmo/boss.rs index ce8e276b0c6..974abdecc78 100644 --- a/crates/ui-egui/src/place_gizmo/boss.rs +++ b/crates/ui-egui/src/place_gizmo/boss.rs @@ -3,7 +3,7 @@ use solidcore_record::Vec3; -use super::{Spec, circle, len}; +use super::{PlaceSource, Spec, circle, len}; use crate::SolveApp; use crate::dialogs::{Dialog, Kind}; use crate::dialogs_plastic::Pl; @@ -14,8 +14,7 @@ pub(super) static SPEC: Spec = Spec { snap_commands: &["plastic.boss"], move_tip: "Drag to move the boss across the model. It snaps to sketch points on the face.", many: false, - places: |app, d| super::one(crate::dialogs_plastic::handle_frame(app, d)), - move_to: |app, d, hits, _| crate::dialogs_plastic::handle_move(app, d, hits), + place: PlaceSource::Input(0), click: None, footprint, freedom: super::anywhere, diff --git a/crates/ui-egui/src/place_gizmo/hole.rs b/crates/ui-egui/src/place_gizmo/hole.rs index 5556055a9c2..36280eb8796 100644 --- a/crates/ui-egui/src/place_gizmo/hole.rs +++ b/crates/ui-egui/src/place_gizmo/hole.rs @@ -16,7 +16,7 @@ use solidcore_record::Vec3; use solidcraft_engine::Sel; use solidcraft_engine::geom::prelude::*; -use super::{Freedom, Place, Spec, circle, face_pick, len, vec3_of}; +use super::{Freedom, Place, PlaceSource, Spec, circle, face_pick, len, vec3_of}; use crate::SolveApp; use crate::dialogs::{Dialog, Kind}; use crate::viewport::Hit; @@ -27,8 +27,7 @@ pub(super) static SPEC: Spec = Spec { snap_commands: &[], move_tip: "Drag to move the hole; click to remove it", many: true, - places, - move_to, + place: PlaceSource::Own { places, move_to }, click: Some(|app, d, key| { if crate::hole_place::several(app, d) { crate::hole_place::several_change_item(&app.session, d, key, None); diff --git a/crates/ui-egui/src/place_gizmo/rest.rs b/crates/ui-egui/src/place_gizmo/rest.rs index 33f4e61de40..fd662f9cf9b 100644 --- a/crates/ui-egui/src/place_gizmo/rest.rs +++ b/crates/ui-egui/src/place_gizmo/rest.rs @@ -3,7 +3,7 @@ use solidcore_record::Vec3; -use super::{Spec, Turn, angle_of, circle, dir_at, len, pt, pulled, rect, vec3_of}; +use super::{PlaceSource, Spec, Turn, angle_of, circle, dir_at, len, pt, pulled, rect, vec3_of}; use crate::SolveApp; use crate::dialogs::{Dialog, Kind}; use crate::dialogs_plastic::Pl; @@ -14,8 +14,7 @@ pub(super) static SPEC: Spec = Spec { snap_commands: &["plastic.rest"], move_tip: "Drag to move the rest across the model. It snaps to sketch points on the face.", many: false, - places: |app, d| super::one(crate::dialogs_plastic::handle_frame(app, d)), - move_to: |app, d, hits, _| crate::dialogs_plastic::handle_move(app, d, hits), + place: PlaceSource::Input(0), click: None, footprint, freedom: super::anywhere, diff --git a/crates/ui-egui/src/place_gizmo/snap_fit.rs b/crates/ui-egui/src/place_gizmo/snap_fit.rs index 0aecaa793b1..1ce4fcef8a8 100644 --- a/crates/ui-egui/src/place_gizmo/snap_fit.rs +++ b/crates/ui-egui/src/place_gizmo/snap_fit.rs @@ -4,7 +4,7 @@ use solidcore_record::Vec3; -use super::{Spec, Turn, angle_of, len, rect}; +use super::{PlaceSource, Spec, Turn, angle_of, len, rect}; use crate::SolveApp; use crate::dialogs::{Dialog, Kind}; use crate::dialogs_plastic::{Pl, hook_dirs}; @@ -15,8 +15,7 @@ pub(super) static SPEC: Spec = Spec { snap_commands: &["plastic.snap_fit"], move_tip: "Drag to move the snap fit across the model. It snaps to sketch points on the face.", many: false, - places: |app, d| super::one(crate::dialogs_plastic::handle_frame(app, d)), - move_to: |app, d, hits, _| crate::dialogs_plastic::handle_move(app, d, hits), + place: PlaceSource::Input(0), click: None, footprint, freedom: super::anywhere, From 7987c64f736f3af0ac4901f0cd777c3edc454dd6 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 1 Nov 2026 03:58:50 +0100 Subject: [PATCH 22/38] claim: #4384 Co-Authored-By: Claude Opus 5.5 From 5db51e928cec433872a41deb97a988f7b7c163c0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 1 Nov 2026 15:00:32 +0100 Subject: [PATCH 23/38] Placement handles: Box, Cylinder, Cone, Sphere, Torus and Coil (#4384) With Placement handles on, the primitives' dialogs get the shared move marker. It stands at the dialog's place (a pre-selected face, the Cylinder's Face input, the typed corner, centre or base, the edited feature's stored point, else the origin), and a drag places the primitive on the face under the pointer, as a pre-selected face places it, from Edit Feature too: a Box, Cylinder, Cone or Coil stands on it, a Sphere or Torus has its centre on it, as today. The footprint is the box's side on the face, the base circle of a cylinder, cone or coil, the widest circle of a sphere and the torus's outer circle lying flat, as the torus is made. No ring: the primitives do not turn in their face. A Coil with a sketch profile has no marker: its place is the profile's. The drag moves the place where the dialog keeps it: a Cylinder's Face input item and its place in the same frame (its reference edge distances are measured again from there, as after a click), a Box's typed corner or centre fields (to the micrometre; its Point pick is cleared), or the picked place for the others. A Cylinder, Cone or Coil does not take a curved face, which has no one axis to stand it on. A typed Box's side on its face is found from the model (the side lying on a planar face that looks at it, its bottom first), so Edit Feature reopens it on a side face too. A Box at a vertex is centred on it, so its marker is at its bottom. The Cylinder's canvas path returned before the handles were drawn; it now draws them. The Placement handles setting's description names the primitives, in every catalog that has it, and the control protocol lists the primitive:position handle. The tip is a new string in assets/locales/pending/primitive-handles.json. Co-Authored-By: Claude Opus 5.5 --- assets/locales/pending/primitive-handles.json | 29 ++ crates/ui-egui/src/canvas.rs | 3 +- crates/ui-egui/src/place_gizmo.rs | 2 + crates/ui-egui/src/place_gizmo/primitive.rs | 230 ++++++++++ .../src/place_gizmo/primitive_tests.rs | 408 ++++++++++++++++++ crates/ui-egui/src/prefs.rs | 8 +- crates/ui-egui/src/primitive_placement.rs | 28 +- docs/control-protocol.md | 4 +- 8 files changed, 705 insertions(+), 7 deletions(-) create mode 100644 assets/locales/pending/primitive-handles.json create mode 100644 crates/ui-egui/src/place_gizmo/primitive.rs create mode 100644 crates/ui-egui/src/place_gizmo/primitive_tests.rs diff --git a/assets/locales/pending/primitive-handles.json b/assets/locales/pending/primitive-handles.json new file mode 100644 index 00000000000..e3215a06334 --- /dev/null +++ b/assets/locales/pending/primitive-handles.json @@ -0,0 +1,29 @@ +{ + "en": { + "Drag to place it on another face.": "Drag to place it on another face." + }, + "ar": { + "Drag to place it on another face.": "اسحب لوضعه على وجه آخر." + }, + "de": { + "Drag to place it on another face.": "Ziehen, um es auf eine andere Fläche zu setzen." + }, + "he": { + "Drag to place it on another face.": "יש לגרור כדי להציב אותו על פאה אחרת." + }, + "ja": { + "Drag to place it on another face.": "ドラッグして別の面に配置します。" + }, + "ko": { + "Drag to place it on another face.": "드래그하여 다른 면에 배치합니다." + }, + "pl": { + "Drag to place it on another face.": "Przeciągnij, aby umieścić go na innej ścianie." + }, + "vi": { + "Drag to place it on another face.": "Kéo để đặt nó lên một bề mặt khác." + }, + "zh": { + "Drag to place it on another face.": "拖动以将其放置到另一个面上。" + } +} diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index cd2cbaa1f8c..df034889374 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -419,10 +419,11 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj return; } // A cylinder's values are typed in its window; its distances from its reference edges - // (#6380) are shown and typed on the canvas, as a hole's. + // (#6380) are shown and typed on the canvas, as a hole's, then its placement handles drawn. if matches!(d.kind, Kind::Primitive { cmd: "solid.cylinder", .. }) { crate::hole_refs::canvas(app, ui, painter, proj, &mut d); app.dialog = Some(d); + crate::place_gizmo::show(app, ui, painter, proj); return; } if let Some((base, dir)) = anchor(app, &d) diff --git a/crates/ui-egui/src/place_gizmo.rs b/crates/ui-egui/src/place_gizmo.rs index 0beaa1103cc..c6fe79f2af5 100644 --- a/crates/ui-egui/src/place_gizmo.rs +++ b/crates/ui-egui/src/place_gizmo.rs @@ -28,6 +28,7 @@ mod boss; mod hole; mod look; +mod primitive; mod rest; mod snap_fit; @@ -218,6 +219,7 @@ pub(crate) struct Turn { static TOOLS: &[&Spec] = &[ &boss::SPEC, &hole::SPEC, + &primitive::SPEC, &rest::SPEC, &snap_fit::SPEC, ]; diff --git a/crates/ui-egui/src/place_gizmo/primitive.rs b/crates/ui-egui/src/place_gizmo/primitive.rs new file mode 100644 index 00000000000..d8df117758c --- /dev/null +++ b/crates/ui-egui/src/place_gizmo/primitive.rs @@ -0,0 +1,230 @@ +//! Box, Cylinder, Cone, Sphere, Torus and Coil: the marker places the primitive on the face under +//! the pointer, standing on it as a pre-selected face places it, while the dialog is open, from +//! Edit Feature too. The primitives do not turn in their face: no ring. +//! +//! Where the place is kept differs by primitive, and the marker moves it there: +//! - a Cylinder stands where its Face input is picked (and its reference edges measure from +//! there, #6380), so a drag replaces that item, as a click on the input does; +//! - a Box placed by its typed corner or centre (#5638) has the drop written into those fields, +//! so it stands on the face, centred across it; +//! - any other, and a Box a pre-selected face placed, takes the drop as its picked place. +//! +//! The marker sits at the dialog's picked place when there is one, else at the stored or typed +//! position (the centre, the base, or the middle of the box's side on its face), else where the +//! command puts a primitive with none (the origin). A typed Box's side on its face is found from +//! the model: the side that lies on a planar face looking at it, its bottom first. +//! +//! A Cylinder, Cone or Coil needs a planar face for its axis: a curved one does not take the drop. +//! A Torus is made flat, so its outline is drawn flat whatever face it is over. +//! +//! A Coil with a sketch profile has no marker: its place is the profile's, and the base and axis +//! the dialog would send from a picked place move the axis but not the section. + +use std::cell::RefCell; +use std::sync::Arc; + +use serde_json::Value; +use solidcore_record::Vec3; +use solidcraft_engine::doc::expr::Kind as ValueKind; +use solidcraft_engine::geom::prelude::*; + +use solidcraft_engine::Sel; + +use super::{PlaceSource, Spec, circle, face_pick, len, rect, vec3_of}; +use crate::SolveApp; +use crate::dialogs::{Dialog, Kind}; +use crate::viewport::Hit; + +pub(super) static SPEC: Spec = Spec { + name: "primitive", + serves: |app, d| super::on(app) && matches!(d.kind, Kind::Primitive { .. }) && !coil_with_profile(d), + snap_commands: &[], + move_tip: "Drag to place it on another face.", + many: false, + place: PlaceSource::Own { places: |app, d| super::one(frame(app, d)), move_to }, + click: None, + footprint, + freedom: super::anywhere, + turn: None, +}; + +/// A planar face's plane: a point on it and its outward normal. +type FacePlane = (Vec3, Vec3); + +thread_local! { + /// The planes of the planar faces of the model state last asked about, found once per state. + static PLANES: RefCell<(Option>, Arc>)> = RefCell::new((None, Arc::new(Vec::new()))); +} + +/// The planes of the model's planar faces. +fn planes(app: &SolveApp) -> Arc> { + let st = crate::open_meshing::session_world(&app.session); + if let Some(known) = PLANES.with(|c| c.borrow().0.as_ref().filter(|k| Arc::ptr_eq(k, &st)).map(|_| c.borrow().1.clone())) { + return known; + } + let found: Vec = st + .bodies + .iter() + .flat_map(|b| b.body.faces((b.body.size() * 1e-3).max(1e-3)).unwrap_or_default()) + .filter_map(|f| Some((f.centroid, f.plane_normal?))) + .collect(); + let found = Arc::new(found); + PLANES.with(|c| *c.borrow_mut() = (Some(st), found.clone())); + found +} + +/// Is this a Coil whose section comes from a sketch (its Profile input holds something)? +fn coil_with_profile(d: &Dialog) -> bool { + matches!(&d.kind, Kind::Primitive { cmd: "solid.coil", .. }) && d.inputs.iter().any(|i| !i.items.is_empty()) +} + +/// A size field's value (mm), zero when it is missing or does not evaluate. +fn size(app: &SolveApp, d: &Dialog, key: &str) -> f64 { + let Kind::Primitive { fields, .. } = &d.kind else { return 0.0 }; + fields.iter().find(|f| f.0 == key).map(|f| len(app, &f.1)).unwrap_or(0.0) +} + +/// The radius, from whichever of `radius` (Edit Feature) or `diameter` (a new one) the dialog holds. +fn radius(app: &SolveApp, d: &Dialog) -> f64 { + let Kind::Primitive { fields, .. } = &d.kind else { return 0.0 }; + if fields.iter().any(|f| f.0 == "radius") { size(app, d, "radius") } else { size(app, d, "diameter") * 0.5 } +} + +/// The box's length, width and height (mm). +fn box_size(app: &SolveApp, d: &Dialog) -> Vec3 { + Vec3::new(size(app, d, "length"), size(app, d, "width"), size(app, d, "height")) +} + +/// A stored or typed point of expressions (numbers, or strings in the design's terms). +fn expr_point(app: &SolveApp, v: &Value) -> Option { + let c = |i: usize| -> Option { + let x = v.as_array()?.get(i)?; + x.as_f64() + .or_else(|| app.session.doc.eval(&app.session.doc.with_design_unit(x.as_str()?, ValueKind::Length), ValueKind::Length).ok()) + .filter(|v| v.is_finite()) + }; + Some(Vec3::new(c(0)?, c(1)?, c(2)?)) +} + +/// Is `n` along a world axis (either way)? +fn square_to(n: Vec3, axis: Vec3) -> bool { + n.dot(axis).abs() > 1.0 - 1e-9 +} + +/// The faces a Box can stand on, by their normal, in the order they are looked for. +const STANDS_ON: [Vec3; 6] = [Vec3::Z, Vec3::X, Vec3::new(-1.0, 0.0, 0.0), Vec3::Y, Vec3::new(0.0, -1.0, 0.0), Vec3::new(0.0, 0.0, -1.0)]; + +/// How far a box side may be from the face plane and still stand on it (mm): a drop is written to +/// the micrometre. +const ON_PLANE: f64 = 1e-3; + +/// Where a typed Box stands: the middle of its side that lies on a planar face of the model +/// looking at it (its bottom first), else the middle of its bottom. +fn box_frame(app: &SolveApp, d: &Dialog) -> Option<(Vec3, Vec3)> { + let half = box_size(app, d) * 0.5; + let centre = match d.extra.get("center") { + Some(v) => expr_point(app, v)?, + None => d.extra.get("corner").and_then(|v| expr_point(app, v)).unwrap_or(Vec3::ZERO) + half, + }; + let side = |n: Vec3| centre - Vec3::new(n.x * half.x, n.y * half.y, n.z * half.z); + let planes = planes(app); + let n = STANDS_ON + .into_iter() + .find(|n| planes.iter().any(|(q, m)| m.dot(*n) > 1.0 - 1e-9 && (side(*n) - *q).dot(*m).abs() < ON_PLANE)) + .unwrap_or(Vec3::Z); + Some((side(n), n)) +} + +fn frame(app: &SolveApp, d: &Dialog) -> Option<(Vec3, Vec3)> { + let Kind::Primitive { cmd, at, .. } = &d.kind else { return None }; + let axis = || d.extra.get("axis").and_then(vec3_of).and_then(|a| a.normalized()).unwrap_or(Vec3::Z); + match (*cmd, at) { + (_, Some((p, Some(n)))) => return Some((*p, *n)), + // A box at a vertex or on a curved face is centred on the point: the marker at its bottom. + ("solid.box", Some((p, None))) => return Some((*p - Vec3::Z * (box_size(app, d).z * 0.5), Vec3::Z)), + // No face to stand on: the axis it is made along, the stored one or the command's. + ("solid.cylinder" | "solid.coil" | "solid.cone", Some((p, None))) => return Some((*p, axis())), + (_, Some((p, None))) => return Some((*p, Vec3::Z)), + (_, None) => {} + } + match *cmd { + "solid.box" => box_frame(app, d), + "solid.cylinder" | "solid.coil" | "solid.cone" => Some((d.extra.get("base").and_then(|v| expr_point(app, v)).unwrap_or(Vec3::ZERO), axis())), + _ => Some((d.extra.get("center").and_then(|v| expr_point(app, v)).unwrap_or(Vec3::ZERO), Vec3::Z)), + } +} + +/// Stand the primitive on the face under the pointer, as a pre-selected face places it: through +/// the Cylinder's Face input (its place follows in the same frame), into a typed Box's corner or +/// centre (the Box's point pick, which no longer says where it is, is dropped), else as the +/// picked place. A Cylinder, Cone or Coil does not take a curved face: it has no one axis there. +fn move_to(app: &SolveApp, d: &mut Dialog, hits: &[Hit], _: usize) -> bool { + let s = &app.session; + let planar = |sel: &Sel| match sel { + Sel::Face { body, index, point } => crate::dialogs::planar_face(s, body, *index).map(|(_, n)| (*point, n)), + _ => None, + }; + if crate::hole_refs::takes(d) { + let Some(to) = face_pick(d, s, hits) else { return false }; + let Some((p, n)) = planar(&to) else { return false }; + if let Some(inp) = d.inputs.first_mut() { + inp.items = vec![to]; + } + if let Kind::Primitive { at, .. } = &mut d.kind { + *at = Some((p, Some(n))); + } + d.error = None; + return true; + } + let Some((p, n)) = hits.iter().find_map(|h| match h { + Hit::Face { body, index, point } => Some((*point, planar(&Sel::Face { body: body.clone(), index: *index, point: *point }).map(|(_, n)| n))), + _ => None, + }) else { + return false; + }; + let sz = box_size(app, d); + let Kind::Primitive { cmd, at, .. } = &mut d.kind else { return false }; + match *cmd { + "solid.cone" | "solid.coil" if n.is_none() => return false, + "solid.box" => { + if at.is_none() { + crate::primitive_placement::dropped(&mut d.extra, p, n.unwrap_or(Vec3::Z), sz); + } else { + *at = Some((p, n)); + } + if let Some(inp) = d.inputs.first_mut() { + inp.items.clear(); + } + } + _ => *at = Some((p, n)), + } + d.error = None; + true +} + +/// The primitive's outline on the face: the box's side that stands on it (a face square to an +/// axis), the cylinder's, cone's or coil's base circle, the sphere's widest circle across the +/// face, the torus's outer circle lying flat, as it is made. +fn footprint(app: &SolveApp, d: &Dialog, base: Vec3, n: Vec3) -> Vec { + let Kind::Primitive { cmd, .. } = &d.kind else { return Vec::new() }; + match *cmd { + "solid.box" => { + let sz = box_size(app, d) * 0.5; + if square_to(n, Vec3::Z) { + rect(base, n, Vec3::X, sz.x, sz.y) + } else if square_to(n, Vec3::X) { + rect(base, n, Vec3::Y, sz.y, sz.z) + } else if square_to(n, Vec3::Y) { + rect(base, n, Vec3::X, sz.x, sz.z) + } else { + Vec::new() + } + } + "solid.torus" => circle(base, Vec3::Z, size(app, d, "major") + size(app, d, "minor")), + _ => circle(base, n, radius(app, d)), + } +} + +#[cfg(test)] +#[path = "primitive_tests.rs"] +mod tests; diff --git a/crates/ui-egui/src/place_gizmo/primitive_tests.rs b/crates/ui-egui/src/place_gizmo/primitive_tests.rs new file mode 100644 index 00000000000..9c1974d0bc8 --- /dev/null +++ b/crates/ui-egui/src/place_gizmo/primitive_tests.rs @@ -0,0 +1,408 @@ +//! The primitives' handle: the marker places a new primitive on a face while its dialog is open, +//! moves one from Edit Feature, and an edit opened again finds it where it was moved. + +use serde_json::json; +use solidcore_record::Vec3; +use solidcraft_engine::Sel; +use solidcraft_engine::doc::FeatureKind; +use solidcraft_engine::geom::prelude::*; + +use super::{footprint, frame, move_to}; +use crate::dialogs::Kind; +use crate::scenario::Harness; +use crate::viewport::Hit; + +/// An 80 × 50 × 10 plate seen from the top, with the handles on. +fn plate() -> Harness { + let mut h = Harness::new(); + h.app.set_origin_shown(false); + h.app.preferences.placement_handles = true; + h.app.run("solid.box", json!({"length": 80, "width": 50, "height": 10})).unwrap(); + h.step(&json!({"call": "ui.view", "params": {"view": "top"}})).unwrap(); + h.settle(); + h +} + +fn start(h: &mut Harness, cmd: &str) { + h.step(&json!({"start": cmd})).unwrap(); + h.settle(); +} + +fn drag(h: &mut Harness, to: [f64; 3]) { + assert!(h.at(&json!({"handle": "primitive:position"})).is_ok(), "the marker is published"); + assert!(h.at(&json!({"handle": "primitive:rotate"})).is_err(), "a primitive has no ring"); + h.step(&json!({"drag": [{"handle": "primitive:position"}, {"world": to}], "steps": 12})).unwrap(); + h.settle(); +} + +fn ok(h: &mut Harness) { + h.step(&json!({"click": {"handle": "dialog:OK"}})).unwrap(); + h.settle(); + assert!(h.app.dialog.is_none(), "OK closed the dialog: {:?}", h.app.dialog.as_ref().map(|d| &d.error)); +} + +fn drag_ok(h: &mut Harness, to: [f64; 3]) { + drag(h, to); + ok(h); +} + +fn value(h: &Harness, e: &str) -> f64 { + h.app.session.doc.eval(e, solidcraft_engine::doc::expr::Kind::Length).unwrap() +} + +fn point(h: &Harness, p: &solidcraft_engine::doc::PointExpr) -> Vec3 { + Vec3::new(value(h, &p[0]), value(h, &p[1]), value(h, &p[2])) +} + +/// The open dialog's typed placement under `key` (the corner or centre fields), in mm. +fn typed(h: &Harness, key: &str) -> Vec3 { + let v = h.app.dialog.as_ref().and_then(|d| d.extra.get(key)).and_then(|v| v.as_array()).expect("typed fields"); + let c = |i: usize| value(h, v[i].as_str().expect("a typed field")); + Vec3::new(c(0), c(1), c(2)) +} + +/// The last feature: the primitive just made. +fn last(h: &Harness) -> (String, FeatureKind) { + let f = h.app.session.doc.features.last().expect("a feature"); + (f.name.clone(), f.kind.clone()) +} + +/// Edit Feature on `name` again: the marker stands on screen where `world` is. +fn reopened_at(h: &mut Harness, name: &str, world: [f64; 3]) { + h.step(&json!({"call": "ui.editFeature", "params": {"feature": name}})).unwrap(); + h.settle(); + let at = h.at(&json!({"handle": "primitive:position"})).expect("the marker is published again"); + let expect = h.at(&json!({"world": world})).unwrap(); + assert!((at[0] - expect[0]).hypot(at[1] - expect[1]) < 2.0, "the edit opens with the marker where it was moved: {at:?} {expect:?}"); +} + +#[test] +fn marker_stands_a_new_box_on_the_face_through_its_corner_fields() { + let mut h = plate(); + start(&mut h, "solid.box"); + drag(&mut h, [40.0, 25.0, 10.0]); + let d = h.app.dialog.as_ref().expect("the dialog is open"); + assert!(matches!(d.kind, Kind::Primitive { at: None, .. }), "the typed placement stays: the fields show it"); + assert!(typed(&h, "corner").dist(Vec3::new(30.0, 15.0, 10.0)) < 1e-3, "the corner fields took the drop: {:?}", d.extra.get("corner")); + ok(&mut h); + let (name, kind) = last(&h); + let FeatureKind::Box { corner, .. } = &kind else { panic!("a Box: {kind:?}") }; + // 20 × 20 × 20 by default, centred over the drop and standing on the top. + assert!(point(&h, corner).dist(Vec3::new(30.0, 15.0, 10.0)) < 1e-3, "the corner: {:?}", point(&h, corner)); + reopened_at(&mut h, &name, [40.0, 25.0, 10.0]); +} + +#[test] +fn marker_moves_a_box_placed_by_its_centre_through_its_centre_fields() { + let mut h = plate(); + let made = h.app.run("solid.box", json!({"length": 10, "width": 6, "height": 8, "center": [20, 15, 14], "operation": "join"})).unwrap(); + let name = made["name"].as_str().unwrap().to_string(); + h.settle(); + h.step(&json!({"call": "ui.editFeature", "params": {"feature": name}})).unwrap(); + h.settle(); + // Edit Feature reads the stored corner back; choosing Center keeps the box where it is. + let at = h.at(&json!({"handle": "primitive:position"})).unwrap(); + let expect = h.at(&json!({"world": [20, 15, 10]})).unwrap(); + assert!((at[0] - expect[0]).hypot(at[1] - expect[1]) < 2.0, "the marker stands under the centre, on the bottom: {at:?} {expect:?}"); + { + let d = h.app.dialog.as_mut().expect("a dialog"); + d.extra.remove("corner"); + d.extra.insert("center".into(), json!(["20 mm", "15 mm", "14 mm"])); + } + drag(&mut h, [60.0, 35.0, 10.0]); + let d = h.app.dialog.as_ref().expect("the dialog is open"); + assert!(typed(&h, "center").dist(Vec3::new(60.0, 35.0, 14.0)) < 1e-3, "the centre fields took the drop: {:?}", d.extra.get("center")); + ok(&mut h); + let f = h.app.session.doc.find_feature(&name).expect("the Box is still there"); + let FeatureKind::Box { corner, .. } = &f.kind else { panic!("a Box: {:?}", f.kind) }; + assert!(point(&h, corner).dist(Vec3::new(55.0, 32.0, 10.0)) < 1e-3, "moved: {:?}", point(&h, corner)); + reopened_at(&mut h, &name, [60.0, 35.0, 10.0]); +} + +#[test] +fn a_dropped_box_stands_out_from_a_side_face_and_under_the_underside() { + let mut extra = serde_json::Map::new(); + let size = Vec3::new(20.0, 10.0, 6.0); + let written = crate::primitive_placement::dropped(&mut extra, Vec3::new(80.0, 25.0, 5.0), Vec3::X, size); + assert_eq!(written, Some(json!(["80 mm", "20 mm", "2 mm"])), "out from the +X side, centred across it"); + assert_eq!(extra.get("corner"), written.as_ref()); + extra.remove("corner"); + extra.insert("center".into(), json!(["0", "0", "0"])); + let written = crate::primitive_placement::dropped(&mut extra, Vec3::new(40.0, 25.0, 0.0), -Vec3::Z, size); + assert_eq!(written, Some(json!(["40 mm", "25 mm", "-3 mm"])), "below the underside: the centre half the height down"); + assert!(!extra.contains_key("corner"), "the choice of Center stays"); +} + +#[test] +fn marker_stands_a_new_cylinder_on_the_face_through_its_face_input() { + let mut h = plate(); + start(&mut h, "solid.cylinder"); + // Nothing was pre-selected: the marker starts where the command would put it, the origin. + drag(&mut h, [40.0, 25.0, 10.0]); + let d = h.app.dialog.as_ref().expect("the dialog is still open"); + match d.inputs[0].items.as_slice() { + [Sel::Face { point, .. }] => assert!(point.dist(Vec3::new(40.0, 25.0, 10.0)) < 0.5, "the Face input: {point:?}"), + other => panic!("one face place in the Face input, not {other:?}"), + } + let Kind::Primitive { at, .. } = &d.kind else { panic!("a primitive") }; + assert!(at.is_some_and(|(p, n)| p.dist(Vec3::new(40.0, 25.0, 10.0)) < 0.5 && n == Some(Vec3::Z)), "it stands where the input is: {at:?}"); + ok(&mut h); + let (name, kind) = last(&h); + let FeatureKind::Cylinder { base, axis, .. } = &kind else { panic!("a Cylinder: {kind:?}") }; + assert!(point(&h, base).dist(Vec3::new(40.0, 25.0, 10.0)) < 0.5, "stands where it was dropped: {:?}", point(&h, base)); + assert!(axis.0.dist(Vec3::Z) < 1e-9, "along the face normal: {:?}", axis.0); + reopened_at(&mut h, &name, [40.0, 25.0, 10.0]); +} + +#[test] +fn dragging_a_cylinder_with_a_reference_edge_measures_its_distance_again() { + let mut h = plate(); + start(&mut h, "solid.cylinder"); + h.step(&json!({"click": {"world": [30, 25, 10]}})).unwrap(); + h.settle(); + h.step(&json!({"click": {"world": [0, 20, 10]}})).unwrap(); + h.settle(); + let distance = |h: &Harness| match &h.app.dialog.as_ref().expect("a dialog").kind { + Kind::Primitive { refs, .. } => value(h, &refs.distance[0]), + other => panic!("a primitive: {other:?}"), + }; + assert!((distance(&h) - 30.0).abs() < 0.5, "measured from the left edge: {}", distance(&h)); + drag(&mut h, [50.0, 30.0, 10.0]); + assert!((distance(&h) - 50.0).abs() < 0.5, "measured again from the drop: {}", distance(&h)); + ok(&mut h); + let (_, kind) = last(&h); + let FeatureKind::Cylinder { base, references, .. } = &kind else { panic!("a Cylinder: {kind:?}") }; + assert_eq!(references.len(), 1); + assert!(point(&h, base).dist(Vec3::new(50.0, 30.0, 10.0)) < 0.5, "{:?}", point(&h, base)); +} + +#[test] +fn marker_stands_a_new_cone_on_the_face() { + let mut h = plate(); + start(&mut h, "solid.cone"); + drag_ok(&mut h, [40.0, 25.0, 10.0]); + let (name, kind) = last(&h); + let FeatureKind::Cone { base, axis, .. } = &kind else { panic!("a Cone: {kind:?}") }; + assert!(point(&h, base).dist(Vec3::new(40.0, 25.0, 10.0)) < 0.5, "{:?}", point(&h, base)); + assert!(axis.0.dist(Vec3::Z) < 1e-9, "{:?}", axis.0); + reopened_at(&mut h, &name, [40.0, 25.0, 10.0]); +} + +#[test] +fn marker_moves_a_sphere_from_edit_feature() { + let mut h = plate(); + let made = h.app.run("solid.sphere", json!({"radius": 4, "center": [15, 15, 10], "operation": "join"})).unwrap(); + let name = made["name"].as_str().unwrap().to_string(); + h.settle(); + reopened_at(&mut h, &name, [15.0, 15.0, 10.0]); + drag_ok(&mut h, [60.0, 35.0, 10.0]); + let f = h.app.session.doc.find_feature(&name).expect("the Sphere is still there"); + let FeatureKind::Sphere { center, .. } = &f.kind else { panic!("a Sphere: {:?}", f.kind) }; + assert!(point(&h, center).dist(Vec3::new(60.0, 35.0, 10.0)) < 0.5, "moved: {:?}", point(&h, center)); + h.step(&json!({"expect": {"errors": 0, "bodies": 1}})).unwrap(); + reopened_at(&mut h, &name, [60.0, 35.0, 10.0]); +} + +#[test] +fn marker_stands_a_new_torus_on_the_face() { + let mut h = plate(); + start(&mut h, "solid.torus"); + // Off the plate's middle: there the torus (25 mm out) touches both long sides, and a drop a + // micrometre off it is a near-tangent join the kernel refuses. + drag_ok(&mut h, [40.0, 20.0, 10.0]); + let (name, kind) = last(&h); + let FeatureKind::Torus { center, .. } = &kind else { panic!("a Torus: {kind:?}") }; + assert!(point(&h, center).dist(Vec3::new(40.0, 20.0, 10.0)) < 0.5, "{:?}", point(&h, center)); + reopened_at(&mut h, &name, [40.0, 20.0, 10.0]); +} + +#[test] +fn marker_stands_a_new_coil_on_the_face() { + let mut h = plate(); + start(&mut h, "solid.coil"); + drag_ok(&mut h, [40.0, 25.0, 10.0]); + let (name, kind) = last(&h); + let FeatureKind::Coil { base, axis, .. } = &kind else { panic!("a Coil: {kind:?}") }; + assert!(point(&h, base).dist(Vec3::new(40.0, 25.0, 10.0)) < 0.5, "{:?}", point(&h, base)); + assert!(axis.0.dist(Vec3::Z) < 1e-9, "{:?}", axis.0); + reopened_at(&mut h, &name, [40.0, 25.0, 10.0]); +} + +#[test] +fn a_coil_with_a_sketch_profile_has_no_marker() { + let mut h = plate(); + // A circle on the plate's top: a profile the Coil can sweep. + let sketch = h.app.run("sketch.create", json!({"plane": {"face": [40, 25, 10]}})).unwrap()["sketch"].as_u64().unwrap(); + h.app.run("sketch.circle.center", json!({"center": [60, 25], "radius": 3})).unwrap(); + h.app.run("sketch.finish", json!({})).unwrap(); + h.settle(); + start(&mut h, "solid.coil"); + assert!(h.at(&json!({"handle": "primitive:position"})).is_ok(), "a coil of its own section has the marker"); + h.app.dialog.as_mut().expect("a dialog").inputs[0].items = vec![Sel::Profile { sketch, index: 0 }]; + h.frames(2); + assert!(h.at(&json!({"handle": "primitive:position"})).is_err(), "with a profile picked, no marker"); + let commands = crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap(); + assert_eq!(commands[0].1["sketch"], json!(sketch), "the coil is made from the profile: {:?}", commands[0].1); +} + +/// With the preference off (the default) no primitive's dialog shows the marker. +#[test] +fn with_the_preference_off_no_primitive_has_a_marker() { + let mut h = plate(); + h.app.preferences.placement_handles = false; + for cmd in ["solid.box", "solid.cone", "solid.coil", "solid.cylinder", "solid.sphere", "solid.torus"] { + start(&mut h, cmd); + assert!(h.app.dialog.is_some(), "{cmd}: a dialog"); + assert!(h.at(&json!({"handle": "primitive:position"})).is_err(), "{cmd}: no marker is published"); + h.app.dialog = None; + } +} + +/// The open dialog's marker place and the direction the solid grows from it. +fn place(h: &Harness) -> (Vec3, Vec3) { + frame(&h.app, h.app.dialog.as_ref().expect("a dialog")).expect("a place") +} + +/// The open dialog's footprint at its marker. +fn outline(h: &Harness) -> Vec { + let (base, n) = place(h); + footprint(&h.app, h.app.dialog.as_ref().expect("a dialog"), base, n) +} + +/// The marker dropped on the face at `p`, as one frame of a drag does; whether it took it. The +/// frame after is not run, so the place read next is the one the drop itself left. +fn drop_on(h: &mut Harness, p: [f64; 3]) -> bool { + let Some(Sel::Face { body, index, point }) = crate::dialogs::face_sel(&h.app.session, Vec3::new(p[0], p[1], p[2])) else { + panic!("a face at {p:?}") + }; + let mut d = h.app.dialog.take().expect("a dialog"); + let took = move_to(&h.app, &mut d, &[Hit::Face { body, index, point }], 0); + h.app.dialog = Some(d); + took +} + +#[test] +fn a_box_dropped_on_a_side_face_stands_on_it_and_reopens_there() { + let mut h = plate(); + start(&mut h, "solid.box"); + assert!(drop_on(&mut h, [80.0, 25.0, 5.0]), "the side face takes the box"); + let (base, n) = place(&h); + assert!(base.dist(Vec3::new(80.0, 25.0, 5.0)) < 1e-3 && n.dist(Vec3::X) < 1e-9, "on the side face: {base:?} {n:?}"); + assert!(outline(&h).iter().all(|p| (p.x - 80.0).abs() < 1e-6), "the outline lies on the side face: {:?}", outline(&h)); + ok(&mut h); + let (name, _) = last(&h); + h.step(&json!({"call": "ui.editFeature", "params": {"feature": name}})).unwrap(); + h.settle(); + let (base, n) = place(&h); + assert!(base.dist(Vec3::new(80.0, 25.0, 5.0)) < 1e-3 && n.dist(Vec3::X) < 1e-9, "reopened on the side face: {base:?} {n:?}"); +} + +#[test] +fn a_side_drop_does_not_follow_another_box_with_the_same_fields() { + let mut h = plate(); + start(&mut h, "solid.box"); + assert!(drop_on(&mut h, [80.0, 25.0, 5.0])); + let typed = h.app.dialog.as_ref().unwrap().extra.get("corner").cloned().expect("the corner fields"); + // Another design with no plate: the same fields stand the box on nothing, so its marker is + // under it. + let mut other = Harness::new(); + other.app.preferences.placement_handles = true; + start(&mut other, "solid.box"); + other.app.dialog.as_mut().unwrap().extra.insert("corner".into(), typed); + let (base, n) = place(&other); + assert!(n.dist(Vec3::Z) < 1e-9 && base.dist(Vec3::new(90.0, 25.0, -5.0)) < 1e-3, "the middle of its bottom: {base:?} {n:?}"); +} + +#[test] +fn a_box_on_a_vertex_has_its_marker_and_outline_at_its_bottom() { + let mut h = plate(); + h.app.session.selection = vec![Sel::Vertex { body: "Body1".into(), point: Vec3::new(80.0, 50.0, 10.0) }]; + start(&mut h, "solid.box"); + // The box is centred on the vertex (20 high), so its bottom is 10 below it. + let (base, n) = place(&h); + assert!(base.dist(Vec3::new(80.0, 50.0, 0.0)) < 1e-6 && n.dist(Vec3::Z) < 1e-9, "{base:?} {n:?}"); + assert!(outline(&h).iter().all(|p| p.z.abs() < 1e-6), "the outline is the box's bottom: {:?}", outline(&h)); +} + +#[test] +fn a_box_moved_by_its_marker_drops_its_point_pick() { + let mut h = plate(); + start(&mut h, "solid.box"); + { + let s = &h.app.session; + let d = h.app.dialog.as_mut().unwrap(); + d.pick(s, Sel::Vertex { body: "Body1".into(), point: Vec3::new(0.0, 0.0, 10.0) }); + } + assert!(!h.app.dialog.as_ref().unwrap().inputs[0].items.is_empty(), "the point is picked"); + assert!(drop_on(&mut h, [40.0, 25.0, 10.0])); + let d = h.app.dialog.as_ref().unwrap(); + assert!(d.inputs[0].items.is_empty(), "the pick no longer says where the box is: {:?}", d.inputs[0].items); + assert!(crate::canvas::anchor(&h.app, d).is_none(), "nothing on the canvas stays at the old point"); +} + +#[test] +fn a_torus_dropped_on_a_side_face_is_outlined_flat_as_it_is_made() { + let mut h = plate(); + start(&mut h, "solid.torus"); + assert!(drop_on(&mut h, [80.0, 25.0, 5.0])); + let o = outline(&h); + assert!(!o.is_empty() && o.iter().all(|p| (p.z - 5.0).abs() < 1e-6), "flat about its centre: {o:?}"); + let commands = crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap(); + assert!(commands[0].1.get("axis").is_none(), "the torus has no axis to tilt: {:?}", commands[0].1); +} + +#[test] +fn a_cylinder_follows_its_marker_in_the_same_frame() { + let mut h = plate(); + start(&mut h, "solid.cylinder"); + assert!(drop_on(&mut h, [40.0, 25.0, 10.0])); + let (base, n) = place(&h); + assert!(base.dist(Vec3::new(40.0, 25.0, 10.0)) < 0.5 && n.dist(Vec3::Z) < 1e-9, "no frame behind the pointer: {base:?}"); +} + +#[test] +fn a_cone_coil_or_cylinder_is_not_dropped_on_a_curved_face() { + let mut h = plate(); + h.app.run("solid.cylinder", json!({"radius": 10, "height": 20, "base": [40, 25, 10], "operation": "new"})).unwrap(); + h.settle(); + for cmd in ["solid.cone", "solid.coil", "solid.cylinder"] { + start(&mut h, cmd); + let before = place(&h); + assert!(!drop_on(&mut h, [50.0, 25.0, 20.0]), "{cmd}: a curved face has no one axis to stand on"); + assert_eq!(place(&h), before, "{cmd}: it stays where it was"); + h.app.dialog = None; + } +} + +#[test] +fn a_tilted_cone_placed_at_a_point_keeps_its_axis_for_the_marker() { + let mut h = plate(); + let made = h + .app + .run("solid.cone", json!({"radius": 5, "top_radius": 0, "height": 10, "base": [20, 20, 30], "axis": [1, 0, 0], "operation": "new"})) + .unwrap(); + let name = made["name"].as_str().unwrap().to_string(); + h.settle(); + h.step(&json!({"call": "ui.editFeature", "params": {"feature": name}})).unwrap(); + h.settle(); + if let Some(Kind::Primitive { at, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) { + *at = Some((Vec3::new(20.0, 20.0, 30.0), None)); + } + let (_, n) = place(&h); + assert!(n.dist(Vec3::X) < 1e-9, "the axis the cone is made along: {n:?}"); + assert!(outline(&h).iter().all(|p| (p.x - 20.0).abs() < 1e-6), "the base circle across that axis"); +} + +#[test] +fn a_cylinder_with_a_reference_edge_reopens_with_its_marker_and_outline_on_its_face() { + let mut h = plate(); + let made = h + .app + .run("solid.cylinder", json!({"radius": 4, "height": 8, "base": [30, 25, 10], "axis": [0, 0, 1], "references": [{"edge": [0, 20, 10], "distance": "30 mm"}], "operation": "join"})) + .unwrap(); + let name = made["name"].as_str().unwrap().to_string(); + h.settle(); + reopened_at(&mut h, &name, [30.0, 25.0, 10.0]); + let o = outline(&h); + assert!(!o.is_empty() && o.iter().all(|p| (p.z - 10.0).abs() < 1e-6 && (p.dist(Vec3::new(30.0, 25.0, 10.0)) - 4.0).abs() < 1e-6), "{o:?}"); +} diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index 72ccaa32000..42849c2ee3b 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -1492,9 +1492,11 @@ preference_settings! { hole_several: bool = false, PAGE_TOOLS => check_id("prefs.design_tools.hole_several"); /// The browser's Origin folder starts hidden in designs that don't keep its eye themselves. hide_origin: bool = false, PAGE_DESIGN => check_tr("ui.hide_origin_by_default"); - /// Handles on the preview of a feature placed on a face (Rest, Boss, Snap Fit): a marker that - /// drags it across the model and a ring that turns it. Off by default: the feature is then placed - /// by its click only, as before, and its Position input takes faces only. + /// Handles on the preview of a feature placed on a face (Rest, Boss, Snap Fit, and the Box, + /// Cylinder, Cone, Sphere, Torus and Coil): a marker that drags it across the model and, where + /// it can turn in the face, a ring that turns it. Off by default: a Rest, Boss or Snap Fit is + /// then placed by its click only, as before, and its Position input takes faces only; a + /// primitive by its fields, its inputs or the selection it opened with. placement_handles: bool = false, PAGE_TOOLS => check_tr("ui.placement_handles"); /// The files a design names (linked designs, font files) may be on any network location, for /// organisations that keep their designs on file servers. Off (the default): only on the diff --git a/crates/ui-egui/src/primitive_placement.rs b/crates/ui-egui/src/primitive_placement.rs index dff599f2fa9..f6a4abe76db 100644 --- a/crates/ui-egui/src/primitive_placement.rs +++ b/crates/ui-egui/src/primitive_placement.rs @@ -14,7 +14,7 @@ use serde_json::{Map, Value, json}; use solidcore_record::Vec3; use solidcraft_engine::Session; use solidcraft_engine::doc::expr::Kind as ValueKind; -use solidcraft_engine::geom::PlaneGeom as _; +use solidcraft_engine::geom::prelude::*; use crate::i18n::tr; use crate::selection::{EDGES, EXTERNAL_POINTS, FACES, ORIGIN, POINTS, SelInput, VERTICES}; @@ -138,6 +138,32 @@ pub(crate) fn picked(s: &Session, cmd: &str, at: &mut Option<(Vec3, Option *at = None; } +/// A Box dropped by its placement marker at `p` on a face with normal `n`: the current placement +/// (the corner or the centre) written so the box stands on the face, centred on `p` across it +/// (only centred on `p` on a face square to no axis), as a pre-selected face places it. `size` is +/// the box's length, width and height (mm). Returns the point written. +pub(crate) fn dropped(extra: &mut Map, p: Vec3, n: Vec3, size: Vec3) -> Option { + if !p.is_finite() { + return None; + } + // How much of the size lies behind `p` along each axis: none (or all) along the face's + // normal, half across it. + let back = |c: f64, size: f64, axis: Vec3| match n.dot(axis) { + d if d > 1.0 - 1e-9 => c, + d if d < -1.0 + 1e-9 => c - size, + _ => c - size * 0.5, + }; + let corner = Vec3::new(back(p.x, size.x, Vec3::X), back(p.y, size.y, Vec3::Y), back(p.z, size.z, Vec3::Z)); + let index = keys("solid.box").iter().position(|k| extra.contains_key(*k)).unwrap_or(0); + let at = if index == 0 { corner } else { corner + size * 0.5 }; + // A drop is only as exact as the pointer: to the micrometre, so the fields read 45 mm, not + // 44.999991 mm. + let um = |v: f64| mm((v * 1e3).round() / 1e3); + let coords = [um(at.x), um(at.y), um(at.z)]; + store("solid.box", extra, index, &coords); + Some(json!(coords)) +} + /// The typed placement into the command's parameters: a bare number typed into a field is in the /// design's units (as in the size fields), an empty field is 0, and a stored number is kept. pub(crate) fn params(s: &Session, cmd: &str, extra: &Map, p: &mut Map) { diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 08b5bd1b46b..9b734b022b3 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -804,7 +804,7 @@ no box selection. | `ui.dialogInput` | `index` | what clicking an input's Select chip does: picks go to that input | | `ui.at` | `world: [x,y,z]` \| `sketch: [x,y]` \| `plane: "XY"` \| `axis: "Z"` \| `dimension: "d1"` (its value text) \| `handle: "arrow"` (a manipulator handle, see `scenario::publish_handle`) | the screen point (a scenario step's target; see `crates/ui-egui/src/scenario.rs`) | | `ui.pick` | `pixels?: [[x,y]…]`, `rays?: [{origin, dir}…]`, `frame?: "window"\|"model"`, `width?`, `height?`, `edges?` (default true), `edge_px?` (default 6), `all?`, `include_ghosted?` | read-only geometry under each pixel or ray (#6304): one entry per input, `null` where nothing is hit — body, face index, exact world `point` and outward `normal`, `depth`, `occurrence`/`component` for placed parts, `edge`/`vertex` within `edge_px` of a pixel, `section_cap: true` on a cut face. `window` pixels are physical pixels of a window screenshot; `model` pixels are pixels of a `ui.render` of `width`×`height` (default 960×600), so it works headless. As `view.pick` through `engine.execute`/`engine.batch`. See `crates/ui-egui/src/view_pick.rs` | -| `ui.handles` | `prefix?` | the handles drawn last frame, `[{name, x, y}]`: toolbar buttons and drop-down items `toolbar:` (the button alone: `button:`; a drop-down row: `dropdown:`, highlighted `dropdown_hot:`, its pin `dropdown_pin:`; Customize Toolbar's check boxes `customize:`), ribbon tabs `tab:` (MODEL, SURFACE, ASSEMBLE, INSERT, INSPECT, MANAGE, VIEW, SHEET METAL, WELDMENTS; contextual SKETCH; workspace RENDER), the toolbar menu button `ribbon:add_tab`, the hint when every tab is hidden `ribbon:tabs_hidden`, Preferences tab check boxes `prefs:toolbar_tab:`, panel labels `panel::` (also `ribbon:section::
`), document overflow list `tab:overflow`, workspace column `ribbon:workspace`, command-search launcher `ribbon:search`, browser rows `row: