Stand up Y-up STEP and IGES files from SolidWorks automatically (#5191)

* claim: #5150

* Stand it up: don't offer it for SolidCraft's own STEP files (#5150)

STEP replies from file.insert_step and doc.open now carry the file's
originating system, and the window skips the stand-up offer when it is
exactly SolidCraft, as SolidCraft's STEP export writes it.

* Stand up Y-up STEP and IGES files from SolidWorks automatically

The STEP header (originating system, preprocessor version, FILE_DESCRIPTION) and the IGES
global section's native system ID say which program wrote a file. A SolidWorks header means
Y up: the import's component is stood up as it opens, as one undo step, and the message offers
Undo. SolidCraft's own files are left alone; an unknown exporter keeps the offer.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Ray <raykholo@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bherbruck
2026-10-23 02:53:20 +00:00
committed by GitHub
parent 0c72ad56d2
commit edf57cec29
15 changed files with 238 additions and 16 deletions
@@ -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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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(())
}