From 6e87fb1a257b5e57ee96f369322f488d4d856449 Mon Sep 17 00:00:00 2001 From: bherbruck Date: Tue, 20 Oct 2026 21:08:04 -0400 Subject: [PATCH] Ribbon: Parameters and Configurations back on Model, Sheet Metal and Sketch; Sheet Metal tab always reachable; Finish Sketch button back in the sketch palette (#3937) Co-authored-by: Claude Sonnet 5.5 --- crates/ui-egui/src/lib.rs | 2 +- crates/ui-egui/src/sketch_palette.rs | 29 ++++++++--- crates/ui-egui/src/toolbar.rs | 10 +++- crates/ui-egui/src/ui_kit/actions.rs | 11 ++++ crates/ui-egui/src/ui_kit/gallery.rs | 3 ++ crates/ui-egui/src/workspace.rs | 77 ++++++++++++++++++++++++++-- docs/book/src/guide/sheet-metal.md | 4 +- docs/book/src/guide/ui-tour.md | 4 +- docs/control-protocol.md | 2 +- docs/ribbon-layout.md | 7 ++- 10 files changed, 126 insertions(+), 23 deletions(-) diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index f2cee33a0..4d502c72b 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -246,7 +246,7 @@ pub use control::{ControlRequest, ControlResponse}; pub struct UiState { /// Automation-only shell mode; never persisted in preferences. pub layout: shell::LayoutMode, - /// Ribbon tab; contextual SKETCH and SHEET METAL join the seven design tabs. + /// Ribbon tab; SHEET METAL and the contextual SKETCH join the seven design tabs. pub tab: String, /// Last contextual body/sketch, only used to select on entry. #[serde(skip)] diff --git a/crates/ui-egui/src/sketch_palette.rs b/crates/ui-egui/src/sketch_palette.rs index 4b7994598..03b731362 100644 --- a/crates/ui-egui/src/sketch_palette.rs +++ b/crates/ui-egui/src/sketch_palette.rs @@ -3,7 +3,7 @@ //! buttons. Options: the line type of the selected curves (normal, construction, centerline), //! Look At, and the display toggles kept with the sketch (grid, snap, slice, profiles, points, //! dimensions, constraints, projected geometry, construction geometry, 3D sketch); the sketch's -//! degrees of freedom. Finish Sketch lives in the ribbon Exit group. Toggles run `sketch.options`, line types +//! degrees of freedom. Finish Sketch sits at the bottom, beside the ribbon's Exit group. Toggles run `sketch.options`, line types //! `sketch.construction` / `sketch.centerline`. //! //! The line type is also a drawing mode: with nothing selected, Construction (or X) makes what @@ -343,6 +343,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) { let mut linetype = None; let mut construction = false; let mut look = false; + let mut finish = false; let mut tie = false; let mut start = None; let feature = active_feature(app); @@ -460,6 +461,10 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) { section_alias("sketch_palette:options_fold", "ui.palette_more"); } crate::ui_kit::Part::Footer => { + let button = crate::ui_kit::wide_primary_button(ui, "Finish Sketch"); + crate::scenario::publish_rect("sketch_palette:finish", button.rect); + crate::scenario::publish_handle("sketch_palette:finish", button.rect.center()); + finish = button.clicked(); let (at, slice) = crate::ui_kit::button_pair( ui, "sketch_palette", @@ -480,13 +485,6 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) { if let Some(rect) = app.viewport.palette_rect { crate::scenario::publish_rect("sketch_palette:outer", rect); } - // Compatibility automation hook now points at the single Finish action in the ribbon. - if let Some(at) = crate::scenario::handle_at("button:sketch.finish") { - crate::scenario::publish_handle("sketch_palette:finish", at); - if let Some(rect) = crate::scenario::rect_of("button:sketch.finish") { - crate::scenario::publish_rect("sketch_palette:finish", rect); - } - } if let Some((key, on)) = set { let mut params = serde_json::Map::new(); params.insert(key, Value::Bool(on)); @@ -513,6 +511,9 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) { if look { crate::dialogs::look_at_sketch_again(app); } + if finish { + app.finish_sketch(); + } } #[cfg(test)] @@ -590,6 +591,18 @@ mod tests { assert!(h.app.session.active_sketch.is_none()); } + #[test] + fn palette_has_a_finish_sketch_button_that_finishes_the_sketch() { + let mut h = crate::scenario::Harness::new(); + h.app.run("sketch.create", json!({"plane":"XY"})).unwrap(); + h.settle(); + let at = crate::scenario::handle_at("sketch_palette:finish").expect("the palette ends in Finish Sketch"); + assert!(crate::scenario::rect_of("sketch_palette:look_at").is_some(), "Look At | Slice stay"); + assert!(crate::scenario::handle_at("button:sketch.finish").is_some(), "and so does the ribbon's Finish"); + h.call("ui.click", json!({"x":at.x,"y":at.y})); + assert!(h.app.session.active_sketch.is_none()); + } + #[test] fn construction_shortcut_keeps_the_drawing_tool_and_commits_its_line_type() { for command in ["sketch.line", "sketch.rectangle.two_point", "sketch.circle.center"] { diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index 5b728e65b..4f043f044 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -775,6 +775,12 @@ fn ribbon_text(ui: &egui::Ui, at: egui::Pos2, text: &str, size: f32, color: Colo ui.painter().galley(origin, galley, color); } +/// SKETCH while editing a sketch and SHEET METAL while a sheet body is active take the contextual +/// tab style; SHEET METAL is an ordinary tab otherwise. +fn contextual_tab(app: &SolveApp, tab: &str) -> bool { + tab == "SKETCH" || (tab == "SHEET METAL" && crate::workspace::sheet_body(app).is_some()) +} + fn ribbon_tabs(app: &mut SolveApp, ui: &mut egui::Ui, row: Rect) { let t = Tokens::get(); let tabs = crate::workspace::visible_tabs(app); @@ -787,7 +793,7 @@ fn ribbon_tabs(app: &mut SolveApp, ui: &mut egui::Ui, row: Rect) { .collect(); let tabs_width: f32 = widths.iter().sum::() + tabs.len().saturating_sub(1) as f32 * 2.0 - + tabs.iter().filter(|tab| matches!(**tab, "SKETCH" | "SHEET METAL")).count() as f32 * 6.0; + + tabs.iter().filter(|tab| contextual_tab(app, tab)).count() as f32 * 6.0; let search_width = crate::ui_kit::CommandSearch::closed_width(ui.ctx()); // The first tab and the search field sit the same distance from the card's top, left and right // edges, so their outer corners are concentric with the card's corners. @@ -817,7 +823,7 @@ fn ribbon_tabs(app: &mut SolveApp, ui: &mut egui::Ui, row: Rect) { let (all, _) = ui.allocate_exact_size(vec2(tabs_width, TAB_ROW_HEIGHT), Sense::hover()); let mut x = all.left(); for (tab, width) in tabs.into_iter().zip(widths) { - let contextual = matches!(tab, "SKETCH" | "SHEET METAL"); + let contextual = contextual_tab(app, tab); if contextual { x += 6.0; } diff --git a/crates/ui-egui/src/ui_kit/actions.rs b/crates/ui-egui/src/ui_kit/actions.rs index 2d79c0d44..444fe9704 100644 --- a/crates/ui-egui/src/ui_kit/actions.rs +++ b/crates/ui-egui/src/ui_kit/actions.rs @@ -279,6 +279,17 @@ pub(crate) fn primary_button(ui: &mut Ui, label: &str) -> Response { response } +/// Accent action across the full width of its container, for the bottom of a panel. Tokens: +/// `form_primary, on_accent, form_button_height, font_label`. +pub(crate) fn wide_primary_button(ui: &mut Ui, label: &str) -> Response { + let t = Tokens::get(); + let text = RichText::new(crate::i18n::tr_label(label)).size(t.font_label).color(t.on_accent); + let size = vec2(ui.available_width(), t.form_button_height); + let response = ui.add(egui::Button::new(crate::fonts::RichTextExt::bold_face(text)).fill(t.form_primary).min_size(size)); + pointer_on_hover(ui, &response); + response +} + #[cfg(test)] #[path = "actions_tests.rs"] mod tests; diff --git a/crates/ui-egui/src/ui_kit/gallery.rs b/crates/ui-egui/src/ui_kit/gallery.rs index 0f55ed77f..f002e7dc8 100644 --- a/crates/ui-egui/src/ui_kit/gallery.rs +++ b/crates/ui-egui/src/ui_kit/gallery.rs @@ -609,6 +609,9 @@ const ELEMENTS: &[Element] = &[ primary_button(ui, "Create"); }); }), + element!("wide_primary_button", |ui, _| { + wide_primary_button(ui, "Finish Sketch"); + }), element!("button", "dialog:row:Gallery", Some("dialog:button:Gallery:Add"), |ui, _| { row(ui, "Gallery", |ui| { button(ui, "Add", Button::Normal); diff --git a/crates/ui-egui/src/workspace.rs b/crates/ui-egui/src/workspace.rs index 02c0691d5..5fc377e90 100644 --- a/crates/ui-egui/src/workspace.rs +++ b/crates/ui-egui/src/workspace.rs @@ -60,6 +60,11 @@ pub struct Section { pub ids: &'static [&'static str], } +/// Parameters and Configurations stay on every design tab they were on before the ribbon +/// redesign (MODEL and SHEET METAL), on SKETCH while editing a sketch, and in MANAGE, their +/// canonical home. +const CONFIGURE: &[&str] = &["parameters.change", "config.table", "config.configure"]; + pub const SECTIONS: &[Section] = &[ Section { tab: "MODEL", @@ -80,6 +85,7 @@ pub const SECTIONS: &[Section] = &[ promoted: 3, ids: &["solid.move", "solid.mirror", "solid.pattern.rectangular", "solid.align", "solid.pattern.circular", "solid.pattern.path"], }, + Section { tab: "MODEL", panel: "CONFIGURE", promoted: 2, ids: CONFIGURE }, Section { tab: "MODEL", panel: "CONSTRUCT", promoted: 1, ids: &["construct.plane.offset"] }, Section { tab: "SURFACE", panel: "CREATE", promoted: 4, ids: &["surface.extrude", "surface.revolve", "surface.sweep", "surface.loft"] }, Section { tab: "SURFACE", panel: "EDIT", promoted: 4, ids: &["surface.trim", "surface.untrim", "surface.extend", "surface.stitch"] }, @@ -232,6 +238,8 @@ pub const SECTIONS: &[Section] = &[ "canvas.insert", ], }, + // Sketch dimensions are driven by parameters, so they are one click away while sketching. + Section { tab: "SKETCH", panel: "CONFIGURE", promoted: 2, ids: CONFIGURE }, Section { tab: "SKETCH", panel: "FINISH SKETCH", promoted: 1, ids: &["sketch.finish"] }, Section { tab: "SHEET METAL", @@ -242,6 +250,7 @@ pub const SECTIONS: &[Section] = &[ Section { tab: "SHEET METAL", panel: "FLAT", promoted: 3, ids: &["sheet.unfold", "sheet.refold", "sheet.flat_pattern"] }, Section { tab: "SHEET METAL", panel: "OUTPUT", promoted: 2, ids: &["sheet.export_dxf", "sheet.export_bend_table"] }, Section { tab: "SHEET METAL", panel: "RULES", promoted: 1, ids: &["sheet.manage_rules"] }, + Section { tab: "SHEET METAL", panel: "CONFIGURE", promoted: 2, ids: CONFIGURE }, Section { tab: "RENDER", panel: "SCENE", promoted: 2, ids: &["render.scene"] }, Section { tab: "RENDER", panel: "IMAGE", promoted: 1, ids: &["render.start"] }, ]; @@ -345,6 +354,8 @@ pub fn destination(c: &CommandSpec) -> Option<(&'static str, &'static str)> { let primary = match c.id { "sheet.manage_rules" => Some(("MANAGE", "RULES")), "sheet.convert" => Some(("MODEL", "MODIFY")), + "parameters.change" => Some(("MANAGE", "PARAMETERS")), + "config.table" | "config.configure" => Some(("MANAGE", "CONFIGURATIONS")), _ => None, }; primary @@ -432,9 +443,9 @@ pub fn visible_tabs(app: &crate::SolveApp) -> Vec<&'static str> { if app.session.active_sketch.is_some() { tabs.push("SKETCH"); } - if sheet_body(app).is_some() { - tabs.push("SHEET METAL"); - } + // Always reachable, as before the ribbon redesign: a sheet-metal part starts from an + // ordinary sketch or solid, so the tab cannot wait for a sheet body. + tabs.push("SHEET METAL"); tabs } @@ -625,7 +636,9 @@ mod tests { #[test] fn contextual_tabs_follow_the_active_body_and_allow_other_tabs() { let mut h = crate::scenario::Harness::new(); - assert_eq!(visible_tabs(&h.app), TABS); + let mut fresh = TABS.to_vec(); + fresh.push("SHEET METAL"); + assert_eq!(visible_tabs(&h.app), fresh, "SHEET METAL is reachable before any sheet body exists"); h.app.run("sketch.create", json!({"plane":"XY"})).unwrap(); assert_eq!(h.app.ui.tab, "SKETCH"); h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[40,30]})).unwrap(); @@ -645,15 +658,69 @@ mod tests { h.app.run("solid.box", json!({"body_name":"Solid", "operation":"new", "length":10, "width":10, "height":10})).unwrap(); h.app.run("select.set", json!({"items":[{"type":"body","name":"Solid"}]})).unwrap(); sync_context(&mut h.app); - assert!(!visible_tabs(&h.app).contains(&"SHEET METAL")); + assert!(visible_tabs(&h.app).contains(&"SHEET METAL"), "the tab stays reachable off a sheet body"); + assert!(sheet_body(&h.app).is_none()); h.app.run("select.set", json!({"items":[{"type":"body","name":"Sheet"}]})).unwrap(); sync_context(&mut h.app); assert_eq!(h.app.ui.tab, "SHEET METAL"); } + /// Parameters and Configurations are on the design tabs they were on before the redesign, and a + /// fresh document reaches Sheet Metal (to flange a sketch or convert a solid) by its tab. + #[test] + fn parameters_and_configurations_are_on_model_and_sheet_metal_and_the_sheet_tab_opens_fresh() { + let specs = solidcraft_engine::command_specs(); + for tab in ["MODEL", "SHEET METAL", "SKETCH", "MANAGE"] { + let ids = panel_ids(tab, &specs); + assert!(ids.contains(&"parameters.change"), "{tab}: Parameters"); + assert!(ids.contains(&"config.table"), "{tab}: Configurations"); + } + for tab in ["MODEL", "SHEET METAL", "SKETCH"] { + let (commands, n) = layout(tab, "CONFIGURE", &specs).unwrap(); + assert_eq!(commands.iter().take(n).map(|c| c.id).collect::>(), ["parameters.change", "config.table"]); + } + let mut h = crate::scenario::Harness::new(); + assert!(sheet_body(&h.app).is_none()); + h.step(&json!({"click":{"handle":"tab:SHEET METAL"}})).unwrap(); + h.frames(2); + assert_eq!(h.app.ui.tab, "SHEET METAL"); + let specs = solidcraft_engine::command_specs(); + let (create, _) = layout("SHEET METAL", "CREATE", &specs).unwrap(); + assert!(create.iter().any(|c| c.id == "sheet.convert"), "Convert to Sheet Metal is in the Sheet Metal tab's Create panel"); + for id in ["sheet.flange", "parameters.change", "config.table"] { + assert!(crate::scenario::handle_at(&format!("button:{id}")).is_some(), "{id} is a button on the fresh Sheet Metal tab"); + } + h.step(&json!({"click":{"handle":"button:parameters.change"}})).unwrap(); + assert!(h.app.params.is_some(), "Parameters opens from the Sheet Metal tab"); + assert_eq!(h.app.ui.tab, "SHEET METAL", "and the tab stays"); + h.step(&json!({"click":{"handle":"params:close"}})).unwrap(); + h.app.run("sketch.create", json!({"plane":"XY"})).unwrap(); + h.frames(2); + assert_eq!(h.app.ui.tab, "SKETCH"); + for id in ["parameters.change", "config.table"] { + assert!(crate::scenario::handle_at(&format!("button:{id}")).is_some(), "{id} is a button on the Sketch tab"); + } + h.app.finish_sketch(); + h.step(&json!({"click":{"handle":"tab:MODEL"}})).unwrap(); + h.frames(2); + h.step(&json!({"click":{"handle":"button:config.table"}})).unwrap(); + assert!(matches!( + h.app.dialog.as_ref().map(|d| &d.kind), + Some(crate::dialogs::Kind::Motion(crate::dialogs_motion::Mo::Configurations { .. })) + )); + assert_eq!(h.app.ui.tab, "MODEL", "Configurations opens from the Model tab without leaving it"); + } + + fn panel_ids(tab: &str, specs: &[&CommandSpec]) -> Vec<&'static str> { + SECTIONS.iter().filter(|s| s.tab == tab).flat_map(|s| layout(tab, s.panel, specs).unwrap().0).map(|c| c.id).collect() + } + #[test] fn starts_palette_and_control_use_the_new_destinations() { let mut h = crate::scenario::Harness::new(); + // Parameters is also on MODEL, so a start from there stays put; from SURFACE it goes home. + h.app.ui.tab = "SURFACE".into(); + h.frames(2); for (id, tab) in [("parameters.change", "MANAGE"), ("solid.box", "MODEL"), ("surface.patch", "SURFACE")] { h.step(&json!({"start":id})).unwrap(); assert_eq!(h.app.ui.tab, tab, "{id}"); diff --git a/docs/book/src/guide/sheet-metal.md b/docs/book/src/guide/sheet-metal.md index e0cc1a1d6..6f2ac558d 100644 --- a/docs/book/src/guide/sheet-metal.md +++ b/docs/book/src/guide/sheet-metal.md @@ -1,7 +1,7 @@ # Sheet metal -MODEL → MODIFY offers Convert to Sheet Metal. The contextual SHEET METAL tab appears -when the active body is a sheet, and builds parts from a sheet of constant thickness under a **sheet metal rule** +MODEL → MODIFY offers Convert to Sheet Metal. The SHEET METAL tab is always available (it is highlighted +and selected when the active body is a sheet), and builds parts from a sheet of constant thickness under a **sheet metal rule** (thickness, bend radius, K-factor), set in **Sheet Metal Rules** (`sheet.manage_rules`). - **Flange** (`sheet.flange`): a base flange from a sketch profile, a contour flange from an open diff --git a/docs/book/src/guide/ui-tour.md b/docs/book/src/guide/ui-tour.md index 6c9d705fc..3a425e353 100644 --- a/docs/book/src/guide/ui-tour.md +++ b/docs/book/src/guide/ui-tour.md @@ -8,8 +8,8 @@ unsaved changes). On the right: Report a bug, Help (?), Preferences (which hold the theme) and the window's buttons. - **Toolbar.** The workspace switcher (DESIGN) sits on the left. The tabs (MODEL, SURFACE, - ASSEMBLE, INSERT, INSPECT, MANAGE and VIEW) hold sections of commands. SKETCH appears while - editing a sketch; SHEET METAL appears for the active sheet body. Both select automatically + ASSEMBLE, INSERT, INSPECT, MANAGE, VIEW and SHEET METAL) hold sections of commands. SKETCH appears while + editing a sketch; SHEET METAL is always there and is highlighted for the active sheet body. Both select automatically when entered, and the other tabs remain available. Click a panel's name for all its commands. Drag a command from the dropdown onto a panel's label or empty space to append it; the insertion line shows its destination. Drop onto an existing diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 9cf50862c..b5ef79c2c 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -140,7 +140,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox. | `ui.sketchToScreen` | `points`: `[[x, y]…]` in active-sketch coordinates | their screen points (null when behind the camera) | | `ui.dialogInput` | `index` | what clicking an input's Select chip does: picks go to that input | | `ui.at` | `world: [x,y,z]` \| `sketch: [x,y]` \| `plane: "XY"` \| `axis: "Z"` \| `dimension: "d1"` (its value text) \| `handle: "arrow"` (a manipulator handle, see `scenario::publish_handle`) | the screen point (a scenario step's target; see `crates/ui-egui/src/scenario.rs`) | -| `ui.handles` | `prefix?` | the handles drawn last frame, `[{name, x, y}]`: toolbar buttons and drop-down items `toolbar:` (the button alone: `button:`; a drop-down row: `dropdown:`, highlighted `dropdown_hot:`, its pin `dropdown_pin:`; Customize Toolbar's check boxes `customize:`), ribbon tabs `tab:` (MODEL, SURFACE, ASSEMBLE, INSERT, INSPECT, MANAGE, VIEW; contextual SKETCH and SHEET METAL; workspace RENDER), panel labels `panel::` (also `ribbon:section::
`), document overflow list `tab:overflow`, workspace column `ribbon:workspace`, command-search launcher `ribbon:search`, browser rows `row: