diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index c39e5a097..22458ddb0 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -103,6 +103,19 @@ fn read_step(path: &str, names: solidcraft_io::StepNames) -> Result Option<(&'static str, &'static str)> { + if import.system.trim().starts_with("SolidCraft") { + return Some(("z", "SolidCraft")); + } + let named = [&import.system, &import.preprocessor, &import.description].iter().any(|h| h.to_ascii_lowercase().contains("solidworks")); + named.then_some(("y", "SolidWorks")) +} + /// A quarter turn about X through the origin: a file's Y up becomes Z up. fn quarter_turn_x() -> solidcraft_doc::Mat { solidcraft_doc::rigid(solidcraft_geom::Vec3::ZERO, solidcraft_geom::Vec3::ZERO, solidcraft_geom::Vec3::X, std::f64::consts::FRAC_PI_2) @@ -120,7 +133,11 @@ fn add_step(s: &mut Session, path: &str, name: Option<&str>, options: &StepOptio let turned = if options.y_up { turn_up(s, &placed)? } else { None }; let created = created_bodies(s, id); let fname = s.doc.feature(id).map(|f| f.name.clone()).unwrap_or_default(); - let mut out = json!({"path": path, "feature": id, "name": fname, "bodies": created, "created_bodies": created, "warnings": sf.warnings}); + let mut out = json!({"path": path, "feature": id, "name": fname, "bodies": created, "created_bodies": created, "warnings": sf.warnings, "system": sf.import.system}); + if let Some((up, exporter)) = exporter_up(&sf.import) { + out["exporter"] = json!(exporter); + out["exporter_up"] = json!(up); + } placed.report(&mut out); if let Some(turned) = turned { out["stand_up"] = json!(turned); @@ -261,7 +278,7 @@ fn open(s: &mut Session, p: &Value) -> Result { s.replace_design(fresh); let errors = s.model.results.iter().filter(|r| r.error.is_some()).count(); let mut out = json!({"path": path, "features": s.doc.features.len(), "errors": errors, "bodies": r["bodies"], "warnings": r["warnings"]}); - for k in ["component", "component_name", "occurrence", "subcomponents", "rigid_joints", "stand_up"] { + for k in ["component", "component_name", "occurrence", "subcomponents", "rigid_joints", "stand_up", "system", "exporter", "exporter_up"] { if let Some(v) = r.get(k) { out[k] = v.clone(); } diff --git a/crates/engine/src/tests/step_import_options.rs b/crates/engine/src/tests/step_import_options.rs index f4264f883..fd8cbab47 100644 --- a/crates/engine/src/tests/step_import_options.rs +++ b/crates/engine/src/tests/step_import_options.rs @@ -274,3 +274,61 @@ fn automatic_part_names_and_assembly_survive_reopening() { assert!(near(extent(&again).0, [0.0, 0.0, 0.0]) && near(extent(&again).1, [40.0, 34.0, 20.0])); assert!((total_volume(&mut again) - (40.0 * 4.0 * 20.0 + 2.0 * 4.0 * 30.0 * 4.0)).abs() < 1e-6); } + +#[test] +fn step_replies_include_originating_system() -> std::result::Result<(), Box> { + let dir = std::env::temp_dir().join(format!("solidcraft-step-system-{}", std::process::id())); + std::fs::create_dir_all(&dir)?; + let path = dir.join("box.step"); + let mut source = Session::default(); + source.execute("solid.box", &json!({"length": 10, "width": 40, "height": 5}))?; + source.execute("file.export", &json!({"path": path.to_string_lossy()}))?; + let text = std::fs::read_to_string(&path)?; + assert!(text.contains("'SolidCraft','SolidCraft'")); + for system in ["SolidCraft", "Example CAD"] { + std::fs::write(&path, text.replace("'SolidCraft','SolidCraft'", &format!("'SolidCraft','{system}'")))?; + for command in ["file.insert_step", "doc.open"] { + let reply = Session::default().execute(command, &json!({"path": path.to_string_lossy()}))?; + assert_eq!(reply.get("system").and_then(Value::as_str), Some(system), "{command}: {reply}"); + } + } + std::fs::remove_dir_all(dir)?; + Ok(()) +} + +/// A header naming SolidWorks says the file has Y up; SolidCraft's own says Z; anything else +/// says nothing (synthetic headers only). +#[test] +fn step_replies_name_a_y_up_exporter() -> std::result::Result<(), Box> { + let dir = std::env::temp_dir().join(format!("solidcraft-step-exporter-{}", std::process::id())); + std::fs::create_dir_all(&dir)?; + let path = dir.join("box.step"); + let mut source = Session::default(); + source.execute("solid.box", &json!({"length": 10, "width": 40, "height": 5}))?; + source.execute("file.export", &json!({"path": path.to_string_lossy()}))?; + let text = std::fs::read_to_string(&path)?; + let header = "'SolidCraft','SolidCraft'"; + assert!(text.contains(header)); + for (preprocessor, system, want) in [ + ("SolidCraft", "SolidCraft", Some(("z", "SolidCraft"))), + ("SolidWorks 2021", "SolidWorks 2021", Some(("y", "SolidWorks"))), + ("Example CAD", "SOLIDWORKS 2019", Some(("y", "SolidWorks"))), + ("Example CAD", "Example CAD", None), + ] { + std::fs::write(&path, text.replace(header, &format!("'{preprocessor}','{system}'")))?; + for command in ["file.insert_step", "doc.open"] { + let reply = Session::default().execute(command, &json!({"path": path.to_string_lossy()}))?; + let got = reply.get("exporter_up").and_then(Value::as_str).zip(reply.get("exporter").and_then(Value::as_str)); + assert_eq!(got, want, "{command} {system}: {reply}"); + } + } + // The program may be named only in FILE_DESCRIPTION. + std::fs::write( + &path, + text.replace("FILE_DESCRIPTION((", "FILE_DESCRIPTION(('SolidWorks export',").replace(header, "'Example CAD','Example CAD'"), + )?; + let reply = Session::default().execute("file.insert_step", &json!({"path": path.to_string_lossy()}))?; + assert_eq!(reply.get("exporter_up").and_then(Value::as_str), Some("y"), "{reply}"); + std::fs::remove_dir_all(dir)?; + Ok(()) +} diff --git a/crates/kernel/src/iges_in.rs b/crates/kernel/src/iges_in.rs index c59b51d3e..7a6765b5b 100644 --- a/crates/kernel/src/iges_in.rs +++ b/crates/kernel/src/iges_in.rs @@ -100,6 +100,8 @@ struct Iges { unit: f64, /// Minimum resolution (model units). resolution: f64, + /// Global section field 5: the system that wrote the file. + native_system: String, } /// Split parameter text into fields at `delim`, stopping at `rdelim`; Hollerith strings (`nH…`) @@ -281,7 +283,7 @@ fn parse(text: &str) -> R { if des.is_empty() { return Err("the file has no entities".into()); } - Ok(Iges { des, params, unit, resolution }) + Ok(Iges { des, params, unit, resolution, native_system: field(5).trim().to_string() }) } /// A model curve segment ready for an edge: STEP curve id, its end points, points a quarter and @@ -1320,8 +1322,17 @@ fn translate(text: &str) -> std::result::Result<(String, Vec), String> { let psa = t.o.add(format!("PRESENTATION_STYLE_ASSIGNMENT((#{ssu}))")); t.o.add(format!("STYLED_ITEM('color',(#{psa}),#{item})")); } - let mut s = String::from( - "ISO-10303-21;\nHEADER;\nFILE_DESCRIPTION(('IGES import'),'2;1');\nFILE_NAME('','',(''),(''),'SolidCraft IGES','','');\nFILE_SCHEMA(('AUTOMOTIVE_DESIGN'));\nENDSEC;\nDATA;\n", + // The global section's native system ID (field 5) is the file's originating system. + let native: String = f + .native_system + .chars() + .filter(|c| c.is_ascii() && !c.is_ascii_control()) + .map(|c| if c == '\\' { ' ' } else { c }) + .collect::() + .replace('\'', "''"); + let mut s = format!( + "ISO-10303-21;\nHEADER;\nFILE_DESCRIPTION(('IGES import'),'2;1');\nFILE_NAME('','',(''),(''),'SolidCraft IGES','{}','');\nFILE_SCHEMA(('AUTOMOTIVE_DESIGN'));\nENDSEC;\nDATA;\n", + native.trim() ); for (i, l) in t.o.lines.iter().enumerate() { let _ = writeln!(s, "#{}={l};", i + 1); diff --git a/crates/kernel/src/iges_in/tests.rs b/crates/kernel/src/iges_in/tests.rs index b7922b5de..b253f3b19 100644 --- a/crates/kernel/src/iges_in/tests.rs +++ b/crates/kernel/src/iges_in/tests.rs @@ -552,3 +552,10 @@ fn a_curve_over_a_tiny_knot_span_still_bounds_its_faces() { assert!(rel(m.volume, 6000.0) < 1e-6 && rel(m.area, 2200.0) < 1e-6, "span {span}: {} {}", m.volume, m.area); } } + +#[test] +fn the_global_sections_native_system_becomes_the_originating_system() { + let imp = round_trip(&box_solid(Vec3::ZERO, Vec3::new(10.0, 20.0, 30.0)).unwrap()); + assert_eq!(imp.system, "SolidCraft"); + assert_eq!(imp.preprocessor, "SolidCraft IGES"); +} diff --git a/crates/kernel/src/step_in/mod.rs b/crates/kernel/src/step_in/mod.rs index b2bad9b42..2454ce143 100644 --- a/crates/kernel/src/step_in/mod.rs +++ b/crates/kernel/src/step_in/mod.rs @@ -88,6 +88,10 @@ pub struct StepImport { pub schema: String, /// FILE_NAME originating system. pub system: String, + /// FILE_NAME preprocessor version. + pub preprocessor: String, + /// FILE_DESCRIPTION text. + pub description: String, } /// A solid the walk found, converted later. @@ -1318,7 +1322,15 @@ impl StepReading { return Err(KernelError::Failed(format!("STEP import: no bodies ({why})"))); } let bodies = std::mem::take(&mut rd.bodies); - Ok(StepImport { bodies, tree, warnings, schema: ex.schemas.join(", "), system: ex.originating_system.clone() }) + Ok(StepImport { + bodies, + tree, + warnings, + schema: ex.schemas.join(", "), + system: ex.originating_system.clone(), + preprocessor: ex.preprocessor.clone(), + description: ex.description.clone(), + }) } /// [`Self::finish`], and the import is cached for the next read of the same text. diff --git a/crates/kernel/src/step_in/p21.rs b/crates/kernel/src/step_in/p21.rs index 855aa92eb..e862774b3 100644 --- a/crates/kernel/src/step_in/p21.rs +++ b/crates/kernel/src/step_in/p21.rs @@ -122,6 +122,10 @@ pub struct Exchange { pub schemas: Vec, /// FILE_NAME originating system. pub originating_system: String, + /// FILE_NAME preprocessor version. + pub preprocessor: String, + /// FILE_DESCRIPTION text, its lines joined by a space. + pub description: String, pub entities: HashMap, /// Ids defined more than once (the first definition is kept). pub duplicates: Vec, @@ -452,7 +456,13 @@ pub fn parse(text: &str) -> Result { ex.schemas = v.iter().filter_map(|p| p.as_str().map(str::to_string)).collect(); } } + "FILE_DESCRIPTION" => { + if let Some(Param::List(v)) = params.first() { + ex.description = v.iter().filter_map(|p| p.as_str()).collect::>().join(" "); + } + } "FILE_NAME" => { + ex.preprocessor = params.get(4).and_then(Param::as_str).unwrap_or("").to_string(); ex.originating_system = params.get(5).and_then(Param::as_str).unwrap_or("").to_string(); } _ => {} diff --git a/crates/ui-egui/src/file_load_ui_tests.rs b/crates/ui-egui/src/file_load_ui_tests.rs index 938f5255a..f4e9ee144 100644 --- a/crates/ui-egui/src/file_load_ui_tests.rs +++ b/crates/ui-egui/src/file_load_ui_tests.rs @@ -234,6 +234,9 @@ fn a_control_import_passes_up_and_names_on() { let mut src = Session::default(); src.execute("solid.box", &json!({"length": 10, "width": 40, "height": 5})).unwrap(); src.execute("file.export", &json!({"path": path})).unwrap(); + // Another program's file: SolidCraft's own exports are not offered (#5150). + let text = std::fs::read_to_string(&path).unwrap(); + std::fs::write(&path, text.replace("'SolidCraft','SolidCraft'", "'SolidCraft','Example CAD'")).unwrap(); // The reply, the part's height and whether the offer is up, for an import by this window. let import = |params: serde_json::Value| { diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index de84fb95c..c65a550dd 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -440,6 +440,8 @@ pub struct SolveApp { /// When Esc was last pressed (input time): a second press soon after finishes the sketch. pub last_escape: Option, pub status: Option<(String, f64, bool)>, + /// The status message offers Undo (a click on it undoes the last step), as after an automatic stand-up. + pub status_undo: bool, pub quit_requested: bool, /// Autosave into the recovery folder (the desktop app turns it on). pub autosave: Option, @@ -574,6 +576,7 @@ impl SolveApp { esc_handled: false, last_escape: None, status: None, + status_undo: false, quit_requested: false, autosave: None, recoverable: Vec::new(), @@ -1201,6 +1204,7 @@ impl SolveApp { let (text, at) = (s.into(), now_ms()); self.messages.push(&text, error, at); self.status = Some((text, at, error)); + self.status_undo = false; } pub fn open_path(&mut self, path: &str) { diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index c68d20460..ddcfbd6e0 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -529,6 +529,9 @@ preference_settings! { look_at_speed: f32 = 1.0, PAGE_NAVIGATION, accept(0.25..=4.0) => enabled_slider(look_at_anim, "Animation speed", 0.5..=3.0, 0.25, |v| format!("{v:.2}×")); /// Default modelling orientation: `z` (Z up) or `y` (Y up) (#3). up_axis: String = "z".into(), PAGE_DESIGN; + /// A STEP or IGES file whose header names a Y-up exporter (SolidWorks) is stood up as it + /// opens, with an Undo in the toast (`stand_up`). + auto_stand_up: bool = true, PAGE_DESIGN => check("Stand up Y-up files automatically", "A STEP or IGES file from a program that saves Y up opens standing, with Undo in the message"); /// After a STEP or IGES file opens, offer to stand a Y-up part up (`stand_up`). offer_stand_up: bool = true, PAGE_DESIGN => check("Offer to stand up Y-up files", "After a STEP or IGES file opens with Z up, offer a quarter turn about X"); /// What a middle-button double-click in the view does: `home`, `fit` or `off`. @@ -2251,6 +2254,11 @@ mod tests { let mut app = SolveApp::new(solidcraft_engine::Session::default(), Default::default()); app.open_path(&path); + assert!(app.stand_up.is_none(), "SolidCraft's own exports already have Z up"); + // Another originating system keeps the offer. + let text = std::fs::read_to_string(&path).unwrap(); + std::fs::write(&path, text.replace("'SolidCraft','SolidCraft'", "'SolidCraft','Example CAD'")).unwrap(); + app.open_path(&path); let offered = app.stand_up.clone().unwrap_or_default(); assert_eq!(offered.len(), 1, "the file's body is offered"); let size = |app: &SolveApp| solidcraft_engine::view::bounds(&app.session); diff --git a/crates/ui-egui/src/prefs/design.rs b/crates/ui-egui/src/prefs/design.rs index 72477178c..4ffc7cacd 100644 --- a/crates/ui-egui/src/prefs/design.rs +++ b/crates/ui-egui/src/prefs/design.rs @@ -46,6 +46,7 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) { crate::i18n::tr_label("Which axis points up in the views (axis view, Home, Look At). Designs are unchanged."), ui_kit::Text::Hint("orientation"), ); + setting::auto_stand_up(app, ui); setting::offer_stand_up(app, ui); ui_kit::text(ui, app.tr("prefs.stand_up_note"), ui_kit::Text::Hint("stand_up")); }); diff --git a/crates/ui-egui/src/stand_up.rs b/crates/ui-egui/src/stand_up.rs index 3b2e3dabf..db62a7c5f 100644 --- a/crates/ui-egui/src/stand_up.rs +++ b/crates/ui-egui/src/stand_up.rs @@ -2,7 +2,9 @@ //! from them opens lying on its back in a Z-up design. After such a file opens, SolidCraft //! offers to stand it up: a quarter turn about X (Y → Z) of the component the file came in as //! (#1386), so an assembly's parts and instances turn together, in one step that can be undone. Preferences › Design › "Offer to stand up Y-up -//! files" turns the offer off; with Y up as the default orientation it isn't needed. +//! files" turns the offer off; with Y up as the default orientation it isn't needed. When the +//! file's header names an exporter known to save Y up (SolidWorks), Preferences › Design › +//! "Stand up Y-up files automatically" stands it up without asking, with Undo in the message. use serde_json::json; @@ -14,14 +16,38 @@ use crate::ui_kit; /// stand them up. pub fn offer(app: &mut SolveApp, path: &str, before: &[String], result: Option<&serde_json::Value>) { let io = &solidcraft_engine::io::is_step_path; - if !(io(path) || solidcraft_engine::io::is_iges_path(path)) || !app.preferences.offer_stand_up || app.preferences.up_axis != "z" { + if !(io(path) || solidcraft_engine::io::is_iges_path(path)) || app.preferences.up_axis != "z" { + return; + } + let text = |k: &str| result.and_then(|r| r.get(k)).and_then(serde_json::Value::as_str); + // SolidCraft's own STEP exports already use Z up. + if text("system") == Some("SolidCraft") || text("exporter_up") == Some("z") { return; } let bodies: Vec = app.session.world_state().bodies.iter().map(|b| b.name.clone()).filter(|n| !before.contains(n)).collect(); - if !bodies.is_empty() { - app.stand_up = Some(bodies); - app.stand_up_occurrence = result.and_then(|r| r.get("occurrence")).and_then(serde_json::Value::as_u64); + if bodies.is_empty() { + return; } + let occurrence = result.and_then(|r| r.get("occurrence")).and_then(serde_json::Value::as_u64); + // A header that names a Y-up exporter: stand it up now, one undoable step, with Undo in the toast. + if text("exporter_up") == Some("y") && app.preferences.auto_stand_up { + let exporter = text("exporter").unwrap_or("a Y-up program").to_string(); + app.stand_up = Some(bodies); + app.stand_up_occurrence = occurrence; + match stand_up(app) { + Ok(()) => { + app.set_status(format!("Stood up (exported Y-up by {exporter}) \u{2014} Undo"), false); + app.status_undo = true; + } + Err(e) => app.set_status(e, true), + } + return; + } + if !app.preferences.offer_stand_up { + return; + } + app.stand_up = Some(bodies); + app.stand_up_occurrence = occurrence; } /// Turn the offered bodies a quarter turn about X (Y up becomes Z up). diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index 07db41b88..720e4e283 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -3263,8 +3263,14 @@ fn transient_messages(app: &mut SolveApp, ui: &egui::Ui, viewport: Rect) { free.max.y = r.top() - t.space_8; // Open the run's messages from the tokenised status toast. crate::scenario::publish_handle("status:chip", r.center()); - if ui.interact(r, egui::Id::new("sc_status_chip"), Sense::click()).on_hover_text(crate::i18n::tr("messages.chip_hint")).clicked() { - app.messages.open = true; + let hint = if app.status_undo { crate::i18n::tr_label("Undo") } else { crate::i18n::tr("messages.chip_hint") }; + if ui.interact(r, egui::Id::new("sc_status_chip"), Sense::click()).on_hover_text(hint).clicked() { + if app.status_undo { + app.status = None; + let _ = app.run("edit.undo", json!({})); + } else { + app.messages.open = true; + } } } // One frame when it is due to go, not a frame every half second while it shows. diff --git a/crates/ui-egui/tests/stand_up_offer.rs b/crates/ui-egui/tests/stand_up_offer.rs index 958afa60a..5c5464c6b 100644 --- a/crates/ui-egui/tests/stand_up_offer.rs +++ b/crates/ui-egui/tests/stand_up_offer.rs @@ -6,14 +6,25 @@ use solidcraft_ui_egui::scenario::Harness; /// A harness with a 10 × 40 × 5 mm box (Y up) just opened from STEP: the offer is up. fn opened() -> Harness { + let h = opened_from("'Example CAD','Example CAD'", |_| {}); + assert_eq!(h.app.stand_up.as_ref().map(Vec::len), Some(1), "the file's body is offered"); + h +} + +/// The same box, its FILE_NAME naming `programs` (preprocessor, originating system), opened +/// after `prepare` has set the app up. +fn opened_from(programs: &str, prepare: impl FnOnce(&mut Harness)) -> Harness { let mut src = Harness::new(); let path = src.dir.join("tall_in_y.step").to_string_lossy().into_owned(); src.app.run("solid.box", json!({"length": 10, "width": 40, "height": 5})).unwrap(); src.app.run("file.export", json!({"path": path})).unwrap(); + // Another program's file: SolidCraft's own exports already have Z up (#5150). + let text = std::fs::read_to_string(&path).unwrap(); + std::fs::write(&path, text.replace("'SolidCraft','SolidCraft'", programs)).unwrap(); let mut h = Harness::new(); + prepare(&mut h); h.app.open_path(&path); h.frames(3); - assert_eq!(h.app.stand_up.as_ref().map(Vec::len), Some(1), "the file's body is offered"); h } @@ -68,3 +79,51 @@ fn prefs_stand_up_false_leaves_the_offer() { assert_eq!(r["result"]["offer_stand_up"], json!(true), "{r}"); assert!((height(&h) - 5.0).abs() < 1e-6); } + +#[test] +fn a_solidworks_header_stands_the_file_up_with_undo() { + let mut h = opened_from("'SolidWorks 2021','SolidWorks 2021'", |_| {}); + assert!(h.app.stand_up.is_none(), "no offer: it stood up on its own"); + assert!((height(&h) - 40.0).abs() < 1e-6, "stood up: {}", height(&h)); + let status = h.app.status.clone().map(|s| s.0); + assert_eq!(status.as_deref(), Some("Stood up (exported Y-up by SolidWorks) \u{2014} Undo")); + assert!(h.app.status_undo); + // Clicking the message is the Undo: one step puts the file back as it was written. + h.run(&json!([{"click": {"handle": "status:chip"}}])).unwrap(); + h.frames(3); + assert!((height(&h) - 5.0).abs() < 1e-6, "undone: {}", height(&h)); + assert!(h.app.stand_up.is_none()); +} + +#[test] +fn a_solidcraft_header_is_left_alone() { + let h = opened_from("'SolidCraft','SolidCraft'", |_| {}); + assert!(h.app.stand_up.is_none(), "no offer"); + assert!(!h.app.status_undo); + assert!((height(&h) - 5.0).abs() < 1e-6, "not turned: {}", height(&h)); +} + +#[test] +fn automatic_stand_up_off_offers_a_solidworks_file_instead() { + let h = opened_from("'SolidWorks 2021','SolidWorks 2021'", |h| h.app.preferences.auto_stand_up = false); + assert_eq!(h.app.stand_up.as_ref().map(Vec::len), Some(1), "offered, not turned"); + assert!((height(&h) - 5.0).abs() < 1e-6); +} + +#[test] +fn the_offer_preference_off_does_not_stop_a_known_y_up_file() { + // An unknown exporter is not offered, but a SolidWorks file still stands up. + let off = |h: &mut Harness| h.app.preferences.offer_stand_up = false; + assert!(opened_from("'Example CAD','Example CAD'", off).app.stand_up.is_none()); + let h = opened_from("'SolidWorks 2021','SolidWorks 2021'", off); + assert!((height(&h) - 40.0).abs() < 1e-6, "stood up: {}", height(&h)); +} + +#[test] +fn old_preferences_files_load_with_automatic_stand_up_on() { + let old: solidcraft_ui_egui::prefs::Prefs = serde_json::from_str(r#"{"offer_stand_up": false, "up_axis": "z"}"#).unwrap(); + assert!(!old.offer_stand_up, "the saved choice is kept"); + assert!(old.auto_stand_up, "the new setting starts on"); + let empty: solidcraft_ui_egui::prefs::Prefs = serde_json::from_str("{}").unwrap(); + assert!(empty.auto_stand_up && empty.offer_stand_up); +} diff --git a/docs/control-protocol.md b/docs/control-protocol.md index a4ea1477d..b71150667 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -205,7 +205,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox. | `ui.home` | `open?`: bool; `sample?`: index | the start page: show or hide it, open a built-in sample (once built); returns `open` and the recent designs | | `ui.shortcut` | `command`, `key?`, `replace?` | a command's key, or rebinds it (`""` clears; a key another command uses is refused unless `replace`) | | `ui.help` | `item?`: `about`, `shortcuts` (read only), `report` (opens a report draft for review), `crashes` (the Crash Reports window) | the version, commit, build date and diagnostic text | -| `ui.prefs` | any of `default_units`, `nav` (`fusion`, `solidworks`, `inventor`, `alias`, `blender`, `tinkercad`, `openscad`, `touchpad`), `zoom_reverse`, `pan_reverse_x` (default false: horizontal scrolling pans the other way), `zoom_to_cursor`, `smooth_wheel_zoom` (default true), `trackpad_pan` (default true: two-finger scroll pans, except Touchpad always zooms; pinch zooms), `orbit_around` (`view_centre` (default: what Pan moves and Fit frames), `origin` (the world origin stays still on screen), `cursor` (the model point under the pointer when the drag began); the older `orbit_cursor` boolean still sets `cursor` when true), `look_at_anim`, `look_at_speed`, `middle_double_click` (`home` (default), `fit`, `off`), `msaa`, `show_frame_rate` (default false: frames per second in the view's bottom-right corner, counting the frames the view draws anyway; it reads 0 FPS once the view is idle), `length_decimals`, `angle_decimals`, `theme` (`dark`, `light`, `system` or a theme file's id: a built-in one such as `gruvbox-dark`, or an imported one; the reply's `theme_ids` lists them), `theme_import` (a `solidcraft-theme/1` file's JSON or text: adds the theme and turns it on; the reply's `theme_imported` is its id), `theme_remove` (an imported theme's id), `theme_export: true` (the reply's `theme_file` is the theme on now as a complete file; see [colour themes](book/src/guide/ui-tour.md#colour-themes)), `language` (`en`, `ja`, `de`, `fr`, `ko`, `ms`, `ru`, `uk`, `zh`; see [localization](localization.md)), `ui_scale`, `ui_font` (an installed font family or a font file for the interface; empty for the built-in font), `up_axis` (`z`, `y`), `offer_stand_up`, `color_vision` (`off` (default), `protan`, `deutan`, `tritan`: colour vision modes, #778), `check_updates` (default true; [updates](book/src/guide/updates.md)); `open` (a page: General, Interface, Design, Navigation, Keyboard Shortcuts, Sketch, Graphics, AI, Plugins; Shortcuts, Assistant and Sketch & selection are aliases, and the former Selection page opens Sketch) opens the Preferences dialog there; `button`: `ok`, `cancel`, `apply`, `defaults`; `stand_up: true` stands up a just-opened Y-up file, `stand_up: false` leaves it as it is ("Leave it": the offer closes and `offer_stand_up` stays on); the offer's buttons are the handles `stand_up:stand`, `stand_up:leave` and `stand_up:never` | sets preferences (kept between runs), returns them all plus `dialog` (the open page or null), `dark` and `stand_up_offer` | +| `ui.prefs` | any of `default_units`, `nav` (`fusion`, `solidworks`, `inventor`, `alias`, `blender`, `tinkercad`, `openscad`, `touchpad`), `zoom_reverse`, `pan_reverse_x` (default false: horizontal scrolling pans the other way), `zoom_to_cursor`, `smooth_wheel_zoom` (default true), `trackpad_pan` (default true: two-finger scroll pans, except Touchpad always zooms; pinch zooms), `orbit_around` (`view_centre` (default: what Pan moves and Fit frames), `origin` (the world origin stays still on screen), `cursor` (the model point under the pointer when the drag began); the older `orbit_cursor` boolean still sets `cursor` when true), `look_at_anim`, `look_at_speed`, `middle_double_click` (`home` (default), `fit`, `off`), `msaa`, `show_frame_rate` (default false: frames per second in the view's bottom-right corner, counting the frames the view draws anyway; it reads 0 FPS once the view is idle), `length_decimals`, `angle_decimals`, `theme` (`dark`, `light`, `system` or a theme file's id: a built-in one such as `gruvbox-dark`, or an imported one; the reply's `theme_ids` lists them), `theme_import` (a `solidcraft-theme/1` file's JSON or text: adds the theme and turns it on; the reply's `theme_imported` is its id), `theme_remove` (an imported theme's id), `theme_export: true` (the reply's `theme_file` is the theme on now as a complete file; see [colour themes](book/src/guide/ui-tour.md#colour-themes)), `language` (`en`, `ja`, `de`, `fr`, `ko`, `ms`, `ru`, `uk`, `zh`; see [localization](localization.md)), `ui_scale`, `ui_font` (an installed font family or a font file for the interface; empty for the built-in font), `up_axis` (`z`, `y`), `auto_stand_up` (default true: a STEP or IGES file whose header names a Y-up exporter, SolidWorks, is stood up as it opens), `offer_stand_up`, `color_vision` (`off` (default), `protan`, `deutan`, `tritan`: colour vision modes, #778), `check_updates` (default true; [updates](book/src/guide/updates.md)); `open` (a page: General, Interface, Design, Navigation, Keyboard Shortcuts, Sketch, Graphics, AI, Plugins; Shortcuts, Assistant and Sketch & selection are aliases, and the former Selection page opens Sketch) opens the Preferences dialog there; `button`: `ok`, `cancel`, `apply`, `defaults`; `stand_up: true` stands up a just-opened Y-up file, `stand_up: false` leaves it as it is ("Leave it": the offer closes and `offer_stand_up` stays on); the offer's buttons are the handles `stand_up:stand`, `stand_up:leave` and `stand_up:never` | sets preferences (kept between runs), returns them all plus `dialog` (the open page or null), `dark` and `stand_up_offer` | | `ui.capture` | `action?`: `capture`, `revert`, `cancel` | answers the Capture Position question (asked when a command starts or the design is saved while components were moved without capturing); without `action`, what waits | | `ui.window` | `action`: minimize, maximize, restore, toggle, close | what the title bar's caption buttons do (on Windows and Linux the application bar is the title bar); close asks about unsaved designs first | | `ui.agent_cursor` | `show` (bool), `speed`: a number from 1 to 5 (times the normal speed) or `"instant"` (no animation: the command runs at once and the pointer jumps to where it acted), `follow_camera` (bool); all optional | the settings. While the cursor is shown, `engine.execute` first glides to the command's toolbar button and to each pick, then runs and replies; later requests wait their turn. `"animate": false` on a call skips it | diff --git a/docs/step-import.md b/docs/step-import.md index 2bc84d489..8e380e4a2 100644 --- a/docs/step-import.md +++ b/docs/step-import.md @@ -45,7 +45,7 @@ the supporting ellipse in the middle. Files from different systems differ in which way is up and in what they call their solids. `doc.open`, `file.insert_step` and the MCP `open` tool take two options for STEP and IGES files; without them a file comes in as written. -- **`up`**: `"z"` (the default) keeps the file's axes. Many systems write Y up, so such a part lies on its back in SolidCraft's Z-up space. `"up": "y"` turns the import's component a quarter turn about X (+90°: Y becomes Z), as the window's "Stand it up" offer does, so an assembly's parts and instances turn together. The import and the turn are one undo step, the reply names the turned occurrence as `stand_up`, and only the file's component turns, not what is already in the design. The window offers to stand a part up after a STEP file opens unless the call said which way is up (`up: "z"` as well as `"y"`). +- **`up`**: `"z"` (the default) keeps the file's axes. Many systems write Y up, so such a part lies on its back in SolidCraft's Z-up space. `"up": "y"` turns the import's component a quarter turn about X (+90°: Y becomes Z), as the window's "Stand it up" offer does, so an assembly's parts and instances turn together. The import and the turn are one undo step, the reply names the turned occurrence as `stand_up`, and only the file's component turns, not what is already in the design. The window offers to stand a part up after a STEP file opens unless the call said which way is up (`up: "z"` as well as `"y"`) or the file came from SolidCraft, which already writes Z up. A STEP reply's `system` is the originating system the file's header names (`SolidCraft` for SolidCraft's own exports). A header that names SolidWorks (in FILE_NAME's originating system or preprocessor version, or in FILE_DESCRIPTION; for IGES, the start of the global section's native system ID, which becomes the originating system) says the file has Y up: the reply carries `exporter` (`SolidWorks`) and `exporter_up` (`y`), and with Preferences › Design › "Stand up Y-up files automatically" on (the default) the window stands the part up as it opens, as one undo step, with Undo in the message. SolidCraft's own files say `z` and are left alone; any other exporter is unknown, so the offer stays. - **`names`**: `"auto"` (the default) keeps meaningful solid names and replaces placeholders such as `Body1` or `Body 2 (3)` with the nearest named product, then the occurrence name if no product is named. `"solid"` keeps the solid's name; `"product"` chooses the part's name; `"instance"` chooses the assembly occurrence (`Post-2`), falling back to the product. If the chosen name is missing, the solid's name remains. Repeated names are numbered (`Post`, `Post (2)`). Names are stored with the Import feature and survive reopening the design. Files without names or assembly metadata retain generated body names and a flat structure. - **Vertices off their curves**: some systems write an edge's vertex a little beside the end of its curve, often further off than the accuracy the file declares (`UNCERTAINTY_MEASURE_WITH_UNIT`). A vertex up to the file's own tolerance off, or up to 1/1000 of the model's size (never more than 1 mm), is read as that end of the edge: the curve's end is moved onto the vertex. A vertex further off leaves its face out, with a warning that says how far off it is.