From 0e4c5ae57704fac709116a9ee390cc8e1b3c51f6 Mon Sep 17 00:00:00 2001 From: Patrick Steinert Date: Tue, 27 Oct 2026 20:08:27 +0000 Subject: [PATCH] Save as Mesh: Add all bodies and Add visible bodies buttons (#7297) * Save as Mesh: Add all bodies and Add visible bodies buttons Two buttons under the Bodies input fill it with every body of the design, or with only the bodies the viewport shows. Co-Authored-By: Claude Opus 5.5 (1M context) * Save as Mesh: translate the two body buttons for every complete catalog ar, he, ja, vi and zh are complete catalogs, so every English message needs an entry there; ko as the ui-text skill asks. Co-Authored-By: Claude Opus 5.5 (1M context) --------- Co-authored-by: Claude Opus 5.5 (1M context) --- .../locales/pending/save-mesh-add-bodies.json | 10 +++++++++ crates/ui-egui/src/browser_card_tests.rs | 21 +++++++++++++++++++ crates/ui-egui/src/dialogs_dense.rs | 2 +- crates/ui-egui/src/dialogs_save_mesh.rs | 20 +++++++++++++++++- 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 assets/locales/pending/save-mesh-add-bodies.json diff --git a/assets/locales/pending/save-mesh-add-bodies.json b/assets/locales/pending/save-mesh-add-bodies.json new file mode 100644 index 000000000..cab34f02f --- /dev/null +++ b/assets/locales/pending/save-mesh-add-bodies.json @@ -0,0 +1,10 @@ +{ + "en": { "Add all bodies": "Add all bodies", "Add visible bodies": "Add visible bodies" }, + "ar": { "Add all bodies": "إضافة كل الأجسام", "Add visible bodies": "إضافة الأجسام المرئية" }, + "de": { "Add all bodies": "Alle Körper hinzufügen", "Add visible bodies": "Sichtbare Körper hinzufügen" }, + "he": { "Add all bodies": "הוספת כל הגופים", "Add visible bodies": "הוספת הגופים הגלויים" }, + "ja": { "Add all bodies": "すべてのボディを追加", "Add visible bodies": "表示中のボディを追加" }, + "ko": { "Add all bodies": "모든 바디 추가", "Add visible bodies": "보이는 바디 추가" }, + "vi": { "Add all bodies": "Thêm tất cả thân khối", "Add visible bodies": "Thêm các thân khối đang hiện" }, + "zh": { "Add all bodies": "添加所有实体", "Add visible bodies": "添加可见实体" } +} diff --git a/crates/ui-egui/src/browser_card_tests.rs b/crates/ui-egui/src/browser_card_tests.rs index 8dac69e0e..3a2cec121 100644 --- a/crates/ui-egui/src/browser_card_tests.rs +++ b/crates/ui-egui/src/browser_card_tests.rs @@ -2,6 +2,27 @@ use super::*; use crate::scenario::{Harness, handle_at, rect_of}; use crate::shell::{LayoutMode, SHELL_GAP}; +#[test] +fn save_mesh_add_all_and_add_visible_bodies_fill_the_bodies_input() { + let mut h = Harness::new(); + for (name, x) in [("One", 0), ("Two", 20), ("Three", 40)] { + h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"corner":[x,0,0],"operation":"new_body","body_name":name})).unwrap(); + } + h.app.run("browser.visibility", json!({"items":["Two"],"visible":false})).unwrap(); + h.app.start("file.save_mesh"); + h.settle(); + for (button, expected) in [("Add all bodies", vec!["One", "Two", "Three"]), ("Add visible bodies", vec!["One", "Three"])] { + let handle = crate::scenario::handles("dialog:button:").into_iter().find(|(n, _)| n.ends_with(&format!(":{button}"))); + let (handle, _) = handle.unwrap_or_else(|| panic!("{button} is shown")); + h.step(&json!({"click":{"handle":handle}})).unwrap(); + let d = h.app.dialog.as_ref().unwrap(); + let crate::dialogs::Kind::SaveMesh(k) = &d.kind else { panic!("Save as Mesh is open") }; + let commands = crate::dialogs_save_mesh::commands(k, &d.inputs).unwrap(); + assert_eq!(commands[0].1["bodies"], json!(expected), "{button}"); + assert!(h.app.session.selection.is_empty(), "the buttons do not change the global selection"); + } +} + #[test] fn browser_body_clicks_fill_and_toggle_save_mesh_inputs() { for mode in [LayoutMode::Floating, LayoutMode::Docked] { diff --git a/crates/ui-egui/src/dialogs_dense.rs b/crates/ui-egui/src/dialogs_dense.rs index b26ddbcbe..1c794e231 100644 --- a/crates/ui-egui/src/dialogs_dense.rs +++ b/crates/ui-egui/src/dialogs_dense.rs @@ -197,7 +197,7 @@ pub(super) fn rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui: Kind::Motion(k) => enter |= crate::dialogs_motion::rows(app, ui, k, &mut d.inputs), Kind::Part(k) => enter |= crate::dialogs_parts::rows(app, ui, k, &d.inputs), Kind::PartSize(k) => enter |= crate::dialogs_part_size::rows(app, ui, k), - Kind::SaveMesh(k) => enter |= crate::dialogs_save_mesh::rows(app, ui, k), + Kind::SaveMesh(k) => enter |= crate::dialogs_save_mesh::rows(app, ui, k, &mut d.inputs), Kind::ViewDxf { dashed, tolerance } => crate::dialogs_view_dxf::rows(app, ui, dashed, tolerance), Kind::InsertDrawing(p) => crate::dialogs_insert_drawing::rows(ui, p), Kind::Sketch => { diff --git a/crates/ui-egui/src/dialogs_save_mesh.rs b/crates/ui-egui/src/dialogs_save_mesh.rs index 5599f994d..495a4e516 100644 --- a/crates/ui-egui/src/dialogs_save_mesh.rs +++ b/crates/ui-egui/src/dialogs_save_mesh.rs @@ -21,6 +21,7 @@ use crate::SolveApp; use crate::dialogs::{Kind, form_row}; use crate::selection::{BODIES, SelInput}; use crate::theme::Tokens; +use solidcraft_engine::Sel; /// The formats, as shown and as `file.save_mesh` names them. /// (label, `format` parameter, file extension). @@ -302,8 +303,25 @@ fn paint_icon(ui: &egui::Ui, rect: egui::Rect, tex: Option, nam } } +/// Every body of the design, in model order; with `visible`, only the bodies the viewport shows. +pub(crate) fn body_picks(app: &SolveApp, visible: bool) -> Vec { + let st = app.session.world_state(); + let shown = |name: &str| !visible || app.session.body_visible(name); + st.bodies.iter().filter(|b| shown(&b.name)).map(|b| Sel::Body { name: b.name.clone() }).collect() +} + /// The rows after the Bodies input; true when Enter was pressed in a field. -pub fn rows(app: &mut SolveApp, ui: &mut egui::Ui, k: &mut SaveMesh) -> bool { +pub fn rows(app: &mut SolveApp, ui: &mut egui::Ui, k: &mut SaveMesh, inputs: &mut [SelInput]) -> bool { + // One row each: the two side by side do not fit the dialog's width. + for (label, visible) in [("Add all bodies", false), ("Add visible bodies", true)] { + form_row(ui, "", |ui| { + if crate::ui_kit::button(ui, crate::i18n::tr_label(label), crate::ui_kit::Button::Small).clicked() + && let Some(input) = inputs.first_mut() + { + input.items = body_picks(app, visible); + } + }); + } if !k.open { choice_row(ui, "Format", "sm_format", &mut k.format, &FORMATS.map(|f| f.0)); choice_row(ui, "Quality", "sm_quality", &mut k.quality, &QUALITIES.map(|q| q.0));