Files
makeCAD/crates/ui-egui/src/dialogs_move_tests.rs
T
plexi32 4f7ff8c4d8 Move: Point to Point takes the origin point (#3696) (#3718)
The origin point was drawn in the view and listed in the browser, but
nothing could pick it: the viewport never offered it as a hit and the
browser's O row had no selection. A new ORIGIN accept bit lets an input
take it as a vertex of no body; Move's point inputs (From, To, Point,
Pivot) accept it, from the view or the browser's Origin folder.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 00:13:59 +00:00

102 lines
4.3 KiB
Rust

//! The Move window's main value: the one the canvas box shows and the keyboard types into.
//! It follows the move type, because each type uses a different value.
use serde_json::json;
use solidcraft_engine::Session;
use super::*;
use crate::Services;
use crate::dialogs::Dialog;
fn move_dialog(mode: usize) -> Dialog {
let mut s = Session::default();
s.execute("solid.box", &json!({"length": 20, "width": 20, "height": 20})).unwrap();
let mut app = SolveApp::new(s, Services::default());
app.start("solid.move");
let mut d = app.dialog.clone().unwrap();
d.kind = kind(mode);
d.inputs = inputs(mode);
if let Some(inp) = d.inputs.first_mut() {
inp.items = vec![Sel::Body { name: "Body1".into() }];
}
d
}
#[test]
fn the_main_value_follows_the_move_type() {
for mode in [FREE, TRANSLATE, POINT_TO_POSITION] {
let mut d = move_dialog(mode);
let got = d.primary().map(|p| (p.0, p.1));
assert_eq!(got, Some(("X", ValueKind::Length)), "{} types a distance", TYPES[mode]);
}
let mut d = move_dialog(ROTATE);
let got = d.primary().map(|p| (p.0, p.1));
assert_eq!(got, Some(("Angle", ValueKind::Angle)), "Rotate types an angle, not an X distance");
let mut d = move_dialog(POINT_TO_POINT);
assert!(d.primary().is_none(), "Point to Point is two picks with nothing to type");
}
#[test]
fn the_main_value_writes_through_to_the_command() {
let mut d = move_dialog(ROTATE);
if let Some((_, _, value)) = d.primary() {
*value = "90 deg".into();
}
let Kind::Move { angle, .. } = &d.kind else { panic!("not a move") };
assert_eq!(angle, "90 deg", "the box edits the angle itself, not a copy of it");
let mut d = move_dialog(TRANSLATE);
if let Some((_, _, value)) = d.primary() {
*value = "30 mm".into();
}
let Kind::Move { x, y, z, .. } = &d.kind else { panic!("not a move") };
assert_eq!((x.as_str(), y.as_str(), z.as_str()), ("30 mm", "0 mm", "0 mm"), "the box edits X alone");
}
/// Free Move and Translate carry the triad. The other three have no manipulator yet, so their
/// value box is the only way to drive them: it must still have somewhere to sit.
#[test]
fn every_move_type_has_somewhere_to_put_its_value_box() {
let mut s = Session::default();
s.execute("solid.box", &json!({"length": 20, "width": 20, "height": 20})).unwrap();
let app = SolveApp::new(s, Services::default());
for mode in [FREE, TRANSLATE, ROTATE, POINT_TO_POINT, POINT_TO_POSITION] {
let d = move_dialog(mode);
let has_triad = triad(&app, &d).is_some();
assert_eq!(has_triad, matches!(mode, FREE | TRANSLATE), "{} triad", TYPES[mode]);
let at = triad(&app, &d).map(|t| t.center).or_else(|| crate::canvas::anchor(&app, &d).map(|(base, _)| base));
assert!(at.is_some(), "{} has nowhere to put its value box", TYPES[mode]);
}
}
/// Point to Point takes the origin point as From or To (#3696): a click on the origin dot picks
/// it, and the body moves from its corner onto the origin.
#[test]
fn point_to_point_takes_the_origin_point() {
let mut h = crate::scenario::Harness::new();
h.app.ui.show_origin = true;
h.app.run("solid.box", json!({"length": 20, "width": 20, "height": 20})).unwrap();
h.app.run("solid.move", json!({"bodies": ["Body1"], "translate": ["30 mm", "20 mm", "0 mm"]})).unwrap();
h.app.cam.distance = 200.0;
h.settle();
let hi = h.app.session.model.state().body("Body1").unwrap().mesh().bounds().max;
h.app.start("solid.move");
{
let d = h.app.dialog.as_mut().unwrap();
d.kind = kind(POINT_TO_POINT);
d.inputs = inputs(POINT_TO_POINT);
d.inputs[0].items = vec![Sel::Body { name: "Body1".into() }];
d.active = 1;
}
let corner = h.call("ui.at", json!({ "world": [hi.x, hi.y, hi.z] }))["result"].clone();
h.step(&json!({ "click": corner })).unwrap();
h.app.dialog.as_mut().unwrap().active = 2;
let origin = h.call("ui.at", json!({ "world": [0, 0, 0] }))["result"].clone();
h.step(&json!({ "click": origin })).unwrap();
let d = h.app.dialog.clone().unwrap();
assert_eq!(d.inputs[2].items, vec![Sel::Vertex { body: String::new(), point: Vec3::ZERO }], "the origin is the To point");
let p = params(&h.app, &d).unwrap();
assert_eq!(p["translate"], json!([mm(-hi.x), mm(-hi.y), mm(-hi.z)]), "the corner goes onto the origin");
}