SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Move: Point to Point takes the origin point (#3696) (#3718)
plexi324f7ff8c4d825
diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rsindex 3c65076fd7..2c95b6b441 100644--- a/crates/ui-egui/src/browser.rs+++ b/crates/ui-egui/src/browser.rs@@ -1237,7 +1237,7 @@ fn origin_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &Actiolet sel = match icon {"plane" => Some(Sel::Plane { name: k.into() }),"axis" => Some(Sel::Axis { name: k.into() }),- _ => None,+ _ => Some(Sel::Vertex { body: String::new(), point: solidcraft_engine::geom::Vec3::ZERO }),};let (selected, mark) = lit_row(lit(&thing));let r = draw_row(@@ -1557,6 +1557,8 @@ fn pick_from_browser(app: &mut SolveApp, x: Sel) {let hit = match &x {Sel::Plane { name } => crate::viewport::Hit::Plane { name: name.clone(), point: solidcraft_engine::geom::Vec3::ZERO },Sel::Axis { name } => crate::viewport::Hit::Axis { name: name.clone() },+ // The origin point goes only into a dialog input that takes it.+ Sel::Vertex { body, point } if body.is_empty() && app.dialog.is_some() => crate::viewport::Hit::Vertex { body: String::new(), point: *point },_ => return,};if let Some(mut d) = app.dialog.take() {diff --git a/crates/ui-egui/src/dialogs_move.rs b/crates/ui-egui/src/dialogs_move.rsindex eb1dfd25a4..a4762e3f04 100644--- a/crates/ui-egui/src/dialogs_move.rs+++ b/crates/ui-egui/src/dialogs_move.rs@@ -12,7 +12,7 @@ use solidcraft_engine::geom::Vec3;use crate::SolveApp;use crate::dialogs::{Dialog, Kind};use crate::gizmo::{self, Change, Drag};-use crate::selection::{AXES, BODIES, EDGES, FACES, SelInput, VERTICES};+use crate::selection::{AXES, BODIES, EDGES, FACES, ORIGIN, SelInput, VERTICES};pub const TYPES: [&str; 5] = ["Free Move", "Translate", "Rotate", "Point to Point", "Point to Position"];pub const FREE: usize = 0;@@ -20,7 +20,7 @@ pub const TRANSLATE: usize = 1;pub const ROTATE: usize = 2;pub const POINT_TO_POINT: usize = 3;pub const POINT_TO_POSITION: usize = 4;-const POINTS: u16 = VERTICES | FACES | EDGES;+const POINTS: u16 = VERTICES | FACES | EDGES | ORIGIN;/// A fresh Move dialog of a type (all values zero).pub fn kind(mode: usize) -> Kind {diff --git a/crates/ui-egui/src/dialogs_move_tests.rs b/crates/ui-egui/src/dialogs_move_tests.rsindex eb52a7c123..f213a59808 100644--- a/crates/ui-egui/src/dialogs_move_tests.rs+++ b/crates/ui-egui/src/dialogs_move_tests.rs@@ -69,3 +69,33 @@ fn every_move_type_has_somewhere_to_put_its_value_box() {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");+}diff --git a/crates/ui-egui/src/selection.rs b/crates/ui-egui/src/selection.rsindex 446cfbec2c..7cf35660d4 100644--- a/crates/ui-egui/src/selection.rs+++ b/crates/ui-egui/src/selection.rs@@ -38,6 +38,8 @@ pub const POINTS: Accept = 512;pub const FEATURES: Accept = 1024;/// Points of the sketch being modified; unlike POINTS these never enable cross-sketch picking.pub const SKETCH_POINTS: Accept = 2048;+/// The origin point, picked as a vertex of no body (in the viewport or the browser's Origin).+pub const ORIGIN: Accept = 4096;/// One selection input of a command dialog ("Profiles", "Edges", "Plane", ...).#[derive(Clone, Debug, PartialEq)]@@ -79,7 +81,8 @@ impl SelInput {Hit::SketchCurve { id, .. } if a & CURVES != 0 => Some(Sel::SketchCurve { id: id.clone() }),Hit::SketchPoint { id, .. } if a & SKETCH_POINTS != 0 => Some(Sel::SketchPoint { id: id.clone() }),Hit::SketchPoint { sketch, id, .. } if a & POINTS != 0 => Some(Sel::SketchPoint { id: format!("{sketch}:{id}") }),- Hit::Vertex { body, point } if a & VERTICES != 0 => Some(Sel::Vertex { body: body.clone(), point: *point }),+ Hit::Vertex { body, point } if body.is_empty() && a & ORIGIN != 0 => Some(Sel::Vertex { body: String::new(), point: *point }),+ Hit::Vertex { body, point } if !body.is_empty() && a & VERTICES != 0 => Some(Sel::Vertex { body: body.clone(), point: *point }),_ => None,}}diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rsindex 7260a695fa..6a2fe1413e 100644--- a/crates/ui-egui/src/viewport.rs+++ b/crates/ui-egui/src/viewport.rs@@ -1172,6 +1172,7 @@ pub(crate) fn pick_cached(app: &mut SolveApp, proj: &Proj, pos: Pos2) -> Vec<Hitapp.dialog.as_ref().and_then(|d| d.active_input()).map(|i| i.accept).hash(&mut h);app.session.visibility.hidden_bodies.hash(&mut h);app.session.visibility.hidden_occurrences.hash(&mut h);+ origin_point_shown(app).hash(&mut h);app.perspective_view().hash(&mut h);(proj.rect.width().to_bits(), proj.rect.height().to_bits()).hash(&mut h);crate::sketch_display::projection_key(proj, app.viewport.pixels_per_point()).hash(&mut h);@@ -1412,6 +1413,16 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,}}}+ // The origin point, for an input that takes it: a vertex of no body, drawn over everything.+ if app.dialog.as_ref().and_then(|d| d.active_input()).is_some_and(|i| i.accept & crate::selection::ORIGIN != 0)+ && origin_point_shown(app)+ && let Some(sp) = proj.to_screen(Vec3::ZERO)+ {+ let dd = sp.distance(pos);+ if dd < 7.0 && bestv.wants(dd) {+ bestv.offer(dd, Hit::Vertex { body: String::new(), point: Vec3::ZERO });+ }+ }hits.extend(bestv.hits());hits.extend(beste.hits());// Origin axes.@@ -3364,11 +3375,15 @@ fn box_select(app: &mut SolveApp, proj: &Proj, bx: BoxSel, add: bool) {let _ = app.run("select.set", json!({"items": items, "add": add}));}+/// Whether the origin point is drawn (the Origin shown and its point not hidden).+fn origin_point_shown(app: &SolveApp) -> bool {+ app.origin_visible() && !app.session.visibility.hidden_origin.iter().any(|h| h == "O")+}+/// Screen-space dots: the origin point, and hovered or selected body vertices.fn points_2d(app: &SolveApp, painter: &egui::Painter, proj: &Proj) {let t = Tokens::get();- if app.origin_visible()- && !app.session.visibility.hidden_origin.iter().any(|h| h == "O")+ if origin_point_shown(app)&& let Some(o) = proj.to_screen(Vec3::ZERO){painter.circle(o, 4.5, t.origin_point, Stroke::new(1.0, Color32::from_gray(110)));