Skip to content

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

Browser: a Joints folder under each component lists the joints that attach it (#9130) (#9404)

PaddleStroke5304294107f6
diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs
index 60fb04db5f..08e0adc77b 100644
--- a/crates/ui-egui/src/browser.rs
+++ b/crates/ui-egui/src/browser.rs
@@ -1744,6 +1744,8 @@ fn occurrence_rows_inner(
}
if !render {
features::rows(app, ui, placement.component, path, depth + 1, acts);
+ // The joints that attach this placement, as the root's Joints folder lists them (#9130).
+ crate::dialogs_assembly::component_joints(app, ui, path, key, depth + 1);
}
if path.len() < 64 {
for child in &placement.children {
diff --git a/crates/ui-egui/src/dialogs_assembly.rs b/crates/ui-egui/src/dialogs_assembly.rs
index 83c2926c69..a753771d3c 100644
--- a/crates/ui-egui/src/dialogs_assembly.rs
+++ b/crates/ui-egui/src/dialogs_assembly.rs
@@ -1510,6 +1510,105 @@ pub fn pick_joint(app: &mut SolveApp, id: u64, add: bool) {
}
}
+/// A placement's Joints folder (#9130): the design's joints that attach this placement (it is
+/// one of the two they join), each beside the placement it joins this one to. The rows are the
+/// same joints as the root Joints folder's and act the same: a click picks the joint, a
+/// double-click edits it, the eye shows or hides its glyph and the menu is the joint's menu.
+/// The folder starts closed and has no eye of its own (the root folder's eye hides every joint
+/// glyph); it isn't drawn for a placement no joint attaches. `key` is the placement's row key.
+pub fn component_joints(app: &mut SolveApp, ui: &mut egui::Ui, path: &[u64], key: &str, depth: usize) {
+ use crate::browser::{Row, draw_row, is_open, toggle};
+ let joints = placement_joints(&app.session.doc, path);
+ if joints.is_empty() {
+ return;
+ }
+ let key = format!("{key}/joints");
+ let open = is_open(app, &key, false);
+ let r = draw_row(ui, ui.id().with(&key), &Row { depth, fold: Some(open), icon: "folder", label: "Joints", ..Default::default() });
+ if r.fold || r.clicked {
+ toggle(app, &key, false);
+ }
+ if !open {
+ return;
+ }
+ // Hiding the root folder hides every glyph: these rows fade with it, as its own rows do.
+ let folder_shown = !app.session.folder_hidden("c0/joints");
+ let mut dialog: Option<Dialog> = None;
+ for j in joints {
+ let id = j.id;
+ let visible = app.session.joint_visible(id);
+ let selected = app.tree.picked_joints.contains(&id);
+ let r = draw_row(
+ ui,
+ ui.id().with((&key, "joint", id)),
+ &Row {
+ depth: depth + 1,
+ eye: Some(visible),
+ icon: "joint",
+ label: &j.name,
+ secondary: &j.other,
+ name: true,
+ selected,
+ dim: j.suppressed || !visible || !folder_shown,
+ ..Default::default()
+ },
+ );
+ if let Some(resp) = &r.resp {
+ resp.clone().on_hover_text(format!("{:?} joint", j.kind));
+ }
+ if r.eye {
+ let _ = app.run("browser.visibility", json!({ "joints": [id], "visible": !visible }));
+ } else if r.clicked {
+ pick_joint(app, id, ui.input(|i| i.modifiers.command || i.modifiers.ctrl));
+ }
+ if r.double {
+ dialog = edit_joint(app, id);
+ }
+ if let Some(at) = r.secondary {
+ if !app.tree.picked_joints.contains(&id) {
+ pick_joint(app, id, false);
+ }
+ crate::context_menu::open_for(app, at, crate::context_menu::Target::Joint { id });
+ }
+ }
+ if let Some(d) = dialog {
+ app.tool = None;
+ app.dialog = Some(d);
+ }
+}
+
+/// A joint as a placement's Joints folder lists it.
+#[derive(Clone, Debug, PartialEq)]
+pub(crate) struct PlacementJoint {
+ pub id: u64,
+ pub name: String,
+ pub kind: JointKind,
+ pub suppressed: bool,
+ /// The name of the placement the joint joins this one to (empty when there is none).
+ pub other: String,
+}
+
+/// The joints that attach the placement at `path` (its last occurrence is one of the two a
+/// joint joins), in the design's joint order.
+pub(crate) fn placement_joints(doc: &solidcraft_engine::doc::Document, path: &[u64]) -> Vec<PlacementJoint> {
+ let Some(&occ) = path.last() else { return Vec::new() };
+ let name_of = |o: u64| doc.occurrences.iter().find(|x| x.id == o).map(|x| x.name.clone()).unwrap_or_default();
+ doc.assembly
+ .joints
+ .iter()
+ .filter_map(|j| {
+ let other = if j.a.occurrence == occ {
+ j.b.occurrence
+ } else if j.b.occurrence == occ {
+ j.a.occurrence
+ } else {
+ return None;
+ };
+ Some(PlacementJoint { id: j.id, name: j.name.clone(), kind: j.kind, suppressed: j.suppressed, other: name_of(other) })
+ })
+ .collect()
+}
+
#[cfg(test)]
#[path = "dialogs_assembly_tests.rs"]
mod tests;
diff --git a/crates/ui-egui/src/joint_browser_tests.rs b/crates/ui-egui/src/joint_browser_tests.rs
index 15f07c5053..d88f00a9ae 100644
--- a/crates/ui-egui/src/joint_browser_tests.rs
+++ b/crates/ui-egui/src/joint_browser_tests.rs
@@ -109,6 +109,66 @@ fn the_menu_and_the_v_key_hide_and_show_picked_joints() {
assert!(h.app.session.joint_visible(hinge) && h.app.session.joint_visible(glue));
}
+/// Each placement has a Joints folder listing the joints that attach it, beside the placement
+/// each joins it to (#9130). Its rows are the root folder's joints: a click picks, the eye
+/// hides, a double-click edits and the menu acts on the same joint.
+#[test]
+fn each_placement_lists_the_joints_that_attach_it() {
+ let mut h = harness();
+ let hinge = id(&h, "Hinge");
+ let occ = |h: &Harness, name: &str| h.app.session.doc.occurrences.iter().find(|o| o.name == name).unwrap().id;
+ let (a, b, c) = (occ(&h, "A:1"), occ(&h, "B:1"), occ(&h, "C:1"));
+ let listed = |h: &Harness, o: u64| -> Vec<(String, String)> {
+ crate::dialogs_assembly::placement_joints(&h.app.session.doc, &[o]).into_iter().map(|j| (j.name, j.other)).collect()
+ };
+ let pair = |n: &str, o: &str| (n.to_string(), o.to_string());
+ assert_eq!(listed(&h, a), [pair("Hinge", "B:1"), pair("Glue", "C:1")]);
+ assert_eq!(listed(&h, b), [pair("Hinge", "A:1")]);
+ assert_eq!(listed(&h, c), [pair("Glue", "A:1")]);
+
+ // The folders start closed: only the root's lists rows.
+ let rows = |label: &str| crate::browser::drawn_rows().into_iter().filter(|r| r.0 == label).map(|r| r.1.center().y).collect::<Vec<_>>();
+ assert_eq!(rows("Joints").len(), 4, "the root's Joints folder and one per placement");
+ assert_eq!(rows("Hinge").len(), 1);
+
+ // Opened, B's folder lists Hinge a second time, below the root's.
+ h.app.tree.expanded.insert(format!("o:{b}/joints"));
+ h.frames(3);
+ let hinges = rows("Hinge");
+ assert_eq!(hinges.len(), 2);
+ assert_eq!(rows("Glue").len(), 1, "Glue doesn't attach B");
+ let at = crate::scenario::handle_at("row:Hinge").unwrap();
+ assert_eq!(at.y, hinges[1], "the row clicked below is B's");
+
+ h.step(&json!({"click": {"handle": "row:Hinge"}, "double": true})).unwrap();
+ h.frames(3);
+ let editing = match h.app.dialog.as_ref().map(|d| &d.kind) {
+ Some(crate::dialogs::Kind::Assembly(crate::dialogs_assembly::Asm::Joint(f))) => f.editing,
+ _ => None,
+ };
+ assert_eq!(editing, Some(hinge), "a double click edits the joint");
+ h.step(&json!({"key": "Escape"})).unwrap();
+ h.frames(3);
+ assert!(h.app.dialog.is_none());
+
+ h.app.tree.picked_joints.clear();
+ click(&mut h, "row:Hinge");
+ assert_eq!(h.app.tree.picked_joints, [hinge]);
+ click(&mut h, "eye:Hinge");
+ assert!(!h.app.session.joint_visible(hinge), "B's eye hides the joint itself");
+ click(&mut h, "eye:Hinge");
+ assert!(h.app.session.joint_visible(hinge));
+
+ // Its menu is the joint's: Delete removes Hinge, and B, which nothing joins now, has no folder.
+ h.step(&json!({"click": {"handle": "row:Hinge"}, "button": "right"})).unwrap();
+ h.frames(3);
+ h.step(&json!({"widget": "Delete"})).unwrap();
+ h.frames(3);
+ assert!(h.app.session.doc.assembly.joints.iter().all(|j| j.id != hinge));
+ assert!(listed(&h, b).is_empty());
+ assert_eq!(rows("Joints").len(), 3, "the root's, A's and C's");
+}
+
mod delete {
//! Joint history and Browser selection must be the target of the Delete key.
use serde_json::{Value, json};