SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Imports through the app keep their matrix, name and options (#4676) (#4746)
dudedagger4289a11d75c0ee
diff --git a/crates/ui-egui/src/file_load.rs b/crates/ui-egui/src/file_load.rsindex dcf9418964..a8a4011971 100644--- a/crates/ui-egui/src/file_load.rs+++ b/crates/ui-egui/src/file_load.rs@@ -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) -> Optioreturn 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}diff --git a/crates/ui-egui/src/file_load_ui_tests.rs b/crates/ui-egui/src/file_load_ui_tests.rsindex f4e9ee144e..57d91231b9 100644--- a/crates/ui-egui/src/file_load_ui_tests.rs+++ b/crates/ui-egui/src/file_load_ui_tests.rs@@ -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", ¶ms).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]