Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Combine takes bodies clicked in the Browser (#4452) (#4766)

DuBearte1a953736ff4a
diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs
index caf16527f0..880786578e 100644
--- a/crates/ui-egui/src/browser.rs
+++ b/crates/ui-egui/src/browser.rs
@@ -1580,9 +1580,24 @@ impl CanvasPanel {
}
}
+/// Does the open dialog's active input take bodies (Combine's target and tools, #4452)? Then a
+/// body clicked in the Browser goes there, as a click on it in the view does, rather than
+/// replacing the selection: overlapping bodies are often only told apart in the Browser.
+fn dialog_takes_body(app: &SolveApp) -> bool {
+ app.dialog.as_ref().and_then(|d| d.active_input()).is_some_and(|i| i.accept & crate::selection::BODIES != 0)
+}
+
/// A browser click on a plane or axis: it goes to the open dialog's input if that takes it,
/// otherwise it becomes the selection.
fn pick_from_browser(app: &mut SolveApp, x: Sel) {
+ if let Sel::Body { .. } = &x
+ && dialog_takes_body(app)
+ && let Some(mut d) = app.dialog.take()
+ {
+ d.pick(&app.session, x);
+ app.dialog = Some(d);
+ return;
+ }
let hit = match &x {
Sel::Plane { name } => crate::viewport::Hit::Plane { name: name.clone(), point: solidcraft_engine::geom::Vec3::ZERO },
Sel::Axis { name } => crate::viewport::Hit::Axis { name: name.clone() },
@@ -1978,6 +1993,8 @@ fn entry_row(
if let Some(s) = e.sel.clone() {
pick_from_browser(app, s);
}
+ } else if let Some(s) = e.sel.clone().filter(|s| matches!(s, Sel::Body { .. }) && dialog_takes_body(app)) {
+ pick_from_browser(app, s);
} else {
click_select(app, ui, e.row_key.clone(), e.sel.clone());
}
diff --git a/crates/ui-egui/src/preselect_tests.rs b/crates/ui-egui/src/preselect_tests.rs
index 0a88937735..c3d040ab1d 100644
--- a/crates/ui-egui/src/preselect_tests.rs
+++ b/crates/ui-egui/src/preselect_tests.rs
@@ -2272,3 +2272,43 @@ fn hovering_a_large_body_does_not_wait_for_its_pick_index() {
assert!(matches!(h.app.viewport.hover, Some(crate::viewport::Hit::Face { .. })), "{:?}", h.app.viewport.hover);
assert!(hover_ms < index_ms / 3.0, "the first hover took {hover_ms:.1} ms; making the index takes {index_ms:.1} ms");
}
+
+/// #4452: with Combine open, bodies clicked in the Browser fill its inputs, as clicks on them
+/// in the view do: the first is the target, the next the tools. Overlapping bodies are often
+/// only told apart in the Browser.
+#[test]
+fn combine_takes_bodies_clicked_in_the_browser() {
+ for layout in ["docked", "floating"] {
+ for control in [false, true] {
+ combine_takes_bodies_clicked_in_the_browser_in(layout, control);
+ }
+ }
+}
+
+/// `control`: click the rows as the control channel's `ui.click` does (move, press and release
+/// in one frame), as an agent or a live screenshot run does.
+fn combine_takes_bodies_clicked_in_the_browser_in(layout: &str, control: bool) {
+ let mut h = crate::scenario::Harness::new();
+ h.step(&json!({"call": "ui.set", "params": {"layout": layout}})).unwrap();
+ h.frames(2);
+ h.app.run("solid.box", json!({"corner": [0, 0, 0], "length": 20, "width": 20, "height": 20, "body_name": "Block"})).unwrap();
+ h.app.run("solid.box", json!({"corner": [10, 10, 10], "length": 20, "width": 20, "height": 20, "body_name": "Cutter"})).unwrap();
+ h.app.session.selection.clear();
+ h.app.start("solid.combine");
+ h.frames(2);
+ for label in ["Block", "Cutter"] {
+ if control {
+ let rows = h.call("ui.handles", json!({"prefix": "row:"}))["result"].clone();
+ let rows = rows.get("handles").cloned().unwrap_or(rows);
+ let row = rows.as_array().unwrap().iter().find(|r| r["name"] == format!("row:{label}")).cloned().unwrap();
+ h.call("ui.click", json!({"x": row["x"], "y": row["y"]}));
+ h.frames(2);
+ } else {
+ h.step(&json!({"click": {"browser": label}})).unwrap();
+ h.frames(1);
+ }
+ }
+ let d = h.app.dialog.as_ref().expect("Combine stays open");
+ assert_eq!(d.inputs[0].items, vec![Sel::Body { name: "Block".into() }], "{layout} control={control} target: {:?}", d.inputs);
+ assert_eq!(d.inputs[1].items, vec![Sel::Body { name: "Cutter".into() }], "{layout} control={control} tools: {:?}", d.inputs);
+}