From ddd65cc4bb8429f612d31b7fc5976bcb1a0aeb23 Mon Sep 17 00:00:00 2001 From: kaltenbrunnermarkus <153593707+kaltenbrunnermarkus@users.noreply.github.com> Date: Sun, 1 Nov 2026 10:10:01 +0000 Subject: [PATCH] Move: say a part's joint conflicts instead of 'no movable joint axis' (#10509) * claim: Move: say a part's joint conflicts instead of 'no movable joint axis' * Move: say a part's joint conflicts instead of 'no movable joint axis' When a joint of the selected part conflicts with the others (the solver can't close its loop), Move found no axis and said "This part has no movable joint axis.", pointing at joint types and limits. It now names the conflicting joint and suggests editing, suppressing or deleting it. Parts with no free joint value and no conflict keep the old message. Refs #10331 Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Markus Kaltenbrunner Co-authored-by: Claude Opus 5.5 --- .../locales/pending/move-joint-conflict.json | 38 ++++++ crates/ui-egui/src/context_menu.rs | 2 +- crates/ui-egui/src/joint_handles.rs | 113 ++++++++++++++++-- 3 files changed, 143 insertions(+), 10 deletions(-) create mode 100644 assets/locales/pending/move-joint-conflict.json diff --git a/assets/locales/pending/move-joint-conflict.json b/assets/locales/pending/move-joint-conflict.json new file mode 100644 index 000000000..c8eeee471 --- /dev/null +++ b/assets/locales/pending/move-joint-conflict.json @@ -0,0 +1,38 @@ +{ + "en": { + "joint_move.conflict": "A joint of this part conflicts with the others: {joint}.", + "joint_move.conflict_hint": "Edit, suppress or delete the conflicting joint so the other joints can place the part." + }, + "ar": { + "joint_move.conflict": "يتعارض أحد مفاصل هذا الجزء مع المفاصل الأخرى: {joint}.", + "joint_move.conflict_hint": "عدّل المفصل المتعارض أو عطّله أو احذفه حتى تتمكن المفاصل الأخرى من وضع الجزء." + }, + "de": { + "joint_move.conflict": "Ein Gelenk dieses Bauteils steht im Konflikt mit den anderen: {joint}.", + "joint_move.conflict_hint": "Bearbeiten, unterdrücken oder löschen Sie das widersprüchliche Gelenk, damit die anderen Gelenke das Bauteil platzieren können." + }, + "he": { + "joint_move.conflict": "אחד המפרקים של החלק הזה מתנגש עם האחרים: {joint}.", + "joint_move.conflict_hint": "ערכו, השביתו או מחקו את המפרק המתנגש כדי שהמפרקים האחרים יוכלו למקם את החלק." + }, + "ja": { + "joint_move.conflict": "この部品のジョイントが他のジョイントと競合しています: {joint}。", + "joint_move.conflict_hint": "競合しているジョイントを編集、抑制、または削除して、他のジョイントで部品を配置できるようにしてください。" + }, + "ko": { + "joint_move.conflict": "이 부품의 조인트가 다른 조인트와 충돌합니다: {joint}.", + "joint_move.conflict_hint": "충돌하는 조인트를 편집, 비활성화 또는 삭제하여 다른 조인트가 부품을 배치할 수 있게 하세요." + }, + "vi": { + "joint_move.conflict": "Một khớp nối của chi tiết này xung đột với các khớp nối khác: {joint}.", + "joint_move.conflict_hint": "Chỉnh sửa, tạm nén hoặc xóa khớp nối xung đột để các khớp nối khác có thể định vị chi tiết." + }, + "zh": { + "joint_move.conflict": "此零部件的一个关节与其他关节冲突:{joint}。", + "joint_move.conflict_hint": "请编辑、抑制或删除冲突的关节,以便其他关节可以放置该零部件。" + }, + "zh-TW": { + "joint_move.conflict": "此零件的一個接頭與其他接頭衝突:{joint}。", + "joint_move.conflict_hint": "請編輯、抑制或刪除衝突的接頭,讓其他接頭可以放置此零件。" + } +} diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rs index 2b47d3f03..cc70f1bb9 100644 --- a/crates/ui-egui/src/context_menu.rs +++ b/crates/ui-egui/src/context_menu.rs @@ -238,7 +238,7 @@ pub struct MenuState { /// A delete waiting for its confirmation (it takes or breaks other features). pub confirm: Option, /// A selected part has no free joint value for the explicit assembly Move command. - pub joint_move_warning: Option, + pub(crate) joint_move_warning: Option, /// Identical copies Extract to File found, waiting to be linked too. pub link_copies: Option, /// The Properties window: title and measurements. diff --git a/crates/ui-egui/src/joint_handles.rs b/crates/ui-egui/src/joint_handles.rs index 58f2d4601..8954a0b91 100644 --- a/crates/ui-egui/src/joint_handles.rs +++ b/crates/ui-egui/src/joint_handles.rs @@ -202,16 +202,62 @@ pub(crate) fn start(app: &mut SolveApp) { { crate::context_menu::run_item(app, &item, Pos2::ZERO); } else { - app.set_status(app.tr("joint_move.fixed").to_string(), false); - let part = app.session.doc.occurrences.iter().find(|o| o.id == occurrence).map(|o| o.name.clone()).unwrap_or_default(); - app.menu.joint_move_warning = Some(part); + let blocked = Blocked::of(app, occurrence); + app.set_status(blocked.reason(app), false); + app.menu.joint_move_warning = Some(blocked); + } +} + +/// Why Move found no axis to show for a part, kept for the warning until it is acknowledged. +#[derive(Clone, Debug, PartialEq, Eq)] +pub(crate) struct Blocked { + pub(crate) part: String, + /// Names of this part's joints the solver reports as conflicting (it can't close their + /// loop). Empty when the part simply has no free joint value. + pub(crate) conflicts: Vec, +} + +impl Blocked { + /// A conflicting joint also leaves no axis, but "no movable joint axis" would send the user + /// to the joint types and limits instead of to the joint that disagrees (#10331). Only + /// joints on this part count: a conflict elsewhere in the design is not why it is blocked. + fn of(app: &SolveApp, occurrence: u64) -> Self { + let doc = &app.session.doc; + let part = doc.occurrences.iter().find(|o| o.id == occurrence).map(|o| o.name.clone()).unwrap_or_default(); + let on_part: BTreeSet = doc + .assembly + .joints + .iter() + .filter(|j| !j.suppressed && (j.a.occurrence == occurrence || j.b.occurrence == occurrence)) + .map(|j| j.id) + .collect(); + let mut conflicts = Vec::new(); + if !on_part.is_empty() { + let solution = joints::solve_holding_with_analysis(doc, &app.session.model.state(), &joints::Held::new(), joints::Analysis::Placement); + for (id, name, _) in solution.conflicts { + if on_part.contains(&id) && !conflicts.contains(&name) { + conflicts.push(name); + } + } + } + Self { part, conflicts } + } + + fn reason(&self, app: &SolveApp) -> String { + if self.conflicts.is_empty() { + app.tr("joint_move.fixed").to_string() + } else { + crate::i18n::format("joint_move.conflict", &[("joint", &self.conflicts.join(", "))]) + } } } /// A blocked Move is a persistent warning, acknowledged with OK, Enter, Escape or Close. /// It never changes the joint type, grounding, limits or the selected geometry. pub(crate) fn show_warning(app: &mut SolveApp, ctx: &egui::Context) { - let Some(part) = app.menu.joint_move_warning.clone() else { return }; + let Some(blocked) = app.menu.joint_move_warning.clone() else { return }; + let reason = blocked.reason(app); + let hint = if blocked.conflicts.is_empty() { "joint_move.blocked_hint" } else { "joint_move.conflict_hint" }; if ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) { app.menu.joint_move_warning = None; return; @@ -220,11 +266,11 @@ pub(crate) fn show_warning(app: &mut SolveApp, ctx: &egui::Context) { .tone(crate::ui_kit::Tone::Warning) .actions(app.tr("ui.heading_ok"), "", None) .show(ctx, true, |ui| { - if !part.is_empty() { - crate::ui_kit::text(ui, &part, crate::ui_kit::Text::Report("part", false)); + if !blocked.part.is_empty() { + crate::ui_kit::text(ui, &blocked.part, crate::ui_kit::Text::Report("part", false)); } - crate::ui_kit::text(ui, app.tr("joint_move.fixed"), crate::ui_kit::Text::Report("reason", false)); - crate::ui_kit::text(ui, app.tr("joint_move.blocked_hint"), crate::ui_kit::Text::Hint("remedy")); + crate::ui_kit::text(ui, &reason, crate::ui_kit::Text::Report("reason", false)); + crate::ui_kit::text(ui, app.tr(hint), crate::ui_kit::Text::Hint("remedy")); }); app.viewport.dialog_rect = crate::scenario::rect_of("dialog:window"); if closed || action != crate::ui_kit::Action::None { @@ -977,6 +1023,55 @@ mod tests { let invalid = crate::prefs::lenient(&json!({"joint_rotation_coarse":0,"joint_rotation_fine":-3})); assert_eq!((invalid.joint_rotation_coarse, invalid.joint_rotation_fine), (10., 0.1)); } + /// Two boards held by two planar joints whose planes cross (#10331): the second joint can't + /// close its loop, so Move names it instead of saying the part has no movable axis. + #[test] + fn blocked_move_names_a_conflicting_joint_of_the_part() { + let mut h = Harness::new(); + h.app.home.open = false; + for (name, y) in [("Yellow", 0), ("Red", 300)] { + h.app.run("component.activate", json!({"component":"root"})).unwrap(); + h.app.run("component.create", json!({"name":name,"grounded":false})).unwrap(); + h.app.run("solid.box", json!({"length":400,"width":100,"height":20,"corner":[0,y,0]})).unwrap(); + } + h.app.run("component.activate", json!({"component":"root"})).unwrap(); + h.app.run("occurrence.ground", json!({"occurrence":"Yellow:1","grounded":true})).unwrap(); + let planar = |name: &str, a: [i32; 3], b: [i32; 3]| json!({"type":"planar","a":{"occurrence":"Yellow","face":a},"b":{"occurrence":"Red","face":b},"name":name}); + h.app.run("joint.create", planar("Top", [200, 50, 20], [200, 350, 0])).unwrap(); + h.app.run("joint.create", planar("Front", [200, 0, 10], [200, 0, 30])).unwrap(); + let solved = joints::solve(&h.app.session.doc, &h.app.session.model.state()); + let conflicting: Vec<_> = solved.conflicts.iter().map(|(_, name, _)| name.as_str()).collect(); + assert!(!conflicting.is_empty(), "the scenario must conflict: {:?}", solved.conflicts); + let component = h.app.session.doc.find_component("Red").unwrap(); + let world = h.app.session.world_state(); + let body = world.bodies.iter().find(|b| h.app.session.doc.model_body_component(b) == component).unwrap().name.clone(); + h.app.session.selection = vec![Sel::Body { name: body }]; + h.frames(3); + h.step(&json!({"click":{"handle":"tab:ASSEMBLE"}})).unwrap(); + h.step(&json!({"click":{"handle":"button:occurrence.move"}})).unwrap(); + h.frames(3); + let blocked = h.app.menu.joint_move_warning.clone().expect("Move must be blocked"); + assert_eq!(blocked.part, "Red:1"); + assert_eq!(blocked.conflicts, conflicting); + let reason = blocked.reason(&h.app); + assert!(reason.contains("conflicts") && conflicting.iter().all(|n| reason.contains(n)), "{reason}"); + assert_ne!(reason, h.app.tr("joint_move.fixed")); + assert!(crate::scenario::rect_of("dialog:window").is_some()); + h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap(); + h.frames(2); + assert!(h.app.menu.joint_move_warning.is_none()); + // Without the conflicting joint the part moves again. + for name in conflicting { + let id = h.app.session.doc.assembly.joints.iter().find(|j| j.name == name).unwrap().id; + h.app.run("joint.delete", json!({"joint":id})).unwrap(); + } + h.frames(2); + h.step(&json!({"click":{"handle":"button:occurrence.move"}})).unwrap(); + h.frames(3); + assert!(h.app.menu.joint_move_warning.is_none()); + assert!(visible(&h.app)); + } + #[test] fn blocked_move_warns_from_both_entry_points_and_dismisses_without_editing() { for reason in ["rigid", "grounded", "limited", "parameter"] { @@ -1005,7 +1100,7 @@ mod tests { h.step(&json!({"click":{"handle":"tab:ASSEMBLE"}})).unwrap(); h.step(&json!({"click":{"handle":"button:occurrence.move"}})).unwrap(); h.frames(3); - assert_eq!(h.app.menu.joint_move_warning.as_deref(), Some("Arm:1"), "{reason}"); + assert_eq!(h.app.menu.joint_move_warning.as_ref().map(|b| (b.part.as_str(), b.conflicts.len())), Some(("Arm:1", 0)), "{reason}"); assert!(crate::scenario::rect_of("dialog:window").is_some(), "a modal must be visible: {reason}"); assert!(!visible(&h.app)); h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap();