* claim: #8006 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * Parts library: button head cap screws, ISO 7380-1 (#8006) Insert Part offered the socket head cap screw but no button head, so a design using button heads had to stand in a cap screw and accept the wrong head. A button_head_cap_screw family now sits beside it, taking the same parameters from the ISO 7380-1 table over M3 to M16. The head is a new Head::Dome: the shank and the head revolve as one outline, with the rim at dk, a short cylindrical flank, the arc of the crown, and a flat top around the socket, so the hex socket stays a plain cut on a plane. The standard draws the flank and the flat but dimensions neither; they are 0.15 k and 0.7 s, and the comment on those constants records what that costs against the standard's crown radius r1 and why neither other fractions nor r1 taken as given does better. dk, k, s and t are exact, each checked against three reproductions of the table. Insert Part, Change Part Size and the bill of materials need no change: they read the families and their table rows from parts.library. The wider fastener request is issue 7692; this is only the one family from it, and leaves the rest of that list open. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * Parts: format after the rebase Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Pending locale: the Button head cap screw family name Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"en": {
|
||||
"parts.family.button_head_cap_screw": "Button head cap screw"
|
||||
},
|
||||
"de": {
|
||||
"parts.family.button_head_cap_screw": "Linsenkopfschraube mit Innensechskant"
|
||||
},
|
||||
"ar": {
|
||||
"parts.family.button_head_cap_screw": "برغي برأس زرّي بتجويف سداسي"
|
||||
},
|
||||
"he": {
|
||||
"parts.family.button_head_cap_screw": "בורג ראש כפתור עם שקע משושה"
|
||||
},
|
||||
"ja": {
|
||||
"parts.family.button_head_cap_screw": "ボタンヘッド六角穴付きボルト"
|
||||
},
|
||||
"vi": {
|
||||
"parts.family.button_head_cap_screw": "Vít đầu tròn lục giác chìm"
|
||||
},
|
||||
"zh": {
|
||||
"parts.family.button_head_cap_screw": "圆头内六角螺钉"
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
"the Insert Part dialog's command (same as parts.insert): family, size, length?, at?|point?+direction?, name?",
|
||||
),
|
||||
CommandSpec::new("parts.insert", "Insert Part", insert).icon("fastener").params(
|
||||
"family (socket_head_cap_screw | hex_bolt | hex_nut | washer | set_screw | dowel_pin | bearing); size (\"M6\", or \"608\" for bearings); \
|
||||
"family (socket_head_cap_screw | button_head_cap_screw | hex_bolt | hex_nut | washer | set_screw | dowel_pin | bearing); size (\"M6\", or \"608\" for bearings); \
|
||||
length? (mm; screws, bolts, set screws, pins; default a standard length near 2.5 d); \
|
||||
at?: [x,y,z] on a hole's rim or wall (the part seats on the hole's face with a rigid joint) | point?: [x,y,z] with direction?: [x,y,z] (no joint); name?",
|
||||
),
|
||||
@@ -33,6 +33,7 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
/// A family: (id, name, standard).
|
||||
const FAMILIES: &[(&str, &str, &str)] = &[
|
||||
("socket_head_cap_screw", "Socket head cap screw", "ISO 4762"),
|
||||
("button_head_cap_screw", "Button head cap screw", "ISO 7380-1"),
|
||||
("hex_bolt", "Hex head bolt / screw", "ISO 4014 / ISO 4017"),
|
||||
("hex_nut", "Hex nut", "ISO 4032"),
|
||||
("washer", "Plain washer", "ISO 7089"),
|
||||
@@ -77,6 +78,33 @@ const SHCS: [(&str, f64, f64, f64, f64); 14] = [
|
||||
("M30", 45.0, 30.0, 22.0, 15.5),
|
||||
];
|
||||
|
||||
/// ISO 7380-1: (size, head diameter dk, head height k, socket s, socket depth t, the last being
|
||||
/// the key engagement depth, which is 0.59 to 0.63 k throughout). The standard runs M3 to M16:
|
||||
/// the M2.5 and M14 some suppliers list are not in it.
|
||||
const BHCS: [(&str, f64, f64, f64, f64); 8] = [
|
||||
("M3", 5.7, 1.65, 2.0, 1.04),
|
||||
("M4", 7.6, 2.2, 2.5, 1.3),
|
||||
("M5", 9.5, 2.75, 3.0, 1.56),
|
||||
("M6", 10.5, 3.3, 4.0, 2.08),
|
||||
("M8", 14.0, 4.4, 5.0, 2.6),
|
||||
("M10", 17.5, 5.5, 6.0, 3.12),
|
||||
("M12", 21.0, 6.6, 8.0, 4.16),
|
||||
("M16", 28.0, 8.8, 10.0, 5.2),
|
||||
];
|
||||
|
||||
/// A button head's cylindrical flank, as a fraction of the head height k, and the flat top it
|
||||
/// keeps around its socket, as a fraction of the socket's across-flats s. The flat clears the
|
||||
/// socket's corners (0.577 s) at every size.
|
||||
///
|
||||
/// ISO 7380-1 draws neither, and a real button head has no flat at all: its crown curves on and
|
||||
/// the socket's corners break through it. The flat is ours, so that the socket is a plain cut on
|
||||
/// a plane. It costs us the standard's crown radius r1, which the head's own dk and k then fix:
|
||||
/// the result is inside r1's tolerance at six of the eight sizes, 0.08 under it at M3 and 0.12
|
||||
/// over it at M12. No one pair of fractions is inside it at all eight, and taking r1 as given
|
||||
/// instead leaves no flat clear of the socket below M10, so dk, k, s and t are what we keep exact.
|
||||
const BUTTON_FLANK: f64 = 0.15;
|
||||
const BUTTON_FLAT: f64 = 0.7;
|
||||
|
||||
/// ISO 4014/4017 hex head: (size, across flats s, head height k).
|
||||
const HEX_BOLT: [(&str, f64, f64); 14] = [
|
||||
("M2", 4.0, 1.4),
|
||||
@@ -170,7 +198,7 @@ fn default_length(d: f64) -> f64 {
|
||||
/// One part's shape, in its own frame.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
enum Shape {
|
||||
/// A head (round or hex), a shank down −z, an optional hex socket in the head's top.
|
||||
/// A head (round, domed or hex), a shank down −z, an optional hex socket in the head's top.
|
||||
Screw { d: f64, pitch: f64, len: f64, head: Head, socket: Option<(f64, f64)> },
|
||||
/// A hex prism with a through hole (nut), z 0…m.
|
||||
Nut { d: f64, pitch: f64, s: f64, m: f64 },
|
||||
@@ -182,8 +210,21 @@ enum Shape {
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
enum Head {
|
||||
Round { dk: f64, k: f64 },
|
||||
Hex { s: f64, k: f64 },
|
||||
Round {
|
||||
dk: f64,
|
||||
k: f64,
|
||||
},
|
||||
/// A button head: a short cylindrical flank, a crown domed over it, and a flat top of
|
||||
/// radius `flat` around the socket, at z = k.
|
||||
Dome {
|
||||
dk: f64,
|
||||
k: f64,
|
||||
flat: f64,
|
||||
},
|
||||
Hex {
|
||||
s: f64,
|
||||
k: f64,
|
||||
},
|
||||
}
|
||||
|
||||
fn shape(family: &str, size: &str, length: Option<f64>) -> std::result::Result<Shape, String> {
|
||||
@@ -195,6 +236,11 @@ fn shape(family: &str, size: &str, length: Option<f64>) -> std::result::Result<S
|
||||
let (_, dk, k, s, t) = SHCS.iter().find(|r| r.0.eq_ignore_ascii_case(size)).copied().ok_or_else(|| need("ISO 4762"))?;
|
||||
Shape::Screw { d, pitch, len: len(d), head: Head::Round { dk, k }, socket: Some((s, t)) }
|
||||
}
|
||||
"button_head_cap_screw" => {
|
||||
let (d, pitch) = metric(size).ok_or_else(|| need("metric"))?;
|
||||
let (_, dk, k, s, t) = BHCS.iter().find(|r| r.0.eq_ignore_ascii_case(size)).copied().ok_or_else(|| need("ISO 7380-1"))?;
|
||||
Shape::Screw { d, pitch, len: len(d), head: Head::Dome { dk, k, flat: BUTTON_FLAT * s }, socket: Some((s, t)) }
|
||||
}
|
||||
"hex_bolt" => {
|
||||
let (d, pitch) = metric(size).ok_or_else(|| need("metric"))?;
|
||||
let (_, s, k) = HEX_BOLT.iter().find(|r| r.0.eq_ignore_ascii_case(size)).copied().ok_or_else(|| need("ISO 4014"))?;
|
||||
@@ -260,15 +306,41 @@ fn cyl(s: &mut Session, d: f64, z0: f64, z1: f64, op: &str) -> Result<()> {
|
||||
|
||||
/// A solid of revolution about z from a closed (r, z) outline, as one body or joined.
|
||||
fn revolve(s: &mut Session, pts: &[(f64, f64)], op: &str) -> Result<()> {
|
||||
revolve_outline(s, pts, None, op)
|
||||
}
|
||||
|
||||
/// The same, with the outline closed from its last point back to its first by an arc through
|
||||
/// `through`: a button head's domed crown.
|
||||
fn revolve_domed(s: &mut Session, pts: &[(f64, f64)], through: (f64, f64), op: &str) -> Result<()> {
|
||||
revolve_outline(s, pts, Some(through), op)
|
||||
}
|
||||
|
||||
fn revolve_outline(s: &mut Session, pts: &[(f64, f64)], arc: Option<(f64, f64)>, op: &str) -> Result<()> {
|
||||
run(s, "sketch.create", json!({"plane": "XZ"}))?;
|
||||
let points: Vec<[f64; 2]> = pts.iter().map(|(r, z)| [*r, -*z]).collect();
|
||||
run(s, "sketch.line", json!({"points": points, "closed": true}))?;
|
||||
let xz = |(r, z): &(f64, f64)| [*r, -*z];
|
||||
let points: Vec<[f64; 2]> = pts.iter().map(xz).collect();
|
||||
run(s, "sketch.line", json!({"points": points, "closed": arc.is_none()}))?;
|
||||
if let (Some(through), Some(first), Some(last)) = (arc, pts.first(), pts.last()) {
|
||||
run(s, "sketch.arc.three_point", json!({"start": xz(last), "through": xz(&through), "end": xz(first)}))?;
|
||||
}
|
||||
fix_all(s)?;
|
||||
run(s, "sketch.finish", json!({}))?;
|
||||
run(s, "solid.revolve", json!({"axis": "y", "operation": op}))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A point halfway along a button head's crown: on the circle centred on the axis that runs
|
||||
/// from the top of the flank (a, c) to the rim of the flat top (b, k).
|
||||
fn crown(a: f64, c: f64, b: f64, k: f64) -> (f64, f64) {
|
||||
// The centre on the axis, equidistant from both, and the radius from it.
|
||||
let zc = (b * b + k * k - a * a - c * c) / (2.0 * (k - c));
|
||||
let r = (b * b + (k - zc) * (k - zc)).sqrt();
|
||||
// Halfway between the directions to the two ends.
|
||||
let (x, z) = ((a + b) / r, (c - zc + k - zc) / r);
|
||||
let n = x.hypot(z);
|
||||
if n.is_finite() && n > 0.0 { (r * x / n, zc + r * z / n) } else { ((a + b) / 2.0, (c + k) / 2.0) }
|
||||
}
|
||||
|
||||
/// Fix every point and curve of the sketch being drawn: a standard part's outline is its size, so
|
||||
/// its sketches are fully defined and a check of the design finds nothing left free in them.
|
||||
fn fix_all(s: &mut Session) -> Result<()> {
|
||||
@@ -297,6 +369,14 @@ fn build(s: &mut Session, sh: &Shape) -> Result<()> {
|
||||
revolve(s, &[(0.0, -len), (d / 2.0, -len), (d / 2.0, 0.0), (dk / 2.0, 0.0), (dk / 2.0, k), (0.0, k)], "new")?;
|
||||
k
|
||||
}
|
||||
// The same outline up to the head's rim, then a short flank, and the arc of the
|
||||
// crown closing it back to the flat top.
|
||||
Head::Dome { dk, k, flat } => {
|
||||
let (a, c) = (dk / 2.0, BUTTON_FLANK * k);
|
||||
let outline = [(flat, k), (0.0, k), (0.0, -len), (d / 2.0, -len), (d / 2.0, 0.0), (a, 0.0), (a, c)];
|
||||
revolve_domed(s, &outline, crown(a, c, flat, k), "new")?;
|
||||
k
|
||||
}
|
||||
// A hex head joined over a shank that runs up into it.
|
||||
Head::Hex { s: af, k } => {
|
||||
hex(s, af, 0.0, k, "new")?;
|
||||
@@ -334,6 +414,7 @@ fn library(_s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let fam = |id: &str| -> Value {
|
||||
let mut sizes: Vec<Value> = match id {
|
||||
"socket_head_cap_screw" => SHCS.iter().map(|r| json!({"size": r.0, "d": metric(r.0).map(|m| m.0), "pitch": metric(r.0).map(|m| m.1), "head_diameter": r.1, "head_height": r.2, "socket": r.3, "socket_depth": r.4})).collect(),
|
||||
"button_head_cap_screw" => BHCS.iter().map(|r| json!({"size": r.0, "d": metric(r.0).map(|m| m.0), "pitch": metric(r.0).map(|m| m.1), "head_diameter": r.1, "head_height": r.2, "socket": r.3, "socket_depth": r.4})).collect(),
|
||||
"hex_bolt" => HEX_BOLT.iter().map(|r| json!({"size": r.0, "d": metric(r.0).map(|m| m.0), "pitch": metric(r.0).map(|m| m.1), "across_flats": r.1, "head_height": r.2})).collect(),
|
||||
"hex_nut" => HEX_NUT.iter().map(|r| json!({"size": r.0, "d": metric(r.0).map(|m| m.0), "pitch": metric(r.0).map(|m| m.1), "across_flats": r.1, "height": r.2})).collect(),
|
||||
"washer" => WASHER.iter().map(|r| json!({"size": r.0, "inner": r.1, "outer": r.2, "thickness": r.3})).collect(),
|
||||
@@ -343,7 +424,8 @@ fn library(_s: &mut Session, p: &Value) -> Result<Value> {
|
||||
_ => Vec::new(),
|
||||
};
|
||||
let (_, name, standard) = FAMILIES.iter().find(|f| f.0 == id).copied().unwrap_or(("", "", ""));
|
||||
let lengths = matches!(id, "socket_head_cap_screw" | "hex_bolt" | "set_screw" | "dowel_pin").then_some(LENGTHS.to_vec());
|
||||
let lengths =
|
||||
matches!(id, "socket_head_cap_screw" | "button_head_cap_screw" | "hex_bolt" | "set_screw" | "dowel_pin").then_some(LENGTHS.to_vec());
|
||||
if lengths.is_some() {
|
||||
for row in &mut sizes {
|
||||
let Some(size) = row.get("size").and_then(Value::as_str).map(str::to_string) else { continue };
|
||||
@@ -378,6 +460,7 @@ fn identity(family: &str, size: &str, sh: &Shape) -> (String, String) {
|
||||
};
|
||||
let standard = match family {
|
||||
"socket_head_cap_screw" => "ISO 4762",
|
||||
"button_head_cap_screw" => "ISO 7380-1",
|
||||
"hex_bolt" => "ISO 4017",
|
||||
"hex_nut" => "ISO 4032",
|
||||
"washer" => "ISO 7089",
|
||||
@@ -411,6 +494,7 @@ fn set_identity(s: &mut Session, comp: u64, now: (String, String), was: Option<(
|
||||
fn label(family: &str) -> &'static str {
|
||||
match family {
|
||||
"socket_head_cap_screw" => "SHCS",
|
||||
"button_head_cap_screw" => "BHCS",
|
||||
"hex_bolt" => "Hex Bolt",
|
||||
"hex_nut" => "Hex Nut",
|
||||
"washer" => "Washer",
|
||||
@@ -633,6 +717,40 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// #7692: a button head cap screw (ISO 7380-1) takes the same parameters as a socket head
|
||||
/// cap screw, with a domed crown in place of the cylindrical head.
|
||||
#[test]
|
||||
fn a_button_head_is_domed_over_the_shank() {
|
||||
let l = run(&mut Session::default(), "parts.library", json!({"family": "button_head_cap_screw"}));
|
||||
let m6 = l["sizes"].as_array().and_then(|a| a.iter().find(|x| x["size"] == "M6")).cloned().unwrap_or_default();
|
||||
assert_eq!((m6["head_diameter"].as_f64(), m6["head_height"].as_f64(), m6["socket"].as_f64()), (Some(10.5), Some(3.3), Some(4.0)));
|
||||
// ISO 7380-1 has no M2, M2.5, M14 or larger than M16; the lengths are a screw's.
|
||||
let sizes: Vec<&str> = l["sizes"].as_array().map(|a| a.iter().filter_map(|x| x["size"].as_str()).collect()).unwrap_or_default();
|
||||
assert_eq!(sizes, ["M3", "M4", "M5", "M6", "M8", "M10", "M12", "M16"]);
|
||||
assert!(l["lengths"].as_array().is_some_and(|a| !a.is_empty()), "{l}");
|
||||
// An M6 x 20 button head: head Ø10.5, 3.3 high over the seating plane, shank 20 long.
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "parts.insert", json!({"family": "button_head_cap_screw", "size": "M6", "length": 20}));
|
||||
let (lo, hi) = bbox(&s, "BHCS M6x20");
|
||||
assert!((hi.x - lo.x - 10.5).abs() < 1e-3 && (lo.z + 20.0).abs() < 1e-6 && (hi.z - 3.3).abs() < 1e-3, "{lo:?} {hi:?}");
|
||||
assert!(s.model.state().threads.iter().any(|t| t.designation.starts_with("M6")), "{:?}", s.model.state().threads);
|
||||
// The profile: full width at the rim and up the flank (0.15 k = 0.50 high), drawing in
|
||||
// over the crown (r = 4.62 halfway up the head), and a flat top of 0.7 s = 2.8, which
|
||||
// leaves a ring of material around the socket's corners at r = 2.31.
|
||||
let st = s.world_state();
|
||||
let widest = |above: f64| {
|
||||
st.bodies.iter().flat_map(|b| b.mesh().positions.clone()).filter(|p| p.z > above).map(|p| p.x.hypot(p.y)).fold(0.0, f64::max)
|
||||
};
|
||||
assert!((5.2..5.26).contains(&widest(-0.1)), "the rim: {}", widest(-0.1));
|
||||
assert!((5.2..5.26).contains(&widest(0.3)), "the flank: {}", widest(0.3));
|
||||
assert!((3.5..4.7).contains(&widest(1.65)), "the crown halfway up: {}", widest(1.65));
|
||||
assert!((2.6..2.9).contains(&widest(3.29)), "the flat top: {}", widest(3.29));
|
||||
// Its part number is the standard and size, as the other families' are.
|
||||
let comp = s.doc.components.iter().find(|c| c.name.starts_with("BHCS")).map(|c| c.id).unwrap_or(0);
|
||||
let number = s.doc.components.iter().find(|c| c.id == comp).and_then(|c| c.metadata.text(solidcraft_doc::metadata::PART_NUMBER));
|
||||
assert_eq!(number, Some("ISO 7380-1 M6x20"));
|
||||
}
|
||||
|
||||
/// #2091: the second and larger ISO sizes, M2, M2.5, M14, M24 and M30, are in the screw, bolt,
|
||||
/// nut and washer tables (they stopped at M3 and M20).
|
||||
#[test]
|
||||
@@ -686,6 +804,7 @@ mod tests {
|
||||
fn every_sketch_of_a_standard_part_is_fully_defined() {
|
||||
for (family, size, resized) in [
|
||||
("socket_head_cap_screw", "M6", "M8"),
|
||||
("button_head_cap_screw", "M6", "M8"),
|
||||
("hex_bolt", "M6", "M8"),
|
||||
("hex_nut", "M6", "M8"),
|
||||
("washer", "M6", "M8"),
|
||||
@@ -710,6 +829,7 @@ mod tests {
|
||||
fn resizing_placed_parts_uses_local_geometry_and_millimetres_in_every_design_unit() {
|
||||
for (family, initial, resized, prefix) in [
|
||||
("socket_head_cap_screw", "M6", "M8", "SHCS"),
|
||||
("button_head_cap_screw", "M6", "M8", "BHCS"),
|
||||
("hex_bolt", "M6", "M8", "Hex Bolt"),
|
||||
("hex_nut", "M6", "M8", "Hex Nut"),
|
||||
("washer", "M6", "M8", "Washer"),
|
||||
@@ -726,7 +846,7 @@ mod tests {
|
||||
assert!(s.model.results.iter().all(|r| r.error.is_none()), "{family} {units}");
|
||||
let b = bbox(&s, prefix);
|
||||
assert!(b.0.x < b.1.x && b.0.y < b.1.y && b.0.z < b.1.z, "{family} {units}: {b:?}");
|
||||
if matches!(family, "socket_head_cap_screw" | "hex_bolt" | "hex_nut" | "set_screw") {
|
||||
if matches!(family, "socket_head_cap_screw" | "button_head_cap_screw" | "hex_bolt" | "hex_nut" | "set_screw") {
|
||||
assert!(s.model.state().threads.iter().any(|t| t.designation == "M8" && (t.pitch - 1.25).abs() < 1e-9), "{family} {units}");
|
||||
}
|
||||
if family == "dowel_pin" {
|
||||
|
||||
@@ -472,6 +472,7 @@ mod tests {
|
||||
fn part_size_round_trips_all_builtin_families_without_adding_a_length_to_rings() {
|
||||
for (family, size, length) in [
|
||||
("socket_head_cap_screw", "M5", Some(20.0)),
|
||||
("button_head_cap_screw", "M5", Some(20.0)),
|
||||
("hex_bolt", "M5", Some(20.0)),
|
||||
("hex_nut", "M5", None),
|
||||
("washer", "M5", None),
|
||||
|
||||
Reference in New Issue
Block a user