SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Sketch Mirror: a circle clicked after the window opens is mirrored too (#11700) (#12747)
PaddleStrokefeeac232f0f5
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 3f32277950..a2e1e18015 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -1589,7 +1589,7 @@ impl Dialog {/// lies on that face (a circle's centre) is taken at the point, as a points input picks it.pub(crate) fn candidate_on(&self, s: &Session, h: &Hit, snap: Option<&FaceSnap>) -> Option<Sel> {if matches!(self.kind, Kind::SketchModify(_)) {- return crate::sketch_modify_ui::candidate(self, s, h);+ return crate::sketch_modify_ui::pick_candidate(self, s, h);}if let Some(target) = self.extrude_target(s, h) {return Some(target);diff --git a/crates/ui-egui/src/sketch_modify_ui.rs b/crates/ui-egui/src/sketch_modify_ui.rsindex 6ca1124445..6d332a1fec 100644--- a/crates/ui-egui/src/sketch_modify_ui.rs+++ b/crates/ui-egui/src/sketch_modify_ui.rs@@ -332,8 +332,45 @@ pub(crate) fn selected_equation(app: &SolveApp) -> Option<String> {state.sketch(sid)?.sketch.equation_of(id).map(|e| e.curve.clone())}-/// Sketch modify inputs accept only the sketch being edited. Origin axes remain valid-/// rectangular-pattern directions, while Hole continues using its separate POINTS mask.+/// What a click on `hit` picks in a sketch modify window: what the active input takes+/// ([`candidate`]), else what the Entities list takes ([`entities_candidate`]).+pub(crate) fn pick_candidate(d: &Dialog, session: &solidcraft_engine::Session, hit: &Hit) -> Option<Sel> {+ candidate(d, session, hit).or_else(|| entities_candidate(d, session, hit))+}++/// The selection a hit adds to the Entities list although another input is active: the commands+/// whose first input is that shared list (Mirror, Move/Copy, Scale, Transform, the patterns) take+/// a curve, point or region the active input refuses there, so one clicked after the window+/// moved on to the mirror line, centre or direction joins the others instead of being dropped+/// without a word (#11700).+fn entities_candidate(d: &Dialog, session: &solidcraft_engine::Session, hit: &Hit) -> Option<Sel> {+ let active = session.active_sketch?;+ let shared = matches!(+ &d.kind,+ Kind::SketchModify(+ Mod::Scale { .. } | Mod::Mirror | Mod::Move { .. } | Mod::Transform { .. } | Mod::PatternRect { .. } | Mod::PatternCirc { .. }+ )+ );+ if !shared || d.active == 0 {+ return None;+ }+ if let Hit::SketchCurve { sketch, .. } | Hit::SketchPoint { sketch, .. } | Hit::Profile { sketch, .. } = hit+ && *sketch != active+ {+ return None;+ }+ d.inputs.first().filter(|input| input.multi)?.accepts(hit, Some(active), |_, _| false)+}++/// Whether a click on `hit` goes to the Entities list rather than the active input (see+/// [`entities_candidate`]).+pub(crate) fn picks_entity(d: &Dialog, session: &solidcraft_engine::Session, hit: &Hit) -> bool {+ candidate(d, session, hit).is_none() && entities_candidate(d, session, hit).is_some()+}++/// What the active input of a sketch modify window takes. Sketch modify inputs accept only the+/// sketch being edited. Origin axes remain valid rectangular-pattern directions, while Hole+/// continues using its separate POINTS mask.pub fn candidate(d: &Dialog, session: &solidcraft_engine::Session, hit: &Hit) -> Option<Sel> {let active = session.active_sketch?;match hit {diff --git a/crates/ui-egui/src/sketch_modify_ui_tests.rs b/crates/ui-egui/src/sketch_modify_ui_tests.rsindex 903e1c423a..c4261f0daf 100644--- a/crates/ui-egui/src/sketch_modify_ui_tests.rs+++ b/crates/ui-egui/src/sketch_modify_ui_tests.rs@@ -242,6 +242,54 @@ fn mirror_uses_the_only_preselected_construction_line_among_multiple_lines() {}}+/// #11700: with circles preselected, Mirror opens on the empty Mirror line. A further circle+/// clicked then joins the Entities (the line field refuses it), so every selected circle is+/// mirrored instead of the last one being dropped without a word; the line is still picked next.+#[test]+fn mirror_takes_a_circle_clicked_while_the_mirror_line_is_active_into_the_entities() {+ let mut h = Harness::new();+ h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();+ h.app.run("sketch.line", json!({"points": [[0, -30], [0, 30]], "construction": true, "ids": ["axis"]})).unwrap();+ for y in [-15, 0, 15] {+ h.app.run("sketch.circle.center", json!({"center": [10, y], "radius": 3})).unwrap();+ }+ h.settle();+ h.step(&json!({"click": {"world": [13, -15, 0]}})).unwrap();+ h.step(&json!({"click": {"world": [13, 0, 0]}, "ctrl": true})).unwrap();+ h.step(&json!({"start": "sketch.mirror"})).unwrap();+ assert_eq!(h.app.dialog.as_ref().unwrap().active, 1, "the window waits for the mirror line");+ h.step(&json!({"click": {"world": [13, 15, 0]}})).unwrap();+ let d = h.app.dialog.as_ref().unwrap();+ let curve = |id: &str| Sel::SketchCurve { id: id.into(), sketch: None };+ assert_eq!(d.inputs[0].items, vec![curve("c1"), curve("c2"), curve("c3")]);+ assert!(d.inputs[1].items.is_empty());+ assert_eq!(d.active, 1, "the mirror line is still the next pick");+ // Clicked again, the circle leaves the Entities, as a pick in that list does.+ h.step(&json!({"click": {"world": [13, 15, 0]}})).unwrap();+ assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items, vec![curve("c1"), curve("c2")]);+ h.step(&json!({"click": {"world": [13, 15, 0]}})).unwrap();+ h.step(&json!({"click": {"world": [0, 25, 0]}})).unwrap();+ assert_eq!(h.app.dialog.as_ref().unwrap().inputs[1].items, vec![curve("axis")]);+ h.frames(2);+ h.step(&json!({"key": "Enter"})).unwrap();+ h.settle();+ assert!(h.app.dialog.is_none(), "{:?}", h.app.status);+ let state = h.app.session.model.state();+ let sketch = &state.sketch(h.app.session.active_sketch.unwrap()).unwrap().sketch;+ let mut centres: Vec<(i64, i64)> = sketch+ .curves+ .iter()+ .filter_map(|c| match c.kind {+ solidcraft_engine::sketch::CurveKind::Circle { c, .. } => sketch.point(c),+ _ => None,+ })+ .filter(|p| p.x < 0.0)+ .map(|p| (p.x.round() as i64, p.y.round() as i64))+ .collect();+ centres.sort();+ assert_eq!(centres, vec![(-10, -15), (-10, 0), (-10, 15)], "every selected circle is mirrored");+}+#[test]fn mirror_auto_line_requires_one_preselected_straight_construction_line_and_the_preference() {for (count, selected, enabled) in [(0, 1, true), (1, 0, true), (2, 0, true), (1, 1, true), (2, 1, true), (2, 2, true), (1, 1, false)] {diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rsindex 020a50f357..5d75165cf5 100644--- a/crates/ui-egui/src/viewport.rs+++ b/crates/ui-egui/src/viewport.rs@@ -3742,6 +3742,13 @@ pub(crate) fn dialog_pick(app: &mut SolveApp, hit: &Hit, sel: Sel) {d.focus = true;d.awaiting_pick = false;d.pick_refused = None;+ } else if crate::sketch_modify_ui::picks_entity(&d, &app.session, hit) {+ // A curve the mirror line, centre or direction refuses joins the Entities list, and the+ // window stays on the input it was on (#11700).+ let on = d.active;+ d.active = 0;+ d.pick(&app.session, sel);+ d.active = on;} else {d.pick(&app.session, sel);}