From 2d1acd95c6061be1cb34a0c4ef2b1900acd06eb6 Mon Sep 17 00:00:00 2001 From: 0rdnungsamt <225375511+0rdnungsamt@users.noreply.github.com> Date: Mon, 9 Nov 2026 06:41:13 +0100 Subject: [PATCH 1/2] claim: #12569 (Section Analysis Distance slider) Co-Authored-By: Claude Opus 5.5 From cc57df6b0bcc6341940c8f9ae6558f49e25d4791 Mon Sep 17 00:00:00 2001 From: 0rdnungsamt <225375511+0rdnungsamt@users.noreply.github.com> Date: Mon, 9 Nov 2026 15:16:57 +0100 Subject: [PATCH 2/2] Section Analysis: a slider on Distance moves the cut live Once a plane is picked, a slider under the Distance field spans the model's extent along the plane's normal. Dragging writes the field, so the existing live preview follows and a typed expression is left alone until the slider is touched. A value typed outside the model widens the range instead of being clamped. Part of #12569. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs_dense.rs | 45 +++++++++++++++++ crates/ui-egui/src/section_browser_tests.rs | 54 +++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/crates/ui-egui/src/dialogs_dense.rs b/crates/ui-egui/src/dialogs_dense.rs index beec99cc590..efe0fd11bfa 100644 --- a/crates/ui-egui/src/dialogs_dense.rs +++ b/crates/ui-egui/src/dialogs_dense.rs @@ -826,9 +826,51 @@ fn coil_rows(ui: &mut egui::Ui, extra: &mut serde_json::Map) -> b enter } +/// The distances along a Section Analysis's plane at which the cut goes through the model, or +/// `None` while the dialog has no plane or there is no model to cut. +fn section_span(app: &SolveApp, d: &Dialog) -> Option<(f64, f64)> { + if !matches!(d.kind, Kind::Section { .. }) { + return None; + } + let (_, params) = apply_commands(app, d).ok()?.into_iter().next()?; + params.get("plane")?; + let cut_at = |distance: &str| { + let mut p = params.clone(); + p["offset"] = json!(distance); + let mut scratch = app.session.scratch(); + scratch.execute("inspect.section", &p).ok()?; + scratch.section + }; + let origin = cut_at("0 mm")?.0; + let along = cut_at("1 mm")?.0 - origin; + let b = crate::viewport::model_bounds(app); + let distances = [b.min.x, b.max.x] + .into_iter() + .flat_map(|x| [b.min.y, b.max.y].into_iter().map(move |y| (x, y))) + .flat_map(|(x, y)| [b.min.z, b.max.z].into_iter().map(move |z| Vec3::new(x, y, z))) + .map(|corner| (corner - origin).dot(along)); + let (lo, hi) = distances.fold((f64::INFINITY, f64::NEG_INFINITY), |(lo, hi), d| (lo.min(d), hi.max(d))); + (lo.is_finite() && hi.is_finite() && lo < hi).then_some((lo, hi)) +} + +/// A slider under Section Analysis's Distance. The field keeps what was typed until the slider +/// is dragged, and a distance typed outside the model widens the slider to reach it. +fn section_slider(app: &SolveApp, ui: &mut egui::Ui, offset: &mut String, (lo, hi): (f64, f64)) { + let doc = &app.session.doc; + let mut shown = crate::length_input::eval(doc, offset, solidcraft_engine::doc::expr::Kind::Length).ok().filter(|x| x.is_finite()).unwrap_or(0.0); + let range = lo.min(shown)..=hi.max(shown); + form_row(ui, "", |ui| { + let slider = ui_kit::Slider { show_value: false, ..Default::default() }; + if ui_kit::slider(ui, &mut shown, range, slider).changed() { + *offset = crate::length_input::model(doc, shown); + } + }); +} + fn additional_rows(app: &mut SolveApp, d: &mut Dialog, ui: &mut egui::Ui) -> bool { let mut enter = false; let through_point = offset_through_point(d).is_some(); + let section_span = section_span(app, d); match &mut d.kind { Kind::Revolve { angle, operation, .. } => { let cur = usize::from(to_object_on(&d.inputs)); @@ -1100,6 +1142,9 @@ fn additional_rows(app: &mut SolveApp, d: &mut Dialog, ui: &mut egui::Ui) -> boo Kind::Measure { result, show, .. } => measure_rows(app, ui, result.as_ref(), show), Kind::Section { offset, flip, hatch } => { enter |= expr_row(ui, "Distance", offset); + if let Some(span) = section_span { + section_slider(app, ui, offset, span); + } ui_kit::options(ui, "feature_options", &mut [("Flip", flip), ("Hatch", hatch)]); if section_turns_off(&app.session, &d.inputs) && !d.extra.contains_key("plane") { ui_kit::text(ui, tr("section.off_hint"), ui_kit::Text::Hint("section_off")); diff --git a/crates/ui-egui/src/section_browser_tests.rs b/crates/ui-egui/src/section_browser_tests.rs index a68f66d9456..ed788d49567 100644 --- a/crates/ui-egui/src/section_browser_tests.rs +++ b/crates/ui-egui/src/section_browser_tests.rs @@ -300,3 +300,57 @@ fn a_section_reopened_from_its_geometry_keeps_its_drag_arrow() { assert!(dir.is_some_and(|n| (n.y.abs() - 1.0).abs() < 1e-9), "{params}: the picked plane's arrow: {dir:?}"); } } + +/// The Distance slider spans the model along the plane and moves the cut while it is held. A +/// distance typed outside the model stays as typed, and with no plane there is no slider. +#[test] +fn the_distance_slider_moves_the_cut_live() { + fn slider(h: &Harness) -> Option { + h.output.accesskit_update.as_ref()?.nodes.iter().find_map(|(_, n)| (n.role() == egui::accesskit::Role::Slider).then(|| n.bounds()).flatten()) + } + fn offset(h: &Harness) -> String { + match h.app.dialog.as_ref().map(|d| &d.kind) { + Some(crate::dialogs::Kind::Section { offset, .. }) => offset.clone(), + other => panic!("not the section dialog: {other:?}"), + } + } + let mut h = harness(); + h.app.preferences.viewport_section_status = false; + h.app.run("solid.box", json!({"length":40,"width":30,"height":20})).unwrap(); + h.app.session.selection.clear(); + h.app.start("inspect.section"); + h.frames(4); + assert!(slider(&h).is_none(), "no plane, no slider"); + h.app.dialog.as_mut().unwrap().inputs[0].items.push(solidcraft_engine::Sel::Plane { name: "XY".into() }); + h.frames(4); + let typed = offset(&h); + let bounds = slider(&h).expect("the Distance slider"); + assert_eq!(offset(&h), typed, "showing the slider leaves the field alone"); + let at = |fraction: f64| pos2((bounds.x0 + fraction * (bounds.x1 - bounds.x0)) as f32, ((bounds.y0 + bounds.y1) / 2.0) as f32); + let start = at(0.25); + h.app.synthetic.extend([ + egui::Event::PointerMoved(start), + egui::Event::PointerButton { pos: start, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }, + ]); + h.frames(3); + let first = crate::viewport::section_plane(&h.app).expect("a cut while held").0.z; + h.app.synthetic.push(egui::Event::PointerMoved(at(0.75))); + h.frames(3); + let second = crate::viewport::section_plane(&h.app).expect("a cut while held").0.z; + assert!(h.ctx.input(|i| i.pointer.primary_down())); + let model = crate::viewport::model_bounds(&h.app); + assert!(second > first && first >= model.min.z && second <= model.max.z, "{first} {second} {model:?}"); + assert!(offset(&h) != typed, "the field follows the slider"); + h.app.synthetic.push(egui::Event::PointerButton { + pos: at(0.75), + button: egui::PointerButton::Primary, + pressed: false, + modifiers: Default::default(), + }); + h.frames(3); + if let Some(crate::dialogs::Kind::Section { offset, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) { + *offset = "500 mm".into(); + } + h.frames(4); + assert_eq!(offset(&h), "500 mm"); +}