Imports through the app keep their matrix, name and options (#4676) (#4746)

The app's background loader (file_load::control) kept only `up` and
`names` of a control-channel open or import, so file.insert_step's
`matrix` and `name` were dropped and the part landed at the origin, and
file.insert_mesh lost all its options. It keeps every parameter but the
path, as given; each command checks them as it does when run directly.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dudedagger42
2026-10-23 13:44:40 +00:00
committed by GitHub
parent 84cad43154
commit 89a11d75c0
2 changed files with 43 additions and 8 deletions
+10 -8
View File
@@ -43,8 +43,8 @@ pub struct Request {
pub reply: Option<Sender<ControlResponse>>,
/// The folders that caller's agent may use: the worker reads the file inside them.
pub scope: Option<solidcraft_engine::io::vfs::PathScope>,
/// What that caller asked of a STEP import besides its path (`up`, `names`): the command
/// gets them as given.
/// What that caller asked of an open or import besides its path (`up`, `names`, `matrix`,
/// `name`, ...): the command gets them as given and checks them as it does run directly.
pub options: serde_json::Map<String, Value>,
}
@@ -64,7 +64,7 @@ impl Request {
fn command(&self) -> (&'static str, Value) {
match &self.kind {
Kind::Open => ("doc.open", self.params()),
Kind::Insert if solidcraft_engine::io::is_mesh_path(&self.path) => ("file.insert_mesh", json!({"path": self.path})),
Kind::Insert if solidcraft_engine::io::is_mesh_path(&self.path) => ("file.insert_mesh", self.params()),
Kind::Insert => ("file.insert_step", self.params()),
Kind::Recover { id, dir } => ("doc.recover", json!({"id": id, "dir": dir})),
Kind::ExportDxf => ("file.export_view_dxf", Value::Object(self.options.clone())),
@@ -277,11 +277,13 @@ pub fn control(app: &mut SolveApp, req: crate::control::ControlRequest) -> Optio
return None;
}
};
let options = if kind == Kind::ExportDxf {
params.and_then(Value::as_object).cloned().unwrap_or_default()
} else {
["up", "names"].iter().filter_map(|k| Some((k.to_string(), params?.get(*k).filter(|v| !v.is_null())?.clone()))).collect()
};
// Everything but the path, as given: taking only `up` and `names` dropped an import's
// `matrix` and `name`, so it landed at the origin with nothing said (#4676).
let mut options = params.and_then(Value::as_object).cloned().unwrap_or_default();
if kind != Kind::ExportDxf {
options.remove("path");
options.retain(|_, v| !v.is_null());
}
let _ = begin_request(app, Request { path: path.into(), kind, reply: Some(req.reply.clone()), scope, options });
None
}
+33
View File
@@ -274,6 +274,39 @@ fn a_control_import_passes_up_and_names_on() {
let _ = std::fs::remove_dir_all(&dir);
}
/// #4676: a control-channel import's `matrix` and `name` reach the command, as they do when it
/// runs in a session: the part lands where the matrix puts it, under the name given.
#[test]
fn a_control_import_passes_its_matrix_and_name_on() {
let dir = scratch("import-matrix");
let path = dir.join("plate.step").to_string_lossy().to_string();
let mut src = Session::default();
src.execute("solid.box", &json!({"length": 60, "width": 40, "height": 5})).unwrap();
src.execute("file.export", &json!({"path": path})).unwrap();
let params = json!({"path": path, "matrix": [1, 0, 0, 100, 0, 1, 0, 0, 0, 0, 1, 0], "name": "Bracket"});
let mut w = Win::new();
let (tx, rx) = std::sync::mpsc::channel();
w.app.control_rx = Some(rx);
let (req, reply_rx) = crate::control::ControlRequest::new("engine.execute", json!({"command": "file.insert_step", "params": params.clone()}));
tx.send(req).unwrap();
let mut reply = None;
for _ in 0..100_000 {
w.frame(vec![]);
reply = reply_rx.try_recv().ok();
if reply.is_some() {
break;
}
}
let reply = reply.expect("the import was answered");
assert_eq!(reply["ok"], true, "{reply}");
let mut sync = Session::default();
assert_eq!(reply["result"], sync.execute("file.insert_step", &params).unwrap(), "the window's reply is the session's");
let b = solidcraft_engine::view::bounds(&w.app.session);
assert!((b.min.x - 100.0).abs() < 1e-6 && (b.max.x - 160.0).abs() < 1e-6, "moved by the matrix: {b:?}");
assert!(w.app.session.doc.components.iter().any(|c| c.name == "Bracket"), "named as asked");
let _ = std::fs::remove_dir_all(&dir);
}
/// An opened design is in the window before its bodies are meshed: the view draws the bodies
/// meshed so far (never meshing one itself), framed from their outlines, until all are.
#[test]