Save as mesh: one dialog for STL and 3MF, with Send to slicer (#1272)

One docked Save as mesh dialog replaces Export STL / 3MF / 3MF with face tags, with an optional Send to slicer that lists the slicers installed on this machine. Engine: file.save_mesh and file.slicers; the Convert Mesh dialog goes (mesh.convert and the MeshConvert feature stay, so existing designs open). Strings in all catalogs; screenshots in the PR. Checked on main + this branch: cargo check --workspace, the engine slicer/mesh/file tests, the UI catalog and menu tests and scenario s14 (the one local colour-token failure is epaint's TexturesDelta panic, which main shows on this machine too).
This commit is contained in:
froglemonade2 authored and GitHub committed 2026-10-15 03:51:28 -04:00
1 parent 3e13eb6392
commit 0872eb959a
28 files changed
+1483 -100

No files matched your search

@@ -164,6 +164,7 @@ const ALLOWED_LITERALS: &[(&str, usize, &str)] = &[
("canvas.rs", 3, "white rings around manipulator handles"),
("context_menu.rs", 1, "the radial menu's shadow"),
("dialogs_appearance.rs", 1, "a design appearance: the colour is the fact"),
("dialogs_save_mesh.rs", 1, "an installed slicer's own icon, drawn untinted"),
("dialogs_library.rs", 1, "a library appearance's swatch: the colour is the fact"),
("dialogs_assembly.rs", 1, "the interference fill, shaded from its token"),
("dialogs_motion.rs", 1, "a white outline"),
+5 -2
View File
@@ -418,6 +418,7 @@ fn viewport_items(app: &SolveApp) -> Vec<Item> {
v.push(Item::sep());
v.push(act("ui.appearance", "Appearance", "appearance").key("A"));
v.push(act("ui.properties", "Properties", "measure").with(json!({ "bodies": [face] })));
v.push(act("ui.saveMesh", "Save As Mesh", "export").with(json!({ "bodies": [face] })));
v.push(Item::sep());
v.push(act("ui.delete", "Delete", "delete").key("Del"));
v.push(act(if hidden { "ui.show" } else { "ui.hide" }, "Show/Hide", "eye").key("V").with(json!({ "bodies": [face] })));
@@ -437,6 +438,7 @@ fn viewport_items(app: &SolveApp) -> Vec<Item> {
v.push(act(if hidden { "ui.show" } else { "ui.hide" }, "Show/Hide", "eye").key("V").with(json!({ "bodies": [body] })));
v.push(Item::sep());
v.push(act("ui.findBrowser", "Find in Browser", "").with(json!({ "body": body })));
v.push(act("ui.saveMesh", "Save As Mesh", "export").with(json!({ "bodies": [body] })));
v.push(Item::sep());
v.push(act("ui.tangentChain", "Select Tangent Chain", ""));
v.push(cmd(app, "inspect.measure", "Measure"));
@@ -1068,8 +1070,9 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) {
app.start("material.assign");
}
"ui.saveMesh" => {
let name = bodies.first().cloned().unwrap_or_else(|| app.session.doc.name.clone());
app.pick_save_command(&format!("{name}.stl"), &["stl"], "file.save_mesh", json!({"bodies": bodies}));
let items: Vec<Value> = bodies.iter().map(|b| json!({"type": "body", "name": b})).collect();
let _ = app.run("select.set", json!({ "items": items }));
app.start("file.save_mesh");
}
"ui.exportDxf" => {
if let Some(id) = id_of(&p, "sketch") {
+19 -3
View File
@@ -253,6 +253,7 @@ pub enum Kind {
Sheet(crate::dialogs_sheet::Sm),
/// Surface tools and Split Face (`dialogs_surface`).
Surface(crate::dialogs_surface::Surf),
SaveMesh(crate::dialogs_save_mesh::SaveMesh),
/// Plastic features (`dialogs_plastic`).
Plastic(crate::dialogs_plastic::Pl),
/// Appearance (`dialogs_appearance`).
@@ -602,6 +603,7 @@ impl Dialog {
let (kind, inputs) = crate::dialogs_assembly::start(app, id)
.or_else(|| crate::dialogs_sheet::start(app, id))
.or_else(|| crate::dialogs_surface::start(app, id))
.or_else(|| crate::dialogs_save_mesh::start(app, id))
.or_else(|| crate::dialogs_plastic::start(app, id))
.or_else(|| crate::dialogs_appearance::start(app, id))
.or_else(|| crate::dialogs_motion::start(app, id))
@@ -1371,6 +1373,7 @@ fn title(k: &Kind) -> &'static str {
Kind::Assembly(k) => k.title(),
Kind::Sheet(k) => k.title(),
Kind::Surface(k) => k.title(),
Kind::SaveMesh(_) => "SAVE AS MESH",
Kind::Plastic(k) => k.title(),
Kind::Appearance(_) => "APPEARANCE",
Kind::Motion(k) => k.title(),
@@ -1675,7 +1678,7 @@ fn input_rows(d: &mut Dialog, ui: &mut egui::Ui, s: &Session) {
/// Width limits of a docked dialog: shrink-wrapped to its content within these.
use crate::frame::{DIALOG_MAX_W, DIALOG_MIN_W, DIALOG_WIDE_MAX_W};
/// Width of value fields and choice boxes in a dialog.
const FIELD_W: f32 = 124.0;
pub(crate) const FIELD_W: f32 = 124.0;
/// Find the Boundary Fill cells again when the tool bodies changed (keeping the choices of
/// cells that are still there).
@@ -1914,7 +1917,10 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
let horizontal_frame = frame.inner_margin.leftf() + frame.inner_margin.rightf() + 2.0 * frame.stroke.width;
// OK is offered once the inputs make a feature.
let has_ok = !matches!(d.kind, Kind::Sketch | Kind::Params { .. } | Kind::Measure { .. });
let valid = !has_ok || !d.previews() || (built.unwrap_or_else(|| apply_commands(app, &d).is_ok()) && app.preview.error.is_none());
let valid = match &d.kind {
Kind::SaveMesh(_) => crate::dialogs_save_mesh::ready(&d.inputs),
_ => !has_ok || !d.previews() || (built.unwrap_or_else(|| apply_commands(app, &d).is_ok()) && app.preview.error.is_none()),
};
let width = if wide { crate::frame::Width::Wide } else { crate::frame::Width::Normal };
let wkey = egui::Id::new(("sc_dialog_w", wide));
let response = crate::frame::docked_on(
@@ -2670,6 +2676,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
Kind::Sheet(k) => enter |= crate::dialogs_sheet::rows(app, ui, k, &mut d.inputs),
Kind::Surface(k) => enter |= crate::dialogs_surface::rows(ui, k),
Kind::SketchModify(k) => enter |= crate::sketch_modify_ui::rows(ui, k),
Kind::SaveMesh(k) => enter |= crate::dialogs_save_mesh::rows(app, ui, k),
Kind::Plastic(k) => enter |= crate::dialogs_plastic::rows(app, ui, k, &d.inputs),
Kind::Appearance(k) => enter |= crate::dialogs_appearance::rows(app, ui, k, &mut d.inputs),
Kind::Motion(k) => enter |= crate::dialogs_motion::rows(app, ui, k, &mut d.inputs),
@@ -2729,7 +2736,11 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
egui::Spinner::new().size(14.0).paint_at(ui, sr);
sresp.on_hover_text(tr("Updating the preview"));
}
let raw_label = if matches!(d.kind, Kind::ConfirmDelete { .. }) { "Delete" } else { "OK" };
let raw_label = match &d.kind {
Kind::ConfirmDelete { .. } => "Delete",
Kind::SaveMesh(k) => crate::dialogs_save_mesh::button(k),
_ => "OK",
};
let label = tr(raw_label);
let raw_close = if matches!(d.kind, Kind::Params { .. } | Kind::Measure { .. }) { "Close" } else { "Cancel" };
let close = tr(raw_close);
@@ -3171,6 +3182,10 @@ fn sels(d: &Dialog, i: usize) -> &[Sel] {
}
pub(crate) fn run_dialog(app: &mut SolveApp, d: &Dialog) -> Result<(), String> {
// Saving asks for a file name first; `Err("")` is the user backing out of that.
if let Kind::SaveMesh(k) = &d.kind {
return crate::dialogs_save_mesh::run(app, k, &d.inputs);
}
let commands = apply_commands(app, d)?;
if let Some((_, marker)) = d.editing {
// Record the actual pre-edit timeline state in the command's undo snapshot.
@@ -3862,6 +3877,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
Kind::Sheet(k) => return crate::dialogs_sheet::commands(app, k, &d.inputs, &d.extra),
Kind::Surface(k) => return crate::dialogs_surface::commands(app, k, &d.inputs, &d.extra),
Kind::SketchModify(k) => return crate::sketch_modify_ui::commands(app, k, &d.inputs, &d.extra),
Kind::SaveMesh(k) => return crate::dialogs_save_mesh::commands(k, &d.inputs),
Kind::Plastic(k) => return crate::dialogs_plastic::commands(app, k, &d.inputs, &d.extra),
Kind::Appearance(k) => return Ok(crate::dialogs_appearance::commands(k, &d.inputs)),
Kind::Motion(k) => return crate::dialogs_motion::commands(app, k, &d.inputs),
+347
View File
@@ -0,0 +1,347 @@
//! The Save as mesh dialog (`file.save_mesh`): which bodies, the mesh format, and optionally a
//! slicer to open the saved file in.
//!
//! Every place that saves a mesh opens this dialog: File › Save as mesh, the Mesh tab, and the
//! Save As Mesh item of the body menus. The slicer list holds the programs the user added (kept
//! between runs, newest first), then the slicers found on this machine, then "Custom…", which asks
//! for a program and adds it at the top; "Custom…" itself is never the selection. Pressing Delete
//! over a program the user added removes it.
use std::collections::HashMap;
use egui::{Color32, Sense, vec2};
use serde_json::{Value, json};
use solidcraft_engine::Sel;
use solidcraft_engine::slicers::{self, Slicer};
use crate::SolveApp;
use crate::dialogs::{Kind, combo, row_label};
use crate::selection::{BODIES, SelInput};
use crate::theme::Tokens;
/// The formats, as shown and as `file.save_mesh` names them.
/// (label, `format` parameter, file extension).
const FORMATS: [(&str, &str, &str); 3] = [("STL", "stl", "stl"), ("3MF", "3mf", "3mf"), ("3MF with face tags", "3mf-tagged", "3mf")];
/// Edge of a slicer's icon in the list.
const ICON: f32 = 16.0;
/// Most programs the user can keep in the list.
const MAX_CUSTOM: usize = 24;
/// The dialog's values.
#[derive(Clone, Debug, PartialEq)]
pub struct SaveMesh {
format: usize,
send: bool,
/// The chosen slicer: an installed one's id, or the path of one the user added.
slicer: String,
/// The slicer list has not been read for this opening yet.
stale: bool,
}
/// One line of the slicer list.
struct Entry {
key: String,
slicer: Slicer,
/// Added by the user (can be deleted).
user: bool,
}
/// The slicers known to the dialog, and their icons.
#[derive(Default)]
pub struct SlicerMenu {
detected: Vec<Slicer>,
custom: Vec<(String, Slicer)>,
icons: HashMap<String, Option<egui::TextureHandle>>,
/// A program chosen in the Custom… file dialog, waiting for the open dialog to take it.
picked: Option<String>,
}
impl SlicerMenu {
/// Look at the machine and at the saved programs again.
pub fn refresh(&mut self, custom_paths: &[String]) {
self.detected = slicers::detect();
self.set_custom(custom_paths);
}
fn set_custom(&mut self, paths: &[String]) {
// A program that has been uninstalled drops out of the list (it stays in the settings).
self.custom = paths.iter().filter_map(|p| slicers::custom(p).map(|s| (p.clone(), s))).collect();
}
fn entries(&self) -> Vec<Entry> {
let user = self.custom.iter().map(|(path, s)| Entry { key: path.clone(), slicer: s.clone(), user: true });
let found = self.detected.iter().map(|s| Entry { key: s.id.clone(), slicer: s.clone(), user: false });
user.chain(found).collect()
}
}
/// The dialog for `file.save_mesh`, with the choices of last time.
pub fn start(app: &SolveApp, id: &str) -> Option<(Kind, Vec<SelInput>)> {
if id != "file.save_mesh" {
return None;
}
let p = &app.preferences;
let format = FORMATS.iter().position(|f| f.1 == p.save_mesh_format).unwrap_or(0);
let kind = Kind::SaveMesh(SaveMesh { format, send: p.save_mesh_send, slicer: p.save_mesh_slicer.clone(), stale: true });
Some((kind, vec![SelInput::new("Bodies", BODIES, true)]))
}
/// A popup with the slicer list is open (Delete belongs to it, not to the design's selection).
pub fn popup_open(ctx: &egui::Context) -> bool {
let frame = ctx.cumulative_frame_nr();
let at = ctx.data(|d| d.get_temp::<u64>(egui::Id::new("sc_slicer_popup")));
at.is_some_and(|n| n + 1 >= frame)
}
/// The icon of an entry as a texture (`None`: no icon could be read).
fn icon(menu: &mut SlicerMenu, ctx: &egui::Context, e: &Entry) -> Option<egui::TextureId> {
let tex = menu.icons.entry(e.key.clone()).or_insert_with(|| {
let bytes = e.slicer.icon.as_ref()?.load()?;
let img = decode(&bytes)?;
Some(ctx.load_texture(format!("slicer-icon-{}", e.key), img, egui::TextureOptions::LINEAR))
});
tex.as_ref().map(egui::TextureHandle::id)
}
/// An icon file (PNG or ICO) as a small square image.
fn decode(bytes: &[u8]) -> Option<egui::ColorImage> {
const SIDE: u32 = 48;
let reader = image::ImageReader::new(std::io::Cursor::new(bytes)).with_guessed_format().ok()?;
let (w, h) = reader.into_dimensions().ok()?;
if w == 0 || h == 0 || w > 4096 || h > 4096 {
return None;
}
let img = image::load_from_memory(bytes).ok()?;
let small = image::imageops::resize(&img.to_rgba8(), SIDE, SIDE, image::imageops::FilterType::Lanczos3);
Some(egui::ColorImage::from_rgba_unmultiplied([SIDE as usize, SIDE as usize], small.as_raw()))
}
/// An icon, or the first letter of the name on a tile when there is none.
fn paint_icon(ui: &egui::Ui, rect: egui::Rect, tex: Option<egui::TextureId>, name: &str) {
match tex {
Some(id) => {
ui.painter().image(id, rect, egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0)), Color32::WHITE);
}
None => {
let t = Tokens::get();
ui.painter().rect_filled(rect, 3.0, t.chip);
let letter = name.chars().next().map(|c| c.to_uppercase().to_string()).unwrap_or_default();
ui.painter().text(rect.center(), egui::Align2::CENTER_CENTER, letter, egui::FontId::proportional(11.0), t.text);
}
}
}
/// 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 {
if k.stale {
// Look at the machine once per opening, then settle on a slicer that exists.
k.stale = false;
app.slicer_menu.picked = None;
app.slicer_menu.refresh(&app.preferences.custom_slicers);
let entries = app.slicer_menu.entries();
if !entries.iter().any(|e| e.key == k.slicer) {
k.slicer = entries.first().map(|e| e.key.clone()).unwrap_or_default();
}
k.send &= !entries.is_empty();
}
row_label(ui, "Format");
combo(ui, "sm_format", &FORMATS.map(|f| f.0), &mut k.format);
ui.end_row();
// A browser has no installed programs to send a file to.
if app.services.pick_program.is_none() {
k.send = false;
return false;
}
row_label(ui, "Send to slicer");
ui.checkbox(&mut k.send, "");
ui.end_row();
row_label(ui, "Slicer");
if let Some(path) = app.slicer_menu.picked.take() {
match add_custom(app, &path) {
Ok(()) => k.slicer = path,
Err(e) => app.set_status(e, true),
}
}
let choosing = app.file_picker_busy();
ui.add_enabled_ui(k.send && !choosing, |ui| slicer_combo(app, ui, k));
ui.end_row();
false
}
fn slicer_combo(app: &mut SolveApp, ui: &mut egui::Ui, k: &mut SaveMesh) {
let entries = app.slicer_menu.entries();
let ctx = ui.ctx().clone();
let current = entries.iter().find(|e| e.key == k.slicer);
let pad = "\u{2003}\u{2003}";
let text = current.map_or_else(|| crate::i18n::tr_label("No slicer found").to_string(), |e| format!("{pad}{}", e.slicer.name));
let mut pick_custom = false;
let mut delete: Option<String> = None;
let mut chosen: Option<String> = None;
let r = egui::ComboBox::from_id_salt("sm_slicer").selected_text(text).width(crate::dialogs::FIELD_W).show_ui(ui, |ui| {
let frame = ctx.cumulative_frame_nr();
ctx.data_mut(|d| d.insert_temp(egui::Id::new("sc_slicer_popup"), frame));
for e in &entries {
let tex = icon(&mut app.slicer_menu, &ctx, e);
let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 22.0), Sense::click());
let selected = e.key == k.slicer;
if resp.hovered() || selected {
let v = ui.visuals();
let fill = if resp.hovered() { v.widgets.hovered.bg_fill } else { v.selection.bg_fill.gamma_multiply(0.5) };
ui.painter().rect_filled(rect, 2.0, fill);
}
paint_icon(ui, egui::Rect::from_min_size(rect.left_center() + vec2(3.0, -ICON / 2.0), vec2(ICON, ICON)), tex, &e.slicer.name);
ui.painter().text(
rect.left_center() + vec2(ICON + 9.0, 0.0),
egui::Align2::LEFT_CENTER,
&e.slicer.name,
egui::FontId::proportional(13.0),
ui.visuals().text_color(),
);
crate::scenario::publish_handle(&format!("dialog:Slicer:{}", e.slicer.name), rect.center());
if e.user {
let hint = crate::i18n::format("ui.slicer_delete_tip", &[("program", e.slicer.command.first().map_or("", String::as_str))]);
resp.clone().on_hover_text(hint);
if resp.hovered() && ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Delete)) {
delete = Some(e.key.clone());
}
}
if resp.clicked() {
chosen = Some(e.key.clone());
ui.close();
}
}
if !entries.is_empty() {
ui.separator();
}
let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 22.0), Sense::click());
if resp.hovered() {
ui.painter().rect_filled(rect, 2.0, ui.visuals().widgets.hovered.bg_fill);
}
ui.painter().text(
rect.left_center() + vec2(ICON + 9.0, 0.0),
egui::Align2::LEFT_CENTER,
crate::i18n::tr_label("Custom…"),
egui::FontId::proportional(13.0),
Tokens::get().text,
);
crate::scenario::publish_handle("dialog:Slicer:Custom", rect.center());
if resp.on_hover_text(crate::i18n::tr("ui.custom_program_tip")).clicked() {
pick_custom = true;
ui.close();
}
});
if let Some(e) = current {
let tex = icon(&mut app.slicer_menu, &ctx, e);
let rect = r.response.rect;
let at = egui::Rect::from_min_size(rect.left_center() + vec2(ui.spacing().button_padding.x + 1.0, -ICON / 2.0), vec2(ICON, ICON));
paint_icon(ui, at, tex, &e.slicer.name);
}
if let Some(key) = chosen {
k.slicer = key;
}
if let Some(key) = delete {
app.preferences.custom_slicers.retain(|p| *p != key);
app.slicer_menu.set_custom(&app.preferences.custom_slicers);
if k.slicer == key {
k.slicer = app.slicer_menu.entries().first().map(|e| e.key.clone()).unwrap_or_default();
}
}
if pick_custom {
// Closing the file dialog without a program leaves the choice as it was.
app.pick_program(|app, path| app.slicer_menu.picked = path);
}
}
/// Put a program the user picked at the top of the list (and keep it).
fn add_custom(app: &mut SolveApp, path: &str) -> Result<(), String> {
if slicers::custom(path).is_none() {
return Err(crate::i18n::format("ui.not_a_program", &[("path", path)]));
}
let list = &mut app.preferences.custom_slicers;
list.retain(|p| p != path);
list.insert(0, path.to_string());
list.truncate(MAX_CUSTOM);
app.slicer_menu.set_custom(&app.preferences.custom_slicers);
Ok(())
}
fn bodies(inputs: &[SelInput]) -> Vec<String> {
inputs
.first()
.map(|i| i.items.iter().filter_map(|s| if let Sel::Body { name } = s { Some(name.clone()) } else { None }).collect())
.unwrap_or_default()
}
/// What the Save (or Send) button asks `file.save_mesh` to do, without the file name.
pub fn commands(k: &SaveMesh, inputs: &[SelInput]) -> Result<Vec<(String, Value)>, String> {
let format = FORMATS.get(k.format).map_or("stl", |f| f.1);
let mut p = json!({ "format": format });
let names = bodies(inputs);
if names.is_empty() {
return Err(crate::i18n::tr("ui.save_mesh_pick_bodies").into());
}
p["bodies"] = json!(names);
if k.send {
if k.slicer.is_empty() {
return Err(crate::i18n::tr("ui.save_mesh_no_slicer").into());
}
p["slicer"] = json!(k.slicer);
}
Ok(vec![("file.save_mesh".into(), p)])
}
/// Save and Send need at least one body.
pub fn ready(inputs: &[SelInput]) -> bool {
!bodies(inputs).is_empty()
}
/// The button's label: Save, or Send when the file goes to a slicer.
pub fn button(k: &SaveMesh) -> &'static str {
if k.send { "Send" } else { "Save" }
}
/// Save: ask for a file name and write the file. Send: write it to a temporary file and start the
/// slicer with it, with no file dialog.
pub fn run(app: &mut SolveApp, k: &SaveMesh, inputs: &[SelInput]) -> Result<(), String> {
let (_, params) = commands(k, inputs)?.into_iter().next().ok_or("nothing to save")?;
let (format, ext) = FORMATS.get(k.format).map_or(("stl", "stl"), |f| (f.1, f.2));
let name = bodies(inputs).first().cloned().unwrap_or_else(|| app.session.doc.name.clone());
let p = &mut app.preferences;
p.save_mesh_format = format.into();
p.save_mesh_send = k.send;
if !k.slicer.is_empty() {
p.save_mesh_slicer = k.slicer.clone();
}
if k.send {
let dir = std::env::temp_dir().join("solidcraft-slicer");
std::fs::create_dir_all(&dir)
.map_err(|e| crate::i18n::format("ui.save_mesh_temp_failed", &[("folder", &dir.display().to_string()), ("error", &e.to_string())]))?;
let file: String = name.chars().map(|c| if c.is_alphanumeric() || "-_. ".contains(c) { c } else { '_' }).collect();
save(app, params, &dir.join(format!("{file}.{ext}")).to_string_lossy());
} else {
// The file dialog answers later; the dialog closes meanwhile, as for every export.
app.pick_save(&format!("{name}.{ext}"), &[ext], move |app, path| {
if let Some(path) = path {
save(app, params, &path);
}
});
}
Ok(())
}
/// Run `file.save_mesh` into `path` and report what happened.
fn save(app: &mut SolveApp, mut params: Value, path: &str) {
// Runs from the file picker's answer, outside the frame's language scope.
let _language = crate::i18n::scope(&app.preferences.language);
params["path"] = json!(path);
let Ok(result) = app.run("file.save_mesh", params) else { return };
match result.get("slicer_error").and_then(Value::as_str) {
Some(e) => app.set_status(e.to_string(), true),
None => match result.get("slicer").and_then(Value::as_str) {
Some(s) => app.set_status(crate::i18n::format("ui.sent_to_slicer", &[("slicer", s)]), false),
None => app.set_status(crate::i18n::format("ui.saved_to", &[("path", path)]), false),
},
}
}
+1 -15
View File
@@ -45,9 +45,6 @@ pub enum Surf {
Stitch {
tolerance: String,
},
ConvertMesh {
tolerance: String,
},
Thicken {
thickness: String,
symmetric: bool,
@@ -79,7 +76,6 @@ impl Surf {
Surf::Offset { .. } => "OFFSET SURFACE",
Surf::Ruled { .. } => "RULED SURFACE",
Surf::Stitch { .. } => "STITCH",
Surf::ConvertMesh { .. } => "CONVERT MESH",
Surf::Thicken { .. } => "THICKEN",
Surf::Extend { .. } => "EXTEND",
Surf::Trim => "TRIM",
@@ -124,7 +120,6 @@ fn inputs(k: &Surf) -> Vec<SelInput> {
vec![SelInput::new("Edges", EDGES, true), SelInput::new("Reference face", FACES, false), SelInput::new("Direction", AXES | EDGES, false)]
}
Surf::Stitch { .. } => vec![SelInput::new("Surfaces", BODIES, true)],
Surf::ConvertMesh { .. } => vec![SelInput::new("Mesh body", BODIES, false)],
Surf::Thicken { .. } => vec![SelInput::new("Surfaces", BODIES, true)],
Surf::Extend { .. } => vec![SelInput::new("Edges", EDGES, true)],
Surf::Trim => vec![
@@ -150,7 +145,6 @@ pub fn start(_app: &SolveApp, id: &str) -> Option<(Kind, Vec<SelInput>)> {
"surface.offset" => Surf::Offset { distance: "2 mm".into(), chain: false },
"surface.ruled" => Surf::Ruled { distance: "10 mm".into(), mode: 0, angle: "5 deg".into(), flip: false, round: false },
"surface.stitch" => Surf::Stitch { tolerance: String::new() },
"mesh.convert" => Surf::ConvertMesh { tolerance: "0.05 mm".into() },
"surface.thicken" => Surf::Thicken { thickness: "2 mm".into(), symmetric: false, operation: 0 },
"surface.extend" => Surf::Extend { distance: "10 mm".into() },
"surface.trim" => Surf::Trim,
@@ -166,7 +160,7 @@ pub fn start(_app: &SolveApp, id: &str) -> Option<(Kind, Vec<SelInput>)> {
pub fn rows(ui: &mut egui::Ui, k: &mut Surf) -> bool {
let mut enter = false;
match k {
Surf::Stitch { tolerance } | Surf::ConvertMesh { tolerance } => {
Surf::Stitch { tolerance } => {
row_label(ui, "Tolerance");
let r = ui.add(egui::TextEdit::singleline(tolerance).hint_text("tight"));
crate::params_dialog::complete(ui, &r, tolerance);
@@ -469,11 +463,6 @@ pub fn commands(app: &SolveApp, k: &Surf, inputs: &[SelInput], extra: &Map<Strin
}
("surface.stitch", p)
}
Surf::ConvertMesh { tolerance } => {
need(0, "a closed mesh body")?;
let body = bodies(inputs, 0).into_iter().next().ok_or("select a mesh body")?;
("mesh.convert", json!({"body":body,"tolerance":tolerance}))
}
Surf::Thicken { thickness, symmetric, operation } => {
need(0, "the surfaces to thicken")?;
(
@@ -661,9 +650,6 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind, frame: &Mat) -> Option<(K
Surf::Stitch { tolerance: if tolerance.trim() == "0" { String::new() } else { tolerance.clone() } },
vec![bodies.iter().map(|n| Sel::Body { name: n.clone() }).collect()],
),
FeatureKind::MeshConvert { body, tolerance } => {
(Surf::ConvertMesh { tolerance: tolerance.clone() }, vec![vec![Sel::Body { name: body.clone() }]])
}
FeatureKind::Thicken { bodies, thickness, symmetric, operation, .. } => (
Surf::Thicken { thickness: thickness.clone(), symmetric: *symmetric, operation: op_index(operation) },
vec![bodies.iter().map(|n| Sel::Body { name: n.clone() }).collect()],
+9
View File
@@ -49,6 +49,15 @@ impl SolveApp {
self.begin_picker(future, Box::new(complete));
}
/// Ask for a program (a slicer). Without a host dialog, the answer is a cancel.
pub(crate) fn pick_program(&mut self, complete: impl FnOnce(&mut SolveApp, Option<String>) + 'static) {
if self.file_picker_busy() {
return;
}
let future = self.services.pick_program.as_ref().map(|pick| pick());
self.begin_picker(future, Box::new(complete));
}
fn begin_picker(&mut self, future: Option<FilePickerFuture>, complete: Completion) {
let Some(future) = future else {
complete(self, None);
+6
View File
@@ -29,6 +29,7 @@ pub mod dialogs_motion;
pub mod dialogs_move;
pub mod dialogs_parts;
pub mod dialogs_plastic;
pub mod dialogs_save_mesh;
pub mod dialogs_sheet;
pub mod dialogs_surface;
pub mod dim_view;
@@ -228,6 +229,8 @@ impl Default for UiState {
pub struct Services {
pub pick_open: Option<Box<dyn Fn() -> FilePickerFuture>>,
pub pick_save: Option<Box<dyn Fn(&str, &[&str]) -> FilePickerFuture>>,
/// Open a dialog asking for a program (a slicer); `None` when the host has no such dialog.
pub pick_program: Option<Box<dyn Fn() -> FilePickerFuture>>,
pub show_in_folder: Option<Box<dyn Fn(&str)>>,
/// Where the host reads the anti-aliasing preference at start (a small JSON file).
pub graphics_path: Option<String>,
@@ -283,6 +286,8 @@ pub struct SolveApp {
/// Preferences kept between runs, and their window.
pub preferences: prefs::Prefs,
pub prefs_window: prefs::PrefsWindow,
/// The slicers the Save as mesh dialog offers.
pub slicer_menu: dialogs_save_mesh::SlicerMenu,
pub preview: preview::PreviewState,
/// OK pressed on a feature that takes a while: its evaluation runs off the window thread.
pub applying: Option<dialogs::Applying>,
@@ -382,6 +387,7 @@ impl SolveApp {
sketch_choices: sketch_families::Choices::default(),
preferences: prefs::Prefs::default(),
prefs_window: prefs::PrefsWindow::default(),
slicer_menu: dialogs_save_mesh::SlicerMenu::default(),
preview: preview::PreviewState::default(),
applying: None,
apply_off_thread: None,
+10
View File
@@ -295,6 +295,12 @@ pub struct Prefs {
pub check_updates: bool,
/// When the last update check ran, and the versions skipped or put off (`update::Memo`).
pub update: crate::update::Memo,
/// Save as mesh: the last format (`stl` or `3mf`), whether it was sent to a slicer, which one
/// (an installed slicer's id or a program path), and the programs the user added (newest first).
pub save_mesh_format: String,
pub save_mesh_send: bool,
pub save_mesh_slicer: String,
pub custom_slicers: Vec<String>,
}
/// What a middle-button double-click in the view does.
@@ -359,6 +365,10 @@ impl Default for Prefs {
color_vision: crate::theme::ColorVision::Off,
check_updates: true,
update: crate::update::Memo::default(),
save_mesh_format: "stl".into(),
save_mesh_send: false,
save_mesh_slicer: String::new(),
custom_slicers: Vec::new(),
}
}
}
+3 -11
View File
@@ -403,22 +403,14 @@ fn file_menu(app: &mut SolveApp, ctx: &egui::Context) {
close = true;
}
ui.separator();
if item_if(ui, "Export STL…", "", shown) {
export(app, "stl");
if item_if(ui, "Save as mesh…", "", shown) {
app.start("file.save_mesh");
close = true;
}
if item_if(ui, "Export STEP…", "", shown) {
export(app, "step");
close = true;
}
if item_if(ui, "Export 3MF…", "", shown) {
export(app, "3mf");
close = true;
}
if item_if(ui, "Export 3MF with Face Tags…", "", shown) {
export_as(app, "3mf", Some("3mf-tagged"));
close = true;
}
if item_if(ui, "Export OBJ…", "", shown) {
export(app, "obj");
close = true;
@@ -1172,7 +1164,7 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) {
}
// A dimension value that is taking the keyboard: letters belong to it (a parameter name
// starting with L or D), even on the frame before its field holds the focus.
if ctx.egui_wants_keyboard_input() || crate::dim_view::editing() {
if ctx.egui_wants_keyboard_input() || crate::dim_view::editing() || crate::dialogs_save_mesh::popup_open(ctx) {
return;
}
let (keys, mods) = ctx.input(|i| {