SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Wave 327/509: STEP import: FILE_DESCRIPTION and the preprocessor name a Y-up exporter again (and 3 more)
jyviko207cb828181c
diff --git a/crates/doc/src/thread_forms.rs b/crates/doc/src/thread_forms.rsindex cc508afe66..b4f4302429 100644--- a/crates/doc/src/thread_forms.rs+++ b/crates/doc/src/thread_forms.rs@@ -400,7 +400,7 @@ impl ThreadForm {}None => {let d = num(body).ok_or_else(bad)?;- let p = self.coarse(d).ok_or_else(|| format!("no coarse pitch for M{} (give it: M{}x1)", show(d), show(d)))?;+ let p = self.coarse(d).ok_or_else(|| no_coarse_pitch(d).unwrap_or_else(bad))?;(d, p, p * n)}}@@ -663,6 +663,18 @@ fn inches(s: &str) -> Option<f64> {num(s)}+/// The refusal for a plain `M<d>` with no ISO coarse pitch: the two coarsest fine pitches to+/// give that suit the diameter. `None` for a diameter no metric thread has.+pub fn no_coarse_pitch(d: f64) -> Option<String> {+ const PITCHES: [f64; 9] = [2.0, 1.5, 1.25, 1.0, 0.75, 0.5, 0.35, 0.25, 0.2];+ if !(d.is_finite() && d > 0.2 && d <= 1e4) {+ return None;+ }+ let first = PITCHES.iter().position(|p| *p <= 0.12 * d).unwrap_or(PITCHES.len() - 1);+ let pitches: Vec<String> = PITCHES.iter().skip(first).take(2).filter(|p| **p < d).map(|p| format!("M{}x{}", show(d), show(*p))).collect();+ (!pitches.is_empty()).then(|| format!("M{} has no coarse ISO pitch: give one, e.g. {}", show(d), pitches.join(" or ")))+}+fn show(v: f64) -> String {let s = format!("{v:.6}");s.trim_end_matches('0').trim_end_matches('.').to_string()diff --git a/crates/engine/src/cmd/features.rs b/crates/engine/src/cmd/features.rsindex 506101442b..816143638a 100644--- a/crates/engine/src/cmd/features.rs+++ b/crates/engine/src/cmd/features.rs@@ -2343,16 +2343,8 @@ fn clearance_diameter(size: &str, fit: &str) -> Option<f64> {/// The pitches to try for a plain `M<d>` that has no ISO coarse pitch, `None` for anything else.fn fine_only_hint(t: &str) -> Option<String> {- const PITCHES: [f64; 9] = [2.0, 1.5, 1.25, 1.0, 0.75, 0.5, 0.35, 0.25, 0.2];let diameter = t.trim().strip_prefix(['M', 'm']).and_then(|d| d.trim().parse::<f64>().ok());- if let Some(d) = diameter.filter(|d| d.is_finite() && *d > 0.2 && *d <= 1e4) {- let first = PITCHES.iter().position(|p| *p <= 0.12 * d).unwrap_or(PITCHES.len() - 1);- let pitches: Vec<String> = PITCHES.iter().skip(first).take(2).filter(|p| **p < d).map(|p| format!("M{d}x{p}")).collect();- if !pitches.is_empty() {- return Some(format!("M{d} has no coarse ISO pitch: give one, e.g. {}", pitches.join(" or ")));- }- }- None+ diameter.and_then(solidcraft_doc::thread_forms::no_coarse_pitch)}/// Largest nominal diameter automatic thread sizing knows (the last ISO coarse size).diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rsindex 1b7de0a78e..6bdaf6e5bb 100644--- a/crates/engine/src/cmd/file.rs+++ b/crates/engine/src/cmd/file.rs@@ -130,7 +130,7 @@ fn exporter_up(import: &solidcraft_kernel::StepImport) -> Option<(&'static str,if import.system.trim().starts_with("SolidCraft") {return Some(("z", "SolidCraft"));}- let named = import.system.to_ascii_lowercase().contains("solidworks");+ let named = [&import.system, &import.preprocessor, &import.description].iter().any(|h| h.to_ascii_lowercase().contains("solidworks"));named.then_some(("y", "SolidWorks"))}diff --git a/crates/engine/src/thread_tests.rs b/crates/engine/src/thread_tests.rsindex b9c2a6b4bf..7a9fea1265 100644--- a/crates/engine/src/thread_tests.rs+++ b/crates/engine/src/thread_tests.rs@@ -270,7 +270,8 @@ fn a_thread_without_a_coarse_pitch_suggests_explicit_pitches() {}for designation in ["MNaN", "Minf", "M-28", "M0", "M1e9", "M1e999", "M28x", "M28xNaN"] {let e = s.execute("solid.thread", &json!({"face": [14, 0, 5], "designation": designation})).unwrap_err().to_string();- assert!(e.contains("unknown thread"), "{designation}: {e}");+ // Each thread form names itself in its refusal: `unknown metric thread`.+ assert!(e.contains("unknown metric thread"), "{designation}: {e}");assert_eq!(s.doc.to_json(), saved);}run(&mut s, "solid.thread", json!({"face": [14, 0, 5], "designation": "M28x2"}));diff --git a/crates/kernel/src/splitface.rs b/crates/kernel/src/splitface.rsindex f6d8098281..f39dc005f7 100644--- a/crates/kernel/src/splitface.rs+++ b/crates/kernel/src/splitface.rs@@ -154,8 +154,9 @@ fn face_patch(body: &Body, face: usize) -> Result<Patch> {let record = body.record();let f = record.faces.get(face).ok_or_else(|| invalid(format!("the tool body has no face {face}")))?;let forward = body.face_forward(face);- // The surface's own parameter box, unbounded where it is.- let dom = SurfaceEval::new(f.parameters()).map_err(|e| invalid(format!("the split tool's surface: {e}")))?.domain();+ // The surface's own parameter box, unbounded where it is: of `surface` itself, not of its+ // NURBS form (SMLib's cylinder is held on one, parameterised otherwise).+ let dom = SurfaceEval::new(&f.surface).map_err(|e| invalid(format!("the split tool's surface: {e}")))?.domain();let range = |k: usize| dom.range[k].map_or(ALL, |(a, b)| [a, b]);Ok(Patch { surface: f.surface.clone(), domain: [range(0), range(1)], flip: !forward })}diff --git a/crates/kernel/src/step_in/mod.rs b/crates/kernel/src/step_in/mod.rsindex ba1d39545b..8b03229edd 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,}/// What an import warning is about, so a window can word a summary of them (the warning's@@ -1330,7 +1334,16 @@ 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, report, schema: ex.schemas.join(", "), system: ex.originating_system.clone() })+ Ok(StepImport {+ bodies,+ tree,+ warnings,+ report,+ 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/surface_kind.rs b/crates/kernel/src/surface_kind.rsindex d0105ca498..94e65c7ac5 100644--- a/crates/kernel/src/surface_kind.rs+++ b/crates/kernel/src/surface_kind.rs@@ -87,11 +87,12 @@ pub fn edge_circle(b: &Body, edge: usize) -> Option<EdgeCircle> {let [t0, t1] = e.interval;let (start, end) = (c.point(t0)?, c.point(t1)?);if let Curve::Circle { frame, radius } = &e.curve {- // The record's parameter is the angle about the frame's z: the edge runs counter-clockwise- // about it from its start to its end.+ // The edge runs counter-clockwise about the frame's z from its start to its end, over the+ // angles of its interval on the circle itself (a NURBS form is parameterised otherwise).let axis = Vec3::from(frame.x_axis).cross(Vec3::from(frame.y_axis)).unit()?;let closed = e.vertices[0] == e.vertices[1];- let angle = if closed { std::f64::consts::TAU } else { (t1 - t0).min(std::f64::consts::TAU) };+ let [a0, a1] = e.curve_interval()?;+ let angle = if closed { std::f64::consts::TAU } else { (a1 - a0).min(std::f64::consts::TAU) };return Some(EdgeCircle { center: Vec3::from(frame.origin), axis, radius: *radius, start, end, angle });}let tol = (b.size() * 1e-7).max(1e-9) * 100.0;diff --git a/crates/step/src/p21.rs b/crates/step/src/p21.rsindex add33a46c3..fec135fec3 100644--- a/crates/step/src/p21.rs+++ b/crates/step/src/p21.rs@@ -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>,@@ -441,7 +445,13 @@ pub fn parse_with(text: &str, watch: Option<&dyn Progress>) -> Result<Exchange,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();}_ => {}