From 1d48707d0ce3446df18ea3bcc0bb348104e15cb7 Mon Sep 17 00:00:00 2001 From: DuBearte <130190089+DuBearte@users.noreply.github.com> Date: Sun, 25 Oct 2026 01:25:38 +0000 Subject: [PATCH] Drive Joints: a Show ghost checkbox (#5905) (#5955) * claim: #5905 * Drive Joints: a Show ghost checkbox (#5905) Driving a joint draws the moved parts' old place as a translucent ghost, which gets in the way when driving joints over and over. Drive Joints has a Show ghost box under its value rows: on by default (nothing changes), off draws only the moved parts at their new place. The stopped-short warning stays. The choice is a preference (drive_joints_ghost), so it is remembered between uses; it affects Drive Joints only. The preview's Colors carry the choice (ghost), so toggling it recomputes the preview (its key hashes the colours) and world_preview leaves the ghost out. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- assets/locales/en.json | 1 + assets/locales/ja.json | 1 + assets/locales/zh.json | 1 + crates/ui-egui/src/dialogs_assembly.rs | 7 +++++++ crates/ui-egui/src/dialogs_assembly_tests.rs | 9 +++++++++ crates/ui-egui/src/prefs.rs | 2 ++ crates/ui-egui/src/preview.rs | 11 ++++++++--- crates/ui-egui/src/preview_drag_tests.rs | 2 +- 8 files changed, 30 insertions(+), 4 deletions(-) diff --git a/assets/locales/en.json b/assets/locales/en.json index 695489813..ad02bc243 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -474,6 +474,7 @@ "Shape": "Shape", "Sheet Rules": "Sheet Rules", "Show Agent Cursor": "Show Agent Cursor", + "Show ghost": "Show ghost", "Show in folder": "Show in folder", "Show the pointer an AI agent moves (#35)": "Show the pointer an AI agent moves (#35)", "Signed axes": "Signed axes", diff --git a/assets/locales/ja.json b/assets/locales/ja.json index 44dd1420f..ad53c6e82 100644 --- a/assets/locales/ja.json +++ b/assets/locales/ja.json @@ -474,6 +474,7 @@ "Shape": "形状", "Sheet Rules": "板金ルール", "Show Agent Cursor": "エージェントカーソルを表示", + "Show ghost": "ゴーストを表示", "Show in folder": "フォルダに表示", "Show the pointer an AI agent moves (#35)": "エージェントが操作するポインターを表示 (#35)", "Signed axes": "符号付き座標軸", diff --git a/assets/locales/zh.json b/assets/locales/zh.json index 19946706e..9f6162a8e 100644 --- a/assets/locales/zh.json +++ b/assets/locales/zh.json @@ -474,6 +474,7 @@ "Shape": "形状", "Sheet Rules": "钣金规则", "Show Agent Cursor": "显示代理光标", + "Show ghost": "显示虚影", "Show in folder": "在文件夹中显示", "Show the pointer an AI agent moves (#35)": "显示 AI 代理移动的指针(#35)", "Signed axes": "带符号轴", diff --git a/crates/ui-egui/src/dialogs_assembly.rs b/crates/ui-egui/src/dialogs_assembly.rs index a46401f60..20678bbad 100644 --- a/crates/ui-egui/src/dialogs_assembly.rs +++ b/crates/ui-egui/src/dialogs_assembly.rs @@ -682,6 +682,10 @@ pub fn rows(app: &mut SolveApp, ui: &mut egui::Ui, k: &mut Asm, inputs: &mut [Se ui.label(RichText::new(why).color(t.warning)); }); } + // The moved parts' old place, drawn as a ghost; remembered between uses (#5905). + form_row(ui, "Show ghost", |ui| { + crate::ui_kit::checkbox(ui, "", &mut app.preferences.drive_joints_ghost); + }); } Asm::MotionLink { a, b, ia, ib, ratio, offset } => { let s = &app.session; @@ -1062,6 +1066,9 @@ pub fn world_preview(s: &Session, cmds: &[(String, Value)], colors: Colors) -> O let built = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| crate::preview::build(&before, &after, colors))); Some(match built { Ok(mut b) => { + if !colors.ghost { + b.scene.ghost.clear(); + } b.bounds = after.bodies.iter().fold(Aabb3::EMPTY, |acc, x| acc.union(&x.mesh().bounds())); b.stopped = stopped; Ok(b) diff --git a/crates/ui-egui/src/dialogs_assembly_tests.rs b/crates/ui-egui/src/dialogs_assembly_tests.rs index 8f1b00807..1c2730624 100644 --- a/crates/ui-egui/src/dialogs_assembly_tests.rs +++ b/crates/ui-egui/src/dialogs_assembly_tests.rs @@ -112,6 +112,7 @@ fn joint_and_drive_preview_on_the_placed_model() { new_body: [2, 2, 2, 255], removed: [3, 3, 3, 100], edge: [0, 0, 0, 255], + ghost: true, }; let cmds = preview_commands(&app, &d).unwrap(); let b = world_preview(&app.session, &cmds, colors).unwrap().unwrap(); @@ -139,6 +140,12 @@ fn joint_and_drive_preview_on_the_placed_model() { assert_eq!(cmds[0].0, "joint.drive"); let b = world_preview(&app.session, &cmds, colors).unwrap().unwrap(); assert_eq!(b.replaced, vec!["Body2".to_string()]); + // The moved part's old place is the ghost, unless Show ghost is off (#5905). + assert!(!b.scene.ghost.is_empty()); + let hidden = world_preview(&app.session, &cmds, crate::preview::Colors { ghost: false, ..colors }).unwrap().unwrap(); + assert!(hidden.scene.ghost.is_empty()); + assert_eq!(hidden.replaced, b.replaced, "the moved part is still shown where it goes"); + assert_eq!(hidden.scene.tris, b.scene.tris); // Features preview as before while nothing is placed away from its frame, and on the // placed model once something is (B moved by its joint). assert!(world_preview(&two_boxes().session, &[("solid.extrude".into(), json!({}))], colors).is_none()); @@ -701,6 +708,7 @@ fn drive_says_where_a_loop_stopped_it() { new_body: [2, 2, 2, 255], removed: [3, 3, 3, 100], edge: [0, 0, 0, 255], + ghost: true, }; let rocker = app.session.doc.assembly.joints.iter().position(|j| j.name == "Rocker").unwrap(); let mut d = drive_joint(&app, app.session.doc.assembly.joints[rocker].id).unwrap(); @@ -760,6 +768,7 @@ fn drive_says_when_its_joint_is_joined_to_nothing_grounded() { new_body: [2, 2, 2, 255], removed: [3, 3, 3, 100], edge: [0, 0, 0, 255], + ghost: true, }; let b = world_preview(&app.session, &apply_commands(&app, &d).unwrap(), colors).unwrap().unwrap(); let why = b.stopped.as_ref().and_then(drive_stop).unwrap(); diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index 914159596..1dbea6604 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -666,6 +666,8 @@ preference_settings! { /// When true: Shift+click adds without removing; Primary toggles. /// When false (default): Shift and Primary both toggle. selection_shift_add_only: bool = false, PAGE_SKETCH; + /// Drive Joints shows the moved parts' old place as a ghost (its Show ghost box, #5905). + drive_joints_ghost: bool = true, PAGE_DESIGN; /// Plugin ids turned off (Preferences › Plugins). An installed plugin whose id is absent is on. disabled_plugins: std::collections::BTreeSet = std::collections::BTreeSet::new(), PAGE_PLUGINS; } diff --git a/crates/ui-egui/src/preview.rs b/crates/ui-egui/src/preview.rs index 637d2c4c6..7d133b013 100644 --- a/crates/ui-egui/src/preview.rs +++ b/crates/ui-egui/src/preview.rs @@ -31,12 +31,14 @@ pub struct Colors { pub new_body: [u8; 4], pub removed: [u8; 4], pub edge: [u8; 4], + /// Whether a moved component's old place is drawn as a ghost (Drive Joints' Show ghost). + pub ghost: bool, } impl Colors { pub fn from_tokens(t: &Tokens) -> Colors { let c = |c: egui::Color32| c.to_srgba_unmultiplied(); - Colors { body: c(t.body), added: c(t.preview_add), new_body: c(t.preview_new), removed: c(t.preview_cut), edge: c(t.body_edge) } + Colors { body: c(t.body), added: c(t.preview_add), new_body: c(t.preview_new), removed: c(t.preview_cut), edge: c(t.body_edge), ghost: true } } fn for_tool(t: &Tokens, tab: &str, active: bool) -> Colors { @@ -320,7 +322,10 @@ pub fn update(app: &mut SolveApp, ctx: &egui::Context) { return; } }; - let colors = Colors::for_tool(&Tokens::get(), &app.ui.tab, app.tool.is_some() || app.dialog.is_some()); + let mut colors = Colors::for_tool(&Tokens::get(), &app.ui.tab, app.tool.is_some() || app.dialog.is_some()); + if app.dialog.as_ref().is_some_and(|d| matches!(d.kind, crate::dialogs::Kind::Assembly(crate::dialogs_assembly::Asm::Drive { .. }))) { + colors.ghost = app.preferences.drive_joints_ghost; + } let key = job_key(&cmds, app.session.revision, colors); let stream_key = stream_key(&cmds, app.session.revision, colors); let tool = as_new_body(&cmds).is_some(); @@ -861,7 +866,7 @@ mod tests { } fn colors() -> Colors { - Colors { body: [1, 1, 1, 255], added: [2, 2, 2, 255], new_body: [4, 4, 4, 255], removed: [3, 3, 3, 100], edge: [0, 0, 0, 255] } + Colors { body: [1, 1, 1, 255], added: [2, 2, 2, 255], new_body: [4, 4, 4, 255], removed: [3, 3, 3, 100], edge: [0, 0, 0, 255], ghost: true } } #[test] diff --git a/crates/ui-egui/src/preview_drag_tests.rs b/crates/ui-egui/src/preview_drag_tests.rs index d6a62e68f..2f9881c7c 100644 --- a/crates/ui-egui/src/preview_drag_tests.rs +++ b/crates/ui-egui/src/preview_drag_tests.rs @@ -3,7 +3,7 @@ use super::*; use serde_json::json; fn colors() -> Colors { - Colors { body: [1, 1, 1, 255], added: [2, 2, 2, 255], new_body: [2, 2, 2, 255], removed: [3, 3, 3, 100], edge: [0, 0, 0, 255] } + Colors { body: [1, 1, 1, 255], added: [2, 2, 2, 255], new_body: [2, 2, 2, 255], removed: [3, 3, 3, 100], edge: [0, 0, 0, 255], ghost: true } } fn fixture() -> Session {