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:
@@ -103,6 +103,19 @@ fn read_step(path: &str, names: solidcraft_io::StepNames) -> Result<solidcraft_i
|
||||
solidcraft_io::step_import_feature_named(&bytes, path, names).map_err(|e| EngineError::Other(format!("{path}: {e}")))
|
||||
}
|
||||
|
||||
/// Which way is up in a STEP or IGES file, from the program its header names: `("y", name)` for
|
||||
/// an exporter whose files have Y up, `("z", name)` for SolidCraft's own (its STEP and IGES exports both name it), else `None`. Only
|
||||
/// SolidWorks is listed as Y up: its STEP and IGES writers are well known to keep that program's
|
||||
/// Y-up front view, and its name is in FILE_NAME (originating system, preprocessor version) and
|
||||
/// often FILE_DESCRIPTION. Programs we aren't sure of stay unknown, so the file is only offered.
|
||||
fn exporter_up(import: &solidcraft_kernel::StepImport) -> 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<Value> {
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user