diff --git a/assets/locales/pending/bridged-counterbore.json b/assets/locales/pending/bridged-counterbore.json new file mode 100644 index 000000000..43779be2e --- /dev/null +++ b/assets/locales/pending/bridged-counterbore.json @@ -0,0 +1,8 @@ +{ + "ar": { "Bridge": "جسر" }, + "en": { "Bridge": "Bridge" }, + "he": { "Bridge": "גשר" }, + "ja": { "Bridge": "ブリッジ" }, + "vi": { "Bridge": "Cầu nối" }, + "zh": { "Bridge": "桥接" } +} diff --git a/crates/doc/src/document.rs b/crates/doc/src/document.rs index e2fb074e6..0a86575b1 100644 --- a/crates/doc/src/document.rs +++ b/crates/doc/src/document.rs @@ -2410,6 +2410,12 @@ pub enum HoleKind { #[serde(default, skip_serializing_if = "Option::is_none")] #[walk(angle = "Tip angle")] tip_angle: Option, + /// Printing aid: two bridge layers this thick below the counterbore's floor (a slot along + /// X, then a square), so a printer bridges the step instead of sagging into it. Absent: + /// a plain counterbore. + #[serde(default, skip_serializing_if = "Option::is_none")] + #[walk(length = "Bridge layer")] + bridge: Option, }, Countersink { #[walk(length = "Countersink diameter")] diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs index c1d435336..72a83ea63 100644 --- a/crates/doc/src/eval.rs +++ b/crates/doc/src/eval.rs @@ -4635,13 +4635,26 @@ fn hole_tools_and_prisms( match hole { HoleKind::Simple => tools.extend(bore(None)?), HoleKind::Drilled { tip_angle } => tools.extend(bore(Some(tip_angle))?), - HoleKind::Counterbore { cb_diameter, cb_depth, tip_angle } => { + HoleKind::Counterbore { cb_diameter, cb_depth, tip_angle, bridge } => { let (rc, dc) = (val(vals, cb_diameter, Kind::Length)? / 2.0, val(vals, cb_depth, Kind::Length)?); if !(rc > r && dc > 0.0 && -dc > bottom) { return Err(DocError::Invalid("the counterbore must be wider than the hole and shallower than it".into())); } // Wide and shallow first: the narrow hole then crosses the pocket floor. tools.push(cyl(rc, -dc, top, "cbore")?); + if let Some(layer) = bridge { + let layer = val(vals, layer, Kind::Length)?; + tools.extend(bridge_tools(&plane, r, rc, dc, bottom, layer)?); + // Through all, `bottom` is the tool's reach, not the material's: the second layer + // must end inside a body (exact classification), short of the exit face. + if depth.is_none() { + let past = *position + dir * (dc + 2.0 * layer + size * 1e-6); + let classes = st.bodies.iter().map(|b| b.body.classify_point(past)).collect::, _>>()?; + if !classes.contains(&kernel::PointClass::Inside) { + return Err(bridge_too_deep(layer, "make the counterbore shallower or the bridge thinner")); + } + } + } tools.extend(bore(tip_angle.as_ref())?); } HoleKind::Countersink { cs_diameter, cs_angle, tip_angle } => { @@ -4670,6 +4683,59 @@ fn hole_tools_and_prisms( Ok(tools) } +/// How much wider than the hole a bridged counterbore's slot and square are, in mm. +const BRIDGE_CLEARANCE: f64 = 0.02; + +/// Why a bridged counterbore's two layers of `layer` were refused: they reach past the hole, and +/// `fix` says what to change. +fn bridge_too_deep(layer: f64, fix: &str) -> DocError { + DocError::Invalid(format!("the two bridge layers ({:.3} mm) must fit in the hole below the counterbore: {fix}", 2.0 * layer)) +} + +/// The bridge layers of a counterbore printed opening down: below its floor, a slot across the +/// whole counterbore, along X (one `layer` thick), then a square (one more), both +/// [`BRIDGE_CLEARANCE`] wider than the hole, so each layer spans between supported edges. +/// `plane` is the hole's, its normal out of the material; the bore crosses both layers, clear of +/// their sides. +fn bridge_tools(plane: &Plane, r: f64, rc: f64, dc: f64, bottom: f64, layer: f64) -> Result)>> { + if !(layer > 0.0 && layer.is_finite()) { + return Err(DocError::Invalid("the bridge layer must be a positive length, such as 0.2 mm".into())); + } + let (t1, t2) = (-dc - layer, -dc - 2.0 * layer); + if t2 <= bottom { + return Err(bridge_too_deep(layer, "make the hole deeper or the bridge thinner")); + } + // Both a hair wider than the hole, so the bore's rim doesn't touch their sides. + let q = r + BRIDGE_CLEARANCE / 2.0; + // The slot's ends need room on the counterbore's wall past that. + if !(rc >= q + BRIDGE_CLEARANCE / 2.0) { + return Err(DocError::Invalid(format!("a bridged counterbore must be at least {} mm wider than the hole", 2.0 * BRIDGE_CLEARANCE))); + } + // The slot along world X where the axis allows it, else along the hole plane's own x. + let n = plane.normal(); + let x = (Vec3::X - n * Vec3::X.dot(n)).normalized().filter(|_| Vec3::X.dot(n).abs() < 0.99).unwrap_or(plane.x); + let bp = Plane::new(plane.origin, x, n.cross(x)).ok_or_else(|| DocError::Invalid("hole axis".into()))?; + // The slot ends on the counterbore's wall: two lines and two arcs of its circle. + let a = (rc * rc - q * q).sqrt(); + let phi = q.atan2(a); + let slot = solidcore_record::Loop2 { + segs: vec![ + solidcore_record::Seg2::Line { a: Vec2::new(-a, -q), b: Vec2::new(a, -q) }, + solidcore_record::Seg2::Arc { center: Vec2::ZERO, radius: rc, start: -phi, sweep: 2.0 * phi }, + solidcore_record::Seg2::Line { a: Vec2::new(a, q), b: Vec2::new(-a, q) }, + solidcore_record::Seg2::Arc { center: Vec2::ZERO, radius: rc, start: std::f64::consts::PI - phi, sweep: 2.0 * phi }, + ], + }; + let square = solidcore_record::Loop2::polygon(&[Vec2::new(-q, -q), Vec2::new(q, -q), Vec2::new(q, q), Vec2::new(-q, q)]); + let mut tools = Vec::new(); + for (outline, lo, hi) in [(slot, t1, -dc), (square, t2, t1)] { + let region = Region2 { outer: outline, holes: vec![] }; + let tool = kernel::extrude(&bp, &[region], lo, hi)?.pop().ok_or_else(|| DocError::Invalid("hole tool".into()))?; + tools.push((crate::lineage::part_tool(tool, "bridge"), None)); + } + Ok(tools) +} + /// The angular interval used by both the solid and its interactive extent handles. #[derive(Clone, Copy, Debug)] pub struct RevolveExtent { diff --git a/crates/doc/src/format/pending/bridged-counterbore.rs b/crates/doc/src/format/pending/bridged-counterbore.rs new file mode 100644 index 000000000..5f960278a --- /dev/null +++ b/crates/doc/src/format/pending/bridged-counterbore.rs @@ -0,0 +1,4 @@ +//! A counterbore hole may save a `bridge` length: two printing layers that thick below the +//! counterbore's floor (a slot as wide as the hole along X, then a square) so a 3D printer bridges +//! the step. An older design has none and keeps a plain counterbore. The last release refuses a +//! design that has it (it asks for an update) instead of opening it without the bridge layers. diff --git a/crates/engine/src/cmd/features.rs b/crates/engine/src/cmd/features.rs index 311bfe333..9dc71daea 100644 --- a/crates/engine/src/cmd/features.rs +++ b/crates/engine/src/cmd/features.rs @@ -105,7 +105,7 @@ pub static COMMANDS: &[CommandSpec] = &[ .at("SOLID", "CREATE") .icon("hole") .key("H") - .params("position: [x,y,z] on a face (numbers, or length expressions the hole follows) | sketch + points: [sketch point ids] (one hole each, perpendicular to the sketch, into the material on whichever side of the sketch plane it is) | sketch alone (every sketch point: standalone points and circle centres); flip?: bool (sketch points: drill to the other side); single?: bool (with one sketch point: a Single hole that follows the point, drilled into the face there); direction?: [x,y,z] (default: into the face, against its outward normal; one that leaves the face is mirrored into it; ignored with sketch points unless single); diameter | thread (a tapped hole, drilled with the tap maker's tabulated drill: ISO metric (a custom metric size: major minus pitch), UNC/UNF, G, Rp, Rc 1/16 to 4, NPT 1/16 to 3; a `diameter` given with it chooses another drill, from the thread's minor diameter to 5% over the tap maker's) | clearance: \"M6\" with fit?: close|normal|loose (ISO 273); depth? (default through all) | to?: [x,y,z] (To Object: drill to that face or point); references?: [{edge: [x,y,z] on a straight edge of the face, distance: expr}] (at most two; the centre goes that far from each edge's line, in the face's plane, and follows the edges; with a numeric position only); type?: simple|drilled|counterbore|countersink; tip_angle?; cb_diameter?, cb_depth?; cs_diameter?, cs_angle?; thread?: \"M6\", \"1/4-20 UNC\", \"G 1/4\", \"Rp 1/4\", \"Rc 1/4\" or \"1/4-18 NPT\" (cosmetic unless modeled); hand?: right|left (the tapped thread's hand; default right; needs thread); thread_depth?: positive length independent of drill depth (default: full useful cylindrical wall; must fit that wall); modeled?: bool (needs thread: the tapped thread cut into the wall, the groove between its teeth, as solid.thread's modelled one; default false: listed only); ease_out?: expr|standard|short (modelled tapped threads: the inner end, towards the bottom, fades out over this length, ISO 3508's runout, standard 2.5 P, short 1.25 P; without it the groove stops square at thread_depth, or clear of a blind hole's bottom); targets?: [body] (the bodies to drill; holes at the points of a sketch on a body's face default to that body, found along the holes' direction on it alone; explicit targets or participants override, [\"*\"] every body)"), + .params("position: [x,y,z] on a face (numbers, or length expressions the hole follows) | sketch + points: [sketch point ids] (one hole each, perpendicular to the sketch, into the material on whichever side of the sketch plane it is) | sketch alone (every sketch point: standalone points and circle centres); flip?: bool (sketch points: drill to the other side); single?: bool (with one sketch point: a Single hole that follows the point, drilled into the face there); direction?: [x,y,z] (default: into the face, against its outward normal; one that leaves the face is mirrored into it; ignored with sketch points unless single); diameter | thread (a tapped hole, drilled with the tap maker's tabulated drill: ISO metric (a custom metric size: major minus pitch), UNC/UNF, G, Rp, Rc 1/16 to 4, NPT 1/16 to 3; a `diameter` given with it chooses another drill, from the thread's minor diameter to 5% over the tap maker's) | clearance: \"M6\" with fit?: close|normal|loose (ISO 273); depth? (default through all) | to?: [x,y,z] (To Object: drill to that face or point); references?: [{edge: [x,y,z] on a straight edge of the face, distance: expr}] (at most two; the centre goes that far from each edge's line, in the face's plane, and follows the edges; with a numeric position only); type?: simple|drilled|counterbore|countersink; tip_angle?; cb_diameter?, cb_depth?, bridge?: length (counterbore: two 3D-printing bridge layers this thick below its floor, a slot along X then a square; e.g. 0.2 mm); cs_diameter?, cs_angle?; thread?: \"M6\", \"1/4-20 UNC\", \"G 1/4\", \"Rp 1/4\", \"Rc 1/4\" or \"1/4-18 NPT\" (cosmetic unless modeled); hand?: right|left (the tapped thread's hand; default right; needs thread); thread_depth?: positive length independent of drill depth (default: full useful cylindrical wall; must fit that wall); modeled?: bool (needs thread: the tapped thread cut into the wall, the groove between its teeth, as solid.thread's modelled one; default false: listed only); ease_out?: expr|standard|short (modelled tapped threads: the inner end, towards the bottom, fades out over this length, ISO 3508's runout, standard 2.5 P, short 1.25 P; without it the groove stops square at thread_depth, or clear of a blind hole's bottom); targets?: [body] (the bodies to drill; holes at the points of a sketch on a body's face default to that body, found along the holes' direction on it alone; explicit targets or participants override, [\"*\"] every body)"), CommandSpec::new("solid.pipe", "Pipe", crate::checked!("solid.pipe", pipe)) .at("SOLID", "CREATE") .icon("pipe") @@ -2838,15 +2838,24 @@ fn hole(s: &mut Session, p: &Value) -> Result { let e = req_expr(cmd, p, k)?; Ok(e) }; + // Given but unreadable (`true`, a list, an empty text): refused, never a plain counterbore. + let bridge = match (expr(p, "bridge"), p.get("bridge")) { + (Some(b), _) => Some(b), + (None, None | Some(Value::Null)) => None, + (None, v) => return Err(bad(cmd, format!("`bridge` {}", expr_problem(v)))), + }; let kind = match str_(p, "type").unwrap_or("simple") { "simple" => match expr(p, "tip_angle") { Some(t) if depth.is_some() => solidcraft_doc::HoleKind::Drilled { tip_angle: t }, _ => solidcraft_doc::HoleKind::Simple, }, "drilled" => solidcraft_doc::HoleKind::Drilled { tip_angle: expr(p, "tip_angle").unwrap_or_else(|| "118 deg".into()) }, - "counterbore" => { - solidcraft_doc::HoleKind::Counterbore { cb_diameter: get("cb_diameter")?, cb_depth: get("cb_depth")?, tip_angle: expr(p, "tip_angle") } - } + "counterbore" => solidcraft_doc::HoleKind::Counterbore { + cb_diameter: get("cb_diameter")?, + cb_depth: get("cb_depth")?, + tip_angle: expr(p, "tip_angle"), + bridge: bridge.clone(), + }, "countersink" => solidcraft_doc::HoleKind::Countersink { cs_diameter: get("cs_diameter")?, cs_angle: expr(p, "cs_angle").unwrap_or_else(|| "90 deg".into()), @@ -2854,6 +2863,11 @@ fn hole(s: &mut Session, p: &Value) -> Result { }, other => return Err(bad(cmd, format!("unknown hole type `{other}`"))), }; + match (&kind, &bridge) { + (solidcraft_doc::HoleKind::Counterbore { .. }, Some(b)) => check_expr(s, b, Kind::Length, cmd, "bridge")?, + (_, Some(_)) => return Err(bad(cmd, "`bridge` needs `type: counterbore`")), + _ => {} + } let to = match p.get("to") { Some(v) => Some(vec3(v).ok_or_else(|| bad(cmd, "`to` must be a point [x, y, z] on the face to drill to"))?), None => None, diff --git a/crates/engine/src/hole_matrix_tests.rs b/crates/engine/src/hole_matrix_tests.rs index 123b2be85..dc862f211 100644 --- a/crates/engine/src/hole_matrix_tests.rs +++ b/crates/engine/src/hole_matrix_tests.rs @@ -179,6 +179,15 @@ fn radial(rr: f64, r: f64, depth: f64) -> f64 { sum } +/// The bridge layers of a counterbore of radius `rc` over a hole of radius r: one 0.2 mm layer of +/// the slot (out to the counterbore wall) and one of the square, both 0.02 mm wider than the +/// hole, each less the bore's disc. +fn bridges(rc: f64, r: f64) -> f64 { + let q = r + 0.01; + let slot = 2.0 * (q * (rc * rc - q * q).sqrt() + rc * rc * (q / rc).asin()); + 0.2 * (slot - PI * r * r) + 0.2 * (4.0 * q * q - PI * r * r) +} + // ---- the cases ------------------------------------------------------------------------------- const DOWN: [f64; 3] = [0.0, 0.0, -1.0]; @@ -411,6 +420,33 @@ fn cases() -> Vec { vec![spot([20.0, 15.0, 20.0], DOWN, 20.0, None)], ) .faces(3), + Case::new( + "type/counterbore-bridged/blind", + block(), + hole(json!({"position": [20, 15, 20], "depth": 10, "type": "counterbore", "cb_diameter": 12, "cb_depth": 3, "bridge": "0.2 mm"})), + cyl(6.0, 3.0) + cyl(r, 7.0) + bridges(6.0, r), + r, + vec![spot([20.0, 15.0, 20.0], DOWN, 10.0, Some(10.0))], + ) + .faces(12), + Case::new( + "type/counterbore-bridged/blind-drill-point", + block(), + hole(json!({"position": [20, 15, 20], "depth": 10, "type": "counterbore", "cb_diameter": 12, "cb_depth": 3, "tip_angle": "118 deg", "bridge": "0.2 mm"})), + cyl(6.0, 3.0) + cyl(r, 7.0) + tip(r) + bridges(6.0, r), + r, + vec![spot([20.0, 15.0, 20.0], DOWN, 10.0, Some(10.0 + r / 59f64.to_radians().tan()))], + ) + .faces(12), + Case::new( + "type/counterbore-bridged/through", + block(), + hole(json!({"position": [20, 15, 20], "type": "counterbore", "cb_diameter": 12, "cb_depth": 3, "bridge": "0.2 mm"})), + cyl(6.0, 3.0) + cyl(r, 17.0) + bridges(6.0, r), + r, + vec![spot([20.0, 15.0, 20.0], DOWN, 20.0, None)], + ) + .faces(11), Case::new( "type/countersink/blind", block(), @@ -893,3 +929,77 @@ fn a_hole_on_a_cones_side_drills_along_its_normal() { let d = direction.0; assert!((d.x + 0.8).abs() < 1e-6 && d.y.abs() < 1e-6 && (d.z + 0.6).abs() < 1e-6, "{d:?}"); } + +#[test] +fn bridged_counterbore_layers_along_x_save_and_refuse_bad_values() { + let block = || { + let mut s = Session::default(); + run(&mut s, "solid.box", json!({"length":40,"width":30,"height":20})).unwrap(); + s + }; + let mut s = block(); + let mut p = json!({"position":[20,15,20],"diameter":6,"type":"counterbore","cb_diameter":12,"cb_depth":3,"bridge":"0.2 mm"}); + run(&mut s, "solid.hole", p.clone()).unwrap(); + // Layer 1 (z 16.8 to 17): the slot runs along X out to the counterbore wall, beside it is solid. + assert!(!solid_at(&s, Vec3::new(25.5, 15.0, 16.9)), "the slot reaches the counterbore wall along X"); + assert!(solid_at(&s, Vec3::new(20.0, 19.5, 16.9)), "beside the slot the layer bridges the counterbore"); + // Layer 2 (z 16.6 to 16.8): the square's corners are open, the slot's ends are bridged. + assert!(!solid_at(&s, Vec3::new(22.9, 17.9, 16.7)), "the square's corner is open"); + assert!(solid_at(&s, Vec3::new(25.5, 15.0, 16.7)), "past the square the second layer is solid"); + // Below both layers the bore is round again. + assert!(solid_at(&s, Vec3::new(22.9, 17.9, 16.5)), "the bore is round below the layers"); + let saved = s.doc.to_json(); + assert!(saved.contains("\"bridge\""), "the design saves the layer"); + let reopened = Session::new(solidcraft_doc::Document::from_json(&saved).unwrap()); + assert!(!solid_at(&reopened, Vec3::new(22.9, 17.9, 16.7)), "the layers survive reopening"); + // A thicker layer moves the square down with it. + let mut thick = block(); + p["bridge"] = json!("0.5 mm"); + run(&mut thick, "solid.hole", p.clone()).unwrap(); + assert!(!solid_at(&thick, Vec3::new(22.9, 17.9, 16.2)), "a 0.5 mm square spans z 16 to 16.5"); + assert!(solid_at(&thick, Vec3::new(22.9, 17.9, 15.9))); + // Left out, nothing is saved and the counterbore is plain. + let mut plain = block(); + p.as_object_mut().unwrap().remove("bridge"); + run(&mut plain, "solid.hole", p.clone()).unwrap(); + // The key, quoted: `format_pending` names `bridged-counterbore` in every design. + assert!(!plain.doc.to_json().contains("\"bridge\"")); + assert!(solid_at(&plain, Vec3::new(22.9, 17.9, 16.7))); + // Refused: a layer that is not a positive length, layers that don't fit in the hole, and a + // bridge on a hole that has no counterbore. + let refusal = |p: &Value| { + let mut s = block(); + let refused = s.execute("solid.hole", p).err().map(|e| e.to_string()).unwrap_or_default(); + let failed = s.doc.features.last().and_then(|f| s.model.result(f.id)).and_then(|r| r.error.clone()).unwrap_or_default(); + format!("{refused}{failed}") + }; + for bad in [json!("0 mm"), json!("-0.2 mm"), json!("30 deg")] { + p["bridge"] = bad.clone(); + assert!(!refusal(&p).is_empty(), "bridge {bad} is refused"); + } + p["bridge"] = json!("0.2 mm"); + p["depth"] = json!(3.3); + assert!(refusal(&p).contains("must fit in the hole"), "too shallow: {}", refusal(&p)); + p.as_object_mut().unwrap().remove("depth"); + // Through all, the layers must end inside the 20 mm block, short of its far face. + p["cb_depth"] = json!(19.7); + assert!(refusal(&p).contains("must fit in the hole"), "past the exit face: {}", refusal(&p)); + p["cb_depth"] = json!(19.5); + assert_eq!(refusal(&p), "", "0.1 mm short of the exit face fits"); + p["cb_depth"] = json!(3); + // A counterbore too narrow for the slot's clearance (a plain one that wide is fine). + p["cb_diameter"] = json!(6.02); + assert!(refusal(&p).contains("wider than the hole"), "too narrow: {}", refusal(&p)); + p["cb_diameter"] = json!(12); + // Given but not a length expression: refused, never a plain counterbore. Null leaves it out. + for bad in [json!(true), json!([]), json!("")] { + p["bridge"] = bad.clone(); + assert!(refusal(&p).contains("`bridge`"), "bridge {bad}: {}", refusal(&p)); + } + p["bridge"] = Value::Null; + assert_eq!(refusal(&p), "", "a null bridge is left out"); + p["bridge"] = json!("0.2 mm"); + p["type"] = json!("countersink"); + p["cs_diameter"] = json!(12); + assert!(refusal(&p).contains("counterbore"), "countersink: {}", refusal(&p)); +} diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 02ff70fe2..9cc8a731c 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -465,6 +465,8 @@ pub struct HoleOpts { /// A tapped hole's drill when it is not the tap maker's for the size (the command's /// `diameter`); none: the tap maker's. pub drill: Option, + /// Counterbore: the thickness of each 3D-printing bridge layer below its floor; empty for none. + pub bridge: String, } impl Default for HoleOpts { @@ -484,6 +486,7 @@ impl Default for HoleOpts { modeled: false, ease_out: crate::dialogs_thread::Ease::default(), drill: None, + bridge: String::new(), } } } @@ -5484,6 +5487,13 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result, S 1 => { params["cb_diameter"] = json!(cb_diameter); params["cb_depth"] = json!(cb_depth); + let bridge = opts.bridge.trim(); + if !bridge.is_empty() { + if !app.session.doc.eval(bridge, ValueKind::Length).is_ok_and(|t| t > 0.0) { + return Err("the bridge layer must be a positive length, such as 0.2 mm, or empty for none".into()); + } + params["bridge"] = json!(bridge); + } } 2 => { params["cs_diameter"] = json!(cs_diameter); @@ -6485,8 +6495,9 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option) -> Option { + HoleKind::Counterbore { cb_diameter: a, cb_depth: b, tip_angle, bridge } => { *kind = 1; + opts.bridge = bridge.as_ref().map(ToString::to_string).unwrap_or_default(); *cb_diameter = a.to_string(); *cb_depth = b.to_string(); if let Some(angle) = tip_angle { @@ -7425,6 +7436,39 @@ mod refused_ok_tests { } } + #[test] + fn bridge_shows_for_counterbores_only_and_sends_a_valid_layer() { + let mut h = hole_dialog(); + let commands = |h: &Harness| apply_commands(&h.app, h.app.dialog.as_ref().unwrap()); + let set_bridge = |h: &mut Harness, text: &str| { + if let Kind::Hole { opts, .. } = &mut h.app.dialog.as_mut().unwrap().kind { + opts.bridge = text.into(); + } + h.frames(2); + }; + h.frames(2); + assert!(crate::scenario::rect_of("dialog:widget:Bridge").is_none(), "a simple hole has no bridge layers"); + if let Kind::Hole { kind, .. } = &mut h.app.dialog.as_mut().unwrap().kind { + *kind = 1; + } + h.frames(2); + assert!(crate::scenario::rect_of("dialog:widget:Bridge").is_some()); + assert!(commands(&h).unwrap()[0].1.get("bridge").is_none(), "empty by default: no bridge"); + set_bridge(&mut h, "0.2 mm"); + assert_eq!(commands(&h).unwrap()[0].1["bridge"], "0.2 mm"); + for bad in ["0", "-0.2 mm", "abc"] { + set_bridge(&mut h, bad); + assert!(commands(&h).is_err(), "bridge {bad:?} is refused"); + } + set_bridge(&mut h, "0.2 mm"); + if let Kind::Hole { kind, .. } = &mut h.app.dialog.as_mut().unwrap().kind { + *kind = 2; + } + h.frames(2); + assert!(crate::scenario::rect_of("dialog:widget:Bridge").is_none(), "a countersink has no bridge layers"); + assert!(commands(&h).unwrap()[0].1.get("bridge").is_none()); + } + /// What the dialog shows in red once the live preview has finished: its own error, else the /// preview's. fn shown(h: &mut Harness) -> Option { diff --git a/crates/ui-egui/src/dialogs_dense.rs b/crates/ui-egui/src/dialogs_dense.rs index d9a494918..d2d6640ef 100644 --- a/crates/ui-egui/src/dialogs_dense.rs +++ b/crates/ui-egui/src/dialogs_dense.rs @@ -728,6 +728,11 @@ pub(super) fn rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui: opts.angled = tip == 1; }); } + // Counterbore only: the thickness of the layers a 3D printer bridges across its + // floor; empty for none. + if *kind == 1 { + enter |= hint_row(ui, "Bridge", &mut opts.bridge, tr("None")); + } // The section through the hole, each size beside its dimension (#2171). let to_object = to_object_on(&d.inputs); enter |= crate::dialogs_hole::rows(ui, &mut d.kind, to_object, &eval); diff --git a/crates/ui-egui/src/length_input.rs b/crates/ui-egui/src/length_input.rs index d65e330c3..7eb6e380b 100644 --- a/crates/ui-egui/src/length_input.rs +++ b/crates/ui-egui/src/length_input.rs @@ -118,7 +118,9 @@ pub(crate) fn fields<'a>(doc: &Document, kind: &'a mut crate::dialogs::Kind) -> D::Pipe { diameter, wall, .. } => vec![diameter, wall], D::Stock { margin } => vec![margin], D::Move { x, y, z, .. } => vec![x, y, z], - D::Hole { diameter, depth, cb_diameter, cb_depth, cs_diameter, .. } => vec![diameter, depth, cb_diameter, cb_depth, cs_diameter], + D::Hole { diameter, depth, cb_diameter, cb_depth, cs_diameter, opts, .. } => { + vec![diameter, depth, cb_diameter, cb_depth, cs_diameter, &mut opts.bridge] + } D::Primitive { fields, .. } => fields.iter_mut().filter(|(key, _)| *key != "revolutions").map(|(_, value)| value).collect(), D::Surface(k) => match k { Surf::Extrude { distance, .. } | Surf::Offset { distance, .. } | Surf::Ruled { distance, .. } | Surf::Extend { distance } => { diff --git a/crates/ui-egui/src/primitive_units_tests.rs b/crates/ui-egui/src/primitive_units_tests.rs index 01bec23d6..89802635d 100644 --- a/crates/ui-egui/src/primitive_units_tests.rs +++ b/crates/ui-egui/src/primitive_units_tests.rs @@ -286,7 +286,7 @@ fn operation_length_defaults_follow_every_design_unit() { ("solid.fillet", &["2", "2"]), ("solid.chamfer", &["1", "1"]), ("solid.shell", &["2"]), - ("solid.hole", &["5", "10", "9", "3", "10"]), + ("solid.hole", &["5", "10", "9", "3", "10", ""]), ("solid.rib", &["2", ""]), ("solid.web", &["2", ""]), ("solid.emboss", &["1"]),