From 686576e3688827b8f6bdd25fb10745aaa33a9a7a Mon Sep 17 00:00:00 2001 From: kaltenbrunnermarkus <153593707+kaltenbrunnermarkus@users.noreply.github.com> Date: Wed, 21 Oct 2026 00:49:48 +0000 Subject: [PATCH] Section Analysis: Edit reopens the dialog where the section was left (#3617) Edit Section Analysis (its menu item, or a double-click on its browser row) opened the dialog at distance 0 with no plane, so moving the cut on by a millimetre meant picking the plane and typing the whole distance again. OK now keeps the dialog's plane pick, distance and flip with the cut they made, and Edit starts from them while the section shown (or hidden) is still that cut. The toolbar still starts a new section afresh, and a section made some other way (a command, an agent) opens the dialog as before. Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/browser.rs | 4 +- crates/ui-egui/src/context_menu.rs | 2 +- crates/ui-egui/src/dialogs.rs | 36 ++++++++++++ crates/ui-egui/src/section_browser_tests.rs | 62 +++++++++++++++++++++ 4 files changed, 102 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs index c2d540f67..c78c3ea98 100644 --- a/crates/ui-egui/src/browser.rs +++ b/crates/ui-egui/src/browser.rs @@ -91,6 +91,8 @@ pub struct TreeState { /// A Section Analysis hidden with its eye in the Analysis folder: its plane (origin, /// normal), so the eye can bring it back (#822). pub hidden_section: Option<(solidcraft_engine::geom::Vec3, solidcraft_engine::geom::Vec3)>, + /// What the Section Analysis dialog's OK last made, for Edit to start from. + pub section_dialog: Option, /// The Analysis folder hidden with its own eye, and the Section Analysis hidden with its /// own: the section shows only while neither is, and each eye keeps its state. pub analysis_hidden: bool, @@ -1401,7 +1403,7 @@ fn analysis_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &mut set_section_shown(app, !section_shown); } if r.double { - app.start("inspect.section"); + crate::dialogs::edit_section(app); } if let Some(p) = r.secondary { acts.menu = Some((p, Target::Section)); diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rs index 9d864045b..67fb16df3 100644 --- a/crates/ui-egui/src/context_menu.rs +++ b/crates/ui-egui/src/context_menu.rs @@ -1103,7 +1103,7 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) { app.tree.hidden_section = None; drop(app.run("inspect.section", json!({"clear": true}))); } - "ui.editSection" => app.start("inspect.section"), + "ui.editSection" => crate::dialogs::edit_section(app), "ui.sectionVisible" => crate::browser::set_section_shown(app, p.get("visible").and_then(Value::as_bool).unwrap_or(true)), "ui.fit" => app.animate_view("fit"), "ui.home" => app.animate_view("home"), diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 59593d37d..70eefe7fd 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -2835,9 +2835,45 @@ pub(crate) fn run_dialog(app: &mut SolveApp, d: &Dialog) -> Result<(), String> { } } } + if let Kind::Section { offset, flip } = &d.kind + && let Some(cut) = app.session.section + { + app.tree.section_dialog = Some(SectionDraft { offset: offset.clone(), flip: *flip, plane: sels(d, 0).to_vec(), cut }); + } Ok(()) } +/// Edit Section Analysis: its dialog, where the dialog that made the section shown (or hidden) +/// now left it, so the cut moves on from there. A section made some other way opens it afresh, +/// as the toolbar always does (a new section, in place of the old). +pub fn edit_section(app: &mut SolveApp) { + app.start("inspect.section"); + let cut = app.session.section.or(app.tree.hidden_section); + let Some(last) = app.tree.section_dialog.clone().filter(|last| cut.is_some_and(|c| same_cut(c, last.cut))) else { return }; + if let Some(d) = app.dialog.as_mut().filter(|d| matches!(d.kind, Kind::Section { .. })) { + d.kind = Kind::Section { offset: last.offset, flip: last.flip }; + if let Some(plane) = d.inputs.first_mut() { + plane.items = last.plane; + } + } +} + +/// What the Section Analysis dialog's OK made: its distance, flip and plane pick, and the cut +/// (origin, normal) they made, so Edit reopens the dialog where it was while that cut stands. +#[derive(Clone, Debug)] +pub struct SectionDraft { + pub offset: String, + pub flip: bool, + pub plane: Vec, + pub cut: (Vec3, Vec3), +} + +/// The same cut, up to rounding (hiding and showing a section runs it again from its plane). +fn same_cut(a: (Vec3, Vec3), b: (Vec3, Vec3)) -> bool { + let tol = 1e-9 * (1.0 + a.0.len().max(b.0.len())); + (a.0 - b.0).len() <= tol && (a.1 - b.1).len() <= 1e-9 +} + /// Placement used to edit a definition in the selected authoring occurrence. pub(crate) fn feature_frame(s: &Session, component: u64) -> solidcraft_engine::doc::Mat { if component == s.active_component { s.active_component_frame() } else { s.placed_document().component_transform(component) } diff --git a/crates/ui-egui/src/section_browser_tests.rs b/crates/ui-egui/src/section_browser_tests.rs index 6d4d3162b..ac1982a89 100644 --- a/crates/ui-egui/src/section_browser_tests.rs +++ b/crates/ui-egui/src/section_browser_tests.rs @@ -86,3 +86,65 @@ fn edit_opens_the_section_dialog() { menu(&mut h, "Edit Section Analysis"); assert!(h.app.dialog.is_some(), "the Section Analysis dialog opens"); } + +fn section_dialog(h: &Harness) -> (String, bool, Vec) { + let d = h.app.dialog.as_ref().expect("the Section Analysis dialog"); + let crate::dialogs::Kind::Section { offset, flip } = &d.kind else { panic!("not the section dialog: {:?}", d.kind) }; + (offset.clone(), *flip, d.inputs.first().map(|i| i.items.clone()).unwrap_or_default()) +} + +fn ok(h: &mut Harness) { + h.frames(2); + h.step(&json!({"widget":"OK"})).unwrap(); + h.frames(3); + assert!(h.app.dialog.is_none(), "OK closes the dialog"); +} + +/// Editing a section reopens its dialog at the plane and distance it was left at, so the cut +/// moves on from there instead of jumping back to the plane. +#[test] +fn edit_starts_from_the_section_as_it_was_left() { + let mut h = harness(); + h.app.run("solid.box", json!({"length":40,"width":30,"height":20})).unwrap(); + h.app.session.selection = vec![solidcraft_engine::Sel::Plane { name: "XY".into() }]; + h.app.start("inspect.section"); + if let Some(crate::dialogs::Kind::Section { offset, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) { + *offset = "12 mm".into(); + } + ok(&mut h); + let cut = h.app.session.section.expect("a section"); + assert!((cut.0.z - 12.0).abs() < 1e-9, "{cut:?}"); + + // The toolbar starts a new section (in place of this one), not an edit of it. + h.app.session.selection.clear(); + h.app.start("inspect.section"); + let (offset, _, plane) = section_dialog(&h); + assert_eq!(offset, "0 mm", "a new section starts at its plane"); + assert!(plane.is_empty(), "a new section picks its own plane: {plane:?}"); + crate::dialogs::cancel(&mut h.app); + h.frames(2); + assert!(h.app.session.section.is_some_and(|c| (c.0.z - 12.0).abs() < 1e-9), "cancelling keeps the section"); + + menu(&mut h, "Edit Section Analysis"); + let (offset, flip, plane) = section_dialog(&h); + assert_eq!((offset.as_str(), flip), ("12 mm", false)); + assert_eq!(plane, vec![solidcraft_engine::Sel::Plane { name: "XY".into() }]); + crate::dialogs::cancel(&mut h.app); + h.frames(2); + + // Hidden and shown again, it is still the section the dialog made. + click(&mut h, "eye:Section Analysis"); + click(&mut h, "eye:Section Analysis"); + menu(&mut h, "Edit Section Analysis"); + assert_eq!(section_dialog(&h).0, "12 mm"); + crate::dialogs::cancel(&mut h.app); + h.frames(2); + + // A section made some other way (here a command) is not the dialog's: Edit starts afresh. + h.app.run("inspect.section", json!({"plane": "XZ", "offset": 5})).unwrap(); + h.frames(3); + menu(&mut h, "Edit Section Analysis"); + let (offset, _, plane) = section_dialog(&h); + assert_eq!(offset, "0 mm"); + assert!(plane.is_empty()); +}