Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Sketch Mirror: use the preselected construction line (#10486)

Leod5e953871bc6
diff --git a/assets/locales/pending/sketch-mirror-auto-line.json b/assets/locales/pending/sketch-mirror-auto-line.json
new file mode 100644
index 0000000000..fb2e2e417c
--- /dev/null
+++ b/assets/locales/pending/sketch-mirror-auto-line.json
@@ -0,0 +1,10 @@
+{
+ "en": { "prefs.sketch_mirror_auto_line": "Use the preselected construction line for Mirror" },
+ "ar": { "prefs.sketch_mirror_auto_line": "استخدام الخط الإنشائي المحدد مسبقًا كمحور للانعكاس" },
+ "de": { "prefs.sketch_mirror_auto_line": "Vorausgewählte Konstruktionslinie zum Spiegeln verwenden" },
+ "he": { "prefs.sketch_mirror_auto_line": "שימוש בישר העזר שנבחר מראש כציר שיקוף" },
+ "ja": { "prefs.sketch_mirror_auto_line": "事前に選択した補助直線をミラー線に使用する" },
+ "ko": { "prefs.sketch_mirror_auto_line": "미리 선택한 보조 직선을 미러 선으로 사용" },
+ "vi": { "prefs.sketch_mirror_auto_line": "Dùng đường dựng hình đã chọn làm đường đối xứng" },
+ "zh": { "prefs.sketch_mirror_auto_line": "将预选的构造直线用作镜像线" }
+}
diff --git a/attribution/pending/sketch-mirror-auto-line.md b/attribution/pending/sketch-mirror-auto-line.md
new file mode 100644
index 0000000000..0015ba5c2f
--- /dev/null
+++ b/attribution/pending/sketch-mirror-auto-line.md
@@ -0,0 +1 @@
+| assets/locales/pending/sketch-mirror-auto-line.json | SolidCraft contributors | Original Mirror preference label and translations | MIT OR Apache-2.0 |
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index a76febed8f..23362f4a71 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -1270,6 +1270,26 @@ impl Dialog {
{
inp.items = default_profiles(s);
}
+ if matches!(d.kind, Kind::SketchModify(crate::sketch_modify_ui::Mod::Mirror)) && app.preferences.sketch_mirror_auto_line {
+ let state = s.model.state();
+ if let Some(sketch) = s.active_sketch.and_then(|id| state.sketch(id)) {
+ let mut lines = s.selection.iter().filter_map(|sel| {
+ let Sel::SketchCurve { id, sketch: from } = sel else { return None };
+ if from.is_some() && *from != s.active_sketch {
+ return None;
+ }
+ let curve = sketch.sketch.curves.get(sketch.sketch.curve_index(id)?)?;
+ (curve.construction && matches!(curve.kind, solidcraft_engine::sketch::CurveKind::Line { .. })).then_some(curve)
+ });
+ if let Some(line) = lines.next()
+ && lines.next().is_none()
+ && let Some(input) = d.inputs.get_mut(1)
+ && input.items.is_empty()
+ {
+ input.items.push(Sel::SketchCurve { id: line.id.clone(), sketch: None });
+ }
+ }
+ }
d.sync_thread(s);
d.sync_material(s);
d.advance();
diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs
index fc4331a7ca..08a660141a 100644
--- a/crates/ui-egui/src/prefs.rs
+++ b/crates/ui-egui/src/prefs.rs
@@ -1603,6 +1603,8 @@ preference_settings! {
sketch_state_icons: bool = true, PAGE_SKETCH;
/// Show the construction-line family in Sketch CREATE; off restores the earlier menu.
sketch_construction_lines: bool = true, PAGE_SKETCH;
+ /// Use the only straight construction line in the preselection as Mirror's reference.
+ sketch_mirror_auto_line: bool = true, PAGE_SKETCH;
/// A sketch tool's shortcut pressed again before the first point steps to the tool's next
/// creation mode (#2459). Off (the default): the key starts the tool again, as it always has.
shortcut_cycles_modes: bool = false, PAGE_SKETCH;
@@ -6194,6 +6196,7 @@ mod tests {
("hide_constraint_glyphs_zoomed_out", json!(false), PAGE_SKETCH),
("suppress_sketch_snap", json!(ModifierCombo::NONE), PAGE_SKETCH),
("sketch_state_icons", json!(false), PAGE_SKETCH),
+ ("sketch_mirror_auto_line", json!(false), PAGE_SKETCH),
("sketch_tracking_guides", json!(false), PAGE_SKETCH),
("sketch_tracking_points", json!(false), PAGE_SKETCH),
("sketch_align_points", json!(true), PAGE_SKETCH),
diff --git a/crates/ui-egui/src/prefs/sketch.rs b/crates/ui-egui/src/prefs/sketch.rs
index e29936b05e..ee2a232e27 100644
--- a/crates/ui-egui/src/prefs/sketch.rs
+++ b/crates/ui-egui/src/prefs/sketch.rs
@@ -90,6 +90,7 @@ fn drawing(app: &mut SolveApp, ui: &mut egui::Ui) {
"prefs.line_hover_tangent_arc",
"prefs.sketch.center_arc",
"prefs.sketch_construction_lines",
+ "prefs.sketch_mirror_auto_line",
"prefs.sketch.ellipse_axes",
"prefs.sketch.auto_dimensions",
"prefs.sketch.auto_locate",
@@ -128,6 +129,7 @@ fn drawing(app: &mut SolveApp, ui: &mut egui::Ui) {
&mut app.preferences.center_arc_follows_cursor,
);
check(ui, "sketch_construction_lines", "prefs.sketch_construction_lines", None, &mut app.preferences.sketch_construction_lines);
+ check(ui, "sketch_mirror_auto_line", "prefs.sketch_mirror_auto_line", None, &mut app.preferences.sketch_mirror_auto_line);
check(ui, "ellipse_axes", "prefs.sketch.ellipse_axes", Some("prefs.sketch.ellipse_axes_note"), &mut app.preferences.ellipse_axes);
check(
ui,
diff --git a/crates/ui-egui/src/sketch_guidance_ui_tests.rs b/crates/ui-egui/src/sketch_guidance_ui_tests.rs
index 45404e4763..f6a6e0e3ee 100644
--- a/crates/ui-egui/src/sketch_guidance_ui_tests.rs
+++ b/crates/ui-egui/src/sketch_guidance_ui_tests.rs
@@ -13,6 +13,7 @@ fn step(h: &mut Harness, value: Value) {
fn fixture() -> Harness {
let mut h = Harness::new();
h.app.preferences.look_at_anim = false;
+ h.app.preferences.sketch_mirror_auto_line = false; // Exercise manual reference picking.
for (command, params) in [
("sketch.create", json!({"plane":"XY"})),
("sketch.line", json!({"points":[[-30,10],[-15,10]]})),
diff --git a/crates/ui-egui/src/sketch_modify_ui_tests.rs b/crates/ui-egui/src/sketch_modify_ui_tests.rs
index ced008fbf2..903e1c423a 100644
--- a/crates/ui-egui/src/sketch_modify_ui_tests.rs
+++ b/crates/ui-egui/src/sketch_modify_ui_tests.rs
@@ -204,6 +204,107 @@ fn the_toolbar_button_opens_a_window_with_both_picks_visible() {
assert_eq!(curve_ids(&h).len(), before);
}
+#[test]
+fn mirror_uses_the_only_preselected_construction_line_among_multiple_lines() {
+ for second_axis in [false, true] {
+ let mut h = line_and_circle();
+ let ids = curve_ids(&h);
+ h.app.run("sketch.construction", json!({"curves": [ids[0]], "value": true})).unwrap();
+ h.app.run("sketch.line", json!({"points": [[5, -20], [5, 20]], "construction": true, "ids": ["second_axis"]})).unwrap();
+ let line = if second_axis { "second_axis" } else { &ids[0] };
+ let mut picks = vec![Sel::SketchCurve { id: line.into(), sketch: None }, Sel::SketchCurve { id: ids[1].clone(), sketch: None }];
+ if second_axis {
+ picks.reverse();
+ }
+ h.app.session.selection = picks.clone();
+ let before = h.app.session.doc.to_json();
+ let undo = h.app.session.undo.len();
+ h.step(&json!({"start": "sketch.mirror"})).unwrap();
+ let d = h.app.dialog.as_ref().unwrap();
+ assert_eq!(d.inputs[0].items, picks);
+ assert_eq!(d.inputs[1].items, vec![Sel::SketchCurve { id: line.into(), sketch: None }]);
+ assert_eq!(h.app.session.doc.to_json(), before, "opening Mirror only previews the result");
+ assert_eq!(h.app.session.undo.len(), undo);
+ 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;
+ assert_eq!(sketch.curves.len(), 4, "neither the reference nor the unselected construction line is copied");
+ let solidcraft_engine::sketch::CurveKind::Circle { c, r } = &sketch.curves.last().unwrap().kind else { panic!("expected mirrored circle") };
+ let at = sketch.point(*c).unwrap();
+ let expected_x = if second_axis { 0.0 } else { -10.0 };
+ assert!((at.x - expected_x).abs() < 1e-6 && at.y.abs() < 1e-6);
+ assert!((*r - 3.0).abs() < 1e-6);
+ h.app.run("edit.undo", json!({})).unwrap();
+ assert_eq!(h.app.session.doc.to_json(), before);
+ }
+}
+
+#[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)] {
+ let mut h = line_and_circle();
+ let ids = curve_ids(&h);
+ // A construction circle never qualifies, and ordinary lines do not count.
+ h.app.run("sketch.construction", json!({"curves": [ids[1]], "value": true})).unwrap();
+ if count > 0 {
+ h.app.run("sketch.construction", json!({"curves": [ids[0]], "value": true})).unwrap();
+ }
+ if count > 1 {
+ h.app.run("sketch.line", json!({"points": [[5, -20], [5, 20]], "construction": true, "ids": ["second_axis"]})).unwrap();
+ }
+ h.app.session.selection = vec![Sel::SketchCurve { id: ids[1].clone(), sketch: None }];
+ h.app
+ .session
+ .selection
+ .extend([ids[0].as_str(), "second_axis"].into_iter().take(selected).map(|id| Sel::SketchCurve { id: id.into(), sketch: None }));
+ h.app.preferences.sketch_mirror_auto_line = enabled;
+ h.step(&json!({"start": "sketch.mirror"})).unwrap();
+ let d = h.app.dialog.as_ref().unwrap();
+ let expected = if count > 0 && selected == 1 && enabled { vec![Sel::SketchCurve { id: ids[0].clone(), sketch: None }] } else { vec![] };
+ assert_eq!(d.inputs[1].items, expected, "count={count}, selected={selected}, enabled={enabled}");
+ }
+}
+
+#[test]
+fn mirror_auto_line_respects_manual_references_and_only_uses_the_active_sketch() {
+ let mut h = line_and_circle();
+ let ids = curve_ids(&h);
+ h.app.run("sketch.construction", json!({"curves": [ids[0]], "value": true})).unwrap();
+ h.app.session.selection.clear();
+ h.step(&json!({"start": "sketch.mirror"})).unwrap();
+ let d = h.app.dialog.as_ref().unwrap();
+ assert!(d.inputs[0].items.is_empty() && d.inputs[1].items.is_empty(), "nothing is inferred without preselection");
+ assert_eq!(d.active, 0);
+ h.step(&json!({"key": "Escape"})).unwrap();
+ let line = Sel::SketchCurve { id: ids[0].clone(), sketch: None };
+ let axis = Sel::Axis { name: "X".into() };
+ h.app.session.selection = vec![axis.clone(), line.clone()];
+ h.step(&json!({"start": "sketch.mirror"})).unwrap();
+ assert_eq!(h.app.dialog.as_ref().unwrap().inputs[1].items, vec![axis]);
+ h.step(&json!({"key": "Escape"})).unwrap();
+ h.app.session.selection = vec![line];
+ h.step(&json!({"start": "sketch.mirror"})).unwrap();
+ assert_eq!(h.app.dialog.as_ref().unwrap().inputs[1].items.len(), 1);
+ h.step(&json!({"click": {"handle": "dialog:clear:Mirror line"}})).unwrap();
+ h.frames(3);
+ assert!(h.app.dialog.as_ref().unwrap().inputs[1].items.is_empty(), "a cleared reference stays empty");
+ h.step(&json!({"key": "Escape"})).unwrap();
+ let previous_sketch = h.app.session.active_sketch;
+ h.app.run("sketch.finish", json!({})).unwrap();
+ h.app.run("sketch.create", json!({"plane": "XZ"})).unwrap();
+ h.app.run("sketch.line", json!({"points": [[0, -20], [0, 20]], "construction": true, "ids": [ids[0]]})).unwrap();
+ h.app.session.selection = vec![Sel::SketchCurve { id: ids[0].clone(), sketch: previous_sketch }];
+ h.step(&json!({"start": "sketch.mirror"})).unwrap();
+ assert!(h.app.dialog.as_ref().unwrap().inputs[1].items.is_empty(), "another sketch's construction line is not used");
+ h.step(&json!({"key": "Escape"})).unwrap();
+ h.app.session.selection = vec![Sel::SketchCurve { id: ids[0].clone(), sketch: h.app.session.active_sketch }];
+ h.step(&json!({"start": "sketch.mirror"})).unwrap();
+ assert_eq!(h.app.dialog.as_ref().unwrap().inputs[1].items, vec![Sel::SketchCurve { id: ids[0].clone(), sketch: None }]);
+}
+
#[test]
fn the_two_picks_become_the_command() {
let h = line_and_circle();
diff --git a/crates/ui-egui/tests/scenarios/sketch_mirror_dialog.json b/crates/ui-egui/tests/scenarios/sketch_mirror_dialog.json
index ae729b9f19..73505abd72 100644
--- a/crates/ui-egui/tests/scenarios/sketch_mirror_dialog.json
+++ b/crates/ui-egui/tests/scenarios/sketch_mirror_dialog.json
@@ -1,5 +1,5 @@
[
- {"call":"ui.prefs","params":{"look_at_anim":false}},
+ {"call":"ui.prefs","params":{"look_at_anim":false,"sketch_mirror_auto_line":false}},
{"call":"engine.execute","params":{"command":"sketch.create","params":{"plane":"XY"}}},
{"call":"engine.execute","params":{"command":"sketch.line","params":{"points":[[-30,10],[-15,10]]}}},
{"call":"engine.execute","params":{"command":"sketch.line","params":{"points":[[-15,10],[-15,25]]}}},
diff --git a/docs/book/src/guide/sketching.md b/docs/book/src/guide/sketching.md
index a78444f91a..3c61f91fe3 100644
--- a/docs/book/src/guide/sketching.md
+++ b/docs/book/src/guide/sketching.md
@@ -546,6 +546,12 @@ it to remove it. Each input has its own Clear button. Source inputs show a count
references identify the chosen mirror line, direction, or centre. Box selection also works
while the window is open. Sketch modify tools take geometry from the sketch being edited.
+If your preselection includes exactly one straight construction line of the active sketch,
+opening Mirror uses it as **Mirror line**, keeping your selected entities. Other construction
+lines in the sketch do not count unless selected. With none or multiple selected construction
+lines, choose the reference manually. You can clear or replace the line. To always choose it
+manually, turn off **Preferences > Sketch > Use the preselected construction line for Mirror**.
+
Proposed sketch geometry appears **green** before confirmation. Change the inputs or values to
update the preview, then press **OK**. **Cancel** discards the preview. A circular pattern centre
can be an existing point or a position clicked in empty sketch space.
diff --git a/docs/control-protocol.md b/docs/control-protocol.md
index 63e46f9867..42ad991144 100644
--- a/docs/control-protocol.md
+++ b/docs/control-protocol.md
@@ -769,6 +769,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own
- `sketch_conflict_colour` (default true: while the open sketch's constraints conflict, the curves and points a failing constraint holds are drawn in the theme's `sketch_conflict` colour too, not only its glyph or dimension; false: only the glyphs and dimensions are red, in `error`, as before, #7244)
- `sketch_construction_lines` (default true: show the Construction Line tool family in Sketch CREATE; false restores the earlier menu)
- `sketch_exit_view` (`keep` (default: the view stays where it is when a sketch ends), `previous` (back to the view from before the sketch), `unless_rotated` (back unless the sketch view was turned))
+- `sketch_mirror_auto_line` (default true: opening Sketch Mirror uses the only preselected straight construction line of the active sketch as its reference; unselected lines do not count; false keeps manual reference selection)
- `sketch_open_look_at` (default true: creating or editing a sketch turns the view to face it; false leaves the view as it is, and Look At faces the sketch when asked)
- `sketch_recent_snap` (default false: while drawing, the cursor snaps where the horizontal guide of one recent circle or arc centre or straight-edge midpoint meets the vertical guide of another; a free coordinate, with no constraint and no construction geometry. Off: those guides stay visual and the cursor does not move. The references come from `sketch_tracking_guides`, #8694)
- `sketch_state_icons` (default true: a sketch's icon in History and the browser takes the colour of its solve state, `sketch` under constrained, `sketch_fixed` fully constrained, `error` while its constraints conflict, and its tooltip names the state; false: every sketch row's icon and tooltip as before, #7245)