Wave 327/509: STEP import: FILE_DESCRIPTION and the preprocessor name a Y-up exporter again (and 3 more)

4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop.

- f8c2fba07 jyviko: STEP import: FILE_DESCRIPTION and the preprocessor name a Y-up exporter again
- 5cc0d5e9c jyviko: Threads: a metric size without a coarse pitch suggests its fine pitches again
- e0545b2bd jyviko: Measure: an arc edge's angle is its span on the circle, not its NURBS parameter
- ae5dc2416 jyviko: Split Body: a face tool runs over its own surface's parameters

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
jyviko
2026-10-28 22:11:05 -04:00
parent 21582b66e9
commit 207cb82818
8 changed files with 48 additions and 18 deletions
+13 -1
View File
@@ -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()
+1 -9
View File
@@ -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).
+1 -1
View File
@@ -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"))
}
+2 -1
View File
@@ -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"}));
+3 -2
View File
@@ -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 })
}
+14 -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,
}
/// 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.
+4 -3
View File
@@ -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;
+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>,
@@ -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();
}
_ => {}