From 9d4d7932ee28a8031d30a1f11944f3ea08f73854 Mon Sep 17 00:00:00 2001 From: sascha2101 Date: Wed, 28 Oct 2026 12:10:45 +0000 Subject: [PATCH] Sketch: offer an arc length dimension for a selected arc (#6039) (#6264) * claim: #6039 * Sketch: offer an arc length dimension for a selected arc (#6039) The arc length dimension already existed in the engine (sketch.dimension with type arc_length), but nothing in the UI led to it: the Dimension tool and the context menu always gave an arc its radius. With exactly one arc selected, the sketch context menu now offers Arc Length Dimension next to Sketch Dimension, which adds the dimension through the existing command. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FN5eEMrqWWXqi65FcK8GXq * test: move the arc length menu test up to avoid a merge conflict Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: sascha2101 <221609842+sascha2101@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/context_menu.rs | 6 ++++++ crates/ui-egui/src/menu_tests.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rs index 2dc061832..d7e6c6c4b 100644 --- a/crates/ui-egui/src/context_menu.rs +++ b/crates/ui-egui/src/context_menu.rs @@ -1122,6 +1122,12 @@ fn sketch_entity_items(app: &SolveApp) -> Vec { v.push(act("ui.paste", "Paste", "paste").key("Ctrl+V").on(app.session.sketch_clipboard.is_some())); v.push(act("ui.delete", "Delete", "delete").key("Del")); v.push(cmd(app, "sketch.dimension", "Sketch Dimension").with(json!({ "entities": ents })).on(ents.len() <= 2)); + // One arc alone: Sketch Dimension gives its radius, this its length along the curve (#6039). + if let [arc] = ents.as_slice() + && ss.sketch.curve_index(arc).and_then(|i| ss.sketch.curves.get(i)).is_some_and(|c| matches!(c.kind, CurveKind::Arc { .. })) + { + v.push(cmd(app, "sketch.dimension", "Arc Length Dimension").with(json!({ "entities": [arc], "type": "arc_length" }))); + } let mut c = Vec::new(); let n = ents.len(); let (l, r, p) = (lines.len(), rounds.len(), points.len()); diff --git a/crates/ui-egui/src/menu_tests.rs b/crates/ui-egui/src/menu_tests.rs index 3d74dfa54..22e5b4092 100644 --- a/crates/ui-egui/src/menu_tests.rs +++ b/crates/ui-egui/src/menu_tests.rs @@ -326,6 +326,36 @@ fn sketch_menu_hides_and_moves_to_another_plane() { assert_eq!(app.tree.redefine, Some(id)); } +#[test] +fn a_selected_arc_offers_an_arc_length_dimension() { + // #6039: the arc length dimension existed as a command, but nothing in the UI led to it. + let mut app = sample_app(); + app.run("sketch.create", json!({"plane": "XY"})).unwrap(); + app.run("sketch.arc.center_point", json!({"center": [0, 0], "start": [10, 0], "end": [0, 10]})).unwrap(); + app.run("sketch.circle.center", json!({"center": [40, 0], "radius": 5})).unwrap(); + let ids: Vec = { + let st = app.session.model.state(); + let ss = st.sketch(app.session.active_sketch.unwrap()).unwrap(); + ss.sketch.curves.iter().map(|c| c.id.clone()).collect() + }; + let select = |app: &mut SolveApp, id: &str| app.run("select.set", json!({"items": [{"type": "sketch_curve", "id": id}]})).unwrap(); + select(&mut app, &ids[1]); + assert!(!context_menu::items(&app, &Target::Viewport).iter().any(|i| i.label == "Arc Length Dimension"), "a circle has no arc length"); + select(&mut app, &ids[0]); + let item = find(&context_menu::items(&app, &Target::Viewport), "Arc Length Dimension"); + assert!(item.enabled); + context_menu::run_item(&mut app, &item, pos2(0.0, 0.0)); + let st = app.session.model.state(); + let ss = st.sketch(app.session.active_sketch.unwrap()).unwrap(); + let len = ss.sketch.constraints.iter().find_map(|c| match c.kind { + solidcraft_engine::sketch::ConstraintKind::ArcLength { value, .. } => Some(value), + _ => None, + }); + // A quarter of a circle of radius 10. + assert!(len.is_some_and(|l| (l - 5.0 * std::f64::consts::PI).abs() < 1e-5), "{:?}", ss.sketch.constraints); + assert!(ss.report.ok()); +} + #[test] fn sketch_entities_offer_the_constraints_that_fit() { let mut app = sample_app();