From f937905cf386905b87ac6287abc0bf9724e2369e Mon Sep 17 00:00:00 2001 From: raykholo Date: Sun, 25 Oct 2026 19:37:01 +0000 Subject: [PATCH] A sketch point on the origin can be dragged (#4719) (#4837) --- .../pending/free-sketch-point-picking.json | 5 ++ crates/ui-egui/src/prefs.rs | 2 + crates/ui-egui/src/prefs/sketch.rs | 1 + crates/ui-egui/src/sketch_drag_ui_tests.rs | 24 +++++++++ crates/ui-egui/src/viewport.rs | 49 +++++++++++++++++-- 5 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 assets/locales/pending/free-sketch-point-picking.json diff --git a/assets/locales/pending/free-sketch-point-picking.json b/assets/locales/pending/free-sketch-point-picking.json new file mode 100644 index 000000000..249185399 --- /dev/null +++ b/assets/locales/pending/free-sketch-point-picking.json @@ -0,0 +1,5 @@ +{ + "en": { "prefs.prefer_free_sketch_points": "Prefer movable sketch points when points overlap" }, + "ja": { "prefs.prefer_free_sketch_points": "スケッチ点が重なったときは移動可能な点を優先する" }, + "zh": { "prefs.prefer_free_sketch_points": "草图点重合时优先选择可移动的点" } +} diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index ce039eb48..7023a7aec 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -680,6 +680,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; + /// Prefer movable sketch points on exact selection ties; off keeps point insertion order. + prefer_free_sketch_points: bool = true, 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. diff --git a/crates/ui-egui/src/prefs/sketch.rs b/crates/ui-egui/src/prefs/sketch.rs index ac6a8b198..a7fbe5ec5 100644 --- a/crates/ui-egui/src/prefs/sketch.rs +++ b/crates/ui-egui/src/prefs/sketch.rs @@ -31,6 +31,7 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) { }); ui_kit::settings_section(ui, "selection", app.tr("prefs.selecting"), |ui| { ui_kit::checkbox(ui, crate::i18n::tr_label("Click selects whole bodies"), &mut app.ui.pick_bodies); + ui_kit::checkbox(ui, app.tr("prefs.prefer_free_sketch_points"), &mut app.preferences.prefer_free_sketch_points); let click = app.tr("prefs.click"); let shift = app.tr("prefs.shift"); let ctrl = app.tr("prefs.ctrl_cmd"); diff --git a/crates/ui-egui/src/sketch_drag_ui_tests.rs b/crates/ui-egui/src/sketch_drag_ui_tests.rs index f9ab726c6..742fa5d94 100644 --- a/crates/ui-egui/src/sketch_drag_ui_tests.rs +++ b/crates/ui-egui/src/sketch_drag_ui_tests.rs @@ -374,3 +374,27 @@ fn a_window_selected_circle_still_takes_its_radius_from_a_drag_on_its_edge() { let r = sk.radius(sk.curve_index("c1").expect("the circle")).expect("a radius"); assert!((r - 15.0).abs() < 0.05, "{r}"); } + +/// A circle drawn on the origin and freed from it (its Coincident deleted) moves by its centre: +/// the centre and the fixed origin are equally near the pointer, and the free one wins (#4841). +#[test] +fn a_freed_circle_centre_on_the_origin_drags_instead_of_the_origin() { + let mut h = Harness::new(); + run(&mut h, "sketch.create", json!({"plane": "XY"})); + run(&mut h, "sketch.circle.center", json!({"center": [0, 0], "radius": 10, "id": "c1"})); + let sid = h.app.session.active_sketch.expect("sketch mode"); + let ids: Vec = h.app.session.doc.sketch(sid).expect("the sketch").constraints.iter().map(|c| c.id.clone()).collect(); + assert!(!ids.is_empty(), "the centre starts coincident with the origin"); + run(&mut h, "sketch.delete", json!({"entities": ids})); + h.call("ui.view", json!({"view": "top"})); + h.app.cam.distance = 150.0; + h.frames(3); + let a = screen(&mut h, 0.0, 0.0); + let b = screen(&mut h, 15.0, 10.0); + let mut path = vec![a]; + path.extend(steps(a, b, 6)); + press_and_move(&mut h, &path); + release(&mut h, b); + assert!(point(&h, "c1.center").dist(Vec2::new(15.0, 10.0)) < 0.05, "{:?}", point(&h, "c1.center")); + assert!(point(&h, "origin").dist(Vec2::new(0.0, 0.0)) < 1e-9); +} diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index 627e69c3b..18e84ec77 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -1526,6 +1526,7 @@ pub(crate) fn pick_cached(app: &mut SolveApp, proj: &Proj, pos: Pos2) -> Vec Option<(Vec2, let sid = app.session.active_sketch?; let st = crate::open_meshing::shown_world(app); let ss = st.sketch(sid)?; - for h in pick(app, proj, pos) { + for h in pick_for_tool(app, proj, pos) { if let Hit::SketchPoint { sketch, id, at } = h && sketch == sid { @@ -5047,6 +5051,43 @@ mod tests { assert!(plane.origin.dist(Vec3::new(0., 50., 10.)) < 1e-9, "{plane:?}"); } + #[test] + fn point_pick_tie_at_origin_prefers_the_drawn_point_after_deleting_coincident() { + let mut s = solidcraft_engine::Session::default(); + s.execute("sketch.create", &json!({"plane": "XY"})).unwrap(); + let drawn = s.execute("sketch.point", &json!({"point": [0, 0], "id": "drawn"})).unwrap(); + let constraint = drawn["constraints"][0].as_str().unwrap(); + s.execute("sketch.delete", &json!({"entities": [constraint]})).unwrap(); + let sid = s.active_sketch.unwrap(); + assert!(s.doc.sketch(sid).unwrap().constraints.is_empty()); + let mut app = SolveApp::new(s, crate::Services::default()); + let proj = projection(&app, Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))); + let at = proj.to_screen(Vec3::ZERO).unwrap(); + assert!(app.preferences.prefer_free_sketch_points); + assert_eq!(sketch_point_at(&app, &proj, at).unwrap().1.as_deref(), Some("origin"), "drawing keeps its origin snap"); + let hits = pick(&app, &proj, at); + assert!(matches!(hits.first(), Some(Hit::SketchPoint { id, .. }) if id == "drawn"), "{hits:?}"); + let all = pick_all(&app, &proj, at); + let points: Vec<_> = all + .iter() + .filter_map(|h| match h { + Hit::SketchPoint { id, .. } => Some(id.as_str()), + _ => None, + }) + .collect(); + assert_eq!(points, ["drawn", "origin"], "Select Other keeps both points"); + assert!(matches!(pick_cached(&mut app, &proj, at).first(), Some(Hit::SketchPoint { id, .. }) if id == "drawn")); + let saved = crate::prefs::set(&mut app, &json!({"prefer_free_sketch_points": false})).unwrap(); + assert_eq!(saved["prefer_free_sketch_points"], false); + assert!(matches!(pick_cached(&mut app, &proj, at).first(), Some(Hit::SketchPoint { id, .. }) if id == "origin")); + assert!(matches!(pick_all(&app, &proj, at).first(), Some(Hit::SketchPoint { id, .. }) if id == "origin")); + let Some(Hit::SketchPoint { id, .. }) = hits.first() else { panic!("no point picked") }; + app.run("sketch.drag", json!({"entity": id, "from": [0, 0], "to": [10, 5]})).unwrap(); + let sk = app.session.doc.sketch(sid).unwrap(); + assert!(sk.point(sk.resolve_point("drawn").unwrap()).unwrap().dist(Vec2::new(10.0, 5.0)) < 1e-6); + assert_eq!(sk.point(0), Some(Vec2::ZERO)); + } + /// Every tangent seam Continuity Analysis reports keeps its colour while the pointer rests on /// a face (#1247): a 60 x 40 x 20 box with its four top edges rounded (6 mm) has eight, four /// against the sides and four against the top face. The tool lit the face under the pointer,