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
+14 -3
View File
@@ -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<Iges> {
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>), 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::<String>()
.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);
+7
View File
@@ -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");
}
+13 -1
View File
@@ -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.
+10
View File
@@ -122,6 +122,10 @@ pub struct Exchange {
pub schemas: Vec<String>,
/// 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<u64, Entity>,
/// Ids defined more than once (the first definition is kept).
pub duplicates: Vec<u64>,
@@ -452,7 +456,13 @@ pub fn parse(text: &str) -> Result<Exchange, String> {
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::<Vec<_>>().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();
}
_ => {}