Skip to content

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

Drive Joints: a Show ghost checkbox (#5905) (#5955)

DuBearte1d48707d0ce3
diff --git a/assets/locales/en.json b/assets/locales/en.json
index 695489813d..ad02bc243b 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 44dd1420f6..ad53c6e821 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 19946706ec..9f6162a8e2 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 a46401f602..20678bbada 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 8f1b008075..1c2730624f 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 9141595966..1dbea66048 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<String> = std::collections::BTreeSet::new(), PAGE_PLUGINS;
}
diff --git a/crates/ui-egui/src/preview.rs b/crates/ui-egui/src/preview.rs
index 637d2c4c67..7d133b013e 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 d6a62e68fa..2f9881c7cc 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 {