A sketch point on the origin can be dragged (#4719) (#4837)

This commit is contained in:
raykholo
2026-10-25 19:37:01 +00:00
committed by GitHub
parent 46f7d4d8dc
commit f937905cf3
5 changed files with 77 additions and 4 deletions
@@ -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": "草图点重合时优先选择可移动的点" }
}
+2
View File
@@ -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.
+1
View File
@@ -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");
@@ -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);
}
+45 -4
View File
@@ -1526,6 +1526,7 @@ pub(crate) fn pick_cached(app: &mut SolveApp, proj: &Proj, pos: Pos2) -> Vec<Hit
app.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,