File menu: Export STL… and Export 3MF… open the mesh dialog with that format; command search finds mesh export by format (#3873)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//! 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
|
||||
//! Every place that saves a mesh opens this dialog: File › Export STL / Export 3MF, 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
|
||||
@@ -39,6 +39,14 @@ pub struct SaveMesh {
|
||||
stale: bool,
|
||||
}
|
||||
|
||||
impl SaveMesh {
|
||||
/// The chosen format, as `file.save_mesh` names it (`stl`, `3mf`, `3mf-tagged`).
|
||||
#[cfg(test)]
|
||||
pub(crate) fn format_name(&self) -> &'static str {
|
||||
FORMATS.get(self.format).map_or("stl", |f| f.1)
|
||||
}
|
||||
}
|
||||
|
||||
/// One line of the slicer list.
|
||||
struct Entry {
|
||||
key: String,
|
||||
@@ -87,6 +95,17 @@ pub fn start(app: &SolveApp, id: &str) -> Option<(Kind, Vec<SelInput>)> {
|
||||
Some((kind, vec![SelInput::new("Bodies", BODIES, true)]))
|
||||
}
|
||||
|
||||
/// Open the dialog with `format` (`stl`, `3mf` or `3mf-tagged`) chosen, whatever was used last:
|
||||
/// File › Export STL… and Export 3MF…. The user can still change it in the dialog.
|
||||
pub fn start_with_format(app: &mut SolveApp, format: &str) {
|
||||
app.start("file.save_mesh");
|
||||
if let Some(index) = FORMATS.iter().position(|f| f.1 == format)
|
||||
&& let Some(Kind::SaveMesh(k)) = app.dialog.as_mut().map(|d| &mut d.kind)
|
||||
{
|
||||
k.format = index;
|
||||
}
|
||||
}
|
||||
|
||||
/// 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();
|
||||
|
||||
@@ -105,6 +105,24 @@ pub fn score(q: &str, s: &str) -> u32 {
|
||||
300u32.saturating_sub(gaps * 20).max(10)
|
||||
}
|
||||
|
||||
/// Words people look for a command by that its name doesn't hold (file formats, what it is for).
|
||||
fn keywords(id: &str) -> &'static str {
|
||||
match id {
|
||||
"file.save_mesh" => "export stl 3mf mesh 3d print printing slicer",
|
||||
"file.export" => "export stl 3mf obj step urdf mesh 3d print",
|
||||
_ => "",
|
||||
}
|
||||
}
|
||||
|
||||
/// How well `q` matches a command's `keywords`: every word of the query starts a keyword.
|
||||
fn keyword_score(q: &str, keywords: &str) -> u32 {
|
||||
if keywords.is_empty() || q.is_empty() {
|
||||
return 0;
|
||||
}
|
||||
let words = || keywords.split_whitespace();
|
||||
if q.split_whitespace().all(|w| words().any(|k| k.starts_with(w))) { 700 } else { 0 }
|
||||
}
|
||||
|
||||
/// A row of the box: the command id, its label, its icon, and where it lives on the toolbar
|
||||
/// (tab, panel; `None` off the toolbar), in the current language.
|
||||
pub type Row = (&'static str, &'static str, &'static str, Option<(&'static str, &'static str)>);
|
||||
@@ -125,6 +143,7 @@ pub fn search(app: &SolveApp, q: &str) -> Vec<Row> {
|
||||
let s = score(&q, label)
|
||||
.max(score(&q, c.label))
|
||||
.max(score(&q, c.id) * 9 / 10)
|
||||
.max(keyword_score(&q, keywords(c.id)))
|
||||
.max(score(&q, tab).max(score(&q, home_tab)) / 3)
|
||||
.max(score(&q, panel).max(score(&q, home_panel)) / 3);
|
||||
let recent = app.sbox.recent.iter().position(|r| r == c.id).map_or(0, |i| 2000u32.saturating_sub(i.min(2000) as u32));
|
||||
|
||||
@@ -555,8 +555,12 @@ fn file_menu(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
close = true;
|
||||
}
|
||||
ui.separator();
|
||||
if item_if(ui, "Save as mesh…", "", "mesh_export", shown) {
|
||||
app.start("file.save_mesh");
|
||||
if item_if(ui, "Export STL…", "", "mesh_export", shown) {
|
||||
crate::dialogs_save_mesh::start_with_format(app, "stl");
|
||||
close = true;
|
||||
}
|
||||
if item_if(ui, "Export 3MF…", "", "mesh_export", shown) {
|
||||
crate::dialogs_save_mesh::start_with_format(app, "3mf");
|
||||
close = true;
|
||||
}
|
||||
if item_if(ui, "Export STEP…", "", "export", shown) {
|
||||
@@ -1893,6 +1897,27 @@ mod header_report_tests {
|
||||
assert!(!solidcraft_engine::io::is_design_container(&std::fs::read(saved).unwrap()), "subsequent Save keeps a .json choice");
|
||||
}
|
||||
|
||||
/// File › Export STL… and Export 3MF… both open the Save as mesh dialog with their format
|
||||
/// chosen (whatever was used last), and command search finds the export by format or purpose.
|
||||
#[test]
|
||||
fn file_menu_has_export_stl_and_3mf_that_open_the_mesh_dialog_with_that_format() {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
h.app.run("solid.box", json!({"length":2,"width":3,"height":4})).unwrap();
|
||||
h.app.preferences.save_mesh_format = "3mf".into();
|
||||
for (item, format) in [("Export STL…", "stl"), ("Export 3MF…", "3mf")] {
|
||||
h.frames(3);
|
||||
h.step(&json!({"click":{"handle":"appbar:file"}})).unwrap();
|
||||
h.step(&json!({"widget": item})).unwrap();
|
||||
let Some(crate::dialogs::Kind::SaveMesh(k)) = h.app.dialog.as_ref().map(|d| &d.kind) else { panic!("{item}: no Save as mesh dialog") };
|
||||
assert_eq!(k.format_name(), format, "{item}");
|
||||
crate::dialogs::cancel(&mut h.app);
|
||||
}
|
||||
for q in ["3mf", "stl", "export 3mf", "print"] {
|
||||
let found = crate::shortcut_box::search(&h.app, q);
|
||||
assert!(found.iter().any(|r| r.0 == "file.save_mesh"), "{q}: {:?}", found.iter().map(|r| r.0).collect::<Vec<_>>());
|
||||
}
|
||||
}
|
||||
|
||||
/// The browser build's File > Download design hands the open design to the host as a
|
||||
/// `.solidcraft` container named after it; a host that saves real files shows no such item.
|
||||
#[test]
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
"click": {"handle": "appbar:file"}
|
||||
},
|
||||
{
|
||||
"widget": "Save as mesh\u2026"
|
||||
"widget": "Export STL\u2026"
|
||||
},
|
||||
{
|
||||
"expect": {
|
||||
|
||||
@@ -38,8 +38,9 @@ A 3MF project saved by a slicer comes in too, also when it keeps its objects in
|
||||
their own inside the file (the 3MF Production extension): each object on the build plate becomes
|
||||
a mesh body, with its parts where the slicer placed them.
|
||||
|
||||
**File → Save as mesh…** (also on the Mesh tab under Modify, and in the right-click menu of a
|
||||
body) saves the selected bodies as STL, 3MF or 3MF with face tags (below). With **Send to slicer** ticked, it writes the file to
|
||||
**File → Export STL…** and **File → Export 3MF…** (also on the Mesh tab under Modify as Save as
|
||||
mesh, and in the right-click menu of a body) open the same dialog with that format chosen; it saves
|
||||
the selected bodies as STL, 3MF or 3MF with face tags (below), and you can change the format there. With **Send to slicer** ticked, it writes the file to
|
||||
a temporary folder and opens it in the chosen slicer instead of asking for a file name. The slicer
|
||||
list shows the slicers found on the computer with their icons; **Custom…** adds any other program
|
||||
to the top of the list (kept between runs; hover an entry you added and press Delete to remove it).
|
||||
@@ -47,7 +48,7 @@ to the top of the list (kept between runs; hover an entry you added and press De
|
||||
Closed mechanical meshes with a constant cross-section can be rebuilt as solids with the
|
||||
`mesh.convert` command (command palette, scripts and the control channel).
|
||||
|
||||
**File → Save as mesh…** with the format **3MF with face tags** (`file.export` or `file.save_mesh` with `format: "3mf-tagged"`) writes an
|
||||
**File → Export 3MF…** with the format changed to **3MF with face tags** (`file.export` or `file.save_mesh` with `format: "3mf-tagged"`) writes an
|
||||
ordinary 3MF in which every triangle also names the B-rep face it lies on and every coordinate
|
||||
is the tessellation's own double-precision value. Meshing and analysis tools can use the tags to
|
||||
keep a model's faces (for loads, boundary conditions or feature edges); other 3MF readers ignore
|
||||
|
||||
@@ -7,7 +7,7 @@ A tessellated body loses its faces: a plain mesh says where the surface is, not
|
||||
each triangle came from. Downstream tools that mesh or analyse a part need that back. They apply
|
||||
loads and boundary conditions to faces, keep face boundaries as feature edges, and group
|
||||
results by face. SolidCraft therefore exports a 3MF in which every triangle carries the index of
|
||||
the B-rep face it lies on (**File → Save as mesh…** (format **3MF with face tags**), or `file.export` with
|
||||
the B-rep face it lies on (**File → Export 3MF…**, then the format **3MF with face tags**, or `file.export` with
|
||||
`format: "3mf-tagged"`).
|
||||
|
||||
## Why 3MF
|
||||
|
||||
Reference in New Issue
Block a user