SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
A sketch point on the origin can be dragged (#4719) (#4837)
raykholof937905cf386
diff --git a/assets/locales/pending/free-sketch-point-picking.json b/assets/locales/pending/free-sketch-point-picking.jsonnew file mode 100644index 0000000000..249185399b--- /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.rsindex ce039eb483..7023a7aec7 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.rsindex ac6a8b1983..a7fbe5ec52 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.rsindex f9ab726c61..742fa5d940 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<String> = 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.rsindex 627e69c3b5..18e84ec77c 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<Hitapp.session.active_sketch.hash(&mut h);app.tool.as_ref().map(|tool| tool.cmd).hash(&mut h);app.dialog.is_none().hash(&mut h);+ app.preferences.prefer_free_sketch_points.hash(&mut h);crate::sketch3d::drawing(app).hash(&mut h);app.dialog.as_ref().and_then(|d| d.active_input()).map(|i| i.accept).hash(&mut h);crate::hole_place::snapping(app).hash(&mut h);@@ -1670,19 +1671,22 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,// A face place (the Single hole's) snaps only to points their sketches show, so a nearer// point that isn't shown (a letter's outline) neither takes the pick nor hides a shown one.let snapping = app.dialog.as_ref().and_then(|d| d.active_input()).is_some_and(|i| crate::dialogs::snaps_to_points(i.accept));+ let prefer_free = app.preferences.prefer_free_sketch_points && include_midpoints && app.tool.is_none() && app.dialog.is_none();let mut best = Near::new(all);for ss in point_sketches.iter().filter_map(|sid| st.sketch(*sid)) {let sid = ss.feature;let shown = snapping.then(|| crate::dialogs::SnapPoints::of(&ss.sketch));let visible = solidcraft_engine::view::SketchPointVisibility::new(&ss.sketch);- for p in &ss.sketch.points {+ for (p, locked) in ss.sketch.points.iter().zip(ss.sketch.locked_points()) {if !visible.takes(p) || shown.as_ref().is_some_and(|f| !f.takes(p)) {continue;}if let Some(sp) = proj.to_screen(ss.plane.to_world(p.pos)) {let dd = sp.distance(pos) - if s.active_sketch == Some(sid) { 2.0 } else { 0.0 };- if dd < 8.0 && best.wants(dd) {- best.offer(dd, Hit::SketchPoint { sketch: sid, id: p.id.clone(), at: p.pos });+ // On a distance tie, grab a movable point before the origin or a linked point.+ let rank = (dd, prefer_free && locked);+ if dd < 8.0 && best.wants(rank) {+ best.offer(rank, Hit::SketchPoint { sketch: sid, id: p.id.clone(), at: p.pos });}}}@@ -3061,7 +3065,7 @@ pub fn sketch_point_at(app: &SolveApp, proj: &Proj, pos: Pos2) -> 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,