diff --git a/assets/locales/pending/drive-rigid-joint.json b/assets/locales/pending/drive-rigid-joint.json new file mode 100644 index 000000000..3b79d1597 --- /dev/null +++ b/assets/locales/pending/drive-rigid-joint.json @@ -0,0 +1,20 @@ +{ + "en": { + "drive.rigid": "{joint} is a rigid joint: it holds its parts still, so it has nothing to drive. To let them move, change its type in Edit Joint: Revolute to rotate, Slider to slide, Cylindrical for both." + }, + "ar": { + "drive.rigid": "{joint} مفصل صلب: يثبّت أجزاءه في مكانها، لذا لا يوجد ما يمكن تحريكه. لتتحرك الأجزاء، غيّر نوعه في «تعديل المفصل»: Revolute للدوران، Slider للانزلاق، Cylindrical لكليهما." + }, + "he": { + "drive.rigid": "{joint} הוא מפרק קשיח: הוא מחזיק את החלקים שלו במקומם, ולכן אין מה להניע. כדי שהחלקים יזוזו, שנו את הסוג שלו ב״עריכת מפרק״: Revolute לסיבוב, Slider להחלקה, Cylindrical לשניהם." + }, + "ja": { + "drive.rigid": "{joint} は剛体ジョイントです。部品をその場に固定するため、駆動するものがありません。動かすには「ジョイントを編集」で種類を変更してください: 回転させるなら Revolute、スライドさせるなら Slider、両方なら Cylindrical。" + }, + "vi": { + "drive.rigid": "{joint} là khớp nối cứng: nó giữ cố định các chi tiết, nên không có gì để dẫn động. Để các chi tiết chuyển động, hãy đổi loại khớp nối trong “Chỉnh sửa khớp nối”: Revolute để xoay, Slider để trượt, Cylindrical cho cả hai." + }, + "zh": { + "drive.rigid": "{joint} 是刚性接头:它把零件固定在原位,因此没有可驱动的运动。要让零件运动,请在“编辑接头”中更改其类型:旋转用 Revolute,滑动用 Slider,两者兼有用 Cylindrical。" + } +} diff --git a/crates/engine/src/cmd/joints.rs b/crates/engine/src/cmd/joints.rs index c74f5767d..7717cac90 100644 --- a/crates/engine/src/cmd/joints.rs +++ b/crates/engine/src/cmd/joints.rs @@ -856,7 +856,7 @@ fn drive(s: &mut Session, p: &Value) -> Result { let id = joint_id(s, p.get("joint"), cmd)?; let kind = s.doc.assembly.joints.iter().find(|j| j.id == id).map(|j| j.kind).ok_or_else(|| bad(cmd, "joint"))?; if kind == JointKind::Rigid { - return Err(bad(cmd, "a rigid joint does not move")); + return Err(bad(cmd, "a rigid joint does not move: joint.edit can make it revolute (turns), slider (slides) or cylindrical (both)")); } let mut q = values_param(s, p, kind, cmd)?; if p.get("values").is_none() && p.get("value").is_none() { diff --git a/crates/engine/src/cmd/joints_tests.rs b/crates/engine/src/cmd/joints_tests.rs index eecc23d48..bcdaecda0 100644 --- a/crates/engine/src/cmd/joints_tests.rs +++ b/crates/engine/src/cmd/joints_tests.rs @@ -192,6 +192,9 @@ fn rigid_cycles_solve_and_conflicts_report() { let c = r["conflicts"].as_array().cloned().unwrap_or_default(); assert_eq!(c.len(), 1, "{r}"); assert!(c[0]["why"].as_str().unwrap_or("").contains("off by"), "{r}"); + // A rigid joint has nothing to drive: the refusal names the types that move (#6981). + let e = s.execute("joint.drive", &json!({"joint": "Wrong", "value": 1})).map(|_| ()).unwrap_err().to_string(); + assert!(e.contains("does not move") && e.contains("joint.edit") && e.contains("revolute") && e.contains("cylindrical"), "{e}"); // Suppressing it clears the conflict. let r = run(&mut s, "joint.edit", json!({"joint": "Wrong", "suppressed": true})); assert_eq!(r["conflicts"].as_array().map(Vec::len), Some(0)); diff --git a/crates/ui-egui/src/dialogs_assembly.rs b/crates/ui-egui/src/dialogs_assembly.rs index 59ee719a4..cbbf7c802 100644 --- a/crates/ui-egui/src/dialogs_assembly.rs +++ b/crates/ui-egui/src/dialogs_assembly.rs @@ -217,10 +217,10 @@ pub fn start(app: &SolveApp, id: &str) -> Option<(Kind, Vec)> { "joint.origin" => (Asm::JointOrigin { name: String::new(), hover: None }, vec![SelInput::new("Snap", SNAPS, false)]), "joint.rigid_group" => (Asm::RigidGroup, vec![SelInput::new("Components", BODIES, true)]), "joint.drive" => { - let joint = picked_joint(app); + let joint = picked_joint(app, true); (Asm::Drive { joint, values: current_values(s, joint), focus: true }, vec![]) } - "motion.trace" => (Asm::Trace(Box::new(trace::form(s, picked_joint(app)))), vec![SelInput::new("Point", SNAPS, false)]), + "motion.trace" => (Asm::Trace(Box::new(trace::form(s, picked_joint(app, false)))), vec![SelInput::new("Point", SNAPS, false)]), "joint.motion_link" => { let b = usize::from(movable(s).len() > 1); (Asm::MotionLink { a: 0, b, ia: 0, ib: 0, ratio: "1".into(), offset: "0".into() }, vec![]) @@ -278,13 +278,15 @@ pub fn preset(s: &Session, k: &mut Asm, p: &Value) -> Result<(), String> { Ok(()) } -/// The joint picked in the browser, else the first that moves (an index into the design's joints). -fn picked_joint(app: &SolveApp) -> usize { +/// The joint picked in the browser, else the first that moves (an index into the design's +/// joints). With `rigid`, a picked rigid joint comes before the first that moves: Drive Joints +/// opened on one says why it can't drive it (#6981). +fn picked_joint(app: &SolveApp, rigid: bool) -> usize { let s = &app.session; let list = movable(s); - let picked = - app.tree.picked_joints.iter().find_map(|id| list.iter().copied().find(|i| s.doc.assembly.joints.get(*i).is_some_and(|j| j.id == *id))); - picked.or(list.first().copied()).unwrap_or(0) + let picked: Vec = app.tree.picked_joints.iter().filter_map(|id| s.doc.assembly.joints.iter().position(|j| j.id == *id)).collect(); + let moving = picked.iter().copied().find(|i| list.contains(i)); + moving.or(picked.first().copied().filter(|_| rigid)).or(list.first().copied()).unwrap_or(0) } /// Indices (into the design's joints) of joints that move (not rigid). @@ -613,23 +615,44 @@ pub fn rows(app: &mut SolveApp, ui: &mut egui::Ui, k: &mut Asm, inputs: &mut [Se Asm::Drive { joint, values, focus } => { let s = &app.session; let list = movable(s); - if list.is_empty() { + // A rigid joint holds its parts still: say so, and offer Edit Joint to change its + // type (#6981). Nothing is driven (no preview, OK stays off) until one that moves is chosen. + let rigid = s.doc.assembly.joints.get(*joint).filter(|j| j.kind == JointKind::Rigid).map(|j| (j.id, j.name.clone())); + if let Some((id, name)) = &rigid { + let mut edit = false; ui.vertical(|ui| { - ui.label(RichText::new(crate::i18n::tr_label("no joint that moves yet")).color(t.text_dim)); + let why = crate::i18n::format("drive.rigid", &[("joint", name.as_str())]); + ui.add(egui::Label::new(RichText::new(why).color(t.warning)).wrap()); + let r = crate::ui_kit::button(ui, crate::i18n::tr_label("Edit Joint"), crate::ui_kit::Button::Normal); + crate::scenario::publish_handle("drive:edit_joint", r.rect.center()); + edit = r.clicked(); }); + if edit && let Some(Kind::Assembly(e)) = edit_joint(app, *id).map(|d| d.kind) { + *k = e; + return false; + } + } + if list.is_empty() { + if rigid.is_none() { + ui.vertical(|ui| { + ui.label(RichText::new(crate::i18n::tr_label("no joint that moves yet")).color(t.text_dim)); + }); + } return false; } let labels: Vec = list.iter().filter_map(|i| s.doc.assembly.joints.get(*i)).map(|j| format!("{} ({:?})", j.name, j.kind)).collect(); let refs: Vec<&str> = labels.iter().map(String::as_str).collect(); - let mut pos = list.iter().position(|i| i == joint).unwrap_or(0); + // On a rigid joint the box shows none of the joints that move until one is chosen. + let mut pos = list.iter().position(|i| i == joint).unwrap_or(list.len()); choice_row(ui, "Joint", "drv_joint", &mut pos, &refs); - let pick = list.get(pos).copied().unwrap_or(0); - if pick != *joint || values.is_empty() { + if let Some(&pick) = list.get(pos) + && (pick != *joint || values.is_empty()) + { *joint = pick; *values = current_values(s, pick); } - let Some(j) = s.doc.assembly.joints.get(*joint).cloned() else { return false }; + let Some(j) = s.doc.assembly.joints.get(*joint).filter(|j| j.kind != JointKind::Rigid).cloned() else { return false }; for (i, v) in values.iter_mut().enumerate() { let angle = j.kind.is_angle(i); let unit_kind = if angle { ValueKind::Angle } else { ValueKind::Length }; @@ -997,6 +1020,10 @@ pub fn commands(app: &SolveApp, k: &Asm, inputs: &[SelInput]) -> Result { let j = s.doc.assembly.joints.get(*joint).ok_or("no joint that moves yet")?; + // A rigid joint has nothing to drive: the dialog says why and offers Edit Joint (#6981). + if j.kind == JointKind::Rigid { + return Err(crate::i18n::format("drive.rigid", &[("joint", &j.name)])); + } cmd("joint.drive", json!({"joint": j.id, "values": values})) } Asm::MotionLink { a, b, ia, ib, ratio, offset } => { diff --git a/crates/ui-egui/src/dialogs_assembly_tests.rs b/crates/ui-egui/src/dialogs_assembly_tests.rs index 07b060104..12883f17d 100644 --- a/crates/ui-egui/src/dialogs_assembly_tests.rs +++ b/crates/ui-egui/src/dialogs_assembly_tests.rs @@ -887,6 +887,43 @@ fn drive_opens_on_the_picked_joint() { let rocker = app.session.doc.assembly.joints.iter().find(|j| j.name == "Rocker").unwrap().id; pick_joint(&mut app, rocker, false); assert_eq!(drive_on(&mut app), "Rocker"); + // A rigid joint picked: it opens on that one, to say why it can't drive it (#6981). + app.run("joint.as_built", json!({"type": "rigid", "a": "Ground", "b": "Crank", "name": "Lock"})).unwrap(); + let lock = app.session.doc.assembly.joints.iter().find(|j| j.name == "Lock").unwrap().id; + pick_joint(&mut app, lock, false); + assert_eq!(drive_on(&mut app), "Lock"); + // Motion Trace still starts on a joint that moves. + app.dialog = None; + app.start("motion.trace"); + match &app.dialog.as_ref().unwrap().kind { + Kind::Assembly(Asm::Trace(f)) => assert_eq!(app.session.doc.assembly.joints[f.joint].name, "Crank"), + k => panic!("{k:?}"), + } +} + +/// Drive Joints in a design whose only joint is rigid (#6981): it opens on that joint and says it +/// holds its parts still and how to let them move, runs no drive (no preview error, no Create +/// Issue, OK off), and its Edit Joint button turns the dialog into Edit Joint on that joint. +#[test] +fn drive_on_a_rigid_joint_says_why_and_offers_edit_joint() { + let mut h = crate::scenario::Harness::new(); + h.app = two_boxes(); + let at = |o: &str| json!({"occurrence": o, "point": [25, 10, 5], "z": [1, 0, 0]}); + h.app.run("joint.create", json!({"type": "rigid", "a": at("A"), "b": at("B"), "name": "Glue"})).unwrap(); + let glue = h.app.session.doc.assembly.joints[0].id; + h.app.start("joint.drive"); + h.frames(4); + let d = h.app.dialog.clone().unwrap(); + let e = apply_commands(&h.app, &d).unwrap_err(); + assert!(e.contains("Glue") && e.contains("holds its parts still") && e.contains("Revolute") && e.contains("Edit Joint"), "{e}"); + assert!(h.app.preview.error.is_none(), "no drive is previewed"); + assert!(crate::scenario::handle_at("dialog:create_issue").is_none(), "no Create Issue for a rigid joint"); + h.step(&json!({"click": {"handle": "drive:edit_joint"}})).unwrap(); + h.frames(2); + match &h.app.dialog.as_ref().unwrap().kind { + Kind::Assembly(Asm::Joint(f)) => assert_eq!(f.editing, Some(glue)), + k => panic!("{k:?}"), + } } /// A rigid joint has nothing to drive: Drive Joints won't start on it. diff --git a/docs/book/src/guide/assemblies.md b/docs/book/src/guide/assemblies.md index 505ddf853..1b2e219bc 100644 --- a/docs/book/src/guide/assemblies.md +++ b/docs/book/src/guide/assemblies.md @@ -56,7 +56,9 @@ joined to the rest of the design. circles and vertices: rigid, revolute, slider, cylindrical, pin-slot, planar and ball, with offsets, flip and limits. **As-built Joint** keeps the current position, **Rigid Group** locks components together, **Drive Joints** moves a joint through its values, and **Motion Link** -couples two joints. Links can be chained (one joint drives a second, which drives a +couples two joints. A rigid joint holds its parts still, so Drive Joints has nothing to drive on +it: it says so and offers **Edit Joint**, where the joint's type changes to Revolute (rotate), +Slider (slide) or Cylindrical (both). Links can be chained (one joint drives a second, which drives a third), and a value is carried through a chain of up to 64 links in whatever order they were made. Contact sets stop motion where bodies would pass through each other, **Motion Study** keys joint values along a timeline, and **Interference** shows overlapping diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 456e42013..10e4a6ef5 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -273,7 +273,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox. | `ui.set` | any `UiState` field (`tab`, `perspective`, `showGrid`, `dark`, `layout`, …), and the browser's view of the design, saved with it: `showOrigin` (the Origin folder's eye), `showSketches` (the design's Sketches folder, `c0/sketches` in `hiddenFolders`), `hiddenBodies`, `hiddenOrigin`, `hiddenSketches`, `shownSketches`, `hiddenJoints`, `hiddenFolders`, `hiddenProfiles`, `shownDims`, `lockedBodies` (whole lists; `browser.visibility` changes single items) | `dark: false` switches to the light theme; `layout: "floating"` (default) or `"compact"` (`"docked"` is also accepted) selects the transient shell layout without saving a preference. Scenarios use `{"call":"ui.set","params":{"layout":"docked"}}` | | `ui.view` | `view`: `front`, `back`, `top`, `bottom`, `left`, `right`, `iso`, `home`, `fit`; `animate` (bool, default false: snap) | | | `ui.camera` | `target?`: `[x, y, z]` (mm), `yaw?`, `pitch?`, `roll?` (radians), `distance?` (mm), `fov?`, `up?`; `fit?`: `true`, `false` or `[occurrence id or name…]` (`root`: the bodies outside every component) | the viewport's orbit camera: it looks at `target` from `distance` away; `yaw` 0 looks along +Y (from the front), `pitch` is the elevation (±π/2: straight down or up), `roll` turns the image. Fields given are set first (the others keep their values), then `fit` frames the listed occurrences (or everything), keeping the direction. The reply, passed back, sets the same view again, so a framing can be stored and replayed. `fov` and `up` follow the perspective setting (`ui.set`) and the up axis preference (`ui.prefs`) and can't change here; a refused field changes nothing | -| `ui.start` | `command`, `params?` | like a toolbar click: starts the sketch tool or dialog for the command. `params` sets what the dialog opens on, and nothing runs until OK: `joint.drive` takes `joint` (id or name; without it, the joint picked in the browser, else the first joint that moves) and `values` (numbers in degrees or millimetres, or expressions); `motion.study` takes `study` (id or name), which opens that study to edit and chart. A command that takes no params is refused before it starts; a param the dialog doesn't take is refused and the dialog closes | +| `ui.start` | `command`, `params?` | like a toolbar click: starts the sketch tool or dialog for the command. `params` sets what the dialog opens on, and nothing runs until OK: `joint.drive` takes `joint` (id or name; without it, the joint picked in the browser, else the first joint that moves; a rigid joint opens to say why it has nothing to drive, with an Edit Joint button, handle `drive:edit_joint`) and `values` (numbers in degrees or millimetres, or expressions); `motion.study` takes `study` (id or name), which opens that study to edit and chart. A command that takes no params is refused before it starts; a param the dialog doesn't take is refused and the dialog closes | | `ui.click` | `x`, `y` (screen points), `button?`: left/right/middle, `shift?`, `ctrl?`, `double?` | real pointer input | | `ui.move` | `x`, `y`, `shift?`, `alt?`, `ctrl?`, `cmd?` | pointer movement without a button; modifiers apply until the next synthetic move/click; a move with omitted modifiers releases them. With `nav: "touchpad"`, Shift pans and Alt/Option orbits. | | `ui.drag` | `x0`, `y0`, `x1`, `y1`, `button?`, `shift?`, `ctrl?`, `steps?`, `hold?`, `hold_end?` | press, move, release; a left drag on the model is a box selection (left to right: window, right to left: crossing); with OpenSCAD navigation, plain left-drag on empty space orbits, Shift+left-drag box-selects, and drags starting on sketch geometry edit it; `hold` keeps the button down that many frames first (a right press-and-hold opens the marking menu, releasing over a direction picks it), `hold_end` that many frames at the end (a sketch drag shows its snap) |