Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Save as Mesh: Add all bodies and Add visible bodies buttons (#7297)

Patrick Steinert0e4c5ae57704
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 0000000000..cab34f02f3
--- /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 8dac69e0ed..3a2cec1213 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 b26ddbcbe4..1c794e2315 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 5599f994df..495a4e5160 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<egui::TextureId>, 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<Sel> {
+ 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));