Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/solidcraft/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ fn services(cc: &eframe::CreationContext<'_>, folder: &DialogFolder) -> Services
let chooser_ctx = cc.egui_ctx.clone();
let open_parent = parent.clone();
let program_parent = parent.clone();
let folder_parent = parent.clone();
let file_parent = parent.clone();
let (open_folder, file_folder, save_folder) = (folder.clone(), folder.clone(), folder.clone());
Services {
Expand Down Expand Up @@ -553,6 +554,10 @@ fn services(cc: &eframe::CreationContext<'_>, folder: &DialogFolder) -> Services
let future = dialog.pick_file();
Box::pin(async move { future.await.map(|p| p.path().to_string_lossy().into_owned()) })
})),
pick_folder: Some(Box::new(move || {
let future = folder_parent.clone().set_title("Choose the network folder").pick_folder();
Box::pin(async move { future.await.map(|p| p.path().to_string_lossy().into_owned()) })
})),
pick_save: Some(Box::new(move |name: &str, exts: &[&str]| {
let dialog = save_folder.start(parent.clone()).set_file_name(name);
let dialog = if exts == [io::DESIGN_EXT, "json"] {
Expand Down
1 change: 1 addition & 0 deletions assets/icons/ui/design/requested_icons.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ mirror false
motion_link false
move false
nav_settings false
network_folder false
new false
normal false
offset false
Expand Down
8 changes: 8 additions & 0 deletions assets/icons/ui/design/svg/model/network_folder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
317 changes: 317 additions & 0 deletions assets/locales/pending/slicer-network-folder.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions attribution/pending/slicer-network-folder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| assets/icons/ui/design/svg/model/network_folder.svg | SolidCraft contributors | original icon master (64 grid) | MIT OR Apache-2.0 |
28 changes: 16 additions & 12 deletions crates/engine/src/cmd/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::schema::new_design::{NewDesignParams, NewDesignResult};
use crate::schema::save::{SaveAsParams, SaveParams, SaveResult};
#[cfg(not(target_arch = "wasm32"))]
use crate::schema::save_mesh::{SaveMeshResult, SlicerDelivery};
use crate::schema::slicers::{SlicerInfo, SlicersParams, SlicersResult};
use crate::schema::slicers::{SlicerEntry, SlicerInfo, SlicersParams, SlicersResult};
use crate::schema::{TypedContract, output_schema_for};
use crate::{EngineError, Result, Session};

Expand Down Expand Up @@ -138,13 +138,13 @@ pub static COMMANDS: &[CommandSpec] = &[
.noundo()
.contract(&SAVE_MESH_CONTRACT)
.output(crate::schema::output_schema_for::<crate::schema::save_mesh::SaveMeshResult>)
.params("path; format?: stl|3mf|3mf-tagged (default from the extension, else stl; 3mf-tagged: docs/formats/3mf-face-tags.md); bodies?: [names] (default: all); ascii?: bool (STL); slicer?: id or name from file.slicers, the program path it lists, or a program the user added under Custom… (send the saved file there, through the same steps as file.send_to_slicer: a slicer that has to be started first is waited for; may be deprecated later in favour of file.send_to_slicer or a Send to App workflow, kept for scripts); single_instance?: bool (default true; see file.send_to_slicer); quality?: standard|fine|finest (STL, OBJ and 3MF: how closely the mesh follows curved faces, a chord tolerance of 2e-4, 5e-5 or 1e-5 of each body's size; default standard); objects?: body|component (3MF only: one object per body, the default, or one object for each placed component with two or more bodies, with those bodies as its parts, so a slicer loads them as one object with parts)"),
.params("path; format?: stl|3mf|3mf-tagged (default from the extension, else stl; 3mf-tagged: docs/formats/3mf-face-tags.md); bodies?: [names] (default: all); ascii?: bool (STL); slicer?: id or name from file.slicers, the program path it lists, a program the user added under Custom…, or a network folder the user added (a copy of the file goes there, under the file's name, numbered rather than replacing one) (send the saved file there, through the same steps as file.send_to_slicer: a slicer that has to be started first is waited for; may be deprecated later in favour of file.send_to_slicer or a Send to App workflow, kept for scripts); single_instance?: bool (default true; see file.send_to_slicer); quality?: standard|fine|finest (STL, OBJ and 3MF: how closely the mesh follows curved faces, a chord tolerance of 2e-4, 5e-5 or 1e-5 of each body's size; default standard); objects?: body|component (3MF only: one object per body, the default, or one object for each placed component with two or more bodies, with those bodies as its parts, so a slicer loads them as one object with parts)"),
CommandSpec::new("file.send_to_slicer", "Send to Slicer", send_to_slicer)
.enabled(starts_programs)
.at("INSERT", "FILES")
.icon("mesh_export")
.noundo()
.params("slicer: id or name from file.slicers, or a program the user added under Custom…; bodies?: [names] (default: the selected bodies); wait?: block|return|no (default block: a slicer that drops a file at a cold start is started alone and the call waits up to 10 s for it to be ready, then sends; return: start it and answer {starting}; no: send now); single_instance?: bool (default true: PrusaSlicer, SuperSlicer and Cura load the file in the window that is open); format?: 3mf|stl|3mf-tagged (default 3mf, in millimetres; STL if that can't be written) → saves the bodies in this user's slicer folder and opens the file in the slicer. The file name stays the same for the same design and bodies, so sending again replaces it (use the slicer's Reload from disk)"),
.params("slicer: id or name from file.slicers: a slicer found on this machine, a program the user added under Custom…, or a network folder the user added (remote:<name>, or its name); bodies?: [names] (default: the selected bodies); wait?: block|return|no (default block: a slicer that drops a file at a cold start is started alone and the call waits up to 10 s for it to be ready, then sends; return: start it and answer {starting}; no: send now); single_instance?: bool (default true: PrusaSlicer, SuperSlicer and Cura load the file in the window that is open); format?: 3mf|stl|3mf-tagged (default 3mf, in millimetres; STL if that can't be written); ascii?: bool (STL; default binary); quality?: standard|fine|finest (how closely the mesh follows curved faces, as file.save_mesh; default standard) → saves the bodies in this user's slicer folder and opens the file in the slicer. The file name stays the same for the same design and bodies, so sending again replaces it (use the slicer's Reload from disk). A network folder starts no program: the file is copied there under the design's name (and the body's, for one body), with (2), (3)… added rather than replacing a file → remote: true, target (its name), sent_to, renamed, or slicer_error; with wait: return the copy goes on in the background and the answer has sending (a ticket) instead"),
CommandSpec::new("file.open_in_easyprint", "Open with EasyPrint", easyprint::open_in_easyprint)
.icon("mesh_export")
.noundo()
Expand All @@ -154,7 +154,7 @@ pub static COMMANDS: &[CommandSpec] = &[
.noundo()
.contract(&SLICERS_CONTRACT)
.output(output_schema_for::<SlicersResult>)
.params("→ the slicers found on this machine: [{id, name, program, icon?}]; pass an id, a name or the program path as file.send_to_slicer's or file.save_mesh's `slicer`"),
.params("→ the network folders the user added, then the slicers found on this machine: [{id, name, program, icon?}] for a slicer, [{id: remote:<name>, name, remote: true, kind: folder, folder}] for a network folder (file.slicers.add_remote); pass an id, a name or the program path as file.send_to_slicer's or file.save_mesh's `slicer`"),
];

fn new_doc(s: &mut Session, p: &Value) -> Result<Value> {
Expand Down Expand Up @@ -1400,8 +1400,9 @@ fn starts_programs(_: &Session) -> std::result::Result<(), String> {
if cfg!(target_arch = "wasm32") { Err("a slicer can't be started from the browser".into()) } else { Ok(()) }
}

/// Save the bodies to this user's slicer folder and start the slicer with the file. The file
/// name stays the same for the same design and bodies, so sending again replaces it.
/// Save the bodies to this user's slicer folder and start the slicer with the file, or copy it to a
/// network folder. The file name stays the same for the same design and bodies, so sending again
/// replaces it.
fn send_to_slicer(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "file.send_to_slicer";
#[cfg(target_arch = "wasm32")]
Expand All @@ -1413,10 +1414,12 @@ fn send_to_slicer(s: &mut Session, p: &Value) -> Result<Value> {
{
let format = match str_(p, "format").map(str::to_ascii_lowercase).as_deref() {
None | Some("3mf") => Format::ThreeMf,
Some("stl") if bool_(p, "ascii").unwrap_or(false) => Format::StlAscii,
Some("stl") => Format::StlBinary,
Some("3mf-tagged") => Format::ThreeMfTagged,
Some(other) => return Err(bad(cmd, format!("unknown mesh format `{other}` (stl, 3mf, 3mf-tagged)"))),
};
let quality = mesh_quality(p, cmd)?;
let spec = str_(p, "slicer").ok_or_else(|| bad(cmd, "give `slicer` (see file.slicers)"))?;
let wait = send::Wait::parse(str_(p, "wait")).ok_or_else(|| bad(cmd, "`wait` is block, return or no"))?;
send::send(
Expand All @@ -1428,7 +1431,7 @@ fn send_to_slicer(s: &mut Session, p: &Value) -> Result<Value> {
bodies: string_list(cmd, p, "bodies")?,
parts: Vec::new(),
format,
quality: Default::default(),
quality,
dest: send::Dest::Folder,
single_instance: bool_(p, "single_instance").unwrap_or(true),
wait,
Expand All @@ -1437,16 +1440,17 @@ fn send_to_slicer(s: &mut Session, p: &Value) -> Result<Value> {
}
}

fn slicers(_: &mut Session, _: &Value) -> Result<Value> {
let slicers = crate::slicers::detect()
.iter()
.map(|d| SlicerInfo {
fn slicers(s: &mut Session, _: &Value) -> Result<Value> {
// The network folders first, as the Send to Slicer list shows them.
let mut slicers: Vec<SlicerEntry> = s.network_folders.iter().map(|t| SlicerEntry::Folder(t.listing())).collect();
slicers.extend(crate::slicers::detect().iter().map(|d| {
SlicerEntry::Slicer(SlicerInfo {
id: d.id.clone(),
name: d.name.clone(),
program: d.command.first().cloned(),
icon: d.icon.as_ref().map(|i| i.path().to_string_lossy().into_owned()),
})
.collect();
}));
serde_json::to_value(SlicersResult { slicers, param_warnings: Vec::new() }).map_err(|e| bad("file.slicers", e.to_string()))
}

Expand Down
12 changes: 6 additions & 6 deletions crates/engine/src/cmd/file_easyprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ pub(super) struct Exported {
pub laid: super::print_face::Laid,
}

/// Export the bodies (the selected ones when none are named), each laid on its print face. A
/// 3MF that can't be written is written as an STL, and `fell_back` says so.
pub(super) fn export_bodies(s: &Session, cmd: &str, named: &[String], format: Format) -> Result<Exported> {
/// Export the bodies (the selected ones when none are named), each laid on its print face and
/// meshed at `quality`. A 3MF that can't be written is written as an STL, and `fell_back` says so.
pub(super) fn export_bodies(s: &Session, cmd: &str, named: &[String], format: Format, quality: solidcraft_io::MeshQuality) -> Result<Exported> {
let mut bodies = named.to_vec();
if bodies.is_empty() {
bodies = s.selection.iter().filter_map(|x| if let crate::Sel::Body { name } = x { Some(name.clone()) } else { None }).collect();
Expand All @@ -37,10 +37,10 @@ pub(super) fn export_bodies(s: &Session, cmd: &str, named: &[String], format: Fo
}
let mut doc = s.doc.painted(&*s.world_state()?);
let laid = super::print_face::lay_on_print_faces(s, &mut doc, &bodies, &[]);
let write = |format| solidcraft_io::export_with_metadata(&doc, &bodies, format, &s.doc.name, &s.doc.metadata);
let write = |format| solidcraft_io::export_with_quality(&doc, &bodies, format, &s.doc.name, &s.doc.metadata, quality);
let mut fell_back = false;
let (bytes, ext) = match (format, write(format)) {
(_, Ok(b)) => (b, if format == Format::StlBinary { "stl" } else { "3mf" }),
(_, Ok(b)) => (b, if matches!(format, Format::StlBinary | Format::StlAscii) { "stl" } else { "3mf" }),
(Format::ThreeMf, Err(_)) => {
fell_back = true;
(write(Format::StlBinary)?, "stl")
Expand All @@ -61,7 +61,7 @@ pub(super) fn open_in_easyprint(s: &mut Session, p: &Value) -> Result<Value> {
if !bool_(p, "consent").unwrap_or(false) {
return Err(bad(cmd, "this uploads the model to Printables' servers: ask the user, then pass `consent: true`"));
}
let Exported { bytes, ext, fell_back, laid, .. } = export_bodies(s, cmd, &string_list(cmd, p, "bodies")?, format)?;
let Exported { bytes, ext, fell_back, laid, .. } = export_bodies(s, cmd, &string_list(cmd, p, "bodies")?, format, Default::default())?;
if bytes.len() > MAX_BYTES {
let mb = bytes.len().div_ceil(1_000_000);
return Err(bad(cmd, format!("the model is {mb} MB and EasyPrint takes {} MB at most: send fewer bodies", MAX_BYTES / 1_000_000)));
Expand Down
105 changes: 105 additions & 0 deletions crates/engine/src/cmd/file_remote.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//! Network folders for Send to Slicer (#2304): add, remove and test the folders a mesh can be
//! sent to (`crate::remote_slicers`). They are the session's (`Session::network_folders`); the
//! desktop app stores them in the user's preferences when these commands succeed and puts them back
//! at the next start. Run without an app (CLI, scripts), a folder lasts as long as the session.

use serde_json::{Value, json};

use super::CommandSpec;
use crate::params::{bad, str_};
use crate::remote_slicers::{self, RemoteTarget};
use crate::schema::file_remote::{AddRemoteParams, RemoteFolderReply, RemoveRemoteParams, RemoveRemoteReply, TestRemoteParams, TestRemoteReply};
use crate::schema::{TypedContract, output_schema_for};
use crate::{Result, Session};

pub static COMMANDS: &[CommandSpec] = &[
CommandSpec::new("file.slicers.add_remote", "Add Network Folder", crate::checked!("file.slicers.add_remote", add_remote))
.icon("network_folder")
.noundo()
.doc_only()
.enabled(reaches_folders)
.contract(&ADD_CONTRACT)
.output(output_schema_for::<RemoteFolderReply>)
.params("name: 1..64 characters (shown in the Send to Slicer list); folder: the folder's whole path, such as a mounted SMB or NFS share that a slicer on another computer reads → {id: remote:<name>, name, kind: folder, folder, replaced}: adds a network folder to Send to Slicer, replacing one of the same name. Nothing is written until a mesh is sent; file.slicers.test checks the folder. The app keeps it in the user's preferences; without an app it lasts as long as the session"),
CommandSpec::new("file.slicers.remove_remote", "Remove Network Folder", crate::checked!("file.slicers.remove_remote", remove_remote))
.icon("delete")
.noundo()
.doc_only()
.enabled(reaches_folders)
.contract(&REMOVE_CONTRACT)
.output(output_schema_for::<RemoveRemoteReply>)
.params("name: a network folder's name or id (file.slicers) → {name, removed: true}; the files sent there stay"),
CommandSpec::new("file.slicers.test", "Test Network Folder", crate::checked!("file.slicers.test", test))
.icon("inspect")
.noundo()
.doc_only()
.enabled(reaches_folders)
.contract(&TEST_CONTRACT)
.output(output_schema_for::<TestRemoteReply>)
.params("name?: a network folder's name or id, or folder?: a folder's whole path (one of the two) → {ok, folder, name?, error?}: writes a small file in the folder and deletes it again, giving up after 30 s; error says what went wrong (not there, no permission, full, no answer)"),
];

const ADD_CONTRACT: TypedContract<AddRemoteParams> = TypedContract::new();
const REMOVE_CONTRACT: TypedContract<RemoveRemoteParams> = TypedContract::new();
const TEST_CONTRACT: TypedContract<TestRemoteParams> = TypedContract::new();

/// The browser build has no folders to write to.
fn reaches_folders(_: &Session) -> std::result::Result<(), String> {
if cfg!(target_arch = "wasm32") { Err("network folders can't be reached from the browser".into()) } else { Ok(()) }
}

/// A folder an agent's commands may use: one in the folders it was allowed (`--allow-path`). The
/// app's own calls have no such limit.
fn allowed(cmd: &str, folder: &str) -> Result<()> {
solidcraft_io::vfs::check(folder).map_err(|e| bad(cmd, e.to_string()))
}

fn add_remote(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "file.slicers.add_remote";
reaches_folders(s).map_err(|e| bad(cmd, e))?;
let name = remote_slicers::check_name(str_(p, "name").unwrap_or_default()).map_err(|e| bad(cmd, e))?;
let folder = remote_slicers::check_folder(str_(p, "folder").unwrap_or_default()).map_err(|e| bad(cmd, e))?;
allowed(cmd, folder)?;
let target = RemoteTarget::folder_target(name, folder);
let replaced = remote_slicers::add(&mut s.network_folders, target.clone()).map_err(|e| bad(cmd, e))?;
Ok(json!({"id": target.id(), "name": target.name, "kind": target.kind(), "folder": target.folder(), "replaced": replaced}))
}

fn remove_remote(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "file.slicers.remove_remote";
reaches_folders(s).map_err(|e| bad(cmd, e))?;
let spec = str_(p, "name").filter(|n| !n.trim().is_empty()).ok_or_else(|| bad(cmd, "give `name` (see file.slicers)"))?;
let gone =
remote_slicers::remove(&mut s.network_folders, spec).ok_or_else(|| bad(cmd, format!("no network folder `{spec}` (see file.slicers)")))?;
Ok(json!({"name": gone.name, "removed": true}))
}

fn test(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "file.slicers.test";
reaches_folders(s).map_err(|e| bad(cmd, e))?;
let (name, folder) = match (str_(p, "name"), str_(p, "folder")) {
(Some(spec), None) => {
let target = remote_slicers::resolve(&s.network_folders, spec)
.ok_or_else(|| bad(cmd, format!("no network folder `{spec}` (see file.slicers)")))?;
if let Some(folder) = target.on_this_computer() {
allowed(cmd, folder)?;
}
(Some(target.name.clone()), target.folder().to_string())
}
(None, Some(folder)) => {
let folder = remote_slicers::check_folder(folder).map_err(|e| bad(cmd, e))?;
allowed(cmd, folder)?;
(None, folder.to_string())
}
_ => return Err(bad(cmd, "give `name` or `folder`, one of the two")),
};
let mut out = json!({"ok": true, "folder": folder});
if let Some(name) = name {
out["name"] = json!(name);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
if let Err(e) = remote_slicers::probe(&folder) {
out["ok"] = json!(false);
out["error"] = json!(e);
}
Ok(out)
}
Loading
Loading