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();